spectra-cli 4.1.1 → 4.3.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 (682) hide show
  1. package/README.md +12 -5
  2. package/dist/.spectra-build-meta.json +9 -0
  3. package/dist/adapters/go-adapter.d.ts.map +1 -1
  4. package/dist/adapters/go-adapter.js +2 -0
  5. package/dist/adapters/go-adapter.js.map +1 -1
  6. package/dist/adapters/index.d.ts +1 -1
  7. package/dist/adapters/index.d.ts.map +1 -1
  8. package/dist/adapters/java-adapter.d.ts.map +1 -1
  9. package/dist/adapters/java-adapter.js +2 -0
  10. package/dist/adapters/java-adapter.js.map +1 -1
  11. package/dist/adapters/language-adapter.d.ts +42 -9
  12. package/dist/adapters/language-adapter.d.ts.map +1 -1
  13. package/dist/adapters/python-adapter.d.ts +34 -6
  14. package/dist/adapters/python-adapter.d.ts.map +1 -1
  15. package/dist/adapters/python-adapter.js +168 -61
  16. package/dist/adapters/python-adapter.js.map +1 -1
  17. package/dist/adapters/ts-js-adapter.d.ts +13 -5
  18. package/dist/adapters/ts-js-adapter.d.ts.map +1 -1
  19. package/dist/adapters/ts-js-adapter.js +55 -14
  20. package/dist/adapters/ts-js-adapter.js.map +1 -1
  21. package/dist/batch/batch-orchestrator.d.ts +74 -5
  22. package/dist/batch/batch-orchestrator.d.ts.map +1 -1
  23. package/dist/batch/batch-orchestrator.js +583 -70
  24. package/dist/batch/batch-orchestrator.js.map +1 -1
  25. package/dist/batch/delta-regenerator.d.ts +2 -2
  26. package/dist/batch/delta-regenerator.d.ts.map +1 -1
  27. package/dist/batch/delta-regenerator.js +21 -28
  28. package/dist/batch/delta-regenerator.js.map +1 -1
  29. package/dist/batch/module-grouper.d.ts +9 -2
  30. package/dist/batch/module-grouper.d.ts.map +1 -1
  31. package/dist/batch/module-grouper.js +3 -1
  32. package/dist/batch/module-grouper.js.map +1 -1
  33. package/dist/batch/regen-plan.d.ts +78 -0
  34. package/dist/batch/regen-plan.d.ts.map +1 -0
  35. package/dist/batch/regen-plan.js +93 -0
  36. package/dist/batch/regen-plan.js.map +1 -0
  37. package/dist/cli/commands/batch.d.ts.map +1 -1
  38. package/dist/cli/commands/batch.js +36 -8
  39. package/dist/cli/commands/batch.js.map +1 -1
  40. package/dist/cli/commands/graph.js +1 -1
  41. package/dist/cli/commands/graph.js.map +1 -1
  42. package/dist/cli/commands/index.d.ts +8 -0
  43. package/dist/cli/commands/index.d.ts.map +1 -0
  44. package/dist/cli/commands/index.js +274 -0
  45. package/dist/cli/commands/index.js.map +1 -0
  46. package/dist/cli/commands/query.d.ts.map +1 -1
  47. package/dist/cli/commands/query.js +3 -1
  48. package/dist/cli/commands/query.js.map +1 -1
  49. package/dist/cli/commands/scaffold-kb.d.ts +9 -0
  50. package/dist/cli/commands/scaffold-kb.d.ts.map +1 -0
  51. package/dist/cli/commands/scaffold-kb.js +179 -0
  52. package/dist/cli/commands/scaffold-kb.js.map +1 -0
  53. package/dist/cli/index.js +33 -14
  54. package/dist/cli/index.js.map +1 -1
  55. package/dist/cli/utils/error-handler.d.ts +0 -6
  56. package/dist/cli/utils/error-handler.d.ts.map +1 -1
  57. package/dist/cli/utils/error-handler.js +0 -13
  58. package/dist/cli/utils/error-handler.js.map +1 -1
  59. package/dist/cli/utils/parse-args.d.ts +55 -3
  60. package/dist/cli/utils/parse-args.d.ts.map +1 -1
  61. package/dist/cli/utils/parse-args.js +176 -13
  62. package/dist/cli/utils/parse-args.js.map +1 -1
  63. package/dist/cli/version-meta.d.ts +16 -0
  64. package/dist/cli/version-meta.d.ts.map +1 -0
  65. package/dist/cli/version-meta.js +28 -0
  66. package/dist/cli/version-meta.js.map +1 -0
  67. package/dist/core/ast-analyzer.d.ts.map +1 -1
  68. package/dist/core/ast-analyzer.js +75 -5
  69. package/dist/core/ast-analyzer.js.map +1 -1
  70. package/dist/core/import-resolver.d.ts +93 -0
  71. package/dist/core/import-resolver.d.ts.map +1 -0
  72. package/dist/core/import-resolver.js +414 -0
  73. package/dist/core/import-resolver.js.map +1 -0
  74. package/dist/core/query-mappers/base-mapper.d.ts +13 -0
  75. package/dist/core/query-mappers/base-mapper.d.ts.map +1 -1
  76. package/dist/core/query-mappers/go-mapper.d.ts +68 -0
  77. package/dist/core/query-mappers/go-mapper.d.ts.map +1 -1
  78. package/dist/core/query-mappers/go-mapper.js +421 -0
  79. package/dist/core/query-mappers/go-mapper.js.map +1 -1
  80. package/dist/core/query-mappers/java-mapper.d.ts +196 -0
  81. package/dist/core/query-mappers/java-mapper.d.ts.map +1 -1
  82. package/dist/core/query-mappers/java-mapper.js +600 -0
  83. package/dist/core/query-mappers/java-mapper.js.map +1 -1
  84. package/dist/core/query-mappers/python-mapper.d.ts +55 -0
  85. package/dist/core/query-mappers/python-mapper.d.ts.map +1 -1
  86. package/dist/core/query-mappers/python-mapper.js +273 -0
  87. package/dist/core/query-mappers/python-mapper.js.map +1 -1
  88. package/dist/core/query-mappers/typescript-mapper.d.ts +102 -0
  89. package/dist/core/query-mappers/typescript-mapper.d.ts.map +1 -1
  90. package/dist/core/query-mappers/typescript-mapper.js +470 -0
  91. package/dist/core/query-mappers/typescript-mapper.js.map +1 -1
  92. package/dist/core/single-spec-orchestrator.d.ts +21 -0
  93. package/dist/core/single-spec-orchestrator.d.ts.map +1 -1
  94. package/dist/core/single-spec-orchestrator.js +187 -23
  95. package/dist/core/single-spec-orchestrator.js.map +1 -1
  96. package/dist/core/skeleton-hash.d.ts +33 -0
  97. package/dist/core/skeleton-hash.d.ts.map +1 -0
  98. package/dist/core/skeleton-hash.js +76 -0
  99. package/dist/core/skeleton-hash.js.map +1 -0
  100. package/dist/core/tree-sitter-analyzer.d.ts +7 -0
  101. package/dist/core/tree-sitter-analyzer.d.ts.map +1 -1
  102. package/dist/core/tree-sitter-analyzer.js +32 -1
  103. package/dist/core/tree-sitter-analyzer.js.map +1 -1
  104. package/dist/core/tree-sitter-fallback.d.ts +12 -4
  105. package/dist/core/tree-sitter-fallback.d.ts.map +1 -1
  106. package/dist/core/tree-sitter-fallback.js +160 -12
  107. package/dist/core/tree-sitter-fallback.js.map +1 -1
  108. package/dist/extraction/extraction-types.d.ts +25 -25
  109. package/dist/extraction/image-extractor.d.ts.map +1 -1
  110. package/dist/extraction/image-extractor.js +3 -1
  111. package/dist/extraction/image-extractor.js.map +1 -1
  112. package/dist/extraction/markdown-extractor.d.ts.map +1 -1
  113. package/dist/extraction/markdown-extractor.js +3 -1
  114. package/dist/extraction/markdown-extractor.js.map +1 -1
  115. package/dist/generator/frontmatter.d.ts +5 -0
  116. package/dist/generator/frontmatter.d.ts.map +1 -1
  117. package/dist/generator/frontmatter.js +4 -0
  118. package/dist/generator/frontmatter.js.map +1 -1
  119. package/dist/generator/index-generator.d.ts +3 -3
  120. package/dist/generator/index-generator.d.ts.map +1 -1
  121. package/dist/generator/index-generator.js +1 -1
  122. package/dist/generator/index-generator.js.map +1 -1
  123. package/dist/graph/directory-graph.d.ts +14 -4
  124. package/dist/graph/directory-graph.d.ts.map +1 -1
  125. package/dist/graph/directory-graph.js +71 -128
  126. package/dist/graph/directory-graph.js.map +1 -1
  127. package/dist/graph/mermaid-renderer.d.ts +8 -5
  128. package/dist/graph/mermaid-renderer.d.ts.map +1 -1
  129. package/dist/graph/mermaid-renderer.js +3 -3
  130. package/dist/graph/mermaid-renderer.js.map +1 -1
  131. package/dist/graph/topological-sort.d.ts +13 -6
  132. package/dist/graph/topological-sort.d.ts.map +1 -1
  133. package/dist/graph/topological-sort.js +2 -2
  134. package/dist/graph/topological-sort.js.map +1 -1
  135. package/dist/kb-mcp/index.d.ts +14 -0
  136. package/dist/kb-mcp/index.d.ts.map +1 -0
  137. package/dist/kb-mcp/index.js +24 -0
  138. package/dist/kb-mcp/index.js.map +1 -0
  139. package/dist/kb-mcp/lib/kb-error.d.ts +21 -0
  140. package/dist/kb-mcp/lib/kb-error.d.ts.map +1 -0
  141. package/dist/kb-mcp/lib/kb-error.js +28 -0
  142. package/dist/kb-mcp/lib/kb-error.js.map +1 -0
  143. package/dist/kb-mcp/lib/kb-locator.d.ts +58 -0
  144. package/dist/kb-mcp/lib/kb-locator.d.ts.map +1 -0
  145. package/dist/kb-mcp/lib/kb-locator.js +85 -0
  146. package/dist/kb-mcp/lib/kb-locator.js.map +1 -0
  147. package/dist/kb-mcp/lib/result-merger.d.ts +35 -0
  148. package/dist/kb-mcp/lib/result-merger.d.ts.map +1 -0
  149. package/dist/kb-mcp/lib/result-merger.js +64 -0
  150. package/dist/kb-mcp/lib/result-merger.js.map +1 -0
  151. package/dist/kb-mcp/server.d.ts +12 -0
  152. package/dist/kb-mcp/server.d.ts.map +1 -0
  153. package/dist/kb-mcp/server.js +29 -0
  154. package/dist/kb-mcp/server.js.map +1 -0
  155. package/dist/kb-mcp/tools/kb-api-lookup.d.ts +28 -0
  156. package/dist/kb-mcp/tools/kb-api-lookup.d.ts.map +1 -0
  157. package/dist/kb-mcp/tools/kb-api-lookup.js +237 -0
  158. package/dist/kb-mcp/tools/kb-api-lookup.js.map +1 -0
  159. package/dist/kb-mcp/tools/kb-doc-lookup.d.ts +20 -0
  160. package/dist/kb-mcp/tools/kb-doc-lookup.d.ts.map +1 -0
  161. package/dist/kb-mcp/tools/kb-doc-lookup.js +92 -0
  162. package/dist/kb-mcp/tools/kb-doc-lookup.js.map +1 -0
  163. package/dist/kb-mcp/tools/kb-search.d.ts +23 -0
  164. package/dist/kb-mcp/tools/kb-search.d.ts.map +1 -0
  165. package/dist/kb-mcp/tools/kb-search.js +126 -0
  166. package/dist/kb-mcp/tools/kb-search.js.map +1 -0
  167. package/dist/knowledge-graph/call-resolver.d.ts +64 -0
  168. package/dist/knowledge-graph/call-resolver.d.ts.map +1 -0
  169. package/dist/knowledge-graph/call-resolver.js +323 -0
  170. package/dist/knowledge-graph/call-resolver.js.map +1 -0
  171. package/dist/knowledge-graph/import-resolver.d.ts +39 -0
  172. package/dist/knowledge-graph/import-resolver.d.ts.map +1 -0
  173. package/dist/knowledge-graph/import-resolver.js +214 -0
  174. package/dist/knowledge-graph/import-resolver.js.map +1 -0
  175. package/dist/knowledge-graph/incremental.d.ts +131 -0
  176. package/dist/knowledge-graph/incremental.d.ts.map +1 -0
  177. package/dist/knowledge-graph/incremental.js +432 -0
  178. package/dist/knowledge-graph/incremental.js.map +1 -0
  179. package/dist/knowledge-graph/index.d.ts +85 -0
  180. package/dist/knowledge-graph/index.d.ts.map +1 -0
  181. package/dist/knowledge-graph/index.js +198 -0
  182. package/dist/knowledge-graph/index.js.map +1 -0
  183. package/dist/knowledge-graph/module-derivation.d.ts +252 -0
  184. package/dist/knowledge-graph/module-derivation.d.ts.map +1 -0
  185. package/dist/knowledge-graph/module-derivation.js +418 -0
  186. package/dist/knowledge-graph/module-derivation.js.map +1 -0
  187. package/dist/knowledge-graph/persistence.d.ts +310 -0
  188. package/dist/knowledge-graph/persistence.d.ts.map +1 -0
  189. package/dist/knowledge-graph/persistence.js +280 -0
  190. package/dist/knowledge-graph/persistence.js.map +1 -0
  191. package/dist/knowledge-graph/query-helpers.d.ts +191 -0
  192. package/dist/knowledge-graph/query-helpers.d.ts.map +1 -0
  193. package/dist/knowledge-graph/query-helpers.js +559 -0
  194. package/dist/knowledge-graph/query-helpers.js.map +1 -0
  195. package/dist/knowledge-graph/relativize.d.ts +51 -0
  196. package/dist/knowledge-graph/relativize.d.ts.map +1 -0
  197. package/dist/knowledge-graph/relativize.js +104 -0
  198. package/dist/knowledge-graph/relativize.js.map +1 -0
  199. package/dist/knowledge-graph/unified-graph.d.ts +310 -0
  200. package/dist/knowledge-graph/unified-graph.d.ts.map +1 -0
  201. package/dist/knowledge-graph/unified-graph.js +182 -0
  202. package/dist/knowledge-graph/unified-graph.js.map +1 -0
  203. package/dist/mcp/agent-context-tools.d.ts +53 -0
  204. package/dist/mcp/agent-context-tools.d.ts.map +1 -0
  205. package/dist/mcp/agent-context-tools.js +806 -0
  206. package/dist/mcp/agent-context-tools.js.map +1 -0
  207. package/dist/mcp/file-nav-tools.d.ts +42 -0
  208. package/dist/mcp/file-nav-tools.d.ts.map +1 -0
  209. package/dist/mcp/file-nav-tools.js +318 -0
  210. package/dist/mcp/file-nav-tools.js.map +1 -0
  211. package/dist/mcp/graph-tools.d.ts +22 -0
  212. package/dist/mcp/graph-tools.d.ts.map +1 -1
  213. package/dist/mcp/graph-tools.js +204 -133
  214. package/dist/mcp/graph-tools.js.map +1 -1
  215. package/dist/mcp/lib/file-nav-helpers.d.ts +128 -0
  216. package/dist/mcp/lib/file-nav-helpers.d.ts.map +1 -0
  217. package/dist/mcp/lib/file-nav-helpers.js +305 -0
  218. package/dist/mcp/lib/file-nav-helpers.js.map +1 -0
  219. package/dist/mcp/lib/response-helpers.d.ts +67 -0
  220. package/dist/mcp/lib/response-helpers.d.ts.map +1 -0
  221. package/dist/mcp/lib/response-helpers.js +103 -0
  222. package/dist/mcp/lib/response-helpers.js.map +1 -0
  223. package/dist/mcp/lib/telemetry.d.ts +69 -0
  224. package/dist/mcp/lib/telemetry.d.ts.map +1 -0
  225. package/dist/mcp/lib/telemetry.js +113 -0
  226. package/dist/mcp/lib/telemetry.js.map +1 -0
  227. package/dist/mcp/lib/tool-response.d.ts +46 -0
  228. package/dist/mcp/lib/tool-response.d.ts.map +1 -0
  229. package/dist/mcp/lib/tool-response.js +83 -0
  230. package/dist/mcp/lib/tool-response.js.map +1 -0
  231. package/dist/mcp/server.d.ts +14 -1
  232. package/dist/mcp/server.d.ts.map +1 -1
  233. package/dist/mcp/server.js +216 -158
  234. package/dist/mcp/server.js.map +1 -1
  235. package/dist/models/call-site.d.ts +68 -0
  236. package/dist/models/call-site.d.ts.map +1 -0
  237. package/dist/models/call-site.js +60 -0
  238. package/dist/models/call-site.js.map +1 -0
  239. package/dist/models/code-skeleton.d.ts +80 -6
  240. package/dist/models/code-skeleton.d.ts.map +1 -1
  241. package/dist/models/code-skeleton.js +30 -0
  242. package/dist/models/code-skeleton.js.map +1 -1
  243. package/dist/models/drift-item.d.ts +4 -4
  244. package/dist/models/module-spec.d.ts +173 -94
  245. package/dist/models/module-spec.d.ts.map +1 -1
  246. package/dist/models/module-spec.js +6 -0
  247. package/dist/models/module-spec.js.map +1 -1
  248. package/dist/panoramic/adr-decision-pipeline.d.ts +53 -0
  249. package/dist/panoramic/adr-decision-pipeline.d.ts.map +1 -0
  250. package/dist/panoramic/adr-decision-pipeline.js +685 -0
  251. package/dist/panoramic/adr-decision-pipeline.js.map +1 -0
  252. package/dist/panoramic/api-surface-generator.d.ts +56 -0
  253. package/dist/panoramic/api-surface-generator.d.ts.map +1 -0
  254. package/dist/panoramic/api-surface-generator.js +1671 -0
  255. package/dist/panoramic/api-surface-generator.js.map +1 -0
  256. package/dist/panoramic/architecture-ir-builder.d.ts +19 -0
  257. package/dist/panoramic/architecture-ir-builder.d.ts.map +1 -0
  258. package/dist/panoramic/architecture-ir-builder.js +561 -0
  259. package/dist/panoramic/architecture-ir-builder.js.map +1 -0
  260. package/dist/panoramic/architecture-ir-exporters.d.ts +7 -0
  261. package/dist/panoramic/architecture-ir-exporters.d.ts.map +1 -0
  262. package/dist/panoramic/architecture-ir-exporters.js +183 -0
  263. package/dist/panoramic/architecture-ir-exporters.js.map +1 -0
  264. package/dist/panoramic/architecture-ir-generator.d.ts +36 -0
  265. package/dist/panoramic/architecture-ir-generator.d.ts.map +1 -0
  266. package/dist/panoramic/architecture-ir-generator.js +51 -0
  267. package/dist/panoramic/architecture-ir-generator.js.map +1 -0
  268. package/dist/panoramic/architecture-ir-mermaid-adapter.d.ts +6 -0
  269. package/dist/panoramic/architecture-ir-mermaid-adapter.d.ts.map +1 -0
  270. package/dist/panoramic/architecture-ir-mermaid-adapter.js +98 -0
  271. package/dist/panoramic/architecture-ir-mermaid-adapter.js.map +1 -0
  272. package/dist/panoramic/architecture-ir-model.d.ts +87 -0
  273. package/dist/panoramic/architecture-ir-model.d.ts.map +1 -0
  274. package/dist/panoramic/architecture-ir-model.js +20 -0
  275. package/dist/panoramic/architecture-ir-model.js.map +1 -0
  276. package/dist/panoramic/architecture-narrative.d.ts +68 -0
  277. package/dist/panoramic/architecture-narrative.d.ts.map +1 -0
  278. package/dist/panoramic/architecture-narrative.js +401 -0
  279. package/dist/panoramic/architecture-narrative.js.map +1 -0
  280. package/dist/panoramic/architecture-overview-generator.d.ts +31 -0
  281. package/dist/panoramic/architecture-overview-generator.d.ts.map +1 -0
  282. package/dist/panoramic/architecture-overview-generator.js +454 -0
  283. package/dist/panoramic/architecture-overview-generator.js.map +1 -0
  284. package/dist/panoramic/architecture-overview-model.d.ts +77 -0
  285. package/dist/panoramic/architecture-overview-model.d.ts.map +1 -0
  286. package/dist/panoramic/architecture-overview-model.js +31 -0
  287. package/dist/panoramic/architecture-overview-model.js.map +1 -0
  288. package/dist/panoramic/batch-project-docs.d.ts.map +1 -1
  289. package/dist/panoramic/batch-project-docs.js +4 -2
  290. package/dist/panoramic/batch-project-docs.js.map +1 -1
  291. package/dist/panoramic/builders/component-view-builder.d.ts +25 -1
  292. package/dist/panoramic/builders/component-view-builder.d.ts.map +1 -1
  293. package/dist/panoramic/builders/component-view-builder.js +83 -3
  294. package/dist/panoramic/builders/component-view-builder.js.map +1 -1
  295. package/dist/panoramic/builders/doc-graph-builder.d.ts +15 -2
  296. package/dist/panoramic/builders/doc-graph-builder.d.ts.map +1 -1
  297. package/dist/panoramic/builders/doc-graph-builder.js +20 -0
  298. package/dist/panoramic/builders/doc-graph-builder.js.map +1 -1
  299. package/dist/panoramic/component-view-builder.d.ts +17 -0
  300. package/dist/panoramic/component-view-builder.d.ts.map +1 -0
  301. package/dist/panoramic/component-view-builder.js +652 -0
  302. package/dist/panoramic/component-view-builder.js.map +1 -0
  303. package/dist/panoramic/component-view-model.d.ts +127 -0
  304. package/dist/panoramic/component-view-model.d.ts.map +1 -0
  305. package/dist/panoramic/component-view-model.js +65 -0
  306. package/dist/panoramic/component-view-model.js.map +1 -0
  307. package/dist/panoramic/config-reference-generator.d.ts +78 -0
  308. package/dist/panoramic/config-reference-generator.d.ts.map +1 -0
  309. package/dist/panoramic/config-reference-generator.js +199 -0
  310. package/dist/panoramic/config-reference-generator.js.map +1 -0
  311. package/dist/panoramic/coverage-auditor.d.ts +95 -0
  312. package/dist/panoramic/coverage-auditor.d.ts.map +1 -0
  313. package/dist/panoramic/coverage-auditor.js +290 -0
  314. package/dist/panoramic/coverage-auditor.js.map +1 -0
  315. package/dist/panoramic/cross-package-analyzer.d.ts +112 -0
  316. package/dist/panoramic/cross-package-analyzer.d.ts.map +1 -0
  317. package/dist/panoramic/cross-package-analyzer.js +258 -0
  318. package/dist/panoramic/cross-package-analyzer.js.map +1 -0
  319. package/dist/panoramic/data-model-generator.d.ts +528 -0
  320. package/dist/panoramic/data-model-generator.d.ts.map +1 -0
  321. package/dist/panoramic/data-model-generator.js +647 -0
  322. package/dist/panoramic/data-model-generator.js.map +1 -0
  323. package/dist/panoramic/doc-graph-builder.d.ts +80 -0
  324. package/dist/panoramic/doc-graph-builder.d.ts.map +1 -0
  325. package/dist/panoramic/doc-graph-builder.js +352 -0
  326. package/dist/panoramic/doc-graph-builder.js.map +1 -0
  327. package/dist/panoramic/docs-bundle-manifest-reader.d.ts +26 -0
  328. package/dist/panoramic/docs-bundle-manifest-reader.d.ts.map +1 -0
  329. package/dist/panoramic/docs-bundle-manifest-reader.js +106 -0
  330. package/dist/panoramic/docs-bundle-manifest-reader.js.map +1 -0
  331. package/dist/panoramic/docs-bundle-orchestrator.d.ts +14 -0
  332. package/dist/panoramic/docs-bundle-orchestrator.d.ts.map +1 -0
  333. package/dist/panoramic/docs-bundle-orchestrator.js +538 -0
  334. package/dist/panoramic/docs-bundle-orchestrator.js.map +1 -0
  335. package/dist/panoramic/docs-bundle-profiles.d.ts +4 -0
  336. package/dist/panoramic/docs-bundle-profiles.d.ts.map +1 -0
  337. package/dist/panoramic/docs-bundle-profiles.js +82 -0
  338. package/dist/panoramic/docs-bundle-profiles.js.map +1 -0
  339. package/dist/panoramic/docs-bundle-types.d.ts +94 -0
  340. package/dist/panoramic/docs-bundle-types.d.ts.map +1 -0
  341. package/dist/panoramic/docs-bundle-types.js +10 -0
  342. package/dist/panoramic/docs-bundle-types.js.map +1 -0
  343. package/dist/panoramic/docs-quality-evaluator.d.ts +31 -0
  344. package/dist/panoramic/docs-quality-evaluator.d.ts.map +1 -0
  345. package/dist/panoramic/docs-quality-evaluator.js +941 -0
  346. package/dist/panoramic/docs-quality-evaluator.js.map +1 -0
  347. package/dist/panoramic/docs-quality-model.d.ts +125 -0
  348. package/dist/panoramic/docs-quality-model.d.ts.map +1 -0
  349. package/dist/panoramic/docs-quality-model.js +166 -0
  350. package/dist/panoramic/docs-quality-model.js.map +1 -0
  351. package/dist/panoramic/dynamic-scenarios-builder.d.ts +18 -0
  352. package/dist/panoramic/dynamic-scenarios-builder.d.ts.map +1 -0
  353. package/dist/panoramic/dynamic-scenarios-builder.js +316 -0
  354. package/dist/panoramic/dynamic-scenarios-builder.js.map +1 -0
  355. package/dist/panoramic/event-surface-generator.d.ts +52 -0
  356. package/dist/panoramic/event-surface-generator.d.ts.map +1 -0
  357. package/dist/panoramic/event-surface-generator.js +507 -0
  358. package/dist/panoramic/event-surface-generator.js.map +1 -0
  359. package/dist/panoramic/generator-registry.d.ts +1 -1
  360. package/dist/panoramic/generator-registry.d.ts.map +1 -1
  361. package/dist/panoramic/generator-registry.js +5 -2
  362. package/dist/panoramic/generator-registry.js.map +1 -1
  363. package/dist/panoramic/generators/cross-package-analyzer.d.ts +5 -5
  364. package/dist/panoramic/generators/cross-package-analyzer.d.ts.map +1 -1
  365. package/dist/panoramic/generators/cross-package-analyzer.js +1 -1
  366. package/dist/panoramic/generators/cross-package-analyzer.js.map +1 -1
  367. package/dist/panoramic/generators/data-model-generator.d.ts +27 -27
  368. package/dist/panoramic/graph/confidence-mapper.d.ts +18 -0
  369. package/dist/panoramic/graph/confidence-mapper.d.ts.map +1 -1
  370. package/dist/panoramic/graph/confidence-mapper.js +26 -0
  371. package/dist/panoramic/graph/confidence-mapper.js.map +1 -1
  372. package/dist/panoramic/graph/graph-builder.d.ts +72 -2
  373. package/dist/panoramic/graph/graph-builder.d.ts.map +1 -1
  374. package/dist/panoramic/graph/graph-builder.js +330 -46
  375. package/dist/panoramic/graph/graph-builder.js.map +1 -1
  376. package/dist/panoramic/graph/graph-paths.d.ts +8 -0
  377. package/dist/panoramic/graph/graph-paths.d.ts.map +1 -1
  378. package/dist/panoramic/graph/graph-paths.js +10 -0
  379. package/dist/panoramic/graph/graph-paths.js.map +1 -1
  380. package/dist/panoramic/graph/graph-query.d.ts +49 -2
  381. package/dist/panoramic/graph/graph-query.d.ts.map +1 -1
  382. package/dist/panoramic/graph/graph-query.js +117 -19
  383. package/dist/panoramic/graph/graph-query.js.map +1 -1
  384. package/dist/panoramic/graph/graph-types.d.ts +32 -3
  385. package/dist/panoramic/graph/graph-types.d.ts.map +1 -1
  386. package/dist/panoramic/graph/index.d.ts +2 -1
  387. package/dist/panoramic/graph/index.d.ts.map +1 -1
  388. package/dist/panoramic/graph/index.js +1 -1
  389. package/dist/panoramic/graph/index.js.map +1 -1
  390. package/dist/panoramic/hyperedges/schema.d.ts +6 -6
  391. package/dist/panoramic/interface-surface-generator.d.ts +50 -0
  392. package/dist/panoramic/interface-surface-generator.d.ts.map +1 -0
  393. package/dist/panoramic/interface-surface-generator.js +388 -0
  394. package/dist/panoramic/interface-surface-generator.js.map +1 -0
  395. package/dist/panoramic/interfaces.d.ts +2 -2
  396. package/dist/panoramic/mock-readme-generator.d.ts +90 -0
  397. package/dist/panoramic/mock-readme-generator.d.ts.map +1 -0
  398. package/dist/panoramic/mock-readme-generator.js +111 -0
  399. package/dist/panoramic/mock-readme-generator.js.map +1 -0
  400. package/dist/panoramic/models/component-view-model.d.ts +1 -1
  401. package/dist/panoramic/models/component-view-model.d.ts.map +1 -1
  402. package/dist/panoramic/models/component-view-model.js.map +1 -1
  403. package/dist/panoramic/narrative-provenance-adapter.d.ts +8 -0
  404. package/dist/panoramic/narrative-provenance-adapter.d.ts.map +1 -0
  405. package/dist/panoramic/narrative-provenance-adapter.js +99 -0
  406. package/dist/panoramic/narrative-provenance-adapter.js.map +1 -0
  407. package/dist/panoramic/parser-registry.d.ts +1 -1
  408. package/dist/panoramic/parser-registry.js +1 -1
  409. package/dist/panoramic/parsers/types.d.ts +6 -6
  410. package/dist/panoramic/pattern-hints-generator.d.ts +28 -0
  411. package/dist/panoramic/pattern-hints-generator.d.ts.map +1 -0
  412. package/dist/panoramic/pattern-hints-generator.js +218 -0
  413. package/dist/panoramic/pattern-hints-generator.js.map +1 -0
  414. package/dist/panoramic/pattern-hints-model.d.ts +89 -0
  415. package/dist/panoramic/pattern-hints-model.d.ts.map +1 -0
  416. package/dist/panoramic/pattern-hints-model.js +61 -0
  417. package/dist/panoramic/pattern-hints-model.js.map +1 -0
  418. package/dist/panoramic/pattern-knowledge-base.d.ts +31 -0
  419. package/dist/panoramic/pattern-knowledge-base.d.ts.map +1 -0
  420. package/dist/panoramic/pattern-knowledge-base.js +407 -0
  421. package/dist/panoramic/pattern-knowledge-base.js.map +1 -0
  422. package/dist/panoramic/pipelines/adr-evidence-verifier.d.ts.map +1 -1
  423. package/dist/panoramic/pipelines/adr-evidence-verifier.js +1 -29
  424. package/dist/panoramic/pipelines/adr-evidence-verifier.js.map +1 -1
  425. package/dist/panoramic/pipelines/coverage-auditor.d.ts.map +1 -1
  426. package/dist/panoramic/pipelines/coverage-auditor.js +4 -2
  427. package/dist/panoramic/pipelines/coverage-auditor.js.map +1 -1
  428. package/dist/panoramic/pipelines/docs-bundle-orchestrator.js +13 -6
  429. package/dist/panoramic/pipelines/docs-bundle-orchestrator.js.map +1 -1
  430. package/dist/panoramic/pipelines/product-ux-docs.d.ts +5 -0
  431. package/dist/panoramic/pipelines/product-ux-docs.d.ts.map +1 -1
  432. package/dist/panoramic/pipelines/product-ux-docs.js +34 -6
  433. package/dist/panoramic/pipelines/product-ux-docs.js.map +1 -1
  434. package/dist/panoramic/product-ux-docs.d.ts +104 -0
  435. package/dist/panoramic/product-ux-docs.d.ts.map +1 -0
  436. package/dist/panoramic/product-ux-docs.js +817 -0
  437. package/dist/panoramic/product-ux-docs.js.map +1 -0
  438. package/dist/panoramic/qa/__tests__/citation.test.d.ts +2 -0
  439. package/dist/panoramic/qa/__tests__/citation.test.d.ts.map +1 -0
  440. package/dist/panoramic/qa/__tests__/citation.test.js +193 -0
  441. package/dist/panoramic/qa/__tests__/citation.test.js.map +1 -0
  442. package/dist/panoramic/qa/__tests__/debt-context.test.d.ts +2 -0
  443. package/dist/panoramic/qa/__tests__/debt-context.test.d.ts.map +1 -0
  444. package/dist/panoramic/qa/__tests__/debt-context.test.js +154 -0
  445. package/dist/panoramic/qa/__tests__/debt-context.test.js.map +1 -0
  446. package/dist/panoramic/qa/__tests__/graph-retriever.test.d.ts +2 -0
  447. package/dist/panoramic/qa/__tests__/graph-retriever.test.d.ts.map +1 -0
  448. package/dist/panoramic/qa/__tests__/graph-retriever.test.js +148 -0
  449. package/dist/panoramic/qa/__tests__/graph-retriever.test.js.map +1 -0
  450. package/dist/panoramic/qa/__tests__/index.test.d.ts +2 -0
  451. package/dist/panoramic/qa/__tests__/index.test.d.ts.map +1 -0
  452. package/dist/panoramic/qa/__tests__/index.test.js +246 -0
  453. package/dist/panoramic/qa/__tests__/index.test.js.map +1 -0
  454. package/dist/panoramic/qa/__tests__/llm-caller.test.d.ts +2 -0
  455. package/dist/panoramic/qa/__tests__/llm-caller.test.d.ts.map +1 -0
  456. package/dist/panoramic/qa/__tests__/llm-caller.test.js +168 -0
  457. package/dist/panoramic/qa/__tests__/llm-caller.test.js.map +1 -0
  458. package/dist/panoramic/qa/__tests__/prompt-builder.test.d.ts +2 -0
  459. package/dist/panoramic/qa/__tests__/prompt-builder.test.d.ts.map +1 -0
  460. package/dist/panoramic/qa/__tests__/prompt-builder.test.js +150 -0
  461. package/dist/panoramic/qa/__tests__/prompt-builder.test.js.map +1 -0
  462. package/dist/panoramic/qa/__tests__/qa-integration.test.d.ts +2 -0
  463. package/dist/panoramic/qa/__tests__/qa-integration.test.d.ts.map +1 -0
  464. package/dist/panoramic/qa/__tests__/qa-integration.test.js +296 -0
  465. package/dist/panoramic/qa/__tests__/qa-integration.test.js.map +1 -0
  466. package/dist/panoramic/qa/__tests__/rag-reranker.test.d.ts +2 -0
  467. package/dist/panoramic/qa/__tests__/rag-reranker.test.d.ts.map +1 -0
  468. package/dist/panoramic/qa/__tests__/rag-reranker.test.js +136 -0
  469. package/dist/panoramic/qa/__tests__/rag-reranker.test.js.map +1 -0
  470. package/dist/panoramic/qa/index.d.ts.map +1 -1
  471. package/dist/panoramic/qa/index.js +10 -3
  472. package/dist/panoramic/qa/index.js.map +1 -1
  473. package/dist/panoramic/query.d.ts +1 -0
  474. package/dist/panoramic/query.d.ts.map +1 -1
  475. package/dist/panoramic/query.js +5 -0
  476. package/dist/panoramic/query.js.map +1 -1
  477. package/dist/panoramic/runtime-topology-generator.d.ts +77 -0
  478. package/dist/panoramic/runtime-topology-generator.d.ts.map +1 -0
  479. package/dist/panoramic/runtime-topology-generator.js +676 -0
  480. package/dist/panoramic/runtime-topology-generator.js.map +1 -0
  481. package/dist/panoramic/runtime-topology-model.d.ts +145 -0
  482. package/dist/panoramic/runtime-topology-model.d.ts.map +1 -0
  483. package/dist/panoramic/runtime-topology-model.js +300 -0
  484. package/dist/panoramic/runtime-topology-model.js.map +1 -0
  485. package/dist/panoramic/troubleshooting-generator.d.ts +51 -0
  486. package/dist/panoramic/troubleshooting-generator.d.ts.map +1 -0
  487. package/dist/panoramic/troubleshooting-generator.js +451 -0
  488. package/dist/panoramic/troubleshooting-generator.js.map +1 -0
  489. package/dist/panoramic/utils/text-segmenter.d.ts +15 -0
  490. package/dist/panoramic/utils/text-segmenter.d.ts.map +1 -1
  491. package/dist/panoramic/utils/text-segmenter.js +38 -0
  492. package/dist/panoramic/utils/text-segmenter.js.map +1 -1
  493. package/dist/panoramic/workspace-index-generator.d.ts +148 -0
  494. package/dist/panoramic/workspace-index-generator.d.ts.map +1 -0
  495. package/dist/panoramic/workspace-index-generator.js +497 -0
  496. package/dist/panoramic/workspace-index-generator.js.map +1 -0
  497. package/dist/runtime-bootstrap.d.ts +9 -0
  498. package/dist/runtime-bootstrap.d.ts.map +1 -0
  499. package/dist/runtime-bootstrap.js +33 -0
  500. package/dist/runtime-bootstrap.js.map +1 -0
  501. package/dist/scaffold-kb/api-entities-serializer.d.ts +12 -0
  502. package/dist/scaffold-kb/api-entities-serializer.d.ts.map +1 -0
  503. package/dist/scaffold-kb/api-entities-serializer.js +144 -0
  504. package/dist/scaffold-kb/api-entities-serializer.js.map +1 -0
  505. package/dist/scaffold-kb/arbitration.d.ts +44 -0
  506. package/dist/scaffold-kb/arbitration.d.ts.map +1 -0
  507. package/dist/scaffold-kb/arbitration.js +144 -0
  508. package/dist/scaffold-kb/arbitration.js.map +1 -0
  509. package/dist/scaffold-kb/chunk-splitter.d.ts +20 -0
  510. package/dist/scaffold-kb/chunk-splitter.d.ts.map +1 -0
  511. package/dist/scaffold-kb/chunk-splitter.js +309 -0
  512. package/dist/scaffold-kb/chunk-splitter.js.map +1 -0
  513. package/dist/scaffold-kb/doc-graph-builder.d.ts +26 -0
  514. package/dist/scaffold-kb/doc-graph-builder.d.ts.map +1 -0
  515. package/dist/scaffold-kb/doc-graph-builder.js +72 -0
  516. package/dist/scaffold-kb/doc-graph-builder.js.map +1 -0
  517. package/dist/scaffold-kb/entity-extractor.d.ts +40 -0
  518. package/dist/scaffold-kb/entity-extractor.d.ts.map +1 -0
  519. package/dist/scaffold-kb/entity-extractor.js +0 -0
  520. package/dist/scaffold-kb/entity-extractor.js.map +1 -0
  521. package/dist/scaffold-kb/entity-heuristic.d.ts +14 -0
  522. package/dist/scaffold-kb/entity-heuristic.d.ts.map +1 -0
  523. package/dist/scaffold-kb/entity-heuristic.js +107 -0
  524. package/dist/scaffold-kb/entity-heuristic.js.map +1 -0
  525. package/dist/scaffold-kb/entity-matcher.d.ts +20 -0
  526. package/dist/scaffold-kb/entity-matcher.d.ts.map +1 -0
  527. package/dist/scaffold-kb/entity-matcher.js +53 -0
  528. package/dist/scaffold-kb/entity-matcher.js.map +1 -0
  529. package/dist/scaffold-kb/entity-util.d.ts +11 -0
  530. package/dist/scaffold-kb/entity-util.d.ts.map +1 -0
  531. package/dist/scaffold-kb/entity-util.js +23 -0
  532. package/dist/scaffold-kb/entity-util.js.map +1 -0
  533. package/dist/scaffold-kb/evidence-envelope.d.ts +17 -0
  534. package/dist/scaffold-kb/evidence-envelope.d.ts.map +1 -0
  535. package/dist/scaffold-kb/evidence-envelope.js +32 -0
  536. package/dist/scaffold-kb/evidence-envelope.js.map +1 -0
  537. package/dist/scaffold-kb/index.d.ts +20 -0
  538. package/dist/scaffold-kb/index.d.ts.map +1 -0
  539. package/dist/scaffold-kb/index.js +102 -0
  540. package/dist/scaffold-kb/index.js.map +1 -0
  541. package/dist/scaffold-kb/ingest/ingest-core.d.ts +47 -0
  542. package/dist/scaffold-kb/ingest/ingest-core.d.ts.map +1 -0
  543. package/dist/scaffold-kb/ingest/ingest-core.js +231 -0
  544. package/dist/scaffold-kb/ingest/ingest-core.js.map +1 -0
  545. package/dist/scaffold-kb/ingest/office-parser.d.ts +33 -0
  546. package/dist/scaffold-kb/ingest/office-parser.d.ts.map +1 -0
  547. package/dist/scaffold-kb/ingest/office-parser.js +187 -0
  548. package/dist/scaffold-kb/ingest/office-parser.js.map +1 -0
  549. package/dist/scaffold-kb/ingest/url-fetcher.d.ts +43 -0
  550. package/dist/scaffold-kb/ingest/url-fetcher.d.ts.map +1 -0
  551. package/dist/scaffold-kb/ingest/url-fetcher.js +245 -0
  552. package/dist/scaffold-kb/ingest/url-fetcher.js.map +1 -0
  553. package/dist/scaffold-kb/ingester.d.ts +38 -0
  554. package/dist/scaffold-kb/ingester.d.ts.map +1 -0
  555. package/dist/scaffold-kb/ingester.js +261 -0
  556. package/dist/scaffold-kb/ingester.js.map +1 -0
  557. package/dist/scaffold-kb/injection-format.d.ts +25 -0
  558. package/dist/scaffold-kb/injection-format.d.ts.map +1 -0
  559. package/dist/scaffold-kb/injection-format.js +55 -0
  560. package/dist/scaffold-kb/injection-format.js.map +1 -0
  561. package/dist/scaffold-kb/kb-writer.d.ts +13 -0
  562. package/dist/scaffold-kb/kb-writer.d.ts.map +1 -0
  563. package/dist/scaffold-kb/kb-writer.js +69 -0
  564. package/dist/scaffold-kb/kb-writer.js.map +1 -0
  565. package/dist/scaffold-kb/keyword-extract.d.ts +16 -0
  566. package/dist/scaffold-kb/keyword-extract.d.ts.map +1 -0
  567. package/dist/scaffold-kb/keyword-extract.js +49 -0
  568. package/dist/scaffold-kb/keyword-extract.js.map +1 -0
  569. package/dist/scaffold-kb/query-sanitizer.d.ts +28 -0
  570. package/dist/scaffold-kb/query-sanitizer.d.ts.map +1 -0
  571. package/dist/scaffold-kb/query-sanitizer.js +38 -0
  572. package/dist/scaffold-kb/query-sanitizer.js.map +1 -0
  573. package/dist/scaffold-kb/recall-eval.d.ts +48 -0
  574. package/dist/scaffold-kb/recall-eval.d.ts.map +1 -0
  575. package/dist/scaffold-kb/recall-eval.js +55 -0
  576. package/dist/scaffold-kb/recall-eval.js.map +1 -0
  577. package/dist/scaffold-kb/schema-compat.d.ts +22 -0
  578. package/dist/scaffold-kb/schema-compat.d.ts.map +1 -0
  579. package/dist/scaffold-kb/schema-compat.js +32 -0
  580. package/dist/scaffold-kb/schema-compat.js.map +1 -0
  581. package/dist/scaffold-kb/search-core.d.ts +42 -0
  582. package/dist/scaffold-kb/search-core.d.ts.map +1 -0
  583. package/dist/scaffold-kb/search-core.js +89 -0
  584. package/dist/scaffold-kb/search-core.js.map +1 -0
  585. package/dist/scaffold-kb/sqlite-engine.d.ts +58 -0
  586. package/dist/scaffold-kb/sqlite-engine.d.ts.map +1 -0
  587. package/dist/scaffold-kb/sqlite-engine.js +61 -0
  588. package/dist/scaffold-kb/sqlite-engine.js.map +1 -0
  589. package/dist/scaffold-kb/sqlite-writer.d.ts +18 -0
  590. package/dist/scaffold-kb/sqlite-writer.d.ts.map +1 -0
  591. package/dist/scaffold-kb/sqlite-writer.js +76 -0
  592. package/dist/scaffold-kb/sqlite-writer.js.map +1 -0
  593. package/dist/scaffold-kb/tokenizer.d.ts +26 -0
  594. package/dist/scaffold-kb/tokenizer.d.ts.map +1 -0
  595. package/dist/scaffold-kb/tokenizer.js +97 -0
  596. package/dist/scaffold-kb/tokenizer.js.map +1 -0
  597. package/dist/scaffold-kb/types.d.ts +157 -0
  598. package/dist/scaffold-kb/types.d.ts.map +1 -0
  599. package/dist/scaffold-kb/types.js +5 -0
  600. package/dist/scaffold-kb/types.js.map +1 -0
  601. package/dist/utils/file-scanner.d.ts +15 -0
  602. package/dist/utils/file-scanner.d.ts.map +1 -1
  603. package/dist/utils/file-scanner.js +18 -1
  604. package/dist/utils/file-scanner.js.map +1 -1
  605. package/dist/utils/string-distance.d.ts +20 -0
  606. package/dist/utils/string-distance.d.ts.map +1 -0
  607. package/dist/utils/string-distance.js +38 -0
  608. package/dist/utils/string-distance.js.map +1 -0
  609. package/package.json +22 -3
  610. package/plugins/demo-kb-en/.claude-plugin/plugin.json +11 -0
  611. package/plugins/demo-kb-en/.mcp.json +8 -0
  612. package/plugins/demo-kb-en/FIXTURE.json +23 -0
  613. package/plugins/demo-kb-en/FIXTURE.md +53 -0
  614. package/plugins/demo-kb-en/ingest-samples/meeting-notes.md +13 -0
  615. package/plugins/demo-kb-en/kb/api-entities.json +3445 -0
  616. package/plugins/demo-kb-en/kb/chunks.sqlite +0 -0
  617. package/plugins/demo-kb-en/kb/doc-graph.json +113 -0
  618. package/plugins/demo-kb-zh/.claude-plugin/plugin.json +11 -0
  619. package/plugins/demo-kb-zh/.mcp.json +8 -0
  620. package/plugins/demo-kb-zh/FIXTURE.json +23 -0
  621. package/plugins/demo-kb-zh/FIXTURE.md +63 -0
  622. package/plugins/demo-kb-zh/ingest-samples/meeting-notes.md +13 -0
  623. package/plugins/demo-kb-zh/kb/api-entities.json +990 -0
  624. package/plugins/demo-kb-zh/kb/chunks.sqlite +0 -0
  625. package/plugins/demo-kb-zh/kb/doc-graph.json +113 -0
  626. package/plugins/spec-driver/.claude-plugin/plugin.json +1 -1
  627. package/plugins/spec-driver/README.md +50 -1
  628. package/plugins/spec-driver/agents/implement.md +20 -1
  629. package/plugins/spec-driver/agents/plan.md +20 -1
  630. package/plugins/spec-driver/agents/quality-review.md +20 -1
  631. package/plugins/spec-driver/agents/spec-review.md +20 -1
  632. package/plugins/spec-driver/agents/verify.md +108 -1
  633. package/plugins/spec-driver/config/orchestration.yaml +39 -31
  634. package/plugins/spec-driver/contracts/orchestration-overrides-contract.yaml +27 -0
  635. package/plugins/spec-driver/contracts/orchestration-schema.mjs +272 -227
  636. package/plugins/spec-driver/contracts/wrapper-source-of-truth.yaml +3 -0
  637. package/plugins/spec-driver/docs/customization.md +134 -0
  638. package/plugins/spec-driver/docs/spectra-mcp-integration.md +165 -0
  639. package/plugins/spec-driver/hooks/hooks.json +9 -0
  640. package/plugins/spec-driver/hooks/stop-fix-compliance-check.sh +36 -0
  641. package/plugins/spec-driver/lib/delegation-contract.mjs +84 -0
  642. package/plugins/spec-driver/lib/orchestration-resolver.mjs +49 -0
  643. package/plugins/spec-driver/lib/orchestrator.mjs +29 -1
  644. package/plugins/spec-driver/lib/preference-rules.mjs +96 -0
  645. package/plugins/spec-driver/scripts/codex-skills.sh +28 -28
  646. package/plugins/spec-driver/scripts/dev/spike-fix-compliance-e2e.mjs +130 -0
  647. package/plugins/spec-driver/scripts/fix-compliance-judge.mjs +415 -0
  648. package/plugins/spec-driver/scripts/generate-adoption-insights.mjs +48 -1
  649. package/plugins/spec-driver/scripts/goal-loop-cli.mjs +307 -0
  650. package/plugins/spec-driver/scripts/init-project.sh +56 -0
  651. package/plugins/spec-driver/scripts/kb-prequery.mjs +125 -0
  652. package/plugins/spec-driver/scripts/lib/config-schema.mjs +200 -94
  653. package/plugins/spec-driver/scripts/lib/ensure-gitignore.sh +277 -0
  654. package/plugins/spec-driver/scripts/lib/extract-wrapper-body.mjs +136 -0
  655. package/plugins/spec-driver/scripts/lib/fix-compliance-core.mjs +434 -0
  656. package/plugins/spec-driver/scripts/lib/fix-compliance-io.mjs +335 -0
  657. package/plugins/spec-driver/scripts/lib/goal-loop-core.mjs +783 -0
  658. package/plugins/spec-driver/scripts/lib/init-project-output.sh +28 -0
  659. package/plugins/spec-driver/scripts/lib/load-zod.mjs +62 -0
  660. package/plugins/spec-driver/scripts/lib/project-profile-resolver.mjs +141 -49
  661. package/plugins/spec-driver/scripts/lib/project-profile-schema.mjs +88 -54
  662. package/plugins/spec-driver/scripts/postinstall.sh +13 -1
  663. package/plugins/spec-driver/scripts/record-workflow-run.mjs +75 -0
  664. package/plugins/spec-driver/scripts/sync-delegation-contract.mjs +187 -0
  665. package/plugins/spec-driver/scripts/sync-preference-rules.mjs +148 -0
  666. package/plugins/spec-driver/scripts/validate-orchestrator-models.mjs +156 -0
  667. package/plugins/spec-driver/scripts/validate-wrapper-sources.mjs +46 -1
  668. package/plugins/spec-driver/skills/spec-driver-feature/SKILL.md +302 -0
  669. package/plugins/spec-driver/skills/spec-driver-fix/SKILL.md +97 -8
  670. package/plugins/spec-driver/skills/spec-driver-implement/SKILL.md +18 -0
  671. package/plugins/spec-driver/skills/spec-driver-refactor/SKILL.md +10 -0
  672. package/plugins/spec-driver/skills/spec-driver-resume/SKILL.md +12 -1
  673. package/plugins/spec-driver/skills/spec-driver-story/SKILL.md +30 -0
  674. package/plugins/spec-driver/templates/delegation-contract.md +27 -0
  675. package/plugins/spec-driver/templates/goal-loop-override-template.yaml +284 -0
  676. package/plugins/spec-driver/templates/preference-rules.md +39 -0
  677. package/plugins/spec-driver/templates/specify-base/project-context-template.yaml +10 -0
  678. package/plugins/spectra/.claude-plugin/plugin.json +1 -1
  679. package/plugins/spectra/README.md +48 -1
  680. package/plugins/spectra/hooks/post-commit.sh +40 -0
  681. package/templates/module-spec.hbs +1 -0
  682. package/templates/product-overview.hbs +1 -1
@@ -0,0 +1,806 @@
1
+ /**
2
+ * Feature 155 — Agent-Context MCP Tools (impact / context / detect_changes)
3
+ *
4
+ * 3 个 tool handler,建在 Feature 151 已 ship 的 UnifiedGraph + call-resolver 之上:
5
+ * - impact: blast radius — 反向 BFS 找受影响 symbols
6
+ * - context: 360° symbol 视图 — definition + callers + callees + imports + relatedSpec
7
+ * - detect_changes: git diff → changedSymbols → impact 链
8
+ *
9
+ * 数据流:
10
+ * getCachedGraphData(projectRoot) // 来自 graph-tools.ts,含 mtime/size stale 检测
11
+ * ↓
12
+ * query-helpers.ts (bfsTraverse / canonicalizeSymbolId / resolveSymbolFuzzy / ...)
13
+ * ↓
14
+ * tool handler 输出 JSON envelope
15
+ *
16
+ * 错误处理(FR-050):统一 envelope `{ isError: true, content: [{type:'text', text: JSON({code, message, hint?, context?})}]}`
17
+ * 错误 code: graph-not-built / symbol-not-found / invalid-symbol-id / invalid-input /
18
+ * invalid-diff / payload-too-large / git-spawn-failed / git-timeout / internal-error
19
+ */
20
+ import { spawnSync } from 'node:child_process';
21
+ import { existsSync } from 'node:fs';
22
+ import * as path from 'node:path';
23
+ import { z } from 'zod';
24
+ import { getCachedGraphData, isGraphFormatStaleError } from './graph-tools.js';
25
+ import { bfsTraverse, canonicalizeSymbolId, computeRiskTier, resolveSymbolFuzzy, findNode, moduleFileFromId, resolveEdgeConfidence, } from '../knowledge-graph/query-helpers.js';
26
+ import { buildTopImpactedRanking, buildTopRelevantCallers, generateNextStepHint, safeStderrLog, } from './lib/response-helpers.js';
27
+ // ============================================================
28
+ // 共享响应原语 + Telemetry(Feature 171 抽到 lib/ 复用,解 C-4 / TELEMETRY-COUPLING)
29
+ // ============================================================
30
+ import { buildErrorResponse, buildSuccessResponse, } from './lib/tool-response.js';
31
+ import { recordAndReturn } from './lib/telemetry.js';
32
+ // 向后兼容 re-export:既有 tests/unit/mcp/telemetry.test.ts 从本模块 import 这些符号
33
+ export { recordAndReturn, writeTelemetry } from './lib/telemetry.js';
34
+ /**
35
+ * 统一 impact / context / detect_changes 三工具的 telemetry 采样 + 顶层 internal-error catch +
36
+ * recordAndReturn 透传,消除三处复制的 _telStart / _telReqSize / 散落 recordAndReturn 样板。
37
+ *
38
+ * 不变量(spec AD-1):agent-context 属"自采样组"——telemetry 在本骨架内(handler 内部)发射,
39
+ * 注册层**不**再包 withTelemetry,故每次调用恰 1 行。
40
+ *
41
+ * 顶层 catch 行为保持与重构前**逐字一致**(behavior-preserve):internal-error 携带 err.message
42
+ * 与截断 stack。该 message/stack 形态属 agent-context 既有行为,不在 F177 C-4 重新脱敏范围
43
+ * (spec 遗留-2)。
44
+ */
45
+ async function runAgentContextTool(toolName, args, body) {
46
+ const _telStart = Date.now();
47
+ let _telReqSize = 0;
48
+ try {
49
+ _telReqSize = JSON.stringify(args).length;
50
+ }
51
+ catch {
52
+ _telReqSize = 0;
53
+ }
54
+ try {
55
+ const out = await body();
56
+ return recordAndReturn(toolName, _telStart, _telReqSize, out.result, out.summary, out.samples);
57
+ }
58
+ catch {
59
+ // F186 T4:脱敏回传给 MCP 客户端的错误响应——不外漏 err.message / stack(可能含绝对路径)。
60
+ // 保留 internal-error code(客户端只消费 code);telemetry 经 recordAndReturn 仍记录该 code。
61
+ return recordAndReturn(toolName, _telStart, _telReqSize, buildErrorResponse('internal-error', '内部错误,请稍后重试'));
62
+ }
63
+ }
64
+ /**
65
+ * Feature 193 FR-006 — 加载 graph,区分三态:
66
+ * - 成功 → { data }
67
+ * - graph-format-stale(旧绝对格式,copy 自其他 worktree)→ { error: stale 响应 }
68
+ * - 缺图 / 其他加载失败 → { error: graph-not-built 响应 }
69
+ *
70
+ * 让 impact/context/detect_changes 对旧格式图给明确重建指引,不静默退化为 graph-not-built。
71
+ */
72
+ function loadGraphOrError(projectRoot) {
73
+ try {
74
+ const cached = getCachedGraphData(projectRoot);
75
+ if (cached === null) {
76
+ return {
77
+ // F186 T4:去掉 projectRoot 内插(避免回传绝对路径),固定文案 + 可执行 hint
78
+ error: buildErrorResponse('graph-not-built', 'graph 未构建', '请先运行 `spectra batch` 生成图谱'),
79
+ };
80
+ }
81
+ return { data: cached };
82
+ }
83
+ catch (err) {
84
+ if (isGraphFormatStaleError(err)) {
85
+ return {
86
+ error: buildErrorResponse('graph-format-stale', err.message, '当前 worktree 的图为旧绝对路径格式(可能 copy 自主仓/其他 worktree)。运行 `spectra index` 或 `spectra batch` 在当前 worktree 重建图。'),
87
+ };
88
+ }
89
+ return {
90
+ // F186 T4:其他加载失败同样脱敏——不回传 projectRoot 绝对路径
91
+ error: buildErrorResponse('graph-not-built', 'graph 未构建', '请先运行 `spectra batch` 生成图谱'),
92
+ };
93
+ }
94
+ }
95
+ // ============================================================
96
+ // impact tool
97
+ // ============================================================
98
+ const ImpactInputSchema = {
99
+ target: z.string().describe('symbol id (e.g. "micrograd/engine.py::Value.__add__")'),
100
+ depth: z.number().int().min(0).max(20).optional().describe('BFS depth (default 2, max 5; 超出 clamp)'),
101
+ minConfidence: z.number().min(0).max(1).optional().describe('confidence 阈值 (default 0.65)'),
102
+ direction: z.enum(['upstream', 'downstream', 'both']).optional().describe('BFS 方向 (default upstream)'),
103
+ budget: z.number().int().min(0).max(10000).optional().describe('节点上限 (default 200, max 1000; 超出 clamp)'),
104
+ projectRoot: z.string().optional().describe('default cwd'),
105
+ };
106
+ export async function handleImpact(args) {
107
+ return runAgentContextTool('impact', args, () => {
108
+ if (typeof args.target !== 'string' || args.target.length === 0) {
109
+ return { result: buildErrorResponse('invalid-input', 'target 必填且为非空字符串') };
110
+ }
111
+ const projectRoot = args.projectRoot ?? process.cwd();
112
+ const loaded = loadGraphOrError(projectRoot);
113
+ if (loaded.error) {
114
+ return { result: loaded.error };
115
+ }
116
+ const { graphData, graphPath, mtimeMs, sizeBytes } = loaded.data;
117
+ // 入参 clamp(FR-015)— handler 层负责 clamp 并附 warning,不依赖 zod max
118
+ const warnings = [];
119
+ const reqDepth = args.depth ?? 2;
120
+ const effectiveDepth = Math.min(Math.max(reqDepth, 0), 5);
121
+ if (effectiveDepth !== reqDepth)
122
+ warnings.push('depth-clamped');
123
+ const reqBudget = args.budget ?? 200;
124
+ const effectiveBudget = Math.min(Math.max(reqBudget, 0), 1000);
125
+ if (effectiveBudget !== reqBudget)
126
+ warnings.push('budget-clamped');
127
+ const reqMinConf = args.minConfidence ?? 0.65;
128
+ const minConfidence = Math.min(Math.max(reqMinConf, 0), 1);
129
+ if (minConfidence !== reqMinConf)
130
+ warnings.push('minConfidence-clamped');
131
+ const direction = args.direction ?? 'upstream';
132
+ // canonicalize symbol id
133
+ const canon = canonicalizeSymbolId(args.target, graphData, { projectRoot });
134
+ if (canon.reason === 'invalid') {
135
+ return { result: buildErrorResponse('invalid-symbol-id', `target 含非法字符或格式: ${args.target}`) };
136
+ }
137
+ // F174:canonicalize not-found 时走分层 fuzzy(autoResolved → 用 resolvedTo 继续;否则结构化 top-3)
138
+ let startId;
139
+ let fuzzyResolved = null;
140
+ if (canon.reason === 'not-found' || canon.canonicalId === null) {
141
+ const fuzzy = resolveSymbolFuzzy(graphData, args.target, { projectRoot });
142
+ if (fuzzy.autoResolved && fuzzy.candidates[0] !== undefined) {
143
+ startId = fuzzy.candidates[0].id;
144
+ fuzzyResolved = { from: args.target, to: fuzzy.candidates[0].id, confidence: fuzzy.candidates[0].confidence };
145
+ warnings.push('fuzzy-resolved');
146
+ }
147
+ else {
148
+ return { result: buildErrorResponse('symbol-not-found', `target 在 graph 中未找到: ${args.target}`, '请检查 symbol id 格式或参考 fuzzyMatches 候选', { fuzzyMatches: fuzzy.candidates.slice(0, 3) }) };
149
+ }
150
+ }
151
+ else {
152
+ startId = canon.canonicalId;
153
+ }
154
+ // BFS
155
+ const r = bfsTraverse(graphData, startId, {
156
+ depth: effectiveDepth,
157
+ minConfidence,
158
+ direction,
159
+ budget: effectiveBudget,
160
+ graphPath,
161
+ graphMtimeMs: mtimeMs,
162
+ graphSizeBytes: sizeBytes,
163
+ relations: ['calls'],
164
+ });
165
+ // 合并 warnings
166
+ for (const w of r.warnings) {
167
+ if (!warnings.includes(w))
168
+ warnings.push(w);
169
+ }
170
+ // summary
171
+ const directCallers = r.affected.filter((a) => a.depth === 1).length;
172
+ const transitive = r.affected.length;
173
+ const riskTier = computeRiskTier(directCallers, transitive);
174
+ const data = {
175
+ affected: r.affected,
176
+ summary: { directCallers, transitive, riskTier },
177
+ effectiveDepth,
178
+ effectiveMinConfidence: minConfidence,
179
+ effectiveBudget,
180
+ effectiveDirection: direction,
181
+ };
182
+ if (warnings.length > 0)
183
+ data['warnings'] = warnings;
184
+ // F174:autoResolved 时附加 resolve 溯源字段
185
+ if (fuzzyResolved !== null) {
186
+ data['resolvedFrom'] = fuzzyResolved.from;
187
+ data['resolvedTo'] = fuzzyResolved.to;
188
+ data['resolvedConfidence'] = fuzzyResolved.confidence;
189
+ }
190
+ // F170c enrichment 三路径(plan G 节):临时变量 + 显式 catch reset 避免 partial fill
191
+ let topImpacted;
192
+ let nextStepHint;
193
+ let enrichmentDegraded;
194
+ try {
195
+ const _topImpacted = buildTopImpactedRanking(r.affected, 5);
196
+ const _nextStepHint = generateNextStepHint('impact', { topImpacted: _topImpacted, affected: r.affected }, 'success');
197
+ topImpacted = _topImpacted;
198
+ nextStepHint = _nextStepHint;
199
+ enrichmentDegraded = false;
200
+ }
201
+ catch (e) {
202
+ topImpacted = [];
203
+ nextStepHint = '';
204
+ enrichmentDegraded = true;
205
+ safeStderrLog(`[F170c] impact enrichment degraded: ${String(e)}\n`);
206
+ }
207
+ data['topImpacted'] = topImpacted;
208
+ data['nextStepHint'] = nextStepHint;
209
+ if (enrichmentDegraded)
210
+ data['_enrichmentDegraded'] = true;
211
+ return { result: buildSuccessResponse(data, ['affected']) };
212
+ });
213
+ }
214
+ // ============================================================
215
+ // context tool
216
+ // ============================================================
217
+ const ContextInputSchema = {
218
+ symbolId: z.string().describe('symbol id'),
219
+ include: z
220
+ .array(z.enum(['callers', 'callees', 'imports', 'related-spec']))
221
+ .optional()
222
+ .describe('字段子集 (default ["callers","callees","imports"])'),
223
+ projectRoot: z.string().optional(),
224
+ };
225
+ export async function handleContext(args) {
226
+ return runAgentContextTool('context', args, () => {
227
+ if (typeof args.symbolId !== 'string' || args.symbolId.length === 0) {
228
+ return { result: buildErrorResponse('invalid-input', 'symbolId 必填且为非空字符串') };
229
+ }
230
+ const projectRoot = args.projectRoot ?? process.cwd();
231
+ // Codex implement-C2:复用 loadGraphOrError,使 graph-format-stale 明确上抛
232
+ // (旧绝对格式图给重建指引),不被外层 catch-all 吞成 internal-error。
233
+ const loaded = loadGraphOrError(projectRoot);
234
+ if (loaded.error) {
235
+ return { result: loaded.error };
236
+ }
237
+ const { graphData } = loaded.data;
238
+ const include = args.include ?? ['callers', 'callees', 'imports'];
239
+ // F174:context handler 引入 warnings 数组(原本无此字段),承载 'fuzzy-resolved' 等
240
+ const warnings = [];
241
+ const canon = canonicalizeSymbolId(args.symbolId, graphData, { projectRoot });
242
+ if (canon.reason === 'invalid') {
243
+ return { result: buildErrorResponse('invalid-symbol-id', `symbolId 含非法字符: ${args.symbolId}`) };
244
+ }
245
+ // F174:canonicalize not-found 时走分层 fuzzy(autoResolved → 用 resolvedTo 继续;否则结构化 top-3)
246
+ let resolvedId;
247
+ let fuzzyResolved = null;
248
+ if (canon.reason === 'not-found' || canon.canonicalId === null) {
249
+ const fuzzy = resolveSymbolFuzzy(graphData, args.symbolId, { projectRoot });
250
+ if (fuzzy.autoResolved && fuzzy.candidates[0] !== undefined) {
251
+ resolvedId = fuzzy.candidates[0].id;
252
+ fuzzyResolved = { from: args.symbolId, to: fuzzy.candidates[0].id, confidence: fuzzy.candidates[0].confidence };
253
+ warnings.push('fuzzy-resolved');
254
+ }
255
+ else {
256
+ return { result: buildErrorResponse('symbol-not-found', `symbolId 在 graph 中未找到: ${args.symbolId}`, '请检查 id 格式或参考 fuzzyMatches 候选', { fuzzyMatches: fuzzy.candidates.slice(0, 3) }) };
257
+ }
258
+ }
259
+ else {
260
+ resolvedId = canon.canonicalId;
261
+ }
262
+ const node = findNode(graphData, resolvedId);
263
+ if (node === null) {
264
+ return { result: buildErrorResponse('symbol-not-found', `节点对象未找到: ${resolvedId}`) };
265
+ }
266
+ const definition = buildDefinition(node);
267
+ const data = { definition };
268
+ if (include.includes('callers')) {
269
+ data['callers'] = collectNeighbors(graphData, resolvedId, 'inbound', 'calls');
270
+ }
271
+ if (include.includes('callees')) {
272
+ data['callees'] = collectNeighbors(graphData, resolvedId, 'outbound', 'calls');
273
+ }
274
+ if (include.includes('imports')) {
275
+ // imports 来自 module 节点的 outbound depends-on / cross-module
276
+ const moduleId = moduleFileFromId(resolvedId);
277
+ const importEntries = collectNeighbors(graphData, moduleId, 'outbound', 'depends-on').concat(collectNeighbors(graphData, moduleId, 'outbound', 'cross-module'));
278
+ // 转换为 import schema
279
+ data['imports'] = importEntries.map((x) => ({
280
+ moduleId: x.id,
281
+ file: moduleFileFromId(x.id),
282
+ confidence: x.confidence,
283
+ }));
284
+ }
285
+ if (include.includes('related-spec')) {
286
+ data['relatedSpec'] = deriveRelatedSpec(resolvedId, projectRoot);
287
+ }
288
+ // F174:autoResolved 时附加 resolve 溯源字段 + warnings
289
+ if (fuzzyResolved !== null) {
290
+ data['resolvedFrom'] = fuzzyResolved.from;
291
+ data['resolvedTo'] = fuzzyResolved.to;
292
+ data['resolvedConfidence'] = fuzzyResolved.confidence;
293
+ }
294
+ if (warnings.length > 0)
295
+ data['warnings'] = warnings;
296
+ // F170c enrichment 三路径(plan G 节)
297
+ const callersRaw = data['callers'] ?? [];
298
+ let topRelevantCallers;
299
+ let nextStepHint;
300
+ let enrichmentDegraded;
301
+ try {
302
+ const _top = buildTopRelevantCallers(callersRaw, 3);
303
+ const _hint = generateNextStepHint('context', { definition, callers: callersRaw }, 'success');
304
+ topRelevantCallers = _top;
305
+ nextStepHint = _hint;
306
+ enrichmentDegraded = false;
307
+ }
308
+ catch (e) {
309
+ topRelevantCallers = [];
310
+ nextStepHint = '';
311
+ enrichmentDegraded = true;
312
+ safeStderrLog(`[F170c] context enrichment degraded: ${String(e)}\n`);
313
+ }
314
+ data['topRelevantCallers'] = topRelevantCallers;
315
+ data['nextStepHint'] = nextStepHint;
316
+ if (enrichmentDegraded)
317
+ data['_enrichmentDegraded'] = true;
318
+ return { result: buildSuccessResponse(data, ['callers', 'callees', 'imports']) };
319
+ });
320
+ }
321
+ function buildDefinition(node) {
322
+ const md = node.metadata;
323
+ const def = {
324
+ id: node.id,
325
+ file: md['sourceFile'] ?? md['sourcePath'] ?? moduleFileFromId(node.id),
326
+ kind: node.kind,
327
+ label: node.label,
328
+ };
329
+ const lineRange = md['lineRange'];
330
+ if (lineRange) {
331
+ if (typeof lineRange.start === 'number')
332
+ def['lineStart'] = lineRange.start;
333
+ if (typeof lineRange.end === 'number')
334
+ def['lineEnd'] = lineRange.end;
335
+ }
336
+ const conf = md['confidence'];
337
+ if (typeof conf === 'string')
338
+ def['confidence'] = conf;
339
+ return def;
340
+ }
341
+ function collectNeighbors(graphData, nodeId, direction, relation) {
342
+ const out = [];
343
+ for (const link of graphData.links) {
344
+ if (link.relation !== relation)
345
+ continue;
346
+ const conf = resolveEdgeConfidence(link);
347
+ if (conf === null)
348
+ continue;
349
+ if (direction === 'inbound' && link.target === nodeId) {
350
+ out.push({ id: link.source, confidence: conf, relation: link.relation });
351
+ }
352
+ else if (direction === 'outbound' && link.source === nodeId) {
353
+ out.push({ id: link.target, confidence: conf, relation: link.relation });
354
+ }
355
+ }
356
+ return out;
357
+ }
358
+ function deriveRelatedSpec(symbolId, projectRoot) {
359
+ const moduleFile = moduleFileFromId(symbolId);
360
+ const slug = path.basename(moduleFile, path.extname(moduleFile));
361
+ const candidates = [
362
+ path.join(projectRoot, 'panoramic', 'modules', `${slug}.spec.md`),
363
+ path.join(projectRoot, 'specs', 'products', 'spectra', '_generated', 'modules', `${slug}.spec.md`),
364
+ path.join(projectRoot, '_meta', 'modules', `${slug}.spec.md`),
365
+ ];
366
+ for (const c of candidates) {
367
+ if (existsSync(c)) {
368
+ return { kind: 'module-coarse', path: path.relative(projectRoot, c) };
369
+ }
370
+ }
371
+ return { kind: 'unknown' };
372
+ }
373
+ // ============================================================
374
+ // detect_changes tool
375
+ // ============================================================
376
+ const DetectChangesInputSchema = {
377
+ diff: z.string().optional().describe('unified diff 文本'),
378
+ baseRef: z.string().optional().describe('git ref (e.g. HEAD~1)'),
379
+ projectRoot: z.string().optional(),
380
+ depth: z.number().int().min(0).max(10).optional().describe('default 2, max 5'),
381
+ budget: z.number().int().min(0).max(10000).optional().describe('default 200, max 1000'),
382
+ minConfidence: z.number().min(0).max(1).optional().describe('default 0.65'),
383
+ };
384
+ const MAX_DIFF_BYTES = 5 * 1024 * 1024; // 5 MB
385
+ const BASEREF_WHITELIST = /^[A-Za-z0-9_./~^@{}-]+$/;
386
+ const GIT_TIMEOUT_MS = 30_000;
387
+ const REVPARSE_TIMEOUT_MS = 5_000;
388
+ export async function handleDetectChanges(args) {
389
+ return runAgentContextTool('detect_changes', args, () => {
390
+ const hasDiff = typeof args.diff === 'string' && args.diff.length > 0;
391
+ const hasBaseRef = typeof args.baseRef === 'string' && args.baseRef.length > 0;
392
+ if (!hasDiff && !hasBaseRef) {
393
+ return { result: buildErrorResponse('invalid-input', '必须提供 diff 或 baseRef 之一', undefined, { reason: 'diff-or-baseref-required' }) };
394
+ }
395
+ const warnings = [];
396
+ if (hasDiff && hasBaseRef) {
397
+ warnings.push('baseRef-ignored');
398
+ }
399
+ const projectRoot = args.projectRoot ?? process.cwd();
400
+ // Codex implement-C2:复用 loadGraphOrError,使 graph-format-stale 明确上抛
401
+ // (旧绝对格式图给重建指引),不被外层 catch-all 吞成 internal-error。
402
+ const loaded = loadGraphOrError(projectRoot);
403
+ if (loaded.error) {
404
+ return { result: loaded.error };
405
+ }
406
+ const { graphData, graphPath, mtimeMs, sizeBytes } = loaded.data;
407
+ // 1) 拿改动文件列表
408
+ let changedFiles;
409
+ let unmappedFromInput = [];
410
+ if (hasDiff) {
411
+ // 5MB 上限校验前置(CRITICAL fix:返回 payload-too-large 而非 invalid-diff)
412
+ if (Buffer.byteLength(args.diff, 'utf-8') > MAX_DIFF_BYTES) {
413
+ return { result: buildErrorResponse('payload-too-large', `diff 超过上限 ${MAX_DIFF_BYTES} 字节`, undefined, { limitBytes: MAX_DIFF_BYTES }) };
414
+ }
415
+ const parsed = parseUnifiedDiff(args.diff);
416
+ if (parsed.error !== undefined) {
417
+ return { result: buildErrorResponse('invalid-diff', parsed.error) };
418
+ }
419
+ changedFiles = parsed.changed;
420
+ unmappedFromInput = parsed.unmapped;
421
+ }
422
+ else {
423
+ const r = runGitDiffNameStatus(args.baseRef, projectRoot);
424
+ if (!r.ok) {
425
+ return { result: buildErrorResponse(r.code, r.message, undefined, r.context) };
426
+ }
427
+ changedFiles = r.changed;
428
+ unmappedFromInput = r.unmapped;
429
+ }
430
+ // 没有改动文件 → success warning(FR-050 'no-changed-files' 是 warning 不是 error)
431
+ if (changedFiles.length === 0 && unmappedFromInput.length === 0) {
432
+ warnings.push('no-changed-files');
433
+ }
434
+ // 2) file → graph symbols 映射
435
+ const fileToSymbols = buildFileSymbolIndex(graphData);
436
+ const changedSymbolsOut = [];
437
+ const unmappedFiles = [...unmappedFromInput];
438
+ const allChangedSymbolIds = [];
439
+ for (const cf of changedFiles) {
440
+ const symbols = fileToSymbols.get(cf.file);
441
+ if (symbols === undefined || symbols.length === 0) {
442
+ unmappedFiles.push({ file: cf.file, reason: 'not-in-graph' });
443
+ continue;
444
+ }
445
+ changedSymbolsOut.push({ file: cf.file, changeKind: cf.changeKind, symbols });
446
+ for (const s of symbols)
447
+ allChangedSymbolIds.push(s);
448
+ }
449
+ // 3) 跨 changedSymbol 共享 budget BFS
450
+ const reqDepth = args.depth ?? 2;
451
+ const effectiveDepth = Math.min(Math.max(reqDepth, 0), 5);
452
+ if (effectiveDepth !== reqDepth)
453
+ warnings.push('depth-clamped');
454
+ const reqBudget = args.budget ?? 200;
455
+ const effectiveBudget = Math.min(Math.max(reqBudget, 0), 1000);
456
+ if (effectiveBudget !== reqBudget)
457
+ warnings.push('budget-clamped');
458
+ const minConfidence = args.minConfidence ?? 0.65;
459
+ const sharedVisited = new Set();
460
+ for (const s of allChangedSymbolIds)
461
+ sharedVisited.add(s);
462
+ const affectedAcc = [];
463
+ let remaining = effectiveBudget;
464
+ for (const startId of allChangedSymbolIds) {
465
+ if (remaining <= 0) {
466
+ warnings.push('budget-truncated');
467
+ break;
468
+ }
469
+ const r = bfsTraverse(graphData, startId, {
470
+ depth: effectiveDepth,
471
+ minConfidence,
472
+ direction: 'upstream',
473
+ budget: remaining,
474
+ sharedVisited,
475
+ graphPath,
476
+ graphMtimeMs: mtimeMs,
477
+ graphSizeBytes: sizeBytes,
478
+ relations: ['calls'],
479
+ });
480
+ affectedAcc.push(...r.affected);
481
+ remaining = effectiveBudget - affectedAcc.length;
482
+ for (const w of r.warnings) {
483
+ if (!warnings.includes(w))
484
+ warnings.push(w);
485
+ }
486
+ if (r.warnings.includes('budget-truncated'))
487
+ break;
488
+ }
489
+ // de-warning(去重)
490
+ const uniqWarnings = [...new Set(warnings)];
491
+ const totalChanged = allChangedSymbolIds.length;
492
+ const totalAffected = affectedAcc.length;
493
+ const riskTier = computeRiskTier(0, totalAffected);
494
+ const data = {
495
+ changedSymbols: changedSymbolsOut,
496
+ affectedSymbols: affectedAcc,
497
+ riskSummary: { totalChanged, totalAffected, riskTier },
498
+ unmappedFiles,
499
+ effectiveBudget,
500
+ effectiveDepth,
501
+ effectiveMinConfidence: minConfidence,
502
+ };
503
+ if (uniqWarnings.length > 0)
504
+ data['warnings'] = uniqWarnings;
505
+ // F170c enrichment(plan G + D 节)
506
+ const enrichment = _computeDetectChangesEnrichment(affectedAcc, riskTier, totalChanged);
507
+ data['riskTier'] = riskTier;
508
+ data['topImpacted'] = enrichment.topImpacted;
509
+ data['nextStepHint'] = enrichment.nextStepHint;
510
+ if (enrichment.degraded)
511
+ data['_enrichmentDegraded'] = true;
512
+ // telemetry sample(Feature 165)
513
+ const { symbolSample, fileSample } = _buildTelemetrySamples(changedSymbolsOut);
514
+ return {
515
+ result: buildSuccessResponse(data, ['affectedSymbols']),
516
+ summary: { changedSymbolsCount: totalChanged },
517
+ samples: { symbols: symbolSample, files: fileSample },
518
+ };
519
+ });
520
+ }
521
+ // ─── detect_changes 私有辅助函数(F170c T-GREEN-2 cleanup) ───
522
+ function _computeDetectChangesEnrichment(affectedAcc, riskTier, totalChanged) {
523
+ try {
524
+ const topImpacted = buildTopImpactedRanking(affectedAcc, 5);
525
+ const nextStepHint = generateNextStepHint('detect_changes', { topImpacted, riskTier, totalChanged }, 'success');
526
+ return { topImpacted, nextStepHint, degraded: false };
527
+ }
528
+ catch (e) {
529
+ safeStderrLog(`[F170c] detect_changes enrichment degraded: ${String(e)}\n`);
530
+ return { topImpacted: [], nextStepHint: '', degraded: true };
531
+ }
532
+ }
533
+ function _buildTelemetrySamples(changedSymbolsOut) {
534
+ const sampleMaxN = 10;
535
+ const symbolSample = [];
536
+ for (const cf of changedSymbolsOut) {
537
+ for (const sym of cf.symbols) {
538
+ if (symbolSample.length >= sampleMaxN)
539
+ break;
540
+ symbolSample.push(sym);
541
+ }
542
+ if (symbolSample.length >= sampleMaxN)
543
+ break;
544
+ }
545
+ const fileSample = [];
546
+ for (const cf of changedSymbolsOut) {
547
+ if (fileSample.length >= sampleMaxN)
548
+ break;
549
+ fileSample.push(cf.file);
550
+ }
551
+ return { symbolSample, fileSample };
552
+ }
553
+ // ─── unified diff 解析 ─────────────────────────────────────
554
+ function parseUnifiedDiff(diff) {
555
+ const lines = diff.split('\n');
556
+ const changed = [];
557
+ const unmapped = [];
558
+ let pendingHeader = null;
559
+ let sawAnyHeader = false;
560
+ const flushPending = (binary) => {
561
+ if (pendingHeader === null)
562
+ return;
563
+ const aPath = pendingHeader.aPath;
564
+ const bPath = pendingHeader.bPath;
565
+ // mode-only diff(仅 diff --git 头,没有 --- / +++ / rename / binary)→ 跳过
566
+ if (!binary && !pendingHeader.sawContent) {
567
+ pendingHeader = null;
568
+ return;
569
+ }
570
+ if (binary) {
571
+ const file = bPath ?? aPath;
572
+ if (file !== undefined && file !== '/dev/null') {
573
+ unmapped.push({ file: stripDiffPrefix(file), reason: 'binary' });
574
+ }
575
+ }
576
+ else {
577
+ // 删除:bPath 为 /dev/null
578
+ if (bPath === '/dev/null' && aPath !== undefined && aPath !== '/dev/null') {
579
+ unmapped.push({ file: stripDiffPrefix(aPath), reason: 'deleted-file' });
580
+ }
581
+ else if (aPath === '/dev/null' && bPath !== undefined && bPath !== '/dev/null') {
582
+ // 新增文件
583
+ unmapped.push({ file: stripDiffPrefix(bPath), reason: 'new-file-not-in-graph-yet' });
584
+ }
585
+ else if (bPath !== undefined && bPath !== '/dev/null') {
586
+ const cleanB = stripDiffPrefix(bPath);
587
+ const cleanA = aPath !== undefined ? stripDiffPrefix(aPath) : cleanB;
588
+ const isRename = cleanA !== cleanB;
589
+ changed.push({ file: cleanB, changeKind: isRename ? 'rename' : 'modified' });
590
+ }
591
+ }
592
+ pendingHeader = null;
593
+ };
594
+ for (const rawLine of lines) {
595
+ const line = rawLine.replace(/\r$/, '');
596
+ if (line.startsWith('diff --git ')) {
597
+ // 上一组结束
598
+ flushPending(false);
599
+ sawAnyHeader = true;
600
+ // 解析 a/<path> b/<path>,可能含引号 + 路径含空格
601
+ // 优先匹配 quoted: diff --git "a/foo bar" "b/foo bar"
602
+ const quotedM = line.match(/^diff --git "(a\/.+?)" "(b\/.+?)"$/);
603
+ const unquotedM = line.match(/^diff --git (a\/[^\s]+) (b\/[^\s]+)$/);
604
+ if (quotedM) {
605
+ pendingHeader = { aPath: quotedM[1], bPath: quotedM[2], sawContent: false };
606
+ }
607
+ else if (unquotedM) {
608
+ pendingHeader = { aPath: unquotedM[1], bPath: unquotedM[2], sawContent: false };
609
+ }
610
+ else {
611
+ // 兜底(rename 等场景 diff --git 头可能没 a/ b/ 前缀)
612
+ pendingHeader = { sawContent: false };
613
+ }
614
+ }
615
+ else if (line.startsWith('--- ')) {
616
+ if (pendingHeader === null)
617
+ pendingHeader = { sawContent: false };
618
+ pendingHeader.aPath = line.slice(4).trim().replace(/^"|"$/g, '');
619
+ pendingHeader.sawContent = true;
620
+ }
621
+ else if (line.startsWith('+++ ')) {
622
+ if (pendingHeader === null)
623
+ pendingHeader = { sawContent: false };
624
+ pendingHeader.bPath = line.slice(4).trim().replace(/^"|"$/g, '');
625
+ pendingHeader.sawContent = true;
626
+ }
627
+ else if (line.startsWith('Binary files') || line.startsWith('GIT binary patch')) {
628
+ flushPending(true);
629
+ }
630
+ else if (line.startsWith('rename to ')) {
631
+ if (pendingHeader === null)
632
+ pendingHeader = { sawContent: false };
633
+ pendingHeader.bPath = 'b/' + line.slice('rename to '.length).trim().replace(/^"|"$/g, '');
634
+ pendingHeader.sawContent = true;
635
+ }
636
+ else if (line.startsWith('rename from ')) {
637
+ if (pendingHeader === null)
638
+ pendingHeader = { sawContent: false };
639
+ pendingHeader.aPath = 'a/' + line.slice('rename from '.length).trim().replace(/^"|"$/g, '');
640
+ pendingHeader.sawContent = true;
641
+ }
642
+ }
643
+ flushPending(false);
644
+ if (!sawAnyHeader && diff.trim().length > 0) {
645
+ return {
646
+ changed: [],
647
+ unmapped: [],
648
+ error: 'unified diff 格式不合法:未找到 `diff --git` 头',
649
+ };
650
+ }
651
+ return { changed, unmapped };
652
+ }
653
+ function stripDiffPrefix(p) {
654
+ if (p.startsWith('a/'))
655
+ return p.slice(2);
656
+ if (p.startsWith('b/'))
657
+ return p.slice(2);
658
+ return p;
659
+ }
660
+ // ─── git diff baseRef 路径 ──────────────────────────────────
661
+ function runGitDiffNameStatus(baseRef, projectRoot) {
662
+ if (!BASEREF_WHITELIST.test(baseRef) || baseRef.startsWith('-')) {
663
+ return {
664
+ ok: false,
665
+ code: 'invalid-input',
666
+ message: `baseRef 含非法字符或以 - 开头: ${baseRef}`,
667
+ context: { reason: 'baseref-format' },
668
+ };
669
+ }
670
+ // 1) rev-parse 验证
671
+ const rev = spawnSync('git', ['rev-parse', '--verify', `${baseRef}^{commit}`], {
672
+ cwd: projectRoot,
673
+ shell: false,
674
+ timeout: REVPARSE_TIMEOUT_MS,
675
+ encoding: 'utf-8',
676
+ });
677
+ if (rev.error !== undefined && rev.error.code === 'ETIMEDOUT') {
678
+ return { ok: false, code: 'git-timeout', message: `rev-parse 超时 (${REVPARSE_TIMEOUT_MS} ms)` };
679
+ }
680
+ if (rev.status !== 0) {
681
+ const stderr = (rev.stderr ?? '').toString().slice(0, 200);
682
+ return {
683
+ ok: false,
684
+ code: 'git-spawn-failed',
685
+ message: `rev-parse 失败: ${stderr || 'unknown'}`,
686
+ context: { reason: 'baseref-invalid', stderr },
687
+ };
688
+ }
689
+ const sha = rev.stdout.trim();
690
+ if (sha.length === 0) {
691
+ return { ok: false, code: 'git-spawn-failed', message: 'rev-parse 返回空 sha' };
692
+ }
693
+ // 2) git diff --name-status
694
+ const diff = spawnSync('git', ['diff', '--name-status', `${sha}...HEAD`], {
695
+ cwd: projectRoot,
696
+ shell: false,
697
+ timeout: GIT_TIMEOUT_MS,
698
+ encoding: 'utf-8',
699
+ });
700
+ if (diff.error !== undefined && diff.error.code === 'ETIMEDOUT') {
701
+ return { ok: false, code: 'git-timeout', message: `git diff 超时 (${GIT_TIMEOUT_MS} ms)` };
702
+ }
703
+ if (diff.status !== 0) {
704
+ const stderr = (diff.stderr ?? '').toString().slice(0, 200);
705
+ return { ok: false, code: 'git-spawn-failed', message: `git diff 失败: ${stderr}` };
706
+ }
707
+ const changed = [];
708
+ const unmapped = [];
709
+ const out = diff.stdout.toString();
710
+ for (const rawLine of out.split('\n')) {
711
+ const line = rawLine.trim();
712
+ if (line.length === 0)
713
+ continue;
714
+ const parts = line.split('\t');
715
+ const status = parts[0] ?? '';
716
+ if (status.startsWith('R')) {
717
+ // R<score>\told\tnew
718
+ const newPath = parts[2];
719
+ if (typeof newPath === 'string' && newPath.length > 0) {
720
+ changed.push({ file: newPath, changeKind: 'rename' });
721
+ }
722
+ }
723
+ else if (status === 'M') {
724
+ const file = parts[1];
725
+ if (typeof file === 'string')
726
+ changed.push({ file, changeKind: 'modified' });
727
+ }
728
+ else if (status === 'A') {
729
+ const file = parts[1];
730
+ if (typeof file === 'string')
731
+ unmapped.push({ file, reason: 'new-file-not-in-graph-yet' });
732
+ }
733
+ else if (status === 'D') {
734
+ const file = parts[1];
735
+ if (typeof file === 'string')
736
+ unmapped.push({ file, reason: 'deleted-file' });
737
+ }
738
+ else {
739
+ // 其他状态(C / T / U 等)按 modified 处理
740
+ const file = parts[parts.length - 1];
741
+ if (typeof file === 'string')
742
+ changed.push({ file, changeKind: 'modified' });
743
+ }
744
+ }
745
+ return { ok: true, changed, unmapped };
746
+ }
747
+ // ─── file → symbols 索引 ───────────────────────────────────
748
+ function buildFileSymbolIndex(graphData) {
749
+ const index = new Map();
750
+ for (const node of graphData.nodes) {
751
+ const file = moduleFileFromId(node.id);
752
+ const list = index.get(file) ?? [];
753
+ list.push(node.id);
754
+ index.set(file, list);
755
+ }
756
+ return index;
757
+ }
758
+ // ============================================================
759
+ // 注册入口
760
+ // ============================================================
761
+ /**
762
+ * 把 3 个 Agent-Context tool 注册到 MCP server。
763
+ * 在 server.ts 里 registerGraphTools(server) 之后调用。
764
+ */
765
+ export function registerAgentContextTools(server) {
766
+ server.tool('impact', `查询 symbol 改动的 blast radius — 反向/正向 BFS 遍历调用链,返回受影响 symbols + risk summary。
767
+
768
+ Use this tool when:
769
+ - 改动前评估 caller 影响面
770
+ - 重构前看 transitive 影响(depth=3-5)
771
+ - 决定 PR review 范围
772
+
773
+ Example:
774
+ - Input: { target: "engine.py::Value.add", depth: 2 }
775
+ - Output: { affected, summary, topImpacted: [{ id, score }], nextStepHint }
776
+
777
+ Typical chained usage:
778
+ - 修代码前: detect_changes → impact → context`, ImpactInputSchema, async (args) => handleImpact(args));
779
+ server.tool('context', `查询 symbol 360° 上下文 — definition + callers + callees + imports + topRelevantCallers。
780
+
781
+ Use this tool when:
782
+ - 第一次接触某 symbol,理解位置/调用方/依赖
783
+ - 修改前查 caller 风格保持一致
784
+ - 调试时定位上游引用源头
785
+
786
+ Example:
787
+ - Input: { symbolId: "engine.py::Value" }
788
+ - Output: { definition, callers, callees, imports, topRelevantCallers, nextStepHint }
789
+
790
+ Typical chained usage:
791
+ - impact → context(查 top 受影响节点的上下文)`, ContextInputSchema, async (args) => handleContext(args));
792
+ server.tool('detect_changes', `从 git diff(unified diff 或 baseRef)派生 changedSymbols + BFS 影响链 + risk 总结。
793
+
794
+ Use this tool when:
795
+ - 收到 patch/PR diff 找实际改动 symbol
796
+ - 提交前自检本次改动的上游影响
797
+ - review 大型 PR 按 risk tier 分级
798
+
799
+ Example:
800
+ - Input: { diff: "diff --git a/engine.py..." } 或 { baseRef: "HEAD~3" }
801
+ - Output: { changedSymbols, affectedSymbols, riskSummary, riskTier, topImpacted, nextStepHint }
802
+
803
+ Typical chained usage:
804
+ - detect_changes → impact → context`, DetectChangesInputSchema, async (args) => handleDetectChanges(args));
805
+ }
806
+ //# sourceMappingURL=agent-context-tools.js.map