sumo-agents 0.5.0 → 0.7.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/src/ui.mjs CHANGED
@@ -12,11 +12,12 @@ import { INPUT_SHOWN } from './mcp.mjs';
12
12
  import { paths } from './paths.mjs';
13
13
  import { scratchDir } from './projects.mjs';
14
14
  import { redact } from './redact.mjs';
15
+ import { keyName, settingsPage, SettingsView } from './settings.mjs';
15
16
  import { elapsed } from './text.mjs';
16
17
  import { cleanPaste, editor, keysOf, matchFiles, menuOf, paste, press, under } from './editor.mjs';
17
18
  import { clipboardImage, copyText, droppedImages } from './images.mjs';
18
19
  import { ASK_TOOL, BASH_TOOL, DELEGATE_TOOL, EDITOR_TOOL } from './tools.mjs';
19
- import { colourEnabled, createRenderer, explained, fold, glyphs, GUTTER, inline, linked, logoLines, markdownOf, messageAt, OUT_AT, pathFrom, pickMessage, renderBlock, safeForTerminal, spinnerMessages, styles, TEXT_AT, tilde, toolView, transcript, unnamed, untab, VERSION, withoutColourCodes, withSpan, wrap } from './tty.mjs';
20
+ import { colourEnabled, createRenderer, explained, flow, fold, glyphs, inline, linked, logoLines, markdownOf, messageAt, pathFrom, pickMessage, renderBlock, safeForTerminal, spinnerMessages, statOf, styles, sunset, tilde, toolView, transcript, untab, VERSION, withoutColourCodes, withSpan, wrap } from './tty.mjs';
20
21
 
21
22
  /**
22
23
  * The chat on a real terminal. What is finished scrolls away above — what
@@ -29,10 +30,9 @@ import { colourEnabled, createRenderer, explained, fold, glyphs, GUTTER, inline,
29
30
  * says who it is — each call on one line, its output behind Ctrl-O — and a
30
31
  * line starting with @ is said to it. An image pasted with Ctrl-V, or a file
31
32
  * dropped on the box, stands in it as `[Image #n]` and goes with the message
32
- * that names it. Every row is set in a ledger: named on the left in a word —
33
- * you, sumo, read, edit, run, ask — its state beside the name, its words after.
34
- * While the conversation is short the box stands at the foot of the window, and
35
- * until the first message is sent the logo stands faint in the room above it. A command
33
+ * that names it. The chat opens on its name in blocks, in a sunset; while the
34
+ * conversation is short the box stands at the foot of the window, and until the
35
+ * first message is sent the logo stands faint in the room above it. A command
36
36
  * shows what it prints while it runs; a message sent while the model works is
37
37
  * read with its next request; a turn ends on a line that says how long it took,
38
38
  * what it changed and what it cost, and — when the window is not the one in
@@ -43,14 +43,13 @@ import { colourEnabled, createRenderer, explained, fold, glyphs, GUTTER, inline,
43
43
  * is drawing; the session in chat.mjs does the work.
44
44
  */
45
45
 
46
- /** The chat's one colour of its own: the terminal's cyan, so the theme the user chose decides its shade, light or dark. */
47
- const ACCENT = 'cyan';
46
+ const ACCENT = '#d77757';
48
47
  /** The marks the screen draws with: plain ones (`chat.screen plain`) for a screen reader. Every component reads them here. */
49
48
  const Marks = createContext(glyphs(false));
50
49
  const useMarks = () => useContext(Marks);
51
50
  /** The name at the top of the chat, two rows of blocks. */
52
- /** How often the spinner on the working line turns: a line with one cell changed, not every character in a colour of its own. */
53
- const SPIN_MS = 100;
51
+ const WORDMARK = ['█▀▀ █ █ █▀▄▀█ █▀█', '▄▄█ █▄█ █ ▀ █ █▄█'];
52
+ const FLOW_STEP_MS = 100;
54
53
  const TONES = { plain: {}, dim: { dimColor: true }, error: { color: 'red' }, add: { color: 'green' }, del: { color: 'red' }, ask: { color: 'yellow' } };
55
54
  const LEAVE_WINDOW_MS = 2000;
56
55
  const NOTICE_MS = 3000;
@@ -62,6 +61,10 @@ const CLEAR = '\x1b[2J\x1b[3J\x1b[H';
62
61
  * the drawing starts at the top. For a chat that opens, or starts over — nothing that was on the terminal is lost to it.
63
62
  */
64
63
  const scrolledClear = (rows) => `\x1b[${rows};1H${'\n'.repeat(rows)}\x1b[H`;
64
+ /** A report that the window came to the front (`ESC[I`) or went behind (`ESC[O`). */
65
+ const FOCUS_REPORT = /\x1b\[[IO]/g;
66
+ /** How long the start of a sequence at the end of a read waits for its rest; and how long after a bare ESC went on as the Esc key a `[I` or `[O` is still the rest of a focus report. */
67
+ const FOCUS_LATE_MS = 1000;
65
68
  /** The terminal says when its window comes to the front and goes behind (`[I`, `[O`); and keeps its title, to be given back. */
66
69
  const FOCUS_ON = '\x1b[?1004h';
67
70
  const FOCUS_OFF = '\x1b[?1004l';
@@ -238,15 +241,13 @@ const retryNote = ({ attempt, limit, reason }) => `${retryWhy(reason)} · retryi
238
241
  const reverse = (text) => `\x1b[7m${text}\x1b[27m`;
239
242
 
240
243
  /**
241
- * The lines under a call: what came back, under the words of the step. Folded to `columns` here, by the same count the
242
- * replies are folded by, so a line too long for the window goes on under itself — not under the gutter, and not past the
243
- * edge. With `max`, at most that many rows: the last says how many lines were folded away — a line partly shown is shown.
244
- * `at` is the column they start on: what came back stands under the step's words, a note of the chat's own under its words.
244
+ * The lines under a call: what came back, the first of them with the mark. Folded to `columns` here, by the same count the
245
+ * replies are folded by, so a line too long for the window goes on under itself — not under the mark, and not past the edge.
246
+ * With `max`, at most that many rows: the last says how many lines were folded away — a line partly shown is shown.
245
247
  */
246
- const linesUnder = (lines, columns, s = styles(false), max = null, at = OUT_AT) => {
248
+ const linesUnder = (lines, columns, s = styles(false), max = null) => {
247
249
  const rows = [];
248
250
  let reached = 0;
249
- const room = Math.max(20, columns - at - 1);
250
251
  // Folded only as far as the budget needs: a long edit is not laid out whole to show its top.
251
252
  while (reached < lines.length && (max === null || rows.length <= max)) {
252
253
  const line = lines[reached];
@@ -254,7 +255,7 @@ const linesUnder = (lines, columns, s = styles(false), max = null, at = OUT_AT)
254
255
  const text = line.span ? withSpan(line, { ...s, inverse: reverse }) : linked(untab(line.text), s);
255
256
  // A numbered line — a diff's, a file's — and an item of a list go on under their own text, not under the number or the bullet.
256
257
  const hang = /^\s*(?:\d+(?: [-+ ] | {2,})\s*|[•*-] |\d+[.)] )/.exec(text)?.[0].length ?? 0;
257
- rows.push(...fold(text, room, ' '.repeat(Math.min(hang, Math.floor(room / 2)))).map((row) => ({ ...line, text: row, from: reached })));
258
+ rows.push(...fold(text, Math.max(20, columns - 6), ' '.repeat(Math.min(hang, Math.floor((columns - 6) / 2)))).map((row) => ({ ...line, text: row, from: reached })));
258
259
  reached++;
259
260
  }
260
261
  let kept = rows;
@@ -265,8 +266,7 @@ const linesUnder = (lines, columns, s = styles(false), max = null, at = OUT_AT)
265
266
  const folded = lines.length - whole;
266
267
  kept.push({ text: `… +${folded} line${folded === 1 ? '' : 's'}`, tone: 'dim' });
267
268
  }
268
- const indent = ' '.repeat(at);
269
- return kept.map((line, i) => h(Text, { key: i, ...TONES[line.tone], wrap: 'truncate' }, `${indent}${line.text}`));
269
+ return kept.map((line, i) => h(Text, { key: i, ...TONES[line.tone], wrap: 'truncate' }, `${i === 0 ? ` ${s.g.under} ` : ' '}${line.text}`));
270
270
  };
271
271
 
272
272
  /**
@@ -278,60 +278,39 @@ function lastLines({ out, cut }) {
278
278
  return (cut ? lines.slice(1) : lines).map((l) => untab(l).trimEnd()).filter(Boolean).slice(-LIVE_LINES);
279
279
  }
280
280
 
281
- /** The last of what a running command has printed so far, faint, under its words: how long it has run is on the step's own row. */
282
- const runningLines = (live) => (live ? lastLines(live) : []).map((line, i) => h(Text, { key: `live-${i}`, dimColor: true, wrap: 'truncate' }, `${' '.repeat(OUT_AT)}${line}`));
283
-
284
- /**
285
- * A row of the ledger: its name set right in the gutter, its state in the column beside it, its words from there on —
286
- * going on under themselves, never under the name. `tone` colours the name, `markTone` the state.
287
- */
288
- function Row({ label = '', tone = DIM, mark = ' ', markTone = null, columns, marginTop = 0, children }) {
289
- return h(
290
- Box,
291
- { marginTop },
292
- h(Box, { flexShrink: 0, width: TEXT_AT }, h(Text, null, h(Text, tone, String(label).slice(0, GUTTER).padStart(GUTTER)), ' ', h(Text, markTone, mark), ' ')),
293
- // A width of its own: a box in a row is never made narrower than its longest word, and a command can be one long word.
294
- h(Box, { flexDirection: 'column', flexShrink: 1, width: Math.max(10, columns - TEXT_AT) }, ...[children].flat()),
295
- );
296
- }
297
- const DIM = { dimColor: true };
298
- /** Words for a row of the ledger, folded to what is left of the window after the gutter, each line on its own. */
299
- const folded = (text, columns) =>
300
- String(text)
301
- .split('\n')
302
- .map((line) => wrap(line, Math.max(10, columns - TEXT_AT - 1)))
303
- .join('\n');
304
-
305
281
  /**
306
- * What a call ran, as the rows it takes after its name: what it was given, how much an edit added and took away, how
307
- * long it ran — folded here, at the spaces, so a row that goes on starts at the words' margin, not with the space it broke at.
282
+ * What a call ran, as the rows it takes: the tool in bold, what it was given, how much an edit added and took away, how
283
+ * long it ran — folded here, at the spaces, so a row that goes on starts at the margin, not with the space it broke at.
308
284
  */
309
285
  function titleRows(view, took, s, width) {
310
- const stat = view.stat ? ` ${s.green(`+${view.stat.added}`)} ${s.red(`−${view.stat.removed}`)}` : '';
311
286
  const time = took >= TOOK_SHOWN_MS ? s.dim(` · ${elapsed(took)}`) : '';
312
- return untab(`${view.detail}${stat}${time}`)
287
+ // Several calls drawn as one say what they were in words, not as a call: `Read 3 files (a.js, b.js, +1)`.
288
+ const what = view.group ? `${s.bold(view.title)} (${view.detail})` : `${s.bold(view.title)}(${view.detail})`;
289
+ return untab(`${what}${statOf(view.stat, s)}${time}`)
313
290
  .split('\n')
314
291
  .flatMap((line) => wrap(line, width).split('\n'));
315
292
  }
316
293
 
317
- /**
318
- * A step: its name in the gutter — read, edit, run — what it was given, and under it what came back; or, while it runs,
319
- * the jobs it started or the last of what it prints. Its state stands beside the name: ✗ failed, • at work (with its
320
- * clock), ? waiting on the user. `tight` sets it straight under the step before it: steps in a row are one list.
321
- */
294
+ /** A tool call: what ran, and under it what came back — or, while it runs, the jobs it started, or what it prints. */
322
295
  function Tool(props) {
323
296
  const g = useMarks();
324
297
  const step = stepOf(props, g);
325
- // At work, the row is drawn again for its clock, a little more often than it turns over so a second is never skipped.
298
+ // Drawn again for its clock, a little more often than it turns over, so a second is never skipped.
326
299
  useAnimation({ interval: 250, isActive: step.ticking });
327
- const { view, failed = false, running = false, tight = false, columns } = props;
328
300
  return h(
329
301
  Box,
330
- { flexDirection: 'column', marginTop: tight ? 0 : 1 },
331
- // A failure has a mark of its own and its name in red: the colour alone says nothing to someone who cannot see it.
332
- h(Row, { label: view.title, tone: failed && !running ? { color: 'red' } : DIM, mark: step.mark, markTone: step.markTone, columns }, ...step.title.map((row, i) => h(Text, { key: i }, row))),
333
- step.note ? h(Text, { dimColor: true }, `${' '.repeat(OUT_AT)}${step.note}`) : null,
334
- ...step.live,
302
+ { flexDirection: 'column', marginTop: props.afterBlank ? 0 : 1 },
303
+ // The mark stands apart from the words, so a command that wraps, or has lines of its own, goes on under them, not under it.
304
+ // A failure has a mark of its own: its colour alone says nothing to someone who cannot see it.
305
+ h(
306
+ Box,
307
+ null,
308
+ h(Box, { flexShrink: 0 }, h(Text, step.markTone, `${step.mark} `)),
309
+ // A width of its own: a box in a row is never made narrower than its longest word, and a command can be one long word.
310
+ h(Box, { flexShrink: 1, flexDirection: 'column', width: Math.max(10, props.columns - 2) }, ...step.title.map((row, i) => h(Text, { key: i }, row))),
311
+ ),
312
+ step.note ? h(Text, { dimColor: true }, ` ${g.under} ${step.note}`) : null,
313
+ ...step.live.map((line, i) => h(Text, { key: `live-${i}`, dimColor: true, wrap: 'truncate' }, ` ${line}`)),
335
314
  ...step.jobs.map(([id, job]) => h(JobAtWork, { key: id, id, job })),
336
315
  ...step.under,
337
316
  );
@@ -346,36 +325,34 @@ function stepOf({ view, failed = false, running = false, waiting = false, jobs =
346
325
  // A question put to the user is not running anything: it waits on them, and says so.
347
326
  // A call held for the user's word runs nothing either: the panel under the work says it waits, and nothing here says it again.
348
327
  // A delegation has no job yet while the router picks the model and effort it runs on.
349
- const asking = running && view.title === 'asked' && !waiting;
350
- // Only what runs has a clock: not a call waiting on the user, nor one whose jobs keep their own. Plain, for a screen
351
- // reader, there is none: the row is drawn again for what the command prints, not for the time.
352
- const ticking = running && !plain && !waiting && !asking && jobs.length === 0;
353
- const ran = ticking && since > 0 ? Date.now() - since : running ? 0 : took;
354
- const width = Math.max(10, columns - TEXT_AT);
328
+ const asking = running && view.title === 'Question' && !waiting;
329
+ const working = running && !waiting && !asking && jobs.length === 0;
330
+ // Only what runs has a clock. Plain, for a screen reader, there is none: the row is drawn again for what the command
331
+ // prints, not for the time.
332
+ const ticking = working && !plain;
333
+ const ran = ticking && since > 0 ? Date.now() - since : 0;
334
+ const width = Math.max(10, columns - 2);
355
335
  // Waiting on the user, the step is one row: the panel under it shows what would run, whole, and the window's rows are its.
356
- const rows = titleRows(view, ran, s, width);
357
- const title = waiting && rows.length > 1 ? [`${rows[0].slice(0, Math.max(1, width - 2))} …`] : rows;
336
+ const rows = titleRows(view, running ? 0 : took, s, width);
337
+ const title = waiting && rows.length > 1 ? [`${titleRows(view, 0, s, width - 2)[0]} …`] : rows;
358
338
  return {
359
339
  ticking,
360
- note: asking ? 'waiting for your answer' : running && !waiting && jobs.length === 0 && view.title === 'job' ? 'picking the model and effort…' : null,
361
- mark: waiting || asking ? g.ask : running ? g.live : failed ? g.fail : ' ',
362
- markTone: waiting || asking ? { color: 'yellow' } : running ? { color: ACCENT } : failed ? { color: 'red' } : null,
340
+ mark: failed && !running ? g.fail : g.tool,
341
+ markTone: { color: running ? undefined : failed ? 'red' : 'green', dimColor: running },
363
342
  title,
364
- live: running && !waiting && jobs.length === 0 ? runningLines(live) : [],
343
+ note: asking ? 'waiting for your answer' : working ? (view.title === 'Delegate' ? 'picking the model and effort…' : `Running…${ran >= 1000 ? ` ${elapsed(ran)}` : ''}`) : null,
344
+ live: working && live ? lastLines(live) : [],
365
345
  jobs,
366
346
  under: linesUnder(view.lines, columns, s, view.rows ?? null),
367
347
  };
368
348
  }
369
349
 
370
- /** The rows a step takes on the screen: the blank one over it, unless it is tight under the step before. */
350
+ /** The rows a step takes on the screen: the blank one over it (unless a reply's blank line is that row), its title, and all that stands under it. */
371
351
  const stepRowCount = (props, g) => {
372
352
  const step = stepOf(props, g);
373
- return (props.tight ? 0 : 1) + step.title.length + (step.note ? 1 : 0) + step.live.length + step.jobs.length + step.under.length;
353
+ return (props.afterBlank ? 0 : 1) + step.title.length + (step.note ? 1 : 0) + step.live.length + step.jobs.length + step.under.length;
374
354
  };
375
355
 
376
- /** Steps follow one another without a blank row between them: after a step, or what a command of the user's printed. */
377
- const STEP_KINDS = new Set(['tool', 'output']);
378
-
379
356
  /** A call that took at least this long says how long, beside what ran. */
380
357
  const TOOK_SHOWN_MS = 1000;
381
358
  /** Thought for less than this, the line that says so would say nothing. */
@@ -396,14 +373,18 @@ const thoughtRows = (text, width, rows = THOUGHT_ROWS) =>
396
373
  .flatMap((line) => wrap(line, width).split('\n'))
397
374
  .slice(-rows);
398
375
 
376
+ /** Each job in a colour of its own, by its id: its rows under the box, its line in the conversation and its open record agree. */
377
+ const JOB_COLOURS = ['cyan', 'magenta', 'blue', 'yellow', 'green'];
378
+ const jobColour = (id) => JOB_COLOURS[Number(id) % JOB_COLOURS.length];
379
+
399
380
  /** The most of a job's title its row under the box shows. */
400
381
  const TITLE_CHARS = 32;
401
382
 
402
383
  /**
403
384
  * A job at work, in one line: how long, how many calls, and that it is working — what it runs and thinks is in its record,
404
- * a step and Enter away, not here. Under the call that waits for it, under the call's words; or — at work in the
405
- * background, with no call standing over it — in a row of the ledger under the box, named by its id, marked when it is
406
- * the one stepped on (`picked`) or the one whose record is open.
385
+ * a step and Enter away, not here. Under the call that waits for it; or — at work in the background, with no call standing
386
+ * over it — in a row of its own under the box, with who it is, marked when it is the one stepped on (`picked`) or the one
387
+ * whose record is open.
407
388
  */
408
389
  function JobAtWork({ id, job, alone = false, picked = false, open = false }) {
409
390
  // Plain, the row says what the job has done, not for how long: a clock would have it read out every second.
@@ -411,25 +392,31 @@ function JobAtWork({ id, job, alone = false, picked = false, open = false }) {
411
392
  const plain = g === glyphs(true);
412
393
  useAnimation({ interval: 1000, isActive: !plain });
413
394
  const calls = `${job.calls} tool call${job.calls === 1 ? '' : 's'}`;
395
+ const mark = alone ? (picked ? ` ${g.pick} ` : ` ${g.tool} `) : ` ${g.under} `;
414
396
  // Under the call that started it the title is the call's own: the row says who works on it, on what, and where to follow it.
415
- const who = alone ? `${job.agent} — ${job.title.length > TITLE_CHARS ? `${job.title.slice(0, TITLE_CHARS - 1)}…` : job.title}` : `j${id} ${job.agent} · ${job.route}`;
416
- const lead = `${who} · ${plain ? '' : `${elapsed(Date.now() - job.since)} · `}${calls} · `;
417
- const rest = [h(Text, { key: 'lead', dimColor: !picked }, lead), h(Text, { key: 'working', dimColor: true }, 'working'), !alone && job.where ? h(Text, { key: 'where', dimColor: true }, ` · ${job.where.replace(/^follow it: /, '')}`) : null];
418
- if (!alone) return h(Text, { wrap: 'truncate' }, ' '.repeat(OUT_AT), ...rest);
419
- return h(Text, { wrap: 'truncate' }, h(Text, picked || open ? { bold: true } : DIM, `j${id}`.padStart(GUTTER)), ' ', h(Text, { color: ACCENT }, picked ? g.pick : ' '), ' ', ...rest);
397
+ const who = alone ? ` ${job.agent} — ${job.title.length > TITLE_CHARS ? `${job.title.slice(0, TITLE_CHARS - 1)}…` : job.title}` : ` ${job.agent} · ${job.route}`;
398
+ const lead = `j${id}${who} · ${plain ? '' : `${elapsed(Date.now() - job.since)} · `}${calls} · `;
399
+ return h(
400
+ Text,
401
+ { wrap: 'truncate' },
402
+ h(Text, picked || open ? { color: ACCENT } : { color: jobColour(id) }, mark),
403
+ h(Text, { dimColor: !picked }, lead),
404
+ h(Text, { dimColor: true }, 'working'),
405
+ !alone && job.where ? h(Text, { dimColor: true }, ` · ${job.where.replace(/^follow it: /, '')}`) : null,
406
+ );
420
407
  }
421
408
 
422
409
  /** The chat itself, as the first of the rows under the box: the place Enter comes back to from a job's record. */
423
410
  const MAIN = 'main';
424
411
 
425
- /** The chat's own row, over the jobs it delegated: marked when it is the one stepped on (`picked`), named in full weight when it is the one on the screen (`shown`). */
412
+ /** The chat's own row, over the jobs it delegated: marked when it is the one stepped on (`picked`), or the one on the screen (`shown`). */
426
413
  function MainAtWork({ working, picked = false, shown = false }) {
427
414
  const g = useMarks();
428
- return h(Text, { wrap: 'truncate' }, h(Text, picked || shown ? { bold: true } : DIM, MAIN.padStart(GUTTER)), ' ', h(Text, { color: ACCENT }, picked ? g.pick : ' '), ' ', h(Text, { dimColor: true }, working ? 'working' : 'idle'));
415
+ return h(Text, { wrap: 'truncate' }, h(Text, picked || shown ? { color: ACCENT } : { dimColor: true }, picked ? ` ${g.pick} ` : ` ${g.tool} `), h(Text, { dimColor: !picked }, 'main · '), h(Text, { dimColor: true }, working ? 'working' : 'idle'));
429
416
  }
430
417
 
431
- /** A line of a job's record, which is written with the full marks, in the marks this screen draws with. */
432
- const inMarks = (line, g) => (g.fail === '✗' ? line : line.replaceAll('✗', g.fail));
418
+ /** A line written with the screen's own marks — a job's record — in the marks this screen draws with. */
419
+ const inMarks = (line, g) => (g.tool === '⏺' ? line : line.replaceAll('⏺', g.tool).replaceAll('⎿', g.under).replaceAll('✗', g.fail).replaceAll('✻', g.thought));
433
420
 
434
421
  /** What a job at work has written down so far, as the screen may show it: its lines, under the one that says who it is. None where there is no record yet. */
435
422
  function recordLines(id) {
@@ -443,38 +430,23 @@ function recordLines(id) {
443
430
  /** The rows of the window an open job's record may take: the turn's own work, the box and the rows under it need the rest. */
444
431
  const openRows = (rows) => Math.max(3, Math.min(rows - 24, Math.floor(rows / 2)));
445
432
 
446
- /**
447
- * Which lines of a record are what came back from a step: the unnamed lines after a step's row, up to the next named row.
448
- * What the job says — its reply, a list or code in it set in as deep — follows a row named sumo, and keeps full weight.
449
- */
450
- export function underSteps(lines) {
451
- let step = false;
452
- return lines.map((line) => {
453
- const name = line.slice(0, GUTTER).trim();
454
- if (name) step = name !== 'sumo';
455
- return !name && step;
456
- });
457
- }
458
-
459
433
  /**
460
434
  * A job opened from under the box: who it is, and the end of what it has written down — each call with the top of what
461
435
  * came back, and what it said — read again as its clock ticks. It is the record `sumo job watch` follows; Ctrl-O has all of it.
462
436
  */
463
- function JobOpen({ id, job, rows, columns }) {
437
+ function JobOpen({ id, job, rows }) {
464
438
  useAnimation({ interval: 1000 });
465
439
  const g = useMarks();
466
440
  const all = recordLines(id);
467
- const faint = underSteps(all);
468
441
  const seen = all.slice(-openRows(rows));
469
442
  const above = all.length - seen.length;
470
- const pad = ' '.repeat(TEXT_AT);
471
443
  return h(
472
444
  Box,
473
445
  { flexDirection: 'column', marginTop: 1 },
474
- h(Row, { label: `j${id}`, tone: { bold: true }, columns }, h(Text, { wrap: 'truncate' }, `${job.agent} · ${job.route} — ${job.title}`)),
475
- above > 0 ? h(Text, { dimColor: true }, `${pad}… +${above} line${above === 1 ? '' : 's'}`) : null,
476
- all.length === 0 ? h(Text, { dimColor: true }, `${pad}nothing done yet`) : null,
477
- ...seen.map((line, i) => h(Text, { key: i, dimColor: faint[all.length - seen.length + i], wrap: 'truncate' }, inMarks(untab(line), g) || ' ')),
446
+ h(Text, { wrap: 'truncate' }, h(Text, { color: jobColour(id) }, `${g.tool} `), h(Text, { bold: true }, `j${id}`), ` ${job.agent} · ${job.route} — ${job.title}`),
447
+ above > 0 ? h(Text, { dimColor: true }, ` … +${above} line${above === 1 ? '' : 's'}`) : null,
448
+ all.length === 0 ? h(Text, { dimColor: true }, ' nothing done yet') : null,
449
+ ...seen.map((line, i) => h(Text, { key: i, dimColor: /^\s*⎿/.test(line), wrap: 'truncate' }, inMarks(untab(line), g) || ' ')),
478
450
  );
479
451
  }
480
452
 
@@ -568,28 +540,34 @@ function Ask({ ask, aside = false, waiting = 1, why = null, explain = false, col
568
540
  // A key that answers nothing has every key explained here, in the panel's own colour, where nothing is cut to fit.
569
541
  // Esc is named as the working line names it, wherever it stops the turn.
570
542
  const keys = why !== null ? `enter refuses with this · esc back to the question${waiting > 1 ? ` · ${waiting - 1} more waiting` : ''}` : explain ? `${explainKeys(ask, aside)}${waiting > 1 ? ` · ${waiting - 1} more waiting` : ''}` : `${answersTo(ask)} · esc ${aside ? 'no' : 'to interrupt'}${waiting > 1 ? ` · ${waiting - 1} more waiting` : ''}`;
571
- // A panel of its own, set apart from the work: named `ask` in yellow, and a yellow bar down the state column beside all
572
- // it asks about — what would run, whole, and the keys that answer — so where the question ends is never in doubt.
573
- // Plain, it has no bar: a frame is read out as a row of lines.
543
+ // A panel of its own, framed in yellow, set apart from the work: why it asks, faint; what would run, whole and set in; the
544
+ // keys that answer. Plain, it has no frame: a frame is read out as a row of lines.
574
545
  const g = useMarks();
575
- const framed = g !== glyphs(true);
576
- const width = Math.max(20, columns - TEXT_AT - 1);
546
+ const framed = g === glyphs(false);
577
547
  // Everything in it is folded here, at the width it is drawn at, so the rows it takes are known before it is drawn.
578
- const titled = folded(title, columns);
579
- const refused = ask.unsandboxed && ask.blocked ? fold(asText(`the sandbox refused: ${ask.blocked}`), width) : [];
580
- const input = whole === '{}' ? null : kept.flatMap((line) => fold(spacesCounted(untab(line)) || ' ', Math.max(10, width - 2)));
548
+ const width = Math.max(20, columns - (framed ? 4 : 0));
549
+ const titled = wrap(`${g.warn} ${title}`, width);
550
+ const refused = ask.unsandboxed && ask.blocked ? fold(asText(`the sandbox refused: ${ask.blocked}`), width - 2) : [];
551
+ const input = whole === '{}' ? null : kept.flatMap((line) => fold(spacesCounted(untab(line)) || ' ', Math.max(10, width - 4)));
581
552
  const keyed = keyRows(keys, width);
582
553
  const reason = why !== null ? fold(`${asText(why)}▌`, Math.max(10, width - 9)) : [];
583
- const noted = (n) => fold(`… ${n.toLocaleString('en-US')} more character${n === 1 ? '' : 's'} not shown — n, and ask the model for less`, Math.max(10, width - 2));
554
+ const noted = (n) => fold(`… ${n.toLocaleString('en-US')} more character${n === 1 ? '' : 's'} not shown — n, and ask the model for less`, Math.max(10, width - 4));
584
555
  // Given the rows it may take (`rows`), what would run is shown as far as they go: a panel taller than the window makes
585
556
  // Ink wipe the screen and the scrollback to draw it. What is left out is counted, as the cap's is, and the advice is the same.
586
557
  let shown = input ?? [];
587
558
  let hidden = unshown;
559
+ // The blank rows around what would run: the first thing a window too short for the panel gives up.
560
+ let around = 1;
588
561
  if (rows !== null && input) {
589
562
  // A key's words longer than a row go on to the next: counted as they would fold, never fewer.
590
563
  const keyRowCount = keyed.reduce((sum, row) => sum + wrap(row, width - 1).split('\n').length, 0);
591
- const fixed = 1 + titled.split('\n').length + refused.length + 2 + (reason.length > 0 ? reason.length + 1 : 0) + keyRowCount;
592
- if (fixed + input.length + (hidden > 0 ? noted(hidden).length : 0) > rows) {
564
+ let fixed = 1 + (framed ? 2 : 0) + titled.split('\n').length + refused.length + 2 + (reason.length > 0 ? reason.length + 1 : 0) + keyRowCount;
565
+ const fits = () => fixed + input.length + (hidden > 0 ? noted(hidden).length : 0) <= rows;
566
+ if (!fits()) {
567
+ around = 0;
568
+ fixed -= 2;
569
+ }
570
+ if (!fits()) {
593
571
  const room = Math.max(1, rows - fixed - noted(hidden + whole.length).length);
594
572
  hidden += input.slice(room).reduce((sum, row) => sum + row.trim().length, 0);
595
573
  shown = input.slice(0, room);
@@ -597,26 +575,21 @@ function Ask({ ask, aside = false, waiting = 1, why = null, explain = false, col
597
575
  }
598
576
  return h(
599
577
  Box,
600
- { marginTop: 1, flexDirection: 'column', width: Math.max(20, columns) },
601
- h(Row, { label: 'ask', tone: { color: 'yellow', bold: true }, mark: g.ask, markTone: { color: 'yellow', bold: true }, columns }, h(Text, { color: 'yellow', bold: true }, titled)),
578
+ { marginTop: 1, flexDirection: 'column', ...(framed ? { borderStyle: 'round', borderColor: 'yellow', paddingX: 1 } : {}), width: Math.max(20, columns) },
579
+ h(Text, { color: 'yellow', bold: true }, titled),
580
+ // Why a run outside is asked: what the sandbox refused, faint, under the question.
581
+ ...refused.map((row, i) => h(Text, { key: `refused-${i}`, dimColor: true, wrap: 'truncate' }, ` ${row}`)),
582
+ // Folded, never cut at the edge: what would run past the window's width is what the question is for. Set in, as what came back from a step is.
602
583
  h(
603
584
  Box,
604
- // The bar stands in the state column: the box starts there, as wide as what is left of the window.
605
- { flexDirection: 'column', ...(framed ? { borderStyle: 'single', borderColor: 'yellow', borderTop: false, borderRight: false, borderBottom: false, marginLeft: GUTTER + 1, paddingLeft: 1, width: Math.max(20, columns - GUTTER - 1) } : { paddingLeft: TEXT_AT, width: Math.max(20, columns) }) },
606
- // Why a run outside is asked: what the sandbox refused, faint, above the command.
607
- ...refused.map((row, i) => h(Text, { key: `refused-${i}`, dimColor: true, wrap: 'truncate' }, row)),
608
- // Folded, never cut at the edge: what would run past the window's width is what the question is for. Set in, as what came back from a step is.
609
- h(
610
- Box,
611
- { flexDirection: 'column', paddingLeft: 2, marginY: 1 },
612
- ...(input === null ? [h(Text, { key: 'none', dimColor: true }, '(no input)')] : shown.map((row, i) => h(Text, { key: i, wrap: 'truncate' }, row || ' '))),
613
- ...(hidden > 0 ? noted(hidden).map((row, i) => h(Text, { key: `noted-${i}`, dimColor: true, wrap: 'truncate' }, row)) : []),
614
- ),
615
- why !== null ? h(Box, { marginBottom: 1 }, h(Box, { flexShrink: 0 }, h(Text, { color: 'yellow' }, 'why not? ')), h(Text, null, reason.join('\n'))) : null,
616
- // The keys go to as many rows as they need, broken only between keys — at full weight, the key itself bold: they are
617
- // what the panel asks the user to read and press.
618
- ...keyed.map((row, i) => h(Text, { key: `keys-${i}`, ...(explain && why === null ? { color: 'yellow' } : {}), wrap: 'wrap' }, ...keysBold(row))),
585
+ { flexDirection: 'column', paddingLeft: 4, marginY: around },
586
+ ...(input === null ? [h(Text, { key: 'none', dimColor: true }, '(no input)')] : shown.map((row, i) => h(Text, { key: i, wrap: 'truncate' }, row || ' '))),
587
+ ...(hidden > 0 ? noted(hidden).map((row, i) => h(Text, { key: `noted-${i}`, dimColor: true, wrap: 'truncate' }, row)) : []),
619
588
  ),
589
+ why !== null ? h(Box, { marginBottom: 1 }, h(Box, { flexShrink: 0 }, h(Text, { color: 'yellow' }, 'why not? ')), h(Text, null, reason.join('\n'))) : null,
590
+ // The keys go to as many rows as they need, broken only between keys — at full weight, the key itself bold: they are
591
+ // what the panel asks the user to read and press.
592
+ ...keyed.map((row, i) => h(Text, { key: `keys-${i}`, ...(explain && why === null ? { color: 'yellow' } : {}), wrap: 'wrap' }, ...keysBold(row))),
620
593
  );
621
594
  }
622
595
 
@@ -641,32 +614,29 @@ export function keyRows(said, width) {
641
614
  return rows;
642
615
  }
643
616
 
644
- /** A mark, and words that go on under themselves, never under the mark: the options of a question. */
617
+ /** A mark, and words that go on under themselves, never under the mark: the rows of a question and its options. */
645
618
  function Hung({ mark, width, color, children }) {
646
619
  return h(Box, null, h(Box, { flexShrink: 0 }, h(Text, { color }, mark)), h(Box, { width: Math.max(10, width - mark.length) }, h(Text, { color }, ...[children].flat())));
647
620
  }
648
621
 
649
- /** A question of the model's: asked by sumo, waiting on the user (?), its options under it, the one the arrows are on marked, and the keys that answer — a pick, or words typed in the box. */
622
+ /** A question of the model's: its options, the one the arrows are on, and the keys that answer — a pick, or words typed in the box. */
650
623
  function Question({ ask, columns }) {
651
624
  const g = useMarks();
652
- const width = Math.max(20, columns - TEXT_AT);
653
625
  return h(
654
626
  Box,
655
627
  { marginTop: 1, flexDirection: 'column' },
656
- h(Row, { label: 'sumo', tone: { bold: true }, mark: g.ask, markTone: { color: 'yellow', bold: true }, columns }, h(Text, { bold: true }, folded(ask.question, columns))),
657
- h(
658
- Box,
659
- { flexDirection: 'column', paddingLeft: TEXT_AT },
660
- ...ask.options.map((option, i) => h(Hung, { key: i, mark: `${i === ask.at ? g.pick : ' '} ${i + 1}. `, width, color: i === ask.at ? ACCENT : undefined }, option.label, option.detail ? h(Text, { dimColor: true }, ` — ${option.detail}`) : null)),
661
- // Broken only between keys, as a panel's are: never `esc` at the end of a row and `to interrupt` on the next.
662
- ...keyRows(`↑↓ choose · enter picks · 1–${ask.options.length} picks that one · or type your own answer · esc to interrupt`, width - 1).map((row, i) => h(Text, { key: `keys-${i}`, dimColor: true }, row)),
663
- ),
628
+ h(Hung, { mark: '? ', width: columns, color: 'yellow' }, ask.question),
629
+ ...ask.options.map((option, i) => h(Hung, { key: i, mark: ` ${i === ask.at ? g.pick : ' '} ${i + 1}. `, width: columns, color: i === ask.at ? ACCENT : undefined }, option.label, option.detail ? h(Text, { dimColor: true }, ` — ${option.detail}`) : null)),
630
+ // Broken only between keys, as a panel's are: never `esc` at the end of a row and `to interrupt` on the next.
631
+ ...keyRows(`↑↓ choose · enter picks · 1–${ask.options.length} picks that one · or type your own answer · esc to interrupt`, Math.max(20, columns - 2)).map((row, i) => h(Box, { key: `keys-${i}`, paddingLeft: 2 }, h(Text, { dimColor: true }, row))),
664
632
  );
665
633
  }
666
634
 
667
- /** One line of a reply; the first of a block is named `sumo` in the gutter, and stands apart from what came before it. */
668
- function Reply({ text, first, columns }) {
669
- return h(Row, { label: first ? 'sumo' : '', tone: { bold: true }, marginTop: first ? 1 : 0, columns }, h(Text, null, text || ' '));
635
+ /** One line of a reply; the first of a block carries the mark. */
636
+ function Reply({ text, first }) {
637
+ const g = useMarks();
638
+ // The mark keeps its two columns: a line with a word wider than the window must not squeeze it, or every row after it shifts left.
639
+ return h(Box, { marginTop: first ? 1 : 0 }, h(Box, { flexShrink: 0 }, h(Text, null, first ? `${g.tool} ` : ' ')), h(Text, null, text || ' '));
670
640
  }
671
641
 
672
642
  /** A folder by where it really is — `/var` is `/private/var` on macOS — or as given, when it is not there to ask. */
@@ -681,93 +651,100 @@ const realOrSame = (folder) => {
681
651
  /** Why the tools are not working in the folder the chat was opened in, and what makes them. */
682
652
  const awayLine = (folder) => `${folder} is not a project: the tools work in scratch — sumo project add . there makes it one`;
683
653
 
684
- /** The fewest columns the folder keeps beside who answers, on the header's row. */
685
- const HEADER_PATH_MIN = 16;
654
+ /** The header's second row: the project the tools work in and its branch, then — faint — the folder it is. */
655
+ const whereRow = (item) => (item.place ? [item.place, h(Text, { key: 'cwd', dimColor: true }, ` · ${item.cwd}`)] : [h(Text, { key: 'cwd', dimColor: true }, item.cwd)]);
686
656
 
687
657
  /** Something finished, drawn once and left to scroll. */
688
658
  /** `columns` is the window's width, handed down: every item asking the terminal for it would be a listener each, on a stream that takes ten. */
689
659
  function Item({ item, columns, s }) {
690
- // The top: sumo, where the tools work, who answers. One row — the room under it is the conversation's.
691
- if (item.kind === 'header') {
692
- const who = h(Text, null, item.route, VERSION ? h(Text, { dimColor: true }, ` · ${VERSION}`) : null);
693
- const beside = columns - TEXT_AT - 1 - `${item.route} · ${VERSION}`.length - 2 >= HEADER_PATH_MIN;
660
+ // A blank line of a reply right before is the row between them: never two in a row.
661
+ const gap = item.afterBlank ? 0 : 1;
662
+ // Plain, the name is said, not drawn in blocks: a reader would spell out every one of them.
663
+ if (item.kind === 'header' && s.plain) {
694
664
  return h(
695
665
  Box,
696
666
  { flexDirection: 'column', marginTop: 1 },
667
+ h(Text, { wrap: 'truncate-end' }, item.route, VERSION ? h(Text, { dimColor: true }, ` sumo ${VERSION}`) : null),
668
+ h(Text, { wrap: 'truncate-middle' }, ...whereRow(item)),
669
+ item.away ? h(Text, { dimColor: true }, wrap(awayLine(item.away), Math.max(10, columns - 1))) : null,
670
+ item.block ? h(Box, { marginTop: 1 }, h(Text, null, item.block)) : null,
671
+ );
672
+ }
673
+ if (item.kind === 'header') {
674
+ return h(
675
+ Box,
676
+ { flexDirection: 'column' },
697
677
  h(
698
- Row,
699
- { label: 'sumo', tone: { color: ACCENT, bold: true }, columns },
700
- // A long path loses its middle, never runs past the edge; who answers keeps its place at the right — or, in a window
701
- // too narrow for both on a row, goes under it: the folder the tools work in is never what gives way.
702
- ...(beside
703
- ? [h(Box, { key: 'row', justifyContent: 'space-between', gap: 2 }, h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate-middle' }, item.cwd)), h(Box, { flexShrink: 0 }, who))]
704
- : [h(Text, { key: 'cwd', dimColor: true, wrap: 'truncate-middle' }, item.cwd), h(Text, { key: 'who', wrap: 'truncate-end' }, who)]),
678
+ Box,
679
+ { gap: 3, marginTop: 1 },
680
+ // The sunset runs across the name, gold at the S to crimson at the O.
681
+ h(Box, { flexDirection: 'column', flexShrink: 0 }, ...WORDMARK.map((row, r) => h(Text, { key: r }, ...[...row].map((ch, i) => h(Text, { key: i, color: sunset(i / (row.length - 1)) }, ch))))),
682
+ // Beside the name, as wide as the window leaves: a long path loses its middle, never runs past the edge.
683
+ h(Box, { flexDirection: 'column', width: Math.max(10, columns - WORDMARK[0].length - 3) }, h(Text, { wrap: 'truncate-end' }, item.route, VERSION ? h(Text, { dimColor: true }, ` sumo ${VERSION}`) : null), h(Text, { wrap: 'truncate-middle' }, ...whereRow(item))),
705
684
  ),
706
- item.away ? h(Box, { paddingLeft: TEXT_AT }, h(Text, { dimColor: true }, wrap(awayLine(item.away), Math.max(10, columns - TEXT_AT - 1)))) : null,
707
- item.block ? h(Box, { marginTop: 1, paddingLeft: TEXT_AT }, h(Text, null, item.block)) : null,
685
+ item.away ? h(Box, { marginTop: 1 }, h(Text, { dimColor: true }, wrap(awayLine(item.away), Math.max(10, columns - 1)))) : null,
686
+ item.block ? h(Box, { marginTop: 1 }, h(Text, null, item.block)) : null,
708
687
  );
709
688
  }
710
- // What the user said is what a scroll back looks for: named `you` in the chat's colour, the words at full weight.
689
+ // What the user said is what a scroll back looks for: full weight, a bar of the chat's colour down its side — plain, a `>` before each line.
711
690
  if (item.kind === 'user') {
712
691
  const more = item.more ? h(Text, { dimColor: true }, `… +${item.more} line${item.more === 1 ? '' : 's'}`) : null;
713
- // Folded here, at the spaces, so a row that goes on starts under the words, not with the space it broke at.
714
- return h(Row, { label: 'you', tone: { color: ACCENT, bold: true }, marginTop: 1, columns }, h(Text, null, folded(untab(item.text), columns)), more);
692
+ if (s.plain) return h(Box, { marginTop: gap, flexDirection: 'column' }, h(Text, null, untab(item.text).split('\n').map((line) => `${s.g.bar} ${line}`).join('\n')), more);
693
+ return h(Box, { marginTop: gap, flexDirection: 'column', borderStyle: 'bold', borderColor: ACCENT, borderTop: false, borderRight: false, borderBottom: false, paddingLeft: 1 }, h(Text, null, untab(item.text)), more);
715
694
  }
716
- if (item.kind === 'text') return h(Reply, { ...item, columns });
717
- if (item.kind === 'tool') return h(Tool, { ...item, tight: STEP_KINDS.has(item.after), columns, s });
695
+ if (item.kind === 'text') return h(Reply, item);
696
+ if (item.kind === 'tool') return h(Tool, { ...item, columns, s });
718
697
  if (item.kind === 'output') return h(Box, { flexDirection: 'column' }, ...linesUnder(item.lines, columns, s));
719
- // The turn summed up, faint, straight under the words that ended it.
720
- if (item.kind === 'footer') return h(Box, { paddingLeft: TEXT_AT, width: columns }, h(Text, { dimColor: true }, wrap(item.text, Math.max(10, columns - TEXT_AT - 1))));
721
- if (item.kind === 'job') return h(Row, { label: `j${item.id}`, tone: { bold: true }, marginTop: 1, columns }, h(Text, null, `${item.agent} · ${item.route} — ${item.title}`, h(Text, { dimColor: true }, ` · ${item.where}`)));
722
- // A failure is named `error` with a mark of its own, as a failed call is, and goes on under its own words, not at the
723
- // window's edge: folded here, at the spaces. What came back stands faint beneath, at the same margin.
698
+ // Its margin holds on every row it wraps to: the turn summed up stands apart from the work above it.
699
+ if (item.kind === 'footer') return h(Box, { marginTop: gap, paddingLeft: 2 }, h(Text, { dimColor: true }, item.text));
700
+ // The mark stands apart from the words, so a line that wraps in a narrow window goes on under them, not under it.
701
+ if (item.kind === 'job') return h(Box, { marginTop: gap }, h(Box, { flexShrink: 0 }, h(Text, { color: jobColour(item.id) }, `${s.g.tool} `)), h(Box, { width: Math.max(10, columns - 2) }, h(Text, null, h(Text, { bold: true }, `j${item.id}`), ` ${item.agent} · ${item.route} — ${item.title}`, h(Text, { dimColor: true }, ` · ${item.where}`))));
702
+ // A failure has a mark of its own, as a failed call has, and goes on under its own words, not at the window's edge:
703
+ // folded here, at the spaces. What came back stands faint beneath, at the same margin.
724
704
  if (item.kind === 'error') {
725
- const width = Math.max(10, columns - TEXT_AT - 1);
705
+ const width = Math.max(10, columns - 2);
726
706
  return h(
727
707
  Box,
728
- { marginTop: 1, flexDirection: 'column' },
729
- h(Row, { label: 'error', tone: { color: 'red' }, mark: s.g.fail, markTone: { color: 'red' }, columns }, h(Text, { color: 'red' }, wrap(unnamed(item.text), width))),
730
- item.detail ? h(Box, { paddingLeft: TEXT_AT }, h(Text, { dimColor: true }, wrap(item.detail, width))) : null,
708
+ { marginTop: gap, flexDirection: 'column' },
709
+ h(Box, null, h(Box, { flexShrink: 0 }, h(Text, { color: 'red' }, `${s.g.fail} `)), h(Box, { width }, h(Text, { color: 'red' }, wrap(item.text, width)))),
710
+ item.detail ? h(Box, { paddingLeft: 2 }, h(Text, { dimColor: true }, item.detail)) : null,
731
711
  );
732
712
  }
733
713
  // /help: the command or key in the chat's colour, what it does faint beside it, going on under itself in a narrow window.
734
- // A table of its own, near the margin: its keys are its gutter, and what they do keeps the room to stay on one row.
735
714
  if (item.kind === 'help') {
736
715
  const wide = Math.max(...item.rows.filter(Boolean).map((row) => row.key.length)) + 2;
737
716
  const room = Math.max(10, columns - 2 - wide);
738
717
  return h(Box, { marginTop: 1, flexDirection: 'column', paddingLeft: 2 }, ...item.rows.map((row, i) => (row ? h(Box, { key: i }, h(Box, { width: wide, flexShrink: 0 }, h(Text, { color: ACCENT }, row.key)), h(Box, { width: room }, h(Text, { dimColor: true }, wrap(row.does, room)))) : h(Text, { key: i }, ' '))));
739
718
  }
740
719
  // What the model thought before it answered: how long, here; the thought itself is in the pager.
741
- if (item.kind === 'thought') return h(Row, { label: 'think', marginTop: 1, columns }, h(Text, { dimColor: true }, `for ${elapsed(item.ms)}`));
742
- // A note of the chat's own — what a command did, where a session stopped — faint, under the words.
743
- return h(Box, { flexDirection: 'column' }, ...linesUnder(item.text.split('\n').map((text) => ({ text, tone: 'dim' })), columns, s, null, TEXT_AT));
720
+ if (item.kind === 'thought') return h(Box, { marginTop: gap }, h(Text, { dimColor: true }, `${s.g.thought} Thought for ${elapsed(item.ms)}`));
721
+ return h(Box, { flexDirection: 'column' }, ...linesUnder(item.text.split('\n').map((text) => ({ text, tone: 'dim' })), columns, s));
744
722
  }
745
723
 
746
724
  /** The fewest characters of its words the working line keeps before what follows them gives way as well. */
747
725
  const WORDS_KEPT = 12;
748
726
 
749
727
  /**
750
- * The line that says it is working: named `sumo`, a spinner turning in its state column, your words — the next of them
751
- * every few seconds — and, faint, how long, how much, and how to stop it. Under it, while the model thinks, the last rows
752
- * of what it has thought so far.
728
+ * The line that says it is working: your words, the next of them every few seconds, a sunset flowing through them; how
729
+ * long, how much, and how to stop it. Under it, while the model thinks, the last rows of what it has thought so far.
753
730
  */
754
- function Working({ messages, first, tokens, thought = '', heard = 0, quietAfterMs = QUIET_AFTER_MS, motion = true, retry = null, plan = null, waiting = false }) {
755
- // With motion off the spinner stands still and the line is drawn once a second, for its clock. While a question
731
+ function Working({ messages, first, tokens, thought = '', heard = 0, quietAfterMs = QUIET_AFTER_MS, motion = true, retry = null, plan = null, waiting = false, afterBlank = false }) {
732
+ // With motion off the words stand in one colour and the line is drawn once a second, for its clock. While a question
756
733
  // waits on the user, nothing works: the line steps aside — the question's own rows say it waits, and how Esc stops the
757
734
  // turn — and nothing is drawn for it, so the screen holds still while the question is read. It stays in place, its
758
735
  // clock running, to come back when the question is answered. Plain, for a screen reader, there is no clock at all: a
759
736
  // row written again every second is a row read out again every second.
760
737
  const g = useMarks();
761
738
  const plain = g === glyphs(true);
762
- const spinning = motion && !waiting;
763
- const { frame } = useAnimation({ interval: spinning ? SPIN_MS : 1000, isActive: !plain && !waiting });
739
+ const flowing = motion && !waiting;
740
+ const { frame } = useAnimation({ interval: flowing ? FLOW_STEP_MS : 1000, isActive: !plain && !waiting });
764
741
  // Timed from when the line appeared, not by the animation, whose clock starts again whenever its pace changes.
765
742
  const began = useRef(Date.now());
766
743
  const time = Date.now() - began.current;
767
744
  const { columns } = useWindowSize();
768
745
  if (waiting) return null;
769
746
  const said = `${messageAt(messages, first, time)}…`;
770
- const thinking = thoughtRows(thought, Math.max(20, columns - OUT_AT - 1));
747
+ const thinking = thoughtRows(thought, Math.max(20, columns - 6));
771
748
  // `heard` is when the model last said or did anything, while nothing of its own is running: a long silence is said, so a stream that died is told from one that thinks.
772
749
  const silent = heard > 0 ? Date.now() - heard : 0;
773
750
  // A request sent again is waited on in the open: how long until it goes, and which try it is.
@@ -778,10 +755,10 @@ function Working({ messages, first, tokens, thought = '', heard = 0, quietAfterM
778
755
  again: retry && plain ? `retrying · attempt ${retry.attempt}/${retry.limit}` : left > 0 ? `retrying in ${Math.ceil(left / 1000)}s · attempt ${retry.attempt}/${retry.limit}` : '',
779
756
  quiet: !plain && silent >= quietAfterMs ? `quiet ${elapsed(silent)}` : '',
780
757
  };
781
- const status = () => [parts.clock, parts.spent, parts.again, parts.quiet, 'esc to interrupt'].filter(Boolean).join(' · ');
758
+ const status = () => `(${[parts.clock, parts.spent, parts.again, parts.quiet, 'esc to interrupt'].filter(Boolean).join(' · ')})`;
782
759
  // In a narrow window what is least needed gives way first — the tokens, the silence — then the words, to a few of their
783
760
  // own, then the clock and the try. How to stop the turn is never what is cut.
784
- const room = () => columns - TEXT_AT - status().length - 3;
761
+ const room = () => columns - status().length - 1;
785
762
  for (const part of ['spent', 'quiet']) if (room() < said.length) parts[part] = '';
786
763
  for (const part of ['clock', 'again']) if (room() < WORDS_KEPT) parts[part] = '';
787
764
  // Cut between words where there is one to cut at: what is left still reads.
@@ -790,16 +767,17 @@ function Working({ messages, first, tokens, thought = '', heard = 0, quietAfterM
790
767
  const words = said.length <= fits ? said : `${(cut.lastIndexOf(' ') >= WORDS_KEPT / 2 ? cut.slice(0, cut.lastIndexOf(' ')) : cut).trimEnd()}…`;
791
768
  return h(
792
769
  Box,
793
- { marginTop: 1, flexDirection: 'column' },
770
+ { marginTop: afterBlank ? 0 : 1, flexDirection: 'column' },
794
771
  // One row: the words, and what follows them cut at the edge rather than set in a column of its own beside them.
795
772
  h(
796
- Row,
797
- { label: 'sumo', tone: { bold: true }, mark: spinning ? g.spin[frame % g.spin.length] : g.live, markTone: { color: ACCENT }, columns },
798
- h(Box, null, h(Box, { flexShrink: 0 }, h(Text, null, `${words} `)), h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate-end' }, status()))),
773
+ Box,
774
+ null,
775
+ h(Box, { flexShrink: 0 }, flowing ? h(Text, null, ...[...words].map((ch, i) => h(Text, { key: i, color: flow(i, frame) }, ch)), ' ') : h(Text, { color: ACCENT }, `${words} `)),
776
+ h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate-end' }, status())),
799
777
  ),
800
778
  // The plan the model keeps in its reply: how far it has got, and what it says comes next.
801
- plan ? h(Text, { dimColor: true, wrap: 'truncate-end' }, `${' '.repeat(TEXT_AT)}plan ${plan.done}/${plan.total}${plan.next ? ` · next: ${plan.next}` : ' · all done'}`) : null,
802
- ...thinking.map((row, i) => h(Text, { key: i, dimColor: true, wrap: 'truncate' }, `${' '.repeat(OUT_AT)}${row}`)),
779
+ plan ? h(Text, { dimColor: true, wrap: 'truncate-end' }, ` plan ${plan.done}/${plan.total}${plan.next ? ` · next: ${plan.next}` : ' · all done'}`) : null,
780
+ ...thinking.map((row, i) => h(Text, { key: i, dimColor: true, wrap: 'truncate' }, `${i === 0 ? ` ${g.under} ` : ' '}${row}`)),
803
781
  );
804
782
  }
805
783
 
@@ -840,33 +818,23 @@ export function inView({ text, cursor }, width, max) {
840
818
  return { text: text.slice(rows[first][0], rows[last][1]), cursor: cursor - rows[first][0], above: first, below: rows.length - 1 - last };
841
819
  }
842
820
 
843
- /**
844
- * Where you type: a faint rule across the window between the conversation and you, then your row of the ledger — named
845
- * `you`, the prompt in the state column, the cursor where the next key lands, set where what you send will stand. Of a
846
- * text too long for it, the rows around the cursor.
847
- */
821
+ /** The box to type in, the cursor drawn where the next key lands; of a text too long for it, the rows around the cursor. */
848
822
  function Input({ state, width, rows, placeholder = '' }) {
849
- const seen = inView(state, Math.max(10, width - TEXT_AT - 1), Math.max(3, Math.min(INPUT_ROWS, rows - 12)));
823
+ const seen = inView(state, Math.max(10, width - 6), Math.max(3, Math.min(INPUT_ROWS, rows - 12)));
850
824
  const { text, cursor } = seen;
851
825
  const on = under(seen);
852
826
  // A cursor on a line end, or past the last character, is drawn as a space of its own.
853
827
  const shown = on === '' || on === '\n' ? ' ' : on;
854
828
  const after = on === '\n' ? text.slice(cursor) : text.slice(cursor + on.length);
855
829
  const hidden = (n) => (n > 0 ? h(Text, { dimColor: true }, `… +${n} line${n === 1 ? '' : 's'}`) : null);
856
- // Plain, there is no rule: a line of box drawing is read out as a row of lines.
857
- const g = useMarks();
858
- const framed = g !== glyphs(true);
830
+ // Plain, the box is its prompt alone: a frame is read out as a row of lines.
831
+ const framed = useMarks().tool === '⏺';
859
832
  return h(
860
833
  Box,
861
- { flexDirection: 'column', width },
862
- framed ? h(Text, { dimColor: true }, g.rule.repeat(Math.max(1, width))) : null,
863
- h(
864
- Box,
865
- null,
866
- h(Box, { flexShrink: 0, width: TEXT_AT }, h(Text, null, h(Text, { dimColor: true }, 'you'.padStart(GUTTER)), ' ', h(Text, { color: ACCENT, bold: true }, g.pick), ' ')),
867
- // An empty box says what it is for, faint behind the cursor, until something has been said.
868
- h(Box, { flexGrow: 1, flexShrink: 1, flexDirection: 'column' }, hidden(seen.above), h(Text, { wrap: !text && placeholder ? 'truncate-end' : 'wrap' }, untab(text.slice(0, cursor)), reverse(untab(shown)), untab(after), !text && placeholder ? h(Text, { dimColor: true }, placeholder) : null), hidden(seen.below)),
869
- ),
834
+ { ...(framed ? { borderStyle: 'round', borderColor: 'gray', paddingX: 1 } : {}), width },
835
+ h(Box, { flexShrink: 0 }, h(Text, null, '> ')),
836
+ // An empty box says what it is for, faint behind the cursor, until something has been said.
837
+ h(Box, { flexGrow: 1, flexShrink: 1, flexDirection: 'column' }, hidden(seen.above), h(Text, { wrap: !text && placeholder ? 'truncate-end' : 'wrap' }, untab(text.slice(0, cursor)), reverse(untab(shown)), untab(after), !text && placeholder ? h(Text, { dimColor: true }, placeholder) : null), hidden(seen.below)),
870
838
  );
871
839
  }
872
840
 
@@ -893,15 +861,14 @@ function clauseFit(text, room) {
893
861
  function Menu({ menu, pick, columns = 80 }) {
894
862
  const g = useMarks();
895
863
  const wide = Math.max(...menu.map((c) => c.label.length)) + 2;
896
- // The row's room for the description: the window less the gutter, the mark and the name.
897
- const room = Math.max(10, columns - TEXT_AT - 1 - wide);
864
+ // The row's room for the description: the window less its margins, the mark and the name.
865
+ const room = Math.max(10, columns - 4 - 2 - wide);
898
866
  const first = Math.min(Math.max(0, pick - MENU_ROWS + 1), Math.max(0, menu.length - MENU_ROWS));
899
867
  const shown = menu.slice(first, first + MENU_ROWS);
900
868
  const below = menu.length - first - shown.length;
901
- // The mark in the state column, the names under the words of the box: what is picked is what the box would hold.
902
869
  return h(
903
870
  Box,
904
- { flexDirection: 'column', paddingLeft: GUTTER + 1, paddingRight: 1 },
871
+ { flexDirection: 'column', paddingX: 2 },
905
872
  first > 0 ? h(Text, { dimColor: true }, ` ↑ ${first} more`) : null,
906
873
  // A hint is one row: wrapped, its second line would stand under the names, where a name is looked for.
907
874
  ...shown.map((c, i) => h(Text, { key: c.name, color: first + i === pick ? ACCENT : undefined, dimColor: first + i !== pick, wrap: 'truncate-end' }, `${first + i === pick ? `${g.pick} ` : ' '}${c.label.padEnd(wide)}`, c.hint ? clauseFit(c.hint, room) : c.hint)),
@@ -936,15 +903,15 @@ const KEY_WIDTH = Math.max(...KEYS.map(([key]) => key.length)) + 2;
936
903
  /** `?` on an empty box: the keys, in as many columns as the window holds, until the next key. */
937
904
  function Keys({ columns }) {
938
905
  const per = columns >= 96 ? 3 : columns >= 64 ? 2 : 1;
939
- const width = Math.floor((columns - TEXT_AT - 1) / per);
906
+ const width = Math.floor((columns - 4) / per);
940
907
  const rows = [];
941
908
  for (let i = 0; i < KEYS.length; i += per) rows.push(KEYS.slice(i, i + per));
942
909
  return h(
943
910
  Box,
944
- { flexDirection: 'column', paddingLeft: TEXT_AT, paddingRight: 1 },
911
+ { flexDirection: 'column', paddingX: 2 },
945
912
  ...rows.map((row, r) => h(Box, { key: r }, ...row.map(([key, does], i) => h(Box, { key: i, width }, h(Text, { wrap: 'truncate-end' }, h(Text, { color: ACCENT }, key.padEnd(KEY_WIDTH)), h(Text, { dimColor: true }, does)))))),
946
913
  // Broken only between its parts, as a question's keys are.
947
- ...keyRows('/help has the commands too · any key closes this', columns - TEXT_AT - 1).map((row, i) => h(Text, { key: `more-${i}`, dimColor: true }, row)),
914
+ ...keyRows('/help has the commands too · any key closes this', columns - 4).map((row, i) => h(Text, { key: `more-${i}`, dimColor: true }, row)),
948
915
  );
949
916
  }
950
917
 
@@ -952,7 +919,7 @@ function Keys({ columns }) {
952
919
  function Search({ search }) {
953
920
  return h(
954
921
  Box,
955
- { paddingLeft: TEXT_AT, paddingRight: 1 },
922
+ { paddingX: 2 },
956
923
  h(
957
924
  Text,
958
925
  { wrap: 'truncate-end' },
@@ -992,31 +959,28 @@ function Status({ session, leaving, notice, jobs, aside = [], pick = null, open
992
959
  // In a narrow window the hints give way, then the place — unless the line has something to say just now, which the place
993
960
  // gives way to; the model, the size of the context and the cost never fold.
994
961
  const route = `${routeLine(session)}${size}${cost}`;
995
- const said = leaving || notice;
996
- // Under the words of the box — unless that would fold the route onto a second row, or cut what the row has to say just
997
- // now: then it starts near the margin, and what is said is said whole.
998
- const at = TEXT_AT + 1 + route.length + (said ? 2 + hint.length : 0) <= columns ? TEXT_AT : 2;
999
962
  // The route in its parts: the size coloured by how far it has grown, the cost yellow once the session has passed its budget.
1000
963
  const routed = h(Text, null, h(Text, { dimColor: true }, routeLine(session)), size ? h(Text, contextTone(tokens), size) : null, cost ? h(Text, overBudget ? { color: 'yellow' } : { dimColor: true }, cost) : null);
1001
- const room = columns - at - 1 - route.length - 2;
964
+ const room = columns - 4 - route.length - 2;
965
+ const said = leaving || notice;
1002
966
  const placed = place && place.length + 3 <= room - (said ? hint.length + 2 : 0) ? place : '';
1003
967
  const hinted = room - (placed ? placed.length + 3 : 0) >= 12 ? fitHint(hint, room - (placed ? placed.length + 3 : 0)) : '';
1004
968
  // With jobs at work the keys are what is needed, and they are long: they follow the jobs, from the left, and give way in a
1005
969
  // narrow window; the route stands at the right with the place beside it, while the keys keep room for their first words.
1006
970
  if (jobs.length > 0) {
1007
971
  // The keys come first here: the place stands beside the route only when they still fit whole.
1008
- const beside = place && columns - at - 1 - route.length - place.length - 3 - 2 >= hint.length;
972
+ const beside = place && columns - 4 - route.length - place.length - 3 - 2 >= hint.length;
1009
973
  return h(
1010
974
  Box,
1011
- { paddingLeft: at, paddingRight: 1, justifyContent: 'space-between', gap: 2 },
1012
- h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate' }, fitHint(hint, columns - at - 1 - route.length - 2 - (beside ? place.length + 3 : 0)))),
975
+ { paddingX: 2, justifyContent: 'space-between', gap: 2 },
976
+ h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate' }, fitHint(hint, columns - 4 - route.length - 2 - (beside ? place.length + 3 : 0)))),
1013
977
  h(Box, { flexShrink: 0, gap: 3 }, routed, beside ? h(Text, { dimColor: true }, place) : null),
1014
978
  );
1015
979
  }
1016
- // The place stands with the route it belongs to, on the left, under the words of the box; the keys at the right.
980
+ // The place stands with the route it belongs to, on the left; the keys at the right.
1017
981
  return h(
1018
982
  Box,
1019
- { paddingLeft: at, paddingRight: 1, justifyContent: 'space-between', gap: 2 },
983
+ { paddingX: 2, justifyContent: 'space-between', gap: 2 },
1020
984
  h(Box, { flexShrink: 0, gap: 3 }, routed, placed ? h(Text, { dimColor: true }, placed) : null),
1021
985
  hinted ? h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate' }, hinted)) : null,
1022
986
  );
@@ -1027,8 +991,7 @@ const HELP_KEYS = [
1027
991
  ['enter', 'send; while the model works, it reads it next'],
1028
992
  ['\\ enter', 'a new line (shift-enter and ctrl-j too)'],
1029
993
  ['esc', 'interrupt the turn, or close a menu'],
1030
- ['↑ ↓', 'what you sent before'],
1031
- ['ctrl-r', 'search what you sent'],
994
+ ['↑ ↓ · ctrl-r', 'what you sent before · a search through it'],
1032
995
  ['ctrl-c', 'clear the box; twice on an empty one to leave'],
1033
996
  ['ctrl-o', 'the whole conversation in your pager'],
1034
997
  ['ctrl-g', 'write the message in your editor'],
@@ -1063,7 +1026,7 @@ function Room({ logo, rows, from, starter = false }) {
1063
1026
  return h(
1064
1027
  Box,
1065
1028
  { ref, flexGrow: 1, flexDirection: 'column', overflow: 'hidden' },
1066
- starter ? h(Box, { marginTop: 1, paddingLeft: TEXT_AT }, h(Text, { dimColor: true, wrap: 'truncate-end' }, STARTER)) : null,
1029
+ starter ? h(Box, { marginTop: 1 }, h(Text, { dimColor: true, wrap: 'truncate-end' }, STARTER)) : null,
1067
1030
  seen ? h(Box, { position: 'absolute', top: at, left: Math.floor((width - wide) / 2), flexDirection: 'column' }, ...logo.map((row, i) => h(Text, { key: i, color: 'gray', dimColor: true }, row || ' '))) : null,
1068
1031
  );
1069
1032
  }
@@ -1083,21 +1046,29 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
1083
1046
  const header = (text) => {
1084
1047
  const at = session.where().cwd;
1085
1048
  const away = at === scratchDir() && realOrSame(cwd) !== at ? tilde(cwd) : null;
1086
- return { kind: 'header', route: routeLine(session), cwd: tilde(at), away, block: text };
1049
+ const where = session.where();
1050
+ return { kind: 'header', route: routeLine(session), place: `${where.name}${where.branch ? ` (${where.branch})` : ''}`, cwd: tilde(at), away, block: text };
1087
1051
  };
1088
1052
  // What the screen holds between draws. Keys and the session's events both write here, in the order they happen, and then ask for a draw.
1089
1053
  // `log` is what happened, as it was said; `items` is the log drawn for this window, and is drawn again when the window or the view changes.
1090
1054
  const st = useRef(null);
1091
1055
  // `live` is what each running command has printed so far and since when; `heard`, when the model last said or did anything;
1092
1056
  // `turn`, what the turn in hand has done; `talking`, that the model — not a `!` command — is what the screen is working on;
1093
- // `pick`, the job under the box that Down has stepped onto; `open`, the one whose record is shown.
1094
- st.current ??= { log: [], items: [], unmeasured: [], used: 0, next: 0, epoch: 0, raw: '', ed: editor(readHistory()), images: [], pastes: [], keys: false, notice: null, queue: [], started: new Map(), known: new Map(), working: null, talking: false, tokens: 0, thought: '', thinking: null, showThinking: true, heard: 0, running: new Map(), live: new Map(), drawSoon: null, jobs: new Map(), pick: null, open: null, asks: [], why: null, reply: null, fresh: true, leaving: null, gone: false, title: null, turn: null, where: session.where(), spent: session.spent(), files: { cwd: null, at: 0, list: [] }, away: false };
1057
+ // `pick`, the job under the box that Down has stepped onto; `open`, the one whose record is shown; `settings`, the
1058
+ // settings page while /config has it open.
1059
+ st.current ??= { log: [], items: [], unmeasured: [], used: 0, next: 0, epoch: 0, raw: '', ed: editor(readHistory()), images: [], pastes: [], keys: false, notice: null, queue: [], started: new Map(), known: new Map(), working: null, talking: false, tokens: 0, thought: '', thinking: null, showThinking: true, heard: 0, running: new Map(), live: new Map(), drawSoon: null, jobs: new Map(), pick: null, open: null, asks: [], why: null, reply: null, fresh: true, leaving: null, gone: false, title: null, turn: null, where: session.where(), spent: session.spent(), files: { cwd: null, at: 0, list: [] }, away: false, settings: null };
1095
1060
  const state = st.current;
1096
1061
  state.columns = columns;
1097
1062
  state.rows = rows;
1098
1063
 
1099
- /** An item as it is placed: its id, and the kind of the one before it — steps one after another stand without a blank row between. */
1100
- const stamped = (item) => ({ id: state.next++, after: state.items.at(-1)?.kind, ...item });
1064
+ /**
1065
+ * An item as it is placed: its id, and whether a blank line of a reply stands right before it — then that line is the
1066
+ * row between them, and the item's own blank row over it is not drawn: never two blank rows in a row.
1067
+ */
1068
+ const stamped = (item) => {
1069
+ const last = state.items.at(-1);
1070
+ return { id: state.next++, afterBlank: last?.kind === 'text' && !String(last.text ?? '').trim(), ...item };
1071
+ };
1101
1072
  const place = (items) => {
1102
1073
  for (const item of items) {
1103
1074
  const placed = stamped(item);
@@ -1133,7 +1104,7 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
1133
1104
  const named = seen.length > 2 ? [...seen.slice(0, 2), `+${seen.length - 2}`] : seen;
1134
1105
  const lines = reads.reduce((sum, entry) => sum + (entry.result.content === '' ? 0 : entry.result.content.replace(/\n$/, '').split('\n').length), 0);
1135
1106
  const files = new Set(reads.map((entry) => entry.call.input?.path)).size;
1136
- return [{ kind: 'tool', view: { title: 'read', detail: `${files} file${files === 1 ? '' : 's'} · ${named.join(', ')}`, lines: [{ text: `${lines} lines`, tone: 'dim' }] }, failed: false, took: reads.reduce((sum, entry) => sum + (entry.took ?? 0), 0) }];
1107
+ return [{ kind: 'tool', view: { title: `Read ${files} file${files === 1 ? '' : 's'}`, detail: named.join(', '), group: true, lines: [{ text: `${lines} lines`, tone: 'dim' }] }, failed: false, took: reads.reduce((sum, entry) => sum + (entry.took ?? 0), 0) }];
1137
1108
  };
1138
1109
  const placeReads = () => {
1139
1110
  if (state.reads.length > 0) place(readsDrawn(state.reads.splice(0)));
@@ -1160,14 +1131,14 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
1160
1131
  state.fresh = false;
1161
1132
  },
1162
1133
  s,
1163
- { width: state.columns - TEXT_AT - 1 },
1134
+ { width: state.columns - 3 },
1164
1135
  );
1165
1136
  /** One entry of the log as the lines this window shows for it. */
1166
1137
  function drawn(entry) {
1167
1138
  if (entry.kind === 'header') {
1168
1139
  // The memory block is the model's; what is wrong in it is the user's to see.
1169
1140
  const warnings = entry.block.split('\n').filter((line) => line.startsWith('Warning')).join('\n');
1170
- return [{ ...entry, block: warnings && renderBlock(warnings, s, { width: state.columns - TEXT_AT - 1 }) }];
1141
+ return [{ ...entry, block: warnings && renderBlock(warnings, s, { width: state.columns - 1 }) }];
1171
1142
  }
1172
1143
  if (entry.kind === 'tool') {
1173
1144
  const view = toolView(entry.call, entry.result, { cwd: state.where.cwd });
@@ -1198,6 +1169,8 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
1198
1169
  const lines = entry.text.split('\n');
1199
1170
  if (lines.length > ECHO_LINES) return [{ ...entry, text: lines.slice(0, ECHO_LINES).join('\n'), more: lines.length - ECHO_LINES }];
1200
1171
  }
1172
+ // A note for the pager alone — which guide rode in with a message — is not drawn on the screen.
1173
+ if (entry.kind === 'note' && entry.quiet) return [];
1201
1174
  if (entry.kind !== 'reply') return [entry];
1202
1175
  const lines = [];
1203
1176
  state.fresh = true;
@@ -1508,6 +1481,13 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
1508
1481
  session.route(args);
1509
1482
  return record({ kind: 'note', text: args ? `${routeLine(session)} from the next message` : `${routeLine(session)} · /model <model> <effort> changes it` });
1510
1483
  }
1484
+ // The settings page, in the box's place until Esc: what it changes is saved as it changes, and said once when it closes.
1485
+ if (control === 'config') {
1486
+ record({ kind: 'user', text: line });
1487
+ const left = () => `${routeLine(session)} ${state.where.name}${state.where.branch ? ` (${state.where.branch})` : ''}`;
1488
+ state.settings = settingsPage({ live: { route: (to) => session.route(to), servers: () => session.mcpServers(), left }, cwd: state.where.cwd, onChange: redraw });
1489
+ return;
1490
+ }
1511
1491
  if (control === 'memory' || control === 'mcp' || control === 'undo') {
1512
1492
  record({ kind: 'user', text: line });
1513
1493
  const text = control === 'undo' ? session.undo() : control === 'mcp' ? (await session.mcp()).join('\n') : await session.memoryPage();
@@ -1866,7 +1846,8 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
1866
1846
  // What the model was handed without being asked: a way of working, or the check it stopped short of.
1867
1847
  const onGuide = ({ name }) => {
1868
1848
  closeReply();
1869
- record({ kind: 'note', text: `guide: ${name}` });
1849
+ // For the pager alone: put in the log, not drawn — drawing nothing would still close a row of reads still growing.
1850
+ state.log.push({ kind: 'note', text: `guide: ${name}`, quiet: true });
1870
1851
  };
1871
1852
  // The pages a reply cites, under it. A title is a page's own words: nothing in it may drive the terminal.
1872
1853
  const onSources = ({ sources }) => {
@@ -1978,7 +1959,7 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
1978
1959
 
1979
1960
  // The window's title says whose chat it is and what it is doing, for a glance at the tab bar: at work, or waiting for an answer.
1980
1961
  useEffect(() => {
1981
- const title = `${state.asks.length > 0 ? '? ' : state.working ? '• ' : ''}sumo · ${state.where.name}`;
1962
+ const title = `${state.asks.length > 0 ? '? ' : state.working ? '✳ ' : ''}sumo · ${state.where.name}`;
1982
1963
  if (title === state.title) return;
1983
1964
  state.title = title;
1984
1965
  tell(`\x1b]2;${safeForTerminal(title)}\x07`);
@@ -2008,6 +1989,15 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
2008
1989
  // The terminal's answer to Ink's keyboard-protocol query, when it comes after Ink stopped waiting for it.
2009
1990
  if (/^\[\?\d+u$/.test(input)) return;
2010
1991
  for (const [one, oneKey] of keysOf(input, key)) {
1992
+ // The settings page takes every key while it is open — Esc and Ctrl-C close it — unless a question waits: that comes first.
1993
+ if (state.settings && state.asks.length === 0) {
1994
+ if (state.settings.key(keyName(one, oneKey))) {
1995
+ const changed = state.settings.summary();
1996
+ state.settings = null;
1997
+ if (changed.length > 0) record({ kind: 'note', text: `settings: ${changed.join(' · ')}` });
1998
+ }
1999
+ continue;
2000
+ }
2011
2001
  // Ctrl-R looking back through what was sent takes every key, Esc and Ctrl-C too: they put the draft back, and stop nothing.
2012
2002
  if (state.ed.search) {
2013
2003
  state.ed = press(state.ed, one, oneKey, session.commands, files).state;
@@ -2142,6 +2132,12 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
2142
2132
  });
2143
2133
  // A file dropped on the terminal arrives pasted as its path: an image's path becomes the image.
2144
2134
  usePaste((text) => {
2135
+ // On the settings page a paste is a field's: a server's command or address, mostly.
2136
+ if (state.settings && state.asks.length === 0) {
2137
+ state.settings.paste(cleanPaste(text).text);
2138
+ redraw();
2139
+ return;
2140
+ }
2145
2141
  // Saying why a call is refused, a paste is part of the reason — on one line — and never lands in the box behind it.
2146
2142
  if (state.why && state.why.ask === state.asks[0]) {
2147
2143
  state.why.text += cleanPaste(text).text.replace(/\s+/g, ' ');
@@ -2180,50 +2176,58 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
2180
2176
  // Ink adds a line under the frame; a frame that reached the last row would be drawn as a full screen.
2181
2177
  const room = state.unmeasured.length > 0 ? 0 : Math.max(0, rows - state.used - 1);
2182
2178
  // Reads that wait for what comes after them, drawn as the row they will make.
2183
- const reads = state.reads.length > 0 ? readsDrawn(state.reads).map((item, i) => ({ after: i === 0 ? state.items.at(-1)?.kind : 'tool', ...item })) : [];
2179
+ // A reply's blank line just placed is the row before what is live under it, as it is before what is placed.
2180
+ const blankBefore = state.items.at(-1)?.kind === 'text' && !String(state.items.at(-1).text ?? '').trim();
2181
+ const reads = state.reads.length > 0 ? readsDrawn(state.reads).map((item, i) => (i === 0 ? { ...item, afterBlank: blankBefore } : item)) : [];
2184
2182
  // What runs now, and under a delegate call the jobs it started.
2185
2183
  // A question of the model's is said once, in its own rows under the work: the call that asks it is not drawn over it.
2186
2184
  const steps = [...state.running.values()]
2187
2185
  .filter((call) => !(call.name === ASK_TOOL.name && state.asks[0]?.options))
2188
- .map((call, i) => ({ key: call.id, columns, s, view: toolView(call, null, { cwd: state.where.cwd }), running: true, tight: i > 0 || (!tail && STEP_KINDS.has(state.reads.length > 0 ? 'tool' : state.items.at(-1)?.kind)), waiting: state.asks.some((a) => !a.options && !a.job && (!a.name || a.name === call.name)), live: state.live.get(call.id), since: state.live.get(call.id)?.since ?? 0, jobs: [...state.jobs].filter(([, job]) => job.parent === call.id) }));
2186
+ .map((call, i) => ({ key: call.id, columns, s, view: toolView(call, null, { cwd: state.where.cwd }), running: true, afterBlank: i === 0 && blankBefore && reads.length === 0 && !tail, waiting: state.asks.some((a) => !a.options && !a.job && (!a.name || a.name === call.name)), live: state.live.get(call.id), since: state.live.get(call.id)?.since ?? 0, jobs: [...state.jobs].filter(([, job]) => job.parent === call.id) }));
2189
2187
  // A question to approve takes the rows the window has left — less the work over it and what stands under it — and never
2190
2188
  // more: a frame that filled the window would have Ink wipe the screen and its scrollback to draw it. Counted from the
2191
2189
  // same layout the rows are drawn from; a line of a reply still arriving is counted as it would fold, never fewer.
2192
2190
  const approving = state.asks.length > 0 && !state.asks[0].options;
2193
2191
  const recorded = approving && state.open !== null ? recordLines(state.open).length : 0;
2194
2192
  const over = approving
2195
- ? reads.reduce((sum, item) => sum + stepRowCount({ ...item, tight: STEP_KINDS.has(item.after), columns, s }, s.g), 0) +
2196
- (tail ? (state.fresh ? 1 : 0) + wrap(untab(tail), Math.max(10, columns - TEXT_AT - 1)).split('\n').length : 0) +
2193
+ ? reads.reduce((sum, item) => sum + stepRowCount({ ...item, columns, s }, s.g), 0) +
2194
+ (tail ? (state.fresh ? 1 : 0) + wrap(untab(tail), Math.max(10, columns - 2)).split('\n').length : 0) +
2197
2195
  steps.reduce((sum, step) => sum + stepRowCount(step, s.g), 0)
2198
2196
  : 0;
2199
2197
  const under = approving ? (state.open !== null ? 2 + Math.min(Math.max(1, recorded), openRows(rows)) + (recorded > openRows(rows) ? 1 : 0) : 0) + (said ? 0 : STARTER_ROWS - 1) + 2 + state.queue.length + rowsUnderBox().length : 0;
2200
2198
  const asked = approving ? rows - 1 - over - under : null;
2199
+ // A question waiting comes before the settings page: it is drawn, and answered, while the page waits behind it.
2200
+ const paging = state.settings !== null && state.asks.length === 0;
2201
2201
  return h(
2202
2202
  Box,
2203
2203
  { flexDirection: 'column', minHeight: room },
2204
2204
  h(Static, { key: state.epoch, items: state.items }, (item) => h(Item, { key: item.id, item, columns, s })),
2205
2205
  ...reads.map((item, i) => h(Item, { key: `reads-${i}`, item, columns, s })),
2206
- tail ? h(Reply, { text: tail, first: state.fresh, columns }) : null,
2206
+ tail ? h(Reply, { text: tail, first: state.fresh }) : null,
2207
2207
  // In one box of their own, so the lines coming and going never move what follows — the working line keeps its clock.
2208
2208
  h(Box, { flexDirection: 'column' }, ...steps.map((step) => h(Tool, step))),
2209
2209
  // The silence that is said is the model's: while a command, a job or a question is in hand, the wait is not on it.
2210
- state.working ? h(Working, { messages, first: state.working, tokens: state.tokens, thought: state.showThinking ? state.thought : '', quietAfterMs, motion, retry: state.retry, plan: state.plan, heard: state.talking && state.running.size === 0 && state.jobs.size === 0 && state.asks.length === 0 ? state.heard : 0, waiting: state.asks.length > 0 }) : null,
2210
+ state.working ? h(Working, { afterBlank: blankBefore && reads.length === 0 && !tail && steps.length === 0, messages, first: state.working, tokens: state.tokens, thought: state.showThinking ? state.thought : '', quietAfterMs, motion, retry: state.retry, plan: state.plan, heard: state.talking && state.running.size === 0 && state.jobs.size === 0 && state.asks.length === 0 ? state.heard : 0, waiting: state.asks.length > 0 }) : null,
2211
2211
  state.asks.length > 0 ? (state.asks[0].options ? h(Question, { ask: state.asks[0], columns }) : h(Ask, { ask: state.asks[0], aside: session.running().includes(state.asks[0].job), waiting: state.asks.length, why: state.why?.ask === state.asks[0] ? state.why.text : null, explain: state.explain?.ask === state.asks[0], columns, cwd: state.where.cwd, rows: asked })) : null,
2212
2212
  // The record of the job that is open, under everything the turn is doing: its end, as it grows.
2213
- state.open !== null ? h(JobOpen, { id: state.open, job: state.jobs.get(state.open), rows, columns }) : null,
2213
+ state.open !== null ? h(JobOpen, { id: state.open, job: state.jobs.get(state.open), rows }) : null,
2214
2214
  // The logo and what to try are the empty room's: once something has been said, the room is the conversation's.
2215
2215
  h(Room, { logo: said ? [] : logo, rows, from: state.used, starter: !said }),
2216
- h(
2217
- Box,
2218
- { flexDirection: 'column', marginTop: 1 },
2219
- // A message for the model is read with its next request — which, while it waits on a delegated job, is when that job reports.
2220
- ...state.queue.map(({ line, steer }, i) => h(Text, { key: i, dimColor: true, wrap: 'truncate' }, `${(steer ? 'next' : 'queued').padStart(GUTTER)} ${steer && atWork.length > 0 ? `${reading} · ` : ''}${line.split('\n')[0]}${line.includes('\n') ? ' …' : ''}`)),
2221
- // While a call waits on the user's word every key is the answer's: no box stands there to type into.
2222
- state.asks.length > 0 && !state.asks[0].options ? null : h(Input, { state: state.ed, width: columns, rows, placeholder: said ? '' : 'Ask anything · / commands · @ files · ? keys' }),
2223
- // The jobs at work in the background, under the box, and the chat over them: they go on whether or not there is a turn.
2224
- ...rowsUnderBox().map((id) => (id === MAIN ? h(MainAtWork, { key: MAIN, working: Boolean(state.working), picked: state.pick === MAIN, shown: state.open === null }) : h(JobAtWork, { key: `j${id}`, id, job: state.jobs.get(id), alone: true, picked: id === state.pick, open: id === state.open }))),
2225
- menu.length > 0 ? h(Menu, { menu, pick: state.ed.pick, columns }) : state.ed.search ? h(Search, { search: state.ed.search }) : state.keys ? h(Keys, { columns }) : h(Status, { session, leaving: Boolean(state.leaving), notice: state.notice?.text, jobs: [...state.jobs.keys()], aside: session.running(), pick: state.pick, open: state.open, where: state.where, spent: state.spent, overBudget: state.overBudget, waiting: state.queue.length > 0, columns }),
2226
- ),
2216
+ // The settings page stands where the box and the rows under it were, one row short of the window so it never fills it.
2217
+ paging
2218
+ ? h(Box, { marginTop: 1 }, h(SettingsView, { page: state.settings, columns, rows: Math.max(8, rows - 2), plain }))
2219
+ : h(
2220
+ Box,
2221
+ { flexDirection: 'column', marginTop: 1 },
2222
+ // A message for the model is read with its next request — which, while it waits on a delegated job, is when that job reports.
2223
+ ...state.queue.map(({ line, steer }, i) => h(Text, { key: i, dimColor: true, wrap: 'truncate' }, ` ${steer ? reading : 'queued'}: ${line.split('\n')[0]}${line.includes('\n') ? ' …' : ''}`)),
2224
+ // While a call waits on the user's word every key is the answer's: no box stands there to type into.
2225
+ state.asks.length > 0 && !state.asks[0].options ? null : h(Input, { state: state.ed, width: columns, rows, placeholder: said ? '' : 'Ask anything' }),
2226
+ // The jobs at work in the background, under the box, and the chat over them: they go on whether or not there is a turn.
2227
+ ...rowsUnderBox().map((id) => (id === MAIN ? h(MainAtWork, { key: MAIN, working: Boolean(state.working), picked: state.pick === MAIN, shown: state.open === null }) : h(JobAtWork, { key: `j${id}`, id, job: state.jobs.get(id), alone: true, picked: id === state.pick, open: id === state.open }))),
2228
+ // While a call waits on the user's word there is no box, and so nothing of the box's under it: the status row alone.
2229
+ menu.length > 0 && !approving ? h(Menu, { menu, pick: state.ed.pick, columns }) : state.ed.search && !approving ? h(Search, { search: state.ed.search }) : state.keys && !approving ? h(Keys, { columns }) : h(Status, { session, leaving: Boolean(state.leaving), notice: state.notice?.text, jobs: [...state.jobs.keys()], aside: session.running(), pick: state.pick, open: state.open, where: state.where, spent: state.spent, overBudget: state.overBudget, waiting: state.queue.length > 0, columns }),
2230
+ ),
2227
2231
  );
2228
2232
  }
2229
2233
 
@@ -2264,18 +2268,56 @@ export function runUi({ session, events, resume = null, stdin = process.stdin, s
2264
2268
  }, KITTY_WAIT_MS).unref();
2265
2269
  }
2266
2270
  // The terminal says when its window comes to the front and when it goes behind (`ESC[I`, `ESC[O`): a long turn that ends
2267
- // behind rings. Ink drops replies like these before they reach the keys, so they are read here, as Ink reads them.
2271
+ // behind rings. The reports are taken out of what is read here, before Ink sees it. Ink drops a whole one, but one that
2272
+ // comes in two reads — the ESC, then `[I` more than 20 ms later, as a multiplexer or a busy terminal may send it — it
2273
+ // reads as the Esc key and then `[I` typed into the box: Esc stopped the turn, and every switch of tabs typed more.
2274
+ // A terminal that speaks the kitty keyboard protocol (Ghostty, kitty, WezTerm: Ink turns it on) sends the Esc key as
2275
+ // `ESC[27u`, never a bare ESC: there a bare ESC at the end of a read is the start of something, and waits for its rest.
2276
+ // Elsewhere a bare ESC is the Esc key and goes on at once; a `[I` or `[O` just after it is still not typed.
2268
2277
  const front = { now: true };
2269
2278
  if (typeof stdin.read === 'function') {
2270
2279
  const read = stdin.read.bind(stdin);
2280
+ let kitty = false;
2281
+ let held = '';
2282
+ let ready = null;
2283
+ let timer = null;
2284
+ let bare = 0;
2271
2285
  stdin.read = (...args) => {
2286
+ if (ready !== null) {
2287
+ const out = ready;
2288
+ ready = null;
2289
+ return out;
2290
+ }
2272
2291
  const chunk = read(...args);
2273
- if (chunk !== null && chunk !== undefined) {
2274
- const text = String(chunk);
2275
- const at = Math.max(text.lastIndexOf('\x1b[I'), text.lastIndexOf('\x1b[O'));
2276
- if (at !== -1) front.now = text[at + 2] === 'I';
2292
+ if (chunk === null || chunk === undefined) return chunk;
2293
+ clearTimeout(timer);
2294
+ let text = held + String(chunk);
2295
+ held = '';
2296
+ // Ink asks whether the terminal speaks the protocol; the answer comes by here on its way to Ink.
2297
+ if (/\x1b\[\?\d+u/.test(text)) kitty = true;
2298
+ // The rest of a report whose ESC went on as a key: still the report's, not something typed.
2299
+ if (Date.now() - bare < FOCUS_LATE_MS && /^\[[IO]/.test(text)) {
2300
+ front.now = text[1] === 'I';
2301
+ text = text.slice(2);
2277
2302
  }
2278
- return chunk;
2303
+ bare = 0;
2304
+ text = text.replace(FOCUS_REPORT, (report) => {
2305
+ front.now = report[2] === 'I';
2306
+ return '';
2307
+ });
2308
+ const tail = /\x1b\[?$/.exec(text);
2309
+ if (tail && (kitty || tail[0] !== '\x1b')) {
2310
+ // Held for its rest; given on as it came if none comes.
2311
+ held = tail[0];
2312
+ text = text.slice(0, tail.index);
2313
+ timer = setTimeout(() => {
2314
+ ready = held;
2315
+ held = '';
2316
+ stdin.emit('readable');
2317
+ }, FOCUS_LATE_MS);
2318
+ timer.unref?.();
2319
+ } else if (tail) bare = Date.now();
2320
+ return text;
2279
2321
  };
2280
2322
  }
2281
2323
  // Plain (`chat.screen plain`), for a screen reader: ASCII marks, no frames, no pictures, and nothing moving.