@colbymchenry/codegraph-win32-arm64 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/codegraph +5 -0
- package/lib/dist/.test-build-engine.json +1 -0
- package/lib/dist/.test-build-viewer.json +1 -0
- package/lib/dist/bin/codegraph.d.ts +1 -0
- package/lib/dist/bin/codegraph.d.ts.map +1 -1
- package/lib/dist/bin/codegraph.js +744 -320
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/bin/viewer-gate.d.ts +17 -0
- package/lib/dist/bin/viewer-gate.d.ts.map +1 -0
- package/lib/dist/bin/viewer-gate.js +31 -0
- package/lib/dist/bin/viewer-gate.js.map +1 -0
- package/lib/dist/context/formatter.d.ts +7 -1
- package/lib/dist/context/formatter.d.ts.map +1 -1
- package/lib/dist/context/formatter.js +12 -6
- package/lib/dist/context/formatter.js.map +1 -1
- package/lib/dist/context/index.d.ts +12 -0
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +103 -16
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +58 -2
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +187 -32
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/migrations.d.ts +1 -1
- package/lib/dist/db/migrations.d.ts.map +1 -1
- package/lib/dist/db/migrations.js +64 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +583 -6
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +1417 -57
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +27 -4
- package/lib/dist/db/sqlite-adapter.d.ts +2 -0
- package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/lib/dist/db/sqlite-adapter.js +56 -7
- package/lib/dist/db/sqlite-adapter.js.map +1 -1
- package/lib/dist/db/synthesis-stage.d.ts +12 -0
- package/lib/dist/db/synthesis-stage.d.ts.map +1 -0
- package/lib/dist/db/synthesis-stage.js +89 -0
- package/lib/dist/db/synthesis-stage.js.map +1 -0
- package/lib/dist/db/wal-valve.d.ts +32 -12
- package/lib/dist/db/wal-valve.d.ts.map +1 -1
- package/lib/dist/db/wal-valve.js +65 -22
- package/lib/dist/db/wal-valve.js.map +1 -1
- package/lib/dist/db/wsl-shared-index.d.ts +53 -0
- package/lib/dist/db/wsl-shared-index.d.ts.map +1 -0
- package/lib/dist/db/wsl-shared-index.js +121 -0
- package/lib/dist/db/wsl-shared-index.js.map +1 -0
- package/lib/dist/directory.d.ts +130 -2
- package/lib/dist/directory.d.ts.map +1 -1
- package/lib/dist/directory.js +306 -23
- package/lib/dist/directory.js.map +1 -1
- package/lib/dist/errors.d.ts +14 -0
- package/lib/dist/errors.d.ts.map +1 -1
- package/lib/dist/errors.js +16 -1
- package/lib/dist/errors.js.map +1 -1
- package/lib/dist/extraction/cfml-extractor.d.ts +1 -0
- package/lib/dist/extraction/cfml-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/cfml-extractor.js +15 -3
- package/lib/dist/extraction/cfml-extractor.js.map +1 -1
- package/lib/dist/extraction/dfm-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/dfm-extractor.js +14 -10
- package/lib/dist/extraction/dfm-extractor.js.map +1 -1
- package/lib/dist/extraction/extraction-version.d.ts +1 -1
- package/lib/dist/extraction/extraction-version.js +1 -1
- package/lib/dist/extraction/function-ref.d.ts +6 -4
- package/lib/dist/extraction/function-ref.d.ts.map +1 -1
- package/lib/dist/extraction/function-ref.js +41 -14
- package/lib/dist/extraction/function-ref.js.map +1 -1
- package/lib/dist/extraction/generated-detection.d.ts +48 -12
- package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
- package/lib/dist/extraction/generated-detection.js +176 -11
- package/lib/dist/extraction/generated-detection.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts +38 -0
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +115 -3
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +218 -14
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +874 -176
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.d.ts +58 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +310 -19
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/languages/dart.d.ts.map +1 -1
- package/lib/dist/extraction/languages/dart.js +8 -3
- package/lib/dist/extraction/languages/dart.js.map +1 -1
- package/lib/dist/extraction/languages/erlang.d.ts.map +1 -1
- package/lib/dist/extraction/languages/erlang.js +58 -22
- package/lib/dist/extraction/languages/erlang.js.map +1 -1
- package/lib/dist/extraction/languages/javascript.js +1 -1
- package/lib/dist/extraction/languages/javascript.js.map +1 -1
- package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -1
- package/lib/dist/extraction/languages/kotlin.js +169 -36
- package/lib/dist/extraction/languages/kotlin.js.map +1 -1
- package/lib/dist/extraction/languages/lua.d.ts.map +1 -1
- package/lib/dist/extraction/languages/lua.js +4 -1
- package/lib/dist/extraction/languages/lua.js.map +1 -1
- package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
- package/lib/dist/extraction/languages/objc.js +4 -0
- package/lib/dist/extraction/languages/objc.js.map +1 -1
- package/lib/dist/extraction/languages/python.d.ts.map +1 -1
- package/lib/dist/extraction/languages/python.js +71 -0
- package/lib/dist/extraction/languages/python.js.map +1 -1
- package/lib/dist/extraction/languages/rust.d.ts +20 -0
- package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
- package/lib/dist/extraction/languages/rust.js +50 -20
- package/lib/dist/extraction/languages/rust.js.map +1 -1
- package/lib/dist/extraction/languages/scala.d.ts.map +1 -1
- package/lib/dist/extraction/languages/scala.js +18 -3
- package/lib/dist/extraction/languages/scala.js.map +1 -1
- package/lib/dist/extraction/languages/typescript.d.ts.map +1 -1
- package/lib/dist/extraction/languages/typescript.js +9 -2
- package/lib/dist/extraction/languages/typescript.js.map +1 -1
- package/lib/dist/extraction/liquid-extractor.d.ts +18 -0
- package/lib/dist/extraction/liquid-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/liquid-extractor.js +98 -22
- package/lib/dist/extraction/liquid-extractor.js.map +1 -1
- package/lib/dist/extraction/mybatis-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/mybatis-extractor.js +6 -4
- package/lib/dist/extraction/mybatis-extractor.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +7 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +20 -1
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/syntax-tokens.d.ts +103 -0
- package/lib/dist/extraction/syntax-tokens.d.ts.map +1 -0
- package/lib/dist/extraction/syntax-tokens.js +381 -0
- package/lib/dist/extraction/syntax-tokens.js.map +1 -0
- package/lib/dist/extraction/tree-sitter-helpers.d.ts +5 -0
- package/lib/dist/extraction/tree-sitter-helpers.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter-helpers.js +17 -0
- package/lib/dist/extraction/tree-sitter-helpers.js.map +1 -1
- package/lib/dist/extraction/tree-sitter-types.d.ts +31 -3
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +101 -18
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +926 -132
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
- package/lib/dist/file-limits.d.ts +40 -0
- package/lib/dist/file-limits.d.ts.map +1 -0
- package/lib/dist/file-limits.js +147 -0
- package/lib/dist/file-limits.js.map +1 -0
- package/lib/dist/graph/branch-guards.d.ts +248 -0
- package/lib/dist/graph/branch-guards.d.ts.map +1 -0
- package/lib/dist/graph/branch-guards.js +2231 -0
- package/lib/dist/graph/branch-guards.js.map +1 -0
- package/lib/dist/graph/dead-code.d.ts +251 -0
- package/lib/dist/graph/dead-code.d.ts.map +1 -0
- package/lib/dist/graph/dead-code.js +776 -0
- package/lib/dist/graph/dead-code.js.map +1 -0
- package/lib/dist/graph/dynamic-boundary-report.d.ts +121 -0
- package/lib/dist/graph/dynamic-boundary-report.d.ts.map +1 -0
- package/lib/dist/graph/dynamic-boundary-report.js +283 -0
- package/lib/dist/graph/dynamic-boundary-report.js.map +1 -0
- package/lib/dist/graph/index.d.ts +4 -0
- package/lib/dist/graph/index.d.ts.map +1 -1
- package/lib/dist/graph/index.js +16 -1
- package/lib/dist/graph/index.js.map +1 -1
- package/lib/dist/graph/named-symbol-flow.d.ts +125 -0
- package/lib/dist/graph/named-symbol-flow.d.ts.map +1 -0
- package/lib/dist/graph/named-symbol-flow.js +552 -0
- package/lib/dist/graph/named-symbol-flow.js.map +1 -0
- package/lib/dist/graph/queries.d.ts.map +1 -1
- package/lib/dist/graph/queries.js +2 -0
- package/lib/dist/graph/queries.js.map +1 -1
- package/lib/dist/graph/symbol-lookup.d.ts +83 -0
- package/lib/dist/graph/symbol-lookup.d.ts.map +1 -0
- package/lib/dist/graph/symbol-lookup.js +181 -0
- package/lib/dist/graph/symbol-lookup.js.map +1 -0
- package/lib/dist/graph/traversal.d.ts +9 -0
- package/lib/dist/graph/traversal.d.ts.map +1 -1
- package/lib/dist/graph/traversal.js +62 -36
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/graph/type-hierarchy.d.ts +155 -0
- package/lib/dist/graph/type-hierarchy.d.ts.map +1 -0
- package/lib/dist/graph/type-hierarchy.js +382 -0
- package/lib/dist/graph/type-hierarchy.js.map +1 -0
- package/lib/dist/index.d.ts +273 -11
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +511 -34
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/index.d.ts +4 -3
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +11 -8
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/targets/antigravity.d.ts.map +1 -1
- package/lib/dist/installer/targets/antigravity.js +14 -2
- package/lib/dist/installer/targets/antigravity.js.map +1 -1
- package/lib/dist/installer/targets/claude.d.ts +3 -0
- package/lib/dist/installer/targets/claude.d.ts.map +1 -1
- package/lib/dist/installer/targets/claude.js +72 -12
- package/lib/dist/installer/targets/claude.js.map +1 -1
- package/lib/dist/installer/targets/codex.d.ts +23 -8
- package/lib/dist/installer/targets/codex.d.ts.map +1 -1
- package/lib/dist/installer/targets/codex.js +74 -47
- package/lib/dist/installer/targets/codex.js.map +1 -1
- package/lib/dist/installer/targets/copilot-cli.d.ts +32 -0
- package/lib/dist/installer/targets/copilot-cli.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-cli.js +215 -0
- package/lib/dist/installer/targets/copilot-cli.js.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts +42 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js +238 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts +47 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.js +219 -0
- package/lib/dist/installer/targets/copilot-vscode.js.map +1 -0
- package/lib/dist/installer/targets/opencode.d.ts +16 -5
- package/lib/dist/installer/targets/opencode.d.ts.map +1 -1
- package/lib/dist/installer/targets/opencode.js +73 -22
- package/lib/dist/installer/targets/opencode.js.map +1 -1
- package/lib/dist/installer/targets/registry.d.ts.map +1 -1
- package/lib/dist/installer/targets/registry.js +6 -0
- package/lib/dist/installer/targets/registry.js.map +1 -1
- package/lib/dist/installer/targets/shared.d.ts +14 -3
- package/lib/dist/installer/targets/shared.d.ts.map +1 -1
- package/lib/dist/installer/targets/shared.js +39 -11
- package/lib/dist/installer/targets/shared.js.map +1 -1
- package/lib/dist/installer/targets/toml.d.ts +6 -5
- package/lib/dist/installer/targets/toml.d.ts.map +1 -1
- package/lib/dist/installer/targets/toml.js +99 -20
- package/lib/dist/installer/targets/toml.js.map +1 -1
- package/lib/dist/installer/targets/types.d.ts +12 -5
- package/lib/dist/installer/targets/types.d.ts.map +1 -1
- package/lib/dist/mcp/answer-freshness.d.ts +10 -0
- package/lib/dist/mcp/answer-freshness.d.ts.map +1 -0
- package/lib/dist/mcp/answer-freshness.js +68 -0
- package/lib/dist/mcp/answer-freshness.js.map +1 -0
- package/lib/dist/mcp/daemon-manager.d.ts +1 -1
- package/lib/dist/mcp/daemon-manager.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-manager.js +17 -1
- package/lib/dist/mcp/daemon-manager.js.map +1 -1
- package/lib/dist/mcp/daemon-paths.d.ts +8 -0
- package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-paths.js +65 -2
- package/lib/dist/mcp/daemon-paths.js.map +1 -1
- package/lib/dist/mcp/daemon-registry.d.ts +17 -4
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-registry.js +133 -23
- package/lib/dist/mcp/daemon-registry.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +26 -13
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +126 -32
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/dynamic-boundaries.d.ts +1 -10
- package/lib/dist/mcp/dynamic-boundaries.d.ts.map +1 -1
- package/lib/dist/mcp/dynamic-boundaries.js +46 -42
- package/lib/dist/mcp/dynamic-boundaries.js.map +1 -1
- package/lib/dist/mcp/engine.d.ts +31 -9
- package/lib/dist/mcp/engine.d.ts.map +1 -1
- package/lib/dist/mcp/engine.js +190 -64
- package/lib/dist/mcp/engine.js.map +1 -1
- package/lib/dist/mcp/explore-dedup.d.ts +140 -0
- package/lib/dist/mcp/explore-dedup.d.ts.map +1 -0
- package/lib/dist/mcp/explore-dedup.js +239 -0
- package/lib/dist/mcp/explore-dedup.js.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts +289 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.js +558 -0
- package/lib/dist/mcp/explore-diagnostics.js.map +1 -0
- package/lib/dist/mcp/explore-session-state.d.ts +217 -0
- package/lib/dist/mcp/explore-session-state.d.ts.map +1 -0
- package/lib/dist/mcp/explore-session-state.js +322 -0
- package/lib/dist/mcp/explore-session-state.js.map +1 -0
- package/lib/dist/mcp/index-freshness-worker.d.ts +2 -0
- package/lib/dist/mcp/index-freshness-worker.d.ts.map +1 -0
- package/lib/dist/mcp/index-freshness-worker.js +30 -0
- package/lib/dist/mcp/index-freshness-worker.js.map +1 -0
- package/lib/dist/mcp/index-freshness.d.ts +7 -0
- package/lib/dist/mcp/index-freshness.d.ts.map +1 -0
- package/lib/dist/mcp/index-freshness.js +94 -0
- package/lib/dist/mcp/index-freshness.js.map +1 -0
- package/lib/dist/mcp/index.d.ts +27 -1
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +159 -14
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts +4 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.js +14 -3
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
- package/lib/dist/mcp/project-lifecycle.d.ts +9 -0
- package/lib/dist/mcp/project-lifecycle.d.ts.map +1 -0
- package/lib/dist/mcp/project-lifecycle.js +181 -0
- package/lib/dist/mcp/project-lifecycle.js.map +1 -0
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +15 -1
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/query-pool.d.ts +2 -2
- package/lib/dist/mcp/query-pool.d.ts.map +1 -1
- package/lib/dist/mcp/query-pool.js +9 -7
- package/lib/dist/mcp/query-pool.js.map +1 -1
- package/lib/dist/mcp/query-worker.js +2 -2
- package/lib/dist/mcp/query-worker.js.map +1 -1
- package/lib/dist/mcp/server-instructions.d.ts +2 -2
- package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
- package/lib/dist/mcp/server-instructions.js +13 -5
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +16 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +36 -13
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/startup-handshake.d.ts +3 -1
- package/lib/dist/mcp/startup-handshake.d.ts.map +1 -1
- package/lib/dist/mcp/startup-handshake.js +10 -2
- package/lib/dist/mcp/startup-handshake.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts +544 -38
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +4246 -770
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/mcp/writer-lock.d.ts +61 -0
- package/lib/dist/mcp/writer-lock.d.ts.map +1 -0
- package/lib/dist/mcp/writer-lock.js +260 -0
- package/lib/dist/mcp/writer-lock.js.map +1 -0
- package/lib/dist/project-config.d.ts +23 -0
- package/lib/dist/project-config.d.ts.map +1 -1
- package/lib/dist/project-config.js +39 -2
- package/lib/dist/project-config.js.map +1 -1
- package/lib/dist/resolution/alias-binding.d.ts +56 -0
- package/lib/dist/resolution/alias-binding.d.ts.map +1 -0
- package/lib/dist/resolution/alias-binding.js +127 -0
- package/lib/dist/resolution/alias-binding.js.map +1 -0
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +21 -19
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts +23 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +330 -154
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/cpp-constructor.d.ts +4 -0
- package/lib/dist/resolution/cpp-constructor.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-constructor.js +123 -0
- package/lib/dist/resolution/cpp-constructor.js.map +1 -0
- package/lib/dist/resolution/cpp-macro-visibility.d.ts +12 -0
- package/lib/dist/resolution/cpp-macro-visibility.d.ts.map +1 -0
- package/lib/dist/resolution/cpp-macro-visibility.js +342 -0
- package/lib/dist/resolution/cpp-macro-visibility.js.map +1 -0
- package/lib/dist/resolution/expo-router-synthesizer.d.ts +32 -0
- package/lib/dist/resolution/expo-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/expo-router-synthesizer.js +189 -0
- package/lib/dist/resolution/expo-router-synthesizer.js.map +1 -0
- package/lib/dist/resolution/frameworks/csharp.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/csharp.js +96 -2
- package/lib/dist/resolution/frameworks/csharp.js.map +1 -1
- package/lib/dist/resolution/frameworks/expo-router.d.ts +189 -0
- package/lib/dist/resolution/frameworks/expo-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/expo-router.js +785 -0
- package/lib/dist/resolution/frameworks/expo-router.js.map +1 -0
- package/lib/dist/resolution/frameworks/express.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/express.js +251 -16
- package/lib/dist/resolution/frameworks/express.js.map +1 -1
- package/lib/dist/resolution/frameworks/index.d.ts +5 -0
- package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/index.js +29 -1
- package/lib/dist/resolution/frameworks/index.js.map +1 -1
- package/lib/dist/resolution/frameworks/java.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/java.js +79 -47
- package/lib/dist/resolution/frameworks/java.js.map +1 -1
- package/lib/dist/resolution/frameworks/nestjs.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/nestjs.js +6 -14
- package/lib/dist/resolution/frameworks/nestjs.js.map +1 -1
- package/lib/dist/resolution/frameworks/nextjs.d.ts +76 -0
- package/lib/dist/resolution/frameworks/nextjs.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/nextjs.js +328 -0
- package/lib/dist/resolution/frameworks/nextjs.js.map +1 -0
- package/lib/dist/resolution/frameworks/object-literal.d.ts +32 -0
- package/lib/dist/resolution/frameworks/object-literal.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/object-literal.js +139 -0
- package/lib/dist/resolution/frameworks/object-literal.js.map +1 -0
- package/lib/dist/resolution/frameworks/package-deps.d.ts +14 -0
- package/lib/dist/resolution/frameworks/package-deps.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/package-deps.js +78 -0
- package/lib/dist/resolution/frameworks/package-deps.js.map +1 -0
- package/lib/dist/resolution/frameworks/python.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/python.js +166 -0
- package/lib/dist/resolution/frameworks/python.js.map +1 -1
- package/lib/dist/resolution/frameworks/react-native.d.ts +26 -0
- package/lib/dist/resolution/frameworks/react-native.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react-native.js +153 -14
- package/lib/dist/resolution/frameworks/react-native.js.map +1 -1
- package/lib/dist/resolution/frameworks/react-router.d.ts +46 -0
- package/lib/dist/resolution/frameworks/react-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/react-router.js +187 -0
- package/lib/dist/resolution/frameworks/react-router.js.map +1 -0
- package/lib/dist/resolution/frameworks/react.d.ts +2 -1
- package/lib/dist/resolution/frameworks/react.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react.js +188 -139
- package/lib/dist/resolution/frameworks/react.js.map +1 -1
- package/lib/dist/resolution/frameworks/svelte.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/svelte.js +6 -1
- package/lib/dist/resolution/frameworks/svelte.js.map +1 -1
- package/lib/dist/resolution/frameworks/sveltekit-router.d.ts +36 -0
- package/lib/dist/resolution/frameworks/sveltekit-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/sveltekit-router.js +156 -0
- package/lib/dist/resolution/frameworks/sveltekit-router.js.map +1 -0
- package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/swift.js +11 -1
- package/lib/dist/resolution/frameworks/swift.js.map +1 -1
- package/lib/dist/resolution/frameworks/tanstack-router.d.ts +84 -0
- package/lib/dist/resolution/frameworks/tanstack-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/tanstack-router.js +437 -0
- package/lib/dist/resolution/frameworks/tanstack-router.js.map +1 -0
- package/lib/dist/resolution/frameworks/vue-router.d.ts +82 -0
- package/lib/dist/resolution/frameworks/vue-router.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/vue-router.js +377 -0
- package/lib/dist/resolution/frameworks/vue-router.js.map +1 -0
- package/lib/dist/resolution/import-resolver.d.ts +38 -0
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +394 -28
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +89 -25
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +567 -149
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/js-builtins.d.ts +13 -0
- package/lib/dist/resolution/js-builtins.d.ts.map +1 -0
- package/lib/dist/resolution/js-builtins.js +46 -0
- package/lib/dist/resolution/js-builtins.js.map +1 -0
- package/lib/dist/resolution/name-matcher.d.ts +99 -22
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +2192 -87
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/next-router-synthesizer.d.ts +27 -0
- package/lib/dist/resolution/next-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/next-router-synthesizer.js +113 -0
- package/lib/dist/resolution/next-router-synthesizer.js.map +1 -0
- package/lib/dist/resolution/path-aliases.d.ts +6 -4
- package/lib/dist/resolution/path-aliases.d.ts.map +1 -1
- package/lib/dist/resolution/path-aliases.js +125 -17
- package/lib/dist/resolution/path-aliases.js.map +1 -1
- package/lib/dist/resolution/react-router-synthesizer.d.ts +33 -0
- package/lib/dist/resolution/react-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/react-router-synthesizer.js +126 -0
- package/lib/dist/resolution/react-router-synthesizer.js.map +1 -0
- package/lib/dist/resolution/resolver-pool.d.ts +2 -0
- package/lib/dist/resolution/resolver-pool.d.ts.map +1 -1
- package/lib/dist/resolution/resolver-pool.js +4 -0
- package/lib/dist/resolution/resolver-pool.js.map +1 -1
- package/lib/dist/resolution/strip-comments.d.ts +6 -0
- package/lib/dist/resolution/strip-comments.d.ts.map +1 -1
- package/lib/dist/resolution/strip-comments.js +58 -0
- package/lib/dist/resolution/strip-comments.js.map +1 -1
- package/lib/dist/resolution/sveltekit-synthesizer.d.ts +58 -0
- package/lib/dist/resolution/sveltekit-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/sveltekit-synthesizer.js +173 -0
- package/lib/dist/resolution/sveltekit-synthesizer.js.map +1 -0
- package/lib/dist/resolution/synth-utils.d.ts +26 -0
- package/lib/dist/resolution/synth-utils.d.ts.map +1 -0
- package/lib/dist/resolution/synth-utils.js +75 -0
- package/lib/dist/resolution/synth-utils.js.map +1 -0
- package/lib/dist/resolution/tanstack-router-synthesizer.d.ts +31 -0
- package/lib/dist/resolution/tanstack-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/tanstack-router-synthesizer.js +114 -0
- package/lib/dist/resolution/tanstack-router-synthesizer.js.map +1 -0
- package/lib/dist/resolution/tier-synthesizer.d.ts +49 -0
- package/lib/dist/resolution/tier-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/tier-synthesizer.js +931 -0
- package/lib/dist/resolution/tier-synthesizer.js.map +1 -0
- package/lib/dist/resolution/types.d.ts +78 -2
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/resolution/types.js +64 -0
- package/lib/dist/resolution/types.js.map +1 -1
- package/lib/dist/resolution/vue-router-synthesizer.d.ts +30 -0
- package/lib/dist/resolution/vue-router-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/vue-router-synthesizer.js +115 -0
- package/lib/dist/resolution/vue-router-synthesizer.js.map +1 -0
- package/lib/dist/search/identifier-segments.d.ts +10 -0
- package/lib/dist/search/identifier-segments.d.ts.map +1 -1
- package/lib/dist/search/identifier-segments.js +29 -0
- package/lib/dist/search/identifier-segments.js.map +1 -1
- package/lib/dist/search/query-paths.d.ts +106 -0
- package/lib/dist/search/query-paths.d.ts.map +1 -0
- package/lib/dist/search/query-paths.js +513 -0
- package/lib/dist/search/query-paths.js.map +1 -0
- package/lib/dist/search/query-utils.d.ts +16 -1
- package/lib/dist/search/query-utils.d.ts.map +1 -1
- package/lib/dist/search/query-utils.js +48 -10
- package/lib/dist/search/query-utils.js.map +1 -1
- package/lib/dist/sync/watch-policy.d.ts +14 -0
- package/lib/dist/sync/watch-policy.d.ts.map +1 -1
- package/lib/dist/sync/watch-policy.js +19 -0
- package/lib/dist/sync/watch-policy.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +74 -35
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +281 -99
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/telemetry/index.d.ts +4 -2
- package/lib/dist/telemetry/index.d.ts.map +1 -1
- package/lib/dist/telemetry/index.js +92 -41
- package/lib/dist/telemetry/index.js.map +1 -1
- package/lib/dist/types.d.ts +21 -2
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +2 -0
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/ui-server/api/deadcode.d.ts +84 -0
- package/lib/dist/ui-server/api/deadcode.d.ts.map +1 -0
- package/lib/dist/ui-server/api/deadcode.js +136 -0
- package/lib/dist/ui-server/api/deadcode.js.map +1 -0
- package/lib/dist/ui-server/api/effects.d.ts +87 -0
- package/lib/dist/ui-server/api/effects.d.ts.map +1 -0
- package/lib/dist/ui-server/api/effects.js +499 -0
- package/lib/dist/ui-server/api/effects.js.map +1 -0
- package/lib/dist/ui-server/api/entrypoints.d.ts +86 -0
- package/lib/dist/ui-server/api/entrypoints.d.ts.map +1 -0
- package/lib/dist/ui-server/api/entrypoints.js +279 -0
- package/lib/dist/ui-server/api/entrypoints.js.map +1 -0
- package/lib/dist/ui-server/api/events.d.ts +183 -0
- package/lib/dist/ui-server/api/events.d.ts.map +1 -0
- package/lib/dist/ui-server/api/events.js +430 -0
- package/lib/dist/ui-server/api/events.js.map +1 -0
- package/lib/dist/ui-server/api/file.d.ts +66 -0
- package/lib/dist/ui-server/api/file.d.ts.map +1 -0
- package/lib/dist/ui-server/api/file.js +235 -0
- package/lib/dist/ui-server/api/file.js.map +1 -0
- package/lib/dist/ui-server/api/filecode.d.ts +126 -0
- package/lib/dist/ui-server/api/filecode.d.ts.map +1 -0
- package/lib/dist/ui-server/api/filecode.js +205 -0
- package/lib/dist/ui-server/api/filecode.js.map +1 -0
- package/lib/dist/ui-server/api/flow.d.ts +226 -0
- package/lib/dist/ui-server/api/flow.d.ts.map +1 -0
- package/lib/dist/ui-server/api/flow.js +612 -0
- package/lib/dist/ui-server/api/flow.js.map +1 -0
- package/lib/dist/ui-server/api/hierarchy.d.ts +81 -0
- package/lib/dist/ui-server/api/hierarchy.d.ts.map +1 -0
- package/lib/dist/ui-server/api/hierarchy.js +92 -0
- package/lib/dist/ui-server/api/hierarchy.js.map +1 -0
- package/lib/dist/ui-server/api/index.d.ts +90 -0
- package/lib/dist/ui-server/api/index.d.ts.map +1 -0
- package/lib/dist/ui-server/api/index.js +332 -0
- package/lib/dist/ui-server/api/index.js.map +1 -0
- package/lib/dist/ui-server/api/map.d.ts +238 -0
- package/lib/dist/ui-server/api/map.d.ts.map +1 -0
- package/lib/dist/ui-server/api/map.js +681 -0
- package/lib/dist/ui-server/api/map.js.map +1 -0
- package/lib/dist/ui-server/api/node.d.ts +81 -0
- package/lib/dist/ui-server/api/node.d.ts.map +1 -0
- package/lib/dist/ui-server/api/node.js +388 -0
- package/lib/dist/ui-server/api/node.js.map +1 -0
- package/lib/dist/ui-server/api/nodes.d.ts +25 -0
- package/lib/dist/ui-server/api/nodes.d.ts.map +1 -0
- package/lib/dist/ui-server/api/nodes.js +45 -0
- package/lib/dist/ui-server/api/nodes.js.map +1 -0
- package/lib/dist/ui-server/api/program.d.ts +139 -0
- package/lib/dist/ui-server/api/program.d.ts.map +1 -0
- package/lib/dist/ui-server/api/program.js +315 -0
- package/lib/dist/ui-server/api/program.js.map +1 -0
- package/lib/dist/ui-server/api/respond.d.ts +76 -0
- package/lib/dist/ui-server/api/respond.d.ts.map +1 -0
- package/lib/dist/ui-server/api/respond.js +186 -0
- package/lib/dist/ui-server/api/respond.js.map +1 -0
- package/lib/dist/ui-server/api/route-roots.d.ts +39 -0
- package/lib/dist/ui-server/api/route-roots.d.ts.map +1 -0
- package/lib/dist/ui-server/api/route-roots.js +96 -0
- package/lib/dist/ui-server/api/route-roots.js.map +1 -0
- package/lib/dist/ui-server/api/routes.d.ts +59 -0
- package/lib/dist/ui-server/api/routes.d.ts.map +1 -0
- package/lib/dist/ui-server/api/routes.js +108 -0
- package/lib/dist/ui-server/api/routes.js.map +1 -0
- package/lib/dist/ui-server/api/screens.d.ts +117 -0
- package/lib/dist/ui-server/api/screens.d.ts.map +1 -0
- package/lib/dist/ui-server/api/screens.js +611 -0
- package/lib/dist/ui-server/api/screens.js.map +1 -0
- package/lib/dist/ui-server/api/search.d.ts +29 -0
- package/lib/dist/ui-server/api/search.d.ts.map +1 -0
- package/lib/dist/ui-server/api/search.js +232 -0
- package/lib/dist/ui-server/api/search.js.map +1 -0
- package/lib/dist/ui-server/api/session.d.ts +52 -0
- package/lib/dist/ui-server/api/session.d.ts.map +1 -0
- package/lib/dist/ui-server/api/session.js +196 -0
- package/lib/dist/ui-server/api/session.js.map +1 -0
- package/lib/dist/ui-server/api/source.d.ts +200 -0
- package/lib/dist/ui-server/api/source.d.ts.map +1 -0
- package/lib/dist/ui-server/api/source.js +422 -0
- package/lib/dist/ui-server/api/source.js.map +1 -0
- package/lib/dist/ui-server/api/stats.d.ts +27 -0
- package/lib/dist/ui-server/api/stats.d.ts.map +1 -0
- package/lib/dist/ui-server/api/stats.js +164 -0
- package/lib/dist/ui-server/api/stats.js.map +1 -0
- package/lib/dist/ui-server/api/steps.d.ts +274 -0
- package/lib/dist/ui-server/api/steps.d.ts.map +1 -0
- package/lib/dist/ui-server/api/steps.js +1446 -0
- package/lib/dist/ui-server/api/steps.js.map +1 -0
- package/lib/dist/ui-server/api/trail-store.d.ts +142 -0
- package/lib/dist/ui-server/api/trail-store.d.ts.map +1 -0
- package/lib/dist/ui-server/api/trail-store.js +323 -0
- package/lib/dist/ui-server/api/trail-store.js.map +1 -0
- package/lib/dist/ui-server/api/trails.d.ts +163 -0
- package/lib/dist/ui-server/api/trails.d.ts.map +1 -0
- package/lib/dist/ui-server/api/trails.js +369 -0
- package/lib/dist/ui-server/api/trails.js.map +1 -0
- package/lib/dist/ui-server/api/when.d.ts +125 -0
- package/lib/dist/ui-server/api/when.d.ts.map +1 -0
- package/lib/dist/ui-server/api/when.js +251 -0
- package/lib/dist/ui-server/api/when.js.map +1 -0
- package/lib/dist/ui-server/api/wire.d.ts +179 -0
- package/lib/dist/ui-server/api/wire.d.ts.map +1 -0
- package/lib/dist/ui-server/api/wire.js +231 -0
- package/lib/dist/ui-server/api/wire.js.map +1 -0
- package/lib/dist/ui-server/assets.d.ts +40 -0
- package/lib/dist/ui-server/assets.d.ts.map +1 -0
- package/lib/dist/ui-server/assets.js +110 -0
- package/lib/dist/ui-server/assets.js.map +1 -0
- package/lib/dist/ui-server/constants.d.ts +32 -0
- package/lib/dist/ui-server/constants.d.ts.map +1 -0
- package/lib/dist/ui-server/constants.js +35 -0
- package/lib/dist/ui-server/constants.js.map +1 -0
- package/lib/dist/ui-server/highlight/index.d.ts +113 -0
- package/lib/dist/ui-server/highlight/index.d.ts.map +1 -0
- package/lib/dist/ui-server/highlight/index.js +307 -0
- package/lib/dist/ui-server/highlight/index.js.map +1 -0
- package/lib/dist/ui-server/highlight/languages.d.ts +36 -0
- package/lib/dist/ui-server/highlight/languages.d.ts.map +1 -0
- package/lib/dist/ui-server/highlight/languages.js +50 -0
- package/lib/dist/ui-server/highlight/languages.js.map +1 -0
- package/lib/dist/ui-server/index.d.ts +92 -0
- package/lib/dist/ui-server/index.d.ts.map +1 -0
- package/lib/dist/ui-server/index.js +399 -0
- package/lib/dist/ui-server/index.js.map +1 -0
- package/lib/dist/ui-server/open-browser.d.ts +31 -0
- package/lib/dist/ui-server/open-browser.d.ts.map +1 -0
- package/lib/dist/ui-server/open-browser.js +79 -0
- package/lib/dist/ui-server/open-browser.js.map +1 -0
- package/lib/dist/ui-server/security.d.ts +127 -0
- package/lib/dist/ui-server/security.d.ts.map +1 -0
- package/lib/dist/ui-server/security.js +332 -0
- package/lib/dist/ui-server/security.js.map +1 -0
- package/lib/dist/ui-server/static.d.ts +45 -0
- package/lib/dist/ui-server/static.d.ts.map +1 -0
- package/lib/dist/ui-server/static.js +165 -0
- package/lib/dist/ui-server/static.js.map +1 -0
- package/lib/dist/utils.d.ts +14 -2
- package/lib/dist/utils.d.ts.map +1 -1
- package/lib/dist/utils.js +25 -10
- package/lib/dist/utils.js.map +1 -1
- package/lib/dist/viewer/assets/archivo-latin-ext-wght-normal-C4zznr8T.woff2 +0 -0
- package/lib/dist/viewer/assets/archivo-latin-wght-normal-E0tuGl4L.woff2 +0 -0
- package/lib/dist/viewer/assets/archivo-vietnamese-wght-normal-XAtsl5Q_.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-400-italic-2syK4fUT.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-400-italic-CBJ8pzag.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-600-normal-CTOM6hUh.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-600-normal-fLZuRloM.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-400-italic-B4oTjJdl.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-400-italic-CBjNughH.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-600-normal-9HEixskS.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-cyrillic-ext-600-normal-V-xxqcpd.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-400-italic-66oory27.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-400-italic-BqAiT5Ww.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-600-normal-DWFSQ4vo.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-400-italic-B7_fu1kp.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-400-italic-Bg0ZHwF4.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-600-normal-D38SheWl.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-latin-ext-600-normal-DmB0ttJJ.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-400-italic-D6eaYXMU.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-400-italic-DRuN92E5.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-600-normal-D2EvbN8M.woff2 +0 -0
- package/lib/dist/viewer/assets/ibm-plex-mono-vietnamese-600-normal-iLQfcSjf.woff +0 -0
- package/lib/dist/viewer/assets/index-CF9yvio6.css +1 -0
- package/lib/dist/viewer/assets/index-D4S7YUPf.js +97 -0
- package/lib/dist/viewer/index.html +16 -0
- package/lib/kernel/codegraph-kernel.node +2 -2
- package/lib/node_modules/.package-lock.json +4 -4
- package/lib/node_modules/picomatch/README.md +56 -51
- package/lib/node_modules/picomatch/lib/constants.js +4 -0
- package/lib/node_modules/picomatch/lib/parse.js +341 -1
- package/lib/node_modules/picomatch/lib/picomatch.js +25 -5
- package/lib/node_modules/picomatch/lib/scan.js +30 -18
- package/lib/node_modules/picomatch/package.json +4 -4
- package/lib/package.json +9 -2
- package/package.json +1 -1
package/lib/dist/db/queries.js
CHANGED
|
@@ -5,20 +5,26 @@
|
|
|
5
5
|
* Prepared statements for CRUD operations on the knowledge graph.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.QueryBuilder = void 0;
|
|
8
|
+
exports.QueryBuilder = exports.DEPRIORITIZED_NAME_BONUS_SCALE = void 0;
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
const query_utils_1 = require("../search/query-utils");
|
|
11
11
|
const query_parser_1 = require("../search/query-parser");
|
|
12
12
|
const generated_detection_1 = require("../extraction/generated-detection");
|
|
13
13
|
const identifier_segments_1 = require("../search/identifier-segments");
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* Files that should not be candidates for "dominant file" detection: test/spec
|
|
16
|
+
* files and tool-generated files. Generated files (`*.pb.go`, `*.pulsar.go`,
|
|
17
|
+
* mock outputs, …) often have huge in-file edge counts that dwarf the real
|
|
18
|
+
* source — etcd's `rpc.pb.go` has 4× the in-file edges of `server.go`.
|
|
19
|
+
*
|
|
20
|
+
* Path patterns plus, when the caller passes the indexed set, files whose
|
|
21
|
+
* HEADER declares them generated — a `payroll.go` full of generated CRUD has
|
|
22
|
+
* exactly the same edge-density problem as `rpc.pb.go` and nothing in its name
|
|
23
|
+
* to catch it (#1500).
|
|
20
24
|
*/
|
|
21
|
-
function isLowValueFile(filePath) {
|
|
25
|
+
function isLowValueFile(filePath, generated) {
|
|
26
|
+
if (generated?.has(filePath))
|
|
27
|
+
return true;
|
|
22
28
|
const lp = filePath.toLowerCase();
|
|
23
29
|
return (/(?:^|\/)(tests?|__tests?__|spec)\//.test(lp) ||
|
|
24
30
|
/_test\.go$/.test(lp) ||
|
|
@@ -34,6 +40,39 @@ function isLowValueFile(filePath) {
|
|
|
34
40
|
(0, generated_detection_1.isGeneratedFile)(filePath));
|
|
35
41
|
}
|
|
36
42
|
const SQLITE_PARAM_CHUNK_SIZE = 500;
|
|
43
|
+
/**
|
|
44
|
+
* A SQL predicate: is the node aliased `alias` a member an INTERFACE declares?
|
|
45
|
+
*
|
|
46
|
+
* `method_signature` / `property_signature` enter the graph as `method` /
|
|
47
|
+
* `property` nodes hung off their interface by a `contains` edge (#1638). They
|
|
48
|
+
* have no body and originate no behaviour, so for a structural judgement about
|
|
49
|
+
* a FILE they are the interface restated, not an extra thing the file declares.
|
|
50
|
+
* See {@link QueryBuilder.getAmbientDeclarationPathsAmong}, the one caller, for
|
|
51
|
+
* why treating them as opaque would break that rule in three places at once.
|
|
52
|
+
*
|
|
53
|
+
* Seeks `idx_edges_target_kind`, so it costs a key lookup per row rather than a
|
|
54
|
+
* join over the whole edge table.
|
|
55
|
+
*/
|
|
56
|
+
const IS_INTERFACE_MEMBER = (alias) => `EXISTS (
|
|
57
|
+
SELECT 1 FROM edges ce JOIN nodes owner ON owner.id = ce.source
|
|
58
|
+
WHERE ce.target = ${alias}.id AND ce.kind = 'contains' AND owner.kind = 'interface'
|
|
59
|
+
)`;
|
|
60
|
+
/**
|
|
61
|
+
* How much of the exact-name bonus a `deprioritize`d path keeps (#982). Damped
|
|
62
|
+
* rather than zeroed: a query that genuinely targets that tree must still rank
|
|
63
|
+
* it, the same "discount, don't erase" rule the path penalty follows.
|
|
64
|
+
*
|
|
65
|
+
* Derived rather than picked. `nameMatchBonus`'s prefix arm tops out below
|
|
66
|
+
* `10 + 30 = 40`, and a de-prioritized node also takes the -15 path penalty, so
|
|
67
|
+
* `80 * SCALE - 15 > 40` is what stops a damped WHOLE-QUERY exact match from
|
|
68
|
+
* losing to a mere prefix match. 0.75 clears it (45). Measured on a 62k-node
|
|
69
|
+
* django index: at 0.25 that invariant breaks in practice — `child`, `parent`
|
|
70
|
+
* and `method` lose rank 1 to `children`, `all_parents` and `method_decorator`
|
|
71
|
+
* — while crowd-out removal is almost flat between 0.75 and 0.5 (39 vs 40 of 88
|
|
72
|
+
* peripheral top-10 slots cleared), so a deeper discount buys little and costs
|
|
73
|
+
* the invariant. Pinned by a test.
|
|
74
|
+
*/
|
|
75
|
+
exports.DEPRIORITIZED_NAME_BONUS_SCALE = 0.75;
|
|
37
76
|
/**
|
|
38
77
|
* Last segment of a (possibly dotted/qualified) reference name — the part a
|
|
39
78
|
* new symbol's plain node name could match: 'util.greet' → 'greet',
|
|
@@ -42,8 +81,11 @@ const SQLITE_PARAM_CHUNK_SIZE = 500;
|
|
|
42
81
|
* refs against newly-added node names.
|
|
43
82
|
*/
|
|
44
83
|
function referenceNameTail(referenceName) {
|
|
45
|
-
|
|
46
|
-
|
|
84
|
+
// Erlang refs carry a written arity (`f/1`, `mod::fn/2` — #1610); the tail a
|
|
85
|
+
// new symbol's plain name could match is the arity-less function name.
|
|
86
|
+
const base = referenceName.replace(/\/\d{1,3}$/, '') || referenceName;
|
|
87
|
+
const idx = Math.max(base.lastIndexOf('.'), base.lastIndexOf(':'));
|
|
88
|
+
return idx >= 0 ? base.slice(idx + 1) : base;
|
|
47
89
|
}
|
|
48
90
|
/**
|
|
49
91
|
* Convert database row to Node object
|
|
@@ -100,6 +142,7 @@ function rowToFileRecord(row) {
|
|
|
100
142
|
indexedAt: row.indexed_at,
|
|
101
143
|
nodeCount: row.node_count,
|
|
102
144
|
errors: row.errors ? (0, utils_1.safeJsonParse)(row.errors, undefined) : undefined,
|
|
145
|
+
generated: row.generated === 1,
|
|
103
146
|
};
|
|
104
147
|
}
|
|
105
148
|
/**
|
|
@@ -112,9 +155,16 @@ class QueryBuilder {
|
|
|
112
155
|
// whole project, not a symbol, so it carries no discriminative signal (#720).
|
|
113
156
|
// Set once by the CodeGraph instance; empty by default (no down-weighting).
|
|
114
157
|
projectNameTokens = new Set();
|
|
158
|
+
isDeprioritizedPath;
|
|
159
|
+
// FTS5 availability flag — detected once at construction time (#1532)
|
|
160
|
+
_fts5Available;
|
|
115
161
|
// Node cache for frequently accessed nodes (LRU-style, max 1000 entries)
|
|
116
162
|
nodeCache = new Map();
|
|
117
163
|
maxCacheSize = 1000;
|
|
164
|
+
// getDominantFile()'s answer, tagged with the database change stamp it was
|
|
165
|
+
// computed under (see getChangeStamp). Query-independent, so one value
|
|
166
|
+
// serves every explore until the database changes (#1864).
|
|
167
|
+
dominantFileMemo;
|
|
118
168
|
// Prepared statements (lazily initialized)
|
|
119
169
|
stmts = {};
|
|
120
170
|
// Names whose segments were already written this session — skips re-splitting
|
|
@@ -131,6 +181,11 @@ class QueryBuilder {
|
|
|
131
181
|
// (and therefore resolution's insertion-order disambiguation) is identical
|
|
132
182
|
// to the one-row-per-run path.
|
|
133
183
|
batchStmts = new Map();
|
|
184
|
+
// Kind-filtered edge reads build their SQL per call (a variable IN list),
|
|
185
|
+
// but from a handful of kind sets: prepare each shape once. Supertype walks
|
|
186
|
+
// and the member-lookup passes issue them per node, and preparing cost
|
|
187
|
+
// about a third of the read.
|
|
188
|
+
edgeKindStmts = new Map();
|
|
134
189
|
static BATCH_SIZES = [128, 32, 8, 1];
|
|
135
190
|
/**
|
|
136
191
|
* Run `rows` through a multi-row `INSERT` built as `head + (tuple,)*n`,
|
|
@@ -166,6 +221,14 @@ class QueryBuilder {
|
|
|
166
221
|
}
|
|
167
222
|
constructor(db) {
|
|
168
223
|
this.db = db;
|
|
224
|
+
// Detect FTS5 availability once (#1532)
|
|
225
|
+
try {
|
|
226
|
+
db.prepare("SELECT * FROM nodes_fts LIMIT 0").get();
|
|
227
|
+
this._fts5Available = true;
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
this._fts5Available = false;
|
|
231
|
+
}
|
|
169
232
|
}
|
|
170
233
|
/**
|
|
171
234
|
* Swap the underlying connection in place. Used by pool workers'
|
|
@@ -183,6 +246,21 @@ class QueryBuilder {
|
|
|
183
246
|
this.db = db;
|
|
184
247
|
this.stmts = {};
|
|
185
248
|
this.batchStmts.clear();
|
|
249
|
+
this.edgeKindStmts.clear();
|
|
250
|
+
// The change stamp is per connection, and fresh connections to two
|
|
251
|
+
// different databases report the same one — the memo goes with the old
|
|
252
|
+
// connection, or a worker following a rebuilt index keeps its answer (#1864).
|
|
253
|
+
this.dominantFileMemo = undefined;
|
|
254
|
+
}
|
|
255
|
+
edgeKindStmt(sql) {
|
|
256
|
+
let stmt = this.edgeKindStmts.get(sql);
|
|
257
|
+
if (!stmt) {
|
|
258
|
+
if (this.edgeKindStmts.size >= 64)
|
|
259
|
+
this.edgeKindStmts.delete(this.edgeKindStmts.keys().next().value);
|
|
260
|
+
stmt = this.db.prepare(sql);
|
|
261
|
+
this.edgeKindStmts.set(sql, stmt);
|
|
262
|
+
}
|
|
263
|
+
return stmt;
|
|
186
264
|
}
|
|
187
265
|
/** Set the normalized project-name tokens used to down-weight non-discriminative
|
|
188
266
|
* query words in path scoring (#720). Called once when the project opens. */
|
|
@@ -193,6 +271,19 @@ class QueryBuilder {
|
|
|
193
271
|
getProjectNameTokens() {
|
|
194
272
|
return this.projectNameTokens;
|
|
195
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Set the predicate that marks a path as de-prioritized by the project's
|
|
276
|
+
* `codegraph.json` `deprioritize` patterns (#982). Ranking-only: those paths
|
|
277
|
+
* stay indexed and findable, they just stop outranking first-party code.
|
|
278
|
+
* Called once when the project opens; undefined disables the lever.
|
|
279
|
+
*/
|
|
280
|
+
setDeprioritizedPathMatcher(matcher) {
|
|
281
|
+
this.isDeprioritizedPath = matcher;
|
|
282
|
+
}
|
|
283
|
+
/** The `deprioritize` predicate (#982), so other rankers apply the same lever. */
|
|
284
|
+
getDeprioritizedPathMatcher() {
|
|
285
|
+
return this.isDeprioritizedPath;
|
|
286
|
+
}
|
|
196
287
|
// ===========================================================================
|
|
197
288
|
// Node Operations
|
|
198
289
|
// ===========================================================================
|
|
@@ -648,10 +739,16 @@ class QueryBuilder {
|
|
|
648
739
|
const uniqueIds = [...new Set(ids)];
|
|
649
740
|
for (let i = 0; i < uniqueIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
650
741
|
const chunk = uniqueIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
742
|
+
// Every edge insert checks its endpoints here, a chunk at a time: the
|
|
743
|
+
// full-size statement is prepared once, the final partial chunk ad hoc.
|
|
744
|
+
let stmt;
|
|
745
|
+
if (chunk.length === SQLITE_PARAM_CHUNK_SIZE) {
|
|
746
|
+
stmt = this.stmts.existingNodeIdsFull ??= this.db.prepare(`SELECT id FROM nodes WHERE id IN (${new Array(SQLITE_PARAM_CHUNK_SIZE).fill('?').join(',')})`);
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
stmt = this.db.prepare(`SELECT id FROM nodes WHERE id IN (${chunk.map(() => '?').join(',')})`);
|
|
750
|
+
}
|
|
751
|
+
const rows = stmt.all(...chunk);
|
|
655
752
|
for (const row of rows) {
|
|
656
753
|
out.add(row.id);
|
|
657
754
|
}
|
|
@@ -677,16 +774,58 @@ class QueryBuilder {
|
|
|
677
774
|
clearCache() {
|
|
678
775
|
this.nodeCache.clear();
|
|
679
776
|
}
|
|
777
|
+
/**
|
|
778
|
+
* Whether any node in `filePath` is exported — `getNodesByFile(f).some((n) =>
|
|
779
|
+
* n.isExported)` as one indexed probe, without decoding the file's nodes.
|
|
780
|
+
*/
|
|
781
|
+
fileHasExportedNode(filePath) {
|
|
782
|
+
if (!this.stmts.fileHasExportedNode) {
|
|
783
|
+
this.stmts.fileHasExportedNode = this.db.prepare('SELECT 1 FROM nodes WHERE file_path = ? AND is_exported = 1 LIMIT 1');
|
|
784
|
+
}
|
|
785
|
+
return this.stmts.fileHasExportedNode.get(filePath) !== undefined;
|
|
786
|
+
}
|
|
787
|
+
/** The exported nodes of a file, in {@link getNodesByFile} order, decoding only those rows. */
|
|
788
|
+
getExportedNodesByFile(filePath) {
|
|
789
|
+
if (!this.stmts.getExportedNodesByFile) {
|
|
790
|
+
this.stmts.getExportedNodesByFile = this.db.prepare('SELECT * FROM nodes WHERE file_path = ? AND is_exported = 1 ORDER BY start_line, id');
|
|
791
|
+
}
|
|
792
|
+
return this.stmts.getExportedNodesByFile.all(filePath).map(rowToNode);
|
|
793
|
+
}
|
|
794
|
+
/** The nodes of a file with one name, in {@link getNodesByFile} order, decoding only those rows. */
|
|
795
|
+
getNodesByFileAndName(filePath, name) {
|
|
796
|
+
if (!this.stmts.getNodesByFileAndName) {
|
|
797
|
+
this.stmts.getNodesByFileAndName = this.db.prepare('SELECT * FROM nodes WHERE file_path = ? AND name = ? ORDER BY start_line, id');
|
|
798
|
+
}
|
|
799
|
+
return this.stmts.getNodesByFileAndName.all(filePath, name).map(rowToNode);
|
|
800
|
+
}
|
|
680
801
|
/**
|
|
681
802
|
* Get all nodes in a file
|
|
682
803
|
*/
|
|
683
804
|
getNodesByFile(filePath) {
|
|
684
805
|
if (!this.stmts.getNodesByFile) {
|
|
685
|
-
this.stmts.getNodesByFile = this.db.prepare('SELECT * FROM nodes WHERE file_path = ? ORDER BY start_line');
|
|
806
|
+
this.stmts.getNodesByFile = this.db.prepare('SELECT * FROM nodes WHERE file_path = ? ORDER BY start_line, id');
|
|
686
807
|
}
|
|
687
808
|
const rows = this.stmts.getNodesByFile.all(filePath);
|
|
688
809
|
return rows.map(rowToNode);
|
|
689
810
|
}
|
|
811
|
+
/**
|
|
812
|
+
* Get all nodes in several files at once — one chunked `IN` query rather than
|
|
813
|
+
* one {@link getNodesByFile} per file (#1975).
|
|
814
|
+
*/
|
|
815
|
+
getNodesByFiles(filePaths) {
|
|
816
|
+
const unique = [...new Set(filePaths)];
|
|
817
|
+
const out = [];
|
|
818
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
819
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
820
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
821
|
+
const rows = this.db
|
|
822
|
+
.prepare(`SELECT * FROM nodes WHERE file_path IN (${placeholders})`)
|
|
823
|
+
.all(...chunk);
|
|
824
|
+
for (const row of rows)
|
|
825
|
+
out.push(rowToNode(row));
|
|
826
|
+
}
|
|
827
|
+
return out;
|
|
828
|
+
}
|
|
690
829
|
/**
|
|
691
830
|
* Find the file that holds the densest concentration of the project's
|
|
692
831
|
* internal call graph — the "core" file. Used by context-builder to
|
|
@@ -704,8 +843,46 @@ class QueryBuilder {
|
|
|
704
843
|
* Excludes test/spec files from candidacy via path-pattern. The agent's
|
|
705
844
|
* typical question is "how does X work", not "how is X tested", so
|
|
706
845
|
* boosting a test file's directory would be a misfire.
|
|
846
|
+
*
|
|
847
|
+
* The answer depends only on the graph, never on the query, and the
|
|
848
|
+
* aggregation behind it scans every edge — seconds on a large index, paid
|
|
849
|
+
* by every generic explore (#1864). So it is memoized per database change
|
|
850
|
+
* stamp: recomputed only after something wrote to the database.
|
|
707
851
|
*/
|
|
708
852
|
getDominantFile() {
|
|
853
|
+
// total_changes() counts writes that are later rolled back, so a result
|
|
854
|
+
// read inside a transaction could outlive a ROLLBACK under an unchanged
|
|
855
|
+
// stamp. Never keep one; `undefined` (a runtime without the getter) is
|
|
856
|
+
// treated the same way.
|
|
857
|
+
if (this.db.inTransaction !== false) {
|
|
858
|
+
this.dominantFileMemo = undefined;
|
|
859
|
+
return this.computeDominantFile();
|
|
860
|
+
}
|
|
861
|
+
const stamp = this.getChangeStamp();
|
|
862
|
+
if (this.dominantFileMemo?.stamp === stamp)
|
|
863
|
+
return this.dominantFileMemo.value;
|
|
864
|
+
const value = this.computeDominantFile();
|
|
865
|
+
this.dominantFileMemo = { stamp, value };
|
|
866
|
+
return value;
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* A value that differs whenever the database content may have changed
|
|
870
|
+
* since the last call, whoever changed it: `total_changes()` counts the
|
|
871
|
+
* rows this connection inserted, updated or deleted, and
|
|
872
|
+
* `PRAGMA data_version` moves when any OTHER connection — another process's
|
|
873
|
+
* sync, a CLI `codegraph index` beside a running MCP server — commits. Both
|
|
874
|
+
* are O(1), so no write path has to remember to invalidate anything.
|
|
875
|
+
* Coarse on purpose: any write, not just one to nodes/edges, forces a
|
|
876
|
+
* recompute, which only costs time, never a stale answer.
|
|
877
|
+
*/
|
|
878
|
+
getChangeStamp() {
|
|
879
|
+
if (!this.stmts.getChangeStamp) {
|
|
880
|
+
this.stmts.getChangeStamp = this.db.prepare('SELECT total_changes() AS changes, (SELECT data_version FROM pragma_data_version) AS version');
|
|
881
|
+
}
|
|
882
|
+
const row = this.stmts.getChangeStamp.get();
|
|
883
|
+
return `${row.changes}:${row.version}`;
|
|
884
|
+
}
|
|
885
|
+
computeDominantFile() {
|
|
709
886
|
if (!this.stmts.getDominantFile) {
|
|
710
887
|
// Pull top 20 candidates; we then filter out test/generated files
|
|
711
888
|
// in code (regex-grade matching that SQL LIKE can't express). The
|
|
@@ -726,7 +903,8 @@ class QueryBuilder {
|
|
|
726
903
|
`);
|
|
727
904
|
}
|
|
728
905
|
const rows = this.stmts.getDominantFile.all();
|
|
729
|
-
const
|
|
906
|
+
const generated = this.getGeneratedPathsAmong(rows.map(r => r.file_path));
|
|
907
|
+
const filtered = rows.filter(r => !isLowValueFile(r.file_path, generated));
|
|
730
908
|
if (filtered.length === 0 || filtered[0].edge_count < 20)
|
|
731
909
|
return null;
|
|
732
910
|
return {
|
|
@@ -759,7 +937,8 @@ class QueryBuilder {
|
|
|
759
937
|
`);
|
|
760
938
|
}
|
|
761
939
|
const rows = this.stmts.getTopRouteFile.all();
|
|
762
|
-
const
|
|
940
|
+
const generated = this.getGeneratedPathsAmong(rows.map(r => r.file_path));
|
|
941
|
+
const filtered = rows.filter(r => !isLowValueFile(r.file_path, generated));
|
|
763
942
|
if (filtered.length === 0)
|
|
764
943
|
return null;
|
|
765
944
|
const totalRoutes = filtered.reduce((sum, r) => sum + r.cnt, 0);
|
|
@@ -789,6 +968,9 @@ class QueryBuilder {
|
|
|
789
968
|
this.stmts.getRoutingManifest = this.db.prepare(`
|
|
790
969
|
SELECT
|
|
791
970
|
r.name AS url,
|
|
971
|
+
r.id AS route_id,
|
|
972
|
+
r.file_path AS route_file,
|
|
973
|
+
r.start_line AS route_line,
|
|
792
974
|
h.name AS handler,
|
|
793
975
|
h.file_path AS handler_file,
|
|
794
976
|
h.start_line AS handler_line,
|
|
@@ -798,14 +980,15 @@ class QueryBuilder {
|
|
|
798
980
|
JOIN nodes h ON e.target = h.id
|
|
799
981
|
WHERE r.kind = 'route'
|
|
800
982
|
AND e.kind IN ('references', 'calls')
|
|
801
|
-
AND h.kind IN ('function', 'method', 'class')
|
|
983
|
+
AND h.kind IN ('function', 'method', 'class', 'constant', 'variable')
|
|
802
984
|
ORDER BY r.file_path, r.start_line
|
|
803
985
|
LIMIT ?
|
|
804
986
|
`);
|
|
805
987
|
}
|
|
806
988
|
const rows = this.stmts.getRoutingManifest.all(limit);
|
|
807
989
|
// Drop test/generated handlers — same hygiene as elsewhere.
|
|
808
|
-
const
|
|
990
|
+
const generated = this.getGeneratedPathsAmong(rows.map(r => r.handler_file));
|
|
991
|
+
const filtered = rows.filter(r => !isLowValueFile(r.handler_file, generated));
|
|
809
992
|
if (filtered.length < 3)
|
|
810
993
|
return null;
|
|
811
994
|
// Identify the file holding the most handlers (the "primary handler file").
|
|
@@ -828,6 +1011,9 @@ class QueryBuilder {
|
|
|
828
1011
|
handlerFile: r.handler_file,
|
|
829
1012
|
handlerLine: r.handler_line,
|
|
830
1013
|
handlerKind: r.handler_kind,
|
|
1014
|
+
routeId: r.route_id,
|
|
1015
|
+
routeFile: r.route_file,
|
|
1016
|
+
routeLine: r.route_line,
|
|
831
1017
|
})),
|
|
832
1018
|
topHandlerFile,
|
|
833
1019
|
topHandlerFileCount,
|
|
@@ -839,7 +1025,7 @@ class QueryBuilder {
|
|
|
839
1025
|
*/
|
|
840
1026
|
getNodesByKind(kind) {
|
|
841
1027
|
if (!this.stmts.getNodesByKind) {
|
|
842
|
-
this.stmts.getNodesByKind = this.db.prepare('SELECT * FROM nodes WHERE kind = ?');
|
|
1028
|
+
this.stmts.getNodesByKind = this.db.prepare('SELECT * FROM nodes WHERE kind = ? ORDER BY file_path, start_line, id');
|
|
843
1029
|
}
|
|
844
1030
|
const rows = this.stmts.getNodesByKind.all(kind);
|
|
845
1031
|
return rows.map(rowToNode);
|
|
@@ -854,11 +1040,29 @@ class QueryBuilder {
|
|
|
854
1040
|
*iterateNodesByKind(kind) {
|
|
855
1041
|
// Fresh statement per call (not a cached one): an iterator holds an open
|
|
856
1042
|
// cursor, so a shared statement would conflict across overlapping scans.
|
|
857
|
-
|
|
1043
|
+
// Synthesis uses first/last-match precedence and caps: insertion order
|
|
1044
|
+
// changes on sync. idx_nodes_kind streams this canonical order without
|
|
1045
|
+
// materializing/sorting all of a large project's methods in memory.
|
|
1046
|
+
const stmt = this.db.prepare('SELECT * FROM nodes WHERE kind = ? ORDER BY file_path, start_line, id');
|
|
858
1047
|
for (const row of stmt.iterate(kind)) {
|
|
859
1048
|
yield rowToNode(row);
|
|
860
1049
|
}
|
|
861
1050
|
}
|
|
1051
|
+
/**
|
|
1052
|
+
* iterateNodesByKind narrowed to some languages, in the same canonical
|
|
1053
|
+
* order — the ORDER BY is total (`id` is unique), so this yields exactly the
|
|
1054
|
+
* nodes a caller filtering iterateNodesByKind by language would keep, in the
|
|
1055
|
+
* same sequence. A Go pass on a TypeScript monorepo otherwise materialized
|
|
1056
|
+
* every method in the project to find a couple of Go ones.
|
|
1057
|
+
*/
|
|
1058
|
+
*iterateNodesByKindIn(kind, languages) {
|
|
1059
|
+
if (languages.length === 0)
|
|
1060
|
+
return;
|
|
1061
|
+
const stmt = this.db.prepare(`SELECT * FROM nodes WHERE kind = ? AND language IN (${languages.map(() => '?').join(', ')}) ORDER BY file_path, start_line, id`);
|
|
1062
|
+
for (const row of stmt.iterate(kind, ...languages)) {
|
|
1063
|
+
yield rowToNode(row);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
862
1066
|
/**
|
|
863
1067
|
* Get all nodes in the database
|
|
864
1068
|
*/
|
|
@@ -878,7 +1082,7 @@ class QueryBuilder {
|
|
|
878
1082
|
*iterateNodesByLanguageWithDecorator(language, decorator) {
|
|
879
1083
|
// Fresh statement per call — an iterator holds an open cursor (see
|
|
880
1084
|
// iterateNodesByKind).
|
|
881
|
-
const stmt = this.db.prepare("SELECT * FROM nodes WHERE language = ? AND decorators LIKE '%' || ? || '%'");
|
|
1085
|
+
const stmt = this.db.prepare("SELECT * FROM nodes WHERE language = ? AND decorators LIKE '%' || ? || '%' ORDER BY file_path, start_line, id");
|
|
882
1086
|
for (const row of stmt.iterate(language, `"${decorator}"`)) {
|
|
883
1087
|
yield rowToNode(row);
|
|
884
1088
|
}
|
|
@@ -894,11 +1098,26 @@ class QueryBuilder {
|
|
|
894
1098
|
return new Set(rows.map((r) => r.language));
|
|
895
1099
|
}
|
|
896
1100
|
/**
|
|
897
|
-
* Get nodes by exact name match (uses idx_nodes_name index)
|
|
1101
|
+
* Get nodes by exact name match (uses idx_nodes_name index).
|
|
1102
|
+
*
|
|
1103
|
+
* This is resolution's candidate list, and the ORDER BY is load-bearing for
|
|
1104
|
+
* index correctness, not cosmetic (CG-33). When a reference names a symbol
|
|
1105
|
+
* that several files define and nothing disambiguates them, resolution binds
|
|
1106
|
+
* to the first candidate — so without an ORDER BY the winner was decided by
|
|
1107
|
+
* rowid, i.e. by the order files happened to be WRITTEN. A full index writes
|
|
1108
|
+
* them in scan order; an incremental sync appends each file as it changes, so
|
|
1109
|
+
* the same tree resolved to different edges depending on how the index was
|
|
1110
|
+
* built, and a long-lived synced index drifted away from a rebuild of itself
|
|
1111
|
+
* (measured at 4.3% of distinct edges, mostly `calls`).
|
|
1112
|
+
*
|
|
1113
|
+
* `(file_path, start_line)` is a property of the CODE, so both paths now pick
|
|
1114
|
+
* the same candidate. The sort is paid once per distinct name per resolution
|
|
1115
|
+
* run — ReferenceResolver memoizes this in its nameCache — and the population
|
|
1116
|
+
* is capped by AMBIGUOUS_NAME_CEILING (#999).
|
|
898
1117
|
*/
|
|
899
1118
|
getNodesByName(name) {
|
|
900
1119
|
if (!this.stmts.getNodesByName) {
|
|
901
|
-
this.stmts.getNodesByName = this.db.prepare('SELECT * FROM nodes WHERE name = ?');
|
|
1120
|
+
this.stmts.getNodesByName = this.db.prepare('SELECT * FROM nodes WHERE name = ? ORDER BY file_path, start_line, id');
|
|
902
1121
|
}
|
|
903
1122
|
const rows = this.stmts.getNodesByName.all(name);
|
|
904
1123
|
return rows.map(rowToNode);
|
|
@@ -914,24 +1133,43 @@ class QueryBuilder {
|
|
|
914
1133
|
const rows = this.stmts.getNodesByNamePrefix.all(prefix, prefix + '', limit);
|
|
915
1134
|
return rows.map(rowToNode);
|
|
916
1135
|
}
|
|
1136
|
+
/** File nodes whose basename starts with `prefix`, without a result cap. */
|
|
1137
|
+
getFileNodesByNamePrefix(prefix) {
|
|
1138
|
+
if (!this.stmts.getFileNodesByNamePrefix) {
|
|
1139
|
+
this.stmts.getFileNodesByNamePrefix = this.db.prepare("SELECT * FROM nodes WHERE kind = 'file' AND name >= ? AND name < ? ORDER BY name");
|
|
1140
|
+
}
|
|
1141
|
+
const rows = this.stmts.getFileNodesByNamePrefix.all(prefix, prefix + '');
|
|
1142
|
+
return rows.map(rowToNode);
|
|
1143
|
+
}
|
|
917
1144
|
/**
|
|
918
1145
|
* Get nodes by exact qualified name match (uses idx_nodes_qualified_name index)
|
|
919
1146
|
*/
|
|
920
1147
|
getNodesByQualifiedNameExact(qualifiedName) {
|
|
921
1148
|
if (!this.stmts.getNodesByQualifiedNameExact) {
|
|
922
|
-
this.stmts.getNodesByQualifiedNameExact = this.db.prepare('SELECT * FROM nodes WHERE qualified_name = ?');
|
|
1149
|
+
this.stmts.getNodesByQualifiedNameExact = this.db.prepare('SELECT * FROM nodes WHERE qualified_name = ? ORDER BY file_path, start_line, id');
|
|
923
1150
|
}
|
|
924
1151
|
const rows = this.stmts.getNodesByQualifiedNameExact.all(qualifiedName);
|
|
925
1152
|
return rows.map(rowToNode);
|
|
926
1153
|
}
|
|
927
1154
|
/**
|
|
928
|
-
* Get nodes by
|
|
1155
|
+
* Get nodes by name, case-insensitively (seeks the idx_nodes_lower_name
|
|
1156
|
+
* expression index).
|
|
1157
|
+
*
|
|
1158
|
+
* The parameter is lowered in SQL rather than trusted to arrive lowered, so
|
|
1159
|
+
* the lookup means the same thing whatever casing a caller hands it. Written
|
|
1160
|
+
* as a bare `lower(name) = ?` it silently returned nothing for any input
|
|
1161
|
+
* carrying an uppercase letter, and — because SQLite's `lower()` folds ASCII
|
|
1162
|
+
* only while JavaScript's `.toLowerCase()` folds Unicode — a caller that
|
|
1163
|
+
* pre-lowered in JavaScript could not match a non-ASCII name at all.
|
|
1164
|
+
*
|
|
1165
|
+
* Note this hardens the query, not its one caller: `matchFuzzy` still lowers
|
|
1166
|
+
* in JavaScript before calling, so the non-ASCII gap remains open there.
|
|
929
1167
|
*/
|
|
930
|
-
getNodesByLowerName(
|
|
1168
|
+
getNodesByLowerName(name) {
|
|
931
1169
|
if (!this.stmts.getNodesByLowerName) {
|
|
932
|
-
this.stmts.getNodesByLowerName = this.db.prepare('SELECT * FROM nodes WHERE lower(name) = ?');
|
|
1170
|
+
this.stmts.getNodesByLowerName = this.db.prepare('SELECT * FROM nodes WHERE lower(name) = lower(?)');
|
|
933
1171
|
}
|
|
934
|
-
const rows = this.stmts.getNodesByLowerName.all(
|
|
1172
|
+
const rows = this.stmts.getNodesByLowerName.all(name);
|
|
935
1173
|
return rows.map(rowToNode);
|
|
936
1174
|
}
|
|
937
1175
|
/**
|
|
@@ -964,9 +1202,9 @@ class QueryBuilder {
|
|
|
964
1202
|
const text = parsed.text;
|
|
965
1203
|
const kinds = mergedKinds;
|
|
966
1204
|
const languages = mergedLanguages;
|
|
967
|
-
// First try FTS5 with prefix matching
|
|
1205
|
+
// First try FTS5 with prefix matching (skip if FTS5 not available, #1532)
|
|
968
1206
|
let results = text
|
|
969
|
-
? this.searchNodesFTS(text, { kinds, languages, limit, offset })
|
|
1207
|
+
? (this._fts5Available !== false ? this.searchNodesFTS(text, { kinds, languages, limit, offset }) : [])
|
|
970
1208
|
// Over-fetch by 5× when running filter-only (no text). The
|
|
971
1209
|
// post-scoring path: + name: filters can be very selective, so
|
|
972
1210
|
// a smaller multiplier risks returning fewer than `limit`
|
|
@@ -989,12 +1227,25 @@ class QueryBuilder {
|
|
|
989
1227
|
// pushing them past the FTS fetch limit before post-hoc scoring can help.
|
|
990
1228
|
// Use the max BM25 score as the base so the nameMatchBonus (exact=30 vs
|
|
991
1229
|
// prefix=20) actually differentiates them after rescoring.
|
|
1230
|
+
//
|
|
1231
|
+
// Whole-name equality MUST be written as `lower(name) = lower(?)` so it
|
|
1232
|
+
// seeks `idx_nodes_lower_name`. The equivalent `name = ? COLLATE NOCASE`
|
|
1233
|
+
// matches no index — `idx_nodes_name` is BINARY-collated and the expression
|
|
1234
|
+
// index only matches the same expression — and degrades to a full table
|
|
1235
|
+
// scan. The `LIMIT 20` does not rescue it: SQLite can only stop early once
|
|
1236
|
+
// it has produced 20 rows, and this runs once per query term, most of which
|
|
1237
|
+
// name nothing in the corpus. Measured per term on an unmatched term:
|
|
1238
|
+
// 0.08ms on gin (2.5k nodes), 0.39ms on excalidraw (11k), 2.4ms on django
|
|
1239
|
+
// (62k) — and growing with the corpus, where the seek is flat at ~0.002ms.
|
|
1240
|
+
// Lowering the parameter in SQL rather than in JS is deliberate: SQLite's
|
|
1241
|
+
// `lower()` and NOCASE both fold ASCII only, while JS `.toLowerCase()`
|
|
1242
|
+
// folds Unicode, which would silently stop matching non-ASCII names.
|
|
992
1243
|
if (results.length > 0 && query) {
|
|
993
1244
|
const existingIds = new Set(results.map(r => r.node.id));
|
|
994
1245
|
const maxFtsScore = Math.max(...results.map(r => r.score));
|
|
995
1246
|
const terms = query.split(/\s+/).filter(t => t.length >= 2);
|
|
996
1247
|
for (const term of terms) {
|
|
997
|
-
let sql = 'SELECT * FROM nodes WHERE name = ?
|
|
1248
|
+
let sql = 'SELECT * FROM nodes WHERE lower(name) = lower(?)';
|
|
998
1249
|
const params = [term];
|
|
999
1250
|
if (kinds && kinds.length > 0) {
|
|
1000
1251
|
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
@@ -1017,13 +1268,24 @@ class QueryBuilder {
|
|
|
1017
1268
|
// Apply multi-signal scoring
|
|
1018
1269
|
if (results.length > 0 && (text || query)) {
|
|
1019
1270
|
const scoringQuery = text || query;
|
|
1020
|
-
results = results.map(r =>
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1271
|
+
results = results.map(r => {
|
|
1272
|
+
// A path the project de-prioritized is saying its symbol NAMES are not
|
|
1273
|
+
// the answer, so the exact-name bonus has to be damped too. The -15 path
|
|
1274
|
+
// penalty alone cannot do it: the bonus is additive and larger (measured
|
|
1275
|
+
// on #982's repro, a `usage()` helper sat at 74.8 vs 51.2 for the top
|
|
1276
|
+
// product symbol — -15 lands at 59.8, still ahead). Damped, not zeroed,
|
|
1277
|
+
// so the tree stays findable when it genuinely is what you asked for.
|
|
1278
|
+
// Evaluated once and reused: the predicate stats the config file.
|
|
1279
|
+
const deprioritized = this.isDeprioritizedPath?.(r.node.filePath) ?? false;
|
|
1280
|
+
const nameBonus = (0, query_utils_1.nameMatchBonus)(r.node.name, scoringQuery);
|
|
1281
|
+
return {
|
|
1282
|
+
...r,
|
|
1283
|
+
score: r.score
|
|
1284
|
+
+ (0, query_utils_1.kindBonus)(r.node.kind)
|
|
1285
|
+
+ (0, query_utils_1.scorePathRelevance)(r.node.filePath, scoringQuery, this.projectNameTokens, deprioritized)
|
|
1286
|
+
+ (deprioritized ? Math.round(nameBonus * exports.DEPRIORITIZED_NAME_BONUS_SCALE) : nameBonus),
|
|
1287
|
+
};
|
|
1288
|
+
});
|
|
1027
1289
|
results.sort((a, b) => b.score - a.score);
|
|
1028
1290
|
// Trim to requested limit after rescoring
|
|
1029
1291
|
if (results.length > limit) {
|
|
@@ -1134,6 +1396,46 @@ class QueryBuilder {
|
|
|
1134
1396
|
}
|
|
1135
1397
|
return results;
|
|
1136
1398
|
}
|
|
1399
|
+
/** Bounded miss diagnostics, independent of relevance filters and ranking. */
|
|
1400
|
+
getExploreMissDiagnostics(query) {
|
|
1401
|
+
const words = [...new Set((query.match(/[\p{L}\p{N}]+/gu) ?? []).map(w => w.toLowerCase()))];
|
|
1402
|
+
const checked = words.filter(w => w.length <= 64).slice(0, 16);
|
|
1403
|
+
const limited = checked.length !== words.length;
|
|
1404
|
+
if (checked.length === 0)
|
|
1405
|
+
return { matched: [], unmatched: [], candidates: [], limited };
|
|
1406
|
+
// EXISTS uses FTS postings and the segment primary key, never source scans.
|
|
1407
|
+
// Vocab rows can outlive deleted definitions, so verify them against nodes.
|
|
1408
|
+
const rows = this.db.prepare(`
|
|
1409
|
+
WITH words(word, pattern) AS (VALUES ${checked.map(() => '(?, ?)').join(', ')})
|
|
1410
|
+
SELECT word, (
|
|
1411
|
+
EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH pattern)
|
|
1412
|
+
OR EXISTS (
|
|
1413
|
+
SELECT 1 FROM name_segment_vocab v WHERE v.segment = word
|
|
1414
|
+
AND EXISTS (SELECT 1 FROM nodes n WHERE n.name = v.name AND n.kind NOT IN ('file', 'import'))
|
|
1415
|
+
)
|
|
1416
|
+
) AS matched FROM words
|
|
1417
|
+
`).all(...checked.flatMap(w => [w, `{name qualified_name signature docstring} : "${w}"*`]));
|
|
1418
|
+
const names = this.db.prepare(`
|
|
1419
|
+
SELECT name FROM (
|
|
1420
|
+
SELECT v.name FROM name_segment_vocab v
|
|
1421
|
+
WHERE v.segment IN (${checked.map(() => '?').join(', ')})
|
|
1422
|
+
AND EXISTS (SELECT 1 FROM nodes n WHERE n.name = v.name AND n.kind NOT IN ('file', 'import'))
|
|
1423
|
+
LIMIT 12
|
|
1424
|
+
)
|
|
1425
|
+
UNION ALL
|
|
1426
|
+
SELECT name FROM (
|
|
1427
|
+
SELECT n.name FROM nodes_fts JOIN nodes n ON n.rowid = nodes_fts.rowid
|
|
1428
|
+
WHERE nodes_fts MATCH ? AND n.kind NOT IN ('file', 'import')
|
|
1429
|
+
LIMIT 12
|
|
1430
|
+
)
|
|
1431
|
+
`).all(...checked, `name : (${checked.map(w => `"${w}"*`).join(' OR ')})`);
|
|
1432
|
+
return {
|
|
1433
|
+
matched: rows.filter(r => r.matched).map(r => r.word),
|
|
1434
|
+
unmatched: rows.filter(r => !r.matched).map(r => r.word),
|
|
1435
|
+
candidates: [...new Set(names.map(r => r.name))].slice(0, 12),
|
|
1436
|
+
limited,
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1137
1439
|
/**
|
|
1138
1440
|
* FTS5 search with prefix matching
|
|
1139
1441
|
*/
|
|
@@ -1262,9 +1564,16 @@ class QueryBuilder {
|
|
|
1262
1564
|
// Pass 1: Find which files contain distinctive (rare) symbols from the query.
|
|
1263
1565
|
// Pass 2: Query each name, boosting results that co-locate with distinctive symbols.
|
|
1264
1566
|
// Pass 1: Find files containing each queried name, identify distinctive names
|
|
1567
|
+
//
|
|
1568
|
+
// Both passes spell whole-name equality as `lower(name) = lower(?)` so they
|
|
1569
|
+
// seek `idx_nodes_lower_name` — see the note in `searchNodes` for why the
|
|
1570
|
+
// `name = ? COLLATE NOCASE` form full-scans instead. This path is the one
|
|
1571
|
+
// that hurts most: it runs both passes for every symbol extracted from the
|
|
1572
|
+
// query, and extraction is generous, so most of those names are absent from
|
|
1573
|
+
// the corpus and never reach either LIMIT.
|
|
1265
1574
|
const nameToFiles = new Map();
|
|
1266
1575
|
for (const name of names) {
|
|
1267
|
-
let sql = 'SELECT DISTINCT file_path FROM nodes WHERE name
|
|
1576
|
+
let sql = 'SELECT DISTINCT file_path FROM nodes WHERE lower(name) = lower(?)';
|
|
1268
1577
|
const params = [name];
|
|
1269
1578
|
if (kinds && kinds.length > 0) {
|
|
1270
1579
|
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
@@ -1290,7 +1599,7 @@ class QueryBuilder {
|
|
|
1290
1599
|
let sql = `
|
|
1291
1600
|
SELECT nodes.*, 1.0 as score
|
|
1292
1601
|
FROM nodes
|
|
1293
|
-
WHERE name
|
|
1602
|
+
WHERE lower(name) = lower(?)
|
|
1294
1603
|
`;
|
|
1295
1604
|
const params = [name];
|
|
1296
1605
|
if (kinds && kinds.length > 0) {
|
|
@@ -1364,6 +1673,30 @@ class QueryBuilder {
|
|
|
1364
1673
|
// ===========================================================================
|
|
1365
1674
|
// Edge Operations
|
|
1366
1675
|
// ===========================================================================
|
|
1676
|
+
/** Must run before file replacement/deletion cascades the endpoint edges. */
|
|
1677
|
+
hasSynthesizedEdgesTouchingFile(filePath) {
|
|
1678
|
+
const owned = "CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.synthesizedBy') END IS NOT NULL";
|
|
1679
|
+
for (const endpoint of ['source', 'target']) {
|
|
1680
|
+
if (this.db.prepare(`SELECT 1 FROM nodes n JOIN edges e ON e.${endpoint} = n.id
|
|
1681
|
+
WHERE n.file_path = ? AND ${owned} LIMIT 1`).get(filePath))
|
|
1682
|
+
return true;
|
|
1683
|
+
}
|
|
1684
|
+
// Wiring often lives in a third file, with neither endpoint in it.
|
|
1685
|
+
return !!this.db.prepare(`SELECT 1 FROM edges e WHERE ${owned}
|
|
1686
|
+
AND CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.registeredAt') END >= ?
|
|
1687
|
+
AND CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.registeredAt') END < ? LIMIT 1`).get(`${filePath}:`, `${filePath};`);
|
|
1688
|
+
}
|
|
1689
|
+
wasSynthesisInput(filePath) {
|
|
1690
|
+
return !!this.db.prepare('SELECT 1 FROM synthesis_inputs WHERE file_path = ?').get(filePath);
|
|
1691
|
+
}
|
|
1692
|
+
replaceSynthesisInputs(files) {
|
|
1693
|
+
this.db.transaction(() => {
|
|
1694
|
+
this.db.exec('DELETE FROM synthesis_inputs');
|
|
1695
|
+
const insert = this.db.prepare('INSERT INTO synthesis_inputs(file_path) VALUES (?)');
|
|
1696
|
+
for (const file of files)
|
|
1697
|
+
insert.run(file);
|
|
1698
|
+
})();
|
|
1699
|
+
}
|
|
1367
1700
|
/**
|
|
1368
1701
|
* Insert a new edge
|
|
1369
1702
|
*/
|
|
@@ -1425,7 +1758,8 @@ class QueryBuilder {
|
|
|
1425
1758
|
this.stmts.deleteEdgesBySource.run(sourceId);
|
|
1426
1759
|
}
|
|
1427
1760
|
/**
|
|
1428
|
-
* Get outgoing edges from a node
|
|
1761
|
+
* Get outgoing edges from a node. Preserve the source/kind index order
|
|
1762
|
+
* (calls before imports/references), then break ties deterministically.
|
|
1429
1763
|
*/
|
|
1430
1764
|
getOutgoingEdges(sourceId, kinds, provenance) {
|
|
1431
1765
|
if ((kinds && kinds.length > 0) || provenance) {
|
|
@@ -1439,30 +1773,640 @@ class QueryBuilder {
|
|
|
1439
1773
|
sql += ' AND provenance = ?';
|
|
1440
1774
|
params.push(provenance);
|
|
1441
1775
|
}
|
|
1442
|
-
|
|
1776
|
+
sql += ' ORDER BY kind, target, line, col';
|
|
1777
|
+
const rows = this.edgeKindStmt(sql).all(...params);
|
|
1443
1778
|
return rows.map(rowToEdge);
|
|
1444
1779
|
}
|
|
1445
1780
|
if (!this.stmts.getEdgesBySource) {
|
|
1446
|
-
this.stmts.getEdgesBySource = this.db.prepare('SELECT * FROM edges WHERE source = ?');
|
|
1781
|
+
this.stmts.getEdgesBySource = this.db.prepare('SELECT * FROM edges WHERE source = ? ORDER BY kind, target, line, col');
|
|
1447
1782
|
}
|
|
1448
1783
|
const rows = this.stmts.getEdgesBySource.all(sourceId);
|
|
1449
1784
|
return rows.map(rowToEdge);
|
|
1450
1785
|
}
|
|
1451
1786
|
/**
|
|
1452
|
-
* Get incoming edges to a node
|
|
1787
|
+
* Get incoming edges to a node. Kind must precede opaque source IDs:
|
|
1788
|
+
* file IDs sort before function IDs, so source-first ordering lets imports
|
|
1789
|
+
* displace actual calls in capped caller lists. Keep deterministic ties
|
|
1790
|
+
* without changing the target/kind index's established kind precedence.
|
|
1453
1791
|
*/
|
|
1454
1792
|
getIncomingEdges(targetId, kinds) {
|
|
1455
1793
|
if (kinds && kinds.length > 0) {
|
|
1456
|
-
const sql = `SELECT * FROM edges WHERE target = ? AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
1457
|
-
const rows = this.
|
|
1794
|
+
const sql = `SELECT * FROM edges WHERE target = ? AND kind IN (${kinds.map(() => '?').join(',')}) ORDER BY kind, source, line, col`;
|
|
1795
|
+
const rows = this.edgeKindStmt(sql).all(targetId, ...kinds);
|
|
1458
1796
|
return rows.map(rowToEdge);
|
|
1459
1797
|
}
|
|
1460
1798
|
if (!this.stmts.getEdgesByTarget) {
|
|
1461
|
-
this.stmts.getEdgesByTarget = this.db.prepare('SELECT * FROM edges WHERE target = ?');
|
|
1799
|
+
this.stmts.getEdgesByTarget = this.db.prepare('SELECT * FROM edges WHERE target = ? ORDER BY kind, source, line, col');
|
|
1462
1800
|
}
|
|
1463
1801
|
const rows = this.stmts.getEdgesByTarget.all(targetId);
|
|
1464
1802
|
return rows.map(rowToEdge);
|
|
1465
1803
|
}
|
|
1804
|
+
/**
|
|
1805
|
+
* Outgoing edges for MANY source nodes in one query.
|
|
1806
|
+
*
|
|
1807
|
+
* The batch form of {@link getOutgoingEdges}. Building a nested outline needs
|
|
1808
|
+
* the `contains` edges of every container in a file at once; doing that one
|
|
1809
|
+
* source at a time is a query per symbol on files that have hundreds.
|
|
1810
|
+
*/
|
|
1811
|
+
getOutgoingEdgesFrom(sourceIds, kinds) {
|
|
1812
|
+
if (sourceIds.length === 0)
|
|
1813
|
+
return [];
|
|
1814
|
+
const unique = [...new Set(sourceIds)];
|
|
1815
|
+
const out = [];
|
|
1816
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1817
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1818
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1819
|
+
let sql = `SELECT * FROM edges WHERE source IN (${placeholders})`;
|
|
1820
|
+
const params = [...chunk];
|
|
1821
|
+
if (kinds && kinds.length > 0) {
|
|
1822
|
+
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
1823
|
+
params.push(...kinds);
|
|
1824
|
+
}
|
|
1825
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
1826
|
+
for (const row of rows)
|
|
1827
|
+
out.push(rowToEdge(row));
|
|
1828
|
+
}
|
|
1829
|
+
return out;
|
|
1830
|
+
}
|
|
1831
|
+
/**
|
|
1832
|
+
* Fan-in (total incoming edge count) for MANY nodes in one query.
|
|
1833
|
+
*
|
|
1834
|
+
* The per-node alternative — `getIncomingEdges(id).length` — is an indexed
|
|
1835
|
+
* lookup each, but a symbol screen rendering a couple of hundred callees
|
|
1836
|
+
* would issue a couple of hundred of them. Ids with no incoming edges are
|
|
1837
|
+
* absent from the map rather than present as 0, so callers can tell "no
|
|
1838
|
+
* edges" from "not asked about".
|
|
1839
|
+
*/
|
|
1840
|
+
countIncomingEdges(ids) {
|
|
1841
|
+
const out = new Map();
|
|
1842
|
+
if (ids.length === 0)
|
|
1843
|
+
return out;
|
|
1844
|
+
const unique = [...new Set(ids)];
|
|
1845
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1846
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1847
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1848
|
+
const rows = this.db
|
|
1849
|
+
.prepare(`SELECT target, COUNT(*) AS count FROM edges WHERE target IN (${placeholders}) GROUP BY target`)
|
|
1850
|
+
.all(...chunk);
|
|
1851
|
+
for (const row of rows)
|
|
1852
|
+
out.set(row.target, row.count);
|
|
1853
|
+
}
|
|
1854
|
+
return out;
|
|
1855
|
+
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Incoming edges for MANY target nodes in one query — the mirror of
|
|
1858
|
+
* {@link getOutgoingEdgesFrom}. Needed wherever a whole file's inbound edges
|
|
1859
|
+
* are wanted at once ("which files import anything in this one?").
|
|
1860
|
+
*/
|
|
1861
|
+
getIncomingEdgesTo(targetIds, kinds) {
|
|
1862
|
+
if (targetIds.length === 0)
|
|
1863
|
+
return [];
|
|
1864
|
+
const unique = [...new Set(targetIds)];
|
|
1865
|
+
const out = [];
|
|
1866
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1867
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1868
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1869
|
+
let sql = `SELECT * FROM edges WHERE target IN (${placeholders})`;
|
|
1870
|
+
const params = [...chunk];
|
|
1871
|
+
if (kinds && kinds.length > 0) {
|
|
1872
|
+
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
|
|
1873
|
+
params.push(...kinds);
|
|
1874
|
+
}
|
|
1875
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
1876
|
+
for (const row of rows)
|
|
1877
|
+
out.push(rowToEdge(row));
|
|
1878
|
+
}
|
|
1879
|
+
return out;
|
|
1880
|
+
}
|
|
1881
|
+
/**
|
|
1882
|
+
* Fan-out (total outgoing edge count) for MANY nodes in one query — the
|
|
1883
|
+
* mirror of {@link countIncomingEdges}. Ids with no outgoing edges are absent
|
|
1884
|
+
* from the map rather than present as 0.
|
|
1885
|
+
*/
|
|
1886
|
+
countOutgoingEdges(ids) {
|
|
1887
|
+
const out = new Map();
|
|
1888
|
+
if (ids.length === 0)
|
|
1889
|
+
return out;
|
|
1890
|
+
const unique = [...new Set(ids)];
|
|
1891
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1892
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1893
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1894
|
+
const rows = this.db
|
|
1895
|
+
.prepare(`SELECT source, COUNT(*) AS count FROM edges WHERE source IN (${placeholders}) GROUP BY source`)
|
|
1896
|
+
.all(...chunk);
|
|
1897
|
+
for (const row of rows)
|
|
1898
|
+
out.set(row.source, row.count);
|
|
1899
|
+
}
|
|
1900
|
+
return out;
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* Symbols nothing in the index points at — the candidate set behind the dead
|
|
1904
|
+
* code list (`src/graph/dead-code.ts`).
|
|
1905
|
+
*
|
|
1906
|
+
* "Points at" is every edge kind EXCEPT `contains`: a class containing a
|
|
1907
|
+
* method is structure, not use, and counting it would make every member look
|
|
1908
|
+
* reached by its own container. A self-edge is excluded for the same reason
|
|
1909
|
+
* a recursive function is not its own caller.
|
|
1910
|
+
*
|
|
1911
|
+
* One scan, one index probe per candidate. `NOT EXISTS` over
|
|
1912
|
+
* `idx_edges_target_kind` is what keeps it that way — the alternative
|
|
1913
|
+
* (`LEFT JOIN edges … GROUP BY`) builds a row per edge for the whole table
|
|
1914
|
+
* before discarding all but the empty groups. Ordered by position so the
|
|
1915
|
+
* answer is stable across runs and groups by file without a second sort.
|
|
1916
|
+
*
|
|
1917
|
+
* The result is deliberately NOT called dead code: an unreferenced symbol is
|
|
1918
|
+
* a symbol with no STATIC reference, and the caller applies the exclusions
|
|
1919
|
+
* (tests, generated files, overrides, unresolved names) that turn the
|
|
1920
|
+
* candidate set into a claim worth making.
|
|
1921
|
+
*/
|
|
1922
|
+
getUnreferencedNodes(kinds, limit) {
|
|
1923
|
+
if (kinds.length === 0 || limit <= 0)
|
|
1924
|
+
return [];
|
|
1925
|
+
const placeholders = kinds.map(() => '?').join(',');
|
|
1926
|
+
const rows = this.db
|
|
1927
|
+
.prepare(`SELECT n.*, COALESCE(f.generated, 0) AS file_generated
|
|
1928
|
+
FROM nodes n
|
|
1929
|
+
LEFT JOIN files f ON f.path = n.file_path
|
|
1930
|
+
WHERE n.kind IN (${placeholders})
|
|
1931
|
+
AND NOT EXISTS (
|
|
1932
|
+
SELECT 1 FROM edges e
|
|
1933
|
+
WHERE e.target = n.id
|
|
1934
|
+
AND e.kind != 'contains'
|
|
1935
|
+
AND e.source != n.id
|
|
1936
|
+
)
|
|
1937
|
+
ORDER BY n.file_path, n.start_line, n.name
|
|
1938
|
+
LIMIT ?`)
|
|
1939
|
+
.all(...kinds, limit);
|
|
1940
|
+
return rows.map((row) => ({ node: rowToNode(row), generated: row.file_generated === 1 }));
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Which of `names` the index holds an UNRESOLVED reference to.
|
|
1944
|
+
*
|
|
1945
|
+
* The point is honesty about our own blind spots. A `failed` row in
|
|
1946
|
+
* `unresolved_refs` records that some file referenced a name and the resolver
|
|
1947
|
+
* could not decide what it meant — so a symbol with that name cannot be
|
|
1948
|
+
* called unreferenced, whatever the edge table says. It is deliberately
|
|
1949
|
+
* matched loosely, on the reference name AND on its tail (`util.greet` →
|
|
1950
|
+
* `greet`), because the question being asked is "could this name be the one
|
|
1951
|
+
* we failed to follow", and a maybe has to count as a yes.
|
|
1952
|
+
*
|
|
1953
|
+
* Bounded-lookup like {@link getGeneratedPathsAmong}: the caller holds a
|
|
1954
|
+
* candidate list, so this is a chunked probe over `idx_unresolved_name`, not
|
|
1955
|
+
* a scan of the table.
|
|
1956
|
+
*/
|
|
1957
|
+
getUnresolvedNamesAmong(names) {
|
|
1958
|
+
const unique = [...new Set(names)].filter((name) => name.length > 0);
|
|
1959
|
+
const found = new Set();
|
|
1960
|
+
if (unique.length === 0)
|
|
1961
|
+
return found;
|
|
1962
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1963
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1964
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1965
|
+
const rows = this.db
|
|
1966
|
+
.prepare(`SELECT DISTINCT reference_name AS name FROM unresolved_refs
|
|
1967
|
+
WHERE reference_name IN (${placeholders})
|
|
1968
|
+
UNION
|
|
1969
|
+
SELECT DISTINCT name_tail AS name FROM unresolved_refs
|
|
1970
|
+
WHERE name_tail IN (${placeholders})`)
|
|
1971
|
+
.all(...chunk, ...chunk);
|
|
1972
|
+
for (const row of rows)
|
|
1973
|
+
found.add(row.name);
|
|
1974
|
+
}
|
|
1975
|
+
return found;
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Which of `nodeIds` extend or implement a type the resolver could not follow.
|
|
1979
|
+
* An ancestor outside the index (`React.Component`, `stream.Transform`, a
|
|
1980
|
+
* framework interface) leaves no edge, only this `extends` / `implements`
|
|
1981
|
+
* row, so it is the one record that such an ancestor exists (#1973).
|
|
1982
|
+
* Chunked probe over `idx_unresolved_from_node`.
|
|
1983
|
+
*/
|
|
1984
|
+
getUnresolvedSupertypeSourcesAmong(nodeIds) {
|
|
1985
|
+
const unique = [...new Set(nodeIds)];
|
|
1986
|
+
const found = new Set();
|
|
1987
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
1988
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
1989
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
1990
|
+
const rows = this.db
|
|
1991
|
+
.prepare(`SELECT DISTINCT from_node_id AS id FROM unresolved_refs
|
|
1992
|
+
WHERE from_node_id IN (${placeholders})
|
|
1993
|
+
AND reference_kind IN ('extends', 'implements')`)
|
|
1994
|
+
.all(...chunk);
|
|
1995
|
+
for (const row of rows)
|
|
1996
|
+
found.add(row.id);
|
|
1997
|
+
}
|
|
1998
|
+
return found;
|
|
1999
|
+
}
|
|
2000
|
+
/**
|
|
2001
|
+
* Which of `names` are carried by MORE THAN ONE symbol, at least one of which
|
|
2002
|
+
* something points at.
|
|
2003
|
+
*
|
|
2004
|
+
* The false positive this exists to kill: `CodeGraph.getTopRouteFile` calls
|
|
2005
|
+
* `this.queries.getTopRouteFile()`, and the resolver — which prefers a
|
|
2006
|
+
* same-name definition in the call site's own file — attaches that edge to
|
|
2007
|
+
* the *calling* method. One of the two ends up with a self-edge and the other
|
|
2008
|
+
* with nothing at all, and neither is unreferenced. From the edge table the
|
|
2009
|
+
* mis-resolution and a genuinely unused twin are the same picture, so the
|
|
2010
|
+
* claim is not made about either.
|
|
2011
|
+
*
|
|
2012
|
+
* Both halves of the condition are load-bearing. **More than one symbol**:
|
|
2013
|
+
* a uniquely-named function that only calls itself is genuinely dead, and
|
|
2014
|
+
* excluding every recursive function would gut the list. **Self-edges
|
|
2015
|
+
* counted**: the self-edge IS the fingerprint of the mis-resolution above, so
|
|
2016
|
+
* it has to count as evidence that this name resolves somewhere.
|
|
2017
|
+
*
|
|
2018
|
+
* Chunked probe over `idx_nodes_name`, bounded by the caller's candidate list.
|
|
2019
|
+
*/
|
|
2020
|
+
getAmbiguousReferencedNames(names) {
|
|
2021
|
+
const unique = [...new Set(names)].filter((name) => name.length > 0);
|
|
2022
|
+
const found = new Set();
|
|
2023
|
+
if (unique.length === 0)
|
|
2024
|
+
return found;
|
|
2025
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2026
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2027
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2028
|
+
const rows = this.db
|
|
2029
|
+
.prepare(`SELECT name FROM (
|
|
2030
|
+
SELECT n.name AS name,
|
|
2031
|
+
EXISTS (
|
|
2032
|
+
SELECT 1 FROM edges e
|
|
2033
|
+
WHERE e.target = n.id AND e.kind != 'contains'
|
|
2034
|
+
) AS referenced
|
|
2035
|
+
FROM nodes n
|
|
2036
|
+
WHERE n.name IN (${placeholders})
|
|
2037
|
+
)
|
|
2038
|
+
GROUP BY name
|
|
2039
|
+
HAVING COUNT(*) > 1 AND SUM(referenced) > 0`)
|
|
2040
|
+
.all(...chunk);
|
|
2041
|
+
for (const row of rows)
|
|
2042
|
+
found.add(row.name);
|
|
2043
|
+
}
|
|
2044
|
+
return found;
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Which of the given languages the index records an EXPORT marker for.
|
|
2048
|
+
*
|
|
2049
|
+
* A self-measurement, and the honest basis for a whole class of exclusion.
|
|
2050
|
+
* The dead code report's strongest filter is "exported symbols may be reached
|
|
2051
|
+
* from outside this repository" — and that filter silently does nothing for a
|
|
2052
|
+
* language whose exports are not recorded, either because the extractor does
|
|
2053
|
+
* not record them (Rust `pub`) or because the language has no such concept at
|
|
2054
|
+
* all (Python, C, Ruby: the header or the module IS the surface). Rather than
|
|
2055
|
+
* carry a table of which is which, ask the index: if nothing in this language
|
|
2056
|
+
* is marked exported, the filter did not run, and no claim about outside
|
|
2057
|
+
* reachability can be made for it.
|
|
2058
|
+
*
|
|
2059
|
+
* `idx_nodes_language` covers the grouping; the caller passes the handful of
|
|
2060
|
+
* languages its candidates are actually in.
|
|
2061
|
+
*/
|
|
2062
|
+
getLanguagesWithExports(languages) {
|
|
2063
|
+
const unique = [...new Set(languages)].filter((language) => language.length > 0);
|
|
2064
|
+
const found = new Set();
|
|
2065
|
+
if (unique.length === 0)
|
|
2066
|
+
return found;
|
|
2067
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2068
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2069
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2070
|
+
const rows = this.db
|
|
2071
|
+
.prepare(`SELECT language, MAX(is_exported) AS any_exported
|
|
2072
|
+
FROM nodes
|
|
2073
|
+
WHERE language IN (${placeholders})
|
|
2074
|
+
GROUP BY language`)
|
|
2075
|
+
.all(...chunk);
|
|
2076
|
+
for (const row of rows)
|
|
2077
|
+
if (row.any_exported === 1)
|
|
2078
|
+
found.add(row.language);
|
|
2079
|
+
}
|
|
2080
|
+
return found;
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* The nodes with the most DISTINCT dependents, most first.
|
|
2084
|
+
*
|
|
2085
|
+
* "Distinct" is the difference that matters: a helper called forty times from
|
|
2086
|
+
* one function has a fan-in of 40 but exactly one dependent. This counts the
|
|
2087
|
+
* second thing — the number a reader means by "N callers" — so the top of
|
|
2088
|
+
* this list is the set of symbols a change actually radiates furthest from.
|
|
2089
|
+
*
|
|
2090
|
+
* `contains` is excluded because it is structure, not dependency: counting it
|
|
2091
|
+
* would rank every file and class above the code they hold.
|
|
2092
|
+
*/
|
|
2093
|
+
getTopDependedOn(limit) {
|
|
2094
|
+
if (limit <= 0)
|
|
2095
|
+
return [];
|
|
2096
|
+
const rows = this.db
|
|
2097
|
+
.prepare(`SELECT target AS nodeId, COUNT(DISTINCT source) AS dependents
|
|
2098
|
+
FROM edges
|
|
2099
|
+
WHERE kind != 'contains' AND source != target
|
|
2100
|
+
GROUP BY target
|
|
2101
|
+
ORDER BY dependents DESC
|
|
2102
|
+
LIMIT ?`)
|
|
2103
|
+
.all(limit);
|
|
2104
|
+
return rows;
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* The graph's executable roots — files that RUN something at module level,
|
|
2108
|
+
* ranked by how much of the project they set in motion.
|
|
2109
|
+
*
|
|
2110
|
+
* The engine records a statement at the top level of a file as an edge from
|
|
2111
|
+
* the *file* node, so `src/bin/codegraph.ts` calling `program.parse()` at
|
|
2112
|
+
* module scope is a `calls` edge out of a `file`. That set is what makes the
|
|
2113
|
+
* roots of a dependency graph visible: a library module holds definitions and
|
|
2114
|
+
* runs nothing until someone imports it, while a CLI, a worker entry or a
|
|
2115
|
+
* build script does its work on the way down the file. `instantiates` counts
|
|
2116
|
+
* the same way — `new Server(...)` at module scope is the same act.
|
|
2117
|
+
*
|
|
2118
|
+
* A call made while initializing a module-level `variable` / `constant` —
|
|
2119
|
+
* `const service = new Service()`, `app = FastAPI()` — is attributed to the
|
|
2120
|
+
* declared name (#693), not to the file, so the file's own edges alone would
|
|
2121
|
+
* miss most of what a real entry point runs. Those names are the file's
|
|
2122
|
+
* top-level code too, so `tops` counts them alongside the file node.
|
|
2123
|
+
*
|
|
2124
|
+
* Ranking multiplies the two things an entry point does: it runs (calls), and
|
|
2125
|
+
* it wires the project together (distinct other files its symbols reach). One
|
|
2126
|
+
* alone is misleading — a registration table makes hundreds of module-level
|
|
2127
|
+
* calls into itself, and a barrel file imports everything and runs nothing.
|
|
2128
|
+
* The product puts the file that does both at the top.
|
|
2129
|
+
*/
|
|
2130
|
+
getTopCallingFiles(limit) {
|
|
2131
|
+
if (limit <= 0)
|
|
2132
|
+
return [];
|
|
2133
|
+
return this.db
|
|
2134
|
+
.prepare(`WITH tops AS (
|
|
2135
|
+
SELECT n.id AS file_id, n.id AS src
|
|
2136
|
+
FROM nodes n
|
|
2137
|
+
WHERE n.kind = 'file'
|
|
2138
|
+
UNION ALL
|
|
2139
|
+
SELECT c.source AS file_id, c.target AS src
|
|
2140
|
+
FROM edges c
|
|
2141
|
+
JOIN nodes f ON f.id = c.source
|
|
2142
|
+
JOIN nodes v ON v.id = c.target
|
|
2143
|
+
WHERE c.kind = 'contains'
|
|
2144
|
+
AND f.kind = 'file'
|
|
2145
|
+
AND v.kind IN ('variable', 'constant')
|
|
2146
|
+
),
|
|
2147
|
+
runs AS (
|
|
2148
|
+
SELECT t.file_id AS id, COUNT(*) AS calls
|
|
2149
|
+
FROM tops t
|
|
2150
|
+
JOIN edges e ON e.source = t.src
|
|
2151
|
+
WHERE e.kind IN ('calls', 'instantiates')
|
|
2152
|
+
GROUP BY t.file_id
|
|
2153
|
+
),
|
|
2154
|
+
cand AS (
|
|
2155
|
+
SELECT r.id AS id, n.file_path AS fp, r.calls AS calls
|
|
2156
|
+
FROM runs r JOIN nodes n ON n.id = r.id
|
|
2157
|
+
),
|
|
2158
|
+
wires AS (
|
|
2159
|
+
SELECT sn.file_path AS fp, COUNT(DISTINCT tn.file_path) AS reaches
|
|
2160
|
+
FROM edges e
|
|
2161
|
+
JOIN nodes sn ON sn.id = e.source
|
|
2162
|
+
JOIN nodes tn ON tn.id = e.target
|
|
2163
|
+
WHERE e.kind != 'contains'
|
|
2164
|
+
AND sn.file_path <> tn.file_path
|
|
2165
|
+
AND sn.file_path IN (SELECT fp FROM cand)
|
|
2166
|
+
GROUP BY sn.file_path
|
|
2167
|
+
)
|
|
2168
|
+
SELECT c.id AS nodeId,
|
|
2169
|
+
c.fp AS filePath,
|
|
2170
|
+
c.calls AS calls,
|
|
2171
|
+
COALESCE(w.reaches, 0) AS reaches,
|
|
2172
|
+
c.calls * (1 + COALESCE(w.reaches, 0)) AS score
|
|
2173
|
+
FROM cand c LEFT JOIN wires w ON w.fp = c.fp
|
|
2174
|
+
ORDER BY score DESC, calls DESC, filePath
|
|
2175
|
+
LIMIT ?`)
|
|
2176
|
+
.all(limit);
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* How many OTHER files depend on each of the given files.
|
|
2180
|
+
*
|
|
2181
|
+
* Counted through the symbols, not the file nodes: an `imports` edge points
|
|
2182
|
+
* at the imported symbol, so a file node almost never receives one and
|
|
2183
|
+
* counting edges into it would report every file as depended on by nobody.
|
|
2184
|
+
* Same-file edges are excluded, which is what makes zero mean "nothing else
|
|
2185
|
+
* in the index reaches into this file" — the honest reading of a root.
|
|
2186
|
+
*/
|
|
2187
|
+
getFileDependentCounts(filePaths) {
|
|
2188
|
+
if (filePaths.length === 0)
|
|
2189
|
+
return [];
|
|
2190
|
+
return this.db
|
|
2191
|
+
.prepare(`SELECT tn.file_path AS filePath, COUNT(DISTINCT sn.file_path) AS dependents
|
|
2192
|
+
FROM edges e
|
|
2193
|
+
JOIN nodes tn ON tn.id = e.target
|
|
2194
|
+
JOIN nodes sn ON sn.id = e.source
|
|
2195
|
+
WHERE e.kind != 'contains'
|
|
2196
|
+
AND tn.file_path IN (SELECT value FROM json_each(?))
|
|
2197
|
+
AND sn.file_path <> tn.file_path
|
|
2198
|
+
GROUP BY tn.file_path`)
|
|
2199
|
+
.all(JSON.stringify(filePaths));
|
|
2200
|
+
}
|
|
2201
|
+
/**
|
|
2202
|
+
* How far each of the given files reaches OUT: distinct other files its
|
|
2203
|
+
* symbols touch, and how many references that is.
|
|
2204
|
+
*
|
|
2205
|
+
* The mirror of {@link getFileDependentCounts}, and the same reasoning about
|
|
2206
|
+
* `contains` and same-file edges applies. It is driven from `nodes` rather
|
|
2207
|
+
* than from `edges` so the work is proportional to the files asked about —
|
|
2208
|
+
* the entry-points endpoint asks it about every test file in the index, and
|
|
2209
|
+
* an edge-first plan would scan the whole table to answer a question about a
|
|
2210
|
+
* tenth of it.
|
|
2211
|
+
*/
|
|
2212
|
+
getFileReachCounts(filePaths) {
|
|
2213
|
+
if (filePaths.length === 0)
|
|
2214
|
+
return [];
|
|
2215
|
+
return this.db
|
|
2216
|
+
.prepare(`SELECT sn.file_path AS filePath,
|
|
2217
|
+
COUNT(DISTINCT tn.file_path) AS reaches,
|
|
2218
|
+
COUNT(*) AS refs
|
|
2219
|
+
FROM nodes sn
|
|
2220
|
+
JOIN edges e ON e.source = sn.id
|
|
2221
|
+
JOIN nodes tn ON tn.id = e.target
|
|
2222
|
+
WHERE sn.file_path IN (SELECT value FROM json_each(?))
|
|
2223
|
+
AND e.kind != 'contains'
|
|
2224
|
+
AND tn.file_path <> sn.file_path
|
|
2225
|
+
GROUP BY sn.file_path`)
|
|
2226
|
+
.all(JSON.stringify(filePaths));
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* The `file` nodes for the given paths, in one query.
|
|
2230
|
+
*
|
|
2231
|
+
* A file's own node is what makes a file row navigable, and looking it up
|
|
2232
|
+
* with {@link getNodesInFile} means materialising every symbol in the file to
|
|
2233
|
+
* throw all but one away.
|
|
2234
|
+
*/
|
|
2235
|
+
getFileNodes(filePaths) {
|
|
2236
|
+
if (filePaths.length === 0)
|
|
2237
|
+
return [];
|
|
2238
|
+
const rows = this.db
|
|
2239
|
+
.prepare(`SELECT * FROM nodes
|
|
2240
|
+
WHERE kind = 'file'
|
|
2241
|
+
AND file_path IN (SELECT value FROM json_each(?))`)
|
|
2242
|
+
.all(JSON.stringify(filePaths));
|
|
2243
|
+
return rows.map(rowToNode);
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* Roll the whole edge table up to module granularity in one pass.
|
|
2247
|
+
*
|
|
2248
|
+
* The caller decides what a module IS — it hands in a file → module
|
|
2249
|
+
* assignment and gets back the cross-module traffic. That split is
|
|
2250
|
+
* deliberate: naming modules is a *policy* (top-level directories, a façade
|
|
2251
|
+
* file kept separate, a monorepo root) that belongs where the reader lives,
|
|
2252
|
+
* while grouping a million edges by it is *mechanics* that must happen in
|
|
2253
|
+
* SQLite. Doing the fold in JavaScript instead means materialising every
|
|
2254
|
+
* cross-file edge in memory; doing the naming in SQL means a tower of
|
|
2255
|
+
* `instr`/`substr` no one can read.
|
|
2256
|
+
*
|
|
2257
|
+
* The assignment lands in a TEMP table with a primary key, so the join is
|
|
2258
|
+
* indexed and the result set is bounded by modules², not by edges. Temp
|
|
2259
|
+
* tables live in SQLite's own temp database, so this stays valid against a
|
|
2260
|
+
* read-only main.
|
|
2261
|
+
*
|
|
2262
|
+
* Two result sets, because they need two different groupings over the same
|
|
2263
|
+
* join: `links` counts edges per (module, module, kind), and `pairs` names
|
|
2264
|
+
* the busiest symbol pairs behind each link (the map's tooltip). `pairs` is
|
|
2265
|
+
* ranked and cut inside SQLite — the un-cut grouping is the one thing here
|
|
2266
|
+
* that scales with distinct symbol names rather than with modules. Pairs are
|
|
2267
|
+
* ranked by `declared` before raw count, so a link's tooltip names the
|
|
2268
|
+
* symbols the source actually points at rather than whichever `has`/`get`
|
|
2269
|
+
* happened to name-match most often.
|
|
2270
|
+
*
|
|
2271
|
+
* `declared` is the subset of a link's edges that came from something the
|
|
2272
|
+
* source *writes down*: an import, a qualified name, an inheritance clause,
|
|
2273
|
+
* or a call through a typed receiver. It exists because bare name matching
|
|
2274
|
+
* (`resolvedBy: 'exact-match'`) is what invents cross-module links out of
|
|
2275
|
+
* common method names — `run`, `push`, `finish` — and a map that lets those
|
|
2276
|
+
* decide the layering puts the storage layer above the CLI.
|
|
2277
|
+
*/
|
|
2278
|
+
aggregateModuleGraph(assignments, options) {
|
|
2279
|
+
if (assignments.length === 0 || options.kinds.length === 0)
|
|
2280
|
+
return { links: [], pairs: [] };
|
|
2281
|
+
const CONFIDENCE = `COALESCE(json_extract(e.metadata, '$.confidence'), 1)`;
|
|
2282
|
+
const DECLARED = `(json_extract(e.metadata, '$.resolvedBy') IN ('import', 'qualified-name')
|
|
2283
|
+
OR e.kind IN ('extends', 'implements')
|
|
2284
|
+
OR (json_extract(e.metadata, '$.resolvedBy') = 'instance-method'
|
|
2285
|
+
AND ${CONFIDENCE} >= 0.9))`;
|
|
2286
|
+
this.db.exec('DROP TABLE IF EXISTS temp.cg_module_map');
|
|
2287
|
+
this.db.exec('CREATE TEMP TABLE cg_module_map (path TEXT PRIMARY KEY, mod TEXT NOT NULL)');
|
|
2288
|
+
try {
|
|
2289
|
+
const insert = this.db.prepare('INSERT OR REPLACE INTO cg_module_map (path, mod) VALUES (?, ?)');
|
|
2290
|
+
this.db.exec('BEGIN');
|
|
2291
|
+
try {
|
|
2292
|
+
for (const row of assignments)
|
|
2293
|
+
insert.run(row.filePath, row.module);
|
|
2294
|
+
this.db.exec('COMMIT');
|
|
2295
|
+
}
|
|
2296
|
+
catch (err) {
|
|
2297
|
+
this.db.exec('ROLLBACK');
|
|
2298
|
+
throw err;
|
|
2299
|
+
}
|
|
2300
|
+
// ONE pass over the edge table. Grouping by the symbol names as well as
|
|
2301
|
+
// the modules costs nothing extra in scan time — the join is what is
|
|
2302
|
+
// expensive — and it buys both results from a single scan. Measured on
|
|
2303
|
+
// this index inflated to 1.6M edges: 1.66s for this query against 3.0s
|
|
2304
|
+
// for the module-level and name-level queries run separately, which is
|
|
2305
|
+
// the difference between meeting and missing the map's cold budget on a
|
|
2306
|
+
// ten-thousand-file repository.
|
|
2307
|
+
const rows = this.db
|
|
2308
|
+
.prepare(`SELECT ms.mod AS source, mt.mod AS target, e.kind AS kind,
|
|
2309
|
+
sn.name AS "from", tn.name AS "to",
|
|
2310
|
+
SUM(CASE WHEN ${CONFIDENCE} >= ? THEN 1 ELSE 0 END) AS count,
|
|
2311
|
+
SUM(CASE WHEN ${CONFIDENCE} >= ? AND ${DECLARED} THEN 1 ELSE 0 END) AS declared,
|
|
2312
|
+
SUM(CASE WHEN ${CONFIDENCE} < ? THEN 1 ELSE 0 END) AS uncertain
|
|
2313
|
+
FROM edges e
|
|
2314
|
+
JOIN nodes sn ON sn.id = e.source
|
|
2315
|
+
JOIN nodes tn ON tn.id = e.target
|
|
2316
|
+
JOIN cg_module_map ms ON ms.path = sn.file_path
|
|
2317
|
+
JOIN cg_module_map mt ON mt.path = tn.file_path
|
|
2318
|
+
WHERE e.kind IN (SELECT value FROM json_each(?))
|
|
2319
|
+
AND ms.mod <> mt.mod
|
|
2320
|
+
GROUP BY ms.mod, mt.mod, e.kind, sn.name, tn.name`)
|
|
2321
|
+
.all(options.minConfidence, options.minConfidence, options.minConfidence, JSON.stringify(options.kinds));
|
|
2322
|
+
return foldModuleRows(rows, options);
|
|
2323
|
+
}
|
|
2324
|
+
finally {
|
|
2325
|
+
this.db.exec('DROP TABLE IF EXISTS temp.cg_module_map');
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
/**
|
|
2329
|
+
* Every ordered pair of files where one reaches into the other, once each.
|
|
2330
|
+
*
|
|
2331
|
+
* The input a cycle finder wants: file-level circular dependencies are the
|
|
2332
|
+
* strongly connected components of this graph. One query instead of the
|
|
2333
|
+
* dependency lookup per file that {@link GraphQueryManager.findCircularDependencies}
|
|
2334
|
+
* does — which matters because a cycle report is only interesting on a large
|
|
2335
|
+
* repo, and that is exactly where a query per file stops being affordable.
|
|
2336
|
+
*
|
|
2337
|
+
* `contains` is excluded (a file "contains" its own symbols, which is not a
|
|
2338
|
+
* dependency), and so are same-file edges and low-confidence name matches:
|
|
2339
|
+
* a cycle conjured by a common method name is a false alarm a reader cannot
|
|
2340
|
+
* check.
|
|
2341
|
+
*/
|
|
2342
|
+
getCrossFileDependencyPairs(minConfidence) {
|
|
2343
|
+
return this.db
|
|
2344
|
+
.prepare(`SELECT DISTINCT sn.file_path AS source, tn.file_path AS target
|
|
2345
|
+
FROM edges e
|
|
2346
|
+
JOIN nodes sn ON sn.id = e.source
|
|
2347
|
+
JOIN nodes tn ON tn.id = e.target
|
|
2348
|
+
WHERE e.kind <> 'contains'
|
|
2349
|
+
AND sn.file_path <> tn.file_path
|
|
2350
|
+
AND COALESCE(json_extract(e.metadata, '$.confidence'), 1) >= ?`)
|
|
2351
|
+
.all(minConfidence);
|
|
2352
|
+
}
|
|
2353
|
+
/**
|
|
2354
|
+
* Every unresolved reference recorded in one FILE, ordered by line.
|
|
2355
|
+
*
|
|
2356
|
+
* The per-symbol form above answers "what does this body reach that the
|
|
2357
|
+
* index does not hold". A whole-file reader asks the same question of every
|
|
2358
|
+
* line at once, and asking it one symbol at a time is a query per symbol —
|
|
2359
|
+
* 153 of them on this repo's largest file. `unresolved_refs.file_path` is
|
|
2360
|
+
* indexed, so this is one lookup whatever the file holds.
|
|
2361
|
+
*
|
|
2362
|
+
* `limit` bounds the answer rather than the work: the caller draws a marker
|
|
2363
|
+
* per row, and a generated file with fifty thousand of them would ship
|
|
2364
|
+
* megabytes to say something a count already says. Rows come back in line
|
|
2365
|
+
* order, so a cap trims the END of the file, which is at least legible.
|
|
2366
|
+
*/
|
|
2367
|
+
getUnresolvedReferencesInFile(filePath, limit = 5000) {
|
|
2368
|
+
if (!this.stmts.getUnresolvedInFile) {
|
|
2369
|
+
this.stmts.getUnresolvedInFile = this.db.prepare('SELECT * FROM unresolved_refs WHERE file_path = ? ORDER BY line, col LIMIT ?');
|
|
2370
|
+
}
|
|
2371
|
+
const rows = this.stmts.getUnresolvedInFile.all(filePath, limit);
|
|
2372
|
+
return rows.map((row) => ({
|
|
2373
|
+
fromNodeId: row.from_node_id,
|
|
2374
|
+
referenceName: row.reference_name,
|
|
2375
|
+
referenceKind: row.reference_kind,
|
|
2376
|
+
line: row.line,
|
|
2377
|
+
column: row.col,
|
|
2378
|
+
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
2379
|
+
filePath: row.file_path,
|
|
2380
|
+
language: row.language,
|
|
2381
|
+
rowId: row.id,
|
|
2382
|
+
}));
|
|
2383
|
+
}
|
|
2384
|
+
/**
|
|
2385
|
+
* References recorded against a symbol that never resolved to a node — the
|
|
2386
|
+
* calls and type mentions that leave the index (a third-party package, a
|
|
2387
|
+
* runtime builtin, a language construct extraction doesn't model).
|
|
2388
|
+
*
|
|
2389
|
+
* Read-only. It exists so a reader can say "N calls into symbols outside the
|
|
2390
|
+
* index" instead of silently showing a callee list shorter than the body's
|
|
2391
|
+
* call sites, which reads as "nothing else happens here".
|
|
2392
|
+
*/
|
|
2393
|
+
getUnresolvedReferencesFrom(fromNodeId) {
|
|
2394
|
+
if (!this.stmts.getUnresolvedFromNode) {
|
|
2395
|
+
this.stmts.getUnresolvedFromNode = this.db.prepare('SELECT * FROM unresolved_refs WHERE from_node_id = ?');
|
|
2396
|
+
}
|
|
2397
|
+
const rows = this.stmts.getUnresolvedFromNode.all(fromNodeId);
|
|
2398
|
+
return rows.map((row) => ({
|
|
2399
|
+
fromNodeId: row.from_node_id,
|
|
2400
|
+
referenceName: row.reference_name,
|
|
2401
|
+
referenceKind: row.reference_kind,
|
|
2402
|
+
line: row.line,
|
|
2403
|
+
column: row.col,
|
|
2404
|
+
candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
|
|
2405
|
+
filePath: row.file_path,
|
|
2406
|
+
language: row.language,
|
|
2407
|
+
rowId: row.id,
|
|
2408
|
+
}));
|
|
2409
|
+
}
|
|
1466
2410
|
/**
|
|
1467
2411
|
* Find all edges where both source and target are in the given node set.
|
|
1468
2412
|
* Useful for recovering inter-node connectivity after BFS.
|
|
@@ -1561,8 +2505,8 @@ class QueryBuilder {
|
|
|
1561
2505
|
upsertFile(file) {
|
|
1562
2506
|
if (!this.stmts.upsertFile) {
|
|
1563
2507
|
this.stmts.upsertFile = this.db.prepare(`
|
|
1564
|
-
INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors)
|
|
1565
|
-
VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors)
|
|
2508
|
+
INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors, generated)
|
|
2509
|
+
VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors, @generated)
|
|
1566
2510
|
ON CONFLICT(path) DO UPDATE SET
|
|
1567
2511
|
content_hash = @contentHash,
|
|
1568
2512
|
language = @language,
|
|
@@ -1570,7 +2514,8 @@ class QueryBuilder {
|
|
|
1570
2514
|
modified_at = @modifiedAt,
|
|
1571
2515
|
indexed_at = @indexedAt,
|
|
1572
2516
|
node_count = @nodeCount,
|
|
1573
|
-
errors = @errors
|
|
2517
|
+
errors = @errors,
|
|
2518
|
+
generated = @generated
|
|
1574
2519
|
`);
|
|
1575
2520
|
}
|
|
1576
2521
|
this.stmts.upsertFile.run({
|
|
@@ -1582,8 +2527,178 @@ class QueryBuilder {
|
|
|
1582
2527
|
indexedAt: file.indexedAt,
|
|
1583
2528
|
nodeCount: file.nodeCount,
|
|
1584
2529
|
errors: file.errors ? JSON.stringify(file.errors) : null,
|
|
2530
|
+
// The upsert always REWRITES the flag: a file that loses its banner in an
|
|
2531
|
+
// edit must lose the flag on the next sync, not keep a stale 1.
|
|
2532
|
+
generated: file.generated ? 1 : 0,
|
|
1585
2533
|
});
|
|
1586
2534
|
}
|
|
2535
|
+
/**
|
|
2536
|
+
* Which of `filePaths` the index flagged as tool-generated (schema v9+).
|
|
2537
|
+
*
|
|
2538
|
+
* Bounded-lookup by design: every consumer already holds a short candidate
|
|
2539
|
+
* list (a ranked file group, an FTS result page, a LIMIT-20 aggregate), so
|
|
2540
|
+
* this stays a partial-index probe over a handful of paths — no whole-repo
|
|
2541
|
+
* set to materialize, and no cache to invalidate, which means a ranking call
|
|
2542
|
+
* can never serve a verdict the last sync already replaced.
|
|
2543
|
+
*
|
|
2544
|
+
* Returns ONLY the content/index signal; callers union it with
|
|
2545
|
+
* {@link isGeneratedFile} so pre-v9 databases (column present, all zeros
|
|
2546
|
+
* until a re-index) keep the path-only behavior rather than regressing.
|
|
2547
|
+
*/
|
|
2548
|
+
getGeneratedPathsAmong(filePaths) {
|
|
2549
|
+
const unique = [...new Set(filePaths)];
|
|
2550
|
+
const found = new Set();
|
|
2551
|
+
if (unique.length === 0)
|
|
2552
|
+
return found;
|
|
2553
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2554
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2555
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2556
|
+
const rows = this.db
|
|
2557
|
+
.prepare(`SELECT path FROM files WHERE generated = 1 AND path IN (${placeholders})`)
|
|
2558
|
+
.all(...chunk);
|
|
2559
|
+
for (const row of rows)
|
|
2560
|
+
found.add(row.path);
|
|
2561
|
+
}
|
|
2562
|
+
return found;
|
|
2563
|
+
}
|
|
2564
|
+
/**
|
|
2565
|
+
* A reusable `(path) => boolean` over a bounded candidate list, unioning the
|
|
2566
|
+
* indexed flag with the path convention. This is the shape every ranking
|
|
2567
|
+
* comparator wants: one query up front, then O(1) per comparison.
|
|
2568
|
+
*/
|
|
2569
|
+
generatedPredicateFor(filePaths) {
|
|
2570
|
+
const flagged = this.getGeneratedPathsAmong(filePaths);
|
|
2571
|
+
return (filePath) => flagged.has(filePath) || (0, generated_detection_1.isGeneratedFile)(filePath);
|
|
2572
|
+
}
|
|
2573
|
+
/**
|
|
2574
|
+
* Which of `filePaths` are AMBIENT DECLARATION files — they declare nothing
|
|
2575
|
+
* but types, and nothing in the index depends on them (CG-28). A hand-written
|
|
2576
|
+
* ambient `.d.ts` of global shims, a vendored typings file, module
|
|
2577
|
+
* augmentation: reachable only by name, structurally attached to nothing.
|
|
2578
|
+
*
|
|
2579
|
+
* Structural, not extension-based, so a hand-written `types.ts` and a `.d.ts`
|
|
2580
|
+
* are judged by the same rule and a `.d.ts` that does declare a class or a
|
|
2581
|
+
* const is (correctly) not caught. Four conditions, all required:
|
|
2582
|
+
*
|
|
2583
|
+
* 1. it declares at least one symbol — an empty or unparsed file is not a
|
|
2584
|
+
* declaration file, it is a file we know nothing about;
|
|
2585
|
+
* 2. EVERY declared symbol is a type-level kind (interface / type alias /
|
|
2586
|
+
* enum / namespace). The narrowness is deliberate and measured: a rule
|
|
2587
|
+
* of "no callables" alone flags 1–18% of a repo, including Kotlin sealed
|
|
2588
|
+
* classes, Rust `mod.rs` re-exports and django's locale constant tables —
|
|
2589
|
+
* real source that must not be demoted. This rule flags 0–4%;
|
|
2590
|
+
* 3. no symbol in it originates a `calls`/`instantiates` edge — the direct
|
|
2591
|
+
* evidence that nothing here has a body;
|
|
2592
|
+
* 4. NOTHING ELSE IN THE INDEX points at it. This is the condition that
|
|
2593
|
+
* separates an ambient shim from a working type module, and it is why
|
|
2594
|
+
* the flag is narrow enough to be safe: `displacement-ts`'s pipeline
|
|
2595
|
+
* `types.ts` passes 1–3 identically but carries 13 inbound imports and
|
|
2596
|
+
* 21 references, so the files that answer a query about the pipeline are
|
|
2597
|
+
* typed BY it — it is part of that answer's structure. An ambient
|
|
2598
|
+
* `declare global` shim has zero. Deliberately index-wide rather than
|
|
2599
|
+
* restricted to the candidate list: the file that imports it is usually
|
|
2600
|
+
* not itself a candidate.
|
|
2601
|
+
*
|
|
2602
|
+
* ### Interface MEMBERS are transparent to all four conditions
|
|
2603
|
+
*
|
|
2604
|
+
* A `method_signature` / `property_signature` inside an interface enters the
|
|
2605
|
+
* graph as a `method` / `property` node (#1638). Read literally that would
|
|
2606
|
+
* break every condition here at once: condition 2 sees non-type kinds and
|
|
2607
|
+
* stops flagging, and — worse, because it is silent — condition 4 starts
|
|
2608
|
+
* seeing inbound `calls` edges the moment a call site through the shim's API
|
|
2609
|
+
* finally has a signature to land on. An ambient `.d.ts` would quietly lose
|
|
2610
|
+
* its damping precisely BECAUSE the platform API it declares is widely used.
|
|
2611
|
+
*
|
|
2612
|
+
* So an interface-owned member is treated the way `parameter` already is: it
|
|
2613
|
+
* neither qualifies, disqualifies, nor counts as inbound dependency. That is
|
|
2614
|
+
* not a new judgement call, it is what keeps the rule measuring what it was
|
|
2615
|
+
* measured on — before #1638 these nodes did not exist, so excluding them
|
|
2616
|
+
* reproduces the 0–4% flag rate the thresholds above were tuned against. It
|
|
2617
|
+
* is also the semantically right answer: a signature with no body is on the
|
|
2618
|
+
* same side of the line as the interface that owns it, and a call edge
|
|
2619
|
+
* landing on one is still not a file that can answer a flow question.
|
|
2620
|
+
*
|
|
2621
|
+
* The interface ITSELF is untouched: the `references` edges an importing
|
|
2622
|
+
* module aims at `UploadStorage` still disqualify the file under (4), which
|
|
2623
|
+
* is what keeps a depended-on `types.ts` out of the flag.
|
|
2624
|
+
*
|
|
2625
|
+
* Bounded-lookup like {@link getGeneratedPathsAmong}: callers hold a ranked
|
|
2626
|
+
* candidate list, so this is a partial-index probe over a handful of paths.
|
|
2627
|
+
*/
|
|
2628
|
+
getAmbientDeclarationPathsAmong(filePaths) {
|
|
2629
|
+
const unique = [...new Set(filePaths)];
|
|
2630
|
+
const found = new Set();
|
|
2631
|
+
if (unique.length === 0)
|
|
2632
|
+
return found;
|
|
2633
|
+
for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
2634
|
+
const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
2635
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
2636
|
+
// `file`/`import`/`export`/`parameter` are structural bookkeeping, not
|
|
2637
|
+
// things the file declares, so they neither qualify nor disqualify.
|
|
2638
|
+
const rows = this.db
|
|
2639
|
+
.prepare(`
|
|
2640
|
+
SELECT n.file_path AS file_path,
|
|
2641
|
+
SUM(CASE WHEN n.kind NOT IN ('file','import','export','parameter')
|
|
2642
|
+
AND NOT ${IS_INTERFACE_MEMBER('n')}
|
|
2643
|
+
THEN 1 ELSE 0 END) AS declared,
|
|
2644
|
+
SUM(CASE WHEN n.kind IN ('interface','type_alias','enum','enum_member','namespace')
|
|
2645
|
+
THEN 1 ELSE 0 END) AS typeDeclared
|
|
2646
|
+
FROM nodes n
|
|
2647
|
+
WHERE n.file_path IN (${placeholders})
|
|
2648
|
+
GROUP BY n.file_path
|
|
2649
|
+
`)
|
|
2650
|
+
.all(...chunk);
|
|
2651
|
+
let candidates = rows
|
|
2652
|
+
.filter((r) => r.declared > 0 && r.declared === r.typeDeclared)
|
|
2653
|
+
.map((r) => r.file_path);
|
|
2654
|
+
if (candidates.length === 0)
|
|
2655
|
+
continue;
|
|
2656
|
+
const disqualify = (sql) => {
|
|
2657
|
+
if (candidates.length === 0)
|
|
2658
|
+
return;
|
|
2659
|
+
const hit = new Set(this.db
|
|
2660
|
+
.prepare(sql.replace('$IN$', candidates.map(() => '?').join(',')))
|
|
2661
|
+
.all(...candidates).map((r) => r.file_path));
|
|
2662
|
+
candidates = candidates.filter((p) => !hit.has(p));
|
|
2663
|
+
};
|
|
2664
|
+
// (3) originates behaviour — a signature has no body to originate from,
|
|
2665
|
+
// so an edge attributed to one is not evidence about this file.
|
|
2666
|
+
disqualify(`
|
|
2667
|
+
SELECT DISTINCT n.file_path AS file_path
|
|
2668
|
+
FROM edges e JOIN nodes n ON n.id = e.source
|
|
2669
|
+
WHERE e.kind IN ('calls','instantiates') AND n.file_path IN ($IN$)
|
|
2670
|
+
AND NOT ${IS_INTERFACE_MEMBER('n')}
|
|
2671
|
+
`);
|
|
2672
|
+
// (4) something outside the file depends on it — but a call that lands on
|
|
2673
|
+
// an interface's own signature is a use of the API, not a dependency on
|
|
2674
|
+
// this file's structure. The edges aimed at the interface still count.
|
|
2675
|
+
disqualify(`
|
|
2676
|
+
SELECT DISTINCT t.file_path AS file_path
|
|
2677
|
+
FROM edges e JOIN nodes t ON t.id = e.target JOIN nodes s ON s.id = e.source
|
|
2678
|
+
WHERE t.file_path IN ($IN$) AND s.file_path <> t.file_path
|
|
2679
|
+
AND NOT ${IS_INTERFACE_MEMBER('t')}
|
|
2680
|
+
`);
|
|
2681
|
+
for (const path of candidates)
|
|
2682
|
+
found.add(path);
|
|
2683
|
+
}
|
|
2684
|
+
return found;
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* A reusable `(path) => boolean` ambient-declaration test over a bounded
|
|
2688
|
+
* candidate list — the shape a ranking comparator wants: one query up front,
|
|
2689
|
+
* O(1) per comparison.
|
|
2690
|
+
*/
|
|
2691
|
+
ambientDeclarationPredicateFor(filePaths) {
|
|
2692
|
+
const flagged = this.getAmbientDeclarationPathsAmong(filePaths);
|
|
2693
|
+
return (filePath) => flagged.has(filePath);
|
|
2694
|
+
}
|
|
2695
|
+
/** How many indexed files carry the generated flag. Surfaced by `status`. */
|
|
2696
|
+
countGeneratedFiles() {
|
|
2697
|
+
const row = this.db
|
|
2698
|
+
.prepare('SELECT COUNT(*) AS n FROM files WHERE generated = 1')
|
|
2699
|
+
.get();
|
|
2700
|
+
return row?.n ?? 0;
|
|
2701
|
+
}
|
|
1587
2702
|
/**
|
|
1588
2703
|
* Delete a file record and its nodes
|
|
1589
2704
|
*/
|
|
@@ -1626,6 +2741,40 @@ class QueryBuilder {
|
|
|
1626
2741
|
.get();
|
|
1627
2742
|
return row?.last ?? null;
|
|
1628
2743
|
}
|
|
2744
|
+
/**
|
|
2745
|
+
* The index's revision marker: how far the last sync got, and how many files
|
|
2746
|
+
* it left behind — one query, both numbers.
|
|
2747
|
+
*
|
|
2748
|
+
* This is the cheapest honest answer to "has the index moved since I last
|
|
2749
|
+
* looked". `MAX(indexed_at)` alone is not enough: a sync that only DELETES
|
|
2750
|
+
* files (a branch checkout that removed a directory) advances nothing, and
|
|
2751
|
+
* the graph the viewer is showing has still changed underneath it. The row
|
|
2752
|
+
* count catches exactly that case.
|
|
2753
|
+
*/
|
|
2754
|
+
getIndexRevision() {
|
|
2755
|
+
const row = this.db
|
|
2756
|
+
.prepare('SELECT MAX(indexed_at) AS last, COUNT(*) AS files FROM files')
|
|
2757
|
+
.get();
|
|
2758
|
+
return { lastIndexedAt: row?.last ?? null, fileCount: row?.files ?? 0 };
|
|
2759
|
+
}
|
|
2760
|
+
/**
|
|
2761
|
+
* Files re-indexed strictly after `since` (ms since epoch), newest first.
|
|
2762
|
+
*
|
|
2763
|
+
* `total` is the real count; `paths` is capped at `limit`. Used by the
|
|
2764
|
+
* viewer's live channel to name what a sync just picked up. A file the same
|
|
2765
|
+
* sync DELETED cannot appear here — it has no row left — which is why the
|
|
2766
|
+
* caller compares {@link getIndexRevision} as well rather than treating an
|
|
2767
|
+
* empty list as "nothing happened".
|
|
2768
|
+
*/
|
|
2769
|
+
getFilesIndexedSince(since, limit) {
|
|
2770
|
+
const count = this.db
|
|
2771
|
+
.prepare('SELECT COUNT(*) AS n FROM files WHERE indexed_at > ?')
|
|
2772
|
+
.get(since);
|
|
2773
|
+
const rows = this.db
|
|
2774
|
+
.prepare('SELECT path FROM files WHERE indexed_at > ? ORDER BY indexed_at DESC, path LIMIT ?')
|
|
2775
|
+
.all(since, Math.max(0, limit));
|
|
2776
|
+
return { paths: rows.map((r) => r.path), total: count?.n ?? rows.length };
|
|
2777
|
+
}
|
|
1629
2778
|
/**
|
|
1630
2779
|
* Get files that need re-indexing (hash changed)
|
|
1631
2780
|
*/
|
|
@@ -1780,11 +2929,19 @@ class QueryBuilder {
|
|
|
1780
2929
|
* (§7a.2) — while the seek is O(batch) forever. `id` is the rowid alias, so
|
|
1781
2930
|
* the enumeration order is identical to the OFFSET reader's.
|
|
1782
2931
|
*/
|
|
1783
|
-
getUnresolvedReferencesBatchAfter(afterRowId, limit) {
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
2932
|
+
getUnresolvedReferencesBatchAfter(afterRowId, limit, prerequisites) {
|
|
2933
|
+
// Resolution prerequisites must be committed before dependent calls,
|
|
2934
|
+
// even when an interrupted sync queued their rows in a different order
|
|
2935
|
+
// from a clean index (#1577). Each phase still seeks by row id in bounded
|
|
2936
|
+
// memory; the default preserves the public reader's original enumeration.
|
|
2937
|
+
const key = prerequisites === undefined ? 'getUnresolvedBatchAfter'
|
|
2938
|
+
: prerequisites ? 'getUnresolvedPrerequisitesAfter' : 'getUnresolvedDependentsAfter';
|
|
2939
|
+
if (!this.stmts[key]) {
|
|
2940
|
+
const filter = prerequisites === undefined ? ''
|
|
2941
|
+
: ` AND reference_kind ${prerequisites ? 'IN' : 'NOT IN'} ('imports', 'extends', 'implements')`;
|
|
2942
|
+
this.stmts[key] = this.db.prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND id > ?${filter} ORDER BY id LIMIT ?`);
|
|
2943
|
+
}
|
|
2944
|
+
const rows = this.stmts[key].all(afterRowId, limit);
|
|
1788
2945
|
return rows.map((row) => ({
|
|
1789
2946
|
fromNodeId: row.from_node_id,
|
|
1790
2947
|
referenceName: row.reference_name,
|
|
@@ -1847,7 +3004,13 @@ class QueryBuilder {
|
|
|
1847
3004
|
const chunkRows = this.db
|
|
1848
3005
|
.prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`)
|
|
1849
3006
|
.all(...chunk);
|
|
1850
|
-
|
|
3007
|
+
// Append with a loop, never a spread: the INPUT chunk is bounded, but
|
|
3008
|
+
// the RESULT rows per chunk are not — a dense recovery sync (e.g. the
|
|
3009
|
+
// #1541 self-heal re-indexing hundreds of files) returns more rows than
|
|
3010
|
+
// V8 allows as arguments, and `push(...chunkRows)` dies with "Maximum
|
|
3011
|
+
// call stack size exceeded", aborting resolution mid-sync (#1558).
|
|
3012
|
+
for (const row of chunkRows)
|
|
3013
|
+
rows.push(row);
|
|
1851
3014
|
}
|
|
1852
3015
|
return rows.map((row) => ({
|
|
1853
3016
|
fromNodeId: row.from_node_id,
|
|
@@ -2018,7 +3181,11 @@ class QueryBuilder {
|
|
|
2018
3181
|
const chunkRows = this.db
|
|
2019
3182
|
.prepare(`SELECT * FROM unresolved_refs WHERE status = 'failed' AND name_tail IN (${placeholders})`)
|
|
2020
3183
|
.all(...chunk);
|
|
2021
|
-
|
|
3184
|
+
// Loop, not spread — same V8 argument-limit hazard as
|
|
3185
|
+
// getUnresolvedReferencesByFiles (#1558): a large definition delta can
|
|
3186
|
+
// select an unbounded number of failed rows per chunk.
|
|
3187
|
+
for (const row of chunkRows)
|
|
3188
|
+
rows.push(row);
|
|
2022
3189
|
}
|
|
2023
3190
|
return rows.map((row) => ({
|
|
2024
3191
|
fromNodeId: row.from_node_id,
|
|
@@ -2032,6 +3199,103 @@ class QueryBuilder {
|
|
|
2032
3199
|
rowId: row.id,
|
|
2033
3200
|
}));
|
|
2034
3201
|
}
|
|
3202
|
+
/**
|
|
3203
|
+
* Resolution edges whose TARGET symbol is named one of `names` — the edges a
|
|
3204
|
+
* sync must re-resolve after `names` gained or lost a definition (CG-33).
|
|
3205
|
+
*
|
|
3206
|
+
* Resolution binds a reference to a node whose name matches the reference's
|
|
3207
|
+
* tail, and it picks among ALL same-named definitions project-wide. So adding
|
|
3208
|
+
* or removing one definition of `pct` changes the answer for every `pct(...)`
|
|
3209
|
+
* reference in the repo — including references in files this sync never
|
|
3210
|
+
* touches, whose edges nothing else revisits. Those edges' current target is,
|
|
3211
|
+
* by that same rule, a node named `pct`, which is why the target's name is a
|
|
3212
|
+
* sufficient (and index-backed, via idx_nodes_name) way to find them without
|
|
3213
|
+
* a schema change or a scan of edge metadata.
|
|
3214
|
+
*
|
|
3215
|
+
* Returns the source file/language alongside each edge so the caller can
|
|
3216
|
+
* resurrect it as its original reference. Excludes `provenance='heuristic'`
|
|
3217
|
+
* (synthesized dispatch edges are not resolution output and carry no refName
|
|
3218
|
+
* stamp to resurrect from — deleting one would be a permanent loss).
|
|
3219
|
+
*
|
|
3220
|
+
* Names matching more than `perNameCeiling` edges are skipped entirely, same
|
|
3221
|
+
* rationale and same default as {@link getRetryableFailedReferences}: at that
|
|
3222
|
+
* population the name is generic (`get`, `clear`, …), one definition changing
|
|
3223
|
+
* won't flip most of them, and rebinding an arbitrary subset is both wasted
|
|
3224
|
+
* work and incoherent coverage.
|
|
3225
|
+
*/
|
|
3226
|
+
getResolutionEdgesByTargetName(names, perNameCeiling = 500) {
|
|
3227
|
+
if (names.length === 0)
|
|
3228
|
+
return [];
|
|
3229
|
+
// Pass 1: per-name edge counts, chunked under the SQLite parameter limit.
|
|
3230
|
+
const keep = [];
|
|
3231
|
+
for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3232
|
+
const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3233
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3234
|
+
const counts = this.db
|
|
3235
|
+
.prepare(`SELECT tgt.name AS name, COUNT(*) AS count
|
|
3236
|
+
FROM edges e
|
|
3237
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
3238
|
+
WHERE tgt.name IN (${placeholders})
|
|
3239
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')
|
|
3240
|
+
GROUP BY tgt.name`)
|
|
3241
|
+
.all(...chunk);
|
|
3242
|
+
for (const row of counts) {
|
|
3243
|
+
if (row.count <= perNameCeiling)
|
|
3244
|
+
keep.push(row.name);
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
if (keep.length === 0)
|
|
3248
|
+
return [];
|
|
3249
|
+
// Pass 2: load the surviving edges with the source file context a
|
|
3250
|
+
// resurrection needs.
|
|
3251
|
+
const out = [];
|
|
3252
|
+
for (let i = 0; i < keep.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3253
|
+
const chunk = keep.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3254
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3255
|
+
const rows = this.db
|
|
3256
|
+
.prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
|
|
3257
|
+
FROM edges e
|
|
3258
|
+
JOIN nodes tgt ON tgt.id = e.target
|
|
3259
|
+
JOIN nodes src ON src.id = e.source
|
|
3260
|
+
WHERE tgt.name IN (${placeholders})
|
|
3261
|
+
AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
|
|
3262
|
+
.all(...chunk);
|
|
3263
|
+
for (const row of rows) {
|
|
3264
|
+
out.push({
|
|
3265
|
+
...rowToEdge(row),
|
|
3266
|
+
edgeId: row.id,
|
|
3267
|
+
sourceFilePath: row.source_file_path,
|
|
3268
|
+
sourceLanguage: row.source_language,
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
return out;
|
|
3273
|
+
}
|
|
3274
|
+
/** Delete edges by primary key — the rebind pass's half of a re-resolution. */
|
|
3275
|
+
deleteEdgesByIds(edgeIds) {
|
|
3276
|
+
if (edgeIds.length === 0)
|
|
3277
|
+
return 0;
|
|
3278
|
+
let changed = 0;
|
|
3279
|
+
this.db.transaction(() => {
|
|
3280
|
+
for (let i = 0; i < edgeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3281
|
+
const chunk = edgeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3282
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3283
|
+
changed += this.db.prepare(`DELETE FROM edges WHERE id IN (${placeholders})`).run(...chunk).changes;
|
|
3284
|
+
}
|
|
3285
|
+
})();
|
|
3286
|
+
return changed;
|
|
3287
|
+
}
|
|
3288
|
+
/**
|
|
3289
|
+
* Replace resolution edges with their original unresolved references as one
|
|
3290
|
+
* transaction. If ref insertion fails, the edge deletion is rolled back.
|
|
3291
|
+
*/
|
|
3292
|
+
replaceResolutionEdgesWithUnresolvedRefs(edgeIds, refs) {
|
|
3293
|
+
return this.db.transaction(() => {
|
|
3294
|
+
const changed = this.deleteEdgesByIds(edgeIds);
|
|
3295
|
+
this.insertUnresolvedRefsBatch(refs);
|
|
3296
|
+
return changed;
|
|
3297
|
+
})();
|
|
3298
|
+
}
|
|
2035
3299
|
/**
|
|
2036
3300
|
* Distinct node names present in the given files — the symbol names a sync
|
|
2037
3301
|
* pass uses to look up retryable failed refs after those files changed.
|
|
@@ -2051,6 +3315,34 @@ class QueryBuilder {
|
|
|
2051
3315
|
}
|
|
2052
3316
|
return [...names];
|
|
2053
3317
|
}
|
|
3318
|
+
/**
|
|
3319
|
+
* Distinct `file\0name` pairs defined by the given files — the shape sync's
|
|
3320
|
+
* definition delta needs (CG-33).
|
|
3321
|
+
*
|
|
3322
|
+
* Deliberately NOT `getNodeNamesByFiles`: a bare name set is taken over the
|
|
3323
|
+
* WHOLE changed batch, so a name that moves between two files in one commit
|
|
3324
|
+
* (or exists in one changed file and is newly added to another) appears on
|
|
3325
|
+
* both sides and cancels out of the symmetric difference — even though a
|
|
3326
|
+
* definition genuinely appeared or vanished and every reference to that name
|
|
3327
|
+
* repo-wide may now bind elsewhere. Keying by file makes each definition its
|
|
3328
|
+
* own fact, so the move is seen as one removal plus one addition.
|
|
3329
|
+
*/
|
|
3330
|
+
getNodeNamePairsByFiles(filePaths) {
|
|
3331
|
+
const pairs = new Set();
|
|
3332
|
+
if (filePaths.length === 0)
|
|
3333
|
+
return pairs;
|
|
3334
|
+
for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
|
|
3335
|
+
const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
|
|
3336
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
3337
|
+
const rows = this.db
|
|
3338
|
+
.prepare(`SELECT DISTINCT file_path, name FROM nodes WHERE file_path IN (${placeholders})`)
|
|
3339
|
+
.all(...chunk);
|
|
3340
|
+
// NUL-joined: a path or a symbol name can contain a space, never a NUL.
|
|
3341
|
+
for (const row of rows)
|
|
3342
|
+
pairs.add(`${row.file_path}\0${row.name}`);
|
|
3343
|
+
}
|
|
3344
|
+
return pairs;
|
|
3345
|
+
}
|
|
2054
3346
|
// ===========================================================================
|
|
2055
3347
|
// Statistics
|
|
2056
3348
|
// ===========================================================================
|
|
@@ -2106,6 +3398,7 @@ class QueryBuilder {
|
|
|
2106
3398
|
edgesByKind,
|
|
2107
3399
|
filesByLanguage,
|
|
2108
3400
|
dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize()
|
|
3401
|
+
walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes()
|
|
2109
3402
|
lastUpdated: Date.now(),
|
|
2110
3403
|
};
|
|
2111
3404
|
}
|
|
@@ -2150,4 +3443,71 @@ class QueryBuilder {
|
|
|
2150
3443
|
}
|
|
2151
3444
|
}
|
|
2152
3445
|
exports.QueryBuilder = QueryBuilder;
|
|
3446
|
+
function foldModuleRows(rows, options) {
|
|
3447
|
+
// A module id is a path and may contain anything printable, so the key
|
|
3448
|
+
// separator has to be something a path cannot hold.
|
|
3449
|
+
const SEP = '\u0000';
|
|
3450
|
+
const links = new Map();
|
|
3451
|
+
const pairKinds = new Set(options.pairKinds);
|
|
3452
|
+
const wantPairs = options.topPairsPerLink > 0 && pairKinds.size > 0;
|
|
3453
|
+
const pairTotals = new Map();
|
|
3454
|
+
for (const row of rows) {
|
|
3455
|
+
const linkKey = `${row.source}${SEP}${row.target}${SEP}${row.kind}`;
|
|
3456
|
+
const link = links.get(linkKey);
|
|
3457
|
+
if (link) {
|
|
3458
|
+
link.count += row.count;
|
|
3459
|
+
link.declared += row.declared;
|
|
3460
|
+
link.uncertain += row.uncertain;
|
|
3461
|
+
}
|
|
3462
|
+
else {
|
|
3463
|
+
links.set(linkKey, {
|
|
3464
|
+
source: row.source,
|
|
3465
|
+
target: row.target,
|
|
3466
|
+
kind: row.kind,
|
|
3467
|
+
count: row.count,
|
|
3468
|
+
declared: row.declared,
|
|
3469
|
+
uncertain: row.uncertain,
|
|
3470
|
+
});
|
|
3471
|
+
}
|
|
3472
|
+
// Only the confident half of a row can be named: an uncertain edge is a
|
|
3473
|
+
// guess, and printing "a to b, 12" for twelve guesses is the map claiming
|
|
3474
|
+
// something it does not know.
|
|
3475
|
+
if (!wantPairs || row.count === 0 || !pairKinds.has(row.kind))
|
|
3476
|
+
continue;
|
|
3477
|
+
const pairKey = `${row.source}${SEP}${row.target}${SEP}${row.from}${SEP}${row.to}`;
|
|
3478
|
+
const pair = pairTotals.get(pairKey);
|
|
3479
|
+
if (pair) {
|
|
3480
|
+
pair.count += row.count;
|
|
3481
|
+
pair.declared += row.declared;
|
|
3482
|
+
}
|
|
3483
|
+
else {
|
|
3484
|
+
pairTotals.set(pairKey, {
|
|
3485
|
+
source: row.source,
|
|
3486
|
+
target: row.target,
|
|
3487
|
+
from: row.from,
|
|
3488
|
+
to: row.to,
|
|
3489
|
+
count: row.count,
|
|
3490
|
+
declared: row.declared,
|
|
3491
|
+
});
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
const byLink = new Map();
|
|
3495
|
+
for (const pair of pairTotals.values()) {
|
|
3496
|
+
const key = `${pair.source}${SEP}${pair.target}`;
|
|
3497
|
+
let list = byLink.get(key);
|
|
3498
|
+
if (!list)
|
|
3499
|
+
byLink.set(key, (list = []));
|
|
3500
|
+
list.push(pair);
|
|
3501
|
+
}
|
|
3502
|
+
const pairs = [];
|
|
3503
|
+
for (const list of byLink.values()) {
|
|
3504
|
+
list.sort((a, b) => b.declared - a.declared ||
|
|
3505
|
+
b.count - a.count ||
|
|
3506
|
+
a.from.localeCompare(b.from) ||
|
|
3507
|
+
a.to.localeCompare(b.to));
|
|
3508
|
+
for (const pair of list.slice(0, options.topPairsPerLink))
|
|
3509
|
+
pairs.push(pair);
|
|
3510
|
+
}
|
|
3511
|
+
return { links: [...links.values()], pairs };
|
|
3512
|
+
}
|
|
2153
3513
|
//# sourceMappingURL=queries.js.map
|