cc-switchboard 0.0.0-stage → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "switchboard",
3
+ "owner": {
4
+ "name": "Siamak Rostami"
5
+ },
6
+ "plugins": [
7
+ {
8
+ "name": "switchboard",
9
+ "source": "./",
10
+ "description": "Automatic model routing for Claude Code with saved setups."
11
+ }
12
+ ],
13
+ "description": "Switchboard: automatic model routing for Claude Code with saved setups."
14
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "switchboard",
3
+ "description": "Per-turn model routing for Claude Code: each prompt runs on the right model and effort (Fable plans and reviews, Opus does hard code and UI, Sonnet does regular code and writing, Haiku does chores), with a band above the prompt and a /router pane.",
4
+ "version": "0.2.10",
5
+ "author": {
6
+ "name": "Siamak Rostami"
7
+ },
8
+ "repository": "https://github.com/siamakrostami/ClaudeModelRouter",
9
+ "license": "MIT",
10
+ "keywords": [
11
+ "model",
12
+ "routing",
13
+ "subagents",
14
+ "fable",
15
+ "opus",
16
+ "sonnet",
17
+ "haiku"
18
+ ],
19
+ "homepage": "https://github.com/siamakrostami/ClaudeModelRouter",
20
+ "types": "./types/index.d.ts"
21
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Siamak Rostami
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,87 @@
1
- # Temporary Holding Version
1
+ # Switchboard
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/cc-switchboard.svg)](https://www.npmjs.com/package/cc-switchboard)
4
+ [![node](https://img.shields.io/node/v/cc-switchboard.svg)](https://nodejs.org)
5
+ [![license](https://img.shields.io/npm/l/cc-switchboard.svg)](LICENSE)
6
+
7
+ Per-turn model routing for Claude Code. You type your request as usual, and Switchboard
8
+ sends that turn to the model and effort that suit it:
9
+
10
+ | Role | Handles | Default |
11
+ |---|---|---|
12
+ | plan | planning, architecture, big decisions | Fable · xhigh |
13
+ | review | code review | Fable · high |
14
+ | hard | hard code, UI, debugging | Opus · high |
15
+ | code | regular code, tests, refactors | Sonnet · medium |
16
+ | write | PR descriptions, Slack, docs, tickets | Sonnet · medium |
17
+ | chores | git, renames, formatting, lookups, commit messages | Haiku · low |
18
+
19
+ A prompt that matches no role stays on your main model.
20
+
21
+ ## How it works
22
+
23
+ Switchboard is a Claude Code mod:
24
+
25
+ - **`prompt.submit`** sorts the prompt into a role with keyword rules.
26
+ - **`turn.step`** sends every main-chat request of that turn with the role's model and
27
+ effort. Nothing goes through a proxy or a helper agent, and subagents are left alone.
28
+ - **The band above the prompt** shows the model, an effort meter, the role, and why it was
29
+ picked:
30
+
31
+ ```
32
+ ▮▮▮▯▯ Opus · high hard ← debug default Router
33
+ ```
34
+
35
+ - **`/router`** opens a pane:
36
+ - **Now**: this turn's route, a pin, and a setup picker.
37
+ - **Setups**: the model and effort for each role, plus save as.
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ npm install -g cc-switchboard
43
+ claude plugin marketplace add "$(npm root -g)/cc-switchboard"
44
+ claude plugin install switchboard@switchboard
45
+ ```
46
+
47
+ From a clone instead: `npm install && npm link`, then `claude plugin marketplace add "$PWD"`
48
+ and the same `claude plugin install` line. Needs Claude Code 2.1.330 or newer.
49
+
50
+ Set your main model to Fable (`"model": "fable"` in `~/.claude/settings.json`).
51
+
52
+ ## Use
53
+
54
+ Just type. To steer one prompt, include one of these:
55
+
56
+ - `#plan` `#review` `#hard` `#code` `#write` `#chores`: force a role
57
+ - `@fable` `@opus` `@sonnet` `@haiku`, or "use haiku for this": force a model
58
+ - `#self` or "do it yourself": stay on the main model
59
+
60
+ In a session:
61
+
62
+ - `/router`: open the pane
63
+ - `/router hard`: pin every turn to one role; `/router auto` unpins
64
+ - `/router off` / `/router on`: pause or resume this session
65
+
66
+ If you switch models yourself with `/model`, Switchboard steps aside until you switch back
67
+ to the main model (set `main_model` in `setups.json` if yours is not Fable).
68
+
69
+ From a terminal:
70
+
71
+ ```bash
72
+ switchboard # full-screen setup picker
73
+ switchboard show | list
74
+ switchboard set code opus high
75
+ switchboard save fast # save the current setup under a name
76
+ switchboard use default
77
+ switchboard off | on # everywhere
78
+ ```
79
+
80
+ Data lives in `~/.claude/switchboard/`: `setups.json`, and `rules.json` (keyword regexes,
81
+ which you can edit).
82
+
83
+ ## Test
84
+
85
+ ```bash
86
+ npm test
87
+ ```
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../src/cli.js';
3
+
4
+ process.exitCode = await main(process.argv.slice(2));
@@ -0,0 +1,79 @@
1
+ import { DEFAULT_RULES, DEFAULT_SETUP, EFFORTS, MODELS, ROLES } from '../src/core/defaults.js'
2
+
3
+ import type { Config, Setup } from '../types'
4
+
5
+ export const MODEL_COLOR: Record<string, string> = {
6
+ fable: '#C084FC',
7
+ opus: '#F59E0B',
8
+ sonnet: '#22D3EE',
9
+ haiku: '#4ADE80',
10
+ }
11
+ export const MODEL_NAME: Record<string, string> = { fable: 'Fable', opus: 'Opus', sonnet: 'Sonnet', haiku: 'Haiku' }
12
+ export const ROLE_LIST: readonly string[] = ROLES
13
+ export const MODEL_LIST: readonly string[] = MODELS
14
+ export const EFFORT_LIST: readonly string[] = EFFORTS
15
+
16
+ export function family(model: string | undefined) {
17
+ return /(fable|opus|sonnet|haiku)/i.exec(model ?? '')?.[1]?.toLowerCase() ?? ''
18
+ }
19
+
20
+ export function meter(effort: string) {
21
+ const level = Math.max(0, EFFORT_LIST.indexOf(effort)) + 1
22
+ return { on: '●'.repeat(level), off: '○'.repeat(EFFORT_LIST.length - level) }
23
+ }
24
+
25
+ function fill(setup: any): Setup {
26
+ const out: Setup = {}
27
+ for (const r of ROLE_LIST) {
28
+ const s = setup && typeof setup[r] === 'object' ? setup[r] : {}
29
+ out[r] = {
30
+ model: MODEL_LIST.includes(s.model) ? s.model : (DEFAULT_SETUP as any)[r].model,
31
+ effort: EFFORT_LIST.includes(s.effort) ? s.effort : (DEFAULT_SETUP as any)[r].effort,
32
+ }
33
+ }
34
+ return out
35
+ }
36
+
37
+ export async function home($: any) {
38
+ const custom = await $.env.get('SWITCHBOARD_HOME')
39
+ return custom || `${await $.env.get('HOME')}/.claude/switchboard`
40
+ }
41
+
42
+ export async function readJson($: any, path: string) {
43
+ try {
44
+ return JSON.parse(await $.fs.read(path))
45
+ } catch {
46
+ return null
47
+ }
48
+ }
49
+
50
+ /** Read setups.json and rules.json (same files the switchboard CLI edits), filling defaults. */
51
+ export async function loadConfig($: any): Promise<Config> {
52
+ const dir = await home($)
53
+ const raw = (await readJson($, `${dir}/setups.json`)) || {}
54
+ const setups: Record<string, Setup> = {}
55
+ for (const [name, s] of Object.entries<any>(raw.setups || {})) setups[name] = fill(s)
56
+ if (!Object.keys(setups).length) setups.default = fill(null)
57
+ const active = typeof raw.active === 'string' && setups[raw.active] ? raw.active : Object.keys(setups)[0]
58
+ const rulesRaw = (await readJson($, `${dir}/rules.json`)) || {}
59
+ const rules: Record<string, string[]> = {}
60
+ for (const r of ROLE_LIST) {
61
+ const v = rulesRaw[r]
62
+ rules[r] = Array.isArray(v) && v.every((x: unknown) => typeof x === 'string') ? v : (DEFAULT_RULES as any)[r]
63
+ }
64
+ return {
65
+ active,
66
+ enabled: raw.enabled !== false,
67
+ mainModel: MODEL_LIST.includes(raw.main_model) ? raw.main_model : 'fable',
68
+ setups,
69
+ rules,
70
+ }
71
+ }
72
+
73
+ /** Write setups.json back in the CLI's format, keeping keys the mod does not know. */
74
+ export async function saveConfig($: any, cfg: Config) {
75
+ const dir = await home($)
76
+ const raw = (await readJson($, `${dir}/setups.json`)) || {}
77
+ const out = { ...raw, active: cfg.active, enabled: cfg.enabled, main_model: cfg.mainModel, setups: cfg.setups }
78
+ await $.fs.write(`${dir}/setups.json`, JSON.stringify(out, null, 2) + '\n')
79
+ }
@@ -0,0 +1 @@
1
+ { "modules": ["./switchboard.tsx"] }
@@ -0,0 +1,417 @@
1
+ import { atom, read, update } from 'claude-code'
2
+ import type { Register } from 'claude-code'
3
+
4
+ import { classify } from '../src/core/classify.js'
5
+ import type { Config, Live, Route, Setup } from '../types'
6
+ import {
7
+ EFFORT_LIST,
8
+ MODEL_COLOR,
9
+ MODEL_LIST,
10
+ MODEL_NAME,
11
+ ROLE_LIST,
12
+ family,
13
+ loadConfig,
14
+ meter,
15
+ saveConfig,
16
+ } from './config'
17
+
18
+ const PANE = 'switchboard'
19
+
20
+ const config = atom({ plugin: 'switchboard', key: 'config' } as const, null, { shape: 'config-1' })
21
+ const route = atom({ plugin: 'switchboard', key: 'route' } as const, null, { shape: 'route-1' })
22
+ const live = atom({ plugin: 'switchboard', key: 'live' } as const, null, { shape: 'live-1' })
23
+ const paused = atom({ plugin: 'switchboard', key: 'paused' } as const, false)
24
+ const manual = atom({ plugin: 'switchboard', key: 'manual' } as const, null)
25
+ const pin = atom({ plugin: 'switchboard', key: 'pin' } as const, null)
26
+ const place = atom({ plugin: 'switchboard', key: 'place' } as const, null)
27
+ const base = atom({ plugin: 'switchboard', key: 'base' } as const, null)
28
+ const tab = atom({ plugin: 'switchboard', key: 'tab' } as const, 'now')
29
+
30
+ async function reload($: any) {
31
+ const cfg = await loadConfig($)
32
+ await update($, config, () => cfg)
33
+ return cfg
34
+ }
35
+
36
+ /** Change the config, save it to setups.json and keep the atom in step. */
37
+ async function edit($: any, fn: (cfg: Config) => Config) {
38
+ const cfg = fn(structuredClone((await read($, config)) ?? (await loadConfig($))))
39
+ await saveConfig($, cfg)
40
+ await update($, config, () => cfg)
41
+ }
42
+
43
+ /** Decide this turn's route from the prompt, a pin, or nothing (stay on the session's model). */
44
+ async function decide($: any, text: string) {
45
+ const cfg = await reload($)
46
+ const sessionModel = family(String(await $.session.model()))
47
+ // Manual only when the model was changed with /model after the session started.
48
+ const started = await read($, base)
49
+ if (!started && sessionModel) await update($, base, () => sessionModel)
50
+ const isManual = sessionModel !== '' && !!started && sessionModel !== started
51
+ await update($, manual, () => (isManual ? sessionModel : null))
52
+ if (!cfg.enabled || isManual || (await read($, paused))) return null
53
+ const setup = cfg.setups[cfg.active]
54
+ const pinned = await read($, pin)
55
+ if (pinned && MODEL_LIST.includes(pinned)) {
56
+ // Pinned to a model: use the effort of the first task that runs on it.
57
+ const role = ROLE_LIST.find(r => setup[r]?.model === pinned) ?? 'code'
58
+ const effort = setup[role]?.model === pinned ? setup[role].effort : 'high'
59
+ return { role, model: pinned, effort, why: '', source: 'pin' } as Route
60
+ }
61
+ const r = classify(text, cfg.rules, setup)
62
+ if (!r) return null
63
+ return { role: r.role, model: r.model, effort: r.effort, why: r.why, source: r.forced ? 'override' : 'auto' } as Route
64
+ }
65
+
66
+ /** Turn routing on or off from the pane. On also clears a saved "enabled: false". */
67
+ async function power($: any, turnOn: boolean) {
68
+ await update($, paused, () => !turnOn)
69
+ if (turnOn && (await read($, config))?.enabled === false) await edit($, c => ({ ...c, enabled: true }))
70
+ }
71
+
72
+ /** Set one task's model or effort in the active setup. */
73
+ async function setSlot($: any, role: string, field: 'model' | 'effort', value: string) {
74
+ await edit($, c => {
75
+ const setup = c.setups[c.active]
76
+ const slot = setup?.[role]
77
+ if (!setup || !slot) return c
78
+ return { ...c, setups: { ...c.setups, [c.active]: { ...setup, [role]: { ...slot, [field]: value } } } }
79
+ })
80
+ }
81
+
82
+ type Mode = 'auto' | 'pinned' | 'main' | 'manual' | 'off'
83
+
84
+ /** What the band and the pane both need: what this turn runs on, and in which mode. */
85
+ function status(cfg: Config, r: Route | null, l: Live | null, isPaused: boolean, man: string | null) {
86
+ const mode: Mode = isPaused || !cfg.enabled ? 'off' : man ? 'manual' : r ? (r.source === 'pin' ? 'pinned' : 'auto') : 'main'
87
+ const routed = mode === 'auto' || mode === 'pinned'
88
+ const idle = l ?? { model: cfg.mainModel, effort: cfg.setups[cfg.active]?.plan?.effort ?? '' }
89
+ const shown = mode === 'manual' ? { model: man as string, effort: l?.effort ?? '' } : routed && r ? { model: r.model, effort: r.effort } : idle
90
+ return {
91
+ mode,
92
+ model: shown.model,
93
+ effort: shown.effort,
94
+ role: routed && r ? r.role : '',
95
+ why: mode === 'auto' && r?.why ? r.why : '',
96
+ }
97
+ }
98
+
99
+ /** Display form of a task, mode or effort word: Plan, Manual, High. */
100
+ const cap = (w: string) => (w ? w[0].toUpperCase() + w.slice(1) : w)
101
+ const EFFORT_LABEL: Record<string, string> = { low: 'Low', medium: 'Medium', high: 'High', xhigh: 'X-High', max: 'Max' }
102
+ const effortLabel = (w: string) => EFFORT_LABEL[w] ?? cap(w)
103
+
104
+ /** The one-line route: meter, model, effort, then the task or the mode. Never wraps. */
105
+ function routeLine(Text: any, s: ReturnType<typeof status>, showEffort = true) {
106
+ const off = s.mode === 'off'
107
+ const color = off ? undefined : MODEL_COLOR[s.model] ?? 'gray'
108
+ const m = meter(s.effort)
109
+ return (
110
+ <Text wrap="truncate-end">
111
+ <Text color={color} dimColor={off}>{m.on}</Text>
112
+ <Text dimColor>{m.off}</Text>
113
+ <Text color={color} dimColor={off} bold={!off}> {MODEL_NAME[s.model] ?? s.model}</Text>
114
+ {s.effort && showEffort ? <Text dimColor> · {effortLabel(s.effort)}</Text> : null}
115
+ {s.mode === 'pinned' ? <Text dimColor>{' '}Pinned</Text> : null}
116
+ {s.mode === 'manual' ? <Text color="warning">{' '}Manual</Text> : null}
117
+ {off ? <Text dimColor>{' '}Off</Text> : null}
118
+ </Text>
119
+ )
120
+ }
121
+
122
+ /** Context use as a bar, coloured green → amber → red, always shown with its percentage. */
123
+ function gauge(pct: number, width: number) {
124
+ const filled = Math.max(0, Math.min(width, Math.round((pct / 100) * width)))
125
+ const color = pct >= 80 ? '#F87171' : pct >= 60 ? '#F59E0B' : '#4ADE80'
126
+ return { on: '▰'.repeat(filled), off: '▱'.repeat(width - filled), color }
127
+ }
128
+
129
+ /** Context use as a circle that fills by quarters, coloured by level; always shown with its percentage. */
130
+ function ring(pct: number) {
131
+ const glyph = pct < 13 ? '○' : pct < 38 ? '◔' : pct < 63 ? '◑' : pct < 88 ? '◕' : '●'
132
+ return { glyph, color: gauge(pct, 1).color }
133
+ }
134
+
135
+ /** Open the pane on one of its tabs. */
136
+ async function openPane($: any, which: 'now' | 'routes') {
137
+ await update($, tab, () => which)
138
+ await $.ui.open({ id: PANE, title: 'Switchboard' })
139
+ }
140
+
141
+ /**
142
+ * Pad a dropdown label so every dropdown in a column is the same width (Select has no width
143
+ * prop). Terminal: plain spaces to the longest label. Desktop: figure spaces, tuned to the
144
+ * app's proportional font.
145
+ */
146
+ const DESKTOP_PAD: Record<string, number> = { Fable: 2, Opus: 2, Sonnet: 0, Haiku: 2, Low: 3, Medium: 0, High: 3, 'X-High': 0, Max: 3 }
147
+ function padLabel(label: string, all: readonly string[], surface: string) {
148
+ if (surface === 'terminal') return label.padEnd(Math.max(...all.map(x => x.length)), ' ')
149
+ return label + '\u2007'.repeat(DESKTOP_PAD[label] ?? 0)
150
+ }
151
+
152
+ /** Project, branch and context percentage for the band. Each part is best effort. */
153
+ async function where($: any) {
154
+ const root = String(await $.session.root())
155
+ const project = root.split('/').filter(Boolean).pop() ?? root
156
+ const copy = await $.vcs.detect({ path: root }).catch(() => null)
157
+ const usage = await $.session.usage().catch(() => null)
158
+ const pct = usage?.context?.percent
159
+ const value: Place = { project, branch: copy?.branch ?? null, ctx: typeof pct === 'number' ? pct : null }
160
+ await update($, place, () => value)
161
+ }
162
+
163
+ export const register: Register = on => {
164
+ on('session.start', async ($, e, next) => {
165
+ await $.command.register({ name: 'router', description: 'Switchboard settings: models per task, setups, pause (also: /router off|on|auto|<task>)' })
166
+ await update($, route, () => null)
167
+ await reload($).catch(() => {})
168
+ await where($).catch(() => {})
169
+ const startModel = family(String(await $.session.model().catch(() => '')))
170
+ await update($, base, () => startModel || null)
171
+ await update($, manual, () => null)
172
+ return next(e)
173
+ })
174
+
175
+ on('command.run', { command: 'router' }, async ($, e) => {
176
+ const arg = e.args.trim().toLowerCase()
177
+ if (arg === 'off' || arg === 'pause') {
178
+ await update($, paused, () => true)
179
+ return { text: 'Switchboard paused for this session.' }
180
+ }
181
+ if (arg === 'on' || arg === 'resume') {
182
+ await update($, paused, () => false)
183
+ return { text: 'Switchboard routing on.' }
184
+ }
185
+ if (arg === 'auto') {
186
+ await update($, pin, () => null)
187
+ return { text: 'Switchboard: back to automatic routing.' }
188
+ }
189
+ if (MODEL_LIST.includes(arg)) {
190
+ await update($, pin, () => arg)
191
+ return { text: `Switchboard: every turn uses ${MODEL_NAME[arg]}. /router auto to undo.` }
192
+ }
193
+ await reload($).catch(() => {})
194
+ await $.ui.open({ id: PANE, title: 'Switchboard' })
195
+ return { text: 'Switchboard pane opened.' }
196
+ })
197
+
198
+ on('turn.complete', async ($, e, next) => {
199
+ const r = await next(e)
200
+ if (!e.agentId) await where($).catch(() => {})
201
+ return r
202
+ })
203
+
204
+ on('prompt.submit', async ($, e, next) => {
205
+ if (!e.agentId) await where($).catch(() => {})
206
+ if (e.agentId || e.command) return next(e)
207
+ const r = await decide($, e.text).catch(() => null)
208
+ await update($, route, () => r)
209
+ return next(e)
210
+ })
211
+
212
+ on('turn.step', async function* ($, e, next) {
213
+ if (e.agentId) return yield* next(e)
214
+ const r = await read($, route)
215
+ if (!r) {
216
+ const sent: Live = { model: family(e.model), effort: typeof e.effort === 'string' ? e.effort : '' }
217
+ await update($, live, () => sent)
218
+ return yield* next(e)
219
+ }
220
+ await update($, live, () => ({ model: r.model, effort: r.effort }))
221
+ return yield* next({ ...e, model: r.model, effort: r.effort as any })
222
+ })
223
+
224
+ // ---- the band above the prompt: one row, route on the left, controls on the right ----
225
+ on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
226
+ if (e.props.hasSurvey) return next(e)
227
+ const cfg = await read($, config)
228
+ if (!cfg) return next(e)
229
+ const { Box, Text, Button } = $.ui.resolve(e)
230
+ const s = status(cfg, await read($, route), await read($, live), await read($, paused), await read($, manual))
231
+ const pinned = await read($, pin)
232
+ const cols = e.props.bodyColumns ?? 80
233
+ const pl = await read($, place)
234
+
235
+ const row = (
236
+ <Box paddingX={1} justifyContent="space-between" gap={2}>
237
+ <Box gap={2} flexShrink={1} overflow="hidden">
238
+ <Box flexShrink={0}>{routeLine(Text, s, cols >= 48)}</Box>
239
+ </Box>
240
+ <Box gap={1} flexShrink={0}>
241
+ {pl && cols >= 90 ? (
242
+ <Text dimColor wrap="truncate-end">
243
+ {pl.project}
244
+ {pl.branch ? ` ⎇ ${pl.branch}` : ''}
245
+ </Text>
246
+ ) : null}
247
+ {pl?.ctx != null ? (
248
+ <Text>
249
+ <Text color={ring(pl.ctx).color}>{ring(pl.ctx).glyph}</Text>
250
+ <Text dimColor={pl.ctx < 60} color={pl.ctx >= 60 ? ring(pl.ctx).color : undefined}> {pl.ctx}%</Text>
251
+ </Text>
252
+ ) : null}
253
+ <Button key="pin" label={pinned ? `${MODEL_NAME[pinned] ?? cap(pinned)} ▾` : 'Auto ▾'} variant="secondary" onPress={() => openPane($, 'now')} />
254
+ <Button key="settings" label="⚙️" variant="secondary" onPress={() => openPane($, 'routes')} />
255
+ </Box>
256
+ </Box>
257
+ )
258
+ return row
259
+ })
260
+
261
+ // ---- the /router pane: tabs and on/off on top, one aligned row per task below ----
262
+ on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
263
+ const { Box, Text, Button, Select } = $.ui.resolve(e)
264
+ const cfg = await read($, config)
265
+ if (!cfg) return <Text dimColor>Loading…</Text>
266
+ const current = (await read($, tab)) === 'routes' ? 'routes' : 'now'
267
+ const s = status(cfg, await read($, route), await read($, live), await read($, paused), await read($, manual))
268
+ const pinned = await read($, pin)
269
+ const pl = await read($, place)
270
+ const isOff = s.mode === 'off'
271
+ const setup: Setup = cfg.setups[cfg.active] ?? {}
272
+ const slotOf = (role: string) => setup[role] ?? { model: cfg.mainModel, effort: '' }
273
+ const startedOn = await read($, base)
274
+ const cols = e.props.bodyColumns ?? 60
275
+
276
+ // Minimized on the desktop: the route alone.
277
+ if (e.props.placement === 'widget') return routeLine(Text, s)
278
+
279
+ // A small section header, like a grouped list's.
280
+ const section = (title: string) => (
281
+ <Box marginTop={1} marginBottom={e.surface === 'terminal' ? 0 : 1}>
282
+ <Text dimColor size="caption" weight="semibold">{title.toUpperCase()}</Text>
283
+ </Box>
284
+ )
285
+ const accent = isOff ? undefined : MODEL_COLOR[s.model] ?? 'gray'
286
+ const m = meter(s.effort)
287
+
288
+ const header = (
289
+ <Box justifyContent="space-between" alignItems="center">
290
+ <Box gap={1}>
291
+ <Button key="tab-now" label="Overview" variant={current === 'now' ? 'primary' : 'secondary'} onPress={() => update($, tab, () => 'now')} />
292
+ <Button key="tab-routes" label="Models" variant={current === 'routes' ? 'primary' : 'secondary'} onPress={() => update($, tab, () => 'routes')} />
293
+ </Box>
294
+ <Box gap={1} alignItems="center">
295
+ <Text dimColor size="footnote">Routing</Text>
296
+ <Button key="power" label={isOff ? 'Off' : 'On'} variant={isOff ? 'secondary' : 'primary'} onPress={() => power($, isOff)} />
297
+ </Box>
298
+ </Box>
299
+ )
300
+
301
+ if (current === 'routes') {
302
+ return (
303
+ <Box flexDirection="column">
304
+ {header}
305
+ {section(`Models · ${cfg.active}`)}
306
+ <Box flexDirection="column" borderStyle="round" borderDimColor paddingX={1}>
307
+ {ROLE_LIST.map(role => {
308
+ const slot = slotOf(role)
309
+ return (
310
+ <Box key={`edit-${role}`} alignItems="center">
311
+ <Box width={10} flexShrink={0}>
312
+ <Text>{cap(role)}</Text>
313
+ </Box>
314
+ <Box width={14} flexShrink={0} flexDirection="column" marginRight={1}>
315
+ <Select key={`model-${role}`} options={MODEL_LIST.map(v => ({ value: v, label: padLabel(MODEL_NAME[v], MODEL_LIST.map(x => MODEL_NAME[x]), e.surface) }))} value={slot.model} onSelect={v => setSlot($, role, 'model', v)} />
316
+ </Box>
317
+ <Box width={14} flexShrink={0} flexDirection="column" marginRight={1}>
318
+ <Select key={`effort-${role}`} options={EFFORT_LIST.map(v => ({ value: v, label: padLabel(effortLabel(v), EFFORT_LIST.map(effortLabel), e.surface) }))} value={slot.effort} onSelect={v => setSlot($, role, 'effort', v)} />
319
+ </Box>
320
+ <Text color={MODEL_COLOR[slot.model]}>{meter(slot.effort).on}</Text>
321
+ <Text dimColor>{meter(slot.effort).off}</Text>
322
+ </Box>
323
+ )
324
+ })}
325
+ </Box>
326
+ {Object.keys(cfg.setups).length > 1 ? (
327
+ <Box flexDirection="column">
328
+ {section('Setup')}
329
+ <Box borderStyle="round" borderDimColor paddingX={1}>
330
+ <Select key="setup" options={Object.keys(cfg.setups).map(v => ({ value: v }))} value={cfg.active} onSelect={v => edit($, c => ({ ...c, active: v }))} />
331
+ </Box>
332
+ </Box>
333
+ ) : null}
334
+ </Box>
335
+ )
336
+ }
337
+
338
+ const modeWord = s.mode === 'main' ? 'Auto' : cap(s.mode)
339
+ const ctx = pl?.ctx
340
+
341
+ return (
342
+ <Box flexDirection="column">
343
+ {header}
344
+
345
+ {section('Now')}
346
+ <Box flexDirection="column" borderStyle="round" borderColor={accent} borderDimColor={isOff} paddingX={1}>
347
+ <Box justifyContent="space-between" gap={2}>
348
+ <Text color={accent} dimColor={isOff} bold size="title" weight="bold">{MODEL_NAME[s.model] ?? s.model}</Text>
349
+ <Text color={s.mode === 'manual' ? 'warning' : accent} dimColor={s.mode === 'main' || isOff} weight="semibold">{modeWord}</Text>
350
+ </Box>
351
+ <Text wrap="truncate-end">
352
+ <Text color={accent} dimColor={isOff}>{m.on}</Text>
353
+ <Text dimColor>{m.off}</Text>
354
+ <Text dimColor size="footnote">{s.effort ? ` ${effortLabel(s.effort)} effort` : ''}{s.why ? ` ← ${s.why}` : ''}</Text>
355
+ </Text>
356
+ {s.mode === 'manual' ? (
357
+ <Text color="warning" size="footnote" wrap="truncate-end">/model {startedOn ?? cfg.mainModel} to resume routing</Text>
358
+ ) : null}
359
+ </Box>
360
+
361
+ {section('Use')}
362
+ <Box borderStyle="round" borderDimColor paddingX={1} flexDirection="column">
363
+ <Box width={20} flexDirection="column">
364
+ <Select
365
+ key="use"
366
+ options={[{ value: 'auto', label: 'Auto' }, ...MODEL_LIST.map(v => ({ value: v, label: MODEL_NAME[v] }))]}
367
+ value={pinned ?? 'auto'}
368
+ onSelect={v => update($, pin, () => (v === 'auto' ? null : v))}
369
+ />
370
+ </Box>
371
+ </Box>
372
+
373
+ {ctx != null ? (
374
+ <Box flexDirection="column">
375
+ {section('Context')}
376
+ <Box borderStyle="round" borderDimColor paddingX={1} gap={1} alignItems="center">
377
+ <Text color={ring(ctx).color} size="title">{ring(ctx).glyph}</Text>
378
+ <Text color={ctx >= 60 ? ring(ctx).color : undefined} weight="semibold">{ctx}%</Text>
379
+ <Text dimColor>used</Text>
380
+ </Box>
381
+ </Box>
382
+ ) : null}
383
+
384
+ {section('Tasks')}
385
+ <Box flexDirection="column" borderStyle="round" borderDimColor paddingX={1}>
386
+ {ROLE_LIST.map(role => {
387
+ const slot = slotOf(role)
388
+ const isNow = !isOff && s.role === role
389
+ const mm = meter(slot.effort)
390
+ return (
391
+ <Box key={`row-${role}`} justifyContent="space-between" gap={1}>
392
+ <Box flexShrink={1} gap={1}>
393
+ <Box width={1} flexShrink={0}>
394
+ <Text color={MODEL_COLOR[slot.model]}>{isNow ? '▸' : ' '}</Text>
395
+ </Box>
396
+ <Box width={9} flexShrink={0}>
397
+ <Text bold={isNow}>{cap(role)}</Text>
398
+ </Box>
399
+ <Box width={8} flexShrink={0}>
400
+ <Text color={isOff ? undefined : MODEL_COLOR[slot.model]} dimColor={isOff}>{MODEL_NAME[slot.model] ?? slot.model}</Text>
401
+ </Box>
402
+ <Box width={8} flexShrink={0}>
403
+ <Text>
404
+ <Text color={isOff ? undefined : MODEL_COLOR[slot.model]} dimColor={isOff}>{mm.on}</Text>
405
+ <Text dimColor>{mm.off}</Text>
406
+ </Text>
407
+ </Box>
408
+ <Text dimColor wrap="truncate-end">{effortLabel(slot.effort)}</Text>
409
+ </Box>
410
+ </Box>
411
+ )
412
+ })}
413
+ </Box>
414
+ </Box>
415
+ )
416
+ })
417
+ }