chore(contract): bare /model dialog contract + plan r2 (gateway-ids plan superseded)

This commit is contained in:
bchanot committed 2026-10-29 16:58:04 +01:00
1 parent 9a20ca797b
commit 757e686445
3 files changed
+116

No files matched your search

@@ -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 <name>`.
- 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 <name>` 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).
@@ -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> (<requested_model|Default>)`, 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`.