@mycodemap/mycodemap 0.5.0 → 0.5.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 (199) hide show
  1. package/CHANGELOG.md +13 -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/SETUP_GUIDE.md +6 -6
  166. package/docs/ai-guide/COMMANDS.md +98 -4
  167. package/docs/ai-guide/INTEGRATION.md +137 -433
  168. package/docs/ai-guide/OUTPUT.md +476 -6
  169. package/docs/ai-guide/PATTERNS.md +41 -11
  170. package/docs/ai-guide/PROMPTS.md +11 -6
  171. package/docs/backlog.md +177 -0
  172. package/docs/eatdogfood-reports/2026-04-17-eatdogfood-agent-experience.md +231 -0
  173. package/docs/exec-plans/completed/2026-04-17-eatdogfood-codemap-cli.md +103 -0
  174. package/docs/ideation/2026-04-15-executable-architecture-constitution-ideation.md +102 -0
  175. package/docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md +47 -0
  176. package/docs/product-specs/MVP3-ARCHITECTURE-COMPARISON.md +11 -10
  177. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-PRD.md +10 -10
  178. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-TECH-PRD.md +17 -12
  179. package/docs/rules/README.md +16 -11
  180. package/docs/rules/architecture-guardrails.md +24 -336
  181. package/docs/rules/code-quality-redlines.md +25 -311
  182. package/docs/rules/engineering-with-codex-openai.md +14 -1
  183. package/docs/rules/validation.md +90 -40
  184. package/mycodemap.config.schema.json +3 -3
  185. package/package.json +7 -2
  186. package/scripts/benchmark-governance-graph.mjs +132 -0
  187. package/scripts/calibrate-contract-gate.mjs +221 -0
  188. package/scripts/capability-report.py +255 -0
  189. package/scripts/qa-rule-control.sh +254 -0
  190. package/scripts/report-high-risk-files.mjs +395 -0
  191. package/scripts/rule-context.mjs +155 -0
  192. package/scripts/smoke-sqlite-impact.mjs +85 -0
  193. package/scripts/sync-analyze-docs.js +1 -0
  194. package/scripts/tests/test_capability_report.py +89 -0
  195. package/scripts/tests/test_rule_control_workflow.py +51 -0
  196. package/scripts/tests/test_validate_rules.py +81 -0
  197. package/scripts/validate-ai-docs.js +283 -1
  198. package/scripts/validate-docs.js +249 -42
  199. package/scripts/validate-rules.py +254 -0
@@ -77,15 +77,33 @@ interface CodeMap {
77
77
  summary: ProjectSummary;
78
78
  modules: ModuleInfo[];
79
79
  dependencies: DependencyGraph;
80
+ graphStatus?: "complete" | "partial";
81
+ failedFileCount?: number;
82
+ parseFailureFiles?: string[];
80
83
  actualMode?: "fast" | "smart";
81
84
  pluginReport?: PluginExecutionReport;
82
85
  }
83
86
  ```
84
87
 
88
+ ### graph integrity 语义
89
+
90
+ | 字段 | 含义 | 何时出现 |
91
+ |------|------|----------|
92
+ | `graphStatus` | 当前图是否完整:`complete` / `partial` | `generate` 输出总会写入 |
93
+ | `failedFileCount` | 发现到但未成功进入最终图的文件数 | `generate` 输出总会写入 |
94
+ | `parseFailureFiles` | 失败文件路径列表 | 仅当 `failedFileCount > 0` 时出现 |
95
+
96
+ - `summary.totalFiles` 仍表示**成功进入最终图**的模块数,不代表发现阶段的总文件数。
97
+ - 若 `graphStatus = "partial"`,Agent / 自动化流程必须把图视为**降级结果**,不能伪装成完整 truth。
98
+ - `generate --symbol-level` 与默认 generate 都遵守同一套 `graphStatus` 语义;差别只在是否 materialize symbol-level `call` 依赖。
99
+
85
100
  ### 示例
86
101
 
87
102
  ```json
88
103
  {
104
+ "graphStatus": "partial",
105
+ "failedFileCount": 1,
106
+ "parseFailureFiles": ["src/broken.ts"],
89
107
  "pluginReport": {
90
108
  "loadedPlugins": ["complexity-analyzer", "my-local-plugin"],
91
109
  "generatedFiles": ["plugins/good.txt"],
@@ -110,6 +128,144 @@ interface CodeMap {
110
128
 
111
129
  ---
112
130
 
131
+ ## experimental MCP tool 输出结构
132
+
133
+ > canonical MCP path 是 `generate --symbol-level → mcp install → host 启动 mcp start`。当前只暴露 `codemap_query` / `codemap_impact` 两个工具。
134
+
135
+ ```typescript
136
+ type McpToolStatus = "ok" | "not_found" | "ambiguous" | "unavailable";
137
+ type McpToolConfidence = "high" | "ambiguous" | "unavailable";
138
+ type McpGraphStatus = "complete" | "partial" | "missing";
139
+ type McpErrorCode = "GRAPH_NOT_FOUND" | "SYMBOL_NOT_FOUND" | "AMBIGUOUS_EDGE";
140
+
141
+ interface McpSymbolRef {
142
+ id: string;
143
+ module_id: string;
144
+ name: string;
145
+ kind: string;
146
+ visibility: "public" | "private" | "protected" | "internal";
147
+ file_path: string;
148
+ line: number;
149
+ column: number;
150
+ signature?: string;
151
+ }
152
+
153
+ interface McpQueryResult {
154
+ status: McpToolStatus;
155
+ confidence: McpToolConfidence;
156
+ graph_status: McpGraphStatus;
157
+ generated_at: string | null;
158
+ failed_file_count: number;
159
+ parse_failure_files: string[];
160
+ symbol?: McpSymbolRef;
161
+ callers: McpSymbolRef[];
162
+ callees: McpSymbolRef[];
163
+ error?: {
164
+ code: McpErrorCode;
165
+ message: string;
166
+ details?: Record<string, unknown>;
167
+ };
168
+ }
169
+
170
+ interface McpImpactResult {
171
+ status: McpToolStatus;
172
+ confidence: McpToolConfidence;
173
+ graph_status: McpGraphStatus;
174
+ generated_at: string | null;
175
+ failed_file_count: number;
176
+ parse_failure_files: string[];
177
+ root_symbol?: McpSymbolRef;
178
+ affected_symbols: Array<{
179
+ symbol: McpSymbolRef;
180
+ depth: number;
181
+ path: string[];
182
+ }>;
183
+ depth: number;
184
+ limit: number;
185
+ truncated: boolean;
186
+ error?: {
187
+ code: McpErrorCode;
188
+ message: string;
189
+ details?: Record<string, unknown>;
190
+ };
191
+ }
192
+ ```
193
+
194
+ ### `codemap_query`
195
+
196
+ 输入:
197
+
198
+ ```typescript
199
+ interface CodemapQueryInput {
200
+ symbol: string;
201
+ filePath?: string;
202
+ }
203
+ ```
204
+
205
+ 语义:
206
+ - `status = "ok"`:返回 `symbol`、`callers`、`callees`
207
+ - `status = "unavailable"` + `GRAPH_NOT_FOUND`:还没生成 symbol-level 图
208
+ - `status = "not_found"` + `SYMBOL_NOT_FOUND`:目标符号不存在
209
+ - `status = "ambiguous"` + `AMBIGUOUS_EDGE`:同名符号无法仅靠 `symbol` / `filePath` 消歧
210
+
211
+ ### `codemap_impact`
212
+
213
+ 输入:
214
+
215
+ ```typescript
216
+ interface CodemapImpactInput {
217
+ symbol: string;
218
+ filePath?: string;
219
+ depth?: number;
220
+ limit?: number;
221
+ }
222
+ ```
223
+
224
+ 语义:
225
+ - `affected_symbols` 按 caller impact 链返回,`path` 从 root symbol id 开始
226
+ - `depth` / `limit` 会被收敛到首期限额,防止 host 挂起
227
+ - `truncated = true` 说明结果已命中 `limit`
228
+
229
+ ### MCP 结果示例
230
+
231
+ ```json
232
+ {
233
+ "status": "ok",
234
+ "confidence": "high",
235
+ "graph_status": "partial",
236
+ "generated_at": "2026-04-19T00:00:00.000Z",
237
+ "failed_file_count": 1,
238
+ "parse_failure_files": ["src/broken.ts"],
239
+ "symbol": {
240
+ "id": "sym-target",
241
+ "module_id": "mod-target",
242
+ "name": "target",
243
+ "kind": "function",
244
+ "visibility": "public",
245
+ "file_path": "src/target.ts",
246
+ "line": 1,
247
+ "column": 1,
248
+ "signature": "target() => void"
249
+ },
250
+ "callers": [
251
+ {
252
+ "id": "sym-caller",
253
+ "module_id": "mod-caller",
254
+ "name": "caller",
255
+ "kind": "function",
256
+ "visibility": "public",
257
+ "file_path": "src/caller.ts",
258
+ "line": 1,
259
+ "column": 1,
260
+ "signature": "caller() => void"
261
+ }
262
+ ],
263
+ "callees": []
264
+ }
265
+ ```
266
+
267
+ ---
268
+
113
269
  ## query 命令输出结构
114
270
 
115
271
  ### JSON 输出 (-j)
@@ -211,6 +367,7 @@ interface AnalyzeOutput {
211
367
  };
212
368
  results: AnalyzeResult[];
213
369
  warnings?: AnalyzeWarning[];
370
+ diagnostics?: AnalyzeDiagnostics;
214
371
  analysis?: ReadAnalysis | LinkAnalysis | ShowAnalysis;
215
372
  metadata: {
216
373
  total: number;
@@ -219,13 +376,35 @@ interface AnalyzeOutput {
219
376
  };
220
377
  }
221
378
 
379
+ interface AnalyzeDiagnostics {
380
+ status: "success" | "partialFailure" | "failure";
381
+ items: AnalyzeDiagnostic[];
382
+ failedTools?: string[];
383
+ degradedTools?: string[];
384
+ }
385
+
386
+ interface AnalyzeDiagnostic {
387
+ code: string;
388
+ severity: "info" | "warning" | "error";
389
+ message: string;
390
+ source: string;
391
+ recoverable: boolean;
392
+ details?: Record<string, unknown>;
393
+ }
394
+
222
395
  interface AnalyzeWarning {
223
- code: "deprecated-intent";
396
+ code:
397
+ | "deprecated-intent"
398
+ | "git-history-unavailable"
399
+ | "git-history-precompute-recommended"
400
+ | "git-history-stale"
401
+ | "git-history-unsupported-intent";
224
402
  severity: "warning";
225
403
  message: string;
226
- deprecatedIntent: "impact" | "dependency" | "search" | "documentation" | "complexity" | "overview" | "reference";
227
- replacementIntent: AnalyzeIntent;
228
- sunsetPolicy: "2-minor-window";
404
+ details?: Record<string, string | number | boolean | null>;
405
+ deprecatedIntent?: "impact" | "dependency" | "search" | "documentation" | "complexity" | "overview" | "reference";
406
+ replacementIntent?: AnalyzeIntent;
407
+ sunsetPolicy?: "2-minor-window";
229
408
  }
230
409
 
231
410
  interface AnalyzeResult {
@@ -241,6 +420,15 @@ interface AnalyzeResult {
241
420
  testFile?: string; // 关联的测试文件
242
421
  dependencies?: string[];
243
422
  impactCount?: number;
423
+ historyRisk?: {
424
+ status: "ok" | "ambiguous" | "not_found" | "unavailable";
425
+ level: "high" | "medium" | "low" | "unavailable";
426
+ confidence: "high" | "medium" | "low" | "unavailable";
427
+ freshness: "fresh" | "stale" | "expired" | "unknown";
428
+ score: number | null;
429
+ factors: string[];
430
+ analyzedAt: string | null;
431
+ };
244
432
  complexityMetrics?: {
245
433
  cyclomatic: number;
246
434
  cognitive: number;
@@ -269,6 +457,22 @@ interface ReadAnalysis {
269
457
  };
270
458
  risk: "high" | "medium" | "low";
271
459
  }>;
460
+ history?: Array<{
461
+ file: string;
462
+ status: "ok" | "ambiguous" | "not_found" | "unavailable";
463
+ confidence: "high" | "medium" | "low" | "unavailable";
464
+ freshness: "fresh" | "stale" | "expired" | "unknown";
465
+ source: "git-live" | "sqlite-materialized" | "sqlite-cache" | "unavailable";
466
+ scopeMode: "full" | "partial" | "top-files-only" | "precompute-required";
467
+ analyzedAt: string | null;
468
+ risk: {
469
+ level: "high" | "medium" | "low" | "unavailable";
470
+ score: number | null;
471
+ gravity: number | null;
472
+ impact: number | null;
473
+ factors: string[];
474
+ };
475
+ }>;
272
476
  }
273
477
 
274
478
  interface LinkAnalysis {
@@ -301,6 +505,13 @@ interface ShowAnalysis {
301
505
  }
302
506
  ```
303
507
 
508
+ ### analyze find failure semantics
509
+
510
+ - `diagnostics.status = "success"` 且 `results=[]`:扫描链路可信完成,表示真实 0 命中。
511
+ - `diagnostics.status = "partialFailure"`:主扫描退化,但配置感知 fallback 已返回可用结果;读取 `degradedTools[]` 和 `items[]`。
512
+ - `diagnostics.status = "failure"`:主扫描与 fallback 都失败,不能把 `results=[]` 当作“代码不存在”;JSON/machine 模式会设置非零 exit code。
513
+ - 通用查找默认仍推荐 `query -S "XXX" -j`;`analyze -i find -k "XXX" --json --structured` 用于需要统一 analyze schema 与 diagnostics 的 Agent 流程。
514
+
304
515
  ### 纯结构化输出 (--structured --json)
305
516
 
306
517
  移除了 `content` 字段,只保留结构化数据:
@@ -375,7 +586,16 @@ interface StructuredResult {
375
586
  "dependencies": [
376
587
  "src/orchestrator/intent-router.ts"
377
588
  ],
378
- "riskLevel": "medium"
589
+ "riskLevel": "medium",
590
+ "historyRisk": {
591
+ "status": "ok",
592
+ "level": "high",
593
+ "confidence": "high",
594
+ "freshness": "fresh",
595
+ "score": 0.82,
596
+ "factors": ["recent bugfixes"],
597
+ "analyzedAt": "2026-04-15T00:00:00.000Z"
598
+ }
379
599
  }
380
600
  }
381
601
  ],
@@ -393,6 +613,24 @@ interface StructuredResult {
393
613
  "impactCount": 3,
394
614
  "risk": "medium"
395
615
  }
616
+ ],
617
+ "history": [
618
+ {
619
+ "file": "src/cli/commands/analyze.ts",
620
+ "status": "ok",
621
+ "confidence": "high",
622
+ "freshness": "fresh",
623
+ "source": "git-live",
624
+ "scopeMode": "full",
625
+ "analyzedAt": "2026-04-15T00:00:00.000Z",
626
+ "risk": {
627
+ "level": "high",
628
+ "score": 0.82,
629
+ "gravity": 0.6,
630
+ "impact": 0.8,
631
+ "factors": ["recent bugfixes"]
632
+ }
633
+ }
396
634
  ]
397
635
  },
398
636
  "metadata": {
@@ -425,7 +663,14 @@ type DesignContractDiagnosticCode =
425
663
  | "duplicate-section"
426
664
  | "empty-section"
427
665
  | "unknown-section"
428
- | "ambiguous-heading";
666
+ | "ambiguous-heading"
667
+ | "invalid-frontmatter"
668
+ | "invalid-rules-root"
669
+ | "invalid-rule-type"
670
+ | "missing-rule-field"
671
+ | "invalid-rule-severity"
672
+ | "unknown-rule-field"
673
+ | "unknown-frontmatter-field";
429
674
 
430
675
  interface DesignValidateOutput {
431
676
  ok: boolean;
@@ -434,6 +679,11 @@ interface DesignValidateOutput {
434
679
  title?: string;
435
680
  missingRequiredSections: Array<"goal" | "constraints" | "acceptanceCriteria" | "nonGoals">;
436
681
  diagnostics: DesignContractDiagnostic[];
682
+ rules: Array<{
683
+ name: string;
684
+ type: "layer_direction" | "forbidden_imports" | "module_public_api_only";
685
+ severity: "error" | "warn";
686
+ }>;
437
687
  sections: Array<{
438
688
  id: DesignContractSectionId;
439
689
  title: string;
@@ -464,6 +714,7 @@ interface DesignContractDiagnostic {
464
714
  "missingRequiredSections": [
465
715
  "acceptanceCriteria"
466
716
  ],
717
+ "rules": [],
467
718
  "diagnostics": [
468
719
  {
469
720
  "code": "missing-section",
@@ -487,6 +738,225 @@ interface DesignContractDiagnostic {
487
738
 
488
739
  ---
489
740
 
741
+ ## check 命令输出结构
742
+
743
+ ### JSON 输出(默认)
744
+
745
+ ```typescript
746
+ interface ContractCheckResult {
747
+ passed: boolean;
748
+ scan_mode: "full" | "diff";
749
+ contract_path: string;
750
+ against_path: string;
751
+ changed_files: string[];
752
+ scanned_files: string[];
753
+ warnings: Array<{
754
+ code: string;
755
+ message: string;
756
+ details?: Record<string, string | number | boolean | null>;
757
+ }>;
758
+ history?: {
759
+ status: "ok" | "ambiguous" | "not_found" | "unavailable";
760
+ confidence: "high" | "medium" | "low" | "unavailable";
761
+ freshness: "fresh" | "stale" | "expired" | "unknown";
762
+ scope_mode: "full" | "partial" | "top-files-only" | "precompute-required";
763
+ enriched_file_count: number;
764
+ unavailable_count: number;
765
+ stale_count: number;
766
+ low_confidence_count: number;
767
+ requires_precompute: boolean;
768
+ };
769
+ violations: Array<{
770
+ rule: string;
771
+ rule_type: "layer_direction" | "forbidden_imports" | "module_public_api_only" | "complexity_threshold";
772
+ severity: "error" | "warn";
773
+ location: string;
774
+ message: string;
775
+ dependency_chain: string[];
776
+ hard_fail: boolean;
777
+ diagnostic?: {
778
+ file?: string;
779
+ line?: number;
780
+ column?: number;
781
+ endLine?: number;
782
+ endColumn?: number;
783
+ scope: "line" | "file" | "general";
784
+ source: "dependency-cruiser" | "custom-evaluator";
785
+ category: "dependency" | "module_boundary" | "complexity";
786
+ degraded: boolean;
787
+ };
788
+ risk?: {
789
+ status: "ok" | "ambiguous" | "not_found" | "unavailable";
790
+ level: "high" | "medium" | "low" | "unavailable";
791
+ confidence: "high" | "medium" | "low" | "unavailable";
792
+ freshness: "fresh" | "stale" | "expired" | "unknown";
793
+ score: number | null;
794
+ factors: string[];
795
+ analyzed_at: string | null;
796
+ };
797
+ }>;
798
+ summary: {
799
+ total_violations: number;
800
+ error_count: number;
801
+ warn_count: number;
802
+ scanned_file_count: number;
803
+ rule_count: number;
804
+ };
805
+ }
806
+ ```
807
+
808
+ ### 示例
809
+
810
+ ```json
811
+ {
812
+ "passed": false,
813
+ "scan_mode": "diff",
814
+ "contract_path": "/repo/mycodemap.design.md",
815
+ "against_path": "src",
816
+ "changed_files": ["src/domain/index.ts"],
817
+ "scanned_files": ["src/app/use-domain.ts", "src/domain/index.ts"],
818
+ "warnings": [
819
+ {
820
+ "code": "hard-gate-window-exceeded",
821
+ "message": "changed files=11 超出 calibrated hard-gate window <=10",
822
+ "details": {
823
+ "calibrated": false,
824
+ "changed_files": 11,
825
+ "max_changed_files": 10,
826
+ "recommended_mode": "warn-only"
827
+ }
828
+ }
829
+ ],
830
+ "history": {
831
+ "status": "ok",
832
+ "confidence": "high",
833
+ "freshness": "fresh",
834
+ "scope_mode": "full",
835
+ "enriched_file_count": 1,
836
+ "unavailable_count": 0,
837
+ "stale_count": 0,
838
+ "low_confidence_count": 0,
839
+ "requires_precompute": false
840
+ },
841
+ "violations": [
842
+ {
843
+ "rule": "app 不可依赖 domain barrel",
844
+ "rule_type": "layer_direction",
845
+ "severity": "error",
846
+ "location": "src/app/use-domain.ts",
847
+ "message": "src/app/use-domain.ts 依赖 src/domain/index.ts,违反规则 app 不可依赖 domain barrel",
848
+ "dependency_chain": ["src/app/use-domain.ts", "src/domain/index.ts"],
849
+ "hard_fail": true,
850
+ "diagnostic": {
851
+ "file": "src/app/use-domain.ts",
852
+ "line": 3,
853
+ "column": 1,
854
+ "scope": "line",
855
+ "source": "dependency-cruiser",
856
+ "category": "dependency",
857
+ "degraded": false
858
+ },
859
+ "risk": {
860
+ "status": "ok",
861
+ "level": "high",
862
+ "confidence": "high",
863
+ "freshness": "fresh",
864
+ "score": 0.88,
865
+ "factors": ["recent bugfixes", "high blast radius"],
866
+ "analyzed_at": "2026-04-15T00:00:00.000Z"
867
+ }
868
+ }
869
+ ],
870
+ "summary": {
871
+ "total_violations": 1,
872
+ "error_count": 1,
873
+ "warn_count": 0,
874
+ "scanned_file_count": 2,
875
+ "rule_count": 1
876
+ }
877
+ }
878
+ ```
879
+
880
+ > `check` 默认就是纯 JSON;`--human` 只改变渲染,不改变底层 `ContractCheckResult` truth。
881
+ > Git history risk 是 additive enrichment:它补充 `history` 与 `violations[].risk`,但不会改变 `severity:error` / exit 语义。history 不可用时应显式返回 `unavailable` / warning,而不是伪装成低风险。
882
+ > CI-native truth:PR 默认 hard gate 仅在 calibration 通过且 `changed files <= 10` 时启用;若出现 `diff-scope-fallback`、`hard-gate-window-exceeded` 或 `false-positive rate >10%`,CI 必须回退 `warn-only / fallback`。校准命令:`node scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10`
883
+
884
+ ### Annotation-friendly diagnostics
885
+
886
+ ```typescript
887
+ interface ContractViolationDiagnostic {
888
+ file?: string;
889
+ line?: number;
890
+ column?: number;
891
+ endLine?: number;
892
+ endColumn?: number;
893
+ scope: "line" | "file" | "general";
894
+ source: "dependency-cruiser" | "custom-evaluator";
895
+ category: "dependency" | "module_boundary" | "complexity";
896
+ degraded: boolean;
897
+ }
898
+
899
+ type ContractGateRecommendation = "hard-gate-ok" | "warn-only" | "re-scope";
900
+
901
+ interface GitLabContractAnnotation {
902
+ description: string;
903
+ check_name: string;
904
+ fingerprint: string;
905
+ severity: "major" | "minor";
906
+ location: {
907
+ path: string;
908
+ lines: {
909
+ begin: number;
910
+ };
911
+ };
912
+ }
913
+ ```
914
+
915
+ - `--annotation-format github` 会直接输出 GitHub Actions annotations;允许 file-scoped degraded diagnostics,但不会伪造不存在的行号。
916
+ - `--annotation-format gitlab --annotation-file gl-code-quality-report.json` 会输出 GitLab Code Quality artifact;只包含 `scope="line"` 且有 `line` 的 diagnostics。
917
+ - `recommended_mode` 是 CI 编排 truth:当 calibration 失败、`changed files <= 10` 条件不满足或 false-positive 漂移时,workflow 必须走 `warn-only / fallback`。
918
+
919
+ ---
920
+
921
+ ## history 命令输出结构
922
+
923
+ ### JSON 输出(默认)
924
+
925
+ ```typescript
926
+ interface HistoryCommandResult {
927
+ query: string;
928
+ status: "ok" | "ambiguous" | "not_found" | "unavailable";
929
+ symbol: null | {
930
+ name: string;
931
+ kind: string;
932
+ file: string;
933
+ line: number;
934
+ };
935
+ candidates: Array<{
936
+ symbolId: string;
937
+ name: string;
938
+ file: string;
939
+ line: number;
940
+ }>;
941
+ files: string[];
942
+ warnings: string[];
943
+ risk: {
944
+ level: "high" | "medium" | "low" | "unavailable";
945
+ score: number | null;
946
+ riskFactors: string[];
947
+ };
948
+ }
949
+ ```
950
+
951
+ ### 失败语义
952
+
953
+ - `ok`: 找到唯一 symbol,并返回 timeline + risk
954
+ - `ambiguous`: 找到多个候选 symbol,不自动合并
955
+ - `not_found`: storage 中找不到 symbol
956
+ - `unavailable`: Git history 不可用或无持久化快照
957
+
958
+ ---
959
+
490
960
  ## design map 命令输出结构
491
961
 
492
962
  ### JSON 输出 (--json)
@@ -170,6 +170,9 @@ node dist/cli/index.js ci check-headers
170
170
  # Step 3: 评估变更风险
171
171
  node dist/cli/index.js ci assess-risk
172
172
 
173
+ # Step 3.5: 需要看某个符号为什么危险 / 最近谁改过时
174
+ node dist/cli/index.js history --symbol createCheckCommand
175
+
173
176
  # Step 4: 检查输出契约(如果修改了 analyze)
174
177
  node dist/cli/index.js ci check-output-contract
175
178
 
@@ -180,6 +183,8 @@ node dist/cli/index.js ci check-docs-sync
180
183
  npm test
181
184
  ```
182
185
 
186
+ > `ci assess-risk`、`check`、`history` 共用同一套 Git history risk truth;若历史不可用,输出会显式返回 `unavailable` / warning,而不是默默降成低风险。
187
+
183
188
  ---
184
189
 
185
190
  ### 模式 F: 复杂分析任务(analysis-only workflow)
@@ -201,6 +206,12 @@ node dist/cli/index.js design handoff mycodemap.design.md --json
201
206
  # Step 0.9: 基于 reviewed handoff truth 做 verification / drift 检查
202
207
  node dist/cli/index.js design verify mycodemap.design.md --json
203
208
 
209
+ # Step 0.95: 先校准当前仓库是否还能默认 hard gate
210
+ node scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10
211
+
212
+ # Step 0.97: 如果需要把 contract 变成 PR 门禁,显式输出 GitHub annotations
213
+ node dist/cli/index.js check --contract mycodemap.design.md --against src --base origin/main --annotation-format github
214
+
204
215
  # Step 1: 启动工作流
205
216
  node dist/cli/index.js workflow start "实现用户认证模块"
206
217
 
@@ -227,11 +238,33 @@ node dist/cli/index.js workflow checkpoint
227
238
  3. `link` - 汇总依赖、引用与关联关系
228
239
  4. `show` - 生成概览、摘要与展示型结果
229
240
 
230
- > 说明:`workflow` 仍只保留 `find` / `read` / `link` / `show` 四阶段;如果任务由人类设计驱动,先走 `design validate → design map → design handoff → design verify` 固定输入、候选范围、review gate 与 drift 检查,再进入 workflow。
241
+ > 说明:`workflow` 仍只保留 `find` / `read` / `link` / `show` 四阶段;如果任务由人类设计驱动,先走 `design validate → design map → design handoff → design verify` 固定输入、候选范围、review gate 与 drift 检查;若还需要执行仓库级代码门禁,先校准再显式运行 `check`。
242
+
243
+ ### 模式 G: CI-native contract gate
244
+
245
+ **适用场景**: 需要把 `mycodemap.design.md` 真正接进 PR / CI,同时保持 annotation 可见且避免 noisy hard gate
246
+
247
+ **执行步骤**:
248
+
249
+ ```bash
250
+ # Step 1: 校准当前仓库的 hard-gate 窗口
251
+ node scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10
252
+
253
+ # Step 2: 在 GitHub PR 中输出 annotation-friendly diagnostics
254
+ node dist/cli/index.js check --contract mycodemap.design.md --against src --base origin/main --annotation-format github
255
+
256
+ # Step 3: 如需 GitLab artifact,写出 line-scoped code-quality 报告
257
+ node dist/cli/index.js check --contract mycodemap.design.md --against src --base origin/main --annotation-format gitlab --annotation-file gl-code-quality-report.json
258
+ ```
259
+
260
+ **决策要点**:
261
+ - PR 默认 hard gate 只在 calibration 通过且 `changed files <= 10` 时开启。
262
+ - 超过窗口、出现 `diff-scope-fallback`,或 `false-positive rate >10%` 时必须显式退回 `warn-only / fallback`。
263
+ - GitHub 允许 file-scoped degraded diagnostics;GitLab 只应输出 line-scoped diagnostics,不伪造行号。
231
264
 
232
265
  ---
233
266
 
234
- ### 模式 G: 切换图存储后端
267
+ ### 模式 H: 切换图存储后端
235
268
 
236
269
  **适用场景**: 需要把 CodeGraph 从默认文件系统存储切到 KùzuDB,或验证 graph backend 是否真正生效
237
270
 
@@ -244,24 +277,21 @@ cat mycodemap.config.json
244
277
  # Step 2: 选择后端
245
278
  # {
246
279
  # "storage": {
247
- # "type": "kuzudb",
248
- # "databasePath": ".codemap/kuzu"
280
+ # "type": "sqlite",
281
+ # "databasePath": ".codemap/governance.sqlite"
249
282
  # }
250
283
  # }
251
284
 
252
- # Step 3: 如需 Kùzu 图数据库后端,安装可选依赖
253
- npm install kuzu
254
-
255
- # Step 4: 重新生成代码地图
285
+ # Step 3: 重新生成代码地图
256
286
  node dist/cli/index.js generate
257
287
 
258
- # Step 5: 验证同一 backend 可被读取
288
+ # Step 4: 验证同一 backend 可被读取
259
289
  node dist/cli/index.js export json -o /tmp/codemap.json
260
290
  ```
261
291
 
262
292
  **决策要点**:
263
- - 旧的 `neo4j` 配置现在应该直接报迁移错误;缺少 `kuzu` 时也应看到显式错误,而不是静默 fallback。
264
- - `storage.type = "auto"` 当前仍保守落到 `filesystem`,不要把阈值字段误读成已上线自动切换。
293
+ - 旧的 `neo4j` / `kuzudb` 配置现在应该直接报迁移错误;显式 `sqlite` 但运行时不满足条件时也应看到显式错误,而不是静默 fallback。
294
+ - `storage.type = "auto"` 当前优先落到 `sqlite`;只有 SQLite 不可用时才回退 `filesystem`,不要把阈值字段误读成更复杂的调度器。
265
295
  - 图存储生产化只收口存储面,不重新开放公共 HTTP API 产品面。
266
296
 
267
297
  ---