@alexeiled/claude-router 1.25.0 → 1.26.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.
@@ -40,6 +40,8 @@ const PLAN_CELLS = 8;
40
40
  const METER_CELLS = 4;
41
41
  // The pin Select's "no pin" choice.
42
42
  export const NO_PIN = 'none';
43
+ /** The "no pin" choice's words: what the Select offers with no pin, and how to drop a pending one. */
44
+ export const noPinLabel = (pending) => (pending ? 'No pin' : 'Pin to a tier');
43
45
 
44
46
  /**
45
47
  * One piece of a band segment: what it says and what it means, never how a surface draws it. A terminal maps `tone` to
@@ -432,7 +434,7 @@ export function pinOf(config, view) {
432
434
  return {
433
435
  value: pending ?? NO_PIN,
434
436
  options: [
435
- { value: NO_PIN, label: pending ? 'No pin' : 'Pin next turn' },
437
+ { value: NO_PIN, label: noPinLabel(pending) },
436
438
  ...TIERS.map((tier) => ({ value: tier, label: pinCard(config, tier) })),
437
439
  ],
438
440
  };
@@ -31,12 +31,14 @@ import {
31
31
  shownConfig,
32
32
  signedUsd,
33
33
  switchesLost,
34
+ tierBars,
34
35
  uncomparedText,
35
36
  usageMetrics,
36
37
  usd,
37
38
  whyText,
38
39
  } from '../../display.mjs';
39
40
  import { limitTone, savingTone } from '../tokens.mjs';
41
+ import { NO_PIN, noPinLabel } from './band.mjs';
40
42
  import { plural, sentence, sinceText } from './format.mjs';
41
43
 
42
44
  const dollars = (value) => (Number.isFinite(value) ? usd(value) : 'not reported');
@@ -59,8 +61,7 @@ function supportText(label, estimate) {
59
61
  /**
60
62
  * @typedef {object} NextPin one per tier, low to high
61
63
  * @property {string} tier
62
- * @property {import('./format.mjs').Words} route the route it runs, as the terminal's grid and a card name it
63
- * @property {string | null} support the classifier's support on the last turn
64
+ * @property {string} route the route it runs, as a card names it
64
65
  * @property {string | null} reading a card's: `current` on the tier that runs now, then the support
65
66
  *
66
67
  * @typedef {object} NextOffModel NEXT TURN with routing off or unavailable: only the model, a note and what pinning needs.
@@ -79,11 +80,21 @@ function supportText(label, estimate) {
79
80
  * @property {string | null} support
80
81
  * @property {string | null} override
81
82
  * @property {{ name: string, from: import('./format.mjs').Words, clear: string | null } | null} mode
83
+ * @property {import('./format.mjs').Words} pinHead what the pin row offers and the model that runs now
84
+ * @property {import('./format.mjs').Words} pinNote where a model no tier routes to is chosen
82
85
  * @property {NextPin[]} pins
86
+ * @property {PinControl} pinControl the pins as one Select: no pin, then one per tier, low to high
83
87
  * @property {string | null} pendingPin
84
88
  * @property {string} firstTurn a card's line before the first routed turn
85
89
  * @property {(tier: string) => void} pick pins the next turn; the pending pin again unpins
86
90
  *
91
+ * @typedef {object} PinControl
92
+ * @property {'pin'} key
93
+ * @property {string} value the pending pin's tier, or NO_PIN
94
+ * @property {{ value: string, label: string }[]} options
95
+ * @property {(value: string) => void} pick a tier pins the next turn; NO_PIN unpins
96
+ * @property {string} text the pending pin's route, or `none`, where a surface has no Select
97
+ *
87
98
  * @typedef {NextOffModel | NextRoutedModel} NextModel
88
99
  *
89
100
  * @typedef {object} Against a part's difference against no routing
@@ -163,7 +174,7 @@ function nextOf(config, view, actions) {
163
174
  if (view.mode !== 'auto')
164
175
  return {
165
176
  state: 'off',
166
- label: routeLabel(current, view.effort),
177
+ label: routeLabel(view.nativeModel, view.nativeEffort),
167
178
  note: { terminal: 'routing off · /model choice', graphical: 'Routing off · /model choice' },
168
179
  pin: { terminal: 'needs routing on (o)', graphical: 'Pinning needs routing on' },
169
180
  };
@@ -174,7 +185,13 @@ function nextOf(config, view, actions) {
174
185
  const override =
175
186
  mode === 'on' && view.activity && base && !sameRoute(resolveRoute(shown, view.tier, view.activity), base);
176
187
  const { mode: routingMode, source } = routingModeOf(view);
188
+ const runsNow = current ? ` · now ${routeLabel(current, view.effort)}` : '';
177
189
  const lever = modeLever(config, view);
190
+ const pending = view.pendingPin ?? null;
191
+ const supportOf = (tier) => {
192
+ const support = view.probabilities?.[tier];
193
+ return Number.isFinite(support) ? percent(support) : null;
194
+ };
178
195
  return {
179
196
  state: 'routed',
180
197
  label: routeLabel(current, view.effort),
@@ -200,25 +217,39 @@ function nextOf(config, view, actions) {
200
217
  clear: source === 'session' ? '/router mode default clears it' : null,
201
218
  }
202
219
  : null,
203
- // One per tier, low to high: the route it runs and the classifier's support on the last turn.
204
- pins: TIERS.map((tier) => {
205
- const support = view.probabilities?.[tier];
206
- return {
207
- tier,
208
- // A card names the model's family and the effort, as the Routes cards word them.
209
- route: {
210
- terminal: pinShort(config, tier),
211
- graphical: pinCard(config, tier),
212
- },
213
- support: Number.isFinite(support) ? percent(support) : null,
214
- // A graphical pin's reading: `current` on the tier that runs now, then the support; null with neither.
215
- reading:
216
- [tier === view.tier ? 'current' : null, Number.isFinite(support) ? percent(support) : null]
217
- .filter(Boolean)
218
- .join(' · ') || null,
219
- };
220
- }),
221
- pendingPin: view.pendingPin ?? null,
220
+ // The pins are tier pins, not a model picker: say so, show what runs now and point to /model for the rest.
221
+ pinHead: {
222
+ terminal: `pin next turn to a tier${runsNow}`,
223
+ graphical: `Pin next turn to a tier${runsNow}`,
224
+ },
225
+ pinNote: {
226
+ terminal: 'other models: /model, with routing off',
227
+ graphical: 'Other models: /model, with routing off',
228
+ },
229
+ // The graphical pins, one per tier, low to high: the route it runs and the classifier's support on the last turn.
230
+ pins: TIERS.map((tier) => ({
231
+ tier,
232
+ // A card names the model's family and the effort, as the Routes cards word them.
233
+ route: pinCard(config, tier),
234
+ // `current` on the tier that runs now, then the support; null with neither.
235
+ reading: [tier === view.tier ? 'current' : null, supportOf(tier)].filter(Boolean).join(' · ') || null,
236
+ })),
237
+ // The terminal's pins as one Select: no pin first, then each tier named by its bars, its route and its support, the
238
+ // tier that runs now marked.
239
+ pinControl: {
240
+ key: 'pin',
241
+ value: pending ?? NO_PIN,
242
+ options: [
243
+ { value: NO_PIN, label: noPinLabel(pending) },
244
+ ...TIERS.map((tier) => ({
245
+ value: tier,
246
+ label: `${tier === view.tier ? '▶ ' : ''}${tierBars(tier)} ${pinShort(config, tier)} ${supportOf(tier) ?? '—'}`,
247
+ })),
248
+ ],
249
+ pick: (value) => (value === NO_PIN ? actions.unpin() : actions.pin(value)),
250
+ text: pending ? [tierBars(pending), pinShort(config, pending)].filter(Boolean).join(' ') : 'none',
251
+ },
252
+ pendingPin: pending,
222
253
  // A card's line before the first routed turn, where the terminal shows none.
223
254
  firstTurn: 'No routed turn yet — the first reply sets the route.',
224
255
  // A press pins the next turn; pressing the pending pin again unpins it.
@@ -25,9 +25,11 @@ import { CHIP_BACKGROUND, TIER_COLOR, toneColor } from '../tokens.mjs';
25
25
 
26
26
  // The hover row's controls sit closer: they are buttons, not readings.
27
27
  const GAP = ' ';
28
- // What follows the readings: a gap, then Router as a plain label. The graphical band draws Router as a bordered Button,
29
- // which is its label and the Button's own `[ ` and ` ]` wide, with no gap before it.
30
- const ROUTER_TAIL = 2 + 'Router'.length;
28
+ // What follows the readings: a gap, then Router as a bracketed Button, `[ Router ]`, where the brackets cost no reading,
29
+ // or as a plain label where they would. The graphical band always draws Router as a bordered Button.
30
+ const ROUTER_LABEL = 'Router';
31
+ const ROUTER_GAP = 2;
32
+ const BRACKETS = '[ ]'.length;
31
33
  // The fewest columns the hover controls are drawn in: Turn off and a gap.
32
34
  const OVERLAY_MIN = 12;
33
35
  // The tier meter's glyphs, one per bar.
@@ -135,17 +137,12 @@ export function terminalBand(elements, config, view, usage, { columns, agentId,
135
137
  ...agentParts(config, agent, back ? room : columns),
136
138
  ]);
137
139
  }
138
- const width = Number.isFinite(columns) ? Math.max(0, columns - ROUTER_TAIL) : columns;
139
- const kept = fitSegments(bandSegments(config, view, usage, actions), width);
140
- const left = joinSegments(kept.filter((s) => !s.right));
141
- const end = joinSegments(kept.filter((s) => s.right));
142
- const pad = end.length
143
- ? Number.isFinite(width)
144
- ? Math.max(SEPARATOR.length, width - partsWidth(left) - partsWidth(end))
145
- : SEPARATOR.length
146
- : 0;
147
- const line = [...left, ...(pad ? [part(' '.repeat(pad))] : []), ...end];
148
- line.push(part(' '), button({ key: 'details', label: 'Router', plain: true, onPress: actions.open }));
140
+ const segments = bandSegments(config, view, usage, actions);
141
+ // The brackets go first: Router keeps them only where they cost nothing the plain label leaves room for, neither a
142
+ // reading nor a hover control.
143
+ const plain = bandLayout(config, view, actions, segments, columns, false);
144
+ const bracketed = bandLayout(config, view, actions, segments, columns, true);
145
+ const { line, hover } = sameLayout(plain, bracketed, columns) ? bracketed : plain;
149
146
  const running = joinSegments(agentSegments(agents ?? [], columns, actions));
150
147
  const second = view.bandDetail ? sessionRow(config, view, usage, columns, now) : [];
151
148
  return Box({
@@ -155,7 +152,7 @@ export function terminalBand(elements, config, view, usage, { columns, agentId,
155
152
  Box({
156
153
  children: [
157
154
  ...line.flatMap((p) => drawPart(elements, p)),
158
- ...hoverOverlays(elements, config, view, actions, kept, line, columns),
155
+ ...hover.map((stretch) => overlay(elements, stretch)),
159
156
  ],
160
157
  }),
161
158
  running.length ? row(running) : null,
@@ -164,20 +161,54 @@ export function terminalBand(elements, config, view, usage, { columns, agentId,
164
161
  });
165
162
  }
166
163
 
167
- // The hover controls, drawn on the row rather than on a row of their own, so the pointer moves nothing. The row has two
168
- // free stretches: over the readings, from after the leading segments up to the last one holding a control (the meter
169
- // and model, a warning with Set up, a pin with its ✕) to the gap before Router; and after Router, to the band's end.
170
- // With readings at the row's end Router sits at the band's end, and the first is all there is. The controls fill the
171
- // wider stretch, and what does not fit goes to the other; each is padded with spaces to blank what is beneath, so no
172
- // Button of the row is covered. A stretch under OVERLAY_MIN columns holds none.
173
- function hoverOverlays(elements, config, view, actions, kept, line, columns) {
174
- const { Box } = elements;
164
+ // The first row's parts with Router after them, plain or in brackets, and where its hover controls go.
165
+ function bandLayout(config, view, actions, segments, columns, brackets) {
166
+ const tail = ROUTER_GAP + ROUTER_LABEL.length + (brackets ? BRACKETS : 0);
167
+ const width = Number.isFinite(columns) ? Math.max(0, columns - tail) : columns;
168
+ const kept = fitSegments(segments, width);
169
+ const left = joinSegments(kept.filter((s) => !s.right));
170
+ const end = joinSegments(kept.filter((s) => s.right));
171
+ const pad = end.length
172
+ ? Number.isFinite(width)
173
+ ? Math.max(SEPARATOR.length, width - partsWidth(left) - partsWidth(end))
174
+ : SEPARATOR.length
175
+ : 0;
176
+ const line = [
177
+ ...left,
178
+ ...(pad ? [part(' '.repeat(pad))] : []),
179
+ ...end,
180
+ part(' '.repeat(ROUTER_GAP)),
181
+ // The engine takes `plain` as true or not at all.
182
+ button({ key: 'details', label: ROUTER_LABEL, ...(brackets ? {} : { plain: true }), onPress: actions.open }),
183
+ ];
184
+ const readings = lineWidth(kept, SEPARATOR);
185
+ return { width, readings, line, hover: hoverPlan(config, view, actions, { kept, line, tail }, columns) };
186
+ }
187
+
188
+ // The hover controls' labels, in order: what a layout offers under the pointer.
189
+ const hoverLabels = (hover) =>
190
+ hover.flatMap(({ fitted }) => fitted.flatMap((s) => s.parts.filter((p) => p.button).map((p) => p.button.label)));
191
+
192
+ // Whether the bracketed layout shows every reading and hover control the plain one does, within its width.
193
+ function sameLayout(plain, bracketed, columns) {
194
+ if (bracketed.readings !== plain.readings) return false;
195
+ if (Number.isFinite(columns) && plain.readings > bracketed.width) return false;
196
+ return hoverLabels(bracketed.hover).join('\n') === hoverLabels(plain.hover).join('\n');
197
+ }
198
+
199
+ // Where the hover controls go, drawn on the row rather than on a row of their own, so the pointer moves nothing. The row
200
+ // has two free stretches: over the readings, from after the leading segments up to the last one holding a control (the
201
+ // meter and model, a warning with Set up, a pin with its ✕) to the gap before Router; and after Router, to the band's
202
+ // end. With readings at the row's end Router sits at the band's end, and the first is all there is. The controls fill
203
+ // the wider stretch, and what does not fit goes to the other; each is padded with spaces to blank what is beneath, so
204
+ // no Button of the row is covered. A stretch under OVERLAY_MIN columns holds none.
205
+ function hoverPlan(config, view, actions, { kept, line, tail }, columns) {
175
206
  const lead = kept.filter((s) => !s.right);
176
207
  const last = lead.findLastIndex((s) => s.parts.some((p) => p.button));
177
208
  const over = lineWidth(lead.slice(0, Math.max(0, last) + 1), SEPARATOR) + SEPARATOR.length;
178
209
  const after = partsWidth(line) + GAP.length;
179
210
  const stretches = [
180
- { left: over, width: partsWidth(line) - ROUTER_TAIL - over },
211
+ { left: over, width: partsWidth(line) - tail - over },
181
212
  { left: after, width: Number.isFinite(columns) ? columns - after : Number.POSITIVE_INFINITY },
182
213
  ]
183
214
  .filter((stretch) => stretch.width >= OVERLAY_MIN)
@@ -193,24 +224,26 @@ function hoverOverlays(elements, config, view, actions, kept, line, columns) {
193
224
  const first = fit(segments, widest.width);
194
225
  const rest = segments.filter((s) => !first.some((placed) => placed.n === s.n));
195
226
  const second = narrower && rest.length ? fit(rest, narrower.width) : [];
196
- const overlay = ({ left, width }, fitted) => {
197
- const controls = fitted.flatMap((s, i) => (i ? [part(GAP), ...s.parts] : s.parts));
198
- const pad = Number.isFinite(width) ? width - partsWidth(controls) : 0;
199
- return Box({
200
- position: 'absolute',
201
- top: 0,
202
- left,
203
- display: 'none',
204
- hover: { display: 'flex' },
205
- children: [...controls, ...(pad > 0 ? [part(' '.repeat(pad))] : [])].flatMap((p) => drawPart(elements, p)),
206
- });
207
- };
208
227
  return [
209
- ...(first.length ? [overlay(widest, first)] : []),
210
- ...(narrower && second.length ? [overlay(narrower, second)] : []),
228
+ ...(first.length ? [{ ...widest, fitted: first }] : []),
229
+ ...(narrower && second.length ? [{ ...narrower, fitted: second }] : []),
211
230
  ];
212
231
  }
213
232
 
233
+ // One stretch of hover controls: hidden until the pointer is over the row, padded to blank what is beneath.
234
+ function overlay(elements, { left, width, fitted }) {
235
+ const controls = fitted.flatMap((s, i) => (i ? [part(GAP), ...s.parts] : s.parts));
236
+ const pad = Number.isFinite(width) ? width - partsWidth(controls) : 0;
237
+ return elements.Box({
238
+ position: 'absolute',
239
+ top: 0,
240
+ left,
241
+ display: 'none',
242
+ hover: { display: 'flex' },
243
+ children: [...controls, ...(pad > 0 ? [part(' '.repeat(pad))] : [])].flatMap((p) => drawPart(elements, p)),
244
+ });
245
+ }
246
+
214
247
  // The route line the terminal places under a turn: the band's words, indented like the transcript's own dim lines.
215
248
  export function terminalRouteLine(elements, config, line, { columns }) {
216
249
  const indent = ' ';
@@ -1,6 +1,6 @@
1
1
  // The Classifier tab as terminal rows: one row per classifier to compare, then the active one's settings and
2
- // readings, this session's agreement and the counts across sessions. Drawn from the model in
3
- // ui/model/classifier.mjs.
2
+ // readings with this session's agreement, in a box from PANEL_COLUMNS, and the counts across sessions. Drawn from the
3
+ // model in ui/model/classifier.mjs.
4
4
  import { isFiniteNumber, toneColor } from '../tokens.mjs';
5
5
  import { dimLines } from './wrap.mjs';
6
6
 
@@ -38,17 +38,19 @@ export function terminalClassifier(ui, model, { columns }) {
38
38
  ui.cell(12, ui.select(active.deadline.control)),
39
39
  wait.slow ? ui.text(wait.text, { color: ui.color('warning') }) : ui.dim(wait.text),
40
40
  ];
41
- const settings = twoLine
42
- ? [
43
- ui.field(12, active.deadline.label, [ui.line(...deadline), ui.help(ui.say(active.deadline.help))]),
44
- ui.field(12, sends.label, [ui.text(ui.say(sends.text), { wrap: 'wrap' }), ui.help(ui.say(sends.help))]),
45
- ]
46
- : [
47
- ui.line(ui.cell(12, active.deadline.label), ...deadline),
48
- ui.dim(`${''.padEnd(12)}${ui.say(active.deadline.help)}`),
49
- ui.line(ui.cell(12, sends.label), ui.say(sends.text)),
50
- ui.dim(` ${ui.say(sends.help)}`),
51
- ];
41
+ // In a box the fixed help lines would overflow its inner width, so they hang in their field as they do when narrow.
42
+ const settings =
43
+ twoLine || ui.boxed(columns)
44
+ ? [
45
+ ui.field(12, active.deadline.label, [ui.line(...deadline), ui.help(ui.say(active.deadline.help))]),
46
+ ui.field(12, sends.label, [ui.text(ui.say(sends.text), { wrap: 'wrap' }), ui.help(ui.say(sends.help))]),
47
+ ]
48
+ : [
49
+ ui.line(ui.cell(12, active.deadline.label), ...deadline),
50
+ ui.dim(`${''.padEnd(12)}${ui.say(active.deadline.help)}`),
51
+ ui.line(ui.cell(12, sends.label), ui.say(sends.text)),
52
+ ui.dim(` ${ui.say(sends.help)}`),
53
+ ];
52
54
  return [
53
55
  ui.line(ui.head('CLASSIFIER'), ui.dim(' · asked once per new turn · a pick saves at once')),
54
56
  twoLine
@@ -59,25 +61,31 @@ export function terminalClassifier(ui, model, { columns }) {
59
61
  ...rows,
60
62
  ...dimLines(ui, ` ${ui.say(model.probeNote)}`, columns),
61
63
  ui.text(' '),
62
- ui.line(ui.head(active.label.toUpperCase()), ui.dim(' · active')),
63
- ...settings,
64
- ui.line(
65
- ui.cell(12, health.label),
66
- health.paused ? ui.text(health.paused, { color: ui.color('warning') }) : health.steady,
67
- ` · ${health.failures}`,
68
- health.last ? ui.dim(` · ${health.last}`) : null,
69
- ),
70
- ui.line(
71
- ui.cell(12, credentials.label),
72
- ui.Button({
73
- key: credentials.button.key,
74
- label: credentials.button.label,
75
- hotkey: credentials.button.hotkey,
76
- onPress: credentials.button.press,
77
- }),
78
- ui.dim(` ${credentials.note}`),
64
+ ...ui.panel(
65
+ columns,
66
+ [
67
+ ui.line(ui.head(active.label.toUpperCase()), ui.dim(' · active')),
68
+ ...settings,
69
+ ui.line(
70
+ ui.cell(12, health.label),
71
+ health.paused ? ui.text(health.paused, { color: ui.color('warning') }) : health.steady,
72
+ ` · ${health.failures}`,
73
+ health.last ? ui.dim(` · ${health.last}`) : null,
74
+ ),
75
+ ui.line(
76
+ ui.cell(12, credentials.label),
77
+ ui.Button({
78
+ key: credentials.button.key,
79
+ label: credentials.button.label,
80
+ hotkey: credentials.button.hotkey,
81
+ onPress: credentials.button.press,
82
+ }),
83
+ ui.dim(` ${credentials.note}`),
84
+ ),
85
+ ...(active.session ? [ui.text(' '), ui.head(active.session.head), ui.text(active.session.text)] : []),
86
+ ],
87
+ false,
79
88
  ),
80
- ...(active.session ? [ui.text(' '), ui.head(active.session.head), ui.text(active.session.text)] : []),
81
89
  ...(model.store
82
90
  ? [
83
91
  ui.text(' '),
@@ -8,6 +8,16 @@ import { TIER_COLOR, toneColor } from '../tokens.mjs';
8
8
  const ACTIVITY_STYLE = { color: toneColor('activity', 'terminal'), italic: true };
9
9
  // A trend's blocks, lowest to highest; a bucket without anything is a dot.
10
10
  const SPARK = '▁▂▃▄▅▆▇█';
11
+ // The narrowest pane that draws a section in a box: Now's widest fixed row, the main/agents cost bar with its `vs` note
12
+ // (61-64 cells), still fits inside. Narrower panes, every narrow pane under 64 among them, keep the plain sections.
13
+ export const PANEL_COLUMNS = 72;
14
+ // What a box takes across: its border and one cell of padding on each side.
15
+ export const PANEL_CHROME = 4;
16
+
17
+ /** Whether a pane `columns` wide draws its sections in boxes: from PANEL_COLUMNS, or with no width. */
18
+ export const boxed = (columns) => !Number.isFinite(columns) || columns >= PANEL_COLUMNS;
19
+ /** The columns a section's lines have: the pane's, less the box around them where there is one. */
20
+ export const inner = (columns) => (boxed(columns) && Number.isFinite(columns) ? columns - PANEL_CHROME : columns);
11
21
 
12
22
  // The session strip fitted to the pane beside its note: pairs of cells merge until both fit.
13
23
  function fittedStrip(strip, columns, since, now) {
@@ -52,6 +62,25 @@ export function kit({ Box, Text, Button, Select }) {
52
62
  activity: (activity) => text(activity, ACTIVITY_STYLE),
53
63
  line,
54
64
  cell,
65
+ boxed,
66
+ inner,
67
+ // A section: its lines in a single-line box from PANEL_COLUMNS, with its title as the first line inside, since the
68
+ // terminal draws no title in a border. Narrower, the lines as they are, then a blank line to part them from the
69
+ // next section unless `spaced` is false.
70
+ panel: (columns, lines, spaced = true) =>
71
+ boxed(columns)
72
+ ? [
73
+ Box({
74
+ flexDirection: 'column',
75
+ borderStyle: 'single',
76
+ borderColor: toneColor('muted', 'terminal'),
77
+ paddingX: 1,
78
+ children: lines.filter(Boolean),
79
+ }),
80
+ ]
81
+ : spaced
82
+ ? [...lines, text(' ')]
83
+ : lines,
55
84
  };
56
85
  return { ...base, ...painters(base), ...forms(base) };
57
86
  }
@@ -1,12 +1,14 @@
1
- // The Now tab as terminal rows: NEXT TURN, RECENT DECISIONS, PLAN, SESSION, CONTEXT, each a run of sibling lines under
2
- // the pane, drawn from the model in ui/model/now.mjs. The colours are the ones the terminal has always drawn for each
3
- // reading, derived here from the model's numbers.
4
- import { gaugeCells, sparkline, tierBars } from '../../display.mjs';
1
+ // The Now tab as terminal rows: NEXT TURN, RECENT DECISIONS, PLAN, SESSION, CONTEXT, each in a box from PANEL_COLUMNS
2
+ // and a run of lines under the pane below it, drawn from the model in ui/model/now.mjs. The colours are the ones the
3
+ // terminal has always drawn for each reading, derived here from the model's numbers.
4
+ import { gaugeCells, sparkline } from '../../display.mjs';
5
5
  import { CHIP_BACKGROUND, isFiniteNumber } from '../tokens.mjs';
6
+ import { dimLines } from './wrap.mjs';
6
7
 
7
- // Below this a pin row holds one pin.
8
- const PIN_ROW_COLUMNS = 64;
9
8
  const SESSION_BAR = 16;
9
+ // A cost bar's label and its amount, before the bar.
10
+ const PART_LABEL = 8;
11
+ const AMOUNT = 7;
10
12
  const ESTIMATE_LABEL = 22;
11
13
 
12
14
  /**
@@ -15,21 +17,23 @@ const ESTIMATE_LABEL = 22;
15
17
  * @param {{ columns: number | null, now: number }} opts
16
18
  */
17
19
  export function terminalNow(ui, model, { columns, now }) {
20
+ // Each section stacks full width: from PANEL_COLUMNS in a box, so its lines fit the box's inner width.
21
+ const room = ui.inner(columns);
18
22
  return [
19
- ...nextLines(ui, model.next, columns),
23
+ ...ui.panel(columns, nextLines(ui, model.next, room)),
20
24
  ...(model.decisions.length
21
- ? [ui.head('RECENT DECISIONS'), ...model.decisions.map((line) => ui.text(line)), ui.text(' ')]
25
+ ? ui.panel(columns, [ui.head('RECENT DECISIONS'), ...model.decisions.map((line) => ui.text(line))])
22
26
  : []),
23
- ...planLines(ui, model.plan),
24
- ...sessionLines(ui, model.session, columns, now),
25
- ...contextLines(ui, model.context),
27
+ ...(model.plan.length ? ui.panel(columns, planLines(ui, model.plan)) : []),
28
+ ...ui.panel(columns, sessionLines(ui, model.session, room, now)),
29
+ ...ui.panel(columns, contextLines(ui, model.context), false),
26
30
  ];
27
31
  }
28
32
 
29
33
  /**
30
34
  * @param {any} ui
31
35
  * @param {import('../model/now.mjs').NextModel} next
32
- * @param {number | null} columns
36
+ * @param {number | null} columns the section's own columns
33
37
  */
34
38
  // NEXT TURN. With routing off or unavailable only the model applies: no tier, activity or reason from an earlier turn.
35
39
  function nextLines(ui, next, columns) {
@@ -64,7 +68,6 @@ function nextLines(ui, next, columns) {
64
68
  )
65
69
  : null,
66
70
  ...pinLines(ui, next, columns),
67
- ui.text(' '),
68
71
  );
69
72
  return out.filter(Boolean);
70
73
  }
@@ -83,7 +86,6 @@ function offLines(ui, next) {
83
86
  ui.dim(` ${ui.say(next.note)}`),
84
87
  ),
85
88
  ui.line(ui.dim(' pin '), ui.dim(ui.say(next.pin))),
86
- ui.text(' '),
87
89
  ];
88
90
  }
89
91
 
@@ -92,20 +94,13 @@ function offLines(ui, next) {
92
94
  * @param {import('../model/now.mjs').NextRoutedModel} next
93
95
  * @param {number | null} columns
94
96
  */
95
- // One button per tier, low to high, named by the route it runs ("▂▄ Haiku·high") with the classifier's support on the
96
- // last turn; the current tier is marked and a pending pin is filled. A press pins the next turn only; pressing the
97
- // pending pin again unpins it.
97
+ // The pins as one dropdown under what they offer: a tier pins the next turn only, No pin drops a pending pin.
98
98
  function pinLines(ui, next, columns) {
99
- const pin = ({ tier, route, support }) =>
100
- ui.Button({
101
- key: `pin-${tier}`,
102
- label: `${next.tier === tier ? '▶ ' : ''}${tierBars(tier)} ${ui.say(route)} ${support ?? '—'}`,
103
- variant: next.pendingPin === tier ? 'primary' : 'secondary',
104
- onPress: () => next.pick(tier),
105
- });
106
- const narrow = isFiniteNumber(columns) && columns < PIN_ROW_COLUMNS;
107
- const rows = narrow ? next.pins.map((one) => [one]) : [next.pins.slice(0, 2), next.pins.slice(2)];
108
- return rows.map((pins, i) => ui.line(i ? ' ' : ui.dim(' pin '), ...pins.flatMap((one) => [pin(one), ' '])));
99
+ return [
100
+ ...dimLines(ui, ` ${ui.say(next.pinHead)}`, columns),
101
+ ui.line(' ', ui.select(next.pinControl)),
102
+ ...dimLines(ui, ` ${ui.say(next.pinNote)}`, columns),
103
+ ];
109
104
  }
110
105
 
111
106
  /**
@@ -114,7 +109,6 @@ function pinLines(ui, next, columns) {
114
109
  */
115
110
  // PLAN: Claude Code's plan windows, when it reports them.
116
111
  function planLines(ui, plan) {
117
- if (!plan.length) return [];
118
112
  return [
119
113
  ui.line(ui.head('PLAN'), ui.dim(' Claude plan usage')),
120
114
  ...plan.map((limit) => {
@@ -128,14 +122,13 @@ function planLines(ui, plan) {
128
122
  limit.reset ? ui.dim(` resets ${limit.reset}`) : null,
129
123
  );
130
124
  }),
131
- ui.text(' '),
132
125
  ];
133
126
  }
134
127
 
135
128
  /**
136
129
  * @param {any} ui
137
130
  * @param {import('../model/now.mjs').SessionModel} session
138
- * @param {number | null} columns
131
+ * @param {number | null} columns the section's own columns
139
132
  * @param {number} now
140
133
  */
141
134
  // SESSION: one total with the subagents, the difference against no routing, the main thread and the subagents as bars
@@ -153,7 +146,7 @@ function sessionLines(ui, session, columns, now) {
153
146
  ),
154
147
  ];
155
148
  // Replies without a list price reach the strip but not the usage record: the tiers still show, the cost cannot.
156
- if (!session.priced) return [...out, ui.dim(` ${ui.say(session.empty)}`), ...strip, ui.text(' ')];
149
+ if (!session.priced) return [...out, ui.dim(` ${ui.say(session.empty)}`), ...strip];
157
150
  out.push(
158
151
  ui.line(
159
152
  ' ',
@@ -177,39 +170,39 @@ function sessionLines(ui, session, columns, now) {
177
170
  );
178
171
  }
179
172
  if (session.note) out.push(ui.dim(` ${session.note}`));
180
- out.push(...costBars(ui, session));
173
+ out.push(...costBars(ui, session, columns));
181
174
  if (session.lost) out.push(ui.lostLine(session.policy));
182
- out.push(...strip, ui.text(' '));
175
+ out.push(...strip);
183
176
  return out;
184
177
  }
185
178
 
186
179
  /**
187
180
  * @param {any} ui
188
181
  * @param {import('../model/now.mjs').SessionModel} session
182
+ * @param {number | null} columns the section's own columns
189
183
  */
190
- // The main thread and the subagents as bars on one scale, each with its difference against no routing; an effort-only
191
- // profile shows its effort mix.
192
- function costBars(ui, session) {
184
+ // The main thread and the subagents as bars on one scale, each with its difference against no routing where it fits; an
185
+ // effort-only profile shows its effort mix.
186
+ function costBars(ui, session, columns) {
193
187
  const { scale } = session;
194
188
  const bar = (value) => {
195
189
  const filled = scale > 0 ? Math.max(value > 0 ? 1 : 0, Math.round((value / scale) * SESSION_BAR)) : 0;
196
190
  return [ui.text('█'.repeat(filled), { color: ui.color('accent') }), ui.dim('░'.repeat(SESSION_BAR - filled))];
197
191
  };
198
- const line = (against) =>
199
- against
200
- ? ui.line(
201
- ' ',
202
- ui.text(against.text, against.tone ? { color: ui.color(against.tone) } : {}),
203
- ui.dim(` vs ${against.versus}`),
204
- )
205
- : null;
192
+ const versus = (against) => {
193
+ if (!against) return null;
194
+ const note = ` vs ${against.versus}`;
195
+ const width = PART_LABEL + AMOUNT + 2 + SESSION_BAR + 2 + against.text.length + note.length;
196
+ if (isFiniteNumber(columns) && width > columns) return null;
197
+ return ui.line(' ', ui.text(against.text, against.tone ? { color: ui.color(against.tone) } : {}), ui.dim(note));
198
+ };
206
199
  const out = session.parts.map((part) =>
207
200
  ui.line(
208
201
  part.name === 'main' ? ' main ' : ' agents',
209
- part.amount.padStart(7),
202
+ part.amount.padStart(AMOUNT),
210
203
  ' ',
211
204
  ...bar(part.usd),
212
- line(part.against),
205
+ versus(part.against),
213
206
  ),
214
207
  );
215
208
  if (session.effortMix.length)