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,190 +1,190 @@
1
- import * as fs from "node:fs";
2
- import type { TeamTaskState, TeamRunManifest } from "../state/types.ts";
3
-
4
- // ============================================================================
5
- // Phase 1.2: Completion Mutation Guard — detects tasks that claim success but
6
- // made no observable mutations. Used by task-runner.ts.
7
- // ============================================================================
8
-
9
- export interface CompletionMutationGuardInput {
10
- role: string;
11
- taskText?: string;
12
- transcriptPath?: string;
13
- stdout?: string;
14
- }
15
-
16
- export interface CompletionMutationGuardResult {
17
- expectedMutation: boolean;
18
- observedMutation: boolean;
19
- reason?: "no_mutation_observed";
20
- observedTools: string[];
21
- }
22
-
23
- const MUTATING_ROLES = new Set(["executor", "test-engineer"]);
24
- const MUTATING_TOOLS = new Set(["edit", "write", "multi_edit", "apply_patch", "replace_in_file", "insert", "delete_files", "create_file", "overwrite", "patch"]);
25
- const READ_ONLY_COMMANDS = /^(pwd|ls|dir|cat|type|sed|grep|rg|find|git\s+(status|diff|log|show|branch|remote|rev-parse|ls-files)|npm\s+(test|run\s+(typecheck|check|lint|test|ci))|node\s+--test)\b/i;
26
- const MUTATING_COMMANDS = /\b(rm\s+-|del\s+|erase\s+|mv\s+|move\s+|cp\s+|copy\s+|mkdir\b|touch\b|git\s+(add|commit|push|reset|clean|checkout|switch|merge|rebase|stash)|npm\s+(install|i|uninstall|publish|version)|pnpm\s+(add|install|remove)|yarn\s+(add|install|remove)|python\b.*>|node\b.*>|echo\b.*>|Set-Content|Out-File|sed\s+-i|tee\b|dd\b.*of=|wget\b.*-O|curl\b.*-o)\b/i;
27
- const READ_ONLY_HINTS = /\b(read-only|no edits?|do not edit|không sửa|khong sua|chỉ đọc|chi doc|plan only|chỉ lập plan|review only|audit only)\b/i;
28
-
29
- function asRecord(value: unknown): Record<string, unknown> | undefined {
30
- return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
31
- }
32
-
33
- function commandText(value: unknown): string {
34
- const record = asRecord(value);
35
- if (!record) return typeof value === "string" ? value : "";
36
- for (const key of ["command", "cmd", "script", "input"]) {
37
- const raw = record[key];
38
- if (typeof raw === "string") return raw;
39
- }
40
- return JSON.stringify(record);
41
- }
42
-
43
- function isMutatingTool(tool: string, args: unknown): boolean {
44
- const normalized = tool.toLowerCase();
45
- if (MUTATING_TOOLS.has(normalized)) return true;
46
- if (normalized === "bash" || normalized === "shell" || normalized === "powershell") {
47
- const command = commandText(args).trim();
48
- if (!command) return false;
49
- // Check mutating patterns first: sed -i is mutating even though plain sed is read-only.
50
- if (MUTATING_COMMANDS.test(command)) return true;
51
- if (READ_ONLY_COMMANDS.test(command)) return false;
52
- // If the command doesn't match either list, treat unknown bash calls as potentially mutating.
53
- return true;
54
- }
55
- return false;
56
- }
57
-
58
- function collectToolCallsFromEvent(event: unknown): Array<{ tool: string; args?: unknown }> {
59
- const record = asRecord(event);
60
- if (!record) return [];
61
- const calls: Array<{ tool: string; args?: unknown }> = [];
62
- const directTool = record.toolName ?? record.name ?? record.tool;
63
- if (typeof directTool === "string" && (record.type === "tool_execution_start" || record.type === "toolCall" || record.type === "tool_call")) {
64
- calls.push({ tool: directTool, args: record.args ?? record.input });
65
- }
66
- const content = Array.isArray(record.content) ? record.content : asRecord(record.message)?.content;
67
- if (Array.isArray(content)) {
68
- for (const part of content) {
69
- const item = asRecord(part);
70
- if (!item) continue;
71
- const tool = item.name ?? item.toolName ?? item.tool;
72
- if (typeof tool === "string" && (item.type === "toolCall" || item.type === "tool_call" || item.type === "tool_execution_start")) calls.push({ tool, args: item.input ?? item.args });
73
- }
74
- }
75
- return calls;
76
- }
77
-
78
- function transcriptText(input: CompletionMutationGuardInput): string {
79
- if (input.transcriptPath && fs.existsSync(input.transcriptPath)) return fs.readFileSync(input.transcriptPath, "utf-8");
80
- return input.stdout ?? "";
81
- }
82
-
83
- export function expectsImplementationMutation(input: Pick<CompletionMutationGuardInput, "role" | "taskText">): boolean {
84
- if (!MUTATING_ROLES.has(input.role)) return false;
85
- return !READ_ONLY_HINTS.test(input.taskText ?? "");
86
- }
87
-
88
- export function evaluateCompletionMutationGuard(input: CompletionMutationGuardInput): CompletionMutationGuardResult {
89
- const expectedMutation = expectsImplementationMutation(input);
90
- const observedTools: string[] = [];
91
- let observedMutation = false;
92
- const text = transcriptText(input);
93
- for (const line of text.split("\n")) {
94
- const trimmed = line.trim();
95
- if (!trimmed) continue;
96
- let event: unknown;
97
- try { event = JSON.parse(trimmed); } catch { continue; }
98
- for (const call of collectToolCallsFromEvent(event)) {
99
- observedTools.push(call.tool);
100
- if (isMutatingTool(call.tool, call.args)) observedMutation = true;
101
- }
102
- }
103
- return {
104
- expectedMutation,
105
- observedMutation,
106
- observedTools,
107
- ...(expectedMutation && !observedMutation ? { reason: "no_mutation_observed" as const } : {}),
108
- };
109
- }
110
-
111
- // ============================================================================
112
- // Phase 11a: Artifact-based Completion Verification — a second layer that
113
- // checks whether a completed task actually produced meaningful artifacts.
114
- // ============================================================================
115
-
116
- /**
117
- * Guard against false-positive task completions.
118
- *
119
- * Checks whether a task that claims success actually produced meaningful output.
120
- * Returns a verification result with the green level (0-3) and any warnings.
121
- */
122
- export interface CompletionVerifyResult {
123
- /** 0 = no output, 1 = minimal, 2 = moderate, 3 = strong */
124
- greenLevel: number;
125
- /** Warnings about potentially incomplete work */
126
- warnings: string[];
127
- }
128
-
129
- const MAX_OUTPUT_PREVIEW = 200;
130
-
131
- function isTrivialError(error: string | undefined): boolean {
132
- if (!error) return false;
133
- return error.trim().length === 0;
134
- }
135
-
136
- export function verifyTaskCompletion(
137
- task: TeamTaskState,
138
- manifest: TeamRunManifest,
139
- ): CompletionVerifyResult {
140
- const warnings: string[] = [];
141
- let greenLevel = 0;
142
-
143
- // Check 1: Has an error?
144
- if (task.error && !isTrivialError(task.error)) {
145
- return { greenLevel: 0, warnings: [`Task has error: ${task.error}`] };
146
- }
147
-
148
- // Check 2: Has result artifact?
149
- if (task.resultArtifact) {
150
- greenLevel += 1;
151
- }
152
-
153
- // Check 3: Has transcript?
154
- if (task.transcriptArtifact) {
155
- greenLevel += 1;
156
- }
157
-
158
- // Check 4: For implementation tasks, verify artifacts were actually produced
159
- const runArtifacts = manifest.artifacts.filter(
160
- (a) => a.producer === task.id || a.producer === task.agent,
161
- );
162
- if (runArtifacts.length > 0) {
163
- greenLevel += 1;
164
- } else if (greenLevel < 3) {
165
- warnings.push("No run-level artifacts produced by this task");
166
- }
167
-
168
- // Check 5: Usage tracking — did the task actually consume tokens?
169
- if (task.usage) {
170
- const totalTokens = (task.usage.input ?? 0) + (task.usage.output ?? 0);
171
- if (totalTokens === 0 && greenLevel < 3) {
172
- warnings.push("Task reports zero token usage — may not have executed");
173
- }
174
- }
175
-
176
- return {
177
- greenLevel: Math.min(greenLevel, 3),
178
- warnings,
179
- };
180
- }
181
-
182
- /**
183
- * Format a preview of task output for diagnostic display.
184
- */
185
- export function formatOutputPreview(output: string | undefined): string {
186
- if (!output) return "(no output)";
187
- const trimmed = output.trim();
188
- if (trimmed.length <= MAX_OUTPUT_PREVIEW) return trimmed;
189
- return trimmed.slice(0, MAX_OUTPUT_PREVIEW) + "...";
190
- }
1
+ import * as fs from "node:fs";
2
+ import type { TeamTaskState, TeamRunManifest } from "../state/types.ts";
3
+
4
+ // ============================================================================
5
+ // Phase 1.2: Completion Mutation Guard — detects tasks that claim success but
6
+ // made no observable mutations. Used by task-runner.ts.
7
+ // ============================================================================
8
+
9
+ export interface CompletionMutationGuardInput {
10
+ role: string;
11
+ taskText?: string;
12
+ transcriptPath?: string;
13
+ stdout?: string;
14
+ }
15
+
16
+ export interface CompletionMutationGuardResult {
17
+ expectedMutation: boolean;
18
+ observedMutation: boolean;
19
+ reason?: "no_mutation_observed";
20
+ observedTools: string[];
21
+ }
22
+
23
+ const MUTATING_ROLES = new Set(["executor", "test-engineer"]);
24
+ const MUTATING_TOOLS = new Set(["edit", "write", "multi_edit", "apply_patch", "replace_in_file", "insert", "delete_files", "create_file", "overwrite", "patch"]);
25
+ const READ_ONLY_COMMANDS = /^(pwd|ls|dir|cat|type|sed|grep|rg|find|git\s+(status|diff|log|show|branch|remote|rev-parse|ls-files)|npm\s+(test|run\s+(typecheck|check|lint|test|ci))|node\s+--test)\b/i;
26
+ const MUTATING_COMMANDS = /\b(rm\s+-|del\s+|erase\s+|mv\s+|move\s+|cp\s+|copy\s+|mkdir\b|touch\b|git\s+(add|commit|push|reset|clean|checkout|switch|merge|rebase|stash)|npm\s+(install|i|uninstall|publish|version)|pnpm\s+(add|install|remove)|yarn\s+(add|install|remove)|python\b.*>|node\b.*>|echo\b.*>|Set-Content|Out-File|sed\s+-i|tee\b|dd\b.*of=|wget\b.*-O|curl\b.*-o)\b/i;
27
+ const READ_ONLY_HINTS = /\b(read-only|no edits?|do not edit|không sửa|khong sua|chỉ đọc|chi doc|plan only|chỉ lập plan|review only|audit only)\b/i;
28
+
29
+ function asRecord(value: unknown): Record<string, unknown> | undefined {
30
+ return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
31
+ }
32
+
33
+ function commandText(value: unknown): string {
34
+ const record = asRecord(value);
35
+ if (!record) return typeof value === "string" ? value : "";
36
+ for (const key of ["command", "cmd", "script", "input"]) {
37
+ const raw = record[key];
38
+ if (typeof raw === "string") return raw;
39
+ }
40
+ return JSON.stringify(record);
41
+ }
42
+
43
+ function isMutatingTool(tool: string, args: unknown): boolean {
44
+ const normalized = tool.toLowerCase();
45
+ if (MUTATING_TOOLS.has(normalized)) return true;
46
+ if (normalized === "bash" || normalized === "shell" || normalized === "powershell") {
47
+ const command = commandText(args).trim();
48
+ if (!command) return false;
49
+ // Check mutating patterns first: sed -i is mutating even though plain sed is read-only.
50
+ if (MUTATING_COMMANDS.test(command)) return true;
51
+ if (READ_ONLY_COMMANDS.test(command)) return false;
52
+ // If the command doesn't match either list, treat unknown bash calls as potentially mutating.
53
+ return true;
54
+ }
55
+ return false;
56
+ }
57
+
58
+ function collectToolCallsFromEvent(event: unknown): Array<{ tool: string; args?: unknown }> {
59
+ const record = asRecord(event);
60
+ if (!record) return [];
61
+ const calls: Array<{ tool: string; args?: unknown }> = [];
62
+ const directTool = record.toolName ?? record.name ?? record.tool;
63
+ if (typeof directTool === "string" && (record.type === "tool_execution_start" || record.type === "toolCall" || record.type === "tool_call")) {
64
+ calls.push({ tool: directTool, args: record.args ?? record.input });
65
+ }
66
+ const content = Array.isArray(record.content) ? record.content : asRecord(record.message)?.content;
67
+ if (Array.isArray(content)) {
68
+ for (const part of content) {
69
+ const item = asRecord(part);
70
+ if (!item) continue;
71
+ const tool = item.name ?? item.toolName ?? item.tool;
72
+ if (typeof tool === "string" && (item.type === "toolCall" || item.type === "tool_call" || item.type === "tool_execution_start")) calls.push({ tool, args: item.input ?? item.args });
73
+ }
74
+ }
75
+ return calls;
76
+ }
77
+
78
+ function transcriptText(input: CompletionMutationGuardInput): string {
79
+ if (input.transcriptPath && fs.existsSync(input.transcriptPath)) return fs.readFileSync(input.transcriptPath, "utf-8");
80
+ return input.stdout ?? "";
81
+ }
82
+
83
+ export function expectsImplementationMutation(input: Pick<CompletionMutationGuardInput, "role" | "taskText">): boolean {
84
+ if (!MUTATING_ROLES.has(input.role)) return false;
85
+ return !READ_ONLY_HINTS.test(input.taskText ?? "");
86
+ }
87
+
88
+ export function evaluateCompletionMutationGuard(input: CompletionMutationGuardInput): CompletionMutationGuardResult {
89
+ const expectedMutation = expectsImplementationMutation(input);
90
+ const observedTools: string[] = [];
91
+ let observedMutation = false;
92
+ const text = transcriptText(input);
93
+ for (const line of text.split("\n")) {
94
+ const trimmed = line.trim();
95
+ if (!trimmed) continue;
96
+ let event: unknown;
97
+ try { event = JSON.parse(trimmed); } catch { continue; }
98
+ for (const call of collectToolCallsFromEvent(event)) {
99
+ observedTools.push(call.tool);
100
+ if (isMutatingTool(call.tool, call.args)) observedMutation = true;
101
+ }
102
+ }
103
+ return {
104
+ expectedMutation,
105
+ observedMutation,
106
+ observedTools,
107
+ ...(expectedMutation && !observedMutation ? { reason: "no_mutation_observed" as const } : {}),
108
+ };
109
+ }
110
+
111
+ // ============================================================================
112
+ // Phase 11a: Artifact-based Completion Verification — a second layer that
113
+ // checks whether a completed task actually produced meaningful artifacts.
114
+ // ============================================================================
115
+
116
+ /**
117
+ * Guard against false-positive task completions.
118
+ *
119
+ * Checks whether a task that claims success actually produced meaningful output.
120
+ * Returns a verification result with the green level (0-3) and any warnings.
121
+ */
122
+ export interface CompletionVerifyResult {
123
+ /** 0 = no output, 1 = minimal, 2 = moderate, 3 = strong */
124
+ greenLevel: number;
125
+ /** Warnings about potentially incomplete work */
126
+ warnings: string[];
127
+ }
128
+
129
+ const MAX_OUTPUT_PREVIEW = 200;
130
+
131
+ function isTrivialError(error: string | undefined): boolean {
132
+ if (!error) return false;
133
+ return error.trim().length === 0;
134
+ }
135
+
136
+ export function verifyTaskCompletion(
137
+ task: TeamTaskState,
138
+ manifest: TeamRunManifest,
139
+ ): CompletionVerifyResult {
140
+ const warnings: string[] = [];
141
+ let greenLevel = 0;
142
+
143
+ // Check 1: Has an error?
144
+ if (task.error && !isTrivialError(task.error)) {
145
+ return { greenLevel: 0, warnings: [`Task has error: ${task.error}`] };
146
+ }
147
+
148
+ // Check 2: Has result artifact?
149
+ if (task.resultArtifact) {
150
+ greenLevel += 1;
151
+ }
152
+
153
+ // Check 3: Has transcript?
154
+ if (task.transcriptArtifact) {
155
+ greenLevel += 1;
156
+ }
157
+
158
+ // Check 4: For implementation tasks, verify artifacts were actually produced
159
+ const runArtifacts = manifest.artifacts.filter(
160
+ (a) => a.producer === task.id || a.producer === task.agent,
161
+ );
162
+ if (runArtifacts.length > 0) {
163
+ greenLevel += 1;
164
+ } else if (greenLevel < 3) {
165
+ warnings.push("No run-level artifacts produced by this task");
166
+ }
167
+
168
+ // Check 5: Usage tracking — did the task actually consume tokens?
169
+ if (task.usage) {
170
+ const totalTokens = (task.usage.input ?? 0) + (task.usage.output ?? 0);
171
+ if (totalTokens === 0 && greenLevel < 3) {
172
+ warnings.push("Task reports zero token usage — may not have executed");
173
+ }
174
+ }
175
+
176
+ return {
177
+ greenLevel: Math.min(greenLevel, 3),
178
+ warnings,
179
+ };
180
+ }
181
+
182
+ /**
183
+ * Format a preview of task output for diagnostic display.
184
+ */
185
+ export function formatOutputPreview(output: string | undefined): string {
186
+ if (!output) return "(no output)";
187
+ const trimmed = output.trim();
188
+ if (trimmed.length <= MAX_OUTPUT_PREVIEW) return trimmed;
189
+ return trimmed.slice(0, MAX_OUTPUT_PREVIEW) + "...";
190
+ }
@@ -70,6 +70,14 @@ export function readCrewAgents(manifest: TeamRunManifest): CrewAgentRecord[] {
70
70
  }
71
71
  }
72
72
 
73
+ export async function readCrewAgentsAsync(manifest: TeamRunManifest): Promise<CrewAgentRecord[]> {
74
+ try {
75
+ return JSON.parse(await fs.promises.readFile(agentsPath(manifest), "utf-8")) as CrewAgentRecord[];
76
+ } catch {
77
+ return [];
78
+ }
79
+ }
80
+
73
81
  export function saveCrewAgents(manifest: TeamRunManifest, records: CrewAgentRecord[]): void {
74
82
  fs.mkdirSync(manifest.stateRoot, { recursive: true });
75
83
  atomicWriteJson(agentsPath(manifest), redactSecrets(records));