@stupidloud/codegraph 0.8.1 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +319 -152
- package/dist/bin/codegraph.d.ts +4 -0
- package/dist/bin/codegraph.d.ts.map +1 -1
- package/dist/bin/codegraph.js +354 -90
- package/dist/bin/codegraph.js.map +1 -1
- package/dist/bin/node-version-check.d.ts +17 -0
- package/dist/bin/node-version-check.d.ts.map +1 -1
- package/dist/bin/node-version-check.js +37 -0
- package/dist/bin/node-version-check.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -11
- package/dist/config.js.map +1 -1
- package/dist/context/formatter.d.ts.map +1 -1
- package/dist/context/formatter.js +25 -6
- package/dist/context/formatter.js.map +1 -1
- package/dist/context/index.d.ts +22 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +257 -6
- package/dist/context/index.js.map +1 -1
- package/dist/context/markers.d.ts +19 -0
- package/dist/context/markers.d.ts.map +1 -0
- package/dist/context/markers.js +22 -0
- package/dist/context/markers.js.map +1 -0
- package/dist/db/index.d.ts +30 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +75 -25
- package/dist/db/index.js.map +1 -1
- package/dist/db/queries.d.ts +104 -0
- package/dist/db/queries.d.ts.map +1 -1
- package/dist/db/queries.js +328 -31
- package/dist/db/queries.js.map +1 -1
- package/dist/db/sqlite-adapter.d.ts +24 -23
- package/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/dist/db/sqlite-adapter.js +54 -174
- package/dist/db/sqlite-adapter.js.map +1 -1
- package/dist/directory.d.ts.map +1 -1
- package/dist/directory.js +6 -20
- package/dist/directory.js.map +1 -1
- package/dist/extraction/generated-detection.d.ts +30 -0
- package/dist/extraction/generated-detection.d.ts.map +1 -0
- package/dist/extraction/generated-detection.js +80 -0
- package/dist/extraction/generated-detection.js.map +1 -0
- package/dist/extraction/grammars.d.ts +23 -1
- package/dist/extraction/grammars.d.ts.map +1 -1
- package/dist/extraction/grammars.js +107 -3
- package/dist/extraction/grammars.js.map +1 -1
- package/dist/extraction/index.d.ts +22 -14
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +272 -183
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/dist/extraction/languages/c-cpp.js +45 -0
- package/dist/extraction/languages/c-cpp.js.map +1 -1
- package/dist/extraction/languages/csharp.d.ts.map +1 -1
- package/dist/extraction/languages/csharp.js +2 -1
- package/dist/extraction/languages/csharp.js.map +1 -1
- package/dist/extraction/languages/go.d.ts.map +1 -1
- package/dist/extraction/languages/go.js +18 -2
- package/dist/extraction/languages/go.js.map +1 -1
- package/dist/extraction/languages/index.d.ts.map +1 -1
- package/dist/extraction/languages/index.js +6 -0
- package/dist/extraction/languages/index.js.map +1 -1
- package/dist/extraction/languages/java.d.ts.map +1 -1
- package/dist/extraction/languages/java.js +6 -0
- package/dist/extraction/languages/java.js.map +1 -1
- package/dist/extraction/languages/kotlin.d.ts.map +1 -1
- package/dist/extraction/languages/kotlin.js +6 -0
- package/dist/extraction/languages/kotlin.js.map +1 -1
- package/dist/extraction/languages/lua.d.ts +3 -0
- package/dist/extraction/languages/lua.d.ts.map +1 -0
- package/dist/extraction/languages/lua.js +150 -0
- package/dist/extraction/languages/lua.js.map +1 -0
- package/dist/extraction/languages/luau.d.ts +3 -0
- package/dist/extraction/languages/luau.d.ts.map +1 -0
- package/dist/extraction/languages/luau.js +37 -0
- package/dist/extraction/languages/luau.js.map +1 -0
- package/dist/extraction/languages/objc.d.ts +3 -0
- package/dist/extraction/languages/objc.d.ts.map +1 -0
- package/dist/extraction/languages/objc.js +133 -0
- package/dist/extraction/languages/objc.js.map +1 -0
- package/dist/extraction/mybatis-extractor.d.ts +48 -0
- package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
- package/dist/extraction/mybatis-extractor.js +198 -0
- package/dist/extraction/mybatis-extractor.js.map +1 -0
- package/dist/extraction/tree-sitter-types.d.ts +14 -0
- package/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.d.ts +84 -0
- package/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.js +715 -16
- package/dist/extraction/tree-sitter.js.map +1 -1
- package/dist/extraction/vue-extractor.d.ts +15 -0
- package/dist/extraction/vue-extractor.d.ts.map +1 -1
- package/dist/extraction/vue-extractor.js +88 -0
- package/dist/extraction/vue-extractor.js.map +1 -1
- package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
- package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
- package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
- package/dist/extraction/wasm-runtime-flags.js +106 -0
- package/dist/extraction/wasm-runtime-flags.js.map +1 -0
- package/dist/graph/traversal.d.ts.map +1 -1
- package/dist/graph/traversal.js +76 -38
- package/dist/graph/traversal.js.map +1 -1
- package/dist/index.d.ts +77 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +133 -19
- package/dist/index.js.map +1 -1
- package/dist/installer/config-writer.d.ts +7 -8
- package/dist/installer/config-writer.d.ts.map +1 -1
- package/dist/installer/config-writer.js +7 -27
- package/dist/installer/config-writer.js.map +1 -1
- package/dist/installer/index.d.ts +51 -16
- package/dist/installer/index.d.ts.map +1 -1
- package/dist/installer/index.js +120 -29
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/instructions-template.d.ts +11 -21
- package/dist/installer/instructions-template.d.ts.map +1 -1
- package/dist/installer/instructions-template.js +12 -56
- package/dist/installer/instructions-template.js.map +1 -1
- package/dist/installer/targets/antigravity.d.ts +57 -0
- package/dist/installer/targets/antigravity.d.ts.map +1 -0
- package/dist/installer/targets/antigravity.js +308 -0
- package/dist/installer/targets/antigravity.js.map +1 -0
- package/dist/installer/targets/claude.d.ts +26 -1
- package/dist/installer/targets/claude.d.ts.map +1 -1
- package/dist/installer/targets/claude.js +118 -40
- package/dist/installer/targets/claude.js.map +1 -1
- package/dist/installer/targets/codex.d.ts.map +1 -1
- package/dist/installer/targets/codex.js +15 -13
- package/dist/installer/targets/codex.js.map +1 -1
- package/dist/installer/targets/cursor.d.ts.map +1 -1
- package/dist/installer/targets/cursor.js +61 -36
- package/dist/installer/targets/cursor.js.map +1 -1
- package/dist/installer/targets/gemini.d.ts +26 -0
- package/dist/installer/targets/gemini.d.ts.map +1 -0
- package/dist/installer/targets/gemini.js +167 -0
- package/dist/installer/targets/gemini.js.map +1 -0
- package/dist/installer/targets/hermes.d.ts +18 -0
- package/dist/installer/targets/hermes.d.ts.map +1 -0
- package/dist/installer/targets/hermes.js +359 -0
- package/dist/installer/targets/hermes.js.map +1 -0
- package/dist/installer/targets/kiro.d.ts +27 -0
- package/dist/installer/targets/kiro.d.ts.map +1 -0
- package/dist/installer/targets/kiro.js +178 -0
- package/dist/installer/targets/kiro.js.map +1 -0
- package/dist/installer/targets/opencode.d.ts.map +1 -1
- package/dist/installer/targets/opencode.js +15 -13
- package/dist/installer/targets/opencode.js.map +1 -1
- package/dist/installer/targets/registry.d.ts.map +1 -1
- package/dist/installer/targets/registry.js +8 -0
- package/dist/installer/targets/registry.js.map +1 -1
- package/dist/installer/targets/shared.d.ts.map +1 -1
- package/dist/installer/targets/shared.js +3 -2
- package/dist/installer/targets/shared.js.map +1 -1
- package/dist/installer/targets/types.d.ts +1 -16
- package/dist/installer/targets/types.d.ts.map +1 -1
- package/dist/mcp/daemon-paths.d.ts +46 -0
- package/dist/mcp/daemon-paths.d.ts.map +1 -0
- package/dist/mcp/daemon-paths.js +125 -0
- package/dist/mcp/daemon-paths.js.map +1 -0
- package/dist/mcp/daemon.d.ts +161 -0
- package/dist/mcp/daemon.d.ts.map +1 -0
- package/dist/mcp/daemon.js +403 -0
- package/dist/mcp/daemon.js.map +1 -0
- package/dist/mcp/engine.d.ts +105 -0
- package/dist/mcp/engine.d.ts.map +1 -0
- package/dist/mcp/engine.js +270 -0
- package/dist/mcp/engine.js.map +1 -0
- package/dist/mcp/index.d.ts +70 -52
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +355 -331
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/proxy.d.ts +81 -0
- package/dist/mcp/proxy.d.ts.map +1 -0
- package/dist/mcp/proxy.js +510 -0
- package/dist/mcp/proxy.js.map +1 -0
- package/dist/mcp/server-instructions.d.ts +1 -1
- package/dist/mcp/server-instructions.d.ts.map +1 -1
- package/dist/mcp/server-instructions.js +21 -21
- package/dist/mcp/session.d.ts +77 -0
- package/dist/mcp/session.d.ts.map +1 -0
- package/dist/mcp/session.js +294 -0
- package/dist/mcp/session.js.map +1 -0
- package/dist/mcp/tools.d.ts +171 -15
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +1714 -298
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/transport.d.ts +111 -29
- package/dist/mcp/transport.d.ts.map +1 -1
- package/dist/mcp/transport.js +181 -71
- package/dist/mcp/transport.js.map +1 -1
- package/dist/mcp/version.d.ts +19 -0
- package/dist/mcp/version.d.ts.map +1 -0
- package/dist/mcp/version.js +71 -0
- package/dist/mcp/version.js.map +1 -0
- package/dist/resolution/callback-synthesizer.d.ts +10 -0
- package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
- package/dist/resolution/callback-synthesizer.js +1300 -0
- package/dist/resolution/callback-synthesizer.js.map +1 -0
- package/dist/resolution/frameworks/csharp.d.ts.map +1 -1
- package/dist/resolution/frameworks/csharp.js +36 -8
- package/dist/resolution/frameworks/csharp.js.map +1 -1
- package/dist/resolution/frameworks/drupal.d.ts +51 -0
- package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
- package/dist/resolution/frameworks/drupal.js +367 -0
- package/dist/resolution/frameworks/drupal.js.map +1 -0
- package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
- package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
- package/dist/resolution/frameworks/expo-modules.js +143 -0
- package/dist/resolution/frameworks/expo-modules.js.map +1 -0
- package/dist/resolution/frameworks/express.d.ts.map +1 -1
- package/dist/resolution/frameworks/express.js +102 -19
- package/dist/resolution/frameworks/express.js.map +1 -1
- package/dist/resolution/frameworks/fabric.d.ts +3 -0
- package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
- package/dist/resolution/frameworks/fabric.js +354 -0
- package/dist/resolution/frameworks/fabric.js.map +1 -0
- package/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/dist/resolution/frameworks/go.js +6 -3
- package/dist/resolution/frameworks/go.js.map +1 -1
- package/dist/resolution/frameworks/index.d.ts +6 -0
- package/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/dist/resolution/frameworks/index.js +29 -1
- package/dist/resolution/frameworks/index.js.map +1 -1
- package/dist/resolution/frameworks/java.d.ts.map +1 -1
- package/dist/resolution/frameworks/java.js +339 -12
- package/dist/resolution/frameworks/java.js.map +1 -1
- package/dist/resolution/frameworks/laravel.d.ts.map +1 -1
- package/dist/resolution/frameworks/laravel.js +17 -8
- package/dist/resolution/frameworks/laravel.js.map +1 -1
- package/dist/resolution/frameworks/nestjs.d.ts.map +1 -1
- package/dist/resolution/frameworks/nestjs.js +324 -0
- package/dist/resolution/frameworks/nestjs.js.map +1 -1
- package/dist/resolution/frameworks/play.d.ts +19 -0
- package/dist/resolution/frameworks/play.d.ts.map +1 -0
- package/dist/resolution/frameworks/play.js +111 -0
- package/dist/resolution/frameworks/play.js.map +1 -0
- package/dist/resolution/frameworks/python.d.ts.map +1 -1
- package/dist/resolution/frameworks/python.js +134 -16
- package/dist/resolution/frameworks/python.js.map +1 -1
- package/dist/resolution/frameworks/react-native.d.ts +3 -0
- package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
- package/dist/resolution/frameworks/react-native.js +360 -0
- package/dist/resolution/frameworks/react-native.js.map +1 -0
- package/dist/resolution/frameworks/react.d.ts.map +1 -1
- package/dist/resolution/frameworks/react.js +96 -3
- package/dist/resolution/frameworks/react.js.map +1 -1
- package/dist/resolution/frameworks/ruby.d.ts.map +1 -1
- package/dist/resolution/frameworks/ruby.js +106 -2
- package/dist/resolution/frameworks/ruby.js.map +1 -1
- package/dist/resolution/frameworks/rust.d.ts.map +1 -1
- package/dist/resolution/frameworks/rust.js +102 -5
- package/dist/resolution/frameworks/rust.js.map +1 -1
- package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
- package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
- package/dist/resolution/frameworks/swift-objc.js +252 -0
- package/dist/resolution/frameworks/swift-objc.js.map +1 -0
- package/dist/resolution/frameworks/swift.d.ts.map +1 -1
- package/dist/resolution/frameworks/swift.js +30 -6
- package/dist/resolution/frameworks/swift.js.map +1 -1
- package/dist/resolution/go-module.d.ts +26 -0
- package/dist/resolution/go-module.d.ts.map +1 -0
- package/dist/resolution/go-module.js +78 -0
- package/dist/resolution/go-module.js.map +1 -0
- package/dist/resolution/import-resolver.d.ts +28 -0
- package/dist/resolution/import-resolver.d.ts.map +1 -1
- package/dist/resolution/import-resolver.js +617 -5
- package/dist/resolution/import-resolver.js.map +1 -1
- package/dist/resolution/index.d.ts +11 -0
- package/dist/resolution/index.d.ts.map +1 -1
- package/dist/resolution/index.js +196 -10
- package/dist/resolution/index.js.map +1 -1
- package/dist/resolution/lru-cache.d.ts +24 -0
- package/dist/resolution/lru-cache.d.ts.map +1 -0
- package/dist/resolution/lru-cache.js +62 -0
- package/dist/resolution/lru-cache.js.map +1 -0
- package/dist/resolution/name-matcher.d.ts.map +1 -1
- package/dist/resolution/name-matcher.js +212 -0
- package/dist/resolution/name-matcher.js.map +1 -1
- package/dist/resolution/swift-objc-bridge.d.ts +134 -0
- package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
- package/dist/resolution/swift-objc-bridge.js +256 -0
- package/dist/resolution/swift-objc-bridge.js.map +1 -0
- package/dist/resolution/types.d.ts +44 -0
- package/dist/resolution/types.d.ts.map +1 -1
- package/dist/resolution/workspace-packages.d.ts +48 -0
- package/dist/resolution/workspace-packages.d.ts.map +1 -0
- package/dist/resolution/workspace-packages.js +208 -0
- package/dist/resolution/workspace-packages.js.map +1 -0
- package/dist/search/query-utils.d.ts +18 -0
- package/dist/search/query-utils.d.ts.map +1 -1
- package/dist/search/query-utils.js +30 -0
- package/dist/search/query-utils.js.map +1 -1
- package/dist/sync/git-hooks.d.ts.map +1 -1
- package/dist/sync/git-hooks.js +2 -0
- package/dist/sync/git-hooks.js.map +1 -1
- package/dist/sync/index.d.ts +3 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +8 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/watcher.d.ts +214 -12
- package/dist/sync/watcher.d.ts.map +1 -1
- package/dist/sync/watcher.js +467 -55
- package/dist/sync/watcher.js.map +1 -1
- package/dist/sync/worktree.d.ts +54 -0
- package/dist/sync/worktree.d.ts.map +1 -0
- package/dist/sync/worktree.js +137 -0
- package/dist/sync/worktree.js.map +1 -0
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.js +1 -1
- package/package.json +2 -2
- package/scripts/add-lang/bench.sh +60 -0
- package/scripts/add-lang/check-grammar.mjs +75 -0
- package/scripts/add-lang/dump-ast.mjs +103 -0
- package/scripts/add-lang/verify-extraction.mjs +70 -0
- package/scripts/agent-eval/arms-F.sh +21 -0
- package/scripts/agent-eval/arms-matrix.sh +37 -0
- package/scripts/agent-eval/bench-readme.sh +28 -0
- package/scripts/agent-eval/bench-why-repo.sh +22 -0
- package/scripts/agent-eval/block-read-hook.sh +19 -0
- package/scripts/agent-eval/hook-settings.json +15 -0
- package/scripts/agent-eval/itrun.sh +24 -11
- package/scripts/agent-eval/parse-arms.mjs +116 -0
- package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
- package/scripts/agent-eval/probe-context.mjs +21 -0
- package/scripts/agent-eval/probe-explore.mjs +40 -0
- package/scripts/agent-eval/probe-node.mjs +20 -0
- package/scripts/agent-eval/probe-sweep.mjs +119 -0
- package/scripts/agent-eval/probe-trace.mjs +20 -0
- package/scripts/agent-eval/run-arms.sh +56 -0
- package/scripts/agent-eval/seq-matrix.mjs +137 -0
- package/scripts/build-bundle.sh +118 -0
- package/scripts/npm-sdk.js +75 -0
- package/scripts/npm-shim.js +246 -0
- package/scripts/pack-npm.sh +119 -0
- package/scripts/prepare-release.mjs +270 -0
- package/scripts/patch-tree-sitter-dart.js +0 -112
- package/scripts/release.sh +0 -68
package/dist/sync/watcher.js
CHANGED
|
@@ -2,11 +2,34 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* File Watcher
|
|
4
4
|
*
|
|
5
|
-
* Watches the project directory for file changes and triggers
|
|
6
|
-
*
|
|
5
|
+
* Watches the project directory for file changes and triggers debounced sync
|
|
6
|
+
* operations to keep the code graph up-to-date.
|
|
7
7
|
*
|
|
8
|
-
* Uses Node
|
|
9
|
-
*
|
|
8
|
+
* Uses Node's built-in `fs.watch` directly (no third-party watcher, no native
|
|
9
|
+
* addon) with a per-platform strategy chosen to keep the open-descriptor /
|
|
10
|
+
* kernel-watch cost BOUNDED rather than growing with the number of files:
|
|
11
|
+
*
|
|
12
|
+
* - macOS / Windows: a SINGLE recursive `fs.watch(root, {recursive:true})`.
|
|
13
|
+
* libuv maps this to one FSEvents stream (macOS) / one
|
|
14
|
+
* ReadDirectoryChangesW handle (Windows), so it costs O(1) descriptors no
|
|
15
|
+
* matter how large the tree. This is the fix for the macOS file-table
|
|
16
|
+
* exhaustion (#644 / #496 / #555 / #628): the previous watcher held one
|
|
17
|
+
* open fd PER WATCHED FILE on macOS (tens of thousands of REG fds), which
|
|
18
|
+
* exhausted `kern.maxfiles` and crashed unrelated processes system-wide.
|
|
19
|
+
*
|
|
20
|
+
* - Linux: recursive `fs.watch` is unsupported, so we watch each (non-ignored)
|
|
21
|
+
* DIRECTORY with one inotify watch — O(directories), NOT O(files). New
|
|
22
|
+
* directories are picked up dynamically and an overall watch cap bounds
|
|
23
|
+
* inotify usage on pathological monorepos (#579). A single inotify watch on
|
|
24
|
+
* a directory already reports create/modify/delete for its children, so
|
|
25
|
+
* per-file watches are never needed.
|
|
26
|
+
*
|
|
27
|
+
* Excluded trees (node_modules/, dist/, .git/, …) are filtered via the
|
|
28
|
+
* indexer's `buildDefaultIgnore` (built-in default-ignore dirs + the project's
|
|
29
|
+
* .gitignore) — on Linux they're never descended into (so they cost no watch),
|
|
30
|
+
* and on macOS/Windows the single recursive stream still covers them but their
|
|
31
|
+
* events are dropped before any sync is scheduled. Either way the watcher's
|
|
32
|
+
* scope matches the indexer's (#276 / #407).
|
|
10
33
|
*/
|
|
11
34
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
35
|
if (k2 === undefined) k2 = k;
|
|
@@ -42,93 +65,353 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
42
65
|
};
|
|
43
66
|
})();
|
|
44
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.FileWatcher = void 0;
|
|
68
|
+
exports.FileWatcher = exports.LockUnavailableError = void 0;
|
|
69
|
+
exports.__emitWatchEventForTests = __emitWatchEventForTests;
|
|
46
70
|
const fs = __importStar(require("fs"));
|
|
71
|
+
const path = __importStar(require("path"));
|
|
47
72
|
const extraction_1 = require("../extraction");
|
|
48
73
|
const errors_1 = require("../errors");
|
|
49
74
|
const utils_1 = require("../utils");
|
|
50
75
|
const watch_policy_1 = require("./watch-policy");
|
|
76
|
+
/**
|
|
77
|
+
* Native recursive `fs.watch` is only reliable on macOS and Windows; on Linux
|
|
78
|
+
* (and AIX) it throws `ERR_FEATURE_UNAVAILABLE_ON_PLATFORM`. We branch on this
|
|
79
|
+
* to pick the recursive vs per-directory strategy.
|
|
80
|
+
*/
|
|
81
|
+
function supportsRecursiveWatch() {
|
|
82
|
+
return process.platform === 'darwin' || process.platform === 'win32';
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Upper bound on simultaneously-watched directories on the Linux per-directory
|
|
86
|
+
* path. Each is one inotify watch; the kernel's `fs.inotify.max_user_watches`
|
|
87
|
+
* is the hard limit (commonly 8k–128k). We stop adding watches past this and
|
|
88
|
+
* log once — partial live-watch (with `codegraph sync` as the backstop) is far
|
|
89
|
+
* better than exhausting the user's inotify budget and breaking watching
|
|
90
|
+
* system-wide (#579). Tunable via CODEGRAPH_MAX_DIR_WATCHES.
|
|
91
|
+
*/
|
|
92
|
+
const DEFAULT_MAX_DIR_WATCHES = 50_000;
|
|
93
|
+
function maxDirWatches() {
|
|
94
|
+
const raw = process.env.CODEGRAPH_MAX_DIR_WATCHES;
|
|
95
|
+
if (raw && /^\d+$/.test(raw)) {
|
|
96
|
+
const n = Number(raw);
|
|
97
|
+
if (n > 0)
|
|
98
|
+
return n;
|
|
99
|
+
}
|
|
100
|
+
return DEFAULT_MAX_DIR_WATCHES;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Test seam (see {@link __emitWatchEventForTests}). Maps a watcher's project
|
|
104
|
+
* root to its live instance so tests can synthesize a change event
|
|
105
|
+
* deterministically — real fs.watch delivery latency races under parallel
|
|
106
|
+
* vitest (the reason the previous chokidar mock existed). Only populated under
|
|
107
|
+
* a test runner, so production carries no bookkeeping or retained references.
|
|
108
|
+
*/
|
|
109
|
+
const liveWatchersForTests = new Map();
|
|
110
|
+
const IS_TEST_RUNTIME = !!(process.env.VITEST || process.env.NODE_ENV === 'test');
|
|
111
|
+
/**
|
|
112
|
+
* Thrown by a `syncFn` to signal that the underlying sync couldn't acquire
|
|
113
|
+
* the cross-process write lock (#449). The watcher treats this as "no
|
|
114
|
+
* progress" — preserves `pendingFiles`, skips `onSyncComplete`, and the
|
|
115
|
+
* `finally` block reschedules. Quiet (debug-only) because a long-running
|
|
116
|
+
* external indexer can hit this every debounce cycle.
|
|
117
|
+
*/
|
|
118
|
+
class LockUnavailableError extends Error {
|
|
119
|
+
constructor(message = 'CodeGraph file lock unavailable; another process is writing') {
|
|
120
|
+
super(message);
|
|
121
|
+
this.name = 'LockUnavailableError';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.LockUnavailableError = LockUnavailableError;
|
|
51
125
|
/**
|
|
52
126
|
* FileWatcher monitors a project directory for changes and triggers
|
|
53
127
|
* debounced sync operations via a provided callback.
|
|
54
128
|
*
|
|
55
129
|
* Design goals:
|
|
56
|
-
* -
|
|
130
|
+
* - Bounded resource usage: O(1) descriptors on macOS/Windows (one recursive
|
|
131
|
+
* watch), O(directories) inotify watches on Linux — never O(files), which
|
|
132
|
+
* was the system-crashing fd leak on macOS (#644/#496/#555/#628).
|
|
57
133
|
* - Debounced to avoid thrashing on rapid saves
|
|
58
|
-
* - Filters
|
|
59
|
-
* - Ignores .codegraph/
|
|
134
|
+
* - Filters to supported source files by extension
|
|
135
|
+
* - Ignores .codegraph/ and .git/ regardless of .gitignore
|
|
136
|
+
* - Tracks per-file pending state so MCP tools can flag stale results
|
|
137
|
+
* without blocking on a sync (issue #403)
|
|
60
138
|
*/
|
|
61
139
|
class FileWatcher {
|
|
62
|
-
watcher
|
|
140
|
+
/** macOS/Windows: the single recursive watcher. Null on Linux. */
|
|
141
|
+
recursiveWatcher = null;
|
|
142
|
+
/** Linux: one watcher per watched directory (keyed by absolute path). */
|
|
143
|
+
dirWatchers = new Map();
|
|
144
|
+
/** Set once the per-directory watch cap is hit, so we log only once. */
|
|
145
|
+
dirCapWarned = false;
|
|
146
|
+
/** Test-only inert mode: started, but with no OS watcher installed. */
|
|
147
|
+
inert = false;
|
|
63
148
|
debounceTimer = null;
|
|
64
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Files seen by the watcher since the last successful sync — populated on
|
|
151
|
+
* every change event, cleared at the start of a sync, and re-populated by
|
|
152
|
+
* events that arrive mid-sync (or restored on sync failure). Keyed by the
|
|
153
|
+
* same project-relative POSIX path the rest of the codebase uses, so a
|
|
154
|
+
* caller can intersect tool-response file paths against this map cheaply.
|
|
155
|
+
*/
|
|
156
|
+
pendingFiles = new Map();
|
|
157
|
+
/**
|
|
158
|
+
* Wall-clock ms at which the in-flight sync began. Combined with
|
|
159
|
+
* {@link pendingFiles}'s `lastSeenMs`, this distinguishes "still in the
|
|
160
|
+
* debounce window" (lastSeen > syncStarted, sync hasn't started yet for
|
|
161
|
+
* this edit) from "currently being indexed" (lastSeen <= syncStarted).
|
|
162
|
+
*/
|
|
163
|
+
syncStartedMs = 0;
|
|
65
164
|
syncing = false;
|
|
66
165
|
stopped = false;
|
|
166
|
+
/**
|
|
167
|
+
* True once the initial watch set is established. Unlike the previous
|
|
168
|
+
* chokidar implementation there is no asynchronous initial "crawl" emitting
|
|
169
|
+
* an `add` per existing file — `fs.watch` only reports changes from the
|
|
170
|
+
* moment it's installed — so this flips to true synchronously at the end of
|
|
171
|
+
* `start()`. The startup reconcile against on-disk state is handled
|
|
172
|
+
* separately by the engine's catch-up sync, not by the watcher.
|
|
173
|
+
*/
|
|
174
|
+
ready = false;
|
|
175
|
+
/**
|
|
176
|
+
* Callbacks that resolve when the watch set is established. Used by tests
|
|
177
|
+
* (and any production caller that cares about a clean baseline) to
|
|
178
|
+
* deterministically gate on watcher readiness.
|
|
179
|
+
*/
|
|
180
|
+
readyWaiters = [];
|
|
181
|
+
// The shared ignore matcher (built-in defaults + project .gitignore), built
|
|
182
|
+
// once at start(). Same source of truth the indexer uses, so watcher scope
|
|
183
|
+
// can never diverge from index scope.
|
|
184
|
+
ignoreMatcher = null;
|
|
67
185
|
projectRoot;
|
|
68
|
-
config;
|
|
69
186
|
debounceMs;
|
|
70
187
|
syncFn;
|
|
71
188
|
onSyncComplete;
|
|
72
189
|
onSyncError;
|
|
73
|
-
|
|
190
|
+
inertForTests;
|
|
191
|
+
constructor(projectRoot, syncFn, options = {}) {
|
|
74
192
|
this.projectRoot = projectRoot;
|
|
75
|
-
this.config = config;
|
|
76
193
|
this.syncFn = syncFn;
|
|
77
194
|
this.debounceMs = options.debounceMs ?? 2000;
|
|
78
195
|
this.onSyncComplete = options.onSyncComplete;
|
|
79
196
|
this.onSyncError = options.onSyncError;
|
|
197
|
+
this.inertForTests = options.inertForTests ?? false;
|
|
80
198
|
}
|
|
81
199
|
/**
|
|
82
200
|
* Start watching for file changes.
|
|
83
201
|
* Returns true if watching started successfully, false otherwise.
|
|
84
202
|
*/
|
|
85
203
|
start() {
|
|
86
|
-
if (this.
|
|
204
|
+
if (this.recursiveWatcher || this.dirWatchers.size > 0 || this.inert)
|
|
87
205
|
return true; // Already watching
|
|
88
206
|
this.stopped = false;
|
|
89
|
-
// Some environments make
|
|
90
|
-
// /mnt/ drives, where
|
|
91
|
-
// handshakes (issue #199). Skip watching
|
|
92
|
-
// manual `codegraph sync` or
|
|
207
|
+
// Some environments make filesystem watching unusable — most notably
|
|
208
|
+
// WSL2 /mnt/ drives, where the underlying fs.watch calls block long
|
|
209
|
+
// enough to break MCP startup handshakes (issue #199). Skip watching
|
|
210
|
+
// there; callers fall back to manual `codegraph sync` or git sync hooks.
|
|
93
211
|
const disabledReason = (0, watch_policy_1.watchDisabledReason)(this.projectRoot);
|
|
94
212
|
if (disabledReason) {
|
|
95
213
|
(0, errors_1.logDebug)('File watcher disabled', { reason: disabledReason, projectRoot: this.projectRoot });
|
|
96
214
|
return false;
|
|
97
215
|
}
|
|
216
|
+
// Reuse the indexer's ignore set so the watcher and indexer agree on scope.
|
|
217
|
+
this.ignoreMatcher = (0, extraction_1.buildDefaultIgnore)(this.projectRoot);
|
|
98
218
|
try {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
219
|
+
if (this.inertForTests) {
|
|
220
|
+
// Test-only: install no OS watcher; the seam drives events instead.
|
|
221
|
+
this.inert = true;
|
|
222
|
+
}
|
|
223
|
+
else if (supportsRecursiveWatch()) {
|
|
224
|
+
this.startRecursive();
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
this.startPerDirectory();
|
|
228
|
+
}
|
|
229
|
+
// No async crawl to wait on: as soon as the watch set is installed we
|
|
230
|
+
// have a clean baseline (pendingFiles is only populated by post-start
|
|
231
|
+
// events). Clear defensively and flip ready.
|
|
232
|
+
this.pendingFiles.clear();
|
|
233
|
+
this.ready = true;
|
|
234
|
+
for (const cb of this.readyWaiters)
|
|
235
|
+
cb();
|
|
236
|
+
this.readyWaiters.length = 0;
|
|
237
|
+
if (IS_TEST_RUNTIME)
|
|
238
|
+
liveWatchersForTests.set(this.projectRoot, this);
|
|
239
|
+
(0, errors_1.logDebug)('File watcher started', {
|
|
240
|
+
projectRoot: this.projectRoot,
|
|
241
|
+
debounceMs: this.debounceMs,
|
|
242
|
+
mode: this.inertForTests ? 'inert' : supportsRecursiveWatch() ? 'recursive' : 'per-directory',
|
|
243
|
+
watchedDirs: this.dirWatchers.size || undefined,
|
|
122
244
|
});
|
|
123
|
-
(0, errors_1.logDebug)('File watcher started', { projectRoot: this.projectRoot, debounceMs: this.debounceMs });
|
|
124
245
|
return true;
|
|
125
246
|
}
|
|
126
247
|
catch (err) {
|
|
127
|
-
//
|
|
128
|
-
(0, errors_1.logWarn)('Could not start file watcher
|
|
248
|
+
// Watcher setup failed (e.g., permission denied, missing directory).
|
|
249
|
+
(0, errors_1.logWarn)('Could not start file watcher', { error: String(err) });
|
|
250
|
+
this.stop();
|
|
129
251
|
return false;
|
|
130
252
|
}
|
|
131
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* macOS/Windows: one recursive watcher for the whole tree. O(1) descriptors.
|
|
256
|
+
* `filename` arrives relative to the project root (with subdirectories), so
|
|
257
|
+
* it maps straight to a project-relative path.
|
|
258
|
+
*/
|
|
259
|
+
startRecursive() {
|
|
260
|
+
this.recursiveWatcher = fs.watch(this.projectRoot, { recursive: true, persistent: true }, (_event, filename) => {
|
|
261
|
+
if (this.stopped || filename == null)
|
|
262
|
+
return;
|
|
263
|
+
this.handleChange((0, utils_1.normalizePath)(String(filename)));
|
|
264
|
+
});
|
|
265
|
+
this.recursiveWatcher.on('error', (err) => {
|
|
266
|
+
(0, errors_1.logWarn)('File watcher error', { error: String(err) });
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Linux: walk the (non-ignored) tree and watch each directory. One inotify
|
|
271
|
+
* watch per directory reports create/modify/delete for that directory's
|
|
272
|
+
* direct children, so we never watch individual files.
|
|
273
|
+
*/
|
|
274
|
+
startPerDirectory() {
|
|
275
|
+
this.watchTree(this.projectRoot, /* markExisting */ false);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Add an inotify watch for `dir` and recurse into its non-ignored
|
|
279
|
+
* subdirectories. When `markExisting` is true (a directory that appeared
|
|
280
|
+
* AFTER startup), the source files already inside it are recorded as pending
|
|
281
|
+
* — this closes the `mkdir + write` race where files created before the new
|
|
282
|
+
* directory's watch is installed would otherwise be missed until the next
|
|
283
|
+
* full sync. The initial startup walk passes false (the engine's catch-up
|
|
284
|
+
* sync owns the baseline).
|
|
285
|
+
*/
|
|
286
|
+
watchTree(dir, markExisting) {
|
|
287
|
+
if (this.dirWatchers.has(dir))
|
|
288
|
+
return;
|
|
289
|
+
if (this.dirWatchers.size >= maxDirWatches()) {
|
|
290
|
+
if (!this.dirCapWarned) {
|
|
291
|
+
this.dirCapWarned = true;
|
|
292
|
+
(0, errors_1.logWarn)('File watcher hit directory-watch cap; remaining subtrees rely on manual/periodic sync', {
|
|
293
|
+
cap: maxDirWatches(),
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
let w;
|
|
299
|
+
try {
|
|
300
|
+
w = fs.watch(dir, { persistent: true }, (_event, filename) => this.handleDirEvent(dir, filename));
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
// ENOENT / EACCES / too-many-open-files — skip this directory quietly.
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
w.on('error', () => this.unwatchDir(dir));
|
|
307
|
+
this.dirWatchers.set(dir, w);
|
|
308
|
+
let entries;
|
|
309
|
+
try {
|
|
310
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
for (const entry of entries) {
|
|
316
|
+
const child = path.join(dir, entry.name);
|
|
317
|
+
if (entry.isDirectory()) {
|
|
318
|
+
if (this.shouldIgnoreDir(child))
|
|
319
|
+
continue;
|
|
320
|
+
this.watchTree(child, markExisting);
|
|
321
|
+
}
|
|
322
|
+
else if (markExisting && entry.isFile()) {
|
|
323
|
+
this.handleChange((0, utils_1.normalizePath)(path.relative(this.projectRoot, child)));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Linux per-directory event handler. `filename` is relative to `dir`. A new
|
|
329
|
+
* sub-directory is picked up by extending the watch tree; everything else is
|
|
330
|
+
* routed through the shared change handler.
|
|
331
|
+
*/
|
|
332
|
+
handleDirEvent(dir, filename) {
|
|
333
|
+
if (this.stopped || filename == null)
|
|
334
|
+
return;
|
|
335
|
+
const full = path.join(dir, String(filename));
|
|
336
|
+
// A newly-created directory needs its own watch (recursive isn't available
|
|
337
|
+
// on Linux). statSync is cheap and these events are rare relative to file
|
|
338
|
+
// edits. If the path vanished (rapid create/delete) the stat throws and we
|
|
339
|
+
// fall through to the change handler, which no-ops on a non-source path.
|
|
340
|
+
try {
|
|
341
|
+
if (fs.statSync(full).isDirectory()) {
|
|
342
|
+
if (!this.shouldIgnoreDir(full))
|
|
343
|
+
this.watchTree(full, /* markExisting */ true);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
// deleted/inaccessible — treat as a normal change below
|
|
349
|
+
}
|
|
350
|
+
this.handleChange((0, utils_1.normalizePath)(path.relative(this.projectRoot, full)));
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Shared change handler for both watch strategies. `rel` is a
|
|
354
|
+
* project-relative POSIX path. Applies the ignore + source-file filters and,
|
|
355
|
+
* for a real source change, records it as pending (#403) and schedules a
|
|
356
|
+
* debounced sync.
|
|
357
|
+
*
|
|
358
|
+
* The recursive (macOS/Windows) watcher reports events for ignored trees too
|
|
359
|
+
* (one stream covers the whole repo), so the ignore check here is load-bearing
|
|
360
|
+
* — it drops node_modules/dist/.git churn before any sync is scheduled.
|
|
361
|
+
*/
|
|
362
|
+
handleChange(rel) {
|
|
363
|
+
if (!rel || rel === '.' || rel.startsWith('..'))
|
|
364
|
+
return;
|
|
365
|
+
if (this.isAlwaysIgnored(rel))
|
|
366
|
+
return;
|
|
367
|
+
if (this.ignoreMatcher && this.ignoreMatcher.ignores(rel))
|
|
368
|
+
return;
|
|
369
|
+
if (!(0, extraction_1.isSourceFile)(rel))
|
|
370
|
+
return;
|
|
371
|
+
(0, errors_1.logDebug)('File change detected', { file: rel });
|
|
372
|
+
if (this.ready) {
|
|
373
|
+
const now = Date.now();
|
|
374
|
+
const existing = this.pendingFiles.get(rel);
|
|
375
|
+
this.pendingFiles.set(rel, {
|
|
376
|
+
firstSeenMs: existing?.firstSeenMs ?? now,
|
|
377
|
+
lastSeenMs: now,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
this.scheduleSync();
|
|
381
|
+
}
|
|
382
|
+
/** Close and forget the watch for a directory that errored/was removed. */
|
|
383
|
+
unwatchDir(dir) {
|
|
384
|
+
const w = this.dirWatchers.get(dir);
|
|
385
|
+
if (w) {
|
|
386
|
+
try {
|
|
387
|
+
w.close();
|
|
388
|
+
}
|
|
389
|
+
catch {
|
|
390
|
+
/* already closed */
|
|
391
|
+
}
|
|
392
|
+
this.dirWatchers.delete(dir);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/** Our own dirs are always ignored, regardless of .gitignore. */
|
|
396
|
+
isAlwaysIgnored(rel) {
|
|
397
|
+
return (rel === '.codegraph' || rel.startsWith('.codegraph/') ||
|
|
398
|
+
rel === '.git' || rel.startsWith('.git/'));
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* True for any directory that should NOT be watched (used while building the
|
|
402
|
+
* Linux per-directory watch tree). Tests the directory form of the path so a
|
|
403
|
+
* dir-only ignore rule like `build/` matches.
|
|
404
|
+
*/
|
|
405
|
+
shouldIgnoreDir(dirPath) {
|
|
406
|
+
const rel = (0, utils_1.normalizePath)(path.relative(this.projectRoot, dirPath));
|
|
407
|
+
if (!rel || rel === '.' || rel.startsWith('..'))
|
|
408
|
+
return false; // root / outside
|
|
409
|
+
if (this.isAlwaysIgnored(rel))
|
|
410
|
+
return true;
|
|
411
|
+
if (!this.ignoreMatcher)
|
|
412
|
+
return false;
|
|
413
|
+
return this.ignoreMatcher.ignores(rel + '/');
|
|
414
|
+
}
|
|
132
415
|
/**
|
|
133
416
|
* Stop watching for file changes.
|
|
134
417
|
*/
|
|
@@ -138,18 +421,71 @@ class FileWatcher {
|
|
|
138
421
|
clearTimeout(this.debounceTimer);
|
|
139
422
|
this.debounceTimer = null;
|
|
140
423
|
}
|
|
141
|
-
if (this.
|
|
142
|
-
|
|
143
|
-
|
|
424
|
+
if (this.recursiveWatcher) {
|
|
425
|
+
try {
|
|
426
|
+
this.recursiveWatcher.close();
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
/* already closed */
|
|
430
|
+
}
|
|
431
|
+
this.recursiveWatcher = null;
|
|
432
|
+
}
|
|
433
|
+
for (const w of this.dirWatchers.values()) {
|
|
434
|
+
try {
|
|
435
|
+
w.close();
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
/* already closed */
|
|
439
|
+
}
|
|
144
440
|
}
|
|
145
|
-
this.
|
|
441
|
+
this.dirWatchers.clear();
|
|
442
|
+
this.dirCapWarned = false;
|
|
443
|
+
this.inert = false;
|
|
444
|
+
this.pendingFiles.clear();
|
|
445
|
+
this.ready = false;
|
|
446
|
+
this.ignoreMatcher = null;
|
|
447
|
+
if (IS_TEST_RUNTIME)
|
|
448
|
+
liveWatchersForTests.delete(this.projectRoot);
|
|
146
449
|
(0, errors_1.logDebug)('File watcher stopped');
|
|
147
450
|
}
|
|
451
|
+
/**
|
|
452
|
+
* @internal Test-only: feed a synthetic project-relative change through the
|
|
453
|
+
* same filter → pendingFiles → debounced-sync path a real fs.watch event
|
|
454
|
+
* takes. Lets the watcher / staleness-banner suites stay deterministic
|
|
455
|
+
* instead of racing on OS watch-delivery latency. See
|
|
456
|
+
* {@link __emitWatchEventForTests}.
|
|
457
|
+
*/
|
|
458
|
+
ingestEventForTests(relPath) {
|
|
459
|
+
this.handleChange((0, utils_1.normalizePath)(relPath));
|
|
460
|
+
}
|
|
148
461
|
/**
|
|
149
462
|
* Whether the watcher is currently active.
|
|
150
463
|
*/
|
|
151
464
|
isActive() {
|
|
152
|
-
return this.
|
|
465
|
+
return (this.recursiveWatcher !== null || this.dirWatchers.size > 0 || this.inert) && !this.stopped;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Resolves once the watch set has been installed (or immediately if it
|
|
469
|
+
* already has). Useful for tests that need a deterministic boundary before
|
|
470
|
+
* asserting on `pendingFiles`.
|
|
471
|
+
*
|
|
472
|
+
* Production callers don't need this: `pendingFiles` is read continuously,
|
|
473
|
+
* the staleness banner is always correct (empty or populated), and there is
|
|
474
|
+
* no asynchronous initial-scan window with `fs.watch`.
|
|
475
|
+
*/
|
|
476
|
+
waitUntilReady(timeoutMs = 10000) {
|
|
477
|
+
if (this.ready)
|
|
478
|
+
return Promise.resolve();
|
|
479
|
+
return new Promise((resolve, reject) => {
|
|
480
|
+
const t = setTimeout(() => {
|
|
481
|
+
const idx = this.readyWaiters.indexOf(handler);
|
|
482
|
+
if (idx >= 0)
|
|
483
|
+
this.readyWaiters.splice(idx, 1);
|
|
484
|
+
reject(new Error(`FileWatcher.waitUntilReady timed out after ${timeoutMs}ms`));
|
|
485
|
+
}, timeoutMs);
|
|
486
|
+
const handler = () => { clearTimeout(t); resolve(); };
|
|
487
|
+
this.readyWaiters.push(handler);
|
|
488
|
+
});
|
|
153
489
|
}
|
|
154
490
|
/**
|
|
155
491
|
* Schedule a debounced sync.
|
|
@@ -165,30 +501,106 @@ class FileWatcher {
|
|
|
165
501
|
}
|
|
166
502
|
/**
|
|
167
503
|
* Flush pending changes by running sync.
|
|
504
|
+
*
|
|
505
|
+
* pendingFiles is NOT cleared at the start of sync — entries are removed
|
|
506
|
+
* only after sync commits successfully, and only for entries whose
|
|
507
|
+
* lastSeenMs <= syncStartedMs. That way, a query that arrives mid-sync
|
|
508
|
+
* still sees the affected files marked stale (the DB hasn't been updated
|
|
509
|
+
* yet), and an event that lands mid-sync persists into the follow-up.
|
|
510
|
+
*
|
|
511
|
+
* On sync failure pendingFiles is left untouched — every edit is still
|
|
512
|
+
* unindexed, and the rescheduled sync will absorb the same set next time.
|
|
168
513
|
*/
|
|
169
514
|
async flush() {
|
|
170
515
|
// If already syncing, the post-sync check will re-trigger
|
|
171
516
|
if (this.syncing || this.stopped)
|
|
172
517
|
return;
|
|
173
|
-
this.
|
|
518
|
+
this.syncStartedMs = Date.now();
|
|
174
519
|
this.syncing = true;
|
|
175
520
|
try {
|
|
176
521
|
const result = await this.syncFn();
|
|
522
|
+
// Remove entries whose most recent event predates this sync — those
|
|
523
|
+
// edits are now in the DB. Entries with lastSeenMs > syncStartedMs
|
|
524
|
+
// arrived mid-sync; whether the in-flight sync captured them depends
|
|
525
|
+
// on when sync read that file, so we keep them as pending and let
|
|
526
|
+
// the follow-up sync handle them. We prefer false positives ("shown
|
|
527
|
+
// stale, actually fresh" → at worst one extra Read) over false
|
|
528
|
+
// negatives ("shown fresh, actually stale" → misleads the agent).
|
|
529
|
+
for (const [filePath, info] of this.pendingFiles) {
|
|
530
|
+
if (info.lastSeenMs <= this.syncStartedMs) {
|
|
531
|
+
this.pendingFiles.delete(filePath);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
177
534
|
this.onSyncComplete?.(result);
|
|
178
535
|
}
|
|
179
536
|
catch (err) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
537
|
+
if (err instanceof LockUnavailableError) {
|
|
538
|
+
// Lock-failure no-op (another writer holds the lock). pendingFiles
|
|
539
|
+
// stays intact and the `finally` block reschedules. Debug-only —
|
|
540
|
+
// a long external index would otherwise spam stderr every cycle.
|
|
541
|
+
(0, errors_1.logDebug)('Watch sync skipped: file lock unavailable', {
|
|
542
|
+
pendingFiles: this.pendingFiles.size,
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
547
|
+
(0, errors_1.logWarn)('Watch sync failed', { error: error.message });
|
|
548
|
+
this.onSyncError?.(error);
|
|
549
|
+
}
|
|
550
|
+
// Failure: leave pendingFiles untouched. Every edit it tracks is
|
|
551
|
+
// still unindexed; the rescheduled sync sees the same set.
|
|
183
552
|
}
|
|
184
553
|
finally {
|
|
185
554
|
this.syncing = false;
|
|
186
|
-
// If
|
|
187
|
-
|
|
555
|
+
// If pending files remain (mid-sync events, or this sync failed),
|
|
556
|
+
// schedule another pass.
|
|
557
|
+
if (this.pendingFiles.size > 0 && !this.stopped) {
|
|
188
558
|
this.scheduleSync();
|
|
189
559
|
}
|
|
190
560
|
}
|
|
191
561
|
}
|
|
562
|
+
/**
|
|
563
|
+
* Snapshot of files seen by the watcher since the last successful sync.
|
|
564
|
+
*
|
|
565
|
+
* Used by MCP tool responses to mark stale results without blocking on a
|
|
566
|
+
* sync: a tool that returns a hit in `src/foo.ts` while `src/foo.ts` is in
|
|
567
|
+
* this list tells the agent "Read this file directly, the index lags."
|
|
568
|
+
*
|
|
569
|
+
* `indexing` is true when a sync is currently in flight whose start time is
|
|
570
|
+
* AFTER this file's most recent event — i.e. that sync will absorb the
|
|
571
|
+
* edit. False means the file is still inside the debounce window and no
|
|
572
|
+
* sync has started yet (a follow-up call a few hundred ms later may show
|
|
573
|
+
* `indexing: true` or the file may have left the list entirely).
|
|
574
|
+
*
|
|
575
|
+
* Cheap: O(pendingFiles.size), no I/O, no locks.
|
|
576
|
+
*/
|
|
577
|
+
getPendingFiles() {
|
|
578
|
+
const result = [];
|
|
579
|
+
for (const [filePath, info] of this.pendingFiles) {
|
|
580
|
+
result.push({
|
|
581
|
+
path: filePath,
|
|
582
|
+
firstSeenMs: info.firstSeenMs,
|
|
583
|
+
lastSeenMs: info.lastSeenMs,
|
|
584
|
+
indexing: this.syncing && this.syncStartedMs >= info.lastSeenMs,
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
return result;
|
|
588
|
+
}
|
|
192
589
|
}
|
|
193
590
|
exports.FileWatcher = FileWatcher;
|
|
591
|
+
/**
|
|
592
|
+
* Test-only: synthesize a source-file change for the live watcher running at
|
|
593
|
+
* `projectRoot`, exercising the real filter → pendingFiles → debounced-sync
|
|
594
|
+
* logic without depending on fs.watch delivery timing (which races under
|
|
595
|
+
* parallel vitest). `relPath` is project-relative POSIX (e.g. "src/foo.ts").
|
|
596
|
+
* Returns false if no live watcher is registered for that root (e.g. outside a
|
|
597
|
+
* test runtime, where the registry is intentionally not populated).
|
|
598
|
+
*/
|
|
599
|
+
function __emitWatchEventForTests(projectRoot, relPath) {
|
|
600
|
+
const w = liveWatchersForTests.get(projectRoot);
|
|
601
|
+
if (!w)
|
|
602
|
+
return false;
|
|
603
|
+
w.ingestEventForTests(relPath);
|
|
604
|
+
return true;
|
|
605
|
+
}
|
|
194
606
|
//# sourceMappingURL=watcher.js.map
|
package/dist/sync/watcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.js","sourceRoot":"","sources":["../../src/sync/watcher.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AAEzB,8CAAkD;AAClD,sCAA8C;AAC9C,oCAAyC;AACzC,iDAAqD;AAwBrD;;;;;;;;;GASG;AACH,MAAa,WAAW;IACd,OAAO,GAAwB,IAAI,CAAC;IACpC,aAAa,GAAyC,IAAI,CAAC;IAC3D,UAAU,GAAG,KAAK,CAAC;IACnB,OAAO,GAAG,KAAK,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAEP,WAAW,CAAS;IACpB,MAAM,CAAkB;IACxB,UAAU,CAAS;IACnB,MAAM,CAA8D;IACpE,cAAc,CAAkC;IAChD,WAAW,CAA+B;IAE3D,YACE,WAAmB,EACnB,MAAuB,EACvB,MAAmE,EACnE,UAAwB,EAAE;QAE1B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;QAC7C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC,CAAC,mBAAmB;QAClD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QAErB,yEAAyE;QACzE,oEAAoE;QACpE,qEAAqE;QACrE,iDAAiD;QACjD,MAAM,cAAc,GAAG,IAAA,kCAAmB,EAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC7D,IAA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