pi-crew 0.1.41 → 0.1.44
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/CHANGELOG.md +47 -0
- package/README.md +51 -0
- package/agents/analyst.md +11 -11
- package/agents/critic.md +11 -11
- package/agents/executor.md +11 -11
- package/agents/explorer.md +11 -11
- package/agents/planner.md +11 -11
- package/agents/reviewer.md +11 -11
- package/agents/security-reviewer.md +11 -11
- package/agents/test-engineer.md +11 -11
- package/agents/verifier.md +11 -11
- package/agents/writer.md +11 -11
- package/docs/refactor-tasks-phase3.md +394 -394
- package/docs/refactor-tasks-phase4.md +564 -564
- package/docs/refactor-tasks-phase5.md +402 -402
- package/docs/refactor-tasks-phase6.md +662 -662
- package/docs/research-extension-examples.md +297 -297
- package/docs/research-extension-system.md +324 -324
- package/docs/research-optimization-plan.md +548 -548
- package/docs/research-phase10-distillation.md +199 -0
- package/docs/research-phase11-distillation.md +201 -0
- package/docs/research-pi-coding-agent.md +357 -357
- package/docs/research-source-pi-crew-reference.md +174 -174
- package/docs/runtime-flow.md +148 -148
- package/docs/source-runtime-refactor-map.md +83 -83
- package/index.ts +6 -6
- package/package.json +1 -1
- package/src/agents/agent-serializer.ts +34 -34
- package/src/agents/discover-agents.ts +5 -4
- package/src/config/config.ts +28 -4
- package/src/extension/cross-extension-rpc.ts +82 -82
- package/src/extension/management.ts +37 -8
- package/src/extension/notification-router.ts +2 -2
- package/src/extension/register.ts +130 -8
- package/src/extension/registration/commands.ts +11 -9
- package/src/extension/registration/compaction-guard.ts +125 -125
- package/src/extension/registration/subagent-tools.ts +28 -19
- package/src/extension/registration/team-tool.ts +2 -1
- package/src/extension/result-watcher.ts +4 -4
- package/src/extension/run-bundle-schema.ts +8 -4
- package/src/extension/run-import.ts +4 -0
- package/src/extension/run-index.ts +23 -1
- package/src/extension/run-maintenance.ts +43 -24
- package/src/extension/team-tool/api.ts +2 -2
- package/src/extension/team-tool/cancel.ts +76 -4
- package/src/extension/team-tool/context.ts +1 -0
- package/src/extension/team-tool/doctor.ts +8 -1
- package/src/extension/team-tool/handle-settings.ts +188 -0
- package/src/extension/team-tool/inspect.ts +41 -41
- package/src/extension/team-tool/lifecycle-actions.ts +79 -79
- package/src/extension/team-tool/plan.ts +19 -19
- package/src/extension/team-tool/respond.ts +67 -0
- package/src/extension/team-tool/run.ts +6 -4
- package/src/extension/team-tool/status.ts +99 -93
- package/src/extension/team-tool-types.ts +4 -0
- package/src/extension/team-tool.ts +5 -1
- package/src/i18n.ts +184 -0
- package/src/observability/correlation.ts +2 -2
- package/src/observability/event-to-metric.ts +10 -3
- package/src/observability/exporters/adapter.ts +7 -1
- package/src/observability/exporters/otlp-exporter.ts +14 -2
- package/src/observability/exporters/prometheus-exporter.ts +9 -2
- package/src/observability/metric-registry.ts +18 -3
- package/src/observability/metric-retention.ts +11 -3
- package/src/observability/metric-sink.ts +9 -4
- package/src/observability/metrics-primitives.ts +4 -3
- package/src/prompt/prompt-runtime.ts +72 -68
- package/src/runtime/agent-control.ts +63 -63
- package/src/runtime/agent-memory.ts +72 -72
- package/src/runtime/agent-observability.ts +114 -114
- package/src/runtime/async-marker.ts +26 -26
- package/src/runtime/attention-events.ts +28 -23
- package/src/runtime/background-runner.ts +53 -53
- package/src/runtime/child-pi.ts +4 -4
- package/src/runtime/completion-guard.ts +95 -4
- package/src/runtime/concurrency.ts +1 -1
- package/src/runtime/crash-recovery.ts +32 -1
- package/src/runtime/crew-agent-runtime.ts +59 -58
- package/src/runtime/deadletter.ts +14 -4
- package/src/runtime/delivery-coordinator.ts +143 -0
- package/src/runtime/direct-run.ts +35 -35
- package/src/runtime/foreground-control.ts +82 -82
- package/src/runtime/green-contract.ts +46 -46
- package/src/runtime/group-join.ts +106 -106
- package/src/runtime/heartbeat-gradient.ts +28 -28
- package/src/runtime/heartbeat-watcher.ts +48 -4
- package/src/runtime/live-agent-control.ts +87 -87
- package/src/runtime/live-agent-manager.ts +85 -85
- package/src/runtime/live-control-realtime.ts +36 -36
- package/src/runtime/live-session-runtime.ts +305 -305
- package/src/runtime/manifest-cache.ts +2 -2
- package/src/runtime/model-fallback.ts +272 -261
- package/src/runtime/overflow-recovery.ts +157 -0
- package/src/runtime/parallel-research.ts +44 -44
- package/src/runtime/parallel-utils.ts +1 -1
- package/src/runtime/pi-json-output.ts +111 -111
- package/src/runtime/policy-engine.ts +79 -78
- package/src/runtime/post-exit-stdio-guard.ts +2 -2
- package/src/runtime/process-status.ts +56 -56
- package/src/runtime/progress-event-coalescer.ts +43 -43
- package/src/runtime/recovery-recipes.ts +74 -74
- package/src/runtime/retry-executor.ts +5 -0
- package/src/runtime/role-permission.ts +39 -39
- package/src/runtime/runtime-resolver.ts +1 -1
- package/src/runtime/session-resources.ts +25 -0
- package/src/runtime/session-snapshot.ts +59 -0
- package/src/runtime/session-usage.ts +79 -79
- package/src/runtime/sidechain-output.ts +29 -29
- package/src/runtime/stale-reconciler.ts +179 -0
- package/src/runtime/subagent-manager.ts +3 -3
- package/src/runtime/supervisor-contact.ts +59 -0
- package/src/runtime/task-display.ts +38 -38
- package/src/runtime/task-output-context.ts +127 -127
- package/src/runtime/task-runner/live-executor.ts +101 -101
- package/src/runtime/task-runner/progress.ts +119 -111
- package/src/runtime/task-runner/result-utils.ts +14 -14
- package/src/runtime/task-runner/state-helpers.ts +22 -22
- package/src/runtime/task-runner.ts +14 -0
- package/src/runtime/team-runner.ts +9 -10
- package/src/runtime/worker-heartbeat.ts +21 -21
- package/src/runtime/worker-startup.ts +57 -57
- package/src/schema/config-schema.ts +2 -1
- package/src/schema/team-tool-schema.ts +115 -109
- package/src/state/artifact-store.ts +4 -2
- package/src/state/atomic-write.ts +12 -4
- package/src/state/contracts.ts +109 -105
- package/src/state/event-log.ts +3 -4
- package/src/state/jsonl-writer.ts +4 -1
- package/src/state/locks.ts +9 -1
- package/src/state/task-claims.ts +44 -42
- package/src/state/usage.ts +29 -29
- package/src/subagents/async-entry.ts +1 -1
- package/src/subagents/index.ts +3 -3
- package/src/subagents/live/control.ts +1 -1
- package/src/subagents/live/manager.ts +1 -1
- package/src/subagents/live/realtime.ts +1 -1
- package/src/subagents/live/session-runtime.ts +1 -1
- package/src/subagents/manager.ts +1 -1
- package/src/subagents/spawn.ts +1 -1
- package/src/teams/discover-teams.ts +2 -2
- package/src/teams/team-serializer.ts +38 -38
- package/src/types/diff.d.ts +18 -18
- package/src/ui/crew-footer.ts +101 -101
- package/src/ui/crew-select-list.ts +111 -111
- package/src/ui/crew-widget.ts +5 -4
- package/src/ui/dashboard-panes/metrics-pane.ts +34 -34
- package/src/ui/dynamic-border.ts +25 -25
- package/src/ui/layout-primitives.ts +106 -106
- package/src/ui/live-run-sidebar.ts +1 -1
- package/src/ui/loaders.ts +158 -158
- package/src/ui/mascot.ts +3 -2
- package/src/ui/powerbar-publisher.ts +7 -6
- package/src/ui/render-diff.ts +119 -119
- package/src/ui/render-scheduler.ts +54 -14
- package/src/ui/run-dashboard.ts +39 -11
- package/src/ui/run-snapshot-cache.ts +336 -36
- package/src/ui/spinner.ts +17 -17
- package/src/ui/status-colors.ts +58 -54
- package/src/ui/syntax-highlight.ts +116 -116
- package/src/ui/theme-adapter.ts +1 -1
- package/src/ui/transcript-viewer.ts +7 -2
- package/src/utils/atomic-write.ts +33 -0
- package/src/utils/completion-dedupe.ts +63 -63
- package/src/utils/file-coalescer.ts +5 -3
- package/src/utils/frontmatter.ts +68 -36
- package/src/utils/git.ts +262 -262
- package/src/utils/ids.ts +12 -12
- package/src/utils/internal-error.ts +1 -1
- package/src/utils/names.ts +27 -26
- package/src/utils/paths.ts +1 -1
- package/src/utils/redaction.ts +44 -41
- package/src/utils/safe-paths.ts +47 -34
- package/src/utils/sleep.ts +2 -2
- package/src/utils/timings.ts +2 -0
- package/src/utils/visual.ts +9 -1
- package/src/workflows/discover-workflows.ts +4 -1
- package/src/workflows/validate-workflow.ts +40 -40
- package/src/worktree/branch-freshness.ts +45 -45
- package/src/worktree/worktree-manager.ts +6 -1
- package/teams/default.team.md +12 -12
- package/teams/fast-fix.team.md +11 -11
- package/teams/implementation.team.md +18 -18
- package/teams/parallel-research.team.md +14 -14
- package/teams/research.team.md +11 -11
- package/teams/review.team.md +12 -12
- package/workflows/default.workflow.md +29 -29
- package/workflows/fast-fix.workflow.md +22 -22
- package/workflows/implementation.workflow.md +38 -38
- package/workflows/parallel-research.workflow.md +46 -46
- package/workflows/research.workflow.md +22 -22
- package/workflows/review.workflow.md +30 -30
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import type { TeamRunManifest } from "../state/types.ts";
|
|
3
|
-
import { agentOutputPath, readCrewAgents } from "./crew-agent-records.ts";
|
|
4
|
-
import type { CrewAgentRecord } from "./crew-agent-runtime.ts";
|
|
5
|
-
|
|
6
|
-
const TOOL_LABELS: Record<string, string> = {
|
|
7
|
-
read: "reading",
|
|
8
|
-
bash: "running command",
|
|
9
|
-
edit: "editing",
|
|
10
|
-
write: "writing",
|
|
11
|
-
grep: "searching",
|
|
12
|
-
find: "finding files",
|
|
13
|
-
ls: "listing",
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export interface TextTailResult {
|
|
17
|
-
path: string;
|
|
18
|
-
text: string;
|
|
19
|
-
bytes: number;
|
|
20
|
-
truncated: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function readTextTail(filePath: string, maxBytes = 64_000): TextTailResult {
|
|
24
|
-
if (!fs.existsSync(filePath)) return { path: filePath, text: "", bytes: 0, truncated: false };
|
|
25
|
-
const stat = fs.statSync(filePath);
|
|
26
|
-
const bytesToRead = Math.min(stat.size, Math.max(0, maxBytes));
|
|
27
|
-
const fd = fs.openSync(filePath, "r");
|
|
28
|
-
try {
|
|
29
|
-
const buffer = Buffer.alloc(bytesToRead);
|
|
30
|
-
fs.readSync(fd, buffer, 0, bytesToRead, stat.size - bytesToRead);
|
|
31
|
-
return { path: filePath, text: buffer.toString("utf-8"), bytes: stat.size, truncated: stat.size > bytesToRead };
|
|
32
|
-
} finally {
|
|
33
|
-
fs.closeSync(fd);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function compactDuration(ms: number | undefined): string | undefined {
|
|
38
|
-
if (ms === undefined || !Number.isFinite(ms)) return undefined;
|
|
39
|
-
if (ms < 1000) return `${Math.round(ms)}ms`;
|
|
40
|
-
if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;
|
|
41
|
-
return `${Math.floor(ms / 60_000)}m${Math.floor((ms % 60_000) / 1000)}s`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function ageBetween(start: string | undefined, end: string | undefined): string | undefined {
|
|
45
|
-
if (!start) return undefined;
|
|
46
|
-
const stop = end ? new Date(end).getTime() : Date.now();
|
|
47
|
-
const ms = Math.max(0, stop - new Date(start).getTime());
|
|
48
|
-
return compactDuration(ms);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function activityText(agent: CrewAgentRecord): string {
|
|
52
|
-
const parts: string[] = [];
|
|
53
|
-
if (agent.progress?.activityState) parts.push(agent.progress.activityState);
|
|
54
|
-
if (agent.progress?.currentTool) parts.push(TOOL_LABELS[agent.progress.currentTool] ?? `tool=${agent.progress.currentTool}`);
|
|
55
|
-
if (agent.toolUses !== undefined) parts.push(`tools=${agent.toolUses}`);
|
|
56
|
-
if (agent.progress?.tokens !== undefined) parts.push(`tokens=${agent.progress.tokens}`);
|
|
57
|
-
if (agent.progress?.turns !== undefined) parts.push(`turns=${agent.progress.turns}`);
|
|
58
|
-
const duration = compactDuration(agent.progress?.durationMs) ?? ageBetween(agent.startedAt, agent.completedAt);
|
|
59
|
-
if (duration) parts.push(duration);
|
|
60
|
-
if (agent.progress?.failedTool) parts.push(`failedTool=${agent.progress.failedTool}`);
|
|
61
|
-
if (agent.progress?.recentOutput?.length) parts.push(`last=${agent.progress.recentOutput.at(-1)}`);
|
|
62
|
-
return parts.join(" ") || "idle";
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function statusGlyph(status: CrewAgentRecord["status"]): string {
|
|
66
|
-
if (status === "completed") return "✓";
|
|
67
|
-
if (status === "failed") return "✗";
|
|
68
|
-
if (status === "running") return "▶";
|
|
69
|
-
if (status === "cancelled" || status === "stopped") return "■";
|
|
70
|
-
return "·";
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function outputWarning(manifest: TeamRunManifest, agent: CrewAgentRecord): string {
|
|
74
|
-
if (agent.status !== "completed") return "";
|
|
75
|
-
try {
|
|
76
|
-
const outputPath = agentOutputPath(manifest, agent.taskId);
|
|
77
|
-
if (!fs.existsSync(outputPath)) return " no-output";
|
|
78
|
-
return fs.statSync(outputPath).size === 0 ? " no-output" : "";
|
|
79
|
-
} catch {
|
|
80
|
-
return " no-output";
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function agentLine(manifest: TeamRunManifest, agent: CrewAgentRecord): string {
|
|
85
|
-
return `- ${statusGlyph(agent.status)} ${agent.taskId} ${agent.role} → ${agent.agent} · ${agent.status} · ${agent.runtime} · ${activityText(agent)}${outputWarning(manifest, agent)}${agent.error ? ` · error=${agent.error}` : ""}`;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function buildAgentDashboard(manifest: TeamRunManifest): { text: string; groups: Record<string, CrewAgentRecord[]> } {
|
|
89
|
-
const agents = readCrewAgents(manifest);
|
|
90
|
-
const groups: Record<string, CrewAgentRecord[]> = {
|
|
91
|
-
running: agents.filter((agent) => agent.status === "running"),
|
|
92
|
-
queued: agents.filter((agent) => agent.status === "queued"),
|
|
93
|
-
recent: agents.filter((agent) => agent.status !== "running" && agent.status !== "queued"),
|
|
94
|
-
};
|
|
95
|
-
const lines = [
|
|
96
|
-
`Crew agents for ${manifest.runId}`,
|
|
97
|
-
`Run: ${manifest.status} · ${manifest.team}/${manifest.workflow ?? "none"} · agents=${agents.length}`,
|
|
98
|
-
`Counts: running=${groups.running.length}, queued=${groups.queued.length}, recent=${groups.recent.length}`,
|
|
99
|
-
"",
|
|
100
|
-
"## Running",
|
|
101
|
-
...(groups.running.length ? groups.running.map((agent) => agentLine(manifest, agent)) : ["- (none)"]),
|
|
102
|
-
"",
|
|
103
|
-
"## Queued",
|
|
104
|
-
...(groups.queued.length ? groups.queued.map((agent) => agentLine(manifest, agent)) : ["- (none)"]),
|
|
105
|
-
"",
|
|
106
|
-
"## Recent",
|
|
107
|
-
...(groups.recent.length ? groups.recent.slice(-10).map((agent) => agentLine(manifest, agent)) : ["- (none)"]),
|
|
108
|
-
];
|
|
109
|
-
return { text: lines.join("\n"), groups };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function readAgentOutput(manifest: TeamRunManifest, taskId: string, maxBytes?: number): TextTailResult {
|
|
113
|
-
return readTextTail(agentOutputPath(manifest, taskId), maxBytes);
|
|
114
|
-
}
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import type { TeamRunManifest } from "../state/types.ts";
|
|
3
|
+
import { agentOutputPath, readCrewAgents } from "./crew-agent-records.ts";
|
|
4
|
+
import type { CrewAgentRecord } from "./crew-agent-runtime.ts";
|
|
5
|
+
|
|
6
|
+
const TOOL_LABELS: Record<string, string> = {
|
|
7
|
+
read: "reading",
|
|
8
|
+
bash: "running command",
|
|
9
|
+
edit: "editing",
|
|
10
|
+
write: "writing",
|
|
11
|
+
grep: "searching",
|
|
12
|
+
find: "finding files",
|
|
13
|
+
ls: "listing",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export interface TextTailResult {
|
|
17
|
+
path: string;
|
|
18
|
+
text: string;
|
|
19
|
+
bytes: number;
|
|
20
|
+
truncated: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function readTextTail(filePath: string, maxBytes = 64_000): TextTailResult {
|
|
24
|
+
if (!fs.existsSync(filePath)) return { path: filePath, text: "", bytes: 0, truncated: false };
|
|
25
|
+
const stat = fs.statSync(filePath);
|
|
26
|
+
const bytesToRead = Math.min(stat.size, Math.max(0, maxBytes));
|
|
27
|
+
const fd = fs.openSync(filePath, "r");
|
|
28
|
+
try {
|
|
29
|
+
const buffer = Buffer.alloc(bytesToRead);
|
|
30
|
+
fs.readSync(fd, buffer, 0, bytesToRead, stat.size - bytesToRead);
|
|
31
|
+
return { path: filePath, text: buffer.toString("utf-8"), bytes: stat.size, truncated: stat.size > bytesToRead };
|
|
32
|
+
} finally {
|
|
33
|
+
fs.closeSync(fd);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function compactDuration(ms: number | undefined): string | undefined {
|
|
38
|
+
if (ms === undefined || !Number.isFinite(ms)) return undefined;
|
|
39
|
+
if (ms < 1000) return `${Math.round(ms)}ms`;
|
|
40
|
+
if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;
|
|
41
|
+
return `${Math.floor(ms / 60_000)}m${Math.floor((ms % 60_000) / 1000)}s`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function ageBetween(start: string | undefined, end: string | undefined): string | undefined {
|
|
45
|
+
if (!start) return undefined;
|
|
46
|
+
const stop = end ? new Date(end).getTime() : Date.now();
|
|
47
|
+
const ms = Math.max(0, stop - new Date(start).getTime());
|
|
48
|
+
return compactDuration(ms);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function activityText(agent: CrewAgentRecord): string {
|
|
52
|
+
const parts: string[] = [];
|
|
53
|
+
if (agent.progress?.activityState) parts.push(agent.progress.activityState);
|
|
54
|
+
if (agent.progress?.currentTool) parts.push(TOOL_LABELS[agent.progress.currentTool] ?? `tool=${agent.progress.currentTool}`);
|
|
55
|
+
if (agent.toolUses !== undefined) parts.push(`tools=${agent.toolUses}`);
|
|
56
|
+
if (agent.progress?.tokens !== undefined) parts.push(`tokens=${agent.progress.tokens}`);
|
|
57
|
+
if (agent.progress?.turns !== undefined) parts.push(`turns=${agent.progress.turns}`);
|
|
58
|
+
const duration = compactDuration(agent.progress?.durationMs) ?? ageBetween(agent.startedAt, agent.completedAt);
|
|
59
|
+
if (duration) parts.push(duration);
|
|
60
|
+
if (agent.progress?.failedTool) parts.push(`failedTool=${agent.progress.failedTool}`);
|
|
61
|
+
if (agent.progress?.recentOutput?.length) parts.push(`last=${agent.progress.recentOutput.at(-1)}`);
|
|
62
|
+
return parts.join(" ") || "idle";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function statusGlyph(status: CrewAgentRecord["status"]): string {
|
|
66
|
+
if (status === "completed") return "✓";
|
|
67
|
+
if (status === "failed") return "✗";
|
|
68
|
+
if (status === "running") return "▶";
|
|
69
|
+
if (status === "cancelled" || status === "stopped") return "■";
|
|
70
|
+
return "·";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function outputWarning(manifest: TeamRunManifest, agent: CrewAgentRecord): string {
|
|
74
|
+
if (agent.status !== "completed") return "";
|
|
75
|
+
try {
|
|
76
|
+
const outputPath = agentOutputPath(manifest, agent.taskId);
|
|
77
|
+
if (!fs.existsSync(outputPath)) return " no-output";
|
|
78
|
+
return fs.statSync(outputPath).size === 0 ? " no-output" : "";
|
|
79
|
+
} catch {
|
|
80
|
+
return " no-output";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function agentLine(manifest: TeamRunManifest, agent: CrewAgentRecord): string {
|
|
85
|
+
return `- ${statusGlyph(agent.status)} ${agent.taskId} ${agent.role} → ${agent.agent} · ${agent.status} · ${agent.runtime} · ${activityText(agent)}${outputWarning(manifest, agent)}${agent.error ? ` · error=${agent.error}` : ""}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function buildAgentDashboard(manifest: TeamRunManifest): { text: string; groups: Record<string, CrewAgentRecord[]> } {
|
|
89
|
+
const agents = readCrewAgents(manifest);
|
|
90
|
+
const groups: Record<string, CrewAgentRecord[]> = {
|
|
91
|
+
running: agents.filter((agent) => agent.status === "running"),
|
|
92
|
+
queued: agents.filter((agent) => agent.status === "queued"),
|
|
93
|
+
recent: agents.filter((agent) => agent.status !== "running" && agent.status !== "queued"),
|
|
94
|
+
};
|
|
95
|
+
const lines = [
|
|
96
|
+
`Crew agents for ${manifest.runId}`,
|
|
97
|
+
`Run: ${manifest.status} · ${manifest.team}/${manifest.workflow ?? "none"} · agents=${agents.length}`,
|
|
98
|
+
`Counts: running=${groups.running.length}, queued=${groups.queued.length}, recent=${groups.recent.length}`,
|
|
99
|
+
"",
|
|
100
|
+
"## Running",
|
|
101
|
+
...(groups.running.length ? groups.running.map((agent) => agentLine(manifest, agent)) : ["- (none)"]),
|
|
102
|
+
"",
|
|
103
|
+
"## Queued",
|
|
104
|
+
...(groups.queued.length ? groups.queued.map((agent) => agentLine(manifest, agent)) : ["- (none)"]),
|
|
105
|
+
"",
|
|
106
|
+
"## Recent",
|
|
107
|
+
...(groups.recent.length ? groups.recent.slice(-10).map((agent) => agentLine(manifest, agent)) : ["- (none)"]),
|
|
108
|
+
];
|
|
109
|
+
return { text: lines.join("\n"), groups };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function readAgentOutput(manifest: TeamRunManifest, taskId: string, maxBytes?: number): TextTailResult {
|
|
113
|
+
return readTextTail(agentOutputPath(manifest, taskId), maxBytes);
|
|
114
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import { atomicWriteJson } from "../state/atomic-write.ts";
|
|
4
|
-
import type { TeamRunManifest } from "../state/types.ts";
|
|
5
|
-
|
|
6
|
-
export interface AsyncStartMarker {
|
|
7
|
-
pid: number;
|
|
8
|
-
startedAt: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function asyncStartMarkerPath(manifest: Pick<TeamRunManifest, "stateRoot">): string {
|
|
12
|
-
return path.join(manifest.stateRoot, "async.pid");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function writeAsyncStartMarker(manifest: Pick<TeamRunManifest, "stateRoot">, marker: AsyncStartMarker): void {
|
|
16
|
-
atomicWriteJson(asyncStartMarkerPath(manifest), marker);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function hasAsyncStartMarker(manifest: Pick<TeamRunManifest, "stateRoot">): boolean {
|
|
20
|
-
try {
|
|
21
|
-
const raw = JSON.parse(fs.readFileSync(asyncStartMarkerPath(manifest), "utf-8")) as Partial<AsyncStartMarker>;
|
|
22
|
-
return typeof raw.pid === "number" && Number.isInteger(raw.pid) && raw.pid > 0 && typeof raw.startedAt === "string" && raw.startedAt.length > 0;
|
|
23
|
-
} catch {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { atomicWriteJson } from "../state/atomic-write.ts";
|
|
4
|
+
import type { TeamRunManifest } from "../state/types.ts";
|
|
5
|
+
|
|
6
|
+
export interface AsyncStartMarker {
|
|
7
|
+
pid: number;
|
|
8
|
+
startedAt: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function asyncStartMarkerPath(manifest: Pick<TeamRunManifest, "stateRoot">): string {
|
|
12
|
+
return path.join(manifest.stateRoot, "async.pid");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function writeAsyncStartMarker(manifest: Pick<TeamRunManifest, "stateRoot">, marker: AsyncStartMarker): void {
|
|
16
|
+
atomicWriteJson(asyncStartMarkerPath(manifest), marker);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function hasAsyncStartMarker(manifest: Pick<TeamRunManifest, "stateRoot">): boolean {
|
|
20
|
+
try {
|
|
21
|
+
const raw = JSON.parse(fs.readFileSync(asyncStartMarkerPath(manifest), "utf-8")) as Partial<AsyncStartMarker>;
|
|
22
|
+
return typeof raw.pid === "number" && Number.isInteger(raw.pid) && raw.pid > 0 && typeof raw.startedAt === "string" && raw.startedAt.length > 0;
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import { appendEvent, readEvents } from "../state/event-log.ts";
|
|
2
|
-
import type { CrewAttentionEventData, TeamRunManifest } from "../state/types.ts";
|
|
3
|
-
|
|
4
|
-
export interface AppendTaskAttentionInput {
|
|
5
|
-
manifest: TeamRunManifest;
|
|
6
|
-
taskId?: string;
|
|
7
|
-
message: string;
|
|
8
|
-
data: CrewAttentionEventData;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function appendTaskAttentionEvent(input: AppendTaskAttentionInput): boolean {
|
|
12
|
-
const recent = readEvents(input.manifest.eventsPath).slice(-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { appendEvent, readEvents } from "../state/event-log.ts";
|
|
2
|
+
import type { CrewAttentionEventData, TeamRunManifest } from "../state/types.ts";
|
|
3
|
+
|
|
4
|
+
export interface AppendTaskAttentionInput {
|
|
5
|
+
manifest: TeamRunManifest;
|
|
6
|
+
taskId?: string;
|
|
7
|
+
message: string;
|
|
8
|
+
data: CrewAttentionEventData;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function appendTaskAttentionEvent(input: AppendTaskAttentionInput): boolean {
|
|
12
|
+
const recent = readEvents(input.manifest.eventsPath).slice(-200);
|
|
13
|
+
const dedupKey = `${input.taskId ?? ""}:${input.data.reason}:${input.data.activityState}`;
|
|
14
|
+
const duplicate = recent.some(
|
|
15
|
+
(event) =>
|
|
16
|
+
event.type === "task.attention" &&
|
|
17
|
+
`${event.taskId ?? ""}:${event.data?.reason ?? ""}:${event.data?.activityState ?? ""}` === dedupKey,
|
|
18
|
+
);
|
|
19
|
+
if (duplicate) return false;
|
|
20
|
+
appendEvent(input.manifest.eventsPath, {
|
|
21
|
+
type: "task.attention",
|
|
22
|
+
runId: input.manifest.runId,
|
|
23
|
+
taskId: input.taskId,
|
|
24
|
+
message: input.message,
|
|
25
|
+
data: { ...input.data },
|
|
26
|
+
});
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { allAgents, discoverAgents } from "../agents/discover-agents.ts";
|
|
2
|
-
import { allTeams, discoverTeams } from "../teams/discover-teams.ts";
|
|
3
|
-
import { appendEvent } from "../state/event-log.ts";
|
|
4
|
-
import { loadRunManifestById, updateRunStatus } from "../state/state-store.ts";
|
|
5
|
-
import { allWorkflows, discoverWorkflows } from "../workflows/discover-workflows.ts";
|
|
6
|
-
import { loadConfig } from "../config/config.ts";
|
|
7
|
-
import { executeTeamRun } from "./team-runner.ts";
|
|
8
|
-
import { resolveCrewRuntime } from "./runtime-resolver.ts";
|
|
9
|
-
import { directTeamAndWorkflowFromRun } from "./direct-run.ts";
|
|
10
|
-
import { expandParallelResearchWorkflow } from "./parallel-research.ts";
|
|
11
|
-
import { writeAsyncStartMarker } from "./async-marker.ts";
|
|
12
|
-
|
|
13
|
-
function argValue(name: string): string | undefined {
|
|
14
|
-
const index = process.argv.indexOf(name);
|
|
15
|
-
if (index === -1) return undefined;
|
|
16
|
-
return process.argv[index + 1];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async function main(): Promise<void> {
|
|
20
|
-
const cwd = argValue("--cwd");
|
|
21
|
-
const runId = argValue("--run-id");
|
|
22
|
-
if (!cwd || !runId) throw new Error("Usage: background-runner.ts --cwd <cwd> --run-id <runId>");
|
|
23
|
-
|
|
24
|
-
const loaded = loadRunManifestById(cwd, runId);
|
|
25
|
-
if (!loaded) throw new Error(`Run '${runId}' not found.`);
|
|
26
|
-
let { manifest, tasks } = loaded;
|
|
27
|
-
appendEvent(manifest.eventsPath, { type: "async.started", runId: manifest.runId, data: { pid: process.pid } });
|
|
28
|
-
writeAsyncStartMarker(manifest, { pid: process.pid, startedAt: new Date().toISOString() });
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
const agents = allAgents(discoverAgents(cwd));
|
|
32
|
-
const direct = directTeamAndWorkflowFromRun(manifest, tasks, agents);
|
|
33
|
-
const team = direct?.team ?? allTeams(discoverTeams(cwd)).find((candidate) => candidate.name === manifest.team);
|
|
34
|
-
if (!team) throw new Error(`Team '${manifest.team}' not found.`);
|
|
35
|
-
const baseWorkflow = direct?.workflow ?? allWorkflows(discoverWorkflows(cwd)).find((candidate) => candidate.name === manifest.workflow);
|
|
36
|
-
if (!baseWorkflow) throw new Error(`Workflow '${manifest.workflow ?? ""}' not found.`);
|
|
37
|
-
const workflow = expandParallelResearchWorkflow(baseWorkflow, cwd);
|
|
38
|
-
const loadedConfig = loadConfig(cwd);
|
|
39
|
-
const runtime = await resolveCrewRuntime(loadedConfig.config);
|
|
40
|
-
const executeWorkers = runtime.kind !== "scaffold";
|
|
41
|
-
const result = await executeTeamRun({ manifest, tasks, team, workflow, agents, executeWorkers, limits: loadedConfig.config.limits, runtime, runtimeConfig: loadedConfig.config.runtime });
|
|
42
|
-
manifest = result.manifest;
|
|
43
|
-
tasks = result.tasks;
|
|
44
|
-
appendEvent(manifest.eventsPath, { type: "async.completed", runId: manifest.runId, data: { status: manifest.status, tasks: tasks.length } });
|
|
45
|
-
} catch (error) {
|
|
46
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
47
|
-
manifest = updateRunStatus(manifest, "failed", message);
|
|
48
|
-
appendEvent(manifest.eventsPath, { type: "async.failed", runId: manifest.runId, message });
|
|
49
|
-
process.exitCode = 1;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
await main();
|
|
1
|
+
import { allAgents, discoverAgents } from "../agents/discover-agents.ts";
|
|
2
|
+
import { allTeams, discoverTeams } from "../teams/discover-teams.ts";
|
|
3
|
+
import { appendEvent } from "../state/event-log.ts";
|
|
4
|
+
import { loadRunManifestById, updateRunStatus } from "../state/state-store.ts";
|
|
5
|
+
import { allWorkflows, discoverWorkflows } from "../workflows/discover-workflows.ts";
|
|
6
|
+
import { loadConfig } from "../config/config.ts";
|
|
7
|
+
import { executeTeamRun } from "./team-runner.ts";
|
|
8
|
+
import { resolveCrewRuntime } from "./runtime-resolver.ts";
|
|
9
|
+
import { directTeamAndWorkflowFromRun } from "./direct-run.ts";
|
|
10
|
+
import { expandParallelResearchWorkflow } from "./parallel-research.ts";
|
|
11
|
+
import { writeAsyncStartMarker } from "./async-marker.ts";
|
|
12
|
+
|
|
13
|
+
function argValue(name: string): string | undefined {
|
|
14
|
+
const index = process.argv.indexOf(name);
|
|
15
|
+
if (index === -1) return undefined;
|
|
16
|
+
return process.argv[index + 1];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function main(): Promise<void> {
|
|
20
|
+
const cwd = argValue("--cwd");
|
|
21
|
+
const runId = argValue("--run-id");
|
|
22
|
+
if (!cwd || !runId) throw new Error("Usage: background-runner.ts --cwd <cwd> --run-id <runId>");
|
|
23
|
+
|
|
24
|
+
const loaded = loadRunManifestById(cwd, runId);
|
|
25
|
+
if (!loaded) throw new Error(`Run '${runId}' not found.`);
|
|
26
|
+
let { manifest, tasks } = loaded;
|
|
27
|
+
appendEvent(manifest.eventsPath, { type: "async.started", runId: manifest.runId, data: { pid: process.pid } });
|
|
28
|
+
writeAsyncStartMarker(manifest, { pid: process.pid, startedAt: new Date().toISOString() });
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const agents = allAgents(discoverAgents(cwd));
|
|
32
|
+
const direct = directTeamAndWorkflowFromRun(manifest, tasks, agents);
|
|
33
|
+
const team = direct?.team ?? allTeams(discoverTeams(cwd)).find((candidate) => candidate.name === manifest.team);
|
|
34
|
+
if (!team) throw new Error(`Team '${manifest.team}' not found.`);
|
|
35
|
+
const baseWorkflow = direct?.workflow ?? allWorkflows(discoverWorkflows(cwd)).find((candidate) => candidate.name === manifest.workflow);
|
|
36
|
+
if (!baseWorkflow) throw new Error(`Workflow '${manifest.workflow ?? ""}' not found.`);
|
|
37
|
+
const workflow = expandParallelResearchWorkflow(baseWorkflow, cwd);
|
|
38
|
+
const loadedConfig = loadConfig(cwd);
|
|
39
|
+
const runtime = await resolveCrewRuntime(loadedConfig.config);
|
|
40
|
+
const executeWorkers = runtime.kind !== "scaffold";
|
|
41
|
+
const result = await executeTeamRun({ manifest, tasks, team, workflow, agents, executeWorkers, limits: loadedConfig.config.limits, runtime, runtimeConfig: loadedConfig.config.runtime });
|
|
42
|
+
manifest = result.manifest;
|
|
43
|
+
tasks = result.tasks;
|
|
44
|
+
appendEvent(manifest.eventsPath, { type: "async.completed", runId: manifest.runId, data: { status: manifest.status, tasks: tasks.length } });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
47
|
+
manifest = updateRunStatus(manifest, "failed", message);
|
|
48
|
+
appendEvent(manifest.eventsPath, { type: "async.failed", runId: manifest.runId, message });
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await main();
|
package/src/runtime/child-pi.ts
CHANGED
|
@@ -69,7 +69,7 @@ function killProcessTree(pid: number | undefined, child?: ChildProcess): void {
|
|
|
69
69
|
}
|
|
70
70
|
childHardKillTimers.delete(pid);
|
|
71
71
|
}, HARD_KILL_MS);
|
|
72
|
-
hardKillTimer.unref
|
|
72
|
+
hardKillTimer.unref();
|
|
73
73
|
child?.once("exit", () => clearHardKillTimer(pid));
|
|
74
74
|
childHardKillTimers.set(pid, hardKillTimer);
|
|
75
75
|
} catch (error) {
|
|
@@ -318,7 +318,7 @@ export async function runChildPi(input: ChildPiRunInput): Promise<ChildPiRunResu
|
|
|
318
318
|
logInternalError("child-pi.response-timeout-term", error, `pid=${child.pid}`);
|
|
319
319
|
}
|
|
320
320
|
}, responseTimeoutMs);
|
|
321
|
-
noResponseTimer.unref
|
|
321
|
+
noResponseTimer.unref();
|
|
322
322
|
};
|
|
323
323
|
const clearNoResponseTimer = (): void => {
|
|
324
324
|
if (noResponseTimer) clearTimeout(noResponseTimer);
|
|
@@ -352,9 +352,9 @@ export async function runChildPi(input: ChildPiRunInput): Promise<ChildPiRunResu
|
|
|
352
352
|
logInternalError("child-pi.final-drain-kill", error, `pid=${child.pid}`);
|
|
353
353
|
}
|
|
354
354
|
}, hardKillMs);
|
|
355
|
-
hardKillTimer.unref
|
|
355
|
+
hardKillTimer.unref();
|
|
356
356
|
}, finalDrainMs);
|
|
357
|
-
finalDrainTimer.unref
|
|
357
|
+
finalDrainTimer.unref();
|
|
358
358
|
},
|
|
359
359
|
});
|
|
360
360
|
|
|
@@ -1,4 +1,10 @@
|
|
|
1
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
|
+
// ============================================================================
|
|
2
8
|
|
|
3
9
|
export interface CompletionMutationGuardInput {
|
|
4
10
|
role: string;
|
|
@@ -15,9 +21,9 @@ export interface CompletionMutationGuardResult {
|
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
const MUTATING_ROLES = new Set(["executor", "test-engineer"]);
|
|
18
|
-
const MUTATING_TOOLS = new Set(["edit", "write", "multi_edit", "apply_patch"]);
|
|
24
|
+
const MUTATING_TOOLS = new Set(["edit", "write", "multi_edit", "apply_patch", "replace_in_file", "insert", "delete_files", "create_file", "overwrite", "patch"]);
|
|
19
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;
|
|
20
|
-
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)\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;
|
|
21
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;
|
|
22
28
|
|
|
23
29
|
function asRecord(value: unknown): Record<string, unknown> | undefined {
|
|
@@ -39,8 +45,12 @@ function isMutatingTool(tool: string, args: unknown): boolean {
|
|
|
39
45
|
if (MUTATING_TOOLS.has(normalized)) return true;
|
|
40
46
|
if (normalized === "bash" || normalized === "shell" || normalized === "powershell") {
|
|
41
47
|
const command = commandText(args).trim();
|
|
42
|
-
if (!command
|
|
43
|
-
|
|
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;
|
|
44
54
|
}
|
|
45
55
|
return false;
|
|
46
56
|
}
|
|
@@ -97,3 +107,84 @@ export function evaluateCompletionMutationGuard(input: CompletionMutationGuardIn
|
|
|
97
107
|
...(expectedMutation && !observedMutation ? { reason: "no_mutation_observed" as const } : {}),
|
|
98
108
|
};
|
|
99
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
|
+
}
|
|
@@ -44,7 +44,7 @@ export function resolveBatchConcurrency(input: ResolveBatchConcurrencyInput): Ba
|
|
|
44
44
|
else source = "workflow";
|
|
45
45
|
const hardCap = positiveInteger(input.hardCap) ?? DEFAULT_CONCURRENCY.hardCap;
|
|
46
46
|
const maxConcurrent = input.allowUnboundedConcurrency ? requested : Math.min(requested, hardCap);
|
|
47
|
-
const readyCount = Math.max(0, Math.trunc(input.readyCount));
|
|
47
|
+
const readyCount = Math.max(0, Math.trunc(Number.isFinite(input.readyCount) ? input.readyCount : 0));
|
|
48
48
|
const cappedReason = maxConcurrent < requested ? `;capped:${hardCap}` : "";
|
|
49
49
|
const unboundedReason = input.allowUnboundedConcurrency && requested > hardCap ? `;unbounded:${hardCap}` : "";
|
|
50
50
|
return {
|