feat(router): a bare /model opens the router's model, variant and scope dialog
Picking the session's current model in the native picker fires no PreModelSwitch, so the scope question never came and the project pin stayed. The bare /model now asks model (fable/opus/sonnet or the native picker), Standard or [1m], then the scope.
This commit is contained in:
1 parent
757e686445
commit
657e5cb55b
6 files changed
+213
-17
No files matched your search
@@ -24,12 +24,16 @@ Q: the engine's `$.ui.ask` takes 2-4 labels (3 lenses BLOCKER on the 8-row layou
|
|||||||
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]
|
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
|
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
|
EXPECT: DOC-OK
|
||||||
EVIDENCE: pending
|
EVIDENCE: MET exit=0 marker-found :: DOC-OK
|
||||||
8. Mod suite green (register.test.ts through `claude plugin test`) and the full suite green.
|
8. Mod suite green (register.test.ts through `claude plugin test`) and the full suite green.
|
||||||
CHECK: make test 2>&1 | tail -1
|
CHECK: make test 2>&1 | tail -1
|
||||||
EXPECT: all suites green
|
EXPECT: all suites green
|
||||||
EVIDENCE: pending
|
EVIDENCE: MET exit=0 marker-found :: all suites green
|
||||||
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.
|
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
|
## 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
|
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
|
||||||
|
|
||||||
|
## PROOF — controller, 2026-10-29
|
||||||
|
- c9 live (user-run): `/reload-plugins` (3 plugins, 7 hooks), bare `/model` → step 1 → opus → `[1m]` → This project → "model: claude-opus-5-5[1m] written to .claude/settings.local.json …; sticky route claude-opus-5-5 set ([1m] follows the session's variant)"; user: "tout est bien apparu et a bien été changé". The engine routes a bare `/model` through command.run.
|
||||||
|
- GATE 0 MET (c7 DOC-OK, c8 all suites green); GATE 1 verifier 8/9 MET + c9 UNVERIFIABLE (now proven above); GATE 2 security PASS (semgrep 0, checklist 0).
|
||||||
+2
-1
@@ -11,7 +11,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/) and this project
|
|||||||
- **/a11y skill**: accessibility leaves `/guardrails` and becomes its own skill. Same A11Y-* rules (img alt, field label, click without keyboard, focus outline removed, positive tabindex) on the shared scan engine (`skills/guardrails/scripts/scanner.py`, a `Catalogue` per CLI; `skills/a11y/scripts/scan.py`, markers `A11Y-CLEAR` / `A11Y-NO-NEW`), a Tab-only walk of the main flow on `--live` through `/browse` (marked not done otherwise), report `.claude/audits/A11Y.md`, fixes proposed with the alt and label wording as the user's choice, applied through the bugfix circuit (`bugfixer`, verify-secure gates, `bugfix/a11y-<date>`), re-pass against a baseline. The keyboard, alt and label doctrine moves from `rules/secure-by-default.md` to the lazy `rules/a11y.md` (loads on UI files only; `rules/web-building.md` points at it). `/guardrails` scans `injection` (INJ-*) and `exposure` (EXP-*) instead, with per-language SQL patterns, shared `code_files` / `hits` / `dedupe_lines` / `client_reachable` helpers and a walker that lists files over 1 MB by path; `--domain a11y` is a usage error there. `/web-validate` keeps full WCAG conformance. Suite `lib/tests/a11y-scan.test.sh`; routing row `reflect`; profiles audit, dev, web, web-full, full, max.
|
- **/a11y skill**: accessibility leaves `/guardrails` and becomes its own skill. Same A11Y-* rules (img alt, field label, click without keyboard, focus outline removed, positive tabindex) on the shared scan engine (`skills/guardrails/scripts/scanner.py`, a `Catalogue` per CLI; `skills/a11y/scripts/scan.py`, markers `A11Y-CLEAR` / `A11Y-NO-NEW`), a Tab-only walk of the main flow on `--live` through `/browse` (marked not done otherwise), report `.claude/audits/A11Y.md`, fixes proposed with the alt and label wording as the user's choice, applied through the bugfix circuit (`bugfixer`, verify-secure gates, `bugfix/a11y-<date>`), re-pass against a baseline. The keyboard, alt and label doctrine moves from `rules/secure-by-default.md` to the lazy `rules/a11y.md` (loads on UI files only; `rules/web-building.md` points at it). `/guardrails` scans `injection` (INJ-*) and `exposure` (EXP-*) instead, with per-language SQL patterns, shared `code_files` / `hits` / `dedupe_lines` / `client_reachable` helpers and a walker that lists files over 1 MB by path; `--domain a11y` is a usage error there. `/web-validate` keeps full WCAG conformance. Suite `lib/tests/a11y-scan.test.sh`; routing row `reflect`; profiles audit, dev, web, web-full, full, max.
|
||||||
- **model-router mod**: `mods/model-router/`, a Claude Code mod (function-hooks plugin), routes every repo skill and agent from phase rows (`plan`, `reflect`, `orchestrate`, `escalate`, `judge`, `audit`, `implement`, `write`, `verify`, `explore`, `apply`, `mechanical`; built-ins Explore on sonnet/medium, Plan on opus/xhigh). A typed skill routes the main loop to its row, and a best-tier row holds across turns in a run slot until `/route clear`, `/route off`, a user `/model` or a typed skill on a non-best row. Agents get their row's model at spawn (within the tier, upward only) and its effort on every step; explicit Agent params win. Orchestrators declare their phases through the `mcp__model-router__route` tool. `ultrathink` in a prompt sets the turn's minimum effort and `/route effort=max` holds until `/route clear`; the built-in `/effort` is not a lever inside a run. `/route show` names the run slot (`main: run <phase>`), and a `null` row in the override drops a default row. The model gets a `route` tool and the user a `/route` command (`show|clear|off|on|reload|pending|ask on|off|forget <name|all|projects>|<phase>|model=<alias|id> effort=<level>|switch on|off|verbose on|off`). Optional per-machine config `~/.claude/model-router.json`, where `"enabled": false` turns it off on that machine. The spinner suffix and the status line show the route in force. It loads in every session through the tracked symlink `skills/model-router` (`model-router@skills-dir`). `make doctor` gains a Mods section; suite `make test suite=lib/tests/mods.test.sh`. Known limits: a main-loop switch (a `/model` hand pick excepted) runs only while the cold read it costs (the context minus what the target model's prompt cache holds) fits `upgradeMaxTokens` (200000) or `downgradeMaxTokens` (120000), and a downgrade also needs `mainModelSwitch` (on by default, off on any non-boolean value); the hooks send full model ids, so the `models` table has to follow new versions.
|
- **model-router mod**: `mods/model-router/`, a Claude Code mod (function-hooks plugin), routes every repo skill and agent from phase rows (`plan`, `reflect`, `orchestrate`, `escalate`, `judge`, `audit`, `implement`, `write`, `verify`, `explore`, `apply`, `mechanical`; built-ins Explore on sonnet/medium, Plan on opus/xhigh). A typed skill routes the main loop to its row, and a best-tier row holds across turns in a run slot until `/route clear`, `/route off`, a user `/model` or a typed skill on a non-best row. Agents get their row's model at spawn (within the tier, upward only) and its effort on every step; explicit Agent params win. Orchestrators declare their phases through the `mcp__model-router__route` tool. `ultrathink` in a prompt sets the turn's minimum effort and `/route effort=max` holds until `/route clear`; the built-in `/effort` is not a lever inside a run. `/route show` names the run slot (`main: run <phase>`), and a `null` row in the override drops a default row. The model gets a `route` tool and the user a `/route` command (`show|clear|off|on|reload|pending|ask on|off|forget <name|all|projects>|<phase>|model=<alias|id> effort=<level>|switch on|off|verbose on|off`). Optional per-machine config `~/.claude/model-router.json`, where `"enabled": false` turns it off on that machine. The spinner suffix and the status line show the route in force. It loads in every session through the tracked symlink `skills/model-router` (`model-router@skills-dir`). `make doctor` gains a Mods section; suite `make test suite=lib/tests/mods.test.sh`. Known limits: a main-loop switch (a `/model` hand pick excepted) runs only while the cold read it costs (the context minus what the target model's prompt cache holds) fits `upgradeMaxTokens` (200000) or `downgradeMaxTokens` (120000), and a downgrade also needs `mainModelSwitch` (on by default, off on any non-boolean value); the hooks send full model ids, so the `models` table has to follow new versions.
|
||||||
- **model-router first-use confirmation**: `mods/model-router/routing.json` (tracked) is the single source of the phase table and of every skill and agent row, and keeps the decisions: `confirmed`, `changed` (`from`/`to`), `projects` exceptions keyed by the origin remote reduced to `host/path` (credentials and local paths never stored), and `ask`. The first use of a rowed typed skill, a rowed agent spawn or a main-loop phase declared through the `route` tool opens a dialog with context: the skill's description (first sentence of its `SKILL.md` frontmatter) or the agent's, the phase with its `about` line (a new field on each of the 12 phases) and the model id and effort the next step really runs on. A row offers Later, Keep or Change; a main-loop phase Later or Keep. Change asks the model (fable, opus, sonnet, haiku with their tier), then the effort among those the phases of that model use (skipped when there is only one), then Everywhere or This project only; the pair maps to an existing phase (rows stay phase names, the same phase counts as Keep, a pair no phase offers is added by hand as a new phase). A skill-row change toasts the model and effort it now runs on, with the `/route switch on` hint when the main loop holds back a downgrade; a free-text answer counts as Later. One dialog at a time, never in headless (`-p`) runs or inside a sub-agent. Only a dialog answer, `/route ask on|off` or `/route forget` (which takes decisions back; a changed row returns to its shipped phase, the frontmatter floors stay yours to realign) writes the file (serialized, 64 KiB cap, never created when absent); each write asks you to commit it from the config repo. `/route pending` lists unconfirmed rows and phases. Layers: routing.json < `~/.claude/model-router.json` (its `ask` wins); a project's `.claude/model-router.json` is never read. Tests: `mods/model-router/hooks/register.test.ts`.
|
- **model-router first-use confirmation**: `mods/model-router/routing.json` (tracked) is the single source of the phase table and of every skill and agent row, and keeps the decisions: `confirmed`, `changed` (`from`/`to`), `projects` exceptions keyed by the origin remote reduced to `host/path` (credentials and local paths never stored), and `ask`. The first use of a rowed typed skill, a rowed agent spawn or a main-loop phase declared through the `route` tool opens a dialog with context: the skill's description (first sentence of its `SKILL.md` frontmatter) or the agent's, the phase with its `about` line (a new field on each of the 12 phases) and the model id and effort the next step really runs on. A row offers Later, Keep or Change; a main-loop phase Later or Keep. Change asks the model (fable, opus, sonnet, haiku with their tier), then the effort among those the phases of that model use (skipped when there is only one), then Everywhere or This project only; the pair maps to an existing phase (rows stay phase names, the same phase counts as Keep, a pair no phase offers is added by hand as a new phase). A skill-row change toasts the model and effort it now runs on, with the `/route switch on` hint when the main loop holds back a downgrade; a free-text answer counts as Later. One dialog at a time, never in headless (`-p`) runs or inside a sub-agent. Only a dialog answer, `/route ask on|off` or `/route forget` (which takes decisions back; a changed row returns to its shipped phase, the frontmatter floors stay yours to realign) writes the file (serialized, 64 KiB cap, never created when absent); each write asks you to commit it from the config repo. `/route pending` lists unconfirmed rows and phases. Layers: routing.json < `~/.claude/model-router.json` (its `ask` wins); a project's `.claude/model-router.json` is never read. Tests: `mods/model-router/hooks/register.test.ts`.
|
||||||
- **model-router `/model` scope**: a `/model <name>` typed in the composer, or a pick in the `/model` picker, with a model the table knows asks where it applies. The picker's switch is held first (PreModelSwitch deny; the engine prints that a hook blocked it); a pick while another dialog is open is refused with `answer the open dialog first`. This project writes the full id as `model` into the project's `.claude/settings.local.json` (created if absent, refused through a link) and sets a sticky model route. This conversation sets the sticky route only. Everywhere runs the native `/model` (user `settings.json`). Both non-native answers drop the run slot and keep a sticky effort. With the picker's Default, no args, an unknown name, a headless run or another origin, the native command runs with no question. A model chosen in that dialog always switches: it bypasses the cold-read caps and the `mainUpgrade` / `mainModelSwitch` flags, and while it is marked down or outside a known window it waits and the automatic chain decides. A native switch or `/clear` drops it; `/route model=` keeps the caps. Known limits: the `/config` Model row still writes user `settings.json`; a dialog never answered has no timeout. Tests: `mods/model-router/hooks/register.test.ts`.
|
- **model-router `/model` scope**: a `/model <name>` typed in the composer, or a pick in the `/model` picker, with a model the table knows asks where it applies. The picker's switch is held first (PreModelSwitch deny; the engine prints that a hook blocked it); a pick while another dialog is open is refused with `answer the open dialog first`. This project writes the full id as `model` into the project's `.claude/settings.local.json` (created if absent, refused through a link) and sets a sticky model route. This conversation sets the sticky route only. Everywhere runs the native `/model` (user `settings.json`). Both non-native answers drop the run slot and keep a sticky effort. With the picker's Default, an unknown name, a headless run or another origin, the native command runs with no question. A model chosen in that dialog always switches: it bypasses the cold-read caps and the `mainUpgrade` / `mainModelSwitch` flags, and while it is marked down or outside a known window it waits and the automatic chain decides. A native switch or `/clear` drops it; `/route model=` keeps the caps. Known limits: the `/config` Model row still writes user `settings.json`; a dialog never answered has no timeout. Tests: `mods/model-router/hooks/register.test.ts`.
|
||||||
- **Manual-push mode**: `git config gitflow.autopush false` (human-set) now stops every push the gitflow lib makes, not only the post-commit / post-merge hooks. `gitflow start` and `finish` branch, commit and merge locally and push nothing; `gitflow delete` leaves the `origin/` copy in place and prints `git push origin --delete <br>` for the user to run. `hooks/unpushed-guard.sh` stays silent at turn end in this mode and opens each session with one `ℹ manual push mode:` line counting the commits no remote holds across every local branch; an unparseable or unreadable `gitflow.autopush` value is treated as manual push mode too, and that line names it. `hooks/push-guard.sh` (PreToolUse, `Bash|Monitor`) refuses any `git push` Claude types while `gitflow.autopush` reads false in the session cwd or in a literal `-C`/`cd` directory the command names (global config counts outside a repo); the refusal tells the user to run it with `! git push`. It reads the mode through the same lib verb as every other reader and fails closed: an unparseable or unreadable value reads as manual, and an internal error, a missing `lib/gitflow.sh`, more than 20 distinct directory tokens in one command (capped before any token is classified), a `cd`/`-C` directory token mixing quoted and unquoted parts, or a payload jq cannot parse whose raw text looks like a push refuse the push (these pathological cases fire in auto mode too). Directory tokens are read as whole shell words, adjacent quoted segments and backslash escapes included. Once the text looks like a push, the command is split into simple commands (quotes, escapes, separators, heredoc bodies dropped) and a push must be git's own subcommand in one of them: `grep "git push"`, `git log -S "git push"`, `git config --get push.default`, `git stash push`, a heredoc quoting a push or a commit message naming one are allowed; `bash -c` scripts are re-checked, wrappers (`sudo`, `env`, `eval`, `xargs`, `timeout`, `git subtree`...) and assignments keep the text verdict. The misses listed in its header fall to a new `autoMode.soft_deny` rule that no request in the turn clears. The session banner adds `🔒 push : manual (autopush=false) — ! git push` when the key reads false, and `🔒 push : manual (autopush bad) — ! git push` when the value is invalid. Skills read the mode through a new lib verb, `bash ~/.claude/lib/gitflow.sh push-mode`: it prints `auto`, `manual` or `invalid` (rc 0) and names an invalid value on stderr (printable characters only, 64 at most). It is the one reader a skill may call, since the `git config` read of the key is denied to Claude. Skills push nothing on their own, except the `/release-candidate` tag in auto-push mode on an explicit go. Every "on origin" or "not pushed" line they print comes from `git rev-list --count origin/<br>..<br>` read after the fact, with the complete `! git …` command when something is left for the user to push. An invalid value (anything but unset, true or false, or a read that fails) is manual push mode for every reader and is named where it is read (see Fixed). Tests: `lib/gitflow-test.sh` T11b (push-mode verb), T18m and T18q blocks, `lib/tests/unpushed-guard.test.sh` T10-T16, `lib/tests/push-guard.test.sh` (98 checks).
|
- **Manual-push mode**: `git config gitflow.autopush false` (human-set) now stops every push the gitflow lib makes, not only the post-commit / post-merge hooks. `gitflow start` and `finish` branch, commit and merge locally and push nothing; `gitflow delete` leaves the `origin/` copy in place and prints `git push origin --delete <br>` for the user to run. `hooks/unpushed-guard.sh` stays silent at turn end in this mode and opens each session with one `ℹ manual push mode:` line counting the commits no remote holds across every local branch; an unparseable or unreadable `gitflow.autopush` value is treated as manual push mode too, and that line names it. `hooks/push-guard.sh` (PreToolUse, `Bash|Monitor`) refuses any `git push` Claude types while `gitflow.autopush` reads false in the session cwd or in a literal `-C`/`cd` directory the command names (global config counts outside a repo); the refusal tells the user to run it with `! git push`. It reads the mode through the same lib verb as every other reader and fails closed: an unparseable or unreadable value reads as manual, and an internal error, a missing `lib/gitflow.sh`, more than 20 distinct directory tokens in one command (capped before any token is classified), a `cd`/`-C` directory token mixing quoted and unquoted parts, or a payload jq cannot parse whose raw text looks like a push refuse the push (these pathological cases fire in auto mode too). Directory tokens are read as whole shell words, adjacent quoted segments and backslash escapes included. Once the text looks like a push, the command is split into simple commands (quotes, escapes, separators, heredoc bodies dropped) and a push must be git's own subcommand in one of them: `grep "git push"`, `git log -S "git push"`, `git config --get push.default`, `git stash push`, a heredoc quoting a push or a commit message naming one are allowed; `bash -c` scripts are re-checked, wrappers (`sudo`, `env`, `eval`, `xargs`, `timeout`, `git subtree`...) and assignments keep the text verdict. The misses listed in its header fall to a new `autoMode.soft_deny` rule that no request in the turn clears. The session banner adds `🔒 push : manual (autopush=false) — ! git push` when the key reads false, and `🔒 push : manual (autopush bad) — ! git push` when the value is invalid. Skills read the mode through a new lib verb, `bash ~/.claude/lib/gitflow.sh push-mode`: it prints `auto`, `manual` or `invalid` (rc 0) and names an invalid value on stderr (printable characters only, 64 at most). It is the one reader a skill may call, since the `git config` read of the key is denied to Claude. Skills push nothing on their own, except the `/release-candidate` tag in auto-push mode on an explicit go. Every "on origin" or "not pushed" line they print comes from `git rev-list --count origin/<br>..<br>` read after the fact, with the complete `! git …` command when something is left for the user to push. An invalid value (anything but unset, true or false, or a read that fails) is manual push mode for every reader and is named where it is read (see Fixed). Tests: `lib/gitflow-test.sh` T11b (push-mode verb), T18m and T18q blocks, `lib/tests/unpushed-guard.test.sh` T10-T16, `lib/tests/push-guard.test.sh` (98 checks).
|
||||||
|
|
||||||
- **model-router prompt classifier**: a plain prompt typed in the composer (12 characters or more, not a slash command, not mid-turn, never under `-p` or in a sub-agent) that no keyword rule, skill, run slot, `/route` or floor covers is labelled by one call to the engine's small model (`design`, `analysis`, `coding`, `bookkeeping`, `chat`), bounded to 3 s. The label maps to plan, reflect, implement or apply and the turn takes that phase's route: its effort, and its model under the switch and the downgrade cap, never above the session model (an `ultrathink` floor raises the effort only, the guess's model holds); no dialog, no file write, gone at the end of the turn, replaced by any route call or typed skill, and dropped for that turn by a `/effort` typed between turns. Three failures in a row pause it for `cooldownMinutes` (one toast, `classifier: paused` in the status line). `"classify": false` in `~/.claude/model-router.json` and `/route classify on|off` turn it off; `/route show` prints `classify:`. The status line reads `route: classifier <phase>` and `/route verbose on` adds `(<phase>: classifier)`.
|
- **model-router prompt classifier**: a plain prompt typed in the composer (12 characters or more, not a slash command, not mid-turn, never under `-p` or in a sub-agent) that no keyword rule, skill, run slot, `/route` or floor covers is labelled by one call to the engine's small model (`design`, `analysis`, `coding`, `bookkeeping`, `chat`), bounded to 3 s. The label maps to plan, reflect, implement or apply and the turn takes that phase's route: its effort, and its model under the switch and the downgrade cap, never above the session model (an `ultrathink` floor raises the effort only, the guess's model holds); no dialog, no file write, gone at the end of the turn, replaced by any route call or typed skill, and dropped for that turn by a `/effort` typed between turns. Three failures in a row pause it for `cooldownMinutes` (one toast, `classifier: paused` in the status line). `"classify": false` in `~/.claude/model-router.json` and `/route classify on|off` turn it off; `/route show` prints `classify:`. The status line reads `route: classifier <phase>` and `/route verbose on` adds `(<phase>: classifier)`.
|
||||||
@@ -23,6 +23,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/) and this project
|
|||||||
- **Architecture defaults carrier**: `lib/architecture-defaults.md`, read before proposing a stack (new project, scaffolding, stack brainstorm, whole-project rewrite): public sites never SPA, Rust by default, web APIs versioned. Path rules `rules/supabase.md` and `rules/cloud-functions.md` hold the full Supabase and cloud-function domains. Suites `lib/tests/user-rules.test.sh` and `lib/tests/doctor-automem.test.sh`.
|
- **Architecture defaults carrier**: `lib/architecture-defaults.md`, read before proposing a stack (new project, scaffolding, stack brainstorm, whole-project rewrite): public sites never SPA, Rust by default, web APIs versioned. Path rules `rules/supabase.md` and `rules/cloud-functions.md` hold the full Supabase and cloud-function domains. Suites `lib/tests/user-rules.test.sh` and `lib/tests/doctor-automem.test.sh`.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
- **model-router bare `/model` dialog**: 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`). Step 1 asks fable, opus, sonnet or `Other model (native picker)` (the native picker, run with the slot free so a pick inside it asks its scope); step 2 asks Standard or `[1m]`; step 3 is the existing scope question. Esc or free text changes nothing. Tests: `mods/model-router/hooks/register.test.ts`.
|
||||||
- Registries are written only through `lib/memory.sh`, never by Edit (`CLAUDE.global.md`, Memory registries); every CAPITALIZE step (`/feat`, `/bugfix`, `/hotfix`, `/ship-feature`, `/capitalize`, `/init-project`, `/onboard`, `commit-changer`) writes through `lib/capitalize-commit.md` § WRITE.
|
- Registries are written only through `lib/memory.sh`, never by Edit (`CLAUDE.global.md`, Memory registries); every CAPITALIZE step (`/feat`, `/bugfix`, `/hotfix`, `/ship-feature`, `/capitalize`, `/init-project`, `/onboard`, `commit-changer`) writes through `lib/capitalize-commit.md` § WRITE.
|
||||||
- `lib/memory-commit.sh commit` runs `memory.sh check --staged` first: a staged v2 registry that removes or rewrites a line inside an entry, gains a duplicate ID, a bad heading or an open fence, or is deleted or downgraded is unstaged and refused with rc 6; v1 registries are skipped.
|
- `lib/memory-commit.sh commit` runs `memory.sh check --staged` first: a staged v2 registry that removes or rewrites a line inside an entry, gains a duplicate ID, a bad heading or an open fence, or is deleted or downgraded is unstaged and refused with rc 6; v1 registries are skipped.
|
||||||
- `/prune-memory` drops its Index drift category (§ D): status fixes go through `memory.sh status`, merges through `memory.sh add --supersedes`, STEP 4 verifies with `memory.sh check` (`CHECK: OK`, was `INDEX SANITY: OK`).
|
- `/prune-memory` drops its Index drift category (§ D): status fixes go through `memory.sh status`, merges through `memory.sh add --supersedes`, STEP 4 verifies with `memory.sh check` (`CHECK: OK`, was `INDEX SANITY: OK`).
|
||||||
|
|||||||
@@ -136,14 +136,14 @@ effort, never version. Transcript audit `python3 lib/effort-audit.py`.
|
|||||||
|
|
||||||
`mods/model-router/` is a Claude Code mod (a function-hooks plugin) that applies this table per request. It loads in every session through the tracked symlink `skills/model-router`, as `model-router@skills-dir`.
|
`mods/model-router/` is a Claude Code mod (a function-hooks plugin) that applies this table per request. It loads in every session through the tracked symlink `skills/model-router`, as `model-router@skills-dir`.
|
||||||
|
|
||||||
- Main loop: every request gets the route in force. A typed skill with a row routes the main loop to it; a best-tier row (`plan`, `reflect`, `orchestrate`, `escalate`; `audit` is an agent row, never typed) holds across turns in a run slot until `/route clear`, `/route off`, a user `/model` (typed with a name or picked in the `/model` picker, it asks the scope: this project, this conversation, everywhere) or a typed skill on a non-best row. A skill without a row leaves the route as it is. A rowed skill the model loads inside a best-tier run moves effort only when its row ranks below the run's model. Main routed onto a model whose context window the conversation outgrew returns to the session model. Before main runs on a model, the one it moves to or the one it keeps (the session's own model included), the mod probes it with one small completion bounded to 8 seconds; the step (and `/route show`, the route tool's answer) waits for it. A timeout or an error marks the model down (reason `probe`, held for `cooldownMinutes` like any breaker hold) and the decision is taken again once. A model already marked down is never probed, and a model that answered is not probed again, `/clear` included, until it is marked down. When a lower model stands in for its tier's head held down (Opus for Fable on a best-tier phase), the phase's own effort goes one notch up: `reflect` xhigh, `plan` max, `orchestrate` high, `escalate` stays max. An effort asked explicitly (`/route ... effort=`, the `route` tool's `effort`) or set by a floor is never raised. `/route show` and the route tool's answer print the level with `(opus stands in for fable)`; the verbose transition line names `stand-in` as a cause.
|
- Main loop: every request gets the route in force. A typed skill with a row routes the main loop to it; a best-tier row (`plan`, `reflect`, `orchestrate`, `escalate`; `audit` is an agent row, never typed) holds across turns in a run slot until `/route clear`, `/route off`, a user `/model` (typed with a name, bare, or picked in the `/model` picker, it asks the scope: this project, this conversation, everywhere) or a typed skill on a non-best row. A skill without a row leaves the route as it is. A rowed skill the model loads inside a best-tier run moves effort only when its row ranks below the run's model. Main routed onto a model whose context window the conversation outgrew returns to the session model. Before main runs on a model, the one it moves to or the one it keeps (the session's own model included), the mod probes it with one small completion bounded to 8 seconds; the step (and `/route show`, the route tool's answer) waits for it. A timeout or an error marks the model down (reason `probe`, held for `cooldownMinutes` like any breaker hold) and the decision is taken again once. A model already marked down is never probed, and a model that answered is not probed again, `/clear` included, until it is marked down. When a lower model stands in for its tier's head held down (Opus for Fable on a best-tier phase), the phase's own effort goes one notch up: `reflect` xhigh, `plan` max, `orchestrate` high, `escalate` stays max. An effort asked explicitly (`/route ... effort=`, the `route` tool's `effort`) or set by a floor is never raised. `/route show` and the route tool's answer print the level with `(opus stands in for fable)`; the verbose transition line names `stand-in` as a cause.
|
||||||
- Sub-agents: a routed agent gets its row's model at spawn, within its tier and only upward from its frontmatter model, and the row's effort on every step. Explicit `model` / `effort` params on the Agent call win; a project-defined agent of the same name keeps its own definition. Built-ins: Explore runs on sonnet/medium, Plan on opus/xhigh. A built-in `general-purpose` agent that main spawns with no `model` param, while main runs below the session model (a downgrade or a breaker fallback), starts on the session model instead of inheriting the lower one; it is not pinned when the session model is marked down, for a fork, a workflow or a nested spawn, or when a project or user definition shadows the built-in. Other agent types are never pinned this way: the hook cannot see their frontmatter model.
|
- Sub-agents: a routed agent gets its row's model at spawn, within its tier and only upward from its frontmatter model, and the row's effort on every step. Explicit `model` / `effort` params on the Agent call win; a project-defined agent of the same name keeps its own definition. Built-ins: Explore runs on sonnet/medium, Plan on opus/xhigh. A built-in `general-purpose` agent that main spawns with no `model` param, while main runs below the session model (a downgrade or a breaker fallback), starts on the session model instead of inheriting the lower one; it is not pinned when the session model is marked down, for a fork, a workflow or a nested spawn, or when a project or user definition shadows the built-in. Other agent types are never pinned this way: the hook cannot see their frontmatter model.
|
||||||
- Levers inside a run: `ultrathink` in a prompt sets the turn's minimum effort; `/route effort=max` holds until `/route clear`. Keyword prompt rules (`plan`, `design`, `architecture`… take plan's effort; `why`, `review`, `audit`… reflect's), `ultrathink` and a main Agent dispatch (the derived `orchestrate` route, held until its background agents end) set the turn's effort only, never a model: they never lift main above the session model, and a held best-tier run keeps its model. Fable on main comes only from a skill row, the `route` tool, a typed `/route` or a hand pick (`/model`, picker). The built-in `/effort` is not a lever inside a run, rows and routes outrank it.
|
- Levers inside a run: `ultrathink` in a prompt sets the turn's minimum effort; `/route effort=max` holds until `/route clear`. Keyword prompt rules (`plan`, `design`, `architecture`… take plan's effort; `why`, `review`, `audit`… reflect's), `ultrathink` and a main Agent dispatch (the derived `orchestrate` route, held until its background agents end) set the turn's effort only, never a model: they never lift main above the session model, and a held best-tier run keeps its model. Fable on main comes only from a skill row, the `route` tool, a typed `/route` or a hand pick (`/model`, picker). The built-in `/effort` is not a lever inside a run, rows and routes outrank it.
|
||||||
- `/model` scope: a pick in the `/model` picker is held first (the engine prints that a hook blocked it), then the same question as `/model <name>` comes. A pick while another dialog is open is refused with `answer the open dialog first`. The picker's Default, no args, an unknown name or a headless run go native, no question. A model chosen in that dialog (a hand pick) always switches: no cold-read cap, no `mainUpgrade` or `mainModelSwitch` flag. A hand pick marked down keeps main where it is until it is back. A native switch (the `/config` Model row included) or `/clear` drops a hand pick; a typed `/route model=` keeps the caps.
|
- `/model` scope: a pick in the `/model` picker is held first (the engine prints that a hook blocked it), then the same question as `/model <name>` comes. A bare `/model` opens the router's model, variant and scope dialog: fable, opus or sonnet, then Standard or `[1m]`, then the scope, the current model included; `Other model (native picker)` opens the native picker (haiku goes through it or `/model haiku`) and Esc changes nothing. A pick while another dialog is open is refused with `answer the open dialog first`. The picker's Default, an unknown name or a headless run go native, no question. A model chosen in that dialog (a hand pick) always switches: no cold-read cap, no `mainUpgrade` or `mainModelSwitch` flag. A hand pick marked down keeps main where it is until it is back. A native switch (the `/config` Model row included) or `/clear` drops a hand pick; a typed `/route model=` keeps the caps.
|
||||||
- Prompt classifier: a plain prompt typed in the composer (12 characters or more, not a slash command) that no keyword rule, skill, run slot, `/route` or floor covers is sent to the engine's small fast model, one call, bounded to 3 seconds (the prompt waits for it, typically under a second). The label (`design`, `analysis`, `coding`, `bookkeeping`, `chat`) maps to plan, reflect, implement or apply (`chat` routes nothing), and the turn takes that phase's route: its effort becomes the turn's default, and its model may move the main loop, never above the session model. A `coding` or `bookkeeping` guess moves main down only when `mainModelSwitch` is on and the cold read fits `downgradeMaxTokens`; an `ultrathink` floor in the same turn raises the effort only, the guess's model holds. No dialog opens and no file is written. The route is gone at the end of the turn, a later route call or typed skill replaces it, and a `/effort` you type between turns drops the guess for that turn only. A typed best-tier skill holds its run slot across turns, so nothing is classified there until `/route clear`. Long prompts are sampled (first 500 and last 1500 code points), so pasted text at the end can steer one turn's route. Three failures in a row pause it for `cooldownMinutes` (one toast, `classifier: paused` in the status line). Never in a sub-agent, mid-turn or under `-p`. Off per session with `/route classify off`, per machine with `"classify": false`. The status line reads `route: classifier <phase>`; `/route verbose on` adds the transition line.
|
- Prompt classifier: a plain prompt typed in the composer (12 characters or more, not a slash command) that no keyword rule, skill, run slot, `/route` or floor covers is sent to the engine's small fast model, one call, bounded to 3 seconds (the prompt waits for it, typically under a second). The label (`design`, `analysis`, `coding`, `bookkeeping`, `chat`) maps to plan, reflect, implement or apply (`chat` routes nothing), and the turn takes that phase's route: its effort becomes the turn's default, and its model may move the main loop, never above the session model. A `coding` or `bookkeeping` guess moves main down only when `mainModelSwitch` is on and the cold read fits `downgradeMaxTokens`; an `ultrathink` floor in the same turn raises the effort only, the guess's model holds. No dialog opens and no file is written. The route is gone at the end of the turn, a later route call or typed skill replaces it, and a `/effort` you type between turns drops the guess for that turn only. A typed best-tier skill holds its run slot across turns, so nothing is classified there until `/route clear`. Long prompts are sampled (first 500 and last 1500 code points), so pasted text at the end can steer one turn's route. Three failures in a row pause it for `cooldownMinutes` (one toast, `classifier: paused` in the status line). Never in a sub-agent, mid-turn or under `-p`. Off per session with `/route classify off`, per machine with `"classify": false`. The status line reads `route: classifier <phase>`; `/route verbose on` adds the transition line.
|
||||||
- `/route` (user command) shows or sets the route: `show`, `clear`, `off`, `on`, `reload`, `pending` (rows and phases not confirmed yet), `ask on|off` (first-use dialog on or off), `forget <name|all|projects>` (takes decisions back: a changed row returns to its shipped phase; `all` and `projects` ask first), a phase name, `model=<alias|id> effort=<level>`, `switch on|off`, `classify on|off` (the prompt classifier, below), `verbose on|off` (logs transitions only: each change of model or effort, with a few words of cause). `/route show` names the run slot when one holds (`main: run <phase>`) and prints the switch with its cap and the prompt-cache TTL (`switch: on (downgrade, cap 120000 tokens cold, ttl 60 min)`). The model sets routes through a `route` tool.
|
- `/route` (user command) shows or sets the route: `show`, `clear`, `off`, `on`, `reload`, `pending` (rows and phases not confirmed yet), `ask on|off` (first-use dialog on or off), `forget <name|all|projects>` (takes decisions back: a changed row returns to its shipped phase; `all` and `projects` ask first), a phase name, `model=<alias|id> effort=<level>`, `switch on|off`, `classify on|off` (the prompt classifier, below), `verbose on|off` (logs transitions only: each change of model or effort, with a few words of cause). `/route show` names the run slot when one holds (`main: run <phase>`) and prints the switch with its cap and the prompt-cache TTL (`switch: on (downgrade, cap 120000 tokens cold, ttl 60 min)`). The model sets routes through a `route` tool.
|
||||||
- First use: the first time a rowed skill is typed, a rowed agent is spawned or a phase is declared on the main loop through the `route` tool, the mod asks once whether the route is right. The question gives context: the skill's description (first sentence of its `SKILL.md` frontmatter) or the agent's, the phase with its `about` line, and the model id and effort the next step really runs on; a declared phase also says what uses it (rows, prompt rules). A row offers Later, Keep or Change; a declared phase offers Later or Keep. Change asks the model (fable, opus, sonnet, haiku, each shown with the tier it heads), then the effort among those the phases on that model use (shipped table: fable medium, high, xhigh or max; sonnet low, medium, high or xhigh; opus and haiku have one level each, so no question), then Everywhere or This project only. Rows stay phase names, so the pair maps to an existing phase: the row's current phase wins a tie and the same phase counts as Keep; a pair no phase offers needs a new phase added by hand in routing.json. Everywhere moves the row and records the shipped phase under `changed`; This project only stores an exception under `projects`, keyed by the origin remote reduced to `host/path` (no credentials, no local paths; a remote that cannot be read that way offers no project choice). Keep lands under `confirmed`; Later, a dismissed dialog or a free-text answer asks again next session. After a skill row changes, a toast names the model and effort that skill now runs on, plus a hint when the main loop holds back a downgrade: `/route switch on` when the switch is off, the cap hold (`held: downgrade skipped: cold read <n> tokens over <cap>`) when the cold read is over `downgradeMaxTokens`. One dialog at a time, never in a headless (`-p`) run, never inside a sub-agent.
|
- First use: the first time a rowed skill is typed, a rowed agent is spawned or a phase is declared on the main loop through the `route` tool, the mod asks once whether the route is right. The question gives context: the skill's description (first sentence of its `SKILL.md` frontmatter) or the agent's, the phase with its `about` line, and the model id and effort the next step really runs on; a declared phase also says what uses it (rows, prompt rules). A row offers Later, Keep or Change; a declared phase offers Later or Keep. Change asks the model (fable, opus, sonnet, haiku, each shown with the tier it heads), then the effort among those the phases on that model use (shipped table: fable medium, high, xhigh or max; sonnet low, medium, high or xhigh; opus and haiku have one level each, so no question), then Everywhere or This project only. Rows stay phase names, so the pair maps to an existing phase: the row's current phase wins a tie and the same phase counts as Keep; a pair no phase offers needs a new phase added by hand in routing.json. Everywhere moves the row and records the shipped phase under `changed`; This project only stores an exception under `projects`, keyed by the origin remote reduced to `host/path` (no credentials, no local paths; a remote that cannot be read that way offers no project choice). Keep lands under `confirmed`; Later, a dismissed dialog or a free-text answer asks again next session. After a skill row changes, a toast names the model and effort that skill now runs on, plus a hint when the main loop holds back a downgrade: `/route switch on` when the switch is off, the cap hold (`held: downgrade skipped: cold read <n> tokens over <cap>`) when the cold read is over `downgradeMaxTokens`. One dialog at a time, never in a headless (`-p`) run, never inside a sub-agent.
|
||||||
- Only a dialog answer, `/route ask on|off` or `/route forget` writes `routing.json`, never the model. Writes are serialized, capped at 64 KiB, and refused when the file is missing (it is never created). Each write leaves the config repo dirty; a toast reminds you to commit it from there. The one other write: `/model <name>` or a `/model` picker pick → This project writes the full id as `model` into the session root's `.claude/settings.local.json` (created if absent, keep it gitignored; refused when `.claude` or the file is a link, or the file is over 64 KiB or not a JSON object). Remove its `model` key to undo.
|
- Only a dialog answer, `/route ask on|off` or `/route forget` writes `routing.json`, never the model. Writes are serialized, capped at 64 KiB, and refused when the file is missing (it is never created). Each write leaves the config repo dirty; a toast reminds you to commit it from there. The one other write: `/model <name>`, the bare `/model` dialog or a `/model` picker pick → This project writes the full id as `model` into the session root's `.claude/settings.local.json` (created if absent, keep it gitignored; refused when `.claude` or the file is a link, or the file is over 64 KiB or not a JSON object). Remove its `model` key to undo.
|
||||||
- The spinner suffix and the status line under the prompt show the route in force; the status line adds ` · switch off` when the downgrade switch is off.
|
- The spinner suffix and the status line under the prompt show the route in force; the status line adds ` · switch off` when the downgrade switch is off.
|
||||||
|
|
||||||
Config layers: `mods/model-router/routing.json` (tracked: phases with their tier, effort and `about` line, rows, decisions, `ask`), then the optional per-machine `~/.claude/model-router.json`, which wins. A `.claude/model-router.json` inside a project is never read. Machine keys: `models` (alias → full id), `windows` (context window per full id), `tiers` (ordered alias lists per tier: `best` fable>opus>sonnet, `big` opus>fable>sonnet, `work` sonnet>opus, `cheap` haiku>sonnet; the first alias not down is used), `fallback` (the rank order of the aliases, best first, used by the breaker), `cooldownMinutes` (how long a model stays marked down after an availability error, 15 by default, doubling per episode up to 300), `mainUpgrade` (default `true`: the main loop may move up to a phase's tier), `upgradeMaxTokens` (default 200000: the largest cold read a main-loop upgrade may cost), `downgradeMaxTokens` (default 120000: the same cap for a downgrade; the cold read is the context minus what the target model's prompt cache already holds, taken from main's last step on that model within the prompt-cache TTL, forgotten by `/clear` and `/route reload`. The TTL follows the engine's `cache_ttl` (5 or 60 minutes) carried by main's model-switch events, is 60 minutes until the first one and survives `/clear`. The context also counts the prompt just submitted, which the engine's usage may not include yet: code points / 3 of its text, its context entries and a typed skill's body, summed and added at the turn's first main step unless usage already grew by half of it. A `document` attachment makes the size unknown, and an unknown context size blocks the switch; the step, `/route show`, the first-use dialog and the toast read the same adjusted size), `phases`, `agents`, `skills`, `prompt` (rules), `mainModelSwitch` (default `true`: the main loop may move down to a cheaper model; a value that is not a boolean turns it off and says so), `classify` (default `true`; `false` stops the prompt classifier on that machine), `probe` (default `true`: the model main runs on, moved to or kept, is tried once, 8 seconds at most, before main is sent to it; `false` skips the probe on that machine; a non-boolean value is ignored and said; `/route show` prints `probe:`), `verbose` (default `false`; `true` logs transitions only, a non-boolean value falls back to `false`), `spinner` (default `true`), `enabled` (default `true`; `false` turns the mod off on that machine), `ask` (overrides routing.json's `ask` on that machine). A `null` value in `agents` or `skills` drops a row. Edit phases and rows by hand in routing.json (a phase's `about`, 120 characters at most, is read from there only and shown in the dialog; a model and effort pair no phase offers needs a new phase there); without it the mod runs the code's default phases, with no rows and no dialog. `/route reload` re-reads both files.
|
Config layers: `mods/model-router/routing.json` (tracked: phases with their tier, effort and `about` line, rows, decisions, `ask`), then the optional per-machine `~/.claude/model-router.json`, which wins. A `.claude/model-router.json` inside a project is never read. Machine keys: `models` (alias → full id), `windows` (context window per full id), `tiers` (ordered alias lists per tier: `best` fable>opus>sonnet, `big` opus>fable>sonnet, `work` sonnet>opus, `cheap` haiku>sonnet; the first alias not down is used), `fallback` (the rank order of the aliases, best first, used by the breaker), `cooldownMinutes` (how long a model stays marked down after an availability error, 15 by default, doubling per episode up to 300), `mainUpgrade` (default `true`: the main loop may move up to a phase's tier), `upgradeMaxTokens` (default 200000: the largest cold read a main-loop upgrade may cost), `downgradeMaxTokens` (default 120000: the same cap for a downgrade; the cold read is the context minus what the target model's prompt cache already holds, taken from main's last step on that model within the prompt-cache TTL, forgotten by `/clear` and `/route reload`. The TTL follows the engine's `cache_ttl` (5 or 60 minutes) carried by main's model-switch events, is 60 minutes until the first one and survives `/clear`. The context also counts the prompt just submitted, which the engine's usage may not include yet: code points / 3 of its text, its context entries and a typed skill's body, summed and added at the turn's first main step unless usage already grew by half of it. A `document` attachment makes the size unknown, and an unknown context size blocks the switch; the step, `/route show`, the first-use dialog and the toast read the same adjusted size), `phases`, `agents`, `skills`, `prompt` (rules), `mainModelSwitch` (default `true`: the main loop may move down to a cheaper model; a value that is not a boolean turns it off and says so), `classify` (default `true`; `false` stops the prompt classifier on that machine), `probe` (default `true`: the model main runs on, moved to or kept, is tried once, 8 seconds at most, before main is sent to it; `false` skips the probe on that machine; a non-boolean value is ignored and said; `/route show` prints `probe:`), `verbose` (default `false`; `true` logs transitions only, a non-boolean value falls back to `false`), `spinner` (default `true`), `enabled` (default `true`; `false` turns the mod off on that machine), `ask` (overrides routing.json's `ask` on that machine). A `null` value in `agents` or `skills` drops a row. Edit phases and rows by hand in routing.json (a phase's `about`, 120 characters at most, is read from there only and shown in the dialog; a model and effort pair no phase offers needs a new phase there); without it the mod runs the code's default phases, with no rows and no dialog. `/route reload` re-reads both files.
|
||||||
|
|||||||
+7
-2
@@ -43,7 +43,12 @@ relaunch: `ultrathink` in the prompt (turn floor) or `/route effort=max`
|
|||||||
Builtin `/effort` is NOT a lever inside a run: rows and routes outrank it.
|
Builtin `/effort` is NOT a lever inside a run: rows and routes outrank it.
|
||||||
|
|
||||||
`/model <name>` typed, or a pick in the `/model` picker, with a name the
|
`/model <name>` typed, or a pick in the `/model` picker, with a name the
|
||||||
router knows asks the scope (Esc changes nothing). The picker's switch is
|
router knows asks the scope (Esc changes nothing). A bare `/model` asks
|
||||||
|
which model first (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. The
|
||||||
|
picker's switch is
|
||||||
held first: the engine prints that a hook blocked it, then the question
|
held first: the engine prints that a hook blocked it, then the question
|
||||||
comes. This project writes the full id as `model` into
|
comes. This project writes the full id as `model` into
|
||||||
`.claude/settings.local.json` (created if absent: keep it gitignored) and
|
`.claude/settings.local.json` (created if absent: keep it gitignored) and
|
||||||
@@ -51,7 +56,7 @@ sets a sticky model route. This conversation sets the sticky route only,
|
|||||||
nothing written. Everywhere is the native command: user `settings.json`,
|
nothing written. Everywhere is the native command: user `settings.json`,
|
||||||
every project. The two non-native answers drop the run slot like a native
|
every project. The two non-native answers drop the run slot like a native
|
||||||
switch and keep a sticky effort; Everywhere drops an earlier sticky model.
|
switch and keep a sticky effort; Everywhere drops an earlier sticky model.
|
||||||
Picker Default, no args, an unknown name or a run with no surface (`-p`)
|
Picker Default, an unknown name or a run with no surface (`-p`)
|
||||||
go native, no question. A native switch (`/config` Model row included)
|
go native, no question. A native switch (`/config` Model row included)
|
||||||
drops a hand pick. The file is the session root's: in a worktree, that
|
drops a hand pick. The file is the session root's: in a worktree, that
|
||||||
worktree's.
|
worktree's.
|
||||||
|
|||||||
@@ -237,6 +237,10 @@ function installDialog(on: On, w: World): void {
|
|||||||
on('tool.call', { tool: 'AskUserQuestion' }, async (_a, e) => {
|
on('tool.call', { tool: 'AskUserQuestion' }, async (_a, e) => {
|
||||||
const q = (e as unknown as { questions: Rec[] }).questions[0] ?? {}
|
const q = (e as unknown as { questions: Rec[] }).questions[0] ?? {}
|
||||||
const options = (q.options as { label: string }[] | undefined) ?? []
|
const options = (q.options as { label: string }[] | undefined) ?? []
|
||||||
|
// the engine takes 2-4 options: a wider ask fails the suite
|
||||||
|
if (options.length < 2 || options.length > 4) {
|
||||||
|
throw new Error(`AskUserQuestion takes 2-4 options, got ${options.length}`)
|
||||||
|
}
|
||||||
w.asked.push({
|
w.asked.push({
|
||||||
text: String(q.question),
|
text: String(q.question),
|
||||||
options: options.map(o => o.label),
|
options: options.map(o => o.label),
|
||||||
@@ -6306,7 +6310,7 @@ test('model command: Everywhere drops a sticky tier too, keeps effort', async (
|
|||||||
|
|
||||||
test('model command: no dialog for a call native owns', async ($, on) => {
|
test('model command: no dialog for a call native owns', async ($, on) => {
|
||||||
const m = await bootModel($, on, [])
|
const m = await bootModel($, on, [])
|
||||||
const args = ['', 'fable opus', 'default', 'opusplan', 'claude-opus-5-6',
|
const args = ['fable opus', 'default', 'opusplan', 'claude-opus-5-6',
|
||||||
'haiku[1m]', 'whatever']
|
'haiku[1m]', 'whatever']
|
||||||
for (const a of args) expect(await modelCmd($, a)).toBe('native')
|
for (const a of args) expect(await modelCmd($, a)).toBe('native')
|
||||||
expect(m.ran).toEqual(args)
|
expect(m.ran).toEqual(args)
|
||||||
@@ -6315,21 +6319,26 @@ test('model command: no dialog for a call native owns', async ($, on) => {
|
|||||||
|
|
||||||
test('model command: no dialog from another origin', async ($, on) => {
|
test('model command: no dialog from another origin', async ($, on) => {
|
||||||
const m = await bootModel($, on, [])
|
const m = await bootModel($, on, [])
|
||||||
expect(await modelCmd($, 'fable', 'sdk')).toBe('native')
|
for (const a of ['fable', '']) {
|
||||||
|
expect(await modelCmd($, a, 'sdk')).toBe('native')
|
||||||
|
}
|
||||||
expect(m.w.asked).toEqual([])
|
expect(m.w.asked).toEqual([])
|
||||||
|
expect(m.ran).toEqual(['fable', ''])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('model command: no dialog when the router is off', async ($, on) => {
|
test('model command: no dialog when the router is off', async ($, on) => {
|
||||||
const m = await bootModel($, on, [])
|
const m = await bootModel($, on, [])
|
||||||
await route($, 'off')
|
await route($, 'off')
|
||||||
expect(await modelCmd($, 'fable')).toBe('native')
|
for (const a of ['fable', '']) expect(await modelCmd($, a)).toBe('native')
|
||||||
expect(m.w.asked).toEqual([])
|
expect(m.w.asked).toEqual([])
|
||||||
|
expect(m.ran).toEqual(['fable', ''])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('model command: no dialog without a surface', async ($, on) => {
|
test('model command: no dialog without a surface', async ($, on) => {
|
||||||
const m = await bootModel($, on, [], OPUS, { surfaces: [] })
|
const m = await bootModel($, on, [], OPUS, { surfaces: [] })
|
||||||
expect(await modelCmd($, 'fable')).toBe('native')
|
for (const a of ['fable', '']) expect(await modelCmd($, a)).toBe('native')
|
||||||
expect(m.w.asked).toEqual([])
|
expect(m.w.asked).toEqual([])
|
||||||
|
expect(m.ran).toEqual(['fable', ''])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('model command: a second /model while one is open goes native', async (
|
test('model command: a second /model while one is open goes native', async (
|
||||||
@@ -6342,9 +6351,11 @@ test('model command: a second /model while one is open goes native', async (
|
|||||||
const first = modelCmd($, 'fable')
|
const first = modelCmd($, 'fable')
|
||||||
await open.gate
|
await open.gate
|
||||||
expect(await modelCmd($, 'opus')).toBe('native')
|
expect(await modelCmd($, 'opus')).toBe('native')
|
||||||
|
expect(await modelCmd($, '')).toBe('native')
|
||||||
held.release()
|
held.release()
|
||||||
expect(await first).toContain('sticky route')
|
expect(await first).toContain('sticky route')
|
||||||
expect(m.w.asked).toHaveLength(1)
|
expect(m.w.asked).toHaveLength(1)
|
||||||
|
expect(m.ran).toEqual(['opus', ''])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('model command: the question notes a project pin only when set', async (
|
test('model command: the question notes a project pin only when set', async (
|
||||||
@@ -6404,6 +6415,127 @@ for (const scope of ['This conversation', 'This project']) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- bare /model: the router's own dialog ---------------------------------
|
||||||
|
|
||||||
|
const STEP1 = ['fable (best)', 'opus (big)', 'sonnet (work)',
|
||||||
|
'Other model (native picker)']
|
||||||
|
const VARIANTS = ['Standard', '[1m]']
|
||||||
|
const NO_MODEL = 'model: no model chosen, nothing changed'
|
||||||
|
const OPUS_1M = `${OPUS}[1m]`
|
||||||
|
|
||||||
|
test('bare model: step 1 lists the table and the native picker', async (
|
||||||
|
$, on) => {
|
||||||
|
const m = await bootModel($, on, [])
|
||||||
|
expect(await modelCmd($, '')).toBe(NO_MODEL)
|
||||||
|
const [q] = m.w.asked as [Asked]
|
||||||
|
expect(q.options).toEqual(STEP1)
|
||||||
|
expect(q.header).toBe('model-router')
|
||||||
|
expect(q.text).toContain(OPUS)
|
||||||
|
expect(q.text.endsWith('Which model?')).toBe(true)
|
||||||
|
expect(m.ran).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('bare model: opus, [1m], This project writes the full id', async (
|
||||||
|
$, on) => {
|
||||||
|
const m = await bootModel($, on,
|
||||||
|
['opus (big)', '[1m]', 'This project'])
|
||||||
|
await modelCmd($, '')
|
||||||
|
expect(m.w.asked.map(q => q.options)).toEqual([STEP1, VARIANTS, SCOPES])
|
||||||
|
const variant = m.w.asked[1] as Asked
|
||||||
|
expect(variant.text.endsWith('Which variant of opus?')).toBe(true)
|
||||||
|
expect(localOf(m.w).model).toBe(OPUS_1M)
|
||||||
|
expect(m.ran).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('bare model: the current model asks its scope too', async ($, on) => {
|
||||||
|
const m = await bootModel($, on,
|
||||||
|
['opus (big)', 'Standard', 'This conversation'])
|
||||||
|
expect(await modelCmd($, '')).toContain(`sticky route ${OPUS}`)
|
||||||
|
expect(m.w.asked).toHaveLength(3)
|
||||||
|
expect(m.ran).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('bare model: Other model runs native with empty args, no scope', async (
|
||||||
|
$, on) => {
|
||||||
|
const m = await bootModel($, on, ['Other model (native picker)'])
|
||||||
|
expect(await modelCmd($, '')).toBe('native')
|
||||||
|
expect(m.ran).toEqual([''])
|
||||||
|
expect(m.w.asked).toHaveLength(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('bare model: a pick inside the native picker asks, never BUSY', async (
|
||||||
|
$, on) => {
|
||||||
|
const ran: string[] = []
|
||||||
|
const outs: unknown[] = []
|
||||||
|
on('command.run', { command: 'model' }, async (_a, e) => {
|
||||||
|
ran.push(e.args)
|
||||||
|
outs.push(await pick($, SONNET))
|
||||||
|
return { text: 'native' }
|
||||||
|
})
|
||||||
|
const toasts = recordToasts(on)
|
||||||
|
const w = newWorld({ answers: ['Other model (native picker)', 'Later'] })
|
||||||
|
const rig = await bootRig($, on, OPUS, 1000, w)
|
||||||
|
expect(await modelCmd($, '')).toBe('native')
|
||||||
|
expect(JSON.stringify(outs)).toContain(DENY)
|
||||||
|
await rig.clock.advance(300)
|
||||||
|
await settle(() => w.asked.length > 1)
|
||||||
|
expect(w.asked[1]?.options).toEqual(SCOPES)
|
||||||
|
expect(toasts).toEqual([])
|
||||||
|
expect(ran).toEqual([''])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('bare model: Esc at step 1 or 2 changes nothing', async ($, on) => {
|
||||||
|
const m = await bootModel($, on, [REJECT, 'sonnet (work)', REJECT])
|
||||||
|
expect(await modelCmd($, '')).toBe(NO_MODEL)
|
||||||
|
expect(m.w.asked).toHaveLength(1)
|
||||||
|
expect(await modelCmd($, '')).toBe(NO_MODEL)
|
||||||
|
expect(m.w.asked).toHaveLength(3)
|
||||||
|
expect(m.ran).toEqual([])
|
||||||
|
expect(m.w.written).toEqual([])
|
||||||
|
expect(mainLine(await route($, 'show'))).toContain('session defaults')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('bare model: Everywhere runs native with the token', async ($, on) => {
|
||||||
|
const m = await bootModel($, on, ['sonnet (work)', 'Standard',
|
||||||
|
'Everywhere', 'sonnet (work)', '[1m]', 'Everywhere'])
|
||||||
|
await modelCmd($, '')
|
||||||
|
await modelCmd($, '')
|
||||||
|
expect(m.ran).toEqual(['sonnet', 'sonnet[1m]'])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('bare model: [1m] with This conversation carries the note', async (
|
||||||
|
$, on) => {
|
||||||
|
await bootModel($, on, ['fable (best)', '[1m]', 'This conversation'])
|
||||||
|
expect(await modelCmd($, '')).toContain("[1m] follows the session's variant")
|
||||||
|
})
|
||||||
|
|
||||||
|
test('bare model: a native throw is reported, native runs once', async (
|
||||||
|
$, on) => {
|
||||||
|
const ran: string[] = []
|
||||||
|
on('command.run', { command: 'model' }, (_a, e) => {
|
||||||
|
ran.push(e.args)
|
||||||
|
throw new Error('boom')
|
||||||
|
})
|
||||||
|
await bootRig($, on, OPUS, 1000,
|
||||||
|
newWorld({ answers: ['Other model (native picker)'] }))
|
||||||
|
const out = await modelCmd($, '')
|
||||||
|
expect(out).toContain('model: native picker failed (')
|
||||||
|
expect(out).not.toContain('boom')
|
||||||
|
expect(ran).toEqual([''])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('kit: an AskUserQuestion of 5 options is refused', async ($, on) => {
|
||||||
|
await bootModel($, on, ['x'])
|
||||||
|
const labels = ['a', 'b', 'c', 'd', 'e']
|
||||||
|
await expect($.tool.call({
|
||||||
|
tool: 'AskUserQuestion',
|
||||||
|
questions: [{
|
||||||
|
question: 'q?', header: 'h', multiSelect: false,
|
||||||
|
options: labels.map(label => ({ label, description: label })),
|
||||||
|
}],
|
||||||
|
} as never)).rejects.toThrow()
|
||||||
|
})
|
||||||
|
|
||||||
test('writes: kit: only the project settings.local.json is carved out', {
|
test('writes: kit: only the project settings.local.json is carved out', {
|
||||||
plugins: [PROBE],
|
plugins: [PROBE],
|
||||||
}, async ($, on) => {
|
}, async ($, on) => {
|
||||||
|
|||||||
@@ -202,6 +202,11 @@ const MODEL_SCOPES: readonly string[] = [
|
|||||||
PROJECT_SCOPE, CONVERSATION, EVERYWHERE,
|
PROJECT_SCOPE, CONVERSATION, EVERYWHERE,
|
||||||
]
|
]
|
||||||
const NO_SCOPE = 'model: no scope chosen, nothing changed'
|
const NO_SCOPE = 'model: no scope chosen, nothing changed'
|
||||||
|
const NATIVE_PICKER = 'Other model (native picker)'
|
||||||
|
const NO_MODEL = 'model: no model chosen, nothing changed'
|
||||||
|
const BARE_ALIASES: readonly string[] = ['fable', 'opus', 'sonnet']
|
||||||
|
const STANDARD = 'Standard'
|
||||||
|
const LONG = '[1m]'
|
||||||
const LOCAL_SETTINGS = '.claude/settings.local.json'
|
const LOCAL_SETTINGS = '.claude/settings.local.json'
|
||||||
const CHOICE_ALIASES: readonly string[] = ['fable', 'opus', 'sonnet', 'haiku']
|
const CHOICE_ALIASES: readonly string[] = ['fable', 'opus', 'sonnet', 'haiku']
|
||||||
const MAX_DESC = 140 // chars of a skill or agent description in a question
|
const MAX_DESC = 140 // chars of a skill or agent description in a question
|
||||||
@@ -2118,8 +2123,9 @@ async function handleCommand($: Api, st: State, args: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- /model <name>: the scope of a switch ---------------------------------
|
// ---- /model: the scope of a switch ----------------------------------------
|
||||||
// A typed `/model <name>` of a model the table knows asks where it applies.
|
// A typed `/model <name>` of a model the table knows asks where it applies;
|
||||||
|
// a bare `/model` opens the router's dialog (model, variant, then scope).
|
||||||
// Everywhere is the native command (user settings.json); the two others set
|
// Everywhere is the native command (user settings.json); the two others set
|
||||||
// a sticky model route, This project also pins `model` in the project's
|
// a sticky model route, This project also pins `model` in the project's
|
||||||
// settings.local.json. Fail-open to native only before an answer.
|
// settings.local.json. Fail-open to native only before an answer.
|
||||||
@@ -2345,6 +2351,49 @@ async function scopeDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bare `/model` dialog: which model, which variant, then the scope.
|
||||||
|
* Returns 'native' when the user picks the native picker.
|
||||||
|
*/
|
||||||
|
async function bareModelDialog(
|
||||||
|
$: Api,
|
||||||
|
st: State,
|
||||||
|
e: CommandRunInput,
|
||||||
|
next: ModelNext,
|
||||||
|
): Promise<CommandRunResult | 'native'> {
|
||||||
|
const labels = BARE_ALIASES.map(a => modelLabel(st.cfg, a))
|
||||||
|
const session = clean(st.sessionModel || 'unknown', 60)
|
||||||
|
const model = await askOr($, `Session: ${session}\nWhich model?`,
|
||||||
|
[...labels, NATIVE_PICKER])
|
||||||
|
if (model === NATIVE_PICKER) return 'native'
|
||||||
|
const alias = BARE_ALIASES[labels.indexOf(model)]
|
||||||
|
if (alias === undefined) return { text: NO_MODEL }
|
||||||
|
const variant = await askOr($,
|
||||||
|
`${STANDARD}: standard context · ${LONG}: 1M context (a conversation ` +
|
||||||
|
`route follows the session's variant)\nWhich variant of ${alias}?`,
|
||||||
|
[STANDARD, LONG])
|
||||||
|
if (variant !== STANDARD && variant !== LONG) return { text: NO_MODEL }
|
||||||
|
const token = variant === LONG ? `${alias}${LONG}` : alias
|
||||||
|
return scopeDialog($, st, token,
|
||||||
|
{ everywhere: () => next({ ...e, args: token }),
|
||||||
|
warnKey: 'command.run model' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Native after the dialog slot is free: a pick inside it asks its scope. */
|
||||||
|
async function nativePicker(
|
||||||
|
$: Api,
|
||||||
|
st: State,
|
||||||
|
e: CommandRunInput,
|
||||||
|
next: ModelNext,
|
||||||
|
): Promise<CommandRunResult> {
|
||||||
|
try {
|
||||||
|
return await next(e)
|
||||||
|
} catch (err) {
|
||||||
|
warnOnce(st, $, 'command.run model', errWord(err))
|
||||||
|
return { text: `model: native picker failed (${errWord(err)})` }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleModelCommand(
|
async function handleModelCommand(
|
||||||
$: Api,
|
$: Api,
|
||||||
st: State,
|
st: State,
|
||||||
@@ -2354,18 +2403,23 @@ async function handleModelCommand(
|
|||||||
await ensureConfig($, st)
|
await ensureConfig($, st)
|
||||||
const tokens = e.args.trim().split(/\s+/)
|
const tokens = e.args.trim().split(/\s+/)
|
||||||
const token = tokens[0] ?? ''
|
const token = tokens[0] ?? ''
|
||||||
|
const bare = token === ''
|
||||||
if (st.off || e.origin.kind !== 'composer' || tokens.length !== 1 ||
|
if (st.off || e.origin.kind !== 'composer' || tokens.length !== 1 ||
|
||||||
!knownModel(st.cfg, token) ||
|
(!bare && !knownModel(st.cfg, token)) ||
|
||||||
(await $.session.surfaces()).length === 0 || st.asking !== null) {
|
(await $.session.surfaces()).length === 0 || st.asking !== null) {
|
||||||
return next(e)
|
return next(e)
|
||||||
}
|
}
|
||||||
st.asking = `model:${token}`
|
st.asking = `model:${token}`
|
||||||
|
let out: CommandRunResult | 'native'
|
||||||
try {
|
try {
|
||||||
return await scopeDialog($, st, token,
|
out = bare
|
||||||
{ everywhere: () => next(e), warnKey: 'command.run model' })
|
? await bareModelDialog($, st, e, next)
|
||||||
|
: await scopeDialog($, st, token,
|
||||||
|
{ everywhere: () => next(e), warnKey: 'command.run model' })
|
||||||
} finally {
|
} finally {
|
||||||
st.asking = null
|
st.asking = null
|
||||||
}
|
}
|
||||||
|
return out === 'native' ? nativePicker($, st, e, next) : out
|
||||||
}
|
}
|
||||||
|
|
||||||
// The /model picker: the engine draws nothing while a PreModelSwitch hook
|
// The /model picker: the engine draws nothing while a PreModelSwitch hook
|
||||||
|
|||||||
Reference in new issue
Block a user