aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-11 11:06:46 +01:00
parent df99318392
commit 86e7c72e5f
10383 changed files with 749164 additions and 749170 deletions

View File

@@ -0,0 +1,55 @@
//! Selects a smaller resume context for legacy subagent rollouts.
//!
//! Legacy subagents copied the parent's full rollout into every child rollout. Migrating those
//! files verbatim can preserve gigabytes of duplicated history even though a resumed subagent only
//! needs its latest bounded model context.
//!
//! This module reverse-scans the legacy rollout for the newest compaction with replacement history
//! and a window number. Malformed records are skipped. If no such compaction exists, the caller
//! falls back to full tolerant replay.
use std::fs::File;
use std::path::PathBuf;
use akode_rollout::ModelContextScan;
use akode_rollout::ModelContextScanProgress;
use akode_rollout::ReverseJsonlScanner;
use akode_rollout::RolloutItem;
use akode_rollout::ScanOutcome;
use serde_json::Value;
use super::line_parser;
use super::migration_error;
use crate::ThreadStoreResult;
/// Returns the suffix starting at the newest usable compaction, if one exists.
pub(super) async fn select_bounded_context(
rollout_path: PathBuf,
) -> ThreadStoreResult<Option<Vec<RolloutItem>>> {
tokio::task::spawn_blocking(move || {
let file = File::open(rollout_path).map_err(migration_error)?;
let mut scanner = ReverseJsonlScanner::new(file)
.map_err(migration_error)?
.with_max_record_bytes(super::MAX_ROLLOUT_LINE_BYTES);
let mut scan = ModelContextScan::default();
while let Some(outcome) = scanner.scan_next::<Value>().map_err(migration_error)? {
let value = match outcome {
ScanOutcome::Parsed(value) => value,
ScanOutcome::Rejected(_) => continue,
};
let Ok(Some(line)) = line_parser::parse_legacy_rollout_value(value) else {
continue;
};
if scan.push(line.item) == ModelContextScanProgress::Complete {
let mut items = scan.finish();
items.retain(|item| !matches!(item, RolloutItem::SessionMeta(_)));
return Ok(Some(items));
}
}
Ok(None)
})
.await
.map_err(migration_error)?
}