pi-crew 0.1.44 → 0.1.45

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 (142) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/agents/analyst.md +11 -11
  3. package/agents/critic.md +11 -11
  4. package/agents/executor.md +11 -11
  5. package/agents/explorer.md +11 -11
  6. package/agents/planner.md +11 -11
  7. package/agents/reviewer.md +11 -11
  8. package/agents/security-reviewer.md +11 -11
  9. package/agents/test-engineer.md +11 -11
  10. package/agents/verifier.md +11 -11
  11. package/agents/writer.md +11 -11
  12. package/docs/refactor-tasks-phase3.md +394 -394
  13. package/docs/refactor-tasks-phase4.md +564 -564
  14. package/docs/refactor-tasks-phase5.md +402 -402
  15. package/docs/refactor-tasks-phase6.md +662 -662
  16. package/docs/research-extension-examples.md +297 -297
  17. package/docs/research-extension-system.md +324 -324
  18. package/docs/research-optimization-plan.md +548 -548
  19. package/docs/research-phase10-distillation.md +198 -198
  20. package/docs/research-phase11-distillation.md +201 -201
  21. package/docs/research-pi-coding-agent.md +357 -357
  22. package/docs/research-source-pi-crew-reference.md +174 -174
  23. package/docs/runtime-flow.md +148 -148
  24. package/docs/source-runtime-refactor-map.md +83 -83
  25. package/index.ts +6 -6
  26. package/package.json +1 -1
  27. package/src/agents/agent-serializer.ts +34 -34
  28. package/src/extension/cross-extension-rpc.ts +82 -82
  29. package/src/extension/register.ts +8 -1
  30. package/src/extension/registration/commands.ts +18 -2
  31. package/src/extension/registration/compaction-guard.ts +125 -125
  32. package/src/extension/registration/subagent-tools.ts +148 -148
  33. package/src/extension/registration/team-tool.ts +26 -8
  34. package/src/extension/run-bundle-schema.ts +89 -89
  35. package/src/extension/run-maintenance.ts +43 -43
  36. package/src/extension/team-tool/cancel.ts +105 -102
  37. package/src/extension/team-tool/context.ts +1 -0
  38. package/src/extension/team-tool/handle-settings.ts +188 -188
  39. package/src/extension/team-tool/inspect.ts +41 -41
  40. package/src/extension/team-tool/lifecycle-actions.ts +79 -79
  41. package/src/extension/team-tool/plan.ts +19 -19
  42. package/src/extension/team-tool/respond.ts +83 -66
  43. package/src/extension/team-tool/run.ts +1 -0
  44. package/src/i18n.ts +184 -184
  45. package/src/observability/exporters/otlp-exporter.ts +77 -77
  46. package/src/prompt/prompt-runtime.ts +72 -72
  47. package/src/runtime/agent-control.ts +63 -63
  48. package/src/runtime/agent-memory.ts +72 -72
  49. package/src/runtime/agent-observability.ts +114 -114
  50. package/src/runtime/async-marker.ts +26 -26
  51. package/src/runtime/attention-events.ts +28 -28
  52. package/src/runtime/background-runner.ts +53 -53
  53. package/src/runtime/child-pi.ts +444 -444
  54. package/src/runtime/completion-guard.ts +190 -190
  55. package/src/runtime/crew-agent-records.ts +8 -0
  56. package/src/runtime/delivery-coordinator.ts +153 -142
  57. package/src/runtime/direct-run.ts +35 -35
  58. package/src/runtime/foreground-control.ts +82 -82
  59. package/src/runtime/green-contract.ts +46 -46
  60. package/src/runtime/group-join.ts +106 -106
  61. package/src/runtime/heartbeat-gradient.ts +28 -28
  62. package/src/runtime/heartbeat-watcher.ts +124 -124
  63. package/src/runtime/live-agent-control.ts +87 -87
  64. package/src/runtime/live-agent-manager.ts +85 -85
  65. package/src/runtime/live-control-realtime.ts +36 -36
  66. package/src/runtime/live-session-runtime.ts +305 -305
  67. package/src/runtime/overflow-recovery.ts +175 -156
  68. package/src/runtime/parallel-research.ts +44 -44
  69. package/src/runtime/pi-json-output.ts +111 -111
  70. package/src/runtime/policy-engine.ts +79 -79
  71. package/src/runtime/progress-event-coalescer.ts +43 -43
  72. package/src/runtime/recovery-recipes.ts +74 -74
  73. package/src/runtime/retry-executor.ts +64 -64
  74. package/src/runtime/role-permission.ts +39 -39
  75. package/src/runtime/session-resources.ts +25 -25
  76. package/src/runtime/session-snapshot.ts +59 -59
  77. package/src/runtime/session-usage.ts +79 -79
  78. package/src/runtime/sidechain-output.ts +29 -29
  79. package/src/runtime/stale-reconciler.ts +199 -179
  80. package/src/runtime/supervisor-contact.ts +59 -59
  81. package/src/runtime/task-display.ts +38 -38
  82. package/src/runtime/task-output-context.ts +127 -127
  83. package/src/runtime/task-runner/live-executor.ts +101 -101
  84. package/src/runtime/task-runner/progress.ts +119 -119
  85. package/src/runtime/task-runner/result-utils.ts +14 -14
  86. package/src/runtime/task-runner/state-helpers.ts +22 -22
  87. package/src/runtime/team-runner.ts +13 -4
  88. package/src/runtime/worker-heartbeat.ts +21 -21
  89. package/src/runtime/worker-startup.ts +57 -57
  90. package/src/state/state-store.ts +43 -0
  91. package/src/state/task-claims.ts +44 -44
  92. package/src/state/types.ts +2 -0
  93. package/src/state/usage.ts +29 -29
  94. package/src/subagents/async-entry.ts +1 -1
  95. package/src/subagents/index.ts +3 -3
  96. package/src/subagents/live/control.ts +1 -1
  97. package/src/subagents/live/manager.ts +1 -1
  98. package/src/subagents/live/realtime.ts +1 -1
  99. package/src/subagents/live/session-runtime.ts +1 -1
  100. package/src/subagents/manager.ts +1 -1
  101. package/src/subagents/spawn.ts +1 -1
  102. package/src/teams/team-serializer.ts +38 -38
  103. package/src/types/diff.d.ts +18 -18
  104. package/src/ui/crew-footer.ts +101 -101
  105. package/src/ui/crew-select-list.ts +111 -111
  106. package/src/ui/crew-widget.ts +5 -1
  107. package/src/ui/dashboard-panes/mailbox-pane.ts +2 -1
  108. package/src/ui/dashboard-panes/metrics-pane.ts +34 -34
  109. package/src/ui/dynamic-border.ts +25 -25
  110. package/src/ui/layout-primitives.ts +106 -106
  111. package/src/ui/loaders.ts +158 -158
  112. package/src/ui/powerbar-publisher.ts +1 -1
  113. package/src/ui/render-diff.ts +119 -119
  114. package/src/ui/render-scheduler.ts +143 -143
  115. package/src/ui/run-snapshot-cache.ts +56 -37
  116. package/src/ui/snapshot-types.ts +5 -0
  117. package/src/ui/spinner.ts +17 -17
  118. package/src/ui/status-colors.ts +58 -58
  119. package/src/ui/syntax-highlight.ts +116 -116
  120. package/src/utils/atomic-write.ts +33 -33
  121. package/src/utils/completion-dedupe.ts +63 -63
  122. package/src/utils/frontmatter.ts +68 -68
  123. package/src/utils/git.ts +262 -262
  124. package/src/utils/ids.ts +12 -12
  125. package/src/utils/names.ts +27 -27
  126. package/src/utils/redaction.ts +44 -44
  127. package/src/utils/safe-paths.ts +47 -47
  128. package/src/utils/sleep.ts +32 -32
  129. package/src/workflows/validate-workflow.ts +40 -40
  130. package/src/worktree/branch-freshness.ts +45 -45
  131. package/teams/default.team.md +12 -12
  132. package/teams/fast-fix.team.md +11 -11
  133. package/teams/implementation.team.md +18 -18
  134. package/teams/parallel-research.team.md +14 -14
  135. package/teams/research.team.md +11 -11
  136. package/teams/review.team.md +12 -12
  137. package/workflows/default.workflow.md +29 -29
  138. package/workflows/fast-fix.workflow.md +22 -22
  139. package/workflows/implementation.workflow.md +38 -38
  140. package/workflows/parallel-research.workflow.md +46 -46
  141. package/workflows/research.workflow.md +22 -22
  142. package/workflows/review.workflow.md +30 -30
@@ -1,143 +1,143 @@
1
- import { logInternalError } from "../utils/internal-error.ts";
2
-
3
- export interface RenderSchedulerEventBus {
4
- on?: (event: string, handler: (payload: unknown) => void) => (() => void) | void;
5
- }
6
-
7
- export interface RenderSchedulerOptions {
8
- debounceMs?: number;
9
- fallbackMs?: number;
10
- events?: string[];
11
- onInvalidate?: (payload: unknown) => void;
12
- }
13
-
14
- const DEFAULT_EVENTS = [
15
- "crew.run.created",
16
- "crew.run.completed",
17
- "crew.run.failed",
18
- "crew.run.cancelled",
19
- "crew.subagent.completed",
20
- "crew.subagent.failed",
21
- "crew.mailbox.updated",
22
- "crew.mailbox.message",
23
- ];
24
-
25
- /**
26
- * Coordinates UI renders with debounce + fallback polling.
27
- *
28
- * Critical: uses recursive setTimeout instead of setInterval + a rendering
29
- * guard (`rendering` / `pendingRender`) so that when render() takes longer
30
- * than the fallback interval, callbacks do NOT pile up and storm the event
31
- * loop. Instead, overlapping schedules are collapsed into a single deferred
32
- * re-render.
33
- */
34
- export class RenderScheduler {
35
- private readonly render: () => void;
36
- private readonly onInvalidate?: (payload: unknown) => void;
37
- private readonly debounceMs: number;
38
- private readonly fallbackMs: number;
39
- private debounceTimer: ReturnType<typeof setTimeout> | undefined;
40
- private fallbackTimer: ReturnType<typeof setTimeout> | undefined;
41
- private disposed = false;
42
- private lastEventAt = 0;
43
- private rendering = false;
44
- private pendingRender = false;
45
- private readonly unsubs: Array<() => void> = [];
46
-
47
- constructor(events: RenderSchedulerEventBus | undefined, render: () => void, options: RenderSchedulerOptions = {}) {
48
- this.render = render;
49
- this.onInvalidate = options.onInvalidate;
50
- this.debounceMs = options.debounceMs ?? 75;
51
- this.fallbackMs = options.fallbackMs ?? 750;
52
- for (const event of options.events ?? DEFAULT_EVENTS) this.subscribe(events, event);
53
- this.fallbackTimer = setTimeout(() => this.fallbackLoop(), this.fallbackMs);
54
- this.fallbackTimer.unref();
55
- }
56
-
57
- private subscribe(events: RenderSchedulerEventBus | undefined, event: string): void {
58
- if (!events?.on) return;
59
- const handler = (payload: unknown): void => this.schedule(payload);
60
- try {
61
- const unsub = events.on(event, handler);
62
- if (typeof unsub === "function") this.unsubs.push(unsub);
63
- } catch (error) {
64
- logInternalError("render-scheduler.subscribe", error, event);
65
- }
66
- }
67
-
68
- /** Recursive setTimeout — avoids setInterval timer storms. */
69
- private fallbackLoop(): void {
70
- if (this.disposed) return;
71
- if (Date.now() - this.lastEventAt < this.fallbackMs) {
72
- if (this.disposed) return;
73
- this.fallbackTimer = setTimeout(() => this.fallbackLoop(), this.fallbackMs);
74
- this.fallbackTimer.unref();
75
- return;
76
- }
77
- this.schedule();
78
- if (this.disposed) return;
79
- this.fallbackTimer = setTimeout(() => this.fallbackLoop(), this.fallbackMs);
80
- this.fallbackTimer.unref();
81
- }
82
-
83
- schedule(payload?: unknown): void {
84
- if (this.disposed) return;
85
- this.lastEventAt = Date.now();
86
- try {
87
- this.onInvalidate?.(payload);
88
- } catch (error) {
89
- logInternalError("render-scheduler.invalidate", error);
90
- }
91
- if (this.debounceTimer) clearTimeout(this.debounceTimer);
92
- this.debounceTimer = setTimeout(() => {
93
- this.debounceTimer = undefined;
94
- this.flush();
95
- }, this.debounceMs);
96
- this.debounceTimer.unref();
97
- }
98
-
99
- /**
100
- * Flush a render. If a render is already in progress the request is
101
- * collapsed: `pendingRender` is set and the caller that holds
102
- * `rendering==true` will loop one more time after finishing.
103
- */
104
- flush(): void {
105
- if (this.disposed) return;
106
- if (this.rendering) {
107
- this.pendingRender = true;
108
- return;
109
- }
110
- this.rendering = true;
111
- this.pendingRender = false;
112
- let iterations = 0;
113
- try {
114
- do {
115
- this.pendingRender = false;
116
- this.render();
117
- iterations += 1;
118
- // Safety valve: 5 re-renders max per flush to prevent infinite loops
119
- // if render() itself calls flush() synchronously.
120
- } while (this.pendingRender && !this.disposed && iterations < 5);
121
- } catch (error) {
122
- logInternalError("render-scheduler.render", error);
123
- } finally {
124
- this.rendering = false;
125
- // If we hit the iteration cap, schedule one more render to drain.
126
- if (iterations >= 5 && this.pendingRender && !this.disposed) {
127
- this.schedule();
128
- }
129
- }
130
- }
131
-
132
- dispose(): void {
133
- if (this.disposed) return;
134
- this.disposed = true;
135
- if (this.debounceTimer) clearTimeout(this.debounceTimer);
136
- if (this.fallbackTimer) clearTimeout(this.fallbackTimer);
137
- this.debounceTimer = undefined;
138
- this.fallbackTimer = undefined;
139
- for (const unsub of this.unsubs.splice(0)) {
140
- try { unsub(); } catch (error) { logInternalError("render-scheduler.unsubscribe", error); }
141
- }
142
- }
143
- }
1
+ import { logInternalError } from "../utils/internal-error.ts";
2
+
3
+ export interface RenderSchedulerEventBus {
4
+ on?: (event: string, handler: (payload: unknown) => void) => (() => void) | void;
5
+ }
6
+
7
+ export interface RenderSchedulerOptions {
8
+ debounceMs?: number;
9
+ fallbackMs?: number;
10
+ events?: string[];
11
+ onInvalidate?: (payload: unknown) => void;
12
+ }
13
+
14
+ const DEFAULT_EVENTS = [
15
+ "crew.run.created",
16
+ "crew.run.completed",
17
+ "crew.run.failed",
18
+ "crew.run.cancelled",
19
+ "crew.subagent.completed",
20
+ "crew.subagent.failed",
21
+ "crew.mailbox.updated",
22
+ "crew.mailbox.message",
23
+ ];
24
+
25
+ /**
26
+ * Coordinates UI renders with debounce + fallback polling.
27
+ *
28
+ * Critical: uses recursive setTimeout instead of setInterval + a rendering
29
+ * guard (`rendering` / `pendingRender`) so that when render() takes longer
30
+ * than the fallback interval, callbacks do NOT pile up and storm the event
31
+ * loop. Instead, overlapping schedules are collapsed into a single deferred
32
+ * re-render.
33
+ */
34
+ export class RenderScheduler {
35
+ private readonly render: () => void;
36
+ private readonly onInvalidate?: (payload: unknown) => void;
37
+ private readonly debounceMs: number;
38
+ private readonly fallbackMs: number;
39
+ private debounceTimer: ReturnType<typeof setTimeout> | undefined;
40
+ private fallbackTimer: ReturnType<typeof setTimeout> | undefined;
41
+ private disposed = false;
42
+ private lastEventAt = 0;
43
+ private rendering = false;
44
+ private pendingRender = false;
45
+ private readonly unsubs: Array<() => void> = [];
46
+
47
+ constructor(events: RenderSchedulerEventBus | undefined, render: () => void, options: RenderSchedulerOptions = {}) {
48
+ this.render = render;
49
+ this.onInvalidate = options.onInvalidate;
50
+ this.debounceMs = options.debounceMs ?? 75;
51
+ this.fallbackMs = options.fallbackMs ?? 750;
52
+ for (const event of options.events ?? DEFAULT_EVENTS) this.subscribe(events, event);
53
+ this.fallbackTimer = setTimeout(() => this.fallbackLoop(), this.fallbackMs);
54
+ this.fallbackTimer.unref();
55
+ }
56
+
57
+ private subscribe(events: RenderSchedulerEventBus | undefined, event: string): void {
58
+ if (!events?.on) return;
59
+ const handler = (payload: unknown): void => this.schedule(payload);
60
+ try {
61
+ const unsub = events.on(event, handler);
62
+ if (typeof unsub === "function") this.unsubs.push(unsub);
63
+ } catch (error) {
64
+ logInternalError("render-scheduler.subscribe", error, event);
65
+ }
66
+ }
67
+
68
+ /** Recursive setTimeout — avoids setInterval timer storms. */
69
+ private fallbackLoop(): void {
70
+ if (this.disposed) return;
71
+ if (Date.now() - this.lastEventAt < this.fallbackMs) {
72
+ if (this.disposed) return;
73
+ this.fallbackTimer = setTimeout(() => this.fallbackLoop(), this.fallbackMs);
74
+ this.fallbackTimer.unref();
75
+ return;
76
+ }
77
+ this.schedule();
78
+ if (this.disposed) return;
79
+ this.fallbackTimer = setTimeout(() => this.fallbackLoop(), this.fallbackMs);
80
+ this.fallbackTimer.unref();
81
+ }
82
+
83
+ schedule(payload?: unknown): void {
84
+ if (this.disposed) return;
85
+ this.lastEventAt = Date.now();
86
+ try {
87
+ this.onInvalidate?.(payload);
88
+ } catch (error) {
89
+ logInternalError("render-scheduler.invalidate", error);
90
+ }
91
+ if (this.debounceTimer) clearTimeout(this.debounceTimer);
92
+ this.debounceTimer = setTimeout(() => {
93
+ this.debounceTimer = undefined;
94
+ this.flush();
95
+ }, this.debounceMs);
96
+ this.debounceTimer.unref();
97
+ }
98
+
99
+ /**
100
+ * Flush a render. If a render is already in progress the request is
101
+ * collapsed: `pendingRender` is set and the caller that holds
102
+ * `rendering==true` will loop one more time after finishing.
103
+ */
104
+ flush(): void {
105
+ if (this.disposed) return;
106
+ if (this.rendering) {
107
+ this.pendingRender = true;
108
+ return;
109
+ }
110
+ this.rendering = true;
111
+ this.pendingRender = false;
112
+ let iterations = 0;
113
+ try {
114
+ do {
115
+ this.pendingRender = false;
116
+ this.render();
117
+ iterations += 1;
118
+ // Safety valve: 5 re-renders max per flush to prevent infinite loops
119
+ // if render() itself calls flush() synchronously.
120
+ } while (this.pendingRender && !this.disposed && iterations < 5);
121
+ } catch (error) {
122
+ logInternalError("render-scheduler.render", error);
123
+ } finally {
124
+ this.rendering = false;
125
+ // If we hit the iteration cap, schedule one more render to drain.
126
+ if (iterations >= 5 && this.pendingRender && !this.disposed) {
127
+ this.schedule();
128
+ }
129
+ }
130
+ }
131
+
132
+ dispose(): void {
133
+ if (this.disposed) return;
134
+ this.disposed = true;
135
+ if (this.debounceTimer) clearTimeout(this.debounceTimer);
136
+ if (this.fallbackTimer) clearTimeout(this.fallbackTimer);
137
+ this.debounceTimer = undefined;
138
+ this.fallbackTimer = undefined;
139
+ for (const unsub of this.unsubs.splice(0)) {
140
+ try { unsub(); } catch (error) { logInternalError("render-scheduler.unsubscribe", error); }
141
+ }
142
+ }
143
+ }
@@ -1,12 +1,12 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
- import { readCrewAgents, agentsPath, agentOutputPath } from "../runtime/crew-agent-records.ts";
4
+ import { readCrewAgents, readCrewAgentsAsync, agentsPath, agentOutputPath } from "../runtime/crew-agent-records.ts";
5
5
  import type { CrewAgentRecord } from "../runtime/crew-agent-runtime.ts";
6
6
  import { isActiveRunStatus } from "../runtime/process-status.ts";
7
7
  import type { TeamEvent } from "../state/event-log.ts";
8
8
  import type { MailboxMessageStatus } from "../state/mailbox.ts";
9
- import { loadRunManifestById } from "../state/state-store.ts";
9
+ import { loadRunManifestById, loadRunManifestByIdAsync } from "../state/state-store.ts";
10
10
  import type { TeamRunManifest, TeamTaskState } from "../state/types.ts";
11
11
  import type { RunSnapshotCache as RunSnapshotCacheBase, RunUiGroupJoin, RunUiMailbox, RunUiProgress, RunUiSnapshot, RunUiUsage } from "./snapshot-types.ts";
12
12
 
@@ -157,16 +157,6 @@ function readTasks(tasksPath: string): TeamTaskState[] {
157
157
  }
158
158
  }
159
159
 
160
- async function readTasksAsync(tasksPath: string): Promise<TeamTaskState[]> {
161
- try {
162
- const content = await fs.promises.readFile(tasksPath, "utf-8");
163
- const parsed = JSON.parse(content) as unknown;
164
- return Array.isArray(parsed) ? (parsed as TeamTaskState[]) : [];
165
- } catch {
166
- throw new Error(`Failed to parse tasks at ${tasksPath}`);
167
- }
168
- }
169
-
170
160
  /** Tail-read JSONL lines from a file, returning parsed objects (limited). */
171
161
  function tailJsonlLines<T>(filePath: string, limit: number, parse: (line: string) => T | undefined): T[] {
172
162
  if (limit <= 0) return [];
@@ -291,13 +281,17 @@ async function recentOutputLinesAsync(manifest: TeamRunManifest, agents: CrewAge
291
281
  }
292
282
 
293
283
  function progressFromTasks(tasks: TeamTaskState[]): RunUiProgress {
294
- return {
295
- total: tasks.length,
296
- completed: tasks.filter((task) => task.status === "completed").length,
297
- running: tasks.filter((task) => task.status === "running").length,
298
- failed: tasks.filter((task) => task.status === "failed").length,
299
- queued: tasks.filter((task) => task.status === "queued").length,
300
- };
284
+ const progress: RunUiProgress = { total: tasks.length, completed: 0, running: 0, failed: 0, queued: 0, waiting: 0, cancelled: 0, skipped: 0 };
285
+ for (const task of tasks) {
286
+ if (task.status === "completed") progress.completed += 1;
287
+ else if (task.status === "running") progress.running += 1;
288
+ else if (task.status === "failed") progress.failed += 1;
289
+ else if (task.status === "queued") progress.queued += 1;
290
+ else if (task.status === "waiting") progress.waiting = (progress.waiting ?? 0) + 1;
291
+ else if (task.status === "cancelled") progress.cancelled = (progress.cancelled ?? 0) + 1;
292
+ else if (task.status === "skipped") progress.skipped = (progress.skipped ?? 0) + 1;
293
+ }
294
+ return progress;
301
295
  }
302
296
 
303
297
  function usageFrom(tasks: TeamTaskState[], agents: CrewAgentRecord[]): RunUiUsage {
@@ -379,7 +373,28 @@ async function readGroupJoinMailboxAsync(filePath: string, delivery: Record<stri
379
373
  });
380
374
  }
381
375
 
382
- function readMailboxCounts(filePath: string, delivery: Record<string, MailboxMessageStatus>): number {
376
+ interface MailboxCount {
377
+ count: number;
378
+ approximate: boolean;
379
+ }
380
+
381
+ function tailApproximate(filePath: string): boolean {
382
+ try {
383
+ return fs.statSync(filePath).size > MAX_TAIL_BYTES;
384
+ } catch {
385
+ return false;
386
+ }
387
+ }
388
+
389
+ async function tailApproximateAsync(filePath: string): Promise<boolean> {
390
+ try {
391
+ return (await fs.promises.stat(filePath)).size > MAX_TAIL_BYTES;
392
+ } catch {
393
+ return false;
394
+ }
395
+ }
396
+
397
+ function readMailboxCounts(filePath: string, delivery: Record<string, MailboxMessageStatus>): MailboxCount {
383
398
  const items = tailJsonlLines(filePath, MAX_TAIL_LINES, (line) => {
384
399
  try {
385
400
  const parsed = JSON.parse(line) as unknown;
@@ -391,10 +406,10 @@ function readMailboxCounts(filePath: string, delivery: Record<string, MailboxMes
391
406
  return 0;
392
407
  }
393
408
  }) as number[];
394
- return items.reduce((sum, val) => sum + val, 0);
409
+ return { count: items.reduce((sum, val) => sum + val, 0), approximate: tailApproximate(filePath) };
395
410
  }
396
411
 
397
- async function readMailboxCountsAsync(filePath: string, delivery: Record<string, MailboxMessageStatus>): Promise<number> {
412
+ async function readMailboxCountsAsync(filePath: string, delivery: Record<string, MailboxMessageStatus>): Promise<MailboxCount> {
398
413
  const items = await tailJsonlLinesAsync(filePath, MAX_TAIL_LINES, (line) => {
399
414
  try {
400
415
  const parsed = JSON.parse(line) as unknown;
@@ -406,7 +421,7 @@ async function readMailboxCountsAsync(filePath: string, delivery: Record<string,
406
421
  return 0;
407
422
  }
408
423
  }) as number[];
409
- return items.reduce((sum, val) => sum + val, 0);
424
+ return { count: items.reduce((sum, val) => sum + val, 0), approximate: await tailApproximateAsync(filePath) };
410
425
  }
411
426
 
412
427
  function groupJoinsFrom(manifest: TeamRunManifest): RunUiGroupJoin[] {
@@ -424,39 +439,43 @@ async function groupJoinsFromAsync(manifest: TeamRunManifest): Promise<RunUiGrou
424
439
  function mailboxFrom(manifest: TeamRunManifest, agents: CrewAgentRecord[]): RunUiMailbox {
425
440
  const root = path.join(manifest.stateRoot, "mailbox");
426
441
  const delivery = readDeliveryMessages(path.join(root, "delivery.json"));
427
- let inboxUnread = readMailboxCounts(path.join(root, "inbox.jsonl"), delivery);
428
- let outboxPending = readMailboxCounts(path.join(root, "outbox.jsonl"), delivery);
442
+ let inbox = readMailboxCounts(path.join(root, "inbox.jsonl"), delivery);
443
+ let outbox = readMailboxCounts(path.join(root, "outbox.jsonl"), delivery);
429
444
  const tasksRoot = path.join(root, "tasks");
430
445
  try {
431
446
  for (const entry of fs.readdirSync(tasksRoot, { withFileTypes: true })) {
432
447
  if (!entry.isDirectory()) continue;
433
- inboxUnread += readMailboxCounts(path.join(tasksRoot, entry.name, "inbox.jsonl"), delivery);
434
- outboxPending += readMailboxCounts(path.join(tasksRoot, entry.name, "outbox.jsonl"), delivery);
448
+ const taskInbox = readMailboxCounts(path.join(tasksRoot, entry.name, "inbox.jsonl"), delivery);
449
+ const taskOutbox = readMailboxCounts(path.join(tasksRoot, entry.name, "outbox.jsonl"), delivery);
450
+ inbox = { count: inbox.count + taskInbox.count, approximate: inbox.approximate || taskInbox.approximate };
451
+ outbox = { count: outbox.count + taskOutbox.count, approximate: outbox.approximate || taskOutbox.approximate };
435
452
  }
436
453
  } catch {
437
454
  // No task mailboxes yet.
438
455
  }
439
456
  const attentionAgents = agents.filter((agent) => agent.progress?.activityState === "needs_attention").length;
440
- return { inboxUnread, outboxPending, needsAttention: inboxUnread + attentionAgents };
457
+ return { inboxUnread: inbox.count, outboxPending: outbox.count, needsAttention: inbox.count + attentionAgents, approximate: inbox.approximate || outbox.approximate };
441
458
  }
442
459
 
443
460
  async function mailboxFromAsync(manifest: TeamRunManifest, agents: CrewAgentRecord[]): Promise<RunUiMailbox> {
444
461
  const root = path.join(manifest.stateRoot, "mailbox");
445
462
  const delivery = await readDeliveryMessagesAsync(path.join(root, "delivery.json"));
446
- let inboxUnread = await readMailboxCountsAsync(path.join(root, "inbox.jsonl"), delivery);
447
- let outboxPending = await readMailboxCountsAsync(path.join(root, "outbox.jsonl"), delivery);
463
+ let inbox = await readMailboxCountsAsync(path.join(root, "inbox.jsonl"), delivery);
464
+ let outbox = await readMailboxCountsAsync(path.join(root, "outbox.jsonl"), delivery);
448
465
  const tasksRoot = path.join(root, "tasks");
449
466
  try {
450
467
  for (const entry of await fs.promises.readdir(tasksRoot, { withFileTypes: true })) {
451
468
  if (!entry.isDirectory()) continue;
452
- inboxUnread += await readMailboxCountsAsync(path.join(tasksRoot, entry.name, "inbox.jsonl"), delivery);
453
- outboxPending += await readMailboxCountsAsync(path.join(tasksRoot, entry.name, "outbox.jsonl"), delivery);
469
+ const taskInbox = await readMailboxCountsAsync(path.join(tasksRoot, entry.name, "inbox.jsonl"), delivery);
470
+ const taskOutbox = await readMailboxCountsAsync(path.join(tasksRoot, entry.name, "outbox.jsonl"), delivery);
471
+ inbox = { count: inbox.count + taskInbox.count, approximate: inbox.approximate || taskInbox.approximate };
472
+ outbox = { count: outbox.count + taskOutbox.count, approximate: outbox.approximate || taskOutbox.approximate };
454
473
  }
455
474
  } catch {
456
475
  // No task mailboxes yet.
457
476
  }
458
477
  const attentionAgents = agents.filter((agent) => agent.progress?.activityState === "needs_attention").length;
459
- return { inboxUnread, outboxPending, needsAttention: inboxUnread + attentionAgents };
478
+ return { inboxUnread: inbox.count, outboxPending: outbox.count, needsAttention: inbox.count + attentionAgents, approximate: inbox.approximate || outbox.approximate };
460
479
  }
461
480
 
462
481
  function signatureFor(input: Omit<RunUiSnapshot, "signature" | "fetchedAt">, stamps: SnapshotStamps): string {
@@ -571,9 +590,9 @@ export function createRunSnapshotCache(cwd: string, options: RunSnapshotCacheOpt
571
590
  }
572
591
 
573
592
  async function buildAsync(runId: string, previous?: CacheEntry): Promise<CacheEntry> {
574
- let loaded: ReturnType<typeof loadRunManifestById>;
593
+ let loaded: Awaited<ReturnType<typeof loadRunManifestByIdAsync>>;
575
594
  try {
576
- loaded = loadRunManifestById(cwd, runId);
595
+ loaded = await loadRunManifestByIdAsync(cwd, runId);
577
596
  } catch {
578
597
  if (previous) return previous;
579
598
  throw new Error(`Run '${runId}' could not be parsed.`);
@@ -585,8 +604,8 @@ export function createRunSnapshotCache(cwd: string, options: RunSnapshotCacheOpt
585
604
  let tasks: TeamTaskState[];
586
605
  let agents: CrewAgentRecord[];
587
606
  try {
588
- tasks = await readTasksAsync(loaded.manifest.tasksPath);
589
- agents = readCrewAgents(loaded.manifest);
607
+ tasks = loaded.tasks;
608
+ agents = await readCrewAgentsAsync(loaded.manifest);
590
609
  } catch {
591
610
  if (previous) return previous;
592
611
  throw new Error(`Run '${runId}' could not be parsed.`);
@@ -8,6 +8,9 @@ export interface RunUiProgress {
8
8
  running: number;
9
9
  failed: number;
10
10
  queued: number;
11
+ waiting?: number;
12
+ cancelled?: number;
13
+ skipped?: number;
11
14
  }
12
15
 
13
16
  export interface RunUiUsage {
@@ -20,6 +23,8 @@ export interface RunUiMailbox {
20
23
  inboxUnread: number;
21
24
  outboxPending: number;
22
25
  needsAttention: number;
26
+ /** True when counts come from bounded tail reads and older messages may be omitted. */
27
+ approximate?: boolean;
23
28
  }
24
29
 
25
30
  export interface RunUiGroupJoin {
package/src/ui/spinner.ts CHANGED
@@ -1,17 +1,17 @@
1
- export const SUBAGENT_SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] as const;
2
- export const SUBAGENT_SPINNER_FRAME_MS = 160;
3
-
4
- export function spinnerBucket(now = Date.now(), frameMs = SUBAGENT_SPINNER_FRAME_MS): number {
5
- return Math.floor(now / Math.max(1, frameMs));
6
- }
7
-
8
- function hashKey(key: string): number {
9
- let hash = 0;
10
- for (let index = 0; index < key.length; index += 1) hash = (hash * 31 + key.charCodeAt(index)) >>> 0;
11
- return hash;
12
- }
13
-
14
- export function spinnerFrame(key = "", now = Date.now()): string {
15
- const offset = key ? hashKey(key) % SUBAGENT_SPINNER_FRAMES.length : 0;
16
- return SUBAGENT_SPINNER_FRAMES[(spinnerBucket(now) + offset) % SUBAGENT_SPINNER_FRAMES.length] ?? SUBAGENT_SPINNER_FRAMES[0];
17
- }
1
+ export const SUBAGENT_SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] as const;
2
+ export const SUBAGENT_SPINNER_FRAME_MS = 160;
3
+
4
+ export function spinnerBucket(now = Date.now(), frameMs = SUBAGENT_SPINNER_FRAME_MS): number {
5
+ return Math.floor(now / Math.max(1, frameMs));
6
+ }
7
+
8
+ function hashKey(key: string): number {
9
+ let hash = 0;
10
+ for (let index = 0; index < key.length; index += 1) hash = (hash * 31 + key.charCodeAt(index)) >>> 0;
11
+ return hash;
12
+ }
13
+
14
+ export function spinnerFrame(key = "", now = Date.now()): string {
15
+ const offset = key ? hashKey(key) % SUBAGENT_SPINNER_FRAMES.length : 0;
16
+ return SUBAGENT_SPINNER_FRAMES[(spinnerBucket(now) + offset) % SUBAGENT_SPINNER_FRAMES.length] ?? SUBAGENT_SPINNER_FRAMES[0];
17
+ }
@@ -1,58 +1,58 @@
1
- import type { CrewTheme, CrewThemeColor } from "./theme-adapter.ts";
2
-
3
- export type RunStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | "stopped" | "blocked" | (string & {});
4
-
5
- export function colorForStatus(status: RunStatus): CrewThemeColor {
6
- switch (status) {
7
- case "running":
8
- return "accent";
9
- case "waiting":
10
- return "muted";
11
- case "completed":
12
- return "success";
13
- case "failed":
14
- case "stale":
15
- return "error";
16
- case "cancelled":
17
- case "blocked":
18
- case "stopped":
19
- return "warning";
20
- case "queued":
21
- default:
22
- return "dim";
23
- }
24
- }
25
-
26
- export function iconForStatus(status: RunStatus, options?: { runningGlyph?: string }): string {
27
- const glyph = options?.runningGlyph ?? "▶";
28
- switch (status) {
29
- case "completed":
30
- return "✓";
31
- case "failed":
32
- case "stale":
33
- return "✗";
34
- case "cancelled":
35
- case "stopped":
36
- return "■";
37
- case "running":
38
- return glyph;
39
- case "waiting":
40
- return "⏳";
41
- case "queued":
42
- return "◦";
43
- case "blocked":
44
- return "⏸";
45
- default:
46
- return "·";
47
- }
48
- }
49
-
50
- export function colorForActivity(activityState: string | undefined): CrewThemeColor {
51
- if (activityState === "needs_attention") return "warning";
52
- if (activityState === "stale") return "error";
53
- return "dim";
54
- }
55
-
56
- export function applyStatusColor(theme: CrewTheme, status: RunStatus, text: string): string {
57
- return theme.fg(colorForStatus(status), text);
58
- }
1
+ import type { CrewTheme, CrewThemeColor } from "./theme-adapter.ts";
2
+
3
+ export type RunStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | "stopped" | "blocked" | (string & {});
4
+
5
+ export function colorForStatus(status: RunStatus): CrewThemeColor {
6
+ switch (status) {
7
+ case "running":
8
+ return "accent";
9
+ case "waiting":
10
+ return "muted";
11
+ case "completed":
12
+ return "success";
13
+ case "failed":
14
+ case "stale":
15
+ return "error";
16
+ case "cancelled":
17
+ case "blocked":
18
+ case "stopped":
19
+ return "warning";
20
+ case "queued":
21
+ default:
22
+ return "dim";
23
+ }
24
+ }
25
+
26
+ export function iconForStatus(status: RunStatus, options?: { runningGlyph?: string }): string {
27
+ const glyph = options?.runningGlyph ?? "▶";
28
+ switch (status) {
29
+ case "completed":
30
+ return "✓";
31
+ case "failed":
32
+ case "stale":
33
+ return "✗";
34
+ case "cancelled":
35
+ case "stopped":
36
+ return "■";
37
+ case "running":
38
+ return glyph;
39
+ case "waiting":
40
+ return "⏳";
41
+ case "queued":
42
+ return "◦";
43
+ case "blocked":
44
+ return "⏸";
45
+ default:
46
+ return "·";
47
+ }
48
+ }
49
+
50
+ export function colorForActivity(activityState: string | undefined): CrewThemeColor {
51
+ if (activityState === "needs_attention") return "warning";
52
+ if (activityState === "stale") return "error";
53
+ return "dim";
54
+ }
55
+
56
+ export function applyStatusColor(theme: CrewTheme, status: RunStatus, text: string): string {
57
+ return theme.fg(colorForStatus(status), text);
58
+ }