fix(cli): /status JSON emits null model and correct session_id in resume mode

Two bugs in --output-format json --resume /status:

1. 'model' field emitted 'restored-session' (a run-mode label) instead of
   the actual model or null. Fixed: status_json_value now takes Option<&str>
   for model; resume path passes None; live REPL path passes Some(model).

2. 'session_id' extracted parent dir name ('sessions') instead of the file
   stem. Session files are session-<id>.jsonl directly under .claw/sessions/,
   not in a subdirectory. Fixed: extract file_stem() instead of
   parent().file_name().

159 CLI tests pass.
This commit is contained in:
YeonGyu-Kim
2026-04-10 02:03:14 +09:00
parent 9cf4033fdf
commit dc4fa55d64

View File

@@ -2741,7 +2741,7 @@ fn run_resume_command(
&context,
)),
json: Some(status_json_value(
"restored-session",
None,
StatusUsage {
message_count: session.messages.len(),
turns: tracker.turns(),
@@ -5006,7 +5006,7 @@ fn print_status_snapshot(
CliOutputFormat::Json => println!(
"{}",
serde_json::to_string_pretty(&status_json_value(
model,
Some(model),
usage,
permission_mode.as_str(),
&context,
@@ -5017,7 +5017,7 @@ fn print_status_snapshot(
}
fn status_json_value(
model: &str,
model: Option<&str>,
usage: StatusUsage,
permission_mode: &str,
context: &StatusContext,
@@ -5046,9 +5046,9 @@ fn status_json_value(
"untracked_files": context.git_summary.untracked_files,
"session": context.session_path.as_ref().map_or_else(|| "live-repl".to_string(), |path| path.display().to_string()),
"session_id": context.session_path.as_ref().and_then(|path| {
// Session files live under .claw/sessions/<session-id>/<file>.jsonl
// Extract the session-id directory component.
path.parent().and_then(|p| p.file_name()).map(|n| n.to_string_lossy().into_owned())
// Session files are named <session-id>.jsonl directly under
// .claw/sessions/. Extract the stem (drop the .jsonl extension).
path.file_stem().map(|n| n.to_string_lossy().into_owned())
}),
"loaded_config_files": context.loaded_config_files,
"discovered_config_files": context.discovered_config_files,