Persist CLI conversation history across sessions

The Rust CLI now stores managed sessions under ~/.claude/sessions,
records additive session metadata in the canonical JSON transcript,
and exposes a /sessions listing alias alongside ID-or-path resume.
Inactive oversized sessions are compacted automatically so old
transcripts remain resumable without growing unchecked.

Constraint: Session JSON must stay backward-compatible with legacy files that lack metadata
Constraint: Managed sessions must use a single canonical JSON file per session without new dependencies
Rejected: Sidecar metadata/index files | duplicated state and diverged from the requested single-file persistence model
Confidence: high
Scope-risk: moderate
Reversibility: clean
Directive: Keep CLI policy in the CLI; only add transcript-adjacent metadata to runtime::Session unless another consumer truly needs more
Tested: cargo fmt; cargo clippy --workspace --all-targets -- -D warnings; cargo test --workspace
Not-tested: Manual interactive REPL smoke test against the live Anthropic API
This commit is contained in:
Yeachan-Heo
2026-04-01 00:58:14 +00:00
parent d6341d54c1
commit 146260083c
8 changed files with 342 additions and 37 deletions

View File

@@ -105,6 +105,7 @@ pub fn compact_session(session: &Session, config: CompactionConfig) -> Compactio
compacted_session: Session {
version: session.version,
messages: compacted_messages,
metadata: session.metadata.clone(),
},
removed_message_count: removed.len(),
}
@@ -393,6 +394,7 @@ mod tests {
let session = Session {
version: 1,
messages: vec![ConversationMessage::user_text("hello")],
metadata: None,
};
let result = compact_session(&session, CompactionConfig::default());
@@ -420,6 +422,7 @@ mod tests {
usage: None,
},
],
metadata: None,
};
let result = compact_session(