@mstar-harness/opencode 1.4.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to the `@mstar-harness/opencode` package are documented in t
4
4
 
5
5
  The monorepo root [CHANGELOG.md](../../CHANGELOG.md) summarizes cross-surface releases.
6
6
 
7
+ ## 1.5.0
8
+
9
+ - Version alignment with harness **1.5.0** (bundled skills/commands: iteration Phase 2 worktree/lease + Phase 5 babysit-first helpers).
10
+
11
+ See root [CHANGELOG.md](../../CHANGELOG.md) **1.5.0**.
12
+
7
13
  ## 1.4.0
8
14
 
9
15
  - Version alignment with harness **1.4.0** (Kimi Code host support lives in shared skills / `.kimi-plugin`; OpenCode package unchanged beyond version bump).
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: iteration-drive
3
- description: Drive the active iteration to completion — Phase 2 Autonomous Execute, Phase 3 iteration-close, Phase 4 Create PR, Phase 5 PR merge-ready loop (greploop / babysit / CI fallback) until mergeable. Not Done until Phase 5 exit checklist passes.
3
+ description: Drive the active iteration to completion — Phase 2 Autonomous Execute, Phase 3 iteration-close, Phase 4 Create PR, Phase 5 PR merge-ready loop (prefer babysit/*-babysit; optional greploop when repo has it; else CI fallback) until mergeable. Not Done until Phase 5 exit checklist passes.
4
4
  agent: project-manager
5
5
  ---
6
6
 
@@ -32,9 +32,9 @@ Phase 2: Autonomous Execute → Phase 3: iteration-close → Phase 4: Create
32
32
  | 禁止 | 必须 |
33
33
  |------|------|
34
34
  | plan / task / phase 边界问用户「是否继续」「要不要现在启动」「是否开 PR」等例行 yes/no | 进度摘要后**下一条动作** = **dispatch**(`Task`)或下一 phase 步骤(打印 checklist → 执行) |
35
- | 用完整 Phase 2 汇报收束 turn 后等待用户 | 同 plan 内 task 间 → **`mstar-sdd` Continuous execution**;当前 plan Done **立刻**下一 plan dispatch |
35
+ | 用完整 Phase 2 汇报收束 turn 后等待用户 | 同 plan 内 task 间 → **`mstar-sdd` Continuous execution**;其他 plan **lease 门控并行** implement;merge 仍串行 |
36
36
  | 把 `## Phase 3/4/5` 标题当作可停下协商点(除合法 STOP) | Phase 3 checklist `[x]` → **立刻** Phase 4;PR 创建后 → **立刻** Phase 5 loop |
37
- | 跨 plan **并行** implement dispatch(多 plan 同时跑 implementer) | Per-plan **串行**:plan A implement→QC→QA→Done 后再 plan B(除非用户书面 override) |
37
+ | 跨 plan **无 lease** 并行 implement | **默认 lease 门控并行**(distinct `execution_lease` + feature worktree);显式 `Plan parallelism: serial` 可恢复逐 plan 串行 |
38
38
 
39
39
  **合法 STOP(仅此升级用户)**:
40
40
 
@@ -79,12 +79,13 @@ SSOT 细化:`mstar-sdd`(task 级)· `mstar-iteration` §2.6(push 纪律
79
79
  6. **`mstar-sdd`** — **before first implement dispatch** in Phase 2(per-task loop SSOT;多 task plan 默认 `Execution mode: sdd`)
80
80
  7. `mstar-review-qc` — before first QC dispatch in Phase 2
81
81
  8. `mstar-plan-artifacts`, `mstar-plan-conventions`, `mstar-branch-worktree`
82
+ 9. **`mstar-iteration/references/phase-2-worktree-lease.md`** — Phase 2 control worktree、`execution_lease`、serial `integration_merge_lease`(§2.0 #5 未 waive)
82
83
 
83
84
  ## Phase 2: Autonomous Execute
84
85
 
85
86
  **Continuous execution applies** — 本节全程遵守上节 **Continuous execution(HARD)**;Completion Report / 进度同步后不得 check-in,下一条必须是 dispatch 或下一 plan。
86
87
 
87
- **Branch policy first** — before any plan dispatch(`mstar-iteration` §2.3):
88
+ **Branch policy + control worktree first** — before any plan dispatch(`mstar-iteration` §2.3 + **`references/phase-2-worktree-lease.md`**):
88
89
 
89
90
  | Field | SSOT | If missing |
90
91
  |-------|------|------------|
@@ -94,12 +95,13 @@ SSOT 细化:`mstar-sdd`(task 级)· `mstar-iteration` §2.6(push 纪律
94
95
 
95
96
  Execute **`mstar-iteration` § Phase 2** exactly. Summary:
96
97
 
97
- 1. **Precondition gate** (§ 2.0) — **four** checks(含 branch metadata #4)
98
+ 1. **Precondition gate** (§ 2.0) — **five** checks(含 branch metadata #4 + control-worktree/lease #5
98
99
  2. **Session todos** (§ 2.1) — set host todos per plan wave
99
100
  3. **Read backlog** (§ 2.2) — `status.json` + branch metadata
100
- 4. **Integration branch** (§ 2.3) — `git checkout -b <spec_integration_branch> <iteration_base_branch>` when creating(**not** implicit `main`)
101
- 5. **Per-plan loop** (§ 2.4) — for each non-`Done` plan:
102
- - Create plan feature branch from integration
101
+ 4. **Integration branch + control worktree** (§ 2.3) — establish control worktree on `spec_integration_branch`; record `metadata.control_worktree_path`; status/SDD via control path
102
+ 5. **Per-plan loop** (§ 2.4) — for each active plan(**lease-gated parallel** across plan IDs unless `Plan parallelism: serial`):
103
+ - Claim or resume `execution_lease`(same `holder` → verify-held-lease; different holder → Blocked)
104
+ - Create/verify plan feature worktree + branch(`Worktree path` in Assignment)
103
105
  - **SDD implement**(默认 `Execution mode: sdd`;`mstar-sdd` 已载入)— per task **串行**:
104
106
  1. `sdd-workspace <plan-id>` → `{SDD_DIR}`
105
107
  2. `task-brief <plan> N` → `{SDD_DIR}/task-N-brief.md`
@@ -111,9 +113,9 @@ Execute **`mstar-iteration` § Phase 2** exactly. Summary:
111
113
  - **禁止**:把整份 plan 或 T1–Tn 全文贴进 implement dispatch;文件交接 SSOT → `mstar-sdd/references/file-handoffs.md`
112
114
  - Update `status.json` + main plan after each Completion Report v2
113
115
  - QC **full tri-review** (`QC mode: full tri-review`, **N=3**, `mstar-review-qc`) + branch `review-package` + QA per plan
114
- - Merge plan branch → integration branch
116
+ - **Serial merge** plan branch → integration(`metadata.integration_merge_lease` from control worktree)
115
117
  - Cross-plan progress sync → compass
116
- - Next plan
118
+ - Next plan / parallel wave
117
119
  6. Repeat until **all** plans `Done` → **STOP**(见 Phase state machine)→ 打印 `## Phase 3: iteration-close` → 执行 **`mstar-iteration` §3**;**不得**进入 Phase 4
118
120
 
119
121
  派发回合纪律 → **`mstar-dispatch-gates`** + **`mstar-iteration` §2.5**。
@@ -170,20 +172,22 @@ Before the first loop pass, search for bundled/host skills(first readable `SKI
170
172
 
171
173
  | Skill | Search paths(示例,按宿主扩展) |
172
174
  |-------|----------------------------------|
173
- | `greploop` | `skills/greploop/SKILL.md`;`~/.cursor/skills-cursor/greploop/SKILL.md`;`~/.agents/skills/greploop/SKILL.md`;Codex plugin `skills/greploop/` |
174
- | `babysit` | `skills/babysit/SKILL.md`;`~/.cursor/skills-cursor/babysit/SKILL.md`;`~/.agents/skills/babysit/SKILL.md` |
175
+ | `babysit` / `*-babysit` | `skills/babysit/SKILL.md`;`skills/*-babysit/SKILL.md`;`~/.cursor/skills-cursor/babysit/SKILL.md`;`~/.cursor/skills-cursor/*-babysit/SKILL.md`;`~/.agents/skills/babysit/SKILL.md`;`~/.agents/skills/*-babysit/SKILL.md` |
176
+ | `greploop`(optional) | `skills/greploop/SKILL.md`;`~/.cursor/skills-cursor/greploop/SKILL.md`;`~/.agents/skills/greploop/SKILL.md`;Codex plugin `skills/greploop/` — **only adopt when the repo uses Greptile / has greploop** |
175
177
 
176
- **Mode selection**:
178
+ **Mode selection**(**babysit-first**):
177
179
 
178
180
  | Priority | Condition | Read before loop | Primary done signal |
179
181
  |----------|-----------|------------------|---------------------|
180
- | 1 | `greploop` found | `greploop` SKILL.md | Greptile score **5/5** on this PR |
181
- | 2 | else `babysit` found | `babysit` SKILL.md | Required CI **all green** + **all** review threads **resolved** |
182
- | 3 | else neither | —(本 command §5.2–§5.4) | Required CI **all green** + **all** review threads **resolved** |
182
+ | 1 | `babysit` **or** any `*-babysit` found | that skill’s `SKILL.md`(prefer exact `babysit`, else first matching `*-babysit`) | Required CI **all green** + **all** review threads **resolved** |
183
+ | 2 | `greploop` found **and** repo has Greptile/greploop | `greploop` SKILL.md | Greptile score **5/5** on this PR(**additive** does not replace priority-1 gates) |
184
+ | 3 | else neither babysit/`*-babysit` | —(本 command §5.2–§5.4) | Required CI **all green** + **all** review threads **resolved** |
183
185
 
184
- **Both greploop and babysit present**: run greploop until **5/5**, then babysit until CI green + reviews resolved(串行;§5.5 仍须满足全部 exit 项).
186
+ **Both babysit/`*-babysit` and greploop apply**: run **babysit/`*-babysit` first**(CI + reviews),then optional greploop until Greptile **5/5**(串行;§5.5 仍须满足全部 exit 项). Do **not** prefer greploop over babysit.
185
187
 
186
- **All modes** share §5.5 exit checklist(CI + reviews + mergeable;Greptile 5/5 mode / repo 条件).
188
+ **No greploop / repo without Greptile**: skip greploop entirely babysit/`*-babysit` or fallback only.
189
+
190
+ **All modes** share §5.5 exit checklist(CI + reviews + mergeable;Greptile 5/5 only when greploop mode ran or repo shows a Greptile score).
187
191
 
188
192
  ### 5.1 PM invariants(Phase 5)
189
193
 
@@ -204,12 +208,12 @@ Repeat until §5.5 exit checklist passes:
204
208
  3. **Active reviews** — fetch **unresolved** review threads only;triage valid change requests
205
209
  4. **CI** — list failing required checks;dispatch or fix in-scope → push
206
210
  5. **Mode-specific pass**:
207
- - **greploop**: follow greploop SKILL until Greptile **5/5**
208
- - **babysit**: follow babysit SKILL(comments + CI loop)
209
- - **fallback**: triage unresolved review threads(§5.3)+ poll CI until all required checks green(no skill Read;**与 babysit 同级的 CI + reviews 门禁**)
211
+ - **babysit / `*-babysit`**: follow that SKILL(comments + CI loop)— **primary**
212
+ - **greploop**(optional, repo has it): follow greploop SKILL until Greptile **5/5** — **after** babysit/`*-babysit` gates when both apply
213
+ - **fallback**(no babysit/`*-babysit`): triage unresolved review threads(§5.3)+ poll CI until all required checks green(no skill Read;**与 babysit 同级的 CI + reviews 门禁**)
210
214
  6. After each push → §5.3 → return to step 1
211
215
 
212
- **Stop looping only when** §5.5 全 `[x]`。若多轮仍 blocked → 升级用户(列出 failing checks / unresolved threads / Greptile score)。
216
+ **Stop looping only when** §5.5 全 `[x]`。若多轮仍 blocked → 升级用户(列出 failing checks / unresolved threads / Greptile score if greploop mode)。
213
217
 
214
218
  ### 5.3 Review fix hygiene(HARD — all modes)
215
219
 
@@ -221,9 +225,9 @@ Whenever a push addresses PR review feedback(human or bot, including Bugbot /
221
225
 
222
226
  Do not bulk-resolve without a per-thread reply. Disagree or uncertain → reply explaining why; leave unresolved and escalate.
223
227
 
224
- ### 5.4 Fallback mode detail(no greploop / babysit
228
+ ### 5.4 Fallback mode detail(no babysit / `*-babysit`)
225
229
 
226
- When neither skill is found, **本 command 承担 babysit 同级职责**(无外部 SKILL,但 exit 标准相同):
230
+ When no `babysit` / `*-babysit` skill is found, **本 command 承担 babysit 同级职责**(无外部 SKILL,但 exit 标准相同)。`greploop` alone does **not** replace babysit — if only greploop is present and the repo has Greptile, still run §5.4 for CI + reviews, and optionally greploop for score:
227
231
 
228
232
  1. Fetch **unresolved** review threads;triage valid change requests → dispatch fix → push → §5.3 comment + resolve
229
233
  2. Poll PR required checks until **all green**(reasonable backoff between polls)
@@ -238,7 +242,7 @@ When neither skill is found, **本 command 承担 babysit 同级职责**(无
238
242
  - [ ] PR mergeable(无 blocking merge conflicts)
239
243
  - [ ] All **required** CI checks green on latest head
240
244
  - [ ] All review threads **resolved**(或用户书面 waive 特定 thread)
241
- - [ ] Greptile **5/5**(若运行了 greploop mode,或 repo 启用 Greptile 且 PR 上可见分数)
245
+ - [ ] Greptile **5/5**(**仅当**采用了可选 greploop mode,或 repo 启用 Greptile 且 PR 上可见分数;无 Greptile 则本项 N/A)
242
246
  - [ ] §5.3 comment + resolve 已完成于本轮所有 addressed reviews
243
247
  - [ ] Host todo `phase-5-pr-merge-ready` 可勾选
244
248
 
@@ -62,8 +62,8 @@ Phase 1: Autonomous start → Phase 2: Autonomous Execute → Phase 3: close
62
62
  | 禁止 | 必须 |
63
63
  |------|------|
64
64
  | 方向 / plan / phase 边界例行 yes/no(「是否同意该方向」「要不要继续」「是否开 PR」) | 进度摘要后**下一条** = dispatch 或下一 phase 步骤 |
65
- | 用 Phase 汇报收束 turn 后等待用户 | Phase 1 lock → **立刻** Phase 2;plan Done 下一 plan Phase 3 |
66
- | 跨 plan 并行 implement | Per-plan **串行** |
65
+ | 用 Phase 汇报收束 turn 后等待用户 | Phase 1 lock → **立刻** Phase 2;plan lease 门控并行 implement;merge 串行 |
66
+ | 跨 plan 无 lease 并行 implement | **默认 lease 门控并行**;`Plan parallelism: serial` 恢复逐 plan 串行 |
67
67
 
68
68
  **合法 STOP(仅此升级用户)**:
69
69
 
@@ -119,6 +119,7 @@ Phase 1: Autonomous start → Phase 2: Autonomous Execute → Phase 3: close
119
119
  9. **`mstar-sdd`** — before first implement dispatch in Phase 2
120
120
  10. `mstar-review-qc` — before first QC dispatch in Phase 2
121
121
  11. `mstar-branch-worktree` — when Git/write or QC checkout
122
+ 12. **`mstar-iteration/references/phase-2-worktree-lease.md`** — Phase 2 control worktree + lease(§2.0 #5 未 waive)
122
123
 
123
124
  **Do not** Read `skills/grill-me/SKILL.md` for this command.
124
125
 
@@ -218,15 +219,15 @@ Register branch fields in compass + `status.json`. Commit docs; push.
218
219
 
219
220
  ## Phase 2: Autonomous Execute
220
221
 
221
- **Continuous execution applies.** Branch policy first(`mstar-iteration` §2.3).
222
+ **Continuous execution applies.** Branch policy + control worktree first(`mstar-iteration` §2.3 + **`references/phase-2-worktree-lease.md`**).
222
223
 
223
224
  Execute **`mstar-iteration` § Phase 2** exactly. Summary:
224
225
 
225
- 1. Precondition gate §2.0(four checks)
226
+ 1. Precondition gate §2.0(five checks;含 control-worktree + lease defaults
226
227
  2. Session todos §2.1
227
228
  3. Read backlog §2.2
228
- 4. Integration branch §2.3
229
- 5. Per-plan loop §2.4 — **SDD** default; serial implementer task reviewer; QC **full tri-review** N=3; QA gate; merge to integration; next plan
229
+ 4. Integration branch + control worktree §2.3
230
+ 5. Per-plan loop §2.4 — **lease-gated parallel** across plan IDs(unless `Plan parallelism: serial`);claim/resume `execution_lease`;feature worktree;**SDD** default;serial merge via `integration_merge_lease`
230
231
  6. All plans `Done` → print `## Phase 3: iteration-close` → **`mstar-iteration` §3**(不得开 PR)
231
232
 
232
233
  派发纪律 → **`mstar-dispatch-gates`** + **`mstar-iteration` §2.5**。
@@ -264,16 +265,16 @@ Execute **`mstar-iteration` § Phase 5**。**§5.5 exit 全 `[x]` = iteration-lo
264
265
 
265
266
  | Skill | Search paths(示例) |
266
267
  |-------|----------------------|
267
- | `greploop` | `skills/greploop/SKILL.md`;`~/.cursor/skills-cursor/greploop/SKILL.md`;`~/.agents/skills/greploop/SKILL.md` |
268
- | `babysit` | `skills/babysit/SKILL.md`;`~/.cursor/skills-cursor/babysit/SKILL.md`;`~/.agents/skills/babysit/SKILL.md` |
268
+ | `babysit` / `*-babysit` | `skills/babysit/SKILL.md`;`skills/*-babysit/SKILL.md`;`~/.cursor/skills-cursor/babysit/`;`~/.agents/skills/babysit/`(及 `*-babysit`) |
269
+ | `greploop`(optional) | `skills/greploop/…`;host skill dirs — **only when repo has Greptile/greploop** |
269
270
 
270
271
  | Priority | Condition | Primary done signal |
271
272
  |----------|-----------|---------------------|
272
- | 1 | `greploop` found | Greptile **5/5** |
273
- | 2 | else `babysit` | Required CI green + reviews resolved |
274
- | 3 | else neither | Same as babysit(本 command fallback) |
273
+ | 1 | `babysit` or any `*-babysit` | Required CI green + reviews resolved |
274
+ | 2 | `greploop` **and** repo has Greptile | Greptile **5/5**(additive) |
275
+ | 3 | else neither babysit/`*-babysit` | Same as babysit(本 command fallback) |
275
276
 
276
- Both present: greploop to 5/5, then babysit(串行).
277
+ Both apply: **babysit/`*-babysit` first**, then optional greploop(串行). Do not prefer greploop over babysit.
277
278
 
278
279
  ### 5.1–5.4 Loop
279
280
 
@@ -288,7 +289,7 @@ Fixes push to `spec_integration_branch` only. PM does not rewrite product code i
288
289
  - [ ] PR mergeable
289
290
  - [ ] All **required** CI checks green on latest head
290
291
  - [ ] All review threads **resolved**(或用户书面 waive)
291
- - [ ] Greptile **5/5**(若 greploop mode / repo 可见分数)
292
+ - [ ] Greptile **5/5**(**仅当**可选 greploop mode / repo 可见分数;否则 N/A)
292
293
  - [ ] Review comment + resolve 已覆盖本轮 addressed feedback
293
294
  - [ ] Host todo `phase-5-pr-merge-ready` 可勾选
294
295
 
@@ -280,4 +280,6 @@ git checkout -b <spec_integration_branch> <iteration_base_branch>
280
280
  - Register `iteration_base_branch`, `spec_integration_branch`, and `target_branch` in compass frontmatter **and** `{HARNESS_DIR}/status.json` root `metadata`
281
281
  - Commit all documents to the integration branch and push to remote
282
282
 
283
+ **Phase 2 note**:integration 分支在此创建;**control worktree + `execution_lease` 门控在 Phase 2 入口**(`iteration-drive` / `iteration-loop`)——见 **`mstar-iteration/references/phase-2-worktree-lease.md`**。
284
+
283
285
  **STOP** if `iteration_base_branch` or `target_branch` is missing. Ask the user or derive only from an already documented project/iteration policy; never silently substitute `main`.
@@ -1,19 +1,20 @@
1
1
  ---
2
2
  name: mstar-branch-worktree
3
- description: Morning Star business-repo Git feature branches, same-repo concurrent `git worktree` isolation (N parallel Task invokes do NOT satisfy isolation — worktrees must exist before writable dispatch), plan/Spec integration branches, and QC/QA checkout alignment (`Review cwd`, `Working branch`, `plan_id`, `Review range` / `Diff basis` must match verbatim across three QC reviewers and QA). Read when PM writes `Working branch` / `Branch policy`, dispatches ≥2 concurrent writable implement tracks on one repo, `Worktree isolation: required`, two or more writable streams touch one repo, dispatching QC tri-review or QA after merging to a single `HEAD`, dev/QA/ops before first `git commit`, or explaining worktree paths. Required for `project-manager` parallel implement or pre-QC orchestration; `fullstack-dev*` / `frontend-dev` / `qa-engineer` / `ops-engineer` on repo writes; `qc-specialist*` before review. Does not replace the state machine (`mstar-harness-core`).
3
+ description: Morning Star business-repo Git feature branches, worktree isolation layers **L1** (iteration cross-plan control worktree + per-plan feature worktrees + `execution_lease`) and **L2** (within-plan — `references/parallel-writable-pre-dispatch.md`; N parallel Task invokes do NOT satisfy isolation), plan/Spec integration branches, and QC/QA checkout alignment (`Review cwd`, `Working branch`, `plan_id`, `Review range` / `Diff basis` must match verbatim across three QC reviewers and QA). Read when PM writes `Working branch` / `Branch policy`, iteration Phase 2 control vs feature worktree paths, dispatches ≥2 concurrent writable implement tracks on one repo, `Worktree isolation: required`, two or more writable streams touch one repo, dispatching QC tri-review or QA after merging to a single `HEAD`, dev/QA/ops before first `git commit`, or explaining worktree paths. Required for `project-manager` parallel implement or pre-QC orchestration; `fullstack-dev*` / `frontend-dev` / `qa-engineer` / `ops-engineer` on repo writes; `qc-specialist*` before review. Does not replace the state machine (`mstar-harness-core`).
4
4
  ---
5
5
 
6
6
  ## Load order(必读顺序)
7
7
 
8
8
  **首次 Read 本 skill 前:必须先 Read `mstar-harness-core`(SKILL.md)。** 冲突时 **以 `mstar-harness-core` 为准**。
9
9
 
10
- **Spec 多 plan 命名**(`iteration_base_branch`、`spec_integration_branch`、`target_branch` PR 门禁)→ **`mstar-plan-conventions`**。同仓并行可写派发前清单 → **`references/parallel-writable-pre-dispatch.md`**;下文为分支与 QC/QA 检出对齐主文。
10
+ **Spec 多 plan 命名**(`iteration_base_branch`、`spec_integration_branch`、`target_branch` PR 门禁)→ **`mstar-plan-conventions`**。**L1/L2 worktree 分层**(迭代 control vs feature、plan 内并行轨)→ 下文 **「Worktree isolation layers」**;**L2** 同仓并行可写派发前清单 → **`references/parallel-writable-pre-dispatch.md`**;迭代 lease claim/merge 细则 → **`mstar-iteration`** `references/phase-2-worktree-lease.md`(勿在本 skill 重复完整协议表)。下文为分支与 QC/QA 检出对齐主文。
11
11
 
12
12
  ## Scope(摘要)
13
13
 
14
14
  - **仅 PM 决定分支**;其他可写角色不得自行新开分支或切回 `main`。
15
15
  - **Assignment 须含其一**:`Working branch: <existing>` | `create <new> from <base>` | `Branch policy: direct on <branch> — <reason>`。
16
- - **同仓 ≥2 可写并发**:派发 **前** 完成 **`references/parallel-writable-pre-dispatch.md`**(含 `git worktree`、绝对 **`Worktree path`**;**N 次并行 invoke 已隔离**)。
16
+ - **L1(跨 plan / 迭代 Phase 2)**:control worktree(`metadata.control_worktree_path`,检出 `spec_integration_branch`)+ 每 plan 独立 feature worktree(`execution_lease.worktree_path` **≠** control 路径)+ lease;见 **「Worktree isolation layers」**。
17
+ - **L2(同 plan 内 ≥2 可写并发)**:派发 **前** 完成 **`references/parallel-writable-pre-dispatch.md`**(含 `git worktree`、绝对 **`Worktree path`**;**N 次并行 invoke ≠ 已隔离**)。单 plan 多轨时 **L1 不替代 L2**。
17
18
  - **QC/QA 前**:待审提交归并到 **单一 `Working branch` `HEAD`**;三审 + QA 共用一套 **`Review cwd` + `plan_id` + `Review range` / `Diff basis`**(逐字相同)。
18
19
 
19
20
  ## Git 功能分支、同仓并发与 Worktree 对齐
@@ -99,9 +100,46 @@ description: Morning Star business-repo Git feature branches, same-repo concurre
99
100
 
100
101
  - `Working branch used: <branch-name>`
101
102
 
103
+ ## Worktree isolation layers (L1 vs L2)
104
+
105
+ Two complementary **worktree** isolation layers coexist. Do **not** conflate them with SDD **review** layers (L1–L4 in `mstar-review-qc/references/review-responsibility-boundaries.md`).
106
+
107
+ | Layer | Scope | When | Mechanism |
108
+ |-------|-------|------|-----------|
109
+ | **L1** | Cross-plan (iteration Phase 2) | Multiple plans may implement concurrently in one iteration | **Control worktree** + per-plan **feature worktrees** + `plans[].execution_lease` |
110
+ | **L2** | Within-plan | Same `plan_id`, same business repo, **≥2 concurrent writable implement tracks** | **`references/parallel-writable-pre-dispatch.md`** — distinct absolute **`Worktree path`** per track |
111
+
112
+ **Stacking rules**
113
+
114
+ - Default **L1** capacity is **one writable track per plan**. If one plan runs **≥2** concurrent writable tracks, each track **also** satisfies **L2**; L1 does **not** replace L2.
115
+ - **L1** applies under iteration commands with Phase 2 control-worktree defaults (unless explicit `Worktree mode: waived` this turn). Single-plan waves without iteration leases still require **L2** when **≥2** parallel writable tracks share one repo.
116
+ - Cross-plan **integration merge** into `spec_integration_branch` remains **serial** (`metadata.integration_merge_lease`) even when L1 feature implementation runs in parallel.
117
+
118
+ ### Control worktree vs feature worktree (iteration / L1)
119
+
120
+ Established at iteration **Phase 2 entry** (Phase 1 Review & Edit may stay on the primary checkout). Normative field names and claim/release/merge protocol → **`mstar-iteration`** `references/phase-2-worktree-lease.md` and maintenance ADR `2026-07-22-iteration-worktree-plan-lease.md`. **Do not invent alternate lease field names in this skill.**
121
+
122
+ | Worktree role | Checked-out branch | Path recorded in `status.json` | Writable product edits |
123
+ |---------------|-------------------|-------------------------------|------------------------|
124
+ | **Control worktree** | Resolved `spec_integration_branch` (same across active plans) | `metadata.control_worktree_path` — canonical **repository root** (not `{HARNESS_DIR}`) | **Forbidden** — coordination, status/SDD SSOT, serial integration merge only |
125
+ | **Feature worktree** (per plan) | Plan `Working branch` / feature branch from integration | `plans[].execution_lease.worktree_path` | **Required cwd** for that plan's product/source edits |
126
+
127
+ **Hard rules**
128
+
129
+ - `execution_lease.worktree_path` **MUST** differ from `metadata.control_worktree_path`.
130
+ - Status SSOT: `<control_worktree_path>/{HARNESS_DIR}/status.json`. SDD SSOT: `<control_worktree_path>/{HARNESS_DIR}/sdd/<plan-id>/`. A feature worktree's same-looking `{HARNESS_DIR}` path is **not** the SSOT.
131
+ - Absolute **`Worktree path`** MUST appear in the writable Assignment and in `execution_lease.worktree_path` before first writable implement dispatch for that plan.
132
+ - Writable dispatch for a plan requires a **verified** `execution_lease` (same read-check-replace-verify discipline as the iteration reference). Full claim tables are **not** duplicated here.
133
+
134
+ **Naming conventions (PM / ops; examples only — paths MUST be canonical absolute)**
135
+
136
+ 1. **Control worktree** — usually the primary checkout or a PM-designated path on `spec_integration_branch`; record once in `metadata.control_worktree_path`.
137
+ 2. **Feature worktree (per plan)** — one distinct sibling directory per active `plan_id`, e.g. `<repo-parent>/worktrees/<plan-id>` or team `.worktrees/<plan-id>`; Assignment **`Worktree path`** must match lease `worktree_path`.
138
+ 3. **L2 track worktrees (within-plan)** — additional distinct directories per parallel implement track under the **same** plan (see **`references/parallel-writable-pre-dispatch.md`**), each with its own PM-approved **`Working branch`**.
139
+
102
140
  ## 同仓并发写入与 Git worktree(强制)
103
141
 
104
- **首要场景是开发阶段**:多条可写流 **并发** 改 **同一仓库** 时,用 worktree 做 **写入侧目录隔离**。派发前清单 → **`references/parallel-writable-pre-dispatch.md`**。下列规则针对该类开发并发;**QC / QA 阶段的检出约定**见下一小节。
142
+ **首要场景是开发阶段(L2;迭代多 plan 时另见上文 L1)**:多条可写流 **并发** 改 **同一仓库** 时,用 worktree 做 **写入侧目录隔离**。派发前清单 → **`references/parallel-writable-pre-dispatch.md`**。下列规则针对该类开发并发;**QC / QA 阶段的检出约定**见下一小节。
105
143
 
106
144
  当 **`project-manager` 在同一调度轮次内并发启动多个** subagent(含宿主侧「并行 Task / 并行 subagent」),且 **≥2 个承接方**可能对 **同一 Git 仓库的同一工作区(同一 cwd 检出目录)**产生写文件或 `git commit` 级改动时:
107
145
 
@@ -1,5 +1,17 @@
1
1
  # Parallel writable pre-dispatch gate (PM)
2
2
 
3
+ ## Layer: L2 (within-plan)
4
+
5
+ This reference is **L2** worktree isolation: **same `plan_id`**, **same business repo**, **≥2 concurrent writable implement tracks**.
6
+
7
+ **L1 (cross-plan)** is separate and stacks on top when iteration Phase 2 defaults apply:
8
+
9
+ - A **control worktree** on `spec_integration_branch` (`metadata.control_worktree_path`) holds status/SDD SSOT and serial integration merge.
10
+ - Each concurrently active plan uses a **distinct feature worktree** (`execution_lease.worktree_path` **≠** `control_worktree_path`) with verified `plans[].execution_lease` before writable dispatch.
11
+ - Claim/hold/release/merge rules → **`mstar-iteration`** `references/phase-2-worktree-lease.md` (not repeated here).
12
+
13
+ When **one plan** runs **≥2** concurrent writable tracks, **L2 still applies** inside that plan even if L1 leases already isolate plans from each other. Run this checklist **per plan** that has multiple parallel implement tracks.
14
+
3
15
  ## Why this exists
4
16
 
5
17
  Host dispatch can satisfy **「N Assignments ⇒ N invokes in one message」** while every writer still shares **one checkout directory**. That may satisfy `mstar-dispatch-gates` tool concurrency but **violates** same-repo write isolation.
@@ -8,9 +20,9 @@ Host dispatch can satisfy **「N Assignments ⇒ N invokes in one message」** w
8
20
 
9
21
  ## Mode switch (do not carry single-track habits)
10
22
 
11
- Serial single-plan waves (one feature branch, one checkout, PM on integration) do **not** authorize multi-writer parallel tracks without re-running this gate.
23
+ Serial single-plan waves (one feature branch, one checkout, PM on integration) do **not** authorize multi-writer parallel tracks without re-running this **L2** gate.
12
24
 
13
- When the round adds a second **concurrent** writable implement track on the **same business repo**, treat it as a **mode switch** — even if earlier plans in the iteration were serial.
25
+ When the round adds a second **concurrent** writable implement track on the **same business repo** within one plan, treat it as a **mode switch** — even if earlier plans in the iteration were serial or L1 already assigned each plan its own feature worktree.
14
26
 
15
27
  ## Pre-dispatch checklist (HARD)
16
28
 
@@ -84,8 +84,11 @@ When **`Execution mode: sdd`** (`mstar-sdd`):
84
84
  | **工具并发** | 同条消息发满 N 次 invoke | 已发 2 个 Task ⇒ 误以为「并行合规」 |
85
85
  | **同仓写隔离** | 派发 **前** 每轨独立 `Worktree path` | 只写了 `Working branch` / `checkout -b` |
86
86
 
87
- - 独立模块可并行 **implement 轨道**(不同 dev Assignment);**同仓 ≥2 可写并发** → **`mstar-branch-worktree`** **`references/parallel-writable-pre-dispatch.md`**(先于 invoke)。
88
- - **SDD 单 plan task** 仍串行(`mstar-sdd`);plan 间默认串行(`mstar-iteration` §2.6)— 用户书面 override 时仍须 worktree 隔离。
87
+ - 独立模块可并行 **implement 轨道**(不同 dev Assignment);**同仓 ≥2 可写并发** → **`mstar-branch-worktree`** **`references/parallel-writable-pre-dispatch.md`**(先于 invoke;同 plan 多轨 = L2)。
88
+ - **SDD 单 plan 内**:task / implementer **仍串行**(`mstar-sdd`);**禁止**同一 plan 内并行 SDD implementer(写冲突)。
89
+ - **跨 plan(迭代 Phase 2)≠ 单 plan 内并行**:不同 `plan_id` 的 feature implement **允许** lease 门控并行(每 plan 独立 verified `plans[].execution_lease` + feature worktree,L1)**仅当** coordination 路径 same-host 独占写锁可用且每次协调变更持锁 → **`mstar-iteration`** §2.0 #5 · **`mstar-plan-artifacts`**。**跨主机 / 无共享 flock** → 默认 **`Plan parallelism: serial`** 或 Assignment 仍写并行 → **Blocked**(用户本轮 `Cross-host lease race: accepted` + audit `notes` 除外)。**`Worktree mode: waived` 不豁免**跨 plan 并行安全闸。**禁止**无 lease 的跨 plan 可写派发(lease 闸未 waive 时)。
90
+ - **`integration_merge_lease`**:`spec_integration_branch` 上的 merge **始终串行**(一次仅一 holder)→ **`mstar-iteration`** · **`mstar-plan-artifacts`**。
91
+ - **`Plan parallelism: serial`**:仅强制跨 plan implement **调度串行**;**不** waive control worktree / `execution_lease` / `integration_merge_lease`(`Worktree mode: waived` 才是 lease/worktree 豁免)→ **`mstar-iteration`** §2.0 #5。
89
92
  - **Plan QC tri** after SDD task loop(`Execution mode: sdd`);**单席**仅 `inline` / hotfix。共用 `Review cwd` / `Working branch` / `plan_id` / `Review range`(**`mstar-branch-worktree`**)。
90
93
  - **Tri 同消息规则**:plan QC tri(SDD 或 Assignment 显式 `QC mode: full tri-review`)时三席 **同一条消息**、**同一套** scope 字段。
91
94
 
@@ -104,8 +107,12 @@ When **`Execution mode: sdd`** (`mstar-sdd`):
104
107
 
105
108
  - QC 三审拆在多条消息(tri 模式)或单席却未附 review-package 路径。
106
109
  - 仅 1 次 invoke 却声称「tri-review 已并行启动」(tri 模式 N=3)。
107
- - SDD 并行 implementer dispatch(**同一 plan 内**多 task)。
108
- - 同仓多轨 writable implement:**N invoke worktree 隔离** **`mstar-branch-worktree`** **`references/parallel-writable-pre-dispatch.md`**。
110
+ - SDD 并行 implementer dispatch(**同一 plan 内**多 task)— **不同于**跨 plan lease 门控并行(后者见上节 L1)。
111
+ - plan 可写派发无 verified `execution_lease`;steal / 覆盖活跃 `execution_lease` `integration_merge_lease`;并行 integration merge。
112
+ - 跨 plan **并行**可写派发在 **无** same-host 独占写锁(跨主机 / 无共享 flock)且 **无** 用户本轮 `Cross-host lease race: accepted` + audit `notes` — **无论** `Worktree mode: waived`。
113
+ - 将 **`Worktree mode: waived`** 当作跨 plan 无锁并行授权(须 serial 或 race-accepted + audit)。
114
+ - `InProgress` 无 `execution_lease` 未走 orphan recovery 即 writable-dispatch。
115
+ - 同仓多轨 writable implement:**N invoke ≠ worktree 隔离**(L2)→ **`mstar-branch-worktree`** **`references/parallel-writable-pre-dispatch.md`**。
109
116
  - 递归同角色 subagent;把 Handoff / 多轨编排措辞当 invoke。
110
117
  - Review-and-edit 链未完成即 commit integration 分支;PM 代做专业角色编辑而不 invoke。
111
118
  - Phase 1 review-and-edit 链三角色并行派发,或未等上一角色返回即派发下一角色。
@@ -143,7 +143,10 @@ Read **`mstar-host`** after this skill; detect host per its table, then Read the
143
143
  | 递归误派 / 误读 Handoff | `mstar-dispatch-gates` |
144
144
  | `quick` 跳过 Prepare | 上表 + `mstar-phase-gates` |
145
145
  | 多 worktree 未归并就 QC | `mstar-branch-worktree` |
146
- | 并行 implementN invoke worktree | `mstar-branch-worktree` `references/parallel-writable-pre-dispatch.md` |
146
+ | 并行 writable implement 无隔离(L2 同 plan 多轨:N invoke worktree;L1 跨 plan:无 verified `execution_lease` + feature worktree) | `mstar-branch-worktree` L1/L2 · `mstar-iteration` §2.6 · `references/parallel-writable-pre-dispatch.md` |
147
+ | 跨 plan 可写派发无 verified `execution_lease` / steal 活跃 lease / 并行 merge 入 `spec_integration_branch` | `mstar-iteration` · `mstar-plan-artifacts`(leases)· `mstar-branch-worktree` L1 |
148
+ | `InProgress` 无 `execution_lease` 未恢复即可写派发 | `mstar-plan-artifacts` — orphan recovery |
149
+ | 混淆跨 plan lease 门控并行与单 plan 内 SDD 并行 implementer | `mstar-dispatch-gates` · `mstar-sdd` |
147
150
  | residual 只写 plan 不写 SSOT | `mstar-plan-artifacts` |
148
151
  | 角色文件塞流程长文 | 用专题 skill |
149
152
  | 无证据宣称完成 | `mstar-coding-behavior` / verification |
@@ -7,7 +7,7 @@ description: Morning Star 迭代管理 —— Phase 1(默认 interactive direc
7
7
 
8
8
  ## Load order
9
9
 
10
- **Read `mstar-harness-core` first.** Path symbols → **`mstar-plan-conventions`**. Per-plan gates → **`mstar-phase-gates`**. Knowledge crystallization → **`mstar-compound`**. **Phase 2 implement 波次**(进入 per-plan implement 前)→ **`mstar-sdd`** + **`mstar-dispatch-gates`**。Phase 2 QC 前 → **`mstar-review-qc`**。On conflict, **`mstar-harness-core` wins**.
10
+ **Read `mstar-harness-core` first.** Path symbols → **`mstar-plan-conventions`**. Per-plan gates → **`mstar-phase-gates`**. Knowledge crystallization → **`mstar-compound`**. **Phase 2 entry**(control worktree + lease)→ **`references/phase-2-worktree-lease.md`** + **`mstar-branch-worktree`**。**Phase 2 implement 波次**(进入 per-plan implement 前)→ **`mstar-sdd`** + **`mstar-dispatch-gates`**。Phase 2 QC 前 → **`mstar-review-qc`**。On conflict, **`mstar-harness-core` wins**.
11
11
 
12
12
  ## 设计思路
13
13
 
@@ -32,7 +32,7 @@ Phase 5: PR merge-ready loop —— 至 mergeable + CI 全绿 + reviews resolved
32
32
  **关键定位**:
33
33
 
34
34
  - **Phase 3** 在 integration 分支收口 compound / roadmap;**开 PR(Phase 4)≠ 迭代交付完成**。
35
- - **Phase 5** 是 **merge-ready loop**:修复 → push → 再验证,直至 §5.5 exit。**Loop 理念 SSOT 在本 skill**;宿主 command 可叠加额外 helper,但不写入 `mstar-*` load order。
35
+ - **Phase 5** 是 **merge-ready loop**:修复 → push → 再验证,直至 §5.5 exit。**Loop 理念 SSOT 在本 skill**;宿主 command 可叠加额外 **non-`mstar-*`** helper(**优先** `babysit` / `*-babysit`;**`greploop` 可选** — 仅当仓库具备 Greptile/`greploop` 时采用),但不写入 `mstar-*` load order。
36
36
  - 一次迭代 = 一个 PR;compound 产物随 PR 合入 `metadata.target_branch`。
37
37
 
38
38
  ## Phase transition gates(HARD — 防跳步)
@@ -208,7 +208,7 @@ Phase 1 与 §1.6 须遵守 **`references/iteration-artifact-boundaries.md`**(
208
208
 
209
209
  **本 Phase 是本 skill 的核心**——定义 per-plan 派发循环的完整流程:前置条件检查、session todos、backlog 读取、integration 分支管理、per-plan dispatch 循环(分支→实现→QC→**QA gate**→Done→合并)、dispatch-first 约束、push 纪律。PM 读取本 Phase 即可执行迭代。
210
210
 
211
- ### 2.0 前置条件(四道闸)
211
+ ### 2.0 前置条件(五道闸)
212
212
 
213
213
  进入 Autonomous Execute 前必须满足:
214
214
 
@@ -216,6 +216,7 @@ Phase 1 与 §1.6 须遵守 **`references/iteration-artifact-boundaries.md`**(
216
216
  2. **Pre-implement gate = GO**:plan 已 locked、tasks ready(见 `mstar-phase-gates`)
217
217
  3. 用户意图为 **continue Autonomous Execute**(推进迭代 Execute、继续 per-plan 循环等)
218
218
  4. **Branch metadata gate**:root `metadata.iteration_base_branch`、`metadata.target_branch` 已登记,且至少一条 active plan 有 `metadata.spec_integration_branch`(或可从 compass 同轮 backfill)。**缺失 → STOP**,不得用 `main`/`master` 补位。
219
+ 5. **Control-worktree + lease defaults**(iteration 命令;可被 `Worktree mode: waived` 豁免):除非本轮 Assignment 显式 `Worktree mode: waived`(或等价用户指令),Phase 2 **必须**在入口建立 control worktree、经 control 路径读写 `status.json` / `{SDD_DIR}`,并在可写派发前 claim `plans[].execution_lease` / `integration_merge_lease`。`Plan parallelism: serial` **不** waive 本闸——仅强制跨 plan **implement** 串行调度;control worktree + lease 仍须满足。**跨 plan 并行安全闸**(**不可**被 `Worktree mode: waived` 豁免):跨 plan **并行可写 implement** 须满足下列之一——(a) coordination 路径(control 或 waived 时主 checkout `{HARNESS_DIR}/status.json`)上 **same-host 独占写锁可用且每次 status/协调变更持锁**;(b) 默认 **`Plan parallelism: serial`**(**waived 时尤其优先默认串行**);(c) 用户本轮显式 `Cross-host lease race: accepted`(或等价)+ `plans[].notes` 审计。**禁止**将 `Worktree mode: waived` 当作跨主机无锁并行的授权。细则 → **`references/phase-2-worktree-lease.md`**。
219
220
 
220
221
  任一 false → **stop**。Phase 1 / Prepare 未完成 → 先完成 Phase 1 或 per-plan Prepare,再进入本 Phase。
221
222
 
@@ -237,7 +238,7 @@ SSOT = `{HARNESS_DIR}/status.json` + `{PLAN_DIR}/`。todos 只追踪本轮下一
237
238
  2. 列出 `status` ∈ `{Todo, InProgress, InReview, Blocked}` 的 plan(优先级:`InProgress` → `InReview` → `Todo` → unblock `Blocked`)
238
239
  3. 读 root `metadata.iteration_base_branch` / `metadata.target_branch`,以及 plan `metadata.spec_integration_branch` / `merge_target` / `primary_spec` 链接
239
240
 
240
- ### 2.3 Integration branch
241
+ ### 2.3 Integration branch + control worktree(Phase 2 入口)
241
242
 
242
243
  **Metadata 解析顺序**(任一环节缺失则 STOP,**禁止**默认 `main`/`master`):
243
244
 
@@ -245,23 +246,40 @@ SSOT = `{HARNESS_DIR}/status.json` + `{PLAN_DIR}/`。todos 只追踪本轮下一
245
246
  2. 若 (1) 缺字段 → 读当前迭代 compass frontmatter 同名键:优先 `{ITERATION_DIR}/<iteration-id>/delivery-compass.md`;若无则 legacy `{ITERATION_DIR}/<iteration-id>-delivery-compass.md`
246
247
  3. 若 compass 有值而 `status.json` 无 → **同轮 backfill** `status.json`
247
248
  4. 仍缺 → 向用户确认 base / PR target;**不得**因 `git symbolic-ref refs/remotes/origin/HEAD` 指向 `main` 就自动采用
249
+ 5. 所有参与本轮迭代的 active plan **必须**解析到**同一** `spec_integration_branch`;不一致 → **STOP**
248
250
 
249
- **Git 操作**:
251
+ **Control worktree(§2.0 #5 未 waive 时 — HARD)**:
252
+
253
+ 1. 解析或创建 **control worktree**(通常 primary checkout 或 PM 指定路径),检出到上一步的 `spec_integration_branch`
254
+ 2. `git fetch`(按需);`git branch --show-current` 确认在 `spec_integration_branch`
255
+ 3. 将规范绝对仓库根路径写入 control 副本 `metadata.control_worktree_path`(仓库根,非 `{HARNESS_DIR}` 子路径)
256
+ 4. 此后 **status / SDD SSOT** 均经 control 路径解析:
257
+ - `<control_worktree_path>/{HARNESS_DIR}/status.json`
258
+ - `<control_worktree_path>/{HARNESS_DIR}/sdd/<plan-id>/`
259
+ 5. 若 integration 分支尚不存在:在 control worktree 内 `git checkout -b <spec_integration_branch> <iteration_base_branch>`(**必须**从记录的 base 创建)
260
+
261
+ **Git 操作(无 control worktree 时 — 仅 `Worktree mode: waived`)**:
250
262
 
251
263
  1. `git fetch`(按需)确认 `iteration_base_branch` 存在
252
- 2. **checkout 或创建** `spec_integration_branch`:
253
- - 已存在 → `git checkout <spec_integration_branch>`
254
- - 不存在 → `git checkout -b <spec_integration_branch> <iteration_base_branch>`(**必须**从记录的 base 创建,不是从当前未记录的 `main` 检出)
264
+ 2. **checkout 或创建** `spec_integration_branch`(同上)
255
265
  3. `git branch --show-current` 确认在 `spec_integration_branch`
256
266
 
257
- 此分支是本迭代内所有 plan feature branch 的 merge target。QC **`Review range` / `Diff basis`** 的 merge-base 参照优先用 `metadata.target_branch`(或 PM 书面指定的 base ref),**禁止**无 Assignment 依据写死 `origin/main`。
267
+ `spec_integration_branch` 是本迭代内所有 plan feature branch 的 merge target。QC **`Review range` / `Diff basis`** 的 merge-base 参照优先用 `metadata.target_branch`(或 PM 书面指定的 base ref),**禁止**无 Assignment 依据写死 `origin/main`。
258
268
 
259
269
  ### 2.4 Per-plan loop(直到全部 Done)
260
270
 
261
- 对每个 active `plan_id`:
271
+ **跨 plan 默认**(**无论** `Worktree mode: waived`):**不同 `plan_id` 可并行 implement** 须满足 §2.0 #5 跨 plan 并行安全闸——(a) coordination 路径 same-host 独占写锁可用且每次 status/协调变更持锁,或 (b) **`Plan parallelism: serial`**(waived 时默认),或 (c) 用户本轮 `Cross-host lease race: accepted` + audit `notes`;否则 Assignment 仍写并行 → **Blocked**。**merge 入 `spec_integration_branch` 仍串行**(`metadata.integration_merge_lease`;waived 时无 merge lease 仍须串行 merge)。未 waive 时 **禁止**无 verified `execution_lease` 的跨 plan 可写派发。
272
+
273
+ 对每个本轮要推进的 active `plan_id`(可交错/并行,非强制 plan A 全 Done 再 plan B):
262
274
 
263
- 1. **Plan startfeature branch**:Assignment `Working branch: create <plan-feature-branch> from <spec_integration_branch>`。一个 plan 一条专用实现分支;plan 内多可写并行轨 → **`mstar-branch-worktree`** **`references/parallel-writable-pre-dispatch.md`**
264
- 2. **Implement InReview**(`§ 2.5`):
275
+ 1. **Claim / resume execution lease**(§2.0 #5 waive):
276
+ - control 路径 **重读** `status.json` 定位 plan 行
277
+ - 若已有 `execution_lease` 且 `holder` **等于本 session** → **resume**:校验 `worktree_path` / `working_branch` 与 Assignment 一致后继续(**不是** steal / Blocked)
278
+ - 若 `execution_lease` 存在且 `holder` **不同** → **Blocked**
279
+ - 若 `status: InProgress` 但 **无** `execution_lease` → **STOP** 升级(孤儿状态恢复 → **`mstar-plan-artifacts`**;本 skill 不自行补 lease)
280
+ - 否则按 **`references/phase-2-worktree-lease.md`** claim:`Todo`/`Blocked` → `InProgress` + 写入完整 `execution_lease`;verify 通过前 **禁止**可写派发
281
+ 2. **Plan start — feature worktree + branch**:创建/校验 dedicated feature worktree;Assignment 须含绝对 `Worktree path` + `Working branch`(与 lease 一致)。plan 内多可写并行轨 → **`mstar-branch-worktree`** **`references/parallel-writable-pre-dispatch.md`**
282
+ 3. **Implement → InReview**(`§ 2.5`;产品编辑在 feature worktree,status/SDD 经 control 路径):
265
283
  - **默认 `Execution mode: sdd`**(多 task plan;hotfix 可 `inline`)。
266
284
  - PM 载入 **`mstar-sdd`** 后,按 plan task 顺序 **串行** per-task 循环(**不是**一次派发 dev 做全部 tasks):
267
285
  1. `sdd-workspace <plan-id>` → `{SDD_DIR}`
@@ -272,10 +290,10 @@ SSOT = `{HARNESS_DIR}/status.json` + `{PLAN_DIR}/`。todos 只追踪本轮下一
272
290
  6. Fix loop 直至 review clean;append `{SDD_DIR}/progress.md`;更新 `status.json` / plan checkbox
273
291
  7. Next task
274
292
  - 每次 Completion Report v2 后更新 `status.json` + 主 plan
275
- 3. **QC → QA gate Done**:per-plan 审查链 → **`mstar-sdd`**(L1–L2)+ **`mstar-review-qc/references/review-responsibility-boundaries.md`**(L3 tri / inline 单席;raw reports in `{SDD_DIR}/review/`,durable summary in main plan/status)+ **`QA gate`**(`mandatory` → `qa-engineer`;`pm-acceptance` → PM checklist)。
276
- 4. **Plan complete — merge back**:合并 plan feature branch `spec_integration_branch`;在下一 plan QC 前解决冲突
277
- 5. **Cross-plan 进度同步**:更新 `{ITERATION_DIR}/<iteration-id>/delivery-compass.md` 的 `## Plans` 表状态列
278
- 6. **Next plan** 从步骤 1 继续
293
+ 4. **QC → QA gate**(plan 保持 **`InReview`**;**保留** `execution_lease`):per-plan 审查链 → **`mstar-sdd`**(L1–L2)+ **`mstar-review-qc/references/review-responsibility-boundaries.md`**(L3 tri / inline 单席;raw reports in `{SDD_DIR}/review/`,durable summary in main plan/status)+ **`QA gate`**(`mandatory` → `qa-engineer`;`pm-acceptance` → PM checklist)。**禁止**在 integration merge 成功前设 `Done` 或删除 `execution_lease`。
294
+ 5. **Plan complete — serial merge back**(§2.0 #5 未 waive):自 **control worktree** claim/resume `metadata.integration_merge_lease` → 将 plan feature branch 合并入 `spec_integration_branch`(仅 merge-lease holder;细则 **`references/phase-2-worktree-lease.md`**)→ 记录 merge commit 证据 → 释放 merge lease;**同轮**设 `Done` 并删除 `execution_lease`。merge 失败:保持 `InReview` + 保留 lease,不得标 `Done`。
295
+ 6. **Cross-plan 进度同步**:更新 `{ITERATION_DIR}/<iteration-id>/delivery-compass.md` 的 `## Plans` 表状态列
296
+ 7. **Next plan / parallel wave** 从步骤 1 继续(可并行推进其他已 claim 的 plan;merge 仍排队串行)
279
297
 
280
298
  全部 plan `Done` → **Phase transition gate**(见上文 **Phase transition gates**):
281
299
 
@@ -294,7 +312,7 @@ SSOT = `{HARNESS_DIR}/status.json` + `{PLAN_DIR}/`。todos 只追踪本轮下一
294
312
  | 串行 | 同一 plan 内 **one implementer at a time**;每 task 后 **one fresh task reviewer** |
295
313
  | Sticky(可选) | Assignment **`SDD implementer session: sticky`** + `implementer-session.json`;implementer **resume**,reviewer **fresh** — `mstar-sdd/references/sticky-implementer-session.md` |
296
314
  | 文件交接 | brief / report / diff / `progress.md` 在 `{SDD_DIR}`;dispatch prompt **只给路径**,不贴 plan 全文或 task 历史 |
297
- | Assignment 字段 | 每个 implement dispatch 须含 `Execution mode: sdd`、`SDD dir`、`Model tier`;**禁止**省略 `Model tier` |
315
+ | Assignment 字段 | 每个 implement dispatch 须含 `Execution mode: sdd`、`SDD dir`、`Model tier`;§2.0 #5 未 waive 时还须含绝对 `Worktree path` + verified `execution_lease`;**禁止**省略 `Model tier` |
298
316
  | 大包 inline | **禁止**把 T1–Tn 或整份 plan 写进 **一个** `fullstack-dev` leaf Assignment 冒充 SDD |
299
317
  | 分支 diff | 全部 task 完成后 `review-package MERGE_BASE HEAD` → `{SDD_DIR}/review/` branch diff → plan QC tri(N=3) |
300
318
 
@@ -311,8 +329,9 @@ Iteration Phase 2 附加:
311
329
  - 不因 harness 流程问题常问「是否继续」「要不要现在启动」—— **决策、记录、dispatch**
312
330
  - 进度汇报 / subagent Completion Report 后,下一条必须是 **dispatch 或下一 gate 动作**,不得以确认问句收束 turn
313
331
  - 未知 → 读 `mstar-*`;仅 **`Blocked`**、secrets、不可逆范围缺口、branch metadata 缺失、或 Phase 5 多轮仍 blocked 时升级用户
314
- - 实际 Git ≠ `working_branch` → **同轮**更新 plan + status
315
- - Per-plan loop **串行**(plan A Done 后再 plan B);plan SDD task **串行** §2.4、§2.5、`mstar-sdd` Continuous execution
332
+ - 实际 Git ≠ `working_branch` → **同轮**更新 plan + status + `execution_lease.working_branch`(如适用)
333
+ - **跨 plan implement**(**无论** `Worktree mode: waived`):并行可写 implement 须满足 §2.0 #5 跨 plan 并行安全闸——same-host 独占写锁 + 每次协调变更持锁,或默认 **`Plan parallelism: serial`**(waived 时尤其优先),或用户本轮 `Cross-host lease race: accepted` + audit `notes`;**禁止**将 waived 当作无锁跨主机并行授权;未 waive 时另须 verified `execution_lease` + feature worktree。**integration merge 串行**(`integration_merge_lease` 或 waived 下无 lease 仍须串行 merge)
334
+ - plan 内 SDD task **串行** — 见 §2.4、§2.5、`mstar-sdd` Continuous execution
316
335
 
317
336
  ---
318
337
 
@@ -447,6 +466,16 @@ PR 目标使用 root `metadata.target_branch`;缺失时停止并补齐,不
447
466
  - **Resolve** when addressed
448
467
  6. Return to step 1
449
468
 
469
+ **Optional host helpers(command 层发现;非 `mstar-*` load order)**:
470
+
471
+ | Priority | Helper | When |
472
+ |----------|--------|------|
473
+ | 1 | `babysit` or any `*-babysit` skill(first readable `SKILL.md`) | **Default prefer** — CI green + reviews resolved loop |
474
+ | 2 | `greploop` | **Optional** — only when the **repo** uses Greptile / has `greploop` available; then run for Greptile **5/5** in addition to babysit/`*-babysit` (or fallback) gates |
475
+ | 3 | neither | Command fallback = babysit-equivalent CI + reviews gates |
476
+
477
+ When both babysit/`*-babysit` and `greploop` apply: **babysit/`*-babysit` first**(CI + reviews),then optional greploop for Greptile score. Discovery paths → host `commands/iteration-drive` / `iteration-loop` Phase 5.
478
+
450
479
  ### 5.2 Phase 5 exit checklist(迭代交付完成)
451
480
 
452
481
  打印 **`## Phase 5 exit checklist`**;全 `[x]` 后方可宣称 **迭代交付完成**:
@@ -482,6 +511,7 @@ PR **merge** 本身可仍由用户手动执行,除非 Assignment 明确授权
482
511
  | `references/iteration-workspace-readme-template.md` | `<iteration-id>/README.md` 可选模板(Documents 单表) |
483
512
  | `references/iteration-corpus-hygiene.md` | §1.6 writing-specialist specs 卫生细则 |
484
513
  | `references/autonomous-direction-lock.md` | §1.2 autonomous direction lock、scale budget、branch resolve |
514
+ | `references/phase-2-worktree-lease.md` | Phase 2 control worktree、`execution_lease`、`integration_merge_lease` |
485
515
  | `mstar-strategy` | iteration-start 时读 `STRATEGY.md` 对齐方向 |
486
516
 
487
517
  ## NOT to do
@@ -507,3 +537,7 @@ PR **merge** 本身可仍由用户手动执行,除非 Assignment 明确授权
507
537
  - **不要在未显式 `Direction lock mode: autonomous` 时跳过与用户收敛方向**(interactive 仍为默认)
508
538
  - **不要在 `autonomous` mode 下例行问用户「是否同意该方向」**(须落盘 rationale;无候选且无约束时 STOP)
509
539
  - **不要把 harness 流程(Review 链 / QC / QA / compound / close / PR 等)计进 Scale budget 的 plan 数量**,也不得为此单独建 process plan 占坑
540
+ - **不要在 Phase 2 无 verified `execution_lease` 就做可写 implement 派发**(resume 仅限同 `holder` verify-held-lease)
541
+ - **不要 steal / 覆盖他人 `execution_lease` 或 `integration_merge_lease`**(除非用户本轮显式 override + audit `notes`)
542
+ - **不要从 feature worktree 的 `{HARNESS_DIR}` 路径当作 status/SDD SSOT**(control worktree 路径为准)
543
+ - **不要并行 merge 入 `spec_integration_branch`**(merge 必须经 `integration_merge_lease` 串行)
@@ -0,0 +1,179 @@
1
+ # Phase 2 control worktree + execution lease
2
+
3
+ Normative field names and claim/release/merge semantics → maintenance ADR
4
+ `.harness/docs/2026-07-22-iteration-worktree-plan-lease.md` (this repo) or
5
+ `mstar-plan-artifacts/references/status-and-residuals.md` (runtime SSOT after
6
+ plan-artifacts sync). This reference is the **iteration-command execution
7
+ checklist**; do not invent alternate lease field names.
8
+
9
+ ## When it applies
10
+
11
+ **Iteration commands only** (`iteration-start` ends before this; `iteration-drive`
12
+ / `iteration-loop` Phase 2+). Defaults are **hard** unless the current turn
13
+ explicitly waives via Assignment `Worktree mode: waived` (or equivalent user
14
+ instruction). `Plan parallelism: serial` is **not** a waiver — it only forces
15
+ serial cross-plan **implement** scheduling while control worktree + leases remain
16
+ required.
17
+
18
+ Phase 1 Review & Edit may stay on the primary checkout. The control-worktree gate
19
+ starts at **Phase 2 entry**.
20
+
21
+ ## Control worktree (Phase 2 entry)
22
+
23
+ 1. Resolve all active plans' `metadata.spec_integration_branch` to the **same**
24
+ integration branch (STOP if mismatch).
25
+ 2. Resolve or create the **control worktree** (usually primary checkout or
26
+ PM-designated path) checked out to that `spec_integration_branch`.
27
+ 3. Verify `git branch --show-current` equals `spec_integration_branch`; working
28
+ tree clean before merge operations.
29
+ 4. Record canonical absolute repository-root path in
30
+ `metadata.control_worktree_path` (not `{HARNESS_DIR}`; canonicalize symlinks).
31
+ 5. Resolve coordination paths from that root:
32
+ - status SSOT: `<control_worktree_path>/{HARNESS_DIR}/status.json`
33
+ - SDD tree: `<control_worktree_path>/{HARNESS_DIR}/sdd/<plan-id>/`
34
+
35
+ All sessions MUST reread the **control copy** of `status.json` immediately before
36
+ claim, release, transfer, plan-status transition, or merge-lease mutation.
37
+
38
+ ### Same-host exclusive write lock
39
+
40
+ All control-path lease mutations (claim, release, transfer, merge-lease
41
+ claim/release) **MUST** run inside a same-host exclusive write lock for the full
42
+ read-check-replace-verify sequence. Prefer `flock` on
43
+ `{HARNESS_DIR}/.status-write.lock`; alternative: atomic `mkdir` on
44
+ `{HARNESS_DIR}/.status-write.lockdir/`. Do **not** invent a distributed CAS CLI.
45
+
46
+ **Cross-plan parallel hard gate:** Applies **whether or not** `Worktree mode: waived`.
47
+ Lease-gated **cross-plan parallel** writable implement is allowed **only when**
48
+ this same-host lock is **available on the coordination `status.json` path and
49
+ used for every status/coordination mutation** in that Phase 2 session (control
50
+ path when lease gate active; primary checkout `{HARNESS_DIR}/status.json` when
51
+ waived). Agents on **different hosts** or with **no shared flock/lockdir** →
52
+ default **`Plan parallelism: serial`** (preferred when waived). Assignment still
53
+ claiming cross-plan parallel without lock availability → **Blocked** until PM
54
+ sets serial scheduling or the user gives current-turn override
55
+ `Cross-host lease race: accepted` (or equivalent) + audit on `plans[].notes`.
56
+ **`Worktree mode: waived` alone is not** this override.
57
+
58
+ Immediately before **any** writable implement dispatch, re-read control
59
+ `status.json` and re-verify `execution_lease` holder + paths match this session;
60
+ mismatch → **STOP**.
61
+
62
+ ## Feature worktree (per plan)
63
+
64
+ - Each concurrently active plan uses a **distinct** absolute feature-worktree
65
+ path and dedicated feature branch from `spec_integration_branch`.
66
+ - `execution_lease.worktree_path` MUST differ from
67
+ `metadata.control_worktree_path` (never reuse the control checkout for product
68
+ edits).
69
+ - `Worktree path` MUST appear in the writable Assignment and in
70
+ `plans[].execution_lease.worktree_path` before first writable implement dispatch.
71
+ - Product/source edits run from the feature worktree; status and SDD
72
+ coordination reads/writes run through the control path.
73
+ - Default **L1**: one writable track per plan. Within-plan multi-writable tracks
74
+ still follow L2 `parallel-writable-pre-dispatch` (`mstar-branch-worktree`).
75
+
76
+ ## Execution lease (`plans[].execution_lease`)
77
+
78
+ Required shape (v1): `holder`, `claimed_at` (RFC 3339 UTC with `Z`),
79
+ `worktree_path`, `working_branch`; optional `session_label` (display only).
80
+
81
+ ### Claim (before `InProgress` or writable dispatch)
82
+
83
+ 1. Read control `status.json`; locate exactly one plan row (`id` or `plan_id`).
84
+ 2. If `execution_lease` exists:
85
+ - **Same `holder` as this session** → **resume**: verify `worktree_path` and
86
+ `working_branch` match the Assignment; continue (not steal/block).
87
+ - **Different `holder`** → **Blocked** (no timestamp makes it stealable).
88
+ 3. Create or verify dedicated feature worktree + branch.
89
+ 4. Re-read `status.json` under write lock; if row/status/lease changed, restart claim.
90
+ 5. One complete-file update (still under lock): `status: "InProgress"` + full `execution_lease`.
91
+ Use temp file + atomic replace; never expose partial JSON.
92
+ 6. Re-read and verify `holder`, `worktree_path`, `working_branch` match before
93
+ any writable dispatch.
94
+
95
+ ### Hold, release, override
96
+
97
+ - Lease stays active across `InProgress` and `InReview` (including post-QC/QA
98
+ ready-to-merge) unless released or transferred.
99
+ - Normal release: re-read control `status.json` under write lock; confirm stored `holder` matches
100
+ this session — mismatch → **Blocked**; then **delete** `execution_lease`
101
+ (never `null` or tombstone).
102
+ - `Done` authority deletes `execution_lease` in the same update as `status: "Done"`
103
+ — **only after** successful integration merge (when lease gate not waived).
104
+ - Override of another holder requires **explicit user instruction this turn** +
105
+ audit note on plan `notes` (prior holder, new holder/release, user authorized).
106
+ - V1: **manual release only** — no `expires_at`, TTL, or heartbeat authority.
107
+
108
+ ### Orphan `InProgress` without lease
109
+
110
+ If a plan row is `InProgress` but has **no** `execution_lease`, STOP and
111
+ escalate — do not invent a lease or writable-dispatch. Unattended "Recover with
112
+ claim" is permitted **only** for the **same** stable `holder`; different holder
113
+ requires verified quiescence + handoff or current-turn user override + audit.
114
+ Recovery semantics → `mstar-plan-artifacts` (not iteration skill).
115
+
116
+ ## Multi-plan parallelism
117
+
118
+ **Cross-plan parallel safety gate** applies **whether or not** `Worktree mode:
119
+ waived` is in effect — waiver does **not** authorize lockless cross-host parallel.
120
+
121
+ - **Feature implementation** MAY proceed in parallel across **different plan IDs**
122
+ only when **one** of:
123
+ 1. Same-host exclusive write lock is available on the coordination
124
+ `status.json` path (control path when lease gate active; primary checkout
125
+ `{HARNESS_DIR}/status.json` when waived) and used for every status/coordination
126
+ mutation in that session; **and** when lease gate is not waived, each plan
127
+ holds a verified, distinct `execution_lease` and feature worktree.
128
+ 2. **`Plan parallelism: serial`** (default when waived; preferred default under
129
+ waiver).
130
+ 3. Current-turn `Cross-host lease race: accepted` (or equivalent) + audit
131
+ `plans[].notes`.
132
+ Cross-host / no shared lock without (2) or (3) → **Blocked** if Assignment still
133
+ claims cross-plan parallel writable implement.
134
+ - **Integration merge** into `spec_integration_branch` is **serial** (one at a time),
135
+ with or without lease gate.
136
+
137
+ ## Integration merge lease (`metadata.integration_merge_lease`)
138
+
139
+ Required shape (v1): `holder`, `claimed_at`, `plan_id`, `source_branch`,
140
+ `target_branch` (= resolved `spec_integration_branch`); optional `session_label`.
141
+
142
+ 1. From control worktree: clean tree; branch = `spec_integration_branch`.
143
+ 2. Under write lock, reread root `metadata`. If `integration_merge_lease` exists:
144
+ - **Same `holder` as this session** → **resume**: verify `plan_id`,
145
+ `source_branch`, `target_branch` match intended merge; confirm control
146
+ worktree state; continue (not steal/block).
147
+ - **Different `holder`** → **Blocked** (cannot expire or steal).
148
+ 3. If unclaimed, claim merge lease (same read-check-replace-verify as execution claim).
149
+ 4. Only merge-lease holder runs integration from `control_worktree_path`.
150
+ 5. On success: record merge commit/evidence; delete merge lease; set plan
151
+ **`Done`** and delete `execution_lease` in the same locked update.
152
+ 6. On conflict/failure: retain leases; plan stays **`InReview`** — do not set
153
+ `Done`. Release merge lease only after control worktree is clean and known state.
154
+
155
+ Execution and merge leases may coexist; merge lease does not grant execution
156
+ ownership for the source plan.
157
+
158
+ ## Waiver
159
+
160
+ Explicit `Worktree mode: waived` (or equivalent user instruction) this turn
161
+ waives **only**:
162
+
163
+ - Control worktree establishment and control-path SSOT routing
164
+ - Per-plan feature worktree defaults
165
+ - `plans[].execution_lease` and `metadata.integration_merge_lease` claim/hold/release
166
+ defaults
167
+
168
+ It does **not** waive the **cross-plan parallel safety gate**. Under waiver,
169
+ cross-plan **parallel writable** implement still requires same-host exclusive
170
+ write lock on the coordination `status.json` path, default **`Plan parallelism:
171
+ serial`**, or current-turn `Cross-host lease race: accepted` + audit
172
+ `plans[].notes`. **Prefer serial scheduling when waived**; parallel under waiver
173
+ only with the race-accepted override (or same-host lock when mutating shared
174
+ status).
175
+
176
+ `Plan parallelism: serial` does **not** waive control worktree or leases.
177
+
178
+ Iteration commands MUST NOT infer waiver from missing worktrees or single-session
179
+ starts. Explicit override this turn only.
@@ -27,6 +27,7 @@ description: Morning Star plan harness artifacts — `{PLAN_DIR}` main plans and
27
27
  - **Canonical**: register new findings only at root `residual_findings`; **`metadata.residual_findings`** is legacy read-only — **do not** dual-write.
28
28
  - **Lifecycle**: open → verified close → **`archived/residuals/<plan-id>.json`**; machine **`severity`** enum in reference.
29
29
  - **`notes.json`**, optional **`tech_debt_summary`** (rollup view; compute via **`scripts/tech-debt-rollup.sh`**).
30
+ - **Iteration Phase 2 leases** (`metadata.control_worktree_path`, `plans[].execution_lease`, `metadata.integration_merge_lease`): claim-before-`InProgress`, resume vs steal, orphan recovery → **`references/status-and-residuals.md`** (“Iteration execution leases”).
30
31
 
31
32
  Field semantics, severity mapping, archive flow, and `jq` examples → **`references/status-and-residuals.md`**.
32
33
 
@@ -130,6 +130,20 @@ In old JSON, **`"severity": "warning"`** is read and rolled up as **`low`**. **F
130
130
  | `review_bundle` | string | Optional pointer to `{SDD_DIR}/review/` for current ephemeral QC/QA evidence |
131
131
  | `task_commits` | array\<object\> | SDD recovery: `{ "task_id": "T1", "base": "<sha>", "head": "<sha>" }` per completed task |
132
132
 
133
+ ### `plans[].execution_lease` (iteration Phase 2)
134
+
135
+ Optional when a plan is not owned; **required** while a Phase 2 session owns writable execution for that plan. Normative protocol below; iteration command checklist → `mstar-iteration/references/phase-2-worktree-lease.md`.
136
+
137
+ | Field | Type | Required | Semantics |
138
+ | --- | --- | --- | --- |
139
+ | `holder` | non-empty string | Yes | Opaque cooperative owner identity (recommended `<host>:<stable-session-id>`, e.g. `cursor:bc-1234`). Stable for claim lifetime; **no credentials**; used for ownership comparison — not `session_label`. |
140
+ | `claimed_at` | RFC 3339 UTC (`Z`) | Yes | Acquisition time (audit only; **not** an expiry clock). |
141
+ | `worktree_path` | absolute path string | Yes | Dedicated feature-worktree root; **MUST** differ from `metadata.control_worktree_path`. |
142
+ | `working_branch` | non-empty string | Yes | Feature branch at `worktree_path`; MUST agree with Assignment **`Working branch`**. |
143
+ | `session_label` | string | No | Human display only — **MUST NOT** authorize or compare ownership. |
144
+
145
+ Writers **delete** `execution_lease` on release; `null` and tombstone objects are invalid.
146
+
133
147
  ### Optional delivery ledger (`phase` + `batches` + `verification`)
134
148
 
135
149
  For multi-batch or multi-role plans:
@@ -161,6 +175,8 @@ Legacy string `plans[].notes` is OK; new repos should use arrays with time + eve
161
175
  | `notes` | array | **Legacy** — prefer **`{HARNESS_DIR}/notes.json`** |
162
176
  | `residual_findings_history` | object | **Legacy** — prefer **`archived/residuals/<plan-id>.json`** |
163
177
  | `tech_debt_summary` | object | Optional rollup over open R#; maintain via script (below) |
178
+ | `control_worktree_path` | absolute path string | Iteration Phase 2: canonical **repository root** (not `{HARNESS_DIR}`) checked out to active `spec_integration_branch`; coordination + serial merge cwd |
179
+ | `integration_merge_lease` | object | While one integration merge is owned; **absent** = unclaimed. Writers **delete** the key on release — never write `null` or tombstone objects |
164
180
 
165
181
  **Formal iteration example** (root `metadata`; values are project-specific — **do not** copy `main` by default):
166
182
 
@@ -181,6 +197,157 @@ Plan row (per active iteration plan):
181
197
  }
182
198
  ```
183
199
 
200
+ ---
201
+
202
+ ## Iteration execution leases (Phase 2)
203
+
204
+ Cooperative coordination through the **control worktree** copy of `{HARNESS_DIR}/status.json`. Not a distributed lock service — non-cooperating processes are out of scope. **Same-host** writers use an exclusive write lock (below) around lease mutations; **cross-plan parallel writable implement** is permitted only when that lock is available on the control path and held for every lease mutation (see hard gate below).
205
+
206
+ **When fields apply:** iteration Phase 2 (after control worktree entry, or primary checkout when `Worktree mode: waived`). Control worktree + lease fields are waived only by explicit current-turn user instruction (`Worktree mode: waived` or equivalent). `Plan parallelism: serial` does **not** waive leases. **`Worktree mode: waived` does not waive the cross-plan parallel safety gate** (see hard gate below).
207
+
208
+ **Path SSOT:** status and SDD reads/writes use `<control_worktree_path>/{HARNESS_DIR}/…`. A feature worktree's same-looking `{HARNESS_DIR}` path is **not** the SSOT.
209
+
210
+ ### Same-host exclusive write lock (control `status.json`)
211
+
212
+ Lease mutations on the **control** copy of `{HARNESS_DIR}/status.json` — execution claim/release/transfer, plan-status transitions that touch leases, and `integration_merge_lease` claim/release — **MUST** run inside a **same-host exclusive write lock** for the full read-check-replace-verify sequence.
213
+
214
+ **Preferred (same machine, shared filesystem):** advisory lock on `{HARNESS_DIR}/.status-write.lock` via `flock` (or equivalent). Hold from first read through post-write verify; release on all exit paths (success or failure).
215
+
216
+ ```bash
217
+ CONTROL_ROOT="<metadata.control_worktree_path>"
218
+ HARNESS=".harness" # or resolved {HARNESS_DIR}
219
+ STATUS="$CONTROL_ROOT/$HARNESS/status.json"
220
+ LOCK="$CONTROL_ROOT/$HARNESS/.status-write.lock"
221
+ (
222
+ flock -x 9 || exit 1
223
+ # read → mutate → temp file + atomic replace → re-read verify
224
+ ) 9>"$LOCK"
225
+ ```
226
+
227
+ **Alternative when `flock` unavailable:** atomic `mkdir` on `{HARNESS_DIR}/.status-write.lockdir/` — success acquires; existing dir → **Blocked** (another writer holds the lock); remove the directory only after successful verify or explicit rollback.
228
+
229
+ **Hard gate — cross-plan parallel writable implement:** Applies **whether or not** `Worktree mode: waived`. Lease-gated **cross-plan parallel** writable implement (when lease gate active) is allowed **only when** a same-host exclusive write lock is **available on the coordination `status.json` filesystem and held for every status/coordination mutation** in that Phase 2 session (execution claim/release/transfer, plan-status transitions, `integration_merge_lease` claim/release when lease gate active). When waived, the coordination path is primary checkout `{HARNESS_DIR}/status.json` — the same lock discipline applies to any shared status mutation before parallel writable dispatch. If agents span hosts or the coordination path has **no shared flock/lockdir** (distinct machines, non-shared mount), **default `Plan parallelism: serial`** for cross-plan implement scheduling — one plan writable wave at a time (**preferred default when waived**). If Assignment still claims cross-plan parallel implement without same-host lock availability → **Blocked** until PM aligns Assignment (`Plan parallelism: serial`) or the user supplies the override below. **`Worktree mode: waived` alone is not** the cross-host parallel override. v1 does **not** add a distributed CAS CLI.
230
+
231
+ **Exception — documented cross-host residual:** Explicit **current-turn** user instruction such as `Cross-host lease race: accepted` (or equally unambiguous equivalent) **plus** audit entry on affected `plans[].notes` (timestamp, hosts/sessions involved, residual race risk acknowledged) permits cooperative multi-host cross-plan parallel with documented residual risk.
232
+
233
+ **Pre-dispatch re-verify:** Immediately before **any** writable implement dispatch, reread control `status.json` and confirm this session still passes verify-held-lease (`holder`, `worktree_path`, `working_branch` match Assignment). Mismatch or absent lease → **STOP** — do not dispatch.
234
+
235
+ ### Root `metadata.integration_merge_lease` (v1)
236
+
237
+ Single global lease authorizing one plan feature branch integration into `spec_integration_branch`.
238
+
239
+ | Field | Type | Required | Semantics |
240
+ | --- | --- | --- | --- |
241
+ | `holder` | non-empty string | Yes | Same format and comparison rules as `execution_lease.holder`. |
242
+ | `claimed_at` | RFC 3339 UTC (`Z`) | Yes | Acquisition time (audit only). |
243
+ | `plan_id` | non-empty string | Yes | `plans[].id` (or legacy `plan_id`) of the feature being integrated. |
244
+ | `source_branch` | non-empty string | Yes | Plan feature branch to integrate. |
245
+ | `target_branch` | non-empty string | Yes | Resolved `spec_integration_branch` — no other target is valid. |
246
+ | `session_label` | string | No | Display only. |
247
+
248
+ Example fragments:
249
+
250
+ ```json
251
+ {
252
+ "metadata": {
253
+ "control_worktree_path": "/repo",
254
+ "integration_merge_lease": {
255
+ "holder": "cursor:bc-1234",
256
+ "claimed_at": "2026-07-22T04:00:00Z",
257
+ "plan_id": "plan-a",
258
+ "source_branch": "feature/plan-a",
259
+ "target_branch": "iteration/2026-07",
260
+ "session_label": "Integrate plan A"
261
+ }
262
+ },
263
+ "plans": [
264
+ {
265
+ "id": "plan-a",
266
+ "status": "InProgress",
267
+ "execution_lease": {
268
+ "holder": "cursor:bc-1234",
269
+ "claimed_at": "2026-07-22T02:30:00Z",
270
+ "worktree_path": "/repo-worktrees/plan-a",
271
+ "working_branch": "feature/plan-a",
272
+ "session_label": "Plan A implementation"
273
+ },
274
+ "metadata": {
275
+ "spec_integration_branch": "iteration/2026-07",
276
+ "merge_target": "iteration/2026-07"
277
+ }
278
+ }
279
+ ]
280
+ }
281
+ ```
282
+
283
+ ### Claim-before-`InProgress` (execution lease)
284
+
285
+ A Phase 2 session **MUST** claim **before** moving a plan from `Todo` or `Blocked` to `InProgress` and **before** any writable dispatch for that plan:
286
+
287
+ 1. Reread the control copy of `status.json`; locate exactly one plan row (`id` or `plan_id` read compatibility).
288
+ 2. **Resume (not steal):** if `execution_lease` exists and `holder` **equals this session** → verify-held-lease: confirm `worktree_path` and `working_branch` match the Assignment; continue (this is **not** Blocked and **not** a new claim).
289
+ 3. **Blocked:** if `execution_lease` exists and `holder` **differs** → stop. No timestamp, TTL, or inactivity makes it stealable.
290
+ 4. **Orphan:** if `status` is `InProgress` but `execution_lease` is absent → **STOP** (see “Orphan recovery” below). Do not writable-dispatch or invent a lease.
291
+ 5. Create or verify the dedicated feature worktree and branch (`worktree_path` ≠ `control_worktree_path`).
292
+ 6. Acquire same-host write lock (see above); reread `status.json`; if row, status, or lease state changed, restart from step 1.
293
+ 7. In **one complete-file update** (under lock), set `status: "InProgress"` and write the full `execution_lease` object. Use a temp file in the same directory and atomically replace `status.json`.
294
+ 8. Reread the stored row; verify `holder`, `worktree_path`, and `working_branch` exactly match the attempted claim. Writable dispatch is forbidden until verification succeeds.
295
+
296
+ V1: **manual release only** — omit `expires_at`; readers **MUST NOT** treat unknown or draft `expires_at` as authority to steal or release.
297
+
298
+ ### Hold, release, and override
299
+
300
+ - Lease remains active across `InProgress` and `InReview` (including review fix rounds) unless deliberately released or transferred.
301
+ - **Release:** reread control `status.json`; stored `holder` must match this session (mismatch → **Blocked**, not permission to delete). Delete `execution_lease` in the same complete-file update — never `null`.
302
+ - Voluntary abandonment: may set `status: "Blocked"` and delete the lease in one update.
303
+ - **`Done` authority** deletes any `execution_lease` in the **same** complete-file update as `status: "Done"` — **only after** successful integration merge into `spec_integration_branch` when Phase 2 lease gate is not waived (see “Integration merge protocol” and `mstar-iteration` §2.4). After QC/QA pass, plan stays **`InReview`** with lease retained until merge succeeds.
304
+ - Temporary blockage may retain the lease when the same holder remains responsible and the plan record explains the next action.
305
+ - **Override (only exception to no-steal):** explicit **user instruction in the current turn** may remove or replace another holder's lease. Append an audit entry to `plans[].notes` with timestamp, prior holder, new holder (or release), and that the user authorized override. Agents **MUST NOT** infer override from age, inactivity, `Blocked` status, or a failed session.
306
+ - Cooperative handoff: current holder explicitly agrees; receiving worktree/branch verified; one complete-file update — otherwise old holder releases and new holder follows normal claim.
307
+
308
+ ### Integration merge protocol
309
+
310
+ Feature implementation may run in parallel across plan IDs **only when** the cross-plan parallel hard gate above is satisfied (same-host lock on coordination `status.json`, default **`Plan parallelism: serial`**, or current-turn `Cross-host lease race: accepted` + audit `plans[].notes` — **not** by `Worktree mode: waived` alone); when lease gate is active, each plan also needs a verified `execution_lease` and distinct feature worktree. Mutations of `spec_integration_branch` are **serial**. Plan status after QC/QA is **`InReview`** with `execution_lease` retained until merge succeeds (when lease gate active); **`Done`** + lease deletion happen **after** the integration merge commit is recorded.
311
+
312
+ 1. From `control_worktree_path`: clean working tree; checked-out branch = resolved `spec_integration_branch`.
313
+ 2. Reread root `metadata` under the same-host write lock (above). If `integration_merge_lease` exists:
314
+ - **Resume (not steal):** `holder` **equals this session** → verify-held-merge-lease: confirm `plan_id`, `source_branch`, and `target_branch` match the intended merge; confirm control worktree state (clean or documented in-progress resolution); continue (this is **not** Blocked).
315
+ - **Blocked:** `holder` **differs** → stop. No timestamp, TTL, or inactivity makes it stealable.
316
+ 3. If unclaimed, claim merge lease with the same read-check-replace-verify discipline as execution claims. `source_branch` and `plan_id` must match the feature; `target_branch` must match `spec_integration_branch`.
317
+ 4. Only the stored merge-lease `holder` runs integration from `control_worktree_path`.
318
+ 5. On success: record merge commit/evidence per plan/status conventions; **delete** `integration_merge_lease`; in the **same** locked update set plan `status: "Done"` and **delete** `execution_lease`.
319
+ 6. On conflict/failure: retain both leases; plan stays **`InReview`** — do **not** set `Done`. Release merge lease only after control worktree is clean and in a known state.
320
+
321
+ Execution and merge leases may coexist; merge lease does not grant execution ownership for the source plan.
322
+
323
+ ### Orphan recovery (`InProgress` without `execution_lease`)
324
+
325
+ Runtime skills that detect this state (e.g. `mstar-iteration`) **STOP** and defer recovery here — they **MUST NOT** silently add a lease or writable-dispatch.
326
+
327
+ **Immediate gate:** no writable dispatch until recovery completes and a verified `execution_lease` exists (or plan is returned to a non-active status).
328
+
329
+ **Resolver:** `@project-manager` (or explicit human/PM ownership resolution after race or corruption).
330
+
331
+ | Path | When | Actions |
332
+ | ---- | ---- | ------- |
333
+ | **Reset to `Todo`** | Work abandoned, unknown owner, or safe to restart claim | One complete-file update under write lock: `status: "Todo"`; ensure `execution_lease` absent; append `plans[].notes` audit (timestamp, reason, actor). |
334
+ | **Recover with claim (same holder)** | Legitimate in-progress work; feature worktree/branch verified on disk; **this session's stable `holder`** matches the prior owner | Unattended recovery permitted **only** for the **same** stable `holder`. Follow claim-before-`InProgress` from step 5 under write lock; append `plans[].notes` audit (orphan recovery, same `holder`, paths verified). |
335
+ | **Recover with claim (different holder)** | New session must take over live work | **Blocked** for unattended recovery. Requires **verified quiescence** of the prior writer (no live writable work on the feature branch/worktree) **and** explicit cooperative handoff from the prior holder, **or** **current-turn user override** + audit `notes` (prior holder, new holder, user authorized). Then normal claim under write lock. |
336
+ | **Escalate / `Blocked`** | Ambiguous ownership, conflicting worktrees, or partial/corrupt `status.json` | Set `status: "Blocked"` with `metadata.blocked_reason`; do **not** writable-dispatch until human/PM resolves. Restore coherent `status.json` from latest complete state if needed. |
337
+
338
+ After any recovery path, the next session must pass verify-held-lease before writable dispatch.
339
+
340
+ ### Agent prohibitions (lease SSOT)
341
+
342
+ - **MUST NOT** steal or overwrite an active `execution_lease` or `integration_merge_lease` (no TTL, age, or inactivity authority in v1).
343
+ - **MUST NOT** writable-dispatch without a verified `execution_lease` for that plan (resume counts only when same `holder` passes verify-held-lease).
344
+ - **MUST NOT** write `null` or tombstone objects for lease keys — **delete** the key on release.
345
+ - **PM NEVER** steal an active lease without explicit current-turn user override + audit `notes` (full list → `mstar-roles/references/project-manager.md` § PM-Specific NEVER Rules).
346
+
347
+ Preservation: writers **MUST** preserve unrelated plan rows, root metadata, and `residual_findings` on every lease mutation.
348
+
349
+ ---
350
+
184
351
  ## General constraints
185
352
 
186
353
  - Each `plans[]` row may include optional **`metadata`** (`{}` or omit).
@@ -4,6 +4,6 @@ Copy these into `{HARNESS_DIR}` when bootstrapping a project. Path symbols (`{HA
4
4
 
5
5
  | File | Copy to | Notes |
6
6
  |------|---------|--------|
7
- | `status.empty.json` | `{HARNESS_DIR}/status.json` | Root `residual_findings` only (see **`mstar-plan-artifacts` SKILL.md**). Replace `updated_at` with the real date. |
7
+ | `status.empty.json` | `{HARNESS_DIR}/status.json` | Root `residual_findings` only (see **`mstar-plan-artifacts` SKILL.md**). Replace `updated_at` with the real date. Iteration Phase 2 lease fields (`control_worktree_path`, `execution_lease`, `integration_merge_lease`) are added at runtime — not in the empty template. |
8
8
  | `notes.empty.json` | `{HARNESS_DIR}/notes.json` | Optional program timeline. Replace `updated_at` when first edited. |
9
9
  | `plans-done.empty.json` | `{HARNESS_DIR}/archived/plans-done.json` | **Profile B only** — `{ "plans": [<plan-id>, ...] }` **only** (`references/done-compaction.md`). Append id on each `Done` compaction; no other keys or object elements. |
@@ -127,6 +127,12 @@ If any item below matches, fix the dispatch/plan state or mark `Blocked`—do **
127
127
  - **NEVER** perform specialist document edits in the PM thread when host invoke is required — that is `dispatch incomplete` (`mstar-dispatch-gates`, `mstar-iteration` §1.6).
128
128
  - **NEVER** mark the last plan `Done` and then create a PR or declare the iteration complete without **`## Phase 3: iteration-close`** and `mstar-iteration` §3.1–§3.5 checklists.
129
129
  - **NEVER** treat final plan closure prose as iteration-close — compound, roadmap `delivered`, and compass `status: completed` require Phase 3.
130
+ - **NEVER** steal or overwrite an active `execution_lease` or `integration_merge_lease` (no TTL, age, or inactivity authority); override only on explicit current-turn user instruction + audit `plans[].notes` (`mstar-plan-artifacts/references/status-and-residuals.md` — “Iteration execution leases”).
131
+ - **NEVER** writable-dispatch for a plan without a **verified** `execution_lease` for that plan (resume only when same `holder` passes verify-held-lease against Assignment `Worktree path` / `Working branch`).
132
+ - **NEVER** writable-dispatch when a plan is `InProgress` but has **no** `execution_lease` — complete orphan recovery first (`mstar-plan-artifacts` — “Orphan recovery”).
133
+ - **NEVER** run or dispatch **parallel** integration merges into `spec_integration_branch` — merge is **serial** via `metadata.integration_merge_lease` from the control worktree (`mstar-iteration` §2.6 · `mstar-branch-worktree` L1).
134
+ - **NEVER** cross-plan writable implement without distinct per-plan verified `execution_lease` + feature worktree; `Plan parallelism: serial` forces serial **scheduling** only — it does **not** waive control worktree or lease gates (`mstar-iteration` §2.0 #5).
135
+ - **NEVER** dispatch **cross-plan parallel** writable implement when same-host exclusive write lock is **not** available on the coordination `status.json` path (cross-host / no shared flock) — default **`Plan parallelism: serial`** or **Blocked** if Assignment still claims parallel; exception only on current-turn user `Cross-host lease race: accepted` (or equivalent) + audit `plans[].notes` — **including when `Worktree mode: waived`** (`mstar-plan-artifacts` — “Hard gate — cross-plan parallel writable implement”).
130
136
 
131
137
  ---
132
138
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mstar-harness/opencode",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Morning Star harness OpenCode plugin (skills bootstrap and agent loading).",
5
5
  "license": "MIT",
6
6
  "repository": {