Skip to content

Commit 7ec6860

Browse files
committed
fix(cli): emit JSON for /config in --output-format json --resume mode
/config resumed returned json:None, falling back to prose output even in --output-format json mode. Adds render_config_json() that produces: { "kind": "config", "cwd": "...", "loaded_files": N, "merged_keys": N, "files": [{"path":"...","source":"user|project|local","loaded":true|false}, ...] } Wires it into the SlashCommand::Config resume arm alongside the existing prose render. Continues the resumed-command JSON parity track (ROADMAP #26). 159 CLI tests pass, fmt clean.
1 parent 0e12d15 commit 7ec6860

File tree

1 file changed

+52
-5
lines changed
  • rust/crates/rusty-claude-cli/src

1 file changed

+52
-5
lines changed

rust/crates/rusty-claude-cli/src/main.rs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,11 +2747,15 @@ fn run_resume_command(
27472747
json: None,
27482748
})
27492749
}
2750-
SlashCommand::Config { section } => Ok(ResumeCommandOutcome {
2751-
session: session.clone(),
2752-
message: Some(render_config_report(section.as_deref())?),
2753-
json: None,
2754-
}),
2750+
SlashCommand::Config { section } => {
2751+
let message = render_config_report(section.as_deref())?;
2752+
let json = render_config_json(section.as_deref())?;
2753+
Ok(ResumeCommandOutcome {
2754+
session: session.clone(),
2755+
message: Some(message),
2756+
json: Some(json),
2757+
})
2758+
}
27552759
SlashCommand::Mcp { action, target } => {
27562760
let cwd = env::current_dir()?;
27572761
let args = match (action.as_deref(), target.as_deref()) {
@@ -5335,6 +5339,49 @@ fn render_config_report(section: Option<&str>) -> Result<String, Box<dyn std::er
53355339
))
53365340
}
53375341

5342+
fn render_config_json(
5343+
_section: Option<&str>,
5344+
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
5345+
let cwd = env::current_dir()?;
5346+
let loader = ConfigLoader::default_for(&cwd);
5347+
let discovered = loader.discover();
5348+
let runtime_config = loader.load()?;
5349+
5350+
let loaded_paths: Vec<_> = runtime_config
5351+
.loaded_entries()
5352+
.iter()
5353+
.map(|e| e.path.display().to_string())
5354+
.collect();
5355+
5356+
let files: Vec<_> = discovered
5357+
.iter()
5358+
.map(|e| {
5359+
let source = match e.source {
5360+
ConfigSource::User => "user",
5361+
ConfigSource::Project => "project",
5362+
ConfigSource::Local => "local",
5363+
};
5364+
let loaded = runtime_config
5365+
.loaded_entries()
5366+
.iter()
5367+
.any(|le| le.path == e.path);
5368+
serde_json::json!({
5369+
"path": e.path.display().to_string(),
5370+
"source": source,
5371+
"loaded": loaded,
5372+
})
5373+
})
5374+
.collect();
5375+
5376+
Ok(serde_json::json!({
5377+
"kind": "config",
5378+
"cwd": cwd.display().to_string(),
5379+
"loaded_files": loaded_paths.len(),
5380+
"merged_keys": runtime_config.merged().len(),
5381+
"files": files,
5382+
}))
5383+
}
5384+
53385385
fn render_memory_report() -> Result<String, Box<dyn std::error::Error>> {
53395386
let cwd = env::current_dir()?;
53405387
let project_context = ProjectContext::discover(&cwd, DEFAULT_DATE)?;

0 commit comments

Comments
 (0)