Preserve structured JSON parity for claw agents

`claw agents --output-format json` was still wrapping the text report,
which meant automation could not distinguish empty inventories from
populated agent definitions. Add a dedicated structured handler in the
commands crate, wire the CLI to it, and extend the contracts to cover
both empty and populated agent listings.

Constraint: Keep text-mode `claw agents` output unchanged while aligning JSON behavior with existing structured inventory handlers
Rejected: Parse the text report into JSON in the CLI layer | brittle duplication and no reusable structured handler
Confidence: high
Scope-risk: narrow
Directive: Keep inventory subcommands on dedicated structured handlers instead of serializing human-readable reports
Tested: cargo test -p commands renders_agents_reports_as_json; cargo test -p rusty-claude-cli --test output_format_contract; cargo test --workspace; cargo fmt --check; cargo clippy --workspace --all-targets -- -D warnings
Not-tested: Manual invocation of `claw agents --output-format json` outside automated tests
This commit is contained in:
Yeachan-Heo
2026-04-06 01:42:43 +00:00
parent ee92f131b0
commit ceaf9cbc23
3 changed files with 240 additions and 14 deletions

View File

@@ -31,10 +31,10 @@ use api::{
};
use commands::{
handle_agents_slash_command, handle_mcp_slash_command, handle_mcp_slash_command_json,
handle_plugins_slash_command, handle_skills_slash_command, handle_skills_slash_command_json,
render_slash_command_help, resume_supported_slash_commands, slash_command_specs,
validate_slash_command_input, SlashCommand,
handle_agents_slash_command, handle_agents_slash_command_json, handle_mcp_slash_command,
handle_mcp_slash_command_json, handle_plugins_slash_command, handle_skills_slash_command,
handle_skills_slash_command_json, render_slash_command_help, resume_supported_slash_commands,
slash_command_specs, validate_slash_command_input, SlashCommand,
};
use compat_harness::{extract_manifest, UpstreamPaths};
use init::initialize_repo;
@@ -3276,16 +3276,11 @@ impl LiveCli {
output_format: CliOutputFormat,
) -> Result<(), Box<dyn std::error::Error>> {
let cwd = env::current_dir()?;
let message = handle_agents_slash_command(args, &cwd)?;
match output_format {
CliOutputFormat::Text => println!("{message}"),
CliOutputFormat::Text => println!("{}", handle_agents_slash_command(args, &cwd)?),
CliOutputFormat::Json => println!(
"{}",
serde_json::to_string_pretty(&json!({
"kind": "agents",
"message": message,
"args": args,
}))?
serde_json::to_string_pretty(&handle_agents_slash_command_json(args, &cwd)?)?
),
}
Ok(())