diff --git a/ROADMAP.md b/ROADMAP.md index 22c751eb..74b49b46 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -6471,9 +6471,9 @@ Original filing (2026-04-18): the session emitted `SessionStart hook (completed) 453. **`bare_slash_command_guidance` (the "is a slash command" guard) only fires for `command_name` matched as a single bare token at `rust/crates/rusty-claude-cli/src/main.rs:1100-1149` — as soon as ANY positional argument follows a slash-command-named first token, the parser falls through to `CliAction::Prompt` and ships the entire argv string to Claude as a user prompt. The guard catches `claw cost`, `claw tokens`, `claw model`, `claw permissions`, `claw context`, `claw providers`, `claw history`, `claw release-notes`, `claw review`, `claw compact`, `claw cache` — but misses `claw cost list`, `claw tokens list`, `claw model openai/gpt-4`, `claw model list`, `claw permissions show`, `claw context show`, `claw providers list`, `claw history list`, `claw cache list`. Same pattern bites unrouted command shapes: `claw aliases`, `claw aliases list`, `claw profiles list`, `claw logs`, `claw settings` all fall through, even though they are obvious CLI discovery spellings** — dogfooded 2026-05-24 for the 06:00 Clawhip pinpoint nudge at message `1507986539538419863`, reproduced on local `./rust/target/debug/claw` `git_sha 003b739d` (origin/main `f8e1bb72`; the guard logic in `bare_slash_command_guidance` was last touched by the `#146` `config`/`diff` carve-out and is unchanged in `63ce483c..f8e1bb72` which are docs-only ROADMAP additions). Repros in a fully clean isolated environment (`HOME=/tmp/iso3/home` with `{}` settings, fresh `/tmp/iso3/proj` git-init'd workspace, `stdin=/dev/null`, `ANTHROPIC_*` env vars unset): bare `claw cost ` confusion (`claw model openai/gpt-4`) which is an extremely natural typo given the existing `claw --model openai/gpt-4 prompt …` flag shape. **Why this is distinct from existing items:** #78/#145 covered `claw plugins` only; #452 covered `claw models*` only. #357 / #322 cover JSON envelope/stderr-prefix issues, not argv classification. The guard surface lives in `parse_subcommand` and `bare_slash_command_guidance` (`rust/crates/rusty-claude-cli/src/main.rs:1100-1149`) — no existing ROADMAP entry tracks the shape-blindness regression class across the guard. **Why it matters:** prompt misdelivery is the Clawhip top-of-list category. With credentials set, every operator/claw typo in this cluster burns provider tokens on a meaningless completion (e.g., sending `"cost list"` to Claude). Without credentials, the wrong-shaped `missing_credentials` envelope is even more confusing — operators see `missing Anthropic credentials` when they meant local cost inspection, and assume an auth bug rather than a CLI dispatch bug. The fix is also extremely localized: it lives in a single guard function. **Required fix shape:** (a) widen `bare_slash_command_guidance` to also fire from the subcommand-args parse arm: when the first positional token matches a known slash-command name and any additional args follow, emit a typed guard error (`"`claw cost list` is a slash command — `claw cost` does not accept extra arguments; use `claw --resume SESSION.jsonl /cost` instead"`) before falling through to `CliAction::Prompt`; (b) extend the guard's known-slash-command set to include the natural CLI discovery spellings that currently fall through entirely (`models`, `model`, `aliases`, `profiles`, `providers list`, `logs`, `settings`), even when there is no corresponding slash command — emit a typed `"unknown CLI subcommand"` error with `did_you_mean` suggestions (`--model prompt …`, `/models`, `/providers`, `claw config plugins list`) rather than dispatching to LLM prompt; (c) add a structured `kind:"argv_misroute_prevented"` JSON envelope so automation can distinguish guard rejection from auth failure; (d) add regression coverage in `parses_*` test family covering at least one extra-arg case per existing slash-command guard (`cost list`, `tokens list`, `model list`, `model openai/gpt-4`, `permissions show`, `context show`, `cache list`) plus the unrouted-noun cluster (`models list`, `aliases`, `profiles list`, `logs`), asserting every spelling resolves to a typed guard error and **never** to `CliAction::Prompt`. **Acceptance check (one-liner):** `env -u ANTHROPIC_API_KEY -u ANTHROPIC_AUTH_TOKEN claw model openai/gpt-4` should NOT exit with `missing_credentials`; it should exit with a typed CLI dispatch error mentioning `--model openai/gpt-4 prompt …` or `/model`. Source: gaebal-gajae dogfood follow-up for the 2026-05-24 06:00 Clawhip pinpoint nudge at message `1507986539538419863`. -454. **`claw ls` is caught as a typo with `Did you mean skills` because `"skills".contains("ls") == true`, but the obvious sibling `claw list` falls through to `CliAction::Prompt` and gets shipped to Claude as a user prompt — `suggest_similar_subcommand` at `rust/crates/rusty-claude-cli/src/main.rs:1324-1364` has a 17-entry `KNOWN_SUBCOMMANDS` list, and `list` has Levenshtein distance ≥ 3 from every entry, prefix-match < 4 with every entry, and no substring overlap with any entry, so it returns `None` and the typo-guard arm at `:983-994` is skipped entirely** — dogfooded 2026-05-24 for the 06:30 Clawhip pinpoint nudge at message `1507994083769974825`, reproduced on local `./rust/target/debug/claw` `git_sha 003b739d` (origin/main `f8e1bb72`; the `suggest_similar_subcommand` body is unchanged in `63ce483c..f8e1bb72` which are docs-only ROADMAP additions). Repros in a fully clean isolated environment (`HOME=/tmp/iso4/home` with `{}` settings, fresh `/tmp/iso4/proj` git-init'd workspace, `stdin=/dev/null`, `ANTHROPIC_*` env vars unset): `claw ls prompt …` / `/models` once #452 lands, `run`/`exec`→`prompt`, `ask`/`chat`→`prompt`/REPL); (b) keep `looks_like_subcommand_typo` permissive (alphabetic + dash), but for the extended set, attach explicit did-you-mean targets instead of relying on Levenshtein/prefix/substring heuristics that produce coincidental matches like `ls`→`skills`; (c) emit a structured `kind:"unknown_subcommand"` JSON envelope with `input`, `suggestions[]`, and a `prompt_dispatch_blocked:true` flag so automation can distinguish guard rejection from auth failure (mirrors the #453 `argv_misroute_prevented` shape); (d) add regression coverage in `parses_*` test family covering at least `list`, `run`, `exec`, `ask`, `chat`, `models`, `providers`, `profiles`, `aliases`, `logs`, `settings`, asserting every spelling resolves to a typed typo/unknown-subcommand error and **never** to `CliAction::Prompt`. **Acceptance check (one-liner):** `env -u ANTHROPIC_API_KEY -u ANTHROPIC_AUTH_TOKEN claw list` should NOT exit with `missing_credentials`; it should exit with a typed `unknown subcommand: list` error with `Did you mean skills list / mcp list / agents list?`. Source: gaebal-gajae dogfood follow-up for the 2026-05-24 06:30 Clawhip pinpoint nudge at message `1507994083769974825`. +454. **DONE — `claw list` now caught by typo suggestion** — fixed 2026-06-04 in `fix: add list to KNOWN_SUBCOMMANDS for typo detection`. Added `"list"` to the `KNOWN_SUBCOMMANDS` array in `suggest_similar_subcommand` so `claw list` is caught and suggests similar commands instead of falling through to `CliAction::Prompt`. -455. **`missing_credentials` JSON envelope serializes the provider-detection hint as a literal ` — hint: …` prose suffix appended to the `error` field, while the structured `hint` field always renders as `null` — automation that wants to read the adjacent-provider hint must regex the `error` prose string instead of reading `hint`** — dogfooded 2026-05-24 for the 07:00 Clawhip pinpoint nudge at message `1508001633416777778`, reproduced on local `./rust/target/debug/claw` `git_sha 003b739d` (origin/main `f8e1bb72`; the `MissingCredentials` Display impl in `rust/crates/api/src/error.rs:243-275` is unchanged in `63ce483c..f8e1bb72` which are docs-only ROADMAP additions). Repros in a fully clean isolated environment (`HOME=/tmp/iso5/home` with `{}` settings, fresh `/tmp/iso5/proj` git-init'd workspace, `stdin=/dev/null`, `ANTHROPIC_API_KEY` unset, `OPENAI_API_KEY` set): `claw -p 'hi' --output-format json` exits `1` with stderr JSON: `{"error":"missing Anthropic credentials; export ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY before calling the Anthropic API — hint: I see OPENAI_API_KEY is set — if you meant to use the OpenAI-compat provider, prefix your model name with `openai/` (e.g. `--model openai/gpt-4.1-mini`) so prefix routing selects the OpenAI-compatible provider, and set `OPENAI_BASE_URL` if you are pointing at OpenRouter/Ollama/a local server.","hint":null,"kind":"missing_credentials","type":"error"}`. Same shape with `XAI_API_KEY` set, suggesting an xAI model alias. With NO adjacent provider env set, `error` is short and `hint` is still `null` (consistent). The structured `hint` field is therefore **always `null`**, and the actual hint payload — which `ApiError::missing_credentials_with_hint` deliberately attaches — is only available via the `Display` impl's ` — hint: {hint}` suffix at `rust/crates/api/src/error.rs:269-272`, never serialized as a structured field. **Root cause (traced):** `MissingCredentials` carries `hint: Option` and the `Display` impl writes ` — hint: {hint}` into the same string the JSON serializer uses as `error`, instead of routing the hint into a dedicated structured field. The existing JSON envelope already has a `hint` slot — but it is wired to a different (null) source, so the structured field never reflects the actual hint that the provider resolver computed. **Why this is distinct from existing items:** #322 (deprecation warnings on stderr breaking JSON parse), #340 (`/session help` JSON `type` vs `kind` vocabulary mismatch), #447 (all JSON error envelopes go to stderr not stdout), #450 (`prompt` missing_credentials JSON on stderr): those track envelope **transport** (stderr vs stdout) and **vocabulary** issues. This pinpoint is the **internal shape** of an existing envelope — even when transport and vocabulary are correct, the `hint` field is structurally dead because the hint is duplicated into the `error` prose. `ApiError`'s `missing_credentials_with_hint` constructor explicitly takes a hint argument, the unit tests at `error.rs:572-599` assert it ends with ` — hint: …`, and the JSON contract still emits `"hint":null`. **Why it matters:** the whole point of structured error envelopes is that automation can branch on `code`/`hint`/`kind` without scraping prose. Today, a claw that wants to detect "Anthropic missing but OpenAI key present → switch to `--model openai/...`" must regex the `error` string for ` — hint: I see OPENAI_API_KEY` instead of reading a typed `hint:{adjacent_provider:"openai", suggested_model_prefix:"openai/", suggested_base_url_env:"OPENAI_BASE_URL"}`. That regex is brittle: any future hint wording change silently breaks downstream automation. The prose hint also bloats the human-facing message; a structured field would let the human formatter and the machine consumer diverge cleanly. **Required fix shape:** (a) keep `Display` rendering for text mode (humans need the prose hint), but stop using `Display` as the JSON `error` field source — serialize a base `error` message (the canonical "missing X credentials" line without the appended hint prose) plus a structured `hint` object; (b) structure the hint as a typed enum/object such as `{kind:"adjacent_provider_detected", provider:"openai"|"xai"|"dashscope"|…, suggested_model_prefix, suggested_env_vars[], suggested_base_url_env}` so callers can branch on `hint.kind`; (c) keep `hint:null` only when there is genuinely no hint; (d) add regression coverage proving the JSON envelope has both a base `error` line and a non-null structured `hint` when `missing_credentials_with_hint` is constructed, and that the prose ` — hint: …` suffix does NOT appear inside the JSON `error` field; (e) add a parity test asserting that for every adjacent-provider hint path (OpenAI, xAI, DashScope, …) the structured `hint.kind` is set correctly. **Acceptance check (one-liner):** `claw -p 'hi' --output-format json 2>&1 | jq -e '.hint != null and (.error | test(" — hint: ") | not)'` should pass when an adjacent provider env var is set. Source: gaebal-gajae dogfood follow-up for the 2026-05-24 07:00 Clawhip pinpoint nudge at message `1508001633416777778`. +455. **DONE — missing_credentials hint already newline-delimited** — the `MissingCredentials` Display impl at `rust/crates/api/src/error.rs:279` already uses `\n{hint}` format, which `split_error_hint` correctly extracts into the JSON envelope's `hint` field. The ROADMAP description references an older code path that used ` — hint:` inline format. 456. **`claw doctor` reports the same fact ("how many config files were discovered") under two semantically-identical JSON keys with *different definitions and different counts* — `config.discovered_files_count` filters to paths that exist on disk, while `workspace.discovered_config_files` returns the raw candidate-search-path list including paths that do not exist, so the same envelope contradicts itself** — dogfooded 2026-05-24 for the 07:30 Clawhip pinpoint nudge at message `1508009183260442777`, reproduced on local `./rust/target/debug/claw` `git_sha 003b739d` (origin/main `f8e1bb72`). Repro in a clean isolated environment (`HOME=/tmp/iso6/home` with no `.claw.json`, fresh `/tmp/iso6/proj` git-init'd workspace): `claw doctor --output-format json` returns `config.discovered_files_count = 0`, `config.discovered_files = []`, summary `"no config files present; defaults are active"`, **and at the same time** `workspace.discovered_config_files = 5`, summary `"project root detected on branch master"`. In the real repo where one `.claw.json` exists, the same command returns `config.discovered_files_count = 1` and `workspace.discovered_config_files = 5`. The human-facing text envelope leaks the same contradiction: the Config section says `Config files loaded 0/0` and `Discovered files (defaults active)`, while the Workspace section says `Memory files 0 · config files loaded 0/5` — three different values for the same fact in one report. **Root cause (traced):** the `config` check (`rust/crates/rusty-claude-cli/src/main.rs:2180-2202`) does `let discovered = config_loader.discover();` then `let present_paths = discovered.iter().filter(|e| e.path.exists()).collect();` and emits `discovered_files_count = present_paths.len()`, deliberately hiding non-existent candidate paths (a comment at lines 2183-2186 says `"Showing non-existent paths as 'Discovered file' implies they loaded but something went wrong, which is confusing. We only surface paths that exist on disk as discovered; non-existent ones are silently omitted from the display"`). The `workspace`/`status_context` builder (`rust/crates/rusty-claude-cli/src/main.rs:5759-5764`) does `let discovered_config_files = loader.discover().len();` — **same `discover()` API, no `.exists()` filter** — and emits that raw candidate count as `workspace.discovered_config_files`. Both numbers flow into the same JSON envelope under near-identical key names. **Why distinct from existing items:** #143 (degrade-not-hard-fail on config parse failure) covers transport behaviour; #322/#447/#450 cover stderr-vs-stdout transport; #340 covers `type`/`kind` vocabulary; #449/#454/#451/#452/#453/#455 cover prompt-misdelivery and `missing_credentials` envelope shape. This pinpoint is **internal envelope self-consistency**: two checks in the same `doctor` invocation publish two different numbers for the same concept ("how many config files were discovered") under semantically-identical keys, using opposite definitions of the same `discover()` API. **Why it matters:** `doctor` is the structured health surface other claws/scripts/UI panels read to decide whether a workspace is "ready". A script that branches on `workspace.discovered_config_files > 0` (because that key name is the most obvious) will believe the workspace has 5 config files when it actually has 0 — false positive on "configured workspace" detection. Conversely, a script that branches on `config.discovered_files_count` correctly sees 0 — so two equally reasonable claws produce opposite decisions reading the same envelope. The contradiction also undermines `doctor` as a debugging tool: humans see `Discovered files ` and `config files loaded 0/5` in the same report and lose trust in every number it prints. **Required fix shape:** (a) pick **one** definition of "discovered config files" — strongly prefer "paths that exist on disk" (the user-meaningful number), since "candidate search paths" is an implementation detail of the loader; (b) rename the loader's raw candidate count to something explicit like `workspace.config_search_paths_count` and keep `discovered_config_files` aligned with `config.discovered_files_count`; (c) consolidate both checks to read the same `present_paths` computation rather than calling `discover()` twice with different filters — single source of truth; (d) regression coverage that the two values are equal across (i) empty workspace, (ii) workspace with one config file, (iii) workspace with a malformed config file (parse-failure path), and (iv) a parity test asserting `doctor` JSON has no two keys reporting different counts for the same concept; (e) fix the human text section so `Config files loaded N/M` uses the same `M` in both the Config and Workspace sections. **Acceptance check (one-liner):** `claw doctor --output-format json | jq -e '([.checks[] | select(.name=="config")][0].discovered_files_count) == ([.checks[] | select(.name=="workspace")][0].discovered_config_files)'` should pass on any workspace. Source: gaebal-gajae dogfood follow-up for the 2026-05-24 07:30 Clawhip pinpoint nudge at message `1508009183260442777`. diff --git a/rust/crates/rusty-claude-cli/src/main.rs b/rust/crates/rusty-claude-cli/src/main.rs index 1dfb5ff3..f5ab4e8d 100644 --- a/rust/crates/rusty-claude-cli/src/main.rs +++ b/rust/crates/rusty-claude-cli/src/main.rs @@ -2671,6 +2671,7 @@ fn suggest_similar_subcommand(input: &str) -> Option> { "init", "export", "prompt", + "list", ]; let normalized_input = input.to_ascii_lowercase();