@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.
Files changed (264) hide show
  1. package/AGENTS.md +121 -0
  2. package/CHANGELOG.md +37 -0
  3. package/README.md +144 -0
  4. package/bin/loop-agent.js +21 -0
  5. package/dist/adapters/aimax.js +91 -0
  6. package/dist/adapters/context.js +32 -0
  7. package/dist/adapters/index.js +28 -0
  8. package/dist/adapters/loop-agent.js +98 -0
  9. package/dist/adapters/types.js +1 -0
  10. package/dist/cli/catalog.js +259 -0
  11. package/dist/cli/help.js +55 -0
  12. package/dist/cli/index.js +3 -0
  13. package/dist/cli/program.js +505 -0
  14. package/dist/cli.js +12 -0
  15. package/dist/commands/closeout.js +13 -0
  16. package/dist/commands/coverage-audit.js +14 -0
  17. package/dist/commands/cursor-prompt.js +222 -0
  18. package/dist/commands/cursor-worker.js +43 -0
  19. package/dist/commands/dag-approve.js +102 -0
  20. package/dist/commands/dag-final-verification.js +76 -0
  21. package/dist/commands/dag-init-hybrid.js +56 -0
  22. package/dist/commands/dag-reconcile-tasks.js +51 -0
  23. package/dist/commands/dag-reject.js +91 -0
  24. package/dist/commands/dag-report.js +177 -0
  25. package/dist/commands/dag-resume.js +34 -0
  26. package/dist/commands/dag-run-task.js +470 -0
  27. package/dist/commands/dag-validate.js +186 -0
  28. package/dist/commands/dag-workflow-compile.js +91 -0
  29. package/dist/commands/dag-workflow-plan.js +130 -0
  30. package/dist/commands/dag-workflow-validate.js +66 -0
  31. package/dist/commands/delegate.js +132 -0
  32. package/dist/commands/docs-archive.js +5 -0
  33. package/dist/commands/docs-audit.js +5 -0
  34. package/dist/commands/doctor.js +50 -0
  35. package/dist/commands/goal.js +92 -0
  36. package/dist/commands/handoff-check.js +5 -0
  37. package/dist/commands/harvest.js +44 -0
  38. package/dist/commands/inspect.js +11 -0
  39. package/dist/commands/instructions.js +195 -0
  40. package/dist/commands/knowledge.js +64 -0
  41. package/dist/commands/loop-benchmark.js +72 -0
  42. package/dist/commands/loop.js +241 -0
  43. package/dist/commands/new-task.js +5 -0
  44. package/dist/commands/pi-prompt.js +181 -0
  45. package/dist/commands/pi-reuse-benchmark.js +153 -0
  46. package/dist/commands/plan-list.js +5 -0
  47. package/dist/commands/promote-run.js +29 -0
  48. package/dist/commands/reference-index.js +16 -0
  49. package/dist/commands/run-dag.js +184 -0
  50. package/dist/commands/spine.js +38 -0
  51. package/dist/commands/stats.js +84 -0
  52. package/dist/commands/status.js +56 -0
  53. package/dist/commands/study-init.js +192 -0
  54. package/dist/commands/workflow.js +259 -0
  55. package/dist/commands/worktree-create.js +31 -0
  56. package/dist/commands/worktree-list.js +5 -0
  57. package/dist/commands/worktree-remove.js +26 -0
  58. package/dist/cursor-worker-entry.js +8 -0
  59. package/dist/executors/config-core.js +55 -0
  60. package/dist/executors/config.js +2 -0
  61. package/dist/executors/cursor-artifacts.js +33 -0
  62. package/dist/executors/cursor-execution-log.js +81 -0
  63. package/dist/executors/cursor-executor-artifacts.js +135 -0
  64. package/dist/executors/cursor-executor.js +468 -0
  65. package/dist/executors/cursor-run.js +115 -0
  66. package/dist/executors/cursor-tool.js +94 -0
  67. package/dist/executors/cursor-worker-client.js +213 -0
  68. package/dist/executors/cursor-worker-protocol.js +18 -0
  69. package/dist/executors/cursor-worker-server.js +54 -0
  70. package/dist/executors/cursor-worker.js +3 -0
  71. package/dist/executors/cursor.js +6 -0
  72. package/dist/executors/dag-cursor-executor.js +88 -0
  73. package/dist/executors/dag-pi-executor.js +322 -0
  74. package/dist/executors/dag-static-executor.js +45 -0
  75. package/dist/executors/dag.js +4 -0
  76. package/dist/executors/index.js +8 -0
  77. package/dist/executors/model-routing.js +60 -0
  78. package/dist/executors/pi-event-serializer.js +43 -0
  79. package/dist/executors/pi-executor.js +606 -0
  80. package/dist/executors/pi-reuse-benchmark.js +316 -0
  81. package/dist/executors/pi-runtime-reuse.js +29 -0
  82. package/dist/executors/pi-sdk-executor.js +255 -0
  83. package/dist/executors/pi-sdk.js +1 -0
  84. package/dist/executors/pi.js +3 -0
  85. package/dist/executors/shell-executor.js +300 -0
  86. package/dist/executors/shell-presets.js +47 -0
  87. package/dist/executors/shell-verification.js +251 -0
  88. package/dist/executors/shell-write-guard.js +126 -0
  89. package/dist/executors/shell.js +3 -0
  90. package/dist/executors/static.js +1 -0
  91. package/dist/governance/checks.js +434 -0
  92. package/dist/governance/harness.js +9 -0
  93. package/dist/governance/index.js +3 -0
  94. package/dist/governance/manifest-types.js +128 -0
  95. package/dist/governance/manifest.js +2 -0
  96. package/dist/governance/path-guard.js +69 -0
  97. package/dist/governance/path-guards.js +2 -0
  98. package/dist/governance/profiles.js +3 -0
  99. package/dist/governance/requirement-coverage.js +425 -0
  100. package/dist/governance/skill-safety.js +135 -0
  101. package/dist/governance/spine-audit.js +152 -0
  102. package/dist/records/closeout.js +2 -0
  103. package/dist/records/harvest.js +236 -0
  104. package/dist/records/index.js +3 -0
  105. package/dist/records/one-shot-runs.js +421 -0
  106. package/dist/records/promotion.js +199 -0
  107. package/dist/shared/artifacts-core.js +88 -0
  108. package/dist/shared/artifacts.js +2 -0
  109. package/dist/shared/context-files.js +32 -0
  110. package/dist/shared/context.js +2 -0
  111. package/dist/shared/copy-dir.js +17 -0
  112. package/dist/shared/git-progress.js +165 -0
  113. package/dist/shared/index.js +5 -0
  114. package/dist/shared/logger.js +23 -0
  115. package/dist/shared/one-shot-prompt-args.js +98 -0
  116. package/dist/shared/path-refs.js +31 -0
  117. package/dist/shared/prompts.js +26 -0
  118. package/dist/shared/reference-context.js +238 -0
  119. package/dist/shared/timeout-policy.js +19 -0
  120. package/dist/shared/timeout.js +1 -0
  121. package/dist/shared/types.js +5 -0
  122. package/dist/task/config-types.js +97 -0
  123. package/dist/task/config.js +2 -0
  124. package/dist/task/delegate.js +220 -0
  125. package/dist/task/goal-audit.js +51 -0
  126. package/dist/task/goal-policy.js +8 -0
  127. package/dist/task/goal.js +3 -0
  128. package/dist/task/ids.js +1 -0
  129. package/dist/task/index.js +9 -0
  130. package/dist/task/lifecycle.js +1 -0
  131. package/dist/task/paths.js +1 -0
  132. package/dist/task/read-model.js +149 -0
  133. package/dist/task/runtime.js +699 -0
  134. package/dist/task/source-state.js +1 -0
  135. package/dist/task/state.js +55 -0
  136. package/dist/task/subagent-guidance.js +1 -0
  137. package/dist/task/workflow-state-types.js +92 -0
  138. package/dist/task/worktree-cleanup.js +140 -0
  139. package/dist/task/worktree.js +171 -0
  140. package/dist/workflows/dag/authoring.js +8 -0
  141. package/dist/workflows/dag/authority-surface.js +138 -0
  142. package/dist/workflows/dag/canvas-observer.js +474 -0
  143. package/dist/workflows/dag/decision-envelope.js +502 -0
  144. package/dist/workflows/dag/decision-evidence.js +153 -0
  145. package/dist/workflows/dag/decision-gates.js +1 -0
  146. package/dist/workflows/dag/executor-registry.js +25 -0
  147. package/dist/workflows/dag/facts.js +4 -0
  148. package/dist/workflows/dag/failure-category.js +111 -0
  149. package/dist/workflows/dag/final-verification.js +180 -0
  150. package/dist/workflows/dag/governance-constants.js +5 -0
  151. package/dist/workflows/dag/governance-profile.js +405 -0
  152. package/dist/workflows/dag/index.js +6 -0
  153. package/dist/workflows/dag/init-hybrid.js +855 -0
  154. package/dist/workflows/dag/knowledge-curator.js +162 -0
  155. package/dist/workflows/dag/lifecycle.js +484 -0
  156. package/dist/workflows/dag/prompt-source.js +88 -0
  157. package/dist/workflows/dag/prompt.js +130 -0
  158. package/dist/workflows/dag/reconcile-tasks.js +404 -0
  159. package/dist/workflows/dag/recovery-recommendation.js +226 -0
  160. package/dist/workflows/dag/repair-artifact.js +136 -0
  161. package/dist/workflows/dag/report.js +1019 -0
  162. package/dist/workflows/dag/runner.js +1677 -0
  163. package/dist/workflows/dag/runtime.js +5 -0
  164. package/dist/workflows/dag/skill-instructions.js +471 -0
  165. package/dist/workflows/dag/skills.js +41 -0
  166. package/dist/workflows/dag/spec.js +3 -0
  167. package/dist/workflows/dag/topo.js +30 -0
  168. package/dist/workflows/dag/types.js +275 -0
  169. package/dist/workflows/dag/upstream-artifacts.js +95 -0
  170. package/dist/workflows/dag/validate.js +527 -0
  171. package/dist/workflows/dynamic/artifacts.js +65 -0
  172. package/dist/workflows/dynamic/compile.js +360 -0
  173. package/dist/workflows/dynamic/compileTypes.js +1 -0
  174. package/dist/workflows/dynamic/errors.js +5 -0
  175. package/dist/workflows/dynamic/index.js +7 -0
  176. package/dist/workflows/dynamic/profiles.js +156 -0
  177. package/dist/workflows/dynamic/spec.js +114 -0
  178. package/dist/workflows/dynamic/validate.js +275 -0
  179. package/dist/workflows/loop/actions.js +1334 -0
  180. package/dist/workflows/loop/benchmark.js +510 -0
  181. package/dist/workflows/loop/closeout.js +134 -0
  182. package/dist/workflows/loop/context.js +48 -0
  183. package/dist/workflows/loop/events.js +25 -0
  184. package/dist/workflows/loop/hash.js +32 -0
  185. package/dist/workflows/loop/index.js +8 -0
  186. package/dist/workflows/loop/paths.js +17 -0
  187. package/dist/workflows/loop/rounds.js +81 -0
  188. package/dist/workflows/loop/signals.js +55 -0
  189. package/dist/workflows/loop/state.js +116 -0
  190. package/dist/workflows/loop/templates.js +54 -0
  191. package/dist/workflows/loop/types.js +28 -0
  192. package/docs/README.md +62 -0
  193. package/docs/agent-dag-recovery-playbook.md +158 -0
  194. package/docs/agent-dag-runner.md +40 -0
  195. package/docs/cursor-executor-usage.md +25 -0
  196. package/docs/decisions/README.md +3 -0
  197. package/docs/design/README.md +36 -0
  198. package/docs/development-principles.md +71 -0
  199. package/docs/dynamic-workflow-dag-engine-roadmap.md +1749 -0
  200. package/docs/exec-plans/README.md +6 -0
  201. package/docs/exec-plans/active/README.md +5 -0
  202. package/docs/exec-plans/completed/README.md +5 -0
  203. package/docs/feature-workflow.md +184 -0
  204. package/docs/harness-methodology-debugging.md +153 -0
  205. package/docs/harness-methodology-tdd.md +130 -0
  206. package/docs/harness-methodology-verification.md +27 -0
  207. package/docs/loop-agent-harness.md +42 -0
  208. package/docs/progress/README.md +3 -0
  209. package/docs/reports/README.md +3 -0
  210. package/docs/templates/adr.md +60 -0
  211. package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -0
  212. package/docs/templates/agent-dag-decision-envelope.schema.json +213 -0
  213. package/docs/templates/agent-dag-decision-gate-dogfood-report.md +117 -0
  214. package/docs/templates/agent-dag-decision-gate.prompt.md +246 -0
  215. package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -0
  216. package/docs/templates/agent-dag-report.schema.json +423 -0
  217. package/docs/templates/agent-dag-review-verdict.prompt.md +68 -0
  218. package/docs/templates/agent-dag.base.json +195 -0
  219. package/docs/templates/agent-dag.final-verification.json +190 -0
  220. package/docs/templates/agent-dag.schema.json +316 -0
  221. package/docs/templates/agent-dag.supervised-implementation.json +500 -0
  222. package/docs/templates/exec-plan.md +64 -0
  223. package/docs/templates/feature-spec.md +53 -0
  224. package/docs/templates/hybrid-dag.json +193 -0
  225. package/docs/templates/progress-log.md +17 -0
  226. package/docs/templates/project-start-checklist.md +9 -0
  227. package/docs/templates/qa-report.md +42 -0
  228. package/docs/templates/sprint-contract.md +29 -0
  229. package/docs/verification-matrix.md +30 -0
  230. package/examples/decision-gate-agent-dag.json +123 -0
  231. package/examples/example-dag.json +51 -0
  232. package/examples/hybrid-loop-agent-dag.json +194 -0
  233. package/harness.json +92 -0
  234. package/package.json +61 -0
  235. package/skills/ai-engineering-context/SKILL.md +48 -0
  236. package/skills/loop-agent/SKILL.md +260 -0
  237. package/skills/loop-agent/references/README.md +63 -0
  238. package/skills/loop-agent/references/command-reference.md +315 -0
  239. package/skills/loop-agent/references/harness-policy.md +258 -0
  240. package/skills/loop-agent/references/hybrid-dag.md +216 -0
  241. package/skills/loop-agent/references/learned/README.md +21 -0
  242. package/skills/loop-agent/references/model-routing.md +36 -0
  243. package/skills/loop-agent/references/multi-worktree.md +54 -0
  244. package/skills/loop-agent/references/one-shot-runs.md +85 -0
  245. package/skills/loop-agent/references/orchestrator-and-interventions.md +169 -0
  246. package/skills/loop-agent/references/pi-prompt.md +23 -0
  247. package/skills/loop-agent/references/pi-subagent-assisted-mode.md +83 -0
  248. package/skills/loop-agent/references/post-implementation-and-patterns.md +44 -0
  249. package/skills/loop-agent/references/task-workflow.md +84 -0
  250. package/skills/loop-agent/references/verification-and-failure-handling.md +74 -0
  251. package/skills/requesting-code-review/SKILL.md +101 -0
  252. package/skills/requesting-code-review/code-reviewer.md +168 -0
  253. package/skills/systematic-debugging/CREATION-LOG.md +119 -0
  254. package/skills/systematic-debugging/SKILL.md +296 -0
  255. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  256. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  257. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  258. package/skills/systematic-debugging/find-polluter.sh +63 -0
  259. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  260. package/skills/systematic-debugging/test-academic.md +14 -0
  261. package/skills/systematic-debugging/test-pressure-1.md +58 -0
  262. package/skills/systematic-debugging/test-pressure-2.md +68 -0
  263. package/skills/systematic-debugging/test-pressure-3.md +69 -0
  264. package/skills/verification-before-completion/SKILL.md +154 -0
@@ -0,0 +1,6 @@
1
+ # Execution Plans
2
+
3
+ - `active/README.md` lists currently active plans.
4
+ - `completed/README.md` lists completed plans.
5
+
6
+ Use an execution plan for changes that affect multiple files, public command behavior, or repository governance.
@@ -0,0 +1,5 @@
1
+ # Active Execution Plans
2
+
3
+ Use this directory for execution plans that are currently in progress.
4
+
5
+ Source repositories may keep concrete active plan files next to this README. The npm package carries this README as a directory contract and does not copy loop-agent source-history active plans; target repositories generate their own active plans.
@@ -0,0 +1,5 @@
1
+ # Completed Execution Plans
2
+
3
+ Completed plans are moved here after their implementation and verification finish.
4
+
5
+ The npm package carries this README as a directory contract. Concrete completed plans are target-repository history and are not copied from loop-agent's source history.
@@ -0,0 +1,184 @@
1
+ # Feature Workflow
2
+
3
+ This document separates two layers:
4
+
5
+ - Session governance: how the supervising human/agent should structure a work session.
6
+ - Runtime workflows: what the code actually executes under `src/workflows/`.
7
+
8
+ ## Default Session Protocol
9
+
10
+ 1. Orient: read `README.md`, `harness.json`, and this docs index.
11
+ 2. Select: choose one bounded work block.
12
+ 3. Contract: state deliverables, non-goals, completion criteria, verification commands, and failure conditions.
13
+ 4. Implement: make the smallest coherent change and update required docs, scripts, and tests.
14
+ 5. Verify: run commands from `verification-matrix.md`; use fresh output for any completion claim.
15
+ 6. Handoff: record evidence in `docs/progress/`, `docs/reports/`, an exec plan, or an ADR when useful.
16
+
17
+ ## Orient
18
+
19
+ Start by understanding the current system rather than assuming absence:
20
+
21
+ - read the repository entrypoints listed in `harness.json`
22
+ - check `git status --short --branch` and recent commits
23
+ - search existing source, tests, scripts, docs, and templates before adding new structure
24
+ - run the smallest baseline check if the task depends on a healthy baseline
25
+ - read methodology docs when the task involves TDD, verification claims, or debugging
26
+
27
+ If the baseline is already broken, record the failing command and decide whether the current work block is to repair the baseline or to proceed with a clearly scoped known failure.
28
+
29
+ ## Select
30
+
31
+ Keep a work block narrow enough to verify. Avoid combining unrelated refactors, features, and documentation migrations.
32
+
33
+ A selected block should have:
34
+
35
+ - a single user-visible or maintainer-visible outcome
36
+ - explicit allowed paths when delegating write work
37
+ - known non-goals
38
+ - a verification command that can prove the result
39
+
40
+ ## Contract
41
+
42
+ For non-trivial work, write or update an execution plan, sprint contract, progress log, or issue-sized note before implementation. The contract should state:
43
+
44
+ - deliverables
45
+ - non-goals
46
+ - acceptance criteria
47
+ - verification commands
48
+ - failure conditions
49
+ - expected artifacts to update
50
+
51
+ For bug fixes, the contract should include the reproduction path and the regression test or smoke check that proves the fix.
52
+
53
+ ## Implement
54
+
55
+ Make the smallest coherent change that satisfies the contract.
56
+
57
+ - Prefer existing helpers and directory boundaries.
58
+ - Update tests for behavior changes.
59
+ - Update docs and examples for workflow or command changes.
60
+ - Update `harness.json`, check scripts, or templates for governance changes.
61
+ - Do not submit placeholder implementations as completed work.
62
+ - When a repeated constraint appears, promote it into a durable artifact.
63
+
64
+ ## Verify
65
+
66
+ Verification is the completion authority.
67
+
68
+ - Use `docs/verification-matrix.md` to choose the narrowest proving command.
69
+ - Run the full command fresh.
70
+ - Read the exit code and output.
71
+ - Fix failures or report the exact failing state.
72
+ - Do not claim completion from stale output or partial checks.
73
+
74
+ ## Agent DAG First
75
+
76
+ For complex implementation work, prefer the DAG workflow:
77
+
78
+ ```bash
79
+ loop-agent new-task <task-id> "Task title"
80
+ loop-agent dag run-task <task-id> --profile auto --strict-models --output <temp-dir>/<task-id>-dag.json
81
+ loop-agent dag validate --dag <temp-dir>/<task-id>-dag.json --strict-models --strict-governance
82
+ loop-agent run-dag --dag <temp-dir>/<task-id>-dag.json --cwd .
83
+ ```
84
+
85
+ `<temp-dir>` means the platform-native temp directory. Use native paths for actual file operations on macOS and Windows; use `/` only for stable repo refs, JSON/Markdown evidence refs, and glob conventions.
86
+
87
+ This is not a linear OS-CIVH runtime state machine. In code, DAG has three command phases:
88
+
89
+ 1. `dag run-task` loads `.harness/tasks/<task-id>/source/需求.md`, optional `执行约束.md`, `task.json`, and adapter verification commands, then writes a DAG spec.
90
+ 2. `dag validate` validates schema, dependencies, governance profile, write boundaries, model routing, and shell verification metadata.
91
+ 3. `run-dag` loads the DAG, topologically sorts tasks into ranks, executes runnable nodes with bounded concurrency, persists `.harness/dag-runs/<lifecycle>/<run-id>/`, and transfers the run to `completed` or `paused`.
92
+
93
+ The standard generated hybrid DAG defaults to no-Cursor execution:
94
+
95
+ ```text
96
+ contract-pi
97
+ -> scout-src + scout-tests
98
+ -> plan-pi
99
+ -> implement-pi
100
+ -> verify-pi
101
+ -> closeout-pi
102
+ ```
103
+
104
+ `implement-pi` uses `executor: "pi"` with `toolProfile: "write"`. When `harness.json` explicitly disables Pi and enables Cursor, the implementation and repair writer nodes use `implement-cursor` / `repair-cursor` instead.
105
+
106
+ The review-gated template inserts:
107
+
108
+ ```text
109
+ verify-pi -> review-pi -> review-gate-shell -> closeout-pi
110
+ ```
111
+
112
+ The supervised template adds write-set audit, soft/hard shell verification, process supervision, bounded repair, decision gates, and optional convergence retry passes around the implementation path.
113
+
114
+ Source references:
115
+
116
+ - `src/commands/dag-run-task.ts`
117
+ - `src/commands/dag-validate.ts`
118
+ - `src/commands/run-dag.ts`
119
+ - `src/workflows/dag/init-hybrid.ts`
120
+ - `src/workflows/dag/runner.ts`
121
+
122
+ The supervising agent remains responsible for:
123
+
124
+ - writing the contract
125
+ - bounding allowed and forbidden paths
126
+ - reviewing DAG/writeSet scope
127
+ - selecting verification commands
128
+ - recording handoff evidence
129
+
130
+ ## Removed Sequential Workflow
131
+
132
+ The historical Level 1 sequential command surface has been removed from the public workflow. Do not use `loop-agent run analyze|plan|spec|implement|verify|retrospective|auto|loop|continue|study` for new work.
133
+
134
+ Use the DAG path instead:
135
+
136
+ ```bash
137
+ loop-agent new-task <task-id> "Task title"
138
+ loop-agent dag run-task <task-id> --profile auto --strict-models --output <temp-dir>/<task-id>-dag.json
139
+ loop-agent dag validate --dag <temp-dir>/<task-id>-dag.json --strict-models --strict-governance
140
+ loop-agent run-dag --dag <temp-dir>/<task-id>-dag.json --cwd .
141
+ ```
142
+
143
+ Legacy `.harness/tasks/<task-id>/.workflow_state.json` files may still be read for compatibility until task status is fully migrated to the DAG-oriented read model. They are not the authority for new task completion.
144
+
145
+ ## Outer Loop Runtime
146
+
147
+ The `loop` command is a long-running task-control layer, not the same thing as the session governance protocol. It records rounds and signals, can run shell verification, Pi review, Cursor fixes, or DAG actions, and can choose the next automatic action.
148
+
149
+ Supported loop actions are:
150
+
151
+ - `shell-verify`
152
+ - `pi-review`
153
+ - `cursor-fix`
154
+ - `dag`
155
+ - `record-round`
156
+ - `add-signal`
157
+ - `closeout`
158
+
159
+ Source references:
160
+
161
+ - `src/commands/loop.ts`
162
+ - `src/workflows/loop/actions.ts`
163
+ - `src/workflows/loop/state.ts`
164
+ - `src/workflows/loop/rounds.ts`
165
+
166
+ ## Debugging And TDD
167
+
168
+ Use the methodology docs when the task demands it:
169
+
170
+ - behavior changes and bug fixes: `docs/harness-methodology-tdd.md`
171
+ - completion or handoff claims: `docs/harness-methodology-verification.md`
172
+ - failures and unexpected behavior: `docs/harness-methodology-debugging.md`
173
+
174
+ ## Handoff
175
+
176
+ A handoff should state:
177
+
178
+ - what changed
179
+ - what was intentionally left out
180
+ - which verification commands ran
181
+ - whether contracts, docs, tests, or scripts were affected
182
+ - any remaining risks or follow-up work
183
+
184
+ For substantial work, update `docs/progress/`, `docs/reports/`, the active exec plan, or `docs/decisions/` so the next session can resume without relying on chat history.
@@ -0,0 +1,153 @@
1
+ # Harness Methodology: Systematic Debugging
2
+
3
+ 从 Superpowers `systematic-debugging` skill 中提取的调试方法,适配本仓库 harness 工作流。
4
+
5
+ ## Iron Law
6
+
7
+ ```
8
+ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
9
+ ```
10
+
11
+ 没有完成 Phase 1(根因调查),就不能提出任何修复方案。修症状 = 失败。
12
+
13
+ ## 何时使用
14
+
15
+ 适用于任何技术问题:
16
+ - 测试失败
17
+ - 生产 bug
18
+ - 意外行为
19
+ - 性能问题
20
+ - 构建/集成失败
21
+
22
+ **尤其要在以下情况使用:**
23
+ - 时间压力下(紧急情况最容易让人猜)
24
+ - "一个快速修复"看起来很明显
25
+ - 已经试过多次修复
26
+ - 上一个修复没奏效
27
+ - 不完全理解问题
28
+
29
+ ## 四阶段流程
30
+
31
+ 每个阶段必须完成才能进入下一个。
32
+
33
+ ### Phase 1:根因调查
34
+
35
+ **在尝试任何修复之前:**
36
+
37
+ 1. **仔细读错误信息**
38
+ - 不要跳过 error 和 warning
39
+ - 错误信息常常包含精确的解决方案
40
+ - 完整读 stack trace
41
+ - 记下文件名、行号、错误码
42
+
43
+ 2. **稳定复现**
44
+ - 能可靠触发吗?
45
+ - 精确步骤是什么?
46
+ - 每次都发生?
47
+ - 如果不能复现 → 收集更多数据,不要猜
48
+
49
+ 3. **检查最近变更**
50
+ - 什么改动可能导致这个问题?
51
+ - `git diff`、最近提交
52
+ - 新依赖、配置变更
53
+ - 环境差异
54
+
55
+ 4. **多组件系统:收集跨层证据**
56
+
57
+ 当系统涉及多个组件(CI → build → sign, API → service → DB):
58
+ ```
59
+ 对每个组件边界:
60
+ - 记录进入组件的数据
61
+ - 记录离开组件的数据
62
+ - 验证环境/配置传播
63
+ - 检查每层状态
64
+
65
+ 跑一次收集证据 → 分析证据确定失败组件 → 针对该组件调查
66
+ ```
67
+
68
+ 5. **追踪数据流**
69
+
70
+ 当错误在深层调用栈中:
71
+ - 坏值从哪里来?
72
+ - 谁用坏值调用了这里?
73
+ - 持续向上追踪直到源头
74
+ - 在源头修复,不在症状处修复
75
+
76
+ ### Phase 2:模式分析
77
+
78
+ 1. **找工作中的例子** — 在同一个代码库里定位相似的工作代码
79
+ 2. **对照参考实现** — 完整阅读参考实现,不要跳读
80
+ 3. **识别差异** — 列出工作和失败之间的每一项差异,再小也不假设"这不重要"
81
+ 4. **理解依赖** — 需要哪些其他组件、设置、配置、假设?
82
+
83
+ ### Phase 3:假设与测试
84
+
85
+ 1. **形成单一假设** — "我认为 X 是根因,因为 Y"
86
+ 2. **最小测试** — 做最小的改动来测试假设,一次只变一个变量
87
+ 3. **验证后再继续** — 成功了?→ Phase 4。没成功?→ 形成新假设。不要在原假设上叠加更多修复
88
+
89
+ ### Phase 4:实现
90
+
91
+ 1. **创建失败测试用例** — 遵循 RED-GREEN-REFACTOR(见 `docs/harness-methodology-tdd.md`)
92
+ 2. **实现单一修复** — 解决已识别的根因,一次一个改动,不顺手重构
93
+ 3. **验证修复** — 测试通过?其他测试没坏?问题真的解决了?
94
+ 4. **如果修复无效**:
95
+ - 尝试了几个修复?
96
+ - < 3 个 → 回到 Phase 1 重新分析
97
+ - **≥ 3 个 → 停止,质疑架构(Phase 4.5)**
98
+
99
+ ### Phase 4.5:质疑架构
100
+
101
+ **以下模式表明架构问题:**
102
+ - 每次修复暴露新的共享状态/耦合/不同位置的问题
103
+ - 修复需要"大规模重构"才能实现
104
+ - 每次修复在其他地方产生新症状
105
+
106
+ **停止并质疑基础:**
107
+ - 这个模式从根本上正确吗?
108
+ - 我们是否在"靠惯性坚持它"?
109
+ - 是否应该重构架构,而不是继续修症状?
110
+
111
+ 在尝试更多修复之前讨论。
112
+
113
+ ## Red Flags:停止并回到 Phase 1
114
+
115
+ 如果你发现自己这样想:
116
+ - "先快速修一下,后面再调查"
117
+ - "试试改 X 看看行不行"
118
+ - "一次改多个东西然后跑测试"
119
+ - "跳过测试,手工验证就行"
120
+ - "大概就是 X 的问题,直接修吧"
121
+ - "不太确定但可能有用"
122
+ - "再试一个修复"(已经试了 2+ 次)
123
+
124
+ **以上任何一种 → 停止。回到 Phase 1。**
125
+
126
+ ## 和 Harness 工作流的对齐
127
+
128
+ | 调试阶段 | Harness 步骤 |
129
+ |---------|-------------|
130
+ | Phase 1:根因调查 | Baseline:先验证当前基线,确认 bug 是可复现的 |
131
+ | Phase 2:模式分析 | Orient:读相关代码、文档、测试,找参考 |
132
+ | Phase 3:假设测试 | Contract:写清修复假设和验证方法 |
133
+ | Phase 4:实现 | Implement → Verify(TDD:先写失败测试) |
134
+ | Phase 4.5:质疑架构 | 可能需要新的 exec plan |
135
+
136
+ ## 快速参考
137
+
138
+ | 阶段 | 关键活动 | 成功标准 |
139
+ |------|---------|---------|
140
+ | 1. 根因 | 读错误、复现、查变更、收集证据 | 理解 WHAT 和 WHY |
141
+ | 2. 模式 | 找工作中的例子、对比 | 识别差异 |
142
+ | 3. 假设 | 形成理论、最小测试 | 确认或新假设 |
143
+ | 4. 实现 | 创建测试、修复、验证 | Bug 解决、测试通过 |
144
+
145
+ ## 当流程揭示"无根因"时
146
+
147
+ 如果系统性调查揭示问题确实属于环境性、时序性或外部依赖:
148
+ 1. 已完成流程(不是跳过)
149
+ 2. 记录调查了什么
150
+ 3. 实现适当处理(重试、超时、错误提示)
151
+ 4. 添加监控/日志供将来调查
152
+
153
+ **但是:** 95% 的"无根因"案例是不完整调查。
@@ -0,0 +1,130 @@
1
+ # Harness Methodology: Test-Driven Development
2
+
3
+ 从 Superpowers `test-driven-development` skill 中提取的 TDD 纪律,适配本仓库 harness 工作流。
4
+
5
+ ## Iron Law
6
+
7
+ ```
8
+ NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
9
+ ```
10
+
11
+ 在测试之前写的任何实现代码,必须在写测试前删除。不是"留作参考"、不是"边写测试边改"——删除就是删除,从零开始实现。
12
+
13
+ ## RED-GREEN-REFACTOR 循环
14
+
15
+ ### RED:写一个失败测试
16
+
17
+ 写一个最小的测试,展示代码应该做什么。
18
+
19
+ **要求:**
20
+ - 一个行为
21
+ - 清晰的命名
22
+ - 真实代码(除非不可避免才 mock)
23
+
24
+ ```
25
+ ✅ test('rejects empty email', async () => {
26
+ const result = await submitForm({ email: '' });
27
+ expect(result.error).toBe('Email required');
28
+ })
29
+
30
+ ❌ test('retry works', ...) // 名字模糊
31
+ ❌ test('validates email and domain and whitespace') // 一次测太多
32
+ ```
33
+
34
+ ### Verify RED:看着它失败
35
+
36
+ **不可跳过。**
37
+
38
+ ```bash
39
+ npm test path/to/test.test.ts
40
+ ```
41
+
42
+ 确认:
43
+ - 测试**失败**(不是报错)
44
+ - 失败原因是你预期的(因为功能还没实现,而不是拼写错误)
45
+ - 测试通过?→ 你在测已有行为,修正测试。测试报错?→ 修复错误,重新跑到真的失败为止。
46
+
47
+ ### GREEN:最小实现
48
+
49
+ 写刚好能让测试通过的最简单代码。不要加功能、不要重构其他代码、不要"顺手优化"。
50
+
51
+ ### Verify GREEN:看着它通过
52
+
53
+ **不可跳过。**
54
+
55
+ ```bash
56
+ npm test path/to/test.test.ts
57
+ ```
58
+
59
+ 确认:
60
+ - 测试通过
61
+ - 其他测试依然通过
62
+ - 输出干净(无 error、warning)
63
+
64
+ ### REFACTOR:清理
65
+
66
+ 只在 GREEN 之后:
67
+ - 消除重复
68
+ - 改善命名
69
+ - 提取辅助函数
70
+
71
+ 保持测试绿色。不添加行为。
72
+
73
+ ## 为什么顺序重要
74
+
75
+ **"我先写实现再补测试"** → 实现后写的测试立即通过,这什么都证明不了。你可能测了错误的东西、漏了边界情况、从未见过它抓到 bug。测试先行迫使你看到测试失败,证明它确实在测有意义的东西。
76
+
77
+ **"我已经手工测过了"** → 手工测试是临时的。没有记录、不能重跑、压力下容易忘。"刚刚试了能用" ≠ 全面覆盖。自动化测试是系统性的,每次跑得一样。
78
+
79
+ **"删掉已写代码太浪费"** → 沉没成本谬误。时间已经花了。现在的选择是:(a) 删掉重写 TDD(X 小时,高信心)vs (b) 保留它然后补测试(30 分钟,低信心,大概率有 bug)。保留不可信的代码才是真正的浪费。
80
+
81
+ ## TDD 与 Harness 工作流的对齐
82
+
83
+ | TDD 阶段 | Harness 步骤 |
84
+ |----------|-------------|
85
+ | RED | Contract → 写验收标准(含测试预期) |
86
+ | GREEN | Implement → 最小实现 |
87
+ | REFACTOR | Verify 通过后可做受控清理 |
88
+ | 循环 | 下一个工作块 |
89
+
90
+ ## 验证清单
91
+
92
+ 在标记工作完成前:
93
+
94
+ - [ ] 每个新函数/方法有对应测试
95
+ - [ ] 看过每个测试在实现前失败
96
+ - [ ] 每个测试因预期原因失败(功能缺失,不是拼写错误)
97
+ - [ ] 为每个测试写了最小实现
98
+ - [ ] 所有测试通过
99
+ - [ ] 输出干净(无 error、warning)
100
+ - [ ] 测试使用真实代码(仅在不可避免时 mock)
101
+ - [ ] 边界情况和错误路径已覆盖
102
+
103
+ 无法勾完所有框 → 跳过了 TDD → 从 RED 重新开始。
104
+
105
+ ## 反模式
106
+
107
+ - **测试 mock 行为而非真实行为**:mock 只在调用外部 API/DB 等不可避免时使用
108
+ - **给生产类加仅测试用的方法**:设计接口应同时对生产者和消费者友好
109
+ - **不理解依赖就 mock**:先理解数据流,再 mock
110
+
111
+ ## Bug 修复的 TDD
112
+
113
+ 发现 bug → 先写复现它的失败测试 → RED-GREEN-REFACTOR → 测试即证明修复有效且防止回归。
114
+
115
+ 永远不要在没有测试的情况下修 bug。
116
+
117
+ ## 当卡住时
118
+
119
+ | 问题 | 解法 |
120
+ |------|------|
121
+ | 不知道怎么写测试 | 先写期望的 API 调用方式;先写断言 |
122
+ | 测试太复杂 | 设计太复杂,简化接口 |
123
+ | 必须 mock 一切 | 代码耦合太重,用依赖注入 |
124
+ | 测试 setup 巨大 | 提取辅助函数;还是复杂?简化设计 |
125
+
126
+ ## 参考
127
+
128
+ - Harness 工作流:`docs/feature-workflow.md`
129
+ - 验证矩阵:`docs/verification-matrix.md`
130
+ - Sprint Contract 模板:`docs/templates/sprint-contract.md`
@@ -0,0 +1,27 @@
1
+ # Verification Methodology
2
+
3
+ Completion claims require current evidence.
4
+
5
+ ## Gate Function
6
+
7
+ 1. Identify the command that proves the claim.
8
+ 2. Run the full command.
9
+ 3. Read the output and exit code.
10
+ 4. Fix failures or report the exact failing state.
11
+ 5. Only then claim the result.
12
+
13
+ ## Common Gates
14
+
15
+ | Claim | Command |
16
+ |---|---|
17
+ | Governance is valid | `bash scripts/check-repo.sh` |
18
+ | TypeScript compiles | `npm run typecheck` |
19
+ | Behavior is covered | `npm test` |
20
+ | Full local delivery is valid | `bash scripts/ci.sh` |
21
+
22
+ ## Red Flags
23
+
24
+ - claiming completion from intent
25
+ - relying on stale command output
26
+ - using a narrow check for a broad claim
27
+ - skipping failed command details
@@ -0,0 +1,42 @@
1
+ # loop-agent Harness
2
+
3
+ loop-agent provides a local harness for structured agent work.
4
+
5
+ ## Runtime Areas
6
+
7
+ - `.harness/tasks/` stores task source, constraints, state, and loop facts.
8
+ - `.harness/dag-runs/` stores DAG run state and artifacts.
9
+ - `.harness/runs/` stores one-shot tool run evidence.
10
+ - `.harness/cache/` stores local runtime cache.
11
+ - `.harness/live/` stores transient live-session files.
12
+
13
+ ## Skill Instructions
14
+
15
+ - `skills/loop-agent/` stores loop-agent's repo-owned skill instructions and references.
16
+ - `skills/<skill-name>/` stores local copies of skills referenced by DAG templates, including supervised implementation roles.
17
+ - Historical `skill/` is no longer a required repository path; runtime lookup keeps it only as a compatibility fallback for `loop-agent`.
18
+
19
+ ## Package Assets
20
+
21
+ The npm package includes static capability assets needed to run and explain the harness: `bin/`, `dist/`, `skills/`, top-level `docs/*.md`, `docs/templates/`, `examples/`, `harness.json`, `AGENTS.md`, `README.md`, and `CHANGELOG.md`.
22
+
23
+ Generated or historical task facts are not package assets. Existing files under `docs/progress/`, `docs/reports/`, `docs/exec-plans/`, and `docs/decisions/` belong to the target repository's history; the package carries only the directory README files for those areas.
24
+
25
+ When `loop-agent` is installed from npm and used against another project, DAG skill instructions resolve from configured, user, or target-local skill directories when present, then fall back to the package-bundled `skills/`. A target project may add local skills, but it does not need loop-agent's source history or a copied `skills/` directory to use the default DAG workflow.
26
+
27
+ ## Command Surfaces
28
+
29
+ - `new-task`, `status`, `inspect`, `doctor`
30
+ - `dag run-task`, `dag validate`, `run-dag`, `dag report`, `dag resume`
31
+ - `delegate`, `harvest`, `promote-run`, `closeout`
32
+ - `loop init`, `loop run`, `loop status`, `loop closeout`
33
+ - `pi-prompt`, `cursor-prompt`
34
+ - `docs audit`, `handoff check`, `spine audit`, `knowledge curate`
35
+
36
+ ## Verification Preset
37
+
38
+ The shell preset `loop-agent-standard-verify` runs typecheck and focused DAG tests. Full delivery should still use:
39
+
40
+ ```bash
41
+ bash scripts/ci.sh
42
+ ```
@@ -0,0 +1,3 @@
1
+ # Progress Logs
2
+
3
+ Use this directory for concise handoff logs that should survive chat context.
@@ -0,0 +1,3 @@
1
+ # Reports
2
+
3
+ Use this directory for verification, audit, benchmark, and closeout reports.
@@ -0,0 +1,60 @@
1
+ # ADR 模板
2
+
3
+ ## 标题
4
+
5
+ > 建议文件名:`0001-<topic>.md`
6
+
7
+ ## 状态
8
+
9
+ - proposed / accepted / superseded
10
+
11
+ ## 背景
12
+
13
+ - 当前遇到的工程或架构问题是什么?
14
+ - 为什么现在必须做决定?
15
+ - 相关上下文、历史方案、约束有哪些?
16
+
17
+ ## 决策
18
+
19
+ - 最终选择什么方案?
20
+ - 明确边界、适用范围、默认行为是什么?
21
+
22
+ ## 备选方案
23
+
24
+ 1. 方案 A:
25
+ 2. 方案 B:
26
+ 3. 方案 C:
27
+
28
+ ## 取舍理由
29
+
30
+ - 为什么选择当前方案?
31
+ - 为什么不选其他方案?
32
+ - 主要 trade-off 是什么?
33
+
34
+ ## 影响范围
35
+
36
+ - 影响的代码目录:
37
+ - 影响的文档/契约:
38
+ - 影响的测试/脚本:
39
+ - 影响的开发流程/harness:
40
+
41
+ ## 后果
42
+
43
+ ### 正面后果
44
+
45
+ -
46
+
47
+ ### 负面后果 / 成本
48
+
49
+ -
50
+
51
+ ## 验证与落地
52
+
53
+ - 需要补哪些实现、脚本或测试:
54
+ - 如何验证决策已经生效:
55
+
56
+ ## 复审条件
57
+
58
+ 当出现以下情况时,建议重新审视本 ADR:
59
+
60
+ -