intentdna 1.7.5 → 1.8.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.
Files changed (152) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/LICENSE +201 -0
  4. package/README.md +143 -194
  5. package/dist/assets/candidates.d.ts +124 -0
  6. package/dist/assets/candidates.js +1249 -0
  7. package/dist/assets/catalog.d.ts +101 -0
  8. package/dist/assets/catalog.js +311 -0
  9. package/dist/assets/evidence.d.ts +93 -0
  10. package/dist/assets/evidence.js +391 -0
  11. package/dist/assets/index.d.ts +4 -0
  12. package/dist/assets/index.js +4 -0
  13. package/dist/assets/metadata.d.ts +19 -0
  14. package/dist/assets/metadata.js +227 -0
  15. package/dist/cli/commands/assets.d.ts +65 -0
  16. package/dist/cli/commands/assets.js +2871 -0
  17. package/dist/cli/commands/auth.d.ts +322 -0
  18. package/dist/cli/commands/auth.js +1592 -0
  19. package/dist/cli/commands/cloud-auth-guidance.d.ts +2 -0
  20. package/dist/cli/commands/cloud-auth-guidance.js +4 -0
  21. package/dist/cli/commands/cloud.d.ts +1359 -0
  22. package/dist/cli/commands/cloud.js +8364 -0
  23. package/dist/cli/commands/evolve.js +18 -2
  24. package/dist/cli/commands/generate.js +25 -2
  25. package/dist/cli/commands/guard.d.ts +1 -1
  26. package/dist/cli/commands/guard.js +1 -1
  27. package/dist/cli/commands/guide.d.ts +15 -0
  28. package/dist/cli/commands/guide.js +1747 -0
  29. package/dist/cli/commands/init.d.ts +12 -0
  30. package/dist/cli/commands/init.js +95 -60
  31. package/dist/cli/commands/org.d.ts +16 -0
  32. package/dist/cli/commands/org.js +2393 -0
  33. package/dist/cli/commands/release.d.ts +59 -0
  34. package/dist/cli/commands/release.js +716 -0
  35. package/dist/cli/commands/report.d.ts +82 -0
  36. package/dist/cli/commands/report.js +1516 -0
  37. package/dist/cli/commands/run.d.ts +6 -1
  38. package/dist/cli/commands/run.js +95 -26
  39. package/dist/cli/commands/sync.d.ts +8 -1
  40. package/dist/cli/commands/sync.js +436 -141
  41. package/dist/cli/commands/templates.d.ts +64 -0
  42. package/dist/cli/commands/templates.js +2151 -1
  43. package/dist/cli/commands/workflow.d.ts +26 -0
  44. package/dist/cli/commands/workflow.js +3053 -0
  45. package/dist/cli/index.js +703 -36
  46. package/dist/compiler/cascade.js +4 -9
  47. package/dist/compiler/compile.js +1 -0
  48. package/dist/governance/evidence-capture-attribution.d.ts +12 -0
  49. package/dist/governance/evidence-capture-attribution.js +46 -0
  50. package/dist/governance/index.d.ts +2 -0
  51. package/dist/governance/index.js +1 -0
  52. package/dist/hooks/cli.d.ts +5 -0
  53. package/dist/hooks/cli.js +149 -5
  54. package/dist/hooks/enforce.d.ts +1 -0
  55. package/dist/hooks/protocol.d.ts +1 -1
  56. package/dist/hooks/protocol.js +1 -1
  57. package/dist/hooks/state.d.ts +41 -0
  58. package/dist/hooks/state.js +126 -2
  59. package/dist/index.d.ts +3 -0
  60. package/dist/index.js +3 -0
  61. package/dist/mcp/tools-state.js +2 -0
  62. package/dist/organization/index.d.ts +121 -0
  63. package/dist/organization/index.js +413 -0
  64. package/dist/runtime/claude-sync-target.d.ts +49 -0
  65. package/dist/runtime/claude-sync-target.js +280 -0
  66. package/dist/runtime/codex-adapter.d.ts +254 -0
  67. package/dist/runtime/codex-adapter.js +1204 -0
  68. package/dist/runtime/codex-sync-target.d.ts +33 -0
  69. package/dist/runtime/codex-sync-target.js +241 -0
  70. package/dist/runtime/index.d.ts +8 -0
  71. package/dist/runtime/index.js +4 -0
  72. package/dist/runtime/output-artifact-registry.d.ts +1 -1
  73. package/dist/runtime/output-artifact-registry.js +2 -0
  74. package/dist/runtime/settings-adapter.d.ts +1 -1
  75. package/dist/runtime/settings-adapter.js +1 -1
  76. package/dist/runtime/skill-adapter.d.ts +5 -1
  77. package/dist/runtime/skill-adapter.js +120 -34
  78. package/dist/runtime/sync-artifact-registry.d.ts +99 -0
  79. package/dist/runtime/sync-artifact-registry.js +194 -0
  80. package/dist/runtime/sync-target-plan.d.ts +45 -0
  81. package/dist/runtime/sync-target-plan.js +19 -0
  82. package/dist/schema/controller-registry.d.ts +8 -1
  83. package/dist/schema/controller-registry.js +8 -0
  84. package/dist/schema/types.d.ts +35 -23
  85. package/dist/schema/types.js +10 -1
  86. package/dist/schema/validate.js +22 -22
  87. package/dist/schema/validators/controllers.js +38 -20
  88. package/dist/schema/workflow-authoring-contract.d.ts +29 -0
  89. package/dist/schema/workflow-authoring-contract.js +109 -0
  90. package/dist/schema/yaml-parser.js +18 -0
  91. package/dist/templates/api-backend.dna.yaml +19 -0
  92. package/dist/templates/brainstorming-first.dna.yaml +19 -0
  93. package/dist/templates/code-cleanup.dna.yaml +19 -0
  94. package/dist/templates/code-review-pipeline.dna.yaml +18 -0
  95. package/dist/templates/documentation-writer.dna.yaml +19 -0
  96. package/dist/templates/flutter-behavior-lock.dna.yaml +19 -0
  97. package/dist/templates/flutter-refactoring-rescue.dna.yaml +19 -0
  98. package/dist/templates/flutter-rewrite-diagnosis-review.dna.yaml +210 -0
  99. package/dist/templates/flutter-rewrite-fix-review-loop.dna.yaml +260 -0
  100. package/dist/templates/flutter-rewrite-new.dna.yaml +506 -0
  101. package/dist/templates/flutter-rewrite.dna.yaml +20 -0
  102. package/dist/templates/frontend-quality.dna.yaml +19 -0
  103. package/dist/templates/full-pipeline.dna.yaml +20 -0
  104. package/dist/templates/marketplace.d.ts +92 -0
  105. package/dist/templates/marketplace.js +502 -0
  106. package/dist/templates/metadata.d.ts +25 -0
  107. package/dist/templates/metadata.js +136 -3
  108. package/dist/templates/mobile-dev.dna.yaml +19 -0
  109. package/dist/templates/multi-agent-handoff-coordination.dna.yaml +156 -0
  110. package/dist/templates/multi-perspective-review.dna.yaml +19 -0
  111. package/dist/templates/persistent-executor.dna.yaml +19 -0
  112. package/dist/templates/qa-loop.dna.yaml +18 -0
  113. package/dist/templates/release-evidence-gate.dna.yaml +131 -0
  114. package/dist/templates/requirements-gate.dna.yaml +19 -0
  115. package/dist/templates/research-orchestration.dna.yaml +19 -0
  116. package/dist/templates/root-cause-analysis.dna.yaml +19 -0
  117. package/dist/templates/safe-refactoring.dna.yaml +321 -0
  118. package/dist/templates/secure-dev.dna.yaml +19 -0
  119. package/dist/templates/subagent-parallel.dna.yaml +19 -0
  120. package/dist/templates/systematic-debugging.dna.yaml +19 -0
  121. package/dist/templates/tdd-strict.dna.yaml +19 -0
  122. package/dist/templates/ui-visual-regression-qa.dna.yaml +133 -0
  123. package/dist/templates/workflow-author.dna.yaml +302 -0
  124. package/dist/templates/workflow-blocked-scope-triage.dna.yaml +242 -0
  125. package/dist/templates/workflow-completion-audit.dna.yaml +254 -0
  126. package/dist/templates/workflow-cross-boundary-resource-approval.dna.yaml +249 -0
  127. package/dist/templates/workflow-evidence-review.dna.yaml +198 -0
  128. package/dist/templates/workflow-module-inventory.dna.yaml +257 -0
  129. package/dist/templates/workflow-runtime-smoke-review.dna.yaml +252 -0
  130. package/dist/templates/workflow-verification-command-routing.dna.yaml +278 -0
  131. package/dist/workflow/authoring-packet.d.ts +67 -0
  132. package/dist/workflow/authoring-packet.js +218 -0
  133. package/dist/workflow/draft.d.ts +159 -0
  134. package/dist/workflow/draft.js +800 -0
  135. package/dist/workflow/index.d.ts +3 -0
  136. package/dist/workflow/index.js +3 -0
  137. package/dist/workflow/suggestion-review.d.ts +65 -0
  138. package/dist/workflow/suggestion-review.js +245 -0
  139. package/package.json +1 -1
  140. package/spec/README.md +15 -48
  141. package/spec/codex-adapter-contract.md +176 -0
  142. package/spec/sync-target-plan.md +158 -0
  143. package/spec/workflow-capability-ir.md +153 -0
  144. package/spec/agent-dispatch-fix.md +0 -116
  145. package/spec/control-plane-convergence-handoff-2026-04-24.md +0 -432
  146. package/spec/flutter-rewrite-template-optimization.md +0 -301
  147. package/spec/foundation-hardening.md +0 -178
  148. package/spec/hooks-infra-harness-hardening.md +0 -741
  149. package/spec/multi-config.md +0 -172
  150. package/spec/parallel-isolation.md +0 -268
  151. package/spec/template-version-namespace-fix.md +0 -653
  152. package/spec/workflow-pipeline.md +0 -101
@@ -1,301 +0,0 @@
1
- # Spec: flutter-rewrite 模板优化
2
-
3
- ## 最终目标
4
-
5
- **把 v1 (GetX) 重写为 v2 (Riverpod),行为完全一致。**
6
-
7
- - behavior-lock: 写测试 = 定义"v1 的行为是什么"
8
- - rescue: 写代码让测试通过 = "v2 的行为和 v1 一样"
9
- - 完成标志: 所有测试 green = 重写成功,行为完全一致
10
-
11
- 所有设计决策必须服务于这个目标。timeout 是安全网(防卡死),不是解法。挂死的测试意味着行为没被验证——rescue 必须修复它们,不能跳过。
12
-
13
- ## 问题
14
-
15
- flutter-rewrite 模板的 behavior-lock 和 rescue 工作流都有设计缺陷,导致:
16
- 1. behavior-lock 不区分首次和重跑,首次跑测试浪费时间
17
- 2. rescue 没有 code review 和 verify 步骤,surgeon 自己写自己审
18
- 3. 没有回归检查、收敛保护、diff 审查
19
-
20
- 参考 OMC agent 设计(code-reviewer/verifier/executor/test-engineer)改进。
21
-
22
- ---
23
-
24
- ## 一、behavior-lock 优化
25
-
26
- ### 场景检测
27
-
28
- ```
29
- 检查 {{test_path}}/$ARGUMENTS/ 是否已有测试文件
30
- 检查 {{behavior_docs}}/$ARGUMENTS.md 是否已存在
31
-
32
- 两者都不存在 → 场景 1(首次)
33
- 至少一个存在 → 场景 2(重跑/增量)
34
- ```
35
-
36
- ### 场景 1: 首次
37
-
38
- ```
39
- scan → 全量扫描 v1,输出完整行为文档
40
- write → 写测试文件 → `flutter analyze` 验证编译 → 不跑 flutter test
41
- commit: "behavior-lock($MODULE): N tests (fresh, not yet runnable)"
42
- ```
43
-
44
- ### 场景 2: 重跑/增量
45
-
46
- ```
47
- scan → 读已有行为文档,对比 v1 变化,输出增量 diff
48
- write → 增量更新测试(不全量重写)→ `flutter test` 无超时 → 记录 baseline
49
- commit: "behavior-lock($MODULE): N tests (X green, Y red from behavior change)"
50
- ```
51
-
52
- ### scanner 增量
53
-
54
- 场景 2 时 scanner 不重写行为文档,而是:
55
- 1. 读已有 behavior doc
56
- 2. 对比 v1 源码变化
57
- 3. 增量更新
58
- 4. 输出 diff 摘要
59
-
60
- ### 超时策略
61
-
62
- | 操作 | 允许? | 原因 |
63
- |------|--------|------|
64
- | `flutter test --timeout 30s` | **允许** | per-test 安全网,挂死标 fail 继续下一个 |
65
- | `timeout Nm flutter test` | 禁止 | 外部杀进程,丢失所有结果 |
66
- | `sleep N && check` 轮询 | 禁止 | 浪费时间 |
67
- | 全量重写已有测试 | 禁止 | 丢失 rescue 成果 |
68
- | 首次跑 `flutter test` | 禁止 | 没实现,编译不过,用 `flutter analyze` |
69
-
70
- **挂死的测试分类**:标记为 `hung: needs mock infrastructure`,不是 `failed`。区别:
71
- - `failed` = 行为不一致,rescue 修 v2 代码
72
- - `hung` = mock 不完整,rescue 先修测试基础设施
73
-
74
- ---
75
-
76
- ## 二、rescue 优化
77
-
78
- ### 当前流程(缺陷)
79
-
80
- ```
81
- investigate → fix → report → 重复
82
- ↑ 无人审查
83
- ↑ 无回归检查
84
- ↑ 无收敛保护
85
- ```
86
-
87
- ### 优化后流程
88
-
89
- ```
90
- investigate → fix → review → verify → report
91
- ↑ 只读审查 diff ↑ 自己跑测试+回归
92
- ```
93
-
94
- ### 新增: review 步骤(参考 OMC code-reviewer)
95
-
96
- ```yaml
97
- - id: review
98
- role: investigator # read-only,不能改代码
99
- depends_on: [fix]
100
- prompt: |
101
- Review surgeon's changes (git diff):
102
- 1. 改动是否最小化?有没有改不该改的文件?
103
- 2. 是否匹配 v2 代码风格(Riverpod, GoRouter)?
104
- 3. mock 是否正确(不是为了让测试过而写假 mock)?
105
- 4. 有没有引入新问题?
106
-
107
- Verdict: APPROVE / REQUEST_CHANGES
108
- 如果 REQUEST_CHANGES → 说明具体问题,下轮 investigate 带上 review 意见
109
- ```
110
-
111
- ### 新增: verify 步骤(参考 OMC verifier)
112
-
113
- ```yaml
114
- - id: verify
115
- role: investigator # read-only
116
- depends_on: [review] # review APPROVE 后才 verify
117
- prompt: |
118
- 自己跑测试验证(不信任 surgeon 的报告):
119
- 1. flutter test {{test_path}}/$ARGUMENTS/ (当前模块,无超时)
120
- 2. flutter test 核心模块(回归检查)
121
- 3. flutter analyze(编译检查)
122
-
123
- 每个 acceptance criterion: VERIFIED / PARTIAL / MISSING
124
- Verdict: PASS / FAIL
125
- ```
126
-
127
- ### surgeon 加约束(参考 OMC executor)
128
-
129
- ```yaml
130
- surgeon:
131
- instructions:
132
- # 现有的保留,新增:
133
- - 每次 fix 前先 `git diff` 确认上轮改动范围
134
- - 每个文件改动后跑 `flutter analyze`
135
- - 单轮最多改 5 个文件,超过说明范围太大需要拆分
136
- - 同一问题失败 3 次 → 停止,报告卡点,不要无限重试
137
- - commit message 必须包含:改了什么、为什么、对应哪个测试
138
- - 不引入新抽象,不重构不相关代码
139
- ```
140
-
141
- ### investigator 加约束
142
-
143
- ```yaml
144
- investigator:
145
- instructions:
146
- # 现有的保留,新增:
147
- - 非首轮:先 review 上轮 git diff,判断方向是否正确
148
- - 如果上轮 fix 没有让任何测试从 red→green,警告"无进展"
149
- - 分类时标注严重度和类型:
150
- CRITICAL: 编译错误(阻塞一切)
151
- HIGH-INFRA: mock 不完整导致 test hang(阻塞行为验证,rescue 优先修)
152
- HIGH-LOGIC: 逻辑测试 fail(行为不一致)
153
- MEDIUM: widget 测试 fail(渲染/导航差异)
154
- LOW: 样式差异
155
- - hung 测试 ≠ failed 测试。hung = mock 基础设施问题,不是 v2 行为问题
156
- ```
157
-
158
- ### 收敛保护
159
-
160
- ```yaml
161
- rescue:
162
- max_rounds: 10
163
- convergence_rule: |
164
- 连续 2 轮无测试进展(green 数没增加)→ 停止
165
- 输出卡点分析 + 剩余问题清单
166
- round_budget: |
167
- 每轮最多改 5 个文件
168
- 每轮必须让至少 1 个测试从 red/skip/hung → green,否则视为无进展
169
- priority_order: |
170
- Phase 1: 修 CRITICAL(编译错误)
171
- Phase 2: 修 HIGH-INFRA(mock 基础设施,让 hung 测试能跑)
172
- Phase 3: 修 HIGH-LOGIC(逻辑测试,让 red 变 green)
173
- Phase 4: 修 MEDIUM(widget 测试,让 red 变 green)
174
- 每个 phase 完成后才进入下一个
175
- ```
176
-
177
- **为什么 HIGH-INFRA 优先于 HIGH-LOGIC?**
178
-
179
- hung 的测试 = 行为没被验证 = 重写目标的盲区。如果跳过 mock 修复直接改逻辑,可能 20 个 widget 行为从来没被检验过。先让所有测试能跑(pass 或 fail),再让它们变绿。
180
-
181
- ### 完整 rescue workflow
182
-
183
- ```yaml
184
- rescue:
185
- name: Rescue
186
- max_rounds: 10
187
- steps:
188
- - id: investigate
189
- role: investigator
190
- prompt: |
191
- Round context:
192
- - If round > 1: review previous round's git diff first
193
- - If previous round had 0 progress: warn and consider changing approach
194
-
195
- Run tests, categorize by severity:
196
- CRITICAL: compile errors, import failures
197
- HIGH: logic test failures (state/notifier)
198
- LOW: widget test failures (rendering/navigation)
199
-
200
- Pick highest severity batch. Trace v1 vs v2. Report breakpoints.
201
-
202
- - id: fix
203
- role: surgeon
204
- depends_on: [investigate]
205
- checkpoints:
206
- - assert: clean_working_tree
207
- prompt: |
208
- Fix identified breakpoints. Rules:
209
- - Read v1 intent, rewrite in v2 style (not copy v1 verbatim)
210
- - Maximum 5 files per round
211
- - flutter analyze after each file change
212
- - Same issue failed 3 times → STOP, report as blocked
213
- - Commit: rescue($ARGUMENTS): round N — what changed and why
214
-
215
- - id: review
216
- role: investigator
217
- depends_on: [fix]
218
- prompt: |
219
- Review surgeon's git diff (read-only):
220
- 1. Changes minimal? No unnecessary files touched?
221
- 2. Matches v2 patterns (Riverpod, GoRouter)?
222
- 3. Mocks correct (not faked to pass)?
223
- 4. No new issues introduced?
224
- Verdict: APPROVE → proceed to verify
225
- Verdict: REQUEST_CHANGES → next round investigate includes review feedback
226
-
227
- - id: verify
228
- role: investigator
229
- depends_on: [review]
230
- prompt: |
231
- Run independently (don't trust surgeon's results):
232
- 1. flutter test {{test_path}}/$ARGUMENTS/ (no timeout)
233
- 2. flutter analyze
234
- 3. Check: any regression in core tests?
235
- Record delta vs last round. PASS or FAIL.
236
-
237
- - id: report
238
- role: investigator
239
- depends_on: [verify]
240
- prompt: |
241
- Summary:
242
- 1. Test delta: +N green, -M red, ±K skipped
243
- 2. Remaining by category (logic vs widget vs platform)
244
- 3. Convergence: are we making progress?
245
- 4. If 2 rounds no progress → STOP, output blocked items
246
- 5. If all green → "Module $ARGUMENTS rescue complete"
247
- 6. Otherwise → "Run /rescue $ARGUMENTS to continue"
248
- ```
249
-
250
- ---
251
-
252
- ## 三、全局规则(两个工作流共享)
253
-
254
- ### DNA gene 层面
255
-
256
- ```yaml
257
- genes:
258
- # 现有 preserve_behavior 等保留,新增:
259
- minimal_change:
260
- description: Each fix should be the smallest possible change
261
- codons:
262
- - type: attract
263
- target: single_file_change
264
- - type: repel
265
- target: unnecessary_refactoring
266
- - type: threshold
267
- condition: "files_changed_per_round <= 5"
268
- action: escalate
269
-
270
- evidence_based:
271
- description: All completion claims require fresh test evidence
272
- codons:
273
- - type: attract
274
- target: run_tests_before_claiming_done
275
- - type: repel
276
- target: trust_without_evidence
277
- ```
278
-
279
- ---
280
-
281
- ## Acceptance Criteria
282
-
283
- ### behavior-lock
284
- - [ ] 场景检测正确(首次 vs 重跑)
285
- - [ ] 首次: 只 analyze,不 test
286
- - [ ] 重跑: 增量更新测试,不全量重写
287
- - [ ] 重跑: 跑测试无超时
288
- - [ ] scanner 增量: 输出 diff 而非全量重写
289
- - [ ] 禁止 sleep 轮询模式
290
-
291
- ### rescue
292
- - [ ] review 步骤: investigator 审查 surgeon 的 git diff
293
- - [ ] verify 步骤: 独立跑测试 + 回归检查
294
- - [ ] surgeon 约束: 最多 5 文件/轮,3 次失败停止
295
- - [ ] 收敛保护: 2 轮无进展 → 停止
296
- - [ ] 轮次上限: 最多 10 轮
297
- - [ ] report 包含收敛判断
298
-
299
- ### 全局
300
- - [ ] minimal_change gene 编译到 IR
301
- - [ ] evidence_based gene 编译到 IR
@@ -1,178 +0,0 @@
1
- # Spec: DNA 基础设施加固
2
-
3
- ## Metadata
4
- - Interview: 5 rounds, final ambiguity 20%
5
- - Date: 2026-04-15
6
- - Status: 设计完成
7
-
8
- ## Goal
9
-
10
- 全面审视 DNA 基础设施的薄弱点,从可靠性 → 治理能力 → 工具体验三个维度加固,对标 OMC 补齐差距,为组织级治理奠基。
11
-
12
- ## 成功标准
13
-
14
- - 零已知缺陷
15
- - 关键路径测试覆盖 >90%
16
- - 可交付给他人使用(不需要作者盯着)
17
- - 架构可扩展(后续治理功能不需要重构基础)
18
-
19
- ## 优先级: 可靠性 → 治理能力 → 工具体验
20
-
21
- ---
22
-
23
- ## 第一阶段: 可靠性加固
24
-
25
- ### R1: Config 编译前验证
26
-
27
- **问题**: `dna compile` 绕过 `validateDNA()`,无效 DNA 静默编译。
28
-
29
- **修复**: sync/compile 入口统一调用 `validateDNA()`,验证失败 → 报错退出。
30
-
31
- ### R2: Trace 并发安全
32
-
33
- **问题**: 多 session 同时 `appendFile` 写 trace.jsonl,可能 corrupt。
34
-
35
- **修复**:
36
- - 方案 A: trace 文件按 session 隔离 → `trace-{date}-{sessionId}.jsonl`
37
- - 方案 B: 使用 `O_APPEND` 原子追加(POSIX 保证 ≤ PIPE_BUF 的 write 原子性)
38
- - 推荐 A(简单、和 OMC 一致)
39
-
40
- ### R3: IR 版本迁移
41
-
42
- **问题**: `ir_version` 字段存在但无迁移逻辑。破坏性 IR 变更让旧 hook 静默失败。
43
-
44
- **修复**:
45
- - dna-hook 检测 `ir_version` 不匹配 → 输出明确错误 "IR version mismatch, run dna sync"
46
- - 保留 fail-open(不 block,但警告)
47
-
48
- ### R4: 原子写入
49
-
50
- **问题**: state 写入使用普通 `writeFile`,进程中断可能 corrupt。
51
-
52
- **修复**: 参考 OMC 的 temp+rename 模式(state.ts 已有,确认所有写入路径都用)
53
-
54
- ### R5: Stale 状态清理
55
-
56
- **问题**: 无超时机制,残留 state 文件永久存在。
57
-
58
- **修复**: 参考 OMC 的 2h stale 超时。SessionStart 时检查并清理过期 state。
59
-
60
- ---
61
-
62
- ## 第二阶段: 治理能力
63
-
64
- ### G1: Session 隔离
65
-
66
- **问题**: `.dna/state/` 无 session 目录,多 session 状态冲突。
67
-
68
- **修复**:
69
- ```
70
- .dna/state/
71
- sessions/
72
- {sessionId}/
73
- workflow.json
74
- trace.jsonl ← session 级 trace
75
- trace/
76
- trace-{date}.jsonl ← 全局 trace(合并视图)
77
- ```
78
-
79
- ### G2: MCP Server — 状态管理工具
80
-
81
- DNA 的第一个 MCP server,提供:
82
- - `dna_state_read(mode)` — 读 workflow/enforce 状态
83
- - `dna_state_write(mode, data)` — 写状态
84
- - `dna_trace_query(filters)` — 查询 trace 数据
85
- - `dna_workflow_status()` — 当前 workflow 进度
86
-
87
- 实现方式: 参考 OMC 的 `createSdkMcpServer()`,注册为 Claude Code plugin 的 MCP server。
88
-
89
- ### G3: MCP Server — 编译工具链
90
-
91
- - `dna_compile(config_path)` — 编译 DNA 到 IR
92
- - `dna_sync()` — 一键同步(等同 CLI dna sync)
93
- - `dna_generate(description)` — 从描述生成 DNA
94
-
95
- 让 LLM 直接操作 DNA,不需要 Bash 中转。
96
-
97
- ### G4: 状态驱动 Enforce
98
-
99
- **问题**: enforce 只读静态 IR,不能根据 workflow 运行时状态调整。
100
-
101
- **修复**: enforce 接受 state 参数,支持条件规则:
102
- - "rescue 第 3 轮后放宽 scope"
103
- - "scan 步骤只读,fix 步骤可写"
104
- - 当前 WorkflowState 已传入 enforce,但只用于 checkpoint。扩展为通用条件。
105
-
106
- ### G5: MCP Server — 远程治理通信(后续)
107
-
108
- - 上报审计数据到中央服务器
109
- - 拉取企业级 DNA 策略
110
- - 接收策略更新推送
111
-
112
- 这是 Phase 7 的企业治理基础,当前只做架构预留。
113
-
114
- ---
115
-
116
- ## 第三阶段: 工具体验
117
-
118
- ### U1: dna sync 自动检测升级
119
-
120
- sync 时对比 `_template_version`,有更新 → 提示升级。
121
-
122
- ### U2: 冷启动优化
123
-
124
- **问题**: 每次 hook 调用 spawn Node.js ~50ms。
125
-
126
- **方案**:
127
- - 短期: IR 缓存到内存(MCP server 常驻进程时自然解决)
128
- - 长期: MCP server 内置 enforce,hook 调用走 MCP 而非 spawn
129
-
130
- ### U3: 错误信息优化
131
-
132
- hook 报错时输出人类可读的提示而非 JSON。`dna verify` 输出友好的健康报告。
133
-
134
- ---
135
-
136
- ## 与 OMC 差距对标
137
-
138
- | 差距 | 对应任务 | 阶段 |
139
- |------|---------|------|
140
- | 无 session 隔离 | G1 | 二 |
141
- | 无 MCP 工具 | G2 + G3 | 二 |
142
- | 每次冷启动 | U2 | 三 |
143
- | 纯静态 enforce | G4 | 二 |
144
- | trace 并发 | R2 | 一 |
145
- | 无原子写入 | R4 | 一 |
146
- | 无 stale 清理 | R5 | 一 |
147
-
148
- ## DNA 已有优势(保持)
149
-
150
- | 优势 | 不要丢 |
151
- |------|--------|
152
- | 纯函数 enforce | 不引入 I/O 到 enforce.ts |
153
- | 编译时 IR | 保持预编译模式,MCP 是补充不是替代 |
154
- | Fail-open | 所有错误 → allow |
155
- | 确定性 | 同 IR + 同 input = 同 output |
156
-
157
- ## Acceptance Criteria
158
-
159
- ### 第一阶段
160
- - [ ] dna compile/sync 编译前调用 validateDNA()
161
- - [ ] trace 写入 session 隔离或原子追加
162
- - [ ] IR 版本不匹配 → 明确警告
163
- - [ ] 所有 state 写入使用 temp+rename
164
- - [ ] SessionStart 清理 >2h stale state
165
- - [ ] 测试覆盖所有修复
166
-
167
- ### 第二阶段
168
- - [x] .dna/state/sessions/{id}/ 目录结构
169
- - [x] MCP server 提供 state_read/write/trace_query
170
- - [x] MCP server 提供 compile/sync/generate
171
- - [x] enforce 支持 WorkflowState 条件规则
172
- - [x] 远程通信架构预留(接口定义,不实现)
173
-
174
- ### 第三阶段
175
- - [x] dna sync 自动检测模板版本 + 提示升级
176
- - [x] MCP server 常驻进程复用完整 hook runtime + IR cache
177
- - [ ] Claude settings hook 零进程调度(后续性能优化)
178
- - [x] 错误信息人类可读