maestro-flow 0.5.37 → 0.5.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/.agents/skills/maestro/SKILL.md +11 -5
  2. package/.agents/skills/maestro-ralph/SKILL.md +80 -12
  3. package/.agents/skills/maestro-ralph-execute/SKILL.md +17 -6
  4. package/.agents/skills/manage-drift-realign/SKILL.md +153 -0
  5. package/.agy/skills/maestro/SKILL.md +11 -5
  6. package/.agy/skills/maestro-ralph/SKILL.md +80 -12
  7. package/.agy/skills/maestro-ralph-execute/SKILL.md +17 -6
  8. package/.agy/skills/manage-drift-realign/SKILL.md +153 -0
  9. package/.claude/commands/maestro-ralph-execute.md +17 -6
  10. package/.claude/commands/maestro-ralph.md +80 -12
  11. package/.claude/commands/maestro.md +11 -5
  12. package/.claude/commands/manage-drift-realign.md +151 -0
  13. package/.codex/skills/maestro/SKILL.md +16 -8
  14. package/.codex/skills/maestro-ralph/SKILL.md +138 -11
  15. package/.codex/skills/maestro-ralph-execute/SKILL.md +17 -6
  16. package/.codex/skills/manage-drift-realign/SKILL.md +471 -0
  17. package/README.md +25 -8
  18. package/README.zh-CN.md +6 -6
  19. package/dashboard/dist-server/src/commands/install-backend.d.ts +10 -0
  20. package/dashboard/dist-server/src/commands/install-backend.js +69 -0
  21. package/dashboard/dist-server/src/commands/install-backend.js.map +1 -1
  22. package/dashboard/dist-server/src/core/component-defs.d.ts +11 -0
  23. package/dashboard/dist-server/src/core/component-defs.js +34 -2
  24. package/dashboard/dist-server/src/core/component-defs.js.map +1 -1
  25. package/dist/src/cli.js +3 -2
  26. package/dist/src/cli.js.map +1 -1
  27. package/dist/src/commands/install-backend.d.ts +10 -0
  28. package/dist/src/commands/install-backend.d.ts.map +1 -1
  29. package/dist/src/commands/install-backend.js +69 -0
  30. package/dist/src/commands/install-backend.js.map +1 -1
  31. package/dist/src/commands/install.js +1 -0
  32. package/dist/src/commands/install.js.map +1 -1
  33. package/dist/src/commands/ralph.d.ts.map +1 -1
  34. package/dist/src/commands/ralph.js +8 -0
  35. package/dist/src/commands/ralph.js.map +1 -1
  36. package/dist/src/commands/timeline.d.ts +14 -0
  37. package/dist/src/commands/timeline.d.ts.map +1 -0
  38. package/dist/src/commands/timeline.js +377 -0
  39. package/dist/src/commands/timeline.js.map +1 -0
  40. package/dist/src/core/component-defs.d.ts +11 -0
  41. package/dist/src/core/component-defs.d.ts.map +1 -1
  42. package/dist/src/core/component-defs.js +34 -2
  43. package/dist/src/core/component-defs.js.map +1 -1
  44. package/dist/src/core/install-executor.d.ts.map +1 -1
  45. package/dist/src/core/install-executor.js +11 -1
  46. package/dist/src/core/install-executor.js.map +1 -1
  47. package/dist/src/core/install-profile.d.ts.map +1 -1
  48. package/dist/src/core/install-profile.js +52 -17
  49. package/dist/src/core/install-profile.js.map +1 -1
  50. package/dist/src/i18n/locales/en.d.ts.map +1 -1
  51. package/dist/src/i18n/locales/en.js +4 -1
  52. package/dist/src/i18n/locales/en.js.map +1 -1
  53. package/dist/src/i18n/locales/zh.d.ts.map +1 -1
  54. package/dist/src/i18n/locales/zh.js +4 -1
  55. package/dist/src/i18n/locales/zh.js.map +1 -1
  56. package/dist/src/i18n/types.d.ts +3 -0
  57. package/dist/src/i18n/types.d.ts.map +1 -1
  58. package/dist/src/ralph/cmd-complete.d.ts +4 -0
  59. package/dist/src/ralph/cmd-complete.d.ts.map +1 -1
  60. package/dist/src/ralph/cmd-complete.js +8 -0
  61. package/dist/src/ralph/cmd-complete.js.map +1 -1
  62. package/dist/src/ralph/cmd-next.js +58 -8
  63. package/dist/src/ralph/cmd-next.js.map +1 -1
  64. package/dist/src/ralph/status-schema.d.ts +29 -2
  65. package/dist/src/ralph/status-schema.d.ts.map +1 -1
  66. package/dist/src/ralph/status-schema.js +1 -1
  67. package/dist/src/tui/install-ui/ComponentGrid.d.ts.map +1 -1
  68. package/dist/src/tui/install-ui/ComponentGrid.js +71 -38
  69. package/dist/src/tui/install-ui/ComponentGrid.js.map +1 -1
  70. package/dist/src/tui/install-ui/ComponentGrid.logic.d.ts +12 -3
  71. package/dist/src/tui/install-ui/ComponentGrid.logic.d.ts.map +1 -1
  72. package/dist/src/tui/install-ui/ComponentGrid.logic.js +21 -4
  73. package/dist/src/tui/install-ui/ComponentGrid.logic.js.map +1 -1
  74. package/dist/src/tui/install-ui/CyberItem.d.ts +3 -1
  75. package/dist/src/tui/install-ui/CyberItem.d.ts.map +1 -1
  76. package/dist/src/tui/install-ui/CyberItem.js +6 -5
  77. package/dist/src/tui/install-ui/CyberItem.js.map +1 -1
  78. package/dist/src/tui/install-ui/GroupedHub.d.ts +9 -0
  79. package/dist/src/tui/install-ui/GroupedHub.d.ts.map +1 -1
  80. package/dist/src/tui/install-ui/GroupedHub.js +54 -47
  81. package/dist/src/tui/install-ui/GroupedHub.js.map +1 -1
  82. package/dist/src/tui/install-ui/InstallConfirm.js +1 -1
  83. package/dist/src/tui/install-ui/InstallConfirm.js.map +1 -1
  84. package/dist/src/tui/install-ui/InstallFlow.d.ts.map +1 -1
  85. package/dist/src/tui/install-ui/InstallFlow.js +54 -5
  86. package/dist/src/tui/install-ui/InstallFlow.js.map +1 -1
  87. package/dist/src/tui/install-ui/types.d.ts +1 -0
  88. package/dist/src/tui/install-ui/types.d.ts.map +1 -1
  89. package/dist/src/tui/install-ui/types.js.map +1 -1
  90. package/dist/src/tui/install-ui/useInstallFlowState.d.ts +8 -2
  91. package/dist/src/tui/install-ui/useInstallFlowState.d.ts.map +1 -1
  92. package/dist/src/tui/install-ui/useInstallFlowState.js +145 -15
  93. package/dist/src/tui/install-ui/useInstallFlowState.js.map +1 -1
  94. package/dist/src/utils/update-notices.js +12 -0
  95. package/dist/src/utils/update-notices.js.map +1 -1
  96. package/package.json +1 -1
  97. package/workflows/agy-instructions.md +127 -88
  98. package/workflows/analyze.md +2 -2
  99. package/workflows/auto-test.md +7 -1
  100. package/workflows/blueprint.md +22 -19
  101. package/workflows/brainstorm.md +11 -3
  102. package/workflows/business-test.md +4 -0
  103. package/workflows/codebase-rebuild.md +8 -1
  104. package/workflows/codebase-refresh.md +7 -1
  105. package/workflows/codex-instructions.md +1 -1
  106. package/workflows/debug.md +5 -2
  107. package/workflows/domain-add.md +6 -0
  108. package/workflows/drift-realign.md +396 -0
  109. package/workflows/execute.md +5 -4
  110. package/workflows/explore-usage.md +2 -2
  111. package/workflows/finish-work.md +6 -6
  112. package/workflows/fork.md +2 -2
  113. package/workflows/grill.md +6 -5
  114. package/workflows/harvest.md +2 -2
  115. package/workflows/impeccable.md +3 -2
  116. package/workflows/init.md +7 -7
  117. package/workflows/integration-test.md +1 -0
  118. package/workflows/issue-gaps-analyze.codex.md +2 -0
  119. package/workflows/issue-gaps-analyze.md +4 -4
  120. package/workflows/issue-plan.md +1 -1
  121. package/workflows/knowhow.md +7 -1
  122. package/workflows/knowledge-audit.md +1 -1
  123. package/workflows/maestro-super.md +2 -2
  124. package/workflows/maestro.md +3 -3
  125. package/workflows/map.md +2 -2
  126. package/workflows/milestone-audit.md +1 -1
  127. package/workflows/milestone-complete.md +1 -1
  128. package/workflows/plan.md +7 -6
  129. package/workflows/quick.md +8 -6
  130. package/workflows/ralph-amend-goal.md +177 -0
  131. package/workflows/refactor.md +2 -0
  132. package/workflows/retrospective.md +7 -3
  133. package/workflows/review.md +6 -4
  134. package/workflows/roadmap-common.md +3 -3
  135. package/workflows/roadmap.md +8 -5
  136. package/workflows/spec-generate.md +23 -18
  137. package/workflows/specs-load.md +1 -1
  138. package/workflows/specs-setup.md +2 -0
  139. package/workflows/sync.md +4 -2
  140. package/workflows/test-gen.md +1 -1
  141. package/workflows/test.md +1 -1
  142. package/workflows/ui-codify-extract.md +1 -0
  143. package/workflows/ui-codify-knowhow.md +1 -1
  144. package/workflows/ui-codify-package.md +1 -1
  145. package/workflows/ui-codify.md +9 -7
  146. package/workflows/ui-design.md +9 -7
  147. package/workflows/ui-style.md +6 -4
  148. package/workflows/verify.md +4 -4
  149. package/workflows/wiki-connect.md +2 -0
  150. package/workflows/wiki-digest.md +5 -3
  151. package/workflows/wiki-manage.md +4 -0
  152. package/workflows/maestro.codex.md +0 -365
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: maestro-ralph
3
3
  description: Use when the optimal command sequence is unclear and needs automated state-based determination
4
- argument-hint: <intent> [-y] | status | continue
4
+ argument-hint: <intent> [-y] | status | continue | --amend [change]
5
5
  allowed-tools:
6
6
  - ask_question
7
7
  - grep_search
@@ -15,6 +15,10 @@ Closed-loop decision engine: read project state → infer position → build ada
15
15
  Ralph builds/evaluates; ralph-execute runs steps. Session: `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`.
16
16
  </purpose>
17
17
 
18
+ <deferred_reading>
19
+ - [ralph-amend-goal.md](~/.maestro/workflows/ralph-amend-goal.md) — read when `--amend` flag active for goal amendment flow
20
+ </deferred_reading>
21
+
18
22
  <context>
19
23
  $ARGUMENTS — intent text, flags, or keywords.
20
24
 
@@ -22,8 +26,9 @@ $ARGUMENTS — intent text, flags, or keywords.
22
26
  ```
23
27
  -y flag → auto_confirm = true # 唯一来源:用户显式传入;ralph 不内部推断(invariant 14)
24
28
  --roadmap → wants_roadmap = true (强制多发布 roadmap 路径;roadmap 默认 opt-in)
29
+ --amend / -a → amend_mode = true (running session 存在时触发目标修改流程)
25
30
  .md/.txt path → input_doc (supplementary context only, NEVER substitutes lifecycle stages)
26
- Remaining → intent
31
+ Remaining → intent (amend_mode 时为 change_request)
27
32
  ```
28
33
 
29
34
  **State files:**
@@ -69,6 +74,7 @@ S_CONFIRM — 用户确认 PERSIST: —
69
74
  S_DISPATCH — 移交 maestro-ralph-execute PERSIST: —
70
75
  S_DECISION_EVAL — 委托评估质量门 PERSIST: —
71
76
  S_APPLY_VERDICT — 应用裁决 + 插入命令 PERSIST: session.steps[], session.passed_gates[]
77
+ S_AMEND_GOAL — 修改 running session 目标 PERSIST: session.task_decomposition, .boundary_contract, .goal_changelog, .steps[]
72
78
  S_FALLBACK — 请求用户输入 PERSIST: —
73
79
  </states>
74
80
 
@@ -77,6 +83,8 @@ S_FALLBACK — 请求用户输入 PERSIST: —
77
83
  S_PARSE_ROUTE:
78
84
  → S_STATUS WHEN: intent == "status"
79
85
  → S_CONTINUE WHEN: intent == "continue"
86
+ → S_AMEND_GOAL WHEN: amend_mode == true AND running session exists
87
+ → S_FALLBACK WHEN: amend_mode == true AND no running session DO: Display: "无运行中的 ralph 会话,--amend 需要活跃 session"
80
88
  → S_DECISION_EVAL WHEN: running session with decision step in "running" status
81
89
  → S_RESOLVE_PHASE WHEN: intent is non-empty ← phase 必须先于 position
82
90
  → S_FALLBACK WHEN: no intent AND no running session
@@ -163,6 +171,11 @@ S_APPLY_VERDICT:
163
171
  GUARD: not auto_confirm → ask_question with override options
164
172
  GUARD: post-reground + drifted + confidence_score >= 60 → A_REGROUND_HALT(漂移熔断为安全门,auto_confirm 不跳过)
165
173
 
174
+ S_AMEND_GOAL:
175
+ → S_DISPATCH WHEN: change applied + user confirmed DO: A_AMEND_GOAL
176
+ → END WHEN: user cancels
177
+ GUARD: RISK_LEVEL=high → auto_confirm 无效,必须 ask_question
178
+
166
179
  S_FALLBACK:
167
180
  → S_PARSE_ROUTE WHEN: user provides input DO: ask_question
168
181
  → END WHEN: user cancels
@@ -402,7 +415,11 @@ Generate steps from `session.lifecycle_position` to `milestone-complete`(`sess
402
415
  3.6. **frontend-verify UI 门控**:仅当当前 phase 交付前端(检出 `dashboard/` 目录,或 phase 目标/计划含 UI 关键词 `landing|page|dashboard|frontend|UI|component|界面`)时保留 `frontend-verify` stage + `post-frontend-verify` decision;纯后端 phase 删除该 stage
403
416
  4. **决策节点**:每个 Decision after 非空的 stage 之后插入 `{ decision: "<gate>", retry_count: 0, max_retries: 2, command_scope: null, command_path: null }`
404
417
  5. **goal-audit 插入**:`task_decomposition` 存在时,在最后一个 evidence-producing stage(execute/review/test)之后、`milestone-complete` 之前插入 `decision:post-goal-audit`
405
- 5.5. **re-grounding 插入**:当 `task_decomposition` 存在 **且** 链路含 ≥3 个执行 step(不含 decision 节点)时,从第 3 个执行 step 起每隔 3 个执行 step 后插入 `{ decision: "post-reground", retry_count: 0, max_retries: 0, command_scope: null, command_path: null }`。不在最后一个执行 step 之后插入(由 goal-audit 覆盖);不与已有 quality-gate decision 节点相邻(顺延到下一个 3-step 边界);fix-loop 动态插入的 step(index > 原始 chain 长度)不纳入计数
418
+ 5.5. **re-grounding 插入**:WHEN `task_decomposition` 存在 AND 执行 step(不含 decision)≥3
419
+ - 从第 3 个执行 step 起每隔 3 个插入 `{ decision: "post-reground", retry_count: 0, max_retries: 0, command_scope: null, command_path: null }`
420
+ - 不在最后一个执行 step 后插入(由 goal-audit 覆盖)
421
+ - 不与已有 quality-gate decision 节点相邻(顺延到下一个 3-step 边界)
422
+ - fix-loop 动态插入的 step **纳入**计数(从插入点起重新计算 3-step 间隔)
406
423
  6. **终点硬约束**:`session.milestone` 存在时 chain 以 `milestone-complete` 结尾;`session.milestone=null`(standalone)时跳过 `milestone-audit` + `milestone-complete` stage,chain 以最后一个质量门 stage 结尾
407
424
  7. **goal_ref 传播**:`task_decomposition` 存在时,每个 step 按 `step.stage ∈ g.lifecycle` 匹配 `step.goal_ref = g.id`(多匹配取字典序最小);decision 节点不打 goal_ref
408
425
  8. **占位符**:independent 保留 `{phase}` `{intent}`;unified 不带 `{phase}`
@@ -413,7 +430,7 @@ Generate steps from `session.lifecycle_position` to `milestone-complete`(`sess
413
430
  - 命中 skills → 同上(type=skill)
414
431
  - 未命中 → `command_scope = "missing"`, `command_path = null`,A_CREATE_SESSION 报错 E006
415
432
  - **不在 build 阶段读取 .md 内容**;`<required_reading>` / `<deferred_reading>` 解析与加载由 `maestro ralph next` CLI 在执行期完成
416
- 10. **每个 step 初始化** `completion_confirmed: false`, `completion_status: null`, `completion_evidence: null`, `deferred_reads: []`, `load: null`(由 `ralph next` 写入)
433
+ 10. **每个 step 初始化** `completion_confirmed: false`, `completion_status: null`, `completion_evidence: null`, `completion_summary: null`, `completion_decisions: null`, `completion_caveats: null`, `completion_deferred: null`, `deferred_reads: []`, `load: null`(由 `ralph next` 写入)
417
434
  11. **scope_verdict gating**(仅当 chain 起点 = `analyze-macro`):
418
435
  - `scope_verdict == large` **且** `wants_roadmap` → 保留 `roadmap` + `analyze`;`plan` 选 phase 列(`{phase}`)
419
436
  - 其余(`medium` / `small`,或 `large` 但非 `wants_roadmap`)→ 跳过 `roadmap` + `analyze` 两 stage;`plan` 选 standalone 列(`--from analyze:{analyze_macro_id}`),不带 `{phase}`
@@ -538,9 +555,12 @@ Runs only when `task_decomposition` present.
538
555
 
539
556
  ### A_REGROUND_EVALUATE
540
557
 
541
- 仅当 `task_decomposition` 存在。周期触发(build rule 5.5)。
558
+ GUARD: `task_decomposition` 存在(周期触发,见 build rule 5.5
542
559
 
543
- 1. status.json 读取:`session.intent`、`session.boundary_contract`、`steps[]` 中 `status=="completed"` 的 step + `completion_evidence`、`task_decomposition` 中已 done 子目标的 `goal` + `done_when`
560
+ 1. Read status.json
561
+ - `session.intent`, `session.boundary_contract`
562
+ - `steps[]` WHERE `status=="completed"` → 取 `completion_evidence`, `completion_summary`, `completion_decisions`, `completion_caveats`
563
+ - `task_decomposition[]` WHERE `status=="done"` → 取 `goal`, `done_when`
544
564
  2. Delegate read-only audit (run_in_background, STOP, wait):
545
565
  ```
546
566
  maestro delegate "PURPOSE: 意图保真检查 — 对照 intent 验证累积执行是否漂移
@@ -554,8 +574,10 @@ Runs only when `task_decomposition` present.
554
574
  definition_of_done = {boundary_contract.definition_of_done}
555
575
  in_scope = {boundary_contract.in_scope}
556
576
  out_of_scope = {boundary_contract.out_of_scope}
557
- completed_steps = [{index, skill, stage, completion_evidence}, ...]
577
+ completed_steps = [{index, skill, stage, completion_evidence, completion_summary, completion_decisions, completion_caveats}, ...]
558
578
  done_goals = [{id, goal, done_when}, ...]
579
+ accumulated_deferred = [{from_step, item}, ...]
580
+ goal_changelog = {session.goal_changelog ?? []}
559
581
  EXPECTED:
560
582
  ---VERDICT---
561
583
  STATUS=aligned|drifted
@@ -566,7 +588,8 @@ Runs only when `task_decomposition` present.
566
588
  CONSTRAINTS:
567
589
  - 只评估,不修改文件
568
590
  - aligned 阈值:≥80% 已完成产出直接服务 intent
569
- - 单个 step 触碰 out_of_scope → 直接判 drifted"
591
+ - 单个 step 触碰 out_of_scope → 直接判 drifted
592
+ - goal_changelog 存在 → 以最新 after.goals 为基准"
570
593
  --role analyze --mode analysis
571
594
  ```
572
595
  3. On callback: parse verdict
@@ -644,6 +667,21 @@ Runs only when `task_decomposition` present.
644
667
  2. Display: ◆ 已达最大重试次数,debug 已执行。请人工介入。
645
668
  3. Display: /maestro-ralph continue 恢复
646
669
 
670
+ ### A_AMEND_GOAL
671
+
672
+ 运行中 session 的目标热修改。详细流程由 `<deferred_reading>` 加载 `ralph-amend-goal.md`。
673
+
674
+ | Phase | 行为 | 产出 |
675
+ |-------|------|------|
676
+ | 1. 快照 | 读 `task_decomposition` + `boundary_contract` + 已完成 steps 的 `completion_summary` | Display: 目标列表 + 进度 |
677
+ | 2. 解析 | `change_request` 非空 → 直接用;为空 → ask_question(修改/新增/移除/调整边界) | `change_type` + `change_request` |
678
+ | 3. Mini Grill | `maestro delegate --role analyze --mode analysis`:评估影响 | RISK_LEVEL + AFFECTED_GOALS + INVALIDATED_STEPS + NEW_GAPS |
679
+ | 4. 确认 | ask_question:应用并继续 / 仅改目标 / 取消 | 用户选择 |
680
+ | 5. 应用 | 归档旧目标(`superseded`)→ 写入新目标(`origin: CHG-xxx`)→ 重建链路 → write status.json | handoff ralph-execute |
681
+
682
+ GUARD: `RISK_LEVEL == high` → ask_question 不跳过(auto_confirm 无效)
683
+ GUARD: 已完成(`status: "done"`)的目标不可 supersede(skip + warn)
684
+
647
685
  </actions>
648
686
 
649
687
  </state_machine>
@@ -656,7 +694,7 @@ Runs only when `task_decomposition` present.
656
694
  {
657
695
  "session_id": "ralph-{YYYYMMDD-HHmmss}",
658
696
  "source": "ralph", "status": "running",
659
- "ralph_protocol_version": "1", // CLI-driven; absent/0 → legacy inline ralph-execute
697
+ "ralph_protocol_version": "2", // CLI-driven; absent/0 → legacy; "1" → basic CLI; "2" → structured completion + enhanced anchor
660
698
  "active_step_index": null, // CLI-managed; only one step held at a time
661
699
  "intent": "", "lifecycle_position": "",
662
700
  "phase": null, "phase_is_new": false,
@@ -691,6 +729,10 @@ Runs only when `task_decomposition` present.
691
729
  "completion_confirmed": false,
692
730
  "completion_status": null,
693
731
  "completion_evidence": null,
732
+ "completion_summary": null, // 一句话总结:做了什么(MUST on DONE)
733
+ "completion_decisions": null, // 本 step 做出的关键决策列表
734
+ "completion_caveats": null, // 后续 step 需注意的事项
735
+ "completion_deferred": null, // 被推迟到后续的工作列表
694
736
  "completed_at": null,
695
737
  "deferred_reads": [], // 由 ralph next CLI 解析 .md 时填充
696
738
  "load": null // { loaded_at, required_files[], deferred_files[], resolve_version } —— 由 ralph next 写入
@@ -704,10 +746,22 @@ Runs only when `task_decomposition` present.
704
746
  "execution_criteria": [],
705
747
  "task_decomposition": [
706
748
  { "id": "G1", "goal": "", "boundary": "", "done_when": "",
707
- "evidence": "", "lifecycle": [], "status": "pending|done",
708
- "completion_confirmed": false, "completed_at": null }
749
+ "evidence": "", "lifecycle": [], "status": "pending|done|superseded",
750
+ "completion_confirmed": false, "completed_at": null,
751
+ "superseded_by": null, "superseded_at": null, "origin": null }
709
752
  ],
710
- "task_decomposition_all_done": false
753
+ "task_decomposition_all_done": false,
754
+
755
+ // goal_changelog: additive; absent → no amendments
756
+ "goal_changelog": [
757
+ { "id": "CHG-001", "timestamp": "{ISO}",
758
+ "change_type": "modify|add|remove|boundary",
759
+ "reason": "变更描述",
760
+ "impact_assessment": { "risk_level": "low|medium|high",
761
+ "invalidated_steps": [], "new_steps_inserted": 0 },
762
+ "before": { "goals": [{"id":"G1","goal":"...","done_when":"..."}] },
763
+ "after": { "goals": [{"id":"G1v2","goal":"...","done_when":"..."}] } }
764
+ ]
711
765
  }
712
766
  ```
713
767
 
@@ -839,5 +893,19 @@ decision:post-goal-audit {retry+1}
839
893
  - [ ] Phase-level deferred chaining:plan/execute step 的 `--from`/`--dir` 注入由 A_RESOLVE_ARGS(ralph-execute)运行时完成;build 阶段标记意图,不预知 artifact ID
840
894
  - [ ] Phase-level plan step 运行时获得 `--from analyze:{phase_analyze_id}`(由 ralph-execute 从 state.json 查找注入)
841
895
  - [ ] Phase-level execute step 运行时获得 `source_artifact_ref = "plan:{id}"`
896
+ - [ ] 每个 step 含 `completion_summary` + `completion_decisions` + `completion_caveats` + `completion_deferred`(初始 null)
897
+ - [ ] `completion_summary` 在 DONE/DONE_WITH_CONCERNS 时为 MUST(由 CLI `--summary` 参数传入)
898
+ - [ ] session_anchor 包含最近 5 个已完成 step 的 `completion_summary` + `completion_caveats`(滑动窗口)
899
+ - [ ] session_anchor 包含 task_decomposition 全局视图(仅 `status != "superseded"` 的目标)
900
+ - [ ] session_anchor boundary_contract 不截断(`capAnchorList` n=8)
901
+ - [ ] session_anchor 包含 Accumulated Signals(聚合所有 caveats + deferred)
902
+ - [ ] re-grounding 完成 steps 信息含 completion_summary/decisions/caveats
903
+ - [ ] fix-loop 动态插入的 step 纳入 re-grounding 3-step 计数
904
+ - [ ] `--amend` 路由到 S_AMEND_GOAL(需 running session)
905
+ - [ ] A_AMEND_GOAL:5 步流程(快照→解析→mini grill→确认→应用)
906
+ - [ ] 旧目标标 `superseded`(`superseded_by` + `superseded_at`),新目标标 `origin: "CHG-xxx"`
907
+ - [ ] `goal_changelog` 记录完整 before/after 快照 + impact_assessment
908
+ - [ ] `RISK_LEVEL=high` 时 amend 不跳过 auto_confirm
909
+ - [ ] session_anchor 中 superseded 目标仅占一行标注,不展开细节
842
910
 
843
911
  </appendix>
@@ -185,7 +185,9 @@ Write enriched args + source_artifact_ref back to status.json.
185
185
  - 退出码 2 → 交给 S_LOCATE
186
186
  - 退出码 3 → active_step_index 已被占用
187
187
  - 退出码 1 → pause session
188
- 2. **Goal context pre-injection** — 若 A_RESOLVE_ARGS 产出了 `goal_snippet`(step.goal_ref 非空),在 ralph next stdout prompt **顶部前置**以下 block,使执行命令感知当前子目标和执行约束:
188
+ 2. **Goal context pre-injection**:
189
+ - GUARD: `ralph_protocol_version >= "2"` → skip(session_anchor 已含 goal context)
190
+ - WHEN `ralph_protocol_version < "2"` 或缺失 AND `step.goal_ref` 非空 → 在 stdout 顶部前置:
189
191
  ```
190
192
  <goal_context>
191
193
  Sub-goal: {goal.id} — {goal.goal}
@@ -195,13 +197,19 @@ Write enriched args + source_artifact_ref back to status.json.
195
197
  Execution criteria: {session.execution_criteria joined by '; '}
196
198
  </goal_context>
197
199
  ```
198
- goal_snippet 时跳过此步。goal_context block 不替换 ralph next stdout 内容,仅在其前方拼接。
199
- 3. **Inline execution** — 按 stdout(含 goal_context 前置)执行;deferred_reading 按需 Read
200
+ 3. **Inline execution** stdout 执行;deferred_reading 按需 Read
200
201
  4. **Complete**:
201
- - `run_command("maestro ralph complete N --status DONE [--evidence <path>]")`
202
- - `run_command("maestro ralph complete N --status DONE_WITH_CONCERNS --concerns \"...\"")`
202
+ - `run_command("maestro ralph complete N --status DONE --summary \"...\" [--evidence <path>] [--decisions \"...\"] [--caveats \"...\"] [--deferred \"...\"]")`
203
+ - `run_command("maestro ralph complete N --status DONE_WITH_CONCERNS --summary \"...\" --concerns \"...\"")`
203
204
  - `run_command("maestro ralph retry N")`
204
205
  - `run_command("maestro ralph complete N --status BLOCKED --reason \"...\"")`
206
+
207
+ | Param | 必填 | 格式 | 示例 |
208
+ |-------|------|------|------|
209
+ | `--summary` | MUST | 动词开头,≤100 字 | `"实现搜索 API 分页逻辑,新增 3 端点"` |
210
+ | `--decisions` | SHOULD(可多次) | 每条一个决策 | `"选择 ELK 布局而非 dagre"` |
211
+ | `--caveats` | SHOULD | 后续注意事项 | `"X 模块 e2e 暂未覆盖新端点"` |
212
+ | `--deferred` | SHOULD(可多次) | 推迟工作 | `"性能优化留到 review 后"` |
205
213
  5. **Propagate context signals** — 关键信号 (`PHASE: N` / `scratch_dir: path` / `BLP-xxx`) 写入 `status.json.context`
206
214
 
207
215
  完成后 S_LOCATE 触发 `view_file(AbsolutePath="<agy-skills-dir>/maestro-ralph-execute/SKILL.md") + execute inline` 自调用。
@@ -280,8 +288,11 @@ Display: `[{index}/{total}] ✗ {step.skill} 失败,会话已暂停。/maestro
280
288
  - [ ] 自调用持续到全部 completion_confirmed 或 paused
281
289
  - [ ] --from auto-injection:phase-level plan step 运行时从 state.json 查找同 phase+milestone 最新 completed analyze artifact → 注入 `--from analyze:{id}`,写 `source_artifact_ref`
282
290
  - [ ] --from auto-injection:phase-level execute step 运行时查找同 phase+milestone 最新 completed plan artifact → 注入 `--dir`,写 `source_artifact_ref`
283
- - [ ] Goal context injection:step.goal_ref 非空时从 task_decomposition 提取 goal_snippet,A_EXEC_STEP ralph next stdout 顶部前置 `<goal_context>` block
291
+ - [ ] Goal context injection:`ralph_protocol_version < "2"` 前置 `<goal_context>` block;`>= "2"` skip(session_anchor 覆盖)
284
292
  - [ ] Goal context 包含 sub-goal description、done_when、boundary、evidence、execution_criteria
285
293
  - [ ] 已有 `--from` 或 `--dir` 的 step 不被 auto-injection 覆盖
294
+ - [ ] `--summary` 在 DONE/DONE_WITH_CONCERNS 时为 MUST(动词开头,≤100 字)
295
+ - [ ] `--decisions`/`--caveats`/`--deferred` 为 SHOULD;存在关键决策/注意事项/推迟工作时填写
296
+ - [ ] 结构化总结由 CLI 写入 status.json,session_anchor 自动聚合注入下游 step
286
297
 
287
298
  </appendix>
@@ -0,0 +1,153 @@
1
+ ---
2
+ name: manage-drift-realign
3
+ description: Detect and realign .workflow/ artifact drift against code reality after refactoring
4
+ argument-hint: --scope <roadmap|spec|codebase|state|issue|knowhow|project|all> [--since YYYY-MM-DD|commit|HEAD~N] [--depth shallow|deep] [--dry-run] [--report] [--auto-archive] [--interactive]
5
+ allowed-tools:
6
+ - ask_question
7
+ - define_subagent
8
+ - grep_search
9
+ - invoke_subagent
10
+ - manage_subagents
11
+ - replace_file_content
12
+ - run_command
13
+ - send_message
14
+ - view_file
15
+ - write_to_file
16
+ ---
17
+ <purpose>
18
+ 检测代码重构/增量变更后,代码现实与 .workflow/ 文档之间的漂移。互补于 `manage-knowledge-audit`(检测知识存储内部矛盾)。本命令通过 git 时间线 + session 历史检测 code↔document 漂移。
19
+ </purpose>
20
+
21
+ <required_reading>
22
+ @~/.maestro/workflows/drift-realign.md
23
+ </required_reading>
24
+
25
+ <deferred_reading>
26
+ - ~/.maestro/workflows/knowledge-audit.md (交叉引用已有审计发现)
27
+ - ~/.maestro/workflows/sync.md (codebase 文档严重漂移时自动触发)
28
+ - ~/.maestro/workflows/codebase-rebuild.md (sync 不足时的回退方案)
29
+ </deferred_reading>
30
+
31
+ <context>
32
+ Arguments: $ARGUMENTS
33
+
34
+ **Scope:** `roadmap` | `spec` | `codebase` | `state` | `issue` | `knowhow` | `project` | `all`(默认 `all`)
35
+
36
+ **`--since`:** 分析起始点。支持日期(`YYYY-MM-DD`)、commit ref(`abc1234`)、相对引用(`HEAD~N`)。默认自动检测:优先读 `state.json` 的 `last_drift_realign` 或 `last_pruned` 时间戳,回退 90 天。
37
+
38
+ **`--depth`:** `shallow`(mtime + 引用检查)vs `deep`(LLM 语义分析)。默认 `shallow`。
39
+
40
+ **`--dry-run`:** 预览模式,不执行任何写入。
41
+
42
+ **`--report`:** 仅生成报告,不进入交互分诊。
43
+
44
+ **`--auto-archive`:** 自动归档陈旧项,跳过逐项确认。
45
+
46
+ **`--interactive`:** 逐项交互分诊(默认)。
47
+
48
+ **互斥规则:** `--report` 覆盖 `--interactive`;`--auto-archive` 覆盖 `--interactive`。
49
+
50
+ **状态文件读取:**
51
+ - `.workflow/state.json`
52
+ - `.workflow/roadmap.md`
53
+ - `.workflow/specs/*.md`
54
+ - `.workflow/codebase/*.md`
55
+ - `.workflow/issues/issues.jsonl`
56
+ - `.workflow/knowhow/*.md`
57
+ - `.workflow/project.md`
58
+
59
+ 使用 `maestro timeline` CLI 构建统一的 git+session 时间线。
60
+ </context>
61
+
62
+ <execution>
63
+ Follow `~/.maestro/workflows/drift-realign.md` Stages 1-9 in order.
64
+
65
+ ### Phase Gates (MANDATORY, BLOCKING)
66
+
67
+ **GATE 1: Parse → Timeline** (Stages 1-2)
68
+ - REQUIRED: `.workflow/` 存在,scope 解析通过,`--since` 已解析。
69
+ - REQUIRED: `maestro timeline --since <date> --json` 产出有效时间线。
70
+ - BLOCKED if `.workflow/` 缺失 (E001)、scope 非法 (E002)、git 不可用 (E003)。
71
+
72
+ **GATE 2: Timeline → Scan** (Stages 2-3 → Stage 4)
73
+ - REQUIRED: `timeline.json` 已生成且包含事件。
74
+ - REQUIRED: `drift_score` 已计算(LOW/MODERATE/SEVERE)。
75
+ - REQUIRED: 若 SEVERE 且 `--depth shallow`,发出 W002 建议 `--depth deep`。
76
+ - BLOCKED if 时间线为空(`--since` 之后无变更)。
77
+
78
+ **GATE 3: Scan → Triage** (Stage 4 → Stages 5-6)
79
+ - REQUIRED: 4 个并行漂移扫描 agent 全部返回结果(或 W003 部分覆盖)。
80
+ - REQUIRED: `DriftFinding[]` 已合并、去重、按严重度排序。
81
+ - BLOCKED if 所有 agent 均失败。
82
+
83
+ **GATE 4: Triage → Apply** (Stages 6-7 → Stage 8)
84
+ - REQUIRED: 备份 tarball 生成于 `.workflow/.trash/drift-realign-{timestamp}/`。
85
+ - REQUIRED: 所有用户决策已记录(或 `--auto-archive`/`--report` 已生效)。
86
+ - REQUIRED: codebase scope 的 rebuild 动作自动触发 `/quality-sync --full`。
87
+ - BLOCKED if 备份失败 (E005)。
88
+
89
+ ### Execution Constraints
90
+
91
+ - **Code-as-Truth**: 代码是唯一真理源。当文档说 X 但代码做 Y 时,文档漂移。
92
+ - **Parallel scan**: Stage 4 在单条消息中派发 4 个 agent(roadmap-scanner、spec-scanner、codebase-scanner、artifact-scanner)。
93
+ - **Auto-rebuild**: 当 codebase-scanner 检测到严重漂移(3+ P0 finding)时,分诊后自动触发 `/quality-sync --full`。若 sync 报告重大结构变更,建议 `/manage-codebase-rebuild`。
94
+ - **Long gap handling**: 当 `drift_window` > 180 天时,自动升级为 `--depth deep` 并警告用户 (W002)。
95
+
96
+ ### Platform Inquiry(Stage 2a,交互式)
97
+
98
+ 当 `session_summary.by_platform` 包含多个平台且 session 总量 > 20 时,使用 ask_question 询问用户修改主要在哪个平台进行。用户选择后以 `--platform` 参数重新获取 timeline,缩小后续分析范围。
99
+
100
+ ### Session 详情加载策略(Stage 2b)
101
+
102
+ `maestro timeline` 每条 session 事件已包含:`summary`(用户提问摘要)、`edited_files`、`code_paths`、`platform`。这些信息在 `--depth shallow` 模式下足以支撑漂移检测。
103
+
104
+ 当 `--depth deep` 时,对与 cold_workflow_files 有 edited_files 交集的 session,通过 `maestro load --type session --id <id> --json` 按需加载完整 body 和 related 字段:
105
+ - 仅加载 edited_files 与 cold_workflow_files 有交集的 session
106
+ - 最多加载 10 个(按交集文件数降序排序)
107
+ - 结果写入 `.workflow/.drift-realign/session-details-{date}.json`
108
+ - scanner agent 在 deep 模式下同时接收 timeline.json + session-details.json
109
+ </execution>
110
+
111
+ <completion>
112
+ ### Next-step routing
113
+
114
+ | Condition | Suggestion |
115
+ |-----------|-----------|
116
+ | codebase 文档已重建 | `/manage-status` |
117
+ | spec 标记待更新 | 手动编辑标记的 spec 文件 |
118
+ | roadmap 已过时 | `/maestro-roadmap` 重新生成 |
119
+ | state.json 需清理 | `/manage-knowledge-audit --scope artifact` |
120
+ | 需要完整同步 | `/quality-sync --full` |
121
+ | project.md 已过时 | 编辑 `.workflow/project.md` |
122
+ </completion>
123
+
124
+ <error_codes>
125
+ | Code | Severity | Condition | Recovery |
126
+ |------|----------|-----------|----------|
127
+ | E001 | error | `.workflow/` 未初始化 | 先跑 `/maestro-init` |
128
+ | E002 | error | `--scope` 非法 | 提供有效 scope: roadmap/spec/codebase/state/issue/knowhow/project/all |
129
+ | E003 | error | git 不可用(非 git 仓库) | 初始化 git |
130
+ | E004 | error | `--since` 无法解析 | 检查日期格式或 commit ref |
131
+ | E005 | error | 备份失败 | 检查磁盘空间 |
132
+ | W001 | warning | session 历史不可用(wiki 未索引) | 运行 `maestro wiki rebuild` |
133
+ | W002 | warning | `drift_window` > 180 天 | 建议使用 `--depth deep` |
134
+ | W003 | warning | 部分 scanner agent 失败 | 以部分覆盖继续 |
135
+ | W004 | warning | git log > 1000 commits | 自动截断至最近 1000 条 |
136
+ </error_codes>
137
+
138
+ <success_criteria>
139
+ - [ ] Scope 正确解析,互斥标志校验通过
140
+ - [ ] `maestro timeline` 已调用,`timeline.json` 已生成
141
+ - [ ] `drift_score` 已计算(LOW/MODERATE/SEVERE 已展示)
142
+ - [ ] 4 个并行 scanner agent 已派发
143
+ - [ ] `DriftFinding[]` 已合并并按 P0 > P1 > P2 排序
144
+ - [ ] 如 `--interactive`:用户已分诊所有 finding
145
+ - [ ] 变更前备份 tarball 已生成
146
+ - [ ] archive 动作已将文件移入 `.trash/`
147
+ - [ ] update 动作已注入 TODO 标记及提示
148
+ - [ ] rebuild 动作已自动触发 `/quality-sync --full`
149
+ - [ ] `state.json` 已更新 `last_drift_realign` 时间戳
150
+ - [ ] `drift-report-{date}.md` 已生成
151
+ - [ ] `drift-log.jsonl` 已追加
152
+ - [ ] 摘要展示及下一步路由已输出
153
+ </success_criteria>
@@ -187,7 +187,9 @@ Write enriched args + source_artifact_ref back to status.json.
187
187
  - 退出码 2 → 交给 S_LOCATE
188
188
  - 退出码 3 → active_step_index 已被占用
189
189
  - 退出码 1 → pause session
190
- 2. **Goal context pre-injection** — 若 A_RESOLVE_ARGS 产出了 `goal_snippet`(step.goal_ref 非空),在 ralph next stdout prompt **顶部前置**以下 block,使执行命令感知当前子目标和执行约束:
190
+ 2. **Goal context pre-injection**:
191
+ - GUARD: `ralph_protocol_version >= "2"` → skip(session_anchor 已含 goal context)
192
+ - WHEN `ralph_protocol_version < "2"` 或缺失 AND `step.goal_ref` 非空 → 在 stdout 顶部前置:
191
193
  ```
192
194
  <goal_context>
193
195
  Sub-goal: {goal.id} — {goal.goal}
@@ -197,13 +199,19 @@ Write enriched args + source_artifact_ref back to status.json.
197
199
  Execution criteria: {session.execution_criteria joined by '; '}
198
200
  </goal_context>
199
201
  ```
200
- goal_snippet 时跳过此步。goal_context block 不替换 ralph next stdout 内容,仅在其前方拼接。
201
- 3. **Inline execution** — 按 stdout(含 goal_context 前置)执行;deferred_reading 按需 Read
202
+ 3. **Inline execution** stdout 执行;deferred_reading 按需 Read
202
203
  4. **Complete**:
203
- - `Bash("maestro ralph complete N --status DONE [--evidence <path>]")`
204
- - `Bash("maestro ralph complete N --status DONE_WITH_CONCERNS --concerns \"...\"")`
204
+ - `Bash("maestro ralph complete N --status DONE --summary \"...\" [--evidence <path>] [--decisions \"...\"] [--caveats \"...\"] [--deferred \"...\"]")`
205
+ - `Bash("maestro ralph complete N --status DONE_WITH_CONCERNS --summary \"...\" --concerns \"...\"")`
205
206
  - `Bash("maestro ralph retry N")`
206
207
  - `Bash("maestro ralph complete N --status BLOCKED --reason \"...\"")`
208
+
209
+ | Param | 必填 | 格式 | 示例 |
210
+ |-------|------|------|------|
211
+ | `--summary` | MUST | 动词开头,≤100 字 | `"实现搜索 API 分页逻辑,新增 3 端点"` |
212
+ | `--decisions` | SHOULD(可多次) | 每条一个决策 | `"选择 ELK 布局而非 dagre"` |
213
+ | `--caveats` | SHOULD | 后续注意事项 | `"X 模块 e2e 暂未覆盖新端点"` |
214
+ | `--deferred` | SHOULD(可多次) | 推迟工作 | `"性能优化留到 review 后"` |
207
215
  5. **Propagate context signals** — 关键信号 (`PHASE: N` / `scratch_dir: path` / `BLP-xxx`) 写入 `status.json.context`
208
216
 
209
217
  完成后 S_LOCATE 触发 `Skill({ skill: "maestro-ralph-execute" })` 自调用。
@@ -282,8 +290,11 @@ Display: `[{index}/{total}] ✗ {step.skill} 失败,会话已暂停。/maestro
282
290
  - [ ] 自调用持续到全部 completion_confirmed 或 paused
283
291
  - [ ] --from auto-injection:phase-level plan step 运行时从 state.json 查找同 phase+milestone 最新 completed analyze artifact → 注入 `--from analyze:{id}`,写 `source_artifact_ref`
284
292
  - [ ] --from auto-injection:phase-level execute step 运行时查找同 phase+milestone 最新 completed plan artifact → 注入 `--dir`,写 `source_artifact_ref`
285
- - [ ] Goal context injection:step.goal_ref 非空时从 task_decomposition 提取 goal_snippet,A_EXEC_STEP ralph next stdout 顶部前置 `<goal_context>` block
293
+ - [ ] Goal context injection:`ralph_protocol_version < "2"` 前置 `<goal_context>` block;`>= "2"` skip(session_anchor 覆盖)
286
294
  - [ ] Goal context 包含 sub-goal description、done_when、boundary、evidence、execution_criteria
287
295
  - [ ] 已有 `--from` 或 `--dir` 的 step 不被 auto-injection 覆盖
296
+ - [ ] `--summary` 在 DONE/DONE_WITH_CONCERNS 时为 MUST(动词开头,≤100 字)
297
+ - [ ] `--decisions`/`--caveats`/`--deferred` 为 SHOULD;存在关键决策/注意事项/推迟工作时填写
298
+ - [ ] 结构化总结由 CLI 写入 status.json,session_anchor 自动聚合注入下游 step
288
299
 
289
300
  </appendix>