mirror of
https://github.com/instructkr/claude-code.git
synced 2026-05-17 11:26:44 +00:00
fix(config): emit section and section_value in JSON output for config subcommands (#2990)
`claw config model --output-format json` and all other section subcommands (`env`, `hooks`, `plugins`) returned identical output with no section field — the section arg was parsed but discarded (_section parameter). Fix: render_config_json now: - Passes section through to handler - Looks up the section value via runtime_config.get(), converting the internal JsonValue to serde_json::Value via render()+parse - Emits `section` (string) and `section_value` (JSON value or null) in the response envelope - Returns ok:false + error for unsupported section tokens Test: config_section_json_emits_section_and_value asserts: - No section field when no section arg - section + section_value fields present for all known sections - ok:false + error for unknown section Pinpoint: ROADMAP #126
This commit is contained in:
@@ -6210,7 +6210,7 @@ fn render_config_report(section: Option<&str>) -> Result<String, Box<dyn std::er
|
||||
}
|
||||
|
||||
fn render_config_json(
|
||||
_section: Option<&str>,
|
||||
section: Option<&str>,
|
||||
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||
let cwd = env::current_dir()?;
|
||||
let loader = ConfigLoader::default_for(&cwd);
|
||||
@@ -6243,13 +6243,52 @@ fn render_config_json(
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(serde_json::json!({
|
||||
let base = serde_json::json!({
|
||||
"kind": "config",
|
||||
"cwd": cwd.display().to_string(),
|
||||
"loaded_files": loaded_paths.len(),
|
||||
"merged_keys": runtime_config.merged().len(),
|
||||
"files": files,
|
||||
}))
|
||||
});
|
||||
|
||||
if let Some(section) = section {
|
||||
let section_rendered: Option<String> = match section {
|
||||
"env" => runtime_config.get("env").map(|v| v.render()),
|
||||
"hooks" => runtime_config.get("hooks").map(|v| v.render()),
|
||||
"model" => runtime_config.get("model").map(|v| v.render()),
|
||||
"plugins" => runtime_config
|
||||
.get("plugins")
|
||||
.or_else(|| runtime_config.get("enabledPlugins"))
|
||||
.map(|v| v.render()),
|
||||
other => {
|
||||
return Ok(serde_json::json!({
|
||||
"kind": "config",
|
||||
"section": other,
|
||||
"ok": false,
|
||||
"error": format!("Unsupported config section '{other}'. Use env, hooks, model, or plugins."),
|
||||
"cwd": cwd.display().to_string(),
|
||||
"loaded_files": loaded_paths.len(),
|
||||
"files": files,
|
||||
}));
|
||||
}
|
||||
};
|
||||
// Parse the rendered JSON string back into serde_json::Value so that
|
||||
// section_value is a real JSON object/array in the envelope, not a quoted string.
|
||||
let section_value: serde_json::Value = section_rendered
|
||||
.as_deref()
|
||||
.and_then(|s| serde_json::from_str(s).ok())
|
||||
.unwrap_or(serde_json::Value::Null);
|
||||
let mut obj = base;
|
||||
let map = obj.as_object_mut().expect("base is object");
|
||||
map.insert(
|
||||
"section".to_string(),
|
||||
serde_json::Value::String(section.to_string()),
|
||||
);
|
||||
map.insert("section_value".to_string(), section_value);
|
||||
return Ok(obj);
|
||||
}
|
||||
|
||||
Ok(base)
|
||||
}
|
||||
|
||||
fn render_memory_report() -> Result<String, Box<dyn std::error::Error>> {
|
||||
|
||||
Reference in New Issue
Block a user