fix(cli): surface session_id in /status JSON output

When running claw --output-format json --resume <session> /status, the
JSON output had 'session' (full file path) but no 'session_id' field,
making it impossible for scripts to extract the loaded session ID.

Now extracts the session-id directory component from the session path
(e.g. .claw/sessions/<session-id>/session-xxx.jsonl → session-id)
and includes it as 'session_id' in the JSON status envelope.

159 CLI tests pass, fmt clean.
This commit is contained in:
YeonGyu-Kim
2026-04-09 19:06:36 +09:00
parent 54269da157
commit e1ed30a038

View File

@@ -4825,6 +4825,11 @@ fn status_json_value(
"unstaged_files": context.git_summary.unstaged_files,
"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())
}),
"loaded_config_files": context.loaded_config_files,
"discovered_config_files": context.discovered_config_files,
"memory_file_count": context.memory_file_count,