pi-crew 0.10.1 → 0.10.3

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 (127) hide show
  1. package/CHANGELOG.md +347 -0
  2. package/NOTICE.md +21 -0
  3. package/README.md +44 -2
  4. package/agents/executor.md +1 -1
  5. package/agents/test-engineer.md +1 -1
  6. package/dist/index.mjs +2555 -932
  7. package/package.json +2 -1
  8. package/schema.json +503 -94
  9. package/skills/real-test-pi-crew/REPORT-TEMPLATE.md +6 -2
  10. package/skills/real-test-pi-crew/SKILL.md +278 -79
  11. package/src/config/config-merge.ts +11 -1
  12. package/src/config/config-validation.ts +47 -2
  13. package/src/config/config.ts +28 -6
  14. package/src/config/defaults.ts +43 -11
  15. package/src/config/env-vars.ts +27 -2
  16. package/src/config/role-tools.ts +4 -2
  17. package/src/config/types.ts +55 -1
  18. package/src/extension/crew-cleanup.ts +13 -0
  19. package/src/extension/crew-vibes/footer.ts +19 -0
  20. package/src/extension/crew-vibes/index.ts +11 -1
  21. package/src/extension/register.ts +8 -0
  22. package/src/extension/registration/command-registration.ts +1 -0
  23. package/src/extension/registration/commands/run.ts +15 -1
  24. package/src/extension/registration/commands/shared.ts +8 -0
  25. package/src/extension/registration/foreground-run-controller.ts +10 -2
  26. package/src/extension/registration/lifecycle-handlers.ts +92 -11
  27. package/src/extension/registration/runtime-cleanup.ts +23 -5
  28. package/src/extension/registration/team-tool.ts +58 -6
  29. package/src/extension/registration/ui.ts +5 -4
  30. package/src/extension/team-tool/doctor.ts +364 -7
  31. package/src/extension/team-tool/handle-settings.ts +19 -0
  32. package/src/extension/team-tool/inspect.ts +10 -2
  33. package/src/extension/team-tool/run-deadline.ts +20 -3
  34. package/src/extension/team-tool/run.ts +26 -2
  35. package/src/extension/team-tool/status.ts +7 -0
  36. package/src/extension/team-tool.ts +35 -2
  37. package/src/hooks/registry.ts +59 -56
  38. package/src/prompt/inbox-poll.ts +90 -0
  39. package/src/prompt/message-tool.ts +166 -0
  40. package/src/prompt/prompt-runtime.ts +201 -18
  41. package/src/prompt/surface-worker.ts +720 -0
  42. package/src/prompt/worker-events-channel.ts +49 -3
  43. package/src/runtime/async-runner.ts +29 -1
  44. package/src/runtime/background-runner.ts +13 -7
  45. package/src/runtime/broker/broker-issuer.ts +27 -2
  46. package/src/runtime/broker/crew-broker-tokens.ts +56 -4
  47. package/src/runtime/broker/crew-broker.ts +261 -41
  48. package/src/runtime/child-pi/child-pi-constants.ts +8 -0
  49. package/src/runtime/child-pi/child-pi-spawn.ts +23 -9
  50. package/src/runtime/child-pi/child-pi-streams.ts +30 -2
  51. package/src/runtime/child-pi/child-pi.ts +353 -5
  52. package/src/runtime/crew-agent-records.ts +13 -1
  53. package/src/runtime/detached-run-results.ts +90 -0
  54. package/src/runtime/dispatch-batch.ts +12 -1
  55. package/src/runtime/event-log-tail-source.ts +374 -0
  56. package/src/runtime/finalize-run.ts +4 -0
  57. package/src/runtime/goal-workflow/adaptive-plan.ts +30 -3
  58. package/src/runtime/goal-workflow/dynamic-workflow-runner.ts +5 -1
  59. package/src/runtime/live-session/live-agent-manager.ts +34 -1
  60. package/src/runtime/live-session/live-control-realtime.ts +10 -0
  61. package/src/runtime/live-session/live-session-runtime.ts +47 -27
  62. package/src/runtime/manifest-cache.ts +128 -17
  63. package/src/runtime/merge-gate.ts +25 -9
  64. package/src/runtime/model/model-fallback.ts +7 -3
  65. package/src/runtime/model/pi-args.ts +54 -65
  66. package/src/runtime/output/sidechain-output.ts +61 -6
  67. package/src/runtime/process/proc-stat.ts +46 -0
  68. package/src/runtime/process/zombie-scanner.ts +32 -19
  69. package/src/runtime/process-status.ts +16 -1
  70. package/src/runtime/recovery/crash-recovery.ts +16 -0
  71. package/src/runtime/run-tracker.ts +77 -10
  72. package/src/runtime/spawn-policy.ts +27 -41
  73. package/src/runtime/surface/degrade.ts +776 -0
  74. package/src/runtime/surface/herdr-provider.ts +546 -0
  75. package/src/runtime/surface/launch-script.ts +172 -0
  76. package/src/runtime/surface/resolve-surface.ts +274 -0
  77. package/src/runtime/surface/surface-provider.ts +129 -0
  78. package/src/runtime/surface/surface-spawn.ts +475 -0
  79. package/src/runtime/surface/tmux-provider.ts +400 -0
  80. package/src/runtime/task-runner/child-executor.ts +47 -0
  81. package/src/runtime/task-runner/post-execution.ts +57 -2
  82. package/src/runtime/task-runner/prompt-builder.ts +1 -0
  83. package/src/runtime/task-runner/retrieval-orchestrator.ts +191 -56
  84. package/src/runtime/task-runner/state-helpers.ts +54 -30
  85. package/src/runtime/task-runner.ts +4 -2
  86. package/src/runtime/team-runner.ts +104 -2
  87. package/src/schema/config-schema.ts +25 -1
  88. package/src/state/atomic-write.ts +219 -40
  89. package/src/state/coordination/locks.ts +7 -5
  90. package/src/state/coordination/mailbox.ts +56 -10
  91. package/src/state/event-log/cursor.ts +413 -23
  92. package/src/state/event-log/event-log.ts +120 -113
  93. package/src/state/event-log/sequence-cache.ts +21 -3
  94. package/src/state/stores/plan-store.ts +1 -1
  95. package/src/state/stores/state-store.ts +171 -9
  96. package/src/state/types.ts +53 -0
  97. package/src/ui/dock-footer.ts +49 -0
  98. package/src/ui/inline-panel/agent-pane.ts +378 -0
  99. package/src/ui/inline-panel/agent-transcript.ts +338 -0
  100. package/src/ui/inline-panel/agent-view-overlay.ts +225 -0
  101. package/src/ui/inline-panel/crew-editor.ts +192 -0
  102. package/src/ui/inline-panel/index.ts +290 -0
  103. package/src/ui/inline-panel/panel-rows.ts +37 -0
  104. package/src/ui/inline-panel/panel-selection.ts +157 -0
  105. package/src/ui/inline-panel/panel-store.ts +111 -0
  106. package/src/ui/inline-panel/view-session-store.ts +36 -0
  107. package/src/ui/pi-ui-compat.ts +9 -0
  108. package/src/ui/render-diff.ts +16 -8
  109. package/src/ui/run-dashboard.ts +87 -42
  110. package/src/ui/run-event-bus.ts +10 -1
  111. package/src/ui/run-snapshot-cache.ts +83 -35
  112. package/src/ui/transcript-cache.ts +101 -13
  113. package/src/ui/transcript-viewer.ts +92 -24
  114. package/src/ui/widget/index.ts +203 -25
  115. package/src/ui/widget/task-list.ts +198 -0
  116. package/src/ui/widget/widget-formatters.ts +240 -4
  117. package/src/ui/widget/widget-renderer.ts +234 -37
  118. package/src/ui/widget/widget-types.ts +11 -0
  119. package/src/utils/child-process-shield.ts +106 -0
  120. package/src/utils/redaction.ts +7 -0
  121. package/src/utils/safe-abort.ts +45 -0
  122. package/src/utils/visual.ts +43 -0
  123. package/src/workflows/discover-workflows.ts +1 -0
  124. package/src/workflows/workflow-config.ts +7 -0
  125. package/src/worktree/worktree-manager.ts +65 -4
  126. package/workflows/default.workflow.md +36 -26
  127. package/workflows/strict-fast-fix.workflow.md +26 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * panel-store.ts — process-wide state shared by the inline panel's two halves.
3
+ *
4
+ * The editor wrapper mutates the cursor; the widget renderer and the transcript
5
+ * pane read it. Neither can own the state (the editor is created by pi's
6
+ * factory, the widget by another), so it lives here as a small observable
7
+ * singleton — the same shape pi-subtask keeps in its closure.
8
+ *
9
+ * Row projection is injected rather than computed here: the widget already owns
10
+ * the manifest/snapshot caches that produce the run list, and duplicating that
11
+ * read on every keypress would put disk I/O on the input path.
12
+ */
13
+
14
+ import type { PanelRow, PanelSelection, PanelTarget } from "./panel-selection.ts";
15
+ import { isAgentSelection } from "./panel-selection.ts";
16
+
17
+ let selection: PanelSelection = null;
18
+ let viewed: PanelTarget | undefined;
19
+ let rowsProvider: (() => PanelRow[]) | undefined;
20
+ const listeners = new Set<() => void>();
21
+
22
+ /** Install the row projection. Called once during panel wiring. */
23
+ export function setPanelRowsProvider(provider: (() => PanelRow[]) | undefined): void {
24
+ rowsProvider = provider;
25
+ }
26
+
27
+ /**
28
+ * Navigable rows, freshly projected on each call.
29
+ *
30
+ * A provider throw must never break input handling — a transient manifest read
31
+ * failure would otherwise make the panel swallow keys — so it degrades to an
32
+ * empty list, which the editor treats as "nothing to navigate".
33
+ */
34
+ export function panelRows(): PanelRow[] {
35
+ if (!rowsProvider) return [];
36
+ try {
37
+ return rowsProvider();
38
+ } catch {
39
+ return [];
40
+ }
41
+ }
42
+
43
+ export function getPanelSelection(): PanelSelection {
44
+ return selection;
45
+ }
46
+
47
+ export function setPanelSelection(next: PanelSelection): void {
48
+ if (next === selection) return;
49
+ if (isAgentSelection(selection) && isAgentSelection(next) && selection.runId === next.runId && selection.taskId === next.taskId) {
50
+ return;
51
+ }
52
+ selection = next;
53
+ notifyPanelChange();
54
+ }
55
+
56
+ export function getViewedAgent(): PanelTarget | undefined {
57
+ return viewed;
58
+ }
59
+
60
+ export function setViewedAgent(next: PanelTarget | undefined): void {
61
+ if (viewed === next) return;
62
+ if (viewed && next && viewed.runId === next.runId && viewed.taskId === next.taskId) return;
63
+ viewed = next;
64
+ notifyPanelChange();
65
+ }
66
+
67
+ /** True while the panel holds the cursor, i.e. keys are not going to the editor. */
68
+ export function isPanelFocused(): boolean {
69
+ return selection !== null;
70
+ }
71
+
72
+ /** What the widget renderer needs, in one read. */
73
+ export function panelDisplayState(): {
74
+ selectedTaskId: string | undefined;
75
+ viewedTaskId: string | undefined;
76
+ focused: boolean;
77
+ } {
78
+ return {
79
+ selectedTaskId: isAgentSelection(selection) ? selection.taskId : undefined,
80
+ viewedTaskId: viewed?.taskId,
81
+ // Cursor-driven: uncapping the row budget while the user is typing
82
+ // into the pane (viewed set, selection null) would jerk the layout on
83
+ // every pane open. The cursor entry is when the full list is needed.
84
+ focused: selection !== null,
85
+ };
86
+ }
87
+
88
+ export function subscribePanelChange(listener: () => void): () => void {
89
+ listeners.add(listener);
90
+ return () => {
91
+ listeners.delete(listener);
92
+ };
93
+ }
94
+
95
+ export function notifyPanelChange(): void {
96
+ for (const listener of [...listeners]) {
97
+ try {
98
+ listener();
99
+ } catch {
100
+ // A failing repaint listener must not stop the others.
101
+ }
102
+ }
103
+ }
104
+
105
+ /** Session teardown / test isolation. */
106
+ export function resetPanelStore(): void {
107
+ selection = null;
108
+ viewed = undefined;
109
+ rowsProvider = undefined;
110
+ listeners.clear();
111
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * view-session-store.ts — session-switch guard for run protection.
3
+ *
4
+ * Agent views are in-document panes (see agent-pane.ts / inline-panel's
5
+ * openPane): viewing an agent NEVER switches, resumes, or tears down a
6
+ * session. This store is the one piece of session-switch machinery that
7
+ * remains, and it protects runs from switches the USER makes (/resume, /new,
8
+ * /fork): a switch tears the current session down via session.abort(), which
9
+ * fires the abort signal of any tool call still in flight — a foreground
10
+ * team run created by that tool is linked to the turn's abort, so ANY switch
11
+ * seconds after a run starts used to kill the run's workers ("Child Pi
12
+ * exited with 143" → run cancelled). While the guard is set, the
13
+ * caller-abort propagation is suppressed (run-deadline.ts).
14
+ *
15
+ * Set by the session_before_switch handler (runs before teardown's abort),
16
+ * cleared on the next session_start (the switch landed) and on reconcile.
17
+ */
18
+
19
+ let sessionSwitchInFlight = false;
20
+
21
+ export function markSessionSwitchInFlight(): void {
22
+ sessionSwitchInFlight = true;
23
+ }
24
+
25
+ export function clearSessionSwitchInFlight(): void {
26
+ sessionSwitchInFlight = false;
27
+ }
28
+
29
+ export function isSessionSwitchInFlight(): boolean {
30
+ return sessionSwitchInFlight;
31
+ }
32
+
33
+ /** Test isolation. */
34
+ export function resetCrewViewSessionState(): void {
35
+ sessionSwitchInFlight = false;
36
+ }
@@ -46,6 +46,15 @@ export function setExtensionWidget(
46
46
  ctx.ui.setWidget(key, content as never, widgetOptions as WidgetOptions);
47
47
  }
48
48
 
49
+ /**
50
+ * Map the crew widget placement onto pi's `WidgetPlacement`. `"bottom"` is a
51
+ * crew-only placement (rendered inside the crew-vibes footer, below the quota
52
+ * lines); when a raw widget slot is involved it falls back to `belowEditor`.
53
+ */
54
+ export function toPiWidgetPlacement(placement: "aboveEditor" | "belowEditor" | "bottom"): "aboveEditor" | "belowEditor" {
55
+ return placement === "bottom" ? "belowEditor" : placement;
56
+ }
57
+
49
58
  type FooterFactory = (tui: unknown, theme: unknown, footerData: unknown) => unknown;
50
59
 
51
60
  /** Install a custom footer component, or pass `undefined` to restore pi's built-in footer.
@@ -36,10 +36,10 @@ const WORD_DIFF_MIN_SIM = 0.15;
36
36
  * characters relative to the longer of the two strings, using word-level
37
37
  * diff to identify the common (unchanged) parts. Returns a value in [0, 1].
38
38
  */
39
- function computeSimilarity(oldContent: string, newContent: string): number {
40
- const wordDiff = Diff.diffWords(oldContent, newContent);
39
+ function computeSimilarity(oldContent: string, newContent: string, wordDiff?: Diff.Change[]): number {
40
+ const parts = wordDiff ?? Diff.diffWords(oldContent, newContent);
41
41
  let commonChars = 0;
42
- for (const part of wordDiff) {
42
+ for (const part of parts) {
43
43
  if (!part.removed && !part.added) {
44
44
  commonChars += part.value.length;
45
45
  }
@@ -49,14 +49,19 @@ function computeSimilarity(oldContent: string, newContent: string): number {
49
49
  return commonChars / maxLen;
50
50
  }
51
51
 
52
- function renderIntraLineDiff(theme: CrewTheme, oldContent: string, newContent: string): { removedLine: string; addedLine: string } {
53
- const wordDiff = Diff.diffWords(oldContent, newContent);
52
+ function renderIntraLineDiff(
53
+ theme: CrewTheme,
54
+ oldContent: string,
55
+ newContent: string,
56
+ wordDiff?: Diff.Change[],
57
+ ): { removedLine: string; addedLine: string } {
58
+ const parts = wordDiff ?? Diff.diffWords(oldContent, newContent);
54
59
  let removedLine = "";
55
60
  let addedLine = "";
56
61
  let isFirstRemoved = true;
57
62
  let isFirstAdded = true;
58
63
 
59
- for (const part of wordDiff) {
64
+ for (const part of parts) {
60
65
  if (part.removed) {
61
66
  let value = part.value;
62
67
  if (isFirstRemoved) {
@@ -130,9 +135,12 @@ export function renderDiff(diffText: string, options: RenderDiffOptions = {}): s
130
135
  if (removedLines.length === 1 && addedLines.length === 1) {
131
136
  const oldContent = replaceTabs(removedLines[0]!.content);
132
137
  const newContent = replaceTabs(addedLines[0]!.content);
133
- const similarity = computeSimilarity(oldContent, newContent);
138
+ // PERF (2026-08-24): diffWords is the expensive call and was run
139
+ // TWICE on identical inputs (similarity + render). One pass, shared.
140
+ const wordDiff = Diff.diffWords(oldContent, newContent);
141
+ const similarity = computeSimilarity(oldContent, newContent, wordDiff);
134
142
  if (similarity >= WORD_DIFF_MIN_SIM) {
135
- const { removedLine, addedLine } = renderIntraLineDiff(theme, oldContent, newContent);
143
+ const { removedLine, addedLine } = renderIntraLineDiff(theme, oldContent, newContent, wordDiff);
136
144
  result.push(theme.fg("toolDiffRemoved", `-${removedLines[0]!.lineNum} ${removedLine}`));
137
145
  result.push(theme.fg("toolDiffAdded", `+${addedLines[0]!.lineNum} ${addedLine}`));
138
146
  } else {
@@ -162,11 +162,11 @@ function formatAge(iso: string | undefined): string | undefined {
162
162
  return `${Math.floor(ms / 3_600_000)}h`;
163
163
  }
164
164
 
165
- function readProgressPreview(run: TeamRunManifest, maxLines = 5, snapshotCache?: RunSnapshotCache): string[] {
165
+ function readProgressPreview(run: TeamRunManifest, maxLines = 5, snapshotCache?: RunSnapshotCache, resolve?: SnapshotResolver): string[] {
166
166
  // P0-6: prefer the snapshot's `recentOutputLines` (no disk I/O) over reading the
167
167
  // progress artifact on every render. The progress artifact content is captured
168
168
  // into the snapshot's recent events / output pipeline upstream.
169
- const snapshot = snapshotFor(run, snapshotCache);
169
+ const snapshot = resolve ? resolve(run) : snapshotFor(run, snapshotCache);
170
170
  if (snapshot?.recentOutputLines?.length) {
171
171
  return ["Progress:", ...snapshot.recentOutputLines.slice(0, maxLines)];
172
172
  }
@@ -206,8 +206,20 @@ function snapshotFor(run: TeamRunManifest, snapshotCache?: RunSnapshotCache): Ru
206
206
  }
207
207
  }
208
208
 
209
- function readRunTasks(run: TeamRunManifest, snapshotCache?: RunSnapshotCache): TeamTaskState[] {
210
- const snapshot = snapshotFor(run, snapshotCache);
209
+ /**
210
+ * PERF (2026-08-24, task 20) — per-frame snapshot resolver. The render path
211
+ * used to resolve each run's snapshot 6-8 times per frame (refreshRuns,
212
+ * buildSignature, groupedRuns, per-row, selected-run), and every
213
+ * `snapshotFor → refreshIfStale` call can stat several files per run when its
214
+ * own TTL expires. `renderUnsafe` now builds a frame-local Map keyed by runId
215
+ * and threads this resolver through every render-path helper. Helpers keep
216
+ * their plain direct-resolution behavior when no resolver is passed
217
+ * (keypress handlers and other callers outside a render frame).
218
+ */
219
+ type SnapshotResolver = (run: TeamRunManifest) => RunUiSnapshot | undefined;
220
+
221
+ function readRunTasks(run: TeamRunManifest, snapshotCache?: RunSnapshotCache, resolve?: SnapshotResolver): TeamTaskState[] {
222
+ const snapshot = resolve ? resolve(run) : snapshotFor(run, snapshotCache);
211
223
  if (snapshot) return snapshot.tasks;
212
224
  // P0-6: when a snapshot cache is provided but hasn't populated yet, return
213
225
  // empty (the render loop falls back to the empty pane placeholder) instead
@@ -266,15 +278,15 @@ function agentPreviewLine(agent: CrewAgentRecord, task: TeamTaskState | undefine
266
278
  );
267
279
  }
268
280
 
269
- function readAgentPreview(run: TeamRunManifest, maxLines = 5, options: RunDashboardOptions = {}): string[] {
281
+ function readAgentPreview(run: TeamRunManifest, maxLines = 5, options: RunDashboardOptions = {}, resolve?: SnapshotResolver): string[] {
270
282
  try {
271
- const snapshot = snapshotFor(run, options.snapshotCache);
283
+ const snapshot = resolve ? resolve(run) : snapshotFor(run, options.snapshotCache);
272
284
  // P0-6: when a snapshot cache is provided but hasn't populated yet, return
273
285
  // the empty-pane placeholder instead of calling `readCrewAgents` (disk I/O)
274
286
  // on every render tick. Legacy callers (no cache) keep the disk-read path
275
287
  // so existing unit tests continue to assert against concrete agent data.
276
288
  const agents = snapshot?.agents ?? (options.snapshotCache ? [] : readCrewAgents(run));
277
- const tasks = snapshot?.tasks ?? readRunTasks(run, options.snapshotCache);
289
+ const tasks = snapshot?.tasks ?? readRunTasks(run, options.snapshotCache, resolve);
278
290
  if (!agents.length) return ["Agents: (none)"];
279
291
  const totals = tasks.reduce(
280
292
  (acc, task) => {
@@ -305,8 +317,8 @@ function readAgentPreview(run: TeamRunManifest, maxLines = 5, options: RunDashbo
305
317
  }
306
318
  }
307
319
 
308
- function agentsFor(run: TeamRunManifest, snapshotCache?: RunSnapshotCache): CrewAgentRecord[] {
309
- const snapshot = snapshotFor(run, snapshotCache);
320
+ function agentsFor(run: TeamRunManifest, snapshotCache?: RunSnapshotCache, resolve?: SnapshotResolver): CrewAgentRecord[] {
321
+ const snapshot = resolve ? resolve(run) : snapshotFor(run, snapshotCache);
310
322
  if (snapshot) return snapshot.agents;
311
323
  // P0-6: when a snapshot cache is provided but hasn't populated yet, return
312
324
  // empty (callers handle the empty-state placeholder) instead of calling
@@ -319,8 +331,14 @@ function agentsFor(run: TeamRunManifest, snapshotCache?: RunSnapshotCache): Crew
319
331
  }
320
332
  }
321
333
 
322
- function runLabel(run: TeamRunManifest, selected: boolean, snapshotCache?: RunSnapshotCache, maxW?: number): string {
323
- const agents = agentsFor(run, snapshotCache);
334
+ function runLabel(
335
+ run: TeamRunManifest,
336
+ selected: boolean,
337
+ snapshotCache?: RunSnapshotCache,
338
+ maxW?: number,
339
+ resolve?: SnapshotResolver,
340
+ ): string {
341
+ const agents = agentsFor(run, snapshotCache, resolve);
324
342
  const stale = isLikelyOrphanedActiveRun(run, agents);
325
343
  const running = agents.find((agent) => agent.status === "running");
326
344
  const queued = agents.find((agent) => agent.status === "queued");
@@ -366,11 +384,11 @@ interface ResolvedRun {
366
384
  status: RunStatus;
367
385
  }
368
386
 
369
- function resolveRuns(runs: TeamRunManifest[], snapshotCache?: RunSnapshotCache): Map<string, ResolvedRun> {
387
+ function resolveRuns(runs: TeamRunManifest[], snapshotCache?: RunSnapshotCache, resolve?: SnapshotResolver): Map<string, ResolvedRun> {
370
388
  const map = new Map<string, ResolvedRun>();
371
389
  for (const run of runs) {
372
- const snapshot = snapshotFor(run, snapshotCache);
373
- const agents = snapshot?.agents ?? agentsFor(run, snapshotCache);
390
+ const snapshot = resolve ? resolve(run) : snapshotFor(run, snapshotCache);
391
+ const agents = snapshot?.agents ?? agentsFor(run, snapshotCache, resolve);
374
392
  const displayRun = snapshot?.manifest ?? run;
375
393
  const status: RunStatus = isLikelyOrphanedActiveRun(displayRun, agents) ? "stale" : (displayRun.status as RunStatus);
376
394
  map.set(run.runId, { manifest: run, snapshot, agents, status });
@@ -378,8 +396,12 @@ function resolveRuns(runs: TeamRunManifest[], snapshotCache?: RunSnapshotCache):
378
396
  return map;
379
397
  }
380
398
 
381
- function groupedRuns(runs: TeamRunManifest[], snapshotCache?: RunSnapshotCache): Array<{ label: string; run?: TeamRunManifest }> {
382
- const resolved = resolveRuns(runs, snapshotCache);
399
+ function groupedRuns(
400
+ runs: TeamRunManifest[],
401
+ snapshotCache?: RunSnapshotCache,
402
+ resolve?: SnapshotResolver,
403
+ ): Array<{ label: string; run?: TeamRunManifest }> {
404
+ const resolved = resolveRuns(runs, snapshotCache, resolve);
383
405
  const rows: Array<{ label: string; run?: TeamRunManifest }> = [];
384
406
  const active = runs.filter((run) =>
385
407
  isDisplayActiveRun(resolved.get(run.runId)?.snapshot?.manifest ?? run, resolved.get(run.runId)?.agents ?? []),
@@ -392,8 +414,13 @@ function groupedRuns(runs: TeamRunManifest[], snapshotCache?: RunSnapshotCache):
392
414
  return rows;
393
415
  }
394
416
 
395
- function selectedRunFromGrouped(runs: TeamRunManifest[], selected: number, snapshotCache?: RunSnapshotCache): TeamRunManifest | undefined {
396
- return groupedRuns(runs, snapshotCache).filter((row) => row.run)[selected]?.run;
417
+ function selectedRunFromGrouped(
418
+ runs: TeamRunManifest[],
419
+ selected: number,
420
+ snapshotCache?: RunSnapshotCache,
421
+ resolve?: SnapshotResolver,
422
+ ): TeamRunManifest | undefined {
423
+ return groupedRuns(runs, snapshotCache, resolve).filter((row) => row.run)[selected]?.run;
397
424
  }
398
425
 
399
426
  function countByStatus(runs: TeamRunManifest[], snapshotCache?: RunSnapshotCache): string {
@@ -520,9 +547,9 @@ export class RunDashboard implements DashboardComponent {
520
547
  return Math.max(12, Math.min(36, rows - 2));
521
548
  }
522
549
 
523
- private refreshRuns(): void {
550
+ private refreshRuns(resolve?: SnapshotResolver): void {
524
551
  if (!this.options.runProvider) return;
525
- const selectedRunId = this.selectedRunId();
552
+ const selectedRunId = this.selectedRunId(resolve);
526
553
  const next = this.options.runProvider();
527
554
  // P3 (#8): re-apply the workspaceId filter on EVERY refresh, not just
528
555
  // the constructor. Without this, runs from other sessions leak back in
@@ -532,7 +559,7 @@ export class RunDashboard implements DashboardComponent {
532
559
  ? unfiltered.filter((run) => !run.ownerSessionId || run.ownerSessionId === this.options.workspaceId)
533
560
  : unfiltered;
534
561
  if (selectedRunId) {
535
- const nextIndex = groupedRuns(this.runs, this.options.snapshotCache)
562
+ const nextIndex = groupedRuns(this.runs, this.options.snapshotCache, resolve)
536
563
  .filter((row) => row.run)
537
564
  .findIndex((row) => row.run?.runId === selectedRunId);
538
565
  if (nextIndex >= 0) this.selected = nextIndex;
@@ -564,7 +591,7 @@ export class RunDashboard implements DashboardComponent {
564
591
  }
565
592
  }
566
593
 
567
- private buildSignature(): string {
594
+ private buildSignature(resolve?: SnapshotResolver): string {
568
595
  // 1.10 (UI-P1-2) — short-TTL cache so we don't re-read every run's
569
596
  // snapshot on every render tick. `snapshotFor → refreshIfStale` can
570
597
  // stat multiple files per run when its own TTL expires, and the
@@ -579,9 +606,9 @@ export class RunDashboard implements DashboardComponent {
579
606
  let hasRunning = false;
580
607
  const statuses = this.runs
581
608
  .map((run) => {
582
- const snapshot = snapshotFor(run, this.options.snapshotCache);
609
+ const snapshot = resolve ? resolve(run) : snapshotFor(run, this.options.snapshotCache);
583
610
  const displayRun = snapshot?.manifest ?? run;
584
- const agents = snapshot?.agents ?? agentsFor(run, this.options.snapshotCache);
611
+ const agents = snapshot?.agents ?? agentsFor(run, this.options.snapshotCache, resolve);
585
612
  const stale = isLikelyOrphanedActiveRun(displayRun, agents);
586
613
  const status: RunStatus = stale ? "stale" : (displayRun.status as RunStatus);
587
614
  if (status === "running" || agents.some((agent) => agent.status === "running")) hasRunning = true;
@@ -611,8 +638,8 @@ export class RunDashboard implements DashboardComponent {
611
638
  this.schedulerHandle?.dispose();
612
639
  }
613
640
 
614
- private selectedRunId(): string | undefined {
615
- return selectedRunFromGrouped(this.runs, this.selected, this.options.snapshotCache)?.runId;
641
+ private selectedRunId(resolve?: SnapshotResolver): string | undefined {
642
+ return selectedRunFromGrouped(this.runs, this.selected, this.options.snapshotCache, resolve)?.runId;
616
643
  }
617
644
 
618
645
  render(width: number): string[] {
@@ -625,13 +652,25 @@ export class RunDashboard implements DashboardComponent {
625
652
  }
626
653
 
627
654
  private renderUnsafe(width: number): string[] {
628
- this.refreshRuns();
629
- const signature = this.buildSignature();
655
+ // PERF (2026-08-24): snapshot resolution stat'd 7-8 files per run 6-8
656
+ // times per frame. Resolve once per frame into a local map and thread
657
+ // it through every render-path consumer below.
658
+ const frameSnapshots = new Map<string, RunUiSnapshot | undefined>();
659
+ const snapshotOnce: SnapshotResolver = (run) => {
660
+ if (!frameSnapshots.has(run.runId)) frameSnapshots.set(run.runId, snapshotFor(run, this.options.snapshotCache));
661
+ return frameSnapshots.get(run.runId);
662
+ };
663
+ this.refreshRuns(snapshotOnce);
664
+ const signature = this.buildSignature(snapshotOnce);
630
665
  if (signature !== this.cachedVersion || this.cachedWidth !== width) {
631
666
  const innerWidth = Math.max(20, width - 4);
632
667
  const borderWidth = Math.min(innerWidth, Math.max(0, width - 2));
633
668
  const fg = (color: Parameters<CrewTheme["fg"]>[0], text: string) => this.theme.fg(color, text);
634
- const borderFill = (count: number) => new DynamicCrewBorder(this.theme).render(count)[0];
669
+ // PERF (2026-08-24): DynamicCrewBorder caches the rendered fill per
670
+ // instance — a new instance per line defeated it. One per render
671
+ // pass; every border()/sep() call below reuses the cached line.
672
+ const crewBorder = new DynamicCrewBorder(this.theme);
673
+ const borderFill = (count: number) => crewBorder.render(count)[0];
635
674
  const border = (left: string, right: string) => `${fg("border", left)}${borderFill(borderWidth)}${fg("border", right)}`;
636
675
  const row = (text: string) => `│ ${pad(truncate(text, innerWidth - 1), innerWidth - 1)}│`;
637
676
  const sep = () => border("├", "┤");
@@ -655,7 +694,7 @@ export class RunDashboard implements DashboardComponent {
655
694
  lines.push(row(fg("dim", "Start one: team action='run' · r reload · Esc close")));
656
695
  } else {
657
696
  // L-1: windowed run list so the selection can never scroll off-screen.
658
- const allGrouped = groupedRuns(this.runs, this.options.snapshotCache);
697
+ const allGrouped = groupedRuns(this.runs, this.options.snapshotCache, snapshotOnce);
659
698
  const selectable = allGrouped.filter((rowItem) => rowItem.run);
660
699
  const selectableCount = selectable.length;
661
700
  if (this.selected > selectableCount - 1) this.selected = Math.max(0, selectableCount - 1);
@@ -668,11 +707,11 @@ export class RunDashboard implements DashboardComponent {
668
707
  continue;
669
708
  }
670
709
  const idx = selectable.findIndex((c) => c.run?.runId === rowItem.run?.runId);
671
- const snap = snapshotFor(rowItem.run, this.options.snapshotCache);
710
+ const snap = snapshotOnce(rowItem.run);
672
711
  const run = snap?.manifest ?? rowItem.run;
673
- const agents = snap?.agents ?? agentsFor(rowItem.run, this.options.snapshotCache);
712
+ const agents = snap?.agents ?? agentsFor(rowItem.run, this.options.snapshotCache, snapshotOnce);
674
713
  const status: RunStatus = isLikelyOrphanedActiveRun(run, agents) ? "stale" : (run.status as RunStatus);
675
- const label = runLabel(run, idx === this.selected, this.options.snapshotCache, innerWidth - 2);
714
+ const label = runLabel(run, idx === this.selected, this.options.snapshotCache, innerWidth - 2, snapshotOnce);
676
715
  lines.push(row(applyStatusColor(this.theme, status, label)));
677
716
  }
678
717
  } else {
@@ -682,25 +721,28 @@ export class RunDashboard implements DashboardComponent {
682
721
  for (let gi = this.runScrollOffset; gi < Math.min(this.runScrollOffset + win.slots, selectableCount); gi++) {
683
722
  const rowItem = selectable[gi];
684
723
  if (!rowItem?.run) continue;
685
- const snap = snapshotFor(rowItem.run, this.options.snapshotCache);
724
+ const snap = snapshotOnce(rowItem.run);
686
725
  const run = snap?.manifest ?? rowItem.run;
687
- const agents = snap?.agents ?? agentsFor(rowItem.run, this.options.snapshotCache);
726
+ const agents = snap?.agents ?? agentsFor(rowItem.run, this.options.snapshotCache, snapshotOnce);
688
727
  const status: RunStatus = isLikelyOrphanedActiveRun(run, agents) ? "stale" : (run.status as RunStatus);
689
- const label = runLabel(run, gi === this.selected, this.options.snapshotCache, innerWidth - 2);
728
+ const label = runLabel(run, gi === this.selected, this.options.snapshotCache, innerWidth - 2, snapshotOnce);
690
729
  lines.push(row(applyStatusColor(this.theme, status, label)));
691
730
  }
692
731
  if (win.hasBottom)
693
732
  lines.push(row(fg("dim", `↓ ${selectableCount - (this.runScrollOffset + win.slots)} more below`)));
694
733
  }
695
734
 
696
- // Selected run detail — compact
697
- const selectedRun = selectedRunFromGrouped(this.runs, this.selected, this.options.snapshotCache);
735
+ // Selected run detail — compact. PERF (2026-08-24): reuse the
736
+ // `selectable` rows already derived from the single groupedRuns()
737
+ // computation above instead of recomputing grouping a third time
738
+ // (`selectedRunFromGrouped` is exactly `selectable[selected].run`).
739
+ const selectedRun = selectable[Math.min(this.selected, selectable.length - 1)]?.run;
698
740
  if (selectedRun) {
699
- const snap = snapshotFor(selectedRun, this.options.snapshotCache);
741
+ const snap = snapshotOnce(selectedRun);
700
742
  const r = snap?.manifest ?? selectedRun;
701
- const agents = snap?.agents ?? agentsFor(selectedRun, this.options.snapshotCache);
743
+ const agents = snap?.agents ?? agentsFor(selectedRun, this.options.snapshotCache, snapshotOnce);
702
744
  const statusStr: RunStatus = isLikelyOrphanedActiveRun(r, agents) ? "stale" : (r.status as RunStatus);
703
- const selectedTasks = snap?.tasks ?? readRunTasks(r, this.options.snapshotCache);
745
+ const selectedTasks = snap?.tasks ?? readRunTasks(r, this.options.snapshotCache, snapshotOnce);
704
746
  lines.push(sep());
705
747
  lines.push(row(`${fg("accent", "▸")} ${truncate(sanitizeLine(r.goal), innerWidth - 6)}`));
706
748
  // L-2: surface the failure/cancellation reason inline for terminal runs.
@@ -741,7 +783,10 @@ export class RunDashboard implements DashboardComponent {
741
783
  : this.activePane === "plan"
742
784
  ? safeRenderPane("plan", () => renderPlanPane(snap, { diff: this.planDiff }))
743
785
  : safeRenderPane("transcript", () => renderTranscriptPane(snap))
744
- : [...readAgentPreview(r, 4, this.options), ...readProgressPreview(r, 2, this.options.snapshotCache)];
786
+ : [
787
+ ...readAgentPreview(r, 4, this.options, snapshotOnce),
788
+ ...readProgressPreview(r, 2, this.options.snapshotCache, snapshotOnce),
789
+ ];
745
790
  const filteredPane = paneLines.filter((l) => l && !l.includes("(none)") && l.trim() !== "");
746
791
  if (filteredPane.length > 0) {
747
792
  lines.push(row(fg("dim", `── ${this.activePane} ──`)));
@@ -359,7 +359,16 @@ export function teamEventToRunEventType(event: TeamEvent): RunEventType | undefi
359
359
  if (type === "run.blocked") return "run_blocked";
360
360
  if (type === "run.running") return "run_started";
361
361
  if (type === "run.cancelled") return "run_cancelled";
362
- if (type === "task.progress" || type === "mailbox.message_queued" || type === "mailbox.message_delivered") return "mailbox_updated";
362
+ if (
363
+ type === "task.progress" ||
364
+ type === "mailbox.message_queued" ||
365
+ type === "mailbox.message_delivered" ||
366
+ // Task 5b (§15.2 wake): broker-side worker→parent wake signal. Maps to
367
+ // the existing mailbox_updated/run:state channel so sidebar+widget
368
+ // refresh through the render scheduler without new UI code.
369
+ type === "worker.message"
370
+ )
371
+ return "mailbox_updated";
363
372
  if (type === "run.effectiveness" || type === "task.attention") return "effectiveness_changed";
364
373
  return undefined;
365
374
  }