cotx-engine 0.1.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/LICENSE +94 -0
- package/README.md +103 -0
- package/dist/commands/compile.d.ts +3 -0
- package/dist/commands/compile.js +93 -0
- package/dist/commands/compile.js.map +1 -0
- package/dist/commands/context.d.ts +1 -0
- package/dist/commands/context.js +98 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/diff.d.ts +19 -0
- package/dist/commands/diff.js +127 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/impact.d.ts +3 -0
- package/dist/commands/impact.js +91 -0
- package/dist/commands/impact.js.map +1 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +13 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/lint.d.ts +13 -0
- package/dist/commands/lint.js +290 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/commands/map.d.ts +6 -0
- package/dist/commands/map.js +409 -0
- package/dist/commands/map.js.map +1 -0
- package/dist/commands/migrate.d.ts +16 -0
- package/dist/commands/migrate.js +150 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/query.d.ts +3 -0
- package/dist/commands/query.js +47 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/rename.d.ts +5 -0
- package/dist/commands/rename.js +163 -0
- package/dist/commands/rename.js.map +1 -0
- package/dist/commands/snapshot.d.ts +6 -0
- package/dist/commands/snapshot.js +48 -0
- package/dist/commands/snapshot.js.map +1 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +72 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/update.d.ts +8 -0
- package/dist/commands/update.js +163 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/write.d.ts +6 -0
- package/dist/commands/write.js +221 -0
- package/dist/commands/write.js.map +1 -0
- package/dist/compiler/auto-describe.d.ts +13 -0
- package/dist/compiler/auto-describe.js +91 -0
- package/dist/compiler/auto-describe.js.map +1 -0
- package/dist/compiler/concept-compiler.d.ts +21 -0
- package/dist/compiler/concept-compiler.js +125 -0
- package/dist/compiler/concept-compiler.js.map +1 -0
- package/dist/compiler/contract-compiler.d.ts +16 -0
- package/dist/compiler/contract-compiler.js +90 -0
- package/dist/compiler/contract-compiler.js.map +1 -0
- package/dist/compiler/delta-detector.d.ts +8 -0
- package/dist/compiler/delta-detector.js +34 -0
- package/dist/compiler/delta-detector.js.map +1 -0
- package/dist/compiler/flow-compiler.d.ts +18 -0
- package/dist/compiler/flow-compiler.js +69 -0
- package/dist/compiler/flow-compiler.js.map +1 -0
- package/dist/compiler/module-compiler.d.ts +18 -0
- package/dist/compiler/module-compiler.js +420 -0
- package/dist/compiler/module-compiler.js.map +1 -0
- package/dist/compiler/stale-detector.d.ts +22 -0
- package/dist/compiler/stale-detector.js +79 -0
- package/dist/compiler/stale-detector.js.map +1 -0
- package/dist/config/ignore-service.d.ts +26 -0
- package/dist/config/ignore-service.js +366 -0
- package/dist/config/ignore-service.js.map +1 -0
- package/dist/core/analysis/cluster-enricher.d.ts +38 -0
- package/dist/core/analysis/cluster-enricher.js +169 -0
- package/dist/core/analysis/cluster-enricher.js.map +1 -0
- package/dist/core/analysis/community-processor.d.ts +39 -0
- package/dist/core/analysis/community-processor.js +319 -0
- package/dist/core/analysis/community-processor.js.map +1 -0
- package/dist/core/analysis/process-processor.d.ts +51 -0
- package/dist/core/analysis/process-processor.js +318 -0
- package/dist/core/analysis/process-processor.js.map +1 -0
- package/dist/core/bridge.d.ts +15 -0
- package/dist/core/bridge.js +63 -0
- package/dist/core/bridge.js.map +1 -0
- package/dist/core/export/json-exporter.d.ts +43 -0
- package/dist/core/export/json-exporter.js +13 -0
- package/dist/core/export/json-exporter.js.map +1 -0
- package/dist/core/graph/graph.d.ts +2 -0
- package/dist/core/graph/graph.js +79 -0
- package/dist/core/graph/graph.js.map +1 -0
- package/dist/core/graph/types.d.ts +25 -0
- package/dist/core/graph/types.js +2 -0
- package/dist/core/graph/types.js.map +1 -0
- package/dist/core/parser/ast-cache.d.ts +11 -0
- package/dist/core/parser/ast-cache.js +36 -0
- package/dist/core/parser/ast-cache.js.map +1 -0
- package/dist/core/parser/call-processor.d.ts +105 -0
- package/dist/core/parser/call-processor.js +1807 -0
- package/dist/core/parser/call-processor.js.map +1 -0
- package/dist/core/parser/call-routing.d.ts +55 -0
- package/dist/core/parser/call-routing.js +113 -0
- package/dist/core/parser/call-routing.js.map +1 -0
- package/dist/core/parser/call-sites/extract-language-call-site.d.ts +10 -0
- package/dist/core/parser/call-sites/extract-language-call-site.js +23 -0
- package/dist/core/parser/call-sites/extract-language-call-site.js.map +1 -0
- package/dist/core/parser/call-sites/java.d.ts +9 -0
- package/dist/core/parser/call-sites/java.js +31 -0
- package/dist/core/parser/call-sites/java.js.map +1 -0
- package/dist/core/parser/cluster-enricher.d.ts +38 -0
- package/dist/core/parser/cluster-enricher.js +169 -0
- package/dist/core/parser/cluster-enricher.js.map +1 -0
- package/dist/core/parser/community-processor.d.ts +39 -0
- package/dist/core/parser/community-processor.js +321 -0
- package/dist/core/parser/community-processor.js.map +1 -0
- package/dist/core/parser/constants.d.ts +16 -0
- package/dist/core/parser/constants.js +17 -0
- package/dist/core/parser/constants.js.map +1 -0
- package/dist/core/parser/entry-point-scoring.d.ts +57 -0
- package/dist/core/parser/entry-point-scoring.js +377 -0
- package/dist/core/parser/entry-point-scoring.js.map +1 -0
- package/dist/core/parser/export-detection.d.ts +57 -0
- package/dist/core/parser/export-detection.js +234 -0
- package/dist/core/parser/export-detection.js.map +1 -0
- package/dist/core/parser/field-extractor.d.ts +34 -0
- package/dist/core/parser/field-extractor.js +33 -0
- package/dist/core/parser/field-extractor.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/c-cpp.d.ts +16 -0
- package/dist/core/parser/field-extractors/configs/c-cpp.js +129 -0
- package/dist/core/parser/field-extractors/configs/c-cpp.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/csharp.d.ts +15 -0
- package/dist/core/parser/field-extractors/configs/csharp.js +129 -0
- package/dist/core/parser/field-extractors/configs/csharp.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/dart.d.ts +12 -0
- package/dist/core/parser/field-extractors/configs/dart.js +93 -0
- package/dist/core/parser/field-extractors/configs/dart.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/go.d.ts +12 -0
- package/dist/core/parser/field-extractors/configs/go.js +66 -0
- package/dist/core/parser/field-extractors/configs/go.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/helpers.d.ts +40 -0
- package/dist/core/parser/field-extractors/configs/helpers.js +118 -0
- package/dist/core/parser/field-extractors/configs/helpers.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/jvm.d.ts +17 -0
- package/dist/core/parser/field-extractors/configs/jvm.js +139 -0
- package/dist/core/parser/field-extractors/configs/jvm.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/php.d.ts +12 -0
- package/dist/core/parser/field-extractors/configs/php.js +69 -0
- package/dist/core/parser/field-extractors/configs/php.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/python.d.ts +15 -0
- package/dist/core/parser/field-extractors/configs/python.js +92 -0
- package/dist/core/parser/field-extractors/configs/python.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/ruby.d.ts +15 -0
- package/dist/core/parser/field-extractors/configs/ruby.js +68 -0
- package/dist/core/parser/field-extractors/configs/ruby.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/rust.d.ts +12 -0
- package/dist/core/parser/field-extractors/configs/rust.js +58 -0
- package/dist/core/parser/field-extractors/configs/rust.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/swift.d.ts +15 -0
- package/dist/core/parser/field-extractors/configs/swift.js +75 -0
- package/dist/core/parser/field-extractors/configs/swift.js.map +1 -0
- package/dist/core/parser/field-extractors/configs/typescript-javascript.d.ts +14 -0
- package/dist/core/parser/field-extractors/configs/typescript-javascript.js +72 -0
- package/dist/core/parser/field-extractors/configs/typescript-javascript.js.map +1 -0
- package/dist/core/parser/field-extractors/generic.d.ts +61 -0
- package/dist/core/parser/field-extractors/generic.js +170 -0
- package/dist/core/parser/field-extractors/generic.js.map +1 -0
- package/dist/core/parser/field-extractors/typescript.d.ts +16 -0
- package/dist/core/parser/field-extractors/typescript.js +167 -0
- package/dist/core/parser/field-extractors/typescript.js.map +1 -0
- package/dist/core/parser/field-types.d.ts +46 -0
- package/dist/core/parser/field-types.js +2 -0
- package/dist/core/parser/field-types.js.map +1 -0
- package/dist/core/parser/filesystem-walker.d.ts +28 -0
- package/dist/core/parser/filesystem-walker.js +82 -0
- package/dist/core/parser/filesystem-walker.js.map +1 -0
- package/dist/core/parser/framework-detection.d.ts +149 -0
- package/dist/core/parser/framework-detection.js +782 -0
- package/dist/core/parser/framework-detection.js.map +1 -0
- package/dist/core/parser/heritage-processor.d.ts +52 -0
- package/dist/core/parser/heritage-processor.js +339 -0
- package/dist/core/parser/heritage-processor.js.map +1 -0
- package/dist/core/parser/import-processor.d.ts +33 -0
- package/dist/core/parser/import-processor.js +382 -0
- package/dist/core/parser/import-processor.js.map +1 -0
- package/dist/core/parser/import-resolvers/csharp.d.ts +19 -0
- package/dist/core/parser/import-resolvers/csharp.js +132 -0
- package/dist/core/parser/import-resolvers/csharp.js.map +1 -0
- package/dist/core/parser/import-resolvers/dart.d.ts +7 -0
- package/dist/core/parser/import-resolvers/dart.js +45 -0
- package/dist/core/parser/import-resolvers/dart.js.map +1 -0
- package/dist/core/parser/import-resolvers/go.d.ts +18 -0
- package/dist/core/parser/import-resolvers/go.js +62 -0
- package/dist/core/parser/import-resolvers/go.js.map +1 -0
- package/dist/core/parser/import-resolvers/jvm.d.ts +32 -0
- package/dist/core/parser/import-resolvers/jvm.js +160 -0
- package/dist/core/parser/import-resolvers/jvm.js.map +1 -0
- package/dist/core/parser/import-resolvers/php.d.ts +25 -0
- package/dist/core/parser/import-resolvers/php.js +81 -0
- package/dist/core/parser/import-resolvers/php.js.map +1 -0
- package/dist/core/parser/import-resolvers/python.d.ts +25 -0
- package/dist/core/parser/import-resolvers/python.js +85 -0
- package/dist/core/parser/import-resolvers/python.js.map +1 -0
- package/dist/core/parser/import-resolvers/ruby.d.ts +15 -0
- package/dist/core/parser/import-resolvers/ruby.js +21 -0
- package/dist/core/parser/import-resolvers/ruby.js.map +1 -0
- package/dist/core/parser/import-resolvers/rust.d.ts +18 -0
- package/dist/core/parser/import-resolvers/rust.js +119 -0
- package/dist/core/parser/import-resolvers/rust.js.map +1 -0
- package/dist/core/parser/import-resolvers/standard.d.ts +36 -0
- package/dist/core/parser/import-resolvers/standard.js +144 -0
- package/dist/core/parser/import-resolvers/standard.js.map +1 -0
- package/dist/core/parser/import-resolvers/swift.d.ts +7 -0
- package/dist/core/parser/import-resolvers/swift.js +25 -0
- package/dist/core/parser/import-resolvers/swift.js.map +1 -0
- package/dist/core/parser/import-resolvers/types.d.ts +44 -0
- package/dist/core/parser/import-resolvers/types.js +7 -0
- package/dist/core/parser/import-resolvers/types.js.map +1 -0
- package/dist/core/parser/import-resolvers/utils.d.ts +35 -0
- package/dist/core/parser/import-resolvers/utils.js +150 -0
- package/dist/core/parser/import-resolvers/utils.js.map +1 -0
- package/dist/core/parser/import-resolvers/vue.d.ts +8 -0
- package/dist/core/parser/import-resolvers/vue.js +10 -0
- package/dist/core/parser/import-resolvers/vue.js.map +1 -0
- package/dist/core/parser/language-config.d.ts +52 -0
- package/dist/core/parser/language-config.js +182 -0
- package/dist/core/parser/language-config.js.map +1 -0
- package/dist/core/parser/language-provider.d.ts +126 -0
- package/dist/core/parser/language-provider.js +25 -0
- package/dist/core/parser/language-provider.js.map +1 -0
- package/dist/core/parser/languages/c-cpp.d.ts +12 -0
- package/dist/core/parser/languages/c-cpp.js +312 -0
- package/dist/core/parser/languages/c-cpp.js.map +1 -0
- package/dist/core/parser/languages/csharp.d.ts +8 -0
- package/dist/core/parser/languages/csharp.js +127 -0
- package/dist/core/parser/languages/csharp.js.map +1 -0
- package/dist/core/parser/languages/dart.d.ts +12 -0
- package/dist/core/parser/languages/dart.js +91 -0
- package/dist/core/parser/languages/dart.js.map +1 -0
- package/dist/core/parser/languages/go.d.ts +11 -0
- package/dist/core/parser/languages/go.js +32 -0
- package/dist/core/parser/languages/go.js.map +1 -0
- package/dist/core/parser/languages/index.d.ts +38 -0
- package/dist/core/parser/languages/index.js +63 -0
- package/dist/core/parser/languages/index.js.map +1 -0
- package/dist/core/parser/languages/java.d.ts +9 -0
- package/dist/core/parser/languages/java.js +33 -0
- package/dist/core/parser/languages/java.js.map +1 -0
- package/dist/core/parser/languages/kotlin.d.ts +9 -0
- package/dist/core/parser/languages/kotlin.js +112 -0
- package/dist/core/parser/languages/kotlin.js.map +1 -0
- package/dist/core/parser/languages/php.d.ts +8 -0
- package/dist/core/parser/languages/php.js +226 -0
- package/dist/core/parser/languages/php.js.map +1 -0
- package/dist/core/parser/languages/python.d.ts +12 -0
- package/dist/core/parser/languages/python.js +66 -0
- package/dist/core/parser/languages/python.js.map +1 -0
- package/dist/core/parser/languages/ruby.d.ts +9 -0
- package/dist/core/parser/languages/ruby.js +109 -0
- package/dist/core/parser/languages/ruby.js.map +1 -0
- package/dist/core/parser/languages/rust.d.ts +12 -0
- package/dist/core/parser/languages/rust.js +121 -0
- package/dist/core/parser/languages/rust.js.map +1 -0
- package/dist/core/parser/languages/swift.d.ts +12 -0
- package/dist/core/parser/languages/swift.js +233 -0
- package/dist/core/parser/languages/swift.js.map +1 -0
- package/dist/core/parser/languages/typescript.d.ts +11 -0
- package/dist/core/parser/languages/typescript.js +169 -0
- package/dist/core/parser/languages/typescript.js.map +1 -0
- package/dist/core/parser/languages/vue.d.ts +13 -0
- package/dist/core/parser/languages/vue.js +65 -0
- package/dist/core/parser/languages/vue.js.map +1 -0
- package/dist/core/parser/markdown-processor.d.ts +17 -0
- package/dist/core/parser/markdown-processor.js +125 -0
- package/dist/core/parser/markdown-processor.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/c-cpp.d.ts +3 -0
- package/dist/core/parser/method-extractors/configs/c-cpp.js +276 -0
- package/dist/core/parser/method-extractors/configs/c-cpp.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/csharp.d.ts +2 -0
- package/dist/core/parser/method-extractors/configs/csharp.js +243 -0
- package/dist/core/parser/method-extractors/configs/csharp.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/dart.d.ts +2 -0
- package/dist/core/parser/method-extractors/configs/dart.js +263 -0
- package/dist/core/parser/method-extractors/configs/dart.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/go.d.ts +2 -0
- package/dist/core/parser/method-extractors/configs/go.js +120 -0
- package/dist/core/parser/method-extractors/configs/go.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/jvm.d.ts +3 -0
- package/dist/core/parser/method-extractors/configs/jvm.js +309 -0
- package/dist/core/parser/method-extractors/configs/jvm.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/php.d.ts +2 -0
- package/dist/core/parser/method-extractors/configs/php.js +243 -0
- package/dist/core/parser/method-extractors/configs/php.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/python.d.ts +2 -0
- package/dist/core/parser/method-extractors/configs/python.js +219 -0
- package/dist/core/parser/method-extractors/configs/python.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/ruby.d.ts +2 -0
- package/dist/core/parser/method-extractors/configs/ruby.js +201 -0
- package/dist/core/parser/method-extractors/configs/ruby.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/rust.d.ts +2 -0
- package/dist/core/parser/method-extractors/configs/rust.js +120 -0
- package/dist/core/parser/method-extractors/configs/rust.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/swift.d.ts +2 -0
- package/dist/core/parser/method-extractors/configs/swift.js +191 -0
- package/dist/core/parser/method-extractors/configs/swift.js.map +1 -0
- package/dist/core/parser/method-extractors/configs/typescript-javascript.d.ts +3 -0
- package/dist/core/parser/method-extractors/configs/typescript-javascript.js +231 -0
- package/dist/core/parser/method-extractors/configs/typescript-javascript.js.map +1 -0
- package/dist/core/parser/method-extractors/generic.d.ts +11 -0
- package/dist/core/parser/method-extractors/generic.js +162 -0
- package/dist/core/parser/method-extractors/generic.js.map +1 -0
- package/dist/core/parser/method-types.d.ts +110 -0
- package/dist/core/parser/method-types.js +2 -0
- package/dist/core/parser/method-types.js.map +1 -0
- package/dist/core/parser/mro-processor.d.ts +46 -0
- package/dist/core/parser/mro-processor.js +677 -0
- package/dist/core/parser/mro-processor.js.map +1 -0
- package/dist/core/parser/named-binding-processor.d.ts +18 -0
- package/dist/core/parser/named-binding-processor.js +43 -0
- package/dist/core/parser/named-binding-processor.js.map +1 -0
- package/dist/core/parser/named-bindings/csharp.d.ts +3 -0
- package/dist/core/parser/named-bindings/csharp.js +38 -0
- package/dist/core/parser/named-bindings/csharp.js.map +1 -0
- package/dist/core/parser/named-bindings/java.d.ts +3 -0
- package/dist/core/parser/named-bindings/java.js +30 -0
- package/dist/core/parser/named-bindings/java.js.map +1 -0
- package/dist/core/parser/named-bindings/kotlin.d.ts +3 -0
- package/dist/core/parser/named-bindings/kotlin.js +37 -0
- package/dist/core/parser/named-bindings/kotlin.js.map +1 -0
- package/dist/core/parser/named-bindings/php.d.ts +3 -0
- package/dist/core/parser/named-bindings/php.js +62 -0
- package/dist/core/parser/named-bindings/php.js.map +1 -0
- package/dist/core/parser/named-bindings/python.d.ts +3 -0
- package/dist/core/parser/named-bindings/python.js +50 -0
- package/dist/core/parser/named-bindings/python.js.map +1 -0
- package/dist/core/parser/named-bindings/rust.d.ts +3 -0
- package/dist/core/parser/named-bindings/rust.js +67 -0
- package/dist/core/parser/named-bindings/rust.js.map +1 -0
- package/dist/core/parser/named-bindings/types.d.ts +16 -0
- package/dist/core/parser/named-bindings/types.js +7 -0
- package/dist/core/parser/named-bindings/types.js.map +1 -0
- package/dist/core/parser/named-bindings/typescript.d.ts +3 -0
- package/dist/core/parser/named-bindings/typescript.js +59 -0
- package/dist/core/parser/named-bindings/typescript.js.map +1 -0
- package/dist/core/parser/parsing-processor.d.ts +23 -0
- package/dist/core/parser/parsing-processor.js +464 -0
- package/dist/core/parser/parsing-processor.js.map +1 -0
- package/dist/core/parser/pipeline.d.ts +17 -0
- package/dist/core/parser/pipeline.js +1405 -0
- package/dist/core/parser/pipeline.js.map +1 -0
- package/dist/core/parser/process-processor.d.ts +51 -0
- package/dist/core/parser/process-processor.js +318 -0
- package/dist/core/parser/process-processor.js.map +1 -0
- package/dist/core/parser/resolution-context.d.ts +58 -0
- package/dist/core/parser/resolution-context.js +136 -0
- package/dist/core/parser/resolution-context.js.map +1 -0
- package/dist/core/parser/route-extractors/expo.d.ts +1 -0
- package/dist/core/parser/route-extractors/expo.js +37 -0
- package/dist/core/parser/route-extractors/expo.js.map +1 -0
- package/dist/core/parser/route-extractors/middleware.d.ts +47 -0
- package/dist/core/parser/route-extractors/middleware.js +168 -0
- package/dist/core/parser/route-extractors/middleware.js.map +1 -0
- package/dist/core/parser/route-extractors/nextjs.d.ts +3 -0
- package/dist/core/parser/route-extractors/nextjs.js +77 -0
- package/dist/core/parser/route-extractors/nextjs.js.map +1 -0
- package/dist/core/parser/route-extractors/php.d.ts +7 -0
- package/dist/core/parser/route-extractors/php.js +23 -0
- package/dist/core/parser/route-extractors/php.js.map +1 -0
- package/dist/core/parser/route-extractors/response-shapes.d.ts +20 -0
- package/dist/core/parser/route-extractors/response-shapes.js +295 -0
- package/dist/core/parser/route-extractors/response-shapes.js.map +1 -0
- package/dist/core/parser/structure-processor.d.ts +2 -0
- package/dist/core/parser/structure-processor.js +37 -0
- package/dist/core/parser/structure-processor.js.map +1 -0
- package/dist/core/parser/symbol-table.d.ts +79 -0
- package/dist/core/parser/symbol-table.js +116 -0
- package/dist/core/parser/symbol-table.js.map +1 -0
- package/dist/core/parser/tree-sitter-queries.d.ts +16 -0
- package/dist/core/parser/tree-sitter-queries.js +1180 -0
- package/dist/core/parser/tree-sitter-queries.js.map +1 -0
- package/dist/core/parser/type-env.d.ts +81 -0
- package/dist/core/parser/type-env.js +1048 -0
- package/dist/core/parser/type-env.js.map +1 -0
- package/dist/core/parser/type-extractors/c-cpp.d.ts +7 -0
- package/dist/core/parser/type-extractors/c-cpp.js +533 -0
- package/dist/core/parser/type-extractors/c-cpp.js.map +1 -0
- package/dist/core/parser/type-extractors/csharp.d.ts +2 -0
- package/dist/core/parser/type-extractors/csharp.js +584 -0
- package/dist/core/parser/type-extractors/csharp.js.map +1 -0
- package/dist/core/parser/type-extractors/dart.d.ts +15 -0
- package/dist/core/parser/type-extractors/dart.js +370 -0
- package/dist/core/parser/type-extractors/dart.js.map +1 -0
- package/dist/core/parser/type-extractors/go.d.ts +2 -0
- package/dist/core/parser/type-extractors/go.js +514 -0
- package/dist/core/parser/type-extractors/go.js.map +1 -0
- package/dist/core/parser/type-extractors/jvm.d.ts +3 -0
- package/dist/core/parser/type-extractors/jvm.js +857 -0
- package/dist/core/parser/type-extractors/jvm.js.map +1 -0
- package/dist/core/parser/type-extractors/php.d.ts +2 -0
- package/dist/core/parser/type-extractors/php.js +535 -0
- package/dist/core/parser/type-extractors/php.js.map +1 -0
- package/dist/core/parser/type-extractors/python.d.ts +2 -0
- package/dist/core/parser/type-extractors/python.js +475 -0
- package/dist/core/parser/type-extractors/python.js.map +1 -0
- package/dist/core/parser/type-extractors/ruby.d.ts +2 -0
- package/dist/core/parser/type-extractors/ruby.js +378 -0
- package/dist/core/parser/type-extractors/ruby.js.map +1 -0
- package/dist/core/parser/type-extractors/rust.d.ts +2 -0
- package/dist/core/parser/type-extractors/rust.js +516 -0
- package/dist/core/parser/type-extractors/rust.js.map +1 -0
- package/dist/core/parser/type-extractors/shared.d.ts +131 -0
- package/dist/core/parser/type-extractors/shared.js +797 -0
- package/dist/core/parser/type-extractors/shared.js.map +1 -0
- package/dist/core/parser/type-extractors/swift.d.ts +2 -0
- package/dist/core/parser/type-extractors/swift.js +485 -0
- package/dist/core/parser/type-extractors/swift.js.map +1 -0
- package/dist/core/parser/type-extractors/types.d.ts +172 -0
- package/dist/core/parser/type-extractors/types.js +2 -0
- package/dist/core/parser/type-extractors/types.js.map +1 -0
- package/dist/core/parser/type-extractors/typescript.d.ts +2 -0
- package/dist/core/parser/type-extractors/typescript.js +662 -0
- package/dist/core/parser/type-extractors/typescript.js.map +1 -0
- package/dist/core/parser/utils/ast-helpers.d.ts +73 -0
- package/dist/core/parser/utils/ast-helpers.js +415 -0
- package/dist/core/parser/utils/ast-helpers.js.map +1 -0
- package/dist/core/parser/utils/call-analysis.d.ts +75 -0
- package/dist/core/parser/utils/call-analysis.js +575 -0
- package/dist/core/parser/utils/call-analysis.js.map +1 -0
- package/dist/core/parser/utils/event-loop.d.ts +5 -0
- package/dist/core/parser/utils/event-loop.js +6 -0
- package/dist/core/parser/utils/event-loop.js.map +1 -0
- package/dist/core/parser/utils/method-props.d.ts +8 -0
- package/dist/core/parser/utils/method-props.js +39 -0
- package/dist/core/parser/utils/method-props.js.map +1 -0
- package/dist/core/parser/utils/verbose.d.ts +1 -0
- package/dist/core/parser/utils/verbose.js +8 -0
- package/dist/core/parser/utils/verbose.js.map +1 -0
- package/dist/core/parser/vue-sfc-extractor.d.ts +44 -0
- package/dist/core/parser/vue-sfc-extractor.js +95 -0
- package/dist/core/parser/vue-sfc-extractor.js.map +1 -0
- package/dist/core/parser/workers/parse-worker.d.ts +171 -0
- package/dist/core/parser/workers/parse-worker.js +1724 -0
- package/dist/core/parser/workers/parse-worker.js.map +1 -0
- package/dist/core/parser/workers/worker-pool.d.ts +16 -0
- package/dist/core/parser/workers/worker-pool.js +124 -0
- package/dist/core/parser/workers/worker-pool.js.map +1 -0
- package/dist/core/shared/graph-types.d.ts +61 -0
- package/dist/core/shared/graph-types.js +5 -0
- package/dist/core/shared/graph-types.js.map +1 -0
- package/dist/core/shared/index.d.ts +4 -0
- package/dist/core/shared/index.js +4 -0
- package/dist/core/shared/index.js.map +1 -0
- package/dist/core/shared/language-detection.d.ts +22 -0
- package/dist/core/shared/language-detection.js +137 -0
- package/dist/core/shared/language-detection.js.map +1 -0
- package/dist/core/shared/languages.d.ts +23 -0
- package/dist/core/shared/languages.js +25 -0
- package/dist/core/shared/languages.js.map +1 -0
- package/dist/core/shared/pipeline.d.ts +15 -0
- package/dist/core/shared/pipeline.js +5 -0
- package/dist/core/shared/pipeline.js.map +1 -0
- package/dist/core/tree-sitter/parser-loader.d.ts +5 -0
- package/dist/core/tree-sitter/parser-loader.js +71 -0
- package/dist/core/tree-sitter/parser-loader.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +132 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/hash.d.ts +1 -0
- package/dist/lib/hash.js +6 -0
- package/dist/lib/hash.js.map +1 -0
- package/dist/lib/naming.d.ts +12 -0
- package/dist/lib/naming.js +28 -0
- package/dist/lib/naming.js.map +1 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +4 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/mcp/server.d.ts +26 -0
- package/dist/mcp/server.js +282 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +37 -0
- package/dist/mcp/tools.js +650 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/query/bm25.d.ts +19 -0
- package/dist/query/bm25.js +60 -0
- package/dist/query/bm25.js.map +1 -0
- package/dist/query/graph-index.d.ts +40 -0
- package/dist/query/graph-index.js +178 -0
- package/dist/query/graph-index.js.map +1 -0
- package/dist/store/derived-index.d.ts +4 -0
- package/dist/store/derived-index.js +68 -0
- package/dist/store/derived-index.js.map +1 -0
- package/dist/store/meta.d.ts +1 -0
- package/dist/store/meta.js +3 -0
- package/dist/store/meta.js.map +1 -0
- package/dist/store/schema.d.ts +135 -0
- package/dist/store/schema.js +2 -0
- package/dist/store/schema.js.map +1 -0
- package/dist/store/store.d.ts +49 -0
- package/dist/store/store.js +254 -0
- package/dist/store/store.js.map +1 -0
- package/dist/types/pipeline.d.ts +12 -0
- package/dist/types/pipeline.js +2 -0
- package/dist/types/pipeline.js.map +1 -0
- package/package.json +69 -0
- package/skills/cotx-enrich/SKILL.md +59 -0
- package/vendor/leiden/index.cjs +355 -0
- package/vendor/leiden/utils.cjs +392 -0
|
@@ -0,0 +1,1405 @@
|
|
|
1
|
+
import { createKnowledgeGraph } from '../graph/graph.js';
|
|
2
|
+
import { processStructure } from './structure-processor.js';
|
|
3
|
+
import { processMarkdown } from './markdown-processor.js';
|
|
4
|
+
import { processParsing } from './parsing-processor.js';
|
|
5
|
+
import { processImports, processImportsFromExtracted, buildImportResolutionContext, } from './import-processor.js';
|
|
6
|
+
import { EMPTY_INDEX } from './import-resolvers/utils.js';
|
|
7
|
+
import { processCalls, processCallsFromExtracted, processAssignmentsFromExtracted, processRoutesFromExtracted, processNextjsFetchRoutes, extractFetchCallsFromFiles, seedCrossFileReceiverTypes, buildImportedReturnTypes, buildImportedRawReturnTypes, buildExportedTypeMapFromGraph, buildImplementorMap, mergeImplementorMaps, } from './call-processor.js';
|
|
8
|
+
import { nextjsFileToRouteURL, normalizeFetchURL } from './route-extractors/nextjs.js';
|
|
9
|
+
import { expoFileToRouteURL } from './route-extractors/expo.js';
|
|
10
|
+
import { phpFileToRouteURL } from './route-extractors/php.js';
|
|
11
|
+
import { extractResponseShapes, extractPHPResponseShapes, } from './route-extractors/response-shapes.js';
|
|
12
|
+
import { extractMiddlewareChain, extractNextjsMiddlewareConfig, compileMatcher, compiledMatcherMatchesRoute, } from './route-extractors/middleware.js';
|
|
13
|
+
import { generateId } from '../../lib/utils.js';
|
|
14
|
+
import { processHeritage, processHeritageFromExtracted, extractExtractedHeritageFromFiles, } from './heritage-processor.js';
|
|
15
|
+
import { computeMRO } from './mro-processor.js';
|
|
16
|
+
import { processCommunities } from './community-processor.js';
|
|
17
|
+
import { processProcesses } from './process-processor.js';
|
|
18
|
+
import { createResolutionContext } from './resolution-context.js';
|
|
19
|
+
import { createASTCache } from './ast-cache.js';
|
|
20
|
+
import { getLanguageFromFilename } from '../shared/index.js';
|
|
21
|
+
import { walkRepositoryPaths, readFileContents } from './filesystem-walker.js';
|
|
22
|
+
import { isLanguageAvailable } from '../tree-sitter/parser-loader.js';
|
|
23
|
+
import { providers, getProviderForFile } from './languages/index.js';
|
|
24
|
+
import { createWorkerPool } from './workers/worker-pool.js';
|
|
25
|
+
import fs from 'node:fs';
|
|
26
|
+
import path from 'node:path';
|
|
27
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
28
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
29
|
+
const EXPO_NAV_PATTERNS = [
|
|
30
|
+
/router\.(push|replace|navigate)\(\s*['"`]([^'"`]+)['"`]/g,
|
|
31
|
+
/<Link\s+[^>]*href=\s*['"`]([^'"`]+)['"`]/g,
|
|
32
|
+
];
|
|
33
|
+
/** Kahn's algorithm: returns files grouped by topological level.
|
|
34
|
+
* Files in the same level have no mutual dependencies — safe to process in parallel.
|
|
35
|
+
* Files in cycles are returned as a final group (no cross-cycle propagation). */
|
|
36
|
+
export function topologicalLevelSort(importMap) {
|
|
37
|
+
// Build in-degree map and reverse dependency map
|
|
38
|
+
const inDegree = new Map();
|
|
39
|
+
const reverseDeps = new Map();
|
|
40
|
+
for (const [file, deps] of importMap) {
|
|
41
|
+
if (!inDegree.has(file))
|
|
42
|
+
inDegree.set(file, 0);
|
|
43
|
+
for (const dep of deps) {
|
|
44
|
+
if (!inDegree.has(dep))
|
|
45
|
+
inDegree.set(dep, 0);
|
|
46
|
+
// file imports dep, so dep must be processed before file
|
|
47
|
+
// In Kahn's terms: dep → file (dep is a prerequisite of file)
|
|
48
|
+
inDegree.set(file, (inDegree.get(file) ?? 0) + 1);
|
|
49
|
+
let rev = reverseDeps.get(dep);
|
|
50
|
+
if (!rev) {
|
|
51
|
+
rev = [];
|
|
52
|
+
reverseDeps.set(dep, rev);
|
|
53
|
+
}
|
|
54
|
+
rev.push(file);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// BFS from zero-in-degree nodes, grouping by level
|
|
58
|
+
const levels = [];
|
|
59
|
+
let currentLevel = [...inDegree.entries()].filter(([, d]) => d === 0).map(([f]) => f);
|
|
60
|
+
while (currentLevel.length > 0) {
|
|
61
|
+
levels.push(currentLevel);
|
|
62
|
+
const nextLevel = [];
|
|
63
|
+
for (const file of currentLevel) {
|
|
64
|
+
for (const dependent of reverseDeps.get(file) ?? []) {
|
|
65
|
+
const newDeg = (inDegree.get(dependent) ?? 1) - 1;
|
|
66
|
+
inDegree.set(dependent, newDeg);
|
|
67
|
+
if (newDeg === 0)
|
|
68
|
+
nextLevel.push(dependent);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
currentLevel = nextLevel;
|
|
72
|
+
}
|
|
73
|
+
// Files still with positive in-degree are in cycles — add as final group
|
|
74
|
+
const cycleFiles = [...inDegree.entries()].filter(([, d]) => d > 0).map(([f]) => f);
|
|
75
|
+
if (cycleFiles.length > 0) {
|
|
76
|
+
levels.push(cycleFiles);
|
|
77
|
+
}
|
|
78
|
+
return { levels, cycleCount: cycleFiles.length };
|
|
79
|
+
}
|
|
80
|
+
/** Max bytes of source content to load per parse chunk. Each chunk's source +
|
|
81
|
+
* parsed ASTs + extracted records + worker serialization overhead all live in
|
|
82
|
+
* memory simultaneously, so this must be conservative. 20MB source ≈ 200-400MB
|
|
83
|
+
* peak working memory per chunk after parse expansion. */
|
|
84
|
+
const CHUNK_BYTE_BUDGET = 20 * 1024 * 1024; // 20MB
|
|
85
|
+
/** Max AST trees to keep in LRU cache */
|
|
86
|
+
const AST_CACHE_CAP = 50;
|
|
87
|
+
/** Minimum percentage of files that must benefit from cross-file seeding to justify the re-resolution pass. */
|
|
88
|
+
const CROSS_FILE_SKIP_THRESHOLD = 0.03;
|
|
89
|
+
/** Hard cap on files re-processed during cross-file propagation. */
|
|
90
|
+
const MAX_CROSS_FILE_REPROCESS = 2000;
|
|
91
|
+
/** Node labels that represent top-level importable symbols.
|
|
92
|
+
* Excludes Method, Property, Constructor (accessed via receiver, not directly imported),
|
|
93
|
+
* and structural labels (File, Folder, Package, Module, Project, etc.). */
|
|
94
|
+
const IMPORTABLE_SYMBOL_LABELS = new Set([
|
|
95
|
+
'Function',
|
|
96
|
+
'Class',
|
|
97
|
+
'Interface',
|
|
98
|
+
'Struct',
|
|
99
|
+
'Enum',
|
|
100
|
+
'Trait',
|
|
101
|
+
'TypeAlias',
|
|
102
|
+
'Const',
|
|
103
|
+
'Static',
|
|
104
|
+
'Record',
|
|
105
|
+
'Union',
|
|
106
|
+
'Typedef',
|
|
107
|
+
'Macro',
|
|
108
|
+
]);
|
|
109
|
+
/** Max synthetic bindings per importing file — prevents memory bloat for
|
|
110
|
+
* C/C++ files that include many large headers. */
|
|
111
|
+
const MAX_SYNTHETIC_BINDINGS_PER_FILE = 1000;
|
|
112
|
+
/** Pre-computed language sets derived from providers at module load. */
|
|
113
|
+
const WILDCARD_LANGUAGES = new Set(Object.values(providers)
|
|
114
|
+
.filter((p) => p.importSemantics === 'wildcard')
|
|
115
|
+
.map((p) => p.id));
|
|
116
|
+
const SYNTHESIS_LANGUAGES = new Set(Object.values(providers)
|
|
117
|
+
.filter((p) => p.importSemantics !== 'named')
|
|
118
|
+
.map((p) => p.id));
|
|
119
|
+
/** Check if a language uses wildcard (whole-module) import semantics.
|
|
120
|
+
* Derived from LanguageProvider.importSemantics — no hardcoded set needed. */
|
|
121
|
+
function isWildcardImportLanguage(lang) {
|
|
122
|
+
return WILDCARD_LANGUAGES.has(lang);
|
|
123
|
+
}
|
|
124
|
+
/** Check if a language needs synthesis before call resolution.
|
|
125
|
+
* True for wildcard-import languages AND namespace-import languages (Python). */
|
|
126
|
+
function needsSynthesis(lang) {
|
|
127
|
+
return SYNTHESIS_LANGUAGES.has(lang);
|
|
128
|
+
}
|
|
129
|
+
/** Synthesize namedImportMap entries for languages with whole-module imports.
|
|
130
|
+
* These languages (Go, Ruby, C/C++, Swift, Python) import all exported symbols from a
|
|
131
|
+
* file, not specific named symbols. After parsing, we know which symbols each file
|
|
132
|
+
* exports (via graph isExported), so we can expand ImportMap edges into per-symbol
|
|
133
|
+
* bindings that Phase 14 can use for cross-file type propagation. */
|
|
134
|
+
function synthesizeWildcardImportBindings(graph, ctx) {
|
|
135
|
+
// Pre-compute exported symbols per file from graph (single pass)
|
|
136
|
+
const exportedSymbolsByFile = new Map();
|
|
137
|
+
graph.forEachNode((node) => {
|
|
138
|
+
if (!node.properties?.isExported)
|
|
139
|
+
return;
|
|
140
|
+
if (!IMPORTABLE_SYMBOL_LABELS.has(node.label))
|
|
141
|
+
return;
|
|
142
|
+
const fp = node.properties.filePath;
|
|
143
|
+
const name = node.properties.name;
|
|
144
|
+
if (!fp || !name)
|
|
145
|
+
return;
|
|
146
|
+
let symbols = exportedSymbolsByFile.get(fp);
|
|
147
|
+
if (!symbols) {
|
|
148
|
+
symbols = [];
|
|
149
|
+
exportedSymbolsByFile.set(fp, symbols);
|
|
150
|
+
}
|
|
151
|
+
symbols.push({ name, filePath: fp });
|
|
152
|
+
});
|
|
153
|
+
if (exportedSymbolsByFile.size === 0)
|
|
154
|
+
return 0;
|
|
155
|
+
// Build a merged import map: ctx.importMap has file-based imports (Ruby, C/C++),
|
|
156
|
+
// but Go/C# package imports use graph IMPORTS edges + PackageMap instead.
|
|
157
|
+
// Collect graph-level IMPORTS edges for wildcard languages missing from ctx.importMap.
|
|
158
|
+
const FILE_PREFIX = 'File:';
|
|
159
|
+
const graphImports = new Map();
|
|
160
|
+
graph.forEachRelationship((rel) => {
|
|
161
|
+
if (rel.type !== 'IMPORTS')
|
|
162
|
+
return;
|
|
163
|
+
if (!rel.sourceId.startsWith(FILE_PREFIX) || !rel.targetId.startsWith(FILE_PREFIX))
|
|
164
|
+
return;
|
|
165
|
+
const srcFile = rel.sourceId.slice(FILE_PREFIX.length);
|
|
166
|
+
const tgtFile = rel.targetId.slice(FILE_PREFIX.length);
|
|
167
|
+
const lang = getLanguageFromFilename(srcFile);
|
|
168
|
+
if (!lang || !isWildcardImportLanguage(lang))
|
|
169
|
+
return;
|
|
170
|
+
// Only add if not already in ctx.importMap (avoid duplicates)
|
|
171
|
+
if (ctx.importMap.get(srcFile)?.has(tgtFile))
|
|
172
|
+
return;
|
|
173
|
+
let set = graphImports.get(srcFile);
|
|
174
|
+
if (!set) {
|
|
175
|
+
set = new Set();
|
|
176
|
+
graphImports.set(srcFile, set);
|
|
177
|
+
}
|
|
178
|
+
set.add(tgtFile);
|
|
179
|
+
});
|
|
180
|
+
let totalSynthesized = 0;
|
|
181
|
+
// Helper: synthesize bindings for a file given its imported files
|
|
182
|
+
const synthesizeForFile = (filePath, importedFiles) => {
|
|
183
|
+
let fileBindings = ctx.namedImportMap.get(filePath);
|
|
184
|
+
let fileCount = fileBindings?.size ?? 0;
|
|
185
|
+
for (const importedFile of importedFiles) {
|
|
186
|
+
const exportedSymbols = exportedSymbolsByFile.get(importedFile);
|
|
187
|
+
if (!exportedSymbols)
|
|
188
|
+
continue;
|
|
189
|
+
for (const sym of exportedSymbols) {
|
|
190
|
+
if (fileCount >= MAX_SYNTHETIC_BINDINGS_PER_FILE)
|
|
191
|
+
return;
|
|
192
|
+
if (fileBindings?.has(sym.name))
|
|
193
|
+
continue;
|
|
194
|
+
if (!fileBindings) {
|
|
195
|
+
fileBindings = new Map();
|
|
196
|
+
ctx.namedImportMap.set(filePath, fileBindings);
|
|
197
|
+
}
|
|
198
|
+
fileBindings.set(sym.name, {
|
|
199
|
+
sourcePath: importedFile,
|
|
200
|
+
exportedName: sym.name,
|
|
201
|
+
});
|
|
202
|
+
fileCount++;
|
|
203
|
+
totalSynthesized++;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
// Process files from ctx.importMap (Ruby, C/C++, Swift file-based imports)
|
|
208
|
+
for (const [filePath, importedFiles] of ctx.importMap) {
|
|
209
|
+
const lang = getLanguageFromFilename(filePath);
|
|
210
|
+
if (!lang || !isWildcardImportLanguage(lang))
|
|
211
|
+
continue;
|
|
212
|
+
synthesizeForFile(filePath, importedFiles);
|
|
213
|
+
}
|
|
214
|
+
// Process files from graph IMPORTS edges (Go and other wildcard-import languages)
|
|
215
|
+
for (const [filePath, importedFiles] of graphImports) {
|
|
216
|
+
synthesizeForFile(filePath, importedFiles);
|
|
217
|
+
}
|
|
218
|
+
// Build module alias map for Python namespace imports.
|
|
219
|
+
// `import models` in app.py → ctx.moduleAliasMap['app.py']['models'] = 'models.py'
|
|
220
|
+
// Enables `models.User()` to resolve to models.py:User without ambiguous symbol expansion.
|
|
221
|
+
const buildPythonModuleAliasForFile = (callerFile, importedFiles) => {
|
|
222
|
+
let aliasMap = ctx.moduleAliasMap.get(callerFile);
|
|
223
|
+
for (const importedFile of importedFiles) {
|
|
224
|
+
// Derive the module alias from the imported filename stem (e.g. "models.py" → "models")
|
|
225
|
+
const lastSlash = importedFile.lastIndexOf('/');
|
|
226
|
+
const base = lastSlash >= 0 ? importedFile.slice(lastSlash + 1) : importedFile;
|
|
227
|
+
const dot = base.lastIndexOf('.');
|
|
228
|
+
const stem = dot >= 0 ? base.slice(0, dot) : base;
|
|
229
|
+
if (!stem)
|
|
230
|
+
continue;
|
|
231
|
+
if (!aliasMap) {
|
|
232
|
+
aliasMap = new Map();
|
|
233
|
+
ctx.moduleAliasMap.set(callerFile, aliasMap);
|
|
234
|
+
}
|
|
235
|
+
aliasMap.set(stem, importedFile);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
for (const [filePath, importedFiles] of ctx.importMap) {
|
|
239
|
+
const provider = getProviderForFile(filePath);
|
|
240
|
+
if (!provider || provider.importSemantics !== 'namespace')
|
|
241
|
+
continue;
|
|
242
|
+
buildPythonModuleAliasForFile(filePath, importedFiles);
|
|
243
|
+
}
|
|
244
|
+
return totalSynthesized;
|
|
245
|
+
}
|
|
246
|
+
/** Phase 14: Cross-file binding propagation.
|
|
247
|
+
* Seeds downstream files with resolved type bindings from upstream exports.
|
|
248
|
+
* Files are processed in topological import order so upstream bindings are
|
|
249
|
+
* available when downstream files are re-resolved. */
|
|
250
|
+
async function runCrossFileBindingPropagation(graph, ctx, exportedTypeMap, allPaths, totalFiles, repoPath, pipelineStart, onProgress) {
|
|
251
|
+
// For the worker path, buildTypeEnv runs inside workers without SymbolTable,
|
|
252
|
+
// so exported bindings must be collected from graph + SymbolTable in main thread.
|
|
253
|
+
if (exportedTypeMap.size === 0 && graph.nodeCount > 0) {
|
|
254
|
+
const graphExports = buildExportedTypeMapFromGraph(graph, ctx.symbols);
|
|
255
|
+
for (const [fp, exports] of graphExports)
|
|
256
|
+
exportedTypeMap.set(fp, exports);
|
|
257
|
+
}
|
|
258
|
+
if (exportedTypeMap.size === 0 || ctx.namedImportMap.size === 0)
|
|
259
|
+
return;
|
|
260
|
+
const allPathSet = new Set(allPaths);
|
|
261
|
+
const { levels, cycleCount } = topologicalLevelSort(ctx.importMap);
|
|
262
|
+
// Cycle diagnostic: only log when actual cycles detected (cycleCount from Kahn's BFS)
|
|
263
|
+
if (isDev && cycleCount > 0) {
|
|
264
|
+
console.log(`🔄 ${cycleCount} files in import cycles (skipped for cross-file propagation)`);
|
|
265
|
+
}
|
|
266
|
+
// Quick count of files with cross-file binding gaps (early exit once threshold exceeded)
|
|
267
|
+
let filesWithGaps = 0;
|
|
268
|
+
const gapThreshold = Math.max(1, Math.ceil(totalFiles * CROSS_FILE_SKIP_THRESHOLD));
|
|
269
|
+
outer: for (const level of levels) {
|
|
270
|
+
for (const filePath of level) {
|
|
271
|
+
const imports = ctx.namedImportMap.get(filePath);
|
|
272
|
+
if (!imports)
|
|
273
|
+
continue;
|
|
274
|
+
for (const [, binding] of imports) {
|
|
275
|
+
const upstream = exportedTypeMap.get(binding.sourcePath);
|
|
276
|
+
if (upstream?.has(binding.exportedName)) {
|
|
277
|
+
filesWithGaps++;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
const def = ctx.symbols.lookupExactFull(binding.sourcePath, binding.exportedName);
|
|
281
|
+
if (def?.returnType) {
|
|
282
|
+
filesWithGaps++;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (filesWithGaps >= gapThreshold)
|
|
287
|
+
break outer;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const gapRatio = totalFiles > 0 ? filesWithGaps / totalFiles : 0;
|
|
291
|
+
if (gapRatio < CROSS_FILE_SKIP_THRESHOLD && filesWithGaps < gapThreshold) {
|
|
292
|
+
if (isDev) {
|
|
293
|
+
console.log(`⏭️ Cross-file re-resolution skipped (${filesWithGaps}/${totalFiles} files, ${(gapRatio * 100).toFixed(1)}% < ${CROSS_FILE_SKIP_THRESHOLD * 100}% threshold)`);
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
onProgress({
|
|
298
|
+
phase: 'parsing',
|
|
299
|
+
percent: 82,
|
|
300
|
+
message: `Cross-file type propagation (${filesWithGaps}+ files)...`,
|
|
301
|
+
stats: { filesProcessed: totalFiles, totalFiles, nodesCreated: graph.nodeCount },
|
|
302
|
+
});
|
|
303
|
+
let crossFileResolved = 0;
|
|
304
|
+
const crossFileStart = Date.now();
|
|
305
|
+
const astCache = createASTCache(AST_CACHE_CAP);
|
|
306
|
+
for (const level of levels) {
|
|
307
|
+
const levelCandidates = [];
|
|
308
|
+
for (const filePath of level) {
|
|
309
|
+
if (crossFileResolved + levelCandidates.length >= MAX_CROSS_FILE_REPROCESS)
|
|
310
|
+
break;
|
|
311
|
+
const imports = ctx.namedImportMap.get(filePath);
|
|
312
|
+
if (!imports)
|
|
313
|
+
continue;
|
|
314
|
+
const seeded = new Map();
|
|
315
|
+
for (const [localName, binding] of imports) {
|
|
316
|
+
const upstream = exportedTypeMap.get(binding.sourcePath);
|
|
317
|
+
if (upstream) {
|
|
318
|
+
const type = upstream.get(binding.exportedName);
|
|
319
|
+
if (type)
|
|
320
|
+
seeded.set(localName, type);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const importedReturns = buildImportedReturnTypes(filePath, ctx.namedImportMap, ctx.symbols);
|
|
324
|
+
const importedRawReturns = buildImportedRawReturnTypes(filePath, ctx.namedImportMap, ctx.symbols);
|
|
325
|
+
if (seeded.size === 0 && importedReturns.size === 0)
|
|
326
|
+
continue;
|
|
327
|
+
if (!allPathSet.has(filePath))
|
|
328
|
+
continue;
|
|
329
|
+
const lang = getLanguageFromFilename(filePath);
|
|
330
|
+
if (!lang || !isLanguageAvailable(lang))
|
|
331
|
+
continue;
|
|
332
|
+
levelCandidates.push({ filePath, seeded, importedReturns, importedRawReturns });
|
|
333
|
+
}
|
|
334
|
+
if (levelCandidates.length === 0)
|
|
335
|
+
continue;
|
|
336
|
+
const levelPaths = levelCandidates.map((c) => c.filePath);
|
|
337
|
+
const contentMap = await readFileContents(repoPath, levelPaths);
|
|
338
|
+
for (const { filePath, seeded, importedReturns, importedRawReturns } of levelCandidates) {
|
|
339
|
+
const content = contentMap.get(filePath);
|
|
340
|
+
if (!content)
|
|
341
|
+
continue;
|
|
342
|
+
const reFile = [{ path: filePath, content }];
|
|
343
|
+
const bindings = new Map();
|
|
344
|
+
if (seeded.size > 0)
|
|
345
|
+
bindings.set(filePath, seeded);
|
|
346
|
+
const importedReturnTypesMap = new Map();
|
|
347
|
+
if (importedReturns.size > 0) {
|
|
348
|
+
importedReturnTypesMap.set(filePath, importedReturns);
|
|
349
|
+
}
|
|
350
|
+
const importedRawReturnTypesMap = new Map();
|
|
351
|
+
if (importedRawReturns.size > 0) {
|
|
352
|
+
importedRawReturnTypesMap.set(filePath, importedRawReturns);
|
|
353
|
+
}
|
|
354
|
+
await processCalls(graph, reFile, astCache, ctx, undefined, exportedTypeMap, bindings.size > 0 ? bindings : undefined, importedReturnTypesMap.size > 0 ? importedReturnTypesMap : undefined, importedRawReturnTypesMap.size > 0 ? importedRawReturnTypesMap : undefined);
|
|
355
|
+
crossFileResolved++;
|
|
356
|
+
}
|
|
357
|
+
if (crossFileResolved >= MAX_CROSS_FILE_REPROCESS) {
|
|
358
|
+
if (isDev)
|
|
359
|
+
console.log(`⚠️ Cross-file re-resolution capped at ${MAX_CROSS_FILE_REPROCESS} files`);
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
astCache.clear();
|
|
364
|
+
if (isDev) {
|
|
365
|
+
const elapsed = Date.now() - crossFileStart;
|
|
366
|
+
const totalElapsed = Date.now() - pipelineStart;
|
|
367
|
+
const reResolutionPct = totalElapsed > 0 ? ((elapsed / totalElapsed) * 100).toFixed(1) : '0';
|
|
368
|
+
console.log(`🔗 Cross-file re-resolution: ${crossFileResolved} candidates re-processed` +
|
|
369
|
+
` in ${elapsed}ms (${reResolutionPct}% of total ingestion time so far)`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Phase 1+2: Scan repository paths, build file/folder structure, process markdown.
|
|
374
|
+
*
|
|
375
|
+
* @reads repoPath (filesystem)
|
|
376
|
+
* @writes graph (File, Folder nodes + CONTAINS edges; Markdown sections + cross-links)
|
|
377
|
+
*/
|
|
378
|
+
async function runScanAndStructure(repoPath, graph, onProgress) {
|
|
379
|
+
// ── Phase 1: Scan paths only (no content read) ─────────────────────
|
|
380
|
+
onProgress({
|
|
381
|
+
phase: 'extracting',
|
|
382
|
+
percent: 0,
|
|
383
|
+
message: 'Scanning repository...',
|
|
384
|
+
});
|
|
385
|
+
const scannedFiles = await walkRepositoryPaths(repoPath, (current, total, filePath) => {
|
|
386
|
+
const scanProgress = Math.round((current / total) * 15);
|
|
387
|
+
onProgress({
|
|
388
|
+
phase: 'extracting',
|
|
389
|
+
percent: scanProgress,
|
|
390
|
+
message: 'Scanning repository...',
|
|
391
|
+
detail: filePath,
|
|
392
|
+
stats: { filesProcessed: current, totalFiles: total, nodesCreated: graph.nodeCount },
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
const totalFiles = scannedFiles.length;
|
|
396
|
+
onProgress({
|
|
397
|
+
phase: 'extracting',
|
|
398
|
+
percent: 15,
|
|
399
|
+
message: 'Repository scanned successfully',
|
|
400
|
+
stats: { filesProcessed: totalFiles, totalFiles, nodesCreated: graph.nodeCount },
|
|
401
|
+
});
|
|
402
|
+
// ── Phase 2: Structure (paths only — no content needed) ────────────
|
|
403
|
+
onProgress({
|
|
404
|
+
phase: 'structure',
|
|
405
|
+
percent: 15,
|
|
406
|
+
message: 'Analyzing project structure...',
|
|
407
|
+
stats: { filesProcessed: 0, totalFiles, nodesCreated: graph.nodeCount },
|
|
408
|
+
});
|
|
409
|
+
const allPaths = scannedFiles.map((f) => f.path);
|
|
410
|
+
processStructure(graph, allPaths);
|
|
411
|
+
onProgress({
|
|
412
|
+
phase: 'structure',
|
|
413
|
+
percent: 20,
|
|
414
|
+
message: 'Project structure analyzed',
|
|
415
|
+
stats: { filesProcessed: totalFiles, totalFiles, nodesCreated: graph.nodeCount },
|
|
416
|
+
});
|
|
417
|
+
// ── Custom (non-tree-sitter) processors ─────────────────────────────
|
|
418
|
+
// Each custom processor follows the pattern in markdown-processor.ts:
|
|
419
|
+
// 1. Export a process function: (graph, files, allPathSet) => result
|
|
420
|
+
// 2. Export a file detection function: (path) => boolean
|
|
421
|
+
// 3. Filter files by extension, write nodes/edges directly to graph
|
|
422
|
+
// To add a new language: create a new processor file, import it here,
|
|
423
|
+
// and add a filter-read-call-log block following the pattern below.
|
|
424
|
+
// ── Phase 2.5: Markdown processing (headings + cross-links) ────────
|
|
425
|
+
const mdScanned = scannedFiles.filter((f) => f.path.endsWith('.md') || f.path.endsWith('.mdx'));
|
|
426
|
+
if (mdScanned.length > 0) {
|
|
427
|
+
const mdContents = await readFileContents(repoPath, mdScanned.map((f) => f.path));
|
|
428
|
+
const mdFiles = mdScanned
|
|
429
|
+
.filter((f) => mdContents.has(f.path))
|
|
430
|
+
.map((f) => ({ path: f.path, content: mdContents.get(f.path) }));
|
|
431
|
+
const allPathSet = new Set(allPaths);
|
|
432
|
+
const mdResult = processMarkdown(graph, mdFiles, allPathSet);
|
|
433
|
+
if (isDev) {
|
|
434
|
+
console.log(` Markdown: ${mdResult.sections} sections, ${mdResult.links} cross-links from ${mdFiles.length} files`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
// COBOL processing removed (not included in cotx-engine fork)
|
|
438
|
+
return { scannedFiles, allPaths, totalFiles };
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Phase 3+4: Chunked parse + resolve loop.
|
|
442
|
+
*
|
|
443
|
+
* Reads source in byte-budget chunks (~20MB each). For each chunk:
|
|
444
|
+
* 1. Parse via worker pool (or sequential fallback)
|
|
445
|
+
* 2. Resolve imports from extracted data
|
|
446
|
+
* 3. Synthesize wildcard import bindings (Go/Ruby/C++/Swift/Python)
|
|
447
|
+
* 4. Resolve heritage + routes per chunk; defer worker CALLS until all chunks
|
|
448
|
+
* have contributed heritage so interface-dispatch implementor map is complete
|
|
449
|
+
* 5. Collect TypeEnv bindings for cross-file propagation
|
|
450
|
+
*
|
|
451
|
+
* State accumulated across chunks: symbolTable, importMap, namedImportMap,
|
|
452
|
+
* moduleAliasMap (all via ResolutionContext), exportedTypeMap, workerTypeEnvBindings.
|
|
453
|
+
*
|
|
454
|
+
* @reads graph (structure nodes from Phase 1+2)
|
|
455
|
+
* @reads allPaths (from scan phase)
|
|
456
|
+
* @writes graph (Symbol nodes, IMPORTS/CALLS/EXTENDS/IMPLEMENTS/ACCESSES edges)
|
|
457
|
+
* @writes ctx.symbolTable, ctx.importMap, ctx.namedImportMap, ctx.moduleAliasMap
|
|
458
|
+
*
|
|
459
|
+
* Follow-up from PR review: MethodExtractor (FieldExtractor parity) and optional
|
|
460
|
+
* METHOD_IMPLEMENTS graph edges to make dispatch queryable without an in-memory map.
|
|
461
|
+
*/
|
|
462
|
+
async function runChunkedParseAndResolve(graph, ctx, scannedFiles, allPaths, totalFiles, repoPath, pipelineStart, onProgress) {
|
|
463
|
+
const symbolTable = ctx.symbols;
|
|
464
|
+
const parseableScanned = scannedFiles.filter((f) => {
|
|
465
|
+
const lang = getLanguageFromFilename(f.path);
|
|
466
|
+
return lang && isLanguageAvailable(lang);
|
|
467
|
+
});
|
|
468
|
+
// Warn about files skipped due to unavailable parsers
|
|
469
|
+
const skippedByLang = new Map();
|
|
470
|
+
for (const f of scannedFiles) {
|
|
471
|
+
const lang = getLanguageFromFilename(f.path);
|
|
472
|
+
if (lang && !isLanguageAvailable(lang)) {
|
|
473
|
+
skippedByLang.set(lang, (skippedByLang.get(lang) || 0) + 1);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
for (const [lang, count] of skippedByLang) {
|
|
477
|
+
console.warn(`Skipping ${count} ${lang} file(s) — ${lang} parser not available (native binding may not have built). Try: npm rebuild tree-sitter-${lang}`);
|
|
478
|
+
}
|
|
479
|
+
const totalParseable = parseableScanned.length;
|
|
480
|
+
if (totalParseable === 0) {
|
|
481
|
+
onProgress({
|
|
482
|
+
phase: 'parsing',
|
|
483
|
+
percent: 82,
|
|
484
|
+
message: 'No parseable files found — skipping parsing phase',
|
|
485
|
+
stats: { filesProcessed: 0, totalFiles: 0, nodesCreated: graph.nodeCount },
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
// Build byte-budget chunks
|
|
489
|
+
const chunks = [];
|
|
490
|
+
let currentChunk = [];
|
|
491
|
+
let currentBytes = 0;
|
|
492
|
+
for (const file of parseableScanned) {
|
|
493
|
+
if (currentChunk.length > 0 && currentBytes + file.size > CHUNK_BYTE_BUDGET) {
|
|
494
|
+
chunks.push(currentChunk);
|
|
495
|
+
currentChunk = [];
|
|
496
|
+
currentBytes = 0;
|
|
497
|
+
}
|
|
498
|
+
currentChunk.push(file.path);
|
|
499
|
+
currentBytes += file.size;
|
|
500
|
+
}
|
|
501
|
+
if (currentChunk.length > 0)
|
|
502
|
+
chunks.push(currentChunk);
|
|
503
|
+
const numChunks = chunks.length;
|
|
504
|
+
if (isDev) {
|
|
505
|
+
const totalMB = parseableScanned.reduce((s, f) => s + f.size, 0) / (1024 * 1024);
|
|
506
|
+
console.log(`📂 Scan: ${totalFiles} paths, ${totalParseable} parseable (${totalMB.toFixed(0)}MB), ${numChunks} chunks @ ${CHUNK_BYTE_BUDGET / (1024 * 1024)}MB budget`);
|
|
507
|
+
}
|
|
508
|
+
onProgress({
|
|
509
|
+
phase: 'parsing',
|
|
510
|
+
percent: 20,
|
|
511
|
+
message: `Parsing ${totalParseable} files in ${numChunks} chunk${numChunks !== 1 ? 's' : ''}...`,
|
|
512
|
+
stats: { filesProcessed: 0, totalFiles: totalParseable, nodesCreated: graph.nodeCount },
|
|
513
|
+
});
|
|
514
|
+
// Don't spawn workers for tiny repos — overhead exceeds benefit
|
|
515
|
+
const MIN_FILES_FOR_WORKERS = 15;
|
|
516
|
+
const MIN_BYTES_FOR_WORKERS = 512 * 1024;
|
|
517
|
+
const totalBytes = parseableScanned.reduce((s, f) => s + f.size, 0);
|
|
518
|
+
// Create worker pool once, reuse across chunks
|
|
519
|
+
let workerPool;
|
|
520
|
+
if (totalParseable >= MIN_FILES_FOR_WORKERS || totalBytes >= MIN_BYTES_FOR_WORKERS) {
|
|
521
|
+
try {
|
|
522
|
+
let workerUrl = new URL('./workers/parse-worker.js', import.meta.url);
|
|
523
|
+
// When running under vitest, import.meta.url points to src/ where no .js exists.
|
|
524
|
+
// Fall back to the compiled dist/ worker so the pool can spawn real worker threads.
|
|
525
|
+
const thisDir = fileURLToPath(new URL('.', import.meta.url));
|
|
526
|
+
if (!fs.existsSync(fileURLToPath(workerUrl))) {
|
|
527
|
+
const distWorker = path.resolve(thisDir, '..', '..', '..', 'dist', 'core', 'ingestion', 'workers', 'parse-worker.js');
|
|
528
|
+
if (fs.existsSync(distWorker)) {
|
|
529
|
+
workerUrl = pathToFileURL(distWorker);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
workerPool = createWorkerPool(workerUrl);
|
|
533
|
+
}
|
|
534
|
+
catch (err) {
|
|
535
|
+
if (isDev)
|
|
536
|
+
console.warn('Worker pool creation failed, using sequential fallback:', err.message);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
let filesParsedSoFar = 0;
|
|
540
|
+
// AST cache sized for one chunk (sequential fallback uses it for import/call/heritage)
|
|
541
|
+
const maxChunkFiles = chunks.reduce((max, c) => Math.max(max, c.length), 0);
|
|
542
|
+
let astCache = createASTCache(maxChunkFiles);
|
|
543
|
+
// Build import resolution context once — suffix index, file lists, resolve cache.
|
|
544
|
+
// Reused across all chunks to avoid rebuilding O(files × path_depth) structures.
|
|
545
|
+
const importCtx = buildImportResolutionContext(allPaths);
|
|
546
|
+
const allPathObjects = allPaths.map((p) => ({ path: p }));
|
|
547
|
+
// Worker path: parse + imports + heritage per chunk; buffer extracted calls and
|
|
548
|
+
// run processCallsFromExtracted once after all chunks so interface-dispatch uses a
|
|
549
|
+
// complete implementor map (heritage from every chunk). Costs peak RAM for buffered
|
|
550
|
+
// call rows vs streaming resolution per chunk.
|
|
551
|
+
const sequentialChunkPaths = [];
|
|
552
|
+
// Pre-compute which chunks need synthesis — O(1) lookup per chunk.
|
|
553
|
+
const chunkNeedsSynthesis = chunks.map((paths) => paths.some((p) => {
|
|
554
|
+
const lang = getLanguageFromFilename(p);
|
|
555
|
+
return lang != null && needsSynthesis(lang);
|
|
556
|
+
}));
|
|
557
|
+
// Phase 14: Collect exported type bindings for cross-file propagation
|
|
558
|
+
const exportedTypeMap = new Map();
|
|
559
|
+
// Accumulate file-scope TypeEnv bindings from workers (closes worker/sequential quality gap)
|
|
560
|
+
const workerTypeEnvBindings = [];
|
|
561
|
+
// Accumulate fetch() calls from workers for Next.js route matching
|
|
562
|
+
const allFetchCalls = [];
|
|
563
|
+
// Accumulate framework-extracted routes (Laravel, etc.) for Route node creation
|
|
564
|
+
const allExtractedRoutes = [];
|
|
565
|
+
// Accumulate decorator-based routes (@Get, @Post, @app.route, etc.)
|
|
566
|
+
const allDecoratorRoutes = [];
|
|
567
|
+
// Accumulate MCP/RPC tool definitions (@mcp.tool(), @app.tool(), etc.)
|
|
568
|
+
const allToolDefs = [];
|
|
569
|
+
const allORMQueries = [];
|
|
570
|
+
const deferredWorkerCalls = [];
|
|
571
|
+
const deferredWorkerHeritage = [];
|
|
572
|
+
const deferredConstructorBindings = [];
|
|
573
|
+
const deferredAssignments = [];
|
|
574
|
+
try {
|
|
575
|
+
for (let chunkIdx = 0; chunkIdx < numChunks; chunkIdx++) {
|
|
576
|
+
const chunkPaths = chunks[chunkIdx];
|
|
577
|
+
// Read content for this chunk only
|
|
578
|
+
const chunkContents = await readFileContents(repoPath, chunkPaths);
|
|
579
|
+
const chunkFiles = chunkPaths
|
|
580
|
+
.filter((p) => chunkContents.has(p))
|
|
581
|
+
.map((p) => ({ path: p, content: chunkContents.get(p) }));
|
|
582
|
+
// Parse this chunk (workers or sequential fallback)
|
|
583
|
+
const chunkWorkerData = await processParsing(graph, chunkFiles, symbolTable, astCache, (current, _total, filePath) => {
|
|
584
|
+
const globalCurrent = filesParsedSoFar + current;
|
|
585
|
+
const parsingProgress = 20 + (globalCurrent / totalParseable) * 62;
|
|
586
|
+
onProgress({
|
|
587
|
+
phase: 'parsing',
|
|
588
|
+
percent: Math.round(parsingProgress),
|
|
589
|
+
message: `Parsing chunk ${chunkIdx + 1}/${numChunks}...`,
|
|
590
|
+
detail: filePath,
|
|
591
|
+
stats: {
|
|
592
|
+
filesProcessed: globalCurrent,
|
|
593
|
+
totalFiles: totalParseable,
|
|
594
|
+
nodesCreated: graph.nodeCount,
|
|
595
|
+
},
|
|
596
|
+
});
|
|
597
|
+
}, workerPool);
|
|
598
|
+
const chunkBasePercent = 20 + (filesParsedSoFar / totalParseable) * 62;
|
|
599
|
+
if (chunkWorkerData) {
|
|
600
|
+
// Imports
|
|
601
|
+
await processImportsFromExtracted(graph, allPathObjects, chunkWorkerData.imports, ctx, (current, total) => {
|
|
602
|
+
onProgress({
|
|
603
|
+
phase: 'parsing',
|
|
604
|
+
percent: Math.round(chunkBasePercent),
|
|
605
|
+
message: `Resolving imports (chunk ${chunkIdx + 1}/${numChunks})...`,
|
|
606
|
+
detail: `${current}/${total} files`,
|
|
607
|
+
stats: {
|
|
608
|
+
filesProcessed: filesParsedSoFar,
|
|
609
|
+
totalFiles: totalParseable,
|
|
610
|
+
nodesCreated: graph.nodeCount,
|
|
611
|
+
},
|
|
612
|
+
});
|
|
613
|
+
}, repoPath, importCtx);
|
|
614
|
+
// ── Wildcard-import synthesis (Ruby / C/C++ / Swift / Go) + Python module aliases ─
|
|
615
|
+
// Synthesize namedImportMap entries for wildcard-import languages and build
|
|
616
|
+
// moduleAliasMap for Python namespace imports. Must run after imports are resolved
|
|
617
|
+
// (importMap is populated) but BEFORE call resolution.
|
|
618
|
+
if (chunkNeedsSynthesis[chunkIdx])
|
|
619
|
+
synthesizeWildcardImportBindings(graph, ctx);
|
|
620
|
+
// Phase 14 E1: Seed cross-file receiver types from ExportedTypeMap
|
|
621
|
+
// before call resolution — eliminates re-parse for single-hop imported receivers.
|
|
622
|
+
// NOTE: In the worker path, exportedTypeMap is empty during chunk processing
|
|
623
|
+
// (populated later in runCrossFileBindingPropagation). This block is latent —
|
|
624
|
+
// it activates only if incremental export collection is added per-chunk.
|
|
625
|
+
if (exportedTypeMap.size > 0 && ctx.namedImportMap.size > 0) {
|
|
626
|
+
const { enrichedCount } = seedCrossFileReceiverTypes(chunkWorkerData.calls, ctx.namedImportMap, exportedTypeMap);
|
|
627
|
+
if (isDev && enrichedCount > 0) {
|
|
628
|
+
console.log(`🔗 E1: Seeded ${enrichedCount} cross-file receiver types (chunk ${chunkIdx + 1})`);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
deferredWorkerCalls.push(...chunkWorkerData.calls);
|
|
632
|
+
deferredWorkerHeritage.push(...chunkWorkerData.heritage);
|
|
633
|
+
deferredConstructorBindings.push(...chunkWorkerData.constructorBindings);
|
|
634
|
+
if (chunkWorkerData.assignments?.length) {
|
|
635
|
+
deferredAssignments.push(...chunkWorkerData.assignments);
|
|
636
|
+
}
|
|
637
|
+
// Heritage + Routes — calls deferred until all chunks have contributed heritage
|
|
638
|
+
// (complete implementor map for interface dispatch).
|
|
639
|
+
await Promise.all([
|
|
640
|
+
processHeritageFromExtracted(graph, chunkWorkerData.heritage, ctx, (current, total) => {
|
|
641
|
+
onProgress({
|
|
642
|
+
phase: 'parsing',
|
|
643
|
+
percent: Math.round(chunkBasePercent),
|
|
644
|
+
message: `Resolving heritage (chunk ${chunkIdx + 1}/${numChunks})...`,
|
|
645
|
+
detail: `${current}/${total} records`,
|
|
646
|
+
stats: {
|
|
647
|
+
filesProcessed: filesParsedSoFar,
|
|
648
|
+
totalFiles: totalParseable,
|
|
649
|
+
nodesCreated: graph.nodeCount,
|
|
650
|
+
},
|
|
651
|
+
});
|
|
652
|
+
}),
|
|
653
|
+
processRoutesFromExtracted(graph, chunkWorkerData.routes ?? [], ctx, (current, total) => {
|
|
654
|
+
onProgress({
|
|
655
|
+
phase: 'parsing',
|
|
656
|
+
percent: Math.round(chunkBasePercent),
|
|
657
|
+
message: `Resolving routes (chunk ${chunkIdx + 1}/${numChunks})...`,
|
|
658
|
+
detail: `${current}/${total} routes`,
|
|
659
|
+
stats: {
|
|
660
|
+
filesProcessed: filesParsedSoFar,
|
|
661
|
+
totalFiles: totalParseable,
|
|
662
|
+
nodesCreated: graph.nodeCount,
|
|
663
|
+
},
|
|
664
|
+
});
|
|
665
|
+
}),
|
|
666
|
+
]);
|
|
667
|
+
// Collect TypeEnv file-scope bindings for exported type enrichment
|
|
668
|
+
if (chunkWorkerData.typeEnvBindings?.length) {
|
|
669
|
+
workerTypeEnvBindings.push(...chunkWorkerData.typeEnvBindings);
|
|
670
|
+
}
|
|
671
|
+
// Collect fetch() calls for Next.js route matching
|
|
672
|
+
if (chunkWorkerData.fetchCalls?.length) {
|
|
673
|
+
allFetchCalls.push(...chunkWorkerData.fetchCalls);
|
|
674
|
+
}
|
|
675
|
+
if (chunkWorkerData.routes?.length) {
|
|
676
|
+
allExtractedRoutes.push(...chunkWorkerData.routes);
|
|
677
|
+
}
|
|
678
|
+
if (chunkWorkerData.decoratorRoutes?.length) {
|
|
679
|
+
allDecoratorRoutes.push(...chunkWorkerData.decoratorRoutes);
|
|
680
|
+
}
|
|
681
|
+
if (chunkWorkerData.toolDefs?.length) {
|
|
682
|
+
allToolDefs.push(...chunkWorkerData.toolDefs);
|
|
683
|
+
}
|
|
684
|
+
if (chunkWorkerData.ormQueries?.length) {
|
|
685
|
+
allORMQueries.push(...chunkWorkerData.ormQueries);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
await processImports(graph, chunkFiles, astCache, ctx, undefined, repoPath, allPaths);
|
|
690
|
+
sequentialChunkPaths.push(chunkPaths);
|
|
691
|
+
}
|
|
692
|
+
filesParsedSoFar += chunkFiles.length;
|
|
693
|
+
// Clear AST cache between chunks to free memory
|
|
694
|
+
astCache.clear();
|
|
695
|
+
// chunkContents + chunkFiles + chunkWorkerData go out of scope → GC reclaims
|
|
696
|
+
}
|
|
697
|
+
// Complete implementor map from all worker heritage, then resolve CALLS once (interface dispatch).
|
|
698
|
+
const fullWorkerImplementorMap = deferredWorkerHeritage.length > 0
|
|
699
|
+
? buildImplementorMap(deferredWorkerHeritage, ctx)
|
|
700
|
+
: new Map();
|
|
701
|
+
if (deferredWorkerCalls.length > 0) {
|
|
702
|
+
await processCallsFromExtracted(graph, deferredWorkerCalls, ctx, (current, total) => {
|
|
703
|
+
onProgress({
|
|
704
|
+
phase: 'parsing',
|
|
705
|
+
percent: 82,
|
|
706
|
+
message: 'Resolving calls (all chunks)...',
|
|
707
|
+
detail: `${current}/${total} files`,
|
|
708
|
+
stats: {
|
|
709
|
+
filesProcessed: filesParsedSoFar,
|
|
710
|
+
totalFiles: totalParseable,
|
|
711
|
+
nodesCreated: graph.nodeCount,
|
|
712
|
+
},
|
|
713
|
+
});
|
|
714
|
+
}, deferredConstructorBindings.length > 0 ? deferredConstructorBindings : undefined, fullWorkerImplementorMap);
|
|
715
|
+
}
|
|
716
|
+
if (deferredAssignments.length > 0) {
|
|
717
|
+
processAssignmentsFromExtracted(graph, deferredAssignments, ctx, deferredConstructorBindings.length > 0 ? deferredConstructorBindings : undefined);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
finally {
|
|
721
|
+
await workerPool?.terminate();
|
|
722
|
+
}
|
|
723
|
+
// Sequential fallback chunks: re-read source for call/heritage resolution
|
|
724
|
+
// Synthesize wildcard import bindings once after ALL imports are processed,
|
|
725
|
+
// before any call resolution — same rationale as the worker-path inline synthesis.
|
|
726
|
+
if (sequentialChunkPaths.length > 0)
|
|
727
|
+
synthesizeWildcardImportBindings(graph, ctx);
|
|
728
|
+
// Merge implementor-map deltas per chunk (O(heritage per chunk)), not O(|edges|) graph scans
|
|
729
|
+
// per chunk — mirrors worker-path deferred heritage without re-iterating all relationships.
|
|
730
|
+
const sequentialImplementorMap = new Map();
|
|
731
|
+
for (const chunkPaths of sequentialChunkPaths) {
|
|
732
|
+
const chunkContents = await readFileContents(repoPath, chunkPaths);
|
|
733
|
+
const chunkFiles = chunkPaths
|
|
734
|
+
.filter((p) => chunkContents.has(p))
|
|
735
|
+
.map((p) => ({ path: p, content: chunkContents.get(p) }));
|
|
736
|
+
astCache = createASTCache(chunkFiles.length);
|
|
737
|
+
const sequentialHeritage = await extractExtractedHeritageFromFiles(chunkFiles, astCache);
|
|
738
|
+
mergeImplementorMaps(sequentialImplementorMap, buildImplementorMap(sequentialHeritage, ctx));
|
|
739
|
+
const rubyHeritage = await processCalls(graph, chunkFiles, astCache, ctx, undefined, exportedTypeMap, undefined, undefined, undefined, sequentialImplementorMap);
|
|
740
|
+
await processHeritage(graph, chunkFiles, astCache, ctx);
|
|
741
|
+
if (rubyHeritage.length > 0) {
|
|
742
|
+
await processHeritageFromExtracted(graph, rubyHeritage, ctx);
|
|
743
|
+
}
|
|
744
|
+
// Extract fetch() calls for Next.js route matching (sequential path)
|
|
745
|
+
const chunkFetchCalls = await extractFetchCallsFromFiles(chunkFiles, astCache);
|
|
746
|
+
if (chunkFetchCalls.length > 0) {
|
|
747
|
+
allFetchCalls.push(...chunkFetchCalls);
|
|
748
|
+
}
|
|
749
|
+
// Extract ORM queries (sequential path)
|
|
750
|
+
for (const f of chunkFiles) {
|
|
751
|
+
extractORMQueriesInline(f.path, f.content, allORMQueries);
|
|
752
|
+
}
|
|
753
|
+
astCache.clear();
|
|
754
|
+
}
|
|
755
|
+
// Log resolution cache stats
|
|
756
|
+
if (isDev) {
|
|
757
|
+
const rcStats = ctx.getStats();
|
|
758
|
+
const total = rcStats.cacheHits + rcStats.cacheMisses;
|
|
759
|
+
const hitRate = total > 0 ? ((rcStats.cacheHits / total) * 100).toFixed(1) : '0';
|
|
760
|
+
console.log(`🔍 Resolution cache: ${rcStats.cacheHits} hits, ${rcStats.cacheMisses} misses (${hitRate}% hit rate)`);
|
|
761
|
+
}
|
|
762
|
+
// ── Worker path quality enrichment: merge TypeEnv file-scope bindings into ExportedTypeMap ──
|
|
763
|
+
// Workers return file-scope bindings from their TypeEnv fixpoint (includes inferred types
|
|
764
|
+
// like `const config = getConfig()` → Config). Filter by graph isExported to match
|
|
765
|
+
// the sequential path's collectExportedBindings behavior.
|
|
766
|
+
if (workerTypeEnvBindings.length > 0) {
|
|
767
|
+
let enriched = 0;
|
|
768
|
+
for (const { filePath, bindings } of workerTypeEnvBindings) {
|
|
769
|
+
for (const [name, type] of bindings) {
|
|
770
|
+
// Verify the symbol is exported via graph node
|
|
771
|
+
const nodeId = `Function:${filePath}:${name}`;
|
|
772
|
+
const varNodeId = `Variable:${filePath}:${name}`;
|
|
773
|
+
const constNodeId = `Const:${filePath}:${name}`;
|
|
774
|
+
const node = graph.getNode(nodeId) ?? graph.getNode(varNodeId) ?? graph.getNode(constNodeId);
|
|
775
|
+
if (!node?.properties?.isExported)
|
|
776
|
+
continue;
|
|
777
|
+
let fileExports = exportedTypeMap.get(filePath);
|
|
778
|
+
if (!fileExports) {
|
|
779
|
+
fileExports = new Map();
|
|
780
|
+
exportedTypeMap.set(filePath, fileExports);
|
|
781
|
+
}
|
|
782
|
+
// Don't overwrite existing entries (Tier 0 from SymbolTable is authoritative)
|
|
783
|
+
if (!fileExports.has(name)) {
|
|
784
|
+
fileExports.set(name, type);
|
|
785
|
+
enriched++;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (isDev && enriched > 0) {
|
|
790
|
+
console.log(`🔗 Worker TypeEnv enrichment: ${enriched} fixpoint-inferred exports added to ExportedTypeMap`);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
// ── Final synthesis pass for whole-module-import languages ──
|
|
794
|
+
// Per-chunk synthesis (above) already ran incrementally. This final pass ensures
|
|
795
|
+
// any remaining files whose imports were not covered inline are also synthesized,
|
|
796
|
+
// and that Phase 14 type propagation has complete namedImportMap data.
|
|
797
|
+
const synthesized = synthesizeWildcardImportBindings(graph, ctx);
|
|
798
|
+
if (isDev && synthesized > 0) {
|
|
799
|
+
console.log(`🔗 Synthesized ${synthesized} additional wildcard import bindings (Go/Ruby/C++/Swift/Python)`);
|
|
800
|
+
}
|
|
801
|
+
// Free import resolution context — suffix index + resolve cache no longer needed
|
|
802
|
+
// (allPathObjects and importCtx hold ~94MB+ for large repos)
|
|
803
|
+
allPathObjects.length = 0;
|
|
804
|
+
importCtx.resolveCache.clear();
|
|
805
|
+
importCtx.index = EMPTY_INDEX; // Release suffix index memory (~30MB for large repos)
|
|
806
|
+
importCtx.normalizedFileList = [];
|
|
807
|
+
return {
|
|
808
|
+
exportedTypeMap,
|
|
809
|
+
allFetchCalls,
|
|
810
|
+
allExtractedRoutes,
|
|
811
|
+
allDecoratorRoutes,
|
|
812
|
+
allToolDefs,
|
|
813
|
+
allORMQueries,
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Post-parse graph analysis: MRO, community detection, process extraction.
|
|
818
|
+
*
|
|
819
|
+
* @reads graph (all nodes and relationships from parse + resolve phases)
|
|
820
|
+
* @writes graph (Community nodes, Process nodes, MEMBER_OF edges, STEP_IN_PROCESS edges, METHOD_OVERRIDES edges)
|
|
821
|
+
*/
|
|
822
|
+
async function runGraphAnalysisPhases(graph, totalFiles, onProgress, routeRegistry, toolDefs) {
|
|
823
|
+
// ── Phase 4.5: Method Resolution Order ──────────────────────────────
|
|
824
|
+
onProgress({
|
|
825
|
+
phase: 'parsing',
|
|
826
|
+
percent: 81,
|
|
827
|
+
message: 'Computing method resolution order...',
|
|
828
|
+
stats: { filesProcessed: totalFiles, totalFiles, nodesCreated: graph.nodeCount },
|
|
829
|
+
});
|
|
830
|
+
const mroResult = computeMRO(graph);
|
|
831
|
+
if (isDev && mroResult.entries.length > 0) {
|
|
832
|
+
console.log(`🔀 MRO: ${mroResult.entries.length} classes analyzed, ${mroResult.ambiguityCount} ambiguities, ${mroResult.overrideEdges} METHOD_OVERRIDES, ${mroResult.methodImplementsEdges} METHOD_IMPLEMENTS`);
|
|
833
|
+
}
|
|
834
|
+
// ── Phase 5: Communities ───────────────────────────────────────────
|
|
835
|
+
onProgress({
|
|
836
|
+
phase: 'communities',
|
|
837
|
+
percent: 82,
|
|
838
|
+
message: 'Detecting code communities...',
|
|
839
|
+
stats: { filesProcessed: totalFiles, totalFiles, nodesCreated: graph.nodeCount },
|
|
840
|
+
});
|
|
841
|
+
const communityResult = await processCommunities(graph, (message, progress) => {
|
|
842
|
+
const communityProgress = 82 + progress * 0.1;
|
|
843
|
+
onProgress({
|
|
844
|
+
phase: 'communities',
|
|
845
|
+
percent: Math.round(communityProgress),
|
|
846
|
+
message,
|
|
847
|
+
stats: { filesProcessed: totalFiles, totalFiles, nodesCreated: graph.nodeCount },
|
|
848
|
+
});
|
|
849
|
+
});
|
|
850
|
+
if (isDev) {
|
|
851
|
+
console.log(`🏘️ Community detection: ${communityResult.stats.totalCommunities} communities found (modularity: ${communityResult.stats.modularity.toFixed(3)})`);
|
|
852
|
+
}
|
|
853
|
+
communityResult.communities.forEach((comm) => {
|
|
854
|
+
graph.addNode({
|
|
855
|
+
id: comm.id,
|
|
856
|
+
label: 'Community',
|
|
857
|
+
properties: {
|
|
858
|
+
name: comm.label,
|
|
859
|
+
filePath: '',
|
|
860
|
+
heuristicLabel: comm.heuristicLabel,
|
|
861
|
+
cohesion: comm.cohesion,
|
|
862
|
+
symbolCount: comm.symbolCount,
|
|
863
|
+
},
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
communityResult.memberships.forEach((membership) => {
|
|
867
|
+
graph.addRelationship({
|
|
868
|
+
id: `${membership.nodeId}_member_of_${membership.communityId}`,
|
|
869
|
+
type: 'MEMBER_OF',
|
|
870
|
+
sourceId: membership.nodeId,
|
|
871
|
+
targetId: membership.communityId,
|
|
872
|
+
confidence: 1.0,
|
|
873
|
+
reason: 'leiden-algorithm',
|
|
874
|
+
});
|
|
875
|
+
});
|
|
876
|
+
// ── Phase 6: Processes ─────────────────────────────────────────────
|
|
877
|
+
onProgress({
|
|
878
|
+
phase: 'processes',
|
|
879
|
+
percent: 94,
|
|
880
|
+
message: 'Detecting execution flows...',
|
|
881
|
+
stats: { filesProcessed: totalFiles, totalFiles, nodesCreated: graph.nodeCount },
|
|
882
|
+
});
|
|
883
|
+
let symbolCount = 0;
|
|
884
|
+
graph.forEachNode((n) => {
|
|
885
|
+
if (n.label !== 'File')
|
|
886
|
+
symbolCount++;
|
|
887
|
+
});
|
|
888
|
+
const dynamicMaxProcesses = Math.max(20, Math.min(300, Math.round(symbolCount / 10)));
|
|
889
|
+
const processResult = await processProcesses(graph, communityResult.memberships, (message, progress) => {
|
|
890
|
+
const processProgress = 94 + progress * 0.05;
|
|
891
|
+
onProgress({
|
|
892
|
+
phase: 'processes',
|
|
893
|
+
percent: Math.round(processProgress),
|
|
894
|
+
message,
|
|
895
|
+
stats: { filesProcessed: totalFiles, totalFiles, nodesCreated: graph.nodeCount },
|
|
896
|
+
});
|
|
897
|
+
}, { maxProcesses: dynamicMaxProcesses, minSteps: 3 });
|
|
898
|
+
if (isDev) {
|
|
899
|
+
console.log(`🔄 Process detection: ${processResult.stats.totalProcesses} processes found (${processResult.stats.crossCommunityCount} cross-community)`);
|
|
900
|
+
}
|
|
901
|
+
processResult.processes.forEach((proc) => {
|
|
902
|
+
graph.addNode({
|
|
903
|
+
id: proc.id,
|
|
904
|
+
label: 'Process',
|
|
905
|
+
properties: {
|
|
906
|
+
name: proc.label,
|
|
907
|
+
filePath: '',
|
|
908
|
+
heuristicLabel: proc.heuristicLabel,
|
|
909
|
+
processType: proc.processType,
|
|
910
|
+
stepCount: proc.stepCount,
|
|
911
|
+
communities: proc.communities,
|
|
912
|
+
entryPointId: proc.entryPointId,
|
|
913
|
+
terminalId: proc.terminalId,
|
|
914
|
+
},
|
|
915
|
+
});
|
|
916
|
+
});
|
|
917
|
+
processResult.steps.forEach((step) => {
|
|
918
|
+
graph.addRelationship({
|
|
919
|
+
id: `${step.nodeId}_step_${step.step}_${step.processId}`,
|
|
920
|
+
type: 'STEP_IN_PROCESS',
|
|
921
|
+
sourceId: step.nodeId,
|
|
922
|
+
targetId: step.processId,
|
|
923
|
+
confidence: 1.0,
|
|
924
|
+
reason: 'trace-detection',
|
|
925
|
+
step: step.step,
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
// Link Route and Tool nodes to Processes via reverse index (file → node id)
|
|
929
|
+
if ((routeRegistry?.size ?? 0) > 0 || (toolDefs?.length ?? 0) > 0) {
|
|
930
|
+
// Reverse indexes: file → all route URLs / tool names (handles multi-route files)
|
|
931
|
+
const routesByFile = new Map();
|
|
932
|
+
if (routeRegistry) {
|
|
933
|
+
for (const [url, entry] of routeRegistry) {
|
|
934
|
+
let list = routesByFile.get(entry.filePath);
|
|
935
|
+
if (!list) {
|
|
936
|
+
list = [];
|
|
937
|
+
routesByFile.set(entry.filePath, list);
|
|
938
|
+
}
|
|
939
|
+
list.push(url);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
const toolsByFile = new Map();
|
|
943
|
+
if (toolDefs) {
|
|
944
|
+
for (const td of toolDefs) {
|
|
945
|
+
let list = toolsByFile.get(td.filePath);
|
|
946
|
+
if (!list) {
|
|
947
|
+
list = [];
|
|
948
|
+
toolsByFile.set(td.filePath, list);
|
|
949
|
+
}
|
|
950
|
+
list.push(td.name);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
let linked = 0;
|
|
954
|
+
for (const proc of processResult.processes) {
|
|
955
|
+
if (!proc.entryPointId)
|
|
956
|
+
continue;
|
|
957
|
+
const entryNode = graph.getNode(proc.entryPointId);
|
|
958
|
+
if (!entryNode)
|
|
959
|
+
continue;
|
|
960
|
+
const entryFile = entryNode.properties.filePath;
|
|
961
|
+
if (!entryFile)
|
|
962
|
+
continue;
|
|
963
|
+
const routeURLs = routesByFile.get(entryFile);
|
|
964
|
+
if (routeURLs) {
|
|
965
|
+
for (const routeURL of routeURLs) {
|
|
966
|
+
const routeNodeId = generateId('Route', routeURL);
|
|
967
|
+
graph.addRelationship({
|
|
968
|
+
id: generateId('ENTRY_POINT_OF', `${routeNodeId}->${proc.id}`),
|
|
969
|
+
sourceId: routeNodeId,
|
|
970
|
+
targetId: proc.id,
|
|
971
|
+
type: 'ENTRY_POINT_OF',
|
|
972
|
+
confidence: 0.85,
|
|
973
|
+
reason: 'route-handler-entry-point',
|
|
974
|
+
});
|
|
975
|
+
linked++;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
const toolNames = toolsByFile.get(entryFile);
|
|
979
|
+
if (toolNames) {
|
|
980
|
+
for (const toolName of toolNames) {
|
|
981
|
+
const toolNodeId = generateId('Tool', toolName);
|
|
982
|
+
graph.addRelationship({
|
|
983
|
+
id: generateId('ENTRY_POINT_OF', `${toolNodeId}->${proc.id}`),
|
|
984
|
+
sourceId: toolNodeId,
|
|
985
|
+
targetId: proc.id,
|
|
986
|
+
type: 'ENTRY_POINT_OF',
|
|
987
|
+
confidence: 0.85,
|
|
988
|
+
reason: 'tool-handler-entry-point',
|
|
989
|
+
});
|
|
990
|
+
linked++;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
if (isDev && linked > 0) {
|
|
995
|
+
console.log(`🔗 Linked ${linked} Route/Tool nodes to execution flows`);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return { communityResult, processResult };
|
|
999
|
+
}
|
|
1000
|
+
// ── Pipeline orchestrator ─────────────────────────────────────────────────
|
|
1001
|
+
export const runPipelineFromRepo = async (repoPath, onProgress, options) => {
|
|
1002
|
+
const graph = createKnowledgeGraph();
|
|
1003
|
+
const ctx = createResolutionContext();
|
|
1004
|
+
const pipelineStart = Date.now();
|
|
1005
|
+
try {
|
|
1006
|
+
// Phase 1+2: Scan paths, build structure, process markdown
|
|
1007
|
+
const { scannedFiles, allPaths, totalFiles } = await runScanAndStructure(repoPath, graph, onProgress);
|
|
1008
|
+
// Phase 3+4: Chunked parse + resolve (imports, calls, heritage, routes)
|
|
1009
|
+
const { exportedTypeMap, allFetchCalls, allExtractedRoutes, allDecoratorRoutes, allToolDefs, allORMQueries, } = await runChunkedParseAndResolve(graph, ctx, scannedFiles, allPaths, totalFiles, repoPath, pipelineStart, onProgress);
|
|
1010
|
+
const routeRegistry = new Map();
|
|
1011
|
+
// Detect Expo Router app/ roots vs Next.js app/ roots (monorepo-safe).
|
|
1012
|
+
const expoAppRoots = new Set();
|
|
1013
|
+
const nextjsAppRoots = new Set();
|
|
1014
|
+
const expoAppPaths = new Set();
|
|
1015
|
+
for (const p of allPaths) {
|
|
1016
|
+
const norm = p.replace(/\\/g, '/');
|
|
1017
|
+
const appIdx = norm.lastIndexOf('app/');
|
|
1018
|
+
if (appIdx < 0)
|
|
1019
|
+
continue;
|
|
1020
|
+
const root = norm.slice(0, appIdx + 4);
|
|
1021
|
+
if (/\/_layout\.(tsx?|jsx?)$/.test(norm))
|
|
1022
|
+
expoAppRoots.add(root);
|
|
1023
|
+
if (/\/page\.(tsx?|jsx?)$/.test(norm))
|
|
1024
|
+
nextjsAppRoots.add(root);
|
|
1025
|
+
}
|
|
1026
|
+
for (const root of nextjsAppRoots)
|
|
1027
|
+
expoAppRoots.delete(root);
|
|
1028
|
+
if (expoAppRoots.size > 0) {
|
|
1029
|
+
for (const p of allPaths) {
|
|
1030
|
+
const norm = p.replace(/\\/g, '/');
|
|
1031
|
+
const appIdx = norm.lastIndexOf('app/');
|
|
1032
|
+
if (appIdx >= 0 && expoAppRoots.has(norm.slice(0, appIdx + 4)))
|
|
1033
|
+
expoAppPaths.add(p);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
for (const p of allPaths) {
|
|
1037
|
+
if (expoAppPaths.has(p)) {
|
|
1038
|
+
const expoURL = expoFileToRouteURL(p);
|
|
1039
|
+
if (expoURL && !routeRegistry.has(expoURL)) {
|
|
1040
|
+
routeRegistry.set(expoURL, { filePath: p, source: 'expo-filesystem-route' });
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
const nextjsURL = nextjsFileToRouteURL(p);
|
|
1045
|
+
if (nextjsURL && !routeRegistry.has(nextjsURL)) {
|
|
1046
|
+
routeRegistry.set(nextjsURL, { filePath: p, source: 'nextjs-filesystem-route' });
|
|
1047
|
+
continue;
|
|
1048
|
+
}
|
|
1049
|
+
if (p.endsWith('.php')) {
|
|
1050
|
+
const phpURL = phpFileToRouteURL(p);
|
|
1051
|
+
if (phpURL && !routeRegistry.has(phpURL)) {
|
|
1052
|
+
routeRegistry.set(phpURL, { filePath: p, source: 'php-file-route' });
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
const ensureSlash = (path) => (path.startsWith('/') ? path : '/' + path);
|
|
1057
|
+
let duplicateRoutes = 0;
|
|
1058
|
+
const addRoute = (url, entry) => {
|
|
1059
|
+
if (routeRegistry.has(url)) {
|
|
1060
|
+
duplicateRoutes++;
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
routeRegistry.set(url, entry);
|
|
1064
|
+
};
|
|
1065
|
+
for (const route of allExtractedRoutes) {
|
|
1066
|
+
if (!route.routePath)
|
|
1067
|
+
continue;
|
|
1068
|
+
addRoute(ensureSlash(route.routePath), {
|
|
1069
|
+
filePath: route.filePath,
|
|
1070
|
+
source: 'framework-route',
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
for (const dr of allDecoratorRoutes) {
|
|
1074
|
+
addRoute(ensureSlash(dr.routePath), {
|
|
1075
|
+
filePath: dr.filePath,
|
|
1076
|
+
source: `decorator-${dr.decoratorName}`,
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
let handlerContents;
|
|
1080
|
+
if (routeRegistry.size > 0) {
|
|
1081
|
+
const handlerPaths = [...routeRegistry.values()].map((e) => e.filePath);
|
|
1082
|
+
handlerContents = await readFileContents(repoPath, handlerPaths);
|
|
1083
|
+
for (const [routeURL, entry] of routeRegistry) {
|
|
1084
|
+
const { filePath: handlerPath, source: routeSource } = entry;
|
|
1085
|
+
const content = handlerContents.get(handlerPath);
|
|
1086
|
+
const { responseKeys, errorKeys } = content
|
|
1087
|
+
? handlerPath.endsWith('.php')
|
|
1088
|
+
? extractPHPResponseShapes(content)
|
|
1089
|
+
: extractResponseShapes(content)
|
|
1090
|
+
: { responseKeys: undefined, errorKeys: undefined };
|
|
1091
|
+
const mwResult = content ? extractMiddlewareChain(content) : undefined;
|
|
1092
|
+
const middleware = mwResult?.chain;
|
|
1093
|
+
const routeNodeId = generateId('Route', routeURL);
|
|
1094
|
+
graph.addNode({
|
|
1095
|
+
id: routeNodeId,
|
|
1096
|
+
label: 'Route',
|
|
1097
|
+
properties: {
|
|
1098
|
+
name: routeURL,
|
|
1099
|
+
filePath: handlerPath,
|
|
1100
|
+
...(responseKeys ? { responseKeys } : {}),
|
|
1101
|
+
...(errorKeys ? { errorKeys } : {}),
|
|
1102
|
+
...(middleware && middleware.length > 0 ? { middleware } : {}),
|
|
1103
|
+
},
|
|
1104
|
+
});
|
|
1105
|
+
const handlerFileId = generateId('File', handlerPath);
|
|
1106
|
+
graph.addRelationship({
|
|
1107
|
+
id: generateId('HANDLES_ROUTE', `${handlerFileId}->${routeNodeId}`),
|
|
1108
|
+
sourceId: handlerFileId,
|
|
1109
|
+
targetId: routeNodeId,
|
|
1110
|
+
type: 'HANDLES_ROUTE',
|
|
1111
|
+
confidence: 1.0,
|
|
1112
|
+
reason: routeSource,
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
if (isDev) {
|
|
1116
|
+
console.log(`🗺️ Route registry: ${routeRegistry.size} routes${duplicateRoutes > 0 ? ` (${duplicateRoutes} duplicate URLs skipped)` : ''}`);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
// ── Phase 3.5b: Link Next.js project-level middleware.ts to routes ──
|
|
1120
|
+
if (routeRegistry.size > 0) {
|
|
1121
|
+
const middlewareCandidates = allPaths.filter((p) => p === 'middleware.ts' ||
|
|
1122
|
+
p === 'middleware.js' ||
|
|
1123
|
+
p === 'middleware.tsx' ||
|
|
1124
|
+
p === 'middleware.jsx' ||
|
|
1125
|
+
p === 'src/middleware.ts' ||
|
|
1126
|
+
p === 'src/middleware.js' ||
|
|
1127
|
+
p === 'src/middleware.tsx' ||
|
|
1128
|
+
p === 'src/middleware.jsx');
|
|
1129
|
+
if (middlewareCandidates.length > 0) {
|
|
1130
|
+
const mwContents = await readFileContents(repoPath, middlewareCandidates);
|
|
1131
|
+
for (const [mwPath, mwContent] of mwContents) {
|
|
1132
|
+
const config = extractNextjsMiddlewareConfig(mwContent);
|
|
1133
|
+
if (!config)
|
|
1134
|
+
continue;
|
|
1135
|
+
const mwLabel = config.wrappedFunctions.length > 0 ? config.wrappedFunctions : [config.exportedName];
|
|
1136
|
+
// Pre-compile matchers once per middleware file
|
|
1137
|
+
const compiled = config.matchers
|
|
1138
|
+
.map(compileMatcher)
|
|
1139
|
+
.filter((m) => m !== null);
|
|
1140
|
+
let linkedCount = 0;
|
|
1141
|
+
for (const [routeURL] of routeRegistry) {
|
|
1142
|
+
const matches = compiled.length === 0 ||
|
|
1143
|
+
compiled.some((cm) => compiledMatcherMatchesRoute(cm, routeURL));
|
|
1144
|
+
if (!matches)
|
|
1145
|
+
continue;
|
|
1146
|
+
const routeNodeId = generateId('Route', routeURL);
|
|
1147
|
+
const existing = graph.getNode(routeNodeId);
|
|
1148
|
+
if (!existing)
|
|
1149
|
+
continue;
|
|
1150
|
+
const currentMw = existing.properties.middleware ?? [];
|
|
1151
|
+
// Prepend project-level middleware (runs before handler-level wrappers)
|
|
1152
|
+
existing.properties.middleware = [
|
|
1153
|
+
...mwLabel,
|
|
1154
|
+
...currentMw.filter((m) => !mwLabel.includes(m)),
|
|
1155
|
+
];
|
|
1156
|
+
linkedCount++;
|
|
1157
|
+
}
|
|
1158
|
+
if (isDev && linkedCount > 0) {
|
|
1159
|
+
console.log(`🛡️ Linked ${mwPath} middleware [${mwLabel.join(', ')}] to ${linkedCount} routes`);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
// Scan HTML/PHP/template files for <form action="/path"> and AJAX url patterns
|
|
1165
|
+
// Scan HTML/template files for <form action="/path"> and AJAX url patterns
|
|
1166
|
+
// Skip .php — already parsed by tree-sitter with http_client/fetch queries
|
|
1167
|
+
const htmlCandidates = allPaths.filter((p) => p.endsWith('.html') ||
|
|
1168
|
+
p.endsWith('.htm') ||
|
|
1169
|
+
p.endsWith('.ejs') ||
|
|
1170
|
+
p.endsWith('.hbs') ||
|
|
1171
|
+
p.endsWith('.blade.php'));
|
|
1172
|
+
if (htmlCandidates.length > 0 && routeRegistry.size > 0) {
|
|
1173
|
+
const htmlContents = await readFileContents(repoPath, htmlCandidates);
|
|
1174
|
+
const htmlPatterns = [/action=["']([^"']+)["']/g, /url:\s*["']([^"']+)["']/g];
|
|
1175
|
+
for (const [filePath, content] of htmlContents) {
|
|
1176
|
+
for (const pattern of htmlPatterns) {
|
|
1177
|
+
pattern.lastIndex = 0;
|
|
1178
|
+
let match;
|
|
1179
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
1180
|
+
const normalized = normalizeFetchURL(match[1]);
|
|
1181
|
+
if (normalized) {
|
|
1182
|
+
allFetchCalls.push({ filePath, fetchURL: normalized, lineNumber: 0 });
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
// ── Phase 3.5c: Extract Expo Router navigation patterns ──
|
|
1189
|
+
if (expoAppPaths.size > 0 && routeRegistry.size > 0) {
|
|
1190
|
+
const unreadExpoPaths = [...expoAppPaths].filter((p) => !handlerContents?.has(p));
|
|
1191
|
+
const extraContents = unreadExpoPaths.length > 0
|
|
1192
|
+
? await readFileContents(repoPath, unreadExpoPaths)
|
|
1193
|
+
: new Map();
|
|
1194
|
+
const allExpoContents = new Map([...(handlerContents ?? new Map()), ...extraContents]);
|
|
1195
|
+
for (const [filePath, content] of allExpoContents) {
|
|
1196
|
+
if (!expoAppPaths.has(filePath))
|
|
1197
|
+
continue;
|
|
1198
|
+
for (const pattern of EXPO_NAV_PATTERNS) {
|
|
1199
|
+
pattern.lastIndex = 0;
|
|
1200
|
+
let match;
|
|
1201
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
1202
|
+
const url = match[2] ?? match[1];
|
|
1203
|
+
if (url && url.startsWith('/')) {
|
|
1204
|
+
allFetchCalls.push({ filePath, fetchURL: url, lineNumber: 0 });
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
if (routeRegistry.size > 0 && allFetchCalls.length > 0) {
|
|
1211
|
+
const routeURLToFile = new Map();
|
|
1212
|
+
for (const [url, entry] of routeRegistry)
|
|
1213
|
+
routeURLToFile.set(url, entry.filePath);
|
|
1214
|
+
// Read consumer file contents so we can extract property access patterns
|
|
1215
|
+
const consumerPaths = [...new Set(allFetchCalls.map((c) => c.filePath))];
|
|
1216
|
+
const consumerContents = await readFileContents(repoPath, consumerPaths);
|
|
1217
|
+
processNextjsFetchRoutes(graph, allFetchCalls, routeURLToFile, consumerContents);
|
|
1218
|
+
if (isDev) {
|
|
1219
|
+
console.log(`🔗 Processed ${allFetchCalls.length} fetch() calls against ${routeRegistry.size} routes`);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
// ── Phase 3.6: Tool Detection (MCP/RPC) ──────────────────────────
|
|
1223
|
+
const toolDefs = [];
|
|
1224
|
+
const seenToolNames = new Set();
|
|
1225
|
+
for (const td of allToolDefs) {
|
|
1226
|
+
if (seenToolNames.has(td.toolName))
|
|
1227
|
+
continue;
|
|
1228
|
+
seenToolNames.add(td.toolName);
|
|
1229
|
+
toolDefs.push({ name: td.toolName, filePath: td.filePath, description: td.description });
|
|
1230
|
+
}
|
|
1231
|
+
// TS tool definition arrays — require inputSchema nearby to distinguish from config objects
|
|
1232
|
+
const toolCandidatePaths = allPaths.filter((p) => (p.endsWith('.ts') || p.endsWith('.js')) &&
|
|
1233
|
+
p.toLowerCase().includes('tool') &&
|
|
1234
|
+
!p.includes('node_modules') &&
|
|
1235
|
+
!p.includes('test') &&
|
|
1236
|
+
!p.includes('__'));
|
|
1237
|
+
if (toolCandidatePaths.length > 0) {
|
|
1238
|
+
const toolContents = await readFileContents(repoPath, toolCandidatePaths);
|
|
1239
|
+
for (const [filePath, content] of toolContents) {
|
|
1240
|
+
// Only scan files that contain 'inputSchema' — this is the MCP tool signature
|
|
1241
|
+
if (!content.includes('inputSchema'))
|
|
1242
|
+
continue;
|
|
1243
|
+
const toolPattern = /name:\s*['"](\w+)['"]\s*,\s*\n?\s*description:\s*[`'"]([\s\S]*?)[`'"]/g;
|
|
1244
|
+
let match;
|
|
1245
|
+
while ((match = toolPattern.exec(content)) !== null) {
|
|
1246
|
+
const name = match[1];
|
|
1247
|
+
if (seenToolNames.has(name))
|
|
1248
|
+
continue;
|
|
1249
|
+
seenToolNames.add(name);
|
|
1250
|
+
toolDefs.push({
|
|
1251
|
+
name,
|
|
1252
|
+
filePath,
|
|
1253
|
+
description: match[2].slice(0, 200).replace(/\n/g, ' ').trim(),
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
// Create Tool nodes and HANDLES_TOOL edges
|
|
1259
|
+
if (toolDefs.length > 0) {
|
|
1260
|
+
for (const td of toolDefs) {
|
|
1261
|
+
const toolNodeId = generateId('Tool', td.name);
|
|
1262
|
+
graph.addNode({
|
|
1263
|
+
id: toolNodeId,
|
|
1264
|
+
label: 'Tool',
|
|
1265
|
+
properties: { name: td.name, filePath: td.filePath, description: td.description },
|
|
1266
|
+
});
|
|
1267
|
+
const handlerFileId = generateId('File', td.filePath);
|
|
1268
|
+
graph.addRelationship({
|
|
1269
|
+
id: generateId('HANDLES_TOOL', `${handlerFileId}->${toolNodeId}`),
|
|
1270
|
+
sourceId: handlerFileId,
|
|
1271
|
+
targetId: toolNodeId,
|
|
1272
|
+
type: 'HANDLES_TOOL',
|
|
1273
|
+
confidence: 1.0,
|
|
1274
|
+
reason: 'tool-definition',
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
if (isDev) {
|
|
1278
|
+
console.log(`🔧 Tool registry: ${toolDefs.length} tools detected`);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
// ── Phase 3.7: ORM Dataflow Detection (Prisma + Supabase) ──────────
|
|
1282
|
+
if (allORMQueries.length > 0) {
|
|
1283
|
+
processORMQueries(graph, allORMQueries, isDev);
|
|
1284
|
+
}
|
|
1285
|
+
// ── Phase 14: Cross-file binding propagation (topological level sort) ──
|
|
1286
|
+
await runCrossFileBindingPropagation(graph, ctx, exportedTypeMap, allPaths, totalFiles, repoPath, pipelineStart, onProgress);
|
|
1287
|
+
// Post-parse graph analysis (MRO, communities, processes)
|
|
1288
|
+
let communityResult;
|
|
1289
|
+
let processResult;
|
|
1290
|
+
if (!options?.skipGraphPhases) {
|
|
1291
|
+
const graphResults = await runGraphAnalysisPhases(graph, totalFiles, onProgress, routeRegistry, toolDefs);
|
|
1292
|
+
communityResult = graphResults.communityResult;
|
|
1293
|
+
processResult = graphResults.processResult;
|
|
1294
|
+
}
|
|
1295
|
+
onProgress({
|
|
1296
|
+
phase: 'complete',
|
|
1297
|
+
percent: 100,
|
|
1298
|
+
message: communityResult && processResult
|
|
1299
|
+
? `Graph complete! ${communityResult.stats.totalCommunities} communities, ${processResult.stats.totalProcesses} processes detected.`
|
|
1300
|
+
: 'Graph complete! (graph phases skipped)',
|
|
1301
|
+
stats: {
|
|
1302
|
+
filesProcessed: totalFiles,
|
|
1303
|
+
totalFiles,
|
|
1304
|
+
nodesCreated: graph.nodeCount,
|
|
1305
|
+
},
|
|
1306
|
+
});
|
|
1307
|
+
return { graph, repoPath, totalFileCount: totalFiles, communityResult, processResult };
|
|
1308
|
+
}
|
|
1309
|
+
catch (error) {
|
|
1310
|
+
ctx.clear();
|
|
1311
|
+
throw error;
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
// Inline ORM regex extraction (avoids importing parse-worker which has worker-only code)
|
|
1315
|
+
const PRISMA_QUERY_RE = /\bprisma\.(\w+)\.(findMany|findFirst|findUnique|findUniqueOrThrow|findFirstOrThrow|create|createMany|update|updateMany|delete|deleteMany|upsert|count|aggregate|groupBy)\s*\(/g;
|
|
1316
|
+
const SUPABASE_QUERY_RE = /\bsupabase\.from\s*\(\s*['"](\w+)['"]\s*\)\s*\.(select|insert|update|delete|upsert)\s*\(/g;
|
|
1317
|
+
function extractORMQueriesInline(filePath, content, out) {
|
|
1318
|
+
const hasPrisma = content.includes('prisma.');
|
|
1319
|
+
const hasSupabase = content.includes('supabase.from');
|
|
1320
|
+
if (!hasPrisma && !hasSupabase)
|
|
1321
|
+
return;
|
|
1322
|
+
if (hasPrisma) {
|
|
1323
|
+
PRISMA_QUERY_RE.lastIndex = 0;
|
|
1324
|
+
let m;
|
|
1325
|
+
while ((m = PRISMA_QUERY_RE.exec(content)) !== null) {
|
|
1326
|
+
const model = m[1];
|
|
1327
|
+
if (model.startsWith('$'))
|
|
1328
|
+
continue;
|
|
1329
|
+
out.push({
|
|
1330
|
+
filePath,
|
|
1331
|
+
orm: 'prisma',
|
|
1332
|
+
model,
|
|
1333
|
+
method: m[2],
|
|
1334
|
+
lineNumber: content.substring(0, m.index).split('\n').length - 1,
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
if (hasSupabase) {
|
|
1339
|
+
SUPABASE_QUERY_RE.lastIndex = 0;
|
|
1340
|
+
let m;
|
|
1341
|
+
while ((m = SUPABASE_QUERY_RE.exec(content)) !== null) {
|
|
1342
|
+
out.push({
|
|
1343
|
+
filePath,
|
|
1344
|
+
orm: 'supabase',
|
|
1345
|
+
model: m[1],
|
|
1346
|
+
method: m[2],
|
|
1347
|
+
lineNumber: content.substring(0, m.index).split('\n').length - 1,
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
// ============================================================================
|
|
1353
|
+
// ORM Query Processing — creates QUERIES edges from callers to model nodes
|
|
1354
|
+
// ============================================================================
|
|
1355
|
+
function processORMQueries(graph, queries, isDev) {
|
|
1356
|
+
const modelNodes = new Map();
|
|
1357
|
+
const seenEdges = new Set();
|
|
1358
|
+
let edgesCreated = 0;
|
|
1359
|
+
for (const q of queries) {
|
|
1360
|
+
const modelKey = `${q.orm}:${q.model}`;
|
|
1361
|
+
let modelNodeId = modelNodes.get(modelKey);
|
|
1362
|
+
if (!modelNodeId) {
|
|
1363
|
+
const candidateIds = [
|
|
1364
|
+
generateId('Class', `${q.model}`),
|
|
1365
|
+
generateId('Interface', `${q.model}`),
|
|
1366
|
+
generateId('CodeElement', `${q.model}`),
|
|
1367
|
+
];
|
|
1368
|
+
const existing = candidateIds.find((id) => graph.getNode(id));
|
|
1369
|
+
if (existing) {
|
|
1370
|
+
modelNodeId = existing;
|
|
1371
|
+
}
|
|
1372
|
+
else {
|
|
1373
|
+
modelNodeId = generateId('CodeElement', `${q.orm}:${q.model}`);
|
|
1374
|
+
graph.addNode({
|
|
1375
|
+
id: modelNodeId,
|
|
1376
|
+
label: 'CodeElement',
|
|
1377
|
+
properties: {
|
|
1378
|
+
name: q.model,
|
|
1379
|
+
filePath: '',
|
|
1380
|
+
description: `${q.orm} model/table: ${q.model}`,
|
|
1381
|
+
},
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
modelNodes.set(modelKey, modelNodeId);
|
|
1385
|
+
}
|
|
1386
|
+
const fileId = generateId('File', q.filePath);
|
|
1387
|
+
const edgeKey = `${fileId}->${modelNodeId}:${q.method}`;
|
|
1388
|
+
if (seenEdges.has(edgeKey))
|
|
1389
|
+
continue;
|
|
1390
|
+
seenEdges.add(edgeKey);
|
|
1391
|
+
graph.addRelationship({
|
|
1392
|
+
id: generateId('QUERIES', edgeKey),
|
|
1393
|
+
sourceId: fileId,
|
|
1394
|
+
targetId: modelNodeId,
|
|
1395
|
+
type: 'QUERIES',
|
|
1396
|
+
confidence: 0.9,
|
|
1397
|
+
reason: `${q.orm}-${q.method}`,
|
|
1398
|
+
});
|
|
1399
|
+
edgesCreated++;
|
|
1400
|
+
}
|
|
1401
|
+
if (isDev) {
|
|
1402
|
+
console.log(`ORM dataflow: ${edgesCreated} QUERIES edges, ${modelNodes.size} models (${queries.length} total calls)`);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
//# sourceMappingURL=pipeline.js.map
|