@colbymchenry/codegraph-win32-arm64 0.9.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dist/bin/codegraph.d.ts +1 -0
- package/lib/dist/bin/codegraph.d.ts.map +1 -1
- package/lib/dist/bin/codegraph.js +394 -10
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/bin/fatal-handler.d.ts +20 -0
- package/lib/dist/bin/fatal-handler.d.ts.map +1 -0
- package/lib/dist/bin/fatal-handler.js +118 -0
- package/lib/dist/bin/fatal-handler.js.map +1 -0
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +7 -0
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +2 -1
- 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 +10 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +43 -0
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +103 -7
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +1 -0
- package/lib/dist/db/sqlite-adapter.d.ts +7 -0
- package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/lib/dist/db/sqlite-adapter.js +3 -0
- package/lib/dist/db/sqlite-adapter.js.map +1 -1
- package/lib/dist/directory.d.ts +49 -2
- package/lib/dist/directory.d.ts.map +1 -1
- package/lib/dist/directory.js +173 -35
- package/lib/dist/directory.js.map +1 -1
- package/lib/dist/extraction/astro-extractor.d.ts +79 -0
- package/lib/dist/extraction/astro-extractor.d.ts.map +1 -0
- package/lib/dist/extraction/astro-extractor.js +320 -0
- package/lib/dist/extraction/astro-extractor.js.map +1 -0
- package/lib/dist/extraction/extraction-version.d.ts +25 -0
- package/lib/dist/extraction/extraction-version.d.ts.map +1 -0
- package/lib/dist/extraction/extraction-version.js +28 -0
- package/lib/dist/extraction/extraction-version.js.map +1 -0
- package/lib/dist/extraction/function-ref.d.ts +118 -0
- package/lib/dist/extraction/function-ref.d.ts.map +1 -0
- package/lib/dist/extraction/function-ref.js +727 -0
- package/lib/dist/extraction/function-ref.js.map +1 -0
- package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
- package/lib/dist/extraction/generated-detection.js +3 -0
- package/lib/dist/extraction/generated-detection.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts +7 -1
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +52 -4
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +34 -0
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +389 -62
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.d.ts +8 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +87 -28
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/languages/csharp.d.ts +22 -0
- package/lib/dist/extraction/languages/csharp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/csharp.js +84 -2
- package/lib/dist/extraction/languages/csharp.js.map +1 -1
- package/lib/dist/extraction/languages/dart.d.ts.map +1 -1
- package/lib/dist/extraction/languages/dart.js +161 -1
- package/lib/dist/extraction/languages/dart.js.map +1 -1
- package/lib/dist/extraction/languages/go.d.ts.map +1 -1
- package/lib/dist/extraction/languages/go.js +43 -2
- package/lib/dist/extraction/languages/go.js.map +1 -1
- package/lib/dist/extraction/languages/index.d.ts.map +1 -1
- package/lib/dist/extraction/languages/index.js +2 -0
- package/lib/dist/extraction/languages/index.js.map +1 -1
- package/lib/dist/extraction/languages/java.d.ts.map +1 -1
- package/lib/dist/extraction/languages/java.js +42 -1
- package/lib/dist/extraction/languages/java.js.map +1 -1
- package/lib/dist/extraction/languages/javascript.d.ts.map +1 -1
- package/lib/dist/extraction/languages/javascript.js +16 -0
- package/lib/dist/extraction/languages/javascript.js.map +1 -1
- package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -1
- package/lib/dist/extraction/languages/kotlin.js +69 -0
- package/lib/dist/extraction/languages/kotlin.js.map +1 -1
- package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
- package/lib/dist/extraction/languages/objc.js +42 -0
- package/lib/dist/extraction/languages/objc.js.map +1 -1
- package/lib/dist/extraction/languages/pascal.d.ts.map +1 -1
- package/lib/dist/extraction/languages/pascal.js +11 -0
- package/lib/dist/extraction/languages/pascal.js.map +1 -1
- package/lib/dist/extraction/languages/php.d.ts.map +1 -1
- package/lib/dist/extraction/languages/php.js +90 -1
- package/lib/dist/extraction/languages/php.js.map +1 -1
- package/lib/dist/extraction/languages/r.d.ts +3 -0
- package/lib/dist/extraction/languages/r.d.ts.map +1 -0
- package/lib/dist/extraction/languages/r.js +314 -0
- package/lib/dist/extraction/languages/r.js.map +1 -0
- package/lib/dist/extraction/languages/ruby.d.ts.map +1 -1
- package/lib/dist/extraction/languages/ruby.js +35 -0
- package/lib/dist/extraction/languages/ruby.js.map +1 -1
- package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
- package/lib/dist/extraction/languages/rust.js +35 -2
- package/lib/dist/extraction/languages/rust.js.map +1 -1
- package/lib/dist/extraction/languages/scala.d.ts.map +1 -1
- package/lib/dist/extraction/languages/scala.js +61 -1
- package/lib/dist/extraction/languages/scala.js.map +1 -1
- package/lib/dist/extraction/languages/swift.d.ts.map +1 -1
- package/lib/dist/extraction/languages/swift.js +61 -0
- package/lib/dist/extraction/languages/swift.js.map +1 -1
- package/lib/dist/extraction/languages/typescript.d.ts +13 -0
- package/lib/dist/extraction/languages/typescript.d.ts.map +1 -1
- package/lib/dist/extraction/languages/typescript.js +38 -0
- package/lib/dist/extraction/languages/typescript.js.map +1 -1
- package/lib/dist/extraction/liquid-extractor.d.ts +7 -0
- package/lib/dist/extraction/liquid-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/liquid-extractor.js +53 -9
- package/lib/dist/extraction/liquid-extractor.js.map +1 -1
- package/lib/dist/extraction/razor-extractor.d.ts +42 -0
- package/lib/dist/extraction/razor-extractor.d.ts.map +1 -0
- package/lib/dist/extraction/razor-extractor.js +285 -0
- package/lib/dist/extraction/razor-extractor.js.map +1 -0
- package/lib/dist/extraction/svelte-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/svelte-extractor.js +6 -3
- package/lib/dist/extraction/svelte-extractor.js.map +1 -1
- package/lib/dist/extraction/tree-sitter-helpers.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter-helpers.js +59 -10
- package/lib/dist/extraction/tree-sitter-helpers.js.map +1 -1
- package/lib/dist/extraction/tree-sitter-types.d.ts +33 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +211 -0
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +1681 -49
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/vue-extractor.d.ts +15 -0
- package/lib/dist/extraction/vue-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/vue-extractor.js +94 -3
- package/lib/dist/extraction/vue-extractor.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-r.wasm +0 -0
- package/lib/dist/graph/queries.d.ts.map +1 -1
- package/lib/dist/graph/queries.js +13 -40
- package/lib/dist/graph/queries.js.map +1 -1
- package/lib/dist/graph/traversal.d.ts.map +1 -1
- package/lib/dist/graph/traversal.js +16 -4
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/index.d.ts +34 -2
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +90 -8
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +63 -2
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/instructions-template.d.ts +34 -11
- package/lib/dist/installer/instructions-template.d.ts.map +1 -1
- package/lib/dist/installer/instructions-template.js +44 -12
- package/lib/dist/installer/instructions-template.js.map +1 -1
- package/lib/dist/installer/targets/claude.d.ts.map +1 -1
- package/lib/dist/installer/targets/claude.js +6 -10
- package/lib/dist/installer/targets/claude.js.map +1 -1
- package/lib/dist/installer/targets/codex.js +4 -6
- package/lib/dist/installer/targets/codex.js.map +1 -1
- package/lib/dist/installer/targets/gemini.js +4 -6
- package/lib/dist/installer/targets/gemini.js.map +1 -1
- package/lib/dist/installer/targets/opencode.d.ts +9 -1
- package/lib/dist/installer/targets/opencode.d.ts.map +1 -1
- package/lib/dist/installer/targets/opencode.js +91 -40
- package/lib/dist/installer/targets/opencode.js.map +1 -1
- package/lib/dist/installer/targets/shared.d.ts +14 -0
- package/lib/dist/installer/targets/shared.d.ts.map +1 -1
- package/lib/dist/installer/targets/shared.js +16 -0
- package/lib/dist/installer/targets/shared.js.map +1 -1
- package/lib/dist/mcp/daemon-manager.d.ts +42 -0
- package/lib/dist/mcp/daemon-manager.d.ts.map +1 -0
- package/lib/dist/mcp/daemon-manager.js +129 -0
- package/lib/dist/mcp/daemon-manager.js.map +1 -0
- package/lib/dist/mcp/daemon-registry.d.ts +47 -0
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -0
- package/lib/dist/mcp/daemon-registry.js +229 -0
- package/lib/dist/mcp/daemon-registry.js.map +1 -0
- package/lib/dist/mcp/daemon.d.ts +60 -1
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +226 -8
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/dynamic-boundaries.d.ts +41 -0
- package/lib/dist/mcp/dynamic-boundaries.d.ts.map +1 -0
- package/lib/dist/mcp/dynamic-boundaries.js +359 -0
- package/lib/dist/mcp/dynamic-boundaries.js.map +1 -0
- package/lib/dist/mcp/index.d.ts +1 -0
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +31 -9
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts +18 -0
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -0
- package/lib/dist/mcp/liveness-watchdog.js +207 -0
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -0
- package/lib/dist/mcp/ppid-watchdog.d.ts +44 -0
- package/lib/dist/mcp/ppid-watchdog.d.ts.map +1 -0
- package/lib/dist/mcp/ppid-watchdog.js +27 -0
- package/lib/dist/mcp/ppid-watchdog.js.map +1 -0
- package/lib/dist/mcp/proxy.d.ts +6 -0
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +153 -24
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/server-instructions.d.ts +12 -1
- package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
- package/lib/dist/mcp/server-instructions.js +43 -16
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +2 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +49 -2
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/stdin-teardown.d.ts +27 -0
- package/lib/dist/mcp/stdin-teardown.d.ts.map +1 -0
- package/lib/dist/mcp/stdin-teardown.js +49 -0
- package/lib/dist/mcp/stdin-teardown.js.map +1 -0
- package/lib/dist/mcp/tools.d.ts +71 -0
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +703 -85
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/mcp/transport.d.ts.map +1 -1
- package/lib/dist/mcp/transport.js +18 -2
- package/lib/dist/mcp/transport.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts +3 -3
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +549 -21
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/frameworks/astro.d.ts +9 -0
- package/lib/dist/resolution/frameworks/astro.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/astro.js +169 -0
- package/lib/dist/resolution/frameworks/astro.js.map +1 -0
- package/lib/dist/resolution/frameworks/expo-modules.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/expo-modules.js +6 -1
- package/lib/dist/resolution/frameworks/expo-modules.js.map +1 -1
- package/lib/dist/resolution/frameworks/index.d.ts +1 -0
- package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/index.js +5 -1
- package/lib/dist/resolution/frameworks/index.js.map +1 -1
- package/lib/dist/resolution/frameworks/java.js +6 -1
- package/lib/dist/resolution/frameworks/java.js.map +1 -1
- package/lib/dist/resolution/frameworks/python.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/python.js +7 -3
- package/lib/dist/resolution/frameworks/python.js.map +1 -1
- package/lib/dist/resolution/frameworks/react-native.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react-native.js +53 -3
- package/lib/dist/resolution/frameworks/react-native.js.map +1 -1
- package/lib/dist/resolution/frameworks/react.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react.js +15 -3
- package/lib/dist/resolution/frameworks/react.js.map +1 -1
- package/lib/dist/resolution/frameworks/svelte.js +5 -1
- package/lib/dist/resolution/frameworks/svelte.js.map +1 -1
- package/lib/dist/resolution/frameworks/vue.js +24 -27
- package/lib/dist/resolution/frameworks/vue.js.map +1 -1
- package/lib/dist/resolution/import-resolver.d.ts +10 -0
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +620 -2
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +80 -0
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +457 -7
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/name-matcher.d.ts +61 -0
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +590 -14
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/types.d.ts +27 -3
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/resolution/workspace-packages.d.ts +48 -0
- package/lib/dist/resolution/workspace-packages.d.ts.map +1 -0
- package/lib/dist/resolution/workspace-packages.js +208 -0
- package/lib/dist/resolution/workspace-packages.js.map +1 -0
- package/lib/dist/search/query-utils.d.ts +17 -1
- package/lib/dist/search/query-utils.d.ts.map +1 -1
- package/lib/dist/search/query-utils.js +79 -10
- package/lib/dist/search/query-utils.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +124 -32
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +326 -111
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/telemetry/index.d.ts +146 -0
- package/lib/dist/telemetry/index.d.ts.map +1 -0
- package/lib/dist/telemetry/index.js +544 -0
- package/lib/dist/telemetry/index.js.map +1 -0
- package/lib/dist/types.d.ts +17 -2
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +3 -0
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/upgrade/index.d.ts +132 -0
- package/lib/dist/upgrade/index.d.ts.map +1 -0
- package/lib/dist/upgrade/index.js +462 -0
- package/lib/dist/upgrade/index.js.map +1 -0
- package/lib/dist/utils.d.ts +30 -24
- package/lib/dist/utils.d.ts.map +1 -1
- package/lib/dist/utils.js +64 -48
- package/lib/dist/utils.js.map +1 -1
- package/lib/node_modules/.package-lock.json +1 -29
- package/lib/package.json +1 -2
- package/package.json +1 -1
- package/lib/node_modules/chokidar/LICENSE +0 -21
- package/lib/node_modules/chokidar/README.md +0 -305
- package/lib/node_modules/chokidar/esm/handler.d.ts +0 -90
- package/lib/node_modules/chokidar/esm/handler.js +0 -629
- package/lib/node_modules/chokidar/esm/index.d.ts +0 -215
- package/lib/node_modules/chokidar/esm/index.js +0 -798
- package/lib/node_modules/chokidar/esm/package.json +0 -1
- package/lib/node_modules/chokidar/handler.d.ts +0 -90
- package/lib/node_modules/chokidar/handler.js +0 -635
- package/lib/node_modules/chokidar/index.d.ts +0 -215
- package/lib/node_modules/chokidar/index.js +0 -804
- package/lib/node_modules/chokidar/package.json +0 -69
- package/lib/node_modules/readdirp/LICENSE +0 -21
- package/lib/node_modules/readdirp/README.md +0 -120
- package/lib/node_modules/readdirp/esm/index.d.ts +0 -108
- package/lib/node_modules/readdirp/esm/index.js +0 -257
- package/lib/node_modules/readdirp/esm/package.json +0 -1
- package/lib/node_modules/readdirp/index.d.ts +0 -108
- package/lib/node_modules/readdirp/index.js +0 -263
- package/lib/node_modules/readdirp/package.json +0 -70
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DEFAULT_WATCHDOG_TIMEOUT_MS = void 0;
|
|
37
|
+
exports.parseWatchdogTimeoutMs = parseWatchdogTimeoutMs;
|
|
38
|
+
exports.deriveCheckIntervalMs = deriveCheckIntervalMs;
|
|
39
|
+
exports.installMainThreadWatchdog = installMainThreadWatchdog;
|
|
40
|
+
/**
|
|
41
|
+
* Main-thread liveness watchdog — belt-and-suspenders for #850.
|
|
42
|
+
*
|
|
43
|
+
* The #850 fix removes the one *known* trigger (the uncaught-exception handler
|
|
44
|
+
* no longer formats a raw Error's `.stack`). But ANY synchronous, non-yielding
|
|
45
|
+
* loop on the main thread — a future V8 stack-format pathology, a runaway
|
|
46
|
+
* regex, an accidental `while (true)` — wedges the event loop, and from JS you
|
|
47
|
+
* cannot interrupt it: timers, signal handlers, and the PPID watchdog all run
|
|
48
|
+
* *on* that blocked loop, so the process pins a core forever with no
|
|
49
|
+
* self-recovery (the exact unrecoverable state #850 reported).
|
|
50
|
+
*
|
|
51
|
+
* **Why a separate PROCESS, not a worker thread.** A worker thread was the
|
|
52
|
+
* obvious first choice and it works in a toy process — but it was validated to
|
|
53
|
+
* FAIL in the real daemon (#850 live test). V8 isolates in one process
|
|
54
|
+
* coordinate on global safepoints, so when one thread requests a GC every other
|
|
55
|
+
* thread must reach a safepoint before it can proceed. A main thread wedged in
|
|
56
|
+
* a tight, non-allocating loop never reaches one, which strands the watchdog
|
|
57
|
+
* worker on its very next allocation/safepoint check — and the #850 hot loop
|
|
58
|
+
* (`SourcePositionTableIterator::Advance`, a non-allocating C++ table walk) is
|
|
59
|
+
* exactly that shape. A child process shares no isolate and no heap with the
|
|
60
|
+
* parent, so the wedge cannot touch it; it kills via the kernel, which honours
|
|
61
|
+
* SIGKILL regardless of what the parent's threads are doing.
|
|
62
|
+
*
|
|
63
|
+
* **How.** The parent writes a heartbeat byte to the child's stdin every
|
|
64
|
+
* `checkMs` from a timer — firing at all means the event loop is turning. The
|
|
65
|
+
* child resets a kill-timer on each byte; if none arrives for `timeoutMs` it
|
|
66
|
+
* `SIGKILL`s the parent so a fresh daemon starts on the next connection. When
|
|
67
|
+
* the parent exits normally the pipe closes and the child exits too (no
|
|
68
|
+
* orphan).
|
|
69
|
+
*
|
|
70
|
+
* **Won't fire on real work.** Heavy parsing runs in the parse worker
|
|
71
|
+
* (off-thread) and indexing shells out to a child process, so the daemon's main
|
|
72
|
+
* thread only ever does fast, bounded work. The default timeout is ~300× the
|
|
73
|
+
* 5h #850 wedge shorter, yet far longer than any legitimate main-thread block.
|
|
74
|
+
* Opt out with `CODEGRAPH_NO_WATCHDOG=1`; tune with `CODEGRAPH_WATCHDOG_TIMEOUT_MS`.
|
|
75
|
+
*/
|
|
76
|
+
const fs = __importStar(require("fs"));
|
|
77
|
+
const os = __importStar(require("os"));
|
|
78
|
+
const child_process_1 = require("child_process");
|
|
79
|
+
/** Default: 60s — ~300× shorter than the 5h #850 wedge, far longer than any real main-thread block. */
|
|
80
|
+
exports.DEFAULT_WATCHDOG_TIMEOUT_MS = 60_000;
|
|
81
|
+
/** `true` for `1/true/yes/on` (case-insensitive); `false` otherwise. */
|
|
82
|
+
function isEnvTruthy(raw) {
|
|
83
|
+
if (!raw)
|
|
84
|
+
return false;
|
|
85
|
+
return ['1', 'true', 'yes', 'on'].includes(raw.trim().toLowerCase());
|
|
86
|
+
}
|
|
87
|
+
/** Parse the timeout env, falling back to the default for missing/invalid values. */
|
|
88
|
+
function parseWatchdogTimeoutMs(raw, fallback = exports.DEFAULT_WATCHDOG_TIMEOUT_MS) {
|
|
89
|
+
if (raw === undefined)
|
|
90
|
+
return fallback;
|
|
91
|
+
const n = Number(raw);
|
|
92
|
+
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
93
|
+
}
|
|
94
|
+
/** Derive a heartbeat cadence that emits several beats inside the timeout window. */
|
|
95
|
+
function deriveCheckIntervalMs(timeoutMs) {
|
|
96
|
+
return Math.min(2000, Math.max(50, Math.round(timeoutMs / 5)));
|
|
97
|
+
}
|
|
98
|
+
/** Arming/teardown diagnostics, gated on the existing MCP debug switch. */
|
|
99
|
+
function debug(msg) {
|
|
100
|
+
if (process.env.CODEGRAPH_MCP_DEBUG) {
|
|
101
|
+
try {
|
|
102
|
+
fs.writeSync(2, `[CodeGraph watchdog] ${msg}\n`);
|
|
103
|
+
}
|
|
104
|
+
catch { /* ignore */ }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The watchdog child body, run via `node -e`. Inlined as a string (not a
|
|
109
|
+
* shipped `.js`) so there is no dist-vs-src path to resolve — it runs
|
|
110
|
+
* identically under `tsx` in tests and under the bundle in production. Reads its
|
|
111
|
+
* target pid + timeout from argv; an MSG built once at startup (the child is
|
|
112
|
+
* never wedged, so allocation here is fine).
|
|
113
|
+
*/
|
|
114
|
+
const CHILD_SOURCE = `
|
|
115
|
+
const fs = require('fs');
|
|
116
|
+
const parentPid = Number(process.argv[1]);
|
|
117
|
+
const timeoutMs = Number(process.argv[2]);
|
|
118
|
+
const secs = Math.round(timeoutMs / 1000);
|
|
119
|
+
const MSG = Buffer.from('[CodeGraph] Main thread unresponsive for ~' + secs + 's — killing the wedged process so a fresh one can start (#850). Disable with CODEGRAPH_NO_WATCHDOG=1.\\n');
|
|
120
|
+
function kill() {
|
|
121
|
+
try { fs.writeSync(2, MSG); } catch (e) {}
|
|
122
|
+
try { process.kill(parentPid, 'SIGKILL'); } catch (e) {}
|
|
123
|
+
process.exit(0);
|
|
124
|
+
}
|
|
125
|
+
let timer = setTimeout(kill, timeoutMs);
|
|
126
|
+
process.stdin.on('data', () => { clearTimeout(timer); timer = setTimeout(kill, timeoutMs); });
|
|
127
|
+
process.stdin.on('end', () => process.exit(0)); // parent closed the pipe (exited) -> no orphan
|
|
128
|
+
process.stdin.on('error', () => process.exit(0)); // pipe broke -> parent gone
|
|
129
|
+
process.stdin.resume();
|
|
130
|
+
`;
|
|
131
|
+
/**
|
|
132
|
+
* Install the main-thread liveness watchdog for a long-lived process. Returns a
|
|
133
|
+
* handle to stop it, or `null` when disabled or when the child can't be spawned
|
|
134
|
+
* (degraded, never throws — a missing watchdog must never keep a process from
|
|
135
|
+
* starting).
|
|
136
|
+
*/
|
|
137
|
+
function installMainThreadWatchdog() {
|
|
138
|
+
if (isEnvTruthy(process.env.CODEGRAPH_NO_WATCHDOG))
|
|
139
|
+
return null;
|
|
140
|
+
const timeoutMs = parseWatchdogTimeoutMs(process.env.CODEGRAPH_WATCHDOG_TIMEOUT_MS);
|
|
141
|
+
const checkMs = deriveCheckIntervalMs(timeoutMs);
|
|
142
|
+
let child;
|
|
143
|
+
try {
|
|
144
|
+
// No execArgv inheritance (unlike Worker), so the child carries none of our
|
|
145
|
+
// V8 flags — it runs no WASM and needs none. stderr inherits the parent's
|
|
146
|
+
// fd 2 so the kill notice lands wherever the parent logs (daemon.log).
|
|
147
|
+
child = (0, child_process_1.spawn)(process.execPath, ['-e', CHILD_SOURCE, String(process.pid), String(timeoutMs)], {
|
|
148
|
+
stdio: ['pipe', 'ignore', 'inherit'],
|
|
149
|
+
windowsHide: true,
|
|
150
|
+
// The watchdog touches no files; keep its cwd off the project/temp dir
|
|
151
|
+
// so it can't hold one open (Windows EPERM-on-cleanup, mirrors the
|
|
152
|
+
// parse-worker quirk).
|
|
153
|
+
cwd: os.tmpdir(),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
debug(`spawn failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
const stdin = child.stdin;
|
|
161
|
+
if (!stdin) {
|
|
162
|
+
debug('child has no stdin pipe; not arming');
|
|
163
|
+
try {
|
|
164
|
+
child.kill();
|
|
165
|
+
}
|
|
166
|
+
catch { /* ignore */ }
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
// Writing after the child exits surfaces EPIPE on the stream — swallow it so
|
|
170
|
+
// it can't escalate to the global handler (which now exits, #850).
|
|
171
|
+
stdin.on('error', () => { });
|
|
172
|
+
child.on('error', (err) => debug(`child error: ${err.message}`));
|
|
173
|
+
// Heartbeat: a byte per tick. When the main thread wedges, these stop and the
|
|
174
|
+
// child's timeout fires. unref'd so it never keeps the process alive itself.
|
|
175
|
+
const heartbeat = setInterval(() => {
|
|
176
|
+
try {
|
|
177
|
+
stdin.write('\n');
|
|
178
|
+
}
|
|
179
|
+
catch { /* child gone */ }
|
|
180
|
+
}, checkMs);
|
|
181
|
+
heartbeat.unref();
|
|
182
|
+
// Neither the child nor its pipe should keep the parent alive past its work.
|
|
183
|
+
child.unref();
|
|
184
|
+
try {
|
|
185
|
+
stdin.unref?.();
|
|
186
|
+
}
|
|
187
|
+
catch { /* ignore */ }
|
|
188
|
+
debug(`armed (child pid ${child.pid ?? '?'}): timeoutMs=${timeoutMs} checkMs=${checkMs}`);
|
|
189
|
+
let stopped = false;
|
|
190
|
+
return {
|
|
191
|
+
stop() {
|
|
192
|
+
if (stopped)
|
|
193
|
+
return;
|
|
194
|
+
stopped = true;
|
|
195
|
+
clearInterval(heartbeat);
|
|
196
|
+
try {
|
|
197
|
+
stdin.end();
|
|
198
|
+
}
|
|
199
|
+
catch { /* ignore */ } // EOF -> child exits cleanly
|
|
200
|
+
try {
|
|
201
|
+
child.kill();
|
|
202
|
+
}
|
|
203
|
+
catch { /* ignore */ } // belt-and-suspenders
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=liveness-watchdog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liveness-watchdog.js","sourceRoot":"","sources":["../../src/mcp/liveness-watchdog.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared decision logic for the PPID watchdog (#277, #692).
|
|
3
|
+
*
|
|
4
|
+
* The watchdog's job: notice that the process we depend on — our parent, or the
|
|
5
|
+
* MCP host reached past an intermediate launcher — has died, so an orphaned
|
|
6
|
+
* proxy / direct server shuts itself down instead of leaking forever.
|
|
7
|
+
*
|
|
8
|
+
* Parent death surfaces differently per OS, and getting this wrong is what
|
|
9
|
+
* caused the unbounded daemon/proxy leak on Windows (#692, #576):
|
|
10
|
+
*
|
|
11
|
+
* - **POSIX** reparents an orphan to init (pid 1), so `process.ppid` *changes*
|
|
12
|
+
* the instant the parent dies. That divergence is the classic #277 signal.
|
|
13
|
+
* - **Windows** never reparents: `process.ppid` keeps reporting the original
|
|
14
|
+
* (now-dead) parent forever, so the change-check can never fire. There we
|
|
15
|
+
* must poll the original parent's *liveness* instead.
|
|
16
|
+
*
|
|
17
|
+
* The liveness fallback is deliberately gated to Windows. On POSIX a
|
|
18
|
+
* double-forked grandparent can legitimately outlive the reparent, so a dead
|
|
19
|
+
* `originalPpid` is not proof of orphaning there — the change-check is the
|
|
20
|
+
* correct and sufficient POSIX signal, and using liveness too would risk a
|
|
21
|
+
* false-positive shutdown.
|
|
22
|
+
*/
|
|
23
|
+
export interface SupervisionState {
|
|
24
|
+
/** `process.ppid` captured at startup. */
|
|
25
|
+
originalPpid: number;
|
|
26
|
+
/** `process.ppid` right now. */
|
|
27
|
+
currentPpid: number;
|
|
28
|
+
/**
|
|
29
|
+
* The MCP host pid threaded past an intermediate launcher
|
|
30
|
+
* (`CODEGRAPH_HOST_PPID`), or null when unknown — e.g. the standalone bundle,
|
|
31
|
+
* which pre-bakes `--liftoff-only` and so never runs the relaunch that sets it.
|
|
32
|
+
*/
|
|
33
|
+
hostPpid: number | null;
|
|
34
|
+
/** Liveness probe — `process.kill(pid, 0)` in production, stubbed in tests. */
|
|
35
|
+
isAlive: (pid: number) => boolean;
|
|
36
|
+
/** Defaults to `process.platform`. */
|
|
37
|
+
platform?: NodeJS.Platform;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns a human-readable reason string when the process has lost its
|
|
41
|
+
* supervisor and should shut down, or null while it is still supervised.
|
|
42
|
+
*/
|
|
43
|
+
export declare function supervisionLostReason(state: SupervisionState): string | null;
|
|
44
|
+
//# sourceMappingURL=ppid-watchdog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ppid-watchdog.d.ts","sourceRoot":"","sources":["../../src/mcp/ppid-watchdog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,+EAA+E;IAC/E,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAClC,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,GAAG,IAAI,CAmB5E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.supervisionLostReason = supervisionLostReason;
|
|
4
|
+
/**
|
|
5
|
+
* Returns a human-readable reason string when the process has lost its
|
|
6
|
+
* supervisor and should shut down, or null while it is still supervised.
|
|
7
|
+
*/
|
|
8
|
+
function supervisionLostReason(state) {
|
|
9
|
+
const { originalPpid, currentPpid, hostPpid, isAlive } = state;
|
|
10
|
+
const platform = state.platform ?? process.platform;
|
|
11
|
+
// POSIX: the parent dying reparents us, so ppid diverges. (Never on Windows.)
|
|
12
|
+
if (currentPpid !== originalPpid) {
|
|
13
|
+
return `ppid ${originalPpid} -> ${currentPpid}`;
|
|
14
|
+
}
|
|
15
|
+
// Windows: ppid is stable across parent death, so detect it by liveness.
|
|
16
|
+
// Skip pid 0/1 — "unknown" and init are never a real Windows parent, and a
|
|
17
|
+
// bogus liveness probe there must not trigger a shutdown.
|
|
18
|
+
if (platform === 'win32' && originalPpid > 1 && !isAlive(originalPpid)) {
|
|
19
|
+
return `parent pid ${originalPpid} exited`;
|
|
20
|
+
}
|
|
21
|
+
// Either platform: the host pid threaded past a launcher shim is gone.
|
|
22
|
+
if (hostPpid !== null && !isAlive(hostPpid)) {
|
|
23
|
+
return `host pid ${hostPpid} exited`;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ppid-watchdog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ppid-watchdog.js","sourceRoot":"","sources":["../../src/mcp/ppid-watchdog.ts"],"names":[],"mappings":";;AA2CA,sDAmBC;AAvBD;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,KAAuB;IAC3D,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC/D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IAEpD,8EAA8E;IAC9E,IAAI,WAAW,KAAK,YAAY,EAAE,CAAC;QACjC,OAAO,QAAQ,YAAY,OAAO,WAAW,EAAE,CAAC;IAClD,CAAC;IACD,yEAAyE;IACzE,2EAA2E;IAC3E,0DAA0D;IAC1D,IAAI,QAAQ,KAAK,OAAO,IAAI,YAAY,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QACvE,OAAO,cAAc,YAAY,SAAS,CAAC;IAC7C,CAAC;IACD,uEAAuE;IACvE,IAAI,QAAQ,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5C,OAAO,YAAY,QAAQ,SAAS,CAAC;IACvC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/lib/dist/mcp/proxy.d.ts
CHANGED
|
@@ -18,7 +18,13 @@
|
|
|
18
18
|
* the direct-mode server uses; see issue #277.
|
|
19
19
|
*/
|
|
20
20
|
import * as net from 'net';
|
|
21
|
+
import { DaemonHello } from './daemon';
|
|
21
22
|
import type { MCPEngine } from './engine';
|
|
23
|
+
/**
|
|
24
|
+
* Log a successful daemon attach — gated behind {@link LOG_ATTACH_ENV} so it is
|
|
25
|
+
* silent by default (see #618). Exported for tests.
|
|
26
|
+
*/
|
|
27
|
+
export declare function logAttachedDaemon(socketPath: string, hello: DaemonHello): void;
|
|
22
28
|
export interface ProxyResult {
|
|
23
29
|
/**
|
|
24
30
|
* `proxied` — successfully attached to a same-version daemon and piped
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/mcp/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/mcp/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAE3B,OAAO,EAAqB,WAAW,EAAwB,MAAM,UAAU,CAAC;AAQhF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAc1C;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAK9E;AAED,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,OAAO,EAAE,SAAS,GAAG,iBAAiB,CAAC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,QAAQ,CAC5B,UAAU,EAAE,MAAM,EAClB,eAAe,GAAE,MAAgC,GAChD,OAAO,CAAC,WAAW,CAAC,CAqCtB;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,MAAM,EAClB,eAAe,GAAE,MAAgC,GAChD,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAAC,CAsBjD;AAsBD;+DAC+D;AAC/D,MAAM,WAAW,kBAAkB;IACjC;yFACqF;IACrF,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9C;6EACyE;IACzE,UAAU,IAAI,SAAS,CAAC;IACxB,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8KpF"}
|
package/lib/dist/mcp/proxy.js
CHANGED
|
@@ -52,6 +52,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
52
52
|
};
|
|
53
53
|
})();
|
|
54
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.logAttachedDaemon = logAttachedDaemon;
|
|
55
56
|
exports.runProxy = runProxy;
|
|
56
57
|
exports.connectWithHello = connectWithHello;
|
|
57
58
|
exports.runLocalHandshakeProxy = runLocalHandshakeProxy;
|
|
@@ -59,12 +60,32 @@ const fs = __importStar(require("fs"));
|
|
|
59
60
|
const net = __importStar(require("net"));
|
|
60
61
|
const wasm_runtime_flags_1 = require("../extraction/wasm-runtime-flags");
|
|
61
62
|
const daemon_1 = require("./daemon");
|
|
63
|
+
const ppid_watchdog_1 = require("./ppid-watchdog");
|
|
64
|
+
const stdin_teardown_1 = require("./stdin-teardown");
|
|
62
65
|
const version_1 = require("./version");
|
|
63
66
|
const session_1 = require("./session");
|
|
64
67
|
const server_instructions_1 = require("./server-instructions");
|
|
65
68
|
const tools_1 = require("./tools");
|
|
69
|
+
const telemetry_1 = require("../telemetry");
|
|
66
70
|
/** Default poll cadence for the PPID watchdog (same as the direct server). */
|
|
67
71
|
const DEFAULT_PPID_POLL_MS = 5000;
|
|
72
|
+
/**
|
|
73
|
+
* Env var that opts INTO the "attached to shared daemon" log line. Off by
|
|
74
|
+
* default: the line is benign INFO, but MCP hosts render any server stderr at
|
|
75
|
+
* error level (and append an `undefined` data field), so on every session start
|
|
76
|
+
* a healthy attach showed up as `[error] … undefined`. Set to `1` to surface it
|
|
77
|
+
* when debugging daemon attach. (#618; approach from #640 by @mturac)
|
|
78
|
+
*/
|
|
79
|
+
const LOG_ATTACH_ENV = 'CODEGRAPH_MCP_LOG_ATTACH';
|
|
80
|
+
/**
|
|
81
|
+
* Log a successful daemon attach — gated behind {@link LOG_ATTACH_ENV} so it is
|
|
82
|
+
* silent by default (see #618). Exported for tests.
|
|
83
|
+
*/
|
|
84
|
+
function logAttachedDaemon(socketPath, hello) {
|
|
85
|
+
if (process.env[LOG_ATTACH_ENV] !== '1')
|
|
86
|
+
return;
|
|
87
|
+
process.stderr.write(`[CodeGraph MCP] Attached to shared daemon on ${socketPath} (pid ${hello.pid}, v${hello.codegraph}).\n`);
|
|
88
|
+
}
|
|
68
89
|
/**
|
|
69
90
|
* Attempt to connect to the daemon at `socketPath` and pipe stdio through it.
|
|
70
91
|
*
|
|
@@ -102,7 +123,8 @@ async function runProxy(socketPath, expectedVersion = version_1.CodeGraphPackage
|
|
|
102
123
|
socket.destroy();
|
|
103
124
|
return { outcome: 'fallback-needed', reason: 'version mismatch' };
|
|
104
125
|
}
|
|
105
|
-
|
|
126
|
+
logAttachedDaemon(socketPath, hello);
|
|
127
|
+
sendClientHello(socket);
|
|
106
128
|
startPpidWatchdog(socket);
|
|
107
129
|
await pipeUntilClose(socket);
|
|
108
130
|
// Host disconnected (or the daemon went away). The proxy's only job is the
|
|
@@ -134,9 +156,30 @@ async function connectWithHello(socketPath, expectedVersion = version_1.CodeGrap
|
|
|
134
156
|
socket.destroy();
|
|
135
157
|
return 'version-mismatch';
|
|
136
158
|
}
|
|
137
|
-
|
|
159
|
+
logAttachedDaemon(socketPath, hello);
|
|
160
|
+
sendClientHello(socket);
|
|
138
161
|
return socket;
|
|
139
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Tell the daemon our pids right after we verify its hello, so its liveness
|
|
165
|
+
* sweep can reap this client if our process dies without the socket ever
|
|
166
|
+
* signalling close (the Windows named-pipe hazard behind #692). Best-effort:
|
|
167
|
+
* sent before any piped bytes so it's always the daemon's first line from us,
|
|
168
|
+
* and a write failure here is harmless (the daemon just falls back to the
|
|
169
|
+
* socket-close lifecycle). `hostPid` mirrors the PPID watchdog: the threaded
|
|
170
|
+
* host pid if set, else our own parent (the host, on a no-relaunch bundle).
|
|
171
|
+
*/
|
|
172
|
+
function sendClientHello(socket) {
|
|
173
|
+
const clientHello = {
|
|
174
|
+
codegraph_client: 1,
|
|
175
|
+
pid: process.pid,
|
|
176
|
+
hostPid: parseHostPpid(process.env[wasm_runtime_flags_1.HOST_PPID_ENV]) ?? process.ppid,
|
|
177
|
+
};
|
|
178
|
+
try {
|
|
179
|
+
socket.write(JSON.stringify(clientHello) + '\n');
|
|
180
|
+
}
|
|
181
|
+
catch { /* best-effort */ }
|
|
182
|
+
}
|
|
140
183
|
/**
|
|
141
184
|
* Local-handshake proxy (the cold-start fix).
|
|
142
185
|
*
|
|
@@ -154,10 +197,28 @@ async function runLocalHandshakeProxy(deps) {
|
|
|
154
197
|
let daemonStatus = 'connecting';
|
|
155
198
|
let daemonSocket = null;
|
|
156
199
|
let clientInitId = undefined; // suppress the daemon's reply to the forwarded initialize
|
|
200
|
+
// Telemetry attribution for the in-process fallback only — calls routed to
|
|
201
|
+
// the daemon are counted by the daemon's own session (which receives the
|
|
202
|
+
// forwarded initialize, clientInfo included), never double-counted here.
|
|
203
|
+
let telemetryClient;
|
|
157
204
|
const pending = []; // client lines buffered until the daemon resolves
|
|
158
205
|
let engine = null;
|
|
159
206
|
let engineReady = null;
|
|
160
207
|
let shuttingDown = false;
|
|
208
|
+
// Requests forwarded to the daemon and not yet answered, keyed by JSON-RPC id.
|
|
209
|
+
// If the daemon dies mid-session (#662 — e.g. an MCP host SIGTERM's it when a
|
|
210
|
+
// new session starts), these would otherwise hang forever; we re-serve them
|
|
211
|
+
// in-process so the host always gets a reply.
|
|
212
|
+
const inflight = new Map();
|
|
213
|
+
const trackInflight = (line) => {
|
|
214
|
+
try {
|
|
215
|
+
const m = JSON.parse(line);
|
|
216
|
+
if (m && m.id !== undefined && typeof m.method === 'string' && m.method !== 'initialize') {
|
|
217
|
+
inflight.set(m.id, line);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch { /* unparseable — nothing we could re-serve anyway */ }
|
|
221
|
+
};
|
|
161
222
|
const writeClient = (obj) => {
|
|
162
223
|
try {
|
|
163
224
|
process.stdout.write((typeof obj === 'string' ? obj : JSON.stringify(obj)) + '\n');
|
|
@@ -201,6 +262,7 @@ async function runLocalHandshakeProxy(deps) {
|
|
|
201
262
|
const params = (msg.params || {});
|
|
202
263
|
const result = await engine.getToolHandler().execute(params.name, params.arguments || {});
|
|
203
264
|
writeClient({ jsonrpc: '2.0', id, result });
|
|
265
|
+
(0, telemetry_1.getTelemetry)().recordUsage('mcp_tool', params.name, !result.isError, telemetryClient);
|
|
204
266
|
}
|
|
205
267
|
catch (err) {
|
|
206
268
|
writeClient({ jsonrpc: '2.0', id, error: { code: -32603, message: err instanceof Error ? err.message : String(err) } });
|
|
@@ -209,10 +271,16 @@ async function runLocalHandshakeProxy(deps) {
|
|
|
209
271
|
else if (msg.method === 'ping' && id !== undefined) {
|
|
210
272
|
writeClient({ jsonrpc: '2.0', id, result: {} });
|
|
211
273
|
}
|
|
274
|
+
else if (id !== undefined && msg.method !== 'initialize') {
|
|
275
|
+
// A request we can't serve in-process (and the daemon is gone) — answer
|
|
276
|
+
// with an error rather than let the host hang on a reply that won't come.
|
|
277
|
+
writeClient({ jsonrpc: '2.0', id, error: { code: -32603, message: 'CodeGraph daemon unavailable' } });
|
|
278
|
+
}
|
|
212
279
|
// initialize already answered locally; notifications (initialized) need no reply.
|
|
213
280
|
};
|
|
214
281
|
const routeToDaemon = (line) => {
|
|
215
282
|
if (daemonStatus === 'ready' && daemonSocket) {
|
|
283
|
+
trackInflight(line);
|
|
216
284
|
try {
|
|
217
285
|
daemonSocket.write(line.endsWith('\n') ? line : line + '\n');
|
|
218
286
|
}
|
|
@@ -246,19 +314,40 @@ async function runLocalHandshakeProxy(deps) {
|
|
|
246
314
|
}
|
|
247
315
|
if (msg.method === 'initialize') {
|
|
248
316
|
clientInitId = msg.id;
|
|
317
|
+
const initParams = (msg.params ?? {});
|
|
318
|
+
if (initParams.clientInfo) {
|
|
319
|
+
telemetryClient = {
|
|
320
|
+
name: typeof initParams.clientInfo.name === 'string' ? initParams.clientInfo.name : undefined,
|
|
321
|
+
version: typeof initParams.clientInfo.version === 'string' ? initParams.clientInfo.version : undefined,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
249
324
|
writeClient({ jsonrpc: '2.0', id: msg.id, result: { protocolVersion: session_1.PROTOCOL_VERSION, capabilities: { tools: {} }, serverInfo: session_1.SERVER_INFO, instructions: server_instructions_1.SERVER_INSTRUCTIONS } });
|
|
250
325
|
routeToDaemon(line); // prime the daemon so it resolves the project (its reply is suppressed below)
|
|
251
326
|
}
|
|
252
327
|
else if (msg.method === 'tools/list') {
|
|
253
328
|
writeClient({ jsonrpc: '2.0', id: msg.id, result: { tools: (0, tools_1.getStaticTools)() } });
|
|
254
329
|
}
|
|
330
|
+
else if (msg.method === 'resources/list') {
|
|
331
|
+
// No resources exposed — answer the probe locally so it never reaches
|
|
332
|
+
// the daemon as an unhandled method and logs `-32601`. (#621)
|
|
333
|
+
writeClient({ jsonrpc: '2.0', id: msg.id, result: { resources: [] } });
|
|
334
|
+
}
|
|
335
|
+
else if (msg.method === 'resources/templates/list') {
|
|
336
|
+
writeClient({ jsonrpc: '2.0', id: msg.id, result: { resourceTemplates: [] } });
|
|
337
|
+
}
|
|
338
|
+
else if (msg.method === 'prompts/list') {
|
|
339
|
+
writeClient({ jsonrpc: '2.0', id: msg.id, result: { prompts: [] } });
|
|
340
|
+
}
|
|
255
341
|
else {
|
|
256
342
|
routeToDaemon(line);
|
|
257
343
|
}
|
|
258
344
|
}
|
|
259
345
|
});
|
|
260
|
-
|
|
261
|
-
|
|
346
|
+
// Shut down when stdin ends/closes — and also on a stdin `'error'`, which a
|
|
347
|
+
// socket-backed stdin (the VS Code stdio shape) can emit on client death
|
|
348
|
+
// instead of a clean close; destroying the stream stops a hung fd from
|
|
349
|
+
// busy-spinning the event loop (#799).
|
|
350
|
+
(0, stdin_teardown_1.treatStdinFailureAsShutdown)(shutdown);
|
|
262
351
|
startPpidWatchdogNoSocket(shutdown);
|
|
263
352
|
// ---- daemon connection (background) ----
|
|
264
353
|
let socket = null;
|
|
@@ -281,20 +370,45 @@ async function runLocalHandshakeProxy(deps) {
|
|
|
281
370
|
sockBuf = sockBuf.slice(idx + 1);
|
|
282
371
|
if (!line.trim())
|
|
283
372
|
continue;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
373
|
+
let resp = null;
|
|
374
|
+
try {
|
|
375
|
+
resp = JSON.parse(line);
|
|
376
|
+
}
|
|
377
|
+
catch { /* not JSON — relay verbatim */ }
|
|
378
|
+
if (resp && resp.id !== undefined && ('result' in resp || 'error' in resp)) {
|
|
379
|
+
inflight.delete(resp.id); // answered — no longer in flight
|
|
380
|
+
// Suppress the daemon's reply to the initialize we forwarded to prime it
|
|
381
|
+
// (the client already got the local handshake response).
|
|
382
|
+
if (clientInitId !== undefined && resp.id === clientInitId)
|
|
383
|
+
continue;
|
|
291
384
|
}
|
|
292
385
|
writeClient(line);
|
|
293
386
|
}
|
|
294
387
|
});
|
|
295
|
-
|
|
296
|
-
|
|
388
|
+
// The daemon going away does NOT end the session (#662). An MCP host can
|
|
389
|
+
// SIGTERM the shared daemon when another session starts; if we exited here,
|
|
390
|
+
// this host would silently lose CodeGraph and any in-flight request would
|
|
391
|
+
// hang. Instead, fall back to the in-process engine for the rest of the
|
|
392
|
+
// session and re-serve whatever the dead daemon never answered.
|
|
393
|
+
const onDaemonLost = () => {
|
|
394
|
+
if (shuttingDown || daemonStatus !== 'ready')
|
|
395
|
+
return; // host teardown, or already handled
|
|
396
|
+
daemonStatus = 'failed';
|
|
397
|
+
try {
|
|
398
|
+
daemonSocket?.destroy();
|
|
399
|
+
}
|
|
400
|
+
catch { /* ignore */ }
|
|
401
|
+
daemonSocket = null;
|
|
402
|
+
process.stderr.write(`[CodeGraph MCP] Shared daemon connection lost; serving this session in-process (degraded), re-serving ${inflight.size} in-flight request(s).\n`);
|
|
403
|
+
const orphaned = [...inflight.values()];
|
|
404
|
+
inflight.clear();
|
|
405
|
+
for (const line of orphaned)
|
|
406
|
+
void handleLocally(line);
|
|
407
|
+
};
|
|
408
|
+
socket.on('close', onDaemonLost);
|
|
409
|
+
socket.on('error', onDaemonLost);
|
|
297
410
|
for (const line of pending) {
|
|
411
|
+
trackInflight(line);
|
|
298
412
|
try {
|
|
299
413
|
socket.write(line + '\n');
|
|
300
414
|
}
|
|
@@ -321,8 +435,14 @@ function startPpidWatchdogNoSocket(onDeath) {
|
|
|
321
435
|
const originalPpid = process.ppid;
|
|
322
436
|
const hostPpid = parseHostPpid(process.env[wasm_runtime_flags_1.HOST_PPID_ENV]);
|
|
323
437
|
const timer = setInterval(() => {
|
|
324
|
-
|
|
325
|
-
|
|
438
|
+
const reason = (0, ppid_watchdog_1.supervisionLostReason)({
|
|
439
|
+
originalPpid,
|
|
440
|
+
currentPpid: process.ppid,
|
|
441
|
+
hostPpid,
|
|
442
|
+
isAlive: isProcessAliveLocal,
|
|
443
|
+
});
|
|
444
|
+
if (reason) {
|
|
445
|
+
process.stderr.write(`[CodeGraph MCP] Parent process exited (${reason}); shutting down.\n`);
|
|
326
446
|
onDeath();
|
|
327
447
|
}
|
|
328
448
|
}, pollMs);
|
|
@@ -412,13 +532,22 @@ function pipeUntilClose(socket) {
|
|
|
412
532
|
catch { /* ignore */ }
|
|
413
533
|
done();
|
|
414
534
|
});
|
|
415
|
-
|
|
535
|
+
// 'close' and 'error' both tear down: a socket-backed stdin can fail with
|
|
536
|
+
// an 'error' (ECONNRESET/hangup) rather than a clean close; destroying it
|
|
537
|
+
// stops a hung fd from busy-spinning the event loop (#799).
|
|
538
|
+
const teardown = () => {
|
|
539
|
+
try {
|
|
540
|
+
process.stdin.destroy();
|
|
541
|
+
}
|
|
542
|
+
catch { /* ignore */ }
|
|
416
543
|
try {
|
|
417
544
|
socket.destroy();
|
|
418
545
|
}
|
|
419
546
|
catch { /* ignore */ }
|
|
420
547
|
done();
|
|
421
|
-
}
|
|
548
|
+
};
|
|
549
|
+
process.stdin.on('close', teardown);
|
|
550
|
+
process.stdin.on('error', teardown);
|
|
422
551
|
socket.on('data', (chunk) => {
|
|
423
552
|
try {
|
|
424
553
|
process.stdout.write(chunk);
|
|
@@ -449,13 +578,13 @@ function startPpidWatchdog(socket) {
|
|
|
449
578
|
const originalPpid = process.ppid;
|
|
450
579
|
const hostPpid = parseHostPpid(process.env[wasm_runtime_flags_1.HOST_PPID_ENV]);
|
|
451
580
|
const timer = setInterval(() => {
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
581
|
+
const reason = (0, ppid_watchdog_1.supervisionLostReason)({
|
|
582
|
+
originalPpid,
|
|
583
|
+
currentPpid: process.ppid,
|
|
584
|
+
hostPpid,
|
|
585
|
+
isAlive: isProcessAliveLocal,
|
|
586
|
+
});
|
|
587
|
+
if (reason) {
|
|
459
588
|
process.stderr.write(`[CodeGraph MCP] Parent process exited (${reason}); shutting down.\n`);
|
|
460
589
|
try {
|
|
461
590
|
socket.destroy();
|