pi-durable-subagents 1.0.31 → 1.0.32
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 +13 -0
- package/README.md +6 -4
- package/dist/ui/screen.js +13 -13
- package/dist/ui/view.js +30 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.32
|
|
4
|
+
|
|
5
|
+
- `/subagents` lists working workflows first (newest first) and finished ones
|
|
6
|
+
after them (most recently ended first), so running work is never buried
|
|
7
|
+
under a page of finished rows. The cursor stays on its row when a workflow
|
|
8
|
+
moves.
|
|
9
|
+
- Rows name subagents the way people know them: a workflow's only subagent by
|
|
10
|
+
the workflow's name, a generated key (`tasks:0`, `chain:1`) by its agent,
|
|
11
|
+
numbered when repeated (`worker 1`, `worker 2`). Applies to the list, the
|
|
12
|
+
dock, the watch view and the input prompts; tools and the CLI keep the key
|
|
13
|
+
as the address. A name longer than the key column is clipped so columns
|
|
14
|
+
stay aligned.
|
|
15
|
+
|
|
3
16
|
## 1.0.31
|
|
4
17
|
|
|
5
18
|
- A run can be shown in the pi session it was started for, not only the one
|
package/README.md
CHANGED
|
@@ -206,10 +206,12 @@ another extension's editor bar (a powerline bar, for example), list
|
|
|
206
206
|
pi-durable-subagents before that extension in `packages`.
|
|
207
207
|
|
|
208
208
|
Press `↓` on an empty editor, or type `/subagents`, to open the list, a floating panel: this
|
|
209
|
-
session's workflows (sessions are independent),
|
|
210
|
-
subagent with its model, what it is doing and for how long, and
|
|
211
|
-
line. Finished ones
|
|
212
|
-
|
|
209
|
+
session's workflows (sessions are independent), working ones first (newest
|
|
210
|
+
first), every subagent with its model, what it is doing and for how long, and
|
|
211
|
+
its latest line. Finished ones follow, most recently ended first, dimmed, with
|
|
212
|
+
their conclusion. A workflow's only subagent is named after the workflow; in a
|
|
213
|
+
fan-out, a generated key (`tasks:0`) shows as its agent (`worker 1`,
|
|
214
|
+
`reviewer`). The key remains the address for `send` and the CLI. A session's workflows include runs started
|
|
213
215
|
through the CLI by a process this session launched (a background driver, a
|
|
214
216
|
script run from its bash tool): pi exports `DSA_SESSION`, and `run` names that
|
|
215
217
|
session (see `--session` below). Other sessions' and a terminal's runs are
|
package/dist/ui/screen.js
CHANGED
|
@@ -2,7 +2,7 @@ import { AssistantMessageComponent, UserMessageComponent, ToolExecutionComponent
|
|
|
2
2
|
import { Input, SelectList, fuzzyFilter, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
import { CT } from "../types.js";
|
|
4
4
|
import { UiActions, UiData } from "./data.js";
|
|
5
|
-
import { doneOrder, isOpen, plainReason, toggleOpen, duration, keepSelection, summaryText,
|
|
5
|
+
import { callName, doneOrder, isOpen, plainReason, toggleOpen, duration, keepSelection, summaryText, listRows, modelLabel, pendingText, resultPhrase, 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";
|
|
@@ -82,7 +82,7 @@ export class SubagentScreen {
|
|
|
82
82
|
beginListInput(kind, row) {
|
|
83
83
|
const c = row.call, w = row.workflow;
|
|
84
84
|
const q = w.attention.find(a => a.kind === "question" && a.call === c.callId);
|
|
85
|
-
this.listInput = { kind, call: c, workflow: w, editor: new Input({ prompt: `${kind} ${
|
|
85
|
+
this.listInput = { kind, call: c, workflow: w, editor: new Input({ prompt: `${kind} ${callName(w, c)}: ` }), ...(kind === "answer" && q ? { qid: q.qid, rev: q.rev } : {}) };
|
|
86
86
|
this.listInput.editor.focused = this.focused;
|
|
87
87
|
this.listNotice = undefined;
|
|
88
88
|
}
|
|
@@ -94,8 +94,8 @@ export class SubagentScreen {
|
|
|
94
94
|
if (!message)
|
|
95
95
|
return;
|
|
96
96
|
this.listInput = undefined;
|
|
97
|
-
const { call: c, kind } = draft;
|
|
98
|
-
this.listAction({ action: "send", to: c.callId, kind, message, ...(kind === "answer" ? { qid: draft.qid, rev: draft.rev } : {}) }, `${kind} ${
|
|
97
|
+
const { call: c, workflow: w, kind } = draft;
|
|
98
|
+
this.listAction({ action: "send", to: c.callId, kind, message, ...(kind === "answer" ? { qid: draft.qid, rev: draft.rev } : {}) }, `${kind} ${callName(w, c)}: ${JSON.stringify(message)}`);
|
|
99
99
|
}
|
|
100
100
|
dispose() { this.disposed = true; }
|
|
101
101
|
refresh() { if (!this.disposed)
|
|
@@ -259,7 +259,7 @@ export class SubagentScreen {
|
|
|
259
259
|
}
|
|
260
260
|
const q = w.attention.find(a => a.kind === "question" && a.call === c.callId);
|
|
261
261
|
const kind = followUp ? "follow-up" : q ? "answer" : "steer";
|
|
262
|
-
void this.send({ action: "send", to: c.callId, kind, message, ...(kind === "answer" ? { qid: q.qid, rev: q.rev } : {}) }, `${kind === "answer" ? "replied to" : followUp ? "queued follow-up for" : c.phase === "sealed" ? "continued" : "steered"} ${
|
|
262
|
+
void this.send({ action: "send", to: c.callId, kind, message, ...(kind === "answer" ? { qid: q.qid, rev: q.rev } : {}) }, `${kind === "answer" ? "replied to" : followUp ? "queued follow-up for" : c.phase === "sealed" ? "continued" : "steered"} ${callName(w, c)}: ${JSON.stringify(message)}`);
|
|
263
263
|
}
|
|
264
264
|
handleInput(key) {
|
|
265
265
|
if (this.disposed)
|
|
@@ -326,7 +326,7 @@ export class SubagentScreen {
|
|
|
326
326
|
else if (key === "r" && w?.paused)
|
|
327
327
|
this.listAction({ action: "resume", wid: w.wid }, `resume ${w.name ?? w.wid}`);
|
|
328
328
|
else if (key === "x" && (c && c.phase !== "sealed" || row?.kind === "workflow" && w?.status === "running")) {
|
|
329
|
-
this.stopTarget = c ? { id: c.callId, name:
|
|
329
|
+
this.stopTarget = c ? { id: c.callId, name: callName(w, c) } : { id: w.wid, name: w.name ?? w.wid };
|
|
330
330
|
}
|
|
331
331
|
// Typing that is not a list key is meant for pi (a message typed with the list still open would
|
|
332
332
|
// otherwise have its Enter open a watch view): close the list and hand the text to the editor.
|
|
@@ -377,10 +377,10 @@ export class SubagentScreen {
|
|
|
377
377
|
return;
|
|
378
378
|
// Panel coordinates: row 0 is the top border, column 2 is the first content column.
|
|
379
379
|
if (event.y === 2) {
|
|
380
|
-
const { c } = this.current();
|
|
381
|
-
if (!c)
|
|
380
|
+
const { c, w } = this.current();
|
|
381
|
+
if (!c || !w)
|
|
382
382
|
return;
|
|
383
|
-
const facts = this.data.facts.get(c.callId), model = `${
|
|
383
|
+
const facts = this.data.facts.get(c.callId), model = `${callName(w, c)} · ${this.name(facts?.model ?? c.model)} ▾ · `;
|
|
384
384
|
const x = event.x - 2;
|
|
385
385
|
if (x < visibleWidth(model))
|
|
386
386
|
this.modelMenu();
|
|
@@ -531,7 +531,7 @@ export class SubagentScreen {
|
|
|
531
531
|
const rowWidth = Math.max(1, size.width - 2);
|
|
532
532
|
this.rows = this.doneTab && w ? doneOrder(w.calls).map(c => {
|
|
533
533
|
const f = this.data.facts.get(c.callId);
|
|
534
|
-
return { id: c.callId, kind: "call", workflow: w, call: c, failed: !c.result?.ok, text: rowText(" ",
|
|
534
|
+
return { id: c.callId, kind: "call", workflow: w, call: c, failed: !c.result?.ok, text: rowText(" ", callName(w, c), this.name(f?.model ?? c.model), resultPhrase(c), [toolCount(f?.tools)], rowWidth) };
|
|
535
535
|
}) : listRows(this.data.workflows, this.state, this.data.facts, this.name, rowWidth);
|
|
536
536
|
height = this.height(Math.max(1, this.rows.length) + footerRows);
|
|
537
537
|
size = inner(width, height); // inner width does not depend on height
|
|
@@ -563,10 +563,10 @@ export class SubagentScreen {
|
|
|
563
563
|
if (!c || !w)
|
|
564
564
|
return panel(["Subagent is no longer in the current revision"], "Subagents", "Esc back");
|
|
565
565
|
const facts = this.data.facts.get(c.callId), active = w.calls.filter(c => c.phase !== "sealed"), done = w.calls.length - active.length;
|
|
566
|
-
const tabs = size.width < 60 ? `${c
|
|
566
|
+
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`;
|
|
567
567
|
const tools = toolCount(facts?.tools), pending = pendingText(c.pending), rule = this.theme.fg("borderMuted", "─".repeat(size.width));
|
|
568
568
|
const switching = c.switching ? ` → ${this.name(c.switching)} (requested)` : "";
|
|
569
|
-
const head = [tabs, `${
|
|
569
|
+
const head = [tabs, `${callName(w, c)} · ${this.name(facts?.model ?? c.model)} ▾${switching} · ${facts?.thinking ?? "off"} ▾${tools ? ` · ${tools}` : ""}${pending ? ` · ${pending}` : ""}`,
|
|
570
570
|
this.theme.fg("dim", this.spend(c, facts)), rule];
|
|
571
571
|
const asking = w.attention.some(a => a.kind === "question" && a.call === c.callId);
|
|
572
572
|
const placeholder = `${c.phase === "sealed" ? "Continue" : asking ? "Reply to" : "Steer"} ${c.key}…${this.uses < 3 ? " / for commands" : ""}`;
|
|
@@ -594,6 +594,6 @@ export class SubagentScreen {
|
|
|
594
594
|
}
|
|
595
595
|
this.inputRow = 1 + head.length + available + 1;
|
|
596
596
|
// pi's own keys for the transcript, spelled out: thinking and tool output expand in place.
|
|
597
|
-
return panel([...head, ...body, rule, ...editor, hint], `${w.name ?? w.wid} › ${
|
|
597
|
+
return panel([...head, ...body, rule, ...editor, hint], new Set(w.calls.map(x => x.key)).size === 1 && w.name ? callName(w, c) : `${w.name ?? w.wid} › ${callName(w, c)}`, `${duration(Date.now() - (c.startedAt ?? Date.now()))} · ctrl+t thinking · ctrl+o tools · Esc back`);
|
|
598
598
|
}
|
|
599
599
|
}
|
package/dist/ui/view.js
CHANGED
|
@@ -29,11 +29,15 @@ export const pendingText = (n) => n ? `${n} message${n === 1 ? "" : "s"} pending
|
|
|
29
29
|
/** UI §2, P7: The list row's small pending marker (the watch header spells it out). */
|
|
30
30
|
export const pendingMarker = (n) => n ? `${n} pending` : "";
|
|
31
31
|
/** UI §2: Sessions are independent: only this session's workflows (it started them, or a run started from it named it
|
|
32
|
-
* as its session, e.g. a CLI driver launched from this pi)
|
|
33
|
-
*
|
|
32
|
+
* as its session, e.g. a CLI driver launched from this pi). Working ones come first, newest start first; finished ones
|
|
33
|
+
* follow, most recently ended first. A workflow moves once, when it finishes (or a follow-up reopens it); the list
|
|
34
|
+
* keeps the selection on the same row id, so the cursor follows it. */
|
|
34
35
|
export function orderWorkflows(workflows, own) {
|
|
36
|
+
const tie = (a, b) => (a.wid < b.wid ? 1 : a.wid > b.wid ? -1 : 0);
|
|
35
37
|
return workflows.filter(w => own === undefined || ownedBy(w, own))
|
|
36
|
-
.sort((a, b) => (b
|
|
38
|
+
.sort((a, b) => Number(isLive(b)) - Number(isLive(a))
|
|
39
|
+
|| (isLive(a) ? (b.startedAt ?? 0) - (a.startedAt ?? 0) : (b.endedAt ?? b.startedAt ?? 0) - (a.endedAt ?? a.startedAt ?? 0))
|
|
40
|
+
|| tie(a, b));
|
|
37
41
|
}
|
|
38
42
|
/** UI §2: Done rows newest result first by immutable end time; ties keep snapshot order, so rows never reshuffle. */
|
|
39
43
|
export function doneOrder(calls) {
|
|
@@ -53,7 +57,7 @@ export function rowText(indent, key, model, phrase, tail, width, cols = { key: 0
|
|
|
53
57
|
const end = tail.filter(Boolean).join(" · ");
|
|
54
58
|
// A long phrase (a long command) is clipped; the tail (tools, age) stays. Under pressure the model column goes first.
|
|
55
59
|
for (const showModel of width >= 40 ? [true, false] : [false]) {
|
|
56
|
-
const head = `${indent}${pad(key, cols.key)} ${showModel ? `${pad(short, width < 70 ? 0 : cols.model)} ` : ""}`;
|
|
60
|
+
const head = `${indent}${pad(cols.key ? truncateToWidth(key, cols.key).replaceAll("\x1b[0m", "") : key, cols.key)} ${showModel ? `${pad(short, width < 70 ? 0 : cols.model)} ` : ""}`;
|
|
57
61
|
const room = width - visibleWidth(head) - (end ? visibleWidth(end) + 2 : 0);
|
|
58
62
|
// truncateToWidth closes its ellipsis with an SGR reset; drop it so a dimmed row stays dim to its end (tools, age).
|
|
59
63
|
if (end && room >= 8)
|
|
@@ -141,6 +145,21 @@ export function statusPhrase(call, workflow, facts, now) {
|
|
|
141
145
|
function failed(c) { return c.phase === "sealed" && c.result && !c.result.ok && c.result.status !== "skipped"; }
|
|
142
146
|
/** UI §2, P37: Calls are named by key; later generations of a key carry their generation. */
|
|
143
147
|
export const label = (c) => c.gen > 1 ? `${c.key}@${c.gen}` : c.key;
|
|
148
|
+
/** A key the spec did not name: generated from the launch form's position (tasks:0, chain:1). */
|
|
149
|
+
const GENERATED = /^(?:tasks|chain):(\d+)$/;
|
|
150
|
+
/** UI §2: How a person knows a call. A workflow's only agent goes by the workflow's name; a generated key (tasks:0) by
|
|
151
|
+
* its agent, numbered when the workflow runs that agent more than once; a named key as is. "@2" marks a later
|
|
152
|
+
* generation. The key stays the address for tools and the CLI; only the UI shows this name. */
|
|
153
|
+
export function callName(w, c) {
|
|
154
|
+
const keys = [...new Set(w.calls.map(x => x.key))], gen = c.gen > 1 ? `@${c.gen}` : "";
|
|
155
|
+
if (keys.length === 1 && w.name)
|
|
156
|
+
return `${w.name}${gen}`;
|
|
157
|
+
if (!GENERATED.test(c.key))
|
|
158
|
+
return `${c.key}${gen}`;
|
|
159
|
+
const peers = keys.filter(k => GENERATED.test(k) && w.calls.find(x => x.key === k)?.agent === c.agent)
|
|
160
|
+
.sort((a, b) => Number(GENERATED.exec(a)[1]) - Number(GENERATED.exec(b)[1]));
|
|
161
|
+
return `${c.agent}${peers.length > 1 ? ` ${peers.indexOf(c.key) + 1}` : ""}${gen}`;
|
|
162
|
+
}
|
|
144
163
|
const WORDS = { ok: "done", stopped: "stopped", failed: "failed", "gate-failed": "failed", timeout: "timeout", budget: "budget", unknown: "unknown", skipped: "skipped", parked: "parked" };
|
|
145
164
|
/** v12 §4: The result word of a sealed status — a stopped call is never called failed; timeout/budget/unknown are named as such. */
|
|
146
165
|
export const resultWord = (status) => WORDS[status] ?? "failed";
|
|
@@ -202,14 +221,14 @@ export function dockLines(workflows, facts, name, width, now = Date.now(), rows
|
|
|
202
221
|
const line = ended && now - (ended.endedAt ?? 0) < 10 * 60_000 ? mainLine(workflows) : undefined;
|
|
203
222
|
return line ? [truncateToWidth(line, Math.max(1, width))] : [];
|
|
204
223
|
}
|
|
205
|
-
const cols = { key: Math.min(
|
|
224
|
+
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(name(facts.get(a.c.callId)?.model ?? a.c.model))))) };
|
|
206
225
|
const shown = active.slice(0, rows);
|
|
207
226
|
const lines = shown.map(({ w, c, asking }) => {
|
|
208
227
|
// A running tool is activity; otherwise a minute without new evidence (no message, no tool) stops the spinner.
|
|
209
228
|
const f = facts.get(c.callId), fresh = Boolean(f?.activity) || now - Math.max(c.lastActivity ?? 0, f?.lastActivity ?? 0, c.startedAt ?? 0) < 60_000;
|
|
210
229
|
const mark = asking ? "?" : c.phase === "queued" ? "·" : fresh ? SPIN[Math.floor(now / 500) % SPIN.length] : "…";
|
|
211
230
|
const phrase = asking ? `asks: ${w.attention.find(a => a.kind === "question" && a.call === c.callId).text}` : statusPhrase(c, w, f, now);
|
|
212
|
-
return rowText(`${mark} `,
|
|
231
|
+
return rowText(`${mark} `, callName(w, c), name(f?.model ?? c.model), phrase, [], width, cols);
|
|
213
232
|
});
|
|
214
233
|
const more = active.length - shown.length;
|
|
215
234
|
lines.push(truncateToWidth(`${more ? `+${more} more · ` : ""}${summaryText(workflows)} · ↓ subagents`, Math.max(1, width)));
|
|
@@ -248,16 +267,16 @@ export function listRows(workflows, state, facts, name, width, now = Date.now())
|
|
|
248
267
|
state.observed.set(w.wid, { working, failures });
|
|
249
268
|
}
|
|
250
269
|
const unviewed = (w) => w.calls.some(c => failed(c) && !state.viewed.has(c.callId));
|
|
251
|
-
const visible = workflows; // caller order
|
|
270
|
+
const visible = workflows; // caller order: working first, then finished (orderWorkflows)
|
|
252
271
|
// Aligned columns across the whole list (UI §2): key and model start at the same column on every row.
|
|
253
|
-
const shownCalls = visible.flatMap(w => w.calls);
|
|
254
|
-
const cols = { key: Math.min(
|
|
255
|
-
model: Math.min(26, Math.max(0, ...shownCalls.map(c => visibleWidth(name(facts.get(c.callId)?.model ?? c.model))))) };
|
|
272
|
+
const shownCalls = visible.flatMap(w => w.calls.map(c => ({ w, c })));
|
|
273
|
+
const cols = { key: Math.min(24, Math.max(0, ...shownCalls.map(({ w, c }) => visibleWidth(callName(w, c))))),
|
|
274
|
+
model: Math.min(26, Math.max(0, ...shownCalls.map(({ c }) => visibleWidth(name(facts.get(c.callId)?.model ?? c.model))))) };
|
|
256
275
|
const callRow = (w, c, indent, preview, dim = false) => {
|
|
257
276
|
const f = facts.get(c.callId), age = c.phase === "sealed" ? `${duration(now - (c.endedAt ?? now))} ago` : c.startedAt ? duration(now - c.startedAt) : "";
|
|
258
277
|
// A requested switch shows at once (it applies when the current step ends; until then it would look as if it had failed).
|
|
259
278
|
const shown = c.switching ? `${name(f?.model ?? c.model)} → ${name(c.switching)}` : name(f?.model ?? c.model);
|
|
260
|
-
const text = rowText(indent,
|
|
279
|
+
const text = rowText(indent, callName(w, c), shown, statusPhrase(c, w, f, now), [pendingMarker(c.pending), toolCount(f?.tools), age], width, cols);
|
|
261
280
|
rows.push({ id: c.callId, kind: "call", workflow: w, call: c, failed: Boolean(failed(c)), dim, text });
|
|
262
281
|
// Overview (UI §2): every active agent shows what it last said, thought or saw, without opening it.
|
|
263
282
|
if (preview !== undefined && c.phase !== "sealed" && f?.latest)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-durable-subagents",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
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",
|