@tea-agent/loop-agent 0.21.0 → 0.23.1

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 (108) hide show
  1. package/AGENTS.md +42 -108
  2. package/CHANGELOG.md +114 -0
  3. package/README.md +7 -4
  4. package/bin/agent-worker.js +0 -0
  5. package/dist/adapters/loop-agent.js +52 -0
  6. package/dist/application/context-usage/skill-resolution-stats.js +263 -0
  7. package/dist/application/dag/generate-task-dag.js +17 -3
  8. package/dist/cli/command-definitions.js +8 -7
  9. package/dist/cli/program.js +17 -15
  10. package/dist/commands/doctor.js +269 -18
  11. package/dist/commands/init.js +198 -86
  12. package/dist/commands/stats.js +40 -11
  13. package/dist/executors/dag-pi-executor.js +2 -0
  14. package/dist/executors/shell-executor.js +162 -19
  15. package/dist/shared/openspec-spec.js +49 -0
  16. package/dist/shared/operator/capabilities.js +11 -1
  17. package/dist/worker/console/app-data.js +4 -0
  18. package/dist/worker/console/chat/instruction-skills.js +217 -0
  19. package/dist/worker/console/chat/model-resolver.js +106 -0
  20. package/dist/worker/console/chat/pi-runtime.js +605 -0
  21. package/dist/worker/console/chat/resource-loader.js +66 -0
  22. package/dist/worker/console/chat/routes.js +357 -0
  23. package/dist/worker/console/chat/session-store.js +238 -0
  24. package/dist/worker/console/chat/tool-adapter.js +238 -0
  25. package/dist/worker/console/chat/tools.js +171 -0
  26. package/dist/worker/console/server.js +55 -0
  27. package/dist/worker/console/static/assets/index-DVl7Jxt5.js +25 -0
  28. package/dist/worker/console/static/assets/index-lVcIr9Ju.css +1 -0
  29. package/dist/worker/console/static/index.html +2 -2
  30. package/dist/worker/feature/profile-schema.js +1 -1
  31. package/dist/worker/observability/read-model.js +21 -1
  32. package/dist/worker/observe/spec-evidence.js +12 -15
  33. package/dist/worker/observe/static/dag-helpers.js +22 -0
  34. package/dist/worker/observe/static/views/dag.js +5 -0
  35. package/dist/workflows/dag/backend-test-markdown-workflow.js +37 -0
  36. package/dist/workflows/dag/frontend-implementation-contract.js +141 -32
  37. package/dist/workflows/dag/frontend-lint-baseline.js +471 -0
  38. package/dist/workflows/dag/frontend-prewrite-gate.js +79 -16
  39. package/dist/workflows/dag/frontend-project-capability.js +11 -8
  40. package/dist/workflows/dag/frontend-repair.js +6 -4
  41. package/dist/workflows/dag/frontend-review-context.js +67 -0
  42. package/dist/workflows/dag/frontend-test-case-quality.js +105 -0
  43. package/dist/workflows/dag/frontend-test-result-contract.js +71 -66
  44. package/dist/workflows/dag/frontend-verification-trace.js +31 -1
  45. package/dist/workflows/dag/frontend-worktree-diff.js +81 -6
  46. package/dist/workflows/dag/init-hybrid.js +412 -84
  47. package/dist/workflows/dag/node-execution.js +38 -1
  48. package/dist/workflows/dag/output-protocol.js +89 -0
  49. package/dist/workflows/dag/prompt.js +35 -1
  50. package/dist/workflows/dag/recovery-recommendation.js +45 -0
  51. package/dist/workflows/dag/report.js +28 -1
  52. package/dist/workflows/dag/rerun-task.js +1 -1
  53. package/dist/workflows/dag/scheduler.js +9 -0
  54. package/dist/workflows/dag/types.js +74 -1
  55. package/dist/workflows/dag/validate.js +55 -0
  56. package/docs/README.md +73 -156
  57. package/docs/architecture/README.md +3 -2
  58. package/docs/architecture/dag-execution.md +2 -2
  59. package/docs/architecture/evolution.md +14 -12
  60. package/docs/architecture/system-overview.md +1 -1
  61. package/docs/architecture/worker-and-feature.md +3 -3
  62. package/docs/governance/README.md +15 -0
  63. package/docs/{harness-methodology-debugging.md → governance/harness-methodology-debugging.md} +27 -3
  64. package/docs/init-surface.manifest.json +22 -4
  65. package/docs/operations/README.md +12 -0
  66. package/docs/{local-development-environment.md → operations/local-development-environment.md} +1 -1
  67. package/docs/skills/vetted-skill-registry.md +23 -3
  68. package/docs/templates/README.md +55 -0
  69. package/docs/templates/agent-dag.schema.json +15 -5
  70. package/docs/templates/backend-test-dag.json +1 -1
  71. package/docs/templates/evaluation/agents-map-slim-v1.candidate.json +9 -0
  72. package/docs/templates/evaluation/agents-map-slim-v1.md +87 -0
  73. package/docs/templates/evaluation/agents-map-verbose-v0.candidate.json +9 -0
  74. package/docs/templates/evaluation/agents-map-verbose-v0.md +153 -0
  75. package/docs/templates/frontend-implementation-contract.schema.json +4 -3
  76. package/docs/templates/frontend-test-case-checklist.md +6 -2
  77. package/docs/templates/frontend-test-dag.json +2 -2
  78. package/docs/templates/hybrid-dag.json +1 -1
  79. package/docs/templates/progress-log.md +9 -2
  80. package/harness.json +5 -5
  81. package/package.json +5 -5
  82. package/scripts/kb-bootstrap-init-skeleton.sh +2 -2
  83. package/skills/agent-worker/SKILL.md +1 -1
  84. package/skills/frontend-design-review/SKILL.md +12 -10
  85. package/skills/frontend-design-review/references/review-checklist.md +4 -4
  86. package/skills/frontend-implementation/SKILL.md +2 -2
  87. package/skills/frontend-implementation/references/code-standards.md +4 -3
  88. package/skills/frontend-implementation/references/design-spec.md +19 -14
  89. package/skills/frontend-implementation/references/node-contracts.md +2 -2
  90. package/skills/frontend-review/SKILL.md +15 -28
  91. package/skills/frontend-review/references/review-findings.md +16 -18
  92. package/skills/frontend-verification/SKILL.md +16 -13
  93. package/skills/frontend-verification/references/verification-checklist.md +18 -30
  94. package/skills/grill-with-docs/SKILL.md +44 -52
  95. package/skills/grill-with-docs/adr-format.md +37 -26
  96. package/skills/grill-with-docs/context-format.md +18 -26
  97. package/skills/loop-agent/SKILL.md +28 -112
  98. package/skills/loop-agent/references/command-reference.md +9 -3
  99. package/skills/loop-agent/references/harness-policy.md +3 -3
  100. package/skills/loop-agent/references/hybrid-dag.md +1 -1
  101. package/skills/loop-agent/references/orchestrator-and-interventions.md +1 -1
  102. package/skills/loop-agent/references/task-workflow.md +2 -0
  103. package/skills/systematic-debugging/SKILL.md +20 -4
  104. package/skills/test-driven-development/SKILL.md +10 -3
  105. package/dist/worker/console/static/assets/index-CUDke82y.js +0 -18
  106. package/dist/worker/console/static/assets/index-wSEksVSO.css +0 -1
  107. /package/docs/{harness-methodology-tdd.md → governance/harness-methodology-tdd.md} +0 -0
  108. /package/docs/{harness-methodology-verification.md → governance/harness-methodology-verification.md} +0 -0
@@ -1,47 +1,58 @@
1
1
  # ADR Format
2
2
 
3
- ADRs live in `ai_workspace/loop-agent/adr/` and use sequential numbering: `0001-slug.md`, `0002-slug.md`, etc.
3
+ ADRs live under `${harness.json.governanceRoot}/decisions/`(源码仓库通常为 `docs/decisions/`;普通初始化目标项目通常为 `ai_workspace/loop-agent/decisions/`)。
4
4
 
5
- Create the `ai_workspace/loop-agent/adr/` directory lazily only when the first ADR is needed.
5
+ Do **not** create a parallel `adr/` tree. Use `decisions/` under the governance root only.
6
6
 
7
- ## Template
8
-
9
- ```md
10
- # {Short title of the decision}
7
+ Create the decisions directory lazily — only when the first ADR is needed and write permission exists.
11
8
 
12
- {1-3 sentences: what's the context, what did we decide, and why.}
13
- ```
9
+ ## Template
14
10
 
15
- That's it. An ADR can be a single paragraph. The value is in recording *that* a decision was made and *why* — not in filling out sections.
11
+ Follow the **target repository's existing ADR template**. In the loop-agent source repo that is `docs/templates/adr.md` with full sections:
16
12
 
17
- ## Optional sections
13
+ - 标题 / 状态
14
+ - 背景
15
+ - 决策
16
+ - 备选方案
17
+ - 取舍理由
18
+ - 影响范围
19
+ - 后果(正面 / 负面)
20
+ - 验证与落地
21
+ - 复审条件
18
22
 
19
- Only include these when they add genuine value. Most ADRs won't need them.
23
+ Do not replace a full local template with a one-paragraph mini-ADR.
20
24
 
21
- - **Status** frontmatter (`proposed | accepted | deprecated | superseded by ADR-NNNN`) useful when decisions are revisited
22
- - **Considered Options** — only when the rejected alternatives are worth remembering
23
- - **Consequences** — only when non-obvious downstream effects need to be called out
25
+ Target projects may ship a copy of the template under their governance `templates/` directory; use that when present.
24
26
 
25
27
  ## Numbering
26
28
 
27
- Scan `ai_workspace/loop-agent/adr/` for the highest existing number and increment by one.
29
+ Scan the decisions directory for the highest existing `NNNN-*.md` number and increment by one. Update the decisions README index when one exists.
28
30
 
29
31
  ## When to offer an ADR
30
32
 
31
- All three of these must be true:
33
+ All three must be true:
32
34
 
33
35
  1. **Hard to reverse** — the cost of changing your mind later is meaningful
34
- 2. **Surprising without context** — a future reader will look at the code and wonder "why on earth did they do it this way?"
35
- 3. **The result of a real trade-off** — there were genuine alternatives and you picked one for specific reasons
36
+ 2. **Surprising without context** — a future reader will wonder why this path was chosen
37
+ 3. **The result of a real trade-off** — genuine alternatives existed and one was chosen for specific reasons
36
38
 
37
- If a decision is easy to reverse, skip it — you'll just reverse it. If it's not surprising, nobody will wonder why. If there was no real alternative, there's nothing to record beyond "we did the obvious thing."
39
+ If any is missing, skip the ADR.
38
40
 
39
41
  ### What qualifies
40
42
 
41
- - **Architectural shape.** "We're using a monorepo." "The write model is event-sourced, the read model is projected into Postgres."
42
- - **Integration patterns between contexts.** "Ordering and Billing communicate via domain events, not synchronous HTTP."
43
- - **Technology choices that carry lock-in.** Database, message bus, auth provider, deployment target. Not every library — just the ones that would take a quarter to swap out.
44
- - **Boundary and scope decisions.** "Customer data is owned by the Customer context; other contexts reference it by ID only." The explicit no-s are as valuable as the yes-s.
45
- - **Deliberate deviations from the obvious path.** "We're using manual SQL instead of an ORM because X." Anything where a reasonable reader would assume the opposite. These stop the next engineer from "fixing" something that was deliberate.
46
- - **Constraints not visible in the code.** "We can't use AWS because of compliance requirements." "Response times must be under 200ms because of the partner API contract."
47
- - **Rejected alternatives when the rejection is non-obvious.** If you considered GraphQL and picked REST for subtle reasons, record it — otherwise someone will suggest GraphQL again in six months.
43
+ - Architectural shape and integration patterns between contexts
44
+ - Technology choices that carry lock-in
45
+ - Boundary and scope decisions (explicit no-es included)
46
+ - Deliberate deviations from the obvious path
47
+ - Constraints not visible in the code
48
+ - Rejected alternatives when the rejection is non-obvious
49
+
50
+ ### What does not
51
+
52
+ - Temporary scheduling
53
+ - Obvious implementation choices with no alternatives
54
+ - Facts that belong in code, tests, or progress/report artifacts
55
+
56
+ ## Write boundary
57
+
58
+ Only create or edit ADR files when the current task `allowedPaths` / DAG `writeSet` allow it. Otherwise return a suggested patch for human or writer follow-up.
@@ -7,7 +7,12 @@
7
7
 
8
8
  {One or two sentence description of what this context is and why it exists.}
9
9
 
10
- ## Language
10
+ ## 使用说明(optional but recommended)
11
+
12
+ - CONTEXT.md is a glossary and nothing else.
13
+ - Do not store implementation details, draft specs, plan status, or architecture decisions.
14
+
15
+ ## 术语 / Language
11
16
 
12
17
  **Order**:
13
18
  {A one or two sentence description of the term}
@@ -16,45 +21,32 @@ _Avoid_: Purchase, transaction
16
21
  **Invoice**:
17
22
  A request for payment sent to a customer after delivery.
18
23
  _Avoid_: Bill, payment request
19
-
20
- **Customer**:
21
- A person or organization that places orders.
22
- _Avoid_: Client, buyer, account
23
24
  ```
24
25
 
26
+ Prefer the target repository's existing heading style(本仓库使用「术语」与 `_避免_`)。
27
+
25
28
  ## Rules
26
29
 
27
- - **Be opinionated.** When multiple words exist for the same concept, pick the best one and list the others under `_Avoid_`.
30
+ - **Be opinionated.** When multiple words exist for the same concept, pick the best one and list the others under `_Avoid_` / `_避免_`.
28
31
  - **Keep definitions tight.** One or two sentences max. Define what it IS, not what it does.
29
- - **Only include terms specific to this project's context.** General programming concepts (timeouts, error types, utility patterns) don't belong even if the project uses them extensively. Before adding a term, ask: is this a concept unique to this context, or a general programming concept? Only the former belongs.
30
- - **Group terms under subheadings** when natural clusters emerge. If all terms belong to a single cohesive area, a flat list is fine.
32
+ - **Glossary only.** No implementation details, specs, plan status, or ADRs.
33
+ - **Only include terms specific to this project's context.** General programming concepts do not belong.
34
+ - **Group terms under subheadings** when natural clusters emerge.
31
35
 
32
36
  ## Single vs multi-context repos
33
37
 
34
38
  **Single context (most repos):** One `CONTEXT.md` at the repo root.
35
39
 
36
- **Multiple contexts:** A `CONTEXT-MAP.md` at the repo root lists the contexts, where they live, and how they relate to each other:
37
-
38
- ```md
39
- # Context Map
40
-
41
- ## Contexts
42
-
43
- - `src/ordering/CONTEXT.md` — receives and tracks customer orders
44
- - `src/billing/CONTEXT.md` — generates invoices and processes payments
45
- - `src/fulfillment/CONTEXT.md` — manages warehouse picking and shipping
46
-
47
- ## Relationships
48
-
49
- - **Ordering → Fulfillment**: Ordering emits `OrderPlaced` events; Fulfillment consumes them to start picking
50
- - **Fulfillment → Billing**: Fulfillment emits `ShipmentDispatched` events; Billing consumes them to generate invoices
51
- - **Ordering ↔ Billing**: Shared types for `CustomerId` and `Money`
52
- ```
40
+ **Multiple contexts:** A `CONTEXT-MAP.md` at the repo root lists the contexts, where they live, and how they relate.
53
41
 
54
42
  The skill infers which structure applies:
55
43
 
56
44
  - If `CONTEXT-MAP.md` exists, read it to find contexts
57
45
  - If only a root `CONTEXT.md` exists, single context
58
- - If neither exists, create a root `CONTEXT.md` lazily when the first term is resolved
46
+ - If neither exists, propose a root `CONTEXT.md` lazily when the first term is resolved — create only when write permission exists
59
47
 
60
48
  When multiple contexts exist, infer which one the current topic relates to. If unclear, ask.
49
+
50
+ ## Write boundary
51
+
52
+ Only edit `CONTEXT.md` when current task `allowedPaths` / DAG `writeSet` allow it. Otherwise return a suggested patch.
@@ -9,142 +9,58 @@ references:
9
9
  required: true
10
10
  - path: references/verification-and-failure-handling.md
11
11
  required: true
12
- - path: references/command-reference.md
13
- required: true
14
12
  ---
15
13
 
16
14
  # loop-agent Workflow
17
15
 
18
- 这是 `loop-agent` 的入口文档,只负责 trigger、routing 和硬规则。较长的 command details、workflow 细节与失败处理放在 `references/`,按需加载。
19
-
20
- ## Canonical Harness Policy
21
-
22
- Shared loop-agent harness workflow 规则见 `references/harness-policy.md`。Repo-local `ai_workspace/loop-agent/loop-agent-harness.md` / `specs/loop-agent-harness.md` 应保持为 local runtime path、governance root、verification commands 的 thin adapters。
16
+ Entry for `loop-agent`: trigger, routing, hard rules. Details live in `references/` on demand. `references/command-reference.md` is discoverable via the routing table, **not** a required reference.
23
17
 
24
18
  ## 默认立场
25
19
 
26
- - 主入口是 **Agent DAG**(经已发布 `loop-agent` / 可选 `agent-worker` CLI)。
27
- - 本 skill openCode 等宿主的定位是 **Compatibility / Operator Assist**,不是「主会话实现业务代码」。
28
- - **主会话 = operator-only**:编排 CLI、审 writeSet、只读 status/doctor/report/observe、记 human gate、跑 shell 验证与 handoff。
29
- - **严禁**主会话绕过 `loop-agent` / `agent-worker` CLI,用宿主 Edit/Write/ApplyPatch 等直接改业务实现,或在 CLI 失败后「救火改文件」。
30
- - **允许(主会话)**:调用 `loop-agent` / `agent-worker`;只读查 `status` / `dag status` / `dag doctor` / `dag report` / `inspect` / Observe;维护任务源 `source/*` 与结构化 `task.json` 边界(通过 CLI 或显式任务准备步骤,而非替代 DAG writer)。
31
- - **禁止(主会话)**:直接实现功能/修 bug 业务代码;把 sidecar 当默认 writer;用聊天自述代替 shell 验证。
32
- - **失败时只允许**:`dag doctor` / `dag report` / `dag reconcile-run`(及 worker 侧 reconcile)、记 human gate、按边界重跑或 replan;不得改走主会话直接写实现。
33
- - DAG `pi` executor 是唯一受治理 Agent runtime:默认 read-only planning / review / diagnosis;`toolProfile: "write"` 时为 bounded implementation / repair。Pi 模型矩阵 LOW=`gpt-5.3-codex-spark`、MED=`glm-5.2`、HIGH=`gpt-5.5`。
34
- - `pi-prompt` 与 `cursor-prompt` 是一次性 helper;sidecar 须在 prompt/tool 参数中收窄。Cursor 仅显式手工 `cursor-prompt`,不是 DAG/Loop writer。
35
- - Shell verification 是事实源;完成声明必须有本轮命令输出。
36
- - 长期结论写回 `ai_workspace/loop-agent/exec-plans/`、`ai_workspace/loop-agent/reports/`、`ai_workspace/loop-agent/progress/` 或 `./skill/`。
20
+ - 主入口是 **Agent DAG**(经 `loop-agent` / 可选 `agent-worker` CLI)。
21
+ - 本 skill 对宿主定位是 **Compatibility / Operator Assist**,不写业务代码。
22
+ - **主会话 = operator-only**:编排 CLI、审 writeSet、只读 status/doctor/report、记 human gate、跑 Shell verification handoff。
23
+ - **严禁**主会话绕过 CLI 用宿主 Edit/Write 改业务实现,或 CLI 失败后「救火改文件」。
24
+ - DAG `pi` executor 默认 read-only;`toolProfile: "write"` 时为 bounded writer;sidecar per call 收窄。
25
+ - Shell verification 是事实源;长期结论写回 `ai_workspace/loop-agent/`、`docs/decisions/` `skills/`。
37
26
 
38
27
  ## 唯一推荐执行路径
39
28
 
40
29
  ```bash
41
- loop-agent new-task <task-id> "Task Title"
42
- # Prefer immutable original PRD first:
43
- # loop-agent import-prd <task-id> --file <path-to-original-prd.md>
44
- # write derived <repo-root>/.harness/tasks/<task-id>/source/需求.md
45
- # write <repo-root>/.harness/tasks/<task-id>/source/执行约束.md
46
-
47
- loop-agent dag run-task <task-id> --profile auto --strict-models --output <temp-dir>/<task-id>-dag.json
48
- loop-agent dag validate --dag <temp-dir>/<task-id>-dag.json --strict-models --strict-governance
49
- loop-agent run-dag --dag <temp-dir>/<task-id>-dag.json --cwd <repo-root>
30
+ loop-agent new-task <task-id> "Title"
31
+ # Prefer immutable PRD: loop-agent import-prd <task-id> --file <path>
32
+ loop-agent dag run-task <task-id> --profile auto --strict-models --output <dag.json>
33
+ loop-agent dag validate --dag <dag.json> --strict-models --strict-governance
34
+ loop-agent run-dag --dag <dag.json> --cwd <repo-root>
50
35
  ```
51
36
 
52
- `loop-agent` 默认指 npm 上已发布的全局 CLI。自举迭代 loop-agent 本仓库时,首次安装或有意升级可用 `npm install -g @tea-agent/loop-agent@latest`,但一次自举任务启动后不要中途升级控制器,并记录 `npm list -g @tea-agent/loop-agent --depth=0` 显示的实际版本。不要用当前工作区的 `npm link` 或 `npm run dev` 控制可能改动 CLI、DAG runtime、executor、package metadata 或 build output 的任务。`npm run dev -- <args>` 只用于源码调试和聚焦 CLI 开发。
53
-
54
- `<temp-dir>` 表示平台原生临时目录。macOS 和 Windows 都应使用实际平台路径;`/` 只用于 repo refs、JSON/Markdown 证据 refs 和 glob 约定。
55
-
56
- 执行前必须审阅:
57
-
58
- - `profileRouting`
59
- - `governanceProfile`
60
- - writer `writeSet`
61
- - writer `forbiddenPaths`
62
- - shell verification commands
63
- - decision gate mode
64
-
65
- ## Pi Sidecar 入口规则
66
-
67
- 短时规划、审查、失败归因可使用 full-capability `pi-prompt`,默认模型是 `glm-5.2`:
68
-
69
- - 只读 sidecar 必须显式传 `--tools read,grep,find,ls`,并在 prompt 中写明不编辑文件。
70
- - 高复杂度 one-shot 诊断可显式加 `--model gpt-5.5`。
71
- - 输出是 advisory,不能替代 deterministic verification;发现必须写回 task source、report、progress 或 exec plan。
72
-
73
- ## Bounded Write Execution
74
-
75
- 需要写业务代码时,**只**通过 DAG `pi` writer(`implement-pi` / `repair-pi`)经 `loop-agent run-dag` / `dag run-task --execute` 等 CLI 路径执行。主会话不得自行 Edit 实现文件「代替」writer。
76
-
77
- Pi writer 节点必须包含 task id、目标、allowed paths、forbidden paths、writeSet、硬约束和预期验证;执行后由主会话**独立跑 shell 验证**(仍经终端/CLI,不手改代码冒充通过)。
78
-
79
- `cursor-prompt` 仅作人工 one-shot sidecar intervention,不进入 Loop auto-execute / Delegate auto-run / DAG writer 选择。细节见 `ai_workspace/loop-agent/cursor-prompt-sidecar.md`、`references/harness-policy.md` 和 `references/verification-and-failure-handling.md`。
80
-
81
- Pi writer / 可选 sidecar prompt 都必须包含:task id、exact objective、allowed/forbidden paths、hard constraints、expected verification、preserve unrelated files。
82
-
83
- bounded writer 完成后,主会话只做独立复核;命令清单见 `references/verification-and-failure-handling.md`。
37
+ 执行前审阅 `profileRouting`、`governanceProfile`、writer `writeSet`、`forbiddenPaths`、decision gate mode。
84
38
 
85
39
  ## 进阶主题路由
86
40
 
87
- 以下主题只在 references 中维护细节,不在本文展开:
88
-
89
41
  | 主题 | Reference |
90
42
  |---|---|
91
- | Long-Running Loop(`loop` init/status/run/record-round/add-signal/closeout、auto mode、signals) | `references/long-running-loop.md` |
92
- | Three-Pass Convergence、repair artifactspine auditknowledge curate、SePO-lite prompt evolution | `references/harness-policy.md` |
93
- | Operator commands(status/doctor/report/closeout/promote/inspect/spine/knowledge/ai_workspace/loop-agent/handoff) | `references/command-reference.md` |
94
- | 伴生 CLI `agent-worker`(TaskSpec / Task Pool / batch / morning report) | `references/command-reference.md` |
95
- | Post-writer 独立验证、verify knobs、failure handling、closeout | `references/verification-and-failure-handling.md` |
96
- | Docs Converge(用户可见变更后的站上/治理文档同步检查表) | `references/docs-converge.md` |
43
+ | Harness policy、Loop、SePO-lite | `references/harness-policy.md` |
44
+ | Agent DAG topologywriteSetrecovery | `references/hybrid-dag.md` |
45
+ | Operator commands、`agent-worker` | `references/command-reference.md` |
46
+ | 独立验证、failure handling、closeout | `references/verification-and-failure-handling.md` |
97
47
 
98
48
  ## Source Layout
99
49
 
100
- 新代码优先从这些目录进入:
101
-
102
- | Area | Entry |
103
- |---|---|
104
- | CLI command tree / help / commander program | `src/cli/` |
105
- | DAG workflow | `src/workflows/dag/` |
106
- | Long-running loop workflow | `src/workflows/loop/` |
107
- | Task runtime | `src/task/` |
108
- | Executors | `src/executors/` |
109
- | Worker TaskSpec pipeline(伴生 CLI `agent-worker`) | `src/worker/` |
110
- | Run records / promotion / closeout | `src/records/` |
111
- | Governance | `src/governance/` |
112
- | Shared helpers | `src/shared/` |
113
- | Repo adapters | `src/adapters/` |
114
-
115
- 不要新增平行兼容入口。CLI public export 的唯一入口是 `src/cli/index.ts`;commander command tree 和 help 实现在 `src/cli/program.ts`。
50
+ CLI `src/cli/`;DAG `src/workflows/dag/`;loop `src/workflows/loop/`;executors `src/executors/`;worker `src/worker/`;governance `src/governance/`。不新增平行兼容入口。
116
51
 
117
52
  ## Hard Rules
118
53
 
119
- 1. One task = one bounded work chunk.
120
- 2. Source materials are mandatory: `source/需求.md` and `source/执行约束.md`. Prefer immutable originals under `source/references/` via `import-prd` or Worker `source_docs`; treat `需求.md` as a derived contract.
121
- 3. Agent DAG is the implementation workflow. Review must three-way check references + derived source + implementation when originals exist.
122
- 4. **Compatibility / Operator Assist**:主会话不得绕过 `loop-agent` / `agent-worker` CLI 直接实现或「救火」改业务代码;失败只走 doctor / reconcile / human gate / 重跑。
123
- 5. DAG `pi` executor stays read-only unless the node sets `toolProfile: "write"`; `pi-prompt` / `cursor-prompt` are full-capability one-shot helpers and must be bounded per call.
124
- 6. Pi writer nodes must be bounded by explicit allowed / forbidden paths and writeSet; Cursor remains `cursor-prompt` sidecar only.
125
- 7. Completed DAG and one-shot run facts are read-only.
126
- 8. Do not write root `artifacts/` from read-only DAG or sidecar steps.
127
- 9. Do not keep hidden workflow state in chat only; write durable conclusions to repo artifacts.
128
- 10. Verify before completion.
54
+ 1. Prefer vertical tracer bullets: each slice crosses the real integration layers with independent acceptance/verification. Do not horizontal-slice.
55
+ 2. Autonomy governance profile: declare AFK/HITL in human gate; choose `--profile` by risk.
56
+ 3. Source materials mandatory: `source/需求.md`、`source/执行约束.md`、优先 `source/references/*` originals
57
+ 4. Agent DAG is the implementation workflow;review three-way checks references + derived source + implementation。
58
+ 5. 主会话不绕过 CLI 直接写业务代码;失败只走 doctor/reconcile/human gate/重跑。
59
+ 6. DAG `pi` executor read-only unless `toolProfile: "write"`;completed run facts read-only;不得从 read-only DAG/sidecar root `artifacts/`。
60
+ 7. No hidden state in chat only;verify before completion.
129
61
 
130
62
  ## References
131
63
 
132
- Required(frontmatter 已声明):
133
-
134
- - `references/harness-policy.md`
135
- - `references/hybrid-dag.md`
136
- - `references/verification-and-failure-handling.md`
137
- - `references/command-reference.md`
138
-
139
- Optional(按需加载):
140
-
141
- - `references/orchestrator-and-interventions.md`
142
- - `references/long-running-loop.md`
143
- - `references/task-workflow.md`
144
- - `references/pi-prompt.md`
145
- - `references/one-shot-runs.md`
146
- - `references/pi-subagent-assisted-mode.md`
147
- - `references/model-routing.md`
148
- - `references/multi-worktree.md`
149
- - `references/post-implementation-and-patterns.md`
150
- - `references/docs-converge.md` — 用户可见变更后的文档收敛检查表;禁止每次重新规划整站大纲
64
+ Required(按需 inline):`references/harness-policy.md`、`references/hybrid-dag.md`、`references/verification-and-failure-handling.md`
65
+
66
+ Optional:`references/command-reference.md`(operator commands、`agent-worker`)、`references/long-running-loop.md`、`references/orchestrator-and-interventions.md`、`references/task-workflow.md`、`references/pi-prompt.md`、`references/one-shot-runs.md`、`references/pi-subagent-assisted-mode.md`、`references/model-routing.md`、`references/multi-worktree.md`、`references/post-implementation-and-patterns.md`、`references/docs-converge.md`
@@ -25,7 +25,7 @@ loop-agent doctor
25
25
 
26
26
  发布包入口加载 `dist/cli.js`;开发入口加载 `src/cli.ts`。
27
27
 
28
- 发布包携带静态能力资料:`.agents/skills/`、`ai_workspace/loop-agent/*.md`、`ai_workspace/loop-agent/templates/` 和 `examples/`。`ai_workspace/loop-agent/progress/`、`ai_workspace/loop-agent/reports/`、`ai_workspace/loop-agent/exec-plans/`、`ai_workspace/loop-agent/decisions/` 的任务正文属于目标仓库运行中生成的事实,不从 npm 包复制;包内只保留这些目录的 README 说明。
28
+ 发布包携带静态能力资料:`skills/`(包内内置,含 `loop-agent` 与 `agent-worker`;`loop-agent init` 投影时镜像为目标项目 `.agents/skills/`)、`docs/templates/`、`docs/architecture/`、`docs/skills/` 和 `examples/`。`ai_workspace/loop-agent/`(默认 governanceRoot)下的 `progress/`、`reports/`、`exec-plans/`、`decisions/` 由 `loop-agent init` 在目标项目创建目录并投放 README,其中的任务正文属于目标仓库运行中生成的事实,不从 npm 包复制。
29
29
 
30
30
  ## 命令参考
31
31
 
@@ -285,6 +285,7 @@ cp ai_workspace/loop-agent/templates/agent-dag.supervised-implementation.json <t
285
285
  (npx vitest run test/dag-supervised-template.test.ts test/dag-validate.test.ts test/dag-shell-executor.test.ts --reporter=dot) # supervised template + shell.verdictGate runtime
286
286
  loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --cwd <repo-root> # 执行 Agent DAG
287
287
  loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --init-only --canvas-path <temp-dir>/hybrid-dag.canvas.tsx # 可选 derived Canvas view
288
+ bash scripts/run-dag-safe.sh --dag <temp-dir>/hybrid-dag.json --cwd <repo-root> [--timeout-secs 7200] # 后台运行 + 轮询,避免外层 bash timeout 杀进程(见 agent-dag-runner.md §Adaptive liveness)
288
289
  loop-agent dag init-hybrid <task-id> # 生成可审阅的 DAG draft
289
290
  loop-agent dag run-task <task-id> # generate + validate(安全默认;无 dag-runs;standard-compatible)
290
291
  loop-agent dag workflow-plan <task-id> --profile pr-review --output <temp-dir>/<task-id>.workflow.json
@@ -488,7 +489,7 @@ loop-agent knowledge curate --markdown
488
489
  loop-agent knowledge curate --markdown --output ai_workspace/loop-agent/reports/<task-id>-learned-proposal.md
489
490
  ```
490
491
 
491
- 读取 `.harness/knowledge/patterns.jsonl` 中 completed convergence repair pattern,按 `failureClass + fixScope shape + invariant` 去重,生成 human-gated learned guidance proposal。命令只生成 proposal,不直接修改 `./skill/references/learned/*.md`;输出会先通过 skill safety audit。
492
+ 读取 `.harness/knowledge/patterns.jsonl` 中 completed convergence repair pattern,按 `failureClass + fixScope shape + invariant` 去重,生成 human-gated learned guidance proposal。命令只生成 proposal,不直接修改 `skills/loop-agent/references/learned/*.md`;输出会先通过 skill safety audit。
492
493
 
493
494
  ### Knowledge graph / query CLI
494
495
 
@@ -562,12 +563,17 @@ agent-worker observe snapshot --repo <repo-root> # 输出 GlobalSnapshot JSON
562
563
  - **推荐** `console serve`(默认 `127.0.0.1:8790`)提供 Operate + Inspect;Inspect 路径为 `/inspect/#/...`,API 仍为根 `/api/**`。`observe serve` 为兼容入口(默认 `8787`,启动时 stderr 输出 `OBSERVE_SERVE_DEPRECATED`);`observe snapshot` 保留。两者都不会启动、暂停或重试 Task / Worker / DAG。
563
564
  - 当前 Worker 仍是 v0(库 + CLI + dogfood),未接入定时/CI 驱动;`report morning` 只能从已有 Task Pool runs 汇总。
564
565
 
565
- ### 查看 duration statistics
566
+ ### 查看 duration statistics / context usage
566
567
 
567
568
  ```bash
568
569
  loop-agent stats
570
+ loop-agent stats context --last 50
571
+ loop-agent stats context --last 50 --json
569
572
  ```
570
573
 
574
+ - `stats`:legacy step-duration 直方图(`.harness/tasks/*/logs/executor.jsonl`)。
575
+ - `stats context`:最近 N 个 DAG runs 的 **skill-resolution** 与节点 outcome 只读聚合(declared/resolved/missing/error、truncation、`unresolvedReferences.reason`、FINISHED/ERROR/SKIPPED + failureCategory)。**不**宣称模型遵循率或 skill execution rate;corrupted snapshot 记为 finding 且 `ok=false`。
576
+
571
577
  ### Worktree delegate / harvest(escape hatch)
572
578
 
573
579
  ```bash
@@ -77,9 +77,9 @@ loop-agent run-dag \
77
77
 
78
78
  `loop-agent` is the preferred global CLI. For self-hosting loop-agent development, the controller must be an installed npm-published package. Use `npm install -g @tea-agent/loop-agent@latest` for first install or intentional upgrades, then treat the installed version as frozen for the current task and record `npm list -g @tea-agent/loop-agent --depth=0`. Do not repeatedly fetch `npx @latest` inside DAG nodes, and do not use the current working tree's `npm link` or `npm run dev` to control tasks that may edit CLI, DAG runtime, executors, package metadata, or build output. Use `npm run dev -- <args>` only for source debugging and focused CLI development.
79
79
 
80
- The npm package carries static capability assets: `.agents/skills/`, top-level governance docs, `ai_workspace/loop-agent/templates/`, `examples/`, `harness.json`, `AGENTS.md`, `README.md`, and `CHANGELOG.md`. Generated or historical task facts under `ai_workspace/loop-agent/progress/`, `ai_workspace/loop-agent/reports/`, `ai_workspace/loop-agent/exec-plans/`, and `ai_workspace/loop-agent/decisions/` belong to the target repository; package only their directory README files, not prior run content.
80
+ The npm package carries static capability assets: `skills/` (bundled in-package, containing `loop-agent` and `agent-worker`; `loop-agent init` mirrors them into the target project's `.agents/skills/`), `docs/templates/`, `docs/architecture/`, `docs/skills/`, `examples/`, `harness.json`, `AGENTS.md`, `README.md`, and `CHANGELOG.md`. `loop-agent init` creates `ai_workspace/loop-agent/` (the default governanceRoot) in the target project with `progress/`, `reports/`, `exec-plans/`, and `decisions/` directories plus their README files; the actual files under those directories belong to the target repository and are not shipped by the npm package.
81
81
 
82
- For arbitrary target repositories, DAG skill instructions must not depend on loop-agent source history being copied into the target repo. Resolve configured, user, or target-local skills when present, then fall back to package-bundled `.agents/skills/` as the stable default capability set.
82
+ For arbitrary target repositories, DAG skill instructions must not depend on loop-agent source history being copied into the target repo. Resolve configured, user, or target-local skills when present, then fall back to the package-bundled `skills/` (mirrored as `.agents/skills/` in the target project) as the stable default capability set.
83
83
 
84
84
  `<temp-dir>` means the platform-native temp directory. Use native paths for actual `--output`, `--dag`, and `--cwd` values on macOS and Windows; use `/` only for stable repo refs, JSON/Markdown evidence refs, and glob conventions.
85
85
 
@@ -190,7 +190,7 @@ Rules:
190
190
 
191
191
  - Learned prompt deltas 是 human-gated proposals;成为 reusable guidance 前须 review。
192
192
  - Prompt deltas 为 Markdown-only process guidance;不得含 shell commands、credential handling、tool permission expansion 或 completion-authority bypass。
193
- - Accepted learned guidance 位于 `./skill/references/learned/<repo>.md` 或 `default.md`。
193
+ - Accepted learned guidance 位于 `skills/loop-agent/references/learned/<repo>.md` 或 `default.md`。
194
194
  - 已 request `loop-agent` 的 DAG implementer prompts 可 inline 最多三个 human-gated learned Markdown sections。
195
195
  - Learned guidance 为 advisory,永不替代 writeSet governance、Decision Gate policy 或 shell verification。
196
196
 
@@ -238,7 +238,7 @@ review-heavy DAG 中长 shell stdout 可能掩盖 proof 时,用 **evidence-sum
238
238
  | 7 | Completed facts | `.harness/dag-runs/completed/**` 仅可读 evidence — 归档后永不 mutate 历史 run 目录、`run.json`、`state.json` 或 `artifacts/**` |
239
239
  | 8 | Verdict gate | review/supervisor 应以 `VERDICT: pass` 或 `VERDICT: request-revision` 开头以利阅读;用 current-run `<fromNodeId>.json`(`$HARNESS_DAG_RUN_DIR`)上 `shell.verdictGate` block,exact-match `accept[]`;默认 `lineMode=first-non-empty`,supervised template 用 `first-verdict-line` 容忍 preamble 或第一条 normalized `VERDICT:` 前的常见整行 Markdown emphasis |
240
240
  | 9 | Decision Gate | 恰好 emit 一个 `DECISION_ENVELOPE_JSON` block;`audit.runId` 须绑定 **当前** run id;禁止 `decision: accept`、发明 schema、extra root key;填 `audit.nodeId` / `audit.model` |
241
- | 10 | writeSet planning | scout 应列出链接的 `./skill/references/**` 为 **writeSet expansion candidates**(P2:遗漏链接 skill ref 会导致无法在 DAG 内收敛,禁止事后主会话大段补写) |
241
+ | 10 | writeSet planning | scout 应列出链接的 `skills/loop-agent/references/**` 为 **writeSet expansion candidates**(P2:遗漏链接 skill ref 会导致无法在 DAG 内收敛,禁止事后主会话大段补写) |
242
242
  | 11 | Evidence summary | `evidence-summary-shell` / leading `EVIDENCE:` 行是 **practice convention**,非 runtime executor、schema field 或 parser |
243
243
  | 12 | Featureization | 除非 repeated real-run failure 证明 checklist guidance 不够,勿加 runtime/schema/validator/CLI/executor feature |
244
244
  | 13 | writeSet / writer backend | `exclusive` node 用 narrow、disjoint path;无 `**`;固定用 Pi write profile |
@@ -72,7 +72,7 @@ Agent DAG read-only node **不得**写 root `artifacts/`。
72
72
  - `./artifacts/**` 不是 DAG artifact 位置;出现该目录通常表示 Cursor prompt 没有收到 DAG-owned artifact dir。
73
73
  - 若必须更新 root `artifacts/`,用显式 write-capable DAG node;不要用主会话「顺手写 root artifacts」代替节点。
74
74
 
75
- **Linked skill-reference writeSet candidates**:DAG task 变更 workflow 语义时,scout 应提议 `./skill/references/**` 为 **writeSet expansion candidates**,并在下一轮 DAG 中写入,而不是 post-DAG 由主会话大段补写 skill。
75
+ **Linked skill-reference writeSet candidates**:DAG task 变更 workflow 语义时,scout 应提议 `skills/loop-agent/references/**` 为 **writeSet expansion candidates**,并在下一轮 DAG 中写入,而不是 post-DAG 由主会话大段补写 skill。
76
76
 
77
77
  **允许的 operator 写入必须记录**:若发生下文极窄 operator 文件维护,须在 `ai_workspace/loop-agent/reports/`、`progress/` 或 exec plan 留下 scope + verification — 不可静默、不可当作实现完成。
78
78
 
@@ -75,6 +75,8 @@ loop-agent --repo-root /path/to/target-repo <command>
75
75
  - `verifyCommands` / adapter verification settings
76
76
  - `dagFallbackReason`,仅用于记录为何某个长期 loop 缺少 DAG round evidence
77
77
 
78
+ 切片形状:每个 task 应是可独立验证的垂直 tracer bullet,而不是某一层的水平批处理。Autonomy(AFK/HITL)与 governance profile(`minimal`/`standard`/`reviewed`/`supervised`)分开声明;默认 `--profile auto`。
79
+
78
80
  ## Verification
79
81
 
80
82
  完成声明必须来自新鲜验证证据。按目标 repo 的 `harness.json.governanceRoot` 下 `verification-matrix.md` 选择最小证明命令;loop-agent 自身常用:
@@ -21,6 +21,19 @@ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
21
21
 
22
22
  若尚未完成 Phase 1,不得提出 fixes。
23
23
 
24
+ ## Feedback Loop Gate(Phase 1 之前)
25
+
26
+ 在列假设、读大段代码或改文件之前,先建立一条**快速、确定性、Agent 可运行**的 pass/fail 信号。完整优先级与手段见 governance 下的 `harness-methodology-debugging.md`。
27
+
28
+ 可执行清单:
29
+
30
+ 1. 选最小回路:失败测试 → HTTP/CLI/浏览器脚本 → fixture/snapshot → 一次性 harness → bisect/differential → 结构化 HITL。
31
+ 2. 跑一次,确认有可重复的 exit code / 断言结果。
32
+ 3. 间歇性问题:先提高复现率,再进入根因调查。
33
+ 4. **无回路 → STOP**:请求环境、artifact 或临时插桩许可;不要猜。
34
+
35
+ Verifier 角色只提供诊断与证据,不得越过 writer `writeSet` / `allowedPaths` 直接修复。
36
+
24
37
  ## When to Use
25
38
 
26
39
  用于 ANY technical issue:
@@ -45,11 +58,11 @@ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
45
58
 
46
59
  ## The Four Phases
47
60
 
48
- 进入下一阶段前 MUST 完成每一 phase。
61
+ 进入下一阶段前 MUST 完成每一 phase。反馈回路是地基,不是第五 phase
49
62
 
50
63
  ### Phase 1: Root Cause Investigation
51
64
 
52
- **在尝试 ANY fix 之前:**
65
+ **在尝试 ANY fix 之前(且已有反馈回路):**
53
66
 
54
67
  1. **Read Error Messages Carefully**
55
68
  - 不要跳过 errors 或 warnings
@@ -215,6 +228,7 @@ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
215
228
  ## Red Flags - STOP and Follow Process
216
229
 
217
230
  若发现自己想:
231
+ - "No pass/fail loop yet — just read code and guess"
218
232
  - "Quick fix for now, investigate later"
219
233
  - "Just try changing X and see if it works"
220
234
  - "Add multiple changes, run tests"
@@ -227,7 +241,7 @@ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
227
241
  - **"One more fix attempt" (when already tried 2+)**
228
242
  - **Each fix reveals new problem in different place**
229
243
 
230
- **ALL of these mean: STOP. Return to Phase 1.**
244
+ **ALL of these mean: STOP. Return to feedback loop / Phase 1.**
231
245
 
232
246
  **If 3+ fixes failed:** Question the architecture (see Phase 4.5)
233
247
 
@@ -259,6 +273,7 @@ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
259
273
 
260
274
  | Phase | Key Activities | Success Criteria |
261
275
  |-------|---------------|------------------|
276
+ | **0. Feedback Loop** | Build fast deterministic pass/fail signal | Repeatable command + exit code |
262
277
  | **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |
263
278
  | **2. Pattern** | Find working examples, compare | Identify differences |
264
279
  | **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |
@@ -284,8 +299,9 @@ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
284
299
  - **`condition-based-waiting.md`** — 用 condition polling 替代 arbitrary timeouts
285
300
 
286
301
  **Related principles:**
287
- - **RED-GREEN-REFACTOR**(见 `ai_workspace/loop-agent/harness-methodology-tdd.md`)— 用于 creating failing test case(Phase 4, Step 1)
302
+ - **RED-GREEN-REFACTOR**(见 `harness.json.governanceRoot` 下 `harness-methodology-tdd.md`)— 用于 creating failing test case(Phase 4, Step 1)
288
303
  - **Verification discipline** — 宣称 success 前 verify fix worked。Run verification command,读 output,THEN claim result。
304
+ - **Feedback loop**(见同目录 `harness-methodology-debugging.md`)— Phase 1 前的 pass/fail 地基。
289
305
 
290
306
  ## Real-World Impact
291
307
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: test-driven-development
3
- description: 用于需要回归覆盖的行为变更与 bug 修复。保持小循环:写失败测试 → 变绿 → 仅在 green 后 refactor
3
+ description: 用于需要回归覆盖的行为变更与 bug 修复。保持小循环:写失败测试 → 变绿 → 仅在 green 后 refactor。禁止水平批处理。
4
4
  ---
5
5
 
6
6
  # Test-Driven Development
@@ -10,11 +10,18 @@ description: 用于需要回归覆盖的行为变更与 bug 修复。保持小
10
10
  ## 规则
11
11
 
12
12
  - 行为是新增或已损坏时,在 production code 之前写或更新聚焦测试。
13
- - 运行聚焦测试,确认因预期原因失败。
14
- - 做最小实现变更使测试变绿。
13
+ - 运行聚焦测试,确认因预期原因失败(RED)。
14
+ - 做最小实现变更使测试变绿(GREEN)。
15
15
  - refactor 仅在 green 之后,且仍在同一 bounded write set 内。
16
16
  - 能测真实本地 module 时,不要用 broad mock。
17
17
 
18
+ ## 垂直切片:一测试一实现
19
+
20
+ - 循环是:**一个行为测试 → 最小实现 → 验证通过 → 下一个行为**。
21
+ - **禁止**「先批量写完所有测试(全部 RED),再批量实现(全部 GREEN)」的水平切片。
22
+ - 每个行为切片必须有独立验收标准与可运行的验证命令。
23
+ - 纯文档 / 机械迁移工作不强制新增测试;行为变更与 bug 修复必须走上述循环。
24
+
18
25
  ## Output
19
26
 
20
27
  报告 red 命令、green 命令,以及仍需要的 broader verification。