@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,149 @@
|
|
|
1
|
+
import { access } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { queryCursorRuns } from "../records/one-shot-runs.js";
|
|
4
|
+
import { defaultHybridDagOutputPath } from "../workflows/dag/init-hybrid.js";
|
|
5
|
+
import { listAllDagRunEntries, readDagRunSpec } from "../workflows/dag/lifecycle.js";
|
|
6
|
+
import { getTaskDir, getTaskPaths, getTaskStatus } from "./runtime.js";
|
|
7
|
+
async function exists(filePath) {
|
|
8
|
+
try {
|
|
9
|
+
await access(filePath);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function listRelatedDagRuns(repoRoot, taskId) {
|
|
17
|
+
const entries = await listAllDagRunEntries(repoRoot);
|
|
18
|
+
const related = [];
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
if (entry.runId.includes(taskId)) {
|
|
21
|
+
related.push(entry);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const spec = await readDagRunSpec(entry.runDir).catch(() => null);
|
|
25
|
+
if (spec && JSON.stringify(spec).includes(taskId)) {
|
|
26
|
+
related.push(entry);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return related;
|
|
30
|
+
}
|
|
31
|
+
function defaultDagDraftPath(taskId) {
|
|
32
|
+
return defaultHybridDagOutputPath(taskId);
|
|
33
|
+
}
|
|
34
|
+
function closeoutPath(repoRoot, taskId) {
|
|
35
|
+
return path.join(repoRoot, "docs", "progress", `${taskId}.md`);
|
|
36
|
+
}
|
|
37
|
+
function deriveNextAction(input) {
|
|
38
|
+
if (!input.sourceReady) {
|
|
39
|
+
return {
|
|
40
|
+
command: `npm run dev -- instructions source --task ${input.taskId} --json`,
|
|
41
|
+
reason: "source materials are not ready",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (!input.dagDraftExists && !input.latestDagRun) {
|
|
45
|
+
return {
|
|
46
|
+
command: `npm run dev -- dag run-task ${input.taskId} --profile auto --strict-models --output ${input.dagDraftPath}`,
|
|
47
|
+
reason: "source ready; DAG draft/run evidence not found",
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (input.dagDraftExists && !input.latestDagRun) {
|
|
51
|
+
return {
|
|
52
|
+
command: `npm run dev -- dag validate --dag ${input.dagDraftPath} --strict-models --strict-governance`,
|
|
53
|
+
reason: "DAG draft exists and needs validation/execution",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (input.latestDagRun && input.latestDagRun.lifecycle !== "completed") {
|
|
57
|
+
return {
|
|
58
|
+
command: `npm run dev -- dag status --run-id ${input.latestDagRun.runId}`,
|
|
59
|
+
reason: "DAG run exists but is not completed",
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (input.latestDagRun && input.promotionRequired && !input.promotionReady) {
|
|
63
|
+
return {
|
|
64
|
+
command: `npm run dev -- promote-run ${input.taskId} --run-id ${input.latestDagRun.runId}`,
|
|
65
|
+
reason: "completed run evidence needs promotion into task artifacts",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (!input.closeoutExists) {
|
|
69
|
+
return {
|
|
70
|
+
command: `npm run dev -- closeout task ${input.taskId}`,
|
|
71
|
+
reason: "promoted task evidence needs closeout",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
command: `npm run dev -- dag report --task ${input.taskId}`,
|
|
76
|
+
reason: "task has source, run evidence, promotion, and closeout records",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export async function buildTaskReadModel(repoRoot, taskId) {
|
|
80
|
+
const taskDir = getTaskDir(repoRoot, taskId);
|
|
81
|
+
const paths = getTaskPaths(repoRoot, taskId);
|
|
82
|
+
const legacyState = await getTaskStatus(repoRoot, taskId);
|
|
83
|
+
const requirementPath = path.join(paths.sourceDir, "需求.md");
|
|
84
|
+
const constraintPath = path.join(paths.sourceDir, "执行约束.md");
|
|
85
|
+
const missing = [];
|
|
86
|
+
if (!(await exists(requirementPath)))
|
|
87
|
+
missing.push(requirementPath);
|
|
88
|
+
const sourceReady = missing.length === 0;
|
|
89
|
+
const dagDraftPath = defaultDagDraftPath(taskId);
|
|
90
|
+
const dagDraftExists = await exists(dagDraftPath);
|
|
91
|
+
const dagRuns = await listRelatedDagRuns(repoRoot, taskId);
|
|
92
|
+
const latestDagRun = dagRuns.at(-1) ?? null;
|
|
93
|
+
const oneShotRuns = await queryCursorRuns(repoRoot, { taskId });
|
|
94
|
+
const hasCompletedRun = latestDagRun?.lifecycle === "completed" ||
|
|
95
|
+
oneShotRuns.some((run) => run.status === "completed");
|
|
96
|
+
const promotionReady = legacyState.artifacts.modifyLog && legacyState.artifacts.verifyResult;
|
|
97
|
+
const closeout = closeoutPath(repoRoot, taskId);
|
|
98
|
+
const closeoutExists = await exists(closeout);
|
|
99
|
+
const nextAction = deriveNextAction({
|
|
100
|
+
taskId,
|
|
101
|
+
sourceReady,
|
|
102
|
+
dagDraftPath,
|
|
103
|
+
dagDraftExists,
|
|
104
|
+
latestDagRun,
|
|
105
|
+
promotionRequired: hasCompletedRun,
|
|
106
|
+
promotionReady,
|
|
107
|
+
closeoutExists,
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
taskId,
|
|
111
|
+
taskDir,
|
|
112
|
+
sourceReadiness: {
|
|
113
|
+
ready: sourceReady,
|
|
114
|
+
missing,
|
|
115
|
+
requirementPath,
|
|
116
|
+
constraintPath,
|
|
117
|
+
},
|
|
118
|
+
dagDraft: {
|
|
119
|
+
path: dagDraftPath,
|
|
120
|
+
exists: dagDraftExists,
|
|
121
|
+
},
|
|
122
|
+
latestDagRun,
|
|
123
|
+
promotion: {
|
|
124
|
+
required: hasCompletedRun,
|
|
125
|
+
ready: promotionReady,
|
|
126
|
+
},
|
|
127
|
+
closeout: {
|
|
128
|
+
path: closeout,
|
|
129
|
+
exists: closeoutExists,
|
|
130
|
+
},
|
|
131
|
+
loopState: {
|
|
132
|
+
path: path.join(taskDir, "loop-state.json"),
|
|
133
|
+
exists: await exists(path.join(taskDir, "loop-state.json")),
|
|
134
|
+
},
|
|
135
|
+
legacyWorkflowState: {
|
|
136
|
+
status: legacyState.status,
|
|
137
|
+
currentStep: legacyState.currentStep,
|
|
138
|
+
completedSteps: legacyState.completedSteps,
|
|
139
|
+
},
|
|
140
|
+
runRefs: {
|
|
141
|
+
oneShotRuns: oneShotRuns.map((run) => ({
|
|
142
|
+
status: run.status,
|
|
143
|
+
logPath: run.logPath,
|
|
144
|
+
})),
|
|
145
|
+
dagRuns: dagRuns.map((run) => run.runId),
|
|
146
|
+
},
|
|
147
|
+
nextAction,
|
|
148
|
+
};
|
|
149
|
+
}
|