Files
imeai-aKode/akode-rs/guardian-context/src/trusted_skills.rs
andrea.difonzo 7c1c6dfa8d Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
  nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 12:37:52 +01:00

99 lines
3.0 KiB
Rust

//! Bounded rendering of host-verified invoked skill paths for async review.
//! Ownership checks, turn storage and delegated evidence selection stay in the host.
use crate::ContextSection;
use crate::SectionContributor;
use crate::SectionError;
use crate::SectionInput;
use crate::SectionScope;
use akode_context_fragments::ContextualUserFragment;
use akode_protocol::models::ContentItem;
use akode_protocol::models::ContentItemKind;
use akode_protocol::models::input_text;
use akode_protocol::protocol::TruncationPolicy;
use serde_json::json;
const MAX_TRUSTED_SKILL_TOKENS: usize = 768;
const TRUSTED_SKILLS_PREFIX: &str = "Codex-verified invoked user-owned skill paths:\n";
/// Host-verified user-owned skill paths for the current Guardian classification.
#[derive(Clone, PartialEq, Eq)]
pub struct TrustedSkills {
pub paths: Vec<String>,
}
impl TrustedSkills {
/// Classification attached to this fragment's rendered text.
pub const KIND: &str = "guardian.trusted_skills";
}
impl ContextualUserFragment for TrustedSkills {
fn content_kind(&self) -> ContentItemKind {
ContentItemKind(Self::KIND.to_owned())
}
fn role(&self) -> &'static str {
"developer"
}
fn markers(&self) -> (&'static str, &'static str) {
Self::type_markers()
}
fn type_markers() -> (&'static str, &'static str) {
("", "")
}
fn body(&self) -> ContentItem {
let mut paths = String::from("[");
let max_path_bytes = TruncationPolicy::Tokens(MAX_TRUSTED_SKILL_TOKENS)
.byte_budget()
.saturating_sub(TRUSTED_SKILLS_PREFIX.len());
for path in &self.paths {
let separator = if paths.ends_with('[') { "" } else { "," };
let encoded_path = json!(path).to_string();
if paths
.len()
.saturating_add(separator.len())
.saturating_add(encoded_path.len())
.saturating_add(1)
> max_path_bytes
{
continue;
}
paths.push_str(separator);
paths.push_str(&encoded_path);
}
paths.push(']');
input_text(format!("{TRUSTED_SKILLS_PREFIX}{paths}"))
}
}
impl std::fmt::Debug for TrustedSkills {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("TrustedSkills")
.field("count", &self.paths.len())
.finish_non_exhaustive()
}
}
pub(crate) struct TrustedSkillsSection;
impl SectionContributor for TrustedSkillsSection {
fn scope(&self) -> SectionScope {
SectionScope::AsyncOnly
}
fn contribute(&self, input: &SectionInput<'_>) -> Result<Option<ContextSection>, SectionError> {
Ok((!input.trusted_skill_paths.is_empty()).then(|| {
ContextSection::TrustedSkills(TrustedSkills {
paths: input.trusted_skill_paths.to_vec(),
})
}))
}
}
#[cfg(test)]
#[path = "trusted_skills_tests.rs"]
mod tests;