pi-crew 0.10.2 → 0.10.4
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/AGENTS.md +2 -1
- package/CHANGELOG.md +249 -0
- package/README.md +5 -1
- package/dist/index.mjs +10844 -7250
- package/docs/architecture.md +4 -4
- package/docs/commands-reference.md +3 -0
- package/docs/publishing.md +15 -3
- package/install.mjs +90 -39
- package/package.json +9 -3
- package/schema.json +11 -0
- package/scripts/README.md +4 -3
- package/skills/real-test-pi-crew/REPORT-TEMPLATE.md +7 -2
- package/skills/real-test-pi-crew/SKILL.md +428 -82
- package/src/config/config-merge.ts +11 -1
- package/src/config/config-validation.ts +40 -1
- package/src/config/config.ts +28 -6
- package/src/config/defaults.ts +35 -10
- package/src/config/env-vars.ts +27 -2
- package/src/config/migration-validator.ts +113 -0
- package/src/config/types.ts +36 -0
- package/src/extension/cross-extension-rpc.ts +3 -7
- package/src/extension/register.ts +13 -0
- package/src/extension/registration/lifecycle-handlers.ts +40 -9
- package/src/extension/registration/observability.ts +3 -7
- package/src/extension/registration/subagent-tools.ts +3 -7
- package/src/extension/registration/team-tool.ts +56 -12
- package/src/extension/registration/ui.ts +3 -8
- package/src/extension/registration/viewers.ts +3 -10
- package/src/extension/team-manager-command.ts +3 -7
- package/src/extension/team-tool/api/agent-control.ts +17 -10
- package/src/extension/team-tool/api/heartbeat.ts +4 -3
- package/src/extension/team-tool/api/mailbox.ts +33 -20
- package/src/extension/team-tool/api/plan-approval.ts +5 -5
- package/src/extension/team-tool/api/task-claims.ts +8 -7
- package/src/extension/team-tool/cancel.ts +6 -0
- package/src/extension/team-tool/doctor.ts +364 -7
- package/src/extension/team-tool/handle-settings.ts +23 -1
- package/src/extension/team-tool/inspect.ts +10 -2
- package/src/extension/team-tool/run.ts +3 -7
- package/src/extension/team-tool/status.ts +12 -0
- package/src/extension/team-tool.ts +41 -16
- package/src/hooks/registry.ts +62 -56
- package/src/prompt/inbox-poll.ts +90 -0
- package/src/prompt/message-tool.ts +166 -0
- package/src/prompt/prompt-runtime.ts +201 -18
- package/src/prompt/scratchpad-lifecycle.ts +3 -3
- package/src/prompt/surface-worker.ts +720 -0
- package/src/prompt/worker-events-channel.ts +49 -3
- package/src/runtime/async-runner.ts +29 -1
- package/src/runtime/background-runner.ts +43 -42
- package/src/runtime/broker/broker-issuer.ts +27 -2
- package/src/runtime/broker/crew-broker-tokens.ts +56 -4
- package/src/runtime/broker/crew-broker.ts +334 -443
- package/src/runtime/broker/delegate/delegate-event.ts +37 -0
- package/src/runtime/broker/mailbox-observer/mailbox-fanout.ts +59 -0
- package/src/runtime/broker/protocol/connection-state.ts +103 -0
- package/src/runtime/broker/protocol/events-replay.ts +68 -0
- package/src/runtime/broker/protocol/manifest-loader.ts +20 -0
- package/src/runtime/broker/protocol/msg-inbox.ts +69 -0
- package/src/runtime/broker/protocol/request-parsers.ts +175 -0
- package/src/runtime/broker/protocol/wait-auth.ts +46 -0
- package/src/runtime/child-pi/child-pi-spawn.ts +23 -9
- package/src/runtime/child-pi/child-pi-streams.ts +9 -1
- package/src/runtime/child-pi/child-pi.ts +368 -5
- package/src/runtime/crew-agent-records.ts +13 -1
- package/src/runtime/dispatch-batch.ts +12 -1
- package/src/runtime/event-log-tail-source.ts +374 -0
- package/src/runtime/finalize-run.ts +19 -7
- package/src/runtime/foreground-control.ts +19 -6
- package/src/runtime/goal-workflow/dynamic-workflow-context.ts +6 -0
- package/src/runtime/goal-workflow/dynamic-workflow-runner.ts +3 -0
- package/src/runtime/goal-workflow/goal-loop-runner.ts +29 -27
- package/src/runtime/goal-workflow/goal-state-store.ts +3 -0
- package/src/runtime/heartbeat/heartbeat-watcher.ts +3 -3
- package/src/runtime/live-session/live-agent-manager.ts +34 -1
- package/src/runtime/live-session/live-control-realtime.ts +10 -0
- package/src/runtime/live-session/live-session-runtime.ts +47 -27
- package/src/runtime/manifest-cache.ts +128 -17
- package/src/runtime/model/pi-args.ts +59 -65
- package/src/runtime/output/sidechain-output.ts +61 -6
- package/src/runtime/plan-replan.ts +3 -0
- package/src/runtime/process/proc-stat.ts +46 -0
- package/src/runtime/process/zombie-scanner.ts +32 -19
- package/src/runtime/spawn-policy.ts +27 -41
- package/src/runtime/stale-reconciler.ts +28 -3
- package/src/runtime/supervisor-contact.ts +3 -0
- package/src/runtime/surface/degrade.ts +776 -0
- package/src/runtime/surface/herdr-provider.ts +546 -0
- package/src/runtime/surface/launch-script.ts +172 -0
- package/src/runtime/surface/resolve-surface.ts +274 -0
- package/src/runtime/surface/surface-provider.ts +129 -0
- package/src/runtime/surface/surface-spawn.ts +475 -0
- package/src/runtime/surface/tmux-provider.ts +400 -0
- package/src/runtime/task-runner/child-executor.ts +80 -0
- package/src/runtime/task-runner/post-execution.ts +57 -2
- package/src/runtime/task-runner/prompt-builder.ts +1 -0
- package/src/runtime/task-runner/retrieval-orchestrator.ts +191 -56
- package/src/runtime/task-runner/state-helpers.ts +54 -30
- package/src/runtime/task-runner.ts +4 -2
- package/src/runtime/team-runner.ts +104 -3
- package/src/schema/config-schema.ts +24 -0
- package/src/state/atomic-write.ts +219 -40
- package/src/state/coordination/locks.ts +7 -5
- package/src/state/coordination/mailbox.ts +56 -10
- package/src/state/event-log/cursor.ts +413 -23
- package/src/state/event-log/event-log.ts +120 -113
- package/src/state/event-log/sequence-cache.ts +21 -3
- package/src/state/stores/ownership-map.ts +5 -4
- package/src/state/stores/plan-store.ts +12 -0
- package/src/state/stores/state-store.ts +103 -6
- package/src/state/types.ts +51 -0
- package/src/ui/inline-panel/agent-pane.ts +3 -0
- package/src/ui/powerbar-publisher.ts +3 -7
- package/src/ui/render-diff.ts +16 -8
- package/src/ui/run-action-dispatcher.ts +7 -10
- package/src/ui/run-dashboard.ts +87 -42
- package/src/ui/run-event-bus.ts +10 -1
- package/src/ui/run-snapshot-cache.ts +83 -35
- package/src/ui/settings-overlay.ts +4 -1
- package/src/ui/transcript-cache.ts +101 -13
- package/src/ui/transcript-viewer.ts +92 -24
- package/src/ui/widget/index.ts +32 -8
- package/src/utils/visual.ts +43 -0
- package/src/worktree/worktree-manager.ts +65 -4
package/src/state/types.ts
CHANGED
|
@@ -408,6 +408,9 @@ export interface TeamRunManifest {
|
|
|
408
408
|
* models.json happens to list first.
|
|
409
409
|
*/
|
|
410
410
|
modelContext?: RunModelContext;
|
|
411
|
+
/** MuxSurface A1 (spec §8.3): pane/pid/lockout state of this run. Absent on
|
|
412
|
+
* runs that never booted a surface worker and on older manifests. */
|
|
413
|
+
surface?: ManifestSurfaceState;
|
|
411
414
|
}
|
|
412
415
|
|
|
413
416
|
export interface RunModelContext {
|
|
@@ -421,6 +424,54 @@ export interface RunModelContext {
|
|
|
421
424
|
availableModels?: string[];
|
|
422
425
|
}
|
|
423
426
|
|
|
427
|
+
/**
|
|
428
|
+
* MuxSurface A1 run-scope surface state (spec §8.3 / §12.3). Written by the
|
|
429
|
+
* team-runner's surface-degrade controller (runtime/surface/degrade.ts) and
|
|
430
|
+
* read by doctor (T12). Plain JSON — manifests parse without a schema, so an
|
|
431
|
+
* absent field means "no surface worker ever booted" and older writers simply
|
|
432
|
+
* don't emit it (backward-compatible in both directions).
|
|
433
|
+
*
|
|
434
|
+
* Per-run scope: every new run starts without `surface`, which IS the
|
|
435
|
+
* "reset ở run sau" of the anti-flap policy (spec §7 step 3).
|
|
436
|
+
*/
|
|
437
|
+
export interface ManifestSurfaceState {
|
|
438
|
+
provider: "tmux" | "herdr" | null;
|
|
439
|
+
/** taskId → pane id of the LIVE pane (removed when the pane is released). */
|
|
440
|
+
panes: Record<string, string>;
|
|
441
|
+
/** taskId → pid, captured from the worker's own `worker.started` event. */
|
|
442
|
+
workerPids: Record<string, number>;
|
|
443
|
+
/**
|
|
444
|
+
* taskId → session file path when the worker self-reports one (optional
|
|
445
|
+
* field of §12.2 — never populated in A1 because pi does not expose its
|
|
446
|
+
* session path to extensions; kept for the degrade-resume seam).
|
|
447
|
+
*/
|
|
448
|
+
sessionPaths: Record<string, string>;
|
|
449
|
+
/**
|
|
450
|
+
* Tab-layout (spec 2026-08-27-surface-tab-layout §5): tabKey (runId) →
|
|
451
|
+
* tab/window ids của run — ghi khi worker spawn trong tab-flow (handle.tabId
|
|
452
|
+
* qua outcome), KHÔNG gỡ khi từng worker xong (tab sống tới run end). Entry
|
|
453
|
+
* được clear (giữ key rỗng) khi run end đã đóng tab qua closeTabForRun.
|
|
454
|
+
* Run dài vượt MAX_PANES_PER_TAB tích lũy nhiều id cùng key.
|
|
455
|
+
*
|
|
456
|
+
* Manifest TRÊN ĐĨA giữ nguyên tabIds sau run end (evidence cho doctor) —
|
|
457
|
+
* tabs non-empty KHÔNG đồng nghĩa orphan; doctor phải liveness-check từng
|
|
458
|
+
* tabId qua mux rồi close-by-ID idempotent (cleanupOrphanSurfacePanes,
|
|
459
|
+
* provider.closeTabById), không đóng mù theo số entry.
|
|
460
|
+
*/
|
|
461
|
+
tabs?: Record<string, string[]>;
|
|
462
|
+
/**
|
|
463
|
+
* Surface is OFF for the rest of this run since `since`:
|
|
464
|
+
* - cause "degrade": ≥1 degrade entry after the classify timeout
|
|
465
|
+
* (anti-flap; counts keep per-cause evidence for doctor).
|
|
466
|
+
* - cause "spawn-fail": 3 consecutive spawn failures.
|
|
467
|
+
*/
|
|
468
|
+
lockout?: {
|
|
469
|
+
since: string;
|
|
470
|
+
counts: { pane: number; mux: number };
|
|
471
|
+
cause: "degrade" | "spawn-fail";
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
424
475
|
export interface UsageState {
|
|
425
476
|
input?: number;
|
|
426
477
|
output?: number;
|
|
@@ -371,5 +371,8 @@ export class CrewAgentPane {
|
|
|
371
371
|
this.unsubscribePanel();
|
|
372
372
|
this.cachedManifest = undefined;
|
|
373
373
|
this.cachedRunId = undefined;
|
|
374
|
+
// Free the per-task transcript ring buffer (≤500 items with full
|
|
375
|
+
// message bodies) instead of retaining it for process lifetime.
|
|
376
|
+
if (this.currentTaskId) resetAgentTranscriptCursor(this.currentTaskId);
|
|
374
377
|
}
|
|
375
378
|
}
|
|
@@ -41,13 +41,9 @@ function hasPowerbarConsumer(events: EventBus): boolean {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
} catch (error) {
|
|
48
|
-
logInternalError("powerbar.statusFallback", error);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
44
|
+
// setStatusFallback removed (WI-5.1 / docs/decisions/2026-09-10): 0 callers,
|
|
45
|
+
// function was deliberately-unused; crew-widget owns the "pi-crew" status
|
|
46
|
+
// bar surface (see test/unit/ui/powerbar-publisher.test.ts:227).
|
|
51
47
|
|
|
52
48
|
function safeEmit(events: EventBus, event: string, data: unknown): void {
|
|
53
49
|
try {
|
package/src/ui/render-diff.ts
CHANGED
|
@@ -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
|
|
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
|
|
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(
|
|
53
|
-
|
|
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
|
|
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
|
-
|
|
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 {
|
|
@@ -3,25 +3,22 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
3
3
|
import type { handleTeamTool as HandleTeamToolFn } from "../extension/team-tool.ts";
|
|
4
4
|
import type { MetricRegistry } from "../observability/metric-registry.ts";
|
|
5
5
|
|
|
6
|
-
let _cachedHandleTeamTool: typeof HandleTeamToolFn | undefined;
|
|
7
6
|
async function handleTeamTool(
|
|
8
7
|
params: Parameters<typeof HandleTeamToolFn>[0],
|
|
9
8
|
ctx: Parameters<typeof HandleTeamToolFn>[1],
|
|
10
9
|
): Promise<Awaited<ReturnType<typeof HandleTeamToolFn>>> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_cachedHandleTeamTool = mod.handleTeamTool;
|
|
15
|
-
}
|
|
16
|
-
return _cachedHandleTeamTool(params, ctx);
|
|
10
|
+
// LAZY: avoid pulling team-tool.ts (and its entire runtime chain) into module load.
|
|
11
|
+
const mod = await import("../extension/team-tool.ts");
|
|
12
|
+
return mod.handleTeamTool(params, ctx);
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
import { isToolError, textFromToolResult } from "../extension/tool-result.ts";
|
|
20
16
|
import { readCrewAgents } from "../runtime/crew-agent-records.ts";
|
|
21
17
|
import { exportDiagnostic } from "../runtime/diagnostic-export.ts";
|
|
22
18
|
import type { MailboxDirection, MailboxMessage } from "../state/coordination/mailbox.ts";
|
|
23
|
-
import {
|
|
19
|
+
import { appendEventBuffered } from "../state/event-log/event-log.ts";
|
|
24
20
|
import { loadRunManifestById, saveRunTasks } from "../state/stores/state-store.ts";
|
|
21
|
+
import { logInternalError } from "../utils/internal-error.ts";
|
|
25
22
|
|
|
26
23
|
export interface RunActionResult {
|
|
27
24
|
ok: boolean;
|
|
@@ -141,12 +138,12 @@ export async function dispatchKillStaleWorkers(ctx: ExtensionContext, runId: str
|
|
|
141
138
|
};
|
|
142
139
|
});
|
|
143
140
|
saveRunTasks(loaded.manifest, tasks);
|
|
144
|
-
|
|
141
|
+
appendEventBuffered(loaded.manifest.eventsPath, {
|
|
145
142
|
type: "worker.kill_stale",
|
|
146
143
|
runId,
|
|
147
144
|
message: `Marked ${count} stale worker heartbeat(s) dead.`,
|
|
148
145
|
data: { count },
|
|
149
|
-
});
|
|
146
|
+
}).catch((e) => logInternalError("run_action_dispatcher.buffered", e, "type=worker.kill_stale"));
|
|
150
147
|
return {
|
|
151
148
|
ok: true,
|
|
152
149
|
message: `Marked ${count} stale worker heartbeat(s) dead.`,
|
package/src/ui/run-dashboard.ts
CHANGED
|
@@ -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
|
-
|
|
210
|
-
|
|
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(
|
|
323
|
-
|
|
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(
|
|
382
|
-
|
|
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(
|
|
396
|
-
|
|
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
|
-
|
|
629
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
: [
|
|
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} ──`)));
|
package/src/ui/run-event-bus.ts
CHANGED
|
@@ -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 (
|
|
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
|
}
|