harnessed 4.32.22 → 4.36.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 (99) hide show
  1. package/README.md +6 -6
  2. package/bin/harnessed-inject-state.mjs +16 -0
  3. package/dist/cli.mjs +1201 -235
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/index.mjs +1 -1
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/schemas/index.mjs.map +1 -1
  8. package/manifests/optional/doc-discipline-gate.yaml +54 -0
  9. package/messages/en.json +8 -0
  10. package/messages/zh-Hans.json +8 -0
  11. package/package.json +1 -1
  12. package/routing/decision_rules.yaml +1 -1
  13. package/workflows/README.md +1 -1
  14. package/workflows/auto/SKILL.md +13 -9
  15. package/workflows/auto/SKILL.zh-Hans.md +13 -9
  16. package/workflows/capabilities.yaml +94 -39
  17. package/workflows/defaults.yaml +8 -2
  18. package/workflows/disciplines/karpathy.yaml +29 -0
  19. package/workflows/disciplines/karpathy.zh-Hans.yaml +27 -0
  20. package/workflows/disciplines/language.yaml +15 -10
  21. package/workflows/disciplines/operational.yaml +1 -1
  22. package/workflows/disciplines/operational.zh-Hans.yaml +1 -1
  23. package/workflows/disciplines/output-style.yaml +10 -2
  24. package/workflows/disciplines/output-style.zh-Hans.yaml +10 -2
  25. package/workflows/disciplines/priority.yaml +15 -2
  26. package/workflows/disciplines/priority.zh-Hans.yaml +15 -2
  27. package/workflows/discuss/auto/SKILL.md +4 -4
  28. package/workflows/discuss/auto/SKILL.zh-Hans.md +4 -4
  29. package/workflows/discuss/auto/workflow.yaml +16 -3
  30. package/workflows/discuss/phase/SKILL.md +1 -1
  31. package/workflows/discuss/phase/SKILL.zh-Hans.md +1 -1
  32. package/workflows/discuss/strategic/SKILL.md +1 -1
  33. package/workflows/discuss/strategic/SKILL.zh-Hans.md +1 -1
  34. package/workflows/discuss/subtask/SKILL.md +1 -1
  35. package/workflows/discuss/subtask/SKILL.zh-Hans.md +1 -1
  36. package/workflows/judgments/parallelism-gate.yaml +11 -6
  37. package/workflows/judgments/phase-gate.yaml +5 -1
  38. package/workflows/judgments/stage-routing.yaml +21 -26
  39. package/workflows/judgments/strategic-gate.yaml +30 -0
  40. package/workflows/judgments/user-overrides.yaml +7 -3
  41. package/workflows/judgments/web-testing-routing.yaml +19 -7
  42. package/workflows/plan/architecture/SKILL.md +7 -3
  43. package/workflows/plan/architecture/SKILL.zh-Hans.md +7 -3
  44. package/workflows/plan/auto/SKILL.md +11 -7
  45. package/workflows/plan/auto/SKILL.zh-Hans.md +11 -7
  46. package/workflows/plan/phase/SKILL.md +7 -3
  47. package/workflows/plan/phase/SKILL.zh-Hans.md +7 -3
  48. package/workflows/research/SKILL.md +24 -9
  49. package/workflows/research/SKILL.zh-Hans.md +23 -9
  50. package/workflows/research/workflow.yaml +43 -3
  51. package/workflows/retro/SKILL.md +7 -3
  52. package/workflows/retro/SKILL.zh-Hans.md +7 -3
  53. package/workflows/role-prompts.yaml +28 -21
  54. package/workflows/role-prompts.zh-Hans.yaml +22 -17
  55. package/workflows/ship/auto/SKILL.md +11 -7
  56. package/workflows/ship/auto/SKILL.zh-Hans.md +11 -7
  57. package/workflows/ship/preflight/SKILL.md +7 -3
  58. package/workflows/ship/preflight/SKILL.zh-Hans.md +7 -3
  59. package/workflows/task/auto/SKILL.md +26 -16
  60. package/workflows/task/auto/SKILL.zh-Hans.md +26 -16
  61. package/workflows/task/auto/workflow.yaml +11 -4
  62. package/workflows/task/clarify/SKILL.md +1 -1
  63. package/workflows/task/clarify/SKILL.zh-Hans.md +1 -1
  64. package/workflows/task/code/SKILL.md +7 -3
  65. package/workflows/task/code/SKILL.zh-Hans.md +7 -3
  66. package/workflows/task/deliver/SKILL.md +53 -35
  67. package/workflows/task/deliver/SKILL.zh-Hans.md +54 -36
  68. package/workflows/task/deliver/workflow.yaml +32 -24
  69. package/workflows/task/test/SKILL.md +7 -3
  70. package/workflows/task/test/SKILL.zh-Hans.md +7 -3
  71. package/workflows/task/test/workflow.yaml +13 -0
  72. package/workflows/verify/auto/SKILL.md +12 -8
  73. package/workflows/verify/auto/SKILL.zh-Hans.md +12 -8
  74. package/workflows/verify/auto/workflow.yaml +3 -1
  75. package/workflows/verify/code-review/SKILL.md +7 -3
  76. package/workflows/verify/code-review/SKILL.zh-Hans.md +7 -3
  77. package/workflows/verify/design/SKILL.md +24 -10
  78. package/workflows/verify/design/SKILL.zh-Hans.md +24 -10
  79. package/workflows/verify/design/workflow.yaml +36 -7
  80. package/workflows/verify/eval-review/SKILL.md +7 -3
  81. package/workflows/verify/eval-review/SKILL.zh-Hans.md +7 -3
  82. package/workflows/verify/multispec/SKILL.md +17 -10
  83. package/workflows/verify/multispec/SKILL.zh-Hans.md +16 -10
  84. package/workflows/verify/multispec/workflow.yaml +7 -5
  85. package/workflows/verify/paranoid/SKILL.md +7 -3
  86. package/workflows/verify/paranoid/SKILL.zh-Hans.md +7 -3
  87. package/workflows/verify/progress/SKILL.md +7 -3
  88. package/workflows/verify/progress/SKILL.zh-Hans.md +7 -3
  89. package/workflows/verify/qa/SKILL.md +33 -14
  90. package/workflows/verify/qa/SKILL.zh-Hans.md +33 -14
  91. package/workflows/verify/qa/workflow.yaml +55 -2
  92. package/workflows/verify/security/SKILL.md +7 -3
  93. package/workflows/verify/security/SKILL.zh-Hans.md +7 -3
  94. package/workflows/verify/simplify/SKILL.md +7 -3
  95. package/workflows/verify/simplify/SKILL.zh-Hans.md +7 -3
  96. package/workflows/verify/validate-phase/SKILL.md +7 -3
  97. package/workflows/verify/validate-phase/SKILL.zh-Hans.md +7 -3
  98. package/manifests/skill-packs/karpathy-skills.yaml +0 -65
  99. package/manifests/tools/ralph-loop.yaml +0 -46
@@ -2,18 +2,18 @@
2
2
  name: task
3
3
  description: |
4
4
  Stage ③ Task 主控编排器 — 串行 invoke 4 sub per subtask (clarify → code → test → deliver)。
5
- ralph-loop COMPLETE wrapper 在 deliver phase 内 (D-10 orthogonal wrapper)。tdd-gate conditional
5
+ completion gate (harnessed 自有 checkpoint CLI) 在 deliver phase 内 (D-10 orthogonal wrapper)。tdd-gate conditional
6
6
  fire on test sub。schema_version: harnessed.workflow.v3 with delegates_to (4 sub: clarify order 1
7
7
  conditional + code order 2 + test order 3 conditional + deliver order 4) + disciplines_applied
8
8
  (6 default) + tools_available (8 entry: superpowers-brainstorming + tdd + grill-with-docs +
9
- improve-codebase-architecture + diagnose + ralph-loop + planning-with-files)。
9
+ improve-codebase-architecture + diagnose + completion-gate + planning-with-files)。
10
10
  Triggered by slash command `/task`
11
11
  (bare per ADR 0030 namespace policy D-02 LOCK) after `harnessed setup`.
12
12
  trigger_phrases:
13
13
  - "task"
14
14
  - "子任务执行"
15
15
  - "stage 3 execute"
16
- - "ralph loop"
16
+ - "completion gate"
17
17
  - "执行子任务"
18
18
  ---
19
19
 
@@ -29,18 +29,24 @@ trigger_phrases:
29
29
  | 1 | `clarify` | `judgments.subtask-gate.brainstorming.fires` | serial | approaches ≥ 2 / core_algorithm / has_api_contract / error_cost=high |
30
30
  | 2 | `code` | (无条件 — karpathy 心法 always-on + mattpocock conditional route) | serial | 始终触发 |
31
31
  | 3 | `test` | `judgments.tdd-gate.tdd-strongly-suggested.fires` | serial | 核心业务 / 算法 / 数据处理 / 回归 risk / reliability (6 fires_when OR-chain) |
32
- | 4 | `deliver` | (无条件 — ralph-loop COMPLETE wrapper) | serial | 始终触发 |
32
+ | 4 | `deliver` | (无条件 — completion gate COMPLETE wrapper) | serial | 始终触发 |
33
33
 
34
34
  Engine runtime 通过 `runMasterOrchestrator` 按顺序 spawn 4 个子工作流阶段
35
35
  (依照 T3.5.W0.1:clarify → code → test → deliver)。K9 invariant 强制执行:每个 serial
36
36
  mode delegate 必须携带显式 `order`。每个 subtask 入口走一次此主控编排器。
37
37
 
38
- ## ralph-loop 正交 wrapper (D-10)
38
+ ## 完成闸门正交 wrapper (D-10)
39
39
 
40
- ralph-loop 是正交 wrapper, 套在 deliver sub 的 01-deliver phase 外层保 completion-promise
41
- verbatim "COMPLETE" (R20.10)。任何执行单元 (subagent / team / 主 session) 都可外层套 ralph-loop
40
+ 完成闸门是正交 wrapper, 套在 deliver sub 的 01-deliver phase 外层保 completion-promise
41
+ verbatim "COMPLETE" (R20.10)。任何执行单元 (subagent / team / 主 session) 都可外层套它
42
42
  保 completion-promise (bundled subagent vs Agent Teams routing — orthogonal wrapper rule).
43
43
 
44
+ 它是 harnessed 自有的 CLI,不是上游 plugin (ADR 0039,4.36.0 摘除 `/ralph-loop` 依赖):
45
+ `harnessed checkpoint complete <sub> --result-file <path>` 对产物 / TDD boundary / verbatim
46
+ `<promise>COMPLETE</promise>` 三重 fail-closed;被拦下时 `harnessed checkpoint fail <sub>
47
+ --failing-tests <n>` 记录尝试并在命中停机条件时打印 BUDGET-EXHAUSTED / NO-PROGRESS /
48
+ BREAK-LOOP。**仅当**三者都未触发才允许重 spawn;任一触发即停。
49
+
44
50
  ## Capability refs
45
51
 
46
52
  Sister `workflows/capabilities.yaml`:
@@ -49,7 +55,7 @@ Sister `workflows/capabilities.yaml`:
49
55
  - `grill-with-docs` — Bucket 1 mattpocock conditional invoke (clarify)
50
56
  - `improve-codebase-architecture` — Bucket 1 mattpocock conditional invoke (code, architecture_health_audit)
51
57
  - `diagnose` — Bucket 1 mattpocock conditional invoke (code/test, bug_root_cause_unknown / test_fail)
52
- - `ralph-loop` — Bucket 4 核心 capability orthogonal wrapper (deliver)
58
+ - `completion-gate` — Bucket 4 核心 capability orthogonal wrapper (deliver;harnessed 自有 `harnessed checkpoint complete` / `fail`,无上游 plugin)
53
59
  - `planning-with-files` — Bucket 4 核心 capability (code + deliver progress.md update)
54
60
 
55
61
  ## Invocation
@@ -71,27 +77,31 @@ Sister `workflows/capabilities.yaml`:
71
77
  session、绕过 Agent Teams,在 Claude Code 内部调用时会挂死)。
72
78
 
73
79
  1. 若 "$ARGUMENTS" 触发澄清判据(≥2 方案 / 核心算法 / API contract / 高错误成本),先在**本 session** 交互澄清(AskUserQuestion)并锁决策;否则透明 skip。产出 locked spec。
74
- 2. Bash: `harnessed gates task --task "<locked spec>" --skip-sub discuss` → 解析 JSON `{fire, skip, parallelism}`。这是 plan SoT(不 spawn)。保留 verbatim JSON。
80
+ 1b. Bash: `harnessed facts task --out .harnessed-facts.json` → 它只列出**本阶段 gate 真正读取**的 fact:能确定性推导的已填好(改动行数 / 触及文件数 / stage,来自 git),判断题留 `null` 并附一行说明。编辑该文件,把 `facts` 里每个 `null` 按 locked spec 换成你的真实判断 —— 只有确实无法判断时才留 null(此时回退内置默认值)。**不要**跳过本步,也**不要**自行编造命令没问的 fact。
81
+ 2. Bash: `harnessed gates task --task "<locked spec>" --context-file .harnessed-facts.json --skip-sub discuss` → 解析 JSON `{fire, skip, parallelism}`。这是 plan SoT(不 spawn)。保留 verbatim JSON。
75
82
  3. Bash: `harnessed checkpoint start task --plan '<step 2 的 verbatim gates JSON>'` → seed per-sub ledger,让 `harnessed status --recover` 能在 compaction 后给你重新定位。
76
- 4. 若 `parallelism.escalate_to_teams === true`:读 `~/.claude/rules/agent-teams.md`,然后把 fired subs 作为 Agent Team 驱动(`TeamCreate` → 每个 sub `Agent(name, team_name, …)` + 其 `harnessed prompt <sub>` prompt → 用 `SendMessage` 协调 → `SendMessage shutdown_request` + `TeamDelete`)。每个 sub 仍按下方 checkpoint(`complete` / `fail`)。
83
+ 4. 若 `parallelism.escalate_to_teams === true`:读 `~/.claude/rules/agent-teams.md`,然后把 fired subs 作为 Agent Team 驱动。**没有建团步骤、也没有建团工具** —— 对每个 fired sub 用 `Agent(name: <sub>, run_in_background: true, prompt: <该 sub 的 `harnessed prompt <sub>` prompt>)` spawn 一个后台 teammate,团在**第一个** spawn 时隐式形成,本 session 即 lead(`team_name` 入参被接受但忽略 —— 团名由 session 派生)。用 `SendMessage` 协调;某个 sub 完成后,**按名**请求该 teammate 关闭(例如「ask the verify-qa teammate to shut down」)。每个 sub 仍按下方 checkpoint(`complete` / `fail`)。
77
84
  5. 否则,对 `order` 里每个 fired sub(serial 串行、parallel 并发):
78
- - **若该项 `is_master: true`**(本身是 stage master —— 如 `/auto` fire `plan`/`task`/`verify`):**不要**直接 prompt+spawn。RECURSE:跑该 master 自己的 `harnessed gates <sub> --task "<spec>" --skip-sub discuss` → `harnessed checkpoint start <sub> --plan '<json>'` → 对它的 fired subs 重复本循环。
85
+ - **若该项 `is_master: true`**(本身是 stage master —— 如 `/auto` fire `plan`/`task`/`verify`):**不要**直接 prompt+spawn。RECURSE:跑该 master 自己的 `harnessed facts <sub> --out .harnessed-facts.json`(填完 null)→ `harnessed gates <sub> --task "<spec>" --context-file .harnessed-facts.json --skip-sub discuss` → `harnessed checkpoint start <sub> --plan '<json>'` → 对它的 fired subs 重复本循环。
79
86
  - **否则(leaf sub):**
80
87
  a. Bash: `harnessed prompt <sub> --task "<spec>" --json` → 解析 `{prompt, max_iterations, model}`。
81
- b. 用 CC-native subagent(Task / Agent 工具)以该 `prompt` + `model` spawn,用 ralph-loop plugin 包裹:`/ralph-loop "<prompt>" --max-iterations <max_iterations> --completion-promise "COMPLETE"`。若 plugin 未装,改用原生 goal gate(Claude Code 2.1.139+ / Codex):`/goal "this subtask is delivered: the subagent's final output contains verbatim <promise>COMPLETE</promise>; or stop after <max_iterations> turns"`,随后 spawn subagent,由 goal 评估器驱动重 spawn 直到目标清除。若 `/goal` 也不可用,自循环:spawn → 检查输出 `<promise>COMPLETE</promise>` → 把上轮输出 append 后重 spawn(至多 max_iterations)。goal 只在叶子 subtask 层设置 — `/goal` 每 session 单槽,嵌套 goal 会覆盖外层。
88
+ b. 用 CC-native subagent(Task / Agent 工具)以该 `prompt` + `model` spawn,然后用 harnessed 自己的完成闸门驱动交付:
89
+ - subagent 返回后,把它的最终输出写入文件,跑 `harnessed checkpoint complete <sub> --result-file <path>` —— 该命令对声明的产物、TDD boundary、逐字 `<promise>COMPLETE</promise>` 三者 fail-closed。
90
+ - 若被拦下,跑 `harnessed checkpoint fail <sub> --failing-tests <n>` 记录本次尝试;命中停机条件时它会打印 BUDGET-EXHAUSTED / NO-PROGRESS / BREAK-LOOP。
91
+ - **仅当**这三者都未触发时才允许重 spawn。任一触发即停:重新收敛子任务范围、修掉阻塞点,或上报用户。绝不越过停机指令继续重 spawn。
82
92
  c. 若输出含 `STATUS: NEEDS_CLARIFICATION` + 问题列表:STOP,用 AskUserQuestion 原样转达,把答案 append 进 spec,再重 spawn 同一 sub。
83
- d. 命中 `<promise>COMPLETE</promise>`:Bash `harnessed checkpoint complete <sub> --summary "<one-line>"`。evidence guard 在此运行(fail-CLOSED):若声明的 `artifacts_expected` 文件缺失会 exit 非零 —— 重 spawn 产出它,或仅在刻意覆盖时传 `--force`。
84
- e. 若 sub 无法达到 COMPLETE(max_iterations 耗尽 / 不可恢复错误):Bash `harnessed checkpoint fail <sub> --summary "<why>"`,然后 STOP 并向用户报告。
93
+ d. 命中 `<promise>COMPLETE</promise>`:把 subagent 最终输出写入文件,再 Bash `harnessed checkpoint complete <sub> --result-file <path> --summary "<one-line>"`。fail-CLOSED —— 除非声明的 `artifacts_expected` 文件全部存在、TDD boundary 通过(证据非空 / 红绿两侧齐全 / 测试文件未被删除)、且结果含逐字 `<promise>COMPLETE</promise>`(或结构化 COMPLETE 状态),否则拦下。`--result <text>` 是内联变体;`--result-file` 优先且在 Windows 上引号安全。exit 非零即表示该 sub **未** done —— 重 spawn 补齐,或仅在刻意覆盖时传 `--force`(记录 `evidence_status=overridden`,是可审计的覆盖而非静默放行)。
94
+ e. 若 complete 闸门拦下:Bash `harnessed checkpoint fail <sub> --failing-tests <n>` 记录本次尝试(该 sub 无测试时省略该 flag —— 回退用证据产物摘要作进展度量)。命中停机条件时它会打印 `BUDGET-EXHAUSTED`(已用尝试次数 vs `workflows/defaults.yaml ralph_max_iterations`)、`NO-PROGRESS`(连续 N 次无进展)或 `BREAK-LOOP`(该 sub 失败次数达阈值)。**仅当**三者都未触发时才允许重 spawn;任一触发即 STOP —— 重新收敛范围、修掉阻塞点或上报用户,并说明情况。
85
95
  6. 所有 fired subs `done`(或记录 `failed`)后,Bash `harnessed status --recover` 确认 ledger,并向用户报告 per-sub fired/skipped/done/failed 摘要。
86
96
 
87
97
  **若丢失上下文(compaction / resume):** 先跑 `harnessed status --recover` —— 它读 ledger 并打印「你在这里,下一步是什么」,让你从第一个 `pending` sub 续跑而非重启。若 ledger 为空,重跑 step 2-3。
88
98
 
89
- <!-- harnessed-generated:v4.9.3 -->
99
+ <!-- harnessed-generated:v4.12.0 -->
90
100
 
91
101
  ## References
92
102
 
93
103
  - D-01 master orchestrator delegation pattern
94
104
  - D-02 bare slash cmd convention (ADR 0030 namespace policy LOCK)
95
- - D-10 ralph-loop orthogonal wrapper
105
+ - D-10 completion gate orthogonal wrapper (ADR 0039 — 内置化后摘除上游 `/ralph-loop`)
96
106
  - workflows/judgments/{subtask-gate,tdd-gate}.yaml — brainstorming + tdd-strongly-suggested triggers
97
107
  - workflows/task/{clarify,code,test,deliver}/workflow.yaml — 4 sub-workflow Phase 3.4 SHIPPED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Stage ③ Task master orchestrator — 串行 invoke 4 sub per subtask (clarify → code → test → deliver)
4
4
  # per bundled Execute-stage cadence + RESEARCH-workflows § Area 2。
5
- # ralph-loop COMPLETE wrapper 在 deliver phase 内 (D-10 orthogonal wrapper not master concern)。
5
+ # completion-gate COMPLETE wrapper 在 deliver phase 内 (D-10 orthogonal wrapper not master concern)。
6
6
  # tdd-gate conditional fire on test sub (sister task/test/workflow.yaml gate
7
7
  # judgments.tdd-gate.tdd-strongly-suggested.fires)。
8
8
  #
@@ -11,7 +11,7 @@
11
11
  # - workflows/judgments/tdd-gate.yaml — tdd-strongly-suggested trigger (test conditional)
12
12
  # - workflows/task/{clarify,code,test,deliver}/workflow.yaml — 4 sub-workflow Phase 3.4 SHIPPED
13
13
  # - workflows/capabilities.yaml — superpowers-brainstorming + tdd + grill-with-docs +
14
- # improve-codebase-architecture + diagnose + ralph-loop + planning-with-files
14
+ # improve-codebase-architecture + diagnose + completion-gate + planning-with-files
15
15
  # - .planning/phase-v3.0-3.2/RESEARCH-workflows.md § Area 2 Master Orchestrator yaml Examples
16
16
  # - src/workflow/schema/workflow.ts WorkflowSchemaV3 + DelegationClause (Phase 3.3 W0.5 SHIPPED)
17
17
  #
@@ -24,7 +24,7 @@ schema_version: harnessed.workflow.v3
24
24
  workflow: task
25
25
  description: |
26
26
  Stage ③ Task master orchestrator — 串行 invoke 4 sub per subtask (clarify → code → test → deliver);
27
- ralph-loop COMPLETE wrapper 在 deliver phase 内 (D-10 orthogonal wrapper not master concern)。
27
+ completion-gate COMPLETE wrapper 在 deliver phase 内 (D-10 orthogonal wrapper not master concern)。
28
28
  tdd-gate conditional fire on test sub (核心业务 / 算法 / 数据处理 / 回归 risk high / reliability
29
29
  required, 6 fires_when OR-chain; bundled tdd-gate judgment)。execute-task 每个 subtask 入口走一次。
30
30
 
@@ -35,12 +35,17 @@ tools_available:
35
35
  - grill-with-docs
36
36
  - improve-codebase-architecture
37
37
  - diagnose
38
- - ralph-loop
38
+ - completion-gate
39
39
  - planning-with-files
40
40
 
41
41
  delegates_to:
42
42
  - sub: clarify
43
43
  gate: judgments.subtask-gate.brainstorming.fires
44
+ # T2.1 D-5 — the ❌ half of subtask-gate finally evaluates: CRUD / a plain
45
+ # standard-lib call / a <20-line change vetoes brainstorming even when an
46
+ # OR-arm of fires_when matched. Veto is fail-OPEN (a broken skips_when never
47
+ # deletes the gate) — src/workflow/skipGate.ts.
48
+ skip_gate: judgments.subtask-gate.brainstorming.skips
44
49
  mode: serial
45
50
  order: 1
46
51
  - sub: code
@@ -48,6 +53,8 @@ delegates_to:
48
53
  order: 2
49
54
  - sub: test
50
55
  gate: judgments.tdd-gate.tdd-strongly-suggested.fires
56
+ # T2.1 D-5 — tdd-gate's declared skips (crud / ui_polish / docs_only).
57
+ skip_gate: judgments.tdd-gate.tdd-strongly-suggested.skips
51
58
  mode: serial
52
59
  order: 3
53
60
  - sub: deliver
@@ -70,7 +70,7 @@ execution stages.
70
70
 
71
71
  Output: a locked spec the execution stages (`/plan` → `/task` → `/verify`) consume without further user input.
72
72
 
73
- <!-- harnessed-generated:v4.9.3 -->
73
+ <!-- harnessed-generated:v4.12.0 -->
74
74
 
75
75
  ## References
76
76
 
@@ -68,7 +68,7 @@ Phase 01-brainstorm 在 `phase.spec_ambiguous == true` 时条件性 fire `grill-
68
68
 
69
69
  产出:一份 locked spec,执行阶段(`/plan` → `/task` → `/verify`)无需再问用户即可消费。
70
70
 
71
- <!-- harnessed-generated:v4.9.3 -->
71
+ <!-- harnessed-generated:v4.12.0 -->
72
72
 
73
73
  ## References
74
74
 
@@ -81,11 +81,15 @@ Do NOT pipe to `harnessed run task-code` — that is the CI/headless path (in-pr
81
81
  that blocks the session inside Claude Code).
82
82
 
83
83
  1. Bash: `harnessed prompt task-code --task "$ARGUMENTS" --json` → parse `{prompt, max_iterations, model}`.
84
- 2. Spawn a CC-native subagent (Task / Agent tool) with that `prompt` + `model`, wrapped in the ralph-loop plugin: `/ralph-loop "<prompt>" --max-iterations <max_iterations> --completion-promise "COMPLETE"`. If the plugin is absent, use the native goal gate instead (Claude Code 2.1.139+ / Codex): `/goal "this subtask is delivered: the subagent's final output contains verbatim <promise>COMPLETE</promise>; or stop after <max_iterations> turns"` then spawn the subagent and let the goal evaluator drive re-spawns until it clears. If `/goal` is unavailable too, self-loop: spawn → check output for `<promise>COMPLETE</promise>` → re-spawn with prior output appended (up to max_iterations). Set the goal only at the leaf subtask level — `/goal` is single-slot per session and a nested goal overwrites the outer one.
84
+ 2. Spawn a CC-native subagent (Task / Agent tool) with that `prompt` and `model`, then drive delivery with harnessed's own completion gate:
85
+ - on return, write the subagent's final output to a file and run `harnessed checkpoint complete task-code --result-file <path>` — it is fail-closed on the declared artifacts, the TDD boundary, and the verbatim `<promise>COMPLETE</promise>`.
86
+ - if it blocks, run `harnessed checkpoint fail task-code --failing-tests <n>` to record the attempt; it prints BUDGET-EXHAUSTED / NO-PROGRESS / BREAK-LOOP when a stop condition is reached.
87
+ - respawn ONLY while none of those three has fired. Any one of them means stop: re-scope the subtask, fix the blocker, or escalate to the user. Never respawn past a stop directive.
85
88
  3. If the output contains `STATUS: NEEDS_CLARIFICATION` + a question list: STOP, relay them verbatim via AskUserQuestion, append the answers to the spec, then re-spawn the same sub.
86
- 4. On `<promise>COMPLETE</promise>`: Bash `harnessed checkpoint complete task-code --summary "<one-line>"`. The evidence guard runs here (fail-CLOSED): if a declared `artifacts_expected` file is missing it exits non-zero — re-spawn to produce it before treating the sub as done.
89
+ 4. On `<promise>COMPLETE</promise>`: write the subagent’s final output to a file, then Bash `harnessed checkpoint complete task-code --result-file <path> --summary "<one-line>"`. Fail-CLOSED — it blocks unless every declared `artifacts_expected` file exists, the TDD boundary passes (non-empty evidence / both the red and green sides present / the test file was not deleted), and the result carries a verbatim `<promise>COMPLETE</promise>` (or a structured COMPLETE status). `--result <text>` is the inline variant; `--result-file` wins and is quoting-safe on Windows. `--force` records an audited override (`evidence_status=overridden`) — it does not silently pass.
90
+ 5. If the complete gate blocked: Bash `harnessed checkpoint fail task-code --failing-tests <n>` to record the attempt. It prints `BUDGET-EXHAUSTED` / `NO-PROGRESS` / `BREAK-LOOP` once a stop condition is reached. Respawn ONLY while none of those three has fired; any one of them means STOP — re-scope the subtask, fix the blocker, or escalate to the user.
87
91
 
88
- <!-- harnessed-generated:v4.9.3 -->
92
+ <!-- harnessed-generated:v4.12.0 -->
89
93
 
90
94
  ## References
91
95
 
@@ -79,11 +79,15 @@ CC-native Task / Agent 工具 spawn subagent(保持 session 响应 + 让澄清 r
79
79
  Code 内部会阻塞 session)。
80
80
 
81
81
  1. Bash: `harnessed prompt task-code --task "$ARGUMENTS" --json` → 解析 `{prompt, max_iterations, model}`。
82
- 2. 用 CC-native subagent(Task / Agent 工具)以该 `prompt` + `model` spawn,用 ralph-loop plugin 包裹:`/ralph-loop "<prompt>" --max-iterations <max_iterations> --completion-promise "COMPLETE"`。若 plugin 未装,改用原生 goal gate(Claude Code 2.1.139+ / Codex):`/goal "this subtask is delivered: the subagent's final output contains verbatim <promise>COMPLETE</promise>; or stop after <max_iterations> turns"`,随后 spawn subagent,由 goal 评估器驱动重 spawn 直到目标清除。若 `/goal` 也不可用,自循环:spawn → 检查输出 `<promise>COMPLETE</promise>` → 把上轮输出 append 后重 spawn(至多 max_iterations)。goal 只在叶子 subtask 层设置 — `/goal` 每 session 单槽,嵌套 goal 会覆盖外层。
82
+ 2. 用 CC-native subagent(Task / Agent 工具)以该 `prompt` + `model` spawn,然后用 harnessed 自己的完成闸门驱动交付:
83
+ - subagent 返回后,把它的最终输出写入文件,跑 `harnessed checkpoint complete task-code --result-file <path>` —— 该命令对声明的产物、TDD boundary、逐字 `<promise>COMPLETE</promise>` 三者 fail-closed。
84
+ - 若被拦下,跑 `harnessed checkpoint fail task-code --failing-tests <n>` 记录本次尝试;命中停机条件时它会打印 BUDGET-EXHAUSTED / NO-PROGRESS / BREAK-LOOP。
85
+ - **仅当**这三者都未触发时才允许重 spawn。任一触发即停:重新收敛子任务范围、修掉阻塞点,或上报用户。绝不越过停机指令继续重 spawn。
83
86
  3. 若输出含 `STATUS: NEEDS_CLARIFICATION` + 问题列表:STOP,用 AskUserQuestion 原样转达,把答案 append 进 spec,再重 spawn。
84
- 4. 命中 `<promise>COMPLETE</promise>`:Bash `harnessed checkpoint complete task-code --summary "<one-line>"`。evidence guard 在此运行(fail-CLOSED):若声明的 `artifacts_expected` 文件缺失会 exit 非零 —— 重 spawn 产出它再算 done。
87
+ 4. 命中 `<promise>COMPLETE</promise>`:把 subagent 最终输出写入文件,再 Bash `harnessed checkpoint complete task-code --result-file <path> --summary "<one-line>"`。fail-CLOSED —— 除非声明的 `artifacts_expected` 文件全部存在、TDD boundary 通过(证据非空 / 红绿两侧齐全 / 测试文件未被删除)、且结果含逐字 `<promise>COMPLETE</promise>`(或结构化 COMPLETE 状态),否则拦下。`--result <text>` 是内联变体;`--result-file` 优先且在 Windows 上引号安全。`--force` 记录可审计的覆盖(`evidence_status=overridden`),不是静默放行。
88
+ 5. 若 complete 闸门拦下:Bash `harnessed checkpoint fail task-code --failing-tests <n>` 记录本次尝试。命中停机条件时会打印 `BUDGET-EXHAUSTED` / `NO-PROGRESS` / `BREAK-LOOP`。**仅当**三者都未触发时才允许重 spawn;任一触发即 STOP —— 重新收敛子任务范围、修掉阻塞点,或上报用户。
85
89
 
86
- <!-- harnessed-generated:v4.9.3 -->
90
+ <!-- harnessed-generated:v4.12.0 -->
87
91
 
88
92
  ## References
89
93
 
@@ -1,21 +1,22 @@
1
1
  ---
2
2
  name: task-deliver
3
3
  description: |
4
- task-deliver workflow v3 — Stage ③.d 子任务交付 sub-workflow (ralph-loop COMPLETE
5
- wrapper + Agent Teams conditional escalation + R20.10 explicit max_iterations_exceeded
6
- fallback)。2-phase composition: 01-deliver (ralph-loop SDK wrapper with completion_promise
7
- verbatim "COMPLETE" + parallelism judgments.parallelism-gate.ralph-loop-wrapper.fires +
4
+ task-deliver workflow v3 — Stage ③.d 子任务交付 sub-workflow (harnessed 自有 completion-gate
5
+ + Agent Teams conditional escalation + R20.10 explicit max_iterations_exceeded
6
+ fallback)。2-phase composition: 01-deliver (completion-gate with completion_promise
7
+ verbatim "COMPLETE" + parallelism judgments.parallelism-gate.completion-gate-wrapper.fires +
8
8
  fallback emit_warning_and_halt exit_code 1) → 02-progress-mark (Claude Code plugin
9
9
  /plan mark subtask complete in progress.md)。
10
10
  schema_version: harnessed.workflow.v3 with disciplines_applied [6] + tools_available
11
- [ralph-loop, agent-teams-create, agent-teams-send-message, agent-teams-shutdown,
11
+ [completion-gate, verification-before-completion, agent-teams-create,
12
+ agent-teams-send-message, agent-teams-shutdown,
12
13
  planning-with-files]. Triggered by harnessed CLI `harnessed task-deliver --task <text>`
13
14
  or slash command `/task-deliver` after `harnessed setup`.
14
15
  trigger_phrases:
15
16
  - "deliver this subtask"
16
17
  - "task-deliver workflow"
17
18
  - "Stage 3 deliver"
18
- - "ralph-loop COMPLETE"
19
+ - "completion gate COMPLETE"
19
20
  - "跑 task-deliver"
20
21
  ---
21
22
 
@@ -25,36 +26,46 @@ trigger_phrases:
25
26
 
26
27
  2-phase sub-workflow mapping the user's CLAUDE.md Stage ③.d 子任务交付 discipline
27
28
  onto the harnessed runtime, fully `harnessed.workflow.v3` schema (Phase v3.0-3.4 W0
28
- T3.4.W0.9 — D-09 L0 Discipline Substrate + D-10 ralph-loop SDK wrapper + D-11 Agent
29
+ T3.4.W0.9 — D-09 L0 Discipline Substrate + D-10 completion gate + D-11 Agent
29
30
  Teams 升级 5 触发 OR-chain + R20.10 explicit max_iterations_exceeded handler).
30
31
 
31
32
  | phase | id | upstream | model | capability / args / parallelism / fallback |
32
33
  | ----- | -- | -------- | ----- | ------------------------------------------ |
33
- | 1 | `01-deliver` | ralph-loop | haiku | `{{ capabilities.ralph-loop.cmd }}` + `args: {completion_promise: COMPLETE, max_iterations: ...}` + `parallelism: judgments.parallelism-gate.ralph-loop-wrapper.fires` + `fallback.max_iterations_exceeded.action: emit_warning_and_halt` |
34
+ | 1 | `01-deliver` | (none — harnessed 自有 CLI) | haiku | `{{ capabilities.completion-gate.cmd }}` + `args: {completion_promise: COMPLETE, max_iterations: ...}` + `parallelism: judgments.parallelism-gate.completion-gate-wrapper.fires` + `fallback.max_iterations_exceeded.action: emit_warning_and_halt` |
34
35
  | 2 | `02-progress-mark` | planning-with-files | haiku | `{{ capabilities.planning-with-files.cmd }}` / `invokes: /plan` / `artifacts_expected: [progress.md]` |
35
36
 
36
37
  Per-phase config loads from `workflows/task/deliver/workflow.yaml`; engine.runRouting
37
38
  spawns each phase as a sub-agent via `@anthropic-ai/claude-agent-sdk` 0.3.142+.
38
39
 
39
- ## Phase 01 ralph-loop COMPLETE wrapper (R20.10 + D-10 + ADR 0011)
40
+ ## Phase 01 completion gate (R20.10 + D-10 + ADR 0039)
40
41
 
41
- ralph-loop SDK wrapper 保 completion-promise verbatim string `"COMPLETE"` — sub-task
42
- 被认为完成的判据是子任务输出包含 verbatim "COMPLETE" string (NOT 启发式 / NOT
43
- LLM-as-judge). Sister capabilities.yaml `ralph-loop` entry impl `bundled-skill` +
44
- `sdk_ref: src/workflow/lib/ralphLoop.ts` (Phase 2.2 v0.2.0 ship)。
42
+ 完成判据是子任务输出包含 verbatim `"COMPLETE"` string (NOT 启发式 / NOT LLM-as-judge)。
43
+ 4.36.0 起这条保证**完全内置**,跑在 harnessed 自己的 live path 上,不依赖任何上游 plugin:
45
44
 
46
- 交互面三级偏好链 (v4.15.0 / ADR 0036): ralph-loop plugin 优先 (fail-closed 逐字匹配 +
47
- 硬 max-iterations) → 未装时 native `/goal` gate (Claude Code 2.1.139+ / Codex 双平台内置,
48
- 条件句写 verbatim `<promise>COMPLETE</promise>` + turn 上界) → `/goal` 亦不可用时 self-loop
49
- 兜底。SDK 路径 (ralphLoopWrap 硬上界) 不参与该链,始终 verbatim 匹配。
45
+ - `harnessed checkpoint complete <sub> --result-file <path>` — fail-CLOSED,同时校验
46
+ 声明的 `artifacts_expected` 产物存在、TDD boundary 通过(证据非空 / 红绿两侧齐全 /
47
+ 测试文件未被删除)、结果含 verbatim `<promise>COMPLETE</promise>`(或结构化 COMPLETE
48
+ 状态)。`--result <text>` 是内联变体;`--result-file` 优先且在 Windows 上引号安全。
49
+ `--force` 记录可审计的覆盖(`evidence_status=overridden`),不是静默放行。
50
+ - `harnessed checkpoint fail <sub> --failing-tests <n>` — 记录本次尝试,并在命中停机
51
+ 条件时打印 `BUDGET-EXHAUSTED`(已用尝试次数 vs `workflows/defaults.yaml
52
+ ralph_max_iterations`)/ `NO-PROGRESS`(连续 N 次无进展;失败测试数,省略该 flag 时退回
53
+ 证据产物摘要)/ `BREAK-LOOP`(该 sub 失败次数达阈值)。
54
+ - **仅当**这三条停机理由都未触发时才允许重 spawn。任一触发即停:重新收敛子任务范围、
55
+ 修掉阻塞点,或上报用户。绝不越过停机指令继续重 spawn。
50
56
 
51
- ### Parallelism — ralph-loop 正交 wrapper
57
+ 这三条停机理由 == 上游 `/ralph-loop --max-iterations` + `--completion-promise` 曾经提供的
58
+ 东西,只是长在自有路径上、没有「装没装」的问题(ADR 0039 supersedes ADR 0036 的
59
+ plugin → `/goal` → self-loop 三级链)。Sister capabilities.yaml `completion-gate` entry
60
+ impl `harnessed-bundled` + `sdk_ref: src/workflow/lib/ralphLoop.ts`。
52
61
 
53
- `parallelism: judgments.parallelism-gate.ralph-loop-wrapper.fires` ref — per R20.10
54
- + D-10, ralph-loop 是 **正交 wrapper** 套在 subagent-default / agent-teams-upgrade /
62
+ ### Parallelism — completion gate 正交 wrapper
63
+
64
+ `parallelism: judgments.parallelism-gate.completion-gate-wrapper.fires` ref — per R20.10
65
+ + D-10, completion gate 是 **正交 wrapper** 套在 subagent-default / agent-teams-upgrade /
55
66
  main-session-fallback 任 1 mode 外层 (NOT 互斥触发器, 而是 `wraps:` orthogonal field
56
- in parallelism-gate.yaml L42-45). Runtime engine 评估 wrapping mode 后 spawn 相应
57
- execution unit + 套 ralph-loop completion check。
67
+ in parallelism-gate.yaml). Runtime engine 评估 wrapping mode 后 spawn 相应
68
+ execution unit + 套 completion check。
58
69
 
59
70
  ### Agent Teams conditional escalation (D-11 + agent-teams.md 5 OR-chain)
60
71
 
@@ -66,7 +77,8 @@ execution unit + 套 ralph-loop completion check。
66
77
  5. `fullstack_three_way == true` — 全栈三路协同
67
78
 
68
79
  任 1 fire → escalate subagent fan-out → Agent Teams Pattern A/B/C。Cleanup mandatory
69
- per agent-teams.md 防呆清单 (SendMessage shutdown_request + TeamDelete) — engine-level
80
+ per agent-teams.md 防呆清单 (lead 按名请求每个 teammate shut down; CC 2.1.178+ 无 teardown
81
+ 工具,团目录 session 退出时自动清理 —— 剩下的纪律是别把 teammate 落在运行态) — engine-level
70
82
  wiring, NOT yaml schema scope。
71
83
 
72
84
  ### R20.10 explicit max_iterations_exceeded handler (NOT silent abort)
@@ -74,10 +86,11 @@ wiring, NOT yaml schema scope。
74
86
  phase.fallback.max_iterations_exceeded = `{action: emit_warning_and_halt, message,
75
87
  exit_code: 1}` — schema-enforced via FallbackMaxIterationsExceeded Type.Literal(
76
88
  'emit_warning_and_halt') (workflow.ts L70-77). Sister Phase 2.4 W1.2 fallbackHandlers.ts
77
- engine.ts wire — ralph-loop 撞 max_iterations 时 explicit emit warning + halt with
78
- exit_code 1, NOT silent abort / continue。
89
+ engine.ts wire — 撞 max_iterations 时 explicit emit warning + halt with
90
+ exit_code 1, NOT silent abort / continue。交互面的对应物是 `checkpoint fail` 打印的
91
+ `BUDGET-EXHAUSTED`。
79
92
 
80
- Brief enforcement W0.9: ✅ ralph-loop completion_promise COMPLETE / ✅ parallelism-gate
93
+ Brief enforcement W0.9: ✅ completion-gate completion_promise COMPLETE / ✅ parallelism-gate
81
94
  ref / ✅ R20.10 explicit max_iterations_exceeded handler。
82
95
 
83
96
  ## Phase 02 progress-mark planning-with-files (D-15 + Q-AUDIT-5a Option A)
@@ -102,24 +115,29 @@ Do NOT pipe to `harnessed run task-deliver` — that is the CI/headless path (in
102
115
  that blocks the session inside Claude Code).
103
116
 
104
117
  1. Bash: `harnessed prompt task-deliver --task "$ARGUMENTS" --json` → parse `{prompt, max_iterations, model}`.
105
- 2. Spawn a CC-native subagent (Task / Agent tool) with that `prompt` + `model`, wrapped in the ralph-loop plugin: `/ralph-loop "<prompt>" --max-iterations <max_iterations> --completion-promise "COMPLETE"`. If the plugin is absent, use the native goal gate instead (Claude Code 2.1.139+ / Codex): `/goal "this subtask is delivered: the subagent's final output contains verbatim <promise>COMPLETE</promise>; or stop after <max_iterations> turns"` then spawn the subagent and let the goal evaluator drive re-spawns until it clears. If `/goal` is unavailable too, self-loop: spawn → check output for `<promise>COMPLETE</promise>` → re-spawn with prior output appended (up to max_iterations). Set the goal only at the leaf subtask level — `/goal` is single-slot per session and a nested goal overwrites the outer one.
118
+ 2. Spawn a CC-native subagent (Task / Agent tool) with that `prompt` and `model`, then drive delivery with harnessed's own completion gate:
119
+ - on return, write the subagent's final output to a file and run `harnessed checkpoint complete task-deliver --result-file <path>` — it is fail-closed on the declared artifacts, the TDD boundary, and the verbatim `<promise>COMPLETE</promise>`.
120
+ - if it blocks, run `harnessed checkpoint fail task-deliver --failing-tests <n>` to record the attempt; it prints BUDGET-EXHAUSTED / NO-PROGRESS / BREAK-LOOP when a stop condition is reached.
121
+ - respawn ONLY while none of those three has fired. Any one of them means stop: re-scope the subtask, fix the blocker, or escalate to the user. Never respawn past a stop directive.
106
122
  3. If the output contains `STATUS: NEEDS_CLARIFICATION` + a question list: STOP, relay them verbatim via AskUserQuestion, append the answers to the spec, then re-spawn the same sub.
107
- 4. On `<promise>COMPLETE</promise>`: Bash `harnessed checkpoint complete task-deliver --summary "<one-line>"`. The evidence guard runs here (fail-CLOSED): if a declared `artifacts_expected` file is missing it exits non-zero — re-spawn to produce it before treating the sub as done.
123
+ 4. On `<promise>COMPLETE</promise>`: write the subagent’s final output to a file, then Bash `harnessed checkpoint complete task-deliver --result-file <path> --summary "<one-line>"`. Fail-CLOSED — it blocks unless every declared `artifacts_expected` file exists, the TDD boundary passes (non-empty evidence / both the red and green sides present / the test file was not deleted), and the result carries a verbatim `<promise>COMPLETE</promise>` (or a structured COMPLETE status). `--result <text>` is the inline variant; `--result-file` wins and is quoting-safe on Windows. `--force` records an audited override (`evidence_status=overridden`) — it does not silently pass.
124
+ 5. If the complete gate blocked: Bash `harnessed checkpoint fail task-deliver --failing-tests <n>` to record the attempt. It prints `BUDGET-EXHAUSTED` / `NO-PROGRESS` / `BREAK-LOOP` once a stop condition is reached. Respawn ONLY while none of those three has fired; any one of them means STOP — re-scope the subtask, fix the blocker, or escalate to the user.
108
125
 
109
- <!-- harnessed-generated:v4.9.3 -->
126
+ <!-- harnessed-generated:v4.12.0 -->
110
127
 
111
128
  ## References
112
129
 
113
130
  - D-09 — L0 Discipline Substrate always-on (6 disciplines)
114
- - D-10 — ralph-loop 真接 SDK wrapper (NOT mock reference; v0.2.0 ship)
131
+ - D-10 — 完成保证真接 SDK wrapper (NOT mock reference; v0.2.0 ship)
115
132
  - D-11 — Agent Teams 升级 5 触发 OR-chain per bundled parallelism-gate rules
116
- - R20.10 — ralph-loop max_iterations_exceeded explicit emit_warning_and_halt
117
- (acceptance c "NOT silent abort"); ralph-loop 正交 wrapper wraps 3 mode
133
+ - R20.10 — max_iterations_exceeded explicit emit_warning_and_halt
134
+ (acceptance c "NOT silent abort"); completion gate 正交 wrapper wraps 3 mode
118
135
  - D-02 — SKILL.md `name:` bare slash cmd (`task-deliver` NOT `task/deliver`) per ADR 0030
119
- - ADR 0011 — SDK + ralph-loop integration v0.2.0 baseline
120
- - `workflows/judgments/parallelism-gate.yaml` triggers.ralph-loop-wrapper +
136
+ - ADR 0011 — SDK + 完成保证 integration v0.2.0 baseline
137
+ - ADR 0039 — 完成保证内置化 + 摘除上游 `/ralph-loop` 依赖 (supersedes ADR 0036)
138
+ - `workflows/judgments/parallelism-gate.yaml` triggers.completion-gate-wrapper +
121
139
  agent-teams-upgrade + subagent-default + main-session-fallback
122
- - `workflows/capabilities.yaml` — ralph-loop + agent-teams-{create,send-message,shutdown}
140
+ - `workflows/capabilities.yaml` — completion-gate + agent-teams-{create,send-message,shutdown}
123
141
  + planning-with-files entries
124
142
  - `workflows/defaults.yaml` — ralph_max_iterations.task-deliver.* values (T3.4.W2.2 followup)
125
143
  - `docs/WORKFLOW.md` — 4-stage workflow mermaid + Stage ③ Execute 章节
@@ -1,21 +1,22 @@
1
1
  ---
2
2
  name: task-deliver
3
3
  description: |
4
- task-deliver workflow v3 — Stage ③.d 子任务交付 sub-workflow (ralph-loop COMPLETE
5
- wrapper + Agent Teams conditional escalation + R20.10 explicit max_iterations_exceeded
6
- fallback)。2-phase composition: 01-deliver (ralph-loop SDK wrapper with completion_promise
7
- verbatim "COMPLETE" + parallelism judgments.parallelism-gate.ralph-loop-wrapper.fires +
4
+ task-deliver workflow v3 — Stage ③.d 子任务交付 sub-workflow (harnessed 自有 completion-gate
5
+ + Agent Teams conditional escalation + R20.10 explicit max_iterations_exceeded
6
+ fallback)。2-phase composition: 01-deliver (completion-gate with completion_promise
7
+ verbatim "COMPLETE" + parallelism judgments.parallelism-gate.completion-gate-wrapper.fires +
8
8
  fallback emit_warning_and_halt exit_code 1) → 02-progress-mark (Claude Code plugin
9
9
  /plan mark subtask complete in progress.md)。
10
10
  schema_version: harnessed.workflow.v3 with disciplines_applied [6] + tools_available
11
- [ralph-loop, agent-teams-create, agent-teams-send-message, agent-teams-shutdown,
11
+ [completion-gate, verification-before-completion, agent-teams-create,
12
+ agent-teams-send-message, agent-teams-shutdown,
12
13
  planning-with-files]. Triggered by harnessed CLI `harnessed task-deliver --task <text>`
13
14
  or slash command `/task-deliver` after `harnessed setup`.
14
15
  trigger_phrases:
15
16
  - "deliver this subtask"
16
17
  - "task-deliver workflow"
17
18
  - "Stage 3 deliver"
18
- - "ralph-loop COMPLETE"
19
+ - "completion gate COMPLETE"
19
20
  - "跑 task-deliver"
20
21
  ---
21
22
 
@@ -25,36 +26,46 @@ trigger_phrases:
25
26
 
26
27
  2-phase 子工作流,将 CLAUDE.md Stage ③.d 子任务交付纪律映射到 harnessed runtime,
27
28
  完整采用 `harnessed.workflow.v3` schema(Phase v3.0-3.4 W0 T3.4.W0.9 — D-09 L0
28
- Discipline Substrate + D-10 ralph-loop SDK wrapper + D-11 Agent Teams 升级 5 触发
29
+ Discipline Substrate + D-10 完成保证 + D-11 Agent Teams 升级 5 触发
29
30
  OR-chain + R20.10 explicit max_iterations_exceeded handler)。
30
31
 
31
32
  | phase | id | upstream | model | capability / args / parallelism / fallback |
32
33
  | ----- | -- | -------- | ----- | ------------------------------------------ |
33
- | 1 | `01-deliver` | ralph-loop | haiku | `{{ capabilities.ralph-loop.cmd }}` + `args: {completion_promise: COMPLETE, max_iterations: ...}` + `parallelism: judgments.parallelism-gate.ralph-loop-wrapper.fires` + `fallback.max_iterations_exceeded.action: emit_warning_and_halt` |
34
+ | 1 | `01-deliver` | (无 — harnessed 自有 CLI) | haiku | `{{ capabilities.completion-gate.cmd }}` + `args: {completion_promise: COMPLETE, max_iterations: ...}` + `parallelism: judgments.parallelism-gate.completion-gate-wrapper.fires` + `fallback.max_iterations_exceeded.action: emit_warning_and_halt` |
34
35
  | 2 | `02-progress-mark` | planning-with-files | haiku | `{{ capabilities.planning-with-files.cmd }}` / `invokes: /plan` / `artifacts_expected: [progress.md]` |
35
36
 
36
37
  每阶段配置从 `workflows/task/deliver/workflow.yaml` 加载;engine.runRouting 通过
37
38
  `@anthropic-ai/claude-agent-sdk` 0.3.142+ 将每个阶段 spawn 为 sub-agent。
38
39
 
39
- ## Phase 01 ralph-loop COMPLETE wrapper (R20.10 + D-10 + ADR 0011)
40
+ ## Phase 01 完成闸门 (R20.10 + D-10 + ADR 0039)
40
41
 
41
- ralph-loop SDK wrapper 保 completion-promise verbatim string `"COMPLETE"`——sub-task
42
- 被认为完成的判据是子任务输出包含 verbatim "COMPLETE" string(NOT 启发式 / NOT
43
- LLM-as-judge)。Sister capabilities.yaml `ralph-loop` entry impl `bundled-skill` +
44
- `sdk_ref: src/workflow/lib/ralphLoop.ts`(Phase 2.2 v0.2.0 ship)。
42
+ 完成判据是子任务输出包含 verbatim `"COMPLETE"` string(NOT 启发式 / NOT LLM-as-judge)。
43
+ 4.36.0 起这条保证**完全内置**,跑在 harnessed 自己的 live path 上,不依赖任何上游 plugin:
45
44
 
46
- 交互面三级偏好链(v4.15.0 / ADR 0036):ralph-loop plugin 优先(fail-closed 逐字匹配 +
47
- 硬 max-iterations)→ 未装时 native `/goal` gate(Claude Code 2.1.139+ / Codex 双平台内置,
48
- 条件句写 verbatim `<promise>COMPLETE</promise>` + turn 上界)→ `/goal` 亦不可用时 self-loop
49
- 兜底。SDK 路径(ralphLoopWrap 硬上界)不参与该链,始终 verbatim 匹配。
45
+ - `harnessed checkpoint complete <sub> --result-file <path>` —— fail-CLOSED,同时校验
46
+ 声明的 `artifacts_expected` 产物存在、TDD boundary 通过(证据非空 / 红绿两侧齐全 /
47
+ 测试文件未被删除)、结果含 verbatim `<promise>COMPLETE</promise>`(或结构化 COMPLETE
48
+ 状态)。`--result <text>` 是内联变体;`--result-file` 优先且在 Windows 上引号安全。
49
+ `--force` 记录可审计的覆盖(`evidence_status=overridden`),不是静默放行。
50
+ - `harnessed checkpoint fail <sub> --failing-tests <n>` —— 记录本次尝试,并在命中停机
51
+ 条件时打印 `BUDGET-EXHAUSTED`(已用尝试次数 vs `workflows/defaults.yaml
52
+ ralph_max_iterations`)/ `NO-PROGRESS`(连续 N 次无进展;失败测试数,省略该 flag 时退回
53
+ 证据产物摘要)/ `BREAK-LOOP`(该 sub 失败次数达阈值)。
54
+ - **仅当**这三条停机理由都未触发时才允许重 spawn。任一触发即停:重新收敛子任务范围、
55
+ 修掉阻塞点,或上报用户。绝不越过停机指令继续重 spawn。
50
56
 
51
- ### Parallelism — ralph-loop 正交 wrapper
57
+ 这三条停机理由 == 上游 `/ralph-loop --max-iterations` + `--completion-promise` 曾经提供的
58
+ 东西,只是长在自有路径上、没有「装没装」的问题(ADR 0039 supersedes ADR 0036 的
59
+ plugin → `/goal` → self-loop 三级链)。Sister capabilities.yaml `completion-gate` entry
60
+ impl `harnessed-bundled` + `sdk_ref: src/workflow/lib/ralphLoop.ts`。
52
61
 
53
- `parallelism: judgments.parallelism-gate.ralph-loop-wrapper.fires` ref——遵循 R20.10
54
- + D-10,ralph-loop 是**正交 wrapper**,套在 subagent-default / agent-teams-upgrade /
62
+ ### Parallelism — 完成闸门正交 wrapper
63
+
64
+ `parallelism: judgments.parallelism-gate.completion-gate-wrapper.fires` ref——遵循 R20.10
65
+ + D-10,完成闸门是**正交 wrapper**,套在 subagent-default / agent-teams-upgrade /
55
66
  main-session-fallback 任意 1 种模式外层(NOT 互斥触发器,而是 parallelism-gate.yaml
56
- L42-45 中的 `wraps:` 正交字段)。Runtime engine 评估 wrapping mode 后 spawn 相应
57
- 执行单元并套 ralph-loop completion check。
67
+ 中的 `wraps:` 正交字段)。Runtime engine 评估 wrapping mode 后 spawn 相应
68
+ 执行单元并套 completion check。
58
69
 
59
70
  ### Agent Teams 条件性升级 (D-11 + agent-teams.md 5 OR-chain)
60
71
 
@@ -66,18 +77,20 @@ L42-45 中的 `wraps:` 正交字段)。Runtime engine 评估 wrapping mode 后
66
77
  5. `fullstack_three_way == true` — 全栈三路协同
67
78
 
68
79
  任 1 触发 → 升级 subagent fan-out → Agent Teams Pattern A/B/C。清理是强制的,
69
- 遵循 agent-teams.md 防呆清单(SendMessage shutdown_request + TeamDelete)——属于
70
- engine 级别的连接,NOT yaml schema 的职责范围。
80
+ 遵循 agent-teams.md 防呆清单(lead 按名请求每个 teammate shut down;CC 2.1.178+ 已无
81
+ teardown 工具,团目录在 session 退出时自动清理——剩下的纪律是别把 teammate 落在运行态)
82
+ ——属于 engine 级别的连接,NOT yaml schema 的职责范围。
71
83
 
72
84
  ### R20.10 explicit max_iterations_exceeded handler(非静默中止)
73
85
 
74
86
  phase.fallback.max_iterations_exceeded = `{action: emit_warning_and_halt, message,
75
87
  exit_code: 1}`——通过 FallbackMaxIterationsExceeded Type.Literal(
76
88
  'emit_warning_and_halt')(workflow.ts L70-77)做 schema 级强制约束。Sister Phase 2.4
77
- W1.2 fallbackHandlers.ts engine.ts wire——ralph-loop 撞 max_iterations 时显式 emit
78
- warning + halt with exit_code 1,NOT 静默中止/继续执行。
89
+ W1.2 fallbackHandlers.ts engine.ts wire——撞 max_iterations 时显式 emit
90
+ warning + halt with exit_code 1,NOT 静默中止/继续执行。交互面的对应物是
91
+ `checkpoint fail` 打印的 `BUDGET-EXHAUSTED`。
79
92
 
80
- Brief enforcement W0.9: ✅ ralph-loop completion_promise COMPLETE / ✅ parallelism-gate
93
+ Brief enforcement W0.9: ✅ completion-gate completion_promise COMPLETE / ✅ parallelism-gate
81
94
  ref / ✅ R20.10 explicit max_iterations_exceeded handler。
82
95
 
83
96
  ## Phase 02 progress-mark planning-with-files (D-15 + Q-AUDIT-5a Option A)
@@ -101,24 +114,29 @@ CC-native Task / Agent 工具 spawn subagent(保持 session 响应 + 让澄清 r
101
114
  Code 内部会阻塞 session)。
102
115
 
103
116
  1. Bash: `harnessed prompt task-deliver --task "$ARGUMENTS" --json` → 解析 `{prompt, max_iterations, model}`。
104
- 2. 用 CC-native subagent(Task / Agent 工具)以该 `prompt` + `model` spawn,用 ralph-loop plugin 包裹:`/ralph-loop "<prompt>" --max-iterations <max_iterations> --completion-promise "COMPLETE"`。若 plugin 未装,改用原生 goal gate(Claude Code 2.1.139+ / Codex):`/goal "this subtask is delivered: the subagent's final output contains verbatim <promise>COMPLETE</promise>; or stop after <max_iterations> turns"`,随后 spawn subagent,由 goal 评估器驱动重 spawn 直到目标清除。若 `/goal` 也不可用,自循环:spawn → 检查输出 `<promise>COMPLETE</promise>` → 把上轮输出 append 后重 spawn(至多 max_iterations)。goal 只在叶子 subtask 层设置 — `/goal` 每 session 单槽,嵌套 goal 会覆盖外层。
117
+ 2. 用 CC-native subagent(Task / Agent 工具)以该 `prompt` + `model` spawn,然后用 harnessed 自己的完成闸门驱动交付:
118
+ - subagent 返回后,把它的最终输出写入文件,跑 `harnessed checkpoint complete task-deliver --result-file <path>` —— 该命令对声明的产物、TDD boundary、逐字 `<promise>COMPLETE</promise>` 三者 fail-closed。
119
+ - 若被拦下,跑 `harnessed checkpoint fail task-deliver --failing-tests <n>` 记录本次尝试;命中停机条件时它会打印 BUDGET-EXHAUSTED / NO-PROGRESS / BREAK-LOOP。
120
+ - **仅当**这三者都未触发时才允许重 spawn。任一触发即停:重新收敛子任务范围、修掉阻塞点,或上报用户。绝不越过停机指令继续重 spawn。
105
121
  3. 若输出含 `STATUS: NEEDS_CLARIFICATION` + 问题列表:STOP,用 AskUserQuestion 原样转达,把答案 append 进 spec,再重 spawn。
106
- 4. 命中 `<promise>COMPLETE</promise>`:Bash `harnessed checkpoint complete task-deliver --summary "<one-line>"`。evidence guard 在此运行(fail-CLOSED):若声明的 `artifacts_expected` 文件缺失会 exit 非零 —— 重 spawn 产出它再算 done。
122
+ 4. 命中 `<promise>COMPLETE</promise>`:把 subagent 最终输出写入文件,再 Bash `harnessed checkpoint complete task-deliver --result-file <path> --summary "<one-line>"`。fail-CLOSED —— 除非声明的 `artifacts_expected` 文件全部存在、TDD boundary 通过(证据非空 / 红绿两侧齐全 / 测试文件未被删除)、且结果含逐字 `<promise>COMPLETE</promise>`(或结构化 COMPLETE 状态),否则拦下。`--result <text>` 是内联变体;`--result-file` 优先且在 Windows 上引号安全。`--force` 记录可审计的覆盖(`evidence_status=overridden`),不是静默放行。
123
+ 5. 若 complete 闸门拦下:Bash `harnessed checkpoint fail task-deliver --failing-tests <n>` 记录本次尝试。命中停机条件时会打印 `BUDGET-EXHAUSTED` / `NO-PROGRESS` / `BREAK-LOOP`。**仅当**三者都未触发时才允许重 spawn;任一触发即 STOP —— 重新收敛子任务范围、修掉阻塞点,或上报用户。
107
124
 
108
- <!-- harnessed-generated:v4.9.3 -->
125
+ <!-- harnessed-generated:v4.12.0 -->
109
126
 
110
127
  ## References
111
128
 
112
129
  - D-09 — L0 Discipline Substrate always-on (6 disciplines)
113
- - D-10 — ralph-loop 真接 SDK wrapper (NOT mock reference; v0.2.0 ship)
130
+ - D-10 — 完成保证真接 SDK wrapper (NOT mock reference; v0.2.0 ship)
114
131
  - D-11 — Agent Teams 升级 5 触发 OR-chain per bundled parallelism-gate rules
115
- - R20.10 — ralph-loop max_iterations_exceeded explicit emit_warning_and_halt
116
- (acceptance c "NOT silent abort"); ralph-loop 正交 wrapper wraps 3 mode
132
+ - R20.10 — max_iterations_exceeded explicit emit_warning_and_halt
133
+ (acceptance c "NOT silent abort"); 完成闸门正交 wrapper wraps 3 mode
117
134
  - D-02 — SKILL.md `name:` bare slash cmd (`task-deliver` NOT `task/deliver`) per ADR 0030
118
- - ADR 0011 — SDK + ralph-loop integration v0.2.0 baseline
119
- - `workflows/judgments/parallelism-gate.yaml` triggers.ralph-loop-wrapper +
135
+ - ADR 0011 — SDK + 完成保证 integration v0.2.0 baseline
136
+ - ADR 0039 — 完成保证内置化 + 摘除上游 `/ralph-loop` 依赖(supersedes ADR 0036)
137
+ - `workflows/judgments/parallelism-gate.yaml` triggers.completion-gate-wrapper +
120
138
  agent-teams-upgrade + subagent-default + main-session-fallback
121
- - `workflows/capabilities.yaml` — ralph-loop + agent-teams-{create,send-message,shutdown}
139
+ - `workflows/capabilities.yaml` — completion-gate + agent-teams-{create,send-message,shutdown}
122
140
  + planning-with-files entries
123
141
  - `workflows/defaults.yaml` — ralph_max_iterations.task-deliver.* values (T3.4.W2.2 followup)
124
142
  - `docs/WORKFLOW.md` — 4-stage workflow mermaid + Stage ③ Execute 章节