maestro-flow-one 0.2.32 → 0.2.34

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,601 @@
1
+ ---
2
+ name: odyssey-planex
3
+ description: Requirement-driven iterative cycle — plan, execute, strict verify, fix loop until acceptance criteria met
4
+ argument-hint: "<requirement> [--max-iterations N] [--skip-generalize] [--auto] [--method agent|cli|auto] [--executor <tool>] [--skip-verify] [-y] [-c]"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Edit
9
+ - Bash
10
+ - Glob
11
+ - Grep
12
+ - Agent
13
+ - AskUserQuestion
14
+ ---
15
+ <purpose>
16
+ Requirement-to-delivery closed loop: parse requirement → define strict acceptance criteria →
17
+ plan tasks → execute → verify against criteria → fix gaps → iterate until ALL criteria pass.
18
+
19
+ Core philosophy:
20
+ - **Acceptance criteria are sacred** — no "close enough", no manual override
21
+ - **Iterate, don't restart** — each fix cycle targets only the failing criteria
22
+ - **CLI-assisted verification** — delegate to external tools for objective quality checks
23
+ - **Evidence-based progress** — every iteration logged with pass/fail per criterion
24
+
25
+ **三句哲学约束(穷尽迭代):**
26
+ 1. **零遗留** — 验收标准必须 ALL pass,不允许"接近通过"
27
+ 2. **穷尽迭代** — verify 失败自动修复重试,直到全部通过或明确升级
28
+ 3. **改进即标准** — 修复后重新验证同区域,新发现的标准违反继续修
29
+ </purpose>
30
+
31
+ <boundary>
32
+ **范围内:** 单一需求的实现闭环 — 从需求解析到验收标准全部通过 + 泛化同类场景
33
+ **范围外:** 多需求编排 → `/maestro-roadmap` | 深度 debugging → `/odyssey-debug` | 代码审查 → `/odyssey-review-test-fix` | UI 优化 → `/odyssey-ui`
34
+ **探索自由度:** 边界内自由探索 — 可自主分解任务、选择实现策略、迭代修复。verify→fix 循环内可尝试不同方案。
35
+ **模板支持:** `--template <name>` 从预定义需求模板启动,自动生成匹配的验收标准和任务分解:
36
+
37
+ | Template | 预设 criteria 模式 | 适用场景 |
38
+ |----------|-------------------|---------|
39
+ | `feature` | 用户故事验收 + 边界测试 + UI 验证 | 新功能开发 |
40
+ | `bugfix` | 回归测试 + 根因确认 + 边界覆盖 | Bug 修复 |
41
+ | `refactor` | 行为不变验证 + 性能基准 + API 兼容 | 重构 |
42
+ | `migration` | 数据一致性 + 回滚验证 + 性能对比 | 数据/API 迁移 |
43
+ | `api-endpoint` | 请求/响应契约 + 错误处理 + 权限校验 | API 开发 |
44
+ </boundary>
45
+
46
+ <execution_discipline>
47
+ **三条铁律(所有阶段适用):**
48
+
49
+ 1. **Phase auto-commit** — 每个阶段完成后**自动** `git commit`,无需用户确认
50
+ - 代码变更 + understanding.md → `git add` → `git commit -m "odyssey-planex({slug}): {phase} — {摘要}"`
51
+ - session.json / evidence.ndjson 为运行时状态,不纳入 commit
52
+
53
+ 2. **有把握才改** — 仅修改自己有把握的内容;不确定的记录决策等人判断
54
+ - 有把握 → 直接修改代码,commit
55
+ - 需要决策 → 记录 `evidence.ndjson {"phase":"decision","status":"pending"}` 不改代码
56
+ - 禁止猜测性修改
57
+
58
+ 3. **多 CLI 辅助** — 利用 `maestro delegate` 调用多个 CLI 工具交叉验证
59
+ - 计划阶段: `--role analyze` 获取任务分解建议
60
+ - 修复前后: `--role review` 确认无回归
61
+ - verify 阶段: cli-review 类型标准自动 delegate
62
+ </execution_discipline>
63
+
64
+ <context>
65
+ $ARGUMENTS — requirement description and optional flags.
66
+
67
+ **Flags:**
68
+ | Flag | Description | Default |
69
+ |------|-------------|---------|
70
+ | `--template <name>` | 预定义需求模板 | — |
71
+ | `--max-iterations N` | Max verify→fix cycles before escalation | 3 |
72
+ | `--skip-generalize` | Skip S_GENERALIZE + S_DISCOVER | false |
73
+ | `--auto` | CLI delegate calls without confirmation | false |
74
+ | `--method agent\|cli\|auto` | Execution method: Agent tool, CLI delegate, or auto-select | `auto` |
75
+ | `--executor <tool>` | Explicit executor tool for CLI delegate mode | First enabled in config |
76
+ | `--skip-verify` | Skip execution post-validation gate | false |
77
+ | `-y` | Auto-confirm — decisions recorded as `deferred` | false |
78
+ | `-c` | Resume most recent session | — |
79
+
80
+ **Session**: `SESSION_DIR = .workflow/scratch/{YYYYMMDD}-planex-odyssey-{slug}/`
81
+
82
+ **Output — 3 files:**
83
+ ```
84
+ SESSION_DIR/
85
+ ├── session.json # state + criteria + iterations + plan
86
+ ├── evidence.ndjson # append-only log (phase distinguishes origin)
87
+ └── understanding.md # evolving narrative (8 sections, one per phase)
88
+ ```
89
+
90
+ **session.json schema:**
91
+ ```json
92
+ {
93
+ "session_id": "planex-odyssey-{YYYYMMDD-HHmmss}",
94
+ "requirement": "",
95
+ "flags": { "max_iterations": 3, "skip_generalize": false, "auto": false, "auto_confirm": false },
96
+ "current_state": "S_INTAKE",
97
+ "acceptance_criteria": [
98
+ {"id":"AC1","criterion":"","verify_method":"test|grep|cli-review|manual","status":"pending","evidence":"","passed_at":null}
99
+ ],
100
+ "plan": { "tasks": [{"id":"T1","title":"","description":"","criteria_refs":["AC1"],"status":"pending","files_modified":[],"domain":"general","executor":"agent"}], "created_at":"" },
101
+ "execution_config": {
102
+ "method": "auto",
103
+ "default_executor": "",
104
+ "domain_routing": { "frontend": "", "backend": "", "default": "agent" },
105
+ "code_review_tool": "Skip",
106
+ "verification_tool": "Auto",
107
+ "confirmed": false
108
+ },
109
+ "iterations": [
110
+ {"iteration":1,"started_at":"","completed_at":"","criteria_before":{"passed":0,"total":0},"criteria_after":{"passed":0,"total":0},"gaps_fixed":[],"files_modified":[]}
111
+ ],
112
+ "current_iteration": 0,
113
+ "patterns": [
114
+ {"id":"P1","source":"AC1 fix","layer":"syntax|semantic|structural","signature":"","description":"","risk":"","fix_template":""}
115
+ ],
116
+ "generalization_stats": {"patterns_extracted":0,"total_hits":0,"cross_layer_confirmed":0,"by_layer":{"syntax":0,"semantic":0,"structural":0},"deepening_triggered":false},
117
+ "phase_goals": [],
118
+ "phase_goals_all_done": false,
119
+ "self_iteration_log": [],
120
+ "cross_phase_loops": 0, "max_loops": 3,
121
+ "created_at": "", "updated_at": ""
122
+ }
123
+ ```
124
+
125
+ **evidence.ndjson** — one JSON per line, `phase` field = `planning|execution|verification|fix|decision|generalization|discovery|self-iteration`
126
+
127
+ **understanding.md sections:** §1 Requirement & Criteria ← S_INTAKE, §2 Plan ← S_PLAN, §3 Execution ← S_EXECUTE, §4 Verification (per iter) ← S_VERIFY, §5 Fix Log (per iter) ← S_FIX, §6 Generalization ← S_GENERALIZE, §7 Discoveries ← S_DISCOVER, §8 Learnings ← S_RECORD
128
+
129
+ **phase_goals[]:**
130
+ | ID | Goal | Done When | Phase | Skip When |
131
+ |----|------|-----------|-------|-----------|
132
+ | G1 | Acceptance criteria defined | ≥1 criterion in acceptance_criteria[] | S_INTAKE | — |
133
+ | G2 | Plan created | session.json.plan populated | S_PLAN | — |
134
+ | G3 | Implementation complete | all plan tasks executed | S_EXECUTE | — |
135
+ | G4 | All criteria pass | all acceptance_criteria[].status == passed | S_VERIFY | — |
136
+ | G5 | Pattern generalized | patterns[] populated ≥1 entry | S_GENERALIZE | skip_generalize |
137
+ | G6 | Discoveries triaged | all scan hits classified | S_DISCOVER | skip_generalize |
138
+ | G7 | Learnings persisted | spec entries created OR no actionable | S_RECORD | — |
139
+
140
+ ### Pre-load(可选,缺失不阻塞)
141
+
142
+ | 层级 | 命令 | 作用 |
143
+ |------|------|------|
144
+ | Codebase docs | Read `.workflow/codebase/ARCHITECTURE.md` | 模块边界,架构约束 |
145
+ | Wiki search | `maestro search "<requirement keywords>" --json` | 先前实现、相关决策(取 top 5) |
146
+ | Coding specs | `maestro spec load --category coding` | 编码规范 + 可发现的 knowhow 工具 |
147
+ | UI specs(条件) | 若涉及前端 → `maestro spec load --category ui` | UI 规范 |
148
+ | Role knowledge | `maestro search --category coding` → 选相关 → `maestro wiki load <id>` | 累积实现领域知识 |
149
+ | Prior sessions | `Glob(".workflow/scratch/*-planex-odyssey-*")` | 相关 odyssey 会话 |
150
+
151
+ ### Knowledge Persistence(S_RECORD 中写入产出文件)
152
+
153
+ S_RECORD 阶段将可沉淀知识 **写入 understanding.md §8 Learnings**,按以下分类结构化:
154
+
155
+ | 分类 | 写入内容 | 后续建议命令 |
156
+ |------|---------|-------------|
157
+ | 多轮 fix cycle pattern | 问题场景 + fix 迭代过程 + 最终方案 | `/spec-add debug "..."` |
158
+ | 可复用实现模式 | 模式描述 + 适用场景 + 代码模板 | `/spec-add coding "..."` |
159
+ | 验收标准模板 | 标准模板 + verify_method 建议 | `/spec-add review "..."` |
160
+ | 泛化 pattern | pattern 签名 + 风险说明 + fix 模板 | `/spec-add coding "..."` |
161
+
162
+ **两步模式:** 执行中写入产出文件(临时记录)→ 任务完成后用户通过 next_step_routing 沉淀为永久知识。执行过程中不调用外部 Skill。
163
+ </context>
164
+
165
+ <self_iteration>
166
+ **Quality Gate** — auto-evaluate after each analytical stage. Insufficient → re-enter with expanded strategy.
167
+
168
+ | Dimension | Sufficient | Insufficient |
169
+ |-----------|-----------|-------------|
170
+ | Coverage | All known files/modules analyzed | Missed targets discoverable via grep/git log |
171
+ | Depth | ≥80% findings have file:line evidence | Most findings lack specifics |
172
+ | Actionability | Each conclusion has concrete next action | Only vague "consider" recommendations |
173
+
174
+ **Rules:** stage complete → evaluate 3 dims → any insufficient → re-enter (max **2 rounds** per stage). Record to evidence.ndjson `{"phase":"self-iteration","type":"quality-gate","stage":"S_XXX","round":N,"assessment":{...},"expansion":"strategy"}`.
175
+
176
+ **Expansion:** Round 1 = broaden scope (more dirs, more delegate angles). Round 2 = shift perspective (different CLI tool, reverse-trace from expected result).
177
+
178
+ **Applies to:** S_PLAN, S_VERIFY, S_GENERALIZE
179
+ </self_iteration>
180
+
181
+ <state_machine>
182
+
183
+ <states>
184
+ S_INTAKE — parse requirement, define acceptance criteria PERSIST: session.json + understanding.md §1
185
+ S_PLAN — decompose tasks, generate execution plan PERSIST: session.json.plan + evidence (planning) + understanding.md §2
186
+ S_EXECUTE — implement tasks PERSIST: code + evidence (execution) + understanding.md §3
187
+ S_VERIFY — iron gate: check every acceptance criterion PERSIST: evidence (verification) + understanding.md §4
188
+ S_FIX — targeted fix for failing criteria (loops to VERIFY) PERSIST: code + evidence (fix) + understanding.md §5
189
+ S_GENERALIZE — extract patterns, 4-agent scan PERSIST: session.json.patterns + understanding.md §6
190
+ S_DISCOVER — triage scan hits, route decisions PERSIST: evidence (discovery|decision) + understanding.md §7
191
+ S_RECORD — persist learnings, final summary PERSIST: understanding.md §8 + spec entries
192
+ </states>
193
+
194
+ <transitions>
195
+ S_INTAKE → S_INTAKE WHEN -c + session found (resume)
196
+ S_INTAKE → S_PLAN WHEN requirement + criteria defined
197
+ S_INTAKE → S_INTAKE WHEN no requirement → AskUserQuestion
198
+
199
+ S_PLAN → S_EXECUTE
200
+ S_EXECUTE → S_VERIFY
201
+
202
+ S_VERIFY → S_GENERALIZE WHEN all passed AND NOT skip_generalize
203
+ S_VERIFY → S_RECORD WHEN all passed AND skip_generalize
204
+ S_VERIFY → S_FIX WHEN some failed AND iteration < max
205
+ S_VERIFY → S_PLAN WHEN fundamental plan flaw discovered, loops < max_loops → cross_phase_loops++ (重规划)
206
+ S_VERIFY → S_RECORD WHEN some failed AND iteration >= max (escalate)
207
+
208
+ S_FIX → S_VERIFY (loop)
209
+
210
+ S_GENERALIZE → S_DISCOVER WHEN hits found
211
+ S_GENERALIZE → S_RECORD WHEN no hits
212
+
213
+ S_DISCOVER → S_EXECUTE : discovery finds area needing same implementation, loops < max_loops → cross_phase_loops++
214
+ S_DISCOVER → S_RECORD : triage complete OR loops >= max_loops (剩余项 → issue)
215
+
216
+ S_RECORD → END
217
+ </transitions>
218
+
219
+ <actions>
220
+
221
+ ### A_INTAKE
222
+
223
+ 1. Parse requirement and flags, generate slug, create SESSION_DIR
224
+ 2. **Define acceptance criteria** — analyze requirement → derive testable criteria. Each gets `verify_method`: test | grep | cli-review | manual
225
+ - **Normal**: AskUserQuestion to confirm/edit
226
+ - **`-y`**: auto-derive, record `{"phase":"decision","type":"criteria-confirmation","status":"deferred"}`
227
+ 3. Search prior knowledge: `maestro search`, related sessions
228
+ 4. Write session.json + understanding.md §1. Mark G1 done. Display Goal Prompt (see Appendix)
229
+
230
+ 📌 **Auto-commit**: `git add understanding.md && git commit -m "odyssey-planex({slug}): INTAKE — 目标解析"`
231
+
232
+ ### A_PLAN
233
+
234
+ 1. Decompose requirement into ordered tasks mapped to acceptance criteria
235
+ 2. CLI-assisted planning (optional):
236
+ ```bash
237
+ maestro delegate "PURPOSE: Create implementation plan for: {requirement}
238
+ TASK: Decompose into subtasks | Map to acceptance criteria | Identify dependencies
239
+ MODE: analysis
240
+ CONTEXT: @**/* | Criteria: {criteria_summary}
241
+ EXPECTED: JSON [{task_id, title, description, criteria_refs, deps}]
242
+ " --role analyze --mode analysis
243
+ ```
244
+ Run_in_background, STOP, wait for callback.
245
+ 3. Write session.json.plan, append evidence (planning), update understanding.md §2. Mark G2 done.
246
+
247
+ 📌 **Auto-commit**: `git add understanding.md && git commit -m "odyssey-planex({slug}): PLAN — 计划制定"`
248
+
249
+ ### A_EXECUTE
250
+
251
+ #### Step 1: Execution Options Confirmation
252
+
253
+ **Skip if** `-y` flag OR `--method` explicitly set OR `execution_config.confirmed == true` (resume).
254
+
255
+ Load available tools: `maestro delegate-config show --json` → extract enabled tools and domain tags.
256
+
257
+ ```
258
+ AskUserQuestion({
259
+ questions: [
260
+ {
261
+ question: "任务如何执行?选择一种方式,或 Other 指定域路由规则(如 '前端gemini 后端codex 其余agent')",
262
+ header: "Executor",
263
+ options: [
264
+ { label: "Auto (Recommended)", description: "域路由: frontend→{frontendTool}, backend→{backendTool}, general→agent" },
265
+ { label: "Agent", description: "Claude Code Agent 执行所有任务(最快)" },
266
+ // 每个 enabled CLI tool 一个选项
267
+ ...availableTools.map(t => ({ label: t, description: `${t} CLI 执行所有任务` }))
268
+ ]
269
+ },
270
+ {
271
+ question: "执行后运行代码审查?",
272
+ header: "Review",
273
+ options: [
274
+ { label: "Skip", description: "不审查" },
275
+ ...availableTools.map(t => ({ label: `${t} Review`, description: `${t} CLI: git diff 质量审查` }))
276
+ ]
277
+ },
278
+ {
279
+ question: "验证门控?(外部模型检查收敛 + 结构 + 反模式)",
280
+ header: "Verify",
281
+ options: [
282
+ { label: "Auto (Recommended)", description: `Delegate 到 ${availableTools[0]} 做收敛+结构+反模式检查` },
283
+ ...availableTools.map(t => ({ label: t, description: `${t}: 验证门控` })),
284
+ { label: "Skip", description: "不验证" }
285
+ ]
286
+ }
287
+ ]
288
+ })
289
+ ```
290
+
291
+ Parse response → write `execution_config` to session.json, set `confirmed: true`.
292
+
293
+ `--skip-verify` flag overrides verification to `"Skip"`.
294
+
295
+ #### Step 2: Executor Resolution
296
+
297
+ Per-task domain routing (when method == "auto"):
298
+
299
+ | Domain | Keywords / Patterns | File Extensions |
300
+ |--------|-------------------|-----------------|
301
+ | frontend | UI, component, page, style, layout, CSS, view | .tsx/.jsx/.vue/.css/.html/.svelte |
302
+ | backend | API, server, database, service, algorithm, worker | .go/.rs/.java/.py/.sql/.proto |
303
+ | general | mixed, config, tests, unclear | .ts/.js/other |
304
+
305
+ Resolution: `execution_config.domain_routing[domain]` → fallback `domain_routing.default` ("agent").
306
+
307
+ Log routing per task:
308
+ ```
309
+ T1 [frontend] → gemini
310
+ T2 [backend] → codex
311
+ T3 [general] → agent
312
+ ```
313
+
314
+ #### Step 3: Task Execution
315
+
316
+ Execute tasks per plan order. Independent tasks (no cross-dependency) may run in parallel.
317
+
318
+ **Agent path:**
319
+ ```
320
+ Spawn Agent with:
321
+ task definition, acceptance criteria refs, prior task summaries, specs_content
322
+ Agent implements → verifies convergence criteria → auto-fix (max 3) → returns result
323
+ ```
324
+
325
+ **CLI path (via maestro delegate):**
326
+ ```bash
327
+ maestro delegate "PURPOSE: Implement task ${task_id}: ${title}; success = criteria ${criteria_refs} satisfied
328
+ TASK: ${description} | Read existing code first | Verify convergence criteria after changes
329
+ MODE: write
330
+ CONTEXT: @${scope}/**/* | Criteria: ${criteria_summary}
331
+ EXPECTED: Working code changes, convergence evidence, summary of what was done
332
+ CONSTRAINTS: Scope limited to task files | Follow project specs
333
+
334
+ ## Acceptance Criteria (must satisfy)
335
+ ${criteria_refs.map(ref => criteria[ref].criterion).join('\n')}
336
+
337
+ ## Implementation Steps
338
+ ${task.description}
339
+
340
+ ## Project Specs
341
+ ${specs_content}
342
+
343
+ ## Prior Task Summaries
344
+ ${prior_summaries}
345
+ " --to ${resolved_executor} --mode write --id planex-${slug}-${task_id}
346
+ ```
347
+
348
+ Run CLI delegate with `run_in_background: true`, STOP, wait for callback.
349
+
350
+ **Deviation Rule** — max 3 auto-fix attempts per task:
351
+ 1. First attempt: normal dispatch
352
+ 2. Retry: `--resume planex-${slug}-${task_id}` with simplified prompt
353
+ 3. Final: fallback to Agent path
354
+ 4. All 3 fail → mark task `blocked`, record checkpoint, continue remaining tasks
355
+
356
+ #### Step 4: Per-Task Evidence
357
+
358
+ Per completed task:
359
+ - Record evidence: `{"phase":"execution","type":"task-completed","task_id":"T1","executor":"agent|gemini|...","files_modified":[],"summary":"","attempt":1}`
360
+ - Update task status in session.json plan
361
+
362
+ #### Step 5: Post-Execution Validation
363
+
364
+ **Skip if** `execution_config.verification_tool == "Skip"` OR `--skip-verify` OR no completed tasks.
365
+
366
+ **Check 1: Summary Consistency** — cross-check task status vs actual file changes (git diff).
367
+
368
+ **Check 2: CLI Verification Gate** — delegate to external model:
369
+ ```bash
370
+ maestro delegate "PURPOSE: Verify execution output meets acceptance criteria; success = all criteria verified with file:line evidence
371
+ TASK:
372
+ 1. CONVERGENCE: For each criterion, read actual code, verify behavior exists, report status with evidence
373
+ 2. EXISTENCE: Verify all expected files exist on disk
374
+ 3. SUBSTANCE: Verify real implementation — flag stubs, placeholders, TODO-only
375
+ 4. ANTI-PATTERNS: Scan for TODO/FIXME/HACK, console.log debug, disabled tests
376
+ MODE: analysis
377
+ CONTEXT: @${modified_files}
378
+ EXPECTED: JSON { convergence: [{criterion, status, evidence}], issues: [{type, file, line, severity}], overall: passed|gaps_found }
379
+ CONSTRAINTS: Read-only | Check ALL criteria exhaustively | Evidence must be file:line
380
+
381
+ ## Acceptance Criteria (verify each)
382
+ ${acceptance_criteria.map(c => c.criterion).join('\n')}
383
+
384
+ ## Modified Files
385
+ ${modified_files.join('\n')}
386
+ " --to ${execution_config.verification_tool} --mode analysis
387
+ ```
388
+
389
+ Run_in_background, STOP, wait for callback.
390
+
391
+ On result:
392
+ - `overall == "passed"` → proceed to S_VERIFY (criteria gate) with boosted confidence
393
+ - `overall == "gaps_found"` → log findings, proceed to S_VERIFY (criteria will catch failures)
394
+
395
+ **Check 3: Code Review** (if `execution_config.code_review_tool != "Skip"`):
396
+ ```bash
397
+ maestro delegate "Review git diff for correctness, style, bugs" --to ${code_review_tool} --mode analysis --rule analysis-review-code-quality
398
+ ```
399
+
400
+ #### Step 6: Completion
401
+
402
+ Update understanding.md §3. Mark G3 done.
403
+
404
+ 📌 **Auto-commit**: `git add -A && git commit -m "odyssey-planex({slug}): EXECUTE — 实现执行"`
405
+
406
+ ### A_VERIFY
407
+
408
+ Iron gate — every acceptance criterion checked objectively.
409
+
410
+ **Verify each criterion by method:**
411
+ | Method | Action |
412
+ |--------|--------|
413
+ | `test` | Run relevant tests, check pass/fail |
414
+ | `grep` | Grep for expected pattern |
415
+ | `cli-review` | `maestro delegate --role review --mode analysis` with criterion as focus |
416
+ | `manual` | **Normal**: AskUserQuestion / **`-y`**: record `deferred` |
417
+
418
+ Record per criterion: `{"phase":"verification","type":"criterion-check","criterion_id":"AC1","method":"","result":"passed|failed","evidence":"","iteration":N}`. Update acceptance_criteria[].status. Append to iterations[].
419
+
420
+ Update understanding.md §4 with pass/fail table.
421
+
422
+ **Route:** all passed → mark G4 done → next state. Some failed + iteration < max → S_FIX. Some failed + iteration >= max → **Normal**: AskUserQuestion (continue/lower bar/accept) / **`-y`**: `deferred`, proceed S_RECORD.
423
+
424
+ 📌 **Auto-commit**: `git add understanding.md && git commit -m "odyssey-planex({slug}): VERIFY — 验收验证"`
425
+
426
+ ### A_FIX
427
+
428
+ 1. Increment current_iteration
429
+ 2. For each failed criterion: diagnose gap → targeted code fix
430
+ 3. CLI fix review (optional):
431
+ ```bash
432
+ maestro delegate "PURPOSE: Review fixes for failing criteria
433
+ TASK: Check fix correctness | Verify no regressions on passing criteria
434
+ MODE: analysis
435
+ CONTEXT: @{modified_files} | Passing: {passing} | Fixed: {fixed}
436
+ EXPECTED: JSON {verdict, regression_risk, concerns}
437
+ " --role review --mode analysis
438
+ ```
439
+ 4. Append evidence (fix), update understanding.md §5 → S_VERIFY
440
+
441
+ 📌 **Auto-commit**: `git add -A && git commit -m "odyssey-planex({slug}): FIX — 修复"`
442
+
443
+ ### A_GENERALIZE
444
+
445
+ Extract reusable patterns from implementation, scan codebase for similar sites.
446
+
447
+ **Pattern extraction (3 layers):**
448
+ | Layer | Method | Example |
449
+ |-------|--------|---------|
450
+ | Syntax | Code regex patterns | validation/error handling patterns |
451
+ | Semantic | Logic pattern description | missing similar checks at other entry points |
452
+ | Structural | File/module structure match | sibling modules lacking same treatment |
453
+
454
+ **4-agent parallel scan** (spawn 4 Agents):
455
+ | Agent | Strategy | Scope |
456
+ |-------|----------|-------|
457
+ | Syntax grep | Grep syntax-layer signatures | full project |
458
+ | Semantic scan | Check for same anti-pattern in related modules | related modules |
459
+ | Structural match | Find structurally similar files | full project |
460
+ | Historical grep | `git log -S "{pattern}"` | full git history |
461
+
462
+ Each returns: `[{pattern_id, file, line, context, risk_level, layer, confidence}]`
463
+
464
+ **Cross-layer dedup:** multi-layer hit on same file:line → boost confidence. Historical hit with existing fix → `already_handled`. Single layer only → `needs_review`.
465
+
466
+ **Quality Gate** (self-iteration) → evaluate coverage/depth/actionability.
467
+
468
+ Write understanding.md §6, generalization_stats. Mark G5 done.
469
+
470
+ 📌 **Auto-commit**: `git add understanding.md && git commit -m "odyssey-planex({slug}): GENERALIZE — 泛化扫描"`
471
+
472
+ ### A_DISCOVER
473
+
474
+ 1. **Triage:** per hit, read context (+-10 lines), classify as `already_handled` | `needs_treatment` | `low_risk`
475
+ 2. **Route:**
476
+ | Classification | Normal | `-y` |
477
+ |---------------|--------|------|
478
+ | needs_treatment | AskUserQuestion: create issue / plan next iter | auto create issue, `deferred` |
479
+ | low_risk | Record only | Record only |
480
+ | already_handled | Skip | Skip |
481
+ 3. Append evidence (discovery + decision), update understanding.md §7. Mark G6 done.
482
+
483
+ 📌 **Auto-commit**: `git add understanding.md && git commit -m "odyssey-planex({slug}): DISCOVER — 发现分类"`
484
+
485
+ ### A_RECORD
486
+
487
+ 1. Finalize understanding.md §8 — iteration summary, what worked, what needed rework
488
+ 2. Write learnings to understanding.md §8: 按 Knowledge Persistence 表分类记录(临时),completion summary 列出建议的 `/spec-add` 命令
489
+ 3. Pending decisions: **Normal** → AskUserQuestion. **`-y`** → display deferred count.
490
+ 4. Goal audit: check all phase_goals[*].completion_confirmed. Mark G7 done.
491
+ 5. Output completion summary:
492
+ ```
493
+ --- PLANEX ODYSSEY COMPLETE ---
494
+ Requirement: {requirement}
495
+ Criteria: {passed}/{total} passed
496
+ Iterations: {N} cycles
497
+ Patterns: {patterns_extracted} ({by_layer} distribution)
498
+ Scan hits: {total_hits} ({cross_layer_confirmed} cross-layer confirmed)
499
+ Issues: {N} created | Decisions: {N} resolved, {M} pending, {K} deferred
500
+ Learnings: {N} spec entries
501
+ Self-iter: {N} rounds across {M} stages
502
+ Goals: {done}/{total} confirmed ({skipped} skipped)
503
+ Status: {ALL_PASSED|PARTIAL|ESCALATED}
504
+ ---
505
+ ```
506
+
507
+ 📌 **Auto-commit**: `git add understanding.md && git commit -m "odyssey-planex({slug}): RECORD — 会话总结"`
508
+
509
+ </actions>
510
+
511
+ <appendix>
512
+
513
+ ### Goal Prompt Template
514
+
515
+ **⚠️ 时机守卫:仅在 A_INTAKE 完成后显示一次(session 创建后、开始 Plan 前)。A_RECORD 完成时禁止重新显示。**
516
+
517
+ ```
518
+ 📋 Planex Odyssey 会话已创建。可随时复制以下 /goal 设定终止条件(执行过程中输入即可):
519
+
520
+ /goal 穷尽迭代:直到 acceptance_criteria[*] 全部 status==passed
521
+ 且 phase_goals_all_done=true 才停。verify 失败自动 fix→re-verify 循环。
522
+ 每轮修复后重新验证,新发现的标准违反继续修,不超过 max_iterations。
523
+ 遇到 phase=decision 的 pending 必须 AskUserQuestion,不得自行 resolve。
524
+ 不允许"接近通过",验收标准必须 ALL pass。
525
+ ```
526
+
527
+ 完成时仅输出 completion summary,不重复此提示。
528
+
529
+ ### `-y` Auto-Confirm Behavior
530
+
531
+ | Decision Point | Normal | `-y` |
532
+ |----------------|--------|------|
533
+ | S_INTAKE criteria confirmation | AskUserQuestion | auto-derive, `deferred` |
534
+ | S_EXECUTE execution options | AskUserQuestion (executor/review/verify) | use defaults (auto/Skip/Auto), `confirmed: true` |
535
+ | S_EXECUTE task blocked (3 retries) | AskUserQuestion: continue or stop | auto continue, log blocked |
536
+ | S_VERIFY manual criterion | AskUserQuestion | `deferred` |
537
+ | S_VERIFY max iteration reached | AskUserQuestion | auto accept, `deferred` |
538
+ | S_DISCOVER classification routing | AskUserQuestion | auto create issue, `deferred` |
539
+ | S_DISCOVER ambiguous items | AskUserQuestion | all `deferred` |
540
+ | S_RECORD decision list | AskUserQuestion | skip |
541
+ | S_RECORD goal audit | AskUserQuestion | auto accept |
542
+
543
+ ### Iteration Model
544
+
545
+ ```
546
+ S_EXECUTE → S_VERIFY ──all pass──→ S_GENERALIZE → S_DISCOVER → S_RECORD
547
+ │ │
548
+ some fail + iter < max no hits ─→ S_RECORD
549
+
550
+ S_FIX ──→ S_VERIFY (loop)
551
+ ```
552
+
553
+ Max iterations (default 3) prevents infinite loops. Each iteration records criteria_before, gaps_fixed, criteria_after.
554
+
555
+ </appendix>
556
+
557
+ </state_machine>
558
+
559
+ <error_codes>
560
+ | Code | Severity | Condition | Recovery |
561
+ |------|----------|-----------|----------|
562
+ | E001 | error | No requirement provided | Provide requirement |
563
+ | E003 | error | Resume but no session found | Start new |
564
+ | E004 | error | Delegate failed | Retry or proceed without |
565
+ | W001 | warning | No acceptance criteria derived | Manual definition needed |
566
+ | W002 | warning | Max iterations reached, criteria still failing | Escalate to user |
567
+ | W003 | warning | CLI review regression concern | Review before next iteration |
568
+ | W004 | warning | Delegate parse failed | Use raw output |
569
+ </error_codes>
570
+
571
+ <success_criteria>
572
+ - [ ] Requirement parsed and ≥1 acceptance criterion defined with verify_method
573
+ - [ ] Plan created with tasks mapped to criteria
574
+ - [ ] Execution options confirmed (executor/review/verify) before task dispatch
575
+ - [ ] Tasks dispatched via resolved executor (agent/cli/auto domain routing)
576
+ - [ ] Per-task deviation rule enforced (max 3 retries, fallback chain)
577
+ - [ ] Post-execution validation gate run (unless --skip-verify)
578
+ - [ ] Tasks executed with evidence logged (executor, attempt count, files_modified)
579
+ - [ ] Every criterion verified by its method after each iteration
580
+ - [ ] Failing criteria trigger targeted fix (not full re-implementation)
581
+ - [ ] Iteration count tracked, max respected
582
+ - [ ] understanding.md updated per phase (§1-§8)
583
+ - [ ] Multi-layer generalization + 4-agent scan (unless --skip-generalize)
584
+ - [ ] Discoveries classified and routed (unless --skip-generalize)
585
+ - [ ] Quality Gate self-iteration triggered when insufficient, logged in self_iteration_log
586
+ - [ ] phase_goals G1-G7 tracked and audited
587
+ - [ ] Goal Prompt displayed once after intake
588
+ - [ ] `-y` mode: no blocking prompts, deferred counted
589
+ - [ ] Session resumable via -c
590
+ - [ ] Completion summary with iteration stats
591
+ </success_criteria>
592
+
593
+ <next_step_routing>
594
+ | Condition | Next step |
595
+ |-----------|-----------|
596
+ | All criteria passed | `/odyssey-review-test-fix <changed-files>` |
597
+ | Max iterations, still failing | `/odyssey-debug "<failing criterion>"` |
598
+ | Want formal review | `/quality-review <phase>` |
599
+ | Issues from discoveries | `/manage-issue list --source planex-odyssey` |
600
+ | Pattern worth documenting | `/learn-decompose <module>` |
601
+ </next_step_routing>