durable-chat 1.0.0 → 1.0.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/README.md +22 -7
- package/dist/tui/app.js +157 -102
- package/dist/tui/composer.js +47 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,16 +16,19 @@ Release process: [docs/RELEASING.md](docs/RELEASING.md).
|
|
|
16
16
|
|
|
17
17
|
Requires Node >= 22.19 (developed on Node 26).
|
|
18
18
|
|
|
19
|
-
Install
|
|
19
|
+
Install from [npm](https://www.npmjs.com/package/durable-chat):
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
npm install
|
|
22
|
+
npm install -g durable-chat
|
|
23
23
|
dchat help
|
|
24
24
|
dchat --provider faux --no-mcp ask "hello" # offline; no model account required
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
Alternatively, install the reviewed archive from the [GitHub release](https://github.com/thorinside/durable-chat/releases):
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install --global https://github.com/thorinside/durable-chat/releases/download/v1.0.0/durable-chat-1.0.0.tgz
|
|
31
|
+
```
|
|
29
32
|
|
|
30
33
|
For a source checkout:
|
|
31
34
|
|
|
@@ -321,6 +324,7 @@ Folders outside home remain absolute. Allow program-controlled titles in your te
|
|
|
321
324
|
| `Alt-S` | steer vs follow-up for the current target (main or job) |
|
|
322
325
|
| `Ctrl-V` | paste an image into the composer (main only) |
|
|
323
326
|
| `Enter` | send, open the selected job, or confirm |
|
|
327
|
+
| `Shift-Enter` | insert a newline in the composer (`Ctrl-J` or `Alt-Enter` fallback) |
|
|
324
328
|
| `j/k`, `g/G`, `PgUp/PgDn` | move selection or scroll |
|
|
325
329
|
| Mouse wheel / trackpad | scroll the pane under the pointer without moving keyboard focus |
|
|
326
330
|
| Cmd-click / Ctrl-click | open transcript links using the terminal's link modifier |
|
|
@@ -346,10 +350,21 @@ Transcript prose supports lightweight Markdown: headings, emphasis, lists, links
|
|
|
346
350
|
blocks, including streaming replies. Tool output stays literal; code blocks use plain styling without
|
|
347
351
|
syntax highlighting. The plain-chat interface is unchanged.
|
|
348
352
|
|
|
349
|
-
The composer
|
|
353
|
+
The multiline composer grows from a dark-grey three-row background and scrolls longer drafts while
|
|
354
|
+
keeping the cursor visible. **Shift-Enter inserts a line break; plain Enter sends.** If your terminal
|
|
355
|
+
does not distinguish Shift-Enter from Enter, use **Ctrl-J** (or Alt-Enter) to insert a newline instead.
|
|
356
|
+
Arrow keys navigate the draft; Backspace/Delete can join lines. Bracketed text pastes keep actual
|
|
357
|
+
line breaks (CRLF and CR normalize to LF) without sending. Large pastes appear as folded paste
|
|
358
|
+
markers; their complete text, not the marker, is sent. Visual wrapping adds no newline characters,
|
|
359
|
+
and text copied without line breaks cannot have its original layout reconstructed.
|
|
350
360
|
Pane headings, the target/status line, and individual jobs have spacer rows; the transcript has a solid
|
|
351
|
-
black background.
|
|
352
|
-
|
|
361
|
+
black background. Tab to jobs, then `j/k` or Up/Down to preview the highlighted job's latest transcript
|
|
362
|
+
and live updates without pressing Enter. `g/G` preview the first/last row. Previewing never changes the
|
|
363
|
+
composer or action target: **Enter pins the job** and focuses its transcript; `Ctrl-T` explicitly toggles
|
|
364
|
+
the target. Tab from jobs to transcript keeps the preview for scrolling; returning to the composer
|
|
365
|
+
restores the pinned target's transcript and keeps your draft. Confirmations still name the pinned target.
|
|
366
|
+
While targeting `main`, newly arriving jobs are highlighted automatically unless you are browsing a
|
|
367
|
+
preview. Returning to `main` selects the newest visible job; manual browsing and pinned targets are
|
|
353
368
|
preserved. A single `Ctrl-C` clears the input or stops waiting as before; a second consecutive press
|
|
354
369
|
within 1.5 seconds requests quit. Typing, navigation, or expiry resets that sequence. Live work still
|
|
355
370
|
gets the floating confirmation; `Ctrl-Q` is no longer a quit shortcut.
|
package/dist/tui/app.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
|
-
import {
|
|
2
|
+
import { matchesKey, stripTerminalSequences, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
3
|
import { getNativeClipboard } from "@earendil-works/pi-tui";
|
|
4
4
|
import { withCancel } from "@earendil-works/chord/context";
|
|
5
5
|
import { selectModel } from "../models.js";
|
|
@@ -9,7 +9,7 @@ import { parseId } from "../commands.js";
|
|
|
9
9
|
import { jobView } from "../format.js";
|
|
10
10
|
import { announceJobStart, compactConversation, createJobInCommit, findJobConversation, jobConversationId, jobCreateOptionsOf, jobRecord, jobInputDraft, normalizeBrief, scanJobs, } from "../jobs.js";
|
|
11
11
|
import { buildJobRows, clampScroll, filterJobs, moveSelection, reconcileJobSelection, targetLabel } from "./state.js";
|
|
12
|
-
import { backgroundLine, bold, dim, fg, padLines, shortenHome, statusText, usageTotals, ACCENT,
|
|
12
|
+
import { backgroundLine, bold, dim, fg, padLines, shortenHome, statusText, usageTotals, ACCENT, COMPOSER_BG, GREEN, MUTED, RED, TEXT, TRANSCRIPT_BG, YELLOW } from "./format.js";
|
|
13
13
|
import { attachmentLabel, createImagePaster, MAX_ATTACHMENTS } from "../images.js";
|
|
14
14
|
import { compactionLimit, contextPercent, formatTokenCount } from "../context-usage.js";
|
|
15
15
|
import { Transcript } from "./transcript.js";
|
|
@@ -17,6 +17,7 @@ import { overlayDialog } from "./dialog.js";
|
|
|
17
17
|
import { JOB_KIND } from "../tasks.js";
|
|
18
18
|
import { TranscriptSelection } from "./selection.js";
|
|
19
19
|
import { openBrowser } from "./browser.js";
|
|
20
|
+
import { Composer, isComposerNewline } from "./composer.js";
|
|
20
21
|
const FLASH_MS = 5000;
|
|
21
22
|
const QUIT_REPEAT_MS = 1500;
|
|
22
23
|
const CHROME_ROWS = 8; // Header + spacer, status spacer + status, three composer rows, and hint.
|
|
@@ -42,11 +43,8 @@ export class Dashboard {
|
|
|
42
43
|
onEditConfig;
|
|
43
44
|
paster;
|
|
44
45
|
attachments = [];
|
|
45
|
-
input
|
|
46
|
-
|
|
47
|
-
placeholder: "type a message or Ctrl-N for a job",
|
|
48
|
-
placeholderStyle: (text) => fg(text, BORDER, { dim: true }),
|
|
49
|
-
});
|
|
46
|
+
input;
|
|
47
|
+
composerHeight = 3;
|
|
50
48
|
state = {
|
|
51
49
|
focus: "composer",
|
|
52
50
|
target: { kind: "main" },
|
|
@@ -66,7 +64,12 @@ export class Dashboard {
|
|
|
66
64
|
scroll = 0;
|
|
67
65
|
jobsScroll;
|
|
68
66
|
contextScroll = 0;
|
|
69
|
-
|
|
67
|
+
/** Display state is independent of the composer/action target while browsing jobs. */
|
|
68
|
+
displayTarget = { kind: "main" };
|
|
69
|
+
displayConversationId;
|
|
70
|
+
previewJobId;
|
|
71
|
+
displayLoad;
|
|
72
|
+
displayCancel;
|
|
70
73
|
lastWidth = 120;
|
|
71
74
|
toast;
|
|
72
75
|
actionLabel;
|
|
@@ -87,7 +90,8 @@ export class Dashboard {
|
|
|
87
90
|
scanning = false;
|
|
88
91
|
scanAgain = false;
|
|
89
92
|
started = false;
|
|
90
|
-
|
|
93
|
+
stopping = false;
|
|
94
|
+
displayVersion = 0;
|
|
91
95
|
quitRequested = false;
|
|
92
96
|
quitArmedAt;
|
|
93
97
|
quitArmTimer;
|
|
@@ -98,6 +102,7 @@ export class Dashboard {
|
|
|
98
102
|
}), (result) => this.flash(result === true ? "copied to clipboard" : typeof result === "string" ? result : "Copy failed", result === true ? "info" : "error"), options.requestRender, options.openUrl ?? ((url) => { void openBrowser(url).catch((error) => this.flash(`Could not open link: ${message(error)}`, "error")); }));
|
|
99
103
|
this.runtime = options.runtime;
|
|
100
104
|
this.rowsOf = options.rows;
|
|
105
|
+
this.input = new Composer(options.rows, options.requestRender);
|
|
101
106
|
this.requestRender = options.requestRender;
|
|
102
107
|
this.onQuit = options.onQuit;
|
|
103
108
|
this.onReboot = options.onReboot;
|
|
@@ -111,6 +116,7 @@ export class Dashboard {
|
|
|
111
116
|
this.main.onUpdate = () => this.renderSoon();
|
|
112
117
|
}
|
|
113
118
|
async start() {
|
|
119
|
+
this.stopping = false;
|
|
114
120
|
await this.main.start(this.runtime.context, this.runtime.config.contextWindow);
|
|
115
121
|
this.current = this.main;
|
|
116
122
|
await this.refreshJobs(true);
|
|
@@ -137,6 +143,9 @@ export class Dashboard {
|
|
|
137
143
|
async stop() {
|
|
138
144
|
this.selection.reset();
|
|
139
145
|
this.started = false;
|
|
146
|
+
this.stopping = true;
|
|
147
|
+
this.displayVersion++;
|
|
148
|
+
this.displayCancel?.();
|
|
140
149
|
this.modelController?.abort();
|
|
141
150
|
this.modelVersion++;
|
|
142
151
|
this.disarmQuit();
|
|
@@ -213,87 +222,124 @@ export class Dashboard {
|
|
|
213
222
|
applyView() {
|
|
214
223
|
const previous = this.visible;
|
|
215
224
|
this.visible = filterJobs(this.rowsAll, this.state.filter, this.state.showFinished);
|
|
216
|
-
|
|
225
|
+
// New arrivals must not move a row the user is currently reading.
|
|
226
|
+
const selectionTarget = this.previewJobId === undefined ? this.state.target : { kind: "job", id: this.previewJobId };
|
|
227
|
+
const selected = reconcileJobSelection(this.visible, previous, selectionTarget, this.state.selectedJobId);
|
|
217
228
|
if (selected !== this.state.selectedJobId)
|
|
218
229
|
this.jobsScroll = undefined;
|
|
219
230
|
this.state.selectedJobId = selected;
|
|
231
|
+
if (this.state.focus === "jobs" || this.previewJobId !== undefined)
|
|
232
|
+
this.previewSelected();
|
|
233
|
+
else if (this.current === undefined)
|
|
234
|
+
void this.showTarget(this.state.target);
|
|
220
235
|
}
|
|
221
|
-
|
|
222
|
-
this.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
236
|
+
previewSelected() {
|
|
237
|
+
this.previewJobId = this.state.selectedJobId;
|
|
238
|
+
void this.showTarget(this.previewJobId === undefined ? this.state.target : { kind: "job", id: this.previewJobId });
|
|
239
|
+
}
|
|
240
|
+
setFocus(focus) {
|
|
241
|
+
this.state.focus = focus;
|
|
242
|
+
this.input.focused = focus === "composer";
|
|
243
|
+
if (focus === "jobs")
|
|
244
|
+
this.previewSelected();
|
|
245
|
+
else if (focus === "composer") {
|
|
246
|
+
this.previewJobId = undefined;
|
|
247
|
+
void this.showTarget(this.state.target);
|
|
227
248
|
}
|
|
228
|
-
|
|
249
|
+
}
|
|
250
|
+
async pinMain() {
|
|
251
|
+
this.previewJobId = undefined;
|
|
229
252
|
this.state.target = { kind: "main" };
|
|
230
253
|
this.state.selectedJobId = reconcileJobSelection(this.visible, [], this.state.target, this.state.selectedJobId);
|
|
231
|
-
this.targetConversationId = undefined;
|
|
232
254
|
this.scroll = 0;
|
|
233
|
-
this.jobsScroll = undefined;
|
|
234
255
|
this.contextScroll = 0;
|
|
235
|
-
this.
|
|
256
|
+
this.jobsScroll = undefined;
|
|
257
|
+
await this.showTarget(this.state.target);
|
|
236
258
|
}
|
|
237
259
|
async pinJob(id) {
|
|
238
|
-
|
|
239
|
-
const row = this.rowsAll.find((item) => item.id === id);
|
|
260
|
+
this.previewJobId = undefined;
|
|
240
261
|
this.state.target = { kind: "job", id };
|
|
262
|
+
this.state.selectedJobId = id;
|
|
241
263
|
this.scroll = 0;
|
|
242
|
-
this.jobsScroll = undefined;
|
|
243
264
|
this.contextScroll = 0;
|
|
244
|
-
this.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
this.
|
|
255
|
-
|
|
256
|
-
return
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
265
|
+
this.jobsScroll = undefined;
|
|
266
|
+
return this.showTarget(this.state.target);
|
|
267
|
+
}
|
|
268
|
+
/** Only the displayed transcript changes here; never the send/action destination. */
|
|
269
|
+
showTarget(target) {
|
|
270
|
+
if (this.stopping)
|
|
271
|
+
return Promise.resolve(false);
|
|
272
|
+
const same = target.kind === this.displayTarget.kind
|
|
273
|
+
&& (target.kind === "main" || (this.displayTarget.kind === "job" && target.id === this.displayTarget.id));
|
|
274
|
+
if (same && this.displayLoad !== undefined)
|
|
275
|
+
return this.displayLoad;
|
|
276
|
+
if (same && this.current !== undefined)
|
|
277
|
+
return Promise.resolve(true);
|
|
278
|
+
const version = ++this.displayVersion;
|
|
279
|
+
this.displayCancel?.();
|
|
280
|
+
const cancellable = target.kind === "job" ? withCancel(this.runtime.context) : undefined;
|
|
281
|
+
this.displayCancel = cancellable?.cancel;
|
|
282
|
+
const context = cancellable?.context ?? this.runtime.context;
|
|
283
|
+
this.displayTarget = target;
|
|
284
|
+
this.displayConversationId = undefined;
|
|
266
285
|
const old = this.current;
|
|
267
|
-
|
|
268
|
-
transcript.onUpdate = () => this.renderSoon();
|
|
269
|
-
try {
|
|
270
|
-
await transcript.start(this.runtime.context, this.runtime.config.contextWindow);
|
|
271
|
-
}
|
|
272
|
-
catch (error) {
|
|
273
|
-
await transcript.stop();
|
|
274
|
-
this.current = undefined;
|
|
275
|
-
this.flash(`could not read the job transcript: ${message(error)}`, "error");
|
|
276
|
-
this.renderSoon();
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
if (version !== this.pinVersion) {
|
|
280
|
-
void transcript.stop();
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
286
|
+
this.current = target.kind === "main" ? this.main : undefined;
|
|
283
287
|
if (old !== undefined && old !== this.main)
|
|
284
288
|
void old.stop();
|
|
285
|
-
this.
|
|
289
|
+
this.selection.reset();
|
|
290
|
+
this.scroll = 0;
|
|
291
|
+
this.contextScroll = 0;
|
|
286
292
|
this.renderSoon();
|
|
287
|
-
|
|
293
|
+
const load = async () => {
|
|
294
|
+
if (target.kind === "main")
|
|
295
|
+
return true;
|
|
296
|
+
let transcript;
|
|
297
|
+
try {
|
|
298
|
+
const row = this.rowsAll.find((item) => item.id === target.id);
|
|
299
|
+
const conversationId = row?.conversationId ?? await jobConversationId(this.runtime.harness, target.id, context);
|
|
300
|
+
if (version !== this.displayVersion)
|
|
301
|
+
return false;
|
|
302
|
+
this.displayConversationId = conversationId;
|
|
303
|
+
if (conversationId === undefined)
|
|
304
|
+
return false; // Retried on job refresh once startup creates it.
|
|
305
|
+
const conversation = await this.runtime.harness.conversation(conversationId, context);
|
|
306
|
+
if (version !== this.displayVersion)
|
|
307
|
+
return false;
|
|
308
|
+
if (conversation === undefined)
|
|
309
|
+
throw new Error(`conversation #${conversationId} is unavailable`);
|
|
310
|
+
transcript = new Transcript(conversation);
|
|
311
|
+
transcript.onUpdate = () => { if (version === this.displayVersion)
|
|
312
|
+
this.renderSoon(); };
|
|
313
|
+
await transcript.start(context, this.runtime.config.contextWindow);
|
|
314
|
+
if (version !== this.displayVersion) {
|
|
315
|
+
await transcript.stop();
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
this.current = transcript;
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
await transcript?.stop();
|
|
323
|
+
if (version === this.displayVersion)
|
|
324
|
+
this.flash(`could not read the job transcript: ${message(error)}`, "error");
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
this.displayLoad = load().finally(() => {
|
|
329
|
+
if (version === this.displayVersion) {
|
|
330
|
+
this.displayLoad = undefined;
|
|
331
|
+
this.renderSoon();
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
return this.displayLoad;
|
|
288
335
|
}
|
|
289
336
|
async openSelected() {
|
|
290
337
|
const id = this.state.selectedJobId;
|
|
291
338
|
if (id === undefined)
|
|
292
339
|
return;
|
|
293
340
|
try {
|
|
294
|
-
if (await this.pinJob(id)) {
|
|
295
|
-
this.
|
|
296
|
-
this.input.focused = false;
|
|
341
|
+
if (await this.pinJob(id) && this.state.focus === "jobs" && this.state.selectedJobId === id && this.state.target.kind === "job" && this.state.target.id === id) {
|
|
342
|
+
this.setFocus("transcript");
|
|
297
343
|
this.renderSoon();
|
|
298
344
|
}
|
|
299
345
|
}
|
|
@@ -336,8 +382,7 @@ export class Dashboard {
|
|
|
336
382
|
beginPrompt(mode) {
|
|
337
383
|
this.state.mode = mode;
|
|
338
384
|
this.input.setValue("");
|
|
339
|
-
this.
|
|
340
|
-
this.input.focused = true;
|
|
385
|
+
this.setFocus("composer");
|
|
341
386
|
this.renderSoon();
|
|
342
387
|
}
|
|
343
388
|
cancelPrompt() {
|
|
@@ -446,7 +491,7 @@ export class Dashboard {
|
|
|
446
491
|
this.runtime.harness.resume();
|
|
447
492
|
await this.refreshJobs();
|
|
448
493
|
await this.pinJob(Number(started.taskId));
|
|
449
|
-
this.
|
|
494
|
+
this.setFocus("transcript");
|
|
450
495
|
this.flash(notifyError === undefined
|
|
451
496
|
? `job #${started.taskId} started`
|
|
452
497
|
: `job #${started.taskId} started; main was not notified: ${notifyError}`, notifyError === undefined ? "info" : "error");
|
|
@@ -536,8 +581,8 @@ export class Dashboard {
|
|
|
536
581
|
await this.runAction(`sending to ${targetLabel(target)}`, async (context) => {
|
|
537
582
|
if (target.kind === "main") {
|
|
538
583
|
const content = attachments.length === 0
|
|
539
|
-
?
|
|
540
|
-
: [...(text.length > 0 ? [{ type: "text", text }] : []), ...attachments.map((image) => ({ type: "image", data: image.data, mimeType: image.mimeType }))];
|
|
584
|
+
? value
|
|
585
|
+
: [...(text.length > 0 ? [{ type: "text", text: value }] : []), ...attachments.map((image) => ({ type: "image", data: image.data, mimeType: image.mimeType }))];
|
|
541
586
|
await this.runtime.root.submit({
|
|
542
587
|
type: "input",
|
|
543
588
|
content,
|
|
@@ -549,7 +594,8 @@ export class Dashboard {
|
|
|
549
594
|
const conversation = await findJobConversation(this.runtime.harness, target.id, context);
|
|
550
595
|
if (conversation === undefined)
|
|
551
596
|
throw new Error(`job #${target.id} has no conversation`);
|
|
552
|
-
|
|
597
|
+
// Validate job input as before, but retain the composed whitespace verbatim.
|
|
598
|
+
await conversation.submit({ ...jobInputDraft(value, this.state.steer), content: value }, context);
|
|
553
599
|
this.flash(this.state.steer ? `steered job #${target.id}` : `sent to job #${target.id}`);
|
|
554
600
|
});
|
|
555
601
|
}
|
|
@@ -657,7 +703,7 @@ export class Dashboard {
|
|
|
657
703
|
return;
|
|
658
704
|
case "tasks":
|
|
659
705
|
await this.refreshJobs();
|
|
660
|
-
this.
|
|
706
|
+
this.setFocus(this.lastWidth >= 64 ? "jobs" : "transcript");
|
|
661
707
|
if (this.lastWidth < 64)
|
|
662
708
|
this.flash(`${this.visible.length} jobs: ${this.visible.map((row) => `#${row.id}`).join(", ") || "none"}`);
|
|
663
709
|
return;
|
|
@@ -670,7 +716,7 @@ export class Dashboard {
|
|
|
670
716
|
throw new Error(`No job #${id}.`);
|
|
671
717
|
if (!(await this.pinJob(id)))
|
|
672
718
|
return;
|
|
673
|
-
this.
|
|
719
|
+
this.setFocus("transcript");
|
|
674
720
|
if (command === "cancel")
|
|
675
721
|
this.requestCancel();
|
|
676
722
|
return;
|
|
@@ -861,8 +907,7 @@ export class Dashboard {
|
|
|
861
907
|
this.pendingResetHandoff = undefined;
|
|
862
908
|
this.state.mode = "reset";
|
|
863
909
|
this.input.setValue("");
|
|
864
|
-
this.
|
|
865
|
-
this.input.focused = true;
|
|
910
|
+
this.setFocus("composer");
|
|
866
911
|
this.renderSoon();
|
|
867
912
|
}
|
|
868
913
|
requestAbortMain() {
|
|
@@ -899,7 +944,7 @@ export class Dashboard {
|
|
|
899
944
|
return Math.max(1, this.bodyHeight() - PANE_HEADING_ROWS);
|
|
900
945
|
}
|
|
901
946
|
bodyHeight() {
|
|
902
|
-
return Math.max(3, Math.max(MIN_ROWS, Math.round(this.rowsOf())) - CHROME_ROWS);
|
|
947
|
+
return Math.max(3, Math.max(MIN_ROWS, Math.round(this.rowsOf())) - CHROME_ROWS - (this.composerHeight - 3));
|
|
903
948
|
}
|
|
904
949
|
/** Shared by rendering, transcript wrapping and pointer hit testing after pane resizes. */
|
|
905
950
|
paneWidths(width) {
|
|
@@ -934,7 +979,7 @@ export class Dashboard {
|
|
|
934
979
|
return width >= 110 ? Math.max(26, Math.min(36, Math.round(width * 0.23))) : 0;
|
|
935
980
|
}
|
|
936
981
|
copy() {
|
|
937
|
-
const target = this.
|
|
982
|
+
const target = this.displayTarget;
|
|
938
983
|
let text = "";
|
|
939
984
|
if (target.kind === "job") {
|
|
940
985
|
const record = this.records.get(target.id);
|
|
@@ -963,6 +1008,8 @@ export class Dashboard {
|
|
|
963
1008
|
render(width) {
|
|
964
1009
|
this.lastWidth = width;
|
|
965
1010
|
const height = Math.max(MIN_ROWS, Math.round(this.rowsOf()));
|
|
1011
|
+
const composer = this.renderComposer(width);
|
|
1012
|
+
this.composerHeight = composer.length;
|
|
966
1013
|
const bodyHeight = this.bodyHeight();
|
|
967
1014
|
if (this.state.mode !== "chat")
|
|
968
1015
|
this.selection.update();
|
|
@@ -991,7 +1038,7 @@ export class Dashboard {
|
|
|
991
1038
|
...padLines(body, bodyHeight, width),
|
|
992
1039
|
" ".repeat(width),
|
|
993
1040
|
this.renderStatus(width),
|
|
994
|
-
...
|
|
1041
|
+
...composer,
|
|
995
1042
|
this.renderHint(width),
|
|
996
1043
|
].slice(0, height);
|
|
997
1044
|
if (this.state.mode === "confirmRollback")
|
|
@@ -1061,14 +1108,14 @@ export class Dashboard {
|
|
|
1061
1108
|
return [...lines, ...content.slice(start, start + Math.max(1, height - PANE_HEADING_ROWS))];
|
|
1062
1109
|
}
|
|
1063
1110
|
renderTranscript(width, height) {
|
|
1064
|
-
const target = targetLabel(this.
|
|
1111
|
+
const target = `${targetLabel(this.displayTarget)}${this.previewJobId === undefined ? "" : " (preview)"}`;
|
|
1065
1112
|
const live = this.current?.live;
|
|
1066
1113
|
const active = live?.generation !== undefined || live?.tools?.some((slot) => slot.status === "running") === true;
|
|
1067
1114
|
const title = `${bold("TRANSCRIPT")} ${dim(target)}${active ? fg(" ● live", GREEN) : ""}${this.scroll > 0 ? dim(` ↑${this.scroll}`) : ""}`;
|
|
1068
1115
|
const lines = [truncateToWidth(title, width, "", true), ""];
|
|
1069
1116
|
const transcript = this.current;
|
|
1070
1117
|
if (transcript === undefined) {
|
|
1071
|
-
lines.push(dim(" No conversation is available for this job yet."));
|
|
1118
|
+
lines.push(dim(this.displayLoad === undefined ? " No conversation is available for this job yet." : " Loading job transcript…"));
|
|
1072
1119
|
return lines;
|
|
1073
1120
|
}
|
|
1074
1121
|
const contentHeight = Math.max(1, height - PANE_HEADING_ROWS);
|
|
@@ -1091,16 +1138,18 @@ export class Dashboard {
|
|
|
1091
1138
|
return [truncateToWidth(bold("CONTEXT"), width, "", true), "", ...content.slice(this.contextScroll, this.contextScroll + viewport)];
|
|
1092
1139
|
}
|
|
1093
1140
|
contextLines(width) {
|
|
1094
|
-
const target = this.
|
|
1141
|
+
const target = this.displayTarget;
|
|
1095
1142
|
const transcript = this.current;
|
|
1096
1143
|
const usage = usageTotals(transcript?.usage);
|
|
1097
1144
|
const live = transcript?.live;
|
|
1098
1145
|
const rows = [];
|
|
1099
|
-
rows.push(["target", targetLabel(target)]);
|
|
1146
|
+
rows.push(["target", targetLabel(this.state.target)]);
|
|
1147
|
+
if (this.previewJobId !== undefined)
|
|
1148
|
+
rows.push(["preview", targetLabel(target)]);
|
|
1100
1149
|
if (target.kind === "job") {
|
|
1101
1150
|
const row = this.rowsAll.find((item) => item.id === target.id);
|
|
1102
1151
|
rows.push(["status", row?.status ?? "unknown"]);
|
|
1103
|
-
const conversation = this.
|
|
1152
|
+
const conversation = this.displayConversationId ?? row?.conversationId;
|
|
1104
1153
|
rows.push(["conversation", conversation === undefined ? "…" : `#${conversation}`]);
|
|
1105
1154
|
rows.push(["brief", row?.brief ?? "(unknown)"]);
|
|
1106
1155
|
if (row?.tags?.length)
|
|
@@ -1155,9 +1204,8 @@ export class Dashboard {
|
|
|
1155
1204
|
const focus = dim(`focus ${this.state.focus}`);
|
|
1156
1205
|
const contextTokens = this.current?.contextTokens;
|
|
1157
1206
|
const window = this.runtime.config.contextWindow;
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1160
|
-
: `ctx ~${formatTokenCount(contextTokens)}/${formatTokenCount(window)}`;
|
|
1207
|
+
const meter = contextTokens === undefined ? "ctx …" : `ctx ~${formatTokenCount(contextTokens)}/${formatTokenCount(window)}`;
|
|
1208
|
+
const context = this.previewJobId === undefined ? meter : `preview ${meter}`;
|
|
1161
1209
|
const line = ` ${dim("target")} ${bold(target)} ${focus} ${dim(context)}${activity}`;
|
|
1162
1210
|
return truncateToWidth(line, width, "", true);
|
|
1163
1211
|
}
|
|
@@ -1185,17 +1233,19 @@ export class Dashboard {
|
|
|
1185
1233
|
}
|
|
1186
1234
|
}
|
|
1187
1235
|
renderComposer(width) {
|
|
1188
|
-
const prefix = ` ${this.composerPrefix()}
|
|
1236
|
+
const prefix = truncateToWidth(` ${this.composerPrefix()}`, Math.max(0, width - 3), "");
|
|
1189
1237
|
const active = this.state.focus === "composer"
|
|
1190
1238
|
&& this.state.mode !== "help"
|
|
1191
1239
|
&& this.state.mode !== "inspector"
|
|
1192
1240
|
&& !this.state.mode.startsWith("confirm");
|
|
1193
1241
|
this.input.focused = active;
|
|
1194
1242
|
const inner = Math.max(1, width - visibleWidth(prefix) - 1);
|
|
1195
|
-
const
|
|
1196
|
-
const
|
|
1197
|
-
|
|
1198
|
-
|
|
1243
|
+
const maxContentRows = Math.max(1, Math.max(MIN_ROWS, Math.round(this.rowsOf())) - CHROME_ROWS - PANE_HEADING_ROWS);
|
|
1244
|
+
const rendered = this.input.render(inner, maxContentRows);
|
|
1245
|
+
return rendered.map((line, index) => {
|
|
1246
|
+
const label = index === 1 ? fg(prefix, active ? ACCENT : MUTED) : " ".repeat(visibleWidth(prefix));
|
|
1247
|
+
return backgroundLine(`${label}${line}`, width, COMPOSER_BG);
|
|
1248
|
+
});
|
|
1199
1249
|
}
|
|
1200
1250
|
renderHint(width) {
|
|
1201
1251
|
let hint;
|
|
@@ -1219,7 +1269,7 @@ export class Dashboard {
|
|
|
1219
1269
|
else if (this.actionLabel !== undefined)
|
|
1220
1270
|
hint = shortcut("CTRL-C", "stop waiting (work stays durable)");
|
|
1221
1271
|
else if (this.state.focus === "composer")
|
|
1222
|
-
hint = [shortcut("ENTER", "send"), shortcut("CTRL-C ×2", "quit"), shortcut("TAB", "jobs"), shortcut("CTRL-T", "target"), shortcut("CTRL-N", "new job"), shortcut("CTRL-V", "paste image"), ...(this.attachments.length === 0 ? [] : [fg(`${this.attachments.length} attached`, YELLOW)])].join(separator);
|
|
1272
|
+
hint = [shortcut("ENTER", "send"), shortcut("SHIFT-ENTER", "newline"), shortcut("CTRL-C ×2", "quit"), shortcut("TAB", "jobs"), shortcut("CTRL-T", "target"), shortcut("CTRL-N", "new job"), shortcut("CTRL-V", "paste image"), ...(this.attachments.length === 0 ? [] : [fg(`${this.attachments.length} attached`, YELLOW)])].join(separator);
|
|
1223
1273
|
else if (this.state.focus === "jobs")
|
|
1224
1274
|
hint = [shortcut("J/K", "select"), shortcut("ENTER", "open"), shortcut("N", "new"), shortcut("C", "cancel"), shortcut("M/SHIFT-R", "compact/reset"), shortcut("I", "info"), shortcut("TAB", "focus")].join(separator);
|
|
1225
1275
|
else
|
|
@@ -1233,6 +1283,7 @@ export class Dashboard {
|
|
|
1233
1283
|
["TAB / SHIFT-TAB", "cycle composer, jobs, transcript"],
|
|
1234
1284
|
["CTRL-T", "target main ↔ selected job"],
|
|
1235
1285
|
["CTRL-N", "new job brief"],
|
|
1286
|
+
["SHIFT-ENTER", "insert a newline (Ctrl-J or Alt-Enter fallback); Enter sends"],
|
|
1236
1287
|
["ALT-S", "steer vs follow-up for the target"],
|
|
1237
1288
|
["CTRL-V", "paste an image into the composer (main only)"],
|
|
1238
1289
|
["ENTER", "send, open job, or confirm prompt"],
|
|
@@ -1285,7 +1336,7 @@ export class Dashboard {
|
|
|
1285
1336
|
`live jobs: ${this.rowsAll.filter((row) => row.live).length}`,
|
|
1286
1337
|
`context: ~${formatTokenCount(this.current?.contextTokens ?? 0)} / ${formatTokenCount(this.runtime.config.contextWindow)} ` +
|
|
1287
1338
|
`(compact at ~${formatTokenCount(compactionLimit(this.runtime.config.contextWindow))})`,
|
|
1288
|
-
|
|
1339
|
+
`${this.previewJobId === undefined ? "target" : "preview"} spend: ${formatTokenCount(usage.tokens)} tokens${usage.cost > 0 ? `, $${usage.cost.toFixed(4)}` : ""}`,
|
|
1289
1340
|
`job tools: ${this.runtime.jobExtensions.flatMap((extension) => extension.tools?.map((tool) => tool.name) ?? []).join(", ") || "(none)"}`,
|
|
1290
1341
|
...this.runtime.mcpNotes.slice(0, 8).map((note) => `mcp: ${note}`),
|
|
1291
1342
|
"",
|
|
@@ -1330,10 +1381,7 @@ export class Dashboard {
|
|
|
1330
1381
|
cycleFocus(backwards) {
|
|
1331
1382
|
const order = this.lastWidth < 64 ? ["composer", "transcript"] : ["composer", "jobs", "transcript"];
|
|
1332
1383
|
const index = Math.max(0, order.indexOf(this.state.focus));
|
|
1333
|
-
this.
|
|
1334
|
-
this.input.focused = this.state.focus === "composer";
|
|
1335
|
-
if (this.state.focus === "jobs" && this.state.selectedJobId === undefined)
|
|
1336
|
-
this.state.selectedJobId = this.visible[0]?.id;
|
|
1384
|
+
this.setFocus(order[(index + (backwards ? order.length - 1 : 1)) % order.length]);
|
|
1337
1385
|
this.renderSoon();
|
|
1338
1386
|
}
|
|
1339
1387
|
handleMouse(event) {
|
|
@@ -1406,6 +1454,11 @@ export class Dashboard {
|
|
|
1406
1454
|
this.cancelPrompt();
|
|
1407
1455
|
return;
|
|
1408
1456
|
}
|
|
1457
|
+
if ((this.state.focus === "composer" || this.state.mode !== "chat") && isComposerNewline(data)) {
|
|
1458
|
+
this.input.handleInput("\n");
|
|
1459
|
+
this.renderSoon();
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1409
1462
|
if (this.state.mode === "model") {
|
|
1410
1463
|
if (matchesKey(data, "escape"))
|
|
1411
1464
|
this.cancelPrompt();
|
|
@@ -1493,8 +1546,7 @@ export class Dashboard {
|
|
|
1493
1546
|
if (matchesKey(data, "escape")) {
|
|
1494
1547
|
if (this.state.target.kind === "job")
|
|
1495
1548
|
void this.pinMain();
|
|
1496
|
-
this.
|
|
1497
|
-
this.input.focused = true;
|
|
1549
|
+
this.setFocus("composer");
|
|
1498
1550
|
this.renderSoon();
|
|
1499
1551
|
return;
|
|
1500
1552
|
}
|
|
@@ -1502,21 +1554,25 @@ export class Dashboard {
|
|
|
1502
1554
|
this.jobsScroll = undefined;
|
|
1503
1555
|
if (matchesKey(data, "down") || data === "j") {
|
|
1504
1556
|
this.state.selectedJobId = moveSelection(this.visible, this.state.selectedJobId, 1);
|
|
1557
|
+
this.previewSelected();
|
|
1505
1558
|
this.renderSoon();
|
|
1506
1559
|
return;
|
|
1507
1560
|
}
|
|
1508
1561
|
if (matchesKey(data, "up") || data === "k") {
|
|
1509
1562
|
this.state.selectedJobId = moveSelection(this.visible, this.state.selectedJobId, -1);
|
|
1563
|
+
this.previewSelected();
|
|
1510
1564
|
this.renderSoon();
|
|
1511
1565
|
return;
|
|
1512
1566
|
}
|
|
1513
1567
|
if (data === "g") {
|
|
1514
1568
|
this.state.selectedJobId = this.visible[0]?.id;
|
|
1569
|
+
this.previewSelected();
|
|
1515
1570
|
this.renderSoon();
|
|
1516
1571
|
return;
|
|
1517
1572
|
}
|
|
1518
1573
|
if (data === "G") {
|
|
1519
1574
|
this.state.selectedJobId = this.visible.at(-1)?.id;
|
|
1575
|
+
this.previewSelected();
|
|
1520
1576
|
this.renderSoon();
|
|
1521
1577
|
return;
|
|
1522
1578
|
}
|
|
@@ -1595,8 +1651,7 @@ export class Dashboard {
|
|
|
1595
1651
|
return;
|
|
1596
1652
|
}
|
|
1597
1653
|
if (data === "s") {
|
|
1598
|
-
this.
|
|
1599
|
-
this.input.focused = true;
|
|
1654
|
+
this.setFocus("composer");
|
|
1600
1655
|
this.renderSoon();
|
|
1601
1656
|
return;
|
|
1602
1657
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CURSOR_MARKER, Editor, matchesKey } from "@earendil-works/pi-tui";
|
|
2
|
+
import { dim } from "./format.js";
|
|
3
|
+
/** Newline gestures must be checked before Enter: legacy Ctrl-J also matches Enter. */
|
|
4
|
+
export function isComposerNewline(data) {
|
|
5
|
+
return matchesKey(data, "ctrl+j") || matchesKey(data, "shift+enter")
|
|
6
|
+
|| matchesKey(data, "alt+enter") || data === "\x1b\r" || data === "\x1b[13;2~";
|
|
7
|
+
}
|
|
8
|
+
/** Toolkit editing/paste/undo semantics, embedded in the dashboard's own layout. */
|
|
9
|
+
export class Composer extends Editor {
|
|
10
|
+
constructor(rows, requestRender) {
|
|
11
|
+
// Editor only uses these two host services (no terminal IO or overlays).
|
|
12
|
+
// The dashboard, rather than a second TUI renderer, owns focus and layout.
|
|
13
|
+
const host = { terminal: { get rows() { return rows(); } }, requestRender };
|
|
14
|
+
super(host, {
|
|
15
|
+
borderColor: dim,
|
|
16
|
+
selectList: { selectedPrefix: dim, selectedText: dim, description: dim, scrollInfo: dim, noMatch: dim },
|
|
17
|
+
});
|
|
18
|
+
// Dashboard owns submission/validation, including preserving outer newlines.
|
|
19
|
+
this.disableSubmit = true;
|
|
20
|
+
}
|
|
21
|
+
getValue() { return this.getExpandedText(); }
|
|
22
|
+
setValue(value) { this.setText(value); }
|
|
23
|
+
renderTopBorder(width, hidden) {
|
|
24
|
+
return hidden > 0 ? super.renderTopBorder(width, hidden) : "";
|
|
25
|
+
}
|
|
26
|
+
renderBottomBorder(width, hidden) {
|
|
27
|
+
return hidden > 0 ? super.renderBottomBorder(width, hidden) : "";
|
|
28
|
+
}
|
|
29
|
+
render(width, maxContentRows = Number.POSITIVE_INFINITY) {
|
|
30
|
+
// The toolkit scrolls at 30% of terminal height but has a five-line minimum.
|
|
31
|
+
// On short terminals crop that viewport around the cursor so panes still fit.
|
|
32
|
+
const focused = this.focused;
|
|
33
|
+
this.focused = true;
|
|
34
|
+
const lines = super.render(width);
|
|
35
|
+
this.focused = focused;
|
|
36
|
+
const content = lines.slice(1, -1);
|
|
37
|
+
const count = Math.max(1, Math.min(content.length, maxContentRows));
|
|
38
|
+
const cursor = Math.max(0, content.findIndex((line) => line.includes(CURSOR_MARKER)));
|
|
39
|
+
const start = Math.max(0, Math.min(cursor - count + 1, content.length - count));
|
|
40
|
+
const result = [
|
|
41
|
+
start > 0 ? super.renderTopBorder(width, start) : lines[0],
|
|
42
|
+
...content.slice(start, start + count),
|
|
43
|
+
start + count < content.length ? super.renderBottomBorder(width, content.length - start - count) : lines.at(-1),
|
|
44
|
+
];
|
|
45
|
+
return focused ? result : result.map((line) => line.replaceAll(CURSOR_MARKER, ""));
|
|
46
|
+
}
|
|
47
|
+
}
|
package/package.json
CHANGED