@tea-agent/loop-agent 0.8.0 → 0.10.0-alpha.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.
Files changed (188) hide show
  1. package/AGENTS.md +10 -0
  2. package/CHANGELOG.md +101 -1
  3. package/README.md +69 -5
  4. package/dist/application/dag/args.js +13 -16
  5. package/dist/application/dag/generate-task-dag.js +32 -2
  6. package/dist/application/dag/run-dag.js +1 -27
  7. package/dist/application/dag/validate-dag.js +2 -2
  8. package/dist/application/loop/run-action.js +0 -4
  9. package/dist/cli/command-definitions.js +7 -11
  10. package/dist/cli/program.js +9 -21
  11. package/dist/commands/cursor-prompt.js +42 -82
  12. package/dist/commands/dag-approve.js +36 -0
  13. package/dist/commands/dag-reconcile-run.js +118 -0
  14. package/dist/commands/delegate.js +75 -77
  15. package/dist/commands/doctor.js +0 -18
  16. package/dist/commands/init.js +60 -40
  17. package/dist/commands/instructions.js +7 -10
  18. package/dist/commands/loop.js +4 -20
  19. package/dist/executors/config-core.js +0 -51
  20. package/dist/executors/dag-pi-executor.js +1 -1
  21. package/dist/executors/dag.js +0 -1
  22. package/dist/executors/index.js +0 -2
  23. package/dist/executors/model-routing.js +9 -9
  24. package/dist/executors/shell-executor.js +75 -9
  25. package/dist/governance/checks.js +6 -3
  26. package/dist/governance/manifest-types.js +33 -2
  27. package/dist/infrastructure/harness/loop-action-store.js +0 -3
  28. package/dist/records/harvest.js +2 -23
  29. package/dist/records/one-shot-runs.js +1 -1
  30. package/dist/shared/artifacts-core.js +24 -5
  31. package/dist/shared/output-truncation.js +37 -0
  32. package/dist/shared/package-metadata.js +353 -0
  33. package/dist/shared/reference-context.js +48 -22
  34. package/dist/{executors/cursor-executor.js → sidecars/cursor-prompt/executor.js} +2 -42
  35. package/dist/sidecars/cursor-prompt/index.js +3 -0
  36. package/dist/sidecars/cursor-prompt/stream.js +121 -0
  37. package/dist/task/config-types.js +30 -13
  38. package/dist/task/delegate.js +9 -21
  39. package/dist/task/runtime.js +2 -3
  40. package/dist/worker/cli.js +243 -0
  41. package/dist/worker/closeout/apply.js +73 -0
  42. package/dist/worker/closeout/preview.js +30 -0
  43. package/dist/worker/delivery/final-verification.js +194 -0
  44. package/dist/worker/delivery/git-transaction.js +354 -0
  45. package/dist/worker/delivery/package.js +502 -0
  46. package/dist/worker/feature/decision-loader.js +68 -0
  47. package/dist/worker/feature/discover.js +14 -0
  48. package/dist/worker/feature/next-action.js +74 -0
  49. package/dist/worker/feature/reducer.js +133 -0
  50. package/dist/worker/feature/review.js +502 -0
  51. package/dist/worker/feature/run.js +365 -0
  52. package/dist/worker/feature/types.js +1 -0
  53. package/dist/worker/follow-up/approve.js +270 -0
  54. package/dist/worker/follow-up/factory.js +234 -0
  55. package/dist/worker/follow-up/paths.js +25 -0
  56. package/dist/worker/follow-up/policy.js +26 -0
  57. package/dist/worker/follow-up/schema.js +93 -0
  58. package/dist/worker/follow-up/store.js +96 -0
  59. package/dist/worker/loop-agent/loop-agent-client.js +345 -101
  60. package/dist/worker/metrics/projector.js +139 -0
  61. package/dist/worker/observability/read-model.js +282 -15
  62. package/dist/worker/observe/paths.js +17 -5
  63. package/dist/worker/observe/routes.js +78 -20
  64. package/dist/worker/observe/server.js +8 -6
  65. package/dist/worker/observe/static/app.js +1045 -177
  66. package/dist/worker/observe/static/index.html +70 -43
  67. package/dist/worker/observe/static/styles.css +553 -610
  68. package/dist/worker/pool/run-store.js +14 -2
  69. package/dist/worker/pool/validation.js +59 -0
  70. package/dist/worker/preflight.js +49 -1
  71. package/dist/worker/report/morning-report.js +41 -6
  72. package/dist/worker/run-task/run-task.js +23 -13
  73. package/dist/worker/runner/run-ready.js +89 -11
  74. package/dist/worker/task-spec/schema.js +0 -1
  75. package/dist/workflows/dag/convergence/controller.js +1 -1
  76. package/dist/workflows/dag/executor-registry.js +0 -2
  77. package/dist/workflows/dag/governance-profile.js +10 -0
  78. package/dist/workflows/dag/init-hybrid.js +601 -26
  79. package/dist/workflows/dag/lifecycle.js +146 -0
  80. package/dist/workflows/dag/node-execution.js +64 -7
  81. package/dist/workflows/dag/prompt.js +16 -0
  82. package/dist/workflows/dag/report.js +2 -0
  83. package/dist/workflows/dag/runner.js +176 -119
  84. package/dist/workflows/dag/scheduler.js +7 -2
  85. package/dist/workflows/dag/skill-snapshot.js +527 -0
  86. package/dist/workflows/dag/types.js +45 -9
  87. package/dist/workflows/dag/validate.js +5 -8
  88. package/dist/workflows/loop/actions/dag-action.js +0 -2
  89. package/dist/workflows/loop/actions/shared.js +1 -1
  90. package/dist/workflows/loop/actions.js +14 -31
  91. package/dist/workflows/loop/benchmark.js +1 -1
  92. package/dist/workflows/loop/index.js +1 -1
  93. package/dist/workflows/loop/policy/auto-policy.js +22 -14
  94. package/dist/workflows/loop/policy/path-patterns.js +13 -0
  95. package/docs/README.md +35 -12
  96. package/docs/agent-dag-recovery-playbook.md +1 -1
  97. package/docs/architecture/README.md +26 -0
  98. package/docs/architecture/dag-execution.md +134 -0
  99. package/docs/architecture/evolution.md +52 -0
  100. package/docs/architecture/facts-and-state.md +58 -0
  101. package/docs/architecture/runtime-boundaries.md +41 -15
  102. package/docs/architecture/system-overview.md +93 -0
  103. package/docs/architecture/worker-and-feature.md +81 -0
  104. package/docs/cursor-prompt-sidecar.md +36 -0
  105. package/docs/decisions/README.md +13 -1
  106. package/docs/design/README.md +39 -13
  107. package/docs/development-principles.md +1 -1
  108. package/docs/exec-plans/active/README.md +2 -2
  109. package/docs/exec-plans/completed/README.md +21 -0
  110. package/docs/feature-workflow.md +44 -4
  111. package/docs/init-surface.manifest.json +63 -1
  112. package/docs/loop-agent-harness.md +65 -3
  113. package/docs/progress/README.md +27 -0
  114. package/docs/reports/README.md +74 -5
  115. package/docs/skills/README.md +2 -1
  116. package/docs/skills/vetted-skill-registry.md +2 -1
  117. package/docs/templates/agent-dag-report.schema.json +4 -2
  118. package/docs/templates/agent-dag.base.json +0 -5
  119. package/docs/templates/agent-dag.final-verification.json +0 -5
  120. package/docs/templates/agent-dag.schema.json +1 -2
  121. package/docs/templates/agent-dag.supervised-implementation.json +1 -6
  122. package/docs/templates/backend-test-dag.generate-pytest.prompt.md +131 -0
  123. package/docs/templates/backend-test-dag.json +213 -0
  124. package/docs/templates/backend-test-dag.retrospect.prompt.md +128 -0
  125. package/docs/templates/backend-test-dag.review-cases.prompt.md +85 -0
  126. package/docs/templates/frontend-design-contract.md +33 -0
  127. package/docs/templates/frontend-task-constraints.md +25 -0
  128. package/docs/templates/frontend-task-requirement.md +61 -0
  129. package/docs/templates/harness.schema.json +8 -5
  130. package/docs/templates/hybrid-dag.json +1 -6
  131. package/docs/templates/init-evolution-review.md +4 -2
  132. package/docs/templates/interactive-ui-round2-experiment.md +1 -1
  133. package/docs/templates/product-line/task.yaml +0 -1
  134. package/docs/templates/worker-dogfood-evidence.md +28 -0
  135. package/docs/templates/worker-dogfood-setup.md +20 -0
  136. package/docs/verification-matrix.md +17 -0
  137. package/examples/decision-gate-agent-dag.json +87 -33
  138. package/examples/example-dag.json +0 -5
  139. package/examples/hybrid-loop-agent-dag.json +0 -5
  140. package/harness.json +6 -11
  141. package/package.json +22 -44
  142. package/scripts/check-product-line-docs.sh +10 -3
  143. package/scripts/check-task-pool-root.sh +1 -1
  144. package/skills/agent-worker/SKILL.md +37 -0
  145. package/skills/agent-worker/references/agent-worker-operator.md +43 -0
  146. package/skills/frontend-design-review/SKILL.md +59 -0
  147. package/skills/frontend-design-review/references/review-checklist.md +37 -0
  148. package/skills/frontend-implementation/SKILL.md +48 -0
  149. package/skills/frontend-implementation/references/code-standards.md +34 -0
  150. package/skills/frontend-implementation/references/design-spec.md +46 -0
  151. package/skills/frontend-implementation/references/node-contracts.md +32 -0
  152. package/skills/frontend-review/SKILL.md +53 -0
  153. package/skills/frontend-review/references/review-findings.md +42 -0
  154. package/skills/frontend-verification/SKILL.md +40 -0
  155. package/skills/frontend-verification/references/verification-checklist.md +56 -0
  156. package/skills/grill-me/SKILL.md +10 -0
  157. package/skills/grill-with-docs/SKILL.md +88 -0
  158. package/skills/grill-with-docs/adr-format.md +47 -0
  159. package/skills/grill-with-docs/context-format.md +60 -0
  160. package/skills/init-capability-evolution/SKILL.md +1 -0
  161. package/skills/loop-agent/SKILL.md +11 -9
  162. package/skills/loop-agent/references/command-reference.md +28 -15
  163. package/skills/loop-agent/references/docs-converge.md +126 -0
  164. package/skills/loop-agent/references/harness-policy.md +7 -7
  165. package/skills/loop-agent/references/hybrid-dag.md +13 -15
  166. package/skills/loop-agent/references/long-running-loop.md +4 -6
  167. package/skills/loop-agent/references/multi-worktree.md +6 -6
  168. package/skills/loop-agent/references/orchestrator-and-interventions.md +3 -3
  169. package/skills/loop-agent/references/pi-subagent-assisted-mode.md +14 -11
  170. package/skills/loop-agent/references/verification-and-failure-handling.md +8 -3
  171. package/skills/using-git-worktrees/SKILL.md +215 -0
  172. package/dist/commands/cursor-worker.js +0 -43
  173. package/dist/cursor-worker-entry.js +0 -8
  174. package/dist/executors/cursor-artifacts.js +0 -33
  175. package/dist/executors/cursor-execution-log.js +0 -81
  176. package/dist/executors/cursor-executor-artifacts.js +0 -134
  177. package/dist/executors/cursor-run.js +0 -115
  178. package/dist/executors/cursor-tool.js +0 -94
  179. package/dist/executors/cursor-worker-client.js +0 -223
  180. package/dist/executors/cursor-worker-protocol.js +0 -18
  181. package/dist/executors/cursor-worker-server.js +0 -54
  182. package/dist/executors/cursor-worker.js +0 -3
  183. package/dist/executors/cursor.js +0 -6
  184. package/dist/executors/dag-cursor-executor.js +0 -87
  185. package/dist/workflows/loop/actions/cursor-fix.js +0 -191
  186. package/dist/workflows/loop/policy/cursor-fix-policy.js +0 -31
  187. package/docs/cursor-executor-usage.md +0 -25
  188. package/docs/dynamic-workflow-dag-engine-roadmap.md +0 -1749
@@ -0,0 +1,74 @@
1
+ export function projectNextAction(input, status) {
2
+ const featureArgs = `--feature-dir ${quote(input.featureDir)} --repo ${quote(input.repoRoot)}`;
3
+ const resolvedFailures = new Set(input.resolvedFailureTaskIds ?? []);
4
+ if (input.projectionWarnings.length > 0 || !input.validationOk) {
5
+ return {
6
+ kind: "repair_projection",
7
+ label: "修复 Feature Packet 或运行事实后重新审阅",
8
+ ...(!input.validationOk
9
+ ? { command: `agent-worker task validate-feature ${quote(input.featureDir)}` }
10
+ : {}),
11
+ };
12
+ }
13
+ const actionCard = input.actionCards?.[0];
14
+ if (actionCard) {
15
+ return { kind: actionCard.action, label: actionCard.label, ...(actionCard.command ? { command: actionCard.command } : {}) };
16
+ }
17
+ const highRisk = input.tasks.find((task) => ["RiskyChange", "ContractMismatch", "SpecUnclear", "NeedsHuman"].includes(task.failureCategory ?? "") && !resolvedFailures.has(task.taskId));
18
+ if (highRisk) {
19
+ return {
20
+ kind: "resolve_high_risk_gate",
21
+ label: `人工审查 ${highRisk.taskId} 的 ${highRisk.failureCategory} Gate`,
22
+ };
23
+ }
24
+ const pendingFollowUp = input.pendingFollowUps?.[0];
25
+ if (pendingFollowUp) {
26
+ return {
27
+ kind: "approve_followup",
28
+ label: `批准 ${pendingFollowUp.followUpId}`,
29
+ command: `agent-worker feature approve-followup --feature-dir ${quote(input.featureDir)} --followup-id ${quote(pendingFollowUp.followUpId)} --repo ${quote(input.repoRoot)} --owner <owner>`,
30
+ };
31
+ }
32
+ const failed = input.tasks.find((task) => task.status === "Failed" && !resolvedFailures.has(task.taskId));
33
+ if (failed) {
34
+ if (failed.failureCategory === "EnvFailure") {
35
+ return {
36
+ kind: "retry_task",
37
+ label: `重试环境失败任务 ${failed.taskId}`,
38
+ command: `agent-worker task retry ${quote(failed.taskId)} --repo ${quote(input.repoRoot)}`,
39
+ };
40
+ }
41
+ return {
42
+ kind: "handle_failure",
43
+ label: `根据失败证据处理 ${failed.taskId};ProductBug 可生成并人工批准 Follow-up`,
44
+ };
45
+ }
46
+ const blocked = input.tasks.find((task) => ["Blocked", "HumanReview", "Abandoned"].includes(task.status ?? ""));
47
+ if (blocked) {
48
+ return {
49
+ kind: "resolve_human_gate",
50
+ label: `处理 ${blocked.taskId} 的人工 Gate 或阻塞原因`,
51
+ };
52
+ }
53
+ if (status === "ready") {
54
+ return {
55
+ kind: "run_feature",
56
+ label: "执行当前 Ready tasks",
57
+ command: `agent-worker batch run-ready ${featureArgs}`,
58
+ };
59
+ }
60
+ if (status === "awaiting_qa") {
61
+ return { kind: "complete_qa", label: "补齐 QA verdict 与 required AC 证据" };
62
+ }
63
+ if (status === "deliverable") {
64
+ return {
65
+ kind: "prepare_closeout",
66
+ label: "预览 Feature Closeout gates",
67
+ command: `agent-worker feature closeout ${featureArgs}`,
68
+ };
69
+ }
70
+ return null;
71
+ }
72
+ function quote(value) {
73
+ return JSON.stringify(value);
74
+ }
@@ -0,0 +1,133 @@
1
+ import { projectNextAction } from "./next-action.js";
2
+ const STATUS_LABELS = {
3
+ draft: "待准备",
4
+ ready: "可执行",
5
+ running: "执行中",
6
+ needs_action: "需处理",
7
+ awaiting_qa: "待验收",
8
+ deliverable: "可交付",
9
+ closed: "已关闭",
10
+ };
11
+ export function reduceFeature(input) {
12
+ const status = deriveStatus(input);
13
+ const readyTasks = input.tasks.filter((task) => isReady(task.taskId, input));
14
+ const blockingItems = [];
15
+ const resolvedFailures = new Set(input.resolvedFailureTaskIds ?? []);
16
+ for (const error of input.validationErrors) {
17
+ blockingItems.push({ type: "validation_error", message: error, evidence: [] });
18
+ }
19
+ for (const warning of input.projectionWarnings) {
20
+ blockingItems.push({ type: "projection_warning", message: warning, evidence: [] });
21
+ }
22
+ for (const followUp of input.pendingFollowUps ?? []) {
23
+ blockingItems.push({
24
+ type: "pending_follow_up",
25
+ taskId: followUp.parentTaskId,
26
+ followUpId: followUp.followUpId,
27
+ message: `${followUp.followUpId} is waiting for approval`,
28
+ evidence: [followUp.draftPath],
29
+ });
30
+ }
31
+ for (const card of input.actionCards ?? []) {
32
+ blockingItems.push({ type: "follow_up_action", taskId: card.parentTaskId, followUpId: card.followUpId, message: card.label, evidence: [card.draftPath] });
33
+ }
34
+ for (const task of input.tasks.filter((item) => ["Failed", "Blocked", "HumanReview", "Abandoned"].includes(item.status ?? "") &&
35
+ !(item.status === "Failed" && resolvedFailures.has(item.taskId)))) {
36
+ blockingItems.push({
37
+ type: task.status === "Failed"
38
+ ? "failed_task"
39
+ : task.status === "HumanReview"
40
+ ? "human_gate"
41
+ : task.status === "Abandoned"
42
+ ? "abandoned_task"
43
+ : "blocked_task",
44
+ taskId: task.taskId,
45
+ ...(task.failureCategory ? { failureCategory: task.failureCategory } : {}),
46
+ message: `${task.taskId} is ${task.status}`,
47
+ evidence: task.failureEvidence ?? [],
48
+ });
49
+ }
50
+ const required = input.acceptance.filter((item) => item.required);
51
+ return {
52
+ schemaVersion: 1,
53
+ featureId: input.featureId,
54
+ status,
55
+ statusLabel: STATUS_LABELS[status],
56
+ summary: {
57
+ tasksTotal: input.tasks.length,
58
+ tasksSucceeded: input.tasks.filter((task) => task.status === "Done").length,
59
+ tasksFailed: input.tasks.filter((task) => task.status === "Failed").length,
60
+ tasksReady: readyTasks.length,
61
+ tasksBlocked: input.tasks.filter((task) => task.status === "Blocked").length,
62
+ requiredAcTotal: required.length,
63
+ requiredAcCovered: required.filter((item) => item.status === "covered" || item.status === "waived").length,
64
+ },
65
+ riskSummary: {
66
+ high: (input.delivery?.riskSummary?.high ?? 0) + input.tasks.filter((task) => ["RiskyChange", "ContractMismatch", "SpecUnclear", "NeedsHuman"].includes(task.failureCategory ?? "")).length,
67
+ medium: (input.delivery?.riskSummary?.medium ?? 0) + input.tasks.filter((task) => task.status === "Failed" && !["RiskyChange", "ContractMismatch", "SpecUnclear", "NeedsHuman"].includes(task.failureCategory ?? "")).length,
68
+ low: (input.delivery?.riskSummary?.low ?? 0) + input.tasks.filter((task) => task.status === "Blocked").length,
69
+ },
70
+ blockingItems,
71
+ followUps: {
72
+ pending: input.pendingFollowUps ?? [],
73
+ actionCards: input.actionCards ?? [],
74
+ resolvedFailureTaskIds: input.resolvedFailureTaskIds ?? [],
75
+ },
76
+ tasks: input.tasks.map((task) => ({
77
+ taskId: task.taskId,
78
+ type: task.type,
79
+ status: task.status ?? (isReady(task.taskId, input) ? "Ready" : "Draft"),
80
+ })),
81
+ acceptanceCoverage: input.acceptance,
82
+ nextAction: projectNextAction(input, status),
83
+ alternativeActions: [],
84
+ evidence: {
85
+ morningReport: input.morningReport ?? null,
86
+ observeSnapshot: input.observeSnapshot ?? null,
87
+ delivery: input.delivery?.path ?? null,
88
+ closeout: input.closeout?.path ?? null,
89
+ },
90
+ projectionWarnings: [...input.projectionWarnings],
91
+ };
92
+ }
93
+ function deriveStatus(input) {
94
+ if (!input.validationOk)
95
+ return "draft";
96
+ if (input.projectionWarnings.length > 0)
97
+ return "needs_action";
98
+ if ((input.pendingFollowUps?.length ?? 0) > 0)
99
+ return "needs_action";
100
+ if ((input.actionCards?.length ?? 0) > 0)
101
+ return "needs_action";
102
+ const requiredComplete = input.acceptance
103
+ .filter((item) => item.required)
104
+ .every((item) => item.status === "covered" || item.status === "waived");
105
+ const resolvedFailures = new Set(input.resolvedFailureTaskIds ?? []);
106
+ const allTasksDone = input.tasks.length > 0 && input.tasks.every((task) => task.status === "Done" || (task.status === "Failed" && resolvedFailures.has(task.taskId)));
107
+ if (input.closeout?.applied &&
108
+ input.closeout.valid &&
109
+ input.delivery?.valid &&
110
+ requiredComplete &&
111
+ allTasksDone)
112
+ return "closed";
113
+ if (input.tasks.some((task) => ["Failed", "Blocked", "HumanReview", "Abandoned"].includes(task.status ?? "") &&
114
+ !(task.status === "Failed" && (input.resolvedFailureTaskIds ?? []).includes(task.taskId)))) {
115
+ return "needs_action";
116
+ }
117
+ if (input.tasks.some((task) => ["Queued", "Running", "AgentCompleted", "VerificationRunning"].includes(task.status ?? "")))
118
+ return "running";
119
+ if (input.tasks.some((task) => isReady(task.taskId, input)))
120
+ return "ready";
121
+ if (allTasksDone && requiredComplete && input.delivery?.valid) {
122
+ return "deliverable";
123
+ }
124
+ if (allTasksDone)
125
+ return "awaiting_qa";
126
+ return "draft";
127
+ }
128
+ function isReady(taskId, input) {
129
+ const task = input.tasks.find((item) => item.taskId === taskId);
130
+ if (!task || task.status)
131
+ return task?.status === "Ready";
132
+ return task.dependsOn.every((dependencyId) => input.tasks.find((item) => item.taskId === dependencyId)?.status === "Done");
133
+ }