From 757e686445c0922f96caf544b17fff8f0dc39def Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 29 Oct 2026 16:58:04 +0100 Subject: [PATCH] chore(contract): bare /model dialog contract + plan r2 (gateway-ids plan superseded) --- .../2026-10-29-bare-model-dialog-1617.md | 35 +++++++++++++ .../2026-10-29-bare-model-dialog-1617.md | 52 +++++++++++++++++++ .../2026-10-29-picker-gateway-ids-1523.md | 29 +++++++++++ 3 files changed, 116 insertions(+) create mode 100644 .claude/tasks/contracts/2026-10-29-bare-model-dialog-1617.md create mode 100644 .claude/tasks/plans/2026-10-29-bare-model-dialog-1617.md create mode 100644 .claude/tasks/plans/2026-10-29-picker-gateway-ids-1523.md diff --git a/.claude/tasks/contracts/2026-10-29-bare-model-dialog-1617.md b/.claude/tasks/contracts/2026-10-29-bare-model-dialog-1617.md new file mode 100644 index 0000000..3493749 --- /dev/null +++ b/.claude/tasks/contracts/2026-10-29-bare-model-dialog-1617.md @@ -0,0 +1,35 @@ +# CONTRACT — bare-model-dialog +- date: 2026-10-29 | flow: feat | branch: feature/bare-model-dialog (off develop 9a20ca7) +- status: active + +## REQUEST (verbatim — IMMUTABLE) +"quand je fais un /model ça change pas le fable 5.1 comme ça devrait" → (after the /bugfix test) "ça prompt bien la question. il faut que ça soit systématique" → option A chosen: "A. et oui tu dois faire le feat" + +Option A as presented (2026-10-29): a bare `/model` opens the mod's own dialog in two steps: (1) which model, from the router's table (Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5, with [1m] variants) plus an "Other model (native picker)" entry; (2) the scope question This project / This conversation / Everywhere. It always asks, the current model included. Everywhere runs the native command; non-Anthropic models and anything outside the table stay reachable through the native entry. + +## CLARIFICATIONS +Q: root cause of the report? / A: /bugfix diagnosis 2026-10-29: picking the model already active in the native picker fires no PreModelSwitch (nothing to switch) → no question, project pin stays; a different-model pick asks (user-run: "Model switch to Sonnet 5.5 was blocked by a PreModelSwitch hook"). Gateway-id normalization dropped (3 lenses FATAL: logged-out OpenRouter session, would switch on automatic routing). Plan `.claude/tasks/plans/2026-10-29-picker-gateway-ids-1523.md` superseded. +Q: step 1 rows? / A: with [1m] variants: `fable (best)`, `fable [1m]`, `opus (big)`, `opus [1m]`, `sonnet (work)`, `sonnet [1m]`, `haiku (cheap)`, `Other model (native picker)` (labels from modelLabel; tier name in parentheses as the table says). [gated 2026-10-29] +Q: Escape at step 1? / A: nothing changes, text `model: no model chosen, nothing changed`. [gated 2026-10-29] + +Q: the engine's `$.ui.ask` takes 2-4 labels (3 lenses BLOCKER on the 8-row layout): which layout? / A: step 1 `fable (best)`, `opus (big)`, `sonnet (work)`, `Other model (native picker)` (haiku through the native picker or `/model haiku`); step 2 `Standard` / `[1m]`; step 3 the scope question. Supersedes the 8-row answer above. [gated 2026-10-29] + +## ACCEPTANCE CRITERIA +1. [gated 2026-10-29, layout] A bare `/model` (composer origin, router on, surface present, no dialog open) asks step 1 with exactly `fable (best)`, `opus (big)`, `sonnet (work)`, `Other model (native picker)` in that order, header `model-router`, text naming the session model and ending `Which model?`; a table row then asks `Standard` / `[1m]` (text ending `?`); no ask ever carries fewer than 2 or more than 4 options (the test kit refuses it); native is not run before an answer. +2. The variant answer then asks the existing scope question (scopeDialog, same three scopes and texts) for the token (`opus`, `opus[1m]`, …), even when it is the session's current model. +3. This project writes the token's full id (`[1m]` kept verbatim: opus + `[1m]` → `claude-opus-5-5[1m]`) into `.claude/settings.local.json` and sets the sticky route; This conversation sets the route only; Everywhere runs the native `/model` with args = the token; none of these runs native with empty args. +4. `Other model (native picker)` runs native with the original empty args (the native picker), no scope question, with the dialog slot already free (a pick inside that picker is held and asks its scope, never the BUSY toast); a native throw there returns a text and native is not run again. +5. Escape / dismiss / free text at step 1 or 2: text `model: no model chosen, nothing changed`, native not run, no scope question, nothing written, no route change. +6. Unchanged: `/model ` typed (scope dialog as today), the PreModelSwitch picker hold (handlePicker), and every native passthrough except the empty-args case (`fable opus`, `default`, `opusplan`, unknown ids, `haiku[1m]`, another origin, router off, no surface, a dialog already open → native, no question). +7. lib/effort-shift.md and README.md describe the bare `/model` dialog (Other model = native picker, Esc changes nothing) and no longer list "no args" among the native passthroughs; CHANGELOG [Unreleased] carries the change. [gated 2026-10-29: README + CHANGELOG added] + CHECK: grep -q 'Other model (native picker)' lib/effort-shift.md && ! grep -q 'Picker Default, no args' lib/effort-shift.md && ! grep -q "Default, no args" README.md && grep -q 'bare `/model`' CHANGELOG.md && echo DOC-OK + EXPECT: DOC-OK + EVIDENCE: pending +8. Mod suite green (register.test.ts through `claude plugin test`) and the full suite green. + CHECK: make test 2>&1 | tail -1 + EXPECT: all suites green + EVIDENCE: pending +9. Live proof (controller, after `/reload-plugins`, user-run): bare `/model` shows step 1; opus → `[1m]` → This project → `.claude/settings.local.json` `model` becomes `claude-opus-5-5[1m]`. If the engine never routes a bare `/model` through `command.run`, this criterion fails and is reported, not worked around. + +## FILE SCOPE +mods/model-router/hooks/register.ts, mods/model-router/hooks/register.test.ts, lib/effort-shift.md, README.md, CHANGELOG.md [gated 2026-10-29], .claude/tasks/contracts/2026-10-29-bare-model-dialog-1617.md, .claude/tasks/plans/2026-10-29-bare-model-dialog-1617.md diff --git a/.claude/tasks/plans/2026-10-29-bare-model-dialog-1617.md b/.claude/tasks/plans/2026-10-29-bare-model-dialog-1617.md new file mode 100644 index 0000000..5bb3280 --- /dev/null +++ b/.claude/tasks/plans/2026-10-29-bare-model-dialog-1617.md @@ -0,0 +1,52 @@ +# Plan r2 — bare `/model` opens the router's dialog (feat) + +Contract: `.claude/tasks/contracts/2026-10-29-bare-model-dialog-1617.md`. r1 had 8 rows in one `$.ui.ask`: the engine takes 2-4 labels (claude-code.d.ts:468, :2122; repo fact w3b plan l.7) → 3 lenses BLOCKER; user re-gated the layout 2026-10-29 (3 steps below). + +## Approach +- Constants (register.ts, near MODEL_SCOPES ~201): `NATIVE_PICKER = 'Other model (native picker)'`, `NO_MODEL = 'model: no model chosen, nothing changed'`, `BARE_ALIASES = ['fable', 'opus', 'sonnet']`, `STANDARD = 'Standard'`, `LONG = '[1m]'`. +- ONE guard in `handleModelCommand` (~2348): `const bare = token === ''` (`''.trim().split(/\s+/)` = `['']`, so `tokens.length === 1`); passthrough when `st.off || origin !== 'composer' || tokens.length !== 1 || (!bare && !knownModel(st.cfg, token)) || no surface || st.asking !== null`. Same slot `st.asking = \`model:${token}\``, same try/finally. +- Inside the try: `bare` → `await bareModelDialog($, st, e, next)`; else the existing `scopeDialog` call unchanged. +- `bareModelDialog` returns a `CommandRunResult` or the marker `'native'`: + - Step 1: `askOr($, text1, [...BARE_ALIASES.map(a => modelLabel(st.cfg, a)), NATIVE_PICKER])` with `text1 = \`Session: ${clean(st.sessionModel || 'unknown', 60)}\nWhich model?\``. Answer = NATIVE_PICKER → `'native'`; a label of BARE_ALIASES → that alias; anything else (Later, free text) → `{ text: NO_MODEL }`. + - Step 2: `askOr($, text2, [STANDARD, LONG])`, `text2 = \`${STANDARD}: standard context · ${LONG}: 1M context (a conversation route follows the session's variant)\nWhich variant of ${alias}?\``. STANDARD → token `alias`; LONG → `alias + '[1m]'`; anything else → `{ text: NO_MODEL }`. + - Step 3: `scopeDialog($, st, token, { everywhere: () => next({ ...e, args: token }), warnKey: 'command.run model' })` (texts, scopes, note, file write unchanged). +- Back in `handleModelCommand`: on `'native'`, the slot is freed by the `finally` FIRST, then `try { return await next(e) } catch (err) { warnOnce(st, $, 'command.run model', errWord(err)); return { text: \`model: native picker failed (${errWord(err)})\` } }` — a pick inside the native picker then reaches handlePicker with a free slot (deny + scope question, not BUSY), and a native throw never re-runs native. +- Haiku: not in step 1 (4-label cap); reachable through the native picker row or a typed `/model haiku`. +- Test kit (register.test.ts ~236-252, `installDialog`): reject an AskUserQuestion whose options count is outside 2-4 (throw like an engine refusal), so a too-wide ask fails the suite. + +## Edge cases +- Router off / sdk origin / `-p` (no surface) / a dialog already open → native with `''` (the native picker), no question. +- Free-text "Other" at step 1 or 2 → NO_MODEL, no toast. +- `[1m]` + This conversation → the route holds the bare alias; variantNote prints "([1m] follows the session's variant)" (token carries `[1m]`). +- `[1m]` + This project → `fullId` keeps `[1m]` verbatim in settings.local.json. +- The current session model is offered and asks the scope like any other (the point of the feat). + +## Tests (register.test.ts, `/model` block ~6066) +1. bare `/model`: step 1 options exactly `['fable (best)', 'opus (big)', 'sonnet (work)', 'Other model (native picker)']`, header `model-router`, text ends `Which model?` and names the session id; `ran` empty. +2. opus → `[1m]` → This project: three questions; local `model` = `claude-opus-5-5[1m]`; `ran` empty. +3. opus (session OPUS) → Standard → This conversation: sticky route `claude-opus-5-5` (route show); `ran` empty. +4. Other model → `ran` = `['']`, one question; a second test whose native stub calls `pick($, SONNET)` before returning: the pick gets DENY and, after 300 ms, the scope question (not the BUSY toast). +5. dismiss at step 1 → NO_MODEL, one question, `ran` empty, no local file; dismiss at step 2 → NO_MODEL, two questions. +6. sonnet → Standard → Everywhere → `ran` = `['sonnet']`; sonnet → `[1m]` → Everywhere → `['sonnet[1m]']`. +7. `[1m]` + This conversation → output contains `[1m] follows the session's variant`. +8. native throw on the Other-model row → text `model: native picker failed (…)`, native ran once. +9. guards: the existing off / sdk / no-surface / dialog-open tests run `''` too (native `''`, no question). +10. 'no dialog for a call native owns': drop `''` from its args list. +11. kit: a direct `$.tool.call({ tool: 'AskUserQuestion', … })` with 5 options rejects (drives the kit hook itself, not `$.ui.ask`). + +## Docs +- lib/effort-shift.md (44-56): after the first sentence add "A bare `/model` asks which model (fable, opus, sonnet, or `Other model (native picker)`, which opens the native picker; haiku goes through it or `/model haiku`), then Standard or `[1m]`, then the same scope question, the current model included; Esc changes nothing." Replace "Picker Default, no args, an unknown name or a run with no surface (`-p`) go native, no question." with "Picker Default, an unknown name or a run with no surface (`-p`) go native, no question." +- Keep the phrase `Other model (native picker)` on ONE line in every doc (the contract oracle greps a line). +- README.md:139 (triggers that ask the scope) and :146 (triggers of the project write): add the bare `/model` dialog. +- register.ts:2121-2122 section comment: name the bare `/model` dialog beside `/model `. +- README.md:142: drop "no args" from the native-passthrough list and add one clause "a bare `/model` opens the router's model, variant and scope dialog". +- CHANGELOG.md [Unreleased]: one Changed line "model-router: a bare `/model` opens the router's dialog (model, variant, scope), so the scope question also comes when the pick is the current model (fable, opus, sonnet; a current haiku goes through `/model haiku`); `Other model (native picker)` keeps the native picker"; and fix the l.14 "no args" mention. + +## Disposition +- supersedes BDR-126 on "no args → native picker untouched" (user option A, 2026-10-29); honors BDR-126/127 elsewhere (scopeDialog reused verbatim; picker hold kept, slot freed before the native picker so it still asks). +- honors LRN-231 (the dialog lives in command.run, never in PreModelSwitch). +- honors BLK-036 for fable/opus/sonnet (no silent user-settings write for a project intent); a current haiku keeps the gap through the native row, `/model haiku` covers it. + +## Risk +Unverified live, first: that `$.ui.ask` awaited inside the `model` command.run hook draws in a real session (TODO.md:15 still lists the typed `/model ` live check as pending; LRN-231 froze in PreModelSwitch). User-run spike before code: `/model opus` typed. +Unverified live: that a bare `/model` reaches `command.run` before the engine draws its picker (the harness assumes it; contract criterion 9 proves it or reports the miss). diff --git a/.claude/tasks/plans/2026-10-29-picker-gateway-ids-1523.md b/.claude/tasks/plans/2026-10-29-picker-gateway-ids-1523.md new file mode 100644 index 0000000..1e9a8e4 --- /dev/null +++ b/.claude/tasks/plans/2026-10-29-picker-gateway-ids-1523.md @@ -0,0 +1,29 @@ +# Bugfix plan — /model picker never asks its scope (gateway ids + silent passthrough) + +Bug report (user, 2026-10-29): "quand je fais un /model ça change pas le fable 5.1 comme ça devrait". Repo /home/bchanot/Documents/claude, `.claude/settings.local.json` pins `"model": "claude-fable-5-1[1m]"`; bare `/model`, pick the "Opus 5.5" row (not Default, user-confirmed); native output "Set model to `Opus 5.5` and saved as your default… settings.local.json pins Fable 5.1 — applies on restart"; no scope question (BDR-127 expects This project / This conversation / Everywhere). + +## Diagnosis +1. PROVEN (transcript cdd27037, 2026-10-29T10:27, before a `/login`): the picker listed a gateway (`OpenAI: GPT-6 Astra`, `Anthropic: Claude Opus 5.5`); after each pick the mod logged `model-router: anthropic/openai/gpt-6-astra unknown to the models table; no switch` then `… anthropic/claude-opus-5.5 unknown …` (unknownCall, register.ts:1351, via canonical() at :1393). Gateway ids are provider-prefixed with a dotted version. `knownModel` (register.ts:2134) and `canonical` (:1086) only know `claude-opus-5-5` etc. (DEFAULT_CONFIG.models :270) → `handlePicker` (:2408) returns `next(e)` → native, silent; the main decision also treats the session model as unknown (never switches). The first pick also wrote `"model": "anthropic/claude-opus-5.5[1m]"` into the tracked settings.json (native Everywhere). +2. NOT PROVEN (13:52, after `/login`, label `Opus 5.5` without provider): no deny, no log. `handlePicker` has 4 silent passthrough exits: `e.source !== 'picker'`, `st.off`, non-string or unknown `requested_model`, `surfaces().length === 0`. None logs, so the cause cannot be read. + +Prior: BDR-127 (picker scope; live test 2026-10-25 with native ids), LRN-231, BLK-036. None covers the gateway id form. + +## Fix plan +1. `mods/model-router/hooks/register.ts`: one normalizer `bareId(id)` used first by `canonical()` and `knownModel()`: + - strip a leading `anthropic/` (once); + - if the rest starts with `claude-`, dotted version digits → dashed (`claude-opus-5.5` → `claude-opus-5-5`, `claude-haiku-5.5[1m]` keeps `[1m]` handling as today); + - anything else unchanged (`anthropic/openai/gpt-6-astra` → `openai/gpt-6-astra`, still unknown → native, as today). + `fullId()` keeps returning the token AS RECEIVED for a non-alias token (so settings.local.json and the sticky route carry the engine's own id: safest switch target on that account). +2. `handlePicker`: when `e.source === 'picker'` and the hook passes through to native, one `tryLog` line `model-router: picker → native: ()`, reason ∈ {off, unknown id, Default, no surface}. Not logged for source command/sdk/auto/resume (those have their own paths and would spam). +3. `mods/model-router/hooks/register.test.ts`: + - picker: `anthropic/claude-opus-5.5` is denied at once and the deferred question comes (regression for cause 1); the question names `anthropic/claude-opus-5.5` (as received); This project writes that id into settings.local.json; + - `anthropic/openai/gpt-6-astra` passes through (non-Anthropic stays native) and logs `picker → native: unknown id`; + - each existing PASSTHROUGH row with source picker now asserts its log line; source command/sdk rows assert NO picker log; + - canonical: `anthropic/claude-opus-5.5` and `anthropic/claude-opus-5.5[1m]` rank like `opus` in the main decision (no "unknown to the models table" line). +4. Proof after merge-ready: user runs `/reload-plugins`, `/model` → Opus 5.5 row: either the question appears, or the new log names the passthrough reason (cause 2 then gets its own bugfix). + +## Out of scope +Router-initiated switches on a gateway account (they send `claude-opus-5-5`; acceptance there unverified, named as a risk). The tracked settings.json `model` write by native Everywhere (BDR-131 policy handles it). + +## Tests +`make test suite=lib/tests/mods.test.sh` (runs `claude plugin test` on the mod) + full `make test`.