spectra-cli 4.1.1 → 4.2.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 (422) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/go-adapter.d.ts.map +1 -1
  3. package/dist/adapters/go-adapter.js +2 -0
  4. package/dist/adapters/go-adapter.js.map +1 -1
  5. package/dist/adapters/index.d.ts +1 -1
  6. package/dist/adapters/index.d.ts.map +1 -1
  7. package/dist/adapters/java-adapter.d.ts.map +1 -1
  8. package/dist/adapters/java-adapter.js +2 -0
  9. package/dist/adapters/java-adapter.js.map +1 -1
  10. package/dist/adapters/language-adapter.d.ts +47 -9
  11. package/dist/adapters/language-adapter.d.ts.map +1 -1
  12. package/dist/adapters/python-adapter.d.ts +34 -6
  13. package/dist/adapters/python-adapter.d.ts.map +1 -1
  14. package/dist/adapters/python-adapter.js +157 -59
  15. package/dist/adapters/python-adapter.js.map +1 -1
  16. package/dist/adapters/ts-js-adapter.d.ts +13 -5
  17. package/dist/adapters/ts-js-adapter.d.ts.map +1 -1
  18. package/dist/adapters/ts-js-adapter.js +55 -14
  19. package/dist/adapters/ts-js-adapter.js.map +1 -1
  20. package/dist/batch/batch-orchestrator.d.ts +30 -4
  21. package/dist/batch/batch-orchestrator.d.ts.map +1 -1
  22. package/dist/batch/batch-orchestrator.js +284 -7
  23. package/dist/batch/batch-orchestrator.js.map +1 -1
  24. package/dist/batch/delta-regenerator.d.ts +2 -2
  25. package/dist/batch/delta-regenerator.d.ts.map +1 -1
  26. package/dist/batch/delta-regenerator.js.map +1 -1
  27. package/dist/batch/module-grouper.d.ts +2 -2
  28. package/dist/batch/module-grouper.d.ts.map +1 -1
  29. package/dist/batch/module-grouper.js +1 -1
  30. package/dist/batch/module-grouper.js.map +1 -1
  31. package/dist/cli/commands/graph.js +1 -1
  32. package/dist/cli/commands/graph.js.map +1 -1
  33. package/dist/cli/commands/index.d.ts +8 -0
  34. package/dist/cli/commands/index.d.ts.map +1 -0
  35. package/dist/cli/commands/index.js +274 -0
  36. package/dist/cli/commands/index.js.map +1 -0
  37. package/dist/cli/commands/query.d.ts.map +1 -1
  38. package/dist/cli/commands/query.js +3 -1
  39. package/dist/cli/commands/query.js.map +1 -1
  40. package/dist/cli/index.js +9 -9
  41. package/dist/cli/index.js.map +1 -1
  42. package/dist/cli/utils/parse-args.d.ts +13 -1
  43. package/dist/cli/utils/parse-args.d.ts.map +1 -1
  44. package/dist/cli/utils/parse-args.js +79 -2
  45. package/dist/cli/utils/parse-args.js.map +1 -1
  46. package/dist/core/ast-analyzer.d.ts.map +1 -1
  47. package/dist/core/ast-analyzer.js +79 -5
  48. package/dist/core/ast-analyzer.js.map +1 -1
  49. package/dist/core/import-resolver.d.ts +90 -0
  50. package/dist/core/import-resolver.d.ts.map +1 -0
  51. package/dist/core/import-resolver.js +273 -0
  52. package/dist/core/import-resolver.js.map +1 -0
  53. package/dist/core/query-mappers/base-mapper.d.ts +13 -0
  54. package/dist/core/query-mappers/base-mapper.d.ts.map +1 -1
  55. package/dist/core/query-mappers/go-mapper.d.ts +68 -0
  56. package/dist/core/query-mappers/go-mapper.d.ts.map +1 -1
  57. package/dist/core/query-mappers/go-mapper.js +421 -0
  58. package/dist/core/query-mappers/go-mapper.js.map +1 -1
  59. package/dist/core/query-mappers/java-mapper.d.ts +196 -0
  60. package/dist/core/query-mappers/java-mapper.d.ts.map +1 -1
  61. package/dist/core/query-mappers/java-mapper.js +600 -0
  62. package/dist/core/query-mappers/java-mapper.js.map +1 -1
  63. package/dist/core/query-mappers/python-mapper.d.ts +55 -0
  64. package/dist/core/query-mappers/python-mapper.d.ts.map +1 -1
  65. package/dist/core/query-mappers/python-mapper.js +273 -0
  66. package/dist/core/query-mappers/python-mapper.js.map +1 -1
  67. package/dist/core/query-mappers/typescript-mapper.d.ts +102 -0
  68. package/dist/core/query-mappers/typescript-mapper.d.ts.map +1 -1
  69. package/dist/core/query-mappers/typescript-mapper.js +470 -0
  70. package/dist/core/query-mappers/typescript-mapper.js.map +1 -1
  71. package/dist/core/single-spec-orchestrator.d.ts.map +1 -1
  72. package/dist/core/single-spec-orchestrator.js +146 -9
  73. package/dist/core/single-spec-orchestrator.js.map +1 -1
  74. package/dist/core/tree-sitter-analyzer.d.ts +6 -0
  75. package/dist/core/tree-sitter-analyzer.d.ts.map +1 -1
  76. package/dist/core/tree-sitter-analyzer.js +33 -1
  77. package/dist/core/tree-sitter-analyzer.js.map +1 -1
  78. package/dist/core/tree-sitter-fallback.d.ts +7 -4
  79. package/dist/core/tree-sitter-fallback.d.ts.map +1 -1
  80. package/dist/core/tree-sitter-fallback.js +157 -12
  81. package/dist/core/tree-sitter-fallback.js.map +1 -1
  82. package/dist/extraction/extraction-types.d.ts +25 -25
  83. package/dist/generator/index-generator.d.ts +3 -3
  84. package/dist/generator/index-generator.d.ts.map +1 -1
  85. package/dist/generator/index-generator.js +1 -1
  86. package/dist/generator/index-generator.js.map +1 -1
  87. package/dist/graph/directory-graph.d.ts +14 -4
  88. package/dist/graph/directory-graph.d.ts.map +1 -1
  89. package/dist/graph/directory-graph.js +71 -128
  90. package/dist/graph/directory-graph.js.map +1 -1
  91. package/dist/graph/mermaid-renderer.d.ts +8 -5
  92. package/dist/graph/mermaid-renderer.d.ts.map +1 -1
  93. package/dist/graph/mermaid-renderer.js +3 -3
  94. package/dist/graph/mermaid-renderer.js.map +1 -1
  95. package/dist/graph/topological-sort.d.ts +13 -6
  96. package/dist/graph/topological-sort.d.ts.map +1 -1
  97. package/dist/graph/topological-sort.js +2 -2
  98. package/dist/graph/topological-sort.js.map +1 -1
  99. package/dist/knowledge-graph/call-resolver.d.ts +64 -0
  100. package/dist/knowledge-graph/call-resolver.d.ts.map +1 -0
  101. package/dist/knowledge-graph/call-resolver.js +323 -0
  102. package/dist/knowledge-graph/call-resolver.js.map +1 -0
  103. package/dist/knowledge-graph/import-resolver.d.ts +114 -0
  104. package/dist/knowledge-graph/import-resolver.d.ts.map +1 -0
  105. package/dist/knowledge-graph/import-resolver.js +537 -0
  106. package/dist/knowledge-graph/import-resolver.js.map +1 -0
  107. package/dist/knowledge-graph/incremental.d.ts +110 -0
  108. package/dist/knowledge-graph/incremental.d.ts.map +1 -0
  109. package/dist/knowledge-graph/incremental.js +410 -0
  110. package/dist/knowledge-graph/incremental.js.map +1 -0
  111. package/dist/knowledge-graph/index.d.ts +74 -0
  112. package/dist/knowledge-graph/index.d.ts.map +1 -0
  113. package/dist/knowledge-graph/index.js +156 -0
  114. package/dist/knowledge-graph/index.js.map +1 -0
  115. package/dist/knowledge-graph/module-derivation.d.ts +238 -0
  116. package/dist/knowledge-graph/module-derivation.d.ts.map +1 -0
  117. package/dist/knowledge-graph/module-derivation.js +418 -0
  118. package/dist/knowledge-graph/module-derivation.js.map +1 -0
  119. package/dist/knowledge-graph/persistence.d.ts +270 -0
  120. package/dist/knowledge-graph/persistence.d.ts.map +1 -0
  121. package/dist/knowledge-graph/persistence.js +226 -0
  122. package/dist/knowledge-graph/persistence.js.map +1 -0
  123. package/dist/knowledge-graph/query-helpers.d.ts +164 -0
  124. package/dist/knowledge-graph/query-helpers.d.ts.map +1 -0
  125. package/dist/knowledge-graph/query-helpers.js +394 -0
  126. package/dist/knowledge-graph/query-helpers.js.map +1 -0
  127. package/dist/knowledge-graph/unified-graph.d.ts +310 -0
  128. package/dist/knowledge-graph/unified-graph.d.ts.map +1 -0
  129. package/dist/knowledge-graph/unified-graph.js +182 -0
  130. package/dist/knowledge-graph/unified-graph.js.map +1 -0
  131. package/dist/mcp/agent-context-tools.d.ts +104 -0
  132. package/dist/mcp/agent-context-tools.d.ts.map +1 -0
  133. package/dist/mcp/agent-context-tools.js +854 -0
  134. package/dist/mcp/agent-context-tools.js.map +1 -0
  135. package/dist/mcp/graph-tools.d.ts +20 -0
  136. package/dist/mcp/graph-tools.d.ts.map +1 -1
  137. package/dist/mcp/graph-tools.js +71 -11
  138. package/dist/mcp/graph-tools.js.map +1 -1
  139. package/dist/mcp/lib/response-helpers.d.ts +67 -0
  140. package/dist/mcp/lib/response-helpers.d.ts.map +1 -0
  141. package/dist/mcp/lib/response-helpers.js +103 -0
  142. package/dist/mcp/lib/response-helpers.js.map +1 -0
  143. package/dist/mcp/server.d.ts +3 -1
  144. package/dist/mcp/server.d.ts.map +1 -1
  145. package/dist/mcp/server.js +9 -10
  146. package/dist/mcp/server.js.map +1 -1
  147. package/dist/models/call-site.d.ts +68 -0
  148. package/dist/models/call-site.d.ts.map +1 -0
  149. package/dist/models/call-site.js +60 -0
  150. package/dist/models/call-site.js.map +1 -0
  151. package/dist/models/code-skeleton.d.ts +78 -6
  152. package/dist/models/code-skeleton.d.ts.map +1 -1
  153. package/dist/models/code-skeleton.js +29 -0
  154. package/dist/models/code-skeleton.js.map +1 -1
  155. package/dist/models/drift-item.d.ts +4 -4
  156. package/dist/models/module-spec.d.ts +155 -94
  157. package/dist/models/module-spec.d.ts.map +1 -1
  158. package/dist/panoramic/adr-decision-pipeline.d.ts +53 -0
  159. package/dist/panoramic/adr-decision-pipeline.d.ts.map +1 -0
  160. package/dist/panoramic/adr-decision-pipeline.js +685 -0
  161. package/dist/panoramic/adr-decision-pipeline.js.map +1 -0
  162. package/dist/panoramic/api-surface-generator.d.ts +56 -0
  163. package/dist/panoramic/api-surface-generator.d.ts.map +1 -0
  164. package/dist/panoramic/api-surface-generator.js +1671 -0
  165. package/dist/panoramic/api-surface-generator.js.map +1 -0
  166. package/dist/panoramic/architecture-ir-builder.d.ts +19 -0
  167. package/dist/panoramic/architecture-ir-builder.d.ts.map +1 -0
  168. package/dist/panoramic/architecture-ir-builder.js +561 -0
  169. package/dist/panoramic/architecture-ir-builder.js.map +1 -0
  170. package/dist/panoramic/architecture-ir-exporters.d.ts +7 -0
  171. package/dist/panoramic/architecture-ir-exporters.d.ts.map +1 -0
  172. package/dist/panoramic/architecture-ir-exporters.js +183 -0
  173. package/dist/panoramic/architecture-ir-exporters.js.map +1 -0
  174. package/dist/panoramic/architecture-ir-generator.d.ts +36 -0
  175. package/dist/panoramic/architecture-ir-generator.d.ts.map +1 -0
  176. package/dist/panoramic/architecture-ir-generator.js +51 -0
  177. package/dist/panoramic/architecture-ir-generator.js.map +1 -0
  178. package/dist/panoramic/architecture-ir-mermaid-adapter.d.ts +6 -0
  179. package/dist/panoramic/architecture-ir-mermaid-adapter.d.ts.map +1 -0
  180. package/dist/panoramic/architecture-ir-mermaid-adapter.js +98 -0
  181. package/dist/panoramic/architecture-ir-mermaid-adapter.js.map +1 -0
  182. package/dist/panoramic/architecture-ir-model.d.ts +87 -0
  183. package/dist/panoramic/architecture-ir-model.d.ts.map +1 -0
  184. package/dist/panoramic/architecture-ir-model.js +20 -0
  185. package/dist/panoramic/architecture-ir-model.js.map +1 -0
  186. package/dist/panoramic/architecture-narrative.d.ts +68 -0
  187. package/dist/panoramic/architecture-narrative.d.ts.map +1 -0
  188. package/dist/panoramic/architecture-narrative.js +401 -0
  189. package/dist/panoramic/architecture-narrative.js.map +1 -0
  190. package/dist/panoramic/architecture-overview-generator.d.ts +31 -0
  191. package/dist/panoramic/architecture-overview-generator.d.ts.map +1 -0
  192. package/dist/panoramic/architecture-overview-generator.js +454 -0
  193. package/dist/panoramic/architecture-overview-generator.js.map +1 -0
  194. package/dist/panoramic/architecture-overview-model.d.ts +77 -0
  195. package/dist/panoramic/architecture-overview-model.d.ts.map +1 -0
  196. package/dist/panoramic/architecture-overview-model.js +31 -0
  197. package/dist/panoramic/architecture-overview-model.js.map +1 -0
  198. package/dist/panoramic/batch-project-docs.d.ts.map +1 -1
  199. package/dist/panoramic/batch-project-docs.js +4 -2
  200. package/dist/panoramic/batch-project-docs.js.map +1 -1
  201. package/dist/panoramic/builders/component-view-builder.d.ts +25 -1
  202. package/dist/panoramic/builders/component-view-builder.d.ts.map +1 -1
  203. package/dist/panoramic/builders/component-view-builder.js +83 -3
  204. package/dist/panoramic/builders/component-view-builder.js.map +1 -1
  205. package/dist/panoramic/builders/doc-graph-builder.d.ts +2 -2
  206. package/dist/panoramic/builders/doc-graph-builder.d.ts.map +1 -1
  207. package/dist/panoramic/builders/doc-graph-builder.js.map +1 -1
  208. package/dist/panoramic/component-view-builder.d.ts +17 -0
  209. package/dist/panoramic/component-view-builder.d.ts.map +1 -0
  210. package/dist/panoramic/component-view-builder.js +652 -0
  211. package/dist/panoramic/component-view-builder.js.map +1 -0
  212. package/dist/panoramic/component-view-model.d.ts +127 -0
  213. package/dist/panoramic/component-view-model.d.ts.map +1 -0
  214. package/dist/panoramic/component-view-model.js +65 -0
  215. package/dist/panoramic/component-view-model.js.map +1 -0
  216. package/dist/panoramic/config-reference-generator.d.ts +78 -0
  217. package/dist/panoramic/config-reference-generator.d.ts.map +1 -0
  218. package/dist/panoramic/config-reference-generator.js +199 -0
  219. package/dist/panoramic/config-reference-generator.js.map +1 -0
  220. package/dist/panoramic/coverage-auditor.d.ts +95 -0
  221. package/dist/panoramic/coverage-auditor.d.ts.map +1 -0
  222. package/dist/panoramic/coverage-auditor.js +290 -0
  223. package/dist/panoramic/coverage-auditor.js.map +1 -0
  224. package/dist/panoramic/cross-package-analyzer.d.ts +112 -0
  225. package/dist/panoramic/cross-package-analyzer.d.ts.map +1 -0
  226. package/dist/panoramic/cross-package-analyzer.js +258 -0
  227. package/dist/panoramic/cross-package-analyzer.js.map +1 -0
  228. package/dist/panoramic/data-model-generator.d.ts +528 -0
  229. package/dist/panoramic/data-model-generator.d.ts.map +1 -0
  230. package/dist/panoramic/data-model-generator.js +647 -0
  231. package/dist/panoramic/data-model-generator.js.map +1 -0
  232. package/dist/panoramic/doc-graph-builder.d.ts +80 -0
  233. package/dist/panoramic/doc-graph-builder.d.ts.map +1 -0
  234. package/dist/panoramic/doc-graph-builder.js +352 -0
  235. package/dist/panoramic/doc-graph-builder.js.map +1 -0
  236. package/dist/panoramic/docs-bundle-manifest-reader.d.ts +26 -0
  237. package/dist/panoramic/docs-bundle-manifest-reader.d.ts.map +1 -0
  238. package/dist/panoramic/docs-bundle-manifest-reader.js +106 -0
  239. package/dist/panoramic/docs-bundle-manifest-reader.js.map +1 -0
  240. package/dist/panoramic/docs-bundle-orchestrator.d.ts +14 -0
  241. package/dist/panoramic/docs-bundle-orchestrator.d.ts.map +1 -0
  242. package/dist/panoramic/docs-bundle-orchestrator.js +538 -0
  243. package/dist/panoramic/docs-bundle-orchestrator.js.map +1 -0
  244. package/dist/panoramic/docs-bundle-profiles.d.ts +4 -0
  245. package/dist/panoramic/docs-bundle-profiles.d.ts.map +1 -0
  246. package/dist/panoramic/docs-bundle-profiles.js +82 -0
  247. package/dist/panoramic/docs-bundle-profiles.js.map +1 -0
  248. package/dist/panoramic/docs-bundle-types.d.ts +94 -0
  249. package/dist/panoramic/docs-bundle-types.d.ts.map +1 -0
  250. package/dist/panoramic/docs-bundle-types.js +10 -0
  251. package/dist/panoramic/docs-bundle-types.js.map +1 -0
  252. package/dist/panoramic/docs-quality-evaluator.d.ts +31 -0
  253. package/dist/panoramic/docs-quality-evaluator.d.ts.map +1 -0
  254. package/dist/panoramic/docs-quality-evaluator.js +941 -0
  255. package/dist/panoramic/docs-quality-evaluator.js.map +1 -0
  256. package/dist/panoramic/docs-quality-model.d.ts +125 -0
  257. package/dist/panoramic/docs-quality-model.d.ts.map +1 -0
  258. package/dist/panoramic/docs-quality-model.js +166 -0
  259. package/dist/panoramic/docs-quality-model.js.map +1 -0
  260. package/dist/panoramic/dynamic-scenarios-builder.d.ts +18 -0
  261. package/dist/panoramic/dynamic-scenarios-builder.d.ts.map +1 -0
  262. package/dist/panoramic/dynamic-scenarios-builder.js +316 -0
  263. package/dist/panoramic/dynamic-scenarios-builder.js.map +1 -0
  264. package/dist/panoramic/event-surface-generator.d.ts +52 -0
  265. package/dist/panoramic/event-surface-generator.d.ts.map +1 -0
  266. package/dist/panoramic/event-surface-generator.js +507 -0
  267. package/dist/panoramic/event-surface-generator.js.map +1 -0
  268. package/dist/panoramic/generator-registry.d.ts +1 -1
  269. package/dist/panoramic/generator-registry.d.ts.map +1 -1
  270. package/dist/panoramic/generator-registry.js +5 -2
  271. package/dist/panoramic/generator-registry.js.map +1 -1
  272. package/dist/panoramic/generators/cross-package-analyzer.d.ts +5 -5
  273. package/dist/panoramic/generators/cross-package-analyzer.d.ts.map +1 -1
  274. package/dist/panoramic/generators/cross-package-analyzer.js +1 -1
  275. package/dist/panoramic/generators/cross-package-analyzer.js.map +1 -1
  276. package/dist/panoramic/generators/data-model-generator.d.ts +27 -27
  277. package/dist/panoramic/graph/confidence-mapper.d.ts +18 -0
  278. package/dist/panoramic/graph/confidence-mapper.d.ts.map +1 -1
  279. package/dist/panoramic/graph/confidence-mapper.js +26 -0
  280. package/dist/panoramic/graph/confidence-mapper.js.map +1 -1
  281. package/dist/panoramic/graph/graph-builder.d.ts.map +1 -1
  282. package/dist/panoramic/graph/graph-builder.js +78 -0
  283. package/dist/panoramic/graph/graph-builder.js.map +1 -1
  284. package/dist/panoramic/graph/graph-paths.d.ts +8 -0
  285. package/dist/panoramic/graph/graph-paths.d.ts.map +1 -1
  286. package/dist/panoramic/graph/graph-paths.js +10 -0
  287. package/dist/panoramic/graph/graph-paths.js.map +1 -1
  288. package/dist/panoramic/graph/graph-query.d.ts +33 -2
  289. package/dist/panoramic/graph/graph-query.d.ts.map +1 -1
  290. package/dist/panoramic/graph/graph-query.js +69 -19
  291. package/dist/panoramic/graph/graph-query.js.map +1 -1
  292. package/dist/panoramic/graph/graph-types.d.ts +32 -3
  293. package/dist/panoramic/graph/graph-types.d.ts.map +1 -1
  294. package/dist/panoramic/hyperedges/schema.d.ts +6 -6
  295. package/dist/panoramic/interface-surface-generator.d.ts +50 -0
  296. package/dist/panoramic/interface-surface-generator.d.ts.map +1 -0
  297. package/dist/panoramic/interface-surface-generator.js +388 -0
  298. package/dist/panoramic/interface-surface-generator.js.map +1 -0
  299. package/dist/panoramic/interfaces.d.ts +2 -2
  300. package/dist/panoramic/mock-readme-generator.d.ts +90 -0
  301. package/dist/panoramic/mock-readme-generator.d.ts.map +1 -0
  302. package/dist/panoramic/mock-readme-generator.js +111 -0
  303. package/dist/panoramic/mock-readme-generator.js.map +1 -0
  304. package/dist/panoramic/models/component-view-model.d.ts +1 -1
  305. package/dist/panoramic/models/component-view-model.d.ts.map +1 -1
  306. package/dist/panoramic/models/component-view-model.js.map +1 -1
  307. package/dist/panoramic/narrative-provenance-adapter.d.ts +8 -0
  308. package/dist/panoramic/narrative-provenance-adapter.d.ts.map +1 -0
  309. package/dist/panoramic/narrative-provenance-adapter.js +99 -0
  310. package/dist/panoramic/narrative-provenance-adapter.js.map +1 -0
  311. package/dist/panoramic/parser-registry.d.ts +1 -1
  312. package/dist/panoramic/parser-registry.js +1 -1
  313. package/dist/panoramic/parsers/types.d.ts +6 -6
  314. package/dist/panoramic/pattern-hints-generator.d.ts +28 -0
  315. package/dist/panoramic/pattern-hints-generator.d.ts.map +1 -0
  316. package/dist/panoramic/pattern-hints-generator.js +218 -0
  317. package/dist/panoramic/pattern-hints-generator.js.map +1 -0
  318. package/dist/panoramic/pattern-hints-model.d.ts +89 -0
  319. package/dist/panoramic/pattern-hints-model.d.ts.map +1 -0
  320. package/dist/panoramic/pattern-hints-model.js +61 -0
  321. package/dist/panoramic/pattern-hints-model.js.map +1 -0
  322. package/dist/panoramic/pattern-knowledge-base.d.ts +31 -0
  323. package/dist/panoramic/pattern-knowledge-base.d.ts.map +1 -0
  324. package/dist/panoramic/pattern-knowledge-base.js +407 -0
  325. package/dist/panoramic/pattern-knowledge-base.js.map +1 -0
  326. package/dist/panoramic/pipelines/coverage-auditor.d.ts.map +1 -1
  327. package/dist/panoramic/pipelines/coverage-auditor.js +4 -2
  328. package/dist/panoramic/pipelines/coverage-auditor.js.map +1 -1
  329. package/dist/panoramic/pipelines/docs-bundle-orchestrator.js +13 -6
  330. package/dist/panoramic/pipelines/docs-bundle-orchestrator.js.map +1 -1
  331. package/dist/panoramic/pipelines/product-ux-docs.d.ts +5 -0
  332. package/dist/panoramic/pipelines/product-ux-docs.d.ts.map +1 -1
  333. package/dist/panoramic/pipelines/product-ux-docs.js +34 -6
  334. package/dist/panoramic/pipelines/product-ux-docs.js.map +1 -1
  335. package/dist/panoramic/product-ux-docs.d.ts +104 -0
  336. package/dist/panoramic/product-ux-docs.d.ts.map +1 -0
  337. package/dist/panoramic/product-ux-docs.js +817 -0
  338. package/dist/panoramic/product-ux-docs.js.map +1 -0
  339. package/dist/panoramic/qa/__tests__/citation.test.d.ts +2 -0
  340. package/dist/panoramic/qa/__tests__/citation.test.d.ts.map +1 -0
  341. package/dist/panoramic/qa/__tests__/citation.test.js +193 -0
  342. package/dist/panoramic/qa/__tests__/citation.test.js.map +1 -0
  343. package/dist/panoramic/qa/__tests__/debt-context.test.d.ts +2 -0
  344. package/dist/panoramic/qa/__tests__/debt-context.test.d.ts.map +1 -0
  345. package/dist/panoramic/qa/__tests__/debt-context.test.js +154 -0
  346. package/dist/panoramic/qa/__tests__/debt-context.test.js.map +1 -0
  347. package/dist/panoramic/qa/__tests__/graph-retriever.test.d.ts +2 -0
  348. package/dist/panoramic/qa/__tests__/graph-retriever.test.d.ts.map +1 -0
  349. package/dist/panoramic/qa/__tests__/graph-retriever.test.js +148 -0
  350. package/dist/panoramic/qa/__tests__/graph-retriever.test.js.map +1 -0
  351. package/dist/panoramic/qa/__tests__/index.test.d.ts +2 -0
  352. package/dist/panoramic/qa/__tests__/index.test.d.ts.map +1 -0
  353. package/dist/panoramic/qa/__tests__/index.test.js +246 -0
  354. package/dist/panoramic/qa/__tests__/index.test.js.map +1 -0
  355. package/dist/panoramic/qa/__tests__/llm-caller.test.d.ts +2 -0
  356. package/dist/panoramic/qa/__tests__/llm-caller.test.d.ts.map +1 -0
  357. package/dist/panoramic/qa/__tests__/llm-caller.test.js +168 -0
  358. package/dist/panoramic/qa/__tests__/llm-caller.test.js.map +1 -0
  359. package/dist/panoramic/qa/__tests__/prompt-builder.test.d.ts +2 -0
  360. package/dist/panoramic/qa/__tests__/prompt-builder.test.d.ts.map +1 -0
  361. package/dist/panoramic/qa/__tests__/prompt-builder.test.js +150 -0
  362. package/dist/panoramic/qa/__tests__/prompt-builder.test.js.map +1 -0
  363. package/dist/panoramic/qa/__tests__/qa-integration.test.d.ts +2 -0
  364. package/dist/panoramic/qa/__tests__/qa-integration.test.d.ts.map +1 -0
  365. package/dist/panoramic/qa/__tests__/qa-integration.test.js +296 -0
  366. package/dist/panoramic/qa/__tests__/qa-integration.test.js.map +1 -0
  367. package/dist/panoramic/qa/__tests__/rag-reranker.test.d.ts +2 -0
  368. package/dist/panoramic/qa/__tests__/rag-reranker.test.d.ts.map +1 -0
  369. package/dist/panoramic/qa/__tests__/rag-reranker.test.js +136 -0
  370. package/dist/panoramic/qa/__tests__/rag-reranker.test.js.map +1 -0
  371. package/dist/panoramic/qa/index.d.ts.map +1 -1
  372. package/dist/panoramic/qa/index.js +10 -3
  373. package/dist/panoramic/qa/index.js.map +1 -1
  374. package/dist/panoramic/runtime-topology-generator.d.ts +77 -0
  375. package/dist/panoramic/runtime-topology-generator.d.ts.map +1 -0
  376. package/dist/panoramic/runtime-topology-generator.js +676 -0
  377. package/dist/panoramic/runtime-topology-generator.js.map +1 -0
  378. package/dist/panoramic/runtime-topology-model.d.ts +145 -0
  379. package/dist/panoramic/runtime-topology-model.d.ts.map +1 -0
  380. package/dist/panoramic/runtime-topology-model.js +300 -0
  381. package/dist/panoramic/runtime-topology-model.js.map +1 -0
  382. package/dist/panoramic/troubleshooting-generator.d.ts +51 -0
  383. package/dist/panoramic/troubleshooting-generator.d.ts.map +1 -0
  384. package/dist/panoramic/troubleshooting-generator.js +451 -0
  385. package/dist/panoramic/troubleshooting-generator.js.map +1 -0
  386. package/dist/panoramic/utils/text-segmenter.d.ts +15 -0
  387. package/dist/panoramic/utils/text-segmenter.d.ts.map +1 -1
  388. package/dist/panoramic/utils/text-segmenter.js +38 -0
  389. package/dist/panoramic/utils/text-segmenter.js.map +1 -1
  390. package/dist/panoramic/workspace-index-generator.d.ts +148 -0
  391. package/dist/panoramic/workspace-index-generator.d.ts.map +1 -0
  392. package/dist/panoramic/workspace-index-generator.js +497 -0
  393. package/dist/panoramic/workspace-index-generator.js.map +1 -0
  394. package/dist/runtime-bootstrap.d.ts +9 -0
  395. package/dist/runtime-bootstrap.d.ts.map +1 -0
  396. package/dist/runtime-bootstrap.js +33 -0
  397. package/dist/runtime-bootstrap.js.map +1 -0
  398. package/dist/utils/file-scanner.js +1 -1
  399. package/dist/utils/file-scanner.js.map +1 -1
  400. package/package.json +12 -2
  401. package/plugins/spec-driver/.claude-plugin/plugin.json +1 -1
  402. package/plugins/spec-driver/README.md +18 -1
  403. package/plugins/spec-driver/agents/implement.md +20 -1
  404. package/plugins/spec-driver/agents/plan.md +20 -1
  405. package/plugins/spec-driver/agents/quality-review.md +20 -1
  406. package/plugins/spec-driver/agents/spec-review.md +20 -1
  407. package/plugins/spec-driver/agents/verify.md +20 -1
  408. package/plugins/spec-driver/docs/customization.md +134 -0
  409. package/plugins/spec-driver/docs/spectra-mcp-integration.md +165 -0
  410. package/plugins/spec-driver/lib/preference-rules.mjs +96 -0
  411. package/plugins/spec-driver/scripts/postinstall.sh +1 -1
  412. package/plugins/spec-driver/scripts/sync-preference-rules.mjs +148 -0
  413. package/plugins/spec-driver/skills/spec-driver-feature/SKILL.md +10 -0
  414. package/plugins/spec-driver/skills/spec-driver-fix/SKILL.md +10 -0
  415. package/plugins/spec-driver/skills/spec-driver-implement/SKILL.md +10 -0
  416. package/plugins/spec-driver/skills/spec-driver-refactor/SKILL.md +10 -0
  417. package/plugins/spec-driver/skills/spec-driver-story/SKILL.md +10 -0
  418. package/plugins/spec-driver/templates/preference-rules.md +39 -0
  419. package/plugins/spectra/.claude-plugin/plugin.json +1 -1
  420. package/plugins/spectra/README.md +48 -1
  421. package/plugins/spectra/hooks/post-commit.sh +40 -0
  422. package/templates/product-overview.hbs +1 -1
@@ -0,0 +1,537 @@
1
+ /**
2
+ * Feature 152 — 通用 Import Path 智能解析模块
3
+ *
4
+ * 提供 Python + TypeScript/JavaScript 的 import 路径解析能力,
5
+ * 供 collectPythonCodeSkeletons(P3)和 collectTsJsCodeSkeletons(P4)调用。
6
+ *
7
+ * 设计原则:
8
+ * - 纯函数(pure function),无状态,零新 npm 依赖(CL-01)
9
+ * - 所有 resolvedPath 输出为相对 projectRoot 的 POSIX 路径(W-5 修复)
10
+ * - 解析失败时返回 { resolvedPath: null, kind: 'unresolved' },不抛异常(FR-2.4)
11
+ *
12
+ * 修复说明(Codex V3 对抗审查通过后的完整修订):
13
+ * - C-1:from . import nn 由 collect 层拆解为 ".nn" 后调用 resolver
14
+ * - C-2:alias-like 前缀(~/、#/、$/、@/)无 paths 命中时返回 unresolved
15
+ * - C-5 + N-2:isInsideProjectRoot 逐 path component 判断,避免字典序误判
16
+ * - W-1:相对路径指向 .json / .d.ts 文件时返回 external
17
+ * - W-5:所有 resolvedPath 输出 POSIX 格式(toPosix 包裹)
18
+ */
19
+ import * as fs from 'fs';
20
+ import * as path from 'path';
21
+ // ───────────────────────────────────────────────────────────
22
+ // 常量
23
+ // ───────────────────────────────────────────────────────────
24
+ /**
25
+ * Python 标准库内置模块集合(plan §5.1 完整列表)。
26
+ * 调用 resolvePythonImport 时,topModule 在此集合内则返回 external。
27
+ */
28
+ const PYTHON_BUILTINS = new Set([
29
+ 'os',
30
+ 'sys',
31
+ 're',
32
+ 'io',
33
+ 'json',
34
+ 'math',
35
+ 'time',
36
+ 'datetime',
37
+ 'collections',
38
+ 'itertools',
39
+ 'functools',
40
+ 'pathlib',
41
+ 'typing',
42
+ 'abc',
43
+ 'copy',
44
+ 'string',
45
+ 'struct',
46
+ 'socket',
47
+ 'threading',
48
+ 'subprocess',
49
+ 'logging',
50
+ 'unittest',
51
+ 'hashlib',
52
+ 'base64',
53
+ 'random',
54
+ 'operator',
55
+ 'contextlib',
56
+ 'weakref',
57
+ 'inspect',
58
+ 'ast',
59
+ 'dis',
60
+ 'gc',
61
+ 'importlib',
62
+ 'types',
63
+ 'enum',
64
+ 'dataclasses',
65
+ 'warnings',
66
+ 'traceback',
67
+ 'pprint',
68
+ 'heapq',
69
+ 'bisect',
70
+ 'array',
71
+ 'queue',
72
+ 'shutil',
73
+ 'glob',
74
+ 'fnmatch',
75
+ 'tempfile',
76
+ 'pickle',
77
+ 'csv',
78
+ 'html',
79
+ 'http',
80
+ 'urllib',
81
+ 'email',
82
+ 'xml',
83
+ 'sqlite3',
84
+ 'zlib',
85
+ 'gzip',
86
+ 'tarfile',
87
+ 'zipfile',
88
+ 'argparse',
89
+ 'textwrap',
90
+ 'decimal',
91
+ 'fractions',
92
+ 'statistics',
93
+ 'cmath',
94
+ 'secrets',
95
+ 'uuid',
96
+ 'platform',
97
+ 'signal',
98
+ 'mmap',
99
+ 'concurrent',
100
+ 'asyncio',
101
+ 'select',
102
+ 'ssl',
103
+ 'configparser',
104
+ 'tomllib',
105
+ 'gettext',
106
+ 'locale',
107
+ 'curses',
108
+ 'readline',
109
+ 'rlcompleter',
110
+ ]);
111
+ /** TS/JS 候补扩展名顺序(plan §5.2) */
112
+ const TS_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx'];
113
+ /** TS/JS index 文件候补后缀 */
114
+ const TS_INDEX_SUFFIXES = TS_EXTENSIONS.map((ext) => `/index${ext}`);
115
+ /** alias-like 前缀列表(C-2 修复):以这些前缀开头的 moduleSpec 无 paths 命中时返回 unresolved */
116
+ const ALIAS_PREFIXES = ['~/', '#/', '$/'];
117
+ // ───────────────────────────────────────────────────────────
118
+ // 内部辅助函数
119
+ // ───────────────────────────────────────────────────────────
120
+ /**
121
+ * 将路径转换为 POSIX 格式(W-5 修复)。
122
+ * 确保跨平台 resolvedPath 始终使用 '/' 分隔符。
123
+ */
124
+ function toPosix(p) {
125
+ return p.split(path.sep).join('/');
126
+ }
127
+ /**
128
+ * 判断 candidate 路径是否严格在 projectRoot 子树内(C-5 + N-2 修复)。
129
+ *
130
+ * 使用 path.relative 计算相对路径,然后逐 path component 检查第一段是否为 '..',
131
+ * 避免字典序误判(如 /proj 与 /projection 的关系)。
132
+ *
133
+ * 注意:candidate === projectRoot 时返回 false(projectRoot 自身不算"在子树内")。
134
+ */
135
+ function isInsideProjectRoot(candidate, projectRoot) {
136
+ const rel = path.relative(projectRoot, candidate);
137
+ // candidate 与 projectRoot 完全相同
138
+ if (rel.length === 0)
139
+ return false;
140
+ // 跨盘符(Windows)
141
+ if (path.isAbsolute(rel))
142
+ return false;
143
+ // 逐 component 检查:第一段为 '..' 则越界
144
+ // 注意:rel='..cache/a.ts' 时 firstSeg='..cache',不为 '..',正确判定为子树内(N-2 修复)
145
+ const firstSeg = rel.split(path.sep)[0];
146
+ if (firstSeg === '..')
147
+ return false;
148
+ return true;
149
+ }
150
+ /**
151
+ * 判断路径是否指向非源文件目标(W-1 修复)。
152
+ * .json 和 .d.ts 文件不进入 callSites graph,返回 external。
153
+ */
154
+ function isNonSourceTarget(p) {
155
+ return p.endsWith('.json') || p.endsWith('.d.ts');
156
+ }
157
+ /**
158
+ * 统计字符串前缀中 '.' 的个数(用于 Python 相对 import level 计算)。
159
+ */
160
+ function countLeadingDots(moduleSpec) {
161
+ let count = 0;
162
+ for (const ch of moduleSpec) {
163
+ if (ch === '.')
164
+ count++;
165
+ else
166
+ break;
167
+ }
168
+ return count;
169
+ }
170
+ // ───────────────────────────────────────────────────────────
171
+ // Public API — resolvePythonImport
172
+ // ───────────────────────────────────────────────────────────
173
+ /**
174
+ * 解析 Python import 路径。
175
+ *
176
+ * 支持 5 种场景(plan §5.1):
177
+ * 1. 绝对包路径(`pkg.engine` → `pkg/engine.py`)
178
+ * 2. `__init__.py` 兜底(包目录 import)
179
+ * 3. 相对 import(level ≥ 1,PEP 328:上溯 level-1 级目录)
180
+ * 4. 祖先包 import(from .. import X)
181
+ * 5. Python stdlib 内置模块返回 external
182
+ *
183
+ * C-1 修复说明:moduleSpec="." 时 stripped 为空,resolver 仅返回 __init__.py;
184
+ * collect 层须把 "from . import nn" 拆解为 resolvePythonImport(".nn", callerFile, root)。
185
+ *
186
+ * @param moduleSpec - import 说明符(如 "micrograd.engine"、".nn"、"..pkg")
187
+ * @param callerFile - 调用方文件的绝对路径
188
+ * @param projectRoot - 项目根目录绝对路径
189
+ * @returns ResolveResult(resolvedPath 为相对 projectRoot 的 POSIX 路径)
190
+ */
191
+ export function resolvePythonImport(moduleSpec, callerFile, projectRoot) {
192
+ const level = countLeadingDots(moduleSpec);
193
+ const stripped = moduleSpec.slice(level); // 去掉前导点
194
+ if (level > 0) {
195
+ // PEP 328:from .X import Y → level=1,上溯 (level-1)=0 级,baseDir = callerFile 所在目录
196
+ // from ..X import Y → level=2,上溯 1 级
197
+ let baseDir = path.dirname(callerFile);
198
+ for (let i = 0; i < level - 1; i++) {
199
+ const parent = path.dirname(baseDir);
200
+ // C-5 修复:检查越界,使用 isInsideProjectRoot 而非字典序
201
+ if (!isInsideProjectRoot(baseDir, projectRoot) && baseDir !== projectRoot) {
202
+ return { resolvedPath: null, kind: 'unresolved' };
203
+ }
204
+ baseDir = parent;
205
+ // 上溯后再检查是否越界
206
+ if (!isInsideProjectRoot(baseDir, projectRoot) && baseDir !== projectRoot) {
207
+ return { resolvedPath: null, kind: 'unresolved' };
208
+ }
209
+ }
210
+ // C-1 修复:stripped 为空时,仅返回 baseDir/__init__.py(包级 import)
211
+ if (stripped === '') {
212
+ const candidate = path.join(baseDir, '__init__.py');
213
+ if (fs.existsSync(candidate)) {
214
+ return {
215
+ resolvedPath: toPosix(path.relative(projectRoot, candidate)),
216
+ kind: 'relative-sibling',
217
+ };
218
+ }
219
+ return { resolvedPath: null, kind: 'unresolved' };
220
+ }
221
+ // `from .submodule import X` 或 `from ..pkg import X`
222
+ const parts = stripped.split('.');
223
+ const candidate1 = path.join(baseDir, ...parts) + '.py';
224
+ const candidate2 = path.join(baseDir, ...parts, '__init__.py');
225
+ for (const candidate of [candidate1, candidate2]) {
226
+ if (fs.existsSync(candidate)) {
227
+ return {
228
+ resolvedPath: toPosix(path.relative(projectRoot, candidate)),
229
+ kind: 'relative-sibling',
230
+ };
231
+ }
232
+ }
233
+ return { resolvedPath: null, kind: 'unresolved' };
234
+ }
235
+ // 绝对 import(无前导点)
236
+ const topModule = moduleSpec.split('.')[0] ?? '';
237
+ // Python stdlib 内置模块
238
+ if (PYTHON_BUILTINS.has(topModule)) {
239
+ return { resolvedPath: null, kind: 'external' };
240
+ }
241
+ // dotted path → 文件路径
242
+ const parts = moduleSpec.split('.');
243
+ const candidate1 = path.join(projectRoot, ...parts) + '.py'; // pkg/engine.py
244
+ const candidate2 = path.join(projectRoot, ...parts, '__init__.py'); // pkg/engine/__init__.py
245
+ for (const candidate of [candidate1, candidate2]) {
246
+ if (fs.existsSync(candidate)) {
247
+ const kind = candidate.endsWith('__init__.py') ? 'package-init' : 'module';
248
+ // W-5 修复:Python absolute import 命中分支也必须 POSIX 化
249
+ return {
250
+ resolvedPath: toPosix(path.relative(projectRoot, candidate)),
251
+ kind,
252
+ };
253
+ }
254
+ }
255
+ return { resolvedPath: null, kind: 'unresolved' };
256
+ }
257
+ // ───────────────────────────────────────────────────────────
258
+ // Public API — resolveTsJsImport
259
+ // ───────────────────────────────────────────────────────────
260
+ /**
261
+ * 解析 TypeScript/JavaScript import 路径。
262
+ *
263
+ * 支持 4 种场景(plan §5.2):
264
+ * 1. 相对路径(`./engine`、`../utils`)按 .ts → .tsx → .js → .jsx → /index.ts 顺序候补
265
+ * 2. tsconfig paths alias(精确 key + wildcard,多 candidates 按数组顺序)
266
+ * 3. baseUrl 解析(baseUrl != null 时)
267
+ * 4. 外部包(npm bare 包名 / scoped 包)→ external
268
+ *
269
+ * 修复:
270
+ * - W-1:相对路径指向 .json / .d.ts 文件时返回 external(不入 callSites graph)
271
+ * - C-2:alias-like 前缀(~/、#/、$/、@/)无 paths 命中时返回 unresolved
272
+ *
273
+ * @param moduleSpec - import 说明符(如 "./engine"、"~/utils"、"express")
274
+ * @param callerFile - 调用方文件的绝对路径
275
+ * @param projectRoot - 项目根目录绝对路径
276
+ * @param tsConfigContext - tsconfig 解析上下文(null/undefined 时仅走相对路径)
277
+ * @returns ResolveResult
278
+ */
279
+ export function resolveTsJsImport(moduleSpec, callerFile, projectRoot, tsConfigContext) {
280
+ // 磁盘绝对路径(罕见)
281
+ if (moduleSpec.startsWith('/')) {
282
+ for (const ext of TS_EXTENSIONS) {
283
+ const candidate = moduleSpec + ext;
284
+ if (fs.existsSync(candidate)) {
285
+ // Codex final C-4 修复:候选必须在 projectRoot 内,否则 unresolved 防止 graph 污染
286
+ if (!isInsideProjectRoot(candidate, projectRoot)) {
287
+ return { resolvedPath: null, kind: 'unresolved' };
288
+ }
289
+ return {
290
+ resolvedPath: toPosix(path.relative(projectRoot, candidate)),
291
+ kind: 'absolute',
292
+ };
293
+ }
294
+ }
295
+ return { resolvedPath: null, kind: 'unresolved' };
296
+ }
297
+ // 相对路径(./ 或 ../)
298
+ if (moduleSpec.startsWith('./') || moduleSpec.startsWith('../')) {
299
+ // W-1 修复:moduleSpec 自身已带 .json / .d.ts 后缀 → external
300
+ if (isNonSourceTarget(moduleSpec)) {
301
+ return { resolvedPath: null, kind: 'external' };
302
+ }
303
+ const base = path.resolve(path.dirname(callerFile), moduleSpec);
304
+ // 按 .ts → .tsx → .js → .jsx 顺序候补
305
+ for (const ext of TS_EXTENSIONS) {
306
+ if (fs.existsSync(base + ext)) {
307
+ // Codex final C-4 修复:候选必须在 projectRoot 内
308
+ if (!isInsideProjectRoot(base + ext, projectRoot)) {
309
+ return { resolvedPath: null, kind: 'unresolved' };
310
+ }
311
+ return {
312
+ resolvedPath: toPosix(path.relative(projectRoot, base + ext)),
313
+ kind: 'relative',
314
+ };
315
+ }
316
+ }
317
+ // 按 /index.ts → /index.tsx 等顺序候补
318
+ for (const suffix of TS_INDEX_SUFFIXES) {
319
+ if (fs.existsSync(base + suffix)) {
320
+ // Codex final C-4 修复:候选必须在 projectRoot 内
321
+ if (!isInsideProjectRoot(base + suffix, projectRoot)) {
322
+ return { resolvedPath: null, kind: 'unresolved' };
323
+ }
324
+ return {
325
+ resolvedPath: toPosix(path.relative(projectRoot, base + suffix)),
326
+ kind: 'relative',
327
+ };
328
+ }
329
+ }
330
+ // 候补失败但 base 路径本身是 .json / .d.ts → 双保险 external
331
+ if (isNonSourceTarget(base)) {
332
+ return { resolvedPath: null, kind: 'external' };
333
+ }
334
+ return { resolvedPath: null, kind: 'unresolved' };
335
+ }
336
+ // 非相对路径:先尝试 paths alias,再 baseUrl,再判定 external
337
+ if (tsConfigContext) {
338
+ // Codex P0 C-1 修复:paths 必须**精确 key 优先于 wildcard**,不依赖 Map 插入顺序
339
+ // 否则用户 tsconfig 中 wildcard 排在 exact 前会先命中 wildcard
340
+ const exactEntries = [];
341
+ const wildcardEntries = [];
342
+ for (const [pattern, replacements] of tsConfigContext.paths) {
343
+ if (pattern.includes('*')) {
344
+ wildcardEntries.push([pattern, replacements]);
345
+ }
346
+ else {
347
+ exactEntries.push([pattern, replacements]);
348
+ }
349
+ }
350
+ const orderedPathsEntries = [...exactEntries, ...wildcardEntries];
351
+ for (const [pattern, replacements] of orderedPathsEntries) {
352
+ const matched = matchPathsPattern(moduleSpec, pattern);
353
+ if (matched !== null) {
354
+ const tail = matched; // wildcard 截断后的尾缀(精确 key 时为 '')
355
+ for (const replacement of replacements) {
356
+ // 替换 wildcard:精确 key 时 replacement 不含 '*',直接使用
357
+ const resolved = replacement.includes('*')
358
+ ? replacement.replace('*', tail)
359
+ : replacement;
360
+ // Codex final C-3 修复:paths replacement 必须叠加 baseUrl(TypeScript 官方语义)
361
+ // 标准模式:baseUrl="src", paths={"@/*": ["*"]} → "@/foo" 解析为 "<configDir>/src/foo"
362
+ // 实施:absBase = configDir + (baseUrl ?? '.') + replacement
363
+ const baseUrl = typeof tsConfigContext.baseUrl === 'string' ? tsConfigContext.baseUrl : '.';
364
+ const absBase = path.resolve(tsConfigContext.configDir, baseUrl, resolved);
365
+ for (const ext of TS_EXTENSIONS) {
366
+ if (fs.existsSync(absBase + ext)) {
367
+ return {
368
+ resolvedPath: toPosix(path.relative(projectRoot, absBase + ext)),
369
+ kind: 'paths-alias',
370
+ };
371
+ }
372
+ }
373
+ for (const suffix of TS_INDEX_SUFFIXES) {
374
+ if (fs.existsSync(absBase + suffix)) {
375
+ return {
376
+ resolvedPath: toPosix(path.relative(projectRoot, absBase + suffix)),
377
+ kind: 'paths-alias',
378
+ };
379
+ }
380
+ }
381
+ }
382
+ }
383
+ }
384
+ // baseUrl 解析(仅 baseUrl 是字符串时)
385
+ // Codex P0 C-2 修复:用 typeof 严格判断,避免 TS 类型签名 string|null 之外 undefined 误穿透
386
+ if (typeof tsConfigContext.baseUrl === 'string') {
387
+ const absBase = path.resolve(tsConfigContext.configDir, tsConfigContext.baseUrl, moduleSpec);
388
+ for (const ext of TS_EXTENSIONS) {
389
+ if (fs.existsSync(absBase + ext)) {
390
+ return {
391
+ resolvedPath: toPosix(path.relative(projectRoot, absBase + ext)),
392
+ kind: 'absolute',
393
+ };
394
+ }
395
+ }
396
+ for (const suffix of TS_INDEX_SUFFIXES) {
397
+ if (fs.existsSync(absBase + suffix)) {
398
+ return {
399
+ resolvedPath: toPosix(path.relative(projectRoot, absBase + suffix)),
400
+ kind: 'absolute',
401
+ };
402
+ }
403
+ }
404
+ }
405
+ }
406
+ // C-2 修复:区分 alias-like(unresolved)与 bare npm package(external)
407
+ // alias-like 前缀:~/、#/、$/
408
+ if (ALIAS_PREFIXES.some((p) => moduleSpec.startsWith(p))) {
409
+ return { resolvedPath: null, kind: 'unresolved' };
410
+ }
411
+ // @/foo(非 scoped 风格的 alias,区别于 @org/lib 这样的 scoped npm 包)
412
+ if (moduleSpec.startsWith('@/')) {
413
+ return { resolvedPath: null, kind: 'unresolved' };
414
+ }
415
+ // 合法 npm 包判定
416
+ const firstSeg = moduleSpec.split('/')[0] ?? '';
417
+ const isScoped = firstSeg.startsWith('@');
418
+ if (isScoped) {
419
+ // scoped 包形如 @org/lib — 首段以 @ 开头,且含 '/'(至少两段)
420
+ return { resolvedPath: null, kind: 'external' };
421
+ }
422
+ // bare npm 包名规则:[a-z0-9][a-z0-9-_.]*
423
+ if (/^[a-z0-9][a-z0-9-_.]*$/.test(firstSeg)) {
424
+ return { resolvedPath: null, kind: 'external' };
425
+ }
426
+ // 含 '/' 但首段不是合法 npm 包名 → alias-like 配置缺失
427
+ return { resolvedPath: null, kind: 'unresolved' };
428
+ }
429
+ /**
430
+ * 匹配 tsconfig paths pattern(精确 key + wildcard)。
431
+ *
432
+ * @param moduleSpec - 被解析的 import 说明符
433
+ * @param pattern - tsconfig paths 中的 key(如 "~/*"、"react")
434
+ * @returns null(不匹配),或 wildcard 截取的尾缀字符串(精确 key 时为 '')
435
+ */
436
+ function matchPathsPattern(moduleSpec, pattern) {
437
+ if (pattern.includes('*')) {
438
+ // wildcard 模式:将 * 前的部分作为前缀,* 后的部分作为后缀
439
+ const starIdx = pattern.indexOf('*');
440
+ const prefix = pattern.slice(0, starIdx);
441
+ const suffix = pattern.slice(starIdx + 1);
442
+ if (moduleSpec.startsWith(prefix) && moduleSpec.endsWith(suffix)) {
443
+ const tail = moduleSpec.slice(prefix.length, moduleSpec.length - suffix.length);
444
+ return tail;
445
+ }
446
+ return null;
447
+ }
448
+ else {
449
+ // 精确 key 匹配
450
+ if (moduleSpec === pattern)
451
+ return '';
452
+ return null;
453
+ }
454
+ }
455
+ // ───────────────────────────────────────────────────────────
456
+ // Public API — findNearestTsConfig
457
+ // ───────────────────────────────────────────────────────────
458
+ /**
459
+ * 从 filePath 向上查找最近的 tsconfig.json(plan §5.3 + C-5 修复)。
460
+ *
461
+ * 上溯范围:从 path.dirname(filePath) 向上,直到 projectRoot 边界(含 projectRoot 本身)。
462
+ * 越过 projectRoot 则停止,不抛异常。
463
+ *
464
+ * @param filePath - 起始文件的绝对路径
465
+ * @param projectRoot - 不超过此目录,超过则返回 null
466
+ * @returns { configDir: string, rawConfig: Record<string, unknown> } | null
467
+ */
468
+ export function findNearestTsConfig(filePath, projectRoot) {
469
+ let dir = path.dirname(filePath);
470
+ // Codex P0 C-3 修复:边界检查必须先于 fs.existsSync,否则
471
+ // `/proj` vs `/projection` 场景中可能先读取越界路径的 tsconfig.json
472
+ // 算法:每轮先验证 dir 是否仍在 projectRoot 子树内(或恰好等于 projectRoot),
473
+ // 通过后才允许 candidate 文件系统检查
474
+ // eslint-disable-next-line no-constant-condition
475
+ while (true) {
476
+ // 边界检查(先于 fs 操作):dir 必须等于 projectRoot 或在其子树内
477
+ if (dir !== projectRoot && !isInsideProjectRoot(dir, projectRoot)) {
478
+ break;
479
+ }
480
+ const candidate = path.join(dir, 'tsconfig.json');
481
+ if (fs.existsSync(candidate)) {
482
+ // quality-review CRITICAL 修复:JSON.parse 必须包 try/catch
483
+ // 损坏的 tsconfig.json(含注释 / 语法错误)不应抛异常吞掉整个 collect 流程,
484
+ // 应继续上溯查找有效的 tsconfig(与 FR-2.4 "解析失败返回 unresolved 不抛异常" 同精神)
485
+ try {
486
+ const rawConfig = JSON.parse(fs.readFileSync(candidate, 'utf8'));
487
+ return { configDir: dir, rawConfig };
488
+ }
489
+ catch {
490
+ // 损坏的 tsconfig.json — 视为不存在,继续向上查找
491
+ }
492
+ }
493
+ // 若当前 dir 已是 projectRoot,不再继续上溯
494
+ if (dir === projectRoot)
495
+ break;
496
+ const parent = path.dirname(dir);
497
+ // 防止无限循环(到达文件系统根时 dirname 不再变化)
498
+ if (parent === dir)
499
+ break;
500
+ dir = parent;
501
+ }
502
+ return null;
503
+ }
504
+ // ───────────────────────────────────────────────────────────
505
+ // Public API — buildTsConfigContext
506
+ // ───────────────────────────────────────────────────────────
507
+ /**
508
+ * 将 findNearestTsConfig 返回的 rawConfig 转换为 TsConfigResolutionContext。
509
+ *
510
+ * 处理规则(T-021a):
511
+ * 1. 读取 rawConfig.compilerOptions.baseUrl(缺省时为 null)
512
+ * 2. 读取 rawConfig.compilerOptions.paths → Map<string, string[]>(缺省时为空 Map)
513
+ * 3. 写入 configDir(由调用方传入,findNearestTsConfig 提供)
514
+ * 4. 不处理 extends 链(YAGNI,CL-04)
515
+ *
516
+ * @param rawConfig - tsconfig.json 的原始 JSON 对象
517
+ * @param configDir - tsconfig.json 所在目录的绝对路径
518
+ * @returns TsConfigResolutionContext
519
+ */
520
+ export function buildTsConfigContext(rawConfig, configDir) {
521
+ const compilerOptions = typeof rawConfig.compilerOptions === 'object' && rawConfig.compilerOptions !== null
522
+ ? rawConfig.compilerOptions
523
+ : {};
524
+ // baseUrl:字符串或 null
525
+ const baseUrl = typeof compilerOptions.baseUrl === 'string' ? compilerOptions.baseUrl : null;
526
+ // paths:对象转 Map<string, string[]>
527
+ const paths = new Map();
528
+ if (typeof compilerOptions.paths === 'object' && compilerOptions.paths !== null) {
529
+ for (const [key, value] of Object.entries(compilerOptions.paths)) {
530
+ if (Array.isArray(value)) {
531
+ paths.set(key, value);
532
+ }
533
+ }
534
+ }
535
+ return { configDir, baseUrl, paths };
536
+ }
537
+ //# sourceMappingURL=import-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-resolver.js","sourceRoot":"","sources":["../../src/knowledge-graph/import-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AA4C7B,8DAA8D;AAC9D,KAAK;AACL,8DAA8D;AAE9D;;;GAGG;AACH,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IACnD,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,MAAM;IACN,MAAM;IACN,UAAU;IACV,aAAa;IACb,WAAW;IACX,WAAW;IACX,SAAS;IACT,QAAQ;IACR,KAAK;IACL,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,YAAY;IACZ,SAAS;IACT,UAAU;IACV,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,YAAY;IACZ,SAAS;IACT,SAAS;IACT,KA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K,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IAE/E,kCAAkC;IAClC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC1C,IAAI,OAAO,eAAe,CAAC,KAAK,KAAK,QAAQ,IAAI,eAAe,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QAChF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAgC,CAAC,EAAE,CAAC;YAC5F,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAiB,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,110 @@
1
+ import { computeFileHash, type SnapshotWrapper } from './persistence.js';
2
+ import type { UnifiedGraph } from './unified-graph.js';
3
+ export interface GitDiffOptions {
4
+ projectRoot: string;
5
+ /**
6
+ * git diff ref 范围,默认 `HEAD`(取工作区相对 HEAD 的变更)。
7
+ * post-commit hook 场景可传 `ORIG_HEAD HEAD`,对应一次 commit 的真实 diff。
8
+ */
9
+ range?: string;
10
+ /**
11
+ * 显式启用 shallow clone 检测;默认开启。
12
+ * 当 `git rev-parse --is-shallow-repository` 返回 'true' 时,本函数返回 null
13
+ * 让调用方降级为全量 hash stale 检测(EC-10)。
14
+ */
15
+ shallowFallback?: boolean;
16
+ }
17
+ /**
18
+ * 调 `git diff --name-only <range>` 取变更文件绝对路径数组。
19
+ *
20
+ * W3 WARN-2 修订:使用 execFileSync / spawnSync 数组形参传递 ref,
21
+ * 不再用模板字符串拼接 shell 命令;range 通过白名单 parseGitRange 校验。
22
+ *
23
+ * 失败 / shallow clone / 非 git 仓库 / range 格式非法 → 返回 null,由调用方触发 full re-index 降级。
24
+ *
25
+ * @returns 绝对路径数组,或 null(降级信号)
26
+ */
27
+ export declare function gitDiff(opts: GitDiffOptions): Promise<string[] | null>;
28
+ export interface ExpandCallersOptions {
29
+ /** 变更文件绝对路径列表 */
30
+ changedFiles: string[];
31
+ /** 已加载的旧 snapshot */
32
+ snapshot: SnapshotWrapper;
33
+ /** 反向扩展深度,默认 1(FR-7);>1 时执行 BFS */
34
+ depth?: number;
35
+ }
36
+ /**
37
+ * 从 changed files 反向扩展直接(或 N 跳)caller 文件。
38
+ *
39
+ * 算法(plan §2.2 端点 → owning file 映射):
40
+ * 1. 按 node.filePath 字段建 file → node ids 索引
41
+ * 2. 当前 frontier = changed files;每跳:
42
+ * a) 取 frontier 文件的所有 owning node ids
43
+ * b) 找出 edge.target 命中这些 ids 的 edges → 取 edge.source
44
+ * c) 反查 source node 的 owning file,加入下一跳 frontier(去重)
45
+ * 3. 累积所有跳的文件并集(含 changed 自身)
46
+ */
47
+ export declare function expandCallers(opts: ExpandCallersOptions): string[];
48
+ export interface MergeIncrementalOptions {
49
+ oldSnapshot: SnapshotWrapper;
50
+ /** expandCallers 输出 + 自身(绝对路径,含 deleted 文件) */
51
+ changedSet: Set<string>;
52
+ /** 仅 changed files 范围内的局部 graph */
53
+ newPartialGraph: UnifiedGraph;
54
+ /** 当前文件 hash 表(changedSet 内**仍存在**的文件,由 buildIncremental 计算) */
55
+ newFileHashes: Record<string, string>;
56
+ }
57
+ /**
58
+ * 把局部图合并回 oldSnapshot:
59
+ * - 移除 oldSnapshot.graph.nodes 中 filePath ∈ changedSet 的所有节点
60
+ * - 移除以这些节点为 source 或 target 的所有 edges(deletion 不留孤儿,EC-9)
61
+ * - 把 newPartialGraph.nodes / .edges 追加(按 node.id 去重)
62
+ * - fileHashes 三态更新:删除 changedSet 中已不存在的文件 key;写入新 hash
63
+ */
64
+ export declare function mergeIncremental(opts: MergeIncrementalOptions): SnapshotWrapper;
65
+ export type IncrementalFallbackReason = 'no-snapshot' | 'shallow-clone' | 'corruption' | 'no-diff';
66
+ export interface BuildIncrementalOptions {
67
+ projectRoot: string;
68
+ /** caller 反向扩展深度,默认 1(clarify Q3) */
69
+ callerDepth?: number;
70
+ /**
71
+ * 显式提供 changed files(来自 chokidar / 测试);
72
+ * 提供时跳过 gitDiff(EC-2 watch 无 git context)。
73
+ */
74
+ changedFilesOverride?: string[];
75
+ /** 显式禁用 git shallow 检测(测试场景) */
76
+ disableShallowFallback?: boolean;
77
+ /** post-commit hook 场景的 ref range,默认 'HEAD' */
78
+ gitRange?: string;
79
+ }
80
+ export interface BuildIncrementalResult {
81
+ snapshot: SnapshotWrapper;
82
+ /** 实际重索引的文件(含 caller expansion;deleted 文件也计入) */
83
+ changedFiles: string[];
84
+ /**
85
+ * 原始 changed file 数(git diff / changedFilesOverride 输入数,**不含** caller expansion)。
86
+ * W3 WARN-3:CLI 层 emit('caller-expand') 输出 = changedFiles.length - origChangedFilesCount。
87
+ */
88
+ origChangedFilesCount: number;
89
+ /** 是否触发了 full re-index 降级 */
90
+ fallbackToFull: boolean;
91
+ fallbackReason?: IncrementalFallbackReason;
92
+ /** 端到端耗时(ms) */
93
+ durationMs: number;
94
+ }
95
+ /**
96
+ * 增量构建主入口。
97
+ *
98
+ * 决策树:
99
+ * 1. loadSnapshot 失败 / null → fallback to full(reason='no-snapshot')
100
+ * 2. changedFilesOverride 非 undefined → 直接用(EC-2 watch 路径)
101
+ * 3. gitDiff 返回 null → fallback to full(reason='shallow-clone')
102
+ * 4. expandCallers 后跑 partial analyzeFile + buildUnifiedGraph
103
+ * 5. mergeIncremental + saveSnapshot
104
+ *
105
+ * 注意:deletion 不重新跑 analyzeFile(文件已不存在),但仍在 changedSet 中,
106
+ * mergeIncremental 会把对应节点 + 边 + hash 全部清掉。
107
+ */
108
+ export declare function buildIncremental(opts: BuildIncrementalOptions): Promise<BuildIncrementalResult>;
109
+ export { computeFileHash };
110
+ //# sourceMappingURL=incremental.d.ts.map