pi-durable-subagents 1.0.28 → 1.0.29

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.29
4
+
5
+ - The pi UI shows subagents that other sessions or the CLI started, kept apart
6
+ from this session's: the dock's summary line adds
7
+ `elsewhere: 4 running (cli 2, 1 session 2)` (dropped first when the line is
8
+ narrow; shown alone when this session runs nothing), and `/subagents` ends
9
+ with a folded `Other sessions` group listing their running workflows with
10
+ name, origin and labels. They can be watched but not changed from here: the
11
+ list's change keys and the watch view's input, model and stop controls
12
+ refuse them, decided by the workflow's origin. `ui.otherSessions: false`
13
+ turns this off.
14
+
3
15
  ## 1.0.28
4
16
 
5
17
  - Lower orchestrator cost. A finished workflow's journal is closed about a
package/README.md CHANGED
@@ -205,12 +205,26 @@ lines above the editor in extension load order, so to keep the dock above
205
205
  another extension's editor bar (a powerline bar, for example), list
206
206
  pi-durable-subagents before that extension in `packages`.
207
207
 
208
+ Subagents that another pi session or the CLI started never get rows in this
209
+ dock; while they run, the summary line adds a count, e.g.
210
+ `elsewhere: 4 running (cli 2, 1 session 2)` (dropped first when the line is
211
+ tight, and shown alone when this session has nothing running).
212
+
208
213
  Press `↓` on an empty editor, or type `/subagents`, to open the list, a floating panel: this
209
214
  session's workflows (sessions are independent), newest first, every
210
215
  subagent with its model, what it is doing and for how long, and its latest
211
216
  line. Finished ones stay there,
212
217
  dimmed, with their conclusion.
213
218
 
219
+ Live workflows of other sessions and the CLI follow in one group at the end,
220
+ `Other sessions (2 workflows, 4 running)`, folded until you press `Enter` on
221
+ it. Each shows its wid, name, origin (`cli:<user>@<host>` or a short session
222
+ id), labels and live calls. You can watch them, but not change them here:
223
+ steer, stop, model, answer and follow-up are refused with a hint to use the
224
+ session or CLI that started them (or the tool's `send` with an explicit
225
+ address). `"ui": { "otherSessions": false }` hides both the count and the
226
+ group.
227
+
214
228
  The list is also where you act. The footer shows the keys for the selected
215
229
  row: `Enter` watch, `s` steer, `f` follow-up, `x` stop (asks `y` first),
216
230
  `m` model, `a` answer. A one-line input opens at the bottom (paste works),
package/dist/ui/data.js CHANGED
@@ -51,6 +51,13 @@ const FINAL_MS = 10_000;
51
51
  /** A1, P25: Read the UI's data from durable workflow snapshots and native session tails only. */
52
52
  export class UiData {
53
53
  workflows = [];
54
+ /** Every workflow read by the last refresh, before the owning session splits them (a watched call of another
55
+ * origin stays watchable after its workflow settles). */
56
+ all = [];
57
+ /** Live workflows of other origins (other pi sessions, the CLI), split off by the session that owns this data. */
58
+ others = [];
59
+ /** Whether other origins' live work is shown (the dock's elsewhere count, the list's Other sessions group). */
60
+ otherSessions = true;
54
61
  /** Facts and session branch per call id; a finished call's are read on first `get` (see refresh). */
55
62
  facts = new Map();
56
63
  sessions = new Map();
@@ -153,6 +160,7 @@ export class UiData {
153
160
  load();
154
161
  }
155
162
  this.workflows = workflows;
163
+ this.all = workflows;
156
164
  this.facts = facts;
157
165
  this.sessions = sessions;
158
166
  // UI-only optional aliases; absence or invalid config must not break execution (P21).
@@ -161,11 +169,13 @@ export class UiData {
161
169
  this.aliases = Object.fromEntries(Object.entries(config.ui?.modelAliases ?? {}).filter(([, v]) => typeof v === "string"));
162
170
  this.dock = ["auto", "line", "off"].includes(config.ui?.dock) ? config.ui.dock : "auto";
163
171
  this.dockAt = config.ui?.dockAt === "below" ? "below" : "above";
172
+ this.otherSessions = config.ui?.otherSessions !== false;
164
173
  }
165
174
  catch {
166
175
  this.aliases = {};
167
176
  this.dock = "auto";
168
177
  this.dockAt = "above";
178
+ this.otherSessions = true;
169
179
  }
170
180
  }
171
181
  }
package/dist/ui/index.js CHANGED
@@ -2,7 +2,7 @@ import { matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tu
2
2
  import { UiActions, UiData } from "./data.js";
3
3
  import { SubagentScreen } from "./screen.js";
4
4
  import { oneLine } from "./frame.js";
5
- import { dockLines, mainLine, modelLabel, orderWorkflows } from "./view.js";
5
+ import { dockLines, mainLine, modelLabel, orderWorkflows, otherWorkflows, othersLive } from "./view.js";
6
6
  import { registerCards } from "./cards.js";
7
7
  import { toolRenderers } from "./tool.js";
8
8
  /** UI §1–3, P16, P21: Register journal-backed list/watch surfaces only in interactive pi. */
@@ -67,16 +67,19 @@ export function registerUi(pi, deps) {
67
67
  if (stopped)
68
68
  return;
69
69
  try {
70
+ // Split by origin at once: nothing between the read and the split may leave other sessions' workflows among
71
+ // this session's (the screen also checks the origin itself before any change).
70
72
  data.refresh();
73
+ const own = `main:${ctx.sessionManager.getSessionId()}`;
74
+ data.others = data.otherSessions ? otherWorkflows(data.workflows, own) : [];
75
+ data.workflows = orderWorkflows(data.workflows, own);
71
76
  actions.reconcile();
72
77
  for (const result of actions.resolutions.splice(0))
73
78
  screen?.controlResult(result);
74
- const own = `main:${ctx.sessionManager.getSessionId()}`;
75
- data.workflows = orderWorkflows(data.workflows, own);
76
79
  // UI §1: the dock — live rows per active agent plus a summary line ("auto"), only the summary ("line"), or nothing.
77
80
  const name = (model) => modelLabel(model, (p, id) => ctx.modelRegistry.find(p, id), data.aliases);
78
81
  const now = Date.now(), dock = data.dock;
79
- const lines = (width) => dock === "off" ? [] : dock === "line" ? [mainLine(data.workflows) ?? ""].filter(Boolean) : dockLines(data.workflows, data.facts, name, width, now);
82
+ const lines = (width) => dock === "off" ? [] : dock === "line" ? [mainLine(data.workflows, data.others, width) ?? ""].filter(Boolean) : dockLines(data.workflows, data.facts, name, width, now, 3, data.others);
80
83
  dockRows = lines;
81
84
  // The widget is installed once, at session start (and again only when its placement changes). pi stacks
82
85
  // widgets in the order they were set, so installing once keeps the dock where the extension load order puts
@@ -117,7 +120,7 @@ export function registerUi(pi, deps) {
117
120
  const open = () => {
118
121
  if (stopped || opening)
119
122
  return "busy";
120
- if (!data.workflows.length)
123
+ if (!data.workflows.length && !othersLive(data.others))
121
124
  return "empty";
122
125
  opening = true;
123
126
  void (async () => {
@@ -131,7 +134,7 @@ export function registerUi(pi, deps) {
131
134
  };
132
135
  openList = open;
133
136
  unsubscribe = ctx.ui.onTerminalInput(key => {
134
- if (stopped || opening || !matchesKey(key, "down") || ctx.ui.getEditorText() !== "" || !editorFocused() || !data.workflows.length)
137
+ if (stopped || opening || !matchesKey(key, "down") || ctx.ui.getEditorText() !== "" || !editorFocused() || !data.workflows.length && !othersLive(data.others))
135
138
  return;
136
139
  open();
137
140
  return { consume: true };
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, label, listRows, modelLabel, pendingText, resultPhrase, rowText, toolCount } from "./view.js";
5
+ import { doneOrder, isOpen, originText, plainReason, toggleOpen, duration, keepSelection, summaryText, label, 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";
@@ -101,8 +101,17 @@ export class SubagentScreen {
101
101
  refresh() { if (!this.disposed)
102
102
  this.tui.requestRender(); }
103
103
  name = (model) => modelLabel(model, (p, id) => this.ctx.modelRegistry.find(p, id), this.data.aliases);
104
+ /** A workflow another session or the CLI started: watchable here, never changed from here. */
105
+ foreign(w) {
106
+ // Decided by origin, not by list membership: a refresh interrupted before the split must not make them editable.
107
+ const id = this.ctx.sessionManager?.getSessionId?.();
108
+ return !!w && (id === undefined || w.origin !== `main:${id}`);
109
+ }
110
+ readOnly(w) {
111
+ return `read-only: started by ${originText(w.origin)}; change it from that session or the CLI (or send with an explicit address)`;
112
+ }
104
113
  current() {
105
- const w = this.data.workflows.find(w => w.wid === this.workflow);
114
+ const w = this.data.workflows.find(w => w.wid === this.workflow) ?? this.data.all.find(w => w.wid === this.workflow);
106
115
  let c = w?.calls.find(c => c.callId === this.watching);
107
116
  // P37: watching a key follows its newest generation (a continued call reopens on the same session).
108
117
  const newest = c && w.calls.filter(x => x.key === c.key && x.gen > c.gen).sort((a, b) => b.gen - a.gen)[0];
@@ -145,8 +154,15 @@ export class SubagentScreen {
145
154
  return;
146
155
  if (row.kind === "call")
147
156
  this.open(row.workflow, row.call);
157
+ else if (row.kind === "workflow" && row.other) {
158
+ const wid = row.workflow.wid;
159
+ if (!this.state.folded.delete(wid))
160
+ this.state.folded.add(wid);
161
+ }
148
162
  else if (row.kind === "workflow")
149
163
  toggleOpen(row.workflow, this.state);
164
+ else if (row.kind === "others")
165
+ this.state.others = !this.state.others;
150
166
  else if (row.kind === "finished")
151
167
  this.state.finished = !this.state.finished;
152
168
  else if (row.workflow) {
@@ -174,6 +190,10 @@ export class SubagentScreen {
174
190
  const c = target ?? this.current().c;
175
191
  if (!c)
176
192
  return;
193
+ if (!target && this.foreign(this.current().w)) {
194
+ this.notice = this.readOnly(this.current().w);
195
+ return;
196
+ }
177
197
  this.menuTitle = `Model for ${c.key}`;
178
198
  const models = this.ctx.modelRegistry.getAvailable();
179
199
  this.menuItems = models.map(m => ({ value: `${m.provider}/${m.id}`, label: this.name(`${m.provider}/${m.id}`) }));
@@ -203,9 +223,13 @@ export class SubagentScreen {
203
223
  this.menu.onCancel = onCancel;
204
224
  }
205
225
  thinkingMenu() {
206
- const { c } = this.current();
226
+ const { c, w } = this.current();
207
227
  if (!c)
208
228
  return;
229
+ if (this.foreign(w)) {
230
+ this.notice = this.readOnly(w);
231
+ return;
232
+ }
209
233
  const model = this.data.facts.get(c.callId)?.model ?? c.model;
210
234
  if (!model)
211
235
  return;
@@ -221,9 +245,13 @@ export class SubagentScreen {
221
245
  };
222
246
  }
223
247
  cycleThinking() {
224
- const { c } = this.current();
248
+ const { c, w } = this.current();
225
249
  if (!c)
226
250
  return;
251
+ if (this.foreign(w)) {
252
+ this.notice = this.readOnly(w);
253
+ return;
254
+ }
227
255
  const facts = this.data.facts.get(c.callId), model = facts?.model ?? c.model;
228
256
  if (!model) {
229
257
  this.notice = "Model not yet recorded";
@@ -239,6 +267,10 @@ export class SubagentScreen {
239
267
  const message = this.input.getValue().trim();
240
268
  if (!message)
241
269
  return;
270
+ if (this.foreign(w)) {
271
+ this.notice = this.readOnly(w);
272
+ return;
273
+ }
242
274
  if (message === "/model") {
243
275
  this.modelMenu();
244
276
  this.input.setValue("");
@@ -315,7 +347,9 @@ export class SubagentScreen {
315
347
  else if (!this.busy) {
316
348
  const row = this.selectedRow(), c = row?.kind === "call" ? row.call : undefined, w = row?.workflow;
317
349
  const asking = c && w?.attention.some(a => a.kind === "question" && a.call === c.callId);
318
- if (key === "s" && c && c.phase !== "sealed")
350
+ if (key.length === 1 && "sfamxr".includes(key) && (row?.other || this.foreign(w)))
351
+ this.listNotice = { text: this.readOnly(w), until: Date.now() + 6000 };
352
+ else if (key === "s" && c && c.phase !== "sealed")
319
353
  this.beginListInput("steer", row);
320
354
  else if (key === "f" && c?.phase === "sealed")
321
355
  this.beginListInput("follow-up", row);
@@ -529,13 +563,20 @@ export class SubagentScreen {
529
563
  // A two-column gutter carries the selection marker: a background alone is invisible in some themes and in
530
564
  // plain-text captures, and x must show which row it would stop.
531
565
  const rowWidth = Math.max(1, size.width - 2);
566
+ const before = this.rows.find(r => r.id === this.selectedId), wasOther = Boolean(before?.other || before?.kind === "others");
532
567
  this.rows = this.doneTab && w ? doneOrder(w.calls).map(c => {
533
568
  const f = this.data.facts.get(c.callId);
534
569
  return { id: c.callId, kind: "call", workflow: w, call: c, failed: !c.result?.ok, text: rowText(" ", label(c), this.name(f?.model ?? c.model), resultPhrase(c), [toolCount(f?.tools)], rowWidth) };
535
- }) : listRows(this.data.workflows, this.state, this.data.facts, this.name, rowWidth);
570
+ }) : listRows(this.data.workflows, this.state, this.data.facts, this.name, rowWidth, Date.now(), this.data.others);
536
571
  height = this.height(Math.max(1, this.rows.length) + footerRows);
537
572
  size = inner(width, height); // inner width does not depend on height
538
- this.selected = keepSelection(this.rows, this.selectedId, this.selected);
573
+ // A vanished row of another session (its workflow ended, or the whole group went) never hands the selection to
574
+ // a different row of this session by position, where x or r would act on it: the group header takes it, or no
575
+ // row is selected (-1) until ↑/↓ chooses one.
576
+ if (wasOther && !this.rows.some(r => r.id === this.selectedId))
577
+ this.selected = this.rows.findIndex(r => r.kind === "others");
578
+ else if (this.selected >= 0 || this.selectedId !== undefined)
579
+ this.selected = keepSelection(this.rows, this.selectedId, this.selected);
539
580
  while (this.rows[this.selected]?.kind === "preview" && this.selected > 0)
540
581
  this.selected--;
541
582
  this.selectedId = this.rows[this.selected]?.id;
@@ -547,8 +588,9 @@ export class SubagentScreen {
547
588
  });
548
589
  const row = this.selectedRow(), c = row?.kind === "call" ? row.call : undefined;
549
590
  const asking = c && row?.workflow?.attention.some(a => a.kind === "question" && a.call === c.callId);
550
- const narrow = size.width < 72;
551
- 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() : "",
591
+ const narrow = size.width < 72, readOnly = row?.other || this.foreign(row?.workflow) || this.doneTab && this.foreign(w);
592
+ const keys = readOnly ? [narrow ? "↑↓" : "↑ ↓ select", row?.kind === "workflow" ? `Enter ${narrow ? "" : this.state.folded.has(row.workflow.wid) ? "expand" : "collapse"}`.trim() : row?.kind === "call" ? (narrow ? "Enter" : "Enter watch") : "",
593
+ narrow ? "read-only" : `read-only: started by ${originText(row?.workflow?.origin ?? w?.origin)}; change it there`, "Esc back"].filter(Boolean).join(" · ") : [narrow ? "↑↓" : "↑ ↓ select", row && row.kind !== "preview" ? `Enter ${narrow ? "" : row.kind === "workflow" ? (isOpen(row.workflow, this.state) ? "collapse" : "expand") : row.kind === "call" ? "watch" : row.kind === "others" ? (this.state.others ? "collapse" : "expand") : "open"}`.trim() : "",
552
594
  c && c.phase !== "sealed" ? (narrow ? "s" : "s steer") : "", c?.phase === "sealed" ? (narrow ? "f" : "f follow-up") : "",
553
595
  c && c.phase !== "sealed" || row?.kind === "workflow" && row.workflow?.status === "running" ? (narrow ? "x" : "x stop") : "",
554
596
  c ? (narrow ? "m" : "m model") : "", asking ? (narrow ? "a" : "a answer") : "", row?.workflow?.paused ? (narrow ? "r" : "r resume") : "", "Esc back"].filter(Boolean).join(" · ");
@@ -569,7 +611,8 @@ export class SubagentScreen {
569
611
  const head = [tabs, `${label(c)} · ${this.name(facts?.model ?? c.model)} ▾${switching} · ${facts?.thinking ?? "off"} ▾${tools ? ` · ${tools}` : ""}${pending ? ` · ${pending}` : ""}`,
570
612
  this.theme.fg("dim", this.spend(c, facts)), rule];
571
613
  const asking = w.attention.some(a => a.kind === "question" && a.call === c.callId);
572
- const placeholder = `${c.phase === "sealed" ? "Continue" : asking ? "Reply to" : "Steer"} ${c.key}…${this.uses < 3 ? " / for commands" : ""}`;
614
+ const placeholder = this.foreign(w) ? `Read-only: started by ${originText(w.origin)}`
615
+ : `${c.phase === "sealed" ? "Continue" : asking ? "Reply to" : "Steer"} ${c.key}…${this.uses < 3 ? " / for commands" : ""}`;
573
616
  const empty = new Input({ prompt: "", placeholder, placeholderStyle: text => this.theme.fg("dim", text) });
574
617
  empty.focused = this.focused;
575
618
  const editor = this.input.getValue() ? this.input.render(size.width) : empty.render(size.width);
package/dist/ui/view.js CHANGED
@@ -34,6 +34,50 @@ export function orderWorkflows(workflows, own) {
34
34
  return workflows.filter(w => own === undefined || w.origin === own)
35
35
  .sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0) || (a.wid < b.wid ? 1 : a.wid > b.wid ? -1 : 0));
36
36
  }
37
+ /** Live workflows started elsewhere (another pi session, the CLI or an unknown origin), newest first. A workflow of
38
+ * another origin counts while it is not settled (as in the status tool's otherSessions): running, parked, or
39
+ * finished with an open follow-up. */
40
+ export function otherWorkflows(workflows, own) {
41
+ return orderWorkflows(workflows.filter(w => w.origin !== own && (isLive(w) || w.status === "parked")));
42
+ }
43
+ /** Who started a workflow, short: `cli:<user>@<host>` as is, a pi session by the head of its id. */
44
+ export function originText(origin) {
45
+ if (!origin)
46
+ return "unknown origin";
47
+ return origin.startsWith("main:") ? `session ${origin.slice(5, 13)}` : origin;
48
+ }
49
+ const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
50
+ /** Live calls of other origins in a few words, e.g. "elsewhere: 4 running (cli 2, 1 session 2)"; undefined when none. */
51
+ export function elsewhereText(others) {
52
+ let cli = 0, unknown = 0, inSessions = 0;
53
+ const sessions = new Set();
54
+ for (const w of others) {
55
+ const n = liveCalls(w).length;
56
+ if (!n)
57
+ continue;
58
+ if (w.origin?.startsWith("cli:"))
59
+ cli += n;
60
+ else if (w.origin?.startsWith("main:")) {
61
+ inSessions += n;
62
+ sessions.add(w.origin);
63
+ }
64
+ else
65
+ unknown += n;
66
+ }
67
+ const total = cli + inSessions + unknown;
68
+ if (!total)
69
+ return undefined;
70
+ const parts = [cli ? `cli ${cli}` : "", inSessions ? `${plural(sessions.size, "session")} ${inSessions}` : "", unknown ? `other ${unknown}` : ""].filter(Boolean);
71
+ return `elsewhere: ${total} running (${parts.join(", ")})`;
72
+ }
73
+ /** Whether other origins have live calls: the one rule for the dock's elsewhere count and for opening the list. */
74
+ export const othersLive = (others) => others.some(w => liveCalls(w).length > 0);
75
+ /** A summary line with the elsewhere count appended when it fits; it is the first part dropped when the width is tight. */
76
+ function withElsewhere(line, elsewhere, width) {
77
+ const both = elsewhere ? `${line} · ${elsewhere}` : line;
78
+ const fit = visibleWidth(both) <= width ? both : line;
79
+ return Number.isFinite(width) ? truncateToWidth(fit, Math.max(1, width)) : fit;
80
+ }
37
81
  /** UI §2: Done rows newest result first by immutable end time; ties keep snapshot order, so rows never reshuffle. */
38
82
  export function doneOrder(calls) {
39
83
  return calls.map((c, i) => ({ c, i })).filter(x => x.c.phase === "sealed").sort((a, b) => (b.c.endedAt ?? 0) - (a.c.endedAt ?? 0) || a.i - b.i).map(x => x.c);
@@ -162,7 +206,14 @@ export function summaryText(workflows) {
162
206
  return finished ? `${finished} finished` : "nothing running";
163
207
  return [s.asking ? `${s.asking} asking` : "", s.working ? `${s.working} working` : "", s.queued ? `${s.queued} queued` : "", s.paused ? `${s.paused} paused` : "", `${s.done}/${s.total}${s.plus ? "+" : ""} done`].filter(Boolean).join(" · ");
164
208
  }
165
- export function mainLine(workflows) {
209
+ /** The one-line dock: this session's summary (or completion sentence), plus the elsewhere count of other origins. */
210
+ export function mainLine(workflows, others = [], width = Infinity) {
211
+ const own = ownLine(workflows), elsewhere = elsewhereText(others);
212
+ if (own)
213
+ return withElsewhere(own, elsewhere, width);
214
+ return elsewhere ? withElsewhere(`${elsewhere} · ↓ subagents`, undefined, width) : undefined;
215
+ }
216
+ function ownLine(workflows) {
166
217
  if (!workflows.length)
167
218
  return undefined;
168
219
  const s = summary(workflows);
@@ -187,7 +238,10 @@ const SPIN = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "
187
238
  /** UI §1: The dock above the editor. While agents work: one row per active agent (questions first, at most `rows`),
188
239
  * then one summary line; afterwards only the completion sentence for ten minutes; otherwise nothing. Activity spins
189
240
  * only while there is fresh evidence, so a quiet agent visibly stops moving. */
190
- export function dockLines(workflows, facts, name, width, now = Date.now(), rows = 3) {
241
+ /** Other origins' live calls never become rows here: they add an "elsewhere" count to the summary line (alone when this
242
+ * session has nothing to show). */
243
+ export function dockLines(workflows, facts, name, width, now = Date.now(), rows = 3, others = []) {
244
+ const elsewhere = elsewhereText(others);
191
245
  const live = workflows.filter(isLive);
192
246
  const active = live.flatMap(w => {
193
247
  const latest = new Map();
@@ -198,8 +252,10 @@ export function dockLines(workflows, facts, name, width, now = Date.now(), rows
198
252
  }).sort((a, b) => Number(b.asking) - Number(a.asking));
199
253
  if (!active.length) {
200
254
  const ended = workflows.filter(w => !isLive(w)).sort((a, b) => (b.endedAt ?? 0) - (a.endedAt ?? 0))[0];
201
- const line = ended && now - (ended.endedAt ?? 0) < 10 * 60_000 ? mainLine(workflows) : undefined;
202
- return line ? [truncateToWidth(line, Math.max(1, width))] : [];
255
+ const line = ended && now - (ended.endedAt ?? 0) < 10 * 60_000 ? ownLine(workflows) : undefined;
256
+ if (line)
257
+ return [withElsewhere(line, elsewhere, width)];
258
+ return elsewhere ? [truncateToWidth(`${elsewhere} · ↓ subagents`, Math.max(1, width))] : [];
203
259
  }
204
260
  const cols = { key: Math.min(14, Math.max(...active.map(a => visibleWidth(label(a.c))))), model: Math.min(20, Math.max(...active.map(a => visibleWidth(name(facts.get(a.c.callId)?.model ?? a.c.model))))) };
205
261
  const shown = active.slice(0, rows);
@@ -211,7 +267,7 @@ export function dockLines(workflows, facts, name, width, now = Date.now(), rows
211
267
  return rowText(`${mark} `, label(c), name(f?.model ?? c.model), phrase, [], width, cols);
212
268
  });
213
269
  const more = active.length - shown.length;
214
- lines.push(truncateToWidth(`${more ? `+${more} more · ` : ""}${summaryText(workflows)} · ↓ subagents`, Math.max(1, width)));
270
+ lines.push(withElsewhere(`${more ? `+${more} more · ` : ""}${summaryText(workflows)} · ↓ subagents`, elsewhere, width));
215
271
  return lines;
216
272
  }
217
273
  /** UI §2, v12 §5: Group workflows (finished ones stay listed, dimmed and expandable — never hidden behind a toggle),
@@ -230,7 +286,9 @@ export function toggleOpen(w, state) {
230
286
  state.done.set(w.wid, Math.max(8, state.done.get(w.wid) ?? 0));
231
287
  }
232
288
  }
233
- export function listRows(workflows, state, facts, name, width, now = Date.now()) {
289
+ /** `others` (live workflows of other origins) follow in one "Other sessions" group at the end, folded until opened;
290
+ * their rows are marked `other` and never feed this session's reopen-on-failure state. */
291
+ export function listRows(workflows, state, facts, name, width, now = Date.now(), others = []) {
234
292
  const rows = [];
235
293
  state.observed ??= new Map();
236
294
  for (const w of workflows) {
@@ -249,18 +307,18 @@ export function listRows(workflows, state, facts, name, width, now = Date.now())
249
307
  const unviewed = (w) => w.calls.some(c => failed(c) && !state.viewed.has(c.callId));
250
308
  const visible = workflows; // caller order (newest first), unchanged when a workflow finishes
251
309
  // Aligned columns across the whole list (UI §2): key and model start at the same column on every row.
252
- const shownCalls = visible.flatMap(w => w.calls);
310
+ const shownCalls = [...visible.flatMap(w => w.calls), ...(state.others ? others.flatMap(liveCalls) : [])];
253
311
  const cols = { key: Math.min(18, Math.max(0, ...shownCalls.map(c => visibleWidth(label(c))))),
254
312
  model: Math.min(26, Math.max(0, ...shownCalls.map(c => visibleWidth(name(facts.get(c.callId)?.model ?? c.model))))) };
255
- const callRow = (w, c, indent, preview, dim = false) => {
313
+ const callRow = (w, c, indent, preview, dim = false, other = false) => {
256
314
  const f = facts.get(c.callId), age = c.phase === "sealed" ? `${duration(now - (c.endedAt ?? now))} ago` : c.startedAt ? duration(now - c.startedAt) : "";
257
315
  // A requested switch shows at once (it applies when the current step ends; until then it would look as if it had failed).
258
316
  const shown = c.switching ? `${name(f?.model ?? c.model)} → ${name(c.switching)}` : name(f?.model ?? c.model);
259
317
  const text = rowText(indent, label(c), shown, statusPhrase(c, w, f, now), [pendingMarker(c.pending), toolCount(f?.tools), age], width, cols);
260
- rows.push({ id: c.callId, kind: "call", workflow: w, call: c, failed: Boolean(failed(c)), dim, text });
318
+ rows.push({ id: c.callId, kind: "call", workflow: w, call: c, failed: Boolean(failed(c)), dim, text, ...(other ? { other } : {}) });
261
319
  // Overview (UI §2): every active agent shows what it last said, thought or saw, without opening it.
262
320
  if (preview !== undefined && c.phase !== "sealed" && f?.latest)
263
- rows.push({ id: `${c.callId}:preview`, kind: "preview", workflow: w, call: c, dim, text: truncateToWidth(`${preview}${f.latest}`, Math.max(1, width)).replaceAll("\x1b[0m", "") });
321
+ rows.push({ id: `${c.callId}:preview`, kind: "preview", workflow: w, call: c, dim, text: truncateToWidth(`${preview}${f.latest}`, Math.max(1, width)).replaceAll("\x1b[0m", ""), ...(other ? { other } : {}) });
264
322
  };
265
323
  for (const v of visible) {
266
324
  // One row per key: the newest generation (key@2) stands for the agent; older ones open from its watch view (← →).
@@ -296,5 +354,24 @@ export function listRows(workflows, state, facts, name, width, now = Date.now())
296
354
  if (more)
297
355
  rows.push({ id: `${w.wid}:more`, kind: "more", workflow: w, dim, text: ` └ … ${done.length - count} more` });
298
356
  }
357
+ if (!others.length)
358
+ return rows;
359
+ // Other sessions: one folded group; inside, each workflow (wid, name, origin, labels) and its live calls only.
360
+ const running = others.reduce((n, w) => n + liveCalls(w).length, 0);
361
+ rows.push({ id: "others", kind: "others", text: `${state.others ? "▾" : "▸"} Other sessions (${plural(others.length, "workflow")}, ${running} running)` });
362
+ if (!state.others)
363
+ return rows;
364
+ for (const w of others) {
365
+ const folded = state.folded.has(w.wid), open = liveCalls(w), latest = new Map();
366
+ for (const c of open)
367
+ latest.set(c.key, c);
368
+ const calls = [...latest.values()];
369
+ const head = ` ${folded ? "▸" : "▾"} ${[w.wid, w.name, originText(w.origin)].filter(Boolean).join(" · ")}`;
370
+ const room = Math.min(60, width - visibleWidth(head) - 3);
371
+ rows.push({ id: w.wid, kind: "workflow", workflow: w, other: true, dim: !calls.length, text: w.labels && room >= 12 ? `${head} · ${labelsText(w.labels, room)}` : head });
372
+ if (folded)
373
+ continue;
374
+ calls.forEach((c, i) => callRow(w, c, i === calls.length - 1 ? " └ " : " ├ ", undefined, false, true));
375
+ }
299
376
  return rows;
300
377
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-durable-subagents",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
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",