Add --resume <session-id> flag for explicit session resumption

- Add --resume CLI flag that conflicts with --new-session
- Add load_continuation_by_id() to load sessions by full or partial ID
- Support loading from latest.json or falling back to session.json
- Handle --resume in both normal and agent modes
- Agent mode validates session belongs to correct agent
This commit is contained in:
Dhanji R. Prasanna
2026-02-05 10:23:39 +11:00
parent 3046f0dd6e
commit fdb1255f02
5 changed files with 160 additions and 2 deletions

View File

@@ -44,6 +44,25 @@ pub async fn run_agent_mode(
// Skip session resume entirely when in chat mode (--agent --chat)
let resuming_session = if chat {
None // Chat mode always starts fresh
} else if let Some(ref session_id) = flags.resume {
// Explicit --resume flag takes precedence
match g3_core::load_continuation_by_id(session_id) {
Ok(continuation) => {
// Verify the session matches this agent (or allow any if agent name matches)
if continuation.agent_name.as_deref() != Some(agent_name) {
eprintln!("Error: Session '{}' belongs to agent '{}', not '{}'",
session_id,
continuation.agent_name.as_deref().unwrap_or("(none)"),
agent_name);
std::process::exit(1);
}
Some(continuation)
}
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}
} else if flags.new_session {
if !chat {
output.print("\n🆕 Starting new session (--new-session flag set)");