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.
- package/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +21 -0
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/bin/switchboard.js +4 -0
- package/hooks/config.ts +79 -0
- package/hooks/hooks.json +1 -0
- package/hooks/switchboard.tsx +417 -0
- package/package.json +47 -4
- package/src/cli.js +105 -0
- package/src/core/classify.js +75 -0
- package/src/core/defaults.js +125 -0
- package/src/core/store.js +249 -0
- package/src/picker/app.js +136 -0
- package/types/index.d.ts +42 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { render, Box, Text, useInput, useApp } from 'ink';
|
|
3
|
+
import { ROLES, MODELS, EFFORTS, ROLE_INFO } from '../core/defaults.js';
|
|
4
|
+
import * as store from '../core/store.js';
|
|
5
|
+
|
|
6
|
+
const h = React.createElement;
|
|
7
|
+
|
|
8
|
+
const MODEL_COLOR = { fable: 'magentaBright', opus: 'yellowBright', sonnet: 'cyanBright', haiku: 'greenBright' };
|
|
9
|
+
const EFFORT_BAR = e => '●'.repeat(EFFORTS.indexOf(e) + 1) + '○'.repeat(EFFORTS.length - EFFORTS.indexOf(e) - 1);
|
|
10
|
+
const cycle = (list, value, step) => list[(list.indexOf(value) + step + list.length) % list.length];
|
|
11
|
+
|
|
12
|
+
function snapshot() {
|
|
13
|
+
const d = store.loadSetups();
|
|
14
|
+
return { setup: store.activeSetup(), active: d.active, names: Object.keys(d.setups), enabled: d.enabled };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function Header({ s }) {
|
|
18
|
+
return h(Box, { borderStyle: 'round', borderColor: 'gray', paddingX: 1, justifyContent: 'space-between' },
|
|
19
|
+
h(Text, null, h(Text, { bold: true, color: 'whiteBright' }, '⇢ Switchboard'), h(Text, { color: 'gray' }, ' model routing for Claude Code')),
|
|
20
|
+
h(Text, null,
|
|
21
|
+
h(Text, { color: 'gray' }, 'setup '), h(Text, { bold: true, color: 'blueBright' }, s.active),
|
|
22
|
+
h(Text, { color: 'gray' }, ' routing '),
|
|
23
|
+
h(Text, { bold: true, color: s.enabled ? 'greenBright' : 'redBright' }, s.enabled ? 'ON' : 'OFF')));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function RoleTable({ s, cursor }) {
|
|
27
|
+
return h(Box, { flexDirection: 'column', paddingX: 1, marginTop: 1 },
|
|
28
|
+
h(Box, null,
|
|
29
|
+
h(Box, { width: 3 }), h(Box, { width: 10 }, h(Text, { color: 'gray' }, 'ROLE')),
|
|
30
|
+
h(Box, { width: 12 }, h(Text, { color: 'gray' }, 'MODEL')),
|
|
31
|
+
h(Box, { width: 16 }, h(Text, { color: 'gray' }, 'EFFORT')),
|
|
32
|
+
h(Text, { color: 'gray' }, 'HANDLES')),
|
|
33
|
+
...ROLES.map((r, i) => {
|
|
34
|
+
const sel = i === cursor;
|
|
35
|
+
const { model, effort } = s.setup[r];
|
|
36
|
+
return h(Box, { key: r },
|
|
37
|
+
h(Box, { width: 3 }, h(Text, { color: 'blueBright' }, sel ? '❯' : ' ')),
|
|
38
|
+
h(Box, { width: 10 }, h(Text, { bold: sel, color: sel ? 'whiteBright' : undefined }, r)),
|
|
39
|
+
h(Box, { width: 12 }, h(Text, { color: MODEL_COLOR[model], bold: true }, sel ? `‹ ${model} ›` : ` ${model}`)),
|
|
40
|
+
h(Box, { width: 16 }, h(Text, { color: sel ? 'whiteBright' : 'gray' }, `${EFFORT_BAR(effort)} ${effort}`)),
|
|
41
|
+
h(Text, { color: 'gray', wrap: 'truncate' }, ROLE_INFO[r]));
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function Footer({ mode, input, s, listCursor, toast }) {
|
|
46
|
+
const key = (k, label) => h(Text, null, h(Text, { color: 'blueBright', bold: true }, k), h(Text, { color: 'gray' }, ` ${label} `));
|
|
47
|
+
let body;
|
|
48
|
+
if (mode === 'save') {
|
|
49
|
+
body = h(Text, null, h(Text, { color: 'gray' }, 'Save setup as: '), h(Text, { color: 'whiteBright' }, input), h(Text, { color: 'blueBright' }, '█'),
|
|
50
|
+
h(Text, { color: 'gray' }, ' enter save · esc cancel'));
|
|
51
|
+
} else if (mode === 'load' || mode === 'delete') {
|
|
52
|
+
body = h(Box, { flexDirection: 'column' },
|
|
53
|
+
h(Text, { color: 'gray' }, mode === 'load' ? 'Load setup (enter load · esc cancel):' : 'Delete setup (enter delete · esc cancel):'),
|
|
54
|
+
...s.names.map((n, i) => h(Text, { key: n },
|
|
55
|
+
h(Text, { color: 'blueBright' }, i === listCursor ? '❯ ' : ' '),
|
|
56
|
+
h(Text, { color: n === s.active ? 'blueBright' : undefined, bold: i === listCursor }, n),
|
|
57
|
+
n === s.active ? h(Text, { color: 'gray' }, ' (active)') : null)));
|
|
58
|
+
} else {
|
|
59
|
+
body = h(Text, null, key('↑↓', 'role'), key('←→', 'model'), key('e', 'effort'), key('s', 'save'), key('l', 'load'),
|
|
60
|
+
key('d', 'delete'), key('t', 'on/off'), key('q', 'quit'));
|
|
61
|
+
}
|
|
62
|
+
return h(Box, { flexDirection: 'column', paddingX: 1, marginTop: 1 },
|
|
63
|
+
body,
|
|
64
|
+
toast ? h(Text, { color: toast.error ? 'redBright' : 'greenBright' }, toast.text) : h(Text, null, ' '));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function App() {
|
|
68
|
+
const { exit } = useApp();
|
|
69
|
+
const [s, setS] = useState(snapshot);
|
|
70
|
+
const [cursor, setCursor] = useState(0);
|
|
71
|
+
const [mode, setMode] = useState('main');
|
|
72
|
+
const [input, setInput] = useState('');
|
|
73
|
+
const [listCursor, setListCursor] = useState(0);
|
|
74
|
+
const [toast, setToast] = useState(null);
|
|
75
|
+
|
|
76
|
+
const act = (fn, ok) => {
|
|
77
|
+
try {
|
|
78
|
+
fn();
|
|
79
|
+
setS(snapshot());
|
|
80
|
+
setToast(ok ? { text: ok } : null);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
setToast({ text: e.message, error: true });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
useInput((ch, key) => {
|
|
87
|
+
if (mode === 'save') {
|
|
88
|
+
if (key.escape) { setMode('main'); setInput(''); return; }
|
|
89
|
+
if (key.return) {
|
|
90
|
+
const name = input.trim();
|
|
91
|
+
act(() => store.saveAs(name), `Saved as "${name}"`);
|
|
92
|
+
setMode('main'); setInput('');
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (key.backspace || key.delete) { setInput(v => v.slice(0, -1)); return; }
|
|
96
|
+
if (ch && !key.ctrl && !key.meta) setInput(v => (v + ch).slice(0, 40));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (mode === 'load' || mode === 'delete') {
|
|
100
|
+
if (key.escape || ch === 'q') { setMode('main'); return; }
|
|
101
|
+
if (key.upArrow) setListCursor(i => Math.max(0, i - 1));
|
|
102
|
+
if (key.downArrow) setListCursor(i => Math.min(s.names.length - 1, i + 1));
|
|
103
|
+
if (key.return) {
|
|
104
|
+
const name = s.names[listCursor];
|
|
105
|
+
if (mode === 'load') act(() => store.use(name), `Loaded "${name}"`);
|
|
106
|
+
else act(() => store.remove(name), `Deleted "${name}"`);
|
|
107
|
+
setMode('main');
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const role = ROLES[cursor];
|
|
112
|
+
const cur = s.setup[role];
|
|
113
|
+
if (ch === 'q' || key.escape || (key.ctrl && ch === 'c')) { exit(); return; }
|
|
114
|
+
if (key.upArrow || ch === 'k') setCursor(i => (i + ROLES.length - 1) % ROLES.length);
|
|
115
|
+
else if (key.downArrow || ch === 'j') setCursor(i => (i + 1) % ROLES.length);
|
|
116
|
+
else if (key.rightArrow) act(() => store.setRole(role, cycle(MODELS, cur.model, 1)));
|
|
117
|
+
else if (key.leftArrow) act(() => store.setRole(role, cycle(MODELS, cur.model, -1)));
|
|
118
|
+
else if (ch === 'e') act(() => store.setRole(role, cur.model, cycle(EFFORTS, cur.effort, 1)));
|
|
119
|
+
else if (ch === 'E') act(() => store.setRole(role, cur.model, cycle(EFFORTS, cur.effort, -1)));
|
|
120
|
+
else if (ch === 's') { setMode('save'); setInput(''); setToast(null); }
|
|
121
|
+
else if (ch === 'l') { setMode('load'); setListCursor(Math.max(0, s.names.indexOf(s.active))); setToast(null); }
|
|
122
|
+
else if (ch === 'd') { setMode('delete'); setListCursor(0); setToast(null); }
|
|
123
|
+
else if (ch === 't') act(() => store.setEnabled(!s.enabled), `Routing ${s.enabled ? 'OFF' : 'ON'}`);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return h(Box, { flexDirection: 'column' },
|
|
127
|
+
h(Header, { s }),
|
|
128
|
+
h(RoleTable, { s, cursor }),
|
|
129
|
+
h(Footer, { mode, input, s, listCursor, toast }),
|
|
130
|
+
h(Text, { color: 'gray', dimColor: true }, ' Changes save instantly and apply to the next helper Claude starts.'));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function runPicker() {
|
|
134
|
+
const app = render(h(App));
|
|
135
|
+
await app.waitUntilExit();
|
|
136
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type RoleSetting = { model: string; effort: string }
|
|
2
|
+
export type Setup = Record<string, RoleSetting>
|
|
3
|
+
|
|
4
|
+
/** setups.json and rules.json as the mod reads them, defaults filled in. */
|
|
5
|
+
export type Config = {
|
|
6
|
+
active: string
|
|
7
|
+
enabled: boolean
|
|
8
|
+
mainModel: string
|
|
9
|
+
setups: Record<string, Setup>
|
|
10
|
+
rules: Record<string, string[]>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Where this turn is going and why. */
|
|
14
|
+
export type Route = {
|
|
15
|
+
role: string
|
|
16
|
+
model: string
|
|
17
|
+
effort: string
|
|
18
|
+
why: string
|
|
19
|
+
source: 'auto' | 'pin' | 'override'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The model and effort the last main-chat request actually went out with. */
|
|
23
|
+
export type Live = { model: string; effort: string }
|
|
24
|
+
|
|
25
|
+
/** Where the session is: project folder name, git branch, context window used. */
|
|
26
|
+
export type Place = { project: string; branch: string | null; ctx: number | null }
|
|
27
|
+
|
|
28
|
+
declare module 'claude-code' {
|
|
29
|
+
interface PluginState {
|
|
30
|
+
switchboard: {
|
|
31
|
+
config: Shaped<Config | null>
|
|
32
|
+
route: Shaped<Route | null>
|
|
33
|
+
live: Shaped<Live | null>
|
|
34
|
+
paused: boolean
|
|
35
|
+
manual: string | null
|
|
36
|
+
pin: string | null
|
|
37
|
+
tab: string
|
|
38
|
+
place: Place | null
|
|
39
|
+
base: string | null
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|