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>
82 lines
2.7 KiB
Rust
82 lines
2.7 KiB
Rust
//! Shared on-disk candidate set for managed daemon restarts.
|
|
|
|
use std::collections::BTreeMap;
|
|
use std::collections::BTreeSet;
|
|
use std::io;
|
|
use std::path::Path;
|
|
|
|
use akode_core::path_utils::write_atomically;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
#[derive(Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
|
pub struct RecoverySnapshot {
|
|
#[serde(skip)]
|
|
pub loaded: BTreeSet<String>,
|
|
pub interrupted: BTreeMap<String, InterruptedTurn>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
|
pub struct InterruptedTurn {
|
|
pub turn_id: String,
|
|
pub output_schema: Option<serde_json::Value>,
|
|
pub service_tier: Option<String>,
|
|
/// Only local execution with thread-owned configuration can continue automatically.
|
|
/// Older snapshots without this identity are reloaded without continuation.
|
|
pub local_environment: Option<akode_app_server_protocol::ThreadEnvironment>,
|
|
}
|
|
|
|
// Old servers accept the array and skip this non-thread entry during best-effort
|
|
// restoration. Keeping metadata in the same atomic file avoids stale sidecars.
|
|
const INTERRUPTION_PREFIX: &str = "codex-interrupted-v1:";
|
|
|
|
pub fn read_snapshot(path: &Path) -> io::Result<RecoverySnapshot> {
|
|
let mut loaded: BTreeSet<String> = match std::fs::read(path) {
|
|
Ok(contents) => serde_json::from_slice(&contents).map_err(io::Error::other)?,
|
|
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(RecoverySnapshot::default()),
|
|
Err(err) => return Err(err),
|
|
};
|
|
let mut snapshot = RecoverySnapshot::default();
|
|
loaded.retain(|entry| {
|
|
if let Some(metadata) = entry.strip_prefix(INTERRUPTION_PREFIX) {
|
|
if let Ok(saved) = serde_json::from_str::<RecoverySnapshot>(metadata) {
|
|
snapshot = saved;
|
|
}
|
|
false
|
|
} else {
|
|
true
|
|
}
|
|
});
|
|
snapshot.interrupted.retain(|id, _| loaded.contains(id));
|
|
snapshot.loaded = loaded;
|
|
Ok(snapshot)
|
|
}
|
|
|
|
pub fn read_candidates(path: &Path) -> io::Result<BTreeSet<String>> {
|
|
Ok(read_snapshot(path)?.loaded)
|
|
}
|
|
|
|
pub fn write_candidates(path: &Path, candidates: &BTreeSet<String>) -> io::Result<()> {
|
|
write_snapshot(
|
|
path,
|
|
&RecoverySnapshot {
|
|
loaded: candidates.clone(),
|
|
..Default::default()
|
|
},
|
|
)
|
|
}
|
|
|
|
pub fn write_snapshot(path: &Path, snapshot: &RecoverySnapshot) -> io::Result<()> {
|
|
let mut saved = snapshot.loaded.clone();
|
|
if !snapshot.interrupted.is_empty() {
|
|
saved.insert(format!(
|
|
"{INTERRUPTION_PREFIX}{}",
|
|
serde_json::to_string(snapshot).map_err(io::Error::other)?
|
|
));
|
|
}
|
|
write_atomically(
|
|
path,
|
|
&serde_json::to_string(&saved).map_err(io::Error::other)?,
|
|
)
|
|
}
|