@mycodemap/mycodemap 0.5.0 → 0.5.2-beta.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 (254) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +77 -9
  3. package/dist/cli/commands/analyze.d.ts +18 -0
  4. package/dist/cli/commands/analyze.d.ts.map +1 -1
  5. package/dist/cli/commands/analyze.js +239 -6
  6. package/dist/cli/commands/analyze.js.map +1 -1
  7. package/dist/cli/commands/check.d.ts +22 -0
  8. package/dist/cli/commands/check.d.ts.map +1 -0
  9. package/dist/cli/commands/check.js +168 -0
  10. package/dist/cli/commands/check.js.map +1 -0
  11. package/dist/cli/commands/ci.d.ts +25 -0
  12. package/dist/cli/commands/ci.d.ts.map +1 -1
  13. package/dist/cli/commands/ci.js +139 -36
  14. package/dist/cli/commands/ci.js.map +1 -1
  15. package/dist/cli/commands/complexity.d.ts.map +1 -1
  16. package/dist/cli/commands/complexity.js +6 -0
  17. package/dist/cli/commands/complexity.js.map +1 -1
  18. package/dist/cli/commands/design.d.ts +5 -0
  19. package/dist/cli/commands/design.d.ts.map +1 -1
  20. package/dist/cli/commands/design.js +6 -0
  21. package/dist/cli/commands/design.js.map +1 -1
  22. package/dist/cli/commands/generate.d.ts +1 -0
  23. package/dist/cli/commands/generate.d.ts.map +1 -1
  24. package/dist/cli/commands/generate.js +121 -8
  25. package/dist/cli/commands/generate.js.map +1 -1
  26. package/dist/cli/commands/history.d.ts +26 -0
  27. package/dist/cli/commands/history.d.ts.map +1 -0
  28. package/dist/cli/commands/history.js +92 -0
  29. package/dist/cli/commands/history.js.map +1 -0
  30. package/dist/cli/commands/mcp.d.ts +13 -0
  31. package/dist/cli/commands/mcp.d.ts.map +1 -0
  32. package/dist/cli/commands/mcp.js +108 -0
  33. package/dist/cli/commands/mcp.js.map +1 -0
  34. package/dist/cli/commands/workflow.d.ts.map +1 -1
  35. package/dist/cli/commands/workflow.js +22 -2
  36. package/dist/cli/commands/workflow.js.map +1 -1
  37. package/dist/cli/config-loader.d.ts.map +1 -1
  38. package/dist/cli/config-loader.js +3 -2
  39. package/dist/cli/config-loader.js.map +1 -1
  40. package/dist/cli/contract-checker.d.ts +33 -0
  41. package/dist/cli/contract-checker.d.ts.map +1 -0
  42. package/dist/cli/contract-checker.js +719 -0
  43. package/dist/cli/contract-checker.js.map +1 -0
  44. package/dist/cli/contract-diff-scope.d.ts +14 -0
  45. package/dist/cli/contract-diff-scope.d.ts.map +1 -0
  46. package/dist/cli/contract-diff-scope.js +127 -0
  47. package/dist/cli/contract-diff-scope.js.map +1 -0
  48. package/dist/cli/contract-gate-thresholds.d.ts +14 -0
  49. package/dist/cli/contract-gate-thresholds.d.ts.map +1 -0
  50. package/dist/cli/contract-gate-thresholds.js +19 -0
  51. package/dist/cli/contract-gate-thresholds.js.map +1 -0
  52. package/dist/cli/design-contract-loader.d.ts.map +1 -1
  53. package/dist/cli/design-contract-loader.js +355 -3
  54. package/dist/cli/design-contract-loader.js.map +1 -1
  55. package/dist/cli/design-scope-resolver.d.ts.map +1 -1
  56. package/dist/cli/design-scope-resolver.js +89 -41
  57. package/dist/cli/design-scope-resolver.js.map +1 -1
  58. package/dist/cli/index.js +18 -6
  59. package/dist/cli/index.js.map +1 -1
  60. package/dist/cli/paths.d.ts.map +1 -1
  61. package/dist/cli/paths.js +30 -7
  62. package/dist/cli/paths.js.map +1 -1
  63. package/dist/core/analyzer.d.ts.map +1 -1
  64. package/dist/core/analyzer.js +16 -0
  65. package/dist/core/analyzer.js.map +1 -1
  66. package/dist/domain/entities/CodeGraph.d.ts +5 -1
  67. package/dist/domain/entities/CodeGraph.d.ts.map +1 -1
  68. package/dist/domain/entities/CodeGraph.js +29 -12
  69. package/dist/domain/entities/CodeGraph.js.map +1 -1
  70. package/dist/domain/entities/Dependency.d.ts +8 -1
  71. package/dist/domain/entities/Dependency.d.ts.map +1 -1
  72. package/dist/domain/entities/Dependency.js +19 -4
  73. package/dist/domain/entities/Dependency.js.map +1 -1
  74. package/dist/domain/entities/Symbol.d.ts +2 -1
  75. package/dist/domain/entities/Symbol.d.ts.map +1 -1
  76. package/dist/domain/entities/Symbol.js +6 -3
  77. package/dist/domain/entities/Symbol.js.map +1 -1
  78. package/dist/infrastructure/storage/StorageFactory.d.ts +1 -0
  79. package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -1
  80. package/dist/infrastructure/storage/StorageFactory.js +7 -2
  81. package/dist/infrastructure/storage/StorageFactory.js.map +1 -1
  82. package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts +3 -1
  83. package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts.map +1 -1
  84. package/dist/infrastructure/storage/adapters/FileSystemStorage.js +10 -2
  85. package/dist/infrastructure/storage/adapters/FileSystemStorage.js.map +1 -1
  86. package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts +3 -1
  87. package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts.map +1 -1
  88. package/dist/infrastructure/storage/adapters/KuzuDBStorage.js +9 -1
  89. package/dist/infrastructure/storage/adapters/KuzuDBStorage.js.map +1 -1
  90. package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts +3 -1
  91. package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts.map +1 -1
  92. package/dist/infrastructure/storage/adapters/MemoryStorage.js +9 -1
  93. package/dist/infrastructure/storage/adapters/MemoryStorage.js.map +1 -1
  94. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts +53 -0
  95. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts.map +1 -0
  96. package/dist/infrastructure/storage/adapters/SQLiteStorage.js +879 -0
  97. package/dist/infrastructure/storage/adapters/SQLiteStorage.js.map +1 -0
  98. package/dist/infrastructure/storage/graph-helpers.d.ts +3 -1
  99. package/dist/infrastructure/storage/graph-helpers.d.ts.map +1 -1
  100. package/dist/infrastructure/storage/graph-helpers.js +90 -0
  101. package/dist/infrastructure/storage/graph-helpers.js.map +1 -1
  102. package/dist/infrastructure/storage/index.d.ts +1 -1
  103. package/dist/infrastructure/storage/index.d.ts.map +1 -1
  104. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts +3 -1
  105. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts.map +1 -1
  106. package/dist/infrastructure/storage/interfaces/StorageBase.js.map +1 -1
  107. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts +27 -0
  108. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts.map +1 -0
  109. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js +246 -0
  110. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js.map +1 -0
  111. package/dist/infrastructure/storage/sqlite/perf-thresholds.d.ts +25 -0
  112. package/dist/infrastructure/storage/sqlite/perf-thresholds.d.ts.map +1 -0
  113. package/dist/infrastructure/storage/sqlite/perf-thresholds.js +25 -0
  114. package/dist/infrastructure/storage/sqlite/perf-thresholds.js.map +1 -0
  115. package/dist/infrastructure/storage/sqlite/schema.d.ts +4 -0
  116. package/dist/infrastructure/storage/sqlite/schema.d.ts.map +1 -0
  117. package/dist/infrastructure/storage/sqlite/schema.js +111 -0
  118. package/dist/infrastructure/storage/sqlite/schema.js.map +1 -0
  119. package/dist/interface/types/design-check.d.ts +73 -0
  120. package/dist/interface/types/design-check.d.ts.map +1 -0
  121. package/dist/interface/types/design-check.js +4 -0
  122. package/dist/interface/types/design-check.js.map +1 -0
  123. package/dist/interface/types/design-contract.d.ts +56 -1
  124. package/dist/interface/types/design-contract.d.ts.map +1 -1
  125. package/dist/interface/types/history-risk.d.ts +90 -0
  126. package/dist/interface/types/history-risk.d.ts.map +1 -0
  127. package/dist/interface/types/history-risk.js +4 -0
  128. package/dist/interface/types/history-risk.js.map +1 -0
  129. package/dist/interface/types/index.d.ts +17 -2
  130. package/dist/interface/types/index.d.ts.map +1 -1
  131. package/dist/interface/types/storage.d.ts +28 -1
  132. package/dist/interface/types/storage.d.ts.map +1 -1
  133. package/dist/orchestrator/adapters/ast-grep-adapter.d.ts +10 -0
  134. package/dist/orchestrator/adapters/ast-grep-adapter.d.ts.map +1 -1
  135. package/dist/orchestrator/adapters/ast-grep-adapter.js +46 -17
  136. package/dist/orchestrator/adapters/ast-grep-adapter.js.map +1 -1
  137. package/dist/orchestrator/adapters/codemap-adapter.d.ts.map +1 -1
  138. package/dist/orchestrator/adapters/codemap-adapter.js +2 -22
  139. package/dist/orchestrator/adapters/codemap-adapter.js.map +1 -1
  140. package/dist/orchestrator/history-risk-service.d.ts +55 -0
  141. package/dist/orchestrator/history-risk-service.d.ts.map +1 -0
  142. package/dist/orchestrator/history-risk-service.js +680 -0
  143. package/dist/orchestrator/history-risk-service.js.map +1 -0
  144. package/dist/orchestrator/types.d.ts +19 -1
  145. package/dist/orchestrator/types.d.ts.map +1 -1
  146. package/dist/orchestrator/types.js +19 -0
  147. package/dist/orchestrator/types.js.map +1 -1
  148. package/dist/server/mcp/index.d.ts +4 -0
  149. package/dist/server/mcp/index.d.ts.map +1 -0
  150. package/dist/server/mcp/index.js +5 -0
  151. package/dist/server/mcp/index.js.map +1 -0
  152. package/dist/server/mcp/server.d.ts +17 -0
  153. package/dist/server/mcp/server.d.ts.map +1 -0
  154. package/dist/server/mcp/server.js +84 -0
  155. package/dist/server/mcp/server.js.map +1 -0
  156. package/dist/server/mcp/service.d.ts +22 -0
  157. package/dist/server/mcp/service.d.ts.map +1 -0
  158. package/dist/server/mcp/service.js +177 -0
  159. package/dist/server/mcp/service.js.map +1 -0
  160. package/dist/server/mcp/types.d.ts +56 -0
  161. package/dist/server/mcp/types.d.ts.map +1 -0
  162. package/dist/server/mcp/types.js +4 -0
  163. package/dist/server/mcp/types.js.map +1 -0
  164. package/docs/AI_ASSISTANT_SETUP.md +1 -1
  165. package/docs/PUBLISHING.md +41 -12
  166. package/docs/SETUP_GUIDE.md +6 -6
  167. package/docs/ai-guide/COMMANDS.md +98 -4
  168. package/docs/ai-guide/INTEGRATION.md +137 -433
  169. package/docs/ai-guide/OUTPUT.md +476 -6
  170. package/docs/ai-guide/PATTERNS.md +41 -11
  171. package/docs/ai-guide/PROMPTS.md +11 -6
  172. package/docs/backlog.md +177 -0
  173. package/docs/eatdogfood-reports/2026-04-17-eatdogfood-agent-experience.md +231 -0
  174. package/docs/exec-plans/completed/2026-04-17-eatdogfood-codemap-cli.md +103 -0
  175. package/docs/ideation/2026-04-15-executable-architecture-constitution-ideation.md +102 -0
  176. package/docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md +47 -0
  177. package/docs/product-specs/MVP3-ARCHITECTURE-COMPARISON.md +11 -10
  178. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-PRD.md +10 -10
  179. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-TECH-PRD.md +17 -12
  180. package/docs/rules/README.md +16 -11
  181. package/docs/rules/architecture-guardrails.md +24 -336
  182. package/docs/rules/code-quality-redlines.md +25 -311
  183. package/docs/rules/engineering-with-codex-openai.md +14 -1
  184. package/docs/rules/pre-release-checklist.md +9 -4
  185. package/docs/rules/validation.md +91 -40
  186. package/mycodemap.config.schema.json +3 -3
  187. package/package.json +7 -2
  188. package/scripts/benchmark-governance-graph.mjs +132 -0
  189. package/scripts/calibrate-contract-gate.mjs +221 -0
  190. package/scripts/capability-report.py +255 -0
  191. package/scripts/pre-release-check.js +2 -2
  192. package/scripts/qa-rule-control.sh +254 -0
  193. package/scripts/report-high-risk-files.mjs +395 -0
  194. package/scripts/rule-context.mjs +155 -0
  195. package/scripts/smoke-sqlite-impact.mjs +85 -0
  196. package/scripts/sync-analyze-docs.js +1 -0
  197. package/scripts/tests/test_capability_report.py +89 -0
  198. package/scripts/tests/test_rule_control_workflow.py +51 -0
  199. package/scripts/tests/test_validate_rules.py +81 -0
  200. package/scripts/validate-ai-docs.js +283 -1
  201. package/scripts/validate-docs.js +249 -42
  202. package/scripts/validate-rules.py +254 -0
  203. package/dist/ai/claude.d.ts +0 -38
  204. package/dist/ai/claude.d.ts.map +0 -1
  205. package/dist/ai/claude.js +0 -169
  206. package/dist/ai/claude.js.map +0 -1
  207. package/dist/ai/codex.d.ts +0 -38
  208. package/dist/ai/codex.d.ts.map +0 -1
  209. package/dist/ai/codex.js +0 -169
  210. package/dist/ai/codex.js.map +0 -1
  211. package/dist/ai/factory.d.ts +0 -48
  212. package/dist/ai/factory.d.ts.map +0 -1
  213. package/dist/ai/factory.js +0 -95
  214. package/dist/ai/factory.js.map +0 -1
  215. package/dist/ai/index.d.ts +0 -12
  216. package/dist/ai/index.d.ts.map +0 -1
  217. package/dist/ai/index.js +0 -29
  218. package/dist/ai/index.js.map +0 -1
  219. package/dist/ai/provider.d.ts +0 -70
  220. package/dist/ai/provider.d.ts.map +0 -1
  221. package/dist/ai/provider.js +0 -31
  222. package/dist/ai/provider.js.map +0 -1
  223. package/dist/ai/subagent-caller.d.ts +0 -90
  224. package/dist/ai/subagent-caller.d.ts.map +0 -1
  225. package/dist/ai/subagent-caller.js +0 -280
  226. package/dist/ai/subagent-caller.js.map +0 -1
  227. package/dist/ai/types.d.ts +0 -70
  228. package/dist/ai/types.d.ts.map +0 -1
  229. package/dist/ai/types.js +0 -5
  230. package/dist/ai/types.js.map +0 -1
  231. package/dist/cli/commands/server.d.ts +0 -9
  232. package/dist/cli/commands/server.d.ts.map +0 -1
  233. package/dist/cli/commands/server.js +0 -65
  234. package/dist/cli/commands/server.js.map +0 -1
  235. package/dist/cli-new/commands/server.d.ts +0 -13
  236. package/dist/cli-new/commands/server.d.ts.map +0 -1
  237. package/dist/cli-new/commands/server.js +0 -90
  238. package/dist/cli-new/commands/server.js.map +0 -1
  239. package/dist/generator/ai-overview.d.ts +0 -51
  240. package/dist/generator/ai-overview.d.ts.map +0 -1
  241. package/dist/generator/ai-overview.js +0 -160
  242. package/dist/generator/ai-overview.js.map +0 -1
  243. package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts +0 -41
  244. package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts.map +0 -1
  245. package/dist/infrastructure/storage/adapters/Neo4jStorage.js +0 -162
  246. package/dist/infrastructure/storage/adapters/Neo4jStorage.js.map +0 -1
  247. package/dist/orchestrator/ai-feed-generator.d.ts +0 -210
  248. package/dist/orchestrator/ai-feed-generator.d.ts.map +0 -1
  249. package/dist/orchestrator/ai-feed-generator.js +0 -377
  250. package/dist/orchestrator/ai-feed-generator.js.map +0 -1
  251. package/docs/archive/test-report-symbol-search.md +0 -384
  252. package/docs/archive/test-scenario-4-complexity-analysis.md +0 -460
  253. package/docs/archive/test_report_scenario5.md +0 -615
  254. package/docs/archive/test_scenario_3_impact_analysis_report.md +0 -520
@@ -195,17 +195,8 @@ function validateAnalyzeDocs(rootDir, failures) {
195
195
  failures
196
196
  );
197
197
 
198
- validateSnippets(
199
- claudeGuide,
200
- 'CLAUDE.md analyze retrieval guidance',
201
- [
202
- 'node dist/cli/index.js analyze -i <find|read|link|show>'
203
- ],
204
- [
205
- 'node dist/cli/index.js analyze <intent>'
206
- ],
207
- failures
208
- );
198
+ // NOTE: CLAUDE.md 已演进为执行手册(路由层),analyze 命令指南已移至 AI_GUIDE.md / docs/ai-guide/
199
+ // 相关检查已下放至 AI_GUIDE.md 与 docs/ai-guide/*.md 的 validateSnippets 中
209
200
 
210
201
  validateSnippets(
211
202
  engineeringGuide,
@@ -226,6 +217,109 @@ function validateAnalyzeDocs(rootDir, failures) {
226
217
  failures.push(...collectAnalyzeDocSyncFailures(rootDir));
227
218
  }
228
219
 
220
+ function validateHistoryRiskDocs(rootDir, failures) {
221
+ const readme = readText(rootDir, 'README.md', failures);
222
+ const aiGuide = readText(rootDir, 'AI_GUIDE.md', failures);
223
+ const claudeGuide = readText(rootDir, 'CLAUDE.md', failures);
224
+ const commandsGuide = readText(rootDir, 'docs/ai-guide/COMMANDS.md', failures);
225
+ const outputGuide = readText(rootDir, 'docs/ai-guide/OUTPUT.md', failures);
226
+ const validationRule = readText(rootDir, 'docs/rules/validation.md', failures);
227
+ const cliIndexSource = readText(rootDir, 'src/cli/index.ts', failures);
228
+ const historyCommandSource = readText(rootDir, 'src/cli/commands/history.ts', failures);
229
+
230
+ if (cliIndexSource) {
231
+ expectIncludes(cliIndexSource, 'program.addCommand(historyCommand);', 'src/cli/index.ts history command registration', failures);
232
+ }
233
+
234
+ if (historyCommandSource) {
235
+ validateSnippets(
236
+ historyCommandSource,
237
+ 'src/cli/commands/history.ts command surface',
238
+ [
239
+ "new Command('history')",
240
+ ".requiredOption('--symbol <name>'",
241
+ ".option('--human'",
242
+ ],
243
+ [],
244
+ failures
245
+ );
246
+ }
247
+
248
+ if (readme) {
249
+ validateSnippets(
250
+ readme,
251
+ 'README.md history risk baseline',
252
+ [
253
+ '# 查询某个符号的历史轨迹与风险摘要\nmycodemap history --symbol createCheckCommand',
254
+ '### `mycodemap history`\n\n符号级 Git history / risk 查询:\n\n```bash\n# 默认输出 machine-first JSON\nmycodemap history --symbol createCheckCommand',
255
+ '`--include-git-history` 现在只会在 `read` intent 上附加统一的 Git history enrichment;其他 intent 会显式给出 warning,而不是 silent noop。',
256
+ '`ci assess-risk` 现在输出 `status/confidence/freshness/source` 与统一 risk level;若 Git history 不可用,会显式打印 `unavailable` / warning,并说明阈值未被应用。'
257
+ ],
258
+ [],
259
+ failures
260
+ );
261
+ }
262
+
263
+ if (aiGuide) {
264
+ validateSnippets(
265
+ aiGuide,
266
+ 'AI_GUIDE.md history risk baseline',
267
+ [
268
+ '`history --symbol <name>`',
269
+ '`check` / `ci assess-risk` / `history` 现在共用同一套 Git history risk truth;history unavailable 时会显式给出 `unavailable` / `confidence=low`',
270
+ 'interface HistoryCommandResult {'
271
+ ],
272
+ [],
273
+ failures
274
+ );
275
+ }
276
+
277
+ // NOTE: CLAUDE.md 已演进为执行手册(路由层),history 风险基线已移至 AI_GUIDE.md / docs/ai-guide/
278
+ // 相关检查已下放至 AI_GUIDE.md 与 docs/ai-guide/*.md 的 validateSnippets 中
279
+
280
+ if (commandsGuide) {
281
+ validateSnippets(
282
+ commandsGuide,
283
+ 'docs/ai-guide/COMMANDS.md history risk baseline',
284
+ [
285
+ '## history - 符号级 Git history / risk 查询',
286
+ 'Git history risk 是 additive enrichment:会附加 `violations[].risk` 与顶层 `history`,但不会改变 `severity:error` / exit 语义',
287
+ '`ci assess-risk` 现在输出 `status / confidence / freshness / source / score / level`'
288
+ ],
289
+ [],
290
+ failures
291
+ );
292
+ }
293
+
294
+ if (outputGuide) {
295
+ validateSnippets(
296
+ outputGuide,
297
+ 'docs/ai-guide/OUTPUT.md history risk baseline',
298
+ [
299
+ 'interface HistoryCommandResult {',
300
+ 'Git history risk 是 additive enrichment:它补充 `history` 与 `violations[].risk`',
301
+ '"git-history-unsupported-intent"'
302
+ ],
303
+ [],
304
+ failures
305
+ );
306
+ }
307
+
308
+ if (validationRule) {
309
+ validateSnippets(
310
+ validationRule,
311
+ 'docs/rules/validation.md history risk baseline',
312
+ [
313
+ '`check` / `ci assess-risk` / `history` / `analyze --include-git-history` 的统一 risk truth',
314
+ 'node dist/cli/index.js history --symbol createCheckCommand',
315
+ 'node scripts/report-high-risk-files.mjs --top 3'
316
+ ],
317
+ [],
318
+ failures
319
+ );
320
+ }
321
+ }
322
+
229
323
  function validateDesignContractDocs(rootDir, failures) {
230
324
  const readme = readText(rootDir, 'README.md', failures);
231
325
  const aiGuide = readText(rootDir, 'AI_GUIDE.md', failures);
@@ -240,9 +334,12 @@ function validateDesignContractDocs(rootDir, failures) {
240
334
  const designTemplate = readText(rootDir, 'docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md', failures);
241
335
  const cliIndexSource = readText(rootDir, 'src/cli/index.ts', failures);
242
336
  const designCommandSource = readText(rootDir, 'src/cli/commands/design.ts', failures);
337
+ const checkCommandSource = readText(rootDir, 'src/cli/commands/check.ts', failures);
338
+ const repoContract = readText(rootDir, 'mycodemap.design.md', failures);
243
339
 
244
340
  if (cliIndexSource) {
245
341
  expectIncludes(cliIndexSource, 'program.addCommand(designCommand);', 'src/cli/index.ts design command registration', failures);
342
+ expectIncludes(cliIndexSource, 'program.addCommand(checkCommand);', 'src/cli/index.ts check command registration', failures);
246
343
  }
247
344
 
248
345
  if (designCommandSource) {
@@ -267,6 +364,28 @@ function validateDesignContractDocs(rootDir, failures) {
267
364
  );
268
365
  }
269
366
 
367
+ if (checkCommandSource) {
368
+ validateSnippets(
369
+ checkCommandSource,
370
+ 'src/cli/commands/check.ts command surface',
371
+ [
372
+ "new Command('check')",
373
+ "--contract <file>",
374
+ "--against <path>",
375
+ '--base <git-ref>',
376
+ '--changed-files <paths...>',
377
+ '--annotation-format <format>',
378
+ '--annotation-file <file>',
379
+ 'resolveContractDiffScope',
380
+ 'runContractCheck',
381
+ 'renderGitHubAnnotations',
382
+ 'renderGitLabAnnotations',
383
+ ],
384
+ [],
385
+ failures
386
+ );
387
+ }
388
+
270
389
  if (readme) {
271
390
  validateSnippets(
272
391
  readme,
@@ -276,6 +395,13 @@ function validateDesignContractDocs(rootDir, failures) {
276
395
  'mycodemap design map mycodemap.design.md --json',
277
396
  'mycodemap design handoff mycodemap.design.md --json',
278
397
  'mycodemap design verify mycodemap.design.md --json',
398
+ 'mycodemap check --contract mycodemap.design.md --against src',
399
+ '--annotation-format github',
400
+ '--annotation-format gitlab --annotation-file gl-code-quality-report.json',
401
+ 'node scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10',
402
+ 'changed files <= 10',
403
+ 'warn-only / fallback',
404
+ 'false-positive rate >10%',
279
405
  'docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md',
280
406
  '`mycodemap.design.md`',
281
407
  '`design validate → design map → design handoff → design verify`'
@@ -294,31 +420,25 @@ function validateDesignContractDocs(rootDir, failures) {
294
420
  'design map mycodemap.design.md --json',
295
421
  'design handoff mycodemap.design.md --json',
296
422
  'design verify mycodemap.design.md --json',
423
+ 'check --contract mycodemap.design.md --against src',
424
+ '--annotation-format github',
425
+ 'node scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10',
426
+ 'changed files <= 10',
427
+ 'warn-only / fallback',
297
428
  '`mycodemap.design.md`',
298
429
  'interface DesignValidateOutput {',
299
430
  'interface DesignMapOutput {',
300
431
  'interface DesignHandoffOutput {',
301
- 'interface DesignVerificationOutput {'
432
+ 'interface DesignVerificationOutput {',
433
+ 'interface ContractCheckResult {'
302
434
  ],
303
435
  [],
304
436
  failures
305
437
  );
306
438
  }
307
439
 
308
- if (claudeGuide) {
309
- validateSnippets(
310
- claudeGuide,
311
- 'CLAUDE.md design retrieval guidance',
312
- [
313
- 'node dist/cli/index.js design validate [file] --json',
314
- 'node dist/cli/index.js design map [file] --json',
315
- 'node dist/cli/index.js design handoff [file] --json',
316
- 'node dist/cli/index.js design verify [file] --json'
317
- ],
318
- [],
319
- failures
320
- );
321
- }
440
+ // NOTE: CLAUDE.md 已演进为执行手册(路由层),design 检索指南已移至 AI_GUIDE.md / docs/ai-guide/
441
+ // 相关检查已下放至 AI_GUIDE.md 与 docs/ai-guide/*.md 的 validateSnippets
322
442
 
323
443
  if (commandsGuide) {
324
444
  validateSnippets(
@@ -330,6 +450,14 @@ function validateDesignContractDocs(rootDir, failures) {
330
450
  'mycodemap design map mycodemap.design.md --json',
331
451
  'mycodemap design handoff mycodemap.design.md --json',
332
452
  'mycodemap design verify mycodemap.design.md --json',
453
+ '## check - 执行 contract gate',
454
+ 'mycodemap check --contract mycodemap.design.md --against src',
455
+ 'mycodemap check --contract mycodemap.design.md --against src --base origin/main',
456
+ '--annotation-format github',
457
+ '--annotation-format gitlab --annotation-file gl-code-quality-report.json',
458
+ 'node scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10',
459
+ 'changed files <= 10',
460
+ 'warn-only / fallback',
333
461
  '`mycodemap.design.md`',
334
462
  '### 必填 sections',
335
463
  '### map',
@@ -348,6 +476,7 @@ function validateDesignContractDocs(rootDir, failures) {
348
476
  'docs/ai-guide/OUTPUT.md design validate schema',
349
477
  [
350
478
  '## design validate 命令输出结构',
479
+ '## check 命令输出结构',
351
480
  '## design map 命令输出结构',
352
481
  '## design handoff 命令输出结构',
353
482
  '## design verify 命令输出结构',
@@ -356,6 +485,15 @@ function validateDesignContractDocs(rootDir, failures) {
356
485
  'interface DesignMapOutput {',
357
486
  'interface DesignHandoffOutput {',
358
487
  'interface DesignVerificationOutput {',
488
+ 'interface ContractCheckResult {',
489
+ 'details?: Record<string, string | number | boolean | null>;',
490
+ 'rule_type: "layer_direction" | "forbidden_imports" | "module_public_api_only" | "complexity_threshold";',
491
+ 'diagnostic?: {',
492
+ 'scope: "line" | "file" | "general";',
493
+ 'category: "dependency" | "module_boundary" | "complexity";',
494
+ 'Annotation-friendly diagnostics',
495
+ 'gl-code-quality-report.json',
496
+ 'warn-only / fallback',
359
497
  'unknowns: string[];',
360
498
  'diagnostics: DesignMappingDiagnostic[];',
361
499
  'readyForExecution: boolean;',
@@ -364,6 +502,9 @@ function validateDesignContractDocs(rootDir, failures) {
364
502
  'openQuestions: DesignHandoffTraceItem[];',
365
503
  'type DesignVerificationStatus =',
366
504
  'type DesignDriftKind =',
505
+ '"scan_mode": "diff"',
506
+ '"rule_type": "layer_direction"',
507
+ '"code": "hard-gate-window-exceeded"',
367
508
  'checklist: Array<{',
368
509
  'drift: Array<{',
369
510
  '"code": "handoff-missing"',
@@ -385,6 +526,11 @@ function validateDesignContractDocs(rootDir, failures) {
385
526
  'node dist/cli/index.js design map mycodemap.design.md --json',
386
527
  'node dist/cli/index.js design handoff mycodemap.design.md --json',
387
528
  'node dist/cli/index.js design verify mycodemap.design.md --json',
529
+ 'node scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10',
530
+ 'node dist/cli/index.js check --contract mycodemap.design.md --against src --base origin/main --annotation-format github',
531
+ '--annotation-format gitlab --annotation-file gl-code-quality-report.json',
532
+ 'changed files <= 10',
533
+ 'warn-only / fallback',
388
534
  '`design validate → design map → design handoff → design verify`',
389
535
  '`workflow` 仍只保留 `find` / `read` / `link` / `show` 四阶段'
390
536
  ],
@@ -402,7 +548,8 @@ function validateDesignContractDocs(rootDir, failures) {
402
548
  'docs/ai-guide/PROMPTS.md design contract prompt',
403
549
  [
404
550
  'cp docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md mycodemap.design.md',
405
- 'node dist/cli/index.js design validate mycodemap.design.md --json'
551
+ 'node dist/cli/index.js design validate mycodemap.design.md --json',
552
+ 'node dist/cli/index.js check --contract mycodemap.design.md --against src'
406
553
  ],
407
554
  [],
408
555
  failures
@@ -418,6 +565,7 @@ function validateDesignContractDocs(rootDir, failures) {
418
565
  '`node dist/cli/index.js design map mycodemap.design.md --json`',
419
566
  '`node dist/cli/index.js design handoff mycodemap.design.md --json`',
420
567
  '`node dist/cli/index.js design verify mycodemap.design.md --json`',
568
+ '`node dist/cli/index.js check --contract mycodemap.design.md --against src`',
421
569
  '`candidates` / `unknowns` / `diagnostics`',
422
570
  '`readyForExecution` / `approvals` / `assumptions` / `openQuestions`',
423
571
  '`checklist` / `drift` / `diagnostics` / `readyForExecution`',
@@ -446,9 +594,11 @@ function validateDesignContractDocs(rootDir, failures) {
446
594
  'docs/rules/validation.md design verification baseline',
447
595
  [
448
596
  '`design validate` / `design map` / `design handoff` / `design verify`',
597
+ '`check --contract mycodemap.design.md --against src`',
449
598
  '`design validate → design map → design handoff → design verify`',
450
599
  'design verify mycodemap.design.md --json',
451
- 'review-needed 与 blocker 退出语义'
600
+ 'review-needed 与 blocker 退出语义',
601
+ 'github.event.pull_request.base.sha'
452
602
  ],
453
603
  [],
454
604
  failures
@@ -461,6 +611,27 @@ function validateDesignContractDocs(rootDir, failures) {
461
611
  'docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md',
462
612
  [
463
613
  '保存为 `mycodemap.design.md`',
614
+ 'rules:',
615
+ 'type: layer_direction',
616
+ '## Goal',
617
+ '## Constraints',
618
+ '## Acceptance Criteria',
619
+ '## Non-Goals'
620
+ ],
621
+ [],
622
+ failures
623
+ );
624
+ }
625
+
626
+ if (repoContract) {
627
+ validateSnippets(
628
+ repoContract,
629
+ 'mycodemap.design.md repo-root contract',
630
+ [
631
+ 'rules:',
632
+ 'type: layer_direction',
633
+ 'from: "src/core/**"',
634
+ 'to: "src/cli/**"',
464
635
  '## Goal',
465
636
  '## Constraints',
466
637
  '## Acceptance Criteria',
@@ -771,6 +942,7 @@ function validatePluginRuntimeDocs(rootDir, failures) {
771
942
  function validateGraphStorageDocs(rootDir, failures) {
772
943
  const readme = readText(rootDir, 'README.md', failures);
773
944
  const aiGuide = readText(rootDir, 'AI_GUIDE.md', failures);
945
+ const claudeGuide = readText(rootDir, 'CLAUDE.md', failures);
774
946
  const commandsGuide = readText(rootDir, 'docs/ai-guide/COMMANDS.md', failures);
775
947
  const quickstartGuide = readText(rootDir, 'docs/ai-guide/QUICKSTART.md', failures);
776
948
  const setupGuide = readText(rootDir, 'docs/SETUP_GUIDE.md', failures);
@@ -783,8 +955,9 @@ function validateGraphStorageDocs(rootDir, failures) {
783
955
  'README.md graph storage contract',
784
956
  [
785
957
  '"storage": {',
786
- '| `storage.type` | `"filesystem" \\| "kuzudb" \\| "memory" \\| "auto"` | 图存储后端类型 | `"filesystem"` |',
787
- '`neo4j` 已不再是正式支持的 backend;旧配置会返回显式迁移错误,不会静默 fallback 到 `filesystem`。',
958
+ '| `storage.type` | `"filesystem" \\| "sqlite" \\| "memory" \\| "auto"` | 图存储后端类型 | `"filesystem"` |',
959
+ '`neo4j` 与 `kuzudb` 已不再是正式支持的 backend;旧配置会返回显式迁移错误,不会静默 fallback 到 `filesystem`。',
960
+ '`storage.type = "auto"` 当前优先选择 `sqlite`;若运行时缺少 `better-sqlite3` 或 Node.js `<20` 导致 SQLite 不可用,则 warning 后回退到 `filesystem`。',
788
961
  '图存储后端生产化不等于重新开放公共 HTTP API 产品面;`Server Layer` 仍是内部架构层。'
789
962
  ],
790
963
  [],
@@ -799,13 +972,17 @@ function validateGraphStorageDocs(rootDir, failures) {
799
972
  [
800
973
  '| "需要切换/排查图存储后端" | 编辑 `mycodemap.config.json.storage` → 运行 `generate` / `export` |',
801
974
  '`generate` 会写入配置的图存储后端;`export` 与内部 `Server Layer` handler 会读取同一份后端数据。',
802
- '`neo4j` 已不再是正式支持的 backend;旧配置会暴露显式迁移错误,不会静默 fallback。'
975
+ '`neo4j` 与 `kuzudb` 已不再是正式支持的 backend;旧配置会暴露显式迁移错误,不会静默 fallback。',
976
+ '`storage.type = "auto"` 当前优先选择 `sqlite`;若运行时缺少 `better-sqlite3` 或 Node.js `<20` 导致 SQLite 不可用,则 warning 后回退到 `filesystem`。'
803
977
  ],
804
978
  [],
805
979
  failures
806
980
  );
807
981
  }
808
982
 
983
+ // NOTE: CLAUDE.md 已演进为执行手册(路由层),graph storage 合约已移至 AI_GUIDE.md / docs/ai-guide/
984
+ // 相关检查已下放至 AI_GUIDE.md 与 docs/ai-guide/*.md 的 validateSnippets 中
985
+
809
986
  if (commandsGuide) {
810
987
  validateSnippets(
811
988
  commandsGuide,
@@ -839,8 +1016,10 @@ function validateGraphStorageDocs(rootDir, failures) {
839
1016
  'docs/SETUP_GUIDE.md graph storage contract',
840
1017
  [
841
1018
  '"storage": {',
842
- '| `storage.type` | string | `"filesystem"` | 图存储后端类型:`filesystem` / `kuzudb` / `memory` / `auto` |',
843
- '旧的 `neo4j` 配置已不再受支持,会返回显式迁移错误,不会静默 fallback 到 `filesystem`。'
1019
+ '| `storage.type` | string | `"filesystem"` | 图存储后端类型:`filesystem` / `sqlite` / `memory` / `auto` |',
1020
+ '旧的 `neo4j` / `kuzudb` 配置已不再受支持,会返回显式迁移错误,不会静默 fallback 到 `filesystem`。',
1021
+ '显式选择 `sqlite` 且运行时缺少 `better-sqlite3` 或 Node.js `<20` 时,会返回显式错误。',
1022
+ '`storage.type = "auto"` 当前优先选择 `sqlite`;仅当 SQLite 运行时不可用时才 warning 后回退到 `filesystem`。'
844
1023
  ],
845
1024
  [],
846
1025
  failures
@@ -854,7 +1033,9 @@ function validateGraphStorageDocs(rootDir, failures) {
854
1033
  [
855
1034
  '若改动涉及 `mycodemap.config.json.storage` 或图数据库适配器',
856
1035
  'schema / README / AI 文档没同步',
857
- '旧的 `neo4j` 配置已经不受支持,但文档还把它写成正式 backend'
1036
+ '旧的 `neo4j` / `kuzudb` 配置已经不受支持,但文档还把它写成正式 backend',
1037
+ 'Node.js `>=20`',
1038
+ '`STORAGE_BACKEND_MIGRATED`、`SQLITE_NOT_AVAILABLE`'
858
1039
  ],
859
1040
  [],
860
1041
  failures
@@ -867,7 +1048,7 @@ function validateGraphStorageDocs(rootDir, failures) {
867
1048
  'mycodemap.config.schema.json storage contract',
868
1049
  [
869
1050
  '"storage"',
870
- '"enum": ["filesystem", "kuzudb", "memory", "auto"]',
1051
+ '"enum": ["filesystem", "sqlite", "memory", "auto"]',
871
1052
  '"outputPath"',
872
1053
  '"databasePath"',
873
1054
  '"autoThresholds"'
@@ -1040,14 +1221,18 @@ function validateProductSpecsDocs(rootDir, failures) {
1040
1221
  [
1041
1222
  '# MVP3 架构对比:历史设计目标 vs v1.3 已落地基线',
1042
1223
  '`src/server/` 保留为**内部架构层**;公共 `server` 命令已移除',
1043
- '`filesystem` / `memory` / `kuzudb` / `auto` 为正式 surface;`neo4j` 已退出正式支持',
1224
+ '`filesystem` / `memory` / `sqlite` / `auto` 为正式 surface;`neo4j` 与 `kuzudb` 已退出正式支持',
1225
+ '当前优先选择 `sqlite`;仅当 SQLite 运行时不可用时 warning 后回退 `filesystem`',
1226
+ '`sqlite` 需要 `better-sqlite3` + Node.js `>=20`;否则返回 `SQLITE_NOT_AVAILABLE`',
1044
1227
  '当前公开能力仅保留 analysis-only:`find → read → link → show`',
1045
1228
  'Java / Rust / C/C++ 等更多 parser 实现 | 接口预留,未作为当前 shipped reality |'
1046
1229
  ],
1047
1230
  [
1048
1231
  '# MVP3 架构对比:Before vs After',
1049
1232
  'cli/commands/viz.ts',
1050
- '支持 14 种语言'
1233
+ '支持 14 种语言',
1234
+ 'Kùzu-only',
1235
+ '当前仍保守落到 `filesystem`'
1051
1236
  ],
1052
1237
  failures
1053
1238
  );
@@ -1060,13 +1245,17 @@ function validateProductSpecsDocs(rootDir, failures) {
1060
1245
  [
1061
1246
  '# CodeMap MVP3 架构重构产品需求文档(PRD,v1.3 同步版)',
1062
1247
  '公共 CLI 不再暴露 `server`、`watch`、`report`、`logs`',
1063
- '| `neo4j` | removed | 不再是正式支持 backend;旧配置返回显式迁移错误 |',
1248
+ '| `auto` | shipped surface | 配置面存在,当前优先选择 `sqlite`;SQLite 不可用时回退 `filesystem` |',
1249
+ '| `neo4j` / `kuzudb` | removed | 不再是正式支持 backend;旧配置返回显式迁移错误 |',
1250
+ '显式 `sqlite` 缺少 `better-sqlite3` 或 Node.js `<20` 时会返回 `SQLITE_NOT_AVAILABLE`',
1064
1251
  '`workflow` 是 **analysis-only** 能力,只编排 `find → read → link → show`',
1065
1252
  '| 公共 HTTP API / `mycodemap server` 产品面 | Deferred |'
1066
1253
  ],
1067
1254
  [
1068
1255
  '支持 14 种语言',
1069
- 'neo4j | shipped'
1256
+ 'neo4j | shipped',
1257
+ 'Kùzu-only',
1258
+ '当前仍保守落到 `filesystem`'
1070
1259
  ],
1071
1260
  failures
1072
1261
  );
@@ -1078,14 +1267,18 @@ function validateProductSpecsDocs(rootDir, failures) {
1078
1267
  'docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-TECH-PRD.md technical baseline',
1079
1268
  [
1080
1269
  '# CodeMap MVP3 架构重构技术需求文档(Tech-PRD,v1.3 同步版)',
1081
- '`neo4j` 已不再是正式支持 backend。',
1270
+ '`neo4j` 与 `kuzudb` 已不再是正式支持 backend。',
1271
+ '显式选择 `sqlite` 且运行时缺少 `better-sqlite3` 或 Node.js `<20` 时,`StorageFactory` 会抛出 `SQLITE_NOT_AVAILABLE`',
1082
1272
  '`auto` 是稳定配置面',
1273
+ '`auto` 会先探测 SQLite runtime,可用时返回 `sqlite`,不可用时 warning 后回退 `filesystem`',
1083
1274
  '但“按规模自动切到图数据库”的更强启发式仍是未来候选,而不是当前完成能力',
1084
1275
  '| analyze / refresh / incremental update 作为公共能力 | 明确返回 `501` unsupported |',
1085
1276
  '`workflow` 当前是 analysis-only 能力:'
1086
1277
  ],
1087
1278
  [
1088
- 'TypeScriptParser, GoParser, PythonParser, ParserRegistry'
1279
+ 'TypeScriptParser, GoParser, PythonParser, ParserRegistry',
1280
+ '当前仍保守返回 `filesystem`',
1281
+ 'Kùzu-native'
1089
1282
  ],
1090
1283
  failures
1091
1284
  );
@@ -1102,7 +1295,8 @@ function validateGuardrailDocs(rootDir, failures) {
1102
1295
  if (readme) {
1103
1296
  const requiredReadmeGuardrails = [
1104
1297
  'npm run docs:check',
1105
- 'mycodemap ci check-docs-sync'
1298
+ 'mycodemap ci check-docs-sync',
1299
+ 'mycodemap check --contract mycodemap.design.md --against src'
1106
1300
  ];
1107
1301
 
1108
1302
  for (const snippet of requiredReadmeGuardrails) {
@@ -1126,12 +1320,24 @@ function validateGuardrailDocs(rootDir, failures) {
1126
1320
 
1127
1321
  if (validationRule) {
1128
1322
  expectIncludes(validationRule, 'npm run docs:check', 'docs/rules/validation.md', failures);
1323
+ expectIncludes(validationRule, 'node dist/cli/index.js check --contract mycodemap.design.md --against src', 'docs/rules/validation.md', failures);
1324
+ expectIncludes(validationRule, 'node scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10', 'docs/rules/validation.md', failures);
1325
+ expectIncludes(validationRule, '--annotation-format github', 'docs/rules/validation.md', failures);
1326
+ expectIncludes(validationRule, 'changed files <= 10', 'docs/rules/validation.md', failures);
1327
+ expectIncludes(validationRule, 'warn-only / fallback', 'docs/rules/validation.md', failures);
1129
1328
  }
1130
1329
 
1131
1330
  if (ciWorkflow) {
1132
1331
  expectIncludes(ciWorkflow, 'run: npm run docs:check', '.github/workflows/ci-gateway.yml', failures);
1133
1332
  expectIncludes(ciWorkflow, 'run: npm run typecheck', '.github/workflows/ci-gateway.yml', failures);
1134
1333
  expectIncludes(ciWorkflow, 'run: npm run build', '.github/workflows/ci-gateway.yml', failures);
1334
+ expectIncludes(ciWorkflow, 'check --contract mycodemap.design.md --against src', '.github/workflows/ci-gateway.yml', failures);
1335
+ expectIncludes(ciWorkflow, 'github.event.pull_request.base.sha', '.github/workflows/ci-gateway.yml', failures);
1336
+ expectIncludes(ciWorkflow, 'scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10', '.github/workflows/ci-gateway.yml', failures);
1337
+ expectIncludes(ciWorkflow, '--annotation-format github', '.github/workflows/ci-gateway.yml', failures);
1338
+ expectIncludes(ciWorkflow, 'contract-gate-calibration.json', '.github/workflows/ci-gateway.yml', failures);
1339
+ expectIncludes(ciWorkflow, 'contract-check-result.json', '.github/workflows/ci-gateway.yml', failures);
1340
+ expectIncludes(ciWorkflow, 'warn-only / fallback', '.github/workflows/ci-gateway.yml', failures);
1135
1341
  expectIncludes(ciWorkflow, 'run: node dist/cli/index.js ci check-docs-sync', '.github/workflows/ci-gateway.yml', failures);
1136
1342
  expectIncludes(ciWorkflow, 'node dist/cli/index.js generate', '.github/workflows/ci-gateway.yml', failures);
1137
1343
  }
@@ -1184,6 +1390,7 @@ function validateDocs(rootDir) {
1184
1390
  validatePluginRuntimeDocs(rootDir, failures);
1185
1391
  validateGraphStorageDocs(rootDir, failures);
1186
1392
  validateAnalyzeDocs(rootDir, failures);
1393
+ validateHistoryRiskDocs(rootDir, failures);
1187
1394
  validateDesignContractDocs(rootDir, failures);
1188
1395
  validateTestingDocs(rootDir, failures);
1189
1396
  validateWorkflowAndDiscoveryDocs(rootDir, failures);