@mstar-harness/opencode 1.3.2 → 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.
@@ -0,0 +1,163 @@
1
+ # Kimi host reference
2
+
3
+ Load when **`mstar-host`** detection resolves **kimi** (Kimi Code CLI session, `.kimi-plugin/plugin.json` plugin installed, `Agent` / `AgentSwarm` / `AskUserQuestion` / `EnterPlanMode` tools, or `/morning-star-harness:*` plugin commands).
4
+
5
+ Plan mode: read **`kimi-plan-mode-bridge.md`** when `EnterPlanMode` / `ExitPlanMode`, `/plan`, or `kimi --plan` is active.
6
+
7
+ Parallel PM dispatch: read **`parallel-dispatch.md`** when dispatching **N ≥ 2** concurrent `Agent` invocations.
8
+
9
+ ## Kimi-only context
10
+
11
+ - Plugin manifest: **`.kimi-plugin/plugin.json`** (plugin root is the **repo root**; paths stay `./skills/` and `./commands/`).
12
+ - Runtime skills: repo `skills/` mounted by the plugin (`"skills": "./skills/"`).
13
+ - Plugin commands: repo `commands/` → `/morning-star-harness:<name>` (e.g. `/morning-star-harness:iteration-start`).
14
+ - **`sessionStart.skill: pm`** auto-loads the PM entry shim on new sessions; `pm` → **Read next** → `mstar-harness-core` → `project-manager.md`.
15
+ - **`/skill:pm`** or **`pm` skill**: same PM entry when invoked manually.
16
+ - Install (user-scoped): in Kimi TUI `/plugins install https://github.com/btspoony/mstar-harness` then `/plugins reload` (or `/new`).
17
+ - Plugins are **user-scoped** (all projects); managed copy lives under `$KIMI_CODE_HOME/plugins/managed/` after `/plugins install`.
18
+ - Project `.agents/skills/` symlinks are **not** required when using the plugin — commands and skills come from the plugin mount.
19
+
20
+ ## Skill loading
21
+
22
+ 1. On session start: `pm` (via `sessionStart.skill`) → **Read next** loads `mstar-harness-core`, then `mstar-roles` → `project-manager.md` when PM is active.
23
+ 2. Read `mstar-host` and this Kimi reference.
24
+ 3. If Plan mode is active, read `kimi-plan-mode-bridge.md`.
25
+ 4. Load `mstar-roles` and the active role reference.
26
+ 5. Load topic skills on demand per the role reference.
27
+
28
+ Use skill names in prompts and references. Avoid absolute local paths unless maintaining this repository or skills are not installed.
29
+
30
+ ## Tools map (default agent)
31
+
32
+ | Kimi tool | Harness use |
33
+ |-----------|-------------|
34
+ | **Agent** | Primary dispatch — delegate one subagent task (`subagent_type`: `coder` \| `explore` \| `plan`) |
35
+ | **AgentSwarm** | Parallel batch when **same** role/profile and prompts differ only by task slice; prefer **N× Agent** when roles differ |
36
+ | **AskUserQuestion** | Structured clarify (1–4 questions, 2–4 options each); prefer over free-form when choices are known |
37
+ | **EnterPlanMode** / **ExitPlanMode** | Plan mode entry/approval → **`kimi-plan-mode-bridge.md`** |
38
+ | **TodoList** | Session UX only; mirror to SSOT plan / `status.json` when durable |
39
+ | **Bash** | Commands, git, tests — evidence per `mstar-coding-behavior` |
40
+ | **Read** / **ReadMediaFile** | File reads |
41
+ | **Glob** / **Grep** | Search (prefer over shell find/grep) |
42
+ | **Write** / **Edit** | Edits |
43
+ | **WebSearch** / **FetchURL** | External docs / facts |
44
+ | **TaskList** / **TaskOutput** / **TaskStop** | Long-running task management when present |
45
+
46
+ OpenCode-style `question` and Cursor **Task** are **not** Kimi tools — do not assume them.
47
+
48
+ ## Role agents (C5 — hard constraint)
49
+
50
+ Kimi ships **built-in subagent types only**. Valid **`subagent_type`** values:
51
+
52
+ | `subagent_type` | Kimi profile | Harness mapping |
53
+ |-----------------|--------------|-----------------|
54
+ | `explore` | Read-only exploration | Orientation, codebase survey, Prepare explore passes |
55
+ | `plan` | Plan-mode subagent | Prepare plan-only work when host is already in plan context |
56
+ | `coder` | General implementation | **All other Morning Star roles** (`product-manager`, `fullstack-dev`, `qc-specialist`, …) |
57
+
58
+ Morning Star role ids (`project-manager`, `fullstack-dev`, `qc-specialist`, …) are **not** valid `subagent_type` values. The host cannot register custom named agents like Codex TOML or Cursor `subagent_type` role ids.
59
+
60
+ ### Role binding in prompt (C5b — required)
61
+
62
+ Because Kimi cannot bind roles via agent config, every dispatch **must** carry the played Morning Star role in the **Assignment** and in the **`Agent` prompt**:
63
+
64
+ 1. **`Execute as: <role-id>`** in Assignment (harness routing SSOT).
65
+ 2. **`Act as <role-id>`** (or equivalent) at the top of the Agent prompt.
66
+ 3. **Skill load list** — instruct the subagent to read `mstar-roles` → `references/<role-id>.md` (or shared reference + parameters) and topic skills per that reference.
67
+ 4. **`subagent_type`** — pick from the mapping table above only.
68
+
69
+ Paste-only Assignment without an **`Agent`** call is **not** dispatch.
70
+
71
+ ### Assignment / Agent-prompt template
72
+
73
+ ```markdown
74
+ ## Assignment
75
+
76
+ **Execute as**: fullstack-dev
77
+ **Delegation**: forbidden
78
+ **Working branch**: feat/example
79
+ **Plan Path**: .mstar/plans/20260717-example.md
80
+
81
+ **IDENTITY:** You ARE `fullstack-dev`. Act as `fullstack-dev` for this task.
82
+ Load: `mstar-harness-core` → `mstar-host` → `kimi.md` → `mstar-roles` → `references/fullstack-dev-shared.md` → topic skills per that reference.
83
+
84
+ <task body>
85
+ ```
86
+
87
+ PM dispatch invocation (same turn):
88
+
89
+ ```text
90
+ Agent(
91
+ subagent_type: "coder",
92
+ prompt: "<full Assignment body including Act as + skill load>"
93
+ )
94
+ ```
95
+
96
+ For **`explore`** orientation:
97
+
98
+ ```text
99
+ Agent(subagent_type: "explore", prompt: "... Act as explore-only orientation; Execute as: n/a ...")
100
+ ```
101
+
102
+ For Prepare plan-only when plan subagent is appropriate:
103
+
104
+ ```text
105
+ Agent(subagent_type: "plan", prompt: "... Act as architect for plan design; load mstar-roles → architect.md ...")
106
+ ```
107
+
108
+ ## PM dispatch (`Agent` / `AgentSwarm`)
109
+
110
+ Harness **dispatch** on Kimi = **one or more `Agent` tool calls** with correct **`subagent_type`** and role-bound prompts.
111
+
112
+ | Harness | Kimi |
113
+ |---------|------|
114
+ | `Execute as: <role-id>` | Role id in Assignment + **Act as** + skill load in **Agent** prompt |
115
+ | `subagent_type` for invoke | `coder` \| `explore` \| `plan` only (see mapping) |
116
+ | 1 Assignment ⇒ 1 invoke | **1 `Agent`** call with full Assignment prompt |
117
+ | Parallel batch **N** | **N `Agent`** calls in **one assistant message** when roles may differ; **`AgentSwarm`** only when same role/profile |
118
+ | No `Agent` call | **Not dispatched** — paste-only / `dispatch incomplete` |
119
+
120
+ ### QC default
121
+
122
+ - **`Execution mode: sdd`**: **N=3** `Agent` calls (`qc-specialist`, `qc-specialist-2`, `qc-specialist-3`) — each prompt **Act as** the respective QC role, all `subagent_type: "coder"`.
123
+ - **`inline`**: **N=1** per `parallel-dispatch.md`.
124
+
125
+ Cannot emit required **N** → **`Blocked`**.
126
+
127
+ ### SDD implement (serial)
128
+
129
+ - **`Execution mode: sdd`**: one implementer **`Agent`** per task id; task reviewer = new **`Agent`** (no sticky resume unless host adds it later).
130
+ - **Never** multiple implementer Agents in one message for the same plan.
131
+
132
+ ## Clarify
133
+
134
+ - Prefer **`AskUserQuestion`** for 1–3 high-impact choices with known options.
135
+ - Fallback: one concise Markdown question after codebase exploration cannot answer it.
136
+ - `AskUserQuestion` for plan approval is wrong in Plan mode — use **`ExitPlanMode`** for plan sign-off.
137
+ - “Question asked” ≠ clarify done; blocking ambiguity → **`Blocked`** or escalation.
138
+
139
+ ## Commands and skills paths
140
+
141
+ | Surface | Path / invocation |
142
+ |---------|-------------------|
143
+ | Plugin skills | `/skill:<skill-name>` or auto-load from `skills/` via plugin |
144
+ | Plugin commands | `/morning-star-harness:iteration-start` etc. |
145
+ | Session entry | `sessionStart.skill: pm` → `mstar-harness-core` via pm **Read next** |
146
+
147
+ ## Files, shell, and approvals
148
+
149
+ - Prefer **Glob** / **Grep** for search; **Write** / **Edit** for edits.
150
+ - Respect Kimi approval prompts for destructive operations.
151
+ - Do not edit `$KIMI_CODE_HOME` credentials, managed plugin copies, or user secrets without explicit consent.
152
+
153
+ ## Git and final evidence
154
+
155
+ - Git work follows `mstar-branch-worktree` and Assignment **Working branch** / **Branch policy**.
156
+ - Completion reports cite concrete commands, artifacts, and commit lines when required.
157
+
158
+ ## Gotchas
159
+
160
+ - Plugin install copies source to managed dir — edit checkout + reinstall to pick up harness changes.
161
+ - **`AgentSwarm`** shares one template — not for mixed-role QC tri-review; use **3× Agent** instead.
162
+ - Session plan file and `TodoList` are not durable SSOT unless mirrored to `{HARNESS_DIR}`.
163
+ - No custom Kimi agent profiles for Morning Star roles — role binding is **always** prompt + skill load (C5b).
@@ -1,6 +1,6 @@
1
1
  # Parallel dispatch (invoke-capable hosts)
2
2
 
3
- Shared PM dispatch contract for **any** host that uses subagent / Task / named-role invoke (OpenCode, Cursor Task, Codex only when a callable multi-agent / Task tool is actually available). Process SSOT also in `mstar-dispatch-gates`.
3
+ Shared PM dispatch contract for **any** host that uses subagent / Task / Agent invoke (OpenCode task tool, Cursor Task, Kimi **Agent** / **AgentSwarm**, Codex only when a callable multi-agent / Task tool is actually available). Process SSOT also in `mstar-dispatch-gates`.
4
4
 
5
5
  If the active host has no callable invoke tool, this reference does not create delegation capability — mark dispatch **`Blocked`** and report to the user. Do not substitute PM-thread or single-session role execution unless the user explicitly overrides harness dispatch for this turn.
6
6
 
@@ -17,7 +17,7 @@ Printing `## Assignment` in the main thread **without** matching host invocation
17
17
 
18
18
  1. Finalize all `N` Assignment payloads (after any prerequisite turn).
19
19
  2. Count distinct `Execute as` sessions (`N`).
20
- 3. Issue **`N` host invocations first** — OpenCode: **N `task` tool** calls with **subagent**; Cursor: **N `Task`** with `subagent_type`; each with one Assignment body. For parallel work, **all `N` tool calls in one assistant message** when the host allows.
20
+ 3. Issue **`N` host invocations first** — OpenCode: **N `task` tool** calls with **subagent**; Cursor: **N `Task`** with `subagent_type`; Kimi: **N `Agent`** calls (each prompt carries **Act as** + skill load; `subagent_type` ∈ {`coder`,`explore`,`plan`} only — see `kimi.md` C5/C5b); each with one Assignment body. For parallel work, **all `N` tool calls in one assistant message** when the host allows.
21
21
  4. Optionally post a short **Status Update** after invocations (audit trail only — does not replace step 3).
22
22
 
23
23
  ## Hard rules
@@ -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