@tea-agent/loop-agent 0.22.0 → 0.24.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 (103) hide show
  1. package/AGENTS.md +42 -108
  2. package/CHANGELOG.md +85 -0
  3. package/README.md +8 -5
  4. package/bin/agent-worker.js +0 -0
  5. package/dist/application/context-usage/skill-resolution-stats.js +263 -0
  6. package/dist/application/dag/generate-task-dag.js +17 -3
  7. package/dist/cli/command-definitions.js +8 -7
  8. package/dist/cli/program.js +17 -15
  9. package/dist/commands/doctor.js +269 -18
  10. package/dist/commands/init.js +101 -86
  11. package/dist/commands/stats.js +40 -11
  12. package/dist/executors/shell-executor.js +20 -7
  13. package/dist/shared/operator/capabilities.js +486 -3
  14. package/dist/worker/console/app-data.js +6 -0
  15. package/dist/worker/console/chat/artifact-card.js +23 -0
  16. package/dist/worker/console/chat/chat-event-store.js +495 -0
  17. package/dist/worker/console/chat/chat-ui-policy.js +25 -0
  18. package/dist/worker/console/chat/composer-draft-store.js +45 -0
  19. package/dist/worker/console/chat/context-panel.js +54 -0
  20. package/dist/worker/console/chat/contract-apply-receipt-store.js +174 -0
  21. package/dist/worker/console/chat/explore-tools.js +299 -0
  22. package/dist/worker/console/chat/human-gate-card.js +37 -0
  23. package/dist/worker/console/chat/instruction-skills.js +217 -0
  24. package/dist/worker/console/chat/interview-adapter.js +136 -0
  25. package/dist/worker/console/chat/model-resolver.js +106 -0
  26. package/dist/worker/console/chat/operation-card.js +23 -0
  27. package/dist/worker/console/chat/pi-console-config.js +158 -0
  28. package/dist/worker/console/chat/pi-runtime.js +1143 -0
  29. package/dist/worker/console/chat/repo-browser.js +140 -0
  30. package/dist/worker/console/chat/repo-walk.js +116 -0
  31. package/dist/worker/console/chat/resource-loader.js +67 -0
  32. package/dist/worker/console/chat/routes.js +1646 -0
  33. package/dist/worker/console/chat/runtime-context.js +24 -0
  34. package/dist/worker/console/chat/runtime-selection.js +37 -0
  35. package/dist/worker/console/chat/session-store.js +437 -0
  36. package/dist/worker/console/chat/shortcuts.js +15 -0
  37. package/dist/worker/console/chat/tool-adapter.js +125 -0
  38. package/dist/worker/console/chat/tools.js +195 -0
  39. package/dist/worker/console/chat/usage.js +37 -0
  40. package/dist/worker/console/chat/workspace-landing.js +56 -0
  41. package/dist/worker/console/dag-confirmation.js +42 -8
  42. package/dist/worker/console/human-gate-token.js +130 -0
  43. package/dist/worker/console/mutation-gate-receipt-store.js +184 -0
  44. package/dist/worker/console/operation-runner.js +6 -2
  45. package/dist/worker/console/operation-sse.js +26 -0
  46. package/dist/worker/console/operator-actions.js +420 -7
  47. package/dist/worker/console/server.js +68 -1
  48. package/dist/worker/console/static/assets/index-BTbrEHnO.css +1 -0
  49. package/dist/worker/console/static/assets/index-D9qLevoP.js +27 -0
  50. package/dist/worker/console/static/index.html +2 -2
  51. package/dist/worker/feature/profile-schema.js +1 -1
  52. package/dist/workflows/dag/backend-test-markdown-workflow.js +9 -5
  53. package/dist/workflows/dag/backend-test-result-contract.js +229 -0
  54. package/dist/workflows/dag/frontend-lint-baseline.js +4 -4
  55. package/dist/workflows/dag/init-hybrid.js +71 -22
  56. package/dist/workflows/dag/node-execution.js +38 -1
  57. package/dist/workflows/dag/output-protocol.js +89 -0
  58. package/dist/workflows/dag/prompt.js +35 -1
  59. package/dist/workflows/dag/recovery-recommendation.js +45 -0
  60. package/dist/workflows/dag/report.js +28 -1
  61. package/dist/workflows/dag/rerun-task.js +1 -1
  62. package/dist/workflows/dag/scheduler.js +9 -0
  63. package/dist/workflows/dag/types.js +12 -0
  64. package/dist/workflows/dag/validate.js +55 -0
  65. package/docs/README.md +73 -156
  66. package/docs/architecture/README.md +7 -6
  67. package/docs/architecture/dag-execution.md +2 -2
  68. package/docs/architecture/evolution.md +16 -14
  69. package/docs/architecture/system-overview.md +1 -1
  70. package/docs/architecture/worker-and-feature.md +3 -3
  71. package/docs/governance/README.md +15 -0
  72. package/docs/{harness-methodology-debugging.md → governance/harness-methodology-debugging.md} +27 -3
  73. package/docs/init-surface.manifest.json +22 -4
  74. package/docs/operations/README.md +12 -0
  75. package/docs/{local-development-environment.md → operations/local-development-environment.md} +1 -1
  76. package/docs/skills/vetted-skill-registry.md +23 -3
  77. package/docs/templates/README.md +55 -0
  78. package/docs/templates/backend-test-dag.json +2 -2
  79. package/docs/templates/evaluation/agents-map-slim-v1.candidate.json +9 -0
  80. package/docs/templates/evaluation/agents-map-slim-v1.md +87 -0
  81. package/docs/templates/evaluation/agents-map-verbose-v0.candidate.json +9 -0
  82. package/docs/templates/evaluation/agents-map-verbose-v0.md +153 -0
  83. package/docs/templates/hybrid-dag.json +1 -1
  84. package/docs/templates/progress-log.md +9 -2
  85. package/harness.json +4 -4
  86. package/package.json +5 -5
  87. package/scripts/kb-bootstrap-init-skeleton.sh +2 -2
  88. package/skills/agent-worker/SKILL.md +1 -1
  89. package/skills/grill-with-docs/SKILL.md +44 -52
  90. package/skills/grill-with-docs/adr-format.md +37 -26
  91. package/skills/grill-with-docs/context-format.md +18 -26
  92. package/skills/loop-agent/SKILL.md +28 -112
  93. package/skills/loop-agent/references/command-reference.md +9 -3
  94. package/skills/loop-agent/references/harness-policy.md +3 -3
  95. package/skills/loop-agent/references/hybrid-dag.md +1 -1
  96. package/skills/loop-agent/references/orchestrator-and-interventions.md +1 -1
  97. package/skills/loop-agent/references/task-workflow.md +2 -0
  98. package/skills/systematic-debugging/SKILL.md +20 -4
  99. package/skills/test-driven-development/SKILL.md +10 -3
  100. package/dist/worker/console/static/assets/index-CUDke82y.js +0 -18
  101. package/dist/worker/console/static/assets/index-wSEksVSO.css +0 -1
  102. /package/docs/{harness-methodology-tdd.md → governance/harness-methodology-tdd.md} +0 -0
  103. /package/docs/{harness-methodology-verification.md → governance/harness-methodology-verification.md} +0 -0
@@ -1,88 +1,80 @@
1
1
  ---
2
2
  name: grill-with-docs
3
- description: Grilling session that challenges your plan against the existing domain model, sharpens terminology, and updates documentation (CONTEXT.md, ADRs) inline as decisions crystallise. Use when user wants to stress-test a plan against their project's language and documented decisions.
3
+ description: >-
4
+ Grilling session that challenges a plan against the existing domain model,
5
+ sharpens terminology, and proposes CONTEXT.md / ADR updates as decisions
6
+ crystallise. Use when the user wants to stress-test a plan against project
7
+ language and documented decisions. Explicit interactive operator skill only —
8
+ not a default DAG role.
9
+ references:
10
+ - path: context-format.md
11
+ required: true
12
+ - path: adr-format.md
13
+ required: true
4
14
  ---
5
15
 
6
- <what-to-do>
16
+ # Grill With Docs
7
17
 
8
- Interview me relentlessly about every aspect of this plan until we reach a shared understanding. Walk down each branch of the design tree, resolving dependencies between decisions one-by-one. For each question, provide your recommended answer.
18
+ 显式交互式 operator skill。用于压力测试计划与术语;**不**加入默认 planner / reviewer / implementer role mapping,避免普通 DAG 被问答阻塞。
9
19
 
10
- Ask the questions one at a time, waiting for feedback on each question before continuing.
20
+ ## What to do
11
21
 
12
- If a question can be answered by exploring the codebase, explore the codebase instead.
13
-
14
- </what-to-do>
15
-
16
- <supporting-info>
17
-
18
- ## Domain awareness
22
+ Interview the user relentlessly about every aspect of the plan until shared understanding. Walk each design branch, resolve decision dependencies one-by-one. For each question, provide a recommended answer.
19
23
 
20
- During codebase exploration, also look for existing documentation:
24
+ Ask questions one at a time; wait for feedback before continuing.
21
25
 
22
- ### File structure
23
-
24
- Most repos have a single context:
26
+ If a question can be answered by exploring the codebase, explore the codebase instead.
25
27
 
26
- ```
27
- /
28
- ├── CONTEXT.md
29
- ├── ai_workspace/loop-agent/
30
- │ └── adr/
31
- │ ├── 0001-event-sourced-orders.md
32
- │ └── 0002-postgres-for-write-model.md
33
- └── src/
34
- ```
28
+ ## Path resolution
35
29
 
36
- If a `CONTEXT-MAP.md` exists at the root, the repo has multiple contexts. The map points to where each one lives:
30
+ 1. Read `harness.json.governanceRoot`(缺省时常见为源码仓库 `docs`,目标项目 `ai_workspace/loop-agent`)。
31
+ 2. Decisions 目录 = `${governanceRoot}/decisions/`(本仓库即 `docs/decisions/`)。
32
+ 3. Glossary = 仓库根 `CONTEXT.md`(多 context 时见 `CONTEXT-MAP.md`)。
33
+ 4. **禁止**硬编码平行 `adr/` 目录树;只用 `${governanceRoot}/decisions/`。
37
34
 
38
- ```
39
- /
40
- ├── CONTEXT-MAP.md
41
- ├── ai_workspace/loop-agent/
42
- │ └── adr/ ← system-wide decisions
43
- ├── src/
44
- │ ├── ordering/
45
- │ │ ├── CONTEXT.md
46
- │ │ └── ai_workspace/loop-agent/adr/ ← context-specific decisions
47
- │ └── billing/
48
- │ ├── CONTEXT.md
49
- │ └── ai_workspace/loop-agent/adr/
50
- ```
35
+ ## Write boundary
51
36
 
52
- Create files lazily — only when you have something to write. If no `CONTEXT.md` exists, create one when the first term is resolved. If no `ai_workspace/loop-agent/adr/` exists, create it when the first ADR is needed.
37
+ - Inline 更新 `CONTEXT.md` / ADR **必须**服从当前 task `allowedPaths` DAG `writeSet`。
38
+ - 无写权限时:只返回建议与待确认 patch,**不得**越界写文档。
39
+ - 不得绕过 human gate、write guard 或 shell completion authority。
53
40
 
54
41
  ## During the session
55
42
 
56
43
  ### Challenge against the glossary
57
44
 
58
- When the user uses a term that conflicts with the existing language in `CONTEXT.md`, call it out immediately. "Your glossary defines 'cancellation' as X, but you seem to mean Y — which is it?"
45
+ 术语与 `CONTEXT.md` 冲突时立即指出。
59
46
 
60
47
  ### Sharpen fuzzy language
61
48
 
62
- When the user uses vague or overloaded terms, propose a precise canonical term. "You're saying 'account' — do you mean the Customer or the User? Those are different things."
49
+ 模糊或过载词要提出规范术语。
63
50
 
64
51
  ### Discuss concrete scenarios
65
52
 
66
- When domain relationships are being discussed, stress-test them with specific scenarios. Invent scenarios that probe edge cases and force the user to be precise about the boundaries between concepts.
53
+ 用具体场景压力测试边界。
67
54
 
68
55
  ### Cross-reference with code
69
56
 
70
- When the user states how something works, check whether the code agrees. If you find a contradiction, surface it: "Your code cancels entire Orders, but you just said partial cancellation is possible — which is right?"
57
+ 声称与代码不符时立即表面矛盾。
71
58
 
72
- ### Update CONTEXT.md inline
59
+ ### Update CONTEXT.md only when allowed
73
60
 
74
- When a term is resolved, update `CONTEXT.md` right there. Don't batch these up — capture them as they happen. Use the format in [context-format.md](./context-format.md).
61
+ 术语敲定后,若有写权限则按 `context-format.md` 立刻更新;否则只给出建议 patch。
75
62
 
76
- `CONTEXT.md` should be totally devoid of implementation details. Do not treat `CONTEXT.md` as a spec, a scratch pad, or a repository for implementation decisions. It is a glossary and nothing else.
63
+ `CONTEXT.md` glossary 且仅是 glossary:不含实现细节、规格草稿、计划状态或架构决策。
77
64
 
78
65
  ### Offer ADRs sparingly
79
66
 
80
- Only offer to create an ADR when all three are true:
67
+ 仅当三条同时成立才提议 ADR
68
+
69
+ 1. **Hard to reverse** — 改变成本可观
70
+ 2. **Surprising without context** — 未来读者会追问 why
71
+ 3. **Real trade-off** — 曾有合理备选并基于具体理由选择
72
+
73
+ 缺一则跳过。格式遵循目标仓库已有模板(见 `adr-format.md`),本仓库使用完整 `docs/templates/adr.md` 字段,不用单段极简 ADR 覆盖本地约定。
81
74
 
82
- 1. **Hard to reverse** — the cost of changing your mind later is meaningful
83
- 2. **Surprising without context** — a future reader will wonder "why did they do it this way?"
84
- 3. **The result of a real trade-off** — there were genuine alternatives and you picked one for specific reasons
75
+ ## Supporting formats
85
76
 
86
- If any of the three is missing, skip the ADR. Use the format in [adr-format.md](./adr-format.md).
77
+ Required references(已进入 skill snapshot):
87
78
 
88
- </supporting-info>
79
+ - `context-format.md`
80
+ - `adr-format.md`
@@ -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 自身常用: