@tea-agent/loop-agent 0.10.0 → 0.12.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.
- package/AGENTS.md +10 -2
- package/CHANGELOG.md +91 -24
- package/README.md +84 -12
- package/dist/application/dag/args.js +1 -12
- package/dist/application/dag/generate-task-dag.js +38 -2
- package/dist/application/dag/run-dag.js +11 -27
- package/dist/application/dag/validate-dag.js +13 -2
- package/dist/application/loop/run-action.js +0 -4
- package/dist/cli/command-definitions.js +44 -16
- package/dist/cli/program.js +40 -23
- package/dist/cli/update/notifier.js +117 -0
- package/dist/cli/update/npm-client.js +151 -0
- package/dist/cli/update/policy.js +58 -0
- package/dist/cli/update/state.js +68 -0
- package/dist/cli.js +33 -0
- package/dist/commands/cursor-prompt.js +42 -82
- package/dist/commands/dag-approve.js +36 -0
- package/dist/commands/delegate.js +75 -77
- package/dist/commands/doctor.js +0 -18
- package/dist/commands/init.js +547 -95
- package/dist/commands/instructions.js +7 -10
- package/dist/commands/loop.js +4 -20
- package/dist/commands/plan.js +50 -0
- package/dist/executors/config-core.js +0 -51
- package/dist/executors/dag-pi-executor.js +1 -1
- package/dist/executors/dag.js +0 -1
- package/dist/executors/index.js +0 -2
- package/dist/executors/model-routing.js +9 -9
- package/dist/executors/shell-executor.js +1 -1
- package/dist/governance/checks.js +6 -3
- package/dist/governance/exec-plans.js +545 -0
- package/dist/governance/manifest-types.js +24 -2
- package/dist/infrastructure/harness/loop-action-store.js +0 -3
- package/dist/records/harvest.js +2 -23
- package/dist/records/one-shot-runs.js +1 -1
- package/dist/shared/artifacts-core.js +24 -5
- package/dist/shared/output-truncation.js +37 -0
- package/dist/shared/package-metadata.js +488 -0
- package/dist/{executors/cursor-executor.js → sidecars/cursor-prompt/executor.js} +2 -42
- package/dist/sidecars/cursor-prompt/index.js +3 -0
- package/dist/sidecars/cursor-prompt/stream.js +121 -0
- package/dist/task/config-types.js +29 -12
- package/dist/task/delegate.js +9 -21
- package/dist/task/runtime.js +1 -2
- package/dist/worker/cli.js +32 -3
- package/dist/worker/delivery/final-verification.js +47 -11
- package/dist/worker/delivery/package.js +63 -10
- package/dist/worker/feature/run.js +60 -8
- package/dist/worker/loop-agent/loop-agent-client.js +329 -126
- package/dist/worker/observability/event-history.js +216 -0
- package/dist/worker/observability/read-model.js +338 -83
- package/dist/worker/observe/paths.js +17 -0
- package/dist/worker/observe/routes.js +165 -21
- package/dist/worker/observe/server.js +59 -1
- package/dist/worker/observe/static/api.js +27 -0
- package/dist/worker/observe/static/app.js +120 -2317
- package/dist/worker/observe/static/constants.js +148 -0
- package/dist/worker/observe/static/copy.js +67 -0
- package/dist/worker/observe/static/dag-helpers.js +172 -0
- package/dist/worker/observe/static/dag-model.js +72 -0
- package/dist/worker/observe/static/dom.js +61 -0
- package/dist/worker/observe/static/format-pool.js +67 -0
- package/dist/worker/observe/static/format.js +292 -0
- package/dist/worker/observe/static/index.html +300 -82
- package/dist/worker/observe/static/kpi.js +94 -0
- package/dist/worker/observe/static/relations.js +128 -0
- package/dist/worker/observe/static/router.js +85 -0
- package/dist/worker/observe/static/run-processing.js +148 -0
- package/dist/worker/observe/static/shell-chrome.js +68 -0
- package/dist/worker/observe/static/state.js +253 -0
- package/dist/worker/observe/static/styles.css +1720 -495
- package/dist/worker/observe/static/views/batch.js +226 -0
- package/dist/worker/observe/static/views/dag-graph.js +172 -0
- package/dist/worker/observe/static/views/dag-inspector.js +477 -0
- package/dist/worker/observe/static/views/dag.js +362 -0
- package/dist/worker/observe/static/views/dashboard.js +442 -0
- package/dist/worker/observe/static/views/failures.js +143 -0
- package/dist/worker/observe/static/views/feature.js +453 -0
- package/dist/worker/observe/static/views/pool.js +347 -0
- package/dist/worker/observe/static/views/run.js +453 -0
- package/dist/worker/observe/static/views/session-timeline.js +205 -0
- package/dist/worker/observe/static/views/shell.js +7 -0
- package/dist/worker/observe/static/views/task.js +260 -0
- package/dist/worker/observe/static/views/timeline.js +163 -0
- package/dist/worker/preflight.js +49 -1
- package/dist/worker/run-task/run-task.js +22 -12
- package/dist/worker/runner/run-ready.js +76 -12
- package/dist/worker/task-spec/schema.js +0 -1
- package/dist/workflows/dag/controller-identity.js +104 -0
- package/dist/workflows/dag/convergence/controller.js +1 -1
- package/dist/workflows/dag/executor-registry.js +0 -2
- package/dist/workflows/dag/init-hybrid.js +797 -27
- package/dist/workflows/dag/node-execution.js +183 -35
- package/dist/workflows/dag/repair-artifact.js +91 -0
- package/dist/workflows/dag/report.js +50 -0
- package/dist/workflows/dag/retry-policy.js +138 -0
- package/dist/workflows/dag/runner.js +77 -17
- package/dist/workflows/dag/runtime-contract.js +87 -0
- package/dist/workflows/dag/scheduler.js +7 -2
- package/dist/workflows/dag/sdd-embedded.js +128 -0
- package/dist/workflows/dag/skill-instructions.js +5 -4
- package/dist/workflows/dag/skill-snapshot.js +529 -0
- package/dist/workflows/dag/types.js +86 -10
- package/dist/workflows/dag/validate.js +73 -12
- package/dist/workflows/loop/actions/dag-action.js +0 -2
- package/dist/workflows/loop/actions/shared.js +1 -1
- package/dist/workflows/loop/actions.js +14 -31
- package/dist/workflows/loop/benchmark.js +1 -1
- package/dist/workflows/loop/index.js +1 -1
- package/dist/workflows/loop/policy/auto-policy.js +22 -14
- package/dist/workflows/loop/policy/path-patterns.js +13 -0
- package/docs/README.md +36 -33
- package/docs/agent-dag-recovery-playbook.md +1 -1
- package/docs/agent-dag-runner.md +28 -3
- package/docs/architecture/README.md +26 -0
- package/docs/architecture/dag-execution.md +140 -0
- package/docs/architecture/evolution.md +53 -0
- package/docs/architecture/facts-and-state.md +58 -0
- package/docs/architecture/runtime-boundaries.md +45 -17
- package/docs/architecture/system-overview.md +93 -0
- package/docs/architecture/worker-and-feature.md +81 -0
- package/docs/cursor-prompt-sidecar.md +36 -0
- package/docs/decisions/README.md +13 -1
- package/docs/design/README.md +43 -21
- package/docs/development-principles.md +2 -2
- package/docs/exec-plans/active/README.md +1 -3
- package/docs/exec-plans/completed/README.md +23 -0
- package/docs/feature-workflow.md +78 -4
- package/docs/harness-methodology-debugging.md +1 -1
- package/docs/harness-methodology-tdd.md +3 -3
- package/docs/init-surface.manifest.json +60 -25
- package/docs/loop-agent-harness.md +28 -4
- package/docs/progress/README.md +50 -1
- package/docs/reports/README.md +90 -18
- package/docs/skills/README.md +2 -1
- package/docs/skills/vetted-skill-registry.md +2 -1
- package/docs/templates/agent-dag-report.schema.json +23 -6
- package/docs/templates/agent-dag.base.json +0 -5
- package/docs/templates/agent-dag.final-verification.json +0 -5
- package/docs/templates/agent-dag.schema.json +70 -3
- package/docs/templates/agent-dag.supervised-implementation.json +9 -8
- package/docs/templates/backend-test-dag.generate-pytest.prompt.md +139 -0
- package/docs/templates/backend-test-dag.json +276 -0
- package/docs/templates/backend-test-dag.retrospect.prompt.md +125 -0
- package/docs/templates/backend-test-dag.review-cases.prompt.md +81 -0
- package/docs/templates/frontend-design-contract.md +33 -0
- package/docs/templates/frontend-task-constraints.md +25 -0
- package/docs/templates/frontend-task-requirement.md +61 -0
- package/docs/templates/harness.schema.json +10 -12
- package/docs/templates/hybrid-dag.json +1 -6
- package/docs/templates/interactive-ui-round2-experiment.md +1 -1
- package/docs/templates/product-line/task.yaml +0 -1
- package/docs/templates/project-start-checklist.md +2 -2
- package/docs/templates/worker-dogfood-evidence.md +28 -0
- package/docs/templates/worker-dogfood-setup.md +20 -0
- package/docs/verification-matrix.md +10 -0
- package/examples/decision-gate-agent-dag.json +87 -33
- package/examples/example-dag.json +0 -5
- package/examples/hybrid-loop-agent-dag.json +0 -5
- package/harness.json +7 -15
- package/package.json +22 -46
- package/scripts/check-product-line-docs.sh +10 -7
- package/skills/agent-worker/SKILL.md +37 -0
- package/skills/agent-worker/references/agent-worker-operator.md +43 -0
- package/skills/frontend-design-review/SKILL.md +59 -0
- package/skills/frontend-design-review/references/review-checklist.md +37 -0
- package/skills/frontend-implementation/SKILL.md +51 -0
- package/skills/frontend-implementation/references/code-standards.md +34 -0
- package/skills/frontend-implementation/references/design-spec.md +46 -0
- package/skills/frontend-implementation/references/node-contracts.md +32 -0
- package/skills/frontend-review/SKILL.md +53 -0
- package/skills/frontend-review/references/review-findings.md +42 -0
- package/skills/frontend-verification/SKILL.md +40 -0
- package/skills/frontend-verification/references/verification-checklist.md +56 -0
- package/skills/grill-me/SKILL.md +10 -0
- package/skills/grill-with-docs/SKILL.md +88 -0
- package/skills/grill-with-docs/adr-format.md +47 -0
- package/skills/grill-with-docs/context-format.md +60 -0
- package/skills/loop-agent/SKILL.md +11 -9
- package/skills/loop-agent/references/command-reference.md +14 -15
- package/skills/loop-agent/references/docs-converge.md +126 -0
- package/skills/loop-agent/references/harness-policy.md +7 -7
- package/skills/loop-agent/references/hybrid-dag.md +36 -20
- package/skills/loop-agent/references/long-running-loop.md +4 -6
- package/skills/loop-agent/references/multi-worktree.md +6 -6
- package/skills/loop-agent/references/orchestrator-and-interventions.md +3 -3
- package/skills/loop-agent/references/pi-subagent-assisted-mode.md +14 -11
- package/skills/loop-agent/references/task-workflow.md +1 -1
- package/skills/loop-agent/references/verification-and-failure-handling.md +6 -0
- package/skills/using-git-worktrees/SKILL.md +215 -0
- package/dist/commands/cursor-worker.js +0 -43
- package/dist/cursor-worker-entry.js +0 -8
- package/dist/executors/cursor-artifacts.js +0 -33
- package/dist/executors/cursor-execution-log.js +0 -81
- package/dist/executors/cursor-executor-artifacts.js +0 -134
- package/dist/executors/cursor-run.js +0 -115
- package/dist/executors/cursor-tool.js +0 -94
- package/dist/executors/cursor-worker-client.js +0 -223
- package/dist/executors/cursor-worker-protocol.js +0 -18
- package/dist/executors/cursor-worker-server.js +0 -54
- package/dist/executors/cursor-worker.js +0 -3
- package/dist/executors/cursor.js +0 -6
- package/dist/executors/dag-cursor-executor.js +0 -87
- package/dist/workflows/loop/actions/cursor-fix.js +0 -191
- package/dist/workflows/loop/policy/cursor-fix-policy.js +0 -31
- package/docs/cursor-executor-usage.md +0 -25
- package/docs/dynamic-workflow-dag-engine-roadmap.md +0 -1749
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
### 核心命令
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
loop-agent delegate <task-id> [--
|
|
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
|
|
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 →
|
|
41
|
-
|
|
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`
|
|
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-
|
|
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、
|
|
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
|
|
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
|
|
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 |
|
|
66
|
-
|
|
67
|
-
| `loop-agent-scout` |
|
|
68
|
-
| `loop-agent-planner` |
|
|
69
|
-
| `loop-agent-reviewer` |
|
|
70
|
-
| `loop-agent-worker` |
|
|
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
|
-
|
|
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
|
|
77
|
-
| `loop-agent-analyze-wide` | 3 parallel scouts →
|
|
78
|
-
| `loop-agent-review-only` |
|
|
79
|
-
| `loop-agent-implement-and-review` | worker → reviewer → worker
|
|
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 的 `
|
|
80
|
+
完成声明必须来自新鲜验证证据。按目标 repo 的 `harness.json.governanceRoot` 下 `verification-matrix.md` 选择最小证明命令;loop-agent 自身常用:
|
|
81
81
|
|
|
82
82
|
```bash
|
|
83
83
|
npm run typecheck
|
|
@@ -72,6 +72,12 @@ product-line taxonomy 的事实源是 `docs/design/state-and-failure-taxonomy.md
|
|
|
72
72
|
- 独立 audit 报告用 `handoff coverage <task-id> [--json|--markdown]`。
|
|
73
73
|
- task status、source/artifacts、DAG outcome、verification 记录可能 drift 时用 `dag reconcile-tasks --glob '<pattern>' [--json|--markdown]`。默认仅报告;`--patch` 不能伪造 verification evidence。
|
|
74
74
|
|
|
75
|
+
### supervised repair gate 与 runtime contract 失败
|
|
76
|
+
|
|
77
|
+
- `repair artifact gate failed: ... no unique governed Pi writer` / `declares repairNodeId "..." but no task with that id exists`:DagSpec 的 `shell.repairArtifactGate` 未声明 `repairNodeId`,或声明的修复节点缺失、不是 gate 直接下游、不是受治理 Pi writer(`executor: pi`、`toolProfile: write`、`writePolicy: exclusive`、`allowedPaths`/`writeSet` 非空且不与 `forbiddenPaths` 冲突)。用当前 controller 重新生成 supervised DAG,或按上述契约补齐修复节点,不要靠改节点名绕过。
|
|
78
|
+
- `incompatible DAG runtime contract` / `runtime contract requires ...`:DagSpec 的 `runtimeContract` 要求的能力超出当前 controller。升级 controller 或用当前 controller 重新生成 DAG;该 preflight 在任何节点执行前失败,不会留下半执行的 run。
|
|
79
|
+
- `controller identity drifted` / `artifact was tampered with`:resume 时的 controller 与 run 创建时冻结的 identity 不一致(package 内容、binary 或 fingerprint 变化),或 `controller-identity.json` 被篡改。启动新 run,而不是在漂移后 resume;completed run facts 保持只读。
|
|
80
|
+
|
|
75
81
|
### Verify 默认保存进度
|
|
76
82
|
`verify` 成功后,loop-agent 默认:
|
|
77
83
|
|
|
@@ -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
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { writeTextArtifactFile } from "../infrastructure/harness/artifact-store.js";
|
|
3
|
-
import { redactPromptForLog, truncateOutput, } from "./cursor-executor.js";
|
|
4
|
-
import { formatCursorFailureMessage, } from "./cursor-execution-log.js";
|
|
5
|
-
const SUMMARY_STDOUT_MAX = 4_000;
|
|
6
|
-
const SUMMARY_STDERR_MAX = 2_000;
|
|
7
|
-
export function buildPromptRedactedMarkdown(prompt) {
|
|
8
|
-
const redacted = redactPromptForLog(prompt);
|
|
9
|
-
return [
|
|
10
|
-
"# Cursor prompt (redacted)",
|
|
11
|
-
"",
|
|
12
|
-
`- ${redacted}`,
|
|
13
|
-
"",
|
|
14
|
-
"Full prompt text is not stored. See `logs/executor.jsonl` for the same hash reference.",
|
|
15
|
-
"",
|
|
16
|
-
].join("\n");
|
|
17
|
-
}
|
|
18
|
-
export function buildCursorRecoverySteps(input) {
|
|
19
|
-
const taskId = input.taskId ?? "<task-id>";
|
|
20
|
-
const session = input.sessionName ?? `task-${taskId}`;
|
|
21
|
-
const lines = ["## Recovery steps", ""];
|
|
22
|
-
if (input.failureCategory) {
|
|
23
|
-
lines.push(`- **Failure**: ${formatCursorFailureMessage(input.failureCategory)} (\`${input.failureCategory}\`)`);
|
|
24
|
-
lines.push("");
|
|
25
|
-
}
|
|
26
|
-
if (input.channel === "delegate") {
|
|
27
|
-
lines.push("### Retry in-process (direct SDK)");
|
|
28
|
-
lines.push("```bash");
|
|
29
|
-
lines.push("cd .");
|
|
30
|
-
lines.push(`npm run dev -- delegate ${taskId} --executor cursor --auto-run`);
|
|
31
|
-
lines.push("```");
|
|
32
|
-
if (input.worktreePath) {
|
|
33
|
-
lines.push("");
|
|
34
|
-
lines.push(`- Worktree: \`${input.worktreePath}\``);
|
|
35
|
-
}
|
|
36
|
-
lines.push("");
|
|
37
|
-
lines.push("### Promote evidence");
|
|
38
|
-
lines.push("```bash");
|
|
39
|
-
lines.push(`npm run dev -- promote-run ${taskId} --run-id <run-id>`);
|
|
40
|
-
lines.push(`npm run dev -- closeout task ${taskId}`);
|
|
41
|
-
lines.push("```");
|
|
42
|
-
lines.push("");
|
|
43
|
-
lines.push("### After closeout");
|
|
44
|
-
lines.push("```bash");
|
|
45
|
-
lines.push(`npm run dev -- harvest ${taskId}`);
|
|
46
|
-
lines.push("```");
|
|
47
|
-
}
|
|
48
|
-
else if (input.channel === "dag") {
|
|
49
|
-
lines.push("### Re-run DAG node");
|
|
50
|
-
lines.push("- Fix upstream outputs or prompts in the DAG JSON, then re-run `run-dag` with a new `--run-id`.");
|
|
51
|
-
lines.push("- Inspect `executor.jsonl` and per-node `result.summary.md` under `.harness/dag-runs/completed/<run-id>/` (or `active/<run-id>/` while the run is still in progress).");
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
lines.push("### Pi cursor tool");
|
|
55
|
-
lines.push("- Retry with a clearer `task` and correct `cwd`.");
|
|
56
|
-
lines.push("- Check `.harness/cache/cursor-executions.jsonl` when cwd contains `.harness`.");
|
|
57
|
-
}
|
|
58
|
-
if (input.failureCategory === "missing-api-key") {
|
|
59
|
-
lines.push("");
|
|
60
|
-
lines.push("- Export `CURSOR_API_KEY` before retrying.");
|
|
61
|
-
}
|
|
62
|
-
return lines;
|
|
63
|
-
}
|
|
64
|
-
function formatTokenUsage(result) {
|
|
65
|
-
const rows = [];
|
|
66
|
-
if (result.tokensUsed !== undefined) {
|
|
67
|
-
rows.push(`| tokensUsed | ${result.tokensUsed} |`);
|
|
68
|
-
}
|
|
69
|
-
const usage = result.details?.usage;
|
|
70
|
-
if (typeof usage?.inputTokens === "number") {
|
|
71
|
-
rows.push(`| inputTokens | ${usage.inputTokens} |`);
|
|
72
|
-
}
|
|
73
|
-
if (typeof usage?.outputTokens === "number") {
|
|
74
|
-
rows.push(`| outputTokens | ${usage.outputTokens} |`);
|
|
75
|
-
}
|
|
76
|
-
if (typeof usage?.totalTokens === "number" &&
|
|
77
|
-
result.tokensUsed === undefined) {
|
|
78
|
-
rows.push(`| totalTokens | ${usage.totalTokens} |`);
|
|
79
|
-
}
|
|
80
|
-
return rows;
|
|
81
|
-
}
|
|
82
|
-
export function buildResultSummaryMarkdown(input) {
|
|
83
|
-
const stdout = truncateOutput(input.result.stdout, SUMMARY_STDOUT_MAX);
|
|
84
|
-
const stderr = truncateOutput(input.result.stderr || "", SUMMARY_STDERR_MAX);
|
|
85
|
-
const recovery = input.recoveryLines ??
|
|
86
|
-
buildCursorRecoverySteps({
|
|
87
|
-
channel: input.context.channel,
|
|
88
|
-
taskId: input.context.taskId,
|
|
89
|
-
sessionName: input.context.taskId
|
|
90
|
-
? `task-${input.context.taskId}`
|
|
91
|
-
: undefined,
|
|
92
|
-
worktreePath: input.context.cwd,
|
|
93
|
-
failureCategory: input.result.ok
|
|
94
|
-
? undefined
|
|
95
|
-
: input.result.failureCategory,
|
|
96
|
-
});
|
|
97
|
-
const meta = [
|
|
98
|
-
"# Cursor execution summary",
|
|
99
|
-
"",
|
|
100
|
-
"## Run metadata",
|
|
101
|
-
"",
|
|
102
|
-
`| Field | Value |`,
|
|
103
|
-
`|-------|-------|`,
|
|
104
|
-
`| channel | ${input.context.channel} |`,
|
|
105
|
-
];
|
|
106
|
-
if (input.context.executionMode)
|
|
107
|
-
meta.push(`| executionMode | ${input.context.executionMode} |`);
|
|
108
|
-
if (input.context.taskId)
|
|
109
|
-
meta.push(`| taskId | ${input.context.taskId} |`);
|
|
110
|
-
if (input.context.dagRunId)
|
|
111
|
-
meta.push(`| dagRunId | ${input.context.dagRunId} |`);
|
|
112
|
-
if (input.context.dagNodeId)
|
|
113
|
-
meta.push(`| dagNodeId | ${input.context.dagNodeId} |`);
|
|
114
|
-
meta.push(`| cwd | ${input.context.cwd} |`, `| model | ${input.model} |`, `| ok | ${input.result.ok} |`, `| status | ${input.result.status} |`, `| failureCategory | ${input.result.failureCategory} |`, `| durationMs | ${input.result.durationMs} |`, ...formatTokenUsage(input.result), "", "## Prompt reference", "", `- ${redactPromptForLog(input.prompt)}`, "", "## Output", "");
|
|
115
|
-
if (stdout.text.trim()) {
|
|
116
|
-
meta.push("### stdout", "", "```text", stdout.text, "```", "");
|
|
117
|
-
if (stdout.truncated)
|
|
118
|
-
meta.push("_(stdout truncated)_", "");
|
|
119
|
-
}
|
|
120
|
-
if (stderr.text.trim()) {
|
|
121
|
-
meta.push("### stderr", "", "```text", stderr.text, "```", "");
|
|
122
|
-
if (stderr.truncated)
|
|
123
|
-
meta.push("_(stderr truncated)_", "");
|
|
124
|
-
}
|
|
125
|
-
meta.push(...recovery, "");
|
|
126
|
-
return meta.join("\n");
|
|
127
|
-
}
|
|
128
|
-
export async function writeCursorExecutorArtifacts(artifactsDir, input) {
|
|
129
|
-
const promptPath = path.join(artifactsDir, "prompt.redacted.md");
|
|
130
|
-
const summaryPath = path.join(artifactsDir, "result.summary.md");
|
|
131
|
-
await writeTextArtifactFile(promptPath, buildPromptRedactedMarkdown(input.prompt));
|
|
132
|
-
await writeTextArtifactFile(summaryPath, buildResultSummaryMarkdown(input));
|
|
133
|
-
return { promptPath, summaryPath };
|
|
134
|
-
}
|