sumo-agents 0.5.0 → 0.6.1
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/CHANGELOG.md +32 -0
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/chat.mjs +14 -14
- package/src/herdr.mjs +1 -3
- package/src/setup.mjs +1 -1
- package/src/tty.mjs +101 -62
- package/src/ui.mjs +273 -259
package/src/ui.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import { elapsed } from './text.mjs';
|
|
|
16
16
|
import { cleanPaste, editor, keysOf, matchFiles, menuOf, paste, press, under } from './editor.mjs';
|
|
17
17
|
import { clipboardImage, copyText, droppedImages } from './images.mjs';
|
|
18
18
|
import { ASK_TOOL, BASH_TOOL, DELEGATE_TOOL, EDITOR_TOOL } from './tools.mjs';
|
|
19
|
-
import { colourEnabled, createRenderer, explained, fold, glyphs,
|
|
19
|
+
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
20
|
|
|
21
21
|
/**
|
|
22
22
|
* The chat on a real terminal. What is finished scrolls away above — what
|
|
@@ -29,10 +29,9 @@ import { colourEnabled, createRenderer, explained, fold, glyphs, GUTTER, inline,
|
|
|
29
29
|
* says who it is — each call on one line, its output behind Ctrl-O — and a
|
|
30
30
|
* line starting with @ is said to it. An image pasted with Ctrl-V, or a file
|
|
31
31
|
* dropped on the box, stands in it as `[Image #n]` and goes with the message
|
|
32
|
-
* that names it.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* until the first message is sent the logo stands faint in the room above it. A command
|
|
32
|
+
* that names it. The chat opens on its name in blocks, in a sunset; while the
|
|
33
|
+
* conversation is short the box stands at the foot of the window, and until the
|
|
34
|
+
* first message is sent the logo stands faint in the room above it. A command
|
|
36
35
|
* shows what it prints while it runs; a message sent while the model works is
|
|
37
36
|
* read with its next request; a turn ends on a line that says how long it took,
|
|
38
37
|
* what it changed and what it cost, and — when the window is not the one in
|
|
@@ -43,14 +42,13 @@ import { colourEnabled, createRenderer, explained, fold, glyphs, GUTTER, inline,
|
|
|
43
42
|
* is drawing; the session in chat.mjs does the work.
|
|
44
43
|
*/
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
const ACCENT = 'cyan';
|
|
45
|
+
const ACCENT = '#d77757';
|
|
48
46
|
/** The marks the screen draws with: plain ones (`chat.screen plain`) for a screen reader. Every component reads them here. */
|
|
49
47
|
const Marks = createContext(glyphs(false));
|
|
50
48
|
const useMarks = () => useContext(Marks);
|
|
51
49
|
/** The name at the top of the chat, two rows of blocks. */
|
|
52
|
-
|
|
53
|
-
const
|
|
50
|
+
const WORDMARK = ['█▀▀ █ █ █▀▄▀█ █▀█', '▄▄█ █▄█ █ ▀ █ █▄█'];
|
|
51
|
+
const FLOW_STEP_MS = 100;
|
|
54
52
|
const TONES = { plain: {}, dim: { dimColor: true }, error: { color: 'red' }, add: { color: 'green' }, del: { color: 'red' }, ask: { color: 'yellow' } };
|
|
55
53
|
const LEAVE_WINDOW_MS = 2000;
|
|
56
54
|
const NOTICE_MS = 3000;
|
|
@@ -62,6 +60,10 @@ const CLEAR = '\x1b[2J\x1b[3J\x1b[H';
|
|
|
62
60
|
* 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
61
|
*/
|
|
64
62
|
const scrolledClear = (rows) => `\x1b[${rows};1H${'\n'.repeat(rows)}\x1b[H`;
|
|
63
|
+
/** A report that the window came to the front (`ESC[I`) or went behind (`ESC[O`). */
|
|
64
|
+
const FOCUS_REPORT = /\x1b\[[IO]/g;
|
|
65
|
+
/** 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. */
|
|
66
|
+
const FOCUS_LATE_MS = 1000;
|
|
65
67
|
/** The terminal says when its window comes to the front and goes behind (`[I`, `[O`); and keeps its title, to be given back. */
|
|
66
68
|
const FOCUS_ON = '\x1b[?1004h';
|
|
67
69
|
const FOCUS_OFF = '\x1b[?1004l';
|
|
@@ -238,15 +240,13 @@ const retryNote = ({ attempt, limit, reason }) => `${retryWhy(reason)} · retryi
|
|
|
238
240
|
const reverse = (text) => `\x1b[7m${text}\x1b[27m`;
|
|
239
241
|
|
|
240
242
|
/**
|
|
241
|
-
* The lines under a call: what came back,
|
|
242
|
-
* replies are folded by, so a line too long for the window goes on under itself — not under the
|
|
243
|
-
*
|
|
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.
|
|
243
|
+
* The lines under a call: what came back, the first of them with the mark. Folded to `columns` here, by the same count the
|
|
244
|
+
* 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.
|
|
245
|
+
* With `max`, at most that many rows: the last says how many lines were folded away — a line partly shown is shown.
|
|
245
246
|
*/
|
|
246
|
-
const linesUnder = (lines, columns, s = styles(false), max = null
|
|
247
|
+
const linesUnder = (lines, columns, s = styles(false), max = null) => {
|
|
247
248
|
const rows = [];
|
|
248
249
|
let reached = 0;
|
|
249
|
-
const room = Math.max(20, columns - at - 1);
|
|
250
250
|
// Folded only as far as the budget needs: a long edit is not laid out whole to show its top.
|
|
251
251
|
while (reached < lines.length && (max === null || rows.length <= max)) {
|
|
252
252
|
const line = lines[reached];
|
|
@@ -254,7 +254,7 @@ const linesUnder = (lines, columns, s = styles(false), max = null, at = OUT_AT)
|
|
|
254
254
|
const text = line.span ? withSpan(line, { ...s, inverse: reverse }) : linked(untab(line.text), s);
|
|
255
255
|
// 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
256
|
const hang = /^\s*(?:\d+(?: [-+ ] | {2,})\s*|[•*-] |\d+[.)] )/.exec(text)?.[0].length ?? 0;
|
|
257
|
-
rows.push(...fold(text,
|
|
257
|
+
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
258
|
reached++;
|
|
259
259
|
}
|
|
260
260
|
let kept = rows;
|
|
@@ -265,8 +265,7 @@ const linesUnder = (lines, columns, s = styles(false), max = null, at = OUT_AT)
|
|
|
265
265
|
const folded = lines.length - whole;
|
|
266
266
|
kept.push({ text: `… +${folded} line${folded === 1 ? '' : 's'}`, tone: 'dim' });
|
|
267
267
|
}
|
|
268
|
-
|
|
269
|
-
return kept.map((line, i) => h(Text, { key: i, ...TONES[line.tone], wrap: 'truncate' }, `${indent}${line.text}`));
|
|
268
|
+
return kept.map((line, i) => h(Text, { key: i, ...TONES[line.tone], wrap: 'truncate' }, `${i === 0 ? ` ${s.g.under} ` : ' '}${line.text}`));
|
|
270
269
|
};
|
|
271
270
|
|
|
272
271
|
/**
|
|
@@ -278,60 +277,39 @@ function lastLines({ out, cut }) {
|
|
|
278
277
|
return (cut ? lines.slice(1) : lines).map((l) => untab(l).trimEnd()).filter(Boolean).slice(-LIVE_LINES);
|
|
279
278
|
}
|
|
280
279
|
|
|
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
280
|
/**
|
|
306
|
-
* What a call ran, as the rows it takes
|
|
307
|
-
* long it ran — folded here, at the spaces, so a row that goes on starts at the
|
|
281
|
+
* 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
|
|
282
|
+
* 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
283
|
*/
|
|
309
284
|
function titleRows(view, took, s, width) {
|
|
310
|
-
const stat = view.stat ? ` ${s.green(`+${view.stat.added}`)} ${s.red(`−${view.stat.removed}`)}` : '';
|
|
311
285
|
const time = took >= TOOK_SHOWN_MS ? s.dim(` · ${elapsed(took)}`) : '';
|
|
312
|
-
|
|
286
|
+
// Several calls drawn as one say what they were in words, not as a call: `Read 3 files (a.js, b.js, +1)`.
|
|
287
|
+
const what = view.group ? `${s.bold(view.title)} (${view.detail})` : `${s.bold(view.title)}(${view.detail})`;
|
|
288
|
+
return untab(`${what}${statOf(view.stat, s)}${time}`)
|
|
313
289
|
.split('\n')
|
|
314
290
|
.flatMap((line) => wrap(line, width).split('\n'));
|
|
315
291
|
}
|
|
316
292
|
|
|
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
|
-
*/
|
|
293
|
+
/** A tool call: what ran, and under it what came back — or, while it runs, the jobs it started, or what it prints. */
|
|
322
294
|
function Tool(props) {
|
|
323
295
|
const g = useMarks();
|
|
324
296
|
const step = stepOf(props, g);
|
|
325
|
-
//
|
|
297
|
+
// Drawn again for its clock, a little more often than it turns over, so a second is never skipped.
|
|
326
298
|
useAnimation({ interval: 250, isActive: step.ticking });
|
|
327
|
-
const { view, failed = false, running = false, tight = false, columns } = props;
|
|
328
299
|
return h(
|
|
329
300
|
Box,
|
|
330
|
-
{ flexDirection: 'column', marginTop:
|
|
331
|
-
//
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
301
|
+
{ flexDirection: 'column', marginTop: props.afterBlank ? 0 : 1 },
|
|
302
|
+
// 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.
|
|
303
|
+
// A failure has a mark of its own: its colour alone says nothing to someone who cannot see it.
|
|
304
|
+
h(
|
|
305
|
+
Box,
|
|
306
|
+
null,
|
|
307
|
+
h(Box, { flexShrink: 0 }, h(Text, step.markTone, `${step.mark} `)),
|
|
308
|
+
// 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.
|
|
309
|
+
h(Box, { flexShrink: 1, flexDirection: 'column', width: Math.max(10, props.columns - 2) }, ...step.title.map((row, i) => h(Text, { key: i }, row))),
|
|
310
|
+
),
|
|
311
|
+
step.note ? h(Text, { dimColor: true }, ` ${g.under} ${step.note}`) : null,
|
|
312
|
+
...step.live.map((line, i) => h(Text, { key: `live-${i}`, dimColor: true, wrap: 'truncate' }, ` ${line}`)),
|
|
335
313
|
...step.jobs.map(([id, job]) => h(JobAtWork, { key: id, id, job })),
|
|
336
314
|
...step.under,
|
|
337
315
|
);
|
|
@@ -346,36 +324,34 @@ function stepOf({ view, failed = false, running = false, waiting = false, jobs =
|
|
|
346
324
|
// A question put to the user is not running anything: it waits on them, and says so.
|
|
347
325
|
// 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
326
|
// A delegation has no job yet while the router picks the model and effort it runs on.
|
|
349
|
-
const asking = running && view.title === '
|
|
350
|
-
|
|
351
|
-
// reader, there is none: the row is drawn again for what the command
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
const
|
|
327
|
+
const asking = running && view.title === 'Question' && !waiting;
|
|
328
|
+
const working = running && !waiting && !asking && jobs.length === 0;
|
|
329
|
+
// Only what runs has a clock. Plain, for a screen reader, there is none: the row is drawn again for what the command
|
|
330
|
+
// prints, not for the time.
|
|
331
|
+
const ticking = working && !plain;
|
|
332
|
+
const ran = ticking && since > 0 ? Date.now() - since : 0;
|
|
333
|
+
const width = Math.max(10, columns - 2);
|
|
355
334
|
// 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,
|
|
357
|
-
const title = waiting && rows.length > 1 ? [`${
|
|
335
|
+
const rows = titleRows(view, running ? 0 : took, s, width);
|
|
336
|
+
const title = waiting && rows.length > 1 ? [`${titleRows(view, 0, s, width - 2)[0]} …`] : rows;
|
|
358
337
|
return {
|
|
359
338
|
ticking,
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
markTone: waiting || asking ? { color: 'yellow' } : running ? { color: ACCENT } : failed ? { color: 'red' } : null,
|
|
339
|
+
mark: failed && !running ? g.fail : g.tool,
|
|
340
|
+
markTone: { color: running ? undefined : failed ? 'red' : 'green', dimColor: running },
|
|
363
341
|
title,
|
|
364
|
-
|
|
342
|
+
note: asking ? 'waiting for your answer' : working ? (view.title === 'Delegate' ? 'picking the model and effort…' : `Running…${ran >= 1000 ? ` ${elapsed(ran)}` : ''}`) : null,
|
|
343
|
+
live: working && live ? lastLines(live) : [],
|
|
365
344
|
jobs,
|
|
366
345
|
under: linesUnder(view.lines, columns, s, view.rows ?? null),
|
|
367
346
|
};
|
|
368
347
|
}
|
|
369
348
|
|
|
370
|
-
/** The rows a step takes on the screen: the blank one over it
|
|
349
|
+
/** 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
350
|
const stepRowCount = (props, g) => {
|
|
372
351
|
const step = stepOf(props, g);
|
|
373
|
-
return (props.
|
|
352
|
+
return (props.afterBlank ? 0 : 1) + step.title.length + (step.note ? 1 : 0) + step.live.length + step.jobs.length + step.under.length;
|
|
374
353
|
};
|
|
375
354
|
|
|
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
355
|
/** A call that took at least this long says how long, beside what ran. */
|
|
380
356
|
const TOOK_SHOWN_MS = 1000;
|
|
381
357
|
/** Thought for less than this, the line that says so would say nothing. */
|
|
@@ -396,14 +372,18 @@ const thoughtRows = (text, width, rows = THOUGHT_ROWS) =>
|
|
|
396
372
|
.flatMap((line) => wrap(line, width).split('\n'))
|
|
397
373
|
.slice(-rows);
|
|
398
374
|
|
|
375
|
+
/** 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. */
|
|
376
|
+
const JOB_COLOURS = ['cyan', 'magenta', 'blue', 'yellow', 'green'];
|
|
377
|
+
const jobColour = (id) => JOB_COLOURS[Number(id) % JOB_COLOURS.length];
|
|
378
|
+
|
|
399
379
|
/** The most of a job's title its row under the box shows. */
|
|
400
380
|
const TITLE_CHARS = 32;
|
|
401
381
|
|
|
402
382
|
/**
|
|
403
383
|
* 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
|
|
405
|
-
*
|
|
406
|
-
*
|
|
384
|
+
* a step and Enter away, not here. Under the call that waits for it; or — at work in the background, with no call standing
|
|
385
|
+
* 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
|
|
386
|
+
* whose record is open.
|
|
407
387
|
*/
|
|
408
388
|
function JobAtWork({ id, job, alone = false, picked = false, open = false }) {
|
|
409
389
|
// Plain, the row says what the job has done, not for how long: a clock would have it read out every second.
|
|
@@ -411,25 +391,31 @@ function JobAtWork({ id, job, alone = false, picked = false, open = false }) {
|
|
|
411
391
|
const plain = g === glyphs(true);
|
|
412
392
|
useAnimation({ interval: 1000, isActive: !plain });
|
|
413
393
|
const calls = `${job.calls} tool call${job.calls === 1 ? '' : 's'}`;
|
|
394
|
+
const mark = alone ? (picked ? ` ${g.pick} ` : ` ${g.tool} `) : ` ${g.under} `;
|
|
414
395
|
// 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 ?
|
|
416
|
-
const lead =
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
396
|
+
const who = alone ? ` ${job.agent} — ${job.title.length > TITLE_CHARS ? `${job.title.slice(0, TITLE_CHARS - 1)}…` : job.title}` : ` ${job.agent} · ${job.route}`;
|
|
397
|
+
const lead = `j${id}${who} · ${plain ? '' : `${elapsed(Date.now() - job.since)} · `}${calls} · `;
|
|
398
|
+
return h(
|
|
399
|
+
Text,
|
|
400
|
+
{ wrap: 'truncate' },
|
|
401
|
+
h(Text, picked || open ? { color: ACCENT } : { color: jobColour(id) }, mark),
|
|
402
|
+
h(Text, { dimColor: !picked }, lead),
|
|
403
|
+
h(Text, { dimColor: true }, 'working'),
|
|
404
|
+
!alone && job.where ? h(Text, { dimColor: true }, ` · ${job.where.replace(/^follow it: /, '')}`) : null,
|
|
405
|
+
);
|
|
420
406
|
}
|
|
421
407
|
|
|
422
408
|
/** The chat itself, as the first of the rows under the box: the place Enter comes back to from a job's record. */
|
|
423
409
|
const MAIN = 'main';
|
|
424
410
|
|
|
425
|
-
/** The chat's own row, over the jobs it delegated: marked when it is the one stepped on (`picked`),
|
|
411
|
+
/** 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
412
|
function MainAtWork({ working, picked = false, shown = false }) {
|
|
427
413
|
const g = useMarks();
|
|
428
|
-
return h(Text, { wrap: 'truncate' }, h(Text, picked || shown ? {
|
|
414
|
+
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
415
|
}
|
|
430
416
|
|
|
431
|
-
/** A line
|
|
432
|
-
const inMarks = (line, g) => (g.
|
|
417
|
+
/** A line written with the screen's own marks — a job's record — in the marks this screen draws with. */
|
|
418
|
+
const inMarks = (line, g) => (g.tool === '⏺' ? line : line.replaceAll('⏺', g.tool).replaceAll('⎿', g.under).replaceAll('✗', g.fail).replaceAll('✻', g.thought));
|
|
433
419
|
|
|
434
420
|
/** 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
421
|
function recordLines(id) {
|
|
@@ -443,38 +429,23 @@ function recordLines(id) {
|
|
|
443
429
|
/** 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
430
|
const openRows = (rows) => Math.max(3, Math.min(rows - 24, Math.floor(rows / 2)));
|
|
445
431
|
|
|
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
432
|
/**
|
|
460
433
|
* 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
434
|
* 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
435
|
*/
|
|
463
|
-
function JobOpen({ id, job, rows
|
|
436
|
+
function JobOpen({ id, job, rows }) {
|
|
464
437
|
useAnimation({ interval: 1000 });
|
|
465
438
|
const g = useMarks();
|
|
466
439
|
const all = recordLines(id);
|
|
467
|
-
const faint = underSteps(all);
|
|
468
440
|
const seen = all.slice(-openRows(rows));
|
|
469
441
|
const above = all.length - seen.length;
|
|
470
|
-
const pad = ' '.repeat(TEXT_AT);
|
|
471
442
|
return h(
|
|
472
443
|
Box,
|
|
473
444
|
{ flexDirection: 'column', marginTop: 1 },
|
|
474
|
-
h(
|
|
475
|
-
above > 0 ? h(Text, { dimColor: true },
|
|
476
|
-
all.length === 0 ? h(Text, { dimColor: true },
|
|
477
|
-
...seen.map((line, i) => h(Text, { key: i, dimColor:
|
|
445
|
+
h(Text, { wrap: 'truncate' }, h(Text, { color: jobColour(id) }, `${g.tool} `), h(Text, { bold: true }, `j${id}`), ` ${job.agent} · ${job.route} — ${job.title}`),
|
|
446
|
+
above > 0 ? h(Text, { dimColor: true }, ` … +${above} line${above === 1 ? '' : 's'}`) : null,
|
|
447
|
+
all.length === 0 ? h(Text, { dimColor: true }, ' nothing done yet') : null,
|
|
448
|
+
...seen.map((line, i) => h(Text, { key: i, dimColor: /^\s*⎿/.test(line), wrap: 'truncate' }, inMarks(untab(line), g) || ' ')),
|
|
478
449
|
);
|
|
479
450
|
}
|
|
480
451
|
|
|
@@ -568,28 +539,34 @@ function Ask({ ask, aside = false, waiting = 1, why = null, explain = false, col
|
|
|
568
539
|
// A key that answers nothing has every key explained here, in the panel's own colour, where nothing is cut to fit.
|
|
569
540
|
// Esc is named as the working line names it, wherever it stops the turn.
|
|
570
541
|
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:
|
|
572
|
-
//
|
|
573
|
-
// Plain, it has no bar: a frame is read out as a row of lines.
|
|
542
|
+
// 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
|
|
543
|
+
// keys that answer. Plain, it has no frame: a frame is read out as a row of lines.
|
|
574
544
|
const g = useMarks();
|
|
575
|
-
const framed = g
|
|
576
|
-
const width = Math.max(20, columns - TEXT_AT - 1);
|
|
545
|
+
const framed = g === glyphs(false);
|
|
577
546
|
// 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
|
|
579
|
-
const
|
|
580
|
-
const
|
|
547
|
+
const width = Math.max(20, columns - (framed ? 4 : 0));
|
|
548
|
+
const titled = wrap(`${g.warn} ${title}`, width);
|
|
549
|
+
const refused = ask.unsandboxed && ask.blocked ? fold(asText(`the sandbox refused: ${ask.blocked}`), width - 2) : [];
|
|
550
|
+
const input = whole === '{}' ? null : kept.flatMap((line) => fold(spacesCounted(untab(line)) || ' ', Math.max(10, width - 4)));
|
|
581
551
|
const keyed = keyRows(keys, width);
|
|
582
552
|
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 -
|
|
553
|
+
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
554
|
// 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
555
|
// 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
556
|
let shown = input ?? [];
|
|
587
557
|
let hidden = unshown;
|
|
558
|
+
// The blank rows around what would run: the first thing a window too short for the panel gives up.
|
|
559
|
+
let around = 1;
|
|
588
560
|
if (rows !== null && input) {
|
|
589
561
|
// A key's words longer than a row go on to the next: counted as they would fold, never fewer.
|
|
590
562
|
const keyRowCount = keyed.reduce((sum, row) => sum + wrap(row, width - 1).split('\n').length, 0);
|
|
591
|
-
|
|
592
|
-
|
|
563
|
+
let fixed = 1 + (framed ? 2 : 0) + titled.split('\n').length + refused.length + 2 + (reason.length > 0 ? reason.length + 1 : 0) + keyRowCount;
|
|
564
|
+
const fits = () => fixed + input.length + (hidden > 0 ? noted(hidden).length : 0) <= rows;
|
|
565
|
+
if (!fits()) {
|
|
566
|
+
around = 0;
|
|
567
|
+
fixed -= 2;
|
|
568
|
+
}
|
|
569
|
+
if (!fits()) {
|
|
593
570
|
const room = Math.max(1, rows - fixed - noted(hidden + whole.length).length);
|
|
594
571
|
hidden += input.slice(room).reduce((sum, row) => sum + row.trim().length, 0);
|
|
595
572
|
shown = input.slice(0, room);
|
|
@@ -597,26 +574,21 @@ function Ask({ ask, aside = false, waiting = 1, why = null, explain = false, col
|
|
|
597
574
|
}
|
|
598
575
|
return h(
|
|
599
576
|
Box,
|
|
600
|
-
{ marginTop: 1, flexDirection: 'column', width: Math.max(20, columns) },
|
|
601
|
-
h(
|
|
577
|
+
{ marginTop: 1, flexDirection: 'column', ...(framed ? { borderStyle: 'round', borderColor: 'yellow', paddingX: 1 } : {}), width: Math.max(20, columns) },
|
|
578
|
+
h(Text, { color: 'yellow', bold: true }, titled),
|
|
579
|
+
// Why a run outside is asked: what the sandbox refused, faint, under the question.
|
|
580
|
+
...refused.map((row, i) => h(Text, { key: `refused-${i}`, dimColor: true, wrap: 'truncate' }, ` ${row}`)),
|
|
581
|
+
// 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
582
|
h(
|
|
603
583
|
Box,
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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))),
|
|
584
|
+
{ flexDirection: 'column', paddingLeft: 4, marginY: around },
|
|
585
|
+
...(input === null ? [h(Text, { key: 'none', dimColor: true }, '(no input)')] : shown.map((row, i) => h(Text, { key: i, wrap: 'truncate' }, row || ' '))),
|
|
586
|
+
...(hidden > 0 ? noted(hidden).map((row, i) => h(Text, { key: `noted-${i}`, dimColor: true, wrap: 'truncate' }, row)) : []),
|
|
619
587
|
),
|
|
588
|
+
why !== null ? h(Box, { marginBottom: 1 }, h(Box, { flexShrink: 0 }, h(Text, { color: 'yellow' }, 'why not? ')), h(Text, null, reason.join('\n'))) : null,
|
|
589
|
+
// The keys go to as many rows as they need, broken only between keys — at full weight, the key itself bold: they are
|
|
590
|
+
// what the panel asks the user to read and press.
|
|
591
|
+
...keyed.map((row, i) => h(Text, { key: `keys-${i}`, ...(explain && why === null ? { color: 'yellow' } : {}), wrap: 'wrap' }, ...keysBold(row))),
|
|
620
592
|
);
|
|
621
593
|
}
|
|
622
594
|
|
|
@@ -641,32 +613,29 @@ export function keyRows(said, width) {
|
|
|
641
613
|
return rows;
|
|
642
614
|
}
|
|
643
615
|
|
|
644
|
-
/** A mark, and words that go on under themselves, never under the mark: the
|
|
616
|
+
/** A mark, and words that go on under themselves, never under the mark: the rows of a question and its options. */
|
|
645
617
|
function Hung({ mark, width, color, children }) {
|
|
646
618
|
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
619
|
}
|
|
648
620
|
|
|
649
|
-
/** A question of the model's:
|
|
621
|
+
/** 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
622
|
function Question({ ask, columns }) {
|
|
651
623
|
const g = useMarks();
|
|
652
|
-
const width = Math.max(20, columns - TEXT_AT);
|
|
653
624
|
return h(
|
|
654
625
|
Box,
|
|
655
626
|
{ marginTop: 1, flexDirection: 'column' },
|
|
656
|
-
h(
|
|
657
|
-
h(
|
|
658
|
-
|
|
659
|
-
|
|
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
|
-
),
|
|
627
|
+
h(Hung, { mark: '? ', width: columns, color: 'yellow' }, ask.question),
|
|
628
|
+
...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)),
|
|
629
|
+
// Broken only between keys, as a panel's are: never `esc` at the end of a row and `to interrupt` on the next.
|
|
630
|
+
...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
631
|
);
|
|
665
632
|
}
|
|
666
633
|
|
|
667
|
-
/** One line of a reply; the first of a block
|
|
668
|
-
function Reply({ text, first
|
|
669
|
-
|
|
634
|
+
/** One line of a reply; the first of a block carries the mark. */
|
|
635
|
+
function Reply({ text, first }) {
|
|
636
|
+
const g = useMarks();
|
|
637
|
+
// 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.
|
|
638
|
+
return h(Box, { marginTop: first ? 1 : 0 }, h(Box, { flexShrink: 0 }, h(Text, null, first ? `${g.tool} ` : ' ')), h(Text, null, text || ' '));
|
|
670
639
|
}
|
|
671
640
|
|
|
672
641
|
/** 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 +650,100 @@ const realOrSame = (folder) => {
|
|
|
681
650
|
/** Why the tools are not working in the folder the chat was opened in, and what makes them. */
|
|
682
651
|
const awayLine = (folder) => `${folder} is not a project: the tools work in scratch — sumo project add . there makes it one`;
|
|
683
652
|
|
|
684
|
-
/** The
|
|
685
|
-
const
|
|
653
|
+
/** The header's second row: the project the tools work in and its branch, then — faint — the folder it is. */
|
|
654
|
+
const whereRow = (item) => (item.place ? [item.place, h(Text, { key: 'cwd', dimColor: true }, ` · ${item.cwd}`)] : [h(Text, { key: 'cwd', dimColor: true }, item.cwd)]);
|
|
686
655
|
|
|
687
656
|
/** Something finished, drawn once and left to scroll. */
|
|
688
657
|
/** `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
658
|
function Item({ item, columns, s }) {
|
|
690
|
-
//
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
659
|
+
// A blank line of a reply right before is the row between them: never two in a row.
|
|
660
|
+
const gap = item.afterBlank ? 0 : 1;
|
|
661
|
+
// Plain, the name is said, not drawn in blocks: a reader would spell out every one of them.
|
|
662
|
+
if (item.kind === 'header' && s.plain) {
|
|
694
663
|
return h(
|
|
695
664
|
Box,
|
|
696
665
|
{ flexDirection: 'column', marginTop: 1 },
|
|
666
|
+
h(Text, { wrap: 'truncate-end' }, item.route, VERSION ? h(Text, { dimColor: true }, ` sumo ${VERSION}`) : null),
|
|
667
|
+
h(Text, { wrap: 'truncate-middle' }, ...whereRow(item)),
|
|
668
|
+
item.away ? h(Text, { dimColor: true }, wrap(awayLine(item.away), Math.max(10, columns - 1))) : null,
|
|
669
|
+
item.block ? h(Box, { marginTop: 1 }, h(Text, null, item.block)) : null,
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
if (item.kind === 'header') {
|
|
673
|
+
return h(
|
|
674
|
+
Box,
|
|
675
|
+
{ flexDirection: 'column' },
|
|
697
676
|
h(
|
|
698
|
-
|
|
699
|
-
{
|
|
700
|
-
//
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
: [h(Text, { key: 'cwd', dimColor: true, wrap: 'truncate-middle' }, item.cwd), h(Text, { key: 'who', wrap: 'truncate-end' }, who)]),
|
|
677
|
+
Box,
|
|
678
|
+
{ gap: 3, marginTop: 1 },
|
|
679
|
+
// The sunset runs across the name, gold at the S to crimson at the O.
|
|
680
|
+
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))))),
|
|
681
|
+
// Beside the name, as wide as the window leaves: a long path loses its middle, never runs past the edge.
|
|
682
|
+
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
683
|
),
|
|
706
|
-
item.away ? h(Box, {
|
|
707
|
-
item.block ? h(Box, { marginTop: 1
|
|
684
|
+
item.away ? h(Box, { marginTop: 1 }, h(Text, { dimColor: true }, wrap(awayLine(item.away), Math.max(10, columns - 1)))) : null,
|
|
685
|
+
item.block ? h(Box, { marginTop: 1 }, h(Text, null, item.block)) : null,
|
|
708
686
|
);
|
|
709
687
|
}
|
|
710
|
-
// What the user said is what a scroll back looks for:
|
|
688
|
+
// 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
689
|
if (item.kind === 'user') {
|
|
712
690
|
const more = item.more ? h(Text, { dimColor: true }, `… +${item.more} line${item.more === 1 ? '' : 's'}`) : null;
|
|
713
|
-
|
|
714
|
-
return h(
|
|
691
|
+
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);
|
|
692
|
+
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
693
|
}
|
|
716
|
-
if (item.kind === 'text') return h(Reply,
|
|
717
|
-
if (item.kind === 'tool') return h(Tool, { ...item,
|
|
694
|
+
if (item.kind === 'text') return h(Reply, item);
|
|
695
|
+
if (item.kind === 'tool') return h(Tool, { ...item, columns, s });
|
|
718
696
|
if (item.kind === 'output') return h(Box, { flexDirection: 'column' }, ...linesUnder(item.lines, columns, s));
|
|
719
|
-
//
|
|
720
|
-
if (item.kind === 'footer') return h(Box, {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
//
|
|
697
|
+
// Its margin holds on every row it wraps to: the turn summed up stands apart from the work above it.
|
|
698
|
+
if (item.kind === 'footer') return h(Box, { marginTop: gap, paddingLeft: 2 }, h(Text, { dimColor: true }, item.text));
|
|
699
|
+
// The mark stands apart from the words, so a line that wraps in a narrow window goes on under them, not under it.
|
|
700
|
+
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}`))));
|
|
701
|
+
// 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:
|
|
702
|
+
// folded here, at the spaces. What came back stands faint beneath, at the same margin.
|
|
724
703
|
if (item.kind === 'error') {
|
|
725
|
-
const width = Math.max(10, columns -
|
|
704
|
+
const width = Math.max(10, columns - 2);
|
|
726
705
|
return h(
|
|
727
706
|
Box,
|
|
728
|
-
{ marginTop:
|
|
729
|
-
h(
|
|
730
|
-
item.detail ? h(Box, { paddingLeft:
|
|
707
|
+
{ marginTop: gap, flexDirection: 'column' },
|
|
708
|
+
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)))),
|
|
709
|
+
item.detail ? h(Box, { paddingLeft: 2 }, h(Text, { dimColor: true }, item.detail)) : null,
|
|
731
710
|
);
|
|
732
711
|
}
|
|
733
712
|
// /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
713
|
if (item.kind === 'help') {
|
|
736
714
|
const wide = Math.max(...item.rows.filter(Boolean).map((row) => row.key.length)) + 2;
|
|
737
715
|
const room = Math.max(10, columns - 2 - wide);
|
|
738
716
|
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
717
|
}
|
|
740
718
|
// What the model thought before it answered: how long, here; the thought itself is in the pager.
|
|
741
|
-
if (item.kind === 'thought') return h(
|
|
742
|
-
|
|
743
|
-
return h(Box, { flexDirection: 'column' }, ...linesUnder(item.text.split('\n').map((text) => ({ text, tone: 'dim' })), columns, s, null, TEXT_AT));
|
|
719
|
+
if (item.kind === 'thought') return h(Box, { marginTop: gap }, h(Text, { dimColor: true }, `${s.g.thought} Thought for ${elapsed(item.ms)}`));
|
|
720
|
+
return h(Box, { flexDirection: 'column' }, ...linesUnder(item.text.split('\n').map((text) => ({ text, tone: 'dim' })), columns, s));
|
|
744
721
|
}
|
|
745
722
|
|
|
746
723
|
/** The fewest characters of its words the working line keeps before what follows them gives way as well. */
|
|
747
724
|
const WORDS_KEPT = 12;
|
|
748
725
|
|
|
749
726
|
/**
|
|
750
|
-
* The line that says it is working:
|
|
751
|
-
*
|
|
752
|
-
* of what it has thought so far.
|
|
727
|
+
* The line that says it is working: your words, the next of them every few seconds, a sunset flowing through them; how
|
|
728
|
+
* 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
729
|
*/
|
|
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
|
|
730
|
+
function Working({ messages, first, tokens, thought = '', heard = 0, quietAfterMs = QUIET_AFTER_MS, motion = true, retry = null, plan = null, waiting = false, afterBlank = false }) {
|
|
731
|
+
// With motion off the words stand in one colour and the line is drawn once a second, for its clock. While a question
|
|
756
732
|
// waits on the user, nothing works: the line steps aside — the question's own rows say it waits, and how Esc stops the
|
|
757
733
|
// turn — and nothing is drawn for it, so the screen holds still while the question is read. It stays in place, its
|
|
758
734
|
// clock running, to come back when the question is answered. Plain, for a screen reader, there is no clock at all: a
|
|
759
735
|
// row written again every second is a row read out again every second.
|
|
760
736
|
const g = useMarks();
|
|
761
737
|
const plain = g === glyphs(true);
|
|
762
|
-
const
|
|
763
|
-
const { frame } = useAnimation({ interval:
|
|
738
|
+
const flowing = motion && !waiting;
|
|
739
|
+
const { frame } = useAnimation({ interval: flowing ? FLOW_STEP_MS : 1000, isActive: !plain && !waiting });
|
|
764
740
|
// Timed from when the line appeared, not by the animation, whose clock starts again whenever its pace changes.
|
|
765
741
|
const began = useRef(Date.now());
|
|
766
742
|
const time = Date.now() - began.current;
|
|
767
743
|
const { columns } = useWindowSize();
|
|
768
744
|
if (waiting) return null;
|
|
769
745
|
const said = `${messageAt(messages, first, time)}…`;
|
|
770
|
-
const thinking = thoughtRows(thought, Math.max(20, columns -
|
|
746
|
+
const thinking = thoughtRows(thought, Math.max(20, columns - 6));
|
|
771
747
|
// `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
748
|
const silent = heard > 0 ? Date.now() - heard : 0;
|
|
773
749
|
// A request sent again is waited on in the open: how long until it goes, and which try it is.
|
|
@@ -778,10 +754,10 @@ function Working({ messages, first, tokens, thought = '', heard = 0, quietAfterM
|
|
|
778
754
|
again: retry && plain ? `retrying · attempt ${retry.attempt}/${retry.limit}` : left > 0 ? `retrying in ${Math.ceil(left / 1000)}s · attempt ${retry.attempt}/${retry.limit}` : '',
|
|
779
755
|
quiet: !plain && silent >= quietAfterMs ? `quiet ${elapsed(silent)}` : '',
|
|
780
756
|
};
|
|
781
|
-
const status = () => [parts.clock, parts.spent, parts.again, parts.quiet, 'esc to interrupt'].filter(Boolean).join(' · ')
|
|
757
|
+
const status = () => `(${[parts.clock, parts.spent, parts.again, parts.quiet, 'esc to interrupt'].filter(Boolean).join(' · ')})`;
|
|
782
758
|
// In a narrow window what is least needed gives way first — the tokens, the silence — then the words, to a few of their
|
|
783
759
|
// own, then the clock and the try. How to stop the turn is never what is cut.
|
|
784
|
-
const room = () => columns -
|
|
760
|
+
const room = () => columns - status().length - 1;
|
|
785
761
|
for (const part of ['spent', 'quiet']) if (room() < said.length) parts[part] = '';
|
|
786
762
|
for (const part of ['clock', 'again']) if (room() < WORDS_KEPT) parts[part] = '';
|
|
787
763
|
// Cut between words where there is one to cut at: what is left still reads.
|
|
@@ -790,16 +766,17 @@ function Working({ messages, first, tokens, thought = '', heard = 0, quietAfterM
|
|
|
790
766
|
const words = said.length <= fits ? said : `${(cut.lastIndexOf(' ') >= WORDS_KEPT / 2 ? cut.slice(0, cut.lastIndexOf(' ')) : cut).trimEnd()}…`;
|
|
791
767
|
return h(
|
|
792
768
|
Box,
|
|
793
|
-
{ marginTop: 1, flexDirection: 'column' },
|
|
769
|
+
{ marginTop: afterBlank ? 0 : 1, flexDirection: 'column' },
|
|
794
770
|
// One row: the words, and what follows them cut at the edge rather than set in a column of its own beside them.
|
|
795
771
|
h(
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
h(Box,
|
|
772
|
+
Box,
|
|
773
|
+
null,
|
|
774
|
+
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} `)),
|
|
775
|
+
h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate-end' }, status())),
|
|
799
776
|
),
|
|
800
777
|
// 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' },
|
|
802
|
-
...thinking.map((row, i) => h(Text, { key: i, dimColor: true, wrap: 'truncate' }, `${
|
|
778
|
+
plan ? h(Text, { dimColor: true, wrap: 'truncate-end' }, ` plan ${plan.done}/${plan.total}${plan.next ? ` · next: ${plan.next}` : ' · all done'}`) : null,
|
|
779
|
+
...thinking.map((row, i) => h(Text, { key: i, dimColor: true, wrap: 'truncate' }, `${i === 0 ? ` ${g.under} ` : ' '}${row}`)),
|
|
803
780
|
);
|
|
804
781
|
}
|
|
805
782
|
|
|
@@ -840,33 +817,23 @@ export function inView({ text, cursor }, width, max) {
|
|
|
840
817
|
return { text: text.slice(rows[first][0], rows[last][1]), cursor: cursor - rows[first][0], above: first, below: rows.length - 1 - last };
|
|
841
818
|
}
|
|
842
819
|
|
|
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
|
-
*/
|
|
820
|
+
/** 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
821
|
function Input({ state, width, rows, placeholder = '' }) {
|
|
849
|
-
const seen = inView(state, Math.max(10, width -
|
|
822
|
+
const seen = inView(state, Math.max(10, width - 6), Math.max(3, Math.min(INPUT_ROWS, rows - 12)));
|
|
850
823
|
const { text, cursor } = seen;
|
|
851
824
|
const on = under(seen);
|
|
852
825
|
// A cursor on a line end, or past the last character, is drawn as a space of its own.
|
|
853
826
|
const shown = on === '' || on === '\n' ? ' ' : on;
|
|
854
827
|
const after = on === '\n' ? text.slice(cursor) : text.slice(cursor + on.length);
|
|
855
828
|
const hidden = (n) => (n > 0 ? h(Text, { dimColor: true }, `… +${n} line${n === 1 ? '' : 's'}`) : null);
|
|
856
|
-
// Plain,
|
|
857
|
-
const
|
|
858
|
-
const framed = g !== glyphs(true);
|
|
829
|
+
// Plain, the box is its prompt alone: a frame is read out as a row of lines.
|
|
830
|
+
const framed = useMarks().tool === '⏺';
|
|
859
831
|
return h(
|
|
860
832
|
Box,
|
|
861
|
-
{
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
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
|
-
),
|
|
833
|
+
{ ...(framed ? { borderStyle: 'round', borderColor: 'gray', paddingX: 1 } : {}), width },
|
|
834
|
+
h(Box, { flexShrink: 0 }, h(Text, null, '> ')),
|
|
835
|
+
// An empty box says what it is for, faint behind the cursor, until something has been said.
|
|
836
|
+
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
837
|
);
|
|
871
838
|
}
|
|
872
839
|
|
|
@@ -893,15 +860,14 @@ function clauseFit(text, room) {
|
|
|
893
860
|
function Menu({ menu, pick, columns = 80 }) {
|
|
894
861
|
const g = useMarks();
|
|
895
862
|
const wide = Math.max(...menu.map((c) => c.label.length)) + 2;
|
|
896
|
-
// The row's room for the description: the window less
|
|
897
|
-
const room = Math.max(10, columns -
|
|
863
|
+
// The row's room for the description: the window less its margins, the mark and the name.
|
|
864
|
+
const room = Math.max(10, columns - 4 - 2 - wide);
|
|
898
865
|
const first = Math.min(Math.max(0, pick - MENU_ROWS + 1), Math.max(0, menu.length - MENU_ROWS));
|
|
899
866
|
const shown = menu.slice(first, first + MENU_ROWS);
|
|
900
867
|
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
868
|
return h(
|
|
903
869
|
Box,
|
|
904
|
-
{ flexDirection: 'column',
|
|
870
|
+
{ flexDirection: 'column', paddingX: 2 },
|
|
905
871
|
first > 0 ? h(Text, { dimColor: true }, ` ↑ ${first} more`) : null,
|
|
906
872
|
// A hint is one row: wrapped, its second line would stand under the names, where a name is looked for.
|
|
907
873
|
...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 +902,15 @@ const KEY_WIDTH = Math.max(...KEYS.map(([key]) => key.length)) + 2;
|
|
|
936
902
|
/** `?` on an empty box: the keys, in as many columns as the window holds, until the next key. */
|
|
937
903
|
function Keys({ columns }) {
|
|
938
904
|
const per = columns >= 96 ? 3 : columns >= 64 ? 2 : 1;
|
|
939
|
-
const width = Math.floor((columns -
|
|
905
|
+
const width = Math.floor((columns - 4) / per);
|
|
940
906
|
const rows = [];
|
|
941
907
|
for (let i = 0; i < KEYS.length; i += per) rows.push(KEYS.slice(i, i + per));
|
|
942
908
|
return h(
|
|
943
909
|
Box,
|
|
944
|
-
{ flexDirection: 'column',
|
|
910
|
+
{ flexDirection: 'column', paddingX: 2 },
|
|
945
911
|
...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
912
|
// Broken only between its parts, as a question's keys are.
|
|
947
|
-
...keyRows('/help has the commands too · any key closes this', columns -
|
|
913
|
+
...keyRows('/help has the commands too · any key closes this', columns - 4).map((row, i) => h(Text, { key: `more-${i}`, dimColor: true }, row)),
|
|
948
914
|
);
|
|
949
915
|
}
|
|
950
916
|
|
|
@@ -952,7 +918,7 @@ function Keys({ columns }) {
|
|
|
952
918
|
function Search({ search }) {
|
|
953
919
|
return h(
|
|
954
920
|
Box,
|
|
955
|
-
{
|
|
921
|
+
{ paddingX: 2 },
|
|
956
922
|
h(
|
|
957
923
|
Text,
|
|
958
924
|
{ wrap: 'truncate-end' },
|
|
@@ -992,31 +958,28 @@ function Status({ session, leaving, notice, jobs, aside = [], pick = null, open
|
|
|
992
958
|
// In a narrow window the hints give way, then the place — unless the line has something to say just now, which the place
|
|
993
959
|
// gives way to; the model, the size of the context and the cost never fold.
|
|
994
960
|
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
961
|
// 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
962
|
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 -
|
|
963
|
+
const room = columns - 4 - route.length - 2;
|
|
964
|
+
const said = leaving || notice;
|
|
1002
965
|
const placed = place && place.length + 3 <= room - (said ? hint.length + 2 : 0) ? place : '';
|
|
1003
966
|
const hinted = room - (placed ? placed.length + 3 : 0) >= 12 ? fitHint(hint, room - (placed ? placed.length + 3 : 0)) : '';
|
|
1004
967
|
// 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
968
|
// narrow window; the route stands at the right with the place beside it, while the keys keep room for their first words.
|
|
1006
969
|
if (jobs.length > 0) {
|
|
1007
970
|
// The keys come first here: the place stands beside the route only when they still fit whole.
|
|
1008
|
-
const beside = place && columns -
|
|
971
|
+
const beside = place && columns - 4 - route.length - place.length - 3 - 2 >= hint.length;
|
|
1009
972
|
return h(
|
|
1010
973
|
Box,
|
|
1011
|
-
{
|
|
1012
|
-
h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate' }, fitHint(hint, columns -
|
|
974
|
+
{ paddingX: 2, justifyContent: 'space-between', gap: 2 },
|
|
975
|
+
h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate' }, fitHint(hint, columns - 4 - route.length - 2 - (beside ? place.length + 3 : 0)))),
|
|
1013
976
|
h(Box, { flexShrink: 0, gap: 3 }, routed, beside ? h(Text, { dimColor: true }, place) : null),
|
|
1014
977
|
);
|
|
1015
978
|
}
|
|
1016
|
-
// The place stands with the route it belongs to, on the left
|
|
979
|
+
// The place stands with the route it belongs to, on the left; the keys at the right.
|
|
1017
980
|
return h(
|
|
1018
981
|
Box,
|
|
1019
|
-
{
|
|
982
|
+
{ paddingX: 2, justifyContent: 'space-between', gap: 2 },
|
|
1020
983
|
h(Box, { flexShrink: 0, gap: 3 }, routed, placed ? h(Text, { dimColor: true }, placed) : null),
|
|
1021
984
|
hinted ? h(Box, { flexShrink: 1 }, h(Text, { dimColor: true, wrap: 'truncate' }, hinted)) : null,
|
|
1022
985
|
);
|
|
@@ -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
|
|
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,7 +1046,8 @@ 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
|
-
|
|
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.
|
|
@@ -1096,8 +1060,14 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
|
|
|
1096
1060
|
state.columns = columns;
|
|
1097
1061
|
state.rows = rows;
|
|
1098
1062
|
|
|
1099
|
-
/**
|
|
1100
|
-
|
|
1063
|
+
/**
|
|
1064
|
+
* 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
|
|
1065
|
+
* row between them, and the item's own blank row over it is not drawn: never two blank rows in a row.
|
|
1066
|
+
*/
|
|
1067
|
+
const stamped = (item) => {
|
|
1068
|
+
const last = state.items.at(-1);
|
|
1069
|
+
return { id: state.next++, afterBlank: last?.kind === 'text' && !String(last.text ?? '').trim(), ...item };
|
|
1070
|
+
};
|
|
1101
1071
|
const place = (items) => {
|
|
1102
1072
|
for (const item of items) {
|
|
1103
1073
|
const placed = stamped(item);
|
|
@@ -1133,7 +1103,7 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
|
|
|
1133
1103
|
const named = seen.length > 2 ? [...seen.slice(0, 2), `+${seen.length - 2}`] : seen;
|
|
1134
1104
|
const lines = reads.reduce((sum, entry) => sum + (entry.result.content === '' ? 0 : entry.result.content.replace(/\n$/, '').split('\n').length), 0);
|
|
1135
1105
|
const files = new Set(reads.map((entry) => entry.call.input?.path)).size;
|
|
1136
|
-
return [{ kind: 'tool', view: { title:
|
|
1106
|
+
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
1107
|
};
|
|
1138
1108
|
const placeReads = () => {
|
|
1139
1109
|
if (state.reads.length > 0) place(readsDrawn(state.reads.splice(0)));
|
|
@@ -1160,14 +1130,14 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
|
|
|
1160
1130
|
state.fresh = false;
|
|
1161
1131
|
},
|
|
1162
1132
|
s,
|
|
1163
|
-
{ width: state.columns -
|
|
1133
|
+
{ width: state.columns - 3 },
|
|
1164
1134
|
);
|
|
1165
1135
|
/** One entry of the log as the lines this window shows for it. */
|
|
1166
1136
|
function drawn(entry) {
|
|
1167
1137
|
if (entry.kind === 'header') {
|
|
1168
1138
|
// The memory block is the model's; what is wrong in it is the user's to see.
|
|
1169
1139
|
const warnings = entry.block.split('\n').filter((line) => line.startsWith('Warning')).join('\n');
|
|
1170
|
-
return [{ ...entry, block: warnings && renderBlock(warnings, s, { width: state.columns -
|
|
1140
|
+
return [{ ...entry, block: warnings && renderBlock(warnings, s, { width: state.columns - 1 }) }];
|
|
1171
1141
|
}
|
|
1172
1142
|
if (entry.kind === 'tool') {
|
|
1173
1143
|
const view = toolView(entry.call, entry.result, { cwd: state.where.cwd });
|
|
@@ -1198,6 +1168,8 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
|
|
|
1198
1168
|
const lines = entry.text.split('\n');
|
|
1199
1169
|
if (lines.length > ECHO_LINES) return [{ ...entry, text: lines.slice(0, ECHO_LINES).join('\n'), more: lines.length - ECHO_LINES }];
|
|
1200
1170
|
}
|
|
1171
|
+
// A note for the pager alone — which guide rode in with a message — is not drawn on the screen.
|
|
1172
|
+
if (entry.kind === 'note' && entry.quiet) return [];
|
|
1201
1173
|
if (entry.kind !== 'reply') return [entry];
|
|
1202
1174
|
const lines = [];
|
|
1203
1175
|
state.fresh = true;
|
|
@@ -1866,7 +1838,8 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
|
|
|
1866
1838
|
// What the model was handed without being asked: a way of working, or the check it stopped short of.
|
|
1867
1839
|
const onGuide = ({ name }) => {
|
|
1868
1840
|
closeReply();
|
|
1869
|
-
|
|
1841
|
+
// For the pager alone: put in the log, not drawn — drawing nothing would still close a row of reads still growing.
|
|
1842
|
+
state.log.push({ kind: 'note', text: `guide: ${name}`, quiet: true });
|
|
1870
1843
|
};
|
|
1871
1844
|
// The pages a reply cites, under it. A title is a page's own words: nothing in it may drive the terminal.
|
|
1872
1845
|
const onSources = ({ sources }) => {
|
|
@@ -1978,7 +1951,7 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
|
|
|
1978
1951
|
|
|
1979
1952
|
// 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
1953
|
useEffect(() => {
|
|
1981
|
-
const title = `${state.asks.length > 0 ? '? ' : state.working ? '
|
|
1954
|
+
const title = `${state.asks.length > 0 ? '? ' : state.working ? '✳ ' : ''}sumo · ${state.where.name}`;
|
|
1982
1955
|
if (title === state.title) return;
|
|
1983
1956
|
state.title = title;
|
|
1984
1957
|
tell(`\x1b]2;${safeForTerminal(title)}\x07`);
|
|
@@ -2180,20 +2153,22 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
|
|
|
2180
2153
|
// Ink adds a line under the frame; a frame that reached the last row would be drawn as a full screen.
|
|
2181
2154
|
const room = state.unmeasured.length > 0 ? 0 : Math.max(0, rows - state.used - 1);
|
|
2182
2155
|
// Reads that wait for what comes after them, drawn as the row they will make.
|
|
2183
|
-
|
|
2156
|
+
// A reply's blank line just placed is the row before what is live under it, as it is before what is placed.
|
|
2157
|
+
const blankBefore = state.items.at(-1)?.kind === 'text' && !String(state.items.at(-1).text ?? '').trim();
|
|
2158
|
+
const reads = state.reads.length > 0 ? readsDrawn(state.reads).map((item, i) => (i === 0 ? { ...item, afterBlank: blankBefore } : item)) : [];
|
|
2184
2159
|
// What runs now, and under a delegate call the jobs it started.
|
|
2185
2160
|
// 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
2161
|
const steps = [...state.running.values()]
|
|
2187
2162
|
.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,
|
|
2163
|
+
.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
2164
|
// A question to approve takes the rows the window has left — less the work over it and what stands under it — and never
|
|
2190
2165
|
// more: a frame that filled the window would have Ink wipe the screen and its scrollback to draw it. Counted from the
|
|
2191
2166
|
// same layout the rows are drawn from; a line of a reply still arriving is counted as it would fold, never fewer.
|
|
2192
2167
|
const approving = state.asks.length > 0 && !state.asks[0].options;
|
|
2193
2168
|
const recorded = approving && state.open !== null ? recordLines(state.open).length : 0;
|
|
2194
2169
|
const over = approving
|
|
2195
|
-
? reads.reduce((sum, item) => sum + stepRowCount({ ...item,
|
|
2196
|
-
(tail ? (state.fresh ? 1 : 0) + wrap(untab(tail), Math.max(10, columns -
|
|
2170
|
+
? reads.reduce((sum, item) => sum + stepRowCount({ ...item, columns, s }, s.g), 0) +
|
|
2171
|
+
(tail ? (state.fresh ? 1 : 0) + wrap(untab(tail), Math.max(10, columns - 2)).split('\n').length : 0) +
|
|
2197
2172
|
steps.reduce((sum, step) => sum + stepRowCount(step, s.g), 0)
|
|
2198
2173
|
: 0;
|
|
2199
2174
|
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;
|
|
@@ -2203,26 +2178,27 @@ function App({ session, events, messages, cwd, block, opening, logo, clipboard,
|
|
|
2203
2178
|
{ flexDirection: 'column', minHeight: room },
|
|
2204
2179
|
h(Static, { key: state.epoch, items: state.items }, (item) => h(Item, { key: item.id, item, columns, s })),
|
|
2205
2180
|
...reads.map((item, i) => h(Item, { key: `reads-${i}`, item, columns, s })),
|
|
2206
|
-
tail ? h(Reply, { text: tail, first: state.fresh
|
|
2181
|
+
tail ? h(Reply, { text: tail, first: state.fresh }) : null,
|
|
2207
2182
|
// In one box of their own, so the lines coming and going never move what follows — the working line keeps its clock.
|
|
2208
2183
|
h(Box, { flexDirection: 'column' }, ...steps.map((step) => h(Tool, step))),
|
|
2209
2184
|
// 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,
|
|
2185
|
+
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
2186
|
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
2187
|
// 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
|
|
2188
|
+
state.open !== null ? h(JobOpen, { id: state.open, job: state.jobs.get(state.open), rows }) : null,
|
|
2214
2189
|
// The logo and what to try are the empty room's: once something has been said, the room is the conversation's.
|
|
2215
2190
|
h(Room, { logo: said ? [] : logo, rows, from: state.used, starter: !said }),
|
|
2216
2191
|
h(
|
|
2217
2192
|
Box,
|
|
2218
2193
|
{ flexDirection: 'column', marginTop: 1 },
|
|
2219
2194
|
// 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' },
|
|
2195
|
+
...state.queue.map(({ line, steer }, i) => h(Text, { key: i, dimColor: true, wrap: 'truncate' }, ` ${steer ? reading : 'queued'}: ${line.split('\n')[0]}${line.includes('\n') ? ' …' : ''}`)),
|
|
2221
2196
|
// 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
|
|
2197
|
+
state.asks.length > 0 && !state.asks[0].options ? null : h(Input, { state: state.ed, width: columns, rows, placeholder: said ? '' : 'Ask anything' }),
|
|
2223
2198
|
// 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
2199
|
...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
|
-
|
|
2200
|
+
// 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.
|
|
2201
|
+
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 }),
|
|
2226
2202
|
),
|
|
2227
2203
|
);
|
|
2228
2204
|
}
|
|
@@ -2264,18 +2240,56 @@ export function runUi({ session, events, resume = null, stdin = process.stdin, s
|
|
|
2264
2240
|
}, KITTY_WAIT_MS).unref();
|
|
2265
2241
|
}
|
|
2266
2242
|
// 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.
|
|
2243
|
+
// behind rings. The reports are taken out of what is read here, before Ink sees it. Ink drops a whole one, but one that
|
|
2244
|
+
// comes in two reads — the ESC, then `[I` more than 20 ms later, as a multiplexer or a busy terminal may send it — it
|
|
2245
|
+
// reads as the Esc key and then `[I` typed into the box: Esc stopped the turn, and every switch of tabs typed more.
|
|
2246
|
+
// A terminal that speaks the kitty keyboard protocol (Ghostty, kitty, WezTerm: Ink turns it on) sends the Esc key as
|
|
2247
|
+
// `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.
|
|
2248
|
+
// 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
2249
|
const front = { now: true };
|
|
2269
2250
|
if (typeof stdin.read === 'function') {
|
|
2270
2251
|
const read = stdin.read.bind(stdin);
|
|
2252
|
+
let kitty = false;
|
|
2253
|
+
let held = '';
|
|
2254
|
+
let ready = null;
|
|
2255
|
+
let timer = null;
|
|
2256
|
+
let bare = 0;
|
|
2271
2257
|
stdin.read = (...args) => {
|
|
2258
|
+
if (ready !== null) {
|
|
2259
|
+
const out = ready;
|
|
2260
|
+
ready = null;
|
|
2261
|
+
return out;
|
|
2262
|
+
}
|
|
2272
2263
|
const chunk = read(...args);
|
|
2273
|
-
if (chunk
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2264
|
+
if (chunk === null || chunk === undefined) return chunk;
|
|
2265
|
+
clearTimeout(timer);
|
|
2266
|
+
let text = held + String(chunk);
|
|
2267
|
+
held = '';
|
|
2268
|
+
// Ink asks whether the terminal speaks the protocol; the answer comes by here on its way to Ink.
|
|
2269
|
+
if (/\x1b\[\?\d+u/.test(text)) kitty = true;
|
|
2270
|
+
// The rest of a report whose ESC went on as a key: still the report's, not something typed.
|
|
2271
|
+
if (Date.now() - bare < FOCUS_LATE_MS && /^\[[IO]/.test(text)) {
|
|
2272
|
+
front.now = text[1] === 'I';
|
|
2273
|
+
text = text.slice(2);
|
|
2277
2274
|
}
|
|
2278
|
-
|
|
2275
|
+
bare = 0;
|
|
2276
|
+
text = text.replace(FOCUS_REPORT, (report) => {
|
|
2277
|
+
front.now = report[2] === 'I';
|
|
2278
|
+
return '';
|
|
2279
|
+
});
|
|
2280
|
+
const tail = /\x1b\[?$/.exec(text);
|
|
2281
|
+
if (tail && (kitty || tail[0] !== '\x1b')) {
|
|
2282
|
+
// Held for its rest; given on as it came if none comes.
|
|
2283
|
+
held = tail[0];
|
|
2284
|
+
text = text.slice(0, tail.index);
|
|
2285
|
+
timer = setTimeout(() => {
|
|
2286
|
+
ready = held;
|
|
2287
|
+
held = '';
|
|
2288
|
+
stdin.emit('readable');
|
|
2289
|
+
}, FOCUS_LATE_MS);
|
|
2290
|
+
timer.unref?.();
|
|
2291
|
+
} else if (tail) bare = Date.now();
|
|
2292
|
+
return text;
|
|
2279
2293
|
};
|
|
2280
2294
|
}
|
|
2281
2295
|
// Plain (`chat.screen plain`), for a screen reader: ASCII marks, no frames, no pictures, and nothing moving.
|