durable-chat 1.0.0 → 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 +95 -17
- package/dist/config.js +10 -1
- package/dist/jobs.js +34 -1
- package/dist/tool.js +5 -27
- package/dist/tui/app.js +294 -165
- package/dist/tui/clipboard.js +78 -0
- package/dist/tui/composer.js +53 -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
|
@@ -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
|
|
|
@@ -287,6 +290,24 @@ the summary placement. A short conversation, or one with no selectable old prefi
|
|
|
287
290
|
The default interface is a three-pane dashboard: jobs on the left, the selected conversation in the
|
|
288
291
|
middle, and live context on the right. The composer sends to `main` by default; open a job to target it.
|
|
289
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
|
+
|
|
290
311
|
The mouse wheel, Magic Mouse and trackpad scroll the pane under the pointer, keeping keyboard focus,
|
|
291
312
|
the composer draft and the selected job unchanged. Pane headings stay fixed; keyboard job navigation
|
|
292
313
|
brings the selection back into view. Alt+wheel scrolls faster.
|
|
@@ -295,6 +316,23 @@ Command-click transcript URLs on macOS (Ctrl-click in terminals that use that mo
|
|
|
295
316
|
in the default browser. Markdown links and bare URLs keep their complete destinations when wrapped.
|
|
296
317
|
Clicks routed to the app also open web links; dragging across a link still selects text.
|
|
297
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
|
+
|
|
298
336
|
The terminal title includes the launch folder, for example `durable-chat — ~/projects/example`.
|
|
299
337
|
The previous title is restored on startup failure or exit using the terminal's title stack.
|
|
300
338
|
Folders outside home remain absolute. Allow program-controlled titles in your terminal; Ghostty's
|
|
@@ -309,7 +347,7 @@ Folders outside home remain absolute. Allow program-controlled titles in your te
|
|
|
309
347
|
│ #10 failed │ │ tokens: 18.2k │
|
|
310
348
|
├──────────────────────┴───────────────────────────────┴──────────────────────┤
|
|
311
349
|
│ to main › _ │
|
|
312
|
-
│ ENTER send ·
|
|
350
|
+
│ ENTER send · ? help · TAB focus · SHIFT-ENTER newline │
|
|
313
351
|
└──────────────────────────────────────────────────────────────────────────────┘
|
|
314
352
|
```
|
|
315
353
|
|
|
@@ -318,24 +356,30 @@ Folders outside home remain absolute. Allow program-controlled titles in your te
|
|
|
318
356
|
| `Tab` / `Shift-Tab` | cycle composer → jobs → transcript |
|
|
319
357
|
| `Ctrl-T` | switch composer target main ↔ selected job |
|
|
320
358
|
| `Ctrl-N` | new job brief |
|
|
321
|
-
| `
|
|
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) |
|
|
322
361
|
| `Ctrl-V` | paste an image into the composer (main only) |
|
|
323
|
-
| `Enter` | send,
|
|
324
|
-
| `
|
|
362
|
+
| `Enter` | send, or pin the highlighted job and focus the composer; confirm prompts |
|
|
363
|
+
| `Shift-Enter` | insert a newline in the composer (`Ctrl-J` or `Alt-Enter` fallback) |
|
|
364
|
+
| `↑/↓` or `j/k`, `g/G`, `PgUp/PgDn` | move selection or scroll outside the composer |
|
|
325
365
|
| Mouse wheel / trackpad | scroll the pane under the pointer without moving keyboard focus |
|
|
326
366
|
| Cmd-click / Ctrl-click | open transcript links using the terminal's link modifier |
|
|
327
367
|
| `n / c / m / R` | new job · cancel · compact · reset (selected target) |
|
|
328
|
-
| `s / t / f / y` |
|
|
368
|
+
| `s / t / f / y` | compose (jobs: pin highlighted job) · expand tools · show finished · copy |
|
|
329
369
|
| `/` | start a slash command in the composer; filter jobs when focus is on jobs/transcript |
|
|
330
370
|
| `[` / `]` | shrink / grow the jobs pane |
|
|
331
|
-
| `{` / `}` | shrink / grow the context pane (
|
|
371
|
+
| `{` / `}` | shrink / grow the context pane when there is room (does not enable a hidden pane) |
|
|
332
372
|
| `0` | reset pane widths |
|
|
333
373
|
| `i` | inspector (config, MCP notes, usage); `e` edits the config |
|
|
334
374
|
| `a` | abort the main run (jobs survive) |
|
|
335
|
-
| `?` | help |
|
|
375
|
+
| `?` | full help outside the composer or with an empty draft; `Tab` then `?` preserves a draft |
|
|
336
376
|
| `Ctrl-C` | stop waiting / clear the prompt / close an overlay; arms quitting for 1.5 seconds |
|
|
337
377
|
| `Ctrl-C` twice | quit; small floating confirmation over the dashboard while live work exists |
|
|
338
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
|
+
|
|
339
383
|
`Ctrl-V` attaches an image to the next message to main. It reads the native clipboard (macOS and
|
|
340
384
|
Windows prebuilds, Linux with X11); `/image <path>` is the fallback where that helper is unavailable.
|
|
341
385
|
Images are prepared with Photon on a worker thread to the model's image limits, and paste is refused
|
|
@@ -346,10 +390,23 @@ Transcript prose supports lightweight Markdown: headings, emphasis, lists, links
|
|
|
346
390
|
blocks, including streaming replies. Tool output stays literal; code blocks use plain styling without
|
|
347
391
|
syntax highlighting. The plain-chat interface is unchanged.
|
|
348
392
|
|
|
349
|
-
The composer
|
|
393
|
+
The multiline composer grows from a dark-grey three-row background and scrolls longer drafts while
|
|
394
|
+
keeping the cursor visible. **Shift-Enter inserts a line break; plain Enter sends.** If your terminal
|
|
395
|
+
does not distinguish Shift-Enter from Enter, use **Ctrl-J** (or Alt-Enter) to insert a newline instead.
|
|
396
|
+
Arrow keys navigate the draft; Backspace/Delete can join lines. Bracketed text pastes keep actual
|
|
397
|
+
line breaks (CRLF and CR normalize to LF) without sending. Large pastes appear as folded paste
|
|
398
|
+
markers; their complete text, not the marker, is sent. Visual wrapping adds no newline characters,
|
|
399
|
+
and text copied without line breaks cannot have its original layout reconstructed.
|
|
350
400
|
Pane headings, the target/status line, and individual jobs have spacer rows; the transcript has a solid
|
|
351
|
-
black background.
|
|
352
|
-
|
|
401
|
+
black background. Tab to jobs, then Up/Down (or `j/k`) to preview the highlighted job's latest transcript
|
|
402
|
+
and live updates without pressing Enter. `g/G` preview the first/last row. Previewing never changes the
|
|
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.
|
|
408
|
+
While targeting `main`, newly arriving jobs are highlighted automatically unless you are browsing a
|
|
409
|
+
preview. Returning to `main` selects the newest visible job; manual browsing and pinned targets are
|
|
353
410
|
preserved. A single `Ctrl-C` clears the input or stops waiting as before; a second consecutive press
|
|
354
411
|
within 1.5 seconds requests quit. Typing, navigation, or expiry resets that sequence. Live work still
|
|
355
412
|
gets the floating confirmation; `Ctrl-Q` is no longer a quit shortcut.
|
|
@@ -363,9 +420,29 @@ Jobs run in the background and main stays usable. The TUI is the single store wr
|
|
|
363
420
|
jobs, and the next run resumes them. `durable-chat --plain` or `durable-chat chat` is the old
|
|
364
421
|
line-oriented interface over the same runtime.
|
|
365
422
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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`.
|
|
369
446
|
|
|
370
447
|
Starting a job from the TUI or `task add` writes a native, model-visible `[host]` start notice into
|
|
371
448
|
main's conversation. Every job reports completion, failure, or abort as a native follow-up input by
|
|
@@ -430,6 +507,7 @@ Inside the plain chat or TUI composer:
|
|
|
430
507
|
/model [id] pick the session-wide model, across configured providers
|
|
431
508
|
/provider [name] list configured providers, or make one active for this session
|
|
432
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
|
|
433
511
|
/image <path> attach an image to the next message to main
|
|
434
512
|
/reboot archive all app state and start a fresh database (confirmation required)
|
|
435
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") {
|