pi-maestro-flow 0.2.0 → 0.3.1

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 (235) hide show
  1. package/README.md +44 -72
  2. package/agents/cross-role-reviewer.md +1 -1
  3. package/agents/impeccable-agent.md +1 -1
  4. package/agents/ralph-executor.md +1 -1
  5. package/agents/team-worker.md +1 -1
  6. package/agents/workflow-analyzer.md +1 -1
  7. package/agents/workflow-codebase-mapper.md +1 -1
  8. package/agents/workflow-collab-planner.md +1 -1
  9. package/agents/workflow-debugger.md +1 -1
  10. package/agents/workflow-executor.md +1 -1
  11. package/agents/workflow-integration-checker.md +1 -1
  12. package/agents/workflow-nyquist-auditor.md +1 -1
  13. package/agents/workflow-phase-researcher.md +1 -1
  14. package/agents/workflow-planner.md +1 -1
  15. package/agents/workflow-project-researcher.md +1 -1
  16. package/agents/workflow-reviewer.md +1 -1
  17. package/agents/workflow-verifier.md +1 -1
  18. package/package.json +18 -4
  19. package/skills/codify-to-knowhow/SKILL.md +1 -1
  20. package/skills/delegation-check/SKILL.md +1 -1
  21. package/skills/domain-add/SKILL.md +5 -5
  22. package/skills/insight-challenge/SKILL.md +1 -1
  23. package/skills/learn-decompose/SKILL.md +4 -4
  24. package/skills/learn-follow/SKILL.md +5 -5
  25. package/skills/learn-investigate/SKILL.md +5 -5
  26. package/skills/learn-second-opinion/SKILL.md +5 -5
  27. package/skills/maestro/SKILL.md +8 -8
  28. package/skills/maestro-amend/SKILL.md +4 -4
  29. package/skills/maestro-analyze/SKILL.md +9 -9
  30. package/skills/maestro-blueprint/SKILL.md +7 -7
  31. package/skills/maestro-brainstorm/SKILL.md +10 -10
  32. package/skills/maestro-collab/SKILL.md +4 -4
  33. package/skills/maestro-companion/SKILL.md +3 -3
  34. package/skills/maestro-composer/SKILL.md +10 -10
  35. package/skills/maestro-execute/SKILL.md +8 -8
  36. package/skills/maestro-fork/SKILL.md +7 -7
  37. package/skills/maestro-grill/SKILL.md +12 -12
  38. package/skills/maestro-guard/SKILL.md +5 -5
  39. package/skills/maestro-help/SKILL.md +3 -3
  40. package/skills/maestro-impeccable/SKILL.md +7 -7
  41. package/skills/maestro-init/SKILL.md +8 -8
  42. package/skills/maestro-merge/SKILL.md +6 -6
  43. package/skills/maestro-milestone-audit/SKILL.md +3 -3
  44. package/skills/maestro-milestone-complete/SKILL.md +8 -8
  45. package/skills/maestro-milestone-release/SKILL.md +9 -9
  46. package/skills/maestro-next/SKILL.md +5 -5
  47. package/skills/maestro-overlay/SKILL.md +19 -19
  48. package/skills/maestro-plan/SKILL.md +8 -8
  49. package/skills/maestro-player/SKILL.md +5 -5
  50. package/skills/maestro-quick/SKILL.md +5 -5
  51. package/skills/maestro-ralph/SKILL.md +15 -15
  52. package/skills/maestro-ralph-cli/SKILL.md +6 -6
  53. package/skills/maestro-ralph-cli-execute/SKILL.md +2 -2
  54. package/skills/maestro-ralph-execute/SKILL.md +4 -4
  55. package/skills/maestro-ralph-v2/SKILL.md +17 -17
  56. package/skills/maestro-roadmap/SKILL.md +7 -7
  57. package/skills/maestro-swarm-workflow/SKILL.md +9 -9
  58. package/skills/maestro-tools-execute/SKILL.md +5 -5
  59. package/skills/maestro-tools-register/SKILL.md +7 -7
  60. package/skills/maestro-ui-codify/SKILL.md +8 -8
  61. package/skills/maestro-universal-workflow/SKILL.md +15 -15
  62. package/skills/maestro-update/SKILL.md +10 -10
  63. package/skills/manage-codebase-rebuild/SKILL.md +4 -4
  64. package/skills/manage-drift-realign/SKILL.md +7 -7
  65. package/skills/manage-harvest/SKILL.md +5 -5
  66. package/skills/manage-issue/SKILL.md +4 -4
  67. package/skills/manage-issue-discover/SKILL.md +7 -7
  68. package/skills/manage-kg-extractors/SKILL.md +3 -3
  69. package/skills/manage-knowhow/SKILL.md +3 -3
  70. package/skills/manage-knowhow-capture/SKILL.md +4 -4
  71. package/skills/manage-knowledge-audit/SKILL.md +5 -5
  72. package/skills/manage-status/SKILL.md +3 -3
  73. package/skills/manage-wiki/SKILL.md +5 -5
  74. package/skills/odyssey-debug/SKILL.md +13 -13
  75. package/skills/odyssey-improve/SKILL.md +15 -15
  76. package/skills/odyssey-planex/SKILL.md +16 -16
  77. package/skills/odyssey-review-test-fix/SKILL.md +11 -11
  78. package/skills/odyssey-ui/SKILL.md +10 -10
  79. package/skills/prompt-generator/SKILL.md +5 -5
  80. package/skills/quality-auto-test/SKILL.md +3 -3
  81. package/skills/quality-debug/SKILL.md +3 -3
  82. package/skills/quality-refactor/SKILL.md +3 -3
  83. package/skills/quality-retrospective/SKILL.md +9 -9
  84. package/skills/quality-review/SKILL.md +4 -4
  85. package/skills/quality-sync/SKILL.md +3 -3
  86. package/skills/quality-test/SKILL.md +4 -4
  87. package/skills/scholar-anti-ai-writing/SKILL.md +1 -1
  88. package/skills/scholar-citation-verify/SKILL.md +1 -1
  89. package/skills/scholar-experiment/SKILL.md +2 -2
  90. package/skills/scholar-ideation/SKILL.md +7 -7
  91. package/skills/scholar-latex-organizer/SKILL.md +1 -1
  92. package/skills/scholar-publish/SKILL.md +3 -3
  93. package/skills/scholar-rebuttal-pro/SKILL.md +3 -3
  94. package/skills/scholar-review/SKILL.md +1 -1
  95. package/skills/scholar-writing/SKILL.md +1 -1
  96. package/skills/security-audit/SKILL.md +2 -2
  97. package/skills/skill-generator/SKILL.md +3 -3
  98. package/skills/skill-iter-tune/SKILL.md +3 -3
  99. package/skills/skill-simplify/SKILL.md +1 -1
  100. package/skills/skill-tuning/SKILL.md +1 -1
  101. package/skills/spec-add/SKILL.md +5 -5
  102. package/skills/spec-load/SKILL.md +3 -3
  103. package/skills/spec-remove/SKILL.md +4 -4
  104. package/skills/spec-setup/SKILL.md +6 -6
  105. package/skills/team-adversarial-swarm/SKILL.md +5 -5
  106. package/skills/team-arch-opt/SKILL.md +2 -2
  107. package/skills/team-brainstorm/SKILL.md +3 -3
  108. package/skills/team-coordinate/SKILL.md +4 -4
  109. package/skills/team-designer/SKILL.md +1 -1
  110. package/skills/team-executor/SKILL.md +3 -3
  111. package/skills/team-frontend/SKILL.md +2 -2
  112. package/skills/team-frontend-debug/SKILL.md +3 -3
  113. package/skills/team-interactive-craft/SKILL.md +2 -2
  114. package/skills/team-issue/SKILL.md +3 -3
  115. package/skills/team-lifecycle-v4/SKILL.md +4 -4
  116. package/skills/team-motion-design/SKILL.md +2 -2
  117. package/skills/team-perf-opt/SKILL.md +3 -3
  118. package/skills/team-planex/SKILL.md +2 -2
  119. package/skills/team-quality-assurance/SKILL.md +3 -3
  120. package/skills/team-review/SKILL.md +3 -3
  121. package/skills/team-roadmap-dev/SKILL.md +3 -3
  122. package/skills/team-swarm/SKILL.md +4 -4
  123. package/skills/team-tech-debt/SKILL.md +2 -2
  124. package/skills/team-testing/SKILL.md +3 -3
  125. package/skills/team-ui-polish/SKILL.md +2 -2
  126. package/skills/team-uidesign/SKILL.md +2 -2
  127. package/skills/team-ultra-analyze/SKILL.md +4 -4
  128. package/skills/team-ux-improve/SKILL.md +3 -3
  129. package/skills/team-visual-a11y/SKILL.md +2 -2
  130. package/skills/workflow-skill-designer/SKILL.md +8 -8
  131. package/templates/business-test-report.json +68 -0
  132. package/templates/config.json +48 -0
  133. package/templates/context.md +16 -0
  134. package/templates/doc-index.json +11 -0
  135. package/templates/index.json +68 -0
  136. package/templates/issue.json +36 -0
  137. package/templates/plan.json +38 -0
  138. package/templates/project.md +60 -0
  139. package/templates/reflection-log.md +20 -0
  140. package/templates/roadmap.md +45 -0
  141. package/templates/scratch-index.json +19 -0
  142. package/templates/search-tool.json +1 -0
  143. package/templates/search-tools.md +47 -0
  144. package/templates/state.json +18 -0
  145. package/templates/task-summary.md +21 -0
  146. package/templates/task.json +89 -0
  147. package/templates/terminology-template.json +22 -0
  148. package/templates/uat.md +21 -0
  149. package/templates/validation.json +31 -0
  150. package/templates/verification.json +37 -0
  151. package/templates/workflow.md +14 -0
  152. package/templates/worktree-scope.json +9 -0
  153. package/templates/worktrees.json +26 -0
  154. package/workflows/agy-instructions.md +156 -0
  155. package/workflows/analyze.md +768 -0
  156. package/workflows/auto-test.md +705 -0
  157. package/workflows/blueprint.md +406 -0
  158. package/workflows/boundary-grill.md +50 -0
  159. package/workflows/brainstorm.md +508 -0
  160. package/workflows/business-test.md +574 -0
  161. package/workflows/chinese-response.md +25 -0
  162. package/workflows/claude-instructions.md +167 -0
  163. package/workflows/codebase-rebuild.md +267 -0
  164. package/workflows/codebase-refresh.md +168 -0
  165. package/workflows/codex-instructions.md +156 -0
  166. package/workflows/coding-philosophy.md +70 -0
  167. package/workflows/command-authoring.md +823 -0
  168. package/workflows/debug.md +409 -0
  169. package/workflows/delegate-usage.md +99 -0
  170. package/workflows/domain-add.md +121 -0
  171. package/workflows/drift-realign.md +396 -0
  172. package/workflows/execute.md +631 -0
  173. package/workflows/explore-usage.md +93 -0
  174. package/workflows/finish-work.md +124 -0
  175. package/workflows/fork.md +162 -0
  176. package/workflows/grill.md +494 -0
  177. package/workflows/harvest.md +478 -0
  178. package/workflows/impeccable.md +168 -0
  179. package/workflows/init.md +157 -0
  180. package/workflows/instruction-authoring-guide.md +97 -0
  181. package/workflows/integration-test.md +186 -0
  182. package/workflows/interview-mechanics.md +8 -0
  183. package/workflows/issue-analyze.md +20 -0
  184. package/workflows/issue-discover.md +238 -0
  185. package/workflows/issue-execute.md +110 -0
  186. package/workflows/issue-gaps-analyze.codex.md +256 -0
  187. package/workflows/issue-gaps-analyze.md +215 -0
  188. package/workflows/issue-plan.md +110 -0
  189. package/workflows/issue.md +338 -0
  190. package/workflows/knowhow.md +429 -0
  191. package/workflows/knowledge-audit.md +355 -0
  192. package/workflows/learn.md +271 -0
  193. package/workflows/maestro-chain-execute.md +20 -0
  194. package/workflows/maestro-link-coordinate.md +114 -0
  195. package/workflows/maestro-super.md +120 -0
  196. package/workflows/maestro.md +501 -0
  197. package/workflows/map.md +74 -0
  198. package/workflows/merge.md +122 -0
  199. package/workflows/milestone-audit.md +155 -0
  200. package/workflows/milestone-complete.md +167 -0
  201. package/workflows/milestone-release.md +82 -0
  202. package/workflows/odyssey-base-codex.md +305 -0
  203. package/workflows/odyssey-base.md +256 -0
  204. package/workflows/overlays.md +109 -0
  205. package/workflows/plan.md +520 -0
  206. package/workflows/quick.md +350 -0
  207. package/workflows/ralph-amend-goal.md +177 -0
  208. package/workflows/refactor.md +87 -0
  209. package/workflows/retrospective.md +471 -0
  210. package/workflows/review.md +448 -0
  211. package/workflows/roadmap-common.md +193 -0
  212. package/workflows/roadmap.md +106 -0
  213. package/workflows/shell-exec-protocol.md +30 -0
  214. package/workflows/skill-authoring.md +265 -0
  215. package/workflows/spec-generate.md +475 -0
  216. package/workflows/specs-add.md +123 -0
  217. package/workflows/specs-load.md +76 -0
  218. package/workflows/specs-remove.md +104 -0
  219. package/workflows/specs-setup.md +316 -0
  220. package/workflows/status.md +149 -0
  221. package/workflows/sync.md +116 -0
  222. package/workflows/tdd.md +255 -0
  223. package/workflows/test-gen.md +226 -0
  224. package/workflows/test.md +385 -0
  225. package/workflows/tools-spec.md +70 -0
  226. package/workflows/ui-codify-extract.md +372 -0
  227. package/workflows/ui-codify-knowhow.md +258 -0
  228. package/workflows/ui-codify-package.md +159 -0
  229. package/workflows/ui-codify.md +227 -0
  230. package/workflows/ui-design.md +393 -0
  231. package/workflows/ui-style.md +201 -0
  232. package/workflows/verify.md +557 -0
  233. package/workflows/wiki-connect.md +153 -0
  234. package/workflows/wiki-digest.md +180 -0
  235. package/workflows/wiki-manage.md +113 -0
@@ -0,0 +1,396 @@
1
+ # Drift Realign Workflow
2
+
3
+ ---
4
+
5
+ ## Prerequisites
6
+
7
+ - `.workflow/` 已初始化(`.workflow/state.json` 存在)
8
+ - Git 仓库可访问(`git log` 可执行)
9
+ - 至少一个 `.workflow/` artifact 存在
10
+ - REQUIRED: wiki indexed via `maestro wiki rebuild` (supports session association)
11
+
12
+
13
+ ---
14
+
15
+ ## Argument Shape
16
+
17
+ ```
18
+ /drift-realign --scope all → 全量扫描所有 scope(交互式)
19
+ /drift-realign --scope spec --since 2026-06-01 → 仅扫 spec 漂移,指定起始时间
20
+ /drift-realign --scope roadmap --depth deep → 深度扫描 roadmap
21
+ /drift-realign --scope all --dry-run → 完整预演,不写盘
22
+ /drift-realign --scope all --report → 仅出报告不动盘
23
+ /drift-realign --scope codebase --auto-archive → 自动归档 codebase 漂移
24
+ /drift-realign --scope all --interactive → 逐条交互决策
25
+ ```
26
+
27
+ | Flag | Effect |
28
+ |------|--------|
29
+ | `--scope <type>` | 目标 scope: roadmap / spec / codebase / state / issue / knowhow / project / all(默认 all) |
30
+ | `--since <date\|commit>` | 起始时间点(日期或 commit hash),覆盖自动推断 |
31
+ | `--depth <level>` | shallow(正则 + 路径校验)/ deep(LLM 语义分析),默认 shallow |
32
+ | `--dry-run` | 全流程预演,展示所有 findings 和建议 action,不写盘 |
33
+ | `--report` | 仅生成报告到 `.workflow/.drift-realign/`,跳过交互和 apply |
34
+ | `--auto-archive` | P1/P2 自动归档,P0 保留人工审查 |
35
+ | `--interactive` | 逐条交互决策(默认开启,除非 `--report` 或 `--auto-archive`)|
36
+
37
+ 互斥规则:`--report` 强制 read-only,覆盖其他 mode;`--auto-archive` 与 `--interactive` 互斥;`--auto-archive` 覆盖 `--interactive`。
38
+
39
+ ---
40
+
41
+ ## Stage 1: parse_input
42
+
43
+ ```
44
+ 验证 .workflow/ 存在(否则 E001)。解析参数:
45
+ scope: roadmap | spec | codebase | state | issue | knowhow | project | all(默认 all,E002 若非法值)
46
+ since: 显式指定 → 使用提供的日期/commit
47
+ state.json.last_drift_realign 存在 → 使用该值
48
+ state.json.last_pruned 存在 → 使用该值
49
+ 兜底 → 90 天前
50
+ depth: shallow(默认)| deep
51
+ mode: interactive(默认)| dry-run | report | auto-archive
52
+
53
+ 互斥校验:
54
+ --report → 强制覆盖 mode 为 read-only
55
+ --auto-archive 覆盖 --interactive(非错误,静默降级); flag session as [LOW CONFIDENCE] (interactive skipped)
56
+
57
+ 检查 git 可用性(E003)。
58
+ 初始化 .workflow/.drift-realign/ 目录。
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Stage 2: reconstruct_timeline
64
+
65
+ ```
66
+ 运行 maestro timeline --since <resolved_date> --json --output .workflow/.drift-realign/timeline-{date}.json
67
+
68
+ timeline 每条 session 事件包含以下字段(已足够 shallow 分析):
69
+ id: session 唯一标识
70
+ title: session 标题
71
+ summary: 用户首条提问摘要(≤200 字符)
72
+ edited_files: 该 session 编辑的文件列表
73
+ code_paths: 该 session 涉及的代码路径
74
+ platform: 平台标识(claude / codex / unknown)
75
+
76
+ 解析输出提取以下结构:
77
+ window: { from, to, total_days }
78
+ git_summary: { commit_count, files_changed, insertions, deletions }
79
+ session_summary: { total, with_edits, last_session_date, by_platform: { claude: N, codex: N, ... } }
80
+ events: 按时间戳排序的 commit + session 事件交织列表
81
+ hot_paths: 变更频率最高的目录列表(包含 git files + session edited_files + code_paths)
82
+ cold_workflow_files: 在窗口内未修改的 .workflow/ 文件列表
83
+ ```
84
+
85
+ ### 2a. 平台问询(交互式)
86
+
87
+ ```
88
+ 检查 session_summary.by_platform 分布。
89
+ 如果存在多个平台且 session 总量 > 20:
90
+ 使用 AskUserQuestion 向用户展示平台分布并询问:
91
+ "检测到多个 session 平台(claude: 80, codex: 40, unknown: 12)。
92
+ 修改主要在哪个平台进行?聚焦特定平台可以缩小分析范围。"
93
+ 选项:
94
+ - 全部平台(不过滤)
95
+ - Claude(仅 Claude Code session)
96
+ - Codex(仅 Codex session)
97
+
98
+ 如果用户选择特定平台:
99
+ 重新运行 maestro timeline --since <date> --platform <选择> --json --output ...
100
+ 后续 scanner agent 仅使用该平台的 session 上下文。
101
+ ```
102
+
103
+ ### 2b. Session 详情按需加载
104
+
105
+ ```
106
+ timeline 事件中的 summary + edited_files + code_paths 足以支撑 shallow 扫描。
107
+ 当 --depth deep 时,scanner agent 可能需要 session 完整内容来判断语义漂移:
108
+
109
+ 对于与 drifted .workflow/ 文件有交集的 session(edited_files 交集检测):
110
+ maestro load --type session --id <session_id> --json
111
+ → 获取 body(详细描述)、related(关联条目)等完整字段
112
+
113
+ 按需加载规则:
114
+ 1. 仅 --depth deep 时触发
115
+ 2. 仅加载 edited_files 与 cold_workflow_files 有交集的 session
116
+ 3. 最多加载 10 个 session(按相关度排序:交集文件数降序)
117
+ 4. 加载结果写入 .workflow/.drift-realign/session-details-{date}.json
118
+ 5. scanner agent 在 deep 模式下同时接收 timeline.json + session-details.json
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Stage 3: compute_drift_score
124
+
125
+ ```
126
+ 公式:drift_score = drift_window_days × sqrt(changed_files_count) × scope_weight
127
+
128
+ changed_files_count 来源:git_summary.files_changed + session 中 edited_files 去重后的独立文件数。
129
+ 合并公式:changed_files_count = |Set(git_files) ∪ Set(session_edited_files)|
130
+
131
+ scope_weight 映射:
132
+ roadmap: 1.5 (结构性,影响所有下游)
133
+ spec: 1.3 (影响编码指导)
134
+ project: 1.4 (基础性)
135
+ state: 1.2 (运行态)
136
+ codebase: 1.0 (文档)
137
+ issue: 0.8 (跟踪)
138
+ knowhow: 0.7 (参考)
139
+
140
+ 阈值判定:
141
+ LOW: score < 30 → 以 --depth shallow 继续
142
+ MODERATE: 30 ≤ score < 100 → 以配置的 depth 继续
143
+ SEVERE: score ≥ 100 → 自动升级为 --depth deep,若 drift_window > 180 天则 emit W002
144
+
145
+ 向用户展示 drift summary。
146
+ ```
147
+
148
+ ---
149
+
150
+ ## Stage 4: parallel_drift_scan
151
+
152
+ **MANDATORY, NOT SUBSTITUTABLE by manual Read/Grep: 在单条消息中并行派发 4 个 agent。每个 agent 接收 timeline.json + 相关 scope 文件 + git diff 摘要。**
153
+
154
+ ### 4a. roadmap-scanner
155
+
156
+ | Drift Type | Detection Algorithm | Severity |
157
+ |-----------|-------------------|----------|
158
+ | phantom_phase | roadmap.md 列出的 phase 在代码或 state.json 中无对应 | P0 |
159
+ | stale_progress | Phase Progress 表格百分比与实际 task 完成状态不符 | P1 |
160
+ | milestone_mismatch | state.json milestones 与 roadmap.md milestone 描述不一致 | P0 |
161
+ | outdated_criteria | 成功标准引用了已删除/重命名的 feature | P1 |
162
+ | dependency_ghost | 依赖引用指向已删除/重构的模块 | P1 |
163
+ | timeline_impossible | roadmap 中的日期已过期但 milestone 未标记完成 | P2 |
164
+
165
+ ### 4b. spec-scanner
166
+
167
+ | Drift Type | Detection Algorithm | Severity |
168
+ |-----------|-------------------|----------|
169
+ | convention_violation | Spec 规定 "使用 X 模式" 但 git diff 显示代码使用 Y 模式 | P0 |
170
+ | dead_import_pattern | Spec 引用的 import 风格在 codebase 中已不存在 | P1 |
171
+ | architecture_breach | 新代码结构违反了架构约束 | P0 |
172
+ | stale_dependency | Spec 提及的库版本/API 与 package.json 矛盾 | P1 |
173
+ | naming_drift | Spec 中的命名规范与 hot_paths 实际命名不匹配 | P2 |
174
+ | test_convention_gap | 测试规范 spec vs 实际测试文件模式 | P2 |
175
+
176
+ 检测方法:
177
+ - shallow:grep spec 引用的模式匹配 hot_paths 文件,检查文件是否存在
178
+ - deep:LLM 阅读 spec entry + hot_paths 代码采样,判断对齐度
179
+
180
+ ### 4c. codebase-scanner
181
+
182
+ | Drift Type | Detection Algorithm | Severity |
183
+ |-----------|-------------------|----------|
184
+ | architecture_outdated | architecture.md 描述的结构已被 git diff 改变 | P0 |
185
+ | feature_missing | features.md 未提及近期 commit 中可见的新 feature | P1 |
186
+ | tech_stack_changed | tech-stack.md 列出已移除的依赖或遗漏新增依赖 | P0 |
187
+ | concern_drift | concerns.md 描述的模式已不存在 | P1 |
188
+ | doc_index_stale | doc-index.json 引用的文件在磁盘上不存在 | P0 |
189
+
190
+ 检测方法:
191
+ - shallow:交叉校验 doc-index.json 路径与文件系统,检查文件 mtime
192
+ - deep:LLM 阅读每个 codebase 文档 + 采样近期代码,判断准确性
193
+
194
+ ### 4d. artifact-scanner
195
+
196
+ | Drift Type | Detection Algorithm | Severity |
197
+ |-----------|-------------------|----------|
198
+ | issue_code_ref_dead | issues.jsonl 的 related_files 指向已移动/删除的路径 | P1 |
199
+ | issue_stale_open | Open issue 的 fix_direction 引用了已重构的代码 | P1 |
200
+ | knowhow_code_ref_dead | Knowhow entry 引用的代码路径已不存在 | P1 |
201
+ | orphan_session | active/ 中的 session 在 state.json 中无对应 artifact | P2 |
202
+ | project_tech_drift | project.md Tech Stack 部分 vs 实际 package.json/code | P0 |
203
+ | project_req_drift | project.md Requirements 部分 vs 已实现的 feature | P1 |
204
+ | accumulated_stale | state.json accumulated_context.key_decisions 引用已重构区域 | P1 |
205
+ | deferred_resolved | state.json deferred items 实际已被 git 历史证明已实现 | P2 |
206
+
207
+ 每个 agent 返回:
208
+ ```
209
+ DriftFinding {
210
+ id: "DFT-{8hex}",
211
+ scope: "roadmap" | "spec" | "codebase" | "state" | "issue" | "knowhow" | "project",
212
+ severity: "P0" | "P1" | "P2",
213
+ target: { file: string, section?: string },
214
+ drift_type: string,
215
+ evidence: { code_reality: string, doc_claim: string, git_ref?: string },
216
+ suggested_action: "keep" | "update" | "archive" | "rebuild",
217
+ update_hint?: string
218
+ }
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Stage 5: synthesize_findings
224
+
225
+ ```
226
+ 合并所有 agent 结果为统一 DriftFinding[]。
227
+
228
+ 去重:若多个 agent 标记同一 file+section,保留最高 severity。
229
+ 排序:P0 优先,然后 P1,然后 P2。
230
+ 按 --scope 过滤(若非 "all")。
231
+ 按 scope 和 severity 统计计数。
232
+
233
+ Conflict-marker 集成:
234
+ MANDATORY, NOT SUBSTITUTABLE by manual Read/Grep: 运行 maestro spec conflict list → 已标记的冲突条目
235
+ 对于已有 conflict-marker 的 spec 条目,若 drift scanner 也检测到同一文件:
236
+ 合并为同一 finding(提升 severity 到 P0,来源标注 "drift + conflict-marker")
237
+ 对于 drift scanner 发现但无 conflict-marker 的条目:保持 scanner 原始 severity
238
+ ```
239
+
240
+ ---
241
+
242
+ ## Stage 6: interactive_triage
243
+
244
+ ```
245
+ 若 --report → 跳至 Stage 9。
246
+ 若 --auto-archive → 自动应用每个 finding 的 suggested_action(P1/P2 直接执行,P0 保留人工审查)。
247
+ 若 --dry-run → 展示所有 findings 及建议 action,跳过 Stage 7-8。
248
+
249
+ 否则,逐条交互:
250
+ ```
251
+
252
+ ```
253
+ [!] Drift Detected (P0 - architecture_outdated)
254
+ Scope: codebase
255
+ Target: .workflow/codebase/architecture.md §Module Boundaries
256
+ Evidence: Code added new src/payments/ module not described in architecture.md
257
+ Git Ref: commit abc123 (2026-06-10)
258
+ Hint: Add Payments module section describing src/payments/ structure
259
+ Suggestion: [u]pdate
260
+
261
+ Action? [k]eep / [u]pdate / [a]rchive / [r]ebuild / [s]kip / [q]uit
262
+ > _
263
+ ```
264
+
265
+ | Action | 行为 |
266
+ |--------|------|
267
+ | `keep` | 确认无漂移或可接受,标记为已审查(记录到 drift-log.jsonl action=keep)|
268
+ | `update` | 在目标文件顶部注入 TODO 标记:`<!-- DRIFT-TODO: {update_hint} (DFT-{id}, {date}) -->` |
269
+ | `archive` | 移动到 .trash/(先备份)|
270
+ | `rebuild` | 标记为自动重建目标(codebase scope 触发 `/quality-sync --full`)|
271
+ | `skip` | 跳过本条不做决策(记录到 drift-log.jsonl action=skipped,下次 re-run 会重新出现)|
272
+
273
+ ---
274
+
275
+ ## Stage 7: backup
276
+
277
+ ```
278
+ mkdir .workflow/.trash/drift-realign-{ISO_timestamp}/
279
+ for each actionable finding:
280
+ cp target.file → .trash/{timestamp}/{relative_path}
281
+ 也备份 state.json → .trash/{timestamp}/state.json.bak
282
+ 若任一备份失败 → E005,禁止 Stage 8
283
+ ```
284
+
285
+ ---
286
+
287
+ ## Stage 8: apply_actions
288
+
289
+ | Action | 实施 |
290
+ |--------|------|
291
+ | `keep` | 写 drift-log.jsonl 一条 action=keep 记录 |
292
+ | `skip` | 写 drift-log.jsonl 一条 action=skipped 记录(不标记 reviewed,下次 re-run 重现)|
293
+ | `update` | 在目标文件头部插入 TODO 注释块:`<!-- DRIFT-TODO: {update_hint} (DFT-{id}, {date}) -->` |
294
+ | `archive` | 移动文件到 `.trash/{timestamp}/` + 更新 state.json 引用 |
295
+ | `rebuild` | 收集 rebuild 目标;全部其他 action 完成后:通过 `Skill()` 自动调用 `/quality-sync --full` |
296
+
297
+ rebuild 后处理:
298
+ - 若 W001 或重大结构变更 → MUST run `/manage-codebase-rebuild`
299
+
300
+ Conflict-marker 清除:
301
+ - 对于 update/archive 的 spec 目标文件,若存在 conflict-marker:
302
+ maestro spec conflict clear <file> <line>
303
+ (与 knowledge-audit 的 deprecate/delete 清除行为对称)
304
+
305
+ 更新 state.json:设置 `last_drift_realign = now`(ISO-8601)
306
+
307
+ state.json 原子写:备份 → 写新版本 → re-read 验证。
308
+
309
+ ---
310
+
311
+ ## Stage 9: report
312
+
313
+ 写 `.workflow/.drift-realign/drift-report-{date}.md`:
314
+
315
+ ```markdown
316
+ # Drift Realign Report — {date}
317
+
318
+ ## Timeline Window
319
+ - From: {from} → To: {to} ({days} days)
320
+ - Git: {commits} commits, {files_changed} files changed
321
+ - Sessions: {total} total, {with_edits} with edits
322
+ - Drift Score: {score} ({LOW|MODERATE|SEVERE})
323
+
324
+ ## Scan Summary
325
+ - Total findings: {N} ({P0} P0 / {P1} P1 / {P2} P2)
326
+ - By scope: roadmap {N} / spec {N} / codebase {N} / state {N} / issue {N} / knowhow {N} / project {N}
327
+
328
+ ## Actions Applied
329
+ | # | Scope | Drift Type | Target | Action | Status |
330
+ |---|-------|-----------|--------|--------|--------|
331
+ | 1 | codebase | architecture_outdated | architecture.md §Module Boundaries | update | OK |
332
+ | 2 | spec | convention_violation | coding-conventions.md §Import Rules | archive | OK |
333
+
334
+ ## Kept (no drift or user chose keep)
335
+ | Finding | Reason |
336
+ |---------|--------|
337
+ | DFT-abc12345 | User chose keep — marked as reviewed |
338
+
339
+ ## Auto-Rebuilt
340
+ - /quality-sync --full triggered: {yes/no}
341
+ - /manage-codebase-rebuild suggested: {yes/no}
342
+
343
+ ## Backup
344
+ - Location: .workflow/.trash/drift-realign-{timestamp}/
345
+ ```
346
+
347
+ 同时追加结构化条目到 `.workflow/.drift-realign/drift-log.jsonl`(每行一条 JSON):
348
+
349
+ ```json
350
+ {
351
+ "realign_id": "DFT-RUN-{timestamp}",
352
+ "finding_id": "DFT-{8hex}",
353
+ "scope": "codebase",
354
+ "drift_type": "architecture_outdated",
355
+ "severity": "P0",
356
+ "target": { "file": ".workflow/codebase/architecture.md", "section": "Module Boundaries" },
357
+ "action": "update",
358
+ "applied_at": "2026-06-24T15:30:00.000Z",
359
+ "backup_path": ".workflow/.trash/drift-realign-20260624T153000/"
360
+ }
361
+ ```
362
+
363
+ 显示摘要并引导后续步骤:
364
+
365
+ ```
366
+ === DRIFT REALIGN COMPLETE ===
367
+ Scope: all
368
+
369
+ Findings: 18 total (4 P0 / 9 P1 / 5 P2)
370
+ Updated: 6 (TODO markers injected)
371
+ Archived: 3 (moved to .trash/)
372
+ Rebuilt: 2 (via /quality-sync --full)
373
+ Kept: 7 (marked as reviewed)
374
+
375
+ Report: .workflow/.drift-realign/drift-report-2026-06-24.md
376
+ Backup: .workflow/.trash/drift-realign-20260624T153000/
377
+
378
+ Next:
379
+ → 处理 TODO 标记: grep -r "DRIFT-TODO" .workflow/
380
+ → 内部矛盾审查: /manage-knowledge-audit --scope all
381
+ → 全量 codebase 重建: /manage-codebase-rebuild
382
+ → 周期巡检 (REQUIRED at milestone end): run --scope all --report
383
+ ```
384
+
385
+ ---
386
+
387
+ ### Safety invariants
388
+
389
+ 1. **Code-as-Truth** — 代码永远是对的;当代码和文档不一致时,是文档漂移了
390
+ 2. **Backup before mutate** — Stage 7 必须成功才能执行 Stage 8;state.json 原子写(备份 → 写新 → re-read 校验)
391
+ 3. **No auto-delete** — drift-realign 绝不物理删除文件;archive 仅移动到 `.trash/`
392
+ 4. **Rebuild is scoped** — 自动重建仅对 codebase scope 触发,绝不对 spec/roadmap 触发
393
+ 5. **Idempotent** — 相同输入产生相同 findings(git 状态 + 文件状态确定性)
394
+ 6. **Graceful degradation** — wiki/session 不可用时(W001),以 git-only timeline 继续; flag timeline as [LOW CONFIDENCE] (wiki/session unavailable)
395
+ 7. **Preserve user work** — TODO 标记是注释,绝不覆盖文件内容
396
+ 8. **State.json atomic** — 所有 state.json 变更遵循 备份 → 写新 → 验证 模式