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.
- package/README.md +1 -1
- package/dist/adapters/go-adapter.d.ts.map +1 -1
- package/dist/adapters/go-adapter.js +2 -0
- package/dist/adapters/go-adapter.js.map +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/java-adapter.d.ts.map +1 -1
- package/dist/adapters/java-adapter.js +2 -0
- package/dist/adapters/java-adapter.js.map +1 -1
- package/dist/adapters/language-adapter.d.ts +47 -9
- package/dist/adapters/language-adapter.d.ts.map +1 -1
- package/dist/adapters/python-adapter.d.ts +34 -6
- package/dist/adapters/python-adapter.d.ts.map +1 -1
- package/dist/adapters/python-adapter.js +157 -59
- package/dist/adapters/python-adapter.js.map +1 -1
- package/dist/adapters/ts-js-adapter.d.ts +13 -5
- package/dist/adapters/ts-js-adapter.d.ts.map +1 -1
- package/dist/adapters/ts-js-adapter.js +55 -14
- package/dist/adapters/ts-js-adapter.js.map +1 -1
- package/dist/batch/batch-orchestrator.d.ts +30 -4
- package/dist/batch/batch-orchestrator.d.ts.map +1 -1
- package/dist/batch/batch-orchestrator.js +284 -7
- package/dist/batch/batch-orchestrator.js.map +1 -1
- package/dist/batch/delta-regenerator.d.ts +2 -2
- package/dist/batch/delta-regenerator.d.ts.map +1 -1
- package/dist/batch/delta-regenerator.js.map +1 -1
- package/dist/batch/module-grouper.d.ts +2 -2
- package/dist/batch/module-grouper.d.ts.map +1 -1
- package/dist/batch/module-grouper.js +1 -1
- package/dist/batch/module-grouper.js.map +1 -1
- package/dist/cli/commands/graph.js +1 -1
- package/dist/cli/commands/graph.js.map +1 -1
- package/dist/cli/commands/index.d.ts +8 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +274 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/query.d.ts.map +1 -1
- package/dist/cli/commands/query.js +3 -1
- package/dist/cli/commands/query.js.map +1 -1
- package/dist/cli/index.js +9 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/utils/parse-args.d.ts +13 -1
- package/dist/cli/utils/parse-args.d.ts.map +1 -1
- package/dist/cli/utils/parse-args.js +79 -2
- package/dist/cli/utils/parse-args.js.map +1 -1
- package/dist/core/ast-analyzer.d.ts.map +1 -1
- package/dist/core/ast-analyzer.js +79 -5
- package/dist/core/ast-analyzer.js.map +1 -1
- package/dist/core/import-resolver.d.ts +90 -0
- package/dist/core/import-resolver.d.ts.map +1 -0
- package/dist/core/import-resolver.js +273 -0
- package/dist/core/import-resolver.js.map +1 -0
- package/dist/core/query-mappers/base-mapper.d.ts +13 -0
- package/dist/core/query-mappers/base-mapper.d.ts.map +1 -1
- package/dist/core/query-mappers/go-mapper.d.ts +68 -0
- package/dist/core/query-mappers/go-mapper.d.ts.map +1 -1
- package/dist/core/query-mappers/go-mapper.js +421 -0
- package/dist/core/query-mappers/go-mapper.js.map +1 -1
- package/dist/core/query-mappers/java-mapper.d.ts +196 -0
- package/dist/core/query-mappers/java-mapper.d.ts.map +1 -1
- package/dist/core/query-mappers/java-mapper.js +600 -0
- package/dist/core/query-mappers/java-mapper.js.map +1 -1
- package/dist/core/query-mappers/python-mapper.d.ts +55 -0
- package/dist/core/query-mappers/python-mapper.d.ts.map +1 -1
- package/dist/core/query-mappers/python-mapper.js +273 -0
- package/dist/core/query-mappers/python-mapper.js.map +1 -1
- package/dist/core/query-mappers/typescript-mapper.d.ts +102 -0
- package/dist/core/query-mappers/typescript-mapper.d.ts.map +1 -1
- package/dist/core/query-mappers/typescript-mapper.js +470 -0
- package/dist/core/query-mappers/typescript-mapper.js.map +1 -1
- package/dist/core/single-spec-orchestrator.d.ts.map +1 -1
- package/dist/core/single-spec-orchestrator.js +146 -9
- package/dist/core/single-spec-orchestrator.js.map +1 -1
- package/dist/core/tree-sitter-analyzer.d.ts +6 -0
- package/dist/core/tree-sitter-analyzer.d.ts.map +1 -1
- package/dist/core/tree-sitter-analyzer.js +33 -1
- package/dist/core/tree-sitter-analyzer.js.map +1 -1
- package/dist/core/tree-sitter-fallback.d.ts +7 -4
- package/dist/core/tree-sitter-fallback.d.ts.map +1 -1
- package/dist/core/tree-sitter-fallback.js +157 -12
- package/dist/core/tree-sitter-fallback.js.map +1 -1
- package/dist/extraction/extraction-types.d.ts +25 -25
- package/dist/generator/index-generator.d.ts +3 -3
- package/dist/generator/index-generator.d.ts.map +1 -1
- package/dist/generator/index-generator.js +1 -1
- package/dist/generator/index-generator.js.map +1 -1
- package/dist/graph/directory-graph.d.ts +14 -4
- package/dist/graph/directory-graph.d.ts.map +1 -1
- package/dist/graph/directory-graph.js +71 -128
- package/dist/graph/directory-graph.js.map +1 -1
- package/dist/graph/mermaid-renderer.d.ts +8 -5
- package/dist/graph/mermaid-renderer.d.ts.map +1 -1
- package/dist/graph/mermaid-renderer.js +3 -3
- package/dist/graph/mermaid-renderer.js.map +1 -1
- package/dist/graph/topological-sort.d.ts +13 -6
- package/dist/graph/topological-sort.d.ts.map +1 -1
- package/dist/graph/topological-sort.js +2 -2
- package/dist/graph/topological-sort.js.map +1 -1
- package/dist/knowledge-graph/call-resolver.d.ts +64 -0
- package/dist/knowledge-graph/call-resolver.d.ts.map +1 -0
- package/dist/knowledge-graph/call-resolver.js +323 -0
- package/dist/knowledge-graph/call-resolver.js.map +1 -0
- package/dist/knowledge-graph/import-resolver.d.ts +114 -0
- package/dist/knowledge-graph/import-resolver.d.ts.map +1 -0
- package/dist/knowledge-graph/import-resolver.js +537 -0
- package/dist/knowledge-graph/import-resolver.js.map +1 -0
- package/dist/knowledge-graph/incremental.d.ts +110 -0
- package/dist/knowledge-graph/incremental.d.ts.map +1 -0
- package/dist/knowledge-graph/incremental.js +410 -0
- package/dist/knowledge-graph/incremental.js.map +1 -0
- package/dist/knowledge-graph/index.d.ts +74 -0
- package/dist/knowledge-graph/index.d.ts.map +1 -0
- package/dist/knowledge-graph/index.js +156 -0
- package/dist/knowledge-graph/index.js.map +1 -0
- package/dist/knowledge-graph/module-derivation.d.ts +238 -0
- package/dist/knowledge-graph/module-derivation.d.ts.map +1 -0
- package/dist/knowledge-graph/module-derivation.js +418 -0
- package/dist/knowledge-graph/module-derivation.js.map +1 -0
- package/dist/knowledge-graph/persistence.d.ts +270 -0
- package/dist/knowledge-graph/persistence.d.ts.map +1 -0
- package/dist/knowledge-graph/persistence.js +226 -0
- package/dist/knowledge-graph/persistence.js.map +1 -0
- package/dist/knowledge-graph/query-helpers.d.ts +164 -0
- package/dist/knowledge-graph/query-helpers.d.ts.map +1 -0
- package/dist/knowledge-graph/query-helpers.js +394 -0
- package/dist/knowledge-graph/query-helpers.js.map +1 -0
- package/dist/knowledge-graph/unified-graph.d.ts +310 -0
- package/dist/knowledge-graph/unified-graph.d.ts.map +1 -0
- package/dist/knowledge-graph/unified-graph.js +182 -0
- package/dist/knowledge-graph/unified-graph.js.map +1 -0
- package/dist/mcp/agent-context-tools.d.ts +104 -0
- package/dist/mcp/agent-context-tools.d.ts.map +1 -0
- package/dist/mcp/agent-context-tools.js +854 -0
- package/dist/mcp/agent-context-tools.js.map +1 -0
- package/dist/mcp/graph-tools.d.ts +20 -0
- package/dist/mcp/graph-tools.d.ts.map +1 -1
- package/dist/mcp/graph-tools.js +71 -11
- package/dist/mcp/graph-tools.js.map +1 -1
- package/dist/mcp/lib/response-helpers.d.ts +67 -0
- package/dist/mcp/lib/response-helpers.d.ts.map +1 -0
- package/dist/mcp/lib/response-helpers.js +103 -0
- package/dist/mcp/lib/response-helpers.js.map +1 -0
- package/dist/mcp/server.d.ts +3 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +9 -10
- package/dist/mcp/server.js.map +1 -1
- package/dist/models/call-site.d.ts +68 -0
- package/dist/models/call-site.d.ts.map +1 -0
- package/dist/models/call-site.js +60 -0
- package/dist/models/call-site.js.map +1 -0
- package/dist/models/code-skeleton.d.ts +78 -6
- package/dist/models/code-skeleton.d.ts.map +1 -1
- package/dist/models/code-skeleton.js +29 -0
- package/dist/models/code-skeleton.js.map +1 -1
- package/dist/models/drift-item.d.ts +4 -4
- package/dist/models/module-spec.d.ts +155 -94
- package/dist/models/module-spec.d.ts.map +1 -1
- package/dist/panoramic/adr-decision-pipeline.d.ts +53 -0
- package/dist/panoramic/adr-decision-pipeline.d.ts.map +1 -0
- package/dist/panoramic/adr-decision-pipeline.js +685 -0
- package/dist/panoramic/adr-decision-pipeline.js.map +1 -0
- package/dist/panoramic/api-surface-generator.d.ts +56 -0
- package/dist/panoramic/api-surface-generator.d.ts.map +1 -0
- package/dist/panoramic/api-surface-generator.js +1671 -0
- package/dist/panoramic/api-surface-generator.js.map +1 -0
- package/dist/panoramic/architecture-ir-builder.d.ts +19 -0
- package/dist/panoramic/architecture-ir-builder.d.ts.map +1 -0
- package/dist/panoramic/architecture-ir-builder.js +561 -0
- package/dist/panoramic/architecture-ir-builder.js.map +1 -0
- package/dist/panoramic/architecture-ir-exporters.d.ts +7 -0
- package/dist/panoramic/architecture-ir-exporters.d.ts.map +1 -0
- package/dist/panoramic/architecture-ir-exporters.js +183 -0
- package/dist/panoramic/architecture-ir-exporters.js.map +1 -0
- package/dist/panoramic/architecture-ir-generator.d.ts +36 -0
- package/dist/panoramic/architecture-ir-generator.d.ts.map +1 -0
- package/dist/panoramic/architecture-ir-generator.js +51 -0
- package/dist/panoramic/architecture-ir-generator.js.map +1 -0
- package/dist/panoramic/architecture-ir-mermaid-adapter.d.ts +6 -0
- package/dist/panoramic/architecture-ir-mermaid-adapter.d.ts.map +1 -0
- package/dist/panoramic/architecture-ir-mermaid-adapter.js +98 -0
- package/dist/panoramic/architecture-ir-mermaid-adapter.js.map +1 -0
- package/dist/panoramic/architecture-ir-model.d.ts +87 -0
- package/dist/panoramic/architecture-ir-model.d.ts.map +1 -0
- package/dist/panoramic/architecture-ir-model.js +20 -0
- package/dist/panoramic/architecture-ir-model.js.map +1 -0
- package/dist/panoramic/architecture-narrative.d.ts +68 -0
- package/dist/panoramic/architecture-narrative.d.ts.map +1 -0
- package/dist/panoramic/architecture-narrative.js +401 -0
- package/dist/panoramic/architecture-narrative.js.map +1 -0
- package/dist/panoramic/architecture-overview-generator.d.ts +31 -0
- package/dist/panoramic/architecture-overview-generator.d.ts.map +1 -0
- package/dist/panoramic/architecture-overview-generator.js +454 -0
- package/dist/panoramic/architecture-overview-generator.js.map +1 -0
- package/dist/panoramic/architecture-overview-model.d.ts +77 -0
- package/dist/panoramic/architecture-overview-model.d.ts.map +1 -0
- package/dist/panoramic/architecture-overview-model.js +31 -0
- package/dist/panoramic/architecture-overview-model.js.map +1 -0
- package/dist/panoramic/batch-project-docs.d.ts.map +1 -1
- package/dist/panoramic/batch-project-docs.js +4 -2
- package/dist/panoramic/batch-project-docs.js.map +1 -1
- package/dist/panoramic/builders/component-view-builder.d.ts +25 -1
- package/dist/panoramic/builders/component-view-builder.d.ts.map +1 -1
- package/dist/panoramic/builders/component-view-builder.js +83 -3
- package/dist/panoramic/builders/component-view-builder.js.map +1 -1
- package/dist/panoramic/builders/doc-graph-builder.d.ts +2 -2
- package/dist/panoramic/builders/doc-graph-builder.d.ts.map +1 -1
- package/dist/panoramic/builders/doc-graph-builder.js.map +1 -1
- package/dist/panoramic/component-view-builder.d.ts +17 -0
- package/dist/panoramic/component-view-builder.d.ts.map +1 -0
- package/dist/panoramic/component-view-builder.js +652 -0
- package/dist/panoramic/component-view-builder.js.map +1 -0
- package/dist/panoramic/component-view-model.d.ts +127 -0
- package/dist/panoramic/component-view-model.d.ts.map +1 -0
- package/dist/panoramic/component-view-model.js +65 -0
- package/dist/panoramic/component-view-model.js.map +1 -0
- package/dist/panoramic/config-reference-generator.d.ts +78 -0
- package/dist/panoramic/config-reference-generator.d.ts.map +1 -0
- package/dist/panoramic/config-reference-generator.js +199 -0
- package/dist/panoramic/config-reference-generator.js.map +1 -0
- package/dist/panoramic/coverage-auditor.d.ts +95 -0
- package/dist/panoramic/coverage-auditor.d.ts.map +1 -0
- package/dist/panoramic/coverage-auditor.js +290 -0
- package/dist/panoramic/coverage-auditor.js.map +1 -0
- package/dist/panoramic/cross-package-analyzer.d.ts +112 -0
- package/dist/panoramic/cross-package-analyzer.d.ts.map +1 -0
- package/dist/panoramic/cross-package-analyzer.js +258 -0
- package/dist/panoramic/cross-package-analyzer.js.map +1 -0
- package/dist/panoramic/data-model-generator.d.ts +528 -0
- package/dist/panoramic/data-model-generator.d.ts.map +1 -0
- package/dist/panoramic/data-model-generator.js +647 -0
- package/dist/panoramic/data-model-generator.js.map +1 -0
- package/dist/panoramic/doc-graph-builder.d.ts +80 -0
- package/dist/panoramic/doc-graph-builder.d.ts.map +1 -0
- package/dist/panoramic/doc-graph-builder.js +352 -0
- package/dist/panoramic/doc-graph-builder.js.map +1 -0
- package/dist/panoramic/docs-bundle-manifest-reader.d.ts +26 -0
- package/dist/panoramic/docs-bundle-manifest-reader.d.ts.map +1 -0
- package/dist/panoramic/docs-bundle-manifest-reader.js +106 -0
- package/dist/panoramic/docs-bundle-manifest-reader.js.map +1 -0
- package/dist/panoramic/docs-bundle-orchestrator.d.ts +14 -0
- package/dist/panoramic/docs-bundle-orchestrator.d.ts.map +1 -0
- package/dist/panoramic/docs-bundle-orchestrator.js +538 -0
- package/dist/panoramic/docs-bundle-orchestrator.js.map +1 -0
- package/dist/panoramic/docs-bundle-profiles.d.ts +4 -0
- package/dist/panoramic/docs-bundle-profiles.d.ts.map +1 -0
- package/dist/panoramic/docs-bundle-profiles.js +82 -0
- package/dist/panoramic/docs-bundle-profiles.js.map +1 -0
- package/dist/panoramic/docs-bundle-types.d.ts +94 -0
- package/dist/panoramic/docs-bundle-types.d.ts.map +1 -0
- package/dist/panoramic/docs-bundle-types.js +10 -0
- package/dist/panoramic/docs-bundle-types.js.map +1 -0
- package/dist/panoramic/docs-quality-evaluator.d.ts +31 -0
- package/dist/panoramic/docs-quality-evaluator.d.ts.map +1 -0
- package/dist/panoramic/docs-quality-evaluator.js +941 -0
- package/dist/panoramic/docs-quality-evaluator.js.map +1 -0
- package/dist/panoramic/docs-quality-model.d.ts +125 -0
- package/dist/panoramic/docs-quality-model.d.ts.map +1 -0
- package/dist/panoramic/docs-quality-model.js +166 -0
- package/dist/panoramic/docs-quality-model.js.map +1 -0
- package/dist/panoramic/dynamic-scenarios-builder.d.ts +18 -0
- package/dist/panoramic/dynamic-scenarios-builder.d.ts.map +1 -0
- package/dist/panoramic/dynamic-scenarios-builder.js +316 -0
- package/dist/panoramic/dynamic-scenarios-builder.js.map +1 -0
- package/dist/panoramic/event-surface-generator.d.ts +52 -0
- package/dist/panoramic/event-surface-generator.d.ts.map +1 -0
- package/dist/panoramic/event-surface-generator.js +507 -0
- package/dist/panoramic/event-surface-generator.js.map +1 -0
- package/dist/panoramic/generator-registry.d.ts +1 -1
- package/dist/panoramic/generator-registry.d.ts.map +1 -1
- package/dist/panoramic/generator-registry.js +5 -2
- package/dist/panoramic/generator-registry.js.map +1 -1
- package/dist/panoramic/generators/cross-package-analyzer.d.ts +5 -5
- package/dist/panoramic/generators/cross-package-analyzer.d.ts.map +1 -1
- package/dist/panoramic/generators/cross-package-analyzer.js +1 -1
- package/dist/panoramic/generators/cross-package-analyzer.js.map +1 -1
- package/dist/panoramic/generators/data-model-generator.d.ts +27 -27
- package/dist/panoramic/graph/confidence-mapper.d.ts +18 -0
- package/dist/panoramic/graph/confidence-mapper.d.ts.map +1 -1
- package/dist/panoramic/graph/confidence-mapper.js +26 -0
- package/dist/panoramic/graph/confidence-mapper.js.map +1 -1
- package/dist/panoramic/graph/graph-builder.d.ts.map +1 -1
- package/dist/panoramic/graph/graph-builder.js +78 -0
- package/dist/panoramic/graph/graph-builder.js.map +1 -1
- package/dist/panoramic/graph/graph-paths.d.ts +8 -0
- package/dist/panoramic/graph/graph-paths.d.ts.map +1 -1
- package/dist/panoramic/graph/graph-paths.js +10 -0
- package/dist/panoramic/graph/graph-paths.js.map +1 -1
- package/dist/panoramic/graph/graph-query.d.ts +33 -2
- package/dist/panoramic/graph/graph-query.d.ts.map +1 -1
- package/dist/panoramic/graph/graph-query.js +69 -19
- package/dist/panoramic/graph/graph-query.js.map +1 -1
- package/dist/panoramic/graph/graph-types.d.ts +32 -3
- package/dist/panoramic/graph/graph-types.d.ts.map +1 -1
- package/dist/panoramic/hyperedges/schema.d.ts +6 -6
- package/dist/panoramic/interface-surface-generator.d.ts +50 -0
- package/dist/panoramic/interface-surface-generator.d.ts.map +1 -0
- package/dist/panoramic/interface-surface-generator.js +388 -0
- package/dist/panoramic/interface-surface-generator.js.map +1 -0
- package/dist/panoramic/interfaces.d.ts +2 -2
- package/dist/panoramic/mock-readme-generator.d.ts +90 -0
- package/dist/panoramic/mock-readme-generator.d.ts.map +1 -0
- package/dist/panoramic/mock-readme-generator.js +111 -0
- package/dist/panoramic/mock-readme-generator.js.map +1 -0
- package/dist/panoramic/models/component-view-model.d.ts +1 -1
- package/dist/panoramic/models/component-view-model.d.ts.map +1 -1
- package/dist/panoramic/models/component-view-model.js.map +1 -1
- package/dist/panoramic/narrative-provenance-adapter.d.ts +8 -0
- package/dist/panoramic/narrative-provenance-adapter.d.ts.map +1 -0
- package/dist/panoramic/narrative-provenance-adapter.js +99 -0
- package/dist/panoramic/narrative-provenance-adapter.js.map +1 -0
- package/dist/panoramic/parser-registry.d.ts +1 -1
- package/dist/panoramic/parser-registry.js +1 -1
- package/dist/panoramic/parsers/types.d.ts +6 -6
- package/dist/panoramic/pattern-hints-generator.d.ts +28 -0
- package/dist/panoramic/pattern-hints-generator.d.ts.map +1 -0
- package/dist/panoramic/pattern-hints-generator.js +218 -0
- package/dist/panoramic/pattern-hints-generator.js.map +1 -0
- package/dist/panoramic/pattern-hints-model.d.ts +89 -0
- package/dist/panoramic/pattern-hints-model.d.ts.map +1 -0
- package/dist/panoramic/pattern-hints-model.js +61 -0
- package/dist/panoramic/pattern-hints-model.js.map +1 -0
- package/dist/panoramic/pattern-knowledge-base.d.ts +31 -0
- package/dist/panoramic/pattern-knowledge-base.d.ts.map +1 -0
- package/dist/panoramic/pattern-knowledge-base.js +407 -0
- package/dist/panoramic/pattern-knowledge-base.js.map +1 -0
- package/dist/panoramic/pipelines/coverage-auditor.d.ts.map +1 -1
- package/dist/panoramic/pipelines/coverage-auditor.js +4 -2
- package/dist/panoramic/pipelines/coverage-auditor.js.map +1 -1
- package/dist/panoramic/pipelines/docs-bundle-orchestrator.js +13 -6
- package/dist/panoramic/pipelines/docs-bundle-orchestrator.js.map +1 -1
- package/dist/panoramic/pipelines/product-ux-docs.d.ts +5 -0
- package/dist/panoramic/pipelines/product-ux-docs.d.ts.map +1 -1
- package/dist/panoramic/pipelines/product-ux-docs.js +34 -6
- package/dist/panoramic/pipelines/product-ux-docs.js.map +1 -1
- package/dist/panoramic/product-ux-docs.d.ts +104 -0
- package/dist/panoramic/product-ux-docs.d.ts.map +1 -0
- package/dist/panoramic/product-ux-docs.js +817 -0
- package/dist/panoramic/product-ux-docs.js.map +1 -0
- package/dist/panoramic/qa/__tests__/citation.test.d.ts +2 -0
- package/dist/panoramic/qa/__tests__/citation.test.d.ts.map +1 -0
- package/dist/panoramic/qa/__tests__/citation.test.js +193 -0
- package/dist/panoramic/qa/__tests__/citation.test.js.map +1 -0
- package/dist/panoramic/qa/__tests__/debt-context.test.d.ts +2 -0
- package/dist/panoramic/qa/__tests__/debt-context.test.d.ts.map +1 -0
- package/dist/panoramic/qa/__tests__/debt-context.test.js +154 -0
- package/dist/panoramic/qa/__tests__/debt-context.test.js.map +1 -0
- package/dist/panoramic/qa/__tests__/graph-retriever.test.d.ts +2 -0
- package/dist/panoramic/qa/__tests__/graph-retriever.test.d.ts.map +1 -0
- package/dist/panoramic/qa/__tests__/graph-retriever.test.js +148 -0
- package/dist/panoramic/qa/__tests__/graph-retriever.test.js.map +1 -0
- package/dist/panoramic/qa/__tests__/index.test.d.ts +2 -0
- package/dist/panoramic/qa/__tests__/index.test.d.ts.map +1 -0
- package/dist/panoramic/qa/__tests__/index.test.js +246 -0
- package/dist/panoramic/qa/__tests__/index.test.js.map +1 -0
- package/dist/panoramic/qa/__tests__/llm-caller.test.d.ts +2 -0
- package/dist/panoramic/qa/__tests__/llm-caller.test.d.ts.map +1 -0
- package/dist/panoramic/qa/__tests__/llm-caller.test.js +168 -0
- package/dist/panoramic/qa/__tests__/llm-caller.test.js.map +1 -0
- package/dist/panoramic/qa/__tests__/prompt-builder.test.d.ts +2 -0
- package/dist/panoramic/qa/__tests__/prompt-builder.test.d.ts.map +1 -0
- package/dist/panoramic/qa/__tests__/prompt-builder.test.js +150 -0
- package/dist/panoramic/qa/__tests__/prompt-builder.test.js.map +1 -0
- package/dist/panoramic/qa/__tests__/qa-integration.test.d.ts +2 -0
- package/dist/panoramic/qa/__tests__/qa-integration.test.d.ts.map +1 -0
- package/dist/panoramic/qa/__tests__/qa-integration.test.js +296 -0
- package/dist/panoramic/qa/__tests__/qa-integration.test.js.map +1 -0
- package/dist/panoramic/qa/__tests__/rag-reranker.test.d.ts +2 -0
- package/dist/panoramic/qa/__tests__/rag-reranker.test.d.ts.map +1 -0
- package/dist/panoramic/qa/__tests__/rag-reranker.test.js +136 -0
- package/dist/panoramic/qa/__tests__/rag-reranker.test.js.map +1 -0
- package/dist/panoramic/qa/index.d.ts.map +1 -1
- package/dist/panoramic/qa/index.js +10 -3
- package/dist/panoramic/qa/index.js.map +1 -1
- package/dist/panoramic/runtime-topology-generator.d.ts +77 -0
- package/dist/panoramic/runtime-topology-generator.d.ts.map +1 -0
- package/dist/panoramic/runtime-topology-generator.js +676 -0
- package/dist/panoramic/runtime-topology-generator.js.map +1 -0
- package/dist/panoramic/runtime-topology-model.d.ts +145 -0
- package/dist/panoramic/runtime-topology-model.d.ts.map +1 -0
- package/dist/panoramic/runtime-topology-model.js +300 -0
- package/dist/panoramic/runtime-topology-model.js.map +1 -0
- package/dist/panoramic/troubleshooting-generator.d.ts +51 -0
- package/dist/panoramic/troubleshooting-generator.d.ts.map +1 -0
- package/dist/panoramic/troubleshooting-generator.js +451 -0
- package/dist/panoramic/troubleshooting-generator.js.map +1 -0
- package/dist/panoramic/utils/text-segmenter.d.ts +15 -0
- package/dist/panoramic/utils/text-segmenter.d.ts.map +1 -1
- package/dist/panoramic/utils/text-segmenter.js +38 -0
- package/dist/panoramic/utils/text-segmenter.js.map +1 -1
- package/dist/panoramic/workspace-index-generator.d.ts +148 -0
- package/dist/panoramic/workspace-index-generator.d.ts.map +1 -0
- package/dist/panoramic/workspace-index-generator.js +497 -0
- package/dist/panoramic/workspace-index-generator.js.map +1 -0
- package/dist/runtime-bootstrap.d.ts +9 -0
- package/dist/runtime-bootstrap.d.ts.map +1 -0
- package/dist/runtime-bootstrap.js +33 -0
- package/dist/runtime-bootstrap.js.map +1 -0
- package/dist/utils/file-scanner.js +1 -1
- package/dist/utils/file-scanner.js.map +1 -1
- package/package.json +12 -2
- package/plugins/spec-driver/.claude-plugin/plugin.json +1 -1
- package/plugins/spec-driver/README.md +18 -1
- package/plugins/spec-driver/agents/implement.md +20 -1
- package/plugins/spec-driver/agents/plan.md +20 -1
- package/plugins/spec-driver/agents/quality-review.md +20 -1
- package/plugins/spec-driver/agents/spec-review.md +20 -1
- package/plugins/spec-driver/agents/verify.md +20 -1
- package/plugins/spec-driver/docs/customization.md +134 -0
- package/plugins/spec-driver/docs/spectra-mcp-integration.md +165 -0
- package/plugins/spec-driver/lib/preference-rules.mjs +96 -0
- package/plugins/spec-driver/scripts/postinstall.sh +1 -1
- package/plugins/spec-driver/scripts/sync-preference-rules.mjs +148 -0
- package/plugins/spec-driver/skills/spec-driver-feature/SKILL.md +10 -0
- package/plugins/spec-driver/skills/spec-driver-fix/SKILL.md +10 -0
- package/plugins/spec-driver/skills/spec-driver-implement/SKILL.md +10 -0
- package/plugins/spec-driver/skills/spec-driver-refactor/SKILL.md +10 -0
- package/plugins/spec-driver/skills/spec-driver-story/SKILL.md +10 -0
- package/plugins/spec-driver/templates/preference-rules.md +39 -0
- package/plugins/spectra/.claude-plugin/plugin.json +1 -1
- package/plugins/spectra/README.md +48 -1
- package/plugins/spectra/hooks/post-commit.sh +40 -0
- package/templates/product-overview.hbs +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental.d.ts","sourceRoot":"","sources":["../../src/knowledge-graph/incremental.ts"],"names":[],"mappings":"AA0BA,OAAO,EAGL,eAAe,EAKf,KAAK,eAAe,EACrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,oBAAoB,CAAC;AAMpE,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAuBD;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CA8C5E;AAMD,MAAM,WAAW,oBAAoB;IACnC,iBAAiB;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,qBAAqB;IACrB,QAAQ,EAAE,eAAe,CAAC;IAC1B,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,EAAE,CA+ClE;AAMD,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,eAAe,CAAC;IAC7B,+CAA+C;IAC/C,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,mCAAmC;IACnC,eAAe,EAAE,YAAY,CAAC;IAC9B,gEAAgE;IAChE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,uBAAuB,GAAG,eAAe,CAiD/E;AAMD,MAAM,MAAM,yBAAyB,GACjC,aAAa,GACb,eAAe,GACf,YAAY,GACZ,SAAS,CAAC;AAEd,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,gCAAgC;IAChC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,eAAe,CAAC;IAC1B,iDAAiD;IACjD,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB;;;OAGG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAC9B,6BAA6B;IAC7B,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,yBAAyB,CAAC;IAC3C,gBAAgB;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,sBAAsB,CAAC,CAsKjC;AA2CD,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature 156 W3 — 增量索引核心模块。
|
|
3
|
+
*
|
|
4
|
+
* 提供以下能力:
|
|
5
|
+
* - gitDiff:从 git diff 取变更文件清单(支持 post-commit / 工作区两种 ref 范围)
|
|
6
|
+
* - expandCallers:从 changed files 反向扩展直接 caller(基于 endpoint → owning file 映射)
|
|
7
|
+
* - mergeIncremental:把 partial graph 合并回 oldSnapshot,保持其他文件节点 / 边不变
|
|
8
|
+
* - buildIncremental:高层入口,协调 load → diff → expand → partial build → merge → save
|
|
9
|
+
*
|
|
10
|
+
* 关键设计决策(plan §2.2 + clarify Q3):
|
|
11
|
+
* - UnifiedGraph 节点 id 形如 `<filePath>::<symbol>` / `<filePath>`,**不能**直接用文件路径匹配边
|
|
12
|
+
* 必须先按 node.filePath 反查 owning nodes,再用 node.id 反查 edges
|
|
13
|
+
* - caller depth 默认 1(spec FR-7 / clarify Q3 决议);接口预留 N,BFS 多跳
|
|
14
|
+
* - shallow clone 降级(EC-10):gitDiff 失败时返回 null,调用方触发 full re-index
|
|
15
|
+
* - rename / delete(EC-9):deletion 不留孤儿——移除该文件所有 nodes + 所有 endpoint 在该文件的 edges
|
|
16
|
+
*
|
|
17
|
+
* **FR-31 守约**:本模块禁止读取 getCurrentUnifiedGraph() 全局 cache;所有数据必须从参数 / snapshot 文件读入。
|
|
18
|
+
*/
|
|
19
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
20
|
+
import * as fsp from 'node:fs/promises';
|
|
21
|
+
import * as path from 'node:path';
|
|
22
|
+
import { analyzeFile } from '../core/ast-analyzer.js';
|
|
23
|
+
import { LanguageAdapterRegistry } from '../adapters/language-adapter-registry.js';
|
|
24
|
+
import { scanFiles } from '../utils/file-scanner.js';
|
|
25
|
+
import { buildSnapshotWrapper, computeAllFileHashes, computeFileHash, detectStaleFiles, loadSnapshot, saveSnapshot, SnapshotWrapperSchema, } from './persistence.js';
|
|
26
|
+
import { buildUnifiedGraph } from './index.js';
|
|
27
|
+
/**
|
|
28
|
+
* 校验 git ref range 是否符合白名单格式(W3 WARN-2 命令注入加固)。
|
|
29
|
+
*
|
|
30
|
+
* 仅允许:
|
|
31
|
+
* - 1~2 个 ref(空格分隔),如 'HEAD' / 'ORIG_HEAD HEAD' / 'HEAD~1 HEAD' / 'abc1234 def5678'
|
|
32
|
+
* - 每个 ref 仅含 [A-Za-z0-9_~^@/.-],长度 ≤ 100
|
|
33
|
+
* - 拒绝任何 shell 元字符(;、&、|、`、$、空格 × 多 / 引号等)
|
|
34
|
+
*
|
|
35
|
+
* 不合法返回 null(gitDiff 调用方会触发 full re-index 降级)。
|
|
36
|
+
*/
|
|
37
|
+
function parseGitRange(raw) {
|
|
38
|
+
const REF_PATTERN = /^[A-Za-z0-9_~^@/.-]+$/;
|
|
39
|
+
const parts = raw.trim().split(/\s+/);
|
|
40
|
+
if (parts.length < 1 || parts.length > 2)
|
|
41
|
+
return null;
|
|
42
|
+
for (const p of parts) {
|
|
43
|
+
if (p.length === 0 || p.length > 100)
|
|
44
|
+
return null;
|
|
45
|
+
if (!REF_PATTERN.test(p))
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return parts;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 调 `git diff --name-only <range>` 取变更文件绝对路径数组。
|
|
52
|
+
*
|
|
53
|
+
* W3 WARN-2 修订:使用 execFileSync / spawnSync 数组形参传递 ref,
|
|
54
|
+
* 不再用模板字符串拼接 shell 命令;range 通过白名单 parseGitRange 校验。
|
|
55
|
+
*
|
|
56
|
+
* 失败 / shallow clone / 非 git 仓库 / range 格式非法 → 返回 null,由调用方触发 full re-index 降级。
|
|
57
|
+
*
|
|
58
|
+
* @returns 绝对路径数组,或 null(降级信号)
|
|
59
|
+
*/
|
|
60
|
+
export async function gitDiff(opts) {
|
|
61
|
+
const projectRoot = path.resolve(opts.projectRoot);
|
|
62
|
+
const range = opts.range ?? 'HEAD';
|
|
63
|
+
const shallowFallback = opts.shallowFallback ?? true;
|
|
64
|
+
// 0. range 白名单校验(W3 WARN-2 命令注入加固)
|
|
65
|
+
const refs = parseGitRange(range);
|
|
66
|
+
if (refs === null) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
// 1. shallow clone 检测:shallow 仓库的 ORIG_HEAD / 历史可能不可用
|
|
70
|
+
if (shallowFallback) {
|
|
71
|
+
try {
|
|
72
|
+
const isShallow = execFileSync('git', ['rev-parse', '--is-shallow-repository'], {
|
|
73
|
+
cwd: projectRoot,
|
|
74
|
+
encoding: 'utf-8',
|
|
75
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
76
|
+
}).trim();
|
|
77
|
+
if (isShallow === 'true') {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// 非 git 仓库或 git 不可用 → 降级
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// 2. 取 diff(spawnSync 数组形参,无 shell 解释;refs 已校验)
|
|
87
|
+
const result = spawnSync('git', ['diff', '--name-only', ...refs], {
|
|
88
|
+
cwd: projectRoot,
|
|
89
|
+
encoding: 'utf-8',
|
|
90
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
91
|
+
shell: false,
|
|
92
|
+
});
|
|
93
|
+
if (result.error || result.status !== 0) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const raw = result.stdout ?? '';
|
|
97
|
+
// 3. 解析为绝对路径
|
|
98
|
+
const lines = raw
|
|
99
|
+
.split('\n')
|
|
100
|
+
.map((l) => l.trim())
|
|
101
|
+
.filter((l) => l.length > 0);
|
|
102
|
+
return lines.map((rel) => (path.isAbsolute(rel) ? rel : path.join(projectRoot, rel)));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 从 changed files 反向扩展直接(或 N 跳)caller 文件。
|
|
106
|
+
*
|
|
107
|
+
* 算法(plan §2.2 端点 → owning file 映射):
|
|
108
|
+
* 1. 按 node.filePath 字段建 file → node ids 索引
|
|
109
|
+
* 2. 当前 frontier = changed files;每跳:
|
|
110
|
+
* a) 取 frontier 文件的所有 owning node ids
|
|
111
|
+
* b) 找出 edge.target 命中这些 ids 的 edges → 取 edge.source
|
|
112
|
+
* c) 反查 source node 的 owning file,加入下一跳 frontier(去重)
|
|
113
|
+
* 3. 累积所有跳的文件并集(含 changed 自身)
|
|
114
|
+
*/
|
|
115
|
+
export function expandCallers(opts) {
|
|
116
|
+
const depth = opts.depth ?? 1;
|
|
117
|
+
const { snapshot } = opts;
|
|
118
|
+
// 索引:file → node ids
|
|
119
|
+
const fileToNodeIds = new Map();
|
|
120
|
+
// 索引:node id → owning file
|
|
121
|
+
const nodeIdToFile = new Map();
|
|
122
|
+
for (const n of snapshot.graph.nodes) {
|
|
123
|
+
if (!n.filePath)
|
|
124
|
+
continue;
|
|
125
|
+
nodeIdToFile.set(n.id, n.filePath);
|
|
126
|
+
let s = fileToNodeIds.get(n.filePath);
|
|
127
|
+
if (!s) {
|
|
128
|
+
s = new Set();
|
|
129
|
+
fileToNodeIds.set(n.filePath, s);
|
|
130
|
+
}
|
|
131
|
+
s.add(n.id);
|
|
132
|
+
}
|
|
133
|
+
const result = new Set(opts.changedFiles);
|
|
134
|
+
let frontier = new Set(opts.changedFiles);
|
|
135
|
+
for (let hop = 0; hop < depth; hop += 1) {
|
|
136
|
+
// 当前跳的所有 owning node ids
|
|
137
|
+
const frontierIds = new Set();
|
|
138
|
+
for (const f of frontier) {
|
|
139
|
+
const ids = fileToNodeIds.get(f);
|
|
140
|
+
if (ids)
|
|
141
|
+
for (const id of ids)
|
|
142
|
+
frontierIds.add(id);
|
|
143
|
+
}
|
|
144
|
+
// 遍历 edges:target 命中 frontierIds → 取 source 所在 file
|
|
145
|
+
const nextFrontier = new Set();
|
|
146
|
+
for (const e of snapshot.graph.edges) {
|
|
147
|
+
if (frontierIds.has(e.target)) {
|
|
148
|
+
const ownerFile = nodeIdToFile.get(e.source);
|
|
149
|
+
if (ownerFile && !result.has(ownerFile)) {
|
|
150
|
+
nextFrontier.add(ownerFile);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (nextFrontier.size === 0)
|
|
155
|
+
break; // 收敛
|
|
156
|
+
for (const f of nextFrontier)
|
|
157
|
+
result.add(f);
|
|
158
|
+
frontier = nextFrontier;
|
|
159
|
+
}
|
|
160
|
+
return Array.from(result);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 把局部图合并回 oldSnapshot:
|
|
164
|
+
* - 移除 oldSnapshot.graph.nodes 中 filePath ∈ changedSet 的所有节点
|
|
165
|
+
* - 移除以这些节点为 source 或 target 的所有 edges(deletion 不留孤儿,EC-9)
|
|
166
|
+
* - 把 newPartialGraph.nodes / .edges 追加(按 node.id 去重)
|
|
167
|
+
* - fileHashes 三态更新:删除 changedSet 中已不存在的文件 key;写入新 hash
|
|
168
|
+
*/
|
|
169
|
+
export function mergeIncremental(opts) {
|
|
170
|
+
const { oldSnapshot, changedSet, newPartialGraph, newFileHashes } = opts;
|
|
171
|
+
// 1. 找出旧图中需要被替换的 owning node id 集合
|
|
172
|
+
const owningIds = new Set();
|
|
173
|
+
for (const n of oldSnapshot.graph.nodes) {
|
|
174
|
+
if (n.filePath && changedSet.has(n.filePath)) {
|
|
175
|
+
owningIds.add(n.id);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// 2. 保留:filePath 不在 changedSet 的旧节点
|
|
179
|
+
const retainedNodes = oldSnapshot.graph.nodes.filter((n) => !(n.filePath && changedSet.has(n.filePath)));
|
|
180
|
+
// 3. 保留:source / target 都不命中 owningIds 的旧边
|
|
181
|
+
const retainedEdges = oldSnapshot.graph.edges.filter((e) => !owningIds.has(e.source) && !owningIds.has(e.target));
|
|
182
|
+
// 4. 合并新局部图节点(按 id 去重,新覆盖旧)
|
|
183
|
+
const nodeMap = new Map();
|
|
184
|
+
for (const n of retainedNodes)
|
|
185
|
+
nodeMap.set(n.id, n);
|
|
186
|
+
for (const n of newPartialGraph.nodes)
|
|
187
|
+
nodeMap.set(n.id, n);
|
|
188
|
+
// 5. 合并 fileHashes:删除 changedSet 中不在 newFileHashes 的(= deleted);新增 / 更新存在的
|
|
189
|
+
const mergedHashes = { ...oldSnapshot.fileHashes };
|
|
190
|
+
for (const f of changedSet) {
|
|
191
|
+
delete mergedHashes[f];
|
|
192
|
+
}
|
|
193
|
+
for (const [f, h] of Object.entries(newFileHashes)) {
|
|
194
|
+
mergedHashes[f] = h;
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
schemaVersion: oldSnapshot.schemaVersion,
|
|
198
|
+
generatedAt: new Date().toISOString(),
|
|
199
|
+
graph: {
|
|
200
|
+
nodes: Array.from(nodeMap.values()),
|
|
201
|
+
edges: [...retainedEdges, ...newPartialGraph.edges],
|
|
202
|
+
metadata: {
|
|
203
|
+
// 保留 oldSnapshot 的 projectRoot / schemaVersion,更新 generatedAt
|
|
204
|
+
...oldSnapshot.graph.metadata,
|
|
205
|
+
generatedAt: new Date().toISOString(),
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
fileHashes: mergedHashes,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* 增量构建主入口。
|
|
213
|
+
*
|
|
214
|
+
* 决策树:
|
|
215
|
+
* 1. loadSnapshot 失败 / null → fallback to full(reason='no-snapshot')
|
|
216
|
+
* 2. changedFilesOverride 非 undefined → 直接用(EC-2 watch 路径)
|
|
217
|
+
* 3. gitDiff 返回 null → fallback to full(reason='shallow-clone')
|
|
218
|
+
* 4. expandCallers 后跑 partial analyzeFile + buildUnifiedGraph
|
|
219
|
+
* 5. mergeIncremental + saveSnapshot
|
|
220
|
+
*
|
|
221
|
+
* 注意:deletion 不重新跑 analyzeFile(文件已不存在),但仍在 changedSet 中,
|
|
222
|
+
* mergeIncremental 会把对应节点 + 边 + hash 全部清掉。
|
|
223
|
+
*/
|
|
224
|
+
export async function buildIncremental(opts) {
|
|
225
|
+
const t0 = Date.now();
|
|
226
|
+
const projectRoot = path.resolve(opts.projectRoot);
|
|
227
|
+
const callerDepth = opts.callerDepth ?? 1;
|
|
228
|
+
// ── 1. load snapshot ──
|
|
229
|
+
const oldSnapshot = await loadSnapshot(projectRoot);
|
|
230
|
+
if (!oldSnapshot) {
|
|
231
|
+
const snapshot = await runFullReindex(projectRoot);
|
|
232
|
+
return {
|
|
233
|
+
snapshot,
|
|
234
|
+
changedFiles: [],
|
|
235
|
+
origChangedFilesCount: 0,
|
|
236
|
+
fallbackToFull: true,
|
|
237
|
+
fallbackReason: 'no-snapshot',
|
|
238
|
+
durationMs: Date.now() - t0,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
// ── 2. 取 changed files ──
|
|
242
|
+
let changedFiles;
|
|
243
|
+
if (opts.changedFilesOverride !== undefined) {
|
|
244
|
+
// 规范化为绝对路径
|
|
245
|
+
const normalized = opts.changedFilesOverride.map((p) => path.isAbsolute(p) ? p : path.join(projectRoot, p));
|
|
246
|
+
// chokidar / watch 路径用 detectStaleFiles 二次确认 hash 真变了,避免编辑器
|
|
247
|
+
// 触摸文件(mtime 变但内容未变)触发不必要的重索引
|
|
248
|
+
const stale = await detectStaleFiles(oldSnapshot, normalized);
|
|
249
|
+
const staleSet = new Set(stale);
|
|
250
|
+
// 保留原 override 中真正 stale 的,加上 detectStaleFiles 发现的 deleted 旧路径
|
|
251
|
+
changedFiles = Array.from(new Set([...normalized.filter((f) => staleSet.has(f)), ...stale]));
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
changedFiles = await gitDiff({
|
|
255
|
+
projectRoot,
|
|
256
|
+
range: opts.gitRange,
|
|
257
|
+
shallowFallback: !opts.disableShallowFallback,
|
|
258
|
+
});
|
|
259
|
+
if (changedFiles === null) {
|
|
260
|
+
const snapshot = await runFullReindex(projectRoot);
|
|
261
|
+
return {
|
|
262
|
+
snapshot,
|
|
263
|
+
changedFiles: [],
|
|
264
|
+
origChangedFilesCount: 0,
|
|
265
|
+
fallbackToFull: true,
|
|
266
|
+
fallbackReason: 'shallow-clone',
|
|
267
|
+
durationMs: Date.now() - t0,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// 仅保留可索引扩展名(避免 README.md 等触发增量)
|
|
272
|
+
const supportedExts = LanguageAdapterRegistry.getInstance().getSupportedExtensions();
|
|
273
|
+
changedFiles = changedFiles.filter((f) => {
|
|
274
|
+
for (const ext of supportedExts) {
|
|
275
|
+
if (f.endsWith(ext))
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
});
|
|
280
|
+
// 记录原始 changed file 数(W3 WARN-3:caller-expand emit 用作减数)
|
|
281
|
+
const origChangedFilesCount = changedFiles.length;
|
|
282
|
+
// ── 3. 空 diff 短路:写回 snapshot 仅刷新 generatedAt ──
|
|
283
|
+
if (changedFiles.length === 0) {
|
|
284
|
+
return {
|
|
285
|
+
snapshot: oldSnapshot,
|
|
286
|
+
changedFiles: [],
|
|
287
|
+
origChangedFilesCount: 0,
|
|
288
|
+
fallbackToFull: false,
|
|
289
|
+
durationMs: Date.now() - t0,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
// ── 4. expandCallers ──
|
|
293
|
+
const expanded = expandCallers({
|
|
294
|
+
changedFiles,
|
|
295
|
+
snapshot: oldSnapshot,
|
|
296
|
+
depth: callerDepth,
|
|
297
|
+
});
|
|
298
|
+
const changedSet = new Set(expanded);
|
|
299
|
+
// ── 5. 对 changedSet 中**仍存在**的文件跑 partial buildUnifiedGraph ──
|
|
300
|
+
const codeSkeletons = new Map();
|
|
301
|
+
for (const f of changedSet) {
|
|
302
|
+
try {
|
|
303
|
+
// fs.access 更轻;analyzeFile 自带 FileNotFoundError 但用 access 提前过滤
|
|
304
|
+
await fsp.access(f);
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
continue; // deleted 文件不参与 partial build
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
const sk = await analyzeFile(f, { projectRoot });
|
|
311
|
+
if (sk)
|
|
312
|
+
codeSkeletons.set(f, sk);
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
// 单文件失败不阻断(与 batch-orchestrator 一致策略)
|
|
316
|
+
process.stderr.write(`[incremental] analyzeFile 失败 (${f}): ${err instanceof Error ? err.message : String(err)}\n`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const newPartialGraph = buildUnifiedGraph({
|
|
320
|
+
projectRoot,
|
|
321
|
+
codeSkeletons,
|
|
322
|
+
});
|
|
323
|
+
// ── 6. 计算新 hash(仅存在文件)──
|
|
324
|
+
const newFileHashes = await computeAllFileHashes(projectRoot, Array.from(codeSkeletons.keys()));
|
|
325
|
+
// ── 7. merge + save ──
|
|
326
|
+
const merged = mergeIncremental({
|
|
327
|
+
oldSnapshot,
|
|
328
|
+
changedSet,
|
|
329
|
+
newPartialGraph,
|
|
330
|
+
newFileHashes,
|
|
331
|
+
});
|
|
332
|
+
// W3 WARN-1:merge 出口前 safeParse 验证;失败视为 corruption 降级(不让坏 snapshot 写盘)
|
|
333
|
+
const validation = SnapshotWrapperSchema.safeParse(merged);
|
|
334
|
+
if (!validation.success) {
|
|
335
|
+
process.stderr.write(`[incremental] mergeIncremental 输出 schema 校验失败,降级 full re-index: ${validation.error.issues
|
|
336
|
+
.slice(0, 3)
|
|
337
|
+
.map((i) => i.message)
|
|
338
|
+
.join('; ')}\n`);
|
|
339
|
+
const snapshot = await runFullReindex(projectRoot);
|
|
340
|
+
return {
|
|
341
|
+
snapshot,
|
|
342
|
+
changedFiles: expanded,
|
|
343
|
+
origChangedFilesCount,
|
|
344
|
+
fallbackToFull: true,
|
|
345
|
+
fallbackReason: 'corruption',
|
|
346
|
+
durationMs: Date.now() - t0,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
// saveSnapshot 失败 → 视为 corruption 降级(罕见路径)
|
|
350
|
+
try {
|
|
351
|
+
await saveSnapshot(merged, projectRoot);
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
process.stderr.write(`[incremental] saveSnapshot 失败,降级 full re-index: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
355
|
+
const snapshot = await runFullReindex(projectRoot);
|
|
356
|
+
return {
|
|
357
|
+
snapshot,
|
|
358
|
+
changedFiles: expanded,
|
|
359
|
+
origChangedFilesCount,
|
|
360
|
+
fallbackToFull: true,
|
|
361
|
+
fallbackReason: 'corruption',
|
|
362
|
+
durationMs: Date.now() - t0,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
snapshot: merged,
|
|
367
|
+
changedFiles: expanded,
|
|
368
|
+
origChangedFilesCount,
|
|
369
|
+
fallbackToFull: false,
|
|
370
|
+
durationMs: Date.now() - t0,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* 触发一次 full re-index(fallback 路径)。
|
|
375
|
+
*
|
|
376
|
+
* 与 src/cli/commands/index.ts 的全量逻辑保持等价(扫描 → analyzeFile → buildUnifiedGraph → save);
|
|
377
|
+
* 提取到本模块独立函数,避免 cli 层 ↔ incremental 层双向依赖。
|
|
378
|
+
*/
|
|
379
|
+
async function runFullReindex(projectRoot) {
|
|
380
|
+
const registry = LanguageAdapterRegistry.getInstance();
|
|
381
|
+
const supportedExts = registry.getSupportedExtensions();
|
|
382
|
+
const scanResult = scanFiles(projectRoot, {
|
|
383
|
+
projectRoot,
|
|
384
|
+
extensions: supportedExts,
|
|
385
|
+
});
|
|
386
|
+
const absFiles = scanResult.files.map((rel) => path.isAbsolute(rel) ? rel : path.join(projectRoot, rel));
|
|
387
|
+
const codeSkeletons = new Map();
|
|
388
|
+
for (const absFile of absFiles) {
|
|
389
|
+
try {
|
|
390
|
+
const sk = await analyzeFile(absFile, { projectRoot });
|
|
391
|
+
if (sk)
|
|
392
|
+
codeSkeletons.set(absFile, sk);
|
|
393
|
+
}
|
|
394
|
+
catch (err) {
|
|
395
|
+
// 单文件失败不阻断;与 buildIncremental 路径一致输出 stderr 便于排查
|
|
396
|
+
process.stderr.write(`[full-reindex] analyzeFile 失败 (${absFile}): ${err instanceof Error ? err.message : String(err)}\n`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const graph = buildUnifiedGraph({
|
|
400
|
+
projectRoot,
|
|
401
|
+
codeSkeletons,
|
|
402
|
+
});
|
|
403
|
+
const fileHashes = await computeAllFileHashes(projectRoot, absFiles);
|
|
404
|
+
const snapshot = buildSnapshotWrapper(graph, fileHashes);
|
|
405
|
+
await saveSnapshot(snapshot, projectRoot);
|
|
406
|
+
return snapshot;
|
|
407
|
+
}
|
|
408
|
+
// 副作用避免:computeFileHash 仅在测试中可能用到,re-export 以方便单测
|
|
409
|
+
export { computeFileHash };
|
|
410
|
+
//# sourceMappingURL=incremental.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental.js","sourceRoot":"","sources":["../../src/knowledge-graph/incremental.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,qBAAqB,GAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAsB/C;;;;;;;;;GASG;AACH,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,WAAW,GAAG,uBAAuB,CAAC;IAC5C,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACtD,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GA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QAAQ,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACzD,MAAM,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAC1C,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,kDAAkD;AAClD,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature 151 — Knowledge Graph 模块顶层 API(FR-3 + Codex C-3 修订)
|
|
3
|
+
*
|
|
4
|
+
* 入口:buildUnifiedGraph(input)
|
|
5
|
+
* - 收集所有 CallSite + callerFile
|
|
6
|
+
* - call-resolver 派生 calls 边
|
|
7
|
+
* - deriveImportEdges 派生 depends-on 边(Codex C-3:ModuleGraph 数据源)
|
|
8
|
+
* - 装配 nodes / edges / metadata 输出 UnifiedGraph
|
|
9
|
+
*
|
|
10
|
+
* 单例 cache:
|
|
11
|
+
* - setCurrentUnifiedGraph / getCurrentUnifiedGraph
|
|
12
|
+
* - 让 panoramic 阶段(component-view-builder DI)能在不改 generate 签名的前提下消费
|
|
13
|
+
* - batch-orchestrator 在生成 graph.json 之前 setCurrentUnifiedGraph(graph)
|
|
14
|
+
*/
|
|
15
|
+
import type { CodeSkeleton } from '../models/code-skeleton.js';
|
|
16
|
+
import type { CallSite } from '../models/call-site.js';
|
|
17
|
+
import { resolveCalls, type CallSiteWithFile } from './call-resolver.js';
|
|
18
|
+
import { UNIFIED_GRAPH_SCHEMA_VERSION, defaultDirectionalForRelation, type UnifiedEdge, type UnifiedGraph, type UnifiedNode } from './unified-graph.js';
|
|
19
|
+
export interface BuildUnifiedGraphInput {
|
|
20
|
+
projectRoot: string;
|
|
21
|
+
/** absoluteFilePath → CodeSkeleton */
|
|
22
|
+
codeSkeletons: ReadonlyMap<string, CodeSkeleton>;
|
|
23
|
+
/** 可选:复用已构建的节点(panoramic GraphNode → UnifiedNode 转换路径),避免重复枚举 */
|
|
24
|
+
preBuiltNodes?: ReadonlyArray<UnifiedNode>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 顶层 API — 把 CodeSkeleton Map 转换为 UnifiedGraph。
|
|
28
|
+
*
|
|
29
|
+
* 输出 edges 同时含 calls + depends-on:
|
|
30
|
+
* - calls 边:来自 resolveCalls(callSites, skeletons)
|
|
31
|
+
* - depends-on 边:来自 deriveImportEdges(skeletons)
|
|
32
|
+
*
|
|
33
|
+
* 其他 relation(contains / cross-module / documents 等)由 graph-builder.ts
|
|
34
|
+
* 在 4 路合并阶段从 docGraph / architectureIR / crossReferenceLinks 注入。
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildUnifiedGraph(input: BuildUnifiedGraphInput): UnifiedGraph;
|
|
37
|
+
/**
|
|
38
|
+
* 从 CodeSkeleton.imports 派生 depends-on 边(Codex C-3 修订 + Feature 156 W1.0 importType 编码)。
|
|
39
|
+
*
|
|
40
|
+
* 设计动机:
|
|
41
|
+
* - ModuleGraph 派生(W1.4)需要 import 边数据源;如果 UnifiedGraph 只产 calls 边,
|
|
42
|
+
* 就无法派生 SCC / topologicalOrder / mermaidSource
|
|
43
|
+
* - batch-orchestrator / doc-graph-builder / delta-regenerator 等 8+ consumer 消费 import 边
|
|
44
|
+
*
|
|
45
|
+
* 实现:每个 CodeSkeleton.imports[].resolvedPath 派生一条
|
|
46
|
+
* `${callerFile} -[depends-on]-> ${target}` 边,confidence='high',directional=true
|
|
47
|
+
*
|
|
48
|
+
* Feature 156 W1.0 v2 / WARN-3 修订:
|
|
49
|
+
* - evidence 字段保持纯 specifier(如 "./foo"),不再编码 importType 前缀
|
|
50
|
+
* —— 避免污染 panoramic 消费方(graph-builder / component-view-builder 直接展示 evidenceText / note)
|
|
51
|
+
* - importType 改写入 edge.metadata.importType 结构化字段(UnifiedEdge.metadata 已 schema 支持)
|
|
52
|
+
* - module-derivation.deriveModuleGraph 从 metadata.importType 读,不再 split evidence
|
|
53
|
+
*
|
|
54
|
+
* 注:本函数不做 cross-module name resolution(那是 call-resolver 的工作);
|
|
55
|
+
* 仅产 module-to-module 的 import 边。
|
|
56
|
+
*/
|
|
57
|
+
export declare function deriveImportEdges(codeSkeletons: ReadonlyMap<string, CodeSkeleton>): UnifiedEdge[];
|
|
58
|
+
/**
|
|
59
|
+
* 设置当前 batch / pipeline 构建好的 UnifiedGraph。
|
|
60
|
+
* 由 batch-orchestrator 在生成 graph.json 之前调用,让下游 component-view-builder
|
|
61
|
+
* 等通过 getCurrentUnifiedGraph() 拿到同一份图。
|
|
62
|
+
*/
|
|
63
|
+
export declare function setCurrentUnifiedGraph(g: UnifiedGraph | null): void;
|
|
64
|
+
/**
|
|
65
|
+
* 获取当前 batch / pipeline 已构建的 UnifiedGraph。
|
|
66
|
+
* 未设置时返回 null(生产 / 测试 / DI fallback)。
|
|
67
|
+
*/
|
|
68
|
+
export declare function getCurrentUnifiedGraph(): UnifiedGraph | null;
|
|
69
|
+
export type { CallSite, UnifiedEdge, UnifiedGraph, UnifiedNode, CallSiteWithFile, };
|
|
70
|
+
export { resolveCalls, UNIFIED_GRAPH_SCHEMA_VERSION, defaultDirectionalForRelation, };
|
|
71
|
+
export { buildModuleSymbolIndex, buildClassMemberIndex, buildImportIndex, buildClassMroIndex, extractClassName, } from './call-resolver.js';
|
|
72
|
+
export { CallSiteSchema, CalleeKindSchema, type CalleeKind, } from '../models/call-site.js';
|
|
73
|
+
export { UnifiedGraphSchema, UnifiedNodeSchema, UnifiedNodeKindSchema, UnifiedEdgeSchema, UnifiedEdgeRelationSchema, ConfidenceTierSchema, type ConfidenceTier, type UnifiedNodeKind, type UnifiedEdgeRelation, } from './unified-graph.js';
|
|
74
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/knowledge-graph/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EA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ACL,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EACzB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { resolveCalls, } from './call-resolver.js';
|
|
2
|
+
import { UNIFIED_GRAPH_SCHEMA_VERSION, defaultDirectionalForRelation, } from './unified-graph.js';
|
|
3
|
+
/**
|
|
4
|
+
* 顶层 API — 把 CodeSkeleton Map 转换为 UnifiedGraph。
|
|
5
|
+
*
|
|
6
|
+
* 输出 edges 同时含 calls + depends-on:
|
|
7
|
+
* - calls 边:来自 resolveCalls(callSites, skeletons)
|
|
8
|
+
* - depends-on 边:来自 deriveImportEdges(skeletons)
|
|
9
|
+
*
|
|
10
|
+
* 其他 relation(contains / cross-module / documents 等)由 graph-builder.ts
|
|
11
|
+
* 在 4 路合并阶段从 docGraph / architectureIR / crossReferenceLinks 注入。
|
|
12
|
+
*/
|
|
13
|
+
export function buildUnifiedGraph(input) {
|
|
14
|
+
const callSites = collectCallSites(input.codeSkeletons);
|
|
15
|
+
const callEdges = resolveCalls(callSites, input.codeSkeletons);
|
|
16
|
+
const importEdges = deriveImportEdges(input.codeSkeletons);
|
|
17
|
+
const nodes = input.preBuiltNodes ?? deriveNodesFromSkeletons(input.codeSkeletons);
|
|
18
|
+
return {
|
|
19
|
+
nodes: [...nodes],
|
|
20
|
+
edges: [...callEdges, ...importEdges],
|
|
21
|
+
metadata: {
|
|
22
|
+
generatedAt: new Date().toISOString(),
|
|
23
|
+
projectRoot: input.projectRoot,
|
|
24
|
+
schemaVersion: UNIFIED_GRAPH_SCHEMA_VERSION,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 从 CodeSkeleton.imports 派生 depends-on 边(Codex C-3 修订 + Feature 156 W1.0 importType 编码)。
|
|
30
|
+
*
|
|
31
|
+
* 设计动机:
|
|
32
|
+
* - ModuleGraph 派生(W1.4)需要 import 边数据源;如果 UnifiedGraph 只产 calls 边,
|
|
33
|
+
* 就无法派生 SCC / topologicalOrder / mermaidSource
|
|
34
|
+
* - batch-orchestrator / doc-graph-builder / delta-regenerator 等 8+ consumer 消费 import 边
|
|
35
|
+
*
|
|
36
|
+
* 实现:每个 CodeSkeleton.imports[].resolvedPath 派生一条
|
|
37
|
+
* `${callerFile} -[depends-on]-> ${target}` 边,confidence='high',directional=true
|
|
38
|
+
*
|
|
39
|
+
* Feature 156 W1.0 v2 / WARN-3 修订:
|
|
40
|
+
* - evidence 字段保持纯 specifier(如 "./foo"),不再编码 importType 前缀
|
|
41
|
+
* —— 避免污染 panoramic 消费方(graph-builder / component-view-builder 直接展示 evidenceText / note)
|
|
42
|
+
* - importType 改写入 edge.metadata.importType 结构化字段(UnifiedEdge.metadata 已 schema 支持)
|
|
43
|
+
* - module-derivation.deriveModuleGraph 从 metadata.importType 读,不再 split evidence
|
|
44
|
+
*
|
|
45
|
+
* 注:本函数不做 cross-module name resolution(那是 call-resolver 的工作);
|
|
46
|
+
* 仅产 module-to-module 的 import 边。
|
|
47
|
+
*/
|
|
48
|
+
export function deriveImportEdges(codeSkeletons) {
|
|
49
|
+
const edges = [];
|
|
50
|
+
for (const [callerFile, sk] of codeSkeletons) {
|
|
51
|
+
for (const imp of sk.imports) {
|
|
52
|
+
if (!imp.resolvedPath)
|
|
53
|
+
continue;
|
|
54
|
+
// 自引用过滤(一些 mapper 把同模块作 import 输出)
|
|
55
|
+
if (imp.resolvedPath === callerFile)
|
|
56
|
+
continue;
|
|
57
|
+
// W1.0 v2 / WARN-3:evidence 保持纯 specifier;importType 写 metadata
|
|
58
|
+
const edge = {
|
|
59
|
+
source: callerFile,
|
|
60
|
+
target: imp.resolvedPath,
|
|
61
|
+
relation: 'depends-on',
|
|
62
|
+
confidence: 'high',
|
|
63
|
+
directional: defaultDirectionalForRelation('depends-on'),
|
|
64
|
+
evidence: imp.moduleSpecifier,
|
|
65
|
+
...(imp.importType ? { metadata: { importType: imp.importType } } : {}),
|
|
66
|
+
};
|
|
67
|
+
edges.push(edge);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return edges;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 收集所有 callSite + 附加 callerFile 上下文。
|
|
74
|
+
* 仅当 CodeSkeleton.callSites 字段存在时收集;空 / 缺失字段视为该文件未抽取 callSites。
|
|
75
|
+
*/
|
|
76
|
+
function collectCallSites(codeSkeletons) {
|
|
77
|
+
const out = [];
|
|
78
|
+
for (const [filePath, sk] of codeSkeletons) {
|
|
79
|
+
if (!sk.callSites || sk.callSites.length === 0)
|
|
80
|
+
continue;
|
|
81
|
+
for (const cs of sk.callSites) {
|
|
82
|
+
out.push({ ...cs, callerFile: filePath });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 从 CodeSkeleton 派生 module + symbol 节点(默认行为)。
|
|
89
|
+
*
|
|
90
|
+
* 仅当 input.preBuiltNodes 未提供时使用。
|
|
91
|
+
* 输出节点结构:
|
|
92
|
+
* - 每个 CodeSkeleton 派生 1 个 module 节点(id = filePath)
|
|
93
|
+
* - 每个 ExportSymbol 派生 1 个 symbol 节点(id = `${filePath}::${exp.name}`)
|
|
94
|
+
* - class 的 members 进一步派生 symbol 节点(id = `${filePath}::${exp.name}.${m.name}`)
|
|
95
|
+
*/
|
|
96
|
+
function deriveNodesFromSkeletons(codeSkeletons) {
|
|
97
|
+
const nodes = [];
|
|
98
|
+
for (const [filePath, sk] of codeSkeletons) {
|
|
99
|
+
nodes.push({
|
|
100
|
+
id: filePath,
|
|
101
|
+
label: filePath.split(/[/\\]/).pop() ?? filePath,
|
|
102
|
+
kind: 'module',
|
|
103
|
+
language: sk.language,
|
|
104
|
+
filePath,
|
|
105
|
+
metadata: {
|
|
106
|
+
callSitesCount: sk.callSites?.length ?? 0,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
for (const exp of sk.exports) {
|
|
110
|
+
const symbolId = `${filePath}::${exp.name}`;
|
|
111
|
+
nodes.push({
|
|
112
|
+
id: symbolId,
|
|
113
|
+
label: exp.name,
|
|
114
|
+
kind: 'symbol',
|
|
115
|
+
language: sk.language,
|
|
116
|
+
filePath,
|
|
117
|
+
});
|
|
118
|
+
if (exp.members) {
|
|
119
|
+
for (const m of exp.members) {
|
|
120
|
+
nodes.push({
|
|
121
|
+
id: `${symbolId}.${m.name}`,
|
|
122
|
+
label: `${exp.name}.${m.name}`,
|
|
123
|
+
kind: 'symbol',
|
|
124
|
+
language: sk.language,
|
|
125
|
+
filePath,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return nodes;
|
|
132
|
+
}
|
|
133
|
+
// ───────────────────────────────────────────────────────────
|
|
134
|
+
// 单例 cache(FR-7 DI provider + Codex W-1 batch 直接路径)
|
|
135
|
+
// ───────────────────────────────────────────────────────────
|
|
136
|
+
let _cachedGraph = null;
|
|
137
|
+
/**
|
|
138
|
+
* 设置当前 batch / pipeline 构建好的 UnifiedGraph。
|
|
139
|
+
* 由 batch-orchestrator 在生成 graph.json 之前调用,让下游 component-view-builder
|
|
140
|
+
* 等通过 getCurrentUnifiedGraph() 拿到同一份图。
|
|
141
|
+
*/
|
|
142
|
+
export function setCurrentUnifiedGraph(g) {
|
|
143
|
+
_cachedGraph = g;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 获取当前 batch / pipeline 已构建的 UnifiedGraph。
|
|
147
|
+
* 未设置时返回 null(生产 / 测试 / DI fallback)。
|
|
148
|
+
*/
|
|
149
|
+
export function getCurrentUnifiedGraph() {
|
|
150
|
+
return _cachedGraph;
|
|
151
|
+
}
|
|
152
|
+
export { resolveCalls, UNIFIED_GRAPH_SCHEMA_VERSION, defaultDirectionalForRelation, };
|
|
153
|
+
export { buildModuleSymbolIndex, buildClassMemberIndex, buildImportIndex, buildClassMroIndex, extractClassName, } from './call-resolver.js';
|
|
154
|
+
export { CallSiteSchema, CalleeKindSchema, } from '../models/call-site.js';
|
|
155
|
+
export { UnifiedGraphSchema, UnifiedNodeSchema, UnifiedNodeKindSchema, UnifiedEdgeSchema, UnifiedEdgeRelationSchema, ConfidenceTierSchema, } from './unified-graph.js';
|
|
156
|
+
//# sourceMappingURL=index.js.map
|