pi-durable-subagents 1.0.42 → 1.0.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/README.md +90 -8
- package/dist/agent/main/schema.js +6 -2
- package/dist/agent/main/snapshots.js +74 -5
- package/dist/agent/main/tool.js +21 -8
- package/dist/agent/main.js +10 -12
- package/dist/cli/control.js +20 -10
- package/dist/cli/main.js +5 -3
- package/dist/cli/requests.js +70 -34
- package/dist/compat/fanout.js +13 -5
- package/dist/compat/spec.js +46 -1
- package/dist/events/fence.js +2 -0
- package/dist/events/waiting.js +25 -3
- package/dist/kernel/journal.js +114 -25
- package/dist/kernel/lifecycle.js +66 -23
- package/dist/kernel/mailbox.js +49 -32
- package/dist/kernel/overlay.js +47 -0
- package/dist/orchestrator/engine.js +175 -41
- package/dist/orchestrator/executor/command.js +54 -0
- package/dist/orchestrator/executor/index.js +360 -8
- package/dist/orchestrator/executor/sweep.js +40 -24
- package/dist/orchestrator/ledger.js +4 -1
- package/dist/orchestrator/main.js +4 -2
- package/dist/orchestrator/providers.js +2 -0
- package/dist/orchestrator/reader-ledger.js +13 -3
- package/dist/orchestrator/restart.js +4 -1
- package/dist/orchestrator/settled.js +14 -2
- package/dist/orchestrator/snapshot.js +88 -9
- package/dist/orchestrator/store.js +133 -33
- package/dist/platform/command.js +98 -0
- package/dist/platform/launch.js +13 -3
- package/dist/requests.js +41 -5
- package/dist/types.js +2 -0
- package/dist/ui/screen.js +62 -13
- package/dist/ui/tool.js +8 -4
- package/dist/ui/view.js +18 -7
- package/package.json +1 -1
package/dist/platform/launch.js
CHANGED
|
@@ -100,15 +100,25 @@ export async function scopeRunner(env, options = {}) {
|
|
|
100
100
|
function started(child) {
|
|
101
101
|
return new Promise((resolve, reject) => { child.once("spawn", resolve); child.once("error", reject); });
|
|
102
102
|
}
|
|
103
|
+
/** The variables the executor sets for one call's processes (a subagent, a command call, a gate). An orchestrator
|
|
104
|
+
* started from inside a call (its CLI, a command that runs `start`) never carries them: with the call's DSA_EXEC it
|
|
105
|
+
* would be one of that call's processes, and the call's fence (its end, a stop) would kill it. */
|
|
106
|
+
export const PER_CALL_ENV = ["DSA_SESSION", "DSA_EXEC", "DSA_CALL", "DSA_INBOX", "DSA_JOURNAL", "DSA_SCHEMA", "DSA_BUDGET", "DSA_MODEL", "DSA_RESULT", "DSA_OUTPUT", "DSA_PROBE"];
|
|
107
|
+
/** `env` without PER_CALL_ENV. */
|
|
108
|
+
export function orchestratorEnv(env) {
|
|
109
|
+
const rest = { ...env };
|
|
110
|
+
for (const name of PER_CALL_ENV)
|
|
111
|
+
delete rest[name];
|
|
112
|
+
return rest;
|
|
113
|
+
}
|
|
103
114
|
/** Start the orchestrator at `entry`, detached, with `env` minus the starting session's DSA_SESSION (it serves every
|
|
104
|
-
* session) plus DSA_HOME and the resolved DSA_PI_BIN. In its own systemd scope when one is available (the scope execs
|
|
115
|
+
* session) and every other per-call variable (PER_CALL_ENV) plus DSA_HOME and the resolved DSA_PI_BIN. In its own systemd scope when one is available (the scope execs
|
|
105
116
|
* the command: same environment, and the pid is the orchestrator's), else a plain detached process. */
|
|
106
117
|
export async function launchOrchestrator(entry, env, options) {
|
|
107
118
|
const pi = resolvePi(env);
|
|
108
119
|
if (!pi.path && options.requirePi)
|
|
109
120
|
throw new PiNotFound(pi.problem);
|
|
110
|
-
const {
|
|
111
|
-
const childEnv = { ...rest, DSA_HOME: options.home, ...(pi.path ? { DSA_PI_BIN: pi.path } : {}) };
|
|
121
|
+
const childEnv = { ...orchestratorEnv(env), DSA_HOME: options.home, ...(pi.path ? { DSA_PI_BIN: pi.path } : {}) };
|
|
112
122
|
const node = options.node ?? process.execPath, run = options.spawn ?? spawn;
|
|
113
123
|
const runner = await scopeRunner(env, options);
|
|
114
124
|
if (runner) {
|
package/dist/requests.js
CHANGED
|
@@ -7,7 +7,7 @@ import { readdir } from 'node:fs/promises';
|
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
9
9
|
import { contentHash } from "./kernel/ids.js";
|
|
10
|
-
import {
|
|
10
|
+
import { readJournalFold } from "./kernel/journal.js";
|
|
11
11
|
import { publishRequest } from "./kernel/mailbox.js";
|
|
12
12
|
import { OsLock } from "./platform/lock.js";
|
|
13
13
|
import { orchInbox, orchLedger, outboxRoot } from "./paths.js";
|
|
@@ -65,17 +65,53 @@ export function specDigest(req) {
|
|
|
65
65
|
}
|
|
66
66
|
return contentHash({ kind: req.kind, body, cond: req.cond });
|
|
67
67
|
}
|
|
68
|
+
// Repeated request checks verify the same immutable prefixes, including on either side of a lock. Retain only
|
|
69
|
+
// negative positions, never envelopes: every check still stats the file and folds fresh appended bytes. The bound
|
|
70
|
+
// counts files, not hinted IDs: one hinted lookup cannot evict its earlier files within the file budget.
|
|
71
|
+
const misses = new Map(), MISS_FILES = 1024, MISS_IDS = 64;
|
|
72
|
+
function requestIn(path, rid, type, related, touched) {
|
|
73
|
+
const probes = [...new Set([rid, ...related])].slice(0, MISS_IDS), key = JSON.stringify([path, type]);
|
|
74
|
+
touched.add(key);
|
|
75
|
+
const known = misses.get(key);
|
|
76
|
+
misses.delete(key); // A failed read must not retain a partially extended prefix or absence set.
|
|
77
|
+
const reusable = known && probes.every(id => known.state.has(id));
|
|
78
|
+
// Watch every cached absent ID while extending: otherwise an appended envelope could invalidate an older hint.
|
|
79
|
+
const watched = new Set(reusable ? known.state : probes);
|
|
80
|
+
let found;
|
|
81
|
+
const record = readJournalFold(path, reusable ? { ...known, state: watched } : undefined, () => watched, (absent, entry) => {
|
|
82
|
+
if (entry.type !== type)
|
|
83
|
+
return;
|
|
84
|
+
const id = entry.request.rid;
|
|
85
|
+
absent.delete(id);
|
|
86
|
+
if (!found && id === rid)
|
|
87
|
+
found = entry;
|
|
88
|
+
}, { needles: [...watched].map(id => JSON.stringify(id)) });
|
|
89
|
+
// Keep positions and absent IDs only, never the found envelope. Torn tails cannot be cached: a repair may
|
|
90
|
+
// commit a line at the same inode/size. Each future check still stats and folds freshly appended bytes.
|
|
91
|
+
if (record && record.length === record.size && record.state.size) {
|
|
92
|
+
if (misses.size >= MISS_FILES) {
|
|
93
|
+
// More files than the budget: omit later positions rather than evict this lookup's earliest files.
|
|
94
|
+
const evict = [...misses.keys()].find(candidate => !touched.has(candidate));
|
|
95
|
+
if (evict !== undefined)
|
|
96
|
+
misses.delete(evict);
|
|
97
|
+
}
|
|
98
|
+
if (misses.size < MISS_FILES)
|
|
99
|
+
misses.set(key, record);
|
|
100
|
+
}
|
|
101
|
+
return found;
|
|
102
|
+
}
|
|
68
103
|
/** The envelope recorded for `rid`: the orchestrator's admitted copy (ledger `request`, kept after prune), else any
|
|
69
|
-
* sender's outbox `sent` entry (published or about to be). Read-only.
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
* sender's outbox `sent` entry (published or about to be). Read-only. Related IDs are only hints for sharing a
|
|
105
|
+
* verified negative prefix; their eventual lookups still read fresh state and preserve first-match/file order. */
|
|
106
|
+
export async function findRequest(home, rid, related = []) {
|
|
107
|
+
const touched = new Set(), admitted = requestIn(orchLedger(home), rid, 'request', related, touched);
|
|
72
108
|
if (admitted)
|
|
73
109
|
return { request: admitted.request, admitted: true };
|
|
74
110
|
const dir = join(outboxRoot(home), 'outbox');
|
|
75
111
|
const names = await readdir(dir).catch(error => { if (error.code === 'ENOENT')
|
|
76
112
|
return []; throw error; });
|
|
77
113
|
for (const name of names.filter(n => n.endsWith('.jsonl')).sort()) {
|
|
78
|
-
const sent =
|
|
114
|
+
const sent = requestIn(join(dir, name), rid, 'sent', related, touched);
|
|
79
115
|
if (sent)
|
|
80
116
|
return { request: sent.request, admitted: false };
|
|
81
117
|
}
|
package/dist/types.js
CHANGED
|
@@ -56,6 +56,8 @@ export const JT = {
|
|
|
56
56
|
rejected: "rejected",
|
|
57
57
|
withdrawn: "withdrawn",
|
|
58
58
|
};
|
|
59
|
+
/** A command call (CallSpec.command): no agent, task or model at runtime even though the type declares them. */
|
|
60
|
+
export const isCommandCall = (spec) => spec?.command !== undefined;
|
|
59
61
|
// ---------------------------------------------------------------------------
|
|
60
62
|
// Environment variables passed to children (child session agent reads them)
|
|
61
63
|
// ---------------------------------------------------------------------------
|
package/dist/ui/screen.js
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
import { AssistantMessageComponent, UserMessageComponent, ToolExecutionComponent, getMarkdownTheme, getSelectListTheme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { Input, SelectList, fuzzyFilter, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import { Input, SelectList, fuzzyFilter, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
3
|
import { CT } from "../types.js";
|
|
4
4
|
import { UiActions, UiData } from "./data.js";
|
|
5
|
-
import { callName, workflowName, doneOrder, isOpen, plainReason, toggleOpen, duration, keepSelection, summaryText, listRows, modelLabel, pendingText, resultPhrase, statusPhrase, rowText, toolCount } from "./view.js";
|
|
5
|
+
import { callName, workflowName, doneOrder, isOpen, plainReason, toggleOpen, duration, keepSelection, summaryText, listRows, modelColumn, modelLabel, pendingText, resultPhrase, statusPhrase, rowText, toolCount } from "./view.js";
|
|
6
6
|
import { fitWidth, frame, inner } from "./frame.js";
|
|
7
7
|
import { thinkingElapsed } from "./thinking.js";
|
|
8
8
|
import { thoughtSummary } from "./session.js";
|
|
9
9
|
const levels = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
10
|
+
/** A command call runs a process: it takes no message and no model; only stop controls it. */
|
|
11
|
+
const isCommand = (c) => c?.command !== undefined;
|
|
12
|
+
const COMMAND_NOTE = "a command call takes no messages or model; x or /stop stops it";
|
|
13
|
+
/** The watch view's second head line of a command call: "running · pid 123 · 2m05s · <log>" / "failed · exit 3 · 41s". */
|
|
14
|
+
export function commandHead(c, w, now) {
|
|
15
|
+
const r = c.result, data = r?.data, log = c.commandRun?.log;
|
|
16
|
+
const ended = r ? [r.status, typeof data?.exitCode === "number" ? `exit ${data.exitCode}` : typeof data?.signal === "string" ? data.signal : "",
|
|
17
|
+
typeof data?.durationMs === "number" ? duration(data.durationMs) : ""] : [statusPhrase(c, w, undefined, now)];
|
|
18
|
+
return [...ended, log ?? ""].filter(Boolean).join(" · ");
|
|
19
|
+
}
|
|
20
|
+
/** The watch view's body of a command call: the whole command, then its result's output (the last 16 KiB of its log)
|
|
21
|
+
* once it ended, else where its output goes. */
|
|
22
|
+
export function commandTranscript(c, w, now) {
|
|
23
|
+
const lines = [`$ ${c.command ?? ""}`, ""];
|
|
24
|
+
if (c.result) {
|
|
25
|
+
if (c.result.error)
|
|
26
|
+
lines.push(c.result.error, "");
|
|
27
|
+
lines.push(...(c.result.output ? c.result.output.replace(/\n+$/, "").split("\n") : ["(no output)"]));
|
|
28
|
+
}
|
|
29
|
+
else if (c.phase === "queued")
|
|
30
|
+
lines.push(statusPhrase(c, w, undefined, now));
|
|
31
|
+
else
|
|
32
|
+
lines.push(`${statusPhrase(c, w, undefined, now)}${c.commandRun?.log ? `; output goes to ${c.commandRun.log}` : ""}`);
|
|
33
|
+
return lines;
|
|
34
|
+
}
|
|
35
|
+
/** One output line wrapped to the panel; control characters (also escape sequences a command printed) are dropped. */
|
|
36
|
+
const wrapLine = (line, width) => wrapTextWithAnsi(line.replace(/\t/g, " ").replace(/[\x00-\x08\x0b-\x1f\x7f]/g, ""), Math.max(1, width));
|
|
10
37
|
/** UI §2–3: A single pi component owns list/watch navigation while the main agent keeps running. */
|
|
11
38
|
const SPIN = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
12
39
|
export class SubagentScreen {
|
|
@@ -174,6 +201,13 @@ export class SubagentScreen {
|
|
|
174
201
|
const c = target ?? this.current().c;
|
|
175
202
|
if (!c)
|
|
176
203
|
return;
|
|
204
|
+
if (isCommand(c)) {
|
|
205
|
+
if (target)
|
|
206
|
+
this.listNotice = { text: COMMAND_NOTE, until: Date.now() + 5000 };
|
|
207
|
+
else
|
|
208
|
+
this.notice = COMMAND_NOTE;
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
177
211
|
this.menuTitle = `Model for ${c.key}`;
|
|
178
212
|
const models = this.ctx.modelRegistry.getAvailable();
|
|
179
213
|
this.menuItems = models.map(m => ({ value: `${m.provider}/${m.id}`, label: this.name(`${m.provider}/${m.id}`) }));
|
|
@@ -204,7 +238,7 @@ export class SubagentScreen {
|
|
|
204
238
|
}
|
|
205
239
|
thinkingMenu() {
|
|
206
240
|
const { c } = this.current();
|
|
207
|
-
if (!c)
|
|
241
|
+
if (!c || isCommand(c))
|
|
208
242
|
return;
|
|
209
243
|
const model = this.data.facts.get(c.callId)?.model ?? c.model;
|
|
210
244
|
if (!model)
|
|
@@ -224,6 +258,10 @@ export class SubagentScreen {
|
|
|
224
258
|
const { c } = this.current();
|
|
225
259
|
if (!c)
|
|
226
260
|
return;
|
|
261
|
+
if (isCommand(c)) {
|
|
262
|
+
this.notice = COMMAND_NOTE;
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
227
265
|
const facts = this.data.facts.get(c.callId), model = facts?.model ?? c.model;
|
|
228
266
|
if (!model) {
|
|
229
267
|
this.notice = "Model not yet recorded";
|
|
@@ -254,7 +292,11 @@ export class SubagentScreen {
|
|
|
254
292
|
return;
|
|
255
293
|
}
|
|
256
294
|
if (message.startsWith("/")) {
|
|
257
|
-
this.notice = "Commands: /model, /stop";
|
|
295
|
+
this.notice = isCommand(c) ? "Commands: /stop" : "Commands: /model, /stop";
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (isCommand(c)) {
|
|
299
|
+
this.notice = COMMAND_NOTE;
|
|
258
300
|
return;
|
|
259
301
|
}
|
|
260
302
|
const q = w.attention.find(a => a.kind === "question" && a.call === c.callId);
|
|
@@ -316,7 +358,9 @@ export class SubagentScreen {
|
|
|
316
358
|
else if (!this.busy) {
|
|
317
359
|
const row = this.selectedRow(), c = row?.kind === "call" ? row.call : undefined, w = row?.workflow;
|
|
318
360
|
const asking = c && w?.attention.some(a => a.kind === "question" && a.call === c.callId);
|
|
319
|
-
if (
|
|
361
|
+
if (isCommand(c) && "sfam".includes(key))
|
|
362
|
+
this.listNotice = { text: COMMAND_NOTE, until: Date.now() + 5000 };
|
|
363
|
+
else if (key === "s" && c && c.phase !== "sealed")
|
|
320
364
|
this.beginListInput("steer", row);
|
|
321
365
|
else if (key === "f" && c?.phase === "sealed")
|
|
322
366
|
this.beginListInput("follow-up", row);
|
|
@@ -379,7 +423,7 @@ export class SubagentScreen {
|
|
|
379
423
|
// Panel coordinates: row 0 is the top border, column 2 is the first content column.
|
|
380
424
|
if (event.y === 2) {
|
|
381
425
|
const { c, w } = this.current();
|
|
382
|
-
if (!c || !w)
|
|
426
|
+
if (!c || !w || isCommand(c))
|
|
383
427
|
return;
|
|
384
428
|
const facts = this.data.facts.get(c.callId), model = `${callName(w, c)} · ${this.name(facts?.model ?? c.model)} ▾ · `;
|
|
385
429
|
const x = event.x - 2;
|
|
@@ -403,6 +447,8 @@ export class SubagentScreen {
|
|
|
403
447
|
return this.input.handleMouse({ ...event, x: event.x - 2, y: 0 });
|
|
404
448
|
}
|
|
405
449
|
transcript(c, w, width) {
|
|
450
|
+
if (isCommand(c))
|
|
451
|
+
return { lines: commandTranscript(c, w, Date.now()).flatMap(line => line ? wrapLine(line, width) : [""]), thoughts: [] };
|
|
406
452
|
const entries = this.data.sessions.get(c.callId) ?? [], lines = [], thoughts = [];
|
|
407
453
|
const tools = new Map();
|
|
408
454
|
// A `{ thought }` part is an expanded thinking block: like pi, a click anywhere on it collapses it again.
|
|
@@ -532,7 +578,7 @@ export class SubagentScreen {
|
|
|
532
578
|
const rowWidth = Math.max(1, size.width - 2);
|
|
533
579
|
this.rows = this.doneTab && w ? doneOrder(w.calls).map(c => {
|
|
534
580
|
const f = this.data.facts.get(c.callId);
|
|
535
|
-
return { id: c.callId, kind: "call", workflow: w, call: c, failed: !c.result?.ok, text: rowText(" ", callName(w, c),
|
|
581
|
+
return { id: c.callId, kind: "call", workflow: w, call: c, failed: !c.result?.ok, text: rowText(" ", callName(w, c), modelColumn(c, f, this.name), resultPhrase(c), [toolCount(f?.tools)], rowWidth) };
|
|
536
582
|
}) : listRows(this.data.workflows, this.state, this.data.facts, this.name, rowWidth);
|
|
537
583
|
height = this.height(Math.max(1, this.rows.length) + footerRows);
|
|
538
584
|
size = inner(width, height); // inner width does not depend on height
|
|
@@ -549,10 +595,11 @@ export class SubagentScreen {
|
|
|
549
595
|
const row = this.selectedRow(), c = row?.kind === "call" ? row.call : undefined;
|
|
550
596
|
const asking = c && row?.workflow?.attention.some(a => a.kind === "question" && a.call === c.callId);
|
|
551
597
|
const narrow = size.width < 72;
|
|
598
|
+
const agent = c && !isCommand(c);
|
|
552
599
|
const keys = [narrow ? "↑↓" : "↑ ↓ select", row && row.kind !== "preview" ? `Enter ${narrow ? "" : row.kind === "workflow" ? (isOpen(row.workflow, this.state) ? "collapse" : "expand") : row.kind === "call" ? "watch" : "open"}`.trim() : "",
|
|
553
|
-
|
|
600
|
+
agent && c.phase !== "sealed" ? (narrow ? "s" : "s steer") : "", agent && c.phase === "sealed" ? (narrow ? "f" : "f follow-up") : "",
|
|
554
601
|
c && c.phase !== "sealed" || row?.kind === "workflow" && row.workflow?.status === "running" ? (narrow ? "x" : "x stop") : "",
|
|
555
|
-
|
|
602
|
+
agent ? (narrow ? "m" : "m model") : "", asking ? (narrow ? "a" : "a answer") : "", row?.workflow?.paused ? (narrow ? "r" : "r resume") : "", "Esc back"].filter(Boolean).join(" · ");
|
|
556
603
|
const notice = this.listNotice && this.listNotice.until > Date.now() ? this.listNotice.text : "";
|
|
557
604
|
const footer = this.listInput ? this.listInput.editor.render(size.width) : this.stopTarget ? [`Stop ${this.stopTarget.name}? y confirm · any other key cancels`] : notice ? [notice] : [];
|
|
558
605
|
const body = this.rows.length ? lines.slice(0, Math.max(0, size.height - footer.length)) : ["No subagents"];
|
|
@@ -567,14 +614,16 @@ export class SubagentScreen {
|
|
|
567
614
|
const tabs = size.width < 60 ? `${callName(w, c)} ${w.calls.indexOf(c) + 1}/${w.calls.length}` : `${[...active.map(c => callName(w, c)), ...(done ? [`${done} done`] : [])].join(" · ")} ← → switch`;
|
|
568
615
|
const tools = toolCount(facts?.tools), pending = pendingText(c.pending), rule = this.theme.fg("borderMuted", "─".repeat(size.width));
|
|
569
616
|
const switching = c.switching ? ` → ${this.name(c.switching)} (requested)` : "";
|
|
570
|
-
|
|
571
|
-
|
|
617
|
+
// A command call shows its command, process and log instead of a model, thinking level and spend.
|
|
618
|
+
const head = isCommand(c) ? [tabs, `${callName(w, c)} · ${modelColumn(c, facts, this.name)}`, this.theme.fg("dim", commandHead(c, w, Date.now())), rule]
|
|
619
|
+
: [tabs, `${callName(w, c)} · ${this.name(facts?.model ?? c.model)} ▾${switching} · ${facts?.thinking ?? "off"} ▾${tools ? ` · ${tools}` : ""}${pending ? ` · ${pending}` : ""}`,
|
|
620
|
+
this.theme.fg("dim", this.spend(c, facts)), ...(c.phase === "queued" && c.answered ? [statusPhrase(c, w, facts, Date.now())] : []), rule];
|
|
572
621
|
const asking = w.attention.some(a => a.kind === "question" && a.call === c.callId);
|
|
573
|
-
const placeholder = `${c.phase === "sealed" ? "Continue" : asking ? "Reply to" : "Steer"} ${c.key}…${this.uses < 3 ? " / for commands" : ""}`;
|
|
622
|
+
const placeholder = isCommand(c) ? `${c.phase === "sealed" ? "Finished" : "Running"} command · /stop stops it` : `${c.phase === "sealed" ? "Continue" : asking ? "Reply to" : "Steer"} ${c.key}…${this.uses < 3 ? " / for commands" : ""}`;
|
|
574
623
|
const empty = new Input({ prompt: "", placeholder, placeholderStyle: text => this.theme.fg("dim", text) });
|
|
575
624
|
empty.focused = this.focused;
|
|
576
625
|
const editor = this.input.getValue() ? this.input.render(size.width) : empty.render(size.width);
|
|
577
|
-
const hint = this.input.getValue().startsWith("/") ? "/model · /stop" : this.notice;
|
|
626
|
+
const hint = this.input.getValue().startsWith("/") ? (isCommand(c) ? "/stop" : "/model · /stop") : this.notice;
|
|
578
627
|
const transcript = this.transcript(c, w, size.width), available = Math.max(1, size.height - head.length - editor.length - 2);
|
|
579
628
|
const bottom = Math.max(0, transcript.lines.length - available);
|
|
580
629
|
// Scrolling back down to the end resumes following, as in pi's own transcript.
|
package/dist/ui/tool.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Text } from "@earendil-works/pi-tui";
|
|
2
2
|
import { plainReason, queuedPhrase } from "./view.js";
|
|
3
|
+
import { commandLine, commandText } from "../orchestrator/snapshot.js";
|
|
4
|
+
/** A step's agent, or "command" for a command step. */
|
|
5
|
+
const who = (s) => s.command !== undefined ? "command" : String(s.agent ?? "?");
|
|
3
6
|
const short = (id) => typeof id === "string" ? (id.length > 12 ? `${id.slice(0, 10)}…` : id) : "";
|
|
4
7
|
const clip = (s, n) => s.length > n ? `${s.slice(0, n - 1)}…` : s;
|
|
5
8
|
/** UI §5: One line per tool call: what was asked, never the raw arguments (scripts and task prompts stay out of the transcript). */
|
|
@@ -8,15 +11,16 @@ export function callLine(args) {
|
|
|
8
11
|
const agents = (list) => {
|
|
9
12
|
const counts = new Map();
|
|
10
13
|
for (const s of list)
|
|
11
|
-
counts.set(
|
|
14
|
+
counts.set(who(s), (counts.get(who(s)) ?? 0) + 1);
|
|
12
15
|
return [...counts].map(([a, n]) => n > 1 ? `${a}×${n}` : a).join(", ");
|
|
13
16
|
};
|
|
14
17
|
switch (args.action) {
|
|
15
18
|
case "run": {
|
|
16
19
|
const what = Array.isArray(args.tasks) ? `${steps.length} in parallel (${agents(steps)})`
|
|
17
|
-
: Array.isArray(args.chain) ? `chain of ${steps.length} (${steps.map(
|
|
20
|
+
: Array.isArray(args.chain) ? `chain of ${steps.length} (${steps.map(who).join(" → ")})`
|
|
18
21
|
: typeof args.source === "string" ? `workflow script (${args.source.split("\n").length} lines)`
|
|
19
|
-
: typeof args.workflow === "string" ? `workflow ${args.workflow}`
|
|
22
|
+
: typeof args.workflow === "string" ? `workflow ${args.workflow}`
|
|
23
|
+
: args.command !== undefined ? `command: ${clip(commandLine(commandText(args.command)), 70)}` : `${String(args.agent ?? "?")}: ${clip(String(args.task ?? "").split("\n")[0], 70)}`;
|
|
20
24
|
return `run ${typeof args.name === "string" ? `${args.name} · ` : ""}${what}`;
|
|
21
25
|
}
|
|
22
26
|
case "send": return `send ${String(args.kind ?? "")} → ${String(args.to ?? "")}${typeof args.message === "string" ? `: ${clip(args.message.split("\n")[0], 70)}` : typeof args.model === "string" ? `: ${args.model}` : ""}`;
|
|
@@ -32,7 +36,7 @@ export function resultLines(details) {
|
|
|
32
36
|
const d = (details ?? {});
|
|
33
37
|
if (typeof d.wid === "string" && typeof d.key === "string" && typeof d.phase === "string") {
|
|
34
38
|
const r = d.result;
|
|
35
|
-
return [`${d.key} · ${r?.status ?? (d.phase === "queued" ? queuedPhrase(d, Date.now()) : d.phase)}${typeof d.model === "string" ? ` · ${d.model}` : ""}`];
|
|
39
|
+
return [`${d.key} · ${r?.status ?? (d.phase === "queued" ? queuedPhrase(d, Date.now()) : d.phase)}${typeof d.model === "string" ? ` · ${d.model}` : ""}${typeof d.command === "string" ? ` · command: ${commandLine(d.command, 60)}` : ""}`];
|
|
36
40
|
}
|
|
37
41
|
if (typeof d.wid === "string" && !Array.isArray(d.calls))
|
|
38
42
|
return [`started workflow ${d.wid}`, ...(typeof d.paused === "string" ? [`⚠ ${d.paused}`] : [])];
|
package/dist/ui/view.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
-
import { answerForwardedNote, isLive, queuedText, labelsText, liveCalls, ownedBy, progressOf } from "../orchestrator/snapshot.js";
|
|
2
|
+
import { answerForwardedNote, commandLine, isLive, queuedText, labelsText, liveCalls, ownedBy, progressOf } from "../orchestrator/snapshot.js";
|
|
3
3
|
import { oneLine } from "./frame.js";
|
|
4
4
|
/** UI §2: Render compact wall-clock durations; never present these as charged active time. */
|
|
5
5
|
export function duration(ms) {
|
|
@@ -22,6 +22,10 @@ export function modelLabel(model, find, aliases = {}) {
|
|
|
22
22
|
const named = (word) => Boolean(word) && new RegExp(`(^|[^a-z0-9])${word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^a-z0-9]|$)`, "i").test(name);
|
|
23
23
|
return suffix.toLowerCase() === family || named(provider) || named(suffix) ? name : `${name} (${suffix})`;
|
|
24
24
|
}
|
|
25
|
+
/** UI §2: The model column of a call: a command call shows its command instead ("command: npm test"). */
|
|
26
|
+
export function modelColumn(c, f, name) {
|
|
27
|
+
return c.command !== undefined ? `command: ${commandLine(c.command, 40)}` : name(f?.model ?? c.model);
|
|
28
|
+
}
|
|
25
29
|
/** UI §2–3: Count committed tool calls compactly; zero is not shown. */
|
|
26
30
|
export const toolCount = (n) => n ? `${n} tool${n === 1 ? "" : "s"}` : "";
|
|
27
31
|
/** UI §3, P7: Messages sent to a call whose delivery the child has not confirmed yet; zero is not shown. */
|
|
@@ -130,6 +134,11 @@ export function statusPhrase(call, workflow, facts, now) {
|
|
|
130
134
|
return `no activity for ${duration(now - Math.max(call.lastActivity ?? call.startedAt ?? now, facts?.lastActivity ?? 0))}`;
|
|
131
135
|
if (call.phase === "queued")
|
|
132
136
|
return workflow.paused ? "paused · r resumes" : queuedPhrase(call, now);
|
|
137
|
+
// A command call has no session: its process and how long it runs (from the start of its attempt).
|
|
138
|
+
if (call.command !== undefined) {
|
|
139
|
+
const run = call.commandRun, age = duration(Math.max(0, now - (call.startedAt ?? now)));
|
|
140
|
+
return run?.pid !== undefined ? `running · pid ${run.pid}${(run.attempt ?? 1) > 1 ? ` · attempt ${run.attempt}` : ""} · ${age}` : `starting · ${age}`;
|
|
141
|
+
}
|
|
133
142
|
// Liveness (UI §2): the age of the newest evidence ticks, and resets whenever the agent does anything.
|
|
134
143
|
const since = duration(Math.max(0, now - Math.max(call.lastActivity ?? 0, facts?.lastActivity ?? 0, call.startedAt ?? 0)));
|
|
135
144
|
if (facts?.activity)
|
|
@@ -175,7 +184,8 @@ export function callName(w, c) {
|
|
|
175
184
|
return `${c.key}${gen}`;
|
|
176
185
|
const peers = keys.filter(k => GENERATED.test(k) && w.calls.find(x => x.key === k)?.agent === c.agent)
|
|
177
186
|
.sort((a, b) => Number(GENERATED.exec(a)[1]) - Number(GENERATED.exec(b)[1]));
|
|
178
|
-
|
|
187
|
+
// A command call has no agent: it goes by "command" (numbered like an agent's when there are several).
|
|
188
|
+
return `${c.agent || (c.command !== undefined ? "command" : "")}${peers.length > 1 ? ` ${peers.indexOf(c.key) + 1}` : ""}${gen}`;
|
|
179
189
|
}
|
|
180
190
|
const WORDS = { ok: "done", stopped: "stopped", failed: "failed", "gate-failed": "failed", timeout: "timeout", budget: "budget", unknown: "unknown", skipped: "skipped", parked: "parked" };
|
|
181
191
|
/** v12 §4: The result word of a sealed status — a stopped call is never called failed; timeout/budget/unknown are named as such. */
|
|
@@ -240,14 +250,15 @@ export function dockLines(workflows, facts, name, width, now = Date.now(), rows
|
|
|
240
250
|
const line = ended && now - (ended.endedAt ?? 0) < 10 * 60_000 ? mainLine(workflows, now) : undefined;
|
|
241
251
|
return line ? [truncateToWidth(line, Math.max(1, width))] : [];
|
|
242
252
|
}
|
|
243
|
-
const cols = { key: Math.min(20, Math.max(...active.map(a => visibleWidth(callName(a.w, a.c))))), model: Math.min(20, Math.max(...active.map(a => visibleWidth(
|
|
253
|
+
const cols = { key: Math.min(20, Math.max(...active.map(a => visibleWidth(callName(a.w, a.c))))), model: Math.min(20, Math.max(...active.map(a => visibleWidth(modelColumn(a.c, facts.get(a.c.callId), name))))) };
|
|
244
254
|
const shown = active.slice(0, rows);
|
|
245
255
|
const lines = shown.map(({ w, c, asking }) => {
|
|
246
256
|
// A running tool is activity; otherwise a minute without new evidence (no message, no tool) stops the spinner.
|
|
247
|
-
|
|
257
|
+
// A running command call is busy as long as its process runs.
|
|
258
|
+
const f = facts.get(c.callId), fresh = Boolean(f?.activity) || c.command !== undefined && c.phase === "running" || now - Math.max(c.lastActivity ?? 0, f?.lastActivity ?? 0, c.startedAt ?? 0) < 60_000;
|
|
248
259
|
const mark = asking ? "?" : c.phase === "queued" ? "·" : fresh ? SPIN[Math.floor(now / 500) % SPIN.length] : "…";
|
|
249
260
|
const phrase = answerForwardedNote(c, now) || (asking ? `asks: ${w.attention.find(a => a.kind === "question" && a.call === c.callId).text}` : statusPhrase(c, w, f, now));
|
|
250
|
-
return rowText(`${mark} `, callName(w, c),
|
|
261
|
+
return rowText(`${mark} `, callName(w, c), modelColumn(c, f, name), phrase, [], width, cols);
|
|
251
262
|
});
|
|
252
263
|
const more = active.length - shown.length;
|
|
253
264
|
lines.push(truncateToWidth(`${more ? `+${more} more · ` : ""}${summaryText(workflows, now)} · ↓ subagents`, Math.max(1, width)));
|
|
@@ -290,11 +301,11 @@ export function listRows(workflows, state, facts, name, width, now = Date.now())
|
|
|
290
301
|
// Aligned columns across the whole list (UI §2): key and model start at the same column on every row.
|
|
291
302
|
const shownCalls = visible.flatMap(w => w.calls.map(c => ({ w, c })));
|
|
292
303
|
const cols = { key: Math.min(24, Math.max(0, ...shownCalls.map(({ w, c }) => visibleWidth(callName(w, c))))),
|
|
293
|
-
model: Math.min(26, Math.max(0, ...shownCalls.map(({ c }) => visibleWidth(
|
|
304
|
+
model: Math.min(26, Math.max(0, ...shownCalls.map(({ c }) => visibleWidth(modelColumn(c, facts.get(c.callId), name))))) };
|
|
294
305
|
const callRow = (w, c, indent, preview, dim = false) => {
|
|
295
306
|
const f = facts.get(c.callId), age = c.phase === "sealed" ? `${duration(now - (c.endedAt ?? now))} ago` : c.startedAt ? duration(now - c.startedAt) : "";
|
|
296
307
|
// A requested switch shows at once (it applies when the current step ends; until then it would look as if it had failed).
|
|
297
|
-
const shown = c.switching ? `${name(f?.model ?? c.model)} → ${name(c.switching)}` :
|
|
308
|
+
const shown = c.switching ? `${name(f?.model ?? c.model)} → ${name(c.switching)}` : modelColumn(c, f, name);
|
|
298
309
|
const text = rowText(indent, callName(w, c), shown, statusPhrase(c, w, f, now), [pendingMarker(c.pending), toolCount(f?.tools), age], width, cols);
|
|
299
310
|
rows.push({ id: c.callId, kind: "call", workflow: w, call: c, failed: Boolean(failed(c)), dim, text });
|
|
300
311
|
// Overview (UI §2): every active agent shows what it last said, thought or saw, without opening it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-durable-subagents",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.45",
|
|
4
4
|
"description": "Subagents for pi that never lose work and never do it twice. Crash-safe workflows, automatic recovery, and a live view just like the main agent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|