@alexeiled/claude-router 1.12.0 → 1.14.0
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/plugin.json +1 -1
- package/CHANGELOG.md +31 -0
- package/docs/architecture.md +2 -2
- package/docs/evaluation.md +8 -7
- package/docs/native-router.md +2 -2
- package/docs/router-pane-now.svg +132 -77
- package/docs/router-pane-usage-whatif.svg +125 -67
- package/docs/router-pane-usage.svg +110 -44
- package/docs/user-guide.md +15 -9
- package/hooks/native-router.mjs +60 -25
- package/lib/band.mjs +36 -10
- package/lib/display.mjs +4 -5
- package/lib/panel.mjs +527 -135
- package/lib/subagents.mjs +182 -64
- package/lib/usage.mjs +1 -1
- package/lib/view.mjs +53 -11
- package/package.json +1 -1
- package/types/index.d.ts +30 -12
package/docs/user-guide.md
CHANGED
|
@@ -53,13 +53,15 @@ Read the first line of the picture from left to right:
|
|
|
53
53
|
| `⚠ Jev timed out · keeping model` | The classifier failed: timed out, unreachable, rejected the key, or paused. |
|
|
54
54
|
| `○ Routing off [ Turn on ] · every turn uses …` | Routing is off: Claude's model answers every turn. **Turn on** turns it back on. The footer also shows `routing off`. |
|
|
55
55
|
| `✕ Routing unavailable` | Nothing routes: an old Claude Code or leftover v0.8 settings. **Fix** opens the pane. |
|
|
56
|
-
| `○ Router ·
|
|
56
|
+
| `○ Router · ■ Haiku 5.5 · moved down by the router` | You are viewing a subagent's transcript. The model it runs on, and who picked it; see below. |
|
|
57
57
|
|
|
58
58
|
The band shows one routing control at a time. While routing is on, hover over the band for a second row: pin a tier for the next turn, **Turn off** routing, or show two rows. While routing is off, **Turn on** sits on the first line next to `Routing off` and stays at any width: a narrow band drops the explanation and the model first. On a narrow band the hover row drops `routing on`, then **2 rows**, then `pin next turn`, then the pins; it keeps **Turn off**, and **1 row** when the band shows two. The hover row needs a pointer: from the keyboard, run `/router off`, or open the pane and press `f`. The two-row band adds this session against your model, the one `/model` selects now: `session saved $1.84 (22%) vs Opus 5.5 · xhigh · 64 replies · cold-cache writes +$0.47`, or `session extra $2.48 (×5.0) vs Haiku 5.5 · high · 41 replies · stronger models +$2.31` when routing cost more. The last part names the larger of the two costs behind the result, when there is one. After a `/model` change the row shows the whole session against the new model. Before the tenth routed reply it reads `session 3 replies · too early to compare`. When the row is short, the cost part drops first, then the reply count. Router remembers that choice across sessions. When Router changes the model between turns, a toast reads `Model changed: old → new · reason`. A pin does not raise one, and neither does a change of effort alone.
|
|
59
59
|
|
|
60
60
|
The band steps aside while a survey needs the space.
|
|
61
61
|
|
|
62
|
-
Inside a turn the router checks the route again as the work changes; see [Changes during a task](#changes-during-a-task). A subagent gets at most one model, when it starts, and keeps it for every step: Haiku for exploration, Opus for clearly hard tasks, Sonnet for the rest. An agent that pins a model in its definition keeps it, unless it sets `modelRouting: auto`. The Usage tab's **SUBAGENTS** section shows what each agent type ran on and cost. See [Subagent routing](configuration.md#subagent-routing).
|
|
62
|
+
Inside a turn the router checks the route again as the work changes; see [Changes during a task](#changes-during-a-task). A subagent gets at most one model, when it starts, and keeps it for every step: Haiku for exploration, Opus for clearly hard tasks, Sonnet for the rest. An agent that pins a model in its definition keeps it, unless it sets `modelRouting: auto`. The Usage tab's **SUBAGENTS** section shows what each agent type ran on and cost, and the Now tab shows this session's agents. See [Subagent routing](configuration.md#subagent-routing).
|
|
63
|
+
|
|
64
|
+
In a subagent's transcript the band names the model the agent runs on and who picked it. `■ Haiku 5.5 · moved down by the router · Claude Code: Opus 5.5` means the router chose a cheaper model than Claude Code would have; `up` means a stronger one. `□ Sonnet 5.5 · the router kept Claude Code’s pick` means the router agreed. `□ Opus 5.5 · Claude Code’s pick: the workflow sets it` means the router did not route the agent, and says why. A narrow band drops the `Claude Code:` part first. The band falls back to `subagent model chosen at spawn` when the router has no record of the agent, such as after a plugin reload, and to `subagents keep their own model` with subagent routing off.
|
|
63
65
|
|
|
64
66
|
## Open the router pane
|
|
65
67
|
|
|
@@ -67,7 +69,7 @@ Run `/router` or select **Router** above the prompt. Without a UI surface, as in
|
|
|
67
69
|
|
|
68
70
|
| Tab | What it answers |
|
|
69
71
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
70
|
-
| 1 Now | What runs next turn, and why
|
|
72
|
+
| 1 Now | What runs next turn, and why, with a **pin** per tier; this session and today at a glance; the first finding worth a look. |
|
|
71
73
|
| 2 Routes | Which model runs: one grid of tiers by activities, the activity routing mode, and an editor for the selected cell. |
|
|
72
74
|
| 3 Policy | How readily the router changes models: the start tier, going down, going up, the activity threshold, the credits cap; the `router.json` path. |
|
|
73
75
|
| 4 Classifier | Which classifier to ask: one row per classifier to compare, the active one's deadline, wait, health and credentials, and the counts kept across sessions. |
|
|
@@ -75,9 +77,13 @@ Run `/router` or select **Router** above the prompt. Without a UI surface, as in
|
|
|
75
77
|
|
|
76
78
|
The top line of every tab, `ROUTING [ ◉ on ] [ ○ off ] Jev ready · 347 ms`, shows the routing mode, switches it, and says whether the classifier is ready. Press `o` or `f` while the pane has focus. **?** shows what the estimates leave out. When routing is unavailable, the top line reads `ROUTING unavailable Claude’s model is kept` with the reason under it, and offers no on or off: see [Troubleshooting](#troubleshooting).
|
|
77
79
|
|
|
78
|
-

|
|
81
|
+
|
|
82
|
+
The **Now** tab answers "what runs next turn, and why". **Next turn** names the tier, the model and effort, and, when an activity override runs, the tier's own model beside it. **Activity** names the classifier's activity as a verb, such as `coding 84%`, with the two next answers and the threshold at which an activity applies. **Why** gives the reason; under it, `Jev gave stronger tiers 88% (needs 82%) · switch ≈ $0.48` compares the classifier's support for the switch with the bar the policy set, and gives the estimated switch cost. **Pin next** has one button per tier, strongest first, with the support the classifier gave it on the last turn; `▶` marks the tier that runs now. A press forces that tier for the next turn only.
|
|
83
|
+
|
|
84
|
+
**SESSION** sums this session from its first routed reply: `since 14:18 · 86 routed replies · 9 route switches`. The strip under it colors every reply since Claude Code started the session by the tier that served it; a dot marks replies routing did not serve, such as those with routing off. Each cell is one reply up to 48 cells. Past that, and on a pane too narrow for the cells, pairs of cells merge and the strip says how many replies a cell holds, so it spans all those replies on one line. After Claude Code restarts a resumed session, the strip starts again and says since when, such as `since 15:02`, while the heading still counts the whole session. The replies per tier, `■ low 41 ■ medium 12 ■ high 33`, double as the color key, and the routed replies per activity follow. **last switch** says when the route last changed and between which tiers, or between which routes when a switch stayed inside a tier, with the activity it ran for. The last line is what routing saved, or cost, against your model this session, with the switch cache writes in it; **Usage** opens the Usage tab on this session.
|
|
79
85
|
|
|
80
|
-
|
|
86
|
+
**TODAY** appears once another session added to today, with the same line for every session today and its own **Usage** link. **SUBAGENTS** appears once this session started a subagent: how many are in the middle of a turn now (`● 1 running`; an agent that waits on its own background command is not counted until it resumes), the same squares as on the Usage tab, and what routing saved on them; **Usage** opens the Usage tab on this session. **WORTH A LOOK** shows today's first finding from the Usage tab, from 20 routed replies, with the tab that changes it. The last lines give the context gauge, the cache reuse and the cost Claude reports; **details** adds the counters and estimates in [Understand usage and estimates](#understand-usage-and-estimates).
|
|
81
87
|
|
|
82
88
|
### Save and undo changes
|
|
83
89
|
|
|
@@ -134,13 +140,13 @@ These are estimates, not a bill. They hold the tokens and the output length the
|
|
|
134
140
|
- **Context** compares the larger available context reading with the routed model's configured window. The router reserves 20% of that window. Values can be unknown when Claude does not provide the needed estimate.
|
|
135
141
|
- **Cache** reuse is cache-read tokens divided by the last response's input counters.
|
|
136
142
|
- **Classifier support**, such as **Jev support**, is the probability the classifier gave each tier on the last classified turn. The line under **Why** compares the support for a switch with the bar the policy required, and shows the estimated switch cost.
|
|
137
|
-
- **
|
|
138
|
-
- **Input per reply**, under **details** on the Now tab, scales the last 30
|
|
143
|
+
- **Route switches** on the Now tab count the turns whose route differed from the turn before: a change of model or effort, so a move from Sonnet to Haiku inside `low` counts too, although its strip color stays. They are the switches the Usage tab counts, and a pin is not one. **Switch writes** is the cache-write cost of those switches inside the saving.
|
|
144
|
+
- **Input per reply**, under **details** on the Now tab, scales the input sizes of the last 30 replies from the lowest to the highest reading. It is a scale comparison, not a forecast.
|
|
139
145
|
- **Cache hits saved** is a configured-price estimate for cached reads before write costs. It is not a measured saving.
|
|
140
146
|
- **Next-turn difference** compares the candidate with the current model under five-minute and one-hour cache-write scenarios. A negative number means the candidate is estimated to cost less for that request.
|
|
141
147
|
- **Payback** estimates later turns to recover an initial difference under assumed future cache reads and the last observed output size. It does not guarantee savings.
|
|
142
148
|
|
|
143
|
-
On the Usage tab, **SUBAGENTS
|
|
149
|
+
On the Usage tab, **SUBAGENTS** covers the same period as the rest of the tab: this session, or every session in every project that uses this router install (`all projects`), since the last **Delete history**. Each agent is one square, colored by the model it ran on: filled (`■`) when the router moved it off the model Claude Code would have picked, hollow (`□`) when it ran on Claude Code's pick, because the router agreed or did not route it. The models and their agents follow the squares, then how many the router moved, and what routing saved or cost on the routed agents against Claude Code's picks. 7d, 30d, Month and All add the agents per day. **ROUTED** lists each agent type the router picked a model for: its squares, agents, cost, and **vs CC**, the same tokens on Claude Code's pick. A row opens to its models, each with how many agents the router kept, moved up or moved down, and to its requests per agent, respawns and classifier failures. **NOT ROUTED** lists the agents Claude Code picked a model for, by reason, with why: `the workflow sets it`, `your model` for a fork, `its agent file sets it`. A row without any priced request says `no price`. Records from before 1.14.0 have no date or model: Session and All add them as one line, and an empty Today or 7d says so. See [Subagent routing](configuration.md#subagent-routing). Plan quota is not on the pane: Claude Code shows it in `/usage`. On the Now tab, **details** adds the context and cache counters, the output of the last reply, the input per reply, and the estimates above.
|
|
144
150
|
|
|
145
151
|
The router keeps no bill. Routing vs your model is an estimate at configured list prices. The pane does not include classifier charges. Claude's native `/cost` is the source for its reported API cost.
|
|
146
152
|
|
|
@@ -201,7 +207,7 @@ These thresholds are starting values. They are not tuned on data yet.
|
|
|
201
207
|
|
|
202
208
|
### Read the activity on the pane
|
|
203
209
|
|
|
204
|
-
- **Now**: the **Activity** line names the classifier's choice as a verb with its share, the two next-best answers, and the threshold at which an activity applies, such as `coding 84% debugging 8% · planning 5% applies at 60%+`. An `uncertain` answer is shown dim: it applies no activity. In `on`, **Why** names the cell when the activity moved the route or the route is an override, such as `coding at low runs on Sonnet 5.5 · high`, or `low runs on its base route, Haiku 5.5 · high` for a move without an activity; a refused move, a hold, or a tier change keeps its reason. **
|
|
210
|
+
- **Now**: the **Activity** line names the classifier's choice as a verb with its share, the two next-best answers, and the threshold at which an activity applies, such as `coding 84% debugging 8% · planning 5% applies at 60%+`. An `uncertain` answer is shown dim: it applies no activity. In `on`, **Why** names the cell when the activity moved the route or the route is an override, such as `coding at low runs on Sonnet 5.5 · high`, or `low runs on its base route, Haiku 5.5 · high` for a move without an activity; a refused move, a hold, or a tier change keeps its reason. **SESSION** counts the routed replies per activity under the strip.
|
|
205
211
|
- **Routes**: see [Edit routes and policy](#edit-routes-and-policy). Each activity is a row of the grid, and a cell shows the model the activity runs at that tier.
|
|
206
212
|
- **Usage**: **BY** with **Activity** lists the period's replies, cost and difference against your model per activity, and `mostly on`, the route most of its replies used, such as `Sonnet 5.5 · high`; opening a row lists its routes. Replies whose turn had no applied activity count as `no activity`. The ledger's switch line counts the route switches by tier and by activity together. See [Compare routing with your model](#compare-routing-with-your-model).
|
|
207
213
|
- **Classifier**: **THIS SESSION** gives **Agreement**, how often the tools a turn used fit the classifier's activity (see [Evaluation](evaluation.md#tool-agreement)).
|
package/hooks/native-router.mjs
CHANGED
|
@@ -93,6 +93,7 @@ import {
|
|
|
93
93
|
emptySubagentStore,
|
|
94
94
|
flushedAgent,
|
|
95
95
|
mergeSubagentStores,
|
|
96
|
+
moveOf,
|
|
96
97
|
passReason,
|
|
97
98
|
RESPAWN_WINDOW_MS,
|
|
98
99
|
readSubagentStore,
|
|
@@ -116,7 +117,14 @@ import {
|
|
|
116
117
|
USAGE_PREFIX,
|
|
117
118
|
usageAfterReset,
|
|
118
119
|
} from '../lib/usage.mjs';
|
|
119
|
-
import {
|
|
120
|
+
import {
|
|
121
|
+
CLEARED_READINGS,
|
|
122
|
+
continuationView,
|
|
123
|
+
healthOf,
|
|
124
|
+
initialView,
|
|
125
|
+
responseMetrics,
|
|
126
|
+
switchView,
|
|
127
|
+
} from '../lib/view.mjs';
|
|
120
128
|
|
|
121
129
|
// The engine follows $ only into functions declared in this file, never across an import: every helper that takes $
|
|
122
130
|
// lives here, and the pure parts live in lib/.
|
|
@@ -165,6 +173,7 @@ const LEDGERS = {
|
|
|
165
173
|
subagents: {
|
|
166
174
|
prefix: SUBAGENT_PREFIX,
|
|
167
175
|
field: 'subagentStore',
|
|
176
|
+
ownField: 'subagentSession',
|
|
168
177
|
read: readSubagentStore,
|
|
169
178
|
afterReset: subagentsAfterReset,
|
|
170
179
|
merge: mergeSubagentStores,
|
|
@@ -224,8 +233,8 @@ function createRouter(options) {
|
|
|
224
233
|
// first request goes out on that route, unless it was pressed again meanwhile.
|
|
225
234
|
pinPresses: 0,
|
|
226
235
|
turnPins: new Map(),
|
|
227
|
-
// Each spawned agent's record by agentId (spawnRecord
|
|
228
|
-
// for respawns.
|
|
236
|
+
// Each spawned agent's record by agentId (spawnRecord, `running` between its steps and its turn's end), and when
|
|
237
|
+
// each parent loop last finished an agent of a type, for respawns.
|
|
229
238
|
agents: new Map(),
|
|
230
239
|
finished: new Map(),
|
|
231
240
|
// Each agent type's definition frontmatter by provider and type, read once per session (agentDefinition).
|
|
@@ -626,7 +635,7 @@ async function* passMain($, e, next, loop, version, nativeModel, reason, router)
|
|
|
626
635
|
const compared = await compareYours($, router, loop, response, e.effort ?? null, nativeModel);
|
|
627
636
|
if (compared) observed.yoursBy = compared.states;
|
|
628
637
|
const written = await $.state.set(ref, observed, { ifVersion: version });
|
|
629
|
-
if (written.isSet) await updateView($, router, responseMetrics(router.view, response, null));
|
|
638
|
+
if (written.isSet) await updateView($, router, responseMetrics(router.view, response, null, Date.now()));
|
|
630
639
|
}
|
|
631
640
|
return response;
|
|
632
641
|
}
|
|
@@ -719,6 +728,7 @@ async function decideTurn($, router, e, signal, step) {
|
|
|
719
728
|
routes: {},
|
|
720
729
|
});
|
|
721
730
|
await updateView($, router, {
|
|
731
|
+
...(activity.switched ? switchView(previous, selected.decision, activity.label, Date.now()) : {}),
|
|
722
732
|
phase: 'routed',
|
|
723
733
|
selectedModel: selected.decision.model,
|
|
724
734
|
actualModel: null,
|
|
@@ -772,6 +782,9 @@ async function transcript($) {
|
|
|
772
782
|
}
|
|
773
783
|
}
|
|
774
784
|
|
|
785
|
+
// The activity a route runs for, as the view labels it: only activity routing `on` applies one.
|
|
786
|
+
const activityLabel = (cfg, decision) => (cfg.activityRouting === 'on' ? (decision.activity ?? null) : null);
|
|
787
|
+
|
|
775
788
|
// A tool continuation whose turn shows stronger work than its route was chosen for moves up once (observedMove). Only
|
|
776
789
|
// tool calls after the last applied review count (`loop.observedFrom`): the review judged the ones before. The
|
|
777
790
|
// transcript is read only when some activity's route at this tier is stronger than the running one.
|
|
@@ -787,7 +800,11 @@ async function moveOnObserved($, router, cfg, loop, e, context) {
|
|
|
787
800
|
// Replies from here on are labelled with the moved activity; the classifier's answer stays as recorded.
|
|
788
801
|
const turn = router.turnActivities.get(e.turnId);
|
|
789
802
|
if (turn) router.turnActivities.set(e.turnId, { ...turn, label: moved.decision.activity });
|
|
790
|
-
await updateView($, router, {
|
|
803
|
+
await updateView($, router, {
|
|
804
|
+
estimate: moved.decision.estimate ?? null,
|
|
805
|
+
comparison: null,
|
|
806
|
+
...switchView(loop.decision, moved.decision, activityLabel(cfg, moved.decision), Date.now()),
|
|
807
|
+
});
|
|
791
808
|
return moved;
|
|
792
809
|
}
|
|
793
810
|
|
|
@@ -820,6 +837,11 @@ async function reviewMidTurn($, router, cfg, loop, e, { context, nativeModel, av
|
|
|
820
837
|
$.ui.toast(switchToast(cfg, previous, selected.decision, selected.decision.estimate));
|
|
821
838
|
const turn = router.turnActivities.get(e.turnId);
|
|
822
839
|
if (turn) router.turnActivities.set(e.turnId, { ...turn, label: selected.decision.activity ?? null });
|
|
840
|
+
await updateView(
|
|
841
|
+
$,
|
|
842
|
+
router,
|
|
843
|
+
switchView(previous, selected.decision, activityLabel(cfg, selected.decision), Date.now()),
|
|
844
|
+
);
|
|
823
845
|
}
|
|
824
846
|
// The pane shows the readings behind the route; a review by a classifier the pane no longer labels keeps them off.
|
|
825
847
|
if (cfg.classifier === router.config.classifier)
|
|
@@ -870,17 +892,10 @@ async function reviewMidTurn($, router, cfg, loop, e, { context, nativeModel, av
|
|
|
870
892
|
return { ...loop, reviewedAt: loop.requests ?? 0 };
|
|
871
893
|
}
|
|
872
894
|
|
|
873
|
-
// A routed reply's metrics in the view,
|
|
874
|
-
// turn's activity record with its list price (`routedUsd`, null when unpriced) and, when its tier served it, its route.
|
|
895
|
+
// A routed reply's metrics in the view, with the tier that served it, and added to the turn's activity record with its list price (`routedUsd`, null when unpriced) and, when its tier served it, its route.
|
|
875
896
|
async function publishReply($, router, turnId, response, tier, route, routedUsd) {
|
|
876
897
|
const turn = router.turnActivities.get(turnId);
|
|
877
|
-
const metrics = responseMetrics(
|
|
878
|
-
router.view,
|
|
879
|
-
response,
|
|
880
|
-
tier,
|
|
881
|
-
tier ? (turn?.label ?? null) : null,
|
|
882
|
-
tier ? route : null,
|
|
883
|
-
);
|
|
898
|
+
const metrics = responseMetrics(router.view, response, tier, Date.now());
|
|
884
899
|
await updateView($, router, metrics);
|
|
885
900
|
if (turn)
|
|
886
901
|
router.turnActivities.set(turnId, {
|
|
@@ -1179,17 +1194,27 @@ async function noteSpawn($, router, { cfg, e, pass, decision, routed, result, de
|
|
|
1179
1194
|
definition,
|
|
1180
1195
|
})
|
|
1181
1196
|
: result.model;
|
|
1197
|
+
const routedModel = decision?.model ?? result.model;
|
|
1182
1198
|
const record = spawnRecord({
|
|
1183
1199
|
sessionId: await $.session.id(),
|
|
1184
1200
|
spawn: e,
|
|
1185
1201
|
pass,
|
|
1186
1202
|
choice: decision?.choice ?? null,
|
|
1187
|
-
routedModel
|
|
1203
|
+
routedModel,
|
|
1188
1204
|
coreModel,
|
|
1205
|
+
move: routed ? moveOf(cfg, routedModel, coreModel) : null,
|
|
1189
1206
|
failed: decision?.failed,
|
|
1190
1207
|
respawn: Number.isFinite(finishedAt) && Date.now() - finishedAt < RESPAWN_WINDOW_MS,
|
|
1191
1208
|
});
|
|
1192
|
-
router.agents.set(result.agentId, { ...record, parentKey });
|
|
1209
|
+
router.agents.set(result.agentId, { ...record, parentKey, running: true });
|
|
1210
|
+
await showRunning($, router);
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
// How many of the agents with a record are between their start or a step and their turn's end, in the view when it
|
|
1214
|
+
// changes. An agent spawned with routing off has no record and is not counted.
|
|
1215
|
+
async function showRunning($, router) {
|
|
1216
|
+
const running = [...router.agents.values()].filter((agent) => agent.running).length;
|
|
1217
|
+
if ((router.view?.subagentsRunning ?? 0) !== running) await updateView($, router, { subagentsRunning: running });
|
|
1193
1218
|
}
|
|
1194
1219
|
|
|
1195
1220
|
// A subagent's prompt-cache lifetime, by Claude Code's rule for requests outside the main conversation.
|
|
@@ -1211,7 +1236,9 @@ async function* stepAgent($, router, e, next) {
|
|
|
1211
1236
|
try {
|
|
1212
1237
|
const ttl = await subagentTtlOf($);
|
|
1213
1238
|
const agent = router.agents.get(e.agentId);
|
|
1214
|
-
if (agent)
|
|
1239
|
+
if (agent)
|
|
1240
|
+
router.agents.set(e.agentId, { ...addAgentReply(router.config, agent, response.usage, ttl), running: true });
|
|
1241
|
+
if (agent && !agent.running) await showRunning($, router);
|
|
1215
1242
|
} catch {}
|
|
1216
1243
|
}
|
|
1217
1244
|
return response;
|
|
@@ -1222,7 +1249,8 @@ async function finishAgent($, router, agentId) {
|
|
|
1222
1249
|
const agent = router.agents.get(agentId);
|
|
1223
1250
|
if (!agent) return;
|
|
1224
1251
|
router.finished.set(agent.parentKey, Date.now());
|
|
1225
|
-
router.agents.set(agentId, flushedAgent(agent));
|
|
1252
|
+
router.agents.set(agentId, { ...flushedAgent(agent), running: false });
|
|
1253
|
+
await showRunning($, router).catch(() => {});
|
|
1226
1254
|
await flushSubagents($, router, [agent]);
|
|
1227
1255
|
}
|
|
1228
1256
|
|
|
@@ -1324,6 +1352,12 @@ function paneActions($, router, view) {
|
|
|
1324
1352
|
() => ({ ...patch, lastWrite: { label, leaves }, notice: `Saved: ${label}. Applies from the next turn.` }),
|
|
1325
1353
|
);
|
|
1326
1354
|
};
|
|
1355
|
+
// The Usage tab's period, kept across sessions; a failed save keeps it for this session.
|
|
1356
|
+
const showPeriod = async (period, patch = {}) => {
|
|
1357
|
+
if (!PERIODS.includes(period)) return;
|
|
1358
|
+
await $.store.set(PERIOD_KEY, period).catch(() => {});
|
|
1359
|
+
await updateView($, router, { usagePeriod: period, usageOpen: null, ...patch });
|
|
1360
|
+
};
|
|
1327
1361
|
return {
|
|
1328
1362
|
mode: (mode) => changeMode($, router, mode),
|
|
1329
1363
|
tab: (tab) => updateView($, router, { tab, notice: null, confirmDelete: false }),
|
|
@@ -1382,12 +1416,9 @@ function paneActions($, router, view) {
|
|
|
1382
1416
|
removeActivity: (activity, tier) => editCell(activity, tier, 'remove'),
|
|
1383
1417
|
selectCell: (cell) => updateView($, router, { routeCell: cell, notice: null }),
|
|
1384
1418
|
usageDetail: () => updateView($, router, { usageDetail: !(router.view ?? view).usageDetail }),
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
await $.store.set(PERIOD_KEY, period).catch(() => {});
|
|
1389
|
-
await updateView($, router, { usagePeriod: period, usageOpen: null });
|
|
1390
|
-
},
|
|
1419
|
+
period: (period) => showPeriod(period),
|
|
1420
|
+
// The Now tab's Usage links: the Usage tab on the period the line sums.
|
|
1421
|
+
usageFor: (period) => showPeriod(period, { tab: 'usage', notice: null, confirmDelete: false }),
|
|
1391
1422
|
usageGroup: (group) => updateView($, router, { usageGroup: group, usageOpen: null }),
|
|
1392
1423
|
usageCompare: () => updateView($, router, { usageCompare: !(router.view ?? view).usageCompare }),
|
|
1393
1424
|
usageOpen: (row) => updateView($, router, { usageOpen: row }),
|
|
@@ -1781,7 +1812,11 @@ export function register(on, options) {
|
|
|
1781
1812
|
router.config,
|
|
1782
1813
|
view,
|
|
1783
1814
|
usage,
|
|
1784
|
-
{
|
|
1815
|
+
{
|
|
1816
|
+
columns: e.props.bodyColumns,
|
|
1817
|
+
agentId: e.props.view?.agentId,
|
|
1818
|
+
agent: router.agents.get(e.props.view?.agentId) ?? null,
|
|
1819
|
+
},
|
|
1785
1820
|
{
|
|
1786
1821
|
open: () => openPane($, router),
|
|
1787
1822
|
mode: (mode) => changeMode($, router, mode),
|
package/lib/band.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
classifierStatus,
|
|
6
6
|
classifierWarns,
|
|
7
7
|
differenceShare,
|
|
8
|
+
modelColor,
|
|
8
9
|
modelName,
|
|
9
10
|
NOT_A_TIER_REASON,
|
|
10
11
|
percentPair,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
} from './display.mjs';
|
|
21
22
|
import { isSameModel } from './route.mjs';
|
|
22
23
|
import { emptyTotals, modelSpec, readout } from './savings.mjs';
|
|
24
|
+
import { PASS_WHY } from './subagents.mjs';
|
|
23
25
|
|
|
24
26
|
const BARS = '▂▄▆█';
|
|
25
27
|
const SEPARATOR = ' · ';
|
|
@@ -265,19 +267,43 @@ function hoverSegments(view, actions, routing) {
|
|
|
265
267
|
].filter(Boolean);
|
|
266
268
|
}
|
|
267
269
|
|
|
268
|
-
|
|
270
|
+
// A subagent's model and who chose it, as the Usage tab's squares show it: filled when the router moved it off
|
|
271
|
+
// Claude Code's pick. Claude Code's model goes first in a narrow band.
|
|
272
|
+
function agentParts(agent, columns) {
|
|
273
|
+
const color = modelColor(agent.routedModel);
|
|
274
|
+
const moved = !agent.pass && agent.move;
|
|
275
|
+
const name = part(`${moved ? '■' : '□'} ${modelName(agent.routedModel)}`, color ? { color } : {});
|
|
276
|
+
const why = agent.pass
|
|
277
|
+
? `Claude Code’s pick: ${PASS_WHY[agent.pass]}`
|
|
278
|
+
: moved
|
|
279
|
+
? `moved ${agent.move === 'moved' ? '' : `${agent.move} `}by the router`
|
|
280
|
+
: agent.choice === 'core'
|
|
281
|
+
? `Claude Code’s pick: ${agent.failed ? 'classifier did not answer' : 'the router sent no model'}`
|
|
282
|
+
: 'the router kept Claude Code’s pick';
|
|
283
|
+
const parts = [part('○ Router · ', { dimColor: true }), name, part(` · ${why}`, { dimColor: true })];
|
|
284
|
+
const pick = part(` · Claude Code: ${modelName(agent.coreModel)}`, { dimColor: true });
|
|
285
|
+
const width = parts.reduce((sum, p) => sum + p.text.length, 0) + pick.text.length;
|
|
286
|
+
return moved && agent.coreModel && !(Number.isFinite(columns) && width > columns) ? [...parts, pick] : parts;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export function renderBand({ Box, Text, Button }, config, view, usage, { columns, agentId, agent = null }, actions) {
|
|
269
290
|
const draw = (p) => (p.button ? Button(p.button) : Text({ ...p.style, children: p.text }));
|
|
270
291
|
const row = (parts) => Box({ children: parts.map(draw) });
|
|
271
|
-
// A subagent's model is chosen once, at spawn, and never changes between its steps.
|
|
292
|
+
// A subagent's model is chosen once, at spawn, and never changes between its steps. Without its record (routing
|
|
293
|
+
// off, or the router reloaded since the spawn) only the mode is known.
|
|
272
294
|
if (agentId)
|
|
273
|
-
return row(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
295
|
+
return row(
|
|
296
|
+
agent
|
|
297
|
+
? agentParts(agent, columns)
|
|
298
|
+
: [
|
|
299
|
+
part(
|
|
300
|
+
config.subagentRouting === 'on'
|
|
301
|
+
? '○ Router · subagent model chosen at spawn'
|
|
302
|
+
: '○ Router · subagents keep their own model',
|
|
303
|
+
{ dimColor: true },
|
|
304
|
+
),
|
|
305
|
+
],
|
|
306
|
+
);
|
|
281
307
|
const kept = fitSegments(bandSegments(config, view, usage, actions), Math.max(0, columns - ROUTER_BUTTON));
|
|
282
308
|
const line = kept.flatMap((s, i) => (i ? [part(SEPARATOR, { dimColor: true }), ...s.parts] : s.parts));
|
|
283
309
|
line.push(part(' '), button({ key: 'details', label: 'Router', plain: true, onPress: actions.open }));
|
package/lib/display.mjs
CHANGED
|
@@ -16,6 +16,10 @@ import { allTime } from './usage.mjs';
|
|
|
16
16
|
|
|
17
17
|
// Cost order, cheapest first, so the colors read as a scale. Hex values: every surface draws them.
|
|
18
18
|
export const TIER_COLOR = { micro: '#5fd7af', low: '#5f9fe0', medium: '#d7af5f', high: '#e0708a' };
|
|
19
|
+
// A subagent's square by the model family it ran on, apart from the tier colors so a model never reads as a tier.
|
|
20
|
+
const MODEL_COLOR = { haiku: '#c3e88d', sonnet: '#f78c6c', opus: '#c792ea', fable: '#89ddff' };
|
|
21
|
+
export const modelColor = (id) =>
|
|
22
|
+
Object.entries(MODEL_COLOR).find(([family]) => String(id ?? '').includes(family))?.[1] ?? null;
|
|
19
23
|
|
|
20
24
|
// Why routing starts off: the session's model is no tier's model. Set at session start, read by the band.
|
|
21
25
|
export const NOT_A_TIER_REASON = 'not a routing tier';
|
|
@@ -38,11 +42,6 @@ export function routeName(config, route) {
|
|
|
38
42
|
return `${modelName(model.id)}${model.efforts.length ? ` · ${route.effort ?? 'session'}` : ''}`;
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
// Changes of route between consecutive replies, from the (model, effort) each request went out with, so a move inside
|
|
42
|
-
// a tier counts and a later change of settings does not rewrite the count. A reply routing did not choose breaks no run.
|
|
43
|
-
export const switchCount = (routes) =>
|
|
44
|
-
routes.slice(1).filter((route, i) => route && routes[i] && route !== routes[i]).length;
|
|
45
|
-
|
|
46
45
|
export const percent = (value) => `${Math.round(value * 100)}%`;
|
|
47
46
|
|
|
48
47
|
// Two shares that are compared, such as a classifier's support and the bar it must clear: whole percents, or as many
|