@tea-agent/loop-agent 0.10.0 → 0.11.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 (166) hide show
  1. package/AGENTS.md +10 -2
  2. package/CHANGELOG.md +67 -25
  3. package/README.md +82 -11
  4. package/dist/application/dag/args.js +1 -12
  5. package/dist/application/dag/generate-task-dag.js +23 -2
  6. package/dist/application/dag/run-dag.js +1 -27
  7. package/dist/application/dag/validate-dag.js +2 -2
  8. package/dist/application/loop/run-action.js +0 -4
  9. package/dist/cli/command-definitions.js +44 -16
  10. package/dist/cli/program.js +40 -23
  11. package/dist/cli/update/notifier.js +117 -0
  12. package/dist/cli/update/npm-client.js +151 -0
  13. package/dist/cli/update/policy.js +58 -0
  14. package/dist/cli/update/state.js +68 -0
  15. package/dist/cli.js +33 -0
  16. package/dist/commands/cursor-prompt.js +42 -82
  17. package/dist/commands/dag-approve.js +36 -0
  18. package/dist/commands/delegate.js +75 -77
  19. package/dist/commands/doctor.js +0 -18
  20. package/dist/commands/init.js +476 -91
  21. package/dist/commands/instructions.js +7 -10
  22. package/dist/commands/loop.js +4 -20
  23. package/dist/commands/plan.js +50 -0
  24. package/dist/executors/config-core.js +0 -51
  25. package/dist/executors/dag-pi-executor.js +1 -1
  26. package/dist/executors/dag.js +0 -1
  27. package/dist/executors/index.js +0 -2
  28. package/dist/executors/model-routing.js +9 -9
  29. package/dist/executors/shell-executor.js +1 -1
  30. package/dist/governance/checks.js +6 -3
  31. package/dist/governance/exec-plans.js +545 -0
  32. package/dist/governance/manifest-types.js +24 -2
  33. package/dist/infrastructure/harness/loop-action-store.js +0 -3
  34. package/dist/records/harvest.js +2 -23
  35. package/dist/records/one-shot-runs.js +1 -1
  36. package/dist/shared/artifacts-core.js +24 -5
  37. package/dist/shared/output-truncation.js +37 -0
  38. package/dist/shared/package-metadata.js +353 -0
  39. package/dist/{executors/cursor-executor.js → sidecars/cursor-prompt/executor.js} +2 -42
  40. package/dist/sidecars/cursor-prompt/index.js +3 -0
  41. package/dist/sidecars/cursor-prompt/stream.js +121 -0
  42. package/dist/task/config-types.js +28 -12
  43. package/dist/task/delegate.js +9 -21
  44. package/dist/task/runtime.js +1 -2
  45. package/dist/worker/cli.js +29 -2
  46. package/dist/worker/delivery/final-verification.js +47 -11
  47. package/dist/worker/delivery/package.js +63 -10
  48. package/dist/worker/feature/run.js +60 -8
  49. package/dist/worker/loop-agent/loop-agent-client.js +329 -126
  50. package/dist/worker/observability/read-model.js +27 -1
  51. package/dist/worker/observe/static/app.js +326 -45
  52. package/dist/worker/observe/static/index.html +1 -1
  53. package/dist/worker/observe/static/styles.css +5 -4
  54. package/dist/worker/preflight.js +49 -1
  55. package/dist/worker/run-task/run-task.js +22 -12
  56. package/dist/worker/runner/run-ready.js +76 -12
  57. package/dist/worker/task-spec/schema.js +0 -1
  58. package/dist/workflows/dag/convergence/controller.js +1 -1
  59. package/dist/workflows/dag/executor-registry.js +0 -2
  60. package/dist/workflows/dag/init-hybrid.js +402 -25
  61. package/dist/workflows/dag/node-execution.js +61 -7
  62. package/dist/workflows/dag/runner.js +45 -17
  63. package/dist/workflows/dag/scheduler.js +7 -2
  64. package/dist/workflows/dag/sdd-embedded.js +128 -0
  65. package/dist/workflows/dag/skill-instructions.js +5 -4
  66. package/dist/workflows/dag/skill-snapshot.js +527 -0
  67. package/dist/workflows/dag/types.js +42 -9
  68. package/dist/workflows/dag/validate.js +5 -8
  69. package/dist/workflows/loop/actions/dag-action.js +0 -2
  70. package/dist/workflows/loop/actions/shared.js +1 -1
  71. package/dist/workflows/loop/actions.js +14 -31
  72. package/dist/workflows/loop/benchmark.js +1 -1
  73. package/dist/workflows/loop/index.js +1 -1
  74. package/dist/workflows/loop/policy/auto-policy.js +22 -14
  75. package/dist/workflows/loop/policy/path-patterns.js +13 -0
  76. package/docs/README.md +36 -33
  77. package/docs/agent-dag-recovery-playbook.md +1 -1
  78. package/docs/agent-dag-runner.md +2 -2
  79. package/docs/architecture/README.md +26 -0
  80. package/docs/architecture/dag-execution.md +134 -0
  81. package/docs/architecture/evolution.md +52 -0
  82. package/docs/architecture/facts-and-state.md +58 -0
  83. package/docs/architecture/runtime-boundaries.md +45 -17
  84. package/docs/architecture/system-overview.md +93 -0
  85. package/docs/architecture/worker-and-feature.md +81 -0
  86. package/docs/cursor-prompt-sidecar.md +36 -0
  87. package/docs/decisions/README.md +13 -1
  88. package/docs/design/README.md +42 -21
  89. package/docs/development-principles.md +2 -2
  90. package/docs/exec-plans/active/README.md +2 -2
  91. package/docs/exec-plans/completed/README.md +12 -0
  92. package/docs/feature-workflow.md +50 -4
  93. package/docs/harness-methodology-debugging.md +1 -1
  94. package/docs/harness-methodology-tdd.md +3 -3
  95. package/docs/init-surface.manifest.json +60 -25
  96. package/docs/loop-agent-harness.md +28 -4
  97. package/docs/progress/README.md +32 -1
  98. package/docs/reports/README.md +84 -18
  99. package/docs/skills/README.md +2 -1
  100. package/docs/skills/vetted-skill-registry.md +2 -1
  101. package/docs/templates/agent-dag-report.schema.json +6 -6
  102. package/docs/templates/agent-dag.base.json +0 -5
  103. package/docs/templates/agent-dag.final-verification.json +0 -5
  104. package/docs/templates/agent-dag.schema.json +1 -2
  105. package/docs/templates/agent-dag.supervised-implementation.json +1 -6
  106. package/docs/templates/frontend-design-contract.md +33 -0
  107. package/docs/templates/frontend-task-constraints.md +25 -0
  108. package/docs/templates/frontend-task-requirement.md +61 -0
  109. package/docs/templates/harness.schema.json +10 -12
  110. package/docs/templates/hybrid-dag.json +1 -6
  111. package/docs/templates/interactive-ui-round2-experiment.md +1 -1
  112. package/docs/templates/product-line/task.yaml +0 -1
  113. package/docs/templates/project-start-checklist.md +2 -2
  114. package/docs/templates/worker-dogfood-evidence.md +28 -0
  115. package/docs/templates/worker-dogfood-setup.md +20 -0
  116. package/docs/verification-matrix.md +10 -0
  117. package/examples/decision-gate-agent-dag.json +87 -33
  118. package/examples/example-dag.json +0 -5
  119. package/examples/hybrid-loop-agent-dag.json +0 -5
  120. package/harness.json +7 -15
  121. package/package.json +22 -46
  122. package/scripts/check-product-line-docs.sh +10 -7
  123. package/skills/agent-worker/SKILL.md +37 -0
  124. package/skills/agent-worker/references/agent-worker-operator.md +43 -0
  125. package/skills/frontend-design-review/SKILL.md +59 -0
  126. package/skills/frontend-design-review/references/review-checklist.md +37 -0
  127. package/skills/frontend-implementation/SKILL.md +51 -0
  128. package/skills/frontend-implementation/references/code-standards.md +34 -0
  129. package/skills/frontend-implementation/references/design-spec.md +46 -0
  130. package/skills/frontend-implementation/references/node-contracts.md +32 -0
  131. package/skills/frontend-review/SKILL.md +53 -0
  132. package/skills/frontend-review/references/review-findings.md +42 -0
  133. package/skills/frontend-verification/SKILL.md +40 -0
  134. package/skills/frontend-verification/references/verification-checklist.md +56 -0
  135. package/skills/grill-me/SKILL.md +10 -0
  136. package/skills/grill-with-docs/SKILL.md +88 -0
  137. package/skills/grill-with-docs/adr-format.md +47 -0
  138. package/skills/grill-with-docs/context-format.md +60 -0
  139. package/skills/loop-agent/SKILL.md +11 -9
  140. package/skills/loop-agent/references/command-reference.md +13 -15
  141. package/skills/loop-agent/references/docs-converge.md +126 -0
  142. package/skills/loop-agent/references/harness-policy.md +7 -7
  143. package/skills/loop-agent/references/hybrid-dag.md +15 -18
  144. package/skills/loop-agent/references/long-running-loop.md +4 -6
  145. package/skills/loop-agent/references/multi-worktree.md +6 -6
  146. package/skills/loop-agent/references/orchestrator-and-interventions.md +3 -3
  147. package/skills/loop-agent/references/pi-subagent-assisted-mode.md +14 -11
  148. package/skills/loop-agent/references/task-workflow.md +1 -1
  149. package/skills/using-git-worktrees/SKILL.md +215 -0
  150. package/dist/commands/cursor-worker.js +0 -43
  151. package/dist/cursor-worker-entry.js +0 -8
  152. package/dist/executors/cursor-artifacts.js +0 -33
  153. package/dist/executors/cursor-execution-log.js +0 -81
  154. package/dist/executors/cursor-executor-artifacts.js +0 -134
  155. package/dist/executors/cursor-run.js +0 -115
  156. package/dist/executors/cursor-tool.js +0 -94
  157. package/dist/executors/cursor-worker-client.js +0 -223
  158. package/dist/executors/cursor-worker-protocol.js +0 -18
  159. package/dist/executors/cursor-worker-server.js +0 -54
  160. package/dist/executors/cursor-worker.js +0 -3
  161. package/dist/executors/cursor.js +0 -6
  162. package/dist/executors/dag-cursor-executor.js +0 -87
  163. package/dist/workflows/loop/actions/cursor-fix.js +0 -191
  164. package/dist/workflows/loop/policy/cursor-fix-policy.js +0 -31
  165. package/docs/cursor-executor-usage.md +0 -25
  166. package/docs/dynamic-workflow-dag-engine-roadmap.md +0 -1749
@@ -1,28 +1,28 @@
1
1
  # Agent DAG Hybrid Workflow(`run-dag` / `dag init-hybrid`)
2
2
 
3
- 创建或执行 loop-agent 工作的首选 Agent DAG path 时使用本文:Level 2 Agent DAG orchestration、Pi read-only + Pi `toolProfile: "write"` bounded execution、optional Cursor backend、write policy、DAG template、task-to-DAG 生成,或基于 governance-profile 的 template 选择。
3
+ 创建或执行 loop-agent 工作的首选 Agent DAG path 时使用本文:Level 2 Agent DAG orchestration、Pi read-only + Pi `toolProfile: "write"` bounded execution、Pi-only writers、write policy、DAG template、task-to-DAG 生成,或基于 governance-profile 的 template 选择。
4
4
 
5
5
  ### DAG workflow 优先级
6
6
 
7
7
  `harness.json.workflowPolicy` 现声明 Agent DAG 为首选 implementation workflow:
8
8
 
9
9
  - `defaultImplementationWorkflow=agent-dag`
10
- - `dag.defaultEntry=dag run-task`
11
- - `dag.outputLanguage=zh-CN`;未配置时也默认中文,显式设为 `en` 可切换英文
12
- - `dag.profileRouting`:`minimal|standard -> standard-dag`,`reviewed -> review-gated-dag`,`supervised -> supervised-implementation`
10
+ - `dag.defaultEntry=dag run-task`
11
+ - `dag.outputLanguage=zh-CN`;未配置时也默认中文,显式设为 `en` 可切换英文
12
+ - `dag.profileRouting`:`minimal|standard -> standard-dag`,`reviewed -> review-gated-dag`,`supervised -> supervised-implementation`
13
13
  - `humanGatePolicy.defaultMode=record-only`;需求不清、架构/公共契约风险、凭据/费用/部署风险、重复 gate failure 或高风险决策时升级人工介入
14
14
 
15
- 此 policy 驱动 `dag run-task --profile auto`:CLI 仍要求显式 `dag run-task`、`dag validate`、`run-dag`,但 `--profile auto` 在确定性 candidate `governanceProfile` 推断后应用 `workflowPolicy.dag.profileRouting`。生成器还会把 `outputLanguage` 写入 DagSpec,runner 在每个 Pi/Cursor 节点 prompt 中注入语言规则;代码、命令、路径、JSON 字段与 gate token 保持原样。`humanGatePolicy` 是默认人机边界声明;真实暂停仍由 DAG 节点的 `decisionGate.mode: "pause-on-human"` 与 decision envelope 触发。无 profile 的 `dag run-task <task-id>` 仍为 standard-compatible,供 legacy/review workflow。
15
+ 此 policy 驱动 `dag run-task --profile auto`:CLI 仍要求显式 `dag run-task`、`dag validate`、`run-dag`,但 `--profile auto` 在确定性 candidate `governanceProfile` 推断后应用 `workflowPolicy.dag.profileRouting`。生成器还会把 `outputLanguage` 写入 DagSpec,runner 在每个 Pi/Cursor 节点 prompt 中注入语言规则;代码、命令、路径、JSON 字段与 gate token 保持原样。`humanGatePolicy` 是默认人机边界声明;真实暂停仍由 DAG 节点的 `decisionGate.mode: "pause-on-human"` 与 decision envelope 触发。无 profile 的 `dag run-task <task-id>` 仍为 standard-compatible,供 legacy/review workflow。
16
16
 
17
17
  ### DAG workflow 层级
18
18
 
19
19
  | 优先级 | 入口 | 使用场景 |
20
20
  |-------|-------|----------|
21
21
  | **Primary / Level 3** | `dag run-task --profile auto` / `dag init-hybrid`(已实现) | 从 task `source/` 自动生成 hybrid DAG;`--profile auto` 路由 standard / review-gated / supervised template;无 profile `run-task` 默认为 standard-compatible generate+validate only |
22
- | **Primary / Level 2** | `run-dag --dag <path>` | 跨 Cursor + Pi + shell executor 执行 Agent DAG orchestration |
22
+ | **Primary / Level 2** | `run-dag --dag <path>` | 跨 Pi + shell + static executor 执行 Agent DAG orchestration |
23
23
  历史顺序式 `run analyze|plan|implement|verify|auto|loop|continue` 已移除。trivial one-line 修正时,记录的 main-session surgical patch 仍可能比建 DAG 更省,但它不是第二套 workflow runtime。
24
24
 
25
- **心智模型**:`run-dag` 是 `.` 内自编的 Agent DAG orchestration;Cursor SDK 仅是 `executor: "cursor"` node leaf executor。Cookbook 式 Cursor DAG 示例同样是基于 Cursor SDK local subagent 的 custom DAG runner,不是 Cursor 原生 DAG API。仅可选地借鉴其 observer/streaming/cancel 模式作为 derived feature;不要替换本 repo 的 hybrid schema、`executorModels`、Pi/shell/static executor 或 `.harness/dag-runs` facts。
25
+ **心智模型**:`run-dag` 是 loop-agent 内自编的 Agent DAG orchestration;受治理 Agent leaf executor 只有 Pi。`cursor-prompt` 是独立 sidecar,不是 DAG node executor。不要把 Cursor 重新引入 hybrid schema / `executorModels` / writer 选择。
26
26
 
27
27
  ### Level 2 Agent DAG hybrid(`run-dag`)
28
28
 
@@ -31,10 +31,8 @@ cp examples/hybrid-loop-agent-dag.json <temp-dir>/hybrid-dag.json
31
31
  loop-agent dag validate --dag <temp-dir>/hybrid-dag.json # 常规 validation + ranks;无 dag-runs 副作用
32
32
  loop-agent dag validate --dag <temp-dir>/hybrid-dag.json --strict-models # 非 canonical executorModels 时也失败
33
33
  loop-agent dag validate --dag <temp-dir>/hybrid-dag.json --strict-governance # governance warning(如 read-only artifact drift)时失败
34
- loop-agent dag validate --dag <temp-dir>/hybrid-dag.json --forbid-executor cursor # offline/CI/no-key 显式 no-Cursor;存在 cursor node 时失败
35
- loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --cwd <repo-root> # 执行(若包含 cursor node 则需 CURSOR_API_KEY)
36
- loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --cwd <repo-root> --no-cursor # 存在 cursor node 时执行前失败
37
- loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --init-only --canvas-path <temp-dir>/hybrid-dag.canvas.tsx # 可选 derived Canvas(无需 CURSOR_API_KEY)
34
+ loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --cwd <repo-root> # 执行 Pi/shell/static DAG
35
+ loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --init-only --canvas-path <temp-dir>/hybrid-dag.canvas.tsx # 可选 derived Canvas
38
36
  ```
39
37
 
40
38
  `<temp-dir>` 表示平台原生临时目录;实际命令中 macOS 与 Windows 都使用本机路径。`/` 只作为 repo refs、JSON/Markdown evidence refs 和 glob 约定的稳定分隔符。
@@ -44,7 +42,7 @@ loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --init-only --canvas-path <t
44
42
  **v2 字段**(均可选;缺失时行为同 v1):
45
43
 
46
44
  - 顶层:`objective`、`successCriteria`、`globalConstraints`、`defaults`、`skillsByRole`、`executorModels`
47
- - 每 node:`role`、`skills`、`writePolicy`、`writeSet`、`piStep`、`shell`、`outputContract`、`executor`(`cursor` | `pi` | `shell` | `static`);Pi 写入节点额外声明 `toolProfile: "write"`
45
+ - 每 node:`role`、`skills`、`writePolicy`、`writeSet`、`piStep`、`shell`、`outputContract`、`executor`(`pi` | `shell` | `static`);Pi 写入节点额外声明 `toolProfile: "write"`
48
46
 
49
47
  **Model 生成 DAG 的 template 卫生**:
50
48
 
@@ -54,14 +52,14 @@ loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --init-only --canvas-path <t
54
52
  - 输出独立时优先 same-rank parallel read-only scout(`scout-src`、`scout-tests` 等),而非 serial scout chain。
55
53
  - 仅当 child 真正需要 upstream output 时加 `depends_on`;review 时质疑 single-chain topology。
56
54
  - `exclusive` implementer node 需 narrow、disjoint 的 `writeSet` path;勿用 `**` 或 repo root。
57
- - 默认 no-Cursor DAG 使用 `pi` read-only scouts/reviewers 与 `toolProfile: "write"` exclusive implementer;Cursor 是显式启用的可选 scout / writer backend。
55
+ - 固定 Pi-only DAG:`pi` read-only scouts/reviewers 与 `toolProfile: "write"` exclusive implementer(`implement-pi` / `repair-pi`)。
58
56
  - model routing 用 `executorModels`;勿用 `defaults.model` 或 legacy 顶层 `models`。
59
57
 
60
58
  **运维 warning**:
61
59
 
62
- - **常规 validation**:`dag validate --dag <path>` 做 schema/topology/ranks。JSON 输出含 `governanceProfile`(确定性 `minimal|standard|reviewed|supervised` 推断,含 `process` / `delivery` / `codeChange` signal 与 `reasons`),及 model-matrix drift、governance lint(如 read-only artifact-boundary drift 或 DAG 内 `check-repo.sh` shell env drift)的 warnings。手写临时 DAG spec 执行前用 `dag validate --dag <path> --strict-models`;governance warning 应 fail fast 时加 `--strict-governance`。no-Cursor 环境用 `dag validate --dag <path> --forbid-executor cursor` `run-dag --no-cursor` 捕获显式 Cursor 节点;默认生成 DAG 应使用 `pi` read-only / Pi write profile / shell。仅当有意在 `.harness/dag-runs/active/` 要 active run snapshot 时用 `run-dag --dry-run`。
60
+ - **常规 validation**:`dag validate --dag <path>` 做 schema/topology/ranks。JSON 输出含 `governanceProfile`(确定性 `minimal|standard|reviewed|supervised` 推断,含 `process` / `delivery` / `codeChange` signal 与 `reasons`),及 model-matrix drift、governance lint(如 read-only artifact-boundary drift 或 DAG 内 `check-repo.sh` shell env drift)的 warnings。手写临时 DAG spec 执行前用 `dag validate --dag <path> --strict-models`;governance warning 应 fail fast 时加 `--strict-governance`。含 `executor: "cursor"` 的旧 DAG 会在 schema 校验失败;默认生成 DAG 使用 `pi` read-only / Pi write profile / shell。仅当有意在 `.harness/dag-runs/active/` 要 active run snapshot 时用 `run-dag --dry-run`。
63
61
  - **Governance profile 推断与 routing(code vs skill 分工)**:`./src/workflows/dag/governance-profile.ts` 从 DAG 结构与 write scope 做 **硬确定性推断**。JSON 输出 **报告** `process` / `delivery` / `codeChange` signal 与人类可读 `reasons`;`profile` tier(`minimal|standard|reviewed|supervised`)仅由该模块 code rule 选择(如多个 exclusive writer、repair node、review-gate topology、`loop-agent-runtime-paths`、`scripts-ci-harness-paths`、weak post-implementation shell verification、supervised topology)。baseline `forbiddenPaths`(`.harness/**`、`.harness/dag-runs/**`、`artifacts/**`)是默认 governance,**本身不是** process-risk signal。skill prompt 与本 reference **解释** tier 并摘要 profile 选择原因;不替代 code 推断。`dag run-task` 转发 embedded validate step 的同一 candidate `governanceProfile`。`dag run-task --profile auto` 先将 candidate profile 经 `harness.json.workflowPolicy.dag.profileRouting` 映射,再在 candidate delivery signal 含 `loop-agent-runtime-paths`、`scripts-ci-harness-paths` 或 `public-contract-paths` 时应用 M4 `supervised-quality-gate` promotion;`profileRouting.routingReasons` 记录确定性 reason。无 profile `dag run-task <task-id>` 仍为 standard-compatible;显式 `--profile minimal|standard|reviewed|supervised` 强制对应 template family(当前 policy 下 minimal/standard 路由到 `standard-dag`),高风险 task 应用 `--profile auto` 或显式 `--profile supervised`,而非显式 `--profile reviewed`。
64
- - **Executor model routing**:DAG spec 选 `executor` 与 `complexity`,可通过 `executorModels` 覆盖 `cursor` / `pi` 的 model 名;不选 provider。默认 routing:Cursor 各 complexity 用 `composer-2.5`;Pi read-only 与 Pi write profile 共用 LOW=`wizard-local/gpt-5.3-codex-spark`、MED=`wizard-local/glm-5.2`、HIGH=`wizard-local/gpt-5.5`。`shell` 不用 model,忽略 `executorModels`。
62
+ - **Executor model routing**:DAG spec 选 `executor` 与 `complexity`,可通过 `executorModels.pi` 覆盖 model 名;不选 provider。默认 routing:Pi LOW=`gpt-5.3-codex-spark`、MED=`glm-5.2`、HIGH=`gpt-5.5`。`shell` 不用 model,忽略 `executorModels`。
65
63
  - **Active visibility**:真实 `run-dag` execution 在 run/node 转换时写 active `state.json`,归档前 core runner 暴露 isolated `DagRunObserver` hook 供 derived view。`.harness/dag-runs/completed/<run-id>/` / `paused/<run-id>/` 仍是 source of truth;observer 输出非 canonical。
66
64
  - **可选 Canvas**:传 `--canvas-path <abs-path>` 或 `--canvas <name>` 输出 derived `.canvas.tsx` live view。省略 flag 行为不变。`--init-only` + Canvas 无需 `CURSOR_API_KEY`。
67
65
 
@@ -102,7 +100,7 @@ contract-pi → scout-src ∥ scout-tests → plan-pi → write-set-audit-pi
102
100
  | `soft-verify-shell` | supervision 前归档 focused test exit code |
103
101
  | `process-supervisor-pi` | read-only audit coverage、boundary drift、verify gap、repair scope;应 prominently 输出 `VERDICT: pass` 或 `VERDICT: request-revision` |
104
102
  | `process-gate-shell` | supervisor node JSON 上 runtime `shell.verdictGate`(仅 `pass` 或 `request-revision`) |
105
- | `repair-pi` / optional `repair-cursor` | supervisor 请求 revision 时在 repair `writeSet` 内 bounded exclusive fix |
103
+ | `repair-pi` | supervisor 请求 revision 时在 repair `writeSet` 内 bounded exclusive fix |
106
104
  | `hard-verify-shell` | lint/typecheck + `HARNESS_ALLOW_ACTIVE_DAG_RUNS=1 check-repo.sh` fact |
107
105
  | `authority-surface-audit-pi` + `authority-surface-gate-shell` | 可选 permission/state/tool-exposure audit;仅 authority signal 或显式 `authority-surface-audit` marker 时插入;gate 仅接受 `VERDICT: pass` |
108
106
  | `review-pi` + `review-gate-shell` | Critical/Important → `request-revision`;node JSON 上 `shell.verdictGate` block,除非 extracted verdict 行为 `VERDICT: pass` |
@@ -124,7 +122,6 @@ loop-agent dag run-task <task-id> --profile standard
124
122
  loop-agent dag run-task <task-id> --profile reviewed # 强制 review-gated DAG
125
123
  loop-agent dag run-task <task-id> --profile supervised # 强制 supervised implementation DAG
126
124
  loop-agent dag run-task <task-id> --strict-models # 非 canonical executorModels 时失败
127
- loop-agent dag run-task <task-id> --no-cursor # 显式 no-Cursor 校验;generated cursor node 时失败
128
125
  loop-agent dag run-task <task-id> --execute --cwd <repo-root> # 要求 narrowed implement writeSet
129
126
  loop-agent dag run-task <task-id> --dry-run --cwd <repo-root> # active snapshot 于 .harness/dag-runs/active/
130
127
  loop-agent dag run-task <task-id> --init-only --cwd <repo-root> # pending active snapshot,不执行 node
@@ -212,6 +209,6 @@ review-heavy DAG 中长 shell stdout 可能掩盖 proof 时,用 **evidence-sum
212
209
  | 10 | writeSet planning | scout 应列出链接的 `./skill/references/**` 为 **writeSet expansion candidates**(P2:遗漏链接 skill ref 迫使 main-session patch) |
213
210
  | 11 | Evidence summary | `evidence-summary-shell` / leading `EVIDENCE:` 行是 **practice convention**,非 runtime executor、schema field 或 parser |
214
211
  | 12 | Featureization | 除非 repeated real-run failure 证明 checklist guidance 不够,勿加 runtime/schema/validator/CLI/executor feature |
215
- | 13 | writeSet / writer backend | `exclusive` node 用 narrow、disjoint path;无 `**`;默认用 Pi write profile,仅在显式启用且 task-fit 时用 Cursor |
212
+ | 13 | writeSet / writer backend | `exclusive` node 用 narrow、disjoint path;无 `**`;固定用 Pi write profile |
216
213
  | 14 | Placeholders | 执行前将 `REPLACE/WITH/...` 换为具体 path |
217
214
  | 15 | Governance | in-flight shell:`HARNESS_ALLOW_ACTIVE_DAG_RUNS=1 bash scripts/check-repo.sh`;archive 后:裸 `bash scripts/check-repo.sh` |
@@ -9,11 +9,10 @@ loop-agent loop init <task-id>
9
9
  loop-agent loop status <task-id>
10
10
  loop-agent loop run <task-id> --action shell-verify --command "bash scripts/check-repo.sh"
11
11
  loop-agent loop run <task-id> --action pi-review
12
- loop-agent loop run <task-id> --action cursor-fix --model composer-2.5
13
12
  loop-agent loop run <task-id> --action dag
14
13
  loop-agent loop run <task-id> --action dag --execute
15
14
  loop-agent loop run <task-id> --auto --max-rounds 3
16
- loop-agent loop run <task-id> --auto --max-rounds 3 --allow-cursor-fix
15
+ loop-agent loop run <task-id> --auto --max-rounds 3
17
16
  loop-agent loop add-signal <task-id> --type human_followup --message "review this boundary before closeout"
18
17
  loop-agent loop closeout <task-id>
19
18
  loop-agent loop record-round <task-id> \
@@ -36,15 +35,14 @@ loop-agent loop record-round <task-id> \
36
35
 
37
36
  - `loop run --action shell-verify` 是 deterministic action;命令 exit code 决定 verification result,输出摘要写入 `loop/verification/round-N.json`。
38
37
  - `loop run --action pi-review` 必须保持 read-only;工具 allowlist 固定为 `read,grep,find,ls`,输出必须包含 `findingSummary`、`failureCategory`、`nextHypothesis`、`recommendedAction`、`fixScope`、`rootCause`,其中 `recommendedAction` 只能是 `implement_fix|replan|pause|done`。
39
- - `loop run --action cursor-fix` 必须读取 task `allowedPaths` / `forbiddenPaths`,拒绝空 allowedPaths allowed/forbidden overlap;对 `complexity=medium|large` 的任务,还必须已有 loop `dag` round 证据,或在 `task.json.dagFallbackReason` 中写明 DAG runtime fallback 原因。调用现有 Cursor bounded executor,并把 one-shot evidence 归档到 `.harness/runs/completed|failed/`。
40
- - `cursor-fix` 只表示 bounded write round 已执行;它不会把 loop 标记 complete,下一步必须进入 `shell-verify` 或 review。
38
+ - 自动写入只能通过 `loop run --action dag --execute` / auto DAG execute;须读取 task `allowedPaths` / `forbiddenPaths` 并审查 writer writeSet。
41
39
  - `loop run --action dag` 默认是 review mode:调用 `dag run-task <task-id> --profile auto --strict-models` 生成 DAG,再用 `dag validate --strict-models --strict-governance` 校验,并记录 review packet。
42
40
  - `loop run --action dag --execute` 才会调用 `run-dag`,随后读取 `dag report --json` 作为 round result;paused DAG 会让 loop 进入 `paused`。
43
41
 
44
42
  ## Auto mode 与写入边界
45
43
 
46
- - `loop run --auto --max-rounds N` 使用 deterministic policy 选择下一轮 action;默认只会自动选择 shell-verify、pi-review、dag review 或 policy pause/block,不自动触发 Cursor 写入。
47
- - 自动 `cursor-fix` 必须显式 opt-in:`task.json.loopAutoWritePolicy="enabled"`,或 `loopAutoWritePolicy="approval-required"` 加 pending approval signal / `--allow-cursor-fix`。即使 opt-in,也必须通过 `allowedPaths`/`forbiddenPaths`/DAG evidence guard;guard 失败会 pause,不会绕过写入边界。
44
+ - `loop run --auto --max-rounds N` 使用 deterministic policy 选择下一轮 action;默认只会自动选择 shell-verify、pi-review、dag review 或 policy pause/block
45
+ - 自动 DAG execute 必须显式 opt-in:`task.json.loopAutoExecutionPolicy="enabled"`,或 `approval-required` 加 pending approval;旧 `loopAutoWritePolicy` fail-fast。
48
46
  - auto mode 遇到同类 failure streak 达阈值会 blocked,避免无限重试。
49
47
 
50
48
  ## Signals
@@ -17,12 +17,12 @@
17
17
  ### 核心命令
18
18
 
19
19
  ```bash
20
- loop-agent delegate <task-id> [--executor pi|cursor] [--base <branch>] [--branch <name>] [--no-symlink] [--auto-run] [--no-auto-run]
20
+ loop-agent delegate <task-id> [--base <branch>] [--branch <name>] [--no-symlink] [--auto-run]
21
21
  loop-agent harvest <task-id> [--squash] [--no-archive] [--keep-worktree]
22
22
  loop-agent worktree list
23
23
  ```
24
24
 
25
- `delegate` 是一步原子操作:校验 `task.json` + `source/需求.md` + `source/执行约束.md` → 在 branch `task/<task-id>` 上创建 `git worktree .worktrees/<task-id>` → 同步 `source/` 与 `task.json` 到 worktree → 相对 symlink `./node_modules` cursor 默认 in-process SDK direct;Pi `--auto-run` 已移除并会提示 DAG 路径。
25
+ `delegate` 是一步原子操作:校验 `task.json` + `source/需求.md` + `source/执行约束.md` → 在 branch `task/<task-id>` 上创建 `git worktree .worktrees/<task-id>` → 同步 `source/` 与 `task.json` 到 worktree → 相对 symlink `./node_modules`。默认只准备 worktree;显式 `--auto-run` 才在其中生成、严格校验并执行 Pi-only DAG
26
26
 
27
27
  `harvest` 是对称 closeout:仅当 `task.status === "completed"` 才运行,然后 merge(默认 `--no-ff`,或 `--squash`),将 `artifacts/`、`logs/`、`.workflow_state.json` 归档回主 repo,移除 worktree + branch。
28
28
 
@@ -37,8 +37,8 @@ loop-agent worktree list
37
37
  ### 生命周期概览
38
38
 
39
39
  ```
40
- delegate → executorspec/implement/verify → completed → harvest → archive + cleanup
41
- ↘ failed → worktree 内排障(不 harvest)
40
+ delegate --auto-run Pi DAG contract/scout/plan/implement/verify → completed → harvest → archive + cleanup
41
+ ↘ failed → worktree 内排障(不 harvest)
42
42
  ```
43
43
 
44
44
  ### 失败处理
@@ -49,6 +49,6 @@ delegate → executor 跑 spec/implement/verify → completed → harvest → ar
49
49
 
50
50
  ### 与 Agent DAG 的关系
51
51
 
52
- Agent DAG 是默认 autonomous path;`delegate`/`harvest` cursor-direct worktree escape hatch。多 task 并行时,每个 task 独立 `delegate`,完成后分别 `harvest`。
52
+ Agent DAG 是默认 autonomous path;`delegate`/`harvest` 提供 worktree 隔离与收口,`--auto-run` 仍只运行 Pi-only DAG。需要人工 Cursor 介入时使用独立的 `cursor-prompt` sidecar,不进入 delegate DAG runtime。多 task 并行时,每个 task 独立 `delegate`,完成后分别 `harvest`。
53
53
 
54
- 详见 `docs/cursor-executor-usage.md` 与 `docs/loop-agent-harness.md`。
54
+ 详见 `docs/cursor-prompt-sidecar.md` 与 `docs/loop-agent-harness.md`。
@@ -8,7 +8,7 @@
8
8
 
9
9
  `harness.json.workflowPolicy` 的 repo 级 policy 将 Agent DAG 作为 autonomous 与 harness-governed work 的 implementation workflow。历史顺序式 `run ...` workflow 已移除。
10
10
 
11
- main session 是 decision-maker 与 scheduler,不是默认 implementer。其稀缺 context 应留给 objective 对齐、DAG review、failure triage、executor 选择、verification review 与 handoff。长时 implementation 应委派给 Agent DAG node、Cursor、Pi、shell 或 worktree delegate。
11
+ main session 是 decision-maker 与 scheduler,不是默认 implementer。其稀缺 context 应留给 objective 对齐、DAG review、failure triage、executor 选择、verification review 与 handoff。长时 implementation 应委派给 Pi-only Agent DAG node、shell verification 或 worktree delegate;Cursor 仅作为显式 one-shot sidecar
12
12
 
13
13
  这不是绝对禁止 edit。main-session 手动 edit 仅允许作为有 verification 与 artifact 记录的 bounded surgical patch。
14
14
 
@@ -18,7 +18,7 @@ main session 是 decision-maker 与 scheduler,不是默认 implementer。其
18
18
  |---|---|---|
19
19
  | Main session | Objective、contract、DAG review、routing、failure triage、approve/reject/resume、handoff | 成为长时 coder |
20
20
  | Agent DAG runner | 可恢复 multi-node orchestration、rank-parallel execution、write policy、run artifacts | 不更新 DAG/source 的 ad-hoc replanning |
21
- | Cursor executor / prompt | Codebase-indexed search、multi-file implementation、bounded refactor/fix | narrow `writeSet` / path scope 的宽写入 |
21
+ | Cursor one-shot prompt | 有界诊断、人工介入的小修复或 executor 调试 | 作为 DAG executor、自动写入路径或无 path scope 的宽写入 |
22
22
  | Pi executor / prompt | Fast reasoning、read-only scouting、planning、review、decision-envelope advice | 充当 hidden state source |
23
23
  | Shell executor | 确定性事实:tests、lint、typecheck、build、governance checks | 智能 repair |
24
24
  | Human gate | Product、architecture、risk、permission 决策 | 常规 implementation debugging |
@@ -130,7 +130,7 @@ main session 编排;不是默认 implementer。in-flight run 期间:
130
130
 
131
131
  坏例子:
132
132
 
133
- - 手工按 `artifacts/实现计划.md` implement feature。
133
+ - 手工按 task `artifacts/实现计划.md` 或根 `artifacts/` 实现功能(应走 DAG plan/implement 节点或 exec-plan)。
134
134
  - 不委派就修大量 test failure。
135
135
  - 改 API/contract 语义。
136
136
  - refactor 子系统。
@@ -62,20 +62,23 @@ pi -p --no-session --no-context-files --no-skills --tools subagent "Reply with e
62
62
 
63
63
  **Agents**(`.pi/agents/`)
64
64
 
65
- | Agent | Role | Model |
66
- |-------|------|-------|
67
- | `loop-agent-scout` | Read-only recon:code、tests、docs、governance | `cursor/composer-2.5` |
68
- | `loop-agent-planner` | Implementation planning:最小可执行 plan | `cursor/composer-2.5` |
69
- | `loop-agent-reviewer` | Strict review:scope drift、verification gap、contract break | `cursor/composer-2.5` |
70
- | `loop-agent-worker` | General execution:bounded implementation 与 fix | `cursor/composer-2.5` |
65
+ | Agent | Role | 对应阶段 |
66
+ |-------|------|----------|
67
+ | `loop-agent-scout` | 只读侦察:code、tests、docs、governance | Scout |
68
+ | `loop-agent-planner` | 最小可执行计划;强调验证与回退 | Plan |
69
+ | `loop-agent-reviewer` | 严格审查:范围漂移、验证缺口、契约破坏 | Verify / Review |
70
+ | `loop-agent-worker` | 有界实现与修补 | Implement |
71
71
 
72
- **Prompt Templates**(`.pi/prompts/`):输入 `/loop-agent-*` 调用
72
+ 另有通用 agents:`scout` / `planner` / `worker` / `reviewer`(中文提示,可被通用 prompt 模板调用)。模型以各 agent frontmatter 为准(当前仓库默认对齐 `harness.json` 的 Pi executor)。
73
+
74
+ **Prompt Templates**(`.pi/prompts/`):输入 `/loop-agent-*` 或通用模板名调用
73
75
 
74
76
  | Template | Flow |
75
77
  |----------|------|
76
- | `loop-agent-scout-and-plan` | scout → planner chain |
77
- | `loop-agent-analyze-wide` | 3 parallel scouts → analysis |
78
- | `loop-agent-review-only` | 独立 review plan/implementation/verification |
79
- | `loop-agent-implement-and-review` | worker → reviewer → worker loop |
78
+ | `loop-agent-scout-and-plan` | parallel scout → planner |
79
+ | `loop-agent-analyze-wide` | 3 parallel scouts → 结构化分析 |
80
+ | `loop-agent-review-only` | 独立审查计划/实现/验证 |
81
+ | `loop-agent-implement-and-review` | worker → reviewer → worker |
82
+ | `scout-and-plan` / `implement` / `implement-and-review` | 通用 chain(调用 `scout`/`planner`/`worker`/`reviewer`) |
80
83
 
81
84
  传 `agentScope: "both"` + `confirmProjectAgents: false` 以访问 repo-local agents。
@@ -77,7 +77,7 @@ loop-agent --repo-root /path/to/target-repo <command>
77
77
 
78
78
  ## Verification
79
79
 
80
- 完成声明必须来自新鲜验证证据。按目标 repo 的 `docs/verification-matrix.md` 选择最小证明命令;loop-agent 自身常用:
80
+ 完成声明必须来自新鲜验证证据。按目标 repo 的 `harness.json.governanceRoot` 下 `verification-matrix.md` 选择最小证明命令;loop-agent 自身常用:
81
81
 
82
82
  ```bash
83
83
  npm run typecheck
@@ -0,0 +1,215 @@
1
+ ---
2
+ name: using-git-worktrees
3
+ description: Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback
4
+ ---
5
+
6
+ # Using Git Worktrees
7
+
8
+ ## Overview
9
+
10
+ Ensure work happens in an isolated workspace. Prefer your platform's native worktree tools. Fall back to manual git worktrees only when no native tool is available.
11
+
12
+ **Core principle:** Detect existing isolation first. Then use native tools. Then fall back to git. Never fight the harness.
13
+
14
+ **Announce at start:** "I'm using the using-git-worktrees skill to set up an isolated workspace."
15
+
16
+ ## Step 0: Detect Existing Isolation
17
+
18
+ **Before creating anything, check if you are already in an isolated workspace.**
19
+
20
+ ```bash
21
+ GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
22
+ GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
23
+ BRANCH=$(git branch --show-current)
24
+ ```
25
+
26
+ **Submodule guard:** `GIT_DIR != GIT_COMMON` is also true inside git submodules. Before concluding "already in a worktree," verify you are not in a submodule:
27
+
28
+ ```bash
29
+ # If this returns a path, you're in a submodule, not a worktree — treat as normal repo
30
+ git rev-parse --show-superproject-working-tree 2>/dev/null
31
+ ```
32
+
33
+ **If `GIT_DIR != GIT_COMMON` (and not a submodule):** You are already in a linked worktree. Skip to Step 3 (Project Setup). Do NOT create another worktree.
34
+
35
+ Report with branch state:
36
+ - On a branch: "Already in isolated workspace at `<path>` on branch `<name>`."
37
+ - Detached HEAD: "Already in isolated workspace at `<path>` (detached HEAD, externally managed). Branch creation needed at finish time."
38
+
39
+ **If `GIT_DIR == GIT_COMMON` (or in a submodule):** You are in a normal repo checkout.
40
+
41
+ Has the user already indicated their worktree preference in your instructions? If not, ask for consent before creating a worktree:
42
+
43
+ > "Would you like me to set up an isolated worktree? It protects your current branch from changes."
44
+
45
+ Honor any existing declared preference without asking. If the user declines consent, work in place and skip to Step 3.
46
+
47
+ ## Step 1: Create Isolated Workspace
48
+
49
+ **You have two mechanisms. Try them in this order.**
50
+
51
+ ### 1a. Native Worktree Tools (preferred)
52
+
53
+ The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like `EnterWorktree`, `WorktreeCreate`, a `/worktree` command, or a `--worktree` flag. If you do, use it and skip to Step 3.
54
+
55
+ Native tools handle directory placement, branch creation, and cleanup automatically. Using `git worktree add` when you have a native tool creates phantom state your harness can't see or manage.
56
+
57
+ Only proceed to Step 1b if you have no native worktree tool available.
58
+
59
+ ### 1b. Git Worktree Fallback
60
+
61
+ **Only use this if Step 1a does not apply** — you have no native worktree tool available. Create a worktree manually using git.
62
+
63
+ #### Directory Selection
64
+
65
+ Follow this priority order. Explicit user preference always beats observed filesystem state.
66
+
67
+ 1. **Check your instructions for a declared worktree directory preference.** If the user has already specified one, use it without asking.
68
+
69
+ 2. **Check for an existing project-local worktree directory:**
70
+ ```bash
71
+ ls -d .worktrees 2>/dev/null # Preferred (hidden)
72
+ ls -d worktrees 2>/dev/null # Alternative
73
+ ```
74
+ If found, use it. If both exist, `.worktrees` wins.
75
+
76
+ 3. **Check for an existing global directory:**
77
+ ```bash
78
+ project=$(basename "$(git rev-parse --show-toplevel)")
79
+ ls -d ~/.worktrees 2>/dev/null
80
+ ```
81
+ If found, use it.
82
+
83
+ 4. **If there is no other guidance available**, default to `.worktrees/` at the project root.
84
+
85
+ #### Safety Verification (project-local directories only)
86
+
87
+ **MUST verify directory is ignored before creating worktree:**
88
+
89
+ ```bash
90
+ git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
91
+ ```
92
+
93
+ **If NOT ignored:** Add to .gitignore, commit the change, then proceed.
94
+
95
+ **Why critical:** Prevents accidentally committing worktree contents to repository.
96
+
97
+ Global directories (`~/.worktrees/`) need no verification.
98
+
99
+ #### Create the Worktree
100
+
101
+ ```bash
102
+ project=$(basename "$(git rev-parse --show-toplevel)")
103
+
104
+ # Determine path based on chosen location
105
+ # For project-local: path="$LOCATION/$BRANCH_NAME"
106
+ # For global: path="~/.worktrees/$BRANCH_NAME"
107
+
108
+ git worktree add "$path" -b "$BRANCH_NAME"
109
+ cd "$path"
110
+ ```
111
+
112
+ **Sandbox fallback:** If `git worktree add` fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation and you're working in the current directory instead. Then run setup and baseline tests in place.
113
+
114
+ ## Step 3: Project Setup
115
+
116
+ Auto-detect and run appropriate setup:
117
+
118
+ ```bash
119
+ # Node.js
120
+ if [ -f package.json ]; then npm install; fi
121
+
122
+ # Rust
123
+ if [ -f Cargo.toml ]; then cargo build; fi
124
+
125
+ # Python
126
+ if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
127
+ if [ -f pyproject.toml ]; then poetry install; fi
128
+
129
+ # Go
130
+ if [ -f go.mod ]; then go mod download; fi
131
+ ```
132
+
133
+ ## Step 4: Verify Clean Baseline
134
+
135
+ Run tests to ensure workspace starts clean:
136
+
137
+ ```bash
138
+ # Use project-appropriate command
139
+ npm test / cargo test / pytest / go test ./...
140
+ ```
141
+
142
+ **If tests fail:** Report failures, ask whether to proceed or investigate.
143
+
144
+ **If tests pass:** Report ready.
145
+
146
+ ### Report
147
+
148
+ ```
149
+ Worktree ready at <full-path>
150
+ Tests passing (<N> tests, 0 failures)
151
+ Ready to implement <feature-name>
152
+ ```
153
+
154
+ ## Quick Reference
155
+
156
+ | Situation | Action |
157
+ |-----------|--------|
158
+ | Already in linked worktree | Skip creation (Step 0) |
159
+ | In a submodule | Treat as normal repo (Step 0 guard) |
160
+ | Native worktree tool available | Use it (Step 1a) |
161
+ | No native tool | Git worktree fallback (Step 1b) |
162
+ | `.worktrees/` exists | Use it (verify ignored) |
163
+ | `worktrees/` exists | Use it (verify ignored) |
164
+ | Both exist | Use `.worktrees/` |
165
+ | Neither exists | Check instruction file, then default `.worktrees/` |
166
+ | Global path exists | Use it (backward compat) |
167
+ | Directory not ignored | Add to .gitignore + commit |
168
+ | Permission error on create | Sandbox fallback, work in place |
169
+ | Tests fail during baseline | Report failures + ask |
170
+ | No package.json/Cargo.toml | Skip dependency install |
171
+
172
+ ## Common Mistakes
173
+
174
+ ### Fighting the harness
175
+
176
+ - **Problem:** Using `git worktree add` when the platform already provides isolation
177
+ - **Fix:** Step 0 detects existing isolation. Step 1a defers to native tools.
178
+
179
+ ### Skipping detection
180
+
181
+ - **Problem:** Creating a nested worktree inside an existing one
182
+ - **Fix:** Always run Step 0 before creating anything
183
+
184
+ ### Skipping ignore verification
185
+
186
+ - **Problem:** Worktree contents get tracked, pollute git status
187
+ - **Fix:** Always use `git check-ignore` before creating project-local worktree
188
+
189
+ ### Assuming directory location
190
+
191
+ - **Problem:** Creates inconsistency, violates project conventions
192
+ - **Fix:** Follow priority: existing > global legacy > instruction file > default
193
+
194
+ ### Proceeding with failing tests
195
+
196
+ - **Problem:** Can't distinguish new bugs from pre-existing issues
197
+ - **Fix:** Report failures, get explicit permission to proceed
198
+
199
+ ## Red Flags
200
+
201
+ **Never:**
202
+ - Create a worktree when Step 0 detects existing isolation
203
+ - Use `git worktree add` when you have a native worktree tool (e.g., `EnterWorktree`). This is the #1 mistake — if you have it, use it.
204
+ - Skip Step 1a by jumping straight to Step 1b's git commands
205
+ - Create worktree without verifying it's ignored (project-local)
206
+ - Skip baseline test verification
207
+ - Proceed with failing tests without asking
208
+
209
+ **Always:**
210
+ - Run Step 0 detection first
211
+ - Prefer native tools over git fallback
212
+ - Follow directory priority: existing > global legacy > instruction file > default
213
+ - Verify directory is ignored for project-local
214
+ - Auto-detect and run project setup
215
+ - Verify clean test baseline
@@ -1,43 +0,0 @@
1
- import { executeCursorTaskViaWorker, getCursorWorkerEntryPath, isCursorWorkerChild, isCursorWorkerEnabled, isCursorWorkerRunning, stopCursorWorker, } from '../executors/cursor-worker-client.js';
2
- export function parseCursorWorkerArgs(args) {
3
- const action = args[0];
4
- if (action === 'status' || action === 'stop' || action === 'ping') {
5
- return { action };
6
- }
7
- throw new Error('usage: cursor-worker <status|stop|ping>');
8
- }
9
- export async function runCursorWorker(repoRoot, rawArgs) {
10
- const { action } = parseCursorWorkerArgs(rawArgs);
11
- if (action === 'status') {
12
- console.log(JSON.stringify({
13
- enabled: isCursorWorkerEnabled(),
14
- running: isCursorWorkerRunning(),
15
- child: isCursorWorkerChild(),
16
- entry: getCursorWorkerEntryPath(),
17
- repoRoot,
18
- }, null, 2));
19
- return;
20
- }
21
- if (action === 'stop') {
22
- await stopCursorWorker();
23
- console.log('cursor worker stopped');
24
- return;
25
- }
26
- if (action === 'ping') {
27
- if (!isCursorWorkerEnabled()) {
28
- console.error('Set CURSOR_USE_WORKER=1 to enable the worker path.');
29
- }
30
- try {
31
- const result = await executeCursorTaskViaWorker({
32
- task: 'Reply with exactly: WORKER_PING_OK',
33
- cwd: repoRoot,
34
- model: 'default',
35
- timeoutMs: 120_000,
36
- });
37
- console.log(JSON.stringify({ ok: result.ok, stdout: result.stdout.trim() }, null, 2));
38
- }
39
- finally {
40
- await stopCursorWorker();
41
- }
42
- }
43
- }
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Long-lived Cursor SDK worker (NDJSON on stdin/stdout).
4
- * Spawned by cursor-worker-client when CURSOR_USE_WORKER=1.
5
- */
6
- import { runCursorWorkerOnStreams } from './executors/cursor-worker-server.js';
7
- process.env.CURSOR_WORKER_CHILD = '1';
8
- await runCursorWorkerOnStreams(process.stdin, process.stdout);
@@ -1,33 +0,0 @@
1
- const MODIFY_LOG_MARKERS = ['修改摘要', '修改文件', '验证', '风险'];
2
- const VERIFY_RESULT_MARKERS = ['命令', 'exit', 'pass', 'fail', '未运行'];
3
- export function validateCursorModifyLog(content) {
4
- const trimmed = content.trim();
5
- if (!trimmed)
6
- return ['修改记录.md is empty'];
7
- if (!trimmed.includes('# 修改记录'))
8
- return ['修改记录.md missing heading: # 修改记录'];
9
- const missing = MODIFY_LOG_MARKERS.filter((marker) => !trimmed.includes(marker));
10
- return missing.map((marker) => `修改记录.md missing section marker: ${marker}`);
11
- }
12
- export function validateCursorVerifyResult(content) {
13
- const trimmed = content.trim();
14
- if (!trimmed)
15
- return ['验证结果.md is empty'];
16
- if (!trimmed.includes('# 验证结果'))
17
- return ['验证结果.md missing heading: # 验证结果'];
18
- const hasCommandMarker = VERIFY_RESULT_MARKERS.some((marker) => trimmed.toLowerCase().includes(marker.toLowerCase()));
19
- if (!hasCommandMarker) {
20
- return ['验证结果.md missing verification command / exit / pass-fail evidence'];
21
- }
22
- return [];
23
- }
24
- export function validateCursorArtifacts(modifyLog, verifyResult) {
25
- return [
26
- ...validateCursorModifyLog(modifyLog),
27
- ...validateCursorVerifyResult(verifyResult),
28
- ];
29
- }
30
- export function isEmptyArtifactTemplate(content, templateMarker) {
31
- const trimmed = content.trim();
32
- return trimmed.includes(templateMarker) && trimmed.split('\n').filter((line) => line.trim().length > 0).length <= 3;
33
- }
@@ -1,81 +0,0 @@
1
- import { access, appendFile, mkdir } from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { buildCursorPrompt, buildRedactedExecutorRecord, } from './cursor-executor.js';
4
- import { appendExecutorRecord } from '../shared/logger.js';
5
- export function resolveDelegateExecutionMode(executor) {
6
- if (executor === 'pi')
7
- return 'pi-worktree';
8
- if (executor === 'cursor')
9
- return 'direct';
10
- return undefined;
11
- }
12
- export function buildCursorExecutionLogRecord(input) {
13
- const base = buildRedactedExecutorRecord({
14
- executor: 'cursor',
15
- model: input.model,
16
- durationMs: input.result.durationMs,
17
- failureCategory: input.result.failureCategory,
18
- ok: input.result.ok,
19
- status: input.result.status,
20
- prompt: input.prompt,
21
- result: input.result,
22
- apiKey: input.apiKey,
23
- });
24
- return {
25
- ...base,
26
- channel: input.context.channel,
27
- executionMode: input.context.executionMode,
28
- cwd: input.context.cwd,
29
- taskId: input.context.taskId,
30
- dagRunId: input.context.dagRunId,
31
- dagNodeId: input.context.dagNodeId,
32
- recordedAt: new Date().toISOString(),
33
- };
34
- }
35
- export async function persistCursorExecutionLog(logsDir, record, fileName = 'executor.jsonl') {
36
- await mkdir(logsDir, { recursive: true });
37
- await appendFile(path.join(logsDir, fileName), `${JSON.stringify(record)}\n`, 'utf-8');
38
- }
39
- /** Append a unified record to `<taskDir>/logs/executor.jsonl`. */
40
- export async function appendCursorExecutionLog(taskDir, record) {
41
- await appendExecutorRecord(taskDir, record);
42
- }
43
- export async function persistCursorToolExecution(cwd, input) {
44
- try {
45
- await access(path.join(cwd, '.harness'));
46
- }
47
- catch {
48
- return;
49
- }
50
- const cacheDir = path.join(cwd, '.harness', 'cache');
51
- const record = buildCursorExecutionLogRecord({
52
- context: { channel: 'tool', cwd },
53
- model: input.model,
54
- prompt: buildCursorPrompt(input.task),
55
- result: input.result,
56
- apiKey: input.apiKey,
57
- });
58
- await persistCursorExecutionLog(cacheDir, record, 'cursor-executions.jsonl');
59
- }
60
- export function formatCursorFailureMessage(category) {
61
- switch (category) {
62
- case 'missing-api-key':
63
- return 'CURSOR_API_KEY is not set.';
64
- case 'auth':
65
- return 'Cursor API authentication failed.';
66
- case 'network':
67
- return 'Cursor API network error.';
68
- case 'timeout':
69
- return 'Cursor execution timed out.';
70
- case 'invalid-output':
71
- return 'Cursor output or artifacts are invalid.';
72
- case 'path-violation':
73
- return 'Cursor task violated path boundaries.';
74
- case 'nonzero-exit':
75
- return 'Cursor agent did not complete successfully.';
76
- case 'success':
77
- return 'OK';
78
- default:
79
- return 'Cursor execution failed.';
80
- }
81
- }