durable-chat 1.0.1 → 1.0.2
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 +77 -14
- package/dist/config.js +10 -1
- package/dist/jobs.js +34 -1
- package/dist/tool.js +5 -27
- package/dist/tui/app.js +147 -73
- package/dist/tui/clipboard.js +78 -0
- package/dist/tui/composer.js +6 -0
- package/dist/tui/format.js +40 -16
- package/dist/tui/markdown-copy.js +97 -0
- package/dist/tui/selection.js +44 -4
- package/dist/tui/transcript.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -290,6 +290,24 @@ the summary placement. A short conversation, or one with no selectable old prefi
|
|
|
290
290
|
The default interface is a three-pane dashboard: jobs on the left, the selected conversation in the
|
|
291
291
|
middle, and live context on the right. The composer sends to `main` by default; open a job to target it.
|
|
292
292
|
|
|
293
|
+
**Ctrl-X** toggles the context pane from any dashboard focus; `/context [on|off|toggle]` does the same
|
|
294
|
+
from the composer (for example, `/context off` hides it). Ctrl-X works with legacy control-byte,
|
|
295
|
+
CSI-u/Kitty, and xterm modifyOtherKeys input without changing macOS Option-key settings. Option-C
|
|
296
|
+
continues to type `ç` when the terminal sends it as text. Alt-C remains an optional alias only in
|
|
297
|
+
terminals sending literal `ESC c` (Meta-C).
|
|
298
|
+
|
|
299
|
+
The choice is saved as `contextPanel: true|false` using the same targeted YAML editor as
|
|
300
|
+
`dchat config set contextPanel false`: it edits the active config (folder-local if present, otherwise
|
|
301
|
+
`$XDG_CONFIG_HOME/durable-chat/config.yaml` or `~/.config/durable-chat/config.yaml`; `.yml` discovery is
|
|
302
|
+
also supported). With `--config` or `DURABLE_CHAT_CONFIG`, only that standalone file is edited. Local
|
|
303
|
+
values override global values; an explicit file stands alone. No conversation state or credential files
|
|
304
|
+
are touched. If saving fails, the preference stays unchanged and an error is shown.
|
|
305
|
+
|
|
306
|
+
Enabled (the default) means “show when there is room”: at least **140 terminal columns**, with at least
|
|
307
|
+
**80 transcript columns** and **26 context columns** after the jobs pane and separators. Manual pane
|
|
308
|
+
resizing obeys those limits too. Narrow-window hiding never changes the saved choice; an explicitly
|
|
309
|
+
hidden pane stays hidden across resizing and restarts. `0` resets widths only, not visibility.
|
|
310
|
+
|
|
293
311
|
The mouse wheel, Magic Mouse and trackpad scroll the pane under the pointer, keeping keyboard focus,
|
|
294
312
|
the composer draft and the selected job unchanged. Pane headings stay fixed; keyboard job navigation
|
|
295
313
|
brings the selection back into view. Alt+wheel scrolls faster.
|
|
@@ -298,6 +316,23 @@ Command-click transcript URLs on macOS (Ctrl-click in terminals that use that mo
|
|
|
298
316
|
in the default browser. Markdown links and bare URLs keep their complete destinations when wrapped.
|
|
299
317
|
Clicks routed to the app also open web links; dragging across a link still selects text.
|
|
300
318
|
|
|
319
|
+
Drag in the transcript to copy selected text; double-click copies a word, triple-click a line.
|
|
320
|
+
Selection stays inside the transcript and excludes blank speaker gutters and right-side cell fill,
|
|
321
|
+
while preserving code indentation, internal spaces and selected line breaks. Visible speaker labels
|
|
322
|
+
are included when selected. Code blocks use source indentation without an extra decorative indent.
|
|
323
|
+
This copies rendered lines, not byte-for-byte Markdown; `y` outside the composer copies the full
|
|
324
|
+
answer instead. On local macOS (Apple Terminal, Ghostty, or tmux), both paths use the native clipboard
|
|
325
|
+
writer, with `/usr/bin/pbcopy` as fallback. The highlight clears only after a successful local write.
|
|
326
|
+
|
|
327
|
+
Over SSH, dchat never writes the remote Mac's clipboard. Other hosts and remote sessions use OSC 52,
|
|
328
|
+
which depends on terminal clipboard permissions and, in tmux, passthrough configuration. Sending an
|
|
329
|
+
escape sequence does **not** confirm delivery: dchat reports it as unconfirmed and retains selection.
|
|
330
|
+
Apple Terminal does not support OSC 52. As a native-selection workaround, toggle **Allow Mouse
|
|
331
|
+
Reporting** with **Command-R**, select text, copy with **Command-C**, then restore mouse reporting.
|
|
332
|
+
Apple documents **Option-drag** as rectangular selection, not ordinary linear selection. Native
|
|
333
|
+
selection copies screen cells and may include pane padding. See [copy verification](docs/transcript-copy.md)
|
|
334
|
+
for limitations and opt-in manual checks.
|
|
335
|
+
|
|
301
336
|
The terminal title includes the launch folder, for example `durable-chat — ~/projects/example`.
|
|
302
337
|
The previous title is restored on startup failure or exit using the terminal's title stack.
|
|
303
338
|
Folders outside home remain absolute. Allow program-controlled titles in your terminal; Ghostty's
|
|
@@ -312,7 +347,7 @@ Folders outside home remain absolute. Allow program-controlled titles in your te
|
|
|
312
347
|
│ #10 failed │ │ tokens: 18.2k │
|
|
313
348
|
├──────────────────────┴───────────────────────────────┴──────────────────────┤
|
|
314
349
|
│ to main › _ │
|
|
315
|
-
│ ENTER send ·
|
|
350
|
+
│ ENTER send · ? help · TAB focus · SHIFT-ENTER newline │
|
|
316
351
|
└──────────────────────────────────────────────────────────────────────────────┘
|
|
317
352
|
```
|
|
318
353
|
|
|
@@ -321,25 +356,30 @@ Folders outside home remain absolute. Allow program-controlled titles in your te
|
|
|
321
356
|
| `Tab` / `Shift-Tab` | cycle composer → jobs → transcript |
|
|
322
357
|
| `Ctrl-T` | switch composer target main ↔ selected job |
|
|
323
358
|
| `Ctrl-N` | new job brief |
|
|
324
|
-
| `
|
|
359
|
+
| `Ctrl-X` | toggle context pane; saved in the active config (`Alt-C` alias for literal `ESC c` input) |
|
|
360
|
+
| `Command-Shift-Enter` | queue one follow-up from the composer, if the terminal reports it (`/send <id> <message>` fallback) |
|
|
325
361
|
| `Ctrl-V` | paste an image into the composer (main only) |
|
|
326
|
-
| `Enter` | send,
|
|
362
|
+
| `Enter` | send, or pin the highlighted job and focus the composer; confirm prompts |
|
|
327
363
|
| `Shift-Enter` | insert a newline in the composer (`Ctrl-J` or `Alt-Enter` fallback) |
|
|
328
|
-
| `j/k`, `g/G`, `PgUp/PgDn` | move selection or scroll |
|
|
364
|
+
| `↑/↓` or `j/k`, `g/G`, `PgUp/PgDn` | move selection or scroll outside the composer |
|
|
329
365
|
| Mouse wheel / trackpad | scroll the pane under the pointer without moving keyboard focus |
|
|
330
366
|
| Cmd-click / Ctrl-click | open transcript links using the terminal's link modifier |
|
|
331
367
|
| `n / c / m / R` | new job · cancel · compact · reset (selected target) |
|
|
332
|
-
| `s / t / f / y` |
|
|
368
|
+
| `s / t / f / y` | compose (jobs: pin highlighted job) · expand tools · show finished · copy |
|
|
333
369
|
| `/` | start a slash command in the composer; filter jobs when focus is on jobs/transcript |
|
|
334
370
|
| `[` / `]` | shrink / grow the jobs pane |
|
|
335
|
-
| `{` / `}` | shrink / grow the context pane (
|
|
371
|
+
| `{` / `}` | shrink / grow the context pane when there is room (does not enable a hidden pane) |
|
|
336
372
|
| `0` | reset pane widths |
|
|
337
373
|
| `i` | inspector (config, MCP notes, usage); `e` edits the config |
|
|
338
374
|
| `a` | abort the main run (jobs survive) |
|
|
339
|
-
| `?` | help |
|
|
375
|
+
| `?` | full help outside the composer or with an empty draft; `Tab` then `?` preserves a draft |
|
|
340
376
|
| `Ctrl-C` | stop waiting / clear the prompt / close an overlay; arms quitting for 1.5 seconds |
|
|
341
377
|
| `Ctrl-C` twice | quit; small floating confirmation over the dashboard while live work exists |
|
|
342
378
|
|
|
379
|
+
The footer shows primary actions for the focused pane and a route to full help, not the entire keymap.
|
|
380
|
+
With a draft, **Tab then ?** opens help without changing the text; **/help** also opens it from the
|
|
381
|
+
composer. Context visibility and less-common shortcuts are listed in full help and the table above.
|
|
382
|
+
|
|
343
383
|
`Ctrl-V` attaches an image to the next message to main. It reads the native clipboard (macOS and
|
|
344
384
|
Windows prebuilds, Linux with X11); `/image <path>` is the fallback where that helper is unavailable.
|
|
345
385
|
Images are prepared with Photon on a worker thread to the model's image limits, and paste is refused
|
|
@@ -358,11 +398,13 @@ line breaks (CRLF and CR normalize to LF) without sending. Large pastes appear a
|
|
|
358
398
|
markers; their complete text, not the marker, is sent. Visual wrapping adds no newline characters,
|
|
359
399
|
and text copied without line breaks cannot have its original layout reconstructed.
|
|
360
400
|
Pane headings, the target/status line, and individual jobs have spacer rows; the transcript has a solid
|
|
361
|
-
black background. Tab to jobs, then `j/k`
|
|
401
|
+
black background. Tab to jobs, then Up/Down (or `j/k`) to preview the highlighted job's latest transcript
|
|
362
402
|
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
|
|
364
|
-
|
|
365
|
-
|
|
403
|
+
composer or action target: **Enter pins the job and focuses the composer**, ready to type immediately.
|
|
404
|
+
It preserves the draft and attachments without submitting them. `s` in jobs does the same; `Ctrl-T`
|
|
405
|
+
explicitly toggles the target. Tab from jobs to transcript keeps the preview for scrolling; returning to
|
|
406
|
+
the composer restores the pinned target's transcript and keeps your draft. `Shift-Tab` from the composer goes straight
|
|
407
|
+
to transcript scrolling (`↑/↓` or `j/k`). Confirmations still name the pinned target.
|
|
366
408
|
While targeting `main`, newly arriving jobs are highlighted automatically unless you are browsing a
|
|
367
409
|
preview. Returning to `main` selects the newest visible job; manual browsing and pinned targets are
|
|
368
410
|
preserved. A single `Ctrl-C` clears the input or stops waiting as before; a second consecutive press
|
|
@@ -378,9 +420,29 @@ Jobs run in the background and main stays usable. The TUI is the single store wr
|
|
|
378
420
|
jobs, and the next run resumes them. `durable-chat --plain` or `durable-chat chat` is the old
|
|
379
421
|
line-oriented interface over the same runtime.
|
|
380
422
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
423
|
+
**Messages to live jobs default to steering.** Tab to jobs, select with ↑/↓ (or j/k), press Enter,
|
|
424
|
+
then type and Enter to submit. A `(steer)` badge identifies the mode. Admission returns immediately:
|
|
425
|
+
native steering queues at the next supported boundary (for example, after the executing tool round),
|
|
426
|
+
without aborting a tool or starting a concurrent turn. It cannot change a model request already in flight.
|
|
427
|
+
The job stays live through its steering response, using the same durable admission/tracking as Main's
|
|
428
|
+
`task` steer action; a "steering queued" notice is not a delivery or completion claim.
|
|
429
|
+
|
|
430
|
+
**Command-Shift-Enter** queues a one-shot follow-up instead: it waits until the current run ends,
|
|
431
|
+
preserving queued message order. The next plain Enter still steers a running job; there is no sticky
|
|
432
|
+
input-mode toggle. Main Enter still sends follow-up, and completed job conversations default to
|
|
433
|
+
follow-up/continuation. Explicit steering of an idle, finished, or finishing job is refused and leaves
|
|
434
|
+
the draft intact. A just-starting job without an active run may also refuse steering; retry once it is
|
|
435
|
+
running. Images remain Main-only and are retained if a job send is refused. Failed admissions retain
|
|
436
|
+
text for correction/retry.
|
|
437
|
+
|
|
438
|
+
The shortcut requires the terminal to transmit Command as Super plus Shift in CSI-u/Kitty input.
|
|
439
|
+
macOS or terminal key bindings may intercept it; legacy input cannot distinguish it, and xterm
|
|
440
|
+
modifyOtherKeys has no distinct Super modifier. dchat does not change terminal settings or infer
|
|
441
|
+
Command from ordinary Enter. Use `/send` below when the gesture is unavailable. Shift-Enter remains
|
|
442
|
+
newline; Option-S (`ß`) remains text. Alt-S no longer toggles an input mode.
|
|
443
|
+
|
|
444
|
+
`/send <id> <message>` explicitly queues follow-up; `/steer <id> <message>` explicitly requests
|
|
445
|
+
steering without changing the pinned target. The CLI equivalent is `task send <id> "<message>" --steer`.
|
|
384
446
|
|
|
385
447
|
Starting a job from the TUI or `task add` writes a native, model-visible `[host]` start notice into
|
|
386
448
|
main's conversation. Every job reports completion, failure, or abort as a native follow-up input by
|
|
@@ -445,6 +507,7 @@ Inside the plain chat or TUI composer:
|
|
|
445
507
|
/model [id] pick the session-wide model, across configured providers
|
|
446
508
|
/provider [name] list configured providers, or make one active for this session
|
|
447
509
|
/thinking [level] session thinking level for main and jobs; the config file decides the next run
|
|
510
|
+
/context [on|off|toggle] TUI only: show/hide context when there is room; saved in the active config
|
|
448
511
|
/image <path> attach an image to the next message to main
|
|
449
512
|
/reboot archive all app state and start a fresh database (confirmation required)
|
|
450
513
|
/rollback [path] select saved state, archive current state, restore a copy, and relaunch
|
package/dist/config.js
CHANGED
|
@@ -10,7 +10,7 @@ export function parseThinkingLevel(raw) {
|
|
|
10
10
|
}
|
|
11
11
|
const KNOWN_KEYS = new Set([
|
|
12
12
|
"store", "provider", "model", "baseUrl", "apiKeyEnv", "contextWindow", "maxTokens",
|
|
13
|
-
"streamTimeoutMs", "retries", "thinkingLevel", "maxTurns", "jobMaxTurns", "autoContinue", "codemode", "providers", "mcp",
|
|
13
|
+
"streamTimeoutMs", "retries", "thinkingLevel", "maxTurns", "jobMaxTurns", "autoContinue", "codemode", "contextPanel", "providers", "mcp",
|
|
14
14
|
]);
|
|
15
15
|
const KNOWN_MCP_KEYS = new Set(["enabled", "servers", "tools", "config"]);
|
|
16
16
|
const KNOWN_PROVIDER_KEYS = new Set([
|
|
@@ -31,6 +31,7 @@ const BUILTIN = {
|
|
|
31
31
|
jobMaxTurns: 120,
|
|
32
32
|
autoContinue: true,
|
|
33
33
|
codemode: true,
|
|
34
|
+
contextPanel: true,
|
|
34
35
|
};
|
|
35
36
|
function expandHome(value) {
|
|
36
37
|
if (value === "~")
|
|
@@ -168,6 +169,8 @@ function validate(path, raw, warnings) {
|
|
|
168
169
|
config.autoContinue = readBoolean(path, "autoContinue", record.autoContinue);
|
|
169
170
|
if (record.codemode !== undefined)
|
|
170
171
|
config.codemode = readBoolean(path, "codemode", record.codemode);
|
|
172
|
+
if (record.contextPanel !== undefined)
|
|
173
|
+
config.contextPanel = readBoolean(path, "contextPanel", record.contextPanel);
|
|
171
174
|
if (record.providers !== undefined) {
|
|
172
175
|
if (typeof record.providers !== "object" || record.providers === null || Array.isArray(record.providers)) {
|
|
173
176
|
throw new ConfigError(path, "providers", "must be a mapping of provider names to settings");
|
|
@@ -351,6 +354,7 @@ export function resolveConfig(overrides = {}, env = process.env) {
|
|
|
351
354
|
jobMaxTurns,
|
|
352
355
|
autoContinue,
|
|
353
356
|
codemode,
|
|
357
|
+
contextPanel: raw.contextPanel ?? BUILTIN.contextPanel,
|
|
354
358
|
mcp: {
|
|
355
359
|
enabled: mcpEnabled,
|
|
356
360
|
servers: envServers ?? raw.mcp?.servers ?? ["substrate"],
|
|
@@ -376,6 +380,8 @@ jobMaxTurns: 120
|
|
|
376
380
|
autoContinue: true
|
|
377
381
|
# QuickJS scripts that call the conversation's tools; only the script's output comes back.
|
|
378
382
|
codemode: true
|
|
383
|
+
# Ctrl-X toggles this in the dashboard; enabled context still hides when space is limited.
|
|
384
|
+
contextPanel: true
|
|
379
385
|
# More than one provider can be configured. The provider key selects the active entry by name, and
|
|
380
386
|
# each entry inherits the values above for keys it does not set. Entry names are provider ids.
|
|
381
387
|
# providers:
|
|
@@ -427,6 +433,7 @@ export function describeConfig(config) {
|
|
|
427
433
|
`jobMaxTurns: ${config.jobMaxTurns}`,
|
|
428
434
|
`autoContinue: ${config.autoContinue}`,
|
|
429
435
|
`codemode: ${config.codemode ? "enabled" : "disabled"}`,
|
|
436
|
+
`contextPanel: ${config.contextPanel}`,
|
|
430
437
|
`apiKey: ${config.apiKey === undefined ? "(none)" : config.apiKeyEnv === undefined ? "(set)" : `from ${config.apiKeyEnv}`}`,
|
|
431
438
|
`mcp: ${config.mcp.enabled ? "enabled" : "disabled"}, servers: ${config.mcp.servers.join(", ") || "(none)"}`,
|
|
432
439
|
...(config.mcp.tools.length === 0 ? [] : [`mcp extra tools: ${config.mcp.tools.join(", ")}`]),
|
|
@@ -450,6 +457,7 @@ const KEY_PATHS = {
|
|
|
450
457
|
jobMaxTurns: ["jobMaxTurns"],
|
|
451
458
|
autoContinue: ["autoContinue"],
|
|
452
459
|
codemode: ["codemode"],
|
|
460
|
+
contextPanel: ["contextPanel"],
|
|
453
461
|
providers: ["providers"],
|
|
454
462
|
"mcp.enabled": ["mcp", "enabled"],
|
|
455
463
|
"mcp.servers": ["mcp", "servers"],
|
|
@@ -557,6 +565,7 @@ export function effectiveValue(config, key) {
|
|
|
557
565
|
case "jobMaxTurns": return String(config.jobMaxTurns);
|
|
558
566
|
case "autoContinue": return String(config.autoContinue);
|
|
559
567
|
case "codemode": return String(config.codemode);
|
|
568
|
+
case "contextPanel": return String(config.contextPanel);
|
|
560
569
|
case "mcp.enabled": return String(config.mcp.enabled);
|
|
561
570
|
case "mcp.servers": return config.mcp.servers.join(", ") || "(none)";
|
|
562
571
|
case "mcp.tools": return config.mcp.tools.join(", ") || "(none)";
|
package/dist/jobs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { configure, ConversationIdle, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
2
3
|
import { JobLink, JobTask, JOB_INSTRUCTIONS, JOB_KIND, MAX_BRIEF_CHARS, jobNoticeEntry } from "./tasks.js";
|
|
3
4
|
export { JOB_INSTRUCTIONS };
|
|
4
5
|
import { JobWorkspaceDoc } from "./workspaces.js";
|
|
@@ -200,6 +201,38 @@ export function jobInputDraft(message, steer) {
|
|
|
200
201
|
whenBusy: steer ? "steer" : "followUp",
|
|
201
202
|
};
|
|
202
203
|
}
|
|
204
|
+
/** Admit steering without waiting for the worker; tracking and admission must commit together. */
|
|
205
|
+
export async function queueJobSteering(harness, id, message, context, requestId = `job:${id}:steer:${randomUUID()}`) {
|
|
206
|
+
if (!Number.isSafeInteger(id) || id <= 0)
|
|
207
|
+
throw new Error("Provide a valid positive job id.");
|
|
208
|
+
const draft = { ...jobInputDraft(message, true), content: message };
|
|
209
|
+
const job = await harness.getTask(id, context);
|
|
210
|
+
if (job === undefined || job.kind !== JOB_KIND)
|
|
211
|
+
throw new Error(`No job #${id}.`);
|
|
212
|
+
if (job.state.status === "terminal")
|
|
213
|
+
throw new Error(`Job #${id} is no longer running. Start or fork a job for new work.`);
|
|
214
|
+
const conversationId = await jobConversationId(harness, id, context);
|
|
215
|
+
const conversation = conversationId === undefined ? undefined : await harness.conversation(conversationId, context);
|
|
216
|
+
if (conversation === undefined)
|
|
217
|
+
throw new Error(`Job #${id} has no conversation.`);
|
|
218
|
+
try {
|
|
219
|
+
await harness.commit(async (tx) => {
|
|
220
|
+
const current = await tx.task(id);
|
|
221
|
+
if (current === undefined || current.kind !== JOB_KIND || current.state.status === "terminal"
|
|
222
|
+
|| current.state.checkpoint.phase !== "run")
|
|
223
|
+
throw new Error(`Job #${id} is no longer running.`);
|
|
224
|
+
const link = await tx.doc(JobLink, id);
|
|
225
|
+
// The job cannot finish between admission and recording the submission it must rejoin.
|
|
226
|
+
await conversation.submit(tx, { ...draft, requestId, whenIdle: "reject" });
|
|
227
|
+
link.steering = { requestId, message: draft.content };
|
|
228
|
+
}, context);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
if (error instanceof ConversationIdle)
|
|
232
|
+
throw new Error(`Job #${id} has no active run to steer; it may have just finished.`);
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
203
236
|
export async function sendToJob(harness, id, message, context, options = {}) {
|
|
204
237
|
const conversation = await findJobConversation(harness, id, context);
|
|
205
238
|
if (conversation === undefined)
|
package/dist/tool.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { arr, obj, oneOf, opt, str } from "@earendil-works/pi-schema";
|
|
2
|
-
import { AgentDoc,
|
|
2
|
+
import { AgentDoc, defineExtension, defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
3
3
|
import { formatJobDetail, formatJobList } from "./format.js";
|
|
4
|
-
import { createJobInCommit,
|
|
5
|
-
import {
|
|
4
|
+
import { createJobInCommit, queueJobSteering, normalizeBrief } from "./jobs.js";
|
|
5
|
+
import { JOB_KIND } from "./tasks.js";
|
|
6
6
|
import { selectForkSource } from "./forks.js";
|
|
7
7
|
import { planWorkspace } from "./workspaces.js";
|
|
8
8
|
import { JobTags, normalizeTags, resolveTaggedSource, setJobTags, taggedJob } from "./tags.js";
|
|
@@ -50,33 +50,11 @@ export function createTaskExtension(options) {
|
|
|
50
50
|
if (!Number.isSafeInteger(id) || id <= 0)
|
|
51
51
|
return textReply("Provide a valid positive job id.", true);
|
|
52
52
|
try {
|
|
53
|
-
|
|
54
|
-
const job = await api.getTask(id, context);
|
|
55
|
-
if (job === undefined || job.kind !== JOB_KIND)
|
|
56
|
-
return textReply(`No job #${id}.`, true);
|
|
57
|
-
if (job.state.status === "terminal")
|
|
58
|
-
return textReply(`Job #${id} is no longer running. Start or fork a job for new work.`, true);
|
|
59
|
-
const conversationId = await jobConversationId(api, id, context);
|
|
60
|
-
const conversation = conversationId === undefined ? undefined : await api.conversation(conversationId, context);
|
|
61
|
-
if (conversation === undefined)
|
|
62
|
-
return textReply(`Job #${id} has no conversation.`, true);
|
|
63
|
-
const requestId = `job:${id}:steer:${api.taskId}`;
|
|
64
|
-
await api.commit(async (tx) => {
|
|
65
|
-
const current = await tx.task(id);
|
|
66
|
-
if (current === undefined || current.kind !== JOB_KIND || current.state.status === "terminal"
|
|
67
|
-
|| current.state.checkpoint.phase !== "run")
|
|
68
|
-
throw new Error(`Job #${id} is no longer running.`);
|
|
69
|
-
const link = await tx.doc(JobLink, id);
|
|
70
|
-
// Admission and tracking are atomic; the job cannot finish between them.
|
|
71
|
-
await conversation.submit(tx, { ...draft, requestId, whenIdle: "reject" });
|
|
72
|
-
link.steering = { requestId, message: draft.content };
|
|
73
|
-
}, context);
|
|
53
|
+
await queueJobSteering(api, id, normalizeBrief(args.message ?? ""), context, `job:${id}:steer:${api.taskId}`);
|
|
74
54
|
return textReply(`Steering queued for job #${id}. It will receive the message at its next boundary; work continues. Wait for its completion notice; do not poll.`);
|
|
75
55
|
}
|
|
76
56
|
catch (error) {
|
|
77
|
-
return textReply(error instanceof
|
|
78
|
-
? `Job #${id} has no active run to steer; it may have just finished.`
|
|
79
|
-
: error instanceof Error ? error.message : String(error), true);
|
|
57
|
+
return textReply(error instanceof Error ? error.message : String(error), true);
|
|
80
58
|
}
|
|
81
59
|
}
|
|
82
60
|
if (args.action === "tag") {
|
package/dist/tui/app.js
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { matchesKey, stripTerminalSequences, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
1
|
+
import { isKeyRelease, matchesKey, stripTerminalSequences, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
2
|
import { getNativeClipboard } from "@earendil-works/pi-tui";
|
|
4
3
|
import { withCancel } from "@earendil-works/chord/context";
|
|
5
4
|
import { selectModel } from "../models.js";
|
|
6
5
|
import { rollbackChoices, rollbackSource } from "../rollback.js";
|
|
7
|
-
import { describeConfig } from "../config.js";
|
|
6
|
+
import { describeConfig, setConfigValue } from "../config.js";
|
|
8
7
|
import { parseId } from "../commands.js";
|
|
9
8
|
import { jobView } from "../format.js";
|
|
10
|
-
import { announceJobStart, compactConversation, createJobInCommit, findJobConversation, jobConversationId, jobCreateOptionsOf, jobRecord, jobInputDraft, normalizeBrief, scanJobs, } from "../jobs.js";
|
|
9
|
+
import { announceJobStart, compactConversation, createJobInCommit, findJobConversation, jobConversationId, jobCreateOptionsOf, jobRecord, jobInputDraft, queueJobSteering, normalizeBrief, scanJobs, } from "../jobs.js";
|
|
11
10
|
import { buildJobRows, clampScroll, filterJobs, moveSelection, reconcileJobSelection, targetLabel } from "./state.js";
|
|
12
|
-
import { backgroundLine, bold, dim, fg, padLines, shortenHome, statusText, usageTotals, ACCENT, COMPOSER_BG, GREEN, MUTED, RED, TEXT, TRANSCRIPT_BG, YELLOW } from "./format.js";
|
|
11
|
+
import { transcriptLine, backgroundLine, bold, dim, fg, padLines, shortenHome, statusText, usageTotals, ACCENT, COMPOSER_BG, GREEN, MUTED, RED, TEXT, TRANSCRIPT_BG, YELLOW } from "./format.js";
|
|
13
12
|
import { attachmentLabel, createImagePaster, MAX_ATTACHMENTS } from "../images.js";
|
|
14
13
|
import { compactionLimit, contextPercent, formatTokenCount } from "../context-usage.js";
|
|
15
14
|
import { Transcript } from "./transcript.js";
|
|
16
15
|
import { overlayDialog } from "./dialog.js";
|
|
17
16
|
import { JOB_KIND } from "../tasks.js";
|
|
18
17
|
import { TranscriptSelection } from "./selection.js";
|
|
18
|
+
import { createTextCopier, copyNotice } from "./clipboard.js";
|
|
19
19
|
import { openBrowser } from "./browser.js";
|
|
20
|
-
import { Composer, isComposerNewline } from "./composer.js";
|
|
20
|
+
import { Composer, isComposerNewline, isComposerQueue } from "./composer.js";
|
|
21
21
|
const FLASH_MS = 5000;
|
|
22
22
|
const QUIT_REPEAT_MS = 1500;
|
|
23
23
|
const CHROME_ROWS = 8; // Header + spacer, status spacer + status, three composer rows, and hint.
|
|
24
24
|
const PANE_HEADING_ROWS = 2; // Title + spacer.
|
|
25
25
|
const MIN_ROWS = CHROME_ROWS + PANE_HEADING_ROWS + 1;
|
|
26
26
|
const JOB_ROW_HEIGHT = 3; // Status, brief, and a spacer between jobs.
|
|
27
|
+
const CONTEXT_BREAKPOINT = 140;
|
|
28
|
+
const MIN_CONTEXT_WIDTH = 26;
|
|
29
|
+
const MIN_TRANSCRIPT_WITH_CONTEXT = 80;
|
|
27
30
|
function shortcut(keys, description) {
|
|
28
31
|
return `${bold(keys.toUpperCase())} ${fg(description, MUTED)}`;
|
|
29
32
|
}
|
|
@@ -31,6 +34,7 @@ function shortcut(keys, description) {
|
|
|
31
34
|
export class Dashboard {
|
|
32
35
|
capturesViewportInput = true;
|
|
33
36
|
selection;
|
|
37
|
+
copyText;
|
|
34
38
|
runtime;
|
|
35
39
|
rowsOf;
|
|
36
40
|
requestRender;
|
|
@@ -52,7 +56,6 @@ export class Dashboard {
|
|
|
52
56
|
filter: "",
|
|
53
57
|
showFinished: true,
|
|
54
58
|
toolsExpanded: false,
|
|
55
|
-
steer: false,
|
|
56
59
|
};
|
|
57
60
|
main;
|
|
58
61
|
current;
|
|
@@ -96,10 +99,8 @@ export class Dashboard {
|
|
|
96
99
|
quitArmedAt;
|
|
97
100
|
quitArmTimer;
|
|
98
101
|
constructor(options) {
|
|
99
|
-
this.
|
|
100
|
-
|
|
101
|
-
return true;
|
|
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")); }));
|
|
102
|
+
this.copyText = options.copySelection ?? createTextCopier();
|
|
103
|
+
this.selection = new TranscriptSelection(this.copyText, (result) => { const notice = copyNotice(result); this.flash(notice.text, notice.kind); }, options.requestRender, options.openUrl ?? ((url) => { void openBrowser(url).catch((error) => this.flash(`Could not open link: ${message(error)}`, "error")); }));
|
|
103
104
|
this.runtime = options.runtime;
|
|
104
105
|
this.rowsOf = options.rows;
|
|
105
106
|
this.input = new Composer(options.rows, options.requestRender);
|
|
@@ -333,15 +334,19 @@ export class Dashboard {
|
|
|
333
334
|
});
|
|
334
335
|
return this.displayLoad;
|
|
335
336
|
}
|
|
337
|
+
steerInput(target = this.state.target) {
|
|
338
|
+
return target.kind === "job" && (this.nodes.has(target.id) || this.records.get(target.id)?.state.status === "running");
|
|
339
|
+
}
|
|
336
340
|
async openSelected() {
|
|
337
341
|
const id = this.state.selectedJobId;
|
|
338
342
|
if (id === undefined)
|
|
339
343
|
return;
|
|
340
344
|
try {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
+
const loaded = this.pinJob(id);
|
|
346
|
+
// Activation is immediate, even during a slow preview read. Its completion must not steal focus.
|
|
347
|
+
this.setFocus("composer");
|
|
348
|
+
this.renderSoon();
|
|
349
|
+
await loaded;
|
|
345
350
|
}
|
|
346
351
|
catch (error) {
|
|
347
352
|
this.flash(message(error), "error");
|
|
@@ -374,11 +379,26 @@ export class Dashboard {
|
|
|
374
379
|
this.renderSoon();
|
|
375
380
|
}
|
|
376
381
|
resizeContext(delta) {
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
this.state.contextPane = Math.max(20, Math.min(max, current + delta));
|
|
382
|
+
const current = this.state.contextPane ?? (this.contextWidth(this.lastWidth) || 30);
|
|
383
|
+
this.state.contextPane = Math.max(MIN_CONTEXT_WIDTH, Math.min(48, current + delta));
|
|
380
384
|
this.renderSoon();
|
|
381
385
|
}
|
|
386
|
+
setContextPanel(visible = this.runtime.config.contextPanel === false) {
|
|
387
|
+
try {
|
|
388
|
+
// Edit the resolved highest-precedence file, not a lower global layer or conversation.
|
|
389
|
+
setConfigValue(this.runtime.config.configPath, "contextPanel", String(visible));
|
|
390
|
+
this.runtime.config.contextPanel = visible;
|
|
391
|
+
this.runtime.config.configFound = true;
|
|
392
|
+
if (!this.runtime.config.configPaths.includes(this.runtime.config.configPath))
|
|
393
|
+
this.runtime.config.configPaths.push(this.runtime.config.configPath);
|
|
394
|
+
this.flash(visible
|
|
395
|
+
? `Context panel enabled${this.contextWidth(this.lastWidth) === 0 ? " (hidden until there is room)" : ""}; saved`
|
|
396
|
+
: "Context panel off; saved");
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
this.flash(`Could not save context panel preference: ${message(error)}`, "error");
|
|
400
|
+
}
|
|
401
|
+
}
|
|
382
402
|
beginPrompt(mode) {
|
|
383
403
|
this.state.mode = mode;
|
|
384
404
|
this.input.setValue("");
|
|
@@ -458,7 +478,7 @@ export class Dashboard {
|
|
|
458
478
|
this.flash(`attached ${attachmentLabel(this.attachments)}`);
|
|
459
479
|
this.renderSoon();
|
|
460
480
|
}
|
|
461
|
-
async submit() {
|
|
481
|
+
async submit(followUp = false) {
|
|
462
482
|
const value = this.input.getValue();
|
|
463
483
|
const text = value.trim();
|
|
464
484
|
if (this.state.mode === "newJob") {
|
|
@@ -558,7 +578,9 @@ export class Dashboard {
|
|
|
558
578
|
if (text.length === 0 && this.attachments.length === 0)
|
|
559
579
|
return;
|
|
560
580
|
if (text.startsWith("/")) {
|
|
561
|
-
|
|
581
|
+
// Addressed job input retains its draft until admission succeeds.
|
|
582
|
+
if (!/^\/(?:send|steer)(?:\s|$)/i.test(text))
|
|
583
|
+
this.input.setValue("");
|
|
562
584
|
try {
|
|
563
585
|
await this.submitSlash(text);
|
|
564
586
|
}
|
|
@@ -573,12 +595,16 @@ export class Dashboard {
|
|
|
573
595
|
this.flash("images go to main only", "error");
|
|
574
596
|
return;
|
|
575
597
|
}
|
|
576
|
-
const attachments = this.attachments;
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
598
|
+
const attachments = [...this.attachments];
|
|
599
|
+
let steer = !followUp && this.steerInput(target);
|
|
600
|
+
const admitted = () => {
|
|
601
|
+
// Admission may finish after the user has begun editing the next draft.
|
|
602
|
+
if (this.input.getValue() === value)
|
|
603
|
+
this.input.setValue("");
|
|
604
|
+
this.attachments = this.attachments.filter((image) => !attachments.includes(image));
|
|
605
|
+
this.scroll = 0;
|
|
606
|
+
};
|
|
607
|
+
await this.runAction(`${steer ? "steering" : "queuing to"} ${targetLabel(target)}`, async (context) => {
|
|
582
608
|
if (target.kind === "main") {
|
|
583
609
|
const content = attachments.length === 0
|
|
584
610
|
? value
|
|
@@ -586,17 +612,31 @@ export class Dashboard {
|
|
|
586
612
|
await this.runtime.root.submit({
|
|
587
613
|
type: "input",
|
|
588
614
|
content,
|
|
589
|
-
whenBusy:
|
|
615
|
+
whenBusy: steer ? "steer" : "followUp",
|
|
590
616
|
}, context);
|
|
591
|
-
|
|
617
|
+
admitted();
|
|
618
|
+
this.flash(steer ? "steered main" : "sent to main");
|
|
592
619
|
return;
|
|
593
620
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
621
|
+
if (!followUp) {
|
|
622
|
+
// Graph/list refresh is debounced; use the durable status for the automatic ingress default.
|
|
623
|
+
const job = await this.runtime.harness.getTask(target.id, context);
|
|
624
|
+
if (job === undefined || job.kind !== JOB_KIND)
|
|
625
|
+
throw new Error(`No job #${target.id}.`);
|
|
626
|
+
steer = job.state.status !== "terminal";
|
|
627
|
+
}
|
|
628
|
+
if (steer) {
|
|
629
|
+
await queueJobSteering(this.runtime.harness, target.id, value, context);
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
const conversation = await findJobConversation(this.runtime.harness, target.id, context);
|
|
633
|
+
if (conversation === undefined)
|
|
634
|
+
throw new Error(`job #${target.id} has no conversation`);
|
|
635
|
+
// One-shot follow-up also continues completed conversations; it does not steer a live run.
|
|
636
|
+
await conversation.submit({ ...jobInputDraft(value, false), content: value }, context);
|
|
637
|
+
}
|
|
638
|
+
admitted();
|
|
639
|
+
this.flash(steer ? `steering queued for job #${target.id}; delivery at next boundary` : `follow-up queued for job #${target.id}`);
|
|
600
640
|
});
|
|
601
641
|
}
|
|
602
642
|
async submitSlash(text) {
|
|
@@ -612,6 +652,14 @@ export class Dashboard {
|
|
|
612
652
|
case "info":
|
|
613
653
|
this.state.mode = "inspector";
|
|
614
654
|
return;
|
|
655
|
+
case "context":
|
|
656
|
+
if (tail === "" || tail === "toggle")
|
|
657
|
+
this.setContextPanel();
|
|
658
|
+
else if (tail === "on" || tail === "off")
|
|
659
|
+
this.setContextPanel(tail === "on");
|
|
660
|
+
else
|
|
661
|
+
throw new Error("Usage: /context [on|off|toggle]");
|
|
662
|
+
return;
|
|
615
663
|
case "model": {
|
|
616
664
|
if (this.onModel === undefined)
|
|
617
665
|
throw new Error("Model switching is unavailable here.");
|
|
@@ -737,11 +785,18 @@ export class Dashboard {
|
|
|
737
785
|
if (content.length === 0)
|
|
738
786
|
throw new Error(`Usage: /${command} <id> <message>`);
|
|
739
787
|
await this.runAction(`${command} job #${id}`, async (context) => {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
788
|
+
if (command === "steer") {
|
|
789
|
+
await queueJobSteering(this.runtime.harness, id, content, context);
|
|
790
|
+
}
|
|
791
|
+
else {
|
|
792
|
+
const conversation = await findJobConversation(this.runtime.harness, id, context);
|
|
793
|
+
if (conversation === undefined)
|
|
794
|
+
throw new Error(`No conversation for job #${id}.`);
|
|
795
|
+
await conversation.submit(jobInputDraft(content, false), context);
|
|
796
|
+
}
|
|
797
|
+
if (this.input.getValue().trim() === text)
|
|
798
|
+
this.input.setValue("");
|
|
799
|
+
this.flash(command === "steer" ? `steering queued for job #${id}; delivery at next boundary` : `follow-up queued for job #${id}`);
|
|
745
800
|
});
|
|
746
801
|
return;
|
|
747
802
|
}
|
|
@@ -920,7 +975,7 @@ export class Dashboard {
|
|
|
920
975
|
return [];
|
|
921
976
|
const lines = [...this.current.lines(width, this.state.toolsExpanded), ...this.current.liveLines(width)];
|
|
922
977
|
// A trailing entry spacer must not occupy the only content row in a short terminal.
|
|
923
|
-
while (lines.length > 0 && stripTerminalSequences(lines.at(-1)).trim().length === 0)
|
|
978
|
+
while (lines.length > 0 && stripTerminalSequences(lines.at(-1).text).trim().length === 0)
|
|
924
979
|
lines.pop();
|
|
925
980
|
return lines;
|
|
926
981
|
}
|
|
@@ -971,14 +1026,15 @@ export class Dashboard {
|
|
|
971
1026
|
return Math.max(24, Math.min(30, Math.round(width * 0.22)));
|
|
972
1027
|
}
|
|
973
1028
|
contextWidth(width) {
|
|
974
|
-
if (this.
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1029
|
+
if (this.runtime.config.contextPanel === false || width < CONTEXT_BREAKPOINT)
|
|
1030
|
+
return 0;
|
|
1031
|
+
const available = width - this.jobsWidth(width) - 2 - MIN_TRANSCRIPT_WITH_CONTEXT;
|
|
1032
|
+
if (available < MIN_CONTEXT_WIDTH)
|
|
1033
|
+
return 0;
|
|
1034
|
+
const preferred = this.state.contextPane ?? Math.max(MIN_CONTEXT_WIDTH, Math.min(36, Math.round(width * 0.2)));
|
|
1035
|
+
return Math.min(preferred, available);
|
|
1036
|
+
}
|
|
1037
|
+
async copy() {
|
|
982
1038
|
const target = this.displayTarget;
|
|
983
1039
|
let text = "";
|
|
984
1040
|
if (target.kind === "job") {
|
|
@@ -1002,8 +1058,13 @@ export class Dashboard {
|
|
|
1002
1058
|
this.flash("nothing to copy", "error");
|
|
1003
1059
|
return;
|
|
1004
1060
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1061
|
+
try {
|
|
1062
|
+
const notice = copyNotice(await this.copyText(text));
|
|
1063
|
+
this.flash(notice.text, notice.kind);
|
|
1064
|
+
}
|
|
1065
|
+
catch {
|
|
1066
|
+
this.flash("Copy failed", "error");
|
|
1067
|
+
}
|
|
1007
1068
|
}
|
|
1008
1069
|
render(width) {
|
|
1009
1070
|
this.lastWidth = width;
|
|
@@ -1061,10 +1122,11 @@ export class Dashboard {
|
|
|
1061
1122
|
renderBody(width, height) {
|
|
1062
1123
|
const { jobsWidth, transcriptWidth, contextWidth } = this.paneWidths(width);
|
|
1063
1124
|
const jobs = jobsWidth > 0 ? padLines(this.renderJobs(jobsWidth, height), height, jobsWidth) : [];
|
|
1064
|
-
const
|
|
1125
|
+
const rows = this.renderTranscript(transcriptWidth, height);
|
|
1126
|
+
const transcript = padLines(rows.map((line) => line.text), height, transcriptWidth)
|
|
1065
1127
|
.map((line) => backgroundLine(line, transcriptWidth, TRANSCRIPT_BG));
|
|
1066
1128
|
if (this.state.mode === "chat") {
|
|
1067
|
-
this.selection.update({ x: jobsWidth > 0 ? jobsWidth + 1 : 0, y: 2 + PANE_HEADING_ROWS, width: transcriptWidth, lines: transcript.slice(PANE_HEADING_ROWS), source: this.current });
|
|
1129
|
+
this.selection.update({ x: jobsWidth > 0 ? jobsWidth + 1 : 0, y: 2 + PANE_HEADING_ROWS, width: transcriptWidth, lines: transcript.slice(PANE_HEADING_ROWS), copyBounds: rows.slice(PANE_HEADING_ROWS), source: this.current });
|
|
1068
1130
|
transcript.splice(PANE_HEADING_ROWS, height - PANE_HEADING_ROWS, ...this.selection.lines());
|
|
1069
1131
|
}
|
|
1070
1132
|
const context = contextWidth > 0 ? padLines(this.renderContext(contextWidth, height), height, contextWidth) : [];
|
|
@@ -1091,10 +1153,10 @@ export class Dashboard {
|
|
|
1091
1153
|
content.push("");
|
|
1092
1154
|
const selected = row.id === this.state.selectedJobId;
|
|
1093
1155
|
const marker = selected ? fg("▸", ACCENT) : " ";
|
|
1094
|
-
const id = `#${row.id
|
|
1156
|
+
const id = `#${String(row.id).padEnd(7)}`;
|
|
1095
1157
|
const state = truncateToWidth(compactJobStatus(row.status), 9).padEnd(9);
|
|
1096
1158
|
const age = row.startedAt === undefined ? "—" : compactDuration(Math.max(0, (row.endedAt ?? this.now()) - row.startedAt));
|
|
1097
|
-
const head = `${marker} ${selected ? bold(id) : id}${statusText(state)} ${dim(age.padStart(3))}`;
|
|
1159
|
+
const head = `${marker} ${selected ? bold(id) : id} ${statusText(state)} ${dim(age.padStart(3))}`;
|
|
1098
1160
|
content.push(truncateToWidth(head, width, "", true));
|
|
1099
1161
|
const briefWidth = Math.max(4, width - 3);
|
|
1100
1162
|
const origin = row.fork === undefined ? "" : `↳ ${row.fork.jobId === undefined ? "main" : `#${row.fork.jobId}`} · `;
|
|
@@ -1112,16 +1174,16 @@ export class Dashboard {
|
|
|
1112
1174
|
const live = this.current?.live;
|
|
1113
1175
|
const active = live?.generation !== undefined || live?.tools?.some((slot) => slot.status === "running") === true;
|
|
1114
1176
|
const title = `${bold("TRANSCRIPT")} ${dim(target)}${active ? fg(" ● live", GREEN) : ""}${this.scroll > 0 ? dim(` ↑${this.scroll}`) : ""}`;
|
|
1115
|
-
const lines = [truncateToWidth(title, width, "", true), ""];
|
|
1177
|
+
const lines = [transcriptLine(truncateToWidth(title, width, "", true)), transcriptLine("")];
|
|
1116
1178
|
const transcript = this.current;
|
|
1117
1179
|
if (transcript === undefined) {
|
|
1118
|
-
lines.push(dim(this.displayLoad === undefined ? " No conversation is available for this job yet." : " Loading job transcript…"));
|
|
1180
|
+
lines.push(transcriptLine(dim(this.displayLoad === undefined ? " No conversation is available for this job yet." : " Loading job transcript…"), 2));
|
|
1119
1181
|
return lines;
|
|
1120
1182
|
}
|
|
1121
1183
|
const contentHeight = Math.max(1, height - PANE_HEADING_ROWS);
|
|
1122
1184
|
const all = this.transcriptLines(width);
|
|
1123
1185
|
if (all.length === 0) {
|
|
1124
|
-
lines.push(dim(" No messages yet. Type below and press Enter."));
|
|
1186
|
+
lines.push(transcriptLine(dim(" No messages yet. Type below and press Enter."), 2));
|
|
1125
1187
|
return lines;
|
|
1126
1188
|
}
|
|
1127
1189
|
const offset = clampScroll(this.scroll, all.length, contentHeight);
|
|
@@ -1227,7 +1289,7 @@ export class Dashboard {
|
|
|
1227
1289
|
case "confirmAbortMain":
|
|
1228
1290
|
return "— › ";
|
|
1229
1291
|
default: {
|
|
1230
|
-
const steer = this.
|
|
1292
|
+
const steer = this.steerInput() ? " (steer)" : "";
|
|
1231
1293
|
return `to ${targetLabel(this.state.target)}${steer} › `;
|
|
1232
1294
|
}
|
|
1233
1295
|
}
|
|
@@ -1269,11 +1331,11 @@ export class Dashboard {
|
|
|
1269
1331
|
else if (this.actionLabel !== undefined)
|
|
1270
1332
|
hint = shortcut("CTRL-C", "stop waiting (work stays durable)");
|
|
1271
1333
|
else if (this.state.focus === "composer")
|
|
1272
|
-
hint = [shortcut("ENTER", "send")
|
|
1334
|
+
hint = [shortcut("ENTER", this.state.target.kind === "main" ? "send" : this.steerInput() ? "steer" : "queue"), ...(this.state.target.kind === "job" && this.steerInput() ? [shortcut("CMD-SHIFT-ENTER", "queue")] : []), shortcut(this.input.getValue().length === 0 ? "?" : "TAB ?", "help"), shortcut("TAB", "focus"), shortcut("SHIFT-ENTER", "newline"), ...(this.attachments.length === 0 ? [] : [fg(`${this.attachments.length} attached`, YELLOW)])].join(separator);
|
|
1273
1335
|
else if (this.state.focus === "jobs")
|
|
1274
|
-
hint = [shortcut("
|
|
1336
|
+
hint = [shortcut("ENTER", "message"), shortcut("↑/↓ J/K", "preview"), shortcut("?", "help"), shortcut("TAB", "focus")].join(separator);
|
|
1275
1337
|
else
|
|
1276
|
-
hint = [shortcut("J/K", "scroll"), shortcut("
|
|
1338
|
+
hint = [shortcut("↑/↓ J/K", "scroll"), shortcut("?", "help"), shortcut("S", "compose"), shortcut("TAB", "focus")].join(separator);
|
|
1277
1339
|
if (this.scroll > 0 && this.state.focus === "transcript")
|
|
1278
1340
|
hint += dim(` · ↑${this.scroll}`);
|
|
1279
1341
|
return truncateToWidth(` ${hint}`, width, "", true);
|
|
@@ -1281,26 +1343,29 @@ export class Dashboard {
|
|
|
1281
1343
|
renderHelp(width, height) {
|
|
1282
1344
|
const bindings = [
|
|
1283
1345
|
["TAB / SHIFT-TAB", "cycle composer, jobs, transcript"],
|
|
1346
|
+
["CTRL-X", "toggle context pane (saved in active config)"],
|
|
1284
1347
|
["CTRL-T", "target main ↔ selected job"],
|
|
1285
1348
|
["CTRL-N", "new job brief"],
|
|
1286
1349
|
["SHIFT-ENTER", "insert a newline (Ctrl-J or Alt-Enter fallback); Enter sends"],
|
|
1287
|
-
["
|
|
1350
|
+
["CMD-SHIFT-ENTER", "queue once from composer (if reported); /send <id> <text> fallback"],
|
|
1288
1351
|
["CTRL-V", "paste an image into the composer (main only)"],
|
|
1289
|
-
["ENTER", "send,
|
|
1352
|
+
["ENTER", "send input, or pin job and focus composer; confirm prompt"],
|
|
1353
|
+
["S (JOBS)", "pin highlighted job and compose; running jobs default to steer"],
|
|
1290
1354
|
["[ / ]", "resize the jobs pane"],
|
|
1291
1355
|
["{ / }", "resize the context pane"],
|
|
1292
1356
|
["0", "reset pane widths"],
|
|
1293
|
-
["J / K", "move job selection or scroll"],
|
|
1357
|
+
["↑ / ↓ or J / K", "move job selection or scroll (not while typing)"],
|
|
1294
1358
|
["WHEEL", "scroll the pane under the pointer"],
|
|
1295
1359
|
["G / SHIFT-G", "jump to oldest / newest"],
|
|
1296
1360
|
["N / C / M / SHIFT-R", "new · cancel · compact · reset"],
|
|
1297
|
-
["S / T / I / F / Y", "
|
|
1361
|
+
["S / T / I / F / Y", "compose · tools · inspector · finished · copy"],
|
|
1298
1362
|
["/", "filter jobs outside composer; commands inside"],
|
|
1299
1363
|
["CTRL-C", "stop waiting / clear prompt / close overlay"],
|
|
1300
1364
|
["CTRL-C ×2", "quit within 1.5s (confirms with live work)"],
|
|
1301
1365
|
];
|
|
1302
1366
|
return this.panel("Help", [
|
|
1303
1367
|
bold("Slash commands (composer)"),
|
|
1368
|
+
"/context off · /context on · /context toggle",
|
|
1304
1369
|
"/help · /info · /tasks · /task <id> · /log <id>",
|
|
1305
1370
|
"/new [brief] · /send <id> <text> · /steer <id> <text>",
|
|
1306
1371
|
"/cancel <id> · /compact [focus] · /reset [handoff]",
|
|
@@ -1417,6 +1482,9 @@ export class Dashboard {
|
|
|
1417
1482
|
return handled;
|
|
1418
1483
|
}
|
|
1419
1484
|
handleInput(data) {
|
|
1485
|
+
// TUI normally filters releases; keep direct dashboard delivery safe too.
|
|
1486
|
+
if (isKeyRelease(data))
|
|
1487
|
+
return;
|
|
1420
1488
|
this.selection.reset();
|
|
1421
1489
|
this.renderSoon();
|
|
1422
1490
|
if (matchesKey(data, "ctrl+c")) {
|
|
@@ -1486,6 +1554,13 @@ export class Dashboard {
|
|
|
1486
1554
|
this.renderSoon();
|
|
1487
1555
|
return;
|
|
1488
1556
|
}
|
|
1557
|
+
// Ctrl-X is unused by the editor and has an unambiguous legacy control byte.
|
|
1558
|
+
// Keep only literal Meta-C as an alias: extended Alt-C matching can also
|
|
1559
|
+
// match printable non-Latin keys via Kitty's base-layout key fallback.
|
|
1560
|
+
if (matchesKey(data, "ctrl+x") || data === "\x1bc") {
|
|
1561
|
+
this.setContextPanel();
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1489
1564
|
if (matchesKey(data, "ctrl+t")) {
|
|
1490
1565
|
void this.toggleTarget();
|
|
1491
1566
|
return;
|
|
@@ -1494,14 +1569,9 @@ export class Dashboard {
|
|
|
1494
1569
|
this.beginPrompt("newJob");
|
|
1495
1570
|
return;
|
|
1496
1571
|
}
|
|
1497
|
-
if (matchesKey(data, "alt+s")) {
|
|
1498
|
-
this.state.steer = !this.state.steer;
|
|
1499
|
-
this.flash(this.state.steer
|
|
1500
|
-
? `${targetLabel(this.state.target)} input will steer the current run`
|
|
1501
|
-
: `${targetLabel(this.state.target)} input will queue as a follow-up`);
|
|
1502
|
-
return;
|
|
1503
|
-
}
|
|
1504
1572
|
if (this.state.focus === "composer") {
|
|
1573
|
+
if (isComposerQueue(data))
|
|
1574
|
+
return this.submit(true);
|
|
1505
1575
|
if (this.input.getValue().length === 0 && data === "?") {
|
|
1506
1576
|
this.state.mode = "help";
|
|
1507
1577
|
this.renderSoon();
|
|
@@ -1552,6 +1622,10 @@ export class Dashboard {
|
|
|
1552
1622
|
}
|
|
1553
1623
|
if (this.state.focus === "jobs") {
|
|
1554
1624
|
this.jobsScroll = undefined;
|
|
1625
|
+
if (data === "s") {
|
|
1626
|
+
void this.openSelected();
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1555
1629
|
if (matchesKey(data, "down") || data === "j") {
|
|
1556
1630
|
this.state.selectedJobId = moveSelection(this.visible, this.state.selectedJobId, 1);
|
|
1557
1631
|
this.previewSelected();
|
|
@@ -1682,7 +1756,7 @@ export class Dashboard {
|
|
|
1682
1756
|
return;
|
|
1683
1757
|
}
|
|
1684
1758
|
if (data === "y") {
|
|
1685
|
-
this.copy();
|
|
1759
|
+
void this.copy();
|
|
1686
1760
|
return;
|
|
1687
1761
|
}
|
|
1688
1762
|
if (data === "q") {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import childProcess from "node:child_process";
|
|
3
|
+
import { getNativeClipboard } from "@earendil-works/pi-tui";
|
|
4
|
+
function pbcopy(text, env) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const child = childProcess.spawn("/usr/bin/pbcopy", [], {
|
|
7
|
+
shell: false,
|
|
8
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
9
|
+
timeout: 3000,
|
|
10
|
+
// pbcopy decodes stdin using the locale, not necessarily UTF-8 by default.
|
|
11
|
+
env: { ...env, LC_ALL: "en_US.UTF-8" },
|
|
12
|
+
});
|
|
13
|
+
let inputError;
|
|
14
|
+
child.on("error", reject);
|
|
15
|
+
child.stdin.on("error", (error) => { inputError = error; });
|
|
16
|
+
child.on("close", (code, signal) => {
|
|
17
|
+
if (code === 0 && !signal && !inputError)
|
|
18
|
+
resolve();
|
|
19
|
+
else
|
|
20
|
+
reject(inputError ?? new Error("pbcopy failed"));
|
|
21
|
+
});
|
|
22
|
+
// Transcript content is only stdin data: never shell source or process arguments.
|
|
23
|
+
child.stdin.end(text, "utf8");
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Shared by transcript selection and keyboard answer copy. Never reads the clipboard. */
|
|
27
|
+
export function createTextCopier(options = {}) {
|
|
28
|
+
const copy = async (text) => {
|
|
29
|
+
const env = options.env ?? process.env;
|
|
30
|
+
const platform = options.platform ?? process.platform;
|
|
31
|
+
const remote = Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.SSH_TTY);
|
|
32
|
+
try {
|
|
33
|
+
if (!(options.isTTY ?? process.stdout.isTTY))
|
|
34
|
+
return "Copy unavailable: no terminal clipboard transport.";
|
|
35
|
+
// Local tmux still shares the Mac pasteboard. Over SSH, native helpers would
|
|
36
|
+
// write to the remote host instead of the terminal user's clipboard.
|
|
37
|
+
if (platform === "darwin" && !remote) {
|
|
38
|
+
try {
|
|
39
|
+
const clipboard = (options.nativeClipboard ?? getNativeClipboard)();
|
|
40
|
+
if (clipboard?.setText) {
|
|
41
|
+
await clipboard.setText(text);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch { /* Fall back when the optional native helper cannot load or write. */ }
|
|
46
|
+
await pbcopy(text, env);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (env.TERM_PROGRAM === "Apple_Terminal")
|
|
50
|
+
return "Copy unavailable: Apple Terminal does not support OSC 52. Use native terminal selection.";
|
|
51
|
+
let sequence = `\x1b]52;c;${Buffer.from(text).toString("base64")}\x07`;
|
|
52
|
+
if (env.TMUX)
|
|
53
|
+
sequence = `\x1bPtmux;${sequence.replaceAll("\x1b", "\x1b\x1b")}\x1b\\`;
|
|
54
|
+
await (options.write ?? ((data) => new Promise((resolve, reject) => {
|
|
55
|
+
process.stdout.write(data, (error) => error ? reject(error) : resolve());
|
|
56
|
+
})))(sequence);
|
|
57
|
+
return { status: "sent" };
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return "Copy failed: clipboard transport unavailable.";
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// Selection and keyboard copies share this queue. Keep native writes and their
|
|
64
|
+
// fallback together so an older completion cannot overwrite a newer request.
|
|
65
|
+
let pending = Promise.resolve();
|
|
66
|
+
return (text) => {
|
|
67
|
+
const result = pending.then(() => copy(text));
|
|
68
|
+
pending = result.then(() => undefined, () => undefined);
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function copyNotice(result) {
|
|
73
|
+
if (result === true)
|
|
74
|
+
return { text: "copied to clipboard", kind: "info" };
|
|
75
|
+
if (typeof result === "object")
|
|
76
|
+
return { text: "Copy sent via OSC 52 (unconfirmed)", kind: "info" };
|
|
77
|
+
return { text: typeof result === "string" ? result : "Copy failed", kind: "error" };
|
|
78
|
+
}
|
package/dist/tui/composer.js
CHANGED
|
@@ -5,6 +5,12 @@ export function isComposerNewline(data) {
|
|
|
5
5
|
return matchesKey(data, "ctrl+j") || matchesKey(data, "shift+enter")
|
|
6
6
|
|| matchesKey(data, "alt+enter") || data === "\x1b\r" || data === "\x1b[13;2~";
|
|
7
7
|
}
|
|
8
|
+
/** Command/Super+Shift+Enter is one-shot follow-up, only when CSI-u reports it.
|
|
9
|
+
* xterm modifyOtherKeys has no distinct Super modifier (its bit 8 is Meta).
|
|
10
|
+
*/
|
|
11
|
+
export function isComposerQueue(data) {
|
|
12
|
+
return data.endsWith("u") && matchesKey(data, "super+shift+enter");
|
|
13
|
+
}
|
|
8
14
|
/** Toolkit editing/paste/undo semantics, embedded in the dashboard's own layout. */
|
|
9
15
|
export class Composer extends Editor {
|
|
10
16
|
constructor(rows, requestRender) {
|
package/dist/tui/format.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { isAbsolute, relative, sep } from "node:path";
|
|
3
|
-
import { backgroundAnsi, indexedColor,
|
|
3
|
+
import { backgroundAnsi, indexedColor, styleText, stripTerminalSequences, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
4
4
|
import { formatDuration } from "../format.js";
|
|
5
|
+
import { renderCopyableMarkdown } from "./markdown-copy.js";
|
|
5
6
|
/** Display paths beneath home with `~`, keeping sibling directories and other roots absolute. */
|
|
6
7
|
export function shortenHome(path, home = homedir()) {
|
|
7
8
|
const suffix = relative(home, path);
|
|
@@ -73,6 +74,9 @@ function blockText(content) {
|
|
|
73
74
|
}).join("\n");
|
|
74
75
|
}
|
|
75
76
|
const TRANSCRIPT_MARKDOWN_THEME = {
|
|
77
|
+
// The transcript already has a speaker gutter; don't add the toolkit's two
|
|
78
|
+
// decorative code columns on top of source indentation (or copy them out).
|
|
79
|
+
codeBlockIndent: "",
|
|
76
80
|
heading: (text) => fg(text, TEXT),
|
|
77
81
|
link: (text) => fg(text, ACCENT),
|
|
78
82
|
linkUrl: dim,
|
|
@@ -88,20 +92,34 @@ const TRANSCRIPT_MARKDOWN_THEME = {
|
|
|
88
92
|
strikethrough: (text) => styleText(text, { strikethrough: true }, MODE),
|
|
89
93
|
underline: (text) => styleText(text, { underline: true }, MODE),
|
|
90
94
|
};
|
|
95
|
+
export function transcriptLine(text, copyStart = 0) {
|
|
96
|
+
return { text, copyStart, copyEnd: visibleWidth(stripTerminalSequences(text).replace(/ +$/u, "")) };
|
|
97
|
+
}
|
|
91
98
|
function prefixLines(text, prefix, width, color) {
|
|
92
99
|
const inner = Math.max(1, width - visibleWidth(prefix));
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const pad = " ".repeat(
|
|
97
|
-
return lines.map((line, index) =>
|
|
100
|
+
const rendered = renderCopyableMarkdown(text, inner, TRANSCRIPT_MARKDOWN_THEME, { color: (value) => fg(value, color) });
|
|
101
|
+
const lines = rendered.length === 0 ? [{ text: "" }] : rendered;
|
|
102
|
+
const gutter = visibleWidth(prefix);
|
|
103
|
+
const pad = " ".repeat(gutter);
|
|
104
|
+
return lines.map((line, index) => {
|
|
105
|
+
const row = transcriptLine(fg(index === 0 ? prefix : pad, color) + line.text,
|
|
106
|
+
// Keep visible speaker labels, but not the blank continuation gutter.
|
|
107
|
+
index === 0 && prefix.trim() !== "" ? prefix.length - prefix.trimStart().length : gutter);
|
|
108
|
+
if (line.copyStart !== undefined && line.copyEnd !== undefined) {
|
|
109
|
+
row.code = line.code;
|
|
110
|
+
row.copyStart = gutter + line.copyStart;
|
|
111
|
+
row.copyEnd = gutter + line.copyEnd;
|
|
112
|
+
}
|
|
113
|
+
row.copySkip = line.copySkip;
|
|
114
|
+
return row;
|
|
115
|
+
});
|
|
98
116
|
}
|
|
99
117
|
function rule(label, width) {
|
|
100
118
|
const text = `── ${label} `;
|
|
101
119
|
return fg(truncateToWidth(text, width, ""), BORDER);
|
|
102
120
|
}
|
|
103
121
|
function ruleWithText(label, body, width, color = MUTED) {
|
|
104
|
-
const lines = [rule(label, width)];
|
|
122
|
+
const lines = [transcriptLine(rule(label, width))];
|
|
105
123
|
if (body.trim().length > 0)
|
|
106
124
|
lines.push(...prefixLines(body.trimEnd(), " ", width, color));
|
|
107
125
|
return lines;
|
|
@@ -113,23 +131,26 @@ function toolResultLines(message, width, expanded) {
|
|
|
113
131
|
const body = blockText(message.content).replace(/\s+/g, " ").trim();
|
|
114
132
|
const summary = body.length > 140 ? `${body.slice(0, 139)}…` : body;
|
|
115
133
|
const head = fg(` ↳ ${mark} ${name}${ms}`, message.isError === true ? RED : GREEN);
|
|
116
|
-
const lines = [truncateToWidth(`${head}${summary.length === 0 ? "" : dim(` ${summary}`)}`, width, "")];
|
|
134
|
+
const lines = [transcriptLine(truncateToWidth(`${head}${summary.length === 0 ? "" : dim(` ${summary}`)}`, width, ""), 6)];
|
|
117
135
|
if (expanded) {
|
|
118
136
|
const indent = " ".repeat(Math.min(10, width - 1));
|
|
119
137
|
const full = blockText(message.content).trimEnd();
|
|
120
138
|
const shown = full.split("\n").slice(0, 12);
|
|
121
139
|
for (const line of shown) {
|
|
122
140
|
for (const wrapped of wrapTextWithAnsi(line, width - indent.length)) {
|
|
123
|
-
lines.push(dim(`${indent}${wrapped}`));
|
|
141
|
+
lines.push(transcriptLine(dim(`${indent}${wrapped}`), indent.length));
|
|
124
142
|
}
|
|
125
143
|
}
|
|
126
144
|
if (full.split("\n").length > shown.length)
|
|
127
|
-
lines.push(dim(`${indent}…`));
|
|
145
|
+
lines.push(transcriptLine(dim(`${indent}…`), indent.length));
|
|
128
146
|
}
|
|
129
147
|
return lines;
|
|
130
148
|
}
|
|
131
149
|
/** One immutable transcript entry to display lines. */
|
|
132
150
|
export function formatEntry(entry, options) {
|
|
151
|
+
return formatEntryLines(entry, options).map((line) => line.text);
|
|
152
|
+
}
|
|
153
|
+
export function formatEntryLines(entry, options) {
|
|
133
154
|
const width = Math.max(8, options.width);
|
|
134
155
|
const messages = (entry.model ?? []);
|
|
135
156
|
if (entry.kind === "pi.user") {
|
|
@@ -142,7 +163,7 @@ export function formatEntry(entry, options) {
|
|
|
142
163
|
if (text.length > 0)
|
|
143
164
|
lines.push(...prefixLines(text, " ai ", width, GREEN));
|
|
144
165
|
if (message.stopReason === "aborted" && text.length === 0)
|
|
145
|
-
lines.push(fg(" [aborted attempt]", MUTED, { dim: true }));
|
|
166
|
+
lines.push(transcriptLine(fg(" [aborted attempt]", MUTED, { dim: true }), 6));
|
|
146
167
|
}
|
|
147
168
|
return lines;
|
|
148
169
|
}
|
|
@@ -158,7 +179,7 @@ export function formatEntry(entry, options) {
|
|
|
158
179
|
return ruleWithText("compacted context", options.toolsExpanded ? summary : "summary retained in history", width, MUTED);
|
|
159
180
|
}
|
|
160
181
|
if (entry.kind === "pi.system") {
|
|
161
|
-
return options.showSystem === true ? [dim(truncateToWidth("── system prompt updated", width, ""))] : [];
|
|
182
|
+
return options.showSystem === true ? [transcriptLine(dim(truncateToWidth("── system prompt updated", width, "")))] : [];
|
|
162
183
|
}
|
|
163
184
|
if (entry.kind === "app.job-handoff") {
|
|
164
185
|
const data = entry.data;
|
|
@@ -170,15 +191,18 @@ export function formatEntry(entry, options) {
|
|
|
170
191
|
const body = messages.map((message) => blockText(message.content)).join(" ").replace(/^\[host\]\s*/, "").trim();
|
|
171
192
|
const lines = ruleWithText(`host · job #${data?.taskId ?? "?"} ${data?.phase ?? "notice"}`, body, width, MUTED);
|
|
172
193
|
if (body.length > 0)
|
|
173
|
-
lines.splice(1, 0, "");
|
|
194
|
+
lines.splice(1, 0, transcriptLine(""));
|
|
174
195
|
return lines;
|
|
175
196
|
}
|
|
176
197
|
if (entry.kind.startsWith("app."))
|
|
177
198
|
return [];
|
|
178
|
-
return options.showSystem === true ? [dim(truncateToWidth(`── ${entry.kind}`, width, ""))] : [];
|
|
199
|
+
return options.showSystem === true ? [transcriptLine(dim(truncateToWidth(`── ${entry.kind}`, width, "")))] : [];
|
|
179
200
|
}
|
|
180
201
|
/** Streaming partial answer and tool slots below the committed transcript. */
|
|
181
202
|
export function formatLive(live, width) {
|
|
203
|
+
return formatLiveLines(live, width).map((line) => line.text);
|
|
204
|
+
}
|
|
205
|
+
export function formatLiveLines(live, width) {
|
|
182
206
|
if (live === undefined)
|
|
183
207
|
return [];
|
|
184
208
|
const lines = [];
|
|
@@ -189,11 +213,11 @@ export function formatLive(live, width) {
|
|
|
189
213
|
const active = (live.tools ?? []).filter((slot) => slot.status !== "done").slice(0, 8);
|
|
190
214
|
for (const slot of active) {
|
|
191
215
|
const status = slot.status ?? "pending";
|
|
192
|
-
lines.push(fg(` ${status === "running" ? "▸" : "·"} ${slot.name ?? "tool"} ${status}`, YELLOW));
|
|
216
|
+
lines.push(transcriptLine(fg(` ${status === "running" ? "▸" : "·"} ${slot.name ?? "tool"} ${status}`, YELLOW), 2));
|
|
193
217
|
}
|
|
194
218
|
if (live.runFailure !== undefined) {
|
|
195
219
|
const detail = live.runFailure.detail === undefined ? "" : `: ${live.runFailure.detail}`;
|
|
196
|
-
lines.push(fg(` run failed: ${live.runFailure.reason ?? "unknown"}${detail}`, RED));
|
|
220
|
+
lines.push(transcriptLine(fg(` run failed: ${live.runFailure.reason ?? "unknown"}${detail}`, RED), 2));
|
|
197
221
|
}
|
|
198
222
|
return lines;
|
|
199
223
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { Markdown, stripTerminalSequences, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
const osc8 = /\x1b\]8;[^;\x1b\x07]*;([^\x1b\x07]*)(?:\x1b\\|\x07)/g;
|
|
4
|
+
/**
|
|
5
|
+
* Theme callbacks identify actual code, not characters that happen to look like rails.
|
|
6
|
+
* OSC 8 annotations survive the toolkit's nested wrapping (including quotes/lists).
|
|
7
|
+
* Real OSC 8 events inside them travel as opaque APC markers: otherwise a real link
|
|
8
|
+
* would replace the annotation in the toolkit's single (NOT stacked) hyperlink state,
|
|
9
|
+
* and its empty close would be indistinguishable from the annotation's close.
|
|
10
|
+
* Both transports are consumed BEFORE rows reach display or link hit testing.
|
|
11
|
+
*/
|
|
12
|
+
export function renderCopyableMarkdown(text, width, theme, style) {
|
|
13
|
+
// No user-authored URL or control sequence can be mistaken for this render's metadata.
|
|
14
|
+
let namespace;
|
|
15
|
+
do {
|
|
16
|
+
namespace = `dchat-internal-code:${randomUUID()}:`;
|
|
17
|
+
} while (text.includes(namespace));
|
|
18
|
+
const sources = [];
|
|
19
|
+
const annotations = new Map();
|
|
20
|
+
const links = new Map();
|
|
21
|
+
const annotate = (value, rendered, border = false) => {
|
|
22
|
+
const id = sources.push({ text: stripTerminalSequences(value), border }) - 1;
|
|
23
|
+
const url = `${namespace}${id}`;
|
|
24
|
+
annotations.set(url, id);
|
|
25
|
+
const shielded = rendered.replace(osc8, (sequence, url) => {
|
|
26
|
+
const marker = `\x1b_${namespace}link:${links.size}\x1b\\`;
|
|
27
|
+
links.set(marker, { sequence, close: url ? `\x1b]8;;${sequence.endsWith("\x07") ? "\x07" : "\x1b\\"}` : undefined });
|
|
28
|
+
return marker;
|
|
29
|
+
});
|
|
30
|
+
return `\x1b]8;;${url}\x1b\\${shielded}\x1b]8;;\x1b\\`;
|
|
31
|
+
};
|
|
32
|
+
const markdown = new Markdown(text, 0, 0, {
|
|
33
|
+
...theme,
|
|
34
|
+
codeBlock: (value) => annotate(value, theme.codeBlock(value)),
|
|
35
|
+
codeBlockBorder: (value) => annotate(value, theme.codeBlockBorder(value), true),
|
|
36
|
+
}, style, { renderLatex: false });
|
|
37
|
+
let previous;
|
|
38
|
+
let link;
|
|
39
|
+
return markdown.render(width).map((line) => {
|
|
40
|
+
let code;
|
|
41
|
+
let copyStart;
|
|
42
|
+
let copyEnd;
|
|
43
|
+
let copySkip = false;
|
|
44
|
+
let active;
|
|
45
|
+
let cleaned = "";
|
|
46
|
+
let cursor = 0;
|
|
47
|
+
for (const match of line.matchAll(/\x1b(?:\]8;[^;\x1b\x07]*;([^\x1b\x07]*)|_[^\x1b\x07]*)(?:\x1b\\|\x07)/g)) {
|
|
48
|
+
cleaned += line.slice(cursor, match.index);
|
|
49
|
+
const id = annotations.get(match[1]);
|
|
50
|
+
const original = links.get(match[0]);
|
|
51
|
+
if (id !== undefined) {
|
|
52
|
+
active = { id, column: visibleWidth(cleaned), offset: cleaned.length };
|
|
53
|
+
if (previous?.id !== id)
|
|
54
|
+
link = undefined;
|
|
55
|
+
// Reopen only inside code bounds, never over the quote/list rail.
|
|
56
|
+
if (link)
|
|
57
|
+
cleaned += link.sequence;
|
|
58
|
+
}
|
|
59
|
+
else if (active && original) {
|
|
60
|
+
cleaned += original.sequence;
|
|
61
|
+
link = original.close ? { sequence: original.sequence, close: original.close } : undefined;
|
|
62
|
+
}
|
|
63
|
+
else if (active && match[1] === "") {
|
|
64
|
+
const source = sources[active.id];
|
|
65
|
+
const fragment = stripTerminalSequences(cleaned.slice(active.offset));
|
|
66
|
+
const continues = previous?.id === active.id;
|
|
67
|
+
const start = source.text.indexOf(fragment, continues ? previous.end : 0);
|
|
68
|
+
if (source.border)
|
|
69
|
+
copySkip = true;
|
|
70
|
+
else {
|
|
71
|
+
copyStart = active.column;
|
|
72
|
+
copyEnd = copyStart + visibleWidth(fragment);
|
|
73
|
+
// If the toolkit transforms a fragment unexpectedly, retain code-only
|
|
74
|
+
// bounds but fall back to rendered rows instead of guessing a source range.
|
|
75
|
+
if (start >= 0)
|
|
76
|
+
code = { source: source.text, start, end: start + fragment.length, continues };
|
|
77
|
+
}
|
|
78
|
+
previous = source.border || start < 0 ? undefined : { id: active.id, end: start + fragment.length };
|
|
79
|
+
// The toolkit closed the annotation, not the shielded user hyperlink.
|
|
80
|
+
// Balance the latter on each physical row; retain its logical state for wraps.
|
|
81
|
+
if (link)
|
|
82
|
+
cleaned += link.close;
|
|
83
|
+
active = undefined;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
cleaned += match[0];
|
|
87
|
+
}
|
|
88
|
+
cursor = match.index + match[0].length;
|
|
89
|
+
}
|
|
90
|
+
cleaned += line.slice(cursor);
|
|
91
|
+
if (!code) {
|
|
92
|
+
previous = undefined;
|
|
93
|
+
link = undefined;
|
|
94
|
+
}
|
|
95
|
+
return { text: cleaned, code, copyStart, copyEnd, copySkip };
|
|
96
|
+
});
|
|
97
|
+
}
|
package/dist/tui/selection.js
CHANGED
|
@@ -28,7 +28,14 @@ export class TranscriptSelection {
|
|
|
28
28
|
update(frame) {
|
|
29
29
|
const old = this.frame;
|
|
30
30
|
if (!old || !frame || old.source !== frame.source || old.x !== frame.x || old.y !== frame.y || old.width !== frame.width
|
|
31
|
-
|| old.lines.length !== frame.lines.length || old.lines.some((line, index) => line !== frame.lines[index])
|
|
31
|
+
|| old.lines.length !== frame.lines.length || old.lines.some((line, index) => line !== frame.lines[index])
|
|
32
|
+
|| old.copyBounds.length !== frame.copyBounds.length
|
|
33
|
+
|| old.copyBounds.some((bounds, index) => {
|
|
34
|
+
const next = frame.copyBounds[index];
|
|
35
|
+
return bounds.copyStart !== next?.copyStart || bounds.copyEnd !== next?.copyEnd || bounds.copySkip !== next?.copySkip
|
|
36
|
+
|| bounds.code?.source !== next?.code?.source || bounds.code?.start !== next?.code?.start
|
|
37
|
+
|| bounds.code?.end !== next?.code?.end || bounds.code?.continues !== next?.code?.continues;
|
|
38
|
+
}))
|
|
32
39
|
this.reset();
|
|
33
40
|
this.frame = frame;
|
|
34
41
|
}
|
|
@@ -70,10 +77,43 @@ export class TranscriptSelection {
|
|
|
70
77
|
}) ?? [];
|
|
71
78
|
}
|
|
72
79
|
async copySelection() {
|
|
73
|
-
|
|
80
|
+
let text = "";
|
|
81
|
+
let selectedRows = 0;
|
|
82
|
+
let previousCodeEnd;
|
|
83
|
+
for (const [row, line] of this.frame.lines.entries()) {
|
|
74
84
|
const columns = this.columns(row);
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
if (!columns)
|
|
86
|
+
continue;
|
|
87
|
+
const bounds = this.frame.copyBounds[row];
|
|
88
|
+
if (bounds?.copySkip) {
|
|
89
|
+
previousCodeEnd = undefined;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const start = Math.max(bounds?.copyStart ?? 0, Math.min(columns.start, bounds?.copyEnd ?? 0));
|
|
93
|
+
const end = Math.max(start, Math.min(columns.end, bounds?.copyEnd ?? 0));
|
|
94
|
+
const fragment = stripTerminalSequences(sliceByColumn(line, start, end - start));
|
|
95
|
+
const code = bounds?.code;
|
|
96
|
+
if (code) {
|
|
97
|
+
const offset = stripTerminalSequences(sliceByColumn(line, bounds.copyStart, start - bounds.copyStart)).length;
|
|
98
|
+
const sourceStart = code.start + offset;
|
|
99
|
+
const sourceEnd = sourceStart + fragment.length;
|
|
100
|
+
// Only semantic continuations join. Restore whitespace dropped by word wrapping
|
|
101
|
+
// from the toolkit's code source, never by guessing from rail characters.
|
|
102
|
+
if (code.continues && previousCodeEnd !== undefined)
|
|
103
|
+
text += code.source.slice(previousCodeEnd, sourceStart);
|
|
104
|
+
else if (selectedRows > 0)
|
|
105
|
+
text += "\n";
|
|
106
|
+
text += code.source.slice(sourceStart, sourceEnd);
|
|
107
|
+
previousCodeEnd = sourceEnd;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
if (selectedRows > 0)
|
|
111
|
+
text += "\n";
|
|
112
|
+
text += fragment;
|
|
113
|
+
previousCodeEnd = undefined;
|
|
114
|
+
}
|
|
115
|
+
selectedRows++;
|
|
116
|
+
}
|
|
77
117
|
if (!text)
|
|
78
118
|
return;
|
|
79
119
|
const version = this.version;
|
package/dist/tui/transcript.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { formatEntryLines, formatLiveLines, transcriptLine } from "./format.js";
|
|
2
2
|
import { estimateContextTokens } from "../context-usage.js";
|
|
3
3
|
const INITIAL_ENTRIES = 80;
|
|
4
4
|
const OLDER_ENTRIES = 60;
|
|
@@ -124,16 +124,16 @@ export class Transcript {
|
|
|
124
124
|
}
|
|
125
125
|
const lines = [];
|
|
126
126
|
for (const entry of this.entries) {
|
|
127
|
-
const formatted =
|
|
127
|
+
const formatted = formatEntryLines(entry, { width, toolsExpanded });
|
|
128
128
|
if (formatted.length > 0) {
|
|
129
|
-
lines.push(...formatted, "");
|
|
129
|
+
lines.push(...formatted, transcriptLine(""));
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
this.cache = { version: this.version, width, tools: toolsExpanded, lines };
|
|
133
133
|
return lines;
|
|
134
134
|
}
|
|
135
135
|
liveLines(width) {
|
|
136
|
-
return
|
|
136
|
+
return formatLiveLines(this.live, width);
|
|
137
137
|
}
|
|
138
138
|
get modelCount() {
|
|
139
139
|
const usage = this.usage;
|
package/package.json
CHANGED