fix(cli): JSON parity for /compact and /clear in resume mode

/compact now emits: {kind:compact, skipped, removed_messages, kept_messages}
/clear now emits:  {kind:clear, previous_session_id, new_session_id, backup, session_file}
/clear (no --confirm) now emits: {kind:error, error:..., hint:...}

Previously both returned json:None and fell through to prose output even
in --output-format json --resume mode. 159 CLI tests pass.
This commit is contained in:
YeonGyu-Kim 2026-04-10 01:31:21 +09:00
parent 39a7dd08bb
commit 78dca71f3f

View File

@ -2678,7 +2678,12 @@ fn run_resume_command(
Ok(ResumeCommandOutcome {
session: result.compacted_session,
message: Some(format_compact_report(removed, kept, skipped)),
json: None,
json: Some(serde_json::json!({
"kind": "compact",
"skipped": skipped,
"removed_messages": removed,
"kept_messages": kept,
})),
})
}
SlashCommand::Clear { confirm } => {
@ -2688,7 +2693,11 @@ fn run_resume_command(
message: Some(
"clear: confirmation required; rerun with /clear --confirm".to_string(),
),
json: None,
json: Some(serde_json::json!({
"kind": "error",
"error": "confirmation required",
"hint": "rerun with /clear --confirm",
})),
});
}
let backup_path = write_session_clear_backup(session, session_path)?;
@ -2704,7 +2713,13 @@ fn run_resume_command(
backup_path.display(),
session_path.display()
)),
json: None,
json: Some(serde_json::json!({
"kind": "clear",
"previous_session_id": previous_session_id,
"new_session_id": new_session_id,
"backup": backup_path.display().to_string(),
"session_file": session_path.display().to_string(),
})),
})
}
SlashCommand::Status => {