mirror of
https://github.com/ultraworkers/claw-code.git
synced 2026-05-30 11:45:20 +08:00
fix(#703): plugins list JSON now has summary:{total,enabled,disabled,load_failures}; drop reload_runtime/target from list response in both top-level and resume paths
This commit is contained in:
parent
1555785294
commit
1a6f54b970
@ -4220,17 +4220,31 @@ fn run_resume_command(
|
|||||||
let cwd = env::current_dir()?;
|
let cwd = env::current_dir()?;
|
||||||
let payload = plugins_command_payload_for(&cwd, action.as_deref(), target.as_deref())?;
|
let payload = plugins_command_payload_for(&cwd, action.as_deref(), target.as_deref())?;
|
||||||
let action_str = action.as_deref().unwrap_or("list");
|
let action_str = action.as_deref().unwrap_or("list");
|
||||||
let json = serde_json::json!({
|
let enabled_count = payload
|
||||||
|
.plugins
|
||||||
|
.iter()
|
||||||
|
.filter(|p| p.get("enabled").and_then(|v| v.as_bool()).unwrap_or(false))
|
||||||
|
.count();
|
||||||
|
let disabled_count = payload.plugins.len().saturating_sub(enabled_count);
|
||||||
|
let mut json = serde_json::json!({
|
||||||
"kind": "plugin",
|
"kind": "plugin",
|
||||||
"action": action_str,
|
"action": action_str,
|
||||||
"target": target,
|
|
||||||
"status": payload.status,
|
"status": payload.status,
|
||||||
|
"summary": {
|
||||||
|
"total": payload.plugins.len(),
|
||||||
|
"enabled": enabled_count,
|
||||||
|
"disabled": disabled_count,
|
||||||
|
"load_failures": payload.load_failures.len(),
|
||||||
|
},
|
||||||
"config_load_error": payload.config_load_error,
|
"config_load_error": payload.config_load_error,
|
||||||
"message": &payload.message,
|
|
||||||
"reload_runtime": payload.reload_runtime,
|
|
||||||
"plugins": payload.plugins,
|
"plugins": payload.plugins,
|
||||||
"load_failures": payload.load_failures,
|
"load_failures": payload.load_failures,
|
||||||
});
|
});
|
||||||
|
if action_str != "list" {
|
||||||
|
json["target"] = serde_json::json!(target);
|
||||||
|
json["reload_runtime"] = serde_json::json!(payload.reload_runtime);
|
||||||
|
json["message"] = serde_json::json!(&payload.message);
|
||||||
|
}
|
||||||
Ok(ResumeCommandOutcome {
|
Ok(ResumeCommandOutcome {
|
||||||
session: session.clone(),
|
session: session.clone(),
|
||||||
message: Some(payload.message),
|
message: Some(payload.message),
|
||||||
@ -5936,20 +5950,36 @@ impl LiveCli {
|
|||||||
let payload = plugins_command_payload_for(&cwd, action, target)?;
|
let payload = plugins_command_payload_for(&cwd, action, target)?;
|
||||||
match output_format {
|
match output_format {
|
||||||
CliOutputFormat::Text => println!("{}", payload.message),
|
CliOutputFormat::Text => println!("{}", payload.message),
|
||||||
CliOutputFormat::Json => println!(
|
CliOutputFormat::Json => {
|
||||||
"{}",
|
let action_str = action.unwrap_or("list");
|
||||||
serde_json::to_string_pretty(&json!({
|
let enabled_count = payload
|
||||||
|
.plugins
|
||||||
|
.iter()
|
||||||
|
.filter(|p| p.get("enabled").and_then(|v| v.as_bool()).unwrap_or(false))
|
||||||
|
.count();
|
||||||
|
let disabled_count = payload.plugins.len().saturating_sub(enabled_count);
|
||||||
|
let mut obj = json!({
|
||||||
"kind": "plugin",
|
"kind": "plugin",
|
||||||
"action": action.unwrap_or("list"),
|
"action": action_str,
|
||||||
"target": target,
|
|
||||||
"status": payload.status,
|
"status": payload.status,
|
||||||
|
"summary": {
|
||||||
|
"total": payload.plugins.len(),
|
||||||
|
"enabled": enabled_count,
|
||||||
|
"disabled": disabled_count,
|
||||||
|
"load_failures": payload.load_failures.len(),
|
||||||
|
},
|
||||||
"config_load_error": payload.config_load_error,
|
"config_load_error": payload.config_load_error,
|
||||||
"message": payload.message,
|
|
||||||
"reload_runtime": payload.reload_runtime,
|
|
||||||
"plugins": payload.plugins,
|
"plugins": payload.plugins,
|
||||||
"load_failures": payload.load_failures,
|
"load_failures": payload.load_failures,
|
||||||
}))?
|
});
|
||||||
),
|
// Only include operation-result fields for mutating actions
|
||||||
|
if action_str != "list" {
|
||||||
|
obj["target"] = json!(target);
|
||||||
|
obj["reload_runtime"] = json!(payload.reload_runtime);
|
||||||
|
obj["message"] = json!(payload.message);
|
||||||
|
}
|
||||||
|
println!("{}", serde_json::to_string_pretty(&obj)?);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -202,13 +202,31 @@ fn inventory_commands_emit_structured_json_when_requested() {
|
|||||||
assert_eq!(plugins["action"], "list");
|
assert_eq!(plugins["action"], "list");
|
||||||
assert_eq!(plugins["status"], "ok");
|
assert_eq!(plugins["status"], "ok");
|
||||||
assert!(plugins["config_load_error"].is_null());
|
assert!(plugins["config_load_error"].is_null());
|
||||||
|
// reload_runtime and target are operation-result fields; list response omits them (#703)
|
||||||
assert!(
|
assert!(
|
||||||
plugins["reload_runtime"].is_boolean(),
|
!plugins
|
||||||
"plugins reload_runtime should be a boolean"
|
.as_object()
|
||||||
|
.map_or(false, |o| o.contains_key("reload_runtime")),
|
||||||
|
"plugins list should not include reload_runtime"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
plugins["target"].is_null(),
|
!plugins
|
||||||
"plugins target should be null when no plugin is targeted"
|
.as_object()
|
||||||
|
.map_or(false, |o| o.contains_key("target")),
|
||||||
|
"plugins list should not include target"
|
||||||
|
);
|
||||||
|
// #703: structured summary replaces prose message
|
||||||
|
assert!(
|
||||||
|
plugins["summary"]["total"].is_number(),
|
||||||
|
"plugins list should have summary.total"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
plugins["summary"]["enabled"].is_number(),
|
||||||
|
"plugins list should have summary.enabled"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
plugins["summary"]["disabled"].is_number(),
|
||||||
|
"plugins list should have summary.disabled"
|
||||||
);
|
);
|
||||||
assert_eq!(plugins["status"], "ok");
|
assert_eq!(plugins["status"], "ok");
|
||||||
let plugin_entries = plugins["plugins"].as_array().expect("plugins array");
|
let plugin_entries = plugins["plugins"].as_array().expect("plugins array");
|
||||||
@ -691,13 +709,22 @@ fn resumed_inventory_commands_emit_structured_json_when_requested() {
|
|||||||
assert_eq!(plugins["action"], "list");
|
assert_eq!(plugins["action"], "list");
|
||||||
assert_eq!(plugins["status"], "ok");
|
assert_eq!(plugins["status"], "ok");
|
||||||
assert!(plugins["config_load_error"].is_null());
|
assert!(plugins["config_load_error"].is_null());
|
||||||
|
// reload_runtime and target are operation-result fields; list response omits them (#703)
|
||||||
assert!(
|
assert!(
|
||||||
plugins["reload_runtime"].is_boolean(),
|
!plugins
|
||||||
"plugins reload_runtime should be a boolean"
|
.as_object()
|
||||||
|
.map_or(false, |o| o.contains_key("reload_runtime")),
|
||||||
|
"plugins list should not include reload_runtime"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
plugins["target"].is_null(),
|
!plugins
|
||||||
"plugins target should be null when no plugin is targeted"
|
.as_object()
|
||||||
|
.map_or(false, |o| o.contains_key("target")),
|
||||||
|
"plugins list should not include target"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
plugins["summary"]["total"].is_number(),
|
||||||
|
"plugins list should have summary.total"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user