mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-10 10:04:50 +08:00
fix(cli): JSON parity for /memory and /providers in resume mode
Two gaps closed:
1. /memory (resume): json field was None, emitting prose regardless of
--output-format json. Now emits:
{kind:memory, cwd, instruction_files:N, files:[{path,lines,preview}...]}
2. /providers (resume): had a spec entry but no parse arm, producing the
circular 'Unknown slash command: /providers — Did you mean /providers'.
Added 'providers' as an alias for 'doctor' in the parse match so
/providers dispatches to the same structured diagnostic output.
3. /doctor (resume): also wired json_value() so --output-format json
returns the structured doctor report instead of None.
Continues ROADMAP #26 resumed-command JSON parity track.
159 CLI tests pass, fmt clean.
This commit is contained in:
@@ -1320,7 +1320,7 @@ pub fn validate_slash_command_input(
|
||||
"skills" | "skill" => SlashCommand::Skills {
|
||||
args: parse_skills_args(remainder.as_deref())?,
|
||||
},
|
||||
"doctor" => {
|
||||
"doctor" | "providers" => {
|
||||
validate_no_args(command, &args)?;
|
||||
SlashCommand::Doctor
|
||||
}
|
||||
|
||||
@@ -2773,7 +2773,7 @@ fn run_resume_command(
|
||||
SlashCommand::Memory => Ok(ResumeCommandOutcome {
|
||||
session: session.clone(),
|
||||
message: Some(render_memory_report()?),
|
||||
json: None,
|
||||
json: Some(render_memory_json()?),
|
||||
}),
|
||||
SlashCommand::Init => {
|
||||
let message = init_claude_md()?;
|
||||
@@ -2829,11 +2829,14 @@ fn run_resume_command(
|
||||
json: Some(handle_skills_slash_command_json(args.as_deref(), &cwd)?),
|
||||
})
|
||||
}
|
||||
SlashCommand::Doctor => Ok(ResumeCommandOutcome {
|
||||
session: session.clone(),
|
||||
message: Some(render_doctor_report()?.render()),
|
||||
json: None,
|
||||
}),
|
||||
SlashCommand::Doctor => {
|
||||
let report = render_doctor_report()?;
|
||||
Ok(ResumeCommandOutcome {
|
||||
session: session.clone(),
|
||||
message: Some(report.render()),
|
||||
json: Some(report.json_value()),
|
||||
})
|
||||
}
|
||||
SlashCommand::Stats => {
|
||||
let usage = UsageTracker::from_session(session).cumulative_usage();
|
||||
Ok(ResumeCommandOutcome {
|
||||
@@ -5421,6 +5424,28 @@ fn render_memory_report() -> Result<String, Box<dyn std::error::Error>> {
|
||||
))
|
||||
}
|
||||
|
||||
fn render_memory_json() -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||
let cwd = env::current_dir()?;
|
||||
let project_context = ProjectContext::discover(&cwd, DEFAULT_DATE)?;
|
||||
let files: Vec<_> = project_context
|
||||
.instruction_files
|
||||
.iter()
|
||||
.map(|f| {
|
||||
json!({
|
||||
"path": f.path.display().to_string(),
|
||||
"lines": f.content.lines().count(),
|
||||
"preview": f.content.lines().next().unwrap_or("").trim(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
Ok(json!({
|
||||
"kind": "memory",
|
||||
"cwd": cwd.display().to_string(),
|
||||
"instruction_files": files.len(),
|
||||
"files": files,
|
||||
}))
|
||||
}
|
||||
|
||||
fn init_claude_md() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let cwd = env::current_dir()?;
|
||||
Ok(initialize_repo(&cwd)?.render())
|
||||
|
||||
Reference in New Issue
Block a user