@tea-agent/loop-agent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +121 -0
- package/CHANGELOG.md +37 -0
- package/README.md +144 -0
- package/bin/loop-agent.js +21 -0
- package/dist/adapters/aimax.js +91 -0
- package/dist/adapters/context.js +32 -0
- package/dist/adapters/index.js +28 -0
- package/dist/adapters/loop-agent.js +98 -0
- package/dist/adapters/types.js +1 -0
- package/dist/cli/catalog.js +259 -0
- package/dist/cli/help.js +55 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/program.js +505 -0
- package/dist/cli.js +12 -0
- package/dist/commands/closeout.js +13 -0
- package/dist/commands/coverage-audit.js +14 -0
- package/dist/commands/cursor-prompt.js +222 -0
- package/dist/commands/cursor-worker.js +43 -0
- package/dist/commands/dag-approve.js +102 -0
- package/dist/commands/dag-final-verification.js +76 -0
- package/dist/commands/dag-init-hybrid.js +56 -0
- package/dist/commands/dag-reconcile-tasks.js +51 -0
- package/dist/commands/dag-reject.js +91 -0
- package/dist/commands/dag-report.js +177 -0
- package/dist/commands/dag-resume.js +34 -0
- package/dist/commands/dag-run-task.js +470 -0
- package/dist/commands/dag-validate.js +186 -0
- package/dist/commands/dag-workflow-compile.js +91 -0
- package/dist/commands/dag-workflow-plan.js +130 -0
- package/dist/commands/dag-workflow-validate.js +66 -0
- package/dist/commands/delegate.js +132 -0
- package/dist/commands/docs-archive.js +5 -0
- package/dist/commands/docs-audit.js +5 -0
- package/dist/commands/doctor.js +50 -0
- package/dist/commands/goal.js +92 -0
- package/dist/commands/handoff-check.js +5 -0
- package/dist/commands/harvest.js +44 -0
- package/dist/commands/inspect.js +11 -0
- package/dist/commands/instructions.js +195 -0
- package/dist/commands/knowledge.js +64 -0
- package/dist/commands/loop-benchmark.js +72 -0
- package/dist/commands/loop.js +241 -0
- package/dist/commands/new-task.js +5 -0
- package/dist/commands/pi-prompt.js +181 -0
- package/dist/commands/pi-reuse-benchmark.js +153 -0
- package/dist/commands/plan-list.js +5 -0
- package/dist/commands/promote-run.js +29 -0
- package/dist/commands/reference-index.js +16 -0
- package/dist/commands/run-dag.js +184 -0
- package/dist/commands/spine.js +38 -0
- package/dist/commands/stats.js +84 -0
- package/dist/commands/status.js +56 -0
- package/dist/commands/study-init.js +192 -0
- package/dist/commands/workflow.js +259 -0
- package/dist/commands/worktree-create.js +31 -0
- package/dist/commands/worktree-list.js +5 -0
- package/dist/commands/worktree-remove.js +26 -0
- package/dist/cursor-worker-entry.js +8 -0
- package/dist/executors/config-core.js +55 -0
- package/dist/executors/config.js +2 -0
- package/dist/executors/cursor-artifacts.js +33 -0
- package/dist/executors/cursor-execution-log.js +81 -0
- package/dist/executors/cursor-executor-artifacts.js +135 -0
- package/dist/executors/cursor-executor.js +468 -0
- package/dist/executors/cursor-run.js +115 -0
- package/dist/executors/cursor-tool.js +94 -0
- package/dist/executors/cursor-worker-client.js +213 -0
- package/dist/executors/cursor-worker-protocol.js +18 -0
- package/dist/executors/cursor-worker-server.js +54 -0
- package/dist/executors/cursor-worker.js +3 -0
- package/dist/executors/cursor.js +6 -0
- package/dist/executors/dag-cursor-executor.js +88 -0
- package/dist/executors/dag-pi-executor.js +322 -0
- package/dist/executors/dag-static-executor.js +45 -0
- package/dist/executors/dag.js +4 -0
- package/dist/executors/index.js +8 -0
- package/dist/executors/model-routing.js +60 -0
- package/dist/executors/pi-event-serializer.js +43 -0
- package/dist/executors/pi-executor.js +606 -0
- package/dist/executors/pi-reuse-benchmark.js +316 -0
- package/dist/executors/pi-runtime-reuse.js +29 -0
- package/dist/executors/pi-sdk-executor.js +255 -0
- package/dist/executors/pi-sdk.js +1 -0
- package/dist/executors/pi.js +3 -0
- package/dist/executors/shell-executor.js +300 -0
- package/dist/executors/shell-presets.js +47 -0
- package/dist/executors/shell-verification.js +251 -0
- package/dist/executors/shell-write-guard.js +126 -0
- package/dist/executors/shell.js +3 -0
- package/dist/executors/static.js +1 -0
- package/dist/governance/checks.js +434 -0
- package/dist/governance/harness.js +9 -0
- package/dist/governance/index.js +3 -0
- package/dist/governance/manifest-types.js +128 -0
- package/dist/governance/manifest.js +2 -0
- package/dist/governance/path-guard.js +69 -0
- package/dist/governance/path-guards.js +2 -0
- package/dist/governance/profiles.js +3 -0
- package/dist/governance/requirement-coverage.js +425 -0
- package/dist/governance/skill-safety.js +135 -0
- package/dist/governance/spine-audit.js +152 -0
- package/dist/records/closeout.js +2 -0
- package/dist/records/harvest.js +236 -0
- package/dist/records/index.js +3 -0
- package/dist/records/one-shot-runs.js +421 -0
- package/dist/records/promotion.js +199 -0
- package/dist/shared/artifacts-core.js +88 -0
- package/dist/shared/artifacts.js +2 -0
- package/dist/shared/context-files.js +32 -0
- package/dist/shared/context.js +2 -0
- package/dist/shared/copy-dir.js +17 -0
- package/dist/shared/git-progress.js +165 -0
- package/dist/shared/index.js +5 -0
- package/dist/shared/logger.js +23 -0
- package/dist/shared/one-shot-prompt-args.js +98 -0
- package/dist/shared/path-refs.js +31 -0
- package/dist/shared/prompts.js +26 -0
- package/dist/shared/reference-context.js +238 -0
- package/dist/shared/timeout-policy.js +19 -0
- package/dist/shared/timeout.js +1 -0
- package/dist/shared/types.js +5 -0
- package/dist/task/config-types.js +97 -0
- package/dist/task/config.js +2 -0
- package/dist/task/delegate.js +220 -0
- package/dist/task/goal-audit.js +51 -0
- package/dist/task/goal-policy.js +8 -0
- package/dist/task/goal.js +3 -0
- package/dist/task/ids.js +1 -0
- package/dist/task/index.js +9 -0
- package/dist/task/lifecycle.js +1 -0
- package/dist/task/paths.js +1 -0
- package/dist/task/read-model.js +149 -0
- package/dist/task/runtime.js +699 -0
- package/dist/task/source-state.js +1 -0
- package/dist/task/state.js +55 -0
- package/dist/task/subagent-guidance.js +1 -0
- package/dist/task/workflow-state-types.js +92 -0
- package/dist/task/worktree-cleanup.js +140 -0
- package/dist/task/worktree.js +171 -0
- package/dist/workflows/dag/authoring.js +8 -0
- package/dist/workflows/dag/authority-surface.js +138 -0
- package/dist/workflows/dag/canvas-observer.js +474 -0
- package/dist/workflows/dag/decision-envelope.js +502 -0
- package/dist/workflows/dag/decision-evidence.js +153 -0
- package/dist/workflows/dag/decision-gates.js +1 -0
- package/dist/workflows/dag/executor-registry.js +25 -0
- package/dist/workflows/dag/facts.js +4 -0
- package/dist/workflows/dag/failure-category.js +111 -0
- package/dist/workflows/dag/final-verification.js +180 -0
- package/dist/workflows/dag/governance-constants.js +5 -0
- package/dist/workflows/dag/governance-profile.js +405 -0
- package/dist/workflows/dag/index.js +6 -0
- package/dist/workflows/dag/init-hybrid.js +855 -0
- package/dist/workflows/dag/knowledge-curator.js +162 -0
- package/dist/workflows/dag/lifecycle.js +484 -0
- package/dist/workflows/dag/prompt-source.js +88 -0
- package/dist/workflows/dag/prompt.js +130 -0
- package/dist/workflows/dag/reconcile-tasks.js +404 -0
- package/dist/workflows/dag/recovery-recommendation.js +226 -0
- package/dist/workflows/dag/repair-artifact.js +136 -0
- package/dist/workflows/dag/report.js +1019 -0
- package/dist/workflows/dag/runner.js +1677 -0
- package/dist/workflows/dag/runtime.js +5 -0
- package/dist/workflows/dag/skill-instructions.js +471 -0
- package/dist/workflows/dag/skills.js +41 -0
- package/dist/workflows/dag/spec.js +3 -0
- package/dist/workflows/dag/topo.js +30 -0
- package/dist/workflows/dag/types.js +275 -0
- package/dist/workflows/dag/upstream-artifacts.js +95 -0
- package/dist/workflows/dag/validate.js +527 -0
- package/dist/workflows/dynamic/artifacts.js +65 -0
- package/dist/workflows/dynamic/compile.js +360 -0
- package/dist/workflows/dynamic/compileTypes.js +1 -0
- package/dist/workflows/dynamic/errors.js +5 -0
- package/dist/workflows/dynamic/index.js +7 -0
- package/dist/workflows/dynamic/profiles.js +156 -0
- package/dist/workflows/dynamic/spec.js +114 -0
- package/dist/workflows/dynamic/validate.js +275 -0
- package/dist/workflows/loop/actions.js +1334 -0
- package/dist/workflows/loop/benchmark.js +510 -0
- package/dist/workflows/loop/closeout.js +134 -0
- package/dist/workflows/loop/context.js +48 -0
- package/dist/workflows/loop/events.js +25 -0
- package/dist/workflows/loop/hash.js +32 -0
- package/dist/workflows/loop/index.js +8 -0
- package/dist/workflows/loop/paths.js +17 -0
- package/dist/workflows/loop/rounds.js +81 -0
- package/dist/workflows/loop/signals.js +55 -0
- package/dist/workflows/loop/state.js +116 -0
- package/dist/workflows/loop/templates.js +54 -0
- package/dist/workflows/loop/types.js +28 -0
- package/docs/README.md +62 -0
- package/docs/agent-dag-recovery-playbook.md +158 -0
- package/docs/agent-dag-runner.md +40 -0
- package/docs/cursor-executor-usage.md +25 -0
- package/docs/decisions/README.md +3 -0
- package/docs/design/README.md +36 -0
- package/docs/development-principles.md +71 -0
- package/docs/dynamic-workflow-dag-engine-roadmap.md +1749 -0
- package/docs/exec-plans/README.md +6 -0
- package/docs/exec-plans/active/README.md +5 -0
- package/docs/exec-plans/completed/README.md +5 -0
- package/docs/feature-workflow.md +184 -0
- package/docs/harness-methodology-debugging.md +153 -0
- package/docs/harness-methodology-tdd.md +130 -0
- package/docs/harness-methodology-verification.md +27 -0
- package/docs/loop-agent-harness.md +42 -0
- package/docs/progress/README.md +3 -0
- package/docs/reports/README.md +3 -0
- package/docs/templates/adr.md +60 -0
- package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -0
- package/docs/templates/agent-dag-decision-envelope.schema.json +213 -0
- package/docs/templates/agent-dag-decision-gate-dogfood-report.md +117 -0
- package/docs/templates/agent-dag-decision-gate.prompt.md +246 -0
- package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -0
- package/docs/templates/agent-dag-report.schema.json +423 -0
- package/docs/templates/agent-dag-review-verdict.prompt.md +68 -0
- package/docs/templates/agent-dag.base.json +195 -0
- package/docs/templates/agent-dag.final-verification.json +190 -0
- package/docs/templates/agent-dag.schema.json +316 -0
- package/docs/templates/agent-dag.supervised-implementation.json +500 -0
- package/docs/templates/exec-plan.md +64 -0
- package/docs/templates/feature-spec.md +53 -0
- package/docs/templates/hybrid-dag.json +193 -0
- package/docs/templates/progress-log.md +17 -0
- package/docs/templates/project-start-checklist.md +9 -0
- package/docs/templates/qa-report.md +42 -0
- package/docs/templates/sprint-contract.md +29 -0
- package/docs/verification-matrix.md +30 -0
- package/examples/decision-gate-agent-dag.json +123 -0
- package/examples/example-dag.json +51 -0
- package/examples/hybrid-loop-agent-dag.json +194 -0
- package/harness.json +92 -0
- package/package.json +61 -0
- package/skills/ai-engineering-context/SKILL.md +48 -0
- package/skills/loop-agent/SKILL.md +260 -0
- package/skills/loop-agent/references/README.md +63 -0
- package/skills/loop-agent/references/command-reference.md +315 -0
- package/skills/loop-agent/references/harness-policy.md +258 -0
- package/skills/loop-agent/references/hybrid-dag.md +216 -0
- package/skills/loop-agent/references/learned/README.md +21 -0
- package/skills/loop-agent/references/model-routing.md +36 -0
- package/skills/loop-agent/references/multi-worktree.md +54 -0
- package/skills/loop-agent/references/one-shot-runs.md +85 -0
- package/skills/loop-agent/references/orchestrator-and-interventions.md +169 -0
- package/skills/loop-agent/references/pi-prompt.md +23 -0
- package/skills/loop-agent/references/pi-subagent-assisted-mode.md +83 -0
- package/skills/loop-agent/references/post-implementation-and-patterns.md +44 -0
- package/skills/loop-agent/references/task-workflow.md +84 -0
- package/skills/loop-agent/references/verification-and-failure-handling.md +74 -0
- package/skills/requesting-code-review/SKILL.md +101 -0
- package/skills/requesting-code-review/code-reviewer.md +168 -0
- package/skills/systematic-debugging/CREATION-LOG.md +119 -0
- package/skills/systematic-debugging/SKILL.md +296 -0
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/skills/systematic-debugging/find-polluter.sh +63 -0
- package/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/skills/systematic-debugging/test-academic.md +14 -0
- package/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/skills/verification-before-completion/SKILL.md +154 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { resolveModelForTask, } from "./types.js";
|
|
5
|
+
function normalizeCanvasPath(canvasPath) {
|
|
6
|
+
if (canvasPath.endsWith(".canvas.tsx"))
|
|
7
|
+
return canvasPath;
|
|
8
|
+
if (canvasPath.endsWith(".tsx")) {
|
|
9
|
+
return canvasPath.replace(/\.tsx$/, "") + ".canvas.tsx";
|
|
10
|
+
}
|
|
11
|
+
return `${canvasPath}.canvas.tsx`;
|
|
12
|
+
}
|
|
13
|
+
/** Mirrors cookbook canvas path scheme for `--canvas <name>`. */
|
|
14
|
+
export function defaultCanvasesDir(cwd) {
|
|
15
|
+
const slug = cwd
|
|
16
|
+
.replace(/^\//, "")
|
|
17
|
+
.replace(/\/+$/, "")
|
|
18
|
+
.split("/")
|
|
19
|
+
.map((seg) => seg.replace(/[^A-Za-z0-9._-]/g, "-"))
|
|
20
|
+
.join("-");
|
|
21
|
+
return path.join(homedir(), ".cursor", "projects", slug, "canvases");
|
|
22
|
+
}
|
|
23
|
+
export function resolveCanvasPath(input) {
|
|
24
|
+
if (input.canvasPath) {
|
|
25
|
+
return path.resolve(normalizeCanvasPath(input.canvasPath));
|
|
26
|
+
}
|
|
27
|
+
if (input.canvasName) {
|
|
28
|
+
const dir = input.canvasesDir
|
|
29
|
+
? path.resolve(input.canvasesDir)
|
|
30
|
+
: defaultCanvasesDir(input.cwd);
|
|
31
|
+
const stem = input.canvasName.replace(/\.canvas\.tsx$/, "");
|
|
32
|
+
return path.join(dir, `${stem}.canvas.tsx`);
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
function isoToEpochMs(iso) {
|
|
37
|
+
if (!iso)
|
|
38
|
+
return undefined;
|
|
39
|
+
const ms = Date.parse(iso);
|
|
40
|
+
return Number.isFinite(ms) ? ms : undefined;
|
|
41
|
+
}
|
|
42
|
+
function mapNodeStatus(status) {
|
|
43
|
+
return status;
|
|
44
|
+
}
|
|
45
|
+
function mapRunOutcome(state) {
|
|
46
|
+
switch (state.status) {
|
|
47
|
+
case "finished":
|
|
48
|
+
return { runOutcome: "SUCCESS" };
|
|
49
|
+
case "partial_failed":
|
|
50
|
+
return {
|
|
51
|
+
runOutcome: "FAILED",
|
|
52
|
+
runMessage: "One or more nodes failed; see task cards.",
|
|
53
|
+
};
|
|
54
|
+
case "failed":
|
|
55
|
+
return { runOutcome: "FAILED", runMessage: "All runnable nodes failed." };
|
|
56
|
+
case "paused":
|
|
57
|
+
return {
|
|
58
|
+
runOutcome: "PAUSED",
|
|
59
|
+
runMessage: state.pauseReason ?? "Run paused for human decision.",
|
|
60
|
+
};
|
|
61
|
+
case "pending":
|
|
62
|
+
case "running":
|
|
63
|
+
default:
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function mapDagRunStateToCanvasState(state, spec, streamingText = {}) {
|
|
68
|
+
const tasks = spec.tasks.map((task) => {
|
|
69
|
+
const node = state.nodes[task.id];
|
|
70
|
+
const status = node ? mapNodeStatus(node.status) : "PENDING";
|
|
71
|
+
const resultText = streamingText[task.id] ??
|
|
72
|
+
node?.assistantText ??
|
|
73
|
+
(status === "FINISHED" || status === "RUNNING" ? node?.stdout : undefined);
|
|
74
|
+
return {
|
|
75
|
+
id: task.id,
|
|
76
|
+
depends_on: task.depends_on,
|
|
77
|
+
complexity: task.complexity,
|
|
78
|
+
executor: task.executor,
|
|
79
|
+
subtask_prompt: task.subtask_prompt,
|
|
80
|
+
status,
|
|
81
|
+
model: resolveModelForTask(task, spec.executorModels) ?? "(none)",
|
|
82
|
+
startedAt: isoToEpochMs(node?.startedAt),
|
|
83
|
+
finishedAt: isoToEpochMs(node?.finishedAt),
|
|
84
|
+
resultText: resultText?.trim() ? resultText : undefined,
|
|
85
|
+
errorMessage: node?.stderr?.trim() ? node.stderr : undefined,
|
|
86
|
+
inputTokens: node?.tokensUsed,
|
|
87
|
+
durationMs: node?.durationMs,
|
|
88
|
+
skippedReason: node?.skippedReason,
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
title: state.title,
|
|
93
|
+
runId: state.runId,
|
|
94
|
+
startedAt: isoToEpochMs(state.startedAt) ?? Date.now(),
|
|
95
|
+
finishedAt: isoToEpochMs(state.finishedAt),
|
|
96
|
+
...mapRunOutcome(state),
|
|
97
|
+
tasks,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export function renderCanvasSource(state) {
|
|
101
|
+
const stateLiteral = JSON.stringify(state, null, 2);
|
|
102
|
+
return `${CANVAS_HEADER}\n\nconst STATE: RunState = ${stateLiteral};\n\n${CANVAS_BODY}\n`;
|
|
103
|
+
}
|
|
104
|
+
export class DagCanvasWriter {
|
|
105
|
+
canvasPath;
|
|
106
|
+
debounceMs;
|
|
107
|
+
pending = null;
|
|
108
|
+
timer = null;
|
|
109
|
+
inFlight = Promise.resolve();
|
|
110
|
+
writeSeq = 0;
|
|
111
|
+
lastFailedWriteSeq = 0;
|
|
112
|
+
lastWriteError = null;
|
|
113
|
+
constructor(canvasPath, debounceMs = 200) {
|
|
114
|
+
this.canvasPath = canvasPath;
|
|
115
|
+
this.debounceMs = debounceMs;
|
|
116
|
+
}
|
|
117
|
+
schedule(state) {
|
|
118
|
+
this.pending = state;
|
|
119
|
+
if (this.timer)
|
|
120
|
+
return;
|
|
121
|
+
this.timer = setTimeout(() => {
|
|
122
|
+
this.timer = null;
|
|
123
|
+
const snapshot = this.pending;
|
|
124
|
+
this.pending = null;
|
|
125
|
+
if (snapshot) {
|
|
126
|
+
this.enqueueWrite(snapshot);
|
|
127
|
+
}
|
|
128
|
+
}, this.debounceMs);
|
|
129
|
+
}
|
|
130
|
+
async flush() {
|
|
131
|
+
if (this.timer) {
|
|
132
|
+
clearTimeout(this.timer);
|
|
133
|
+
this.timer = null;
|
|
134
|
+
}
|
|
135
|
+
const snapshot = this.pending;
|
|
136
|
+
this.pending = null;
|
|
137
|
+
const targetWriteSeq = snapshot ? this.enqueueWrite(snapshot) : this.writeSeq;
|
|
138
|
+
await this.inFlight;
|
|
139
|
+
if (targetWriteSeq > 0 && this.lastFailedWriteSeq === targetWriteSeq) {
|
|
140
|
+
throw this.lastWriteError;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
getLastWriteError() {
|
|
144
|
+
return this.lastWriteError;
|
|
145
|
+
}
|
|
146
|
+
enqueueWrite(state) {
|
|
147
|
+
const seq = ++this.writeSeq;
|
|
148
|
+
this.inFlight = this.inFlight.then(async () => {
|
|
149
|
+
try {
|
|
150
|
+
await this.writeNow(state);
|
|
151
|
+
if (this.lastFailedWriteSeq < seq) {
|
|
152
|
+
this.lastWriteError = null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
this.lastFailedWriteSeq = seq;
|
|
157
|
+
this.lastWriteError = err;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return seq;
|
|
161
|
+
}
|
|
162
|
+
async writeNow(state) {
|
|
163
|
+
const source = renderCanvasSource(state);
|
|
164
|
+
await mkdir(path.dirname(this.canvasPath), { recursive: true });
|
|
165
|
+
await writeFile(this.canvasPath, source, "utf8");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export function createDagCanvasObserver(opts) {
|
|
169
|
+
const writer = new DagCanvasWriter(opts.canvasPath, opts.debounceMs ?? 200);
|
|
170
|
+
const streamingText = {};
|
|
171
|
+
const publish = (state) => {
|
|
172
|
+
writer.schedule(mapDagRunStateToCanvasState(state, opts.spec, streamingText));
|
|
173
|
+
};
|
|
174
|
+
const observer = {
|
|
175
|
+
onRunStart: (state) => {
|
|
176
|
+
publish(state);
|
|
177
|
+
},
|
|
178
|
+
onNodeStart: (nodeId, state) => {
|
|
179
|
+
delete streamingText[nodeId];
|
|
180
|
+
publish(state);
|
|
181
|
+
},
|
|
182
|
+
onNodeOutput: (nodeId, chunk, state) => {
|
|
183
|
+
streamingText[nodeId] = (streamingText[nodeId] ?? "") + chunk;
|
|
184
|
+
publish(state);
|
|
185
|
+
},
|
|
186
|
+
onNodeFinish: (_nodeId, state) => {
|
|
187
|
+
publish(state);
|
|
188
|
+
},
|
|
189
|
+
onRunFinish: (state) => {
|
|
190
|
+
publish(state);
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
observer,
|
|
195
|
+
flush: () => writer.flush(),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const CANVAS_HEADER = `/* AUTO-GENERATED by . run-dag canvas observer. Derived view only — canonical state lives in .harness/dag-runs/. */
|
|
199
|
+
import {
|
|
200
|
+
Card,
|
|
201
|
+
CardBody,
|
|
202
|
+
CardHeader,
|
|
203
|
+
Divider,
|
|
204
|
+
Grid,
|
|
205
|
+
H1,
|
|
206
|
+
H2,
|
|
207
|
+
Pill,
|
|
208
|
+
Row,
|
|
209
|
+
Stack,
|
|
210
|
+
Stat,
|
|
211
|
+
Text,
|
|
212
|
+
computeDAGLayout,
|
|
213
|
+
useHostTheme,
|
|
214
|
+
} from 'cursor/canvas';
|
|
215
|
+
import { useMemo } from 'react';
|
|
216
|
+
|
|
217
|
+
type TaskStatus = 'PENDING' | 'RUNNING' | 'FINISHED' | 'ERROR' | 'SKIPPED';
|
|
218
|
+
type Complexity = 'HIGH' | 'MED' | 'LOW';
|
|
219
|
+
type Executor = 'cursor' | 'pi' | 'shell' | 'static';
|
|
220
|
+
|
|
221
|
+
interface TaskState {
|
|
222
|
+
id: string;
|
|
223
|
+
depends_on: string[];
|
|
224
|
+
complexity: Complexity;
|
|
225
|
+
executor: Executor;
|
|
226
|
+
subtask_prompt: string;
|
|
227
|
+
status: TaskStatus;
|
|
228
|
+
model: string;
|
|
229
|
+
startedAt?: number;
|
|
230
|
+
finishedAt?: number;
|
|
231
|
+
resultText?: string;
|
|
232
|
+
errorMessage?: string;
|
|
233
|
+
inputTokens?: number;
|
|
234
|
+
outputTokens?: number;
|
|
235
|
+
durationMs?: number;
|
|
236
|
+
skippedReason?: string;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
interface RunState {
|
|
240
|
+
title: string;
|
|
241
|
+
runId: string;
|
|
242
|
+
startedAt: number;
|
|
243
|
+
finishedAt?: number;
|
|
244
|
+
runOutcome?: 'SUCCESS' | 'FAILED' | 'INTERRUPTED' | 'PAUSED';
|
|
245
|
+
runMessage?: string;
|
|
246
|
+
tasks: TaskState[];
|
|
247
|
+
}`;
|
|
248
|
+
const CANVAS_BODY = String.raw `const NODE_W = 200;
|
|
249
|
+
const NODE_H = 72;
|
|
250
|
+
|
|
251
|
+
function pillToneFor(status: TaskStatus): 'neutral' | 'info' | 'success' | 'warning' {
|
|
252
|
+
switch (status) {
|
|
253
|
+
case 'PENDING':
|
|
254
|
+
return 'neutral';
|
|
255
|
+
case 'RUNNING':
|
|
256
|
+
return 'info';
|
|
257
|
+
case 'FINISHED':
|
|
258
|
+
return 'success';
|
|
259
|
+
case 'ERROR':
|
|
260
|
+
return 'warning';
|
|
261
|
+
case 'SKIPPED':
|
|
262
|
+
return 'neutral';
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function formatDuration(ms?: number): string {
|
|
267
|
+
if (ms === undefined) return '—';
|
|
268
|
+
if (ms < 1000) return ms + 'ms';
|
|
269
|
+
const s = ms / 1000;
|
|
270
|
+
if (s < 60) return s.toFixed(1) + 's';
|
|
271
|
+
const m = Math.floor(s / 60);
|
|
272
|
+
const rem = Math.round(s - m * 60);
|
|
273
|
+
return m + 'm ' + rem + 's';
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function elapsed(state: RunState): number {
|
|
277
|
+
const end = state.finishedAt ?? Date.now();
|
|
278
|
+
return end - state.startedAt;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function DAGGraph({ state }: { state: RunState }): JSX.Element {
|
|
282
|
+
const theme = useHostTheme();
|
|
283
|
+
const layout = computeDAGLayout({
|
|
284
|
+
nodes: state.tasks.map((t) => ({ id: t.id })),
|
|
285
|
+
edges: state.tasks.flatMap((t) =>
|
|
286
|
+
t.depends_on.map((d) => ({ from: d, to: t.id })),
|
|
287
|
+
),
|
|
288
|
+
direction: 'vertical',
|
|
289
|
+
nodeWidth: NODE_W,
|
|
290
|
+
nodeHeight: NODE_H,
|
|
291
|
+
rankGap: 72,
|
|
292
|
+
nodeGap: 40,
|
|
293
|
+
padding: 24,
|
|
294
|
+
});
|
|
295
|
+
const byId = new Map(state.tasks.map((t) => [t.id, t]));
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
<svg width={layout.width} height={layout.height} style={{ display: 'block', maxWidth: '100%' }}>
|
|
299
|
+
{layout.edges.map((e, i) => (
|
|
300
|
+
<line
|
|
301
|
+
key={'e' + i}
|
|
302
|
+
x1={e.sourceX}
|
|
303
|
+
y1={e.sourceY}
|
|
304
|
+
x2={e.targetX}
|
|
305
|
+
y2={e.targetY}
|
|
306
|
+
stroke={theme.stroke.secondary}
|
|
307
|
+
strokeWidth={1.25}
|
|
308
|
+
markerEnd="url(#dag-arrow)"
|
|
309
|
+
/>
|
|
310
|
+
))}
|
|
311
|
+
<defs>
|
|
312
|
+
<marker id="dag-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
|
|
313
|
+
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.stroke.secondary} />
|
|
314
|
+
</marker>
|
|
315
|
+
</defs>
|
|
316
|
+
{layout.nodes.map((n) => {
|
|
317
|
+
const t = byId.get(n.id);
|
|
318
|
+
if (!t) return null;
|
|
319
|
+
return (
|
|
320
|
+
<g key={n.id} transform={'translate(' + n.x + ',' + n.y + ')'}>
|
|
321
|
+
<rect
|
|
322
|
+
width={NODE_W}
|
|
323
|
+
height={NODE_H}
|
|
324
|
+
rx={8}
|
|
325
|
+
ry={8}
|
|
326
|
+
fill={theme.fill.secondary}
|
|
327
|
+
stroke={theme.stroke.secondary}
|
|
328
|
+
strokeWidth={t.status === 'RUNNING' ? 2 : 1}
|
|
329
|
+
/>
|
|
330
|
+
<text x={12} y={22} fontSize={13} fontWeight={600} fill={theme.text.primary}>
|
|
331
|
+
{t.id.length > 22 ? t.id.slice(0, 21) + '…' : t.id}
|
|
332
|
+
</text>
|
|
333
|
+
<text x={12} y={42} fontSize={10.5} fill={theme.text.secondary}>
|
|
334
|
+
{t.executor} · {t.complexity} · {t.status}
|
|
335
|
+
</text>
|
|
336
|
+
<text x={12} y={58} fontSize={10.5} fill={theme.text.tertiary}>
|
|
337
|
+
{formatDuration(t.durationMs)}
|
|
338
|
+
</text>
|
|
339
|
+
</g>
|
|
340
|
+
);
|
|
341
|
+
})}
|
|
342
|
+
</svg>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export default function DagRun(): JSX.Element {
|
|
347
|
+
const counts = useMemo(
|
|
348
|
+
() =>
|
|
349
|
+
STATE.tasks.reduce(
|
|
350
|
+
(acc, t) => {
|
|
351
|
+
acc.total += 1;
|
|
352
|
+
const key = t.status.toLowerCase() as 'pending' | 'running' | 'finished' | 'error' | 'skipped';
|
|
353
|
+
if (key in acc) acc[key] += 1;
|
|
354
|
+
return acc;
|
|
355
|
+
},
|
|
356
|
+
{ total: 0, pending: 0, running: 0, finished: 0, error: 0, skipped: 0 },
|
|
357
|
+
),
|
|
358
|
+
[],
|
|
359
|
+
);
|
|
360
|
+
const isFinal = STATE.finishedAt !== undefined;
|
|
361
|
+
const statusLabel =
|
|
362
|
+
STATE.runOutcome === 'PAUSED'
|
|
363
|
+
? 'PAUSED'
|
|
364
|
+
: STATE.runOutcome === 'FAILED'
|
|
365
|
+
? 'FAILED'
|
|
366
|
+
: isFinal
|
|
367
|
+
? 'COMPLETE'
|
|
368
|
+
: 'RUNNING';
|
|
369
|
+
const statusTone =
|
|
370
|
+
STATE.runOutcome === 'FAILED'
|
|
371
|
+
? 'danger'
|
|
372
|
+
: STATE.runOutcome === 'PAUSED'
|
|
373
|
+
? 'warning'
|
|
374
|
+
: isFinal
|
|
375
|
+
? 'success'
|
|
376
|
+
: 'info';
|
|
377
|
+
|
|
378
|
+
return (
|
|
379
|
+
<Stack gap={20}>
|
|
380
|
+
<Stack gap={6}>
|
|
381
|
+
<H1>{STATE.title}</H1>
|
|
382
|
+
<Text tone="secondary" size="small">
|
|
383
|
+
run {STATE.runId}
|
|
384
|
+
</Text>
|
|
385
|
+
<Row gap={10} align="center">
|
|
386
|
+
<Pill tone={statusTone} active size="sm">
|
|
387
|
+
{statusLabel}
|
|
388
|
+
</Pill>
|
|
389
|
+
<Text tone="secondary" size="small">
|
|
390
|
+
{counts.total} tasks · elapsed {formatDuration(elapsed(STATE))}
|
|
391
|
+
</Text>
|
|
392
|
+
</Row>
|
|
393
|
+
{STATE.runMessage ? (
|
|
394
|
+
<Text tone="secondary" size="small">
|
|
395
|
+
{STATE.runMessage}
|
|
396
|
+
</Text>
|
|
397
|
+
) : null}
|
|
398
|
+
</Stack>
|
|
399
|
+
|
|
400
|
+
<Grid columns={6} gap={12}>
|
|
401
|
+
<Stat value={String(counts.total)} label="Total" />
|
|
402
|
+
<Stat value={String(counts.pending)} label="Pending" />
|
|
403
|
+
<Stat value={String(counts.running)} label="Running" tone={counts.running > 0 ? 'info' : undefined} />
|
|
404
|
+
<Stat value={String(counts.finished)} label="Finished" tone={counts.finished > 0 ? 'success' : undefined} />
|
|
405
|
+
<Stat value={String(counts.error)} label="Errored" tone={counts.error > 0 ? 'danger' : undefined} />
|
|
406
|
+
<Stat value={String(counts.skipped)} label="Skipped" />
|
|
407
|
+
</Grid>
|
|
408
|
+
|
|
409
|
+
<Divider />
|
|
410
|
+
|
|
411
|
+
<Stack gap={12}>
|
|
412
|
+
<H2>Graph</H2>
|
|
413
|
+
<DAGGraph state={STATE} />
|
|
414
|
+
</Stack>
|
|
415
|
+
|
|
416
|
+
<Divider />
|
|
417
|
+
|
|
418
|
+
<Stack gap={12}>
|
|
419
|
+
<H2>Tasks</H2>
|
|
420
|
+
<Stack gap={10}>
|
|
421
|
+
{STATE.tasks.map((t) => (
|
|
422
|
+
<Card key={t.id} collapsible defaultOpen={t.status !== 'PENDING'}>
|
|
423
|
+
<CardHeader
|
|
424
|
+
trailing={
|
|
425
|
+
<Row gap={6} align="center">
|
|
426
|
+
<Pill tone="neutral" size="sm">
|
|
427
|
+
{t.executor}
|
|
428
|
+
</Pill>
|
|
429
|
+
<Pill tone={pillToneFor(t.status)} active={t.status !== 'PENDING'} size="sm">
|
|
430
|
+
{t.status}
|
|
431
|
+
</Pill>
|
|
432
|
+
</Row>
|
|
433
|
+
}
|
|
434
|
+
>
|
|
435
|
+
{t.id}
|
|
436
|
+
</CardHeader>
|
|
437
|
+
<CardBody>
|
|
438
|
+
<Stack gap={8}>
|
|
439
|
+
<Text tone="secondary" size="small">
|
|
440
|
+
Model {t.model}
|
|
441
|
+
{t.depends_on.length > 0 ? ' · depends on ' + t.depends_on.join(', ') : ''}
|
|
442
|
+
{t.durationMs !== undefined ? ' · ' + formatDuration(t.durationMs) : ''}
|
|
443
|
+
</Text>
|
|
444
|
+
<Text size="small">
|
|
445
|
+
<Text as="span" weight="semibold">
|
|
446
|
+
Prompt:{' '}
|
|
447
|
+
</Text>
|
|
448
|
+
{t.subtask_prompt}
|
|
449
|
+
</Text>
|
|
450
|
+
{t.resultText ? (
|
|
451
|
+
<pre style={{ margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
|
|
452
|
+
{t.resultText}
|
|
453
|
+
{t.status === 'RUNNING' ? '\u2588' : ''}
|
|
454
|
+
</pre>
|
|
455
|
+
) : null}
|
|
456
|
+
{t.skippedReason ? (
|
|
457
|
+
<Text size="small" tone="secondary">
|
|
458
|
+
Skipped: {t.skippedReason}
|
|
459
|
+
</Text>
|
|
460
|
+
) : null}
|
|
461
|
+
{t.errorMessage ? (
|
|
462
|
+
<Text size="small" tone="secondary">
|
|
463
|
+
{t.errorMessage}
|
|
464
|
+
</Text>
|
|
465
|
+
) : null}
|
|
466
|
+
</Stack>
|
|
467
|
+
</CardBody>
|
|
468
|
+
</Card>
|
|
469
|
+
))}
|
|
470
|
+
</Stack>
|
|
471
|
+
</Stack>
|
|
472
|
+
</Stack>
|
|
473
|
+
);
|
|
474
|
+
}`;
|