@colbymchenry/codegraph-win32-arm64 1.4.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/codegraph.cmd +1 -1
- package/lib/dist/bin/codegraph.js +206 -44
- package/lib/dist/bin/codegraph.js.map +1 -1
- 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 +101 -25
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +179 -0
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +368 -7
- 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 +25 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +234 -5
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +687 -53
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +16 -3
- package/lib/dist/db/sqlite-adapter.d.ts +3 -1
- package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/lib/dist/db/sqlite-adapter.js +22 -4
- package/lib/dist/db/sqlite-adapter.js.map +1 -1
- package/lib/dist/db/wal-valve.d.ts +15 -2
- package/lib/dist/db/wal-valve.d.ts.map +1 -1
- package/lib/dist/db/wal-valve.js +88 -6
- package/lib/dist/db/wal-valve.js.map +1 -1
- package/lib/dist/directory.d.ts +29 -0
- package/lib/dist/directory.d.ts.map +1 -1
- package/lib/dist/directory.js +52 -0
- package/lib/dist/directory.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.map +1 -1
- package/lib/dist/extraction/function-ref.js +6 -0
- 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.map +1 -1
- package/lib/dist/extraction/grammars.js +101 -2
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +138 -3
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +518 -94
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/kernel/decode.d.ts +9 -0
- package/lib/dist/extraction/kernel/decode.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/decode.js +162 -0
- package/lib/dist/extraction/kernel/decode.js.map +1 -0
- package/lib/dist/extraction/kernel/index.d.ts +64 -0
- package/lib/dist/extraction/kernel/index.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/index.js +279 -0
- package/lib/dist/extraction/kernel/index.js.map +1 -0
- package/lib/dist/extraction/kernel/layout.d.ts +101 -0
- package/lib/dist/extraction/kernel/layout.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/layout.js +104 -0
- package/lib/dist/extraction/kernel/layout.js.map +1 -0
- package/lib/dist/extraction/kernel/loader.d.ts +103 -0
- package/lib/dist/extraction/kernel/loader.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/loader.js +146 -0
- package/lib/dist/extraction/kernel/loader.js.map +1 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts +14 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +868 -16
- package/lib/dist/extraction/languages/c-cpp.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/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/rust.d.ts +20 -0
- package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
- package/lib/dist/extraction/languages/rust.js +47 -20
- package/lib/dist/extraction/languages/rust.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +15 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +35 -1
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/parse-worker.js +35 -1
- package/lib/dist/extraction/parse-worker.js.map +1 -1
- package/lib/dist/extraction/store-worker.d.ts +24 -0
- package/lib/dist/extraction/store-worker.d.ts.map +1 -0
- package/lib/dist/extraction/store-worker.js +139 -0
- package/lib/dist/extraction/store-worker.js.map +1 -0
- package/lib/dist/extraction/store-writer.d.ts +63 -0
- package/lib/dist/extraction/store-writer.d.ts.map +1 -0
- package/lib/dist/extraction/store-writer.js +174 -0
- package/lib/dist/extraction/store-writer.js.map +1 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts +2 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +27 -5
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +257 -56
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.js +27 -3
- package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
- 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/traversal.js +1 -1
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/index.d.ts +36 -2
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +305 -11
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/beta-signup.d.ts +54 -0
- package/lib/dist/installer/beta-signup.d.ts.map +1 -0
- package/lib/dist/installer/beta-signup.js +178 -0
- package/lib/dist/installer/beta-signup.js.map +1 -0
- 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 +19 -6
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/targets/claude.d.ts.map +1 -1
- package/lib/dist/installer/targets/claude.js +37 -5
- package/lib/dist/installer/targets/claude.js.map +1 -1
- package/lib/dist/installer/targets/codex.d.ts +22 -8
- package/lib/dist/installer/targets/codex.d.ts.map +1 -1
- package/lib/dist/installer/targets/codex.js +65 -48
- 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 +209 -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/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/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 +5 -5
- package/lib/dist/installer/targets/types.d.ts.map +1 -1
- 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 +1 -1
- package/lib/dist/mcp/daemon-manager.js.map +1 -1
- package/lib/dist/mcp/daemon-paths.d.ts +6 -0
- package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-paths.js +54 -0
- package/lib/dist/mcp/daemon-paths.js.map +1 -1
- package/lib/dist/mcp/daemon-registry.d.ts +10 -0
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-registry.js +51 -3
- package/lib/dist/mcp/daemon-registry.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +9 -6
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +10 -8
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/engine.d.ts +3 -0
- package/lib/dist/mcp/engine.d.ts.map +1 -1
- package/lib/dist/mcp/engine.js +45 -3
- package/lib/dist/mcp/engine.js.map +1 -1
- package/lib/dist/mcp/explore-dedup.d.ts +137 -0
- package/lib/dist/mcp/explore-dedup.d.ts.map +1 -0
- package/lib/dist/mcp/explore-dedup.js +236 -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.d.ts +24 -0
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +67 -6
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.js +3 -1
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +6 -1
- package/lib/dist/mcp/proxy.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 +8 -3
- 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/tools.d.ts +276 -10
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +2425 -237
- package/lib/dist/mcp/tools.js.map +1 -1
- 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/c-fnptr-synthesizer.d.ts +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +582 -138
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts +54 -10
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +287 -167
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/cooperative-yield.d.ts +10 -2
- package/lib/dist/resolution/cooperative-yield.d.ts.map +1 -1
- package/lib/dist/resolution/cooperative-yield.js +6 -4
- package/lib/dist/resolution/cooperative-yield.js.map +1 -1
- package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/go.js +29 -6
- package/lib/dist/resolution/frameworks/go.js.map +1 -1
- 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/import-resolver.d.ts +2 -3
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +184 -9
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +87 -2
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +731 -134
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/memory-budget.d.ts +48 -0
- package/lib/dist/resolution/memory-budget.d.ts.map +1 -0
- package/lib/dist/resolution/memory-budget.js +162 -0
- package/lib/dist/resolution/memory-budget.js.map +1 -0
- package/lib/dist/resolution/name-matcher.d.ts +42 -1
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +681 -99
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- 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/resolver-pool.d.ts +106 -0
- package/lib/dist/resolution/resolver-pool.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-pool.js +344 -0
- package/lib/dist/resolution/resolver-pool.js.map +1 -0
- package/lib/dist/resolution/resolver-worker.d.ts +17 -0
- package/lib/dist/resolution/resolver-worker.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-worker.js +141 -0
- package/lib/dist/resolution/resolver-worker.js.map +1 -0
- package/lib/dist/resolution/types.d.ts +3 -0
- package/lib/dist/resolution/types.d.ts.map +1 -1
- 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 +57 -0
- package/lib/dist/search/query-paths.d.ts.map +1 -0
- package/lib/dist/search/query-paths.js +298 -0
- package/lib/dist/search/query-paths.js.map +1 -0
- package/lib/dist/search/query-utils.d.ts +1 -1
- package/lib/dist/search/query-utils.d.ts.map +1 -1
- package/lib/dist/search/query-utils.js +13 -3
- package/lib/dist/search/query-utils.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +47 -1
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +127 -8
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/types.d.ts +61 -3
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +27 -1
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/ui/color.d.ts +21 -0
- package/lib/dist/ui/color.d.ts.map +1 -0
- package/lib/dist/ui/color.js +42 -0
- package/lib/dist/ui/color.js.map +1 -0
- package/lib/dist/ui/glyphs.d.ts +35 -10
- package/lib/dist/ui/glyphs.d.ts.map +1 -1
- package/lib/dist/ui/glyphs.js +59 -12
- package/lib/dist/ui/glyphs.js.map +1 -1
- package/lib/dist/ui/shimmer-progress.d.ts.map +1 -1
- package/lib/dist/ui/shimmer-progress.js +78 -4
- package/lib/dist/ui/shimmer-progress.js.map +1 -1
- package/lib/dist/ui/shimmer-worker.js +25 -17
- package/lib/dist/ui/shimmer-worker.js.map +1 -1
- package/lib/dist/ui/types.d.ts +0 -2
- package/lib/dist/ui/types.d.ts.map +1 -1
- package/lib/dist/upgrade/index.d.ts +7 -0
- package/lib/dist/upgrade/index.d.ts.map +1 -1
- package/lib/dist/upgrade/index.js +18 -5
- package/lib/dist/upgrade/index.js.map +1 -1
- package/lib/kernel/codegraph-kernel.node +0 -0
- package/lib/node_modules/.package-lock.json +1 -1
- package/lib/package.json +6 -1
- package/package.json +6 -2
|
@@ -47,6 +47,7 @@ exports.buildDefaultIgnore = buildDefaultIgnore;
|
|
|
47
47
|
exports.buildScopeIgnore = buildScopeIgnore;
|
|
48
48
|
exports.discoverEmbeddedRepoRoots = discoverEmbeddedRepoRoots;
|
|
49
49
|
exports.findUnindexedIgnoredRepos = findUnindexedIgnoredRepos;
|
|
50
|
+
exports.getGitChangedFiles = getGitChangedFiles;
|
|
50
51
|
exports.scanDirectory = scanDirectory;
|
|
51
52
|
exports.scanDirectoryAsync = scanDirectoryAsync;
|
|
52
53
|
const fs = __importStar(require("fs"));
|
|
@@ -57,6 +58,9 @@ const crypto = __importStar(require("crypto"));
|
|
|
57
58
|
const child_process_1 = require("child_process");
|
|
58
59
|
const tree_sitter_1 = require("./tree-sitter");
|
|
59
60
|
const parse_pool_1 = require("./parse-pool");
|
|
61
|
+
const store_writer_1 = require("./store-writer");
|
|
62
|
+
const kernel_1 = require("./kernel");
|
|
63
|
+
const generated_detection_1 = require("./generated-detection");
|
|
60
64
|
const grammars_1 = require("./grammars");
|
|
61
65
|
const project_config_1 = require("../project-config");
|
|
62
66
|
const directory_1 = require("../directory");
|
|
@@ -807,6 +811,11 @@ function findUnindexedIgnoredRepos(rootDir) {
|
|
|
807
811
|
if (includeIgnored?.ignores((0, utils_1.normalizePath)(dir)))
|
|
808
812
|
continue; // already opted in — nothing to nag about
|
|
809
813
|
for (const repo of findNestedGitRepos(path.join(rootDir, dir), dir)) {
|
|
814
|
+
// Per-repo opt-in check, mirroring findIgnoredEmbeddedRepos: a child
|
|
815
|
+
// pattern (`repos/a/`) doesn't match the parent dir above but DOES
|
|
816
|
+
// cover this repo — it's indexed, so don't nag about it (#1295).
|
|
817
|
+
if (includeIgnored?.ignores((0, utils_1.normalizePath)(repo)))
|
|
818
|
+
continue;
|
|
810
819
|
repos.push(repo);
|
|
811
820
|
if (repos.length >= UNINDEXED_IGNORED_REPO_HINT_CAP)
|
|
812
821
|
return repos;
|
|
@@ -837,9 +846,22 @@ function findIgnoredEmbeddedRepos(repoDir, includeIgnored, prefix) {
|
|
|
837
846
|
for (const dir of listIgnoredDirs(repoDir)) {
|
|
838
847
|
if (defaults.ignores(dir))
|
|
839
848
|
continue;
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
849
|
+
const nested = findNestedGitRepos(path.join(repoDir, dir), dir);
|
|
850
|
+
if (includeIgnored.ignores((0, utils_1.normalizePath)(prefix + dir))) {
|
|
851
|
+
// The whole ignored dir is opted in — every nested repo under it counts.
|
|
852
|
+
repos.push(...nested);
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
// A single gitignore rule often covers the PARENT of the opted-in
|
|
856
|
+
// repos: `.gitignore: /repos/` lists `repos/` as ONE ignored entry,
|
|
857
|
+
// while `includeIgnored: ["repos/a/"]` (the CLI hint's own suggested
|
|
858
|
+
// spelling) names the child — which never matches the parent path, so
|
|
859
|
+
// the opt-in silently did nothing (#1295). Match each nested repo
|
|
860
|
+
// root individually so both spellings work. The walk is bounded
|
|
861
|
+
// (depth/entry caps in findNestedGitRepos) and only runs when
|
|
862
|
+
// includeIgnored is configured at all.
|
|
863
|
+
repos.push(...nested.filter((r) => includeIgnored.ignores((0, utils_1.normalizePath)(prefix + r))));
|
|
864
|
+
}
|
|
843
865
|
}
|
|
844
866
|
return repos;
|
|
845
867
|
}
|
|
@@ -1036,7 +1058,14 @@ function getGitChangedFiles(rootDir) {
|
|
|
1036
1058
|
}
|
|
1037
1059
|
}
|
|
1038
1060
|
function collectGitStatus(repoDir, prefix, out, overrides, includeIgnored = null, exclude = null) {
|
|
1039
|
-
const output = (0, child_process_1.execFileSync)('git',
|
|
1061
|
+
const output = (0, child_process_1.execFileSync)('git',
|
|
1062
|
+
// `-uall` lists individual untracked files instead of collapsing an
|
|
1063
|
+
// entirely-untracked directory into one `?? dir/` entry, which would
|
|
1064
|
+
// otherwise be dropped here (only embedded git repos are recursed into
|
|
1065
|
+
// below). Nested untracked git repos still collapse to `?? repo/` even
|
|
1066
|
+
// with `-uall` — git never crosses a repo boundary — so the recursion
|
|
1067
|
+
// still handles them. (#1213)
|
|
1068
|
+
['status', '--porcelain', '--no-renames', '-uall'], { cwd: repoDir, encoding: 'utf-8', timeout: 10000, maxBuffer: 50 * 1024 * 1024, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true });
|
|
1040
1069
|
// This repo's own ignore rules — built-in defaults (#407) plus its .gitignore.
|
|
1041
1070
|
// Change detection must exclude the SAME files the full index does, but git
|
|
1042
1071
|
// status hides neither: it ignores nothing for *tracked* paths, and the
|
|
@@ -1323,10 +1352,47 @@ class ExtractionOrchestrator {
|
|
|
1323
1352
|
* hasn't run yet so single-file re-index paths can detect on the spot.
|
|
1324
1353
|
*/
|
|
1325
1354
|
detectedFrameworkNames = null;
|
|
1355
|
+
/**
|
|
1356
|
+
* Scope matcher for SCOPED syncs, memoized on the mtimes of the two root
|
|
1357
|
+
* files it is derived from (`codegraph.json`, `.gitignore`). See
|
|
1358
|
+
* {@link scopedSyncMatcher}.
|
|
1359
|
+
*/
|
|
1360
|
+
scopedMatcher = null;
|
|
1326
1361
|
constructor(rootDir, queries) {
|
|
1327
1362
|
this.rootDir = rootDir;
|
|
1328
1363
|
this.queries = queries;
|
|
1329
1364
|
}
|
|
1365
|
+
/**
|
|
1366
|
+
* The scope matcher a scoped sync applies to the paths it was handed — the
|
|
1367
|
+
* same `buildScopeIgnore` the full scan uses, so an explicitly-passed path
|
|
1368
|
+
* that is OUT of scope (a user `exclude` in `codegraph.json`, a `.gitignore`
|
|
1369
|
+
* rule, a built-in default) is treated exactly as the full walk would treat
|
|
1370
|
+
* it: absent, hence removed if tracked, never parsed (#1590).
|
|
1371
|
+
*
|
|
1372
|
+
* Memoized on the root config + root `.gitignore` mtimes: building the
|
|
1373
|
+
* matcher runs embedded-repo discovery (`git ls-files`), which would defeat
|
|
1374
|
+
* the scoped path's whole point (skipping O(repo) work) if paid per sync.
|
|
1375
|
+
* Two `stat`s per sync while nothing changed. An embedded repo created
|
|
1376
|
+
* between config edits joins the scoped matcher on the next full sync, the
|
|
1377
|
+
* same lifecycle the watcher's own matcher already has.
|
|
1378
|
+
*/
|
|
1379
|
+
scopedSyncMatcher() {
|
|
1380
|
+
const key = [project_config_1.PROJECT_CONFIG_FILENAME, '.gitignore']
|
|
1381
|
+
.map((name) => {
|
|
1382
|
+
try {
|
|
1383
|
+
return String(fs.statSync(path.join(this.rootDir, name)).mtimeMs);
|
|
1384
|
+
}
|
|
1385
|
+
catch {
|
|
1386
|
+
return '-';
|
|
1387
|
+
}
|
|
1388
|
+
})
|
|
1389
|
+
.join('|');
|
|
1390
|
+
if (this.scopedMatcher && this.scopedMatcher.key === key)
|
|
1391
|
+
return this.scopedMatcher.matcher;
|
|
1392
|
+
const matcher = buildScopeIgnore(this.rootDir);
|
|
1393
|
+
this.scopedMatcher = { key, matcher };
|
|
1394
|
+
return matcher;
|
|
1395
|
+
}
|
|
1330
1396
|
/**
|
|
1331
1397
|
* Build a filesystem-backed ResolutionContext sufficient for framework
|
|
1332
1398
|
* detection. Graph-query methods (getNodesByName etc.) return empty because
|
|
@@ -1407,8 +1473,17 @@ class ExtractionOrchestrator {
|
|
|
1407
1473
|
// null in the normal case, or a promise to await (at this safe,
|
|
1408
1474
|
// between-transactions boundary) when the WAL has outrun the off-thread
|
|
1409
1475
|
// checkpointer past its hard cap. See db/wal-valve.ts.
|
|
1410
|
-
walBackpressure
|
|
1476
|
+
walBackpressure,
|
|
1477
|
+
// Fresh-DB store offload (perf): when set, per-file store bundles are
|
|
1478
|
+
// applied by a dedicated writer thread instead of the main thread. Only
|
|
1479
|
+
// passed for a COMPLETELY fresh database, where the main thread performs
|
|
1480
|
+
// no reads/writes during the parse loop, so one writer applying bundles
|
|
1481
|
+
// in file order preserves the #1015 determinism exactly.
|
|
1482
|
+
storeWriterOpts) {
|
|
1483
|
+
const tGrammar = Date.now();
|
|
1411
1484
|
await (0, grammars_1.initGrammars)();
|
|
1485
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
1486
|
+
console.error(`[phase-timing] grammar-init: ${Date.now() - tGrammar}ms`);
|
|
1412
1487
|
const startTime = Date.now();
|
|
1413
1488
|
const errors = [];
|
|
1414
1489
|
let filesIndexed = 0;
|
|
@@ -1443,6 +1518,10 @@ class ExtractionOrchestrator {
|
|
|
1443
1518
|
});
|
|
1444
1519
|
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
1445
1520
|
console.error(`[phase-timing] scan: ${Date.now() - tScan}ms (${files.length} files)`);
|
|
1521
|
+
// A re-index over an existing DB skips unchanged-hash files at the store,
|
|
1522
|
+
// which would preserve wiped zero-node rows (#1541) — drop them first so
|
|
1523
|
+
// this run stores their files fresh. No-op on a fresh DB.
|
|
1524
|
+
this.healZeroNodeRows();
|
|
1446
1525
|
// Detect frameworks once per indexAll run using the scanned file list.
|
|
1447
1526
|
// Names are passed to each parse call so framework-specific extractors
|
|
1448
1527
|
// (route nodes, middleware, etc.) run after the tree-sitter pass.
|
|
@@ -1491,8 +1570,15 @@ class ExtractionOrchestrator {
|
|
|
1491
1570
|
let pool = null;
|
|
1492
1571
|
if (useWorker) {
|
|
1493
1572
|
// CODEGRAPH_PARSE_WORKERS: explicit worker count; 1 = the old single-worker
|
|
1494
|
-
// behaviour (the conservative rollback). Unset → clamp(cores-1, 1, 8)
|
|
1495
|
-
|
|
1573
|
+
// behaviour (the conservative rollback). Unset → clamp(cores-1, 1, 8),
|
|
1574
|
+
// with cores from availableParallelism — cpuset/affinity-honest, where
|
|
1575
|
+
// os.cpus() enumerates the host's CPUs and spawned 8 wasm workers (and
|
|
1576
|
+
// their grammar heaps) inside a 2-CPU container for zero extra
|
|
1577
|
+
// throughput (§7a.1). Floored so a 2-core box still gets 2 workers:
|
|
1578
|
+
// parse is worker-side CPU, and 1 worker measured 34% slower than the
|
|
1579
|
+
// old oversubscribed pool on the kernel-scale 2-cpuset envelope
|
|
1580
|
+
// (493s vs 369s) — main + store-worker don't fill the second core.
|
|
1581
|
+
const poolSize = (0, parse_pool_1.resolveParsePoolSize)(process.env.CODEGRAPH_PARSE_WORKERS, Math.max(3, os.availableParallelism()));
|
|
1496
1582
|
// Read each needed grammar's WASM ONCE here and hand the bytes to every
|
|
1497
1583
|
// worker, so spawns/respawns load grammars from memory instead of
|
|
1498
1584
|
// re-reading them from disk (#1231: on an HDD, respawn re-reads amplify
|
|
@@ -1508,11 +1594,32 @@ class ExtractionOrchestrator {
|
|
|
1508
1594
|
grammarBuffers,
|
|
1509
1595
|
});
|
|
1510
1596
|
log(`Parse worker pool: ${poolSize} worker(s)`);
|
|
1597
|
+
// Bulk index: every core will be needed — spawn the whole pool now so
|
|
1598
|
+
// worker boot overlaps the first read batches instead of trickling in
|
|
1599
|
+
// behind queue-pressure growth.
|
|
1600
|
+
pool.prewarm();
|
|
1511
1601
|
}
|
|
1512
1602
|
else {
|
|
1513
1603
|
// In-process fallback: load grammars locally and parse on the main thread.
|
|
1514
1604
|
await (0, grammars_1.loadGrammarsForLanguages)(neededLanguages);
|
|
1515
1605
|
}
|
|
1606
|
+
// Dedicated store writer thread (fresh DB only — see the parameter doc).
|
|
1607
|
+
// Same availability rule as the parse pool: needs the compiled worker
|
|
1608
|
+
// (absent when running from source in tests → main-thread fallback).
|
|
1609
|
+
const storeWorkerPath = path.join(__dirname, 'store-worker.js');
|
|
1610
|
+
let storeWriter = null;
|
|
1611
|
+
if (storeWriterOpts &&
|
|
1612
|
+
process.env.CODEGRAPH_NO_STORE_WORKER !== '1' &&
|
|
1613
|
+
fs.existsSync(storeWorkerPath)) {
|
|
1614
|
+
// Deliberately NOT awaiting ready(): worker_threads delivers messages in
|
|
1615
|
+
// order, so bundles posted while the worker is still booting queue
|
|
1616
|
+
// behind 'open'. A boot failure surfaces at the first drain() — same
|
|
1617
|
+
// propagation point as a store error.
|
|
1618
|
+
storeWriter = new store_writer_1.StoreWriter(storeWorkerPath, storeWriterOpts.dbPath, storeWriterOpts.fastInit);
|
|
1619
|
+
log('Store writer thread active');
|
|
1620
|
+
}
|
|
1621
|
+
/** Queue-depth bound for un-acked bundles (bundles hold whole node/edge arrays). */
|
|
1622
|
+
const STORE_WRITER_WINDOW = 64;
|
|
1516
1623
|
/**
|
|
1517
1624
|
* Parse one file: on the pool when available (the promise REJECTS on a worker
|
|
1518
1625
|
* crash/timeout — the caller records it and the retry pass re-attempts), or
|
|
@@ -1554,10 +1661,34 @@ class ExtractionOrchestrator {
|
|
|
1554
1661
|
const bp = walBackpressure?.();
|
|
1555
1662
|
if (bp)
|
|
1556
1663
|
await bp;
|
|
1557
|
-
//
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1664
|
+
// Kernel deferred-decode results carry table sizes in kernelCounts
|
|
1665
|
+
// (their object arrays are empty — decode happens at the store).
|
|
1666
|
+
const nodeCount = result.kernelCounts?.nodes ?? result.nodes.length;
|
|
1667
|
+
const edgeCount = result.kernelCounts?.edges ?? result.edges.length;
|
|
1668
|
+
// Store: on the writer thread when active (fresh DB — bundles applied
|
|
1669
|
+
// in the same file order this chain dispatches them), else on the main
|
|
1670
|
+
// thread (SQLite connections are per-thread).
|
|
1671
|
+
const language = (0, grammars_1.detectLanguage)(filePath, content, overrides);
|
|
1672
|
+
if (storeWriter) {
|
|
1673
|
+
if (result.kernelBuffers) {
|
|
1674
|
+
// Buffers go to the writer as-is; the worker decodes + finalizes.
|
|
1675
|
+
// The main thread's only per-file work stays O(1) + the content hash.
|
|
1676
|
+
storeWriter.send({
|
|
1677
|
+
kernel: true,
|
|
1678
|
+
filePath,
|
|
1679
|
+
language,
|
|
1680
|
+
buffers: result.kernelBuffers,
|
|
1681
|
+
file: this.buildFileRecord(filePath, content, language, stats, nodeCount, result.errors),
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
else {
|
|
1685
|
+
storeWriter.send(this.buildFreshStoreBundle(filePath, content, language, stats, result));
|
|
1686
|
+
}
|
|
1687
|
+
await storeWriter.waitBelow(STORE_WRITER_WINDOW);
|
|
1688
|
+
}
|
|
1689
|
+
else {
|
|
1690
|
+
const materialized = (0, kernel_1.materializeKernelResult)(result, filePath, language);
|
|
1691
|
+
await this.storeExtractionResult(filePath, content, language, stats, materialized, commitYield);
|
|
1561
1692
|
}
|
|
1562
1693
|
if (result.errors.length > 0) {
|
|
1563
1694
|
for (const err of result.errors) {
|
|
@@ -1566,10 +1697,10 @@ class ExtractionOrchestrator {
|
|
|
1566
1697
|
}
|
|
1567
1698
|
errors.push(...result.errors);
|
|
1568
1699
|
}
|
|
1569
|
-
if (
|
|
1700
|
+
if (nodeCount > 0) {
|
|
1570
1701
|
filesIndexed++;
|
|
1571
|
-
totalNodes +=
|
|
1572
|
-
totalEdges +=
|
|
1702
|
+
totalNodes += nodeCount;
|
|
1703
|
+
totalEdges += edgeCount;
|
|
1573
1704
|
}
|
|
1574
1705
|
else if (result.errors.some((e) => e.severity === 'error')) {
|
|
1575
1706
|
filesErrored++;
|
|
@@ -1588,16 +1719,19 @@ class ExtractionOrchestrator {
|
|
|
1588
1719
|
}
|
|
1589
1720
|
onProgress?.({ phase: 'parsing', current: processed, total, currentFile: filePath });
|
|
1590
1721
|
};
|
|
1591
|
-
const recordParseFailure = (filePath, err) => {
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1722
|
+
const recordParseFailure = async (filePath, content, stats, err) => {
|
|
1723
|
+
await storeResult(filePath, content, stats, {
|
|
1724
|
+
nodes: [],
|
|
1725
|
+
edges: [],
|
|
1726
|
+
unresolvedReferences: [],
|
|
1727
|
+
errors: [{
|
|
1728
|
+
message: err instanceof Error ? err.message : String(err),
|
|
1729
|
+
filePath,
|
|
1730
|
+
severity: 'error',
|
|
1731
|
+
code: 'parse_error',
|
|
1732
|
+
}],
|
|
1733
|
+
durationMs: 0,
|
|
1599
1734
|
});
|
|
1600
|
-
onProgress?.({ phase: 'parsing', current: processed, total });
|
|
1601
1735
|
};
|
|
1602
1736
|
// Commit buffered parses to the DB in file order, advancing the cursor over
|
|
1603
1737
|
// contiguous completed results. Runs after each parse settles (and once more
|
|
@@ -1622,7 +1756,7 @@ class ExtractionOrchestrator {
|
|
|
1622
1756
|
if (item.ok)
|
|
1623
1757
|
await storeResult(item.filePath, item.content, item.stats, item.result);
|
|
1624
1758
|
else
|
|
1625
|
-
recordParseFailure(item.filePath, item.err);
|
|
1759
|
+
await recordParseFailure(item.filePath, item.content, item.stats, item.err);
|
|
1626
1760
|
}
|
|
1627
1761
|
}
|
|
1628
1762
|
catch (err) {
|
|
@@ -1642,7 +1776,7 @@ class ExtractionOrchestrator {
|
|
|
1642
1776
|
completed.set(seq, { ok: true, filePath, content, stats, result });
|
|
1643
1777
|
}
|
|
1644
1778
|
catch (parseErr) {
|
|
1645
|
-
completed.set(seq, { ok: false, filePath, err: parseErr });
|
|
1779
|
+
completed.set(seq, { ok: false, filePath, content, stats, err: parseErr });
|
|
1646
1780
|
}
|
|
1647
1781
|
flushOrdered();
|
|
1648
1782
|
})();
|
|
@@ -1663,6 +1797,7 @@ class ExtractionOrchestrator {
|
|
|
1663
1797
|
await flushOrdered();
|
|
1664
1798
|
}
|
|
1665
1799
|
};
|
|
1800
|
+
const tParseLoop = Date.now();
|
|
1666
1801
|
for (let i = 0; i < files.length; i += FILE_IO_BATCH_SIZE) {
|
|
1667
1802
|
if (signal?.aborted) {
|
|
1668
1803
|
aborted = true;
|
|
@@ -1713,15 +1848,18 @@ class ExtractionOrchestrator {
|
|
|
1713
1848
|
// useful symbols. The single-file extractFile path already enforces
|
|
1714
1849
|
// this; the bulk path used to silently skip the check.
|
|
1715
1850
|
if (stats.size > MAX_FILE_SIZE) {
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1851
|
+
await storeResult(filePath, content, stats, {
|
|
1852
|
+
nodes: [],
|
|
1853
|
+
edges: [],
|
|
1854
|
+
unresolvedReferences: [],
|
|
1855
|
+
errors: [{
|
|
1856
|
+
message: `File exceeds max size (${stats.size} > ${MAX_FILE_SIZE})`,
|
|
1857
|
+
filePath,
|
|
1858
|
+
severity: 'warning',
|
|
1859
|
+
code: 'size_exceeded',
|
|
1860
|
+
}],
|
|
1861
|
+
durationMs: 0,
|
|
1723
1862
|
});
|
|
1724
|
-
onProgress?.({ phase: 'parsing', current: processed, total });
|
|
1725
1863
|
continue;
|
|
1726
1864
|
}
|
|
1727
1865
|
// Parse on the pool (main thread stays unblocked). Errors/timeouts are
|
|
@@ -1736,10 +1874,29 @@ class ExtractionOrchestrator {
|
|
|
1736
1874
|
if (!aborted) {
|
|
1737
1875
|
await Promise.all(inFlight);
|
|
1738
1876
|
await flushOrdered();
|
|
1739
|
-
if (flushError)
|
|
1877
|
+
if (flushError) {
|
|
1878
|
+
if (storeWriter)
|
|
1879
|
+
await storeWriter.close();
|
|
1740
1880
|
throw flushError;
|
|
1881
|
+
}
|
|
1882
|
+
// All bundles are posted; wait for the writer to apply them, then close
|
|
1883
|
+
// its connection BEFORE any main-thread DB work below (retry pass,
|
|
1884
|
+
// resolution) so exactly one connection writes at a time.
|
|
1885
|
+
if (storeWriter) {
|
|
1886
|
+
try {
|
|
1887
|
+
await storeWriter.drain();
|
|
1888
|
+
}
|
|
1889
|
+
finally {
|
|
1890
|
+
await storeWriter.close();
|
|
1891
|
+
storeWriter = null;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1741
1894
|
}
|
|
1895
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
1896
|
+
console.error(`[phase-timing] parse-loop: ${Date.now() - tParseLoop}ms`);
|
|
1742
1897
|
if (signal?.aborted || aborted) {
|
|
1898
|
+
if (storeWriter)
|
|
1899
|
+
await storeWriter.close();
|
|
1743
1900
|
if (pool)
|
|
1744
1901
|
await pool.destroy();
|
|
1745
1902
|
return {
|
|
@@ -1803,8 +1960,15 @@ class ExtractionOrchestrator {
|
|
|
1803
1960
|
stillFailing.push(errEntry);
|
|
1804
1961
|
continue;
|
|
1805
1962
|
}
|
|
1963
|
+
// The pool hands kernel results back as an undecoded buffer transport
|
|
1964
|
+
// (`nodes`/`edges` EMPTY, tables in kernelBuffers). The main loop
|
|
1965
|
+
// decodes or forwards to the store worker; this path stores directly,
|
|
1966
|
+
// so decode here — otherwise a kernel-language retry passes the gate
|
|
1967
|
+
// below via `errors.length === 0`, stores nothing, and the file is
|
|
1968
|
+
// permanently recorded as "(0 symbols)" with the error erased (#1541).
|
|
1969
|
+
const language = (0, grammars_1.detectLanguage)(filePath, content, overrides);
|
|
1970
|
+
result = (0, kernel_1.materializeKernelResult)(result, filePath, language);
|
|
1806
1971
|
if (result.nodes.length > 0 || result.errors.length === 0) {
|
|
1807
|
-
const language = (0, grammars_1.detectLanguage)(filePath, content, overrides);
|
|
1808
1972
|
const stats = await fsp.stat(path.join(this.rootDir, filePath));
|
|
1809
1973
|
await this.storeExtractionResult(filePath, content, language, stats, result, commitYield);
|
|
1810
1974
|
const idx = errors.indexOf(errEntry);
|
|
@@ -1851,13 +2015,20 @@ class ExtractionOrchestrator {
|
|
|
1851
2015
|
catch {
|
|
1852
2016
|
continue;
|
|
1853
2017
|
}
|
|
2018
|
+
// Same undecoded-transport hazard as the first retry pass (#1541).
|
|
2019
|
+
const language = (0, grammars_1.detectLanguage)(filePath, fullContent, overrides);
|
|
2020
|
+
result = (0, kernel_1.materializeKernelResult)(result, filePath, language);
|
|
1854
2021
|
if (result.nodes.length > 0 || result.errors.length === 0) {
|
|
1855
|
-
const language = (0, grammars_1.detectLanguage)(filePath, fullContent, overrides);
|
|
1856
2022
|
const stats = await fsp.stat(path.join(this.rootDir, filePath));
|
|
1857
2023
|
await this.storeExtractionResult(filePath, fullContent, language, stats, result, commitYield);
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
2024
|
+
// Salvaged from comment-stripped source: keep a visible trace in
|
|
2025
|
+
// the summary instead of erasing the failure outright — the
|
|
2026
|
+
// stored result may be missing whatever the failing parse choked
|
|
2027
|
+
// on, and a silently "clean" file here is how an index quietly
|
|
2028
|
+
// disagrees with a later per-file sync of the same bytes (#1565).
|
|
2029
|
+
errEntry.severity = 'warning';
|
|
2030
|
+
errEntry.code = 'salvaged_stripped';
|
|
2031
|
+
errEntry.message = `Indexed from comment-stripped source after repeated parse failures (symbols may be incomplete until the file is re-indexed): ${errEntry.message}`;
|
|
1861
2032
|
filesErrored--;
|
|
1862
2033
|
filesIndexed++;
|
|
1863
2034
|
totalNodes += result.nodes.length;
|
|
@@ -1984,9 +2155,10 @@ class ExtractionOrchestrator {
|
|
|
1984
2155
|
durationMs: 0,
|
|
1985
2156
|
};
|
|
1986
2157
|
}
|
|
2158
|
+
const language = (0, grammars_1.detectLanguage)(relativePath, content, (0, project_config_1.loadExtensionOverrides)(this.rootDir));
|
|
1987
2159
|
// Check file size
|
|
1988
2160
|
if (stats.size > MAX_FILE_SIZE) {
|
|
1989
|
-
|
|
2161
|
+
const result = {
|
|
1990
2162
|
nodes: [],
|
|
1991
2163
|
edges: [],
|
|
1992
2164
|
unresolvedReferences: [],
|
|
@@ -2000,9 +2172,10 @@ class ExtractionOrchestrator {
|
|
|
2000
2172
|
],
|
|
2001
2173
|
durationMs: 0,
|
|
2002
2174
|
};
|
|
2175
|
+
await this.storeExtractionResult(relativePath, content, language, stats, result, (0, cooperative_yield_1.createYielder)());
|
|
2176
|
+
return result;
|
|
2003
2177
|
}
|
|
2004
2178
|
// Detect language (honoring the project's codegraph.json extension overrides)
|
|
2005
|
-
const language = (0, grammars_1.detectLanguage)(relativePath, content, (0, project_config_1.loadExtensionOverrides)(this.rootDir));
|
|
2006
2179
|
if (!(0, grammars_1.isLanguageSupported)(language)) {
|
|
2007
2180
|
return {
|
|
2008
2181
|
nodes: [],
|
|
@@ -2018,15 +2191,43 @@ class ExtractionOrchestrator {
|
|
|
2018
2191
|
const frameworkNames = this.ensureDetectedFrameworks();
|
|
2019
2192
|
const result = (0, tree_sitter_1.extractFromSource)(relativePath, content, language, frameworkNames);
|
|
2020
2193
|
// Store in database
|
|
2021
|
-
|
|
2022
|
-
await this.storeExtractionResult(relativePath, content, language, stats, result, (0, cooperative_yield_1.createYielder)());
|
|
2023
|
-
}
|
|
2194
|
+
await this.storeExtractionResult(relativePath, content, language, stats, result, (0, cooperative_yield_1.createYielder)());
|
|
2024
2195
|
return result;
|
|
2025
2196
|
}
|
|
2026
2197
|
/**
|
|
2027
2198
|
* Store extraction result in database
|
|
2028
2199
|
*/
|
|
2200
|
+
/**
|
|
2201
|
+
* Delete file rows recorded with ZERO nodes so their files re-index.
|
|
2202
|
+
*
|
|
2203
|
+
* No extraction path stores an empty, error-free result for a
|
|
2204
|
+
* symbol-bearing language — even an empty file keeps its file node — so a
|
|
2205
|
+
* zero-node row is a wiped one (#1541: an interrupted parse's retry stored
|
|
2206
|
+
* an undecoded kernel transport). The wiped row's content hash matches the
|
|
2207
|
+
* on-disk bytes, so every hash-based reconcile skips the file forever;
|
|
2208
|
+
* deleting the row lets the normal add path repair it. File-level-only
|
|
2209
|
+
* languages (yaml, twig, properties) are left alone. Deleting a zero-node
|
|
2210
|
+
* row cascades nothing: it has no nodes, so no edges or refs either.
|
|
2211
|
+
*/
|
|
2212
|
+
healZeroNodeRows() {
|
|
2213
|
+
for (const f of this.queries.getAllFiles()) {
|
|
2214
|
+
// A zero-node row WITH recorded errors is a deliberate skip marker
|
|
2215
|
+
// (#1557: oversized / repeatedly-unparseable files are persisted with
|
|
2216
|
+
// their reason so syncs stop retrying them) — leave those alone. The
|
|
2217
|
+
// #1541 wipe rows are the error-FREE zero-node rows.
|
|
2218
|
+
if (f.nodeCount === 0 &&
|
|
2219
|
+
!(0, grammars_1.isFileLevelOnlyLanguage)(f.language) &&
|
|
2220
|
+
(f.errors === undefined || f.errors.length === 0)) {
|
|
2221
|
+
this.queries.deleteFile(f.path);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2029
2225
|
async storeExtractionResult(filePath, content, language, stats, result, onYield) {
|
|
2226
|
+
// A kernel result can arrive as an undecoded buffer transport (empty
|
|
2227
|
+
// node/edge arrays, tables riding in kernelBuffers). Decode it before
|
|
2228
|
+
// storing — persisting the transport as-is records the file as having no
|
|
2229
|
+
// symbols at all (#1541). No-op for already-decoded results.
|
|
2230
|
+
result = (0, kernel_1.materializeKernelResult)(result, filePath, language);
|
|
2030
2231
|
// Bulk inserts run in bounded sub-transactions with a yield between, so a
|
|
2031
2232
|
// giant generated file (tens of thousands of symbols) can't block the
|
|
2032
2233
|
// event loop — and the #850 watchdog heartbeat — for the whole store.
|
|
@@ -2035,11 +2236,24 @@ class ExtractionOrchestrator {
|
|
|
2035
2236
|
// is unchanged: a partially-stored file has no record and re-indexes.
|
|
2036
2237
|
const STORE_CHUNK = 2000;
|
|
2037
2238
|
const contentHash = hashContent(content);
|
|
2038
|
-
// Check if file already exists and hasn't changed
|
|
2239
|
+
// Check if file already exists and hasn't changed. A skip/failure MARKER
|
|
2240
|
+
// row (zero nodes + recorded errors, #1557) never blocks a store carrying
|
|
2241
|
+
// real content: markers are written BEFORE the retry pass under the same
|
|
2242
|
+
// content hash, so treating them as "no changes" would silently discard a
|
|
2243
|
+
// successful retry's symbols — a permanent empty file presented as
|
|
2244
|
+
// recovered (the #1541 wipe, reintroduced through the marker path).
|
|
2039
2245
|
const existingFile = this.queries.getFileByPath(filePath);
|
|
2040
2246
|
if (existingFile && existingFile.contentHash === contentHash) {
|
|
2041
|
-
|
|
2247
|
+
const existingIsMarker = existingFile.nodeCount === 0 && (existingFile.errors?.length ?? 0) > 0;
|
|
2248
|
+
const incomingHasContent = result.nodes.length > 0;
|
|
2249
|
+
if (!existingIsMarker || !incomingHasContent) {
|
|
2250
|
+
return; // No changes
|
|
2251
|
+
}
|
|
2042
2252
|
}
|
|
2253
|
+
// Re-decided on every re-index of a changed file, so a banner added (or
|
|
2254
|
+
// removed) by an edit is reflected on the next sync (#1500). Computed after
|
|
2255
|
+
// the unchanged-file early return so untouched files pay nothing.
|
|
2256
|
+
const generated = (0, generated_detection_1.detectGeneratedFile)(filePath, content);
|
|
2043
2257
|
// Snapshot incoming cross-file edges BEFORE deleting this file's nodes.
|
|
2044
2258
|
// `deleteFile` cascades to delete every edge whose source OR target is a
|
|
2045
2259
|
// node in this file (edges.FK ... ON DELETE CASCADE). Edges whose SOURCE is
|
|
@@ -2067,15 +2281,53 @@ class ExtractionOrchestrator {
|
|
|
2067
2281
|
// This prevents FK violations when edges reference nodes that would
|
|
2068
2282
|
// be silently skipped by insertNode() (see issue #42).
|
|
2069
2283
|
const validNodes = result.nodes.filter((n) => n.id && n.kind && n.name && n.filePath && n.language);
|
|
2284
|
+
const insertedIds = new Set(validNodes.map((n) => n.id));
|
|
2285
|
+
const validEdges = result.edges.filter((e) => insertedIds.has(e.source) && insertedIds.has(e.target));
|
|
2286
|
+
const validRefs = result.unresolvedReferences
|
|
2287
|
+
.filter((ref) => insertedIds.has(ref.fromNodeId))
|
|
2288
|
+
.map((ref) => ({
|
|
2289
|
+
...ref,
|
|
2290
|
+
filePath: ref.filePath ?? filePath,
|
|
2291
|
+
language: ref.language ?? language,
|
|
2292
|
+
}));
|
|
2293
|
+
// Fast path for the common case (everything fits one chunk): the whole
|
|
2294
|
+
// file — nodes, edges, refs, file record — lands in ONE transaction with
|
|
2295
|
+
// no event-loop yields in between. Giant generated files keep the chunked
|
|
2296
|
+
// + yielding path below so the #850 watchdog heartbeat stays serviced.
|
|
2297
|
+
const fitsOneChunk = validNodes.length <= STORE_CHUNK &&
|
|
2298
|
+
validEdges.length <= STORE_CHUNK &&
|
|
2299
|
+
validRefs.length <= STORE_CHUNK;
|
|
2300
|
+
if (fitsOneChunk) {
|
|
2301
|
+
// Snapshot/re-resolution of cross-file incoming edges (below) still runs
|
|
2302
|
+
// for the sync path; on a fresh bulk index crossFileIncomingEdges is [].
|
|
2303
|
+
this.queries.storeFileBundle({
|
|
2304
|
+
nodes: validNodes,
|
|
2305
|
+
edges: validEdges,
|
|
2306
|
+
refs: validRefs,
|
|
2307
|
+
file: {
|
|
2308
|
+
path: filePath,
|
|
2309
|
+
contentHash,
|
|
2310
|
+
language,
|
|
2311
|
+
size: stats.size,
|
|
2312
|
+
modifiedAt: stats.mtimeMs,
|
|
2313
|
+
indexedAt: Date.now(),
|
|
2314
|
+
nodeCount: result.nodes.length,
|
|
2315
|
+
errors: result.errors.length > 0 ? result.errors : undefined,
|
|
2316
|
+
generated,
|
|
2317
|
+
},
|
|
2318
|
+
});
|
|
2319
|
+
if (crossFileIncomingEdges.length > 0) {
|
|
2320
|
+
this.reattachCrossFileEdges(crossFileIncomingEdges, validNodes);
|
|
2321
|
+
}
|
|
2322
|
+
return;
|
|
2323
|
+
}
|
|
2070
2324
|
// Insert nodes (chunked — see STORE_CHUNK above)
|
|
2071
2325
|
for (let i = 0; i < validNodes.length; i += STORE_CHUNK) {
|
|
2072
2326
|
this.queries.insertNodes(validNodes.slice(i, i + STORE_CHUNK));
|
|
2073
2327
|
await onYield?.();
|
|
2074
2328
|
}
|
|
2075
2329
|
// Filter edges to only reference nodes that were actually inserted
|
|
2076
|
-
if (
|
|
2077
|
-
const insertedIds = new Set(validNodes.map((n) => n.id));
|
|
2078
|
-
const validEdges = result.edges.filter((e) => insertedIds.has(e.source) && insertedIds.has(e.target));
|
|
2330
|
+
if (validEdges.length > 0) {
|
|
2079
2331
|
for (let i = 0; i < validEdges.length; i += STORE_CHUNK) {
|
|
2080
2332
|
this.queries.insertEdges(validEdges.slice(i, i + STORE_CHUNK));
|
|
2081
2333
|
await onYield?.();
|
|
@@ -2100,44 +2352,12 @@ class ExtractionOrchestrator {
|
|
|
2100
2352
|
// a ref from the target's plain name would strip receiver/qualifier
|
|
2101
2353
|
// context and risk a rebind a full re-index would never make.
|
|
2102
2354
|
if (crossFileIncomingEdges.length > 0) {
|
|
2103
|
-
|
|
2104
|
-
for (const n of validNodes) {
|
|
2105
|
-
newNodesByKindName.set(`${n.kind}\0${n.name}`, n.id);
|
|
2106
|
-
}
|
|
2107
|
-
const reinserted = [];
|
|
2108
|
-
const resurrected = [];
|
|
2109
|
-
for (const e of crossFileIncomingEdges) {
|
|
2110
|
-
const newTargetId = newNodesByKindName.get(`${e.targetKind}\0${e.targetName}`);
|
|
2111
|
-
if (newTargetId) {
|
|
2112
|
-
reinserted.push({ source: e.source, target: newTargetId, kind: e.kind, metadata: e.metadata, line: e.line, column: e.column, provenance: e.provenance });
|
|
2113
|
-
}
|
|
2114
|
-
else {
|
|
2115
|
-
const ref = resurrectRefFromDroppedEdge(e);
|
|
2116
|
-
if (ref)
|
|
2117
|
-
resurrected.push(ref);
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
|
-
if (reinserted.length > 0) {
|
|
2121
|
-
this.queries.insertEdges(reinserted);
|
|
2122
|
-
}
|
|
2123
|
-
if (resurrected.length > 0) {
|
|
2124
|
-
this.queries.insertUnresolvedRefsBatch(resurrected);
|
|
2125
|
-
}
|
|
2355
|
+
this.reattachCrossFileEdges(crossFileIncomingEdges, validNodes);
|
|
2126
2356
|
}
|
|
2127
2357
|
// Insert unresolved references in batch with denormalized filePath/language
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
.filter((ref) => insertedIds.has(ref.fromNodeId))
|
|
2132
|
-
.map((ref) => ({
|
|
2133
|
-
...ref,
|
|
2134
|
-
filePath: ref.filePath ?? filePath,
|
|
2135
|
-
language: ref.language ?? language,
|
|
2136
|
-
}));
|
|
2137
|
-
for (let i = 0; i < refsWithContext.length; i += STORE_CHUNK) {
|
|
2138
|
-
this.queries.insertUnresolvedRefsBatch(refsWithContext.slice(i, i + STORE_CHUNK));
|
|
2139
|
-
await onYield?.();
|
|
2140
|
-
}
|
|
2358
|
+
for (let i = 0; i < validRefs.length; i += STORE_CHUNK) {
|
|
2359
|
+
this.queries.insertUnresolvedRefsBatch(validRefs.slice(i, i + STORE_CHUNK));
|
|
2360
|
+
await onYield?.();
|
|
2141
2361
|
}
|
|
2142
2362
|
// Insert file record
|
|
2143
2363
|
const fileRecord = {
|
|
@@ -2149,9 +2369,126 @@ class ExtractionOrchestrator {
|
|
|
2149
2369
|
indexedAt: Date.now(),
|
|
2150
2370
|
nodeCount: result.nodes.length,
|
|
2151
2371
|
errors: result.errors.length > 0 ? result.errors : undefined,
|
|
2372
|
+
generated,
|
|
2152
2373
|
};
|
|
2153
2374
|
this.queries.upsertFile(fileRecord);
|
|
2154
2375
|
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Build one file's store bundle for the FRESH-DB path: no existing-file
|
|
2378
|
+
* check, no cross-file edge snapshot (both are re-index concerns — a fresh
|
|
2379
|
+
* database has neither). Filters mirror storeExtractionResult exactly.
|
|
2380
|
+
*/
|
|
2381
|
+
/** The FileRecord for a fresh-index store (nodeCount is the PRE-filter count). */
|
|
2382
|
+
buildFileRecord(filePath, content, language, stats, nodeCount, resultErrors) {
|
|
2383
|
+
return {
|
|
2384
|
+
path: filePath,
|
|
2385
|
+
contentHash: hashContent(content),
|
|
2386
|
+
language,
|
|
2387
|
+
size: stats.size,
|
|
2388
|
+
modifiedAt: stats.mtimeMs,
|
|
2389
|
+
indexedAt: Date.now(),
|
|
2390
|
+
nodeCount,
|
|
2391
|
+
errors: resultErrors.length > 0 ? resultErrors : undefined,
|
|
2392
|
+
// Decided here, once, while the content is already in memory — never at
|
|
2393
|
+
// query time (#1500). The header scan short-circuits on a single
|
|
2394
|
+
// substring test for ~every hand-written file.
|
|
2395
|
+
generated: (0, generated_detection_1.detectGeneratedFile)(filePath, content),
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
buildFreshStoreBundle(filePath, content, language, stats, result) {
|
|
2399
|
+
return (0, store_writer_1.finalizeStoreBundle)(result, filePath, language, this.buildFileRecord(filePath, content, language, stats, result.nodes.length, result.errors));
|
|
2400
|
+
}
|
|
2401
|
+
/**
|
|
2402
|
+
* Re-attach cross-file incoming edges snapshotted before a re-index delete
|
|
2403
|
+
* (#899): re-resolve each edge's target to the re-indexed node's new id by
|
|
2404
|
+
* (kind, name); targets that vanished are resurrected as their original
|
|
2405
|
+
* unresolved ref (#1240's removal-side counterpart) when the edge carries
|
|
2406
|
+
* its refName stamp.
|
|
2407
|
+
*/
|
|
2408
|
+
reattachCrossFileEdges(crossFileIncomingEdges, validNodes) {
|
|
2409
|
+
const newNodesByKindName = new Map();
|
|
2410
|
+
for (const n of validNodes) {
|
|
2411
|
+
newNodesByKindName.set(`${n.kind}\0${n.name}`, n.id);
|
|
2412
|
+
}
|
|
2413
|
+
const reinserted = [];
|
|
2414
|
+
const resurrected = [];
|
|
2415
|
+
for (const e of crossFileIncomingEdges) {
|
|
2416
|
+
const newTargetId = newNodesByKindName.get(`${e.targetKind}\0${e.targetName}`);
|
|
2417
|
+
if (newTargetId) {
|
|
2418
|
+
reinserted.push({ source: e.source, target: newTargetId, kind: e.kind, metadata: e.metadata, line: e.line, column: e.column, provenance: e.provenance });
|
|
2419
|
+
}
|
|
2420
|
+
else {
|
|
2421
|
+
const ref = resurrectRefFromDroppedEdge(e);
|
|
2422
|
+
if (ref)
|
|
2423
|
+
resurrected.push(ref);
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
if (reinserted.length > 0) {
|
|
2427
|
+
this.queries.insertEdges(reinserted);
|
|
2428
|
+
}
|
|
2429
|
+
if (resurrected.length > 0) {
|
|
2430
|
+
this.queries.insertUnresolvedRefsBatch(resurrected);
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
/**
|
|
2434
|
+
* Re-open, for re-resolution, every resolution edge whose answer this sync
|
|
2435
|
+
* may have changed — the fix for index drift (CG-33).
|
|
2436
|
+
*
|
|
2437
|
+
* Incremental sync re-resolves only the references IN the changed files, but
|
|
2438
|
+
* resolution's answer is a function of the WHOLE graph: a reference binds to
|
|
2439
|
+
* one of the same-named definitions project-wide, so adding or removing a
|
|
2440
|
+
* definition of `pct` can change which `pct` every other file's `pct(...)`
|
|
2441
|
+
* should bind to. Those other files are never revisited, and their references
|
|
2442
|
+
* resolved successfully once and were deleted from `unresolved_refs`, so
|
|
2443
|
+
* nothing existed to revisit them with — the index kept an answer that was
|
|
2444
|
+
* correct against an older graph. Measured on codegraph's own long-lived
|
|
2445
|
+
* index: 4.3% of distinct edges differed from a clean rebuild, in BOTH
|
|
2446
|
+
* directions, overwhelmingly `calls`. See docs/benchmarks/index-drift-cg33.md.
|
|
2447
|
+
*
|
|
2448
|
+
* This deletes each affected edge and re-inserts it as the reference that
|
|
2449
|
+
* created it (the refName/refKind stamp), status='pending', for the sync's
|
|
2450
|
+
* resolution sweep to bind against the post-sync graph — the same input a
|
|
2451
|
+
* full rebuild resolves from, which is what makes the two converge.
|
|
2452
|
+
*
|
|
2453
|
+
* Deliberately conservative in three ways, because a wrong deletion is a
|
|
2454
|
+
* permanent edge loss while a missed rebind is only residual drift:
|
|
2455
|
+
* - an edge with no refName stamp (synthesized, or built by an engine older
|
|
2456
|
+
* than the stamp) is left ALONE rather than reconstructed from the target's
|
|
2457
|
+
* plain name, same rule as `resurrectRefFromDroppedEdge`;
|
|
2458
|
+
* - edges whose source is in a file this sync already re-extracted are
|
|
2459
|
+
* skipped — their references were re-resolved from scratch moments ago;
|
|
2460
|
+
* - very common names are skipped by the per-name ceiling in
|
|
2461
|
+
* `getResolutionEdgesByTargetName`.
|
|
2462
|
+
*
|
|
2463
|
+
* Returns the number of references resurrected.
|
|
2464
|
+
*/
|
|
2465
|
+
resurrectStaleResolutionEdges(definitionDelta, changedFilePaths) {
|
|
2466
|
+
if (definitionDelta.length === 0)
|
|
2467
|
+
return 0;
|
|
2468
|
+
const alreadyFresh = new Set(changedFilePaths);
|
|
2469
|
+
const candidates = this.queries.getResolutionEdgesByTargetName(definitionDelta);
|
|
2470
|
+
const edgeIds = [];
|
|
2471
|
+
const refs = [];
|
|
2472
|
+
for (const e of candidates) {
|
|
2473
|
+
if (alreadyFresh.has(e.sourceFilePath))
|
|
2474
|
+
continue;
|
|
2475
|
+
const ref = resurrectRefFromDroppedEdge(e);
|
|
2476
|
+
if (!ref)
|
|
2477
|
+
continue; // no stamp — never delete what we cannot restore
|
|
2478
|
+
edgeIds.push(e.edgeId);
|
|
2479
|
+
refs.push(ref);
|
|
2480
|
+
}
|
|
2481
|
+
if (refs.length === 0)
|
|
2482
|
+
return 0;
|
|
2483
|
+
// Delete first. The sweep re-inserts whichever edge resolution now picks,
|
|
2484
|
+
// and `insertEdges` is INSERT OR IGNORE against idx_edges_identity — so a
|
|
2485
|
+
// rebind to the same target is a clean no-op, but leaving the old row in
|
|
2486
|
+
// place for a rebind ELSEWHERE would keep both, turning drift into
|
|
2487
|
+
// duplication.
|
|
2488
|
+
this.queries.deleteEdgesByIds(edgeIds);
|
|
2489
|
+
this.queries.insertUnresolvedRefsBatch(refs);
|
|
2490
|
+
return refs.length;
|
|
2491
|
+
}
|
|
2155
2492
|
/**
|
|
2156
2493
|
* Sync the index with the current file state.
|
|
2157
2494
|
*
|
|
@@ -2160,7 +2497,17 @@ class ExtractionOrchestrator {
|
|
|
2160
2497
|
* changes. This works in non-git projects and catches committed changes from
|
|
2161
2498
|
* `git pull`/`checkout`/`merge`/`rebase` that `git status` cannot see.
|
|
2162
2499
|
*/
|
|
2163
|
-
async sync(onProgress
|
|
2500
|
+
async sync(onProgress,
|
|
2501
|
+
/**
|
|
2502
|
+
* Watcher fast path: the exact project-relative paths the OS reported as
|
|
2503
|
+
* changed. When provided, reconciliation runs over ONLY these paths —
|
|
2504
|
+
* per-path logic identical to the full walk (stat pre-filter, hash
|
|
2505
|
+
* confirm, the #1240 removal/resurrection flow) — skipping the O(repo)
|
|
2506
|
+
* scan and tracked-load. Callers must pass undefined whenever the change
|
|
2507
|
+
* set is not exactly known (directory removals, event overflow): the full
|
|
2508
|
+
* scan-diff remains the ground truth those cases need (#1285).
|
|
2509
|
+
*/
|
|
2510
|
+
scopedPaths) {
|
|
2164
2511
|
await (0, grammars_1.initGrammars)(); // Initialize WASM runtime (grammars loaded lazily below)
|
|
2165
2512
|
const startTime = Date.now();
|
|
2166
2513
|
let filesChecked = 0;
|
|
@@ -2169,6 +2516,10 @@ class ExtractionOrchestrator {
|
|
|
2169
2516
|
let filesRemoved = 0;
|
|
2170
2517
|
let nodesUpdated = 0;
|
|
2171
2518
|
const changedFilePaths = [];
|
|
2519
|
+
// `file\0name` definition pairs for the files this sync touches, sampled
|
|
2520
|
+
// BEFORE their nodes are replaced/deleted. Compared against the post-store
|
|
2521
|
+
// pairs below to derive `definitionDelta` (CG-33).
|
|
2522
|
+
const pairsBefore = new Set();
|
|
2172
2523
|
onProgress?.({
|
|
2173
2524
|
phase: 'scanning',
|
|
2174
2525
|
current: 0,
|
|
@@ -2185,15 +2536,53 @@ class ExtractionOrchestrator {
|
|
|
2185
2536
|
// changes from `git pull`/`checkout`/`merge`/`rebase` — which `git status`
|
|
2186
2537
|
// cannot see, because the working tree is clean afterward.
|
|
2187
2538
|
const tSyncScan = Date.now();
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2539
|
+
let currentFiles;
|
|
2540
|
+
let trackedFiles;
|
|
2541
|
+
if (scopedPaths && scopedPaths.length > 0) {
|
|
2542
|
+
// Scoped reconcile: stat only the reported paths. filesChecked counts
|
|
2543
|
+
// the PATHS examined (not the files found) — it must stay non-zero even
|
|
2544
|
+
// when every scoped path was a deletion, because CodeGraph.watch()
|
|
2545
|
+
// reads `filesChecked === 0 && durationMs === 0` as the
|
|
2546
|
+
// lock-unavailable signature (#449).
|
|
2547
|
+
const unique = [...new Set(scopedPaths)];
|
|
2548
|
+
// A scoped path is "present" only if it exists AND is in scope — the
|
|
2549
|
+
// same two gates the full walk applies (source extension, scope
|
|
2550
|
+
// matcher). Without the scope gate a caller's stale view of scope
|
|
2551
|
+
// leaked straight into the index: the watcher re-parsed a file the
|
|
2552
|
+
// user had just excluded in `codegraph.json` while `codegraph sync`
|
|
2553
|
+
// removed it (#1590). Out-of-scope paths fall out of `currentFiles`,
|
|
2554
|
+
// so a tracked one takes the removal branch below, exactly as a full
|
|
2555
|
+
// sync would treat it. (`include`-forced paths pass: ScopeIgnore
|
|
2556
|
+
// applies the include precedence itself.)
|
|
2557
|
+
const scope = this.scopedSyncMatcher();
|
|
2558
|
+
const overrides = (0, project_config_1.loadExtensionOverrides)(this.rootDir);
|
|
2559
|
+
currentFiles = unique.filter((p) => (0, grammars_1.isSourceFile)(p, overrides) &&
|
|
2560
|
+
!scope.ignores(p) &&
|
|
2561
|
+
fs.existsSync(path.join(this.rootDir, p)));
|
|
2562
|
+
trackedFiles = [];
|
|
2563
|
+
for (const p of unique) {
|
|
2564
|
+
const rec = this.queries.getFileByPath(p);
|
|
2565
|
+
if (rec)
|
|
2566
|
+
trackedFiles.push(rec);
|
|
2567
|
+
}
|
|
2568
|
+
filesChecked = unique.length;
|
|
2569
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
2570
|
+
console.error(`[phase-timing] sync-scoped: ${Date.now() - tSyncScan}ms (${unique.length} paths, ${trackedFiles.length} tracked)`);
|
|
2571
|
+
}
|
|
2572
|
+
else {
|
|
2573
|
+
currentFiles = await scanDirectoryAsync(this.rootDir);
|
|
2574
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
2575
|
+
console.error(`[phase-timing] sync-scan: ${Date.now() - tSyncScan}ms (${currentFiles.length} files)`);
|
|
2576
|
+
filesChecked = currentFiles.length;
|
|
2577
|
+
// Full reconcile only (scoped syncs must not touch rows outside their
|
|
2578
|
+
// scope): drop zero-node rows so the wiped files re-index as adds below.
|
|
2579
|
+
this.healZeroNodeRows();
|
|
2580
|
+
const tTracked = Date.now();
|
|
2581
|
+
trackedFiles = this.queries.getAllFiles();
|
|
2582
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
2583
|
+
console.error(`[phase-timing] sync-tracked-load: ${Date.now() - tTracked}ms (${trackedFiles.length} tracked)`);
|
|
2584
|
+
}
|
|
2192
2585
|
const currentSet = new Set(currentFiles);
|
|
2193
|
-
const tTracked = Date.now();
|
|
2194
|
-
const trackedFiles = this.queries.getAllFiles();
|
|
2195
|
-
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
2196
|
-
console.error(`[phase-timing] sync-tracked-load: ${Date.now() - tTracked}ms (${trackedFiles.length} tracked)`);
|
|
2197
2586
|
const trackedMap = new Map();
|
|
2198
2587
|
for (const f of trackedFiles) {
|
|
2199
2588
|
trackedMap.set(f.path, f);
|
|
@@ -2213,6 +2602,10 @@ class ExtractionOrchestrator {
|
|
|
2213
2602
|
// failed until the symbol reappears somewhere. (A deleted file whose
|
|
2214
2603
|
// CALLERS are also being deleted is fine: their nodes cascade later
|
|
2215
2604
|
// in this loop and take the resurrected rows with them.)
|
|
2605
|
+
// Every name this file defined is about to stop existing here, which
|
|
2606
|
+
// narrows the candidate set for that name repo-wide (CG-33).
|
|
2607
|
+
for (const pair of this.queries.getNodeNamePairsByFiles([tracked.path]))
|
|
2608
|
+
pairsBefore.add(pair);
|
|
2216
2609
|
const incoming = this.queries.getCrossFileIncomingEdgesWithTarget(tracked.path);
|
|
2217
2610
|
if (incoming.length > 0) {
|
|
2218
2611
|
const resurrected = incoming
|
|
@@ -2277,6 +2670,14 @@ class ExtractionOrchestrator {
|
|
|
2277
2670
|
filesModified++;
|
|
2278
2671
|
}
|
|
2279
2672
|
}
|
|
2673
|
+
// Sampled here — after the add/modify classification, before any file is
|
|
2674
|
+
// re-extracted — because `storeExtractionResult` deletes a file's nodes
|
|
2675
|
+
// before inserting the new ones, so this is the last point the pre-edit
|
|
2676
|
+
// definition set is readable (CG-33).
|
|
2677
|
+
if (filesToIndex.length > 0) {
|
|
2678
|
+
for (const pair of this.queries.getNodeNamePairsByFiles(filesToIndex))
|
|
2679
|
+
pairsBefore.add(pair);
|
|
2680
|
+
}
|
|
2280
2681
|
// Load only grammars needed for changed files
|
|
2281
2682
|
if (filesToIndex.length > 0) {
|
|
2282
2683
|
const overrides = (0, project_config_1.loadExtensionOverrides)(this.rootDir);
|
|
@@ -2300,6 +2701,28 @@ class ExtractionOrchestrator {
|
|
|
2300
2701
|
const result = await this.indexFile(filePath);
|
|
2301
2702
|
nodesUpdated += result.nodes.length;
|
|
2302
2703
|
}
|
|
2704
|
+
// Names whose definition set this sync changed: a `file\0name` pair present
|
|
2705
|
+
// before but not after (removed/renamed away) or after but not before
|
|
2706
|
+
// (added). A pair on both sides is untouched as far as resolution's
|
|
2707
|
+
// candidate set is concerned — only its node id moved, which
|
|
2708
|
+
// reattachCrossFileEdges already follows — so an edit that only changes
|
|
2709
|
+
// bodies yields an empty delta and no downstream rebind work (CG-33).
|
|
2710
|
+
//
|
|
2711
|
+
// Compared per FILE, not as one name set over the whole batch: a commit
|
|
2712
|
+
// that adds `collect` to a new file while an unrelated changed file already
|
|
2713
|
+
// defined `collect` must still flag the name, and a bare name set cancels
|
|
2714
|
+
// exactly that case out. That miss left the largest residual class in the
|
|
2715
|
+
// first measurement of this fix.
|
|
2716
|
+
const pairsAfter = this.queries.getNodeNamePairsByFiles(filesToIndex);
|
|
2717
|
+
const deltaNames = new Set();
|
|
2718
|
+
const nameOf = (pair) => pair.slice(pair.indexOf('\0') + 1);
|
|
2719
|
+
for (const pair of pairsBefore)
|
|
2720
|
+
if (!pairsAfter.has(pair))
|
|
2721
|
+
deltaNames.add(nameOf(pair));
|
|
2722
|
+
for (const pair of pairsAfter)
|
|
2723
|
+
if (!pairsBefore.has(pair))
|
|
2724
|
+
deltaNames.add(nameOf(pair));
|
|
2725
|
+
const definitionDelta = [...deltaNames];
|
|
2303
2726
|
return {
|
|
2304
2727
|
filesChecked,
|
|
2305
2728
|
filesAdded,
|
|
@@ -2308,6 +2731,7 @@ class ExtractionOrchestrator {
|
|
|
2308
2731
|
nodesUpdated,
|
|
2309
2732
|
durationMs: Date.now() - startTime,
|
|
2310
2733
|
changedFilePaths: changedFilePaths.length > 0 ? changedFilePaths : undefined,
|
|
2734
|
+
definitionDelta: definitionDelta.length > 0 ? definitionDelta : undefined,
|
|
2311
2735
|
};
|
|
2312
2736
|
}
|
|
2313
2737
|
/**
|