mirror of
https://github.com/instructkr/claude-code.git
synced 2026-05-31 01:36:45 +00:00
Compare commits
1 Commits
bac47d91bd
...
docs/roadm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
527dd6b1ce |
@@ -6302,3 +6302,5 @@ Original filing (2026-04-18): the session emitted `SessionStart hook (completed)
|
|||||||
381. **Top-level `cache --help --output-format json` hangs with zero stdout/stderr instead of returning bounded command help JSON** — dogfooded 2026-04-30 for the 03:00 nudge on current `origin/main` / rebuilt `./rust/target/debug/claw` with embedded `git_sha` `d95b230c`. After #358 and #380 landed for the cost/tokens preflight help hangs, a fresh adjacent probe on the cache-control surface showed the same silent failure class: repeated bounded runs of `timeout --kill-after=1s 8s ./rust/target/debug/claw cache --help --output-format json` exited `124` with `stdout=0` and `stderr=0`. In the same rebuilt binary, `version --output-format json` returned promptly with version/build metadata, proving the binary itself and JSON output path are reachable. This is distinct from the separate `/cache` slash-command envelope mismatch class: the affected surface here is top-level `cache` command help, where agents need bounded local discovery before deciding whether to inspect, clear, or summarize cache state. **Required fix shape:** (a) make `cache --help --output-format json` return static/bounded stdout JSON with `kind:"help"` or `kind:"cache"`, `action:"help"`, usage, options, examples, supported output formats, and related slash/direct commands; (b) ensure help rendering does not initialize slow cache/session/provider state; (c) if any dynamic provider is consulted, return a typed JSON timeout/unavailable error instead of hanging; (d) add regression coverage proving cache help in JSON mode returns within a deterministic budget. **Why this matters:** cache inspection and cleanup are recovery/control-plane operations. If cache help hangs silently, claws cannot safely discover cache semantics before attempting cleanup, and automation stalls before it can choose a non-destructive cache action. Source: gaebal-gajae dogfood follow-up for the 03:00 nudge on rebuilt `./rust/target/debug/claw` `d95b230c`.
|
381. **Top-level `cache --help --output-format json` hangs with zero stdout/stderr instead of returning bounded command help JSON** — dogfooded 2026-04-30 for the 03:00 nudge on current `origin/main` / rebuilt `./rust/target/debug/claw` with embedded `git_sha` `d95b230c`. After #358 and #380 landed for the cost/tokens preflight help hangs, a fresh adjacent probe on the cache-control surface showed the same silent failure class: repeated bounded runs of `timeout --kill-after=1s 8s ./rust/target/debug/claw cache --help --output-format json` exited `124` with `stdout=0` and `stderr=0`. In the same rebuilt binary, `version --output-format json` returned promptly with version/build metadata, proving the binary itself and JSON output path are reachable. This is distinct from the separate `/cache` slash-command envelope mismatch class: the affected surface here is top-level `cache` command help, where agents need bounded local discovery before deciding whether to inspect, clear, or summarize cache state. **Required fix shape:** (a) make `cache --help --output-format json` return static/bounded stdout JSON with `kind:"help"` or `kind:"cache"`, `action:"help"`, usage, options, examples, supported output formats, and related slash/direct commands; (b) ensure help rendering does not initialize slow cache/session/provider state; (c) if any dynamic provider is consulted, return a typed JSON timeout/unavailable error instead of hanging; (d) add regression coverage proving cache help in JSON mode returns within a deterministic budget. **Why this matters:** cache inspection and cleanup are recovery/control-plane operations. If cache help hangs silently, claws cannot safely discover cache semantics before attempting cleanup, and automation stalls before it can choose a non-destructive cache action. Source: gaebal-gajae dogfood follow-up for the 03:00 nudge on rebuilt `./rust/target/debug/claw` `d95b230c`.
|
||||||
|
|
||||||
422. **`export --output-format json` and `--resume latest` report the same "no managed sessions" scenario using two different `kind` codes — `no_managed_sessions` vs `session_load_failed` — making "no session found" undetectable by a single kind-code check** — dogfooded 2026-04-30 KST (UTC+9) by Jobdori on `e939777f`. Running `claw export --output-format json` with no session present returns (on stderr, exit 1): `{"error":"no managed sessions found in .claw/sessions/<fingerprint>/","hint":"Start \`claw\` to create a session, then rerun with \`--resume latest\`.\nNote: claw partitions sessions per workspace fingerprint; sessions from other CWDs are invisible.","kind":"no_managed_sessions","type":"error"}`. Running `claw --resume latest /status --output-format json` with no session present returns (on stderr, exit 1): `{"error":"failed to restore session: no managed sessions found in .claw/sessions/<fingerprint>/","hint":"Start \`claw\` to create a session, then rerun with \`--resume latest\`.\nNote: claw partitions sessions per workspace fingerprint; sessions from other CWDs are invisible.","kind":"session_load_failed","type":"error"}`. Both describe the same root condition — there are no sessions to operate on — but they expose it via different `kind` discriminants. Automation that checks `kind == "no_managed_sessions"` to detect a cold workspace will miss the `--resume` path's `session_load_failed`, and vice versa. A wrapper that guards "run with --resume only if a session exists" must special-case both codes. The hint text is identical between them, suggesting the messages are logically equivalent. Additionally neither code matches the proposed canonical names `session_not_found` / `session_load_failed` as stable `ErrorKind` discriminants described in ROADMAP #77's fix shape, which explicitly proposes typed error-kind codes for session lifecycle failures. **Required fix shape:** (a) unify "no sessions found for this workspace fingerprint" under a single canonical `kind` code — either `no_managed_sessions` or `session_not_found` — used consistently by every command path that encounters an empty session registry; (b) if `session_load_failed` is a more general category (covering e.g. corrupt session files, IO errors, schema version mismatches), it should nest a concrete `reason:"no_managed_sessions"` or `reason:"session_not_found"` sub-field so callers can distinguish "empty registry" from "found but unreadable"; (c) align with the canonical error-kind contract proposed in #77; (d) add regression coverage proving `export` and `--resume latest` in an empty workspace both return an error with the same top-level `kind` code. **Why this matters:** session guard-rails in orchestration need a single stable `kind` to detect cold workspaces without enumerating all possible no-session synonyms. Two divergent codes for the same condition make defensive automation brittle and contradict the promise of machine-readable error envelopes. Source: Jobdori live dogfood, `e939777f`, 2026-04-30 KST (UTC+9).
|
422. **`export --output-format json` and `--resume latest` report the same "no managed sessions" scenario using two different `kind` codes — `no_managed_sessions` vs `session_load_failed` — making "no session found" undetectable by a single kind-code check** — dogfooded 2026-04-30 KST (UTC+9) by Jobdori on `e939777f`. Running `claw export --output-format json` with no session present returns (on stderr, exit 1): `{"error":"no managed sessions found in .claw/sessions/<fingerprint>/","hint":"Start \`claw\` to create a session, then rerun with \`--resume latest\`.\nNote: claw partitions sessions per workspace fingerprint; sessions from other CWDs are invisible.","kind":"no_managed_sessions","type":"error"}`. Running `claw --resume latest /status --output-format json` with no session present returns (on stderr, exit 1): `{"error":"failed to restore session: no managed sessions found in .claw/sessions/<fingerprint>/","hint":"Start \`claw\` to create a session, then rerun with \`--resume latest\`.\nNote: claw partitions sessions per workspace fingerprint; sessions from other CWDs are invisible.","kind":"session_load_failed","type":"error"}`. Both describe the same root condition — there are no sessions to operate on — but they expose it via different `kind` discriminants. Automation that checks `kind == "no_managed_sessions"` to detect a cold workspace will miss the `--resume` path's `session_load_failed`, and vice versa. A wrapper that guards "run with --resume only if a session exists" must special-case both codes. The hint text is identical between them, suggesting the messages are logically equivalent. Additionally neither code matches the proposed canonical names `session_not_found` / `session_load_failed` as stable `ErrorKind` discriminants described in ROADMAP #77's fix shape, which explicitly proposes typed error-kind codes for session lifecycle failures. **Required fix shape:** (a) unify "no sessions found for this workspace fingerprint" under a single canonical `kind` code — either `no_managed_sessions` or `session_not_found` — used consistently by every command path that encounters an empty session registry; (b) if `session_load_failed` is a more general category (covering e.g. corrupt session files, IO errors, schema version mismatches), it should nest a concrete `reason:"no_managed_sessions"` or `reason:"session_not_found"` sub-field so callers can distinguish "empty registry" from "found but unreadable"; (c) align with the canonical error-kind contract proposed in #77; (d) add regression coverage proving `export` and `--resume latest` in an empty workspace both return an error with the same top-level `kind` code. **Why this matters:** session guard-rails in orchestration need a single stable `kind` to detect cold workspaces without enumerating all possible no-session synonyms. Two divergent codes for the same condition make defensive automation brittle and contradict the promise of machine-readable error envelopes. Source: Jobdori live dogfood, `e939777f`, 2026-04-30 KST (UTC+9).
|
||||||
|
|
||||||
|
426. **`claw plugins --output-format json` surface has zero test coverage in `output_format_contract.rs` — the contract tests that lock every other major JSON surface (`agents`, `mcp`, `skills`, `status`, `sandbox`, `doctor`, `help`, `version`, `acp`, `bootstrap-plan`, `system-prompt`, `init`, `diff`, `config`) do not include a single assertion about `plugins`, leaving the plugin JSON shape entirely untested and free to silently drift** — dogfooded 2026-05-01 KST (UTC+9) by Jobdori on `57096b0a`. Inspection of `rust/crates/rusty-claude-cli/tests/output_format_contract.rs` (11 tests) shows coverage for every major `--output-format json` surface except `plugins`. Live binary produces `{"action":"list","kind":"plugin","message":"<prose table>","reload_runtime":false,"target":null}` for `claw plugins --output-format json`, but no test asserts (a) that `kind == "plugin"`, (b) that `action == "list"`, (c) that the payload is valid JSON at all, (d) that `reload_runtime` is present and boolean, or (e) that `target` is present and null/typed. The only plugin-related test in `mock_parity_harness.rs` covers plugin tool execution round-trip, not the CLI inspection surface. This means the `plugins list` JSON schema documented in ROADMAP #416 (mutation-shape envelope, missing `plugins:[]` array) can silently regress or change shape between commits with no CI signal. By contrast, if `agents list` drops the `agents[]` field, `inventory_commands_emit_structured_json_when_requested` catches it immediately. **Required fix shape:** (a) add a `plugins_command_emits_json_when_requested` test in `output_format_contract.rs` that: runs `claw plugins --output-format json` in an isolated temp dir, asserts stdout is valid JSON, asserts `kind == "plugin"`, asserts `action == "list"`, asserts `reload_runtime` is boolean, asserts `target` is JSON null when no plugin is targeted; (b) add a second assertion variant for `claw plugins enable <name> --output-format json` to confirm the lifecycle-mutation envelope fields are stable; (c) pair with the existing ROADMAP #416 fix so when `plugins:[]` array is added, a test assertion locks it; (d) extend to `plugins disable`, `plugins install`, and `plugins uninstall` shapes once they are implemented. **Why this matters:** test brittleness — the plugin JSON surface is the only major `--output-format json` surface with zero contract coverage. Any schema change, regression, or panic in `plugins` dispatch goes undetected until a downstream claw hits it at runtime. CI's four-check suite gives a false assurance of coverage for plugin JSON because `cargo test --workspace` passes even with zero plugin contract assertions. Source: Jobdori dogfood + test-file inspection, `57096b0a`, 2026-05-01 KST (UTC+9). Cross-reference: #416 (plugins list returns mutation shape, no plugins array).
|
||||||
|
|||||||
@@ -2371,40 +2371,6 @@ pub fn handle_skills_slash_command(args: Option<&str>, cwd: &Path) -> std::io::R
|
|||||||
let skills = load_skills_from_roots(&roots)?;
|
let skills = load_skills_from_roots(&roots)?;
|
||||||
Ok(render_skills_report(&skills))
|
Ok(render_skills_report(&skills))
|
||||||
}
|
}
|
||||||
Some(args) if args.starts_with("list ") => {
|
|
||||||
let filter = args["list ".len()..].trim().to_lowercase();
|
|
||||||
let roots = discover_skill_roots(cwd);
|
|
||||||
let skills = load_skills_from_roots(&roots)?;
|
|
||||||
let filtered: Vec<_> = skills
|
|
||||||
.into_iter()
|
|
||||||
.filter(|s| s.name.to_lowercase().contains(&filter))
|
|
||||||
.collect();
|
|
||||||
Ok(render_skills_report(&filtered))
|
|
||||||
}
|
|
||||||
Some("show" | "info" | "describe") => {
|
|
||||||
let roots = discover_skill_roots(cwd);
|
|
||||||
let skills = load_skills_from_roots(&roots)?;
|
|
||||||
Ok(render_skills_report(&skills))
|
|
||||||
}
|
|
||||||
Some(args)
|
|
||||||
if args.starts_with("show ")
|
|
||||||
|| args.starts_with("info ")
|
|
||||||
|| args.starts_with("describe ") =>
|
|
||||||
{
|
|
||||||
let name = args
|
|
||||||
.splitn(2, ' ')
|
|
||||||
.nth(1)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.trim()
|
|
||||||
.to_lowercase();
|
|
||||||
let roots = discover_skill_roots(cwd);
|
|
||||||
let skills = load_skills_from_roots(&roots)?;
|
|
||||||
let matched: Vec<_> = skills
|
|
||||||
.into_iter()
|
|
||||||
.filter(|s| s.name.to_lowercase() == name)
|
|
||||||
.collect();
|
|
||||||
Ok(render_skills_report(&matched))
|
|
||||||
}
|
|
||||||
Some("install") => Ok(render_skills_usage(Some("install"))),
|
Some("install") => Ok(render_skills_usage(Some("install"))),
|
||||||
Some(args) if args.starts_with("install ") => {
|
Some(args) if args.starts_with("install ") => {
|
||||||
let target = args["install ".len()..].trim();
|
let target = args["install ".len()..].trim();
|
||||||
@@ -2436,40 +2402,6 @@ pub fn handle_skills_slash_command_json(args: Option<&str>, cwd: &Path) -> std::
|
|||||||
let skills = load_skills_from_roots(&roots)?;
|
let skills = load_skills_from_roots(&roots)?;
|
||||||
Ok(render_skills_report_json(&skills))
|
Ok(render_skills_report_json(&skills))
|
||||||
}
|
}
|
||||||
Some(args) if args.starts_with("list ") => {
|
|
||||||
let filter = args["list ".len()..].trim().to_lowercase();
|
|
||||||
let roots = discover_skill_roots(cwd);
|
|
||||||
let skills = load_skills_from_roots(&roots)?;
|
|
||||||
let filtered: Vec<_> = skills
|
|
||||||
.into_iter()
|
|
||||||
.filter(|s| s.name.to_lowercase().contains(&filter))
|
|
||||||
.collect();
|
|
||||||
Ok(render_skills_report_json(&filtered))
|
|
||||||
}
|
|
||||||
Some("show" | "info" | "describe") => {
|
|
||||||
let roots = discover_skill_roots(cwd);
|
|
||||||
let skills = load_skills_from_roots(&roots)?;
|
|
||||||
Ok(render_skills_report_json(&skills))
|
|
||||||
}
|
|
||||||
Some(args)
|
|
||||||
if args.starts_with("show ")
|
|
||||||
|| args.starts_with("info ")
|
|
||||||
|| args.starts_with("describe ") =>
|
|
||||||
{
|
|
||||||
let name = args
|
|
||||||
.splitn(2, ' ')
|
|
||||||
.nth(1)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.trim()
|
|
||||||
.to_lowercase();
|
|
||||||
let roots = discover_skill_roots(cwd);
|
|
||||||
let skills = load_skills_from_roots(&roots)?;
|
|
||||||
let matched: Vec<_> = skills
|
|
||||||
.into_iter()
|
|
||||||
.filter(|s| s.name.to_lowercase() == name)
|
|
||||||
.collect();
|
|
||||||
Ok(render_skills_report_json(&matched))
|
|
||||||
}
|
|
||||||
Some("install") => Ok(render_skills_usage_json(Some("install"))),
|
Some("install") => Ok(render_skills_usage_json(Some("install"))),
|
||||||
Some(args) if args.starts_with("install ") => {
|
Some(args) if args.starts_with("install ") => {
|
||||||
let target = args["install ".len()..].trim();
|
let target = args["install ".len()..].trim();
|
||||||
@@ -2487,20 +2419,10 @@ pub fn handle_skills_slash_command_json(args: Option<&str>, cwd: &Path) -> std::
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn classify_skills_slash_command(args: Option<&str>) -> SkillSlashDispatch {
|
pub fn classify_skills_slash_command(args: Option<&str>) -> SkillSlashDispatch {
|
||||||
match normalize_optional_args(args) {
|
match normalize_optional_args(args) {
|
||||||
None | Some("list" | "help" | "-h" | "--help" | "show" | "info" | "describe") => {
|
None | Some("list" | "help" | "-h" | "--help") => SkillSlashDispatch::Local,
|
||||||
SkillSlashDispatch::Local
|
|
||||||
}
|
|
||||||
Some(args) if args == "install" || args.starts_with("install ") => {
|
Some(args) if args == "install" || args.starts_with("install ") => {
|
||||||
SkillSlashDispatch::Local
|
SkillSlashDispatch::Local
|
||||||
}
|
}
|
||||||
Some(args)
|
|
||||||
if args.starts_with("list ")
|
|
||||||
|| args.starts_with("show ")
|
|
||||||
|| args.starts_with("info ")
|
|
||||||
|| args.starts_with("describe ") =>
|
|
||||||
{
|
|
||||||
SkillSlashDispatch::Local
|
|
||||||
}
|
|
||||||
Some(args) => SkillSlashDispatch::Invoke(format!("${}", args.trim_start_matches('/'))),
|
Some(args) => SkillSlashDispatch::Invoke(format!("${}", args.trim_start_matches('/'))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4697,32 +4619,6 @@ mod tests {
|
|||||||
assert!(agents_error.contains(" Usage /agents [list|help]"));
|
assert!(agents_error.contains(" Usage /agents [list|help]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn skills_show_and_list_filter_do_not_invoke_model() {
|
|
||||||
// `show`, `info`, `list <filter>` must route to Local, not Invoke.
|
|
||||||
// Regression for: `claw skills show plan` unexpectedly spawned a model session.
|
|
||||||
for token in &["show", "info", "describe"] {
|
|
||||||
assert_eq!(
|
|
||||||
classify_skills_slash_command(Some(token)),
|
|
||||||
SkillSlashDispatch::Local,
|
|
||||||
"`skills {token}` alone must be Local"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for prefix in &["show ", "info ", "list ", "describe "] {
|
|
||||||
let arg = format!("{prefix}plan");
|
|
||||||
assert_eq!(
|
|
||||||
classify_skills_slash_command(Some(&arg)),
|
|
||||||
SkillSlashDispatch::Local,
|
|
||||||
"`skills {arg}` must be Local, not Invoke"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Bare invocable tokens still dispatch to Invoke.
|
|
||||||
assert_eq!(
|
|
||||||
classify_skills_slash_command(Some("plan")),
|
|
||||||
SkillSlashDispatch::Invoke("$plan".to_string()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn accepts_skills_invocation_arguments_for_prompt_dispatch() {
|
fn accepts_skills_invocation_arguments_for_prompt_dispatch() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
@@ -2627,15 +2627,12 @@ fn print_version(output_format: CliOutputFormat) -> Result<(), Box<dyn std::erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn version_json_value() -> serde_json::Value {
|
fn version_json_value() -> serde_json::Value {
|
||||||
let executable_path = env::current_exe().ok().map(|p| p.display().to_string());
|
|
||||||
json!({
|
json!({
|
||||||
"kind": "version",
|
"kind": "version",
|
||||||
"message": render_version_report(),
|
"message": render_version_report(),
|
||||||
"version": VERSION,
|
"version": VERSION,
|
||||||
"git_sha": GIT_SHA,
|
"git_sha": GIT_SHA,
|
||||||
"target": BUILD_TARGET,
|
"target": BUILD_TARGET,
|
||||||
"build_date": DEFAULT_DATE,
|
|
||||||
"executable_path": executable_path,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3526,10 +3523,10 @@ fn run_resume_command(
|
|||||||
Ok(ResumeCommandOutcome {
|
Ok(ResumeCommandOutcome {
|
||||||
session: session.clone(),
|
session: session.clone(),
|
||||||
message: Some(handle_agents_slash_command(args.as_deref(), &cwd)?),
|
message: Some(handle_agents_slash_command(args.as_deref(), &cwd)?),
|
||||||
json: Some(
|
json: Some(serde_json::json!({
|
||||||
serde_json::to_value(handle_agents_slash_command_json(args.as_deref(), &cwd)?)
|
"kind": "agents",
|
||||||
.unwrap_or_else(|_| serde_json::json!(null)),
|
"text": handle_agents_slash_command(args.as_deref(), &cwd)?,
|
||||||
),
|
})),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
SlashCommand::Skills { args } => {
|
SlashCommand::Skills { args } => {
|
||||||
@@ -3545,37 +3542,6 @@ fn run_resume_command(
|
|||||||
json: Some(handle_skills_slash_command_json(args.as_deref(), &cwd)?),
|
json: Some(handle_skills_slash_command_json(args.as_deref(), &cwd)?),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
SlashCommand::Plugins { action, target } => {
|
|
||||||
// Only list is supported in resume mode (no runtime to reload)
|
|
||||||
match action.as_deref() {
|
|
||||||
Some("install") | Some("uninstall") | Some("enable") | Some("disable")
|
|
||||||
| Some("update") => {
|
|
||||||
return Err(
|
|
||||||
"resumed /plugins mutations are interactive-only; start `claw` and run `/plugins` in the REPL".into(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
let cwd = env::current_dir()?;
|
|
||||||
let loader = ConfigLoader::default_for(&cwd);
|
|
||||||
let runtime_config = loader.load()?;
|
|
||||||
let mut manager = build_plugin_manager(&cwd, &loader, &runtime_config);
|
|
||||||
let result =
|
|
||||||
handle_plugins_slash_command(action.as_deref(), target.as_deref(), &mut manager)?;
|
|
||||||
let action_str = action.as_deref().unwrap_or("list");
|
|
||||||
let json = serde_json::json!({
|
|
||||||
"kind": "plugin",
|
|
||||||
"action": action_str,
|
|
||||||
"target": target,
|
|
||||||
"message": &result.message,
|
|
||||||
"reload_runtime": result.reload_runtime,
|
|
||||||
});
|
|
||||||
Ok(ResumeCommandOutcome {
|
|
||||||
session: session.clone(),
|
|
||||||
message: Some(result.message),
|
|
||||||
json: Some(json),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
SlashCommand::Doctor => {
|
SlashCommand::Doctor => {
|
||||||
let report = render_doctor_report()?;
|
let report = render_doctor_report()?;
|
||||||
Ok(ResumeCommandOutcome {
|
Ok(ResumeCommandOutcome {
|
||||||
@@ -3662,6 +3628,7 @@ fn run_resume_command(
|
|||||||
| SlashCommand::Model { .. }
|
| SlashCommand::Model { .. }
|
||||||
| SlashCommand::Permissions { .. }
|
| SlashCommand::Permissions { .. }
|
||||||
| SlashCommand::Session { .. }
|
| SlashCommand::Session { .. }
|
||||||
|
| SlashCommand::Plugins { .. }
|
||||||
| SlashCommand::Login
|
| SlashCommand::Login
|
||||||
| SlashCommand::Logout
|
| SlashCommand::Logout
|
||||||
| SlashCommand::Vim
|
| SlashCommand::Vim
|
||||||
@@ -6240,7 +6207,7 @@ fn render_config_report(section: Option<&str>) -> Result<String, Box<dyn std::er
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_config_json(
|
fn render_config_json(
|
||||||
section: Option<&str>,
|
_section: Option<&str>,
|
||||||
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||||
let cwd = env::current_dir()?;
|
let cwd = env::current_dir()?;
|
||||||
let loader = ConfigLoader::default_for(&cwd);
|
let loader = ConfigLoader::default_for(&cwd);
|
||||||
@@ -6273,52 +6240,13 @@ fn render_config_json(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let base = serde_json::json!({
|
Ok(serde_json::json!({
|
||||||
"kind": "config",
|
"kind": "config",
|
||||||
"cwd": cwd.display().to_string(),
|
"cwd": cwd.display().to_string(),
|
||||||
"loaded_files": loaded_paths.len(),
|
"loaded_files": loaded_paths.len(),
|
||||||
"merged_keys": runtime_config.merged().len(),
|
"merged_keys": runtime_config.merged().len(),
|
||||||
"files": files,
|
"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>> {
|
fn render_memory_report() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
|||||||
@@ -30,15 +30,6 @@ fn version_emits_json_when_requested() {
|
|||||||
let parsed = assert_json_command(&root, &["--output-format", "json", "version"]);
|
let parsed = assert_json_command(&root, &["--output-format", "json", "version"]);
|
||||||
assert_eq!(parsed["kind"], "version");
|
assert_eq!(parsed["kind"], "version");
|
||||||
assert_eq!(parsed["version"], env!("CARGO_PKG_VERSION"));
|
assert_eq!(parsed["version"], env!("CARGO_PKG_VERSION"));
|
||||||
// Provenance fields must be present for binary identification (#507).
|
|
||||||
assert!(
|
|
||||||
parsed["build_date"].is_string(),
|
|
||||||
"build_date must be a string in version JSON"
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
parsed["executable_path"].is_string(),
|
|
||||||
"executable_path must be a string in version JSON so callers can identify which binary is running"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -114,18 +105,6 @@ fn inventory_commands_emit_structured_json_when_requested() {
|
|||||||
let skills = assert_json_command(&root, &["--output-format", "json", "skills"]);
|
let skills = assert_json_command(&root, &["--output-format", "json", "skills"]);
|
||||||
assert_eq!(skills["kind"], "skills");
|
assert_eq!(skills["kind"], "skills");
|
||||||
assert_eq!(skills["action"], "list");
|
assert_eq!(skills["action"], "list");
|
||||||
|
|
||||||
let plugins = assert_json_command(&root, &["--output-format", "json", "plugins"]);
|
|
||||||
assert_eq!(plugins["kind"], "plugin");
|
|
||||||
assert_eq!(plugins["action"], "list");
|
|
||||||
assert!(
|
|
||||||
plugins["reload_runtime"].is_boolean(),
|
|
||||||
"plugins reload_runtime should be a boolean"
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
plugins["target"].is_null(),
|
|
||||||
"plugins target should be null when no plugin is targeted"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -369,62 +348,6 @@ fn resumed_inventory_commands_emit_structured_json_when_requested() {
|
|||||||
assert_eq!(skills["action"], "list");
|
assert_eq!(skills["action"], "list");
|
||||||
assert!(skills["summary"]["total"].is_number());
|
assert!(skills["summary"]["total"].is_number());
|
||||||
assert!(skills["skills"].is_array());
|
assert!(skills["skills"].is_array());
|
||||||
|
|
||||||
let agents = assert_json_command_with_env(
|
|
||||||
&root,
|
|
||||||
&[
|
|
||||||
"--output-format",
|
|
||||||
"json",
|
|
||||||
"--resume",
|
|
||||||
session_path.to_str().expect("utf8 session path"),
|
|
||||||
"/agents",
|
|
||||||
],
|
|
||||||
&[
|
|
||||||
(
|
|
||||||
"CLAW_CONFIG_HOME",
|
|
||||||
config_home.to_str().expect("utf8 config home"),
|
|
||||||
),
|
|
||||||
("HOME", home.to_str().expect("utf8 home")),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
assert_eq!(agents["kind"], "agents");
|
|
||||||
assert_eq!(agents["action"], "list");
|
|
||||||
assert!(
|
|
||||||
agents["agents"].is_array(),
|
|
||||||
"agents field must be a JSON array"
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
agents["count"].is_number(),
|
|
||||||
"count must be a number, not a text render"
|
|
||||||
);
|
|
||||||
|
|
||||||
let plugins = assert_json_command_with_env(
|
|
||||||
&root,
|
|
||||||
&[
|
|
||||||
"--output-format",
|
|
||||||
"json",
|
|
||||||
"--resume",
|
|
||||||
session_path.to_str().expect("utf8 session path"),
|
|
||||||
"/plugins",
|
|
||||||
],
|
|
||||||
&[
|
|
||||||
(
|
|
||||||
"CLAW_CONFIG_HOME",
|
|
||||||
config_home.to_str().expect("utf8 config home"),
|
|
||||||
),
|
|
||||||
("HOME", home.to_str().expect("utf8 home")),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
assert_eq!(plugins["kind"], "plugin");
|
|
||||||
assert_eq!(plugins["action"], "list");
|
|
||||||
assert!(
|
|
||||||
plugins["reload_runtime"].is_boolean(),
|
|
||||||
"plugins reload_runtime should be a boolean"
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
plugins["target"].is_null(),
|
|
||||||
"plugins target should be null when no plugin is targeted"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -461,44 +384,6 @@ fn resumed_version_and_init_emit_structured_json_when_requested() {
|
|||||||
assert!(root.join("CLAUDE.md").exists());
|
assert!(root.join("CLAUDE.md").exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn config_section_json_emits_section_and_value() {
|
|
||||||
let root = unique_temp_dir("config-section-json");
|
|
||||||
fs::create_dir_all(&root).expect("temp dir should exist");
|
|
||||||
|
|
||||||
// Without a section: should return base envelope (no section field).
|
|
||||||
let base = assert_json_command(&root, &["--output-format", "json", "config"]);
|
|
||||||
assert_eq!(base["kind"], "config");
|
|
||||||
assert!(base["loaded_files"].is_number());
|
|
||||||
assert!(base["merged_keys"].is_number());
|
|
||||||
assert!(
|
|
||||||
base.get("section").is_none(),
|
|
||||||
"no section field without section arg"
|
|
||||||
);
|
|
||||||
|
|
||||||
// With a known section: should add section + section_value fields.
|
|
||||||
for section in &["model", "env", "hooks", "plugins"] {
|
|
||||||
let result = assert_json_command(&root, &["--output-format", "json", "config", section]);
|
|
||||||
assert_eq!(result["kind"], "config", "section={section}");
|
|
||||||
assert_eq!(
|
|
||||||
result["section"].as_str(),
|
|
||||||
Some(*section),
|
|
||||||
"section field must match requested section, got {result:?}"
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
result.get("section_value").is_some(),
|
|
||||||
"section_value field must be present for section={section}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// With an unsupported section: should return ok:false + error field.
|
|
||||||
let bad = assert_json_command(&root, &["--output-format", "json", "config", "unknown"]);
|
|
||||||
assert_eq!(bad["kind"], "config");
|
|
||||||
assert_eq!(bad["ok"], false);
|
|
||||||
assert!(bad["error"].as_str().is_some());
|
|
||||||
assert!(bad["section"].as_str().is_some());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn assert_json_command(current_dir: &Path, args: &[&str]) -> Value {
|
fn assert_json_command(current_dir: &Path, args: &[&str]) -> Value {
|
||||||
assert_json_command_with_env(current_dir, args, &[])
|
assert_json_command_with_env(current_dir, args, &[])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,8 +227,6 @@ fn resumed_status_command_emits_structured_json_when_requested() {
|
|||||||
// given
|
// given
|
||||||
let temp_dir = unique_temp_dir("resume-status-json");
|
let temp_dir = unique_temp_dir("resume-status-json");
|
||||||
fs::create_dir_all(&temp_dir).expect("temp dir should exist");
|
fs::create_dir_all(&temp_dir).expect("temp dir should exist");
|
||||||
let config_home = temp_dir.join("config-home");
|
|
||||||
fs::create_dir_all(&config_home).expect("isolated config home should exist");
|
|
||||||
let session_path = temp_dir.join("session.jsonl");
|
let session_path = temp_dir.join("session.jsonl");
|
||||||
|
|
||||||
let mut session = workspace_session(&temp_dir);
|
let mut session = workspace_session(&temp_dir);
|
||||||
@@ -240,9 +238,7 @@ fn resumed_status_command_emits_structured_json_when_requested() {
|
|||||||
.expect("session should persist");
|
.expect("session should persist");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
// Use an isolated CLAW_CONFIG_HOME so ~/.claw/settings.json is not loaded,
|
let output = run_claw(
|
||||||
// which would cause loaded_config_files to be non-zero (#65).
|
|
||||||
let output = run_claw_with_env(
|
|
||||||
&temp_dir,
|
&temp_dir,
|
||||||
&[
|
&[
|
||||||
"--output-format",
|
"--output-format",
|
||||||
@@ -251,7 +247,6 @@ fn resumed_status_command_emits_structured_json_when_requested() {
|
|||||||
session_path.to_str().expect("utf8 path"),
|
session_path.to_str().expect("utf8 path"),
|
||||||
"/status",
|
"/status",
|
||||||
],
|
],
|
||||||
&[("CLAW_CONFIG_HOME", config_home.to_str().expect("utf8 path"))],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
|
|||||||
Reference in New Issue
Block a user