@timmyjl12/pi-subagents 0.20.0 → 0.21.0

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.
Files changed (159) hide show
  1. package/CHANGELOG.md +862 -827
  2. package/README.md +1125 -1080
  3. package/dist/active-agents-prompt.d.ts +31 -9
  4. package/dist/active-agents-prompt.js +73 -9
  5. package/dist/agent-color.js +9 -1
  6. package/dist/agent-file-toggle.d.ts +1 -1
  7. package/dist/agent-manager.d.ts +405 -18
  8. package/dist/agent-manager.js +1661 -131
  9. package/dist/agent-runner.d.ts +45 -6
  10. package/dist/agent-runner.js +109 -18
  11. package/dist/agent-types.d.ts +30 -7
  12. package/dist/agent-types.js +38 -9
  13. package/dist/awaited-result.d.ts +37 -0
  14. package/dist/awaited-result.js +150 -0
  15. package/dist/child-session-shutdown.d.ts +19 -1
  16. package/dist/child-session-shutdown.js +60 -11
  17. package/dist/cleanup-plans.d.ts +10 -0
  18. package/dist/cleanup-plans.js +112 -0
  19. package/dist/cross-extension-rpc.d.ts +8 -1
  20. package/dist/cross-extension-rpc.js +59 -5
  21. package/dist/custom-agents.d.ts +34 -9
  22. package/dist/custom-agents.js +308 -111
  23. package/dist/default-agents.d.ts +1 -1
  24. package/dist/env.d.ts +1 -1
  25. package/dist/error-log.d.ts +6 -0
  26. package/dist/error-log.js +8 -0
  27. package/dist/force-main-model.d.ts +21 -0
  28. package/dist/force-main-model.js +28 -0
  29. package/dist/goal-bridge.d.ts +155 -0
  30. package/dist/goal-bridge.js +305 -0
  31. package/dist/group-join.d.ts +5 -1
  32. package/dist/group-join.js +52 -7
  33. package/dist/index.d.ts +5 -5
  34. package/dist/index.js +2827 -333
  35. package/dist/invocation-config.d.ts +30 -3
  36. package/dist/invocation-config.js +30 -1
  37. package/dist/memory.d.ts +1 -1
  38. package/dist/mention-clone.d.ts +1 -1
  39. package/dist/model-scope.d.ts +1 -1
  40. package/dist/nested-tools.d.ts +22 -1
  41. package/dist/nested-tools.js +120 -26
  42. package/dist/output-file.d.ts +15 -4
  43. package/dist/output-file.js +146 -43
  44. package/dist/prompts.d.ts +1 -1
  45. package/dist/recovery.d.ts +1 -1
  46. package/dist/report-cleanup.d.ts +204 -0
  47. package/dist/report-cleanup.js +1632 -0
  48. package/dist/report-store.d.ts +738 -0
  49. package/dist/report-store.js +3612 -0
  50. package/dist/schedule-store.d.ts +14 -6
  51. package/dist/schedule-store.js +88 -58
  52. package/dist/schedule.d.ts +20 -8
  53. package/dist/schedule.js +135 -74
  54. package/dist/settings.d.ts +39 -11
  55. package/dist/settings.js +22 -5
  56. package/dist/status-note.d.ts +1 -1
  57. package/dist/structured-output.d.ts +1 -1
  58. package/dist/types.d.ts +32 -3
  59. package/dist/ui/agent-mention.d.ts +2 -2
  60. package/dist/ui/agent-widget.d.ts +82 -13
  61. package/dist/ui/agent-widget.js +155 -37
  62. package/dist/ui/cleanup-preview.d.ts +59 -0
  63. package/dist/ui/cleanup-preview.js +466 -0
  64. package/dist/ui/conversation-viewer.d.ts +4 -4
  65. package/dist/ui/conversation-viewer.js +10 -6
  66. package/dist/ui/fleet-list.d.ts +3 -3
  67. package/dist/ui/fleet-list.js +3 -3
  68. package/dist/ui/fleet-overlay.d.ts +37 -6
  69. package/dist/ui/fleet-overlay.js +214 -18
  70. package/dist/ui/hub-feed.d.ts +52 -0
  71. package/dist/ui/hub-feed.js +148 -0
  72. package/dist/ui/native-transcript.js +5 -1
  73. package/dist/ui/schedule-menu.d.ts +1 -1
  74. package/dist/ui/schedule-menu.js +1 -1
  75. package/dist/ui/workflow-card.d.ts +4 -4
  76. package/dist/ui/workflow-dialog.d.ts +4 -4
  77. package/dist/ui/workflow-dialog.js +8 -3
  78. package/dist/ui/workflow-menu.d.ts +2 -2
  79. package/dist/usage.d.ts +12 -0
  80. package/dist/usage.js +28 -1
  81. package/dist/workflow/entry.d.ts +3 -3
  82. package/dist/workflow/host.d.ts +7 -4
  83. package/dist/workflow/host.js +162 -48
  84. package/dist/workflow/journal.d.ts +23 -7
  85. package/dist/workflow/journal.js +80 -23
  86. package/dist/workflow/progress.d.ts +1 -1
  87. package/dist/workflow/runtime.d.ts +45 -6
  88. package/dist/workflow/runtime.js +105 -16
  89. package/dist/workflow/task.d.ts +13 -4
  90. package/dist/workflow/task.js +7 -1
  91. package/dist/workflow/tool-description.d.ts +7 -2
  92. package/dist/workflow/tool-description.js +10 -5
  93. package/docs/{FORK.md → DEVELOPMENT.md} +4 -4
  94. package/docs/artifacts.md +93 -0
  95. package/docs/rpc.md +252 -189
  96. package/docs/runtime-performance.md +53 -0
  97. package/docs/workflows.md +48 -18
  98. package/examples/agent-tool-description.md +2 -2
  99. package/examples/workflows/review-panel.js +6 -3
  100. package/package.json +5 -5
  101. package/src/active-agents-prompt.ts +115 -39
  102. package/src/agent-color.ts +10 -2
  103. package/src/agent-file-toggle.ts +2 -2
  104. package/src/agent-manager.ts +3312 -1601
  105. package/src/agent-runner.ts +164 -36
  106. package/src/agent-types.ts +56 -11
  107. package/src/awaited-result.ts +187 -0
  108. package/src/child-session-shutdown.ts +114 -46
  109. package/src/cleanup-plans.ts +112 -0
  110. package/src/cross-extension-rpc.ts +68 -9
  111. package/src/custom-agents.ts +384 -112
  112. package/src/default-agents.ts +1 -1
  113. package/src/enabled-models.ts +1 -1
  114. package/src/env.ts +1 -1
  115. package/src/error-log.ts +10 -1
  116. package/src/force-main-model.ts +29 -0
  117. package/src/goal-bridge.ts +468 -0
  118. package/src/group-join.ts +56 -9
  119. package/src/index.ts +2987 -349
  120. package/src/invocation-config.ts +50 -4
  121. package/src/memory.ts +1 -1
  122. package/src/mention-clone.ts +3 -3
  123. package/src/model-scope.ts +1 -1
  124. package/src/nested-tools.ts +164 -33
  125. package/src/output-file.ts +168 -46
  126. package/src/prompts.ts +1 -1
  127. package/src/recovery.ts +2 -2
  128. package/src/report-cleanup.ts +2044 -0
  129. package/src/report-store.ts +4130 -0
  130. package/src/schedule-store.ts +244 -201
  131. package/src/schedule.ts +144 -80
  132. package/src/settings.ts +61 -16
  133. package/src/skill-loader.ts +1 -1
  134. package/src/standalone-fallback.ts +2 -2
  135. package/src/status-note.ts +1 -1
  136. package/src/structured-output.ts +1 -1
  137. package/src/types.ts +33 -3
  138. package/src/ui/agent-mention.ts +3 -3
  139. package/src/ui/agent-widget.ts +179 -45
  140. package/src/ui/cleanup-preview.ts +518 -0
  141. package/src/ui/conversation-viewer.ts +19 -15
  142. package/src/ui/fleet-list.ts +7 -7
  143. package/src/ui/fleet-overlay.ts +1048 -847
  144. package/src/ui/hub-feed.ts +179 -0
  145. package/src/ui/native-transcript.ts +7 -3
  146. package/src/ui/schedule-menu.ts +4 -4
  147. package/src/ui/workflow-card.ts +4 -4
  148. package/src/ui/workflow-dialog.ts +10 -6
  149. package/src/ui/workflow-menu.ts +4 -4
  150. package/src/usage.ts +53 -3
  151. package/src/workflow/collisions.ts +1 -1
  152. package/src/workflow/entry.ts +3 -3
  153. package/src/workflow/host.ts +174 -54
  154. package/src/workflow/journal.ts +80 -23
  155. package/src/workflow/progress.ts +1 -1
  156. package/src/workflow/runtime.ts +146 -23
  157. package/src/workflow/saved.ts +3 -3
  158. package/src/workflow/task.ts +18 -7
  159. package/src/workflow/tool-description.ts +10 -5
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * fleet-overlay.ts — model-picker-style two-pane fleet overlay.
3
3
  *
4
- * The full-screen counterpart to the below-editor FleetView list
5
- * (`fleet-list.ts`, which stays the compact glanceable surface). Frame, top to
6
- * bottom:
4
+ * The full-screen counterpart to the compact AgentWidget list
5
+ * (`agent-widget.ts`, placed above or below the editor). Frame, top to bottom:
7
6
  *
8
7
  * ```
9
8
  * ╭─ Subagents ─────────────────── 9 agents · 4 workflows ─╮
@@ -34,6 +33,14 @@
34
33
  * the entry — the conversation overlay for an agent, the workflow inspector for
35
34
  * a run — stacked over this one; Esc there returns here.
36
35
  *
36
+ * Agent Hub additions (oh-my-pi parity):
37
+ * - under the detail card, a live transcript tail of the selected agent
38
+ * (prompts, replies, tool calls, failures) plus its current tools and context use;
39
+ * - `2` switches the right pane to an Activity log across agents (`f` cycles
40
+ * All/Errors/Responses/Tools, `s` toggles all agents vs the selected one), `1` returns;
41
+ * - `t` shows nested agents as a parent → child tree, `/` filters by id/handle/name/task;
42
+ * - `x` twice stops a running agent, `r` resumes a finished one; Alt+A closes.
43
+ *
37
44
  * Narrow terminals (below {@link TWO_PANE_MIN_WIDTH} columns) drop the left
38
45
  * pane entirely: the detail card renders full width and carries a position
39
46
  * marker (`3 of 9`), so the roster is still navigable by ↑/↓ without ever
@@ -48,9 +55,9 @@
48
55
  * imports, no hardcoded colors.
49
56
  */
50
57
  import { type Component, type Focusable } from "@earendil-works/pi-tui";
51
- import type { AgentRecord } from "../types.js";
52
- import { type AgentActivity, type Theme } from "./agent-widget.js";
53
- import { type FleetWorkflow } from "./fleet-list.js";
58
+ import type { AgentRecord } from "../types.ts";
59
+ import { type AgentActivity, type Theme } from "./agent-widget.ts";
60
+ import { type FleetWorkflow } from "./fleet-list.ts";
54
61
  /** Below this the left pane is dropped and the detail card runs full width. */
55
62
  export declare const TWO_PANE_MIN_WIDTH = 72;
56
63
  /**
@@ -71,6 +78,7 @@ export type RosterEntry = {
71
78
  } | {
72
79
  readonly kind: "agent";
73
80
  readonly record: AgentRecord;
81
+ readonly depth?: number;
74
82
  };
75
83
  /** What the overlay reads from the host; every source is pulled live per render. */
76
84
  export interface FleetOverlayDeps {
@@ -101,6 +109,12 @@ export interface FleetOverlayDeps {
101
109
  readonly openWorkflow: (id: string) => Promise<void> | void;
102
110
  readonly done: (result: undefined) => void;
103
111
  readonly notify?: (message: string, type?: "info" | "warning" | "error") => void;
112
+ /** Every record including nested children, for the tree view (`t`). Defaults to `records`. */
113
+ readonly allRecords?: () => AgentRecord[];
114
+ /** Stop a running agent (`x` twice). Returns whether it was stopped. */
115
+ readonly stopAgent?: (record: AgentRecord) => boolean;
116
+ /** Resume a finished agent with a follow-up (`r`); the host asks for the message. */
117
+ readonly resumeAgent?: (record: AgentRecord) => Promise<void> | void;
104
118
  }
105
119
  /**
106
120
  * The fleet overlay. See the file header for the frame layout and the
@@ -119,6 +133,15 @@ export declare class FleetOverlay implements Component, Focusable {
119
133
  private readonly dismissed;
120
134
  private closed;
121
135
  private layout;
136
+ /** Right pane: the selected entry's card + live transcript, or the cross-agent activity log. */
137
+ private tab;
138
+ private tree;
139
+ private filter;
140
+ private filtering;
141
+ private activityFilter;
142
+ private activityScope;
143
+ /** Key armed by a first `x`; a second `x` on the same row stops it. */
144
+ private stopArmed;
122
145
  private readonly timer;
123
146
  private focusedFlag;
124
147
  constructor(deps: FleetOverlayDeps);
@@ -150,6 +173,9 @@ export declare class FleetOverlay implements Component, Focusable {
150
173
  /** Remove the selected settled row from this view. Running work is not dismissible. */
151
174
  private dismissSelected;
152
175
  handleInput(data: string): void;
176
+ private handleFilterInput;
177
+ /** Hub keys; true when the key was consumed. */
178
+ private handleHubKey;
153
179
  private terminalRows;
154
180
  private layoutFor;
155
181
  private renderSectionRow;
@@ -163,6 +189,11 @@ export declare class FleetOverlay implements Component, Focusable {
163
189
  */
164
190
  private agentTail;
165
191
  private detailLines;
192
+ private feedLine;
193
+ /** Card, then the live transcript filling the rest of the pane (newest at the bottom). */
194
+ private agentPane;
195
+ /** Activity tab: newest events across agents (or the selected one), filtered by kind. */
196
+ private activityPane;
166
197
  private headerRight;
167
198
  private footerLine;
168
199
  render(width: number): string[];
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * fleet-overlay.ts — model-picker-style two-pane fleet overlay.
3
3
  *
4
- * The full-screen counterpart to the below-editor FleetView list
5
- * (`fleet-list.ts`, which stays the compact glanceable surface). Frame, top to
6
- * bottom:
4
+ * The full-screen counterpart to the compact AgentWidget list
5
+ * (`agent-widget.ts`, placed above or below the editor). Frame, top to bottom:
7
6
  *
8
7
  * ```
9
8
  * ╭─ Subagents ─────────────────── 9 agents · 4 workflows ─╮
@@ -34,6 +33,14 @@
34
33
  * the entry — the conversation overlay for an agent, the workflow inspector for
35
34
  * a run — stacked over this one; Esc there returns here.
36
35
  *
36
+ * Agent Hub additions (oh-my-pi parity):
37
+ * - under the detail card, a live transcript tail of the selected agent
38
+ * (prompts, replies, tool calls, failures) plus its current tools and context use;
39
+ * - `2` switches the right pane to an Activity log across agents (`f` cycles
40
+ * All/Errors/Responses/Tools, `s` toggles all agents vs the selected one), `1` returns;
41
+ * - `t` shows nested agents as a parent → child tree, `/` filters by id/handle/name/task;
42
+ * - `x` twice stops a running agent, `r` resumes a finished one; Alt+A closes.
43
+ *
37
44
  * Narrow terminals (below {@link TWO_PANE_MIN_WIDTH} columns) drop the left
38
45
  * pane entirely: the detail card renders full width and carries a position
39
46
  * marker (`3 of 9`), so the roster is still navigable by ↑/↓ without ever
@@ -47,13 +54,14 @@
47
54
  * primitives and the structural widget `Theme` (fg/bold) only — no sibling
48
55
  * imports, no hardcoded colors.
49
56
  */
50
- import { isKeyRelease, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
57
+ import { decodeKittyPrintable, isKeyRelease, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
51
58
  import { formatAdvisorLastReview, formatAdvisorState } from "../advisor-status.js";
52
59
  import { hasAgentBadge, renderAgentName } from "../agent-color.js";
53
60
  import { isTopLevelAgent } from "../agent-manager.js";
54
61
  import { getLifetimeCost, getLifetimeTotal } from "../usage.js";
55
- import { buildInvocationTags, describeActivity, formatCost } from "./agent-widget.js";
62
+ import { buildInvocationTags, describeActivity, formatCost, sanitizeRowText } from "./agent-widget.js";
56
63
  import { formatFleetElapsed, formatFleetTokens } from "./fleet-list.js";
64
+ import { ACTIVITY_FILTERS, activityFeed, transcriptTail, treeOrder, } from "./hub-feed.js";
57
65
  // ─── geometry ────────────────────────────────────────────────────────────────
58
66
  /**
59
67
  * Rows outside the body pane: top rule, blank, split opener, split closer,
@@ -251,6 +259,18 @@ function sectionOfWorkflow(run) {
251
259
  function entryKey(entry) {
252
260
  return entry.kind === "agent" ? `agent:${entry.record.id}` : `workflow:${entry.workflow.id}`;
253
261
  }
262
+ const FEED_COLOR = { prompt: "accent", response: "text", tool: "muted", error: "error" };
263
+ const FEED_MARK = { prompt: "›", response: "◆", tool: "⚙", error: "✗" };
264
+ function clockTime(at) {
265
+ if (at === undefined)
266
+ return "--:--:--";
267
+ const d = new Date(at);
268
+ return [d.getHours(), d.getMinutes(), d.getSeconds()].map(n => String(n).padStart(2, "0")).join(":");
269
+ }
270
+ /** Id, handle, alias, type, task — what `/` matches against. */
271
+ function agentHaystack(record) {
272
+ return [record.id, record.handle, record.alias, record.type, record.description].filter(Boolean).join(" ").toLowerCase();
273
+ }
254
274
  /**
255
275
  * The fleet overlay. See the file header for the frame layout and the
256
276
  * roster → detail navigation model.
@@ -268,6 +288,15 @@ export class FleetOverlay {
268
288
  dismissed = new Set();
269
289
  closed = false;
270
290
  layout;
291
+ /** Right pane: the selected entry's card + live transcript, or the cross-agent activity log. */
292
+ tab = "agents";
293
+ tree = false;
294
+ filter = "";
295
+ filtering = false;
296
+ activityFilter = "all";
297
+ activityScope = "all";
298
+ /** Key armed by a first `x`; a second `x` on the same row stops it. */
299
+ stopArmed;
271
300
  timer;
272
301
  // Focusable: no embedded editor/IME, so the flag is a plain holder.
273
302
  focusedFlag = false;
@@ -300,21 +329,28 @@ export class FleetOverlay {
300
329
  }
301
330
  /** Flat row list: section headers interleaved, entries newest-first within. */
302
331
  buildRows() {
332
+ const query = this.filter.trim().toLowerCase();
303
333
  const agents = this.agentRecords();
304
- const runs = this.deps.workflows().filter(run => !this.dismissed.has(`workflow:${run.id}`));
334
+ const runs = this.deps.workflows().filter(run => !this.dismissed.has(`workflow:${run.id}`) && (!query || `${run.id} ${run.name}`.toLowerCase().includes(query)));
335
+ const all = this.tree ? (this.deps.allRecords?.() ?? this.deps.records()).filter(record => record.session !== undefined) : [];
305
336
  const rows = [];
306
337
  for (const section of SECTIONS) {
307
338
  const sectionRuns = runs
308
339
  .filter(run => sectionOfWorkflow(run) === section.id)
309
340
  .sort((a, b) => b.startedAt - a.startedAt);
310
341
  const sectionAgents = agents
311
- .filter(record => sectionOfAgent(record) === section.id && !this.dismissed.has(`agent:${record.id}`))
342
+ .filter(record => sectionOfAgent(record) === section.id && (this.tree || !this.dismissed.has(`agent:${record.id}`)))
312
343
  .sort((a, b) => b.startedAt - a.startedAt);
344
+ // Tree view: each top-level agent is followed by its nested children (any status).
345
+ const agentRows = this.tree
346
+ ? treeOrder(sectionAgents, all, record => this.dismissed.has(`agent:${record.id}`))
347
+ .map(({ record, depth }) => ({ kind: "agent", record, depth }))
348
+ : sectionAgents.map(record => ({ kind: "agent", record }));
313
349
  const entries = [
314
350
  // Runs sit above agents, as in the widget: a run owns most of the
315
351
  // agents that would otherwise crowd the same section.
316
352
  ...sectionRuns.map(workflow => ({ kind: "workflow", workflow })),
317
- ...sectionAgents.map(record => ({ kind: "agent", record })),
353
+ ...agentRows.filter(row => !query || agentHaystack(row.record).includes(query)),
318
354
  ];
319
355
  if (entries.length === 0)
320
356
  continue;
@@ -418,12 +454,30 @@ export class FleetOverlay {
418
454
  handleInput(data) {
419
455
  if (this.closed || isKeyRelease(data))
420
456
  return;
421
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
457
+ if (this.filtering) {
458
+ this.handleFilterInput(data);
459
+ return;
460
+ }
461
+ if (matchesKey(data, "ctrl+c") || matchesKey(data, "alt+a")) {
462
+ this.finish();
463
+ return;
464
+ }
465
+ if (matchesKey(data, "escape")) {
466
+ // Esc ladder: clear an active filter first, then close.
467
+ if (this.filter) {
468
+ this.filter = "";
469
+ this.deps.tui.requestRender();
470
+ return;
471
+ }
422
472
  this.finish();
423
473
  return;
424
474
  }
425
475
  const rows = this.buildRows();
426
476
  const entries = this.reconcile(rows);
477
+ if (this.handleHubKey(data, rows)) {
478
+ this.deps.tui.requestRender();
479
+ return;
480
+ }
427
481
  const page = Math.max(1, (this.layout?.bodyHeight ?? 10) - 1);
428
482
  const movements = [
429
483
  { keys: ["up"], delta: -1, wrap: true },
@@ -451,6 +505,77 @@ export class FleetOverlay {
451
505
  return;
452
506
  }
453
507
  }
508
+ handleFilterInput(data) {
509
+ if (matchesKey(data, "escape")) {
510
+ this.filtering = false;
511
+ this.filter = "";
512
+ }
513
+ else if (matchesKey(data, "enter") || matchesKey(data, "return")) {
514
+ this.filtering = false;
515
+ }
516
+ else if (matchesKey(data, "backspace")) {
517
+ this.filter = this.filter.slice(0, -1);
518
+ }
519
+ else {
520
+ // Text keys arrive as bare bytes, or as CSI-u presses when the terminal
521
+ // enables the Kitty protocol (flag 1 sends every printable key that way).
522
+ const text = decodeKittyPrintable(data) ?? (data.length === 1 && data >= " " && data !== "\x7f" ? data : undefined);
523
+ if (text)
524
+ this.filter += text;
525
+ }
526
+ this.deps.tui.requestRender();
527
+ }
528
+ /** Hub keys; true when the key was consumed. */
529
+ handleHubKey(data, rows) {
530
+ const entry = this.selectedEntry(rows);
531
+ const armed = this.stopArmed;
532
+ this.stopArmed = undefined;
533
+ if (matchesKey(data, "1"))
534
+ this.tab = "agents";
535
+ else if (matchesKey(data, "2"))
536
+ this.tab = "activity";
537
+ else if (matchesKey(data, "t"))
538
+ this.tree = !this.tree;
539
+ else if (matchesKey(data, "/"))
540
+ this.filtering = true;
541
+ else if (matchesKey(data, "f") && this.tab === "activity") {
542
+ this.activityFilter = ACTIVITY_FILTERS[(ACTIVITY_FILTERS.indexOf(this.activityFilter) + 1) % ACTIVITY_FILTERS.length];
543
+ }
544
+ else if (matchesKey(data, "s") && this.tab === "activity") {
545
+ this.activityScope = this.activityScope === "all" ? "selected" : "all";
546
+ }
547
+ else if (matchesKey(data, "x")) {
548
+ if (entry?.kind !== "agent" || !this.deps.stopAgent)
549
+ return true;
550
+ const record = entry.record;
551
+ if (record.status !== "running" && record.status !== "queued") {
552
+ this.deps.notify?.("Only a running agent can be stopped.", "info");
553
+ return true;
554
+ }
555
+ const key = entryKey(entry);
556
+ if (armed !== key) {
557
+ this.stopArmed = key;
558
+ this.deps.notify?.(`Press x again to stop "${record.description}".`, "warning");
559
+ return true;
560
+ }
561
+ if (this.deps.stopAgent(record))
562
+ this.deps.notify?.(`Stopped "${record.description}".`, "info");
563
+ }
564
+ else if (matchesKey(data, "r")) {
565
+ if (entry?.kind !== "agent" || !this.deps.resumeAgent)
566
+ return true;
567
+ const record = entry.record;
568
+ if (record.status === "running" || record.status === "queued") {
569
+ this.deps.notify?.("Agent is still running — Enter opens it to steer.", "info");
570
+ return true;
571
+ }
572
+ const key = entryKey(entry);
573
+ void Promise.resolve(this.deps.resumeAgent(record)).then(() => this.afterStackedClose(key), error => this.deps.notify?.(`Could not resume: ${errorMessage(error)}`, "error"));
574
+ }
575
+ else
576
+ return false;
577
+ return true;
578
+ }
454
579
  // ── layout ────────────────────────────────────────────────────────────
455
580
  terminalRows() {
456
581
  const rows = this.deps.tui.terminal?.rows ?? 40;
@@ -493,7 +618,7 @@ export class FleetOverlay {
493
618
  if (entry.kind === "workflow") {
494
619
  const run = entry.workflow;
495
620
  const kind = this.theme.fg(selected ? "text" : "muted", "workflow");
496
- const name = selected ? this.theme.fg("text", run.name) : run.name;
621
+ const name = selected ? this.theme.fg("text", sanitizeRowText(run.name)) : sanitizeRowText(run.name);
497
622
  head = `${cursor}${dot} ${kind} ${name}`;
498
623
  const elapsed = (run.completedAt ?? Date.now()) - run.startedAt;
499
624
  const agents = `${run.doneCount}/${run.totalCount} agent${run.totalCount === 1 ? "" : "s"}`;
@@ -504,8 +629,10 @@ export class FleetOverlay {
504
629
  const name = renderAgentName(record.type, this.theme, selected
505
630
  ? { fallbackColor: "text", bold: hasAgentBadge(record.type) }
506
631
  : { fallbackColor: "muted" });
507
- const description = selected ? this.theme.fg("text", record.description) : record.description;
508
- head = `${cursor}${dot} ${name} ${description}`;
632
+ const description = selected ? this.theme.fg("text", sanitizeRowText(record.description)) : sanitizeRowText(record.description);
633
+ const depth = entry.depth ?? 0;
634
+ const indent = depth > 0 ? `${" ".repeat(depth - 1)}${this.theme.fg("dim", "└ ")}` : "";
635
+ head = `${cursor}${indent}${dot} ${name} ${description}`;
509
636
  const elapsed = formatFleetElapsed((record.completedAt ?? Date.now()) - record.startedAt);
510
637
  const tokens = formatFleetTokens(getLifetimeTotal(record.lifetimeUsage));
511
638
  const cost = this.deps.showCost() ? formatCost(getLifetimeCost(record.lifetimeUsage)) : "";
@@ -562,7 +689,7 @@ export class FleetOverlay {
562
689
  if (entry.kind === "workflow") {
563
690
  const run = entry.workflow;
564
691
  const section = SECTIONS.find(s => s.id === sectionOfWorkflow(run)) ?? SECTIONS[0];
565
- const nameLine = `${this.theme.fg(section.color, this.glyphs.bullet)} ${this.theme.fg("muted", "workflow")} ${run.name}`;
692
+ const nameLine = `${this.theme.fg(section.color, this.glyphs.bullet)} ${this.theme.fg("muted", "workflow")} ${sanitizeRowText(run.name)}`;
566
693
  lines.push(rightAlign(nameLine, this.theme.fg("dim", positionRaw), width));
567
694
  lines.push(this.theme.fg("dim", ` ${BOX.horizontal.repeat(Math.max(0, width - 4))}`));
568
695
  const elapsed = formatFleetElapsed((run.completedAt ?? Date.now()) - run.startedAt);
@@ -580,13 +707,13 @@ export class FleetOverlay {
580
707
  lines.push(rightAlign(nameLine, this.theme.fg("dim", positionRaw), width));
581
708
  lines.push(this.theme.fg("dim", ` ${BOX.horizontal.repeat(Math.max(0, width - 4))}`));
582
709
  lines.push(this.field("Type", this.theme.fg("text", record.type), width));
583
- lines.push(this.field("Task", this.theme.fg("muted", record.description), width));
710
+ lines.push(this.field("Task", this.theme.fg("muted", sanitizeRowText(record.description)), width));
584
711
  lines.push(this.field("Status", this.theme.fg(section.color, record.status), width));
585
712
  const { modelName, modelId, tags } = buildInvocationTags(record.invocation);
586
- lines.push(this.field("Model", this.theme.fg("text", modelId ?? modelName ?? "session default"), width));
713
+ lines.push(this.field("Model", this.theme.fg("text", sanitizeRowText(modelId ?? modelName ?? "session default")), width));
587
714
  const [thinking, ...flags] = splitThinkingTag(tags);
588
715
  if (thinking)
589
- lines.push(this.field("Thinking", this.theme.fg("text", thinking), width));
716
+ lines.push(this.field("Thinking", this.theme.fg("text", sanitizeRowText(thinking)), width));
590
717
  if (flags.length > 0)
591
718
  lines.push(this.field("Flags", this.theme.fg("muted", flags.join(" · ")), width));
592
719
  lines.push(this.field("Elapsed", this.theme.fg("text", formatFleetElapsed((record.completedAt ?? Date.now()) - record.startedAt)), width));
@@ -597,6 +724,17 @@ export class FleetOverlay {
597
724
  lines.push(this.field("Cost", this.theme.fg("text", cost), width));
598
725
  }
599
726
  lines.push(this.field("Tools", this.theme.fg("text", String(record.toolUses)), width));
727
+ const activity = this.deps.activity.get(record.id);
728
+ if ((record.status === "running" || record.status === "queued") && activity && activity.activeTools.size > 0) {
729
+ lines.push(this.field("Now", this.theme.fg("accent", [...activity.activeTools.values()].join(", ")), width));
730
+ }
731
+ const usage = record.session
732
+ ?.getContextUsage?.();
733
+ if (typeof usage?.percent === "number") {
734
+ lines.push(this.field("Context", this.theme.fg("text", `${Math.round(usage.percent)}%`), width));
735
+ }
736
+ if (record.parentAgentId)
737
+ lines.push(this.field("Parent", this.theme.fg("muted", record.parentAgentId), width));
600
738
  const advisor = record.advisorStatus;
601
739
  lines.push(this.field("Advisor", this.theme.fg("muted", formatAdvisorState(advisor)), width));
602
740
  if (advisor && (advisor.state !== "off" || advisor.reviews > 0 || advisor.lastReviewAt !== undefined)) {
@@ -614,6 +752,45 @@ export class FleetOverlay {
614
752
  lines.push(this.theme.fg("dim", " Enter to open full view · Esc to close"));
615
753
  return lines.map(line => clip(line, width));
616
754
  }
755
+ feedLine(event, width, prefix = "") {
756
+ const mark = this.theme.fg(FEED_COLOR[event.kind], FEED_MARK[event.kind]);
757
+ return clip(` ${prefix}${mark} ${this.theme.fg(FEED_COLOR[event.kind], event.text)}`, width);
758
+ }
759
+ /** Card, then the live transcript filling the rest of the pane (newest at the bottom). */
760
+ agentPane(rows, width, height) {
761
+ const card = this.detailLines(rows, width);
762
+ const entry = this.selectedEntry(rows);
763
+ const room = height - card.length - 2;
764
+ if (entry?.kind !== "agent" || room < 2)
765
+ return card.slice(0, height);
766
+ const tail = transcriptTail(entry.record, room);
767
+ if (tail.length === 0)
768
+ return card;
769
+ return [
770
+ ...card,
771
+ "",
772
+ this.theme.fg("dim", clip(` ${BOX.horizontal} Live transcript ${BOX.horizontal.repeat(Math.max(0, width - 22))}`, width)),
773
+ ...tail.map(event => this.feedLine(event, width)),
774
+ ].slice(0, height);
775
+ }
776
+ /** Activity tab: newest events across agents (or the selected one), filtered by kind. */
777
+ activityPane(rows, width, height) {
778
+ const entry = this.selectedEntry(rows);
779
+ const scoped = this.activityScope === "selected" && entry?.kind === "agent";
780
+ const records = scoped
781
+ ? [entry.record]
782
+ : this.entriesOf(rows).flatMap(row => (row.entry.kind === "agent" ? [row.entry.record] : []));
783
+ const header = `${this.theme.bold(this.theme.fg("accent", "Activity"))} ` +
784
+ this.theme.fg("dim", `${this.activityFilter} · ${scoped ? "selected agent" : "all agents"} · f filter · s scope · 1 back`);
785
+ const feed = activityFeed(records, { filter: this.activityFilter, limit: Math.max(0, height - 2) });
786
+ const lines = [clip(` ${header}`, width), this.theme.fg("dim", ` ${BOX.horizontal.repeat(Math.max(0, width - 4))}`)];
787
+ if (feed.length === 0)
788
+ lines.push(this.theme.fg("muted", " No activity matches."));
789
+ for (const item of feed) {
790
+ lines.push(this.feedLine(item, width, `${this.theme.fg("dim", clockTime(item.at))} ${this.theme.fg("muted", item.agent)} `));
791
+ }
792
+ return lines.slice(0, height);
793
+ }
617
794
  // ── frame ─────────────────────────────────────────────────────────────
618
795
  headerRight(entries) {
619
796
  const agents = entries.filter(row => row.entry.kind === "agent").length;
@@ -621,17 +798,34 @@ export class FleetOverlay {
621
798
  const parts = [`${agents} agent${agents === 1 ? "" : "s"}`];
622
799
  if (workflows > 0)
623
800
  parts.push(`${workflows} workflow${workflows === 1 ? "" : "s"}`);
801
+ if (this.tree)
802
+ parts.push("tree");
803
+ if (this.filter || this.filtering)
804
+ parts.push(`/${this.filter}${this.filtering ? "▏" : ""}`);
624
805
  return parts.join(" · ");
625
806
  }
626
807
  footerLine(width) {
627
808
  const separator = this.theme.fg("dim", " · ");
809
+ if (this.filtering) {
810
+ return clip(` ${keyHint(this.theme, "type", "filter")}${separator}${keyHint(this.theme, "enter", "keep")}${separator}${keyHint(this.theme, "esc", "clear")}`, width);
811
+ }
628
812
  const required = [
629
813
  keyHint(this.theme, "↑↓", "move"),
630
814
  keyHint(this.theme, "enter", "open"),
631
815
  keyHint(this.theme, "d", "dismiss"),
632
816
  ];
633
817
  const close = keyHint(this.theme, "esc", "close");
634
- return clip(` ${required.join(separator)}${separator}${close}`, width);
818
+ const hub = [
819
+ keyHint(this.theme, "1/2", this.tab === "agents" ? "activity" : "agents"),
820
+ keyHint(this.theme, "t", "tree"),
821
+ keyHint(this.theme, "/", "filter"),
822
+ keyHint(this.theme, "x", "stop"),
823
+ keyHint(this.theme, "r", "resume"),
824
+ ];
825
+ // Hub hints are extras: they drop out first on a narrow frame.
826
+ const base = ` ${required.join(separator)}${separator}${close}`;
827
+ const full = ` ${required.join(separator)}${separator}${hub.join(separator)}${separator}${close}`;
828
+ return clip(visibleWidth(full) <= width ? full : base, width);
635
829
  }
636
830
  render(width) {
637
831
  const requested = Math.max(1, Math.floor(width));
@@ -647,7 +841,9 @@ export class FleetOverlay {
647
841
  const rows = this.buildRows();
648
842
  const entries = this.reconcile(rows);
649
843
  this.ensureSelectionVisible(rows);
650
- const detail = this.detailLines(rows, layout.bodyWidth).slice(0, layout.bodyHeight);
844
+ const detail = this.tab === "activity"
845
+ ? this.activityPane(rows, layout.bodyWidth, layout.bodyHeight)
846
+ : this.agentPane(rows, layout.bodyWidth, layout.bodyHeight);
651
847
  const lines = [];
652
848
  lines.push(topRule(this.theme, w, "Subagents", this.headerRight(entries)));
653
849
  lines.push(contentRow(this.theme, "", w));
@@ -0,0 +1,52 @@
1
+ /**
2
+ * hub-feed.ts — pure data for the fleet overlay's live panes (omp Agent Hub parity).
3
+ *
4
+ * - `transcriptTail`: the last few events of one agent's child session — prompts,
5
+ * replies, tool calls and failed results — for the right pane under the detail card.
6
+ * - `activityFeed`: the same events across every agent, newest first, for the
7
+ * Activity tab, with All / Errors / Responses / Tools filters.
8
+ * - `treeOrder`: parent → child ordering for the tree view.
9
+ *
10
+ * Everything is derived from `session.messages` on render; no extra state is
11
+ * recorded, so the feed can never disagree with the conversation viewer.
12
+ */
13
+ import type { AgentRecord } from "../types.ts";
14
+ export type FeedKind = "prompt" | "response" | "tool" | "error";
15
+ export type ActivityFilter = "all" | "errors" | "responses" | "tools";
16
+ export declare const ACTIVITY_FILTERS: readonly ActivityFilter[];
17
+ export interface FeedEvent {
18
+ readonly kind: FeedKind;
19
+ readonly text: string;
20
+ readonly at?: number;
21
+ }
22
+ export interface ActivityEntry extends FeedEvent {
23
+ readonly agentId: string;
24
+ readonly agent: string;
25
+ }
26
+ /** Events of one message, in order. */
27
+ export declare function eventsOf(message: unknown): FeedEvent[];
28
+ /** The last `max` events of an agent's session, oldest → newest (bottom is live). */
29
+ export declare function transcriptTail(record: AgentRecord, max: number): FeedEvent[];
30
+ /**
31
+ * Combined log across agents, newest first. Each agent contributes at most
32
+ * `perAgent` recent events so one chatty agent cannot crowd out the rest.
33
+ */
34
+ export declare function activityFeed(records: readonly AgentRecord[], options: {
35
+ filter: ActivityFilter;
36
+ limit: number;
37
+ perAgent?: number;
38
+ }): ActivityEntry[];
39
+ export interface TreeRow {
40
+ readonly record: AgentRecord;
41
+ readonly depth: number;
42
+ }
43
+ /**
44
+ * Parent → child order. Roots are the given top-level records in their given
45
+ * order; each child follows its parent, oldest first. Orphans (parent swept)
46
+ * surface as roots so nothing disappears.
47
+ *
48
+ * `hidden` drops a row from the output without dropping what is under it: the
49
+ * subtree is still traversed, one level up, so a view filter (a dismissed row)
50
+ * can never re-insert the row it removed or hide its descendants.
51
+ */
52
+ export declare function treeOrder(roots: readonly AgentRecord[], all: readonly AgentRecord[], hidden?: (record: AgentRecord) => boolean): TreeRow[];