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>
This commit is contained in:
200
akode-rs/ext/extension-api/src/contributors/world_state.rs
Normal file
200
akode-rs/ext/extension-api/src/contributors/world_state.rs
Normal file
@@ -0,0 +1,200 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use akode_protocol::ThreadId;
|
||||
use akode_protocol::models::ContentItem;
|
||||
use akode_protocol::models::ContentItemMetadata;
|
||||
use akode_protocol::openai_models::ModelInfo;
|
||||
use akode_protocol::protocol::TurnEnvironmentSelection;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::ExtensionData;
|
||||
use crate::ExtensionMetrics;
|
||||
|
||||
/// Host state available while an extension contributes one sampling step's World State.
|
||||
pub struct WorldStateContributionInput<'a> {
|
||||
pub thread_id: ThreadId,
|
||||
pub turn_id: &'a str,
|
||||
/// Resolved model metadata captured for this sampling step, retained across discovery.
|
||||
pub model_info: &'a ModelInfo,
|
||||
pub environments: &'a [TurnEnvironmentSelection],
|
||||
/// Metrics bound to the captured model for this sampling step.
|
||||
pub extension_metrics: Option<Arc<dyn ExtensionMetrics>>,
|
||||
pub session_store: &'a ExtensionData,
|
||||
pub thread_store: &'a ExtensionData,
|
||||
pub turn_store: &'a ExtensionData,
|
||||
/// The same captured extension inputs that were used to build this step's tools.
|
||||
pub step_store: &'a ExtensionData,
|
||||
/// Persisted comparison state from the last recorded step. Its rendered text may have
|
||||
/// left model history; use a retained-fragment matcher before referring back to it.
|
||||
/// After compaction, sections may contain only retained extension metadata.
|
||||
pub previous_world_state: Option<&'a serde_json::Map<String, Value>>,
|
||||
}
|
||||
|
||||
/// What the harness knows about the previous value of one extension-owned section.
|
||||
pub enum PreviousWorldStateSection<'a> {
|
||||
Absent,
|
||||
Unknown,
|
||||
Known(&'a Value),
|
||||
}
|
||||
|
||||
/// Model-visible content rendered by an extension-owned World State section.
|
||||
/// Markers apply only to `InputText` bodies.
|
||||
/// The producer owns size bounds for the content; rendering does not truncate it.
|
||||
/// Non-text user-role bodies are currently classified as ordinary user media.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct RenderedWorldStateFragment {
|
||||
role: &'static str,
|
||||
markers: (&'static str, &'static str),
|
||||
body: ContentItem,
|
||||
metadata: ContentItemMetadata,
|
||||
}
|
||||
|
||||
impl RenderedWorldStateFragment {
|
||||
pub fn new(
|
||||
role: &'static str,
|
||||
markers: (&'static str, &'static str),
|
||||
body: ContentItem,
|
||||
) -> Self {
|
||||
Self {
|
||||
role,
|
||||
markers,
|
||||
body,
|
||||
metadata: ContentItemMetadata::harness(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Attach the producer's source before the harness assembles the context message.
|
||||
pub fn with_metadata(mut self, metadata: ContentItemMetadata) -> Self {
|
||||
self.metadata = metadata;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn metadata(&self) -> &ContentItemMetadata {
|
||||
&self.metadata
|
||||
}
|
||||
|
||||
pub fn role(&self) -> &'static str {
|
||||
self.role
|
||||
}
|
||||
|
||||
pub fn markers(&self) -> (&'static str, &'static str) {
|
||||
self.markers
|
||||
}
|
||||
|
||||
pub fn body(&self) -> &ContentItem {
|
||||
&self.body
|
||||
}
|
||||
}
|
||||
|
||||
type RenderDiff = dyn for<'a> Fn(PreviousWorldStateSection<'a>) -> (Option<Value>, Option<RenderedWorldStateFragment>)
|
||||
+ Send
|
||||
+ Sync;
|
||||
type LegacyFragmentMatcher = dyn Fn(&str, &str) -> bool + Send + Sync;
|
||||
|
||||
/// One extension-owned World State section captured for a sampling step.
|
||||
///
|
||||
/// The extension owns the stable ID, comparison snapshot, and diff rendering. The harness owns
|
||||
/// persistence and the concrete model-context fragment envelope.
|
||||
#[derive(Clone)]
|
||||
pub struct WorldStateSectionContribution {
|
||||
id: &'static str,
|
||||
include_in_full_context: bool,
|
||||
window_prefix: bool,
|
||||
render_diff: Arc<RenderDiff>,
|
||||
matches_legacy_fragment: Arc<LegacyFragmentMatcher>,
|
||||
matches_retained_fragment: Option<Arc<LegacyFragmentMatcher>>,
|
||||
}
|
||||
|
||||
impl WorldStateSectionContribution {
|
||||
/// Return a replacement snapshot and/or fragment. A missing snapshot retains the
|
||||
/// previous section state; a missing fragment emits no model-visible update. A null
|
||||
/// snapshot removes the section from persisted state.
|
||||
pub fn new(
|
||||
id: &'static str,
|
||||
render_diff: impl for<'a> Fn(
|
||||
PreviousWorldStateSection<'a>,
|
||||
) -> (Option<Value>, Option<RenderedWorldStateFragment>)
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
) -> Self {
|
||||
Self {
|
||||
id,
|
||||
include_in_full_context: true,
|
||||
window_prefix: false,
|
||||
render_diff: Arc::new(render_diff),
|
||||
matches_legacy_fragment: Arc::new(|_, _| false),
|
||||
matches_retained_fragment: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Recompute this section during ordinary step context updates instead of replaying
|
||||
/// its captured value when initial or compacted context is rebuilt. Full rendering
|
||||
/// omits both its fragment and comparison snapshot so a fresh contribution can emit.
|
||||
/// After prefix compaction, the next diff receives [`PreviousWorldStateSection::Unknown`]
|
||||
/// if the section's legacy matcher recognizes text in the retained suffix.
|
||||
pub fn without_full_context(mut self) -> Self {
|
||||
self.include_in_full_context = false;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn include_in_full_context(&self) -> bool {
|
||||
self.include_in_full_context
|
||||
}
|
||||
|
||||
pub fn with_legacy_matcher(
|
||||
mut self,
|
||||
matcher: impl Fn(&str, &str) -> bool + Send + Sync + 'static,
|
||||
) -> Self {
|
||||
self.matches_legacy_fragment = Arc::new(matcher);
|
||||
self
|
||||
}
|
||||
|
||||
/// Render this section's developer fragments as separate messages before retained
|
||||
/// history when the harness builds a window (including after compaction). Changes
|
||||
/// within an existing window are still appended as ordinary history updates.
|
||||
/// Fragments with any other role are not rendered, including in history updates.
|
||||
/// The producer still owns content size bounds; prefix placement does not truncate.
|
||||
pub fn with_window_prefix(mut self) -> Self {
|
||||
self.window_prefix = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn is_window_prefix(&self) -> bool {
|
||||
self.window_prefix
|
||||
}
|
||||
|
||||
/// Requires a matching model-visible fragment whenever a persisted snapshot is reused.
|
||||
pub fn with_retained_fragment_matcher(
|
||||
mut self,
|
||||
matcher: impl Fn(&str, &str) -> bool + Send + Sync + 'static,
|
||||
) -> Self {
|
||||
self.matches_retained_fragment = Some(Arc::new(matcher));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &'static str {
|
||||
self.id
|
||||
}
|
||||
|
||||
pub fn render_diff(
|
||||
&self,
|
||||
previous: PreviousWorldStateSection<'_>,
|
||||
) -> (Option<Value>, Option<RenderedWorldStateFragment>) {
|
||||
(self.render_diff)(previous)
|
||||
}
|
||||
|
||||
pub fn matches_legacy_fragment(&self, role: &str, text: &str) -> bool {
|
||||
(self.matches_legacy_fragment)(role, text)
|
||||
}
|
||||
|
||||
pub fn has_retained_fragment_matcher(&self) -> bool {
|
||||
self.matches_retained_fragment.is_some()
|
||||
}
|
||||
|
||||
pub fn matches_retained_fragment(&self, role: &str, text: &str) -> bool {
|
||||
self.matches_retained_fragment
|
||||
.as_ref()
|
||||
.is_some_and(|matcher| matcher(role, text))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user