@colbymchenry/codegraph-darwin-x64 0.9.3 → 0.9.5
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 +3 -0
- package/lib/dist/bin/codegraph.d.ts.map +1 -1
- package/lib/dist/bin/codegraph.js +250 -0
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/context/index.d.ts +13 -0
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +120 -1
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +18 -0
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +31 -0
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/queries.d.ts +16 -0
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +80 -27
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts +6 -0
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +31 -1
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +15 -2
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +170 -78
- package/lib/dist/extraction/index.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/objc.d.ts +3 -0
- package/lib/dist/extraction/languages/objc.d.ts.map +1 -0
- package/lib/dist/extraction/languages/objc.js +133 -0
- package/lib/dist/extraction/languages/objc.js.map +1 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts +4 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +155 -9
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.d.ts +12 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.js +14 -2
- package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
- package/lib/dist/graph/traversal.d.ts.map +1 -1
- package/lib/dist/graph/traversal.js +71 -36
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/index.d.ts +21 -2
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +42 -0
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/instructions-template.d.ts +2 -2
- package/lib/dist/installer/instructions-template.d.ts.map +1 -1
- package/lib/dist/installer/instructions-template.js +3 -2
- package/lib/dist/installer/instructions-template.js.map +1 -1
- package/lib/dist/mcp/daemon-paths.d.ts +46 -0
- package/lib/dist/mcp/daemon-paths.d.ts.map +1 -0
- package/lib/dist/mcp/daemon-paths.js +125 -0
- package/lib/dist/mcp/daemon-paths.js.map +1 -0
- package/lib/dist/mcp/daemon.d.ts +161 -0
- package/lib/dist/mcp/daemon.d.ts.map +1 -0
- package/lib/dist/mcp/daemon.js +403 -0
- package/lib/dist/mcp/daemon.js.map +1 -0
- package/lib/dist/mcp/engine.d.ts +100 -0
- package/lib/dist/mcp/engine.d.ts.map +1 -0
- package/lib/dist/mcp/engine.js +291 -0
- package/lib/dist/mcp/engine.js.map +1 -0
- package/lib/dist/mcp/index.d.ts +67 -52
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +347 -330
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/proxy.d.ts +46 -0
- package/lib/dist/mcp/proxy.d.ts.map +1 -0
- package/lib/dist/mcp/proxy.js +276 -0
- package/lib/dist/mcp/proxy.js.map +1 -0
- package/lib/dist/mcp/server-instructions.d.ts +1 -1
- package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
- package/lib/dist/mcp/server-instructions.js +3 -1
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +67 -0
- package/lib/dist/mcp/session.d.ts.map +1 -0
- package/lib/dist/mcp/session.js +276 -0
- package/lib/dist/mcp/session.js.map +1 -0
- package/lib/dist/mcp/tools.d.ts +130 -2
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +902 -37
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/mcp/transport.d.ts +111 -29
- package/lib/dist/mcp/transport.d.ts.map +1 -1
- package/lib/dist/mcp/transport.js +181 -71
- package/lib/dist/mcp/transport.js.map +1 -1
- package/lib/dist/mcp/version.d.ts +19 -0
- package/lib/dist/mcp/version.d.ts.map +1 -0
- package/lib/dist/mcp/version.js +71 -0
- package/lib/dist/mcp/version.js.map +1 -0
- package/lib/dist/resolution/callback-synthesizer.d.ts +10 -0
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -0
- package/lib/dist/resolution/callback-synthesizer.js +847 -0
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -0
- package/lib/dist/resolution/frameworks/csharp.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/csharp.js +36 -8
- package/lib/dist/resolution/frameworks/csharp.js.map +1 -1
- package/lib/dist/resolution/frameworks/drupal.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/drupal.js +44 -12
- package/lib/dist/resolution/frameworks/drupal.js.map +1 -1
- package/lib/dist/resolution/frameworks/expo-modules.d.ts +3 -0
- package/lib/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/expo-modules.js +143 -0
- package/lib/dist/resolution/frameworks/expo-modules.js.map +1 -0
- package/lib/dist/resolution/frameworks/express.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/express.js +102 -19
- package/lib/dist/resolution/frameworks/express.js.map +1 -1
- package/lib/dist/resolution/frameworks/fabric.d.ts +3 -0
- package/lib/dist/resolution/frameworks/fabric.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/fabric.js +354 -0
- package/lib/dist/resolution/frameworks/fabric.js.map +1 -0
- package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/go.js +6 -3
- package/lib/dist/resolution/frameworks/go.js.map +1 -1
- package/lib/dist/resolution/frameworks/index.d.ts +5 -0
- package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/index.js +25 -1
- package/lib/dist/resolution/frameworks/index.js.map +1 -1
- package/lib/dist/resolution/frameworks/java.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/java.js +70 -12
- package/lib/dist/resolution/frameworks/java.js.map +1 -1
- package/lib/dist/resolution/frameworks/laravel.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/laravel.js +17 -8
- package/lib/dist/resolution/frameworks/laravel.js.map +1 -1
- package/lib/dist/resolution/frameworks/play.d.ts +19 -0
- package/lib/dist/resolution/frameworks/play.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/play.js +111 -0
- package/lib/dist/resolution/frameworks/play.js.map +1 -0
- package/lib/dist/resolution/frameworks/python.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/python.js +134 -16
- package/lib/dist/resolution/frameworks/python.js.map +1 -1
- package/lib/dist/resolution/frameworks/react-native.d.ts +3 -0
- package/lib/dist/resolution/frameworks/react-native.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/react-native.js +360 -0
- package/lib/dist/resolution/frameworks/react-native.js.map +1 -0
- package/lib/dist/resolution/frameworks/react.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/react.js +96 -3
- package/lib/dist/resolution/frameworks/react.js.map +1 -1
- package/lib/dist/resolution/frameworks/ruby.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/ruby.js +106 -2
- package/lib/dist/resolution/frameworks/ruby.js.map +1 -1
- package/lib/dist/resolution/frameworks/rust.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/rust.js +102 -5
- package/lib/dist/resolution/frameworks/rust.js.map +1 -1
- package/lib/dist/resolution/frameworks/swift-objc.d.ts +37 -0
- package/lib/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/swift-objc.js +252 -0
- package/lib/dist/resolution/frameworks/swift-objc.js.map +1 -0
- package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/swift.js +30 -6
- package/lib/dist/resolution/frameworks/swift.js.map +1 -1
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +1 -0
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +61 -9
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/lru-cache.d.ts +24 -0
- package/lib/dist/resolution/lru-cache.d.ts.map +1 -0
- package/lib/dist/resolution/lru-cache.js +62 -0
- package/lib/dist/resolution/lru-cache.js.map +1 -0
- package/lib/dist/resolution/swift-objc-bridge.d.ts +134 -0
- package/lib/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
- package/lib/dist/resolution/swift-objc-bridge.js +256 -0
- package/lib/dist/resolution/swift-objc-bridge.js.map +1 -0
- package/lib/dist/resolution/types.d.ts +8 -0
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/sync/index.d.ts +3 -1
- package/lib/dist/sync/index.d.ts.map +1 -1
- package/lib/dist/sync/index.js +7 -1
- package/lib/dist/sync/index.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +109 -7
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +215 -33
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/sync/worktree.d.ts +54 -0
- package/lib/dist/sync/worktree.d.ts.map +1 -0
- package/lib/dist/sync/worktree.js +136 -0
- package/lib/dist/sync/worktree.js.map +1 -0
- package/lib/dist/types.d.ts +1 -1
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +1 -0
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/utils.js +1 -1
- package/lib/node_modules/.package-lock.json +29 -1
- package/lib/node_modules/chokidar/LICENSE +21 -0
- package/lib/node_modules/chokidar/README.md +305 -0
- package/lib/node_modules/chokidar/esm/handler.d.ts +90 -0
- package/lib/node_modules/chokidar/esm/handler.js +629 -0
- package/lib/node_modules/chokidar/esm/index.d.ts +215 -0
- package/lib/node_modules/chokidar/esm/index.js +798 -0
- package/lib/node_modules/chokidar/esm/package.json +1 -0
- package/lib/node_modules/chokidar/handler.d.ts +90 -0
- package/lib/node_modules/chokidar/handler.js +635 -0
- package/lib/node_modules/chokidar/index.d.ts +215 -0
- package/lib/node_modules/chokidar/index.js +804 -0
- package/lib/node_modules/chokidar/package.json +69 -0
- package/lib/node_modules/readdirp/LICENSE +21 -0
- package/lib/node_modules/readdirp/README.md +120 -0
- package/lib/node_modules/readdirp/esm/index.d.ts +108 -0
- package/lib/node_modules/readdirp/esm/index.js +257 -0
- package/lib/node_modules/readdirp/esm/package.json +1 -0
- package/lib/node_modules/readdirp/index.d.ts +108 -0
- package/lib/node_modules/readdirp/index.js +263 -0
- package/lib/node_modules/readdirp/package.json +70 -0
- package/lib/package.json +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP per-connection session — speaks the JSON-RPC protocol (initialize,
|
|
4
|
+
* tools/list, tools/call) over a single {@link JsonRpcTransport}. It owns
|
|
5
|
+
* per-client state only (which protocol version the client asked for, whether
|
|
6
|
+
* it advertised `roots`, the one-shot roots/list latch); the heavyweight
|
|
7
|
+
* resources (CodeGraph, watcher, ToolHandler) live in the shared
|
|
8
|
+
* {@link MCPEngine} so daemon mode can collapse N inotify sets / DB handles
|
|
9
|
+
* to one.
|
|
10
|
+
*
|
|
11
|
+
* The state-machine itself mirrors what `MCPServer` used to do inline before
|
|
12
|
+
* issue #411 split it out — the same regression tests in
|
|
13
|
+
* `__tests__/mcp-initialize.test.ts` still drive this code path.
|
|
14
|
+
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.MCPSession = void 0;
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const transport_1 = require("./transport");
|
|
52
|
+
const tools_1 = require("./tools");
|
|
53
|
+
const server_instructions_1 = require("./server-instructions");
|
|
54
|
+
const version_1 = require("./version");
|
|
55
|
+
/**
|
|
56
|
+
* MCP Server Info — kept on the session because some clients log it. The
|
|
57
|
+
* version tracks the real package version (was a hard-coded '0.1.0').
|
|
58
|
+
*/
|
|
59
|
+
const SERVER_INFO = {
|
|
60
|
+
name: 'codegraph',
|
|
61
|
+
version: version_1.CodeGraphPackageVersion,
|
|
62
|
+
};
|
|
63
|
+
/** MCP Protocol Version (latest the server claims). */
|
|
64
|
+
const PROTOCOL_VERSION = '2024-11-05';
|
|
65
|
+
/**
|
|
66
|
+
* How long to wait for the client's `roots/list` response before giving up
|
|
67
|
+
* and falling back to the process cwd.
|
|
68
|
+
*/
|
|
69
|
+
const ROOTS_LIST_TIMEOUT_MS = 5000;
|
|
70
|
+
/**
|
|
71
|
+
* Convert a file:// URI to a filesystem path. Handles URL encoding and
|
|
72
|
+
* Windows drive letter paths.
|
|
73
|
+
*/
|
|
74
|
+
function fileUriToPath(uri) {
|
|
75
|
+
try {
|
|
76
|
+
const url = new URL(uri);
|
|
77
|
+
let filePath = decodeURIComponent(url.pathname);
|
|
78
|
+
if (process.platform === 'win32' && /^\/[a-zA-Z]:/.test(filePath)) {
|
|
79
|
+
filePath = filePath.slice(1);
|
|
80
|
+
}
|
|
81
|
+
return path.resolve(filePath);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return uri.replace(/^file:\/\/\/?/, '');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** First usable filesystem path from a `roots/list` result, or null. */
|
|
88
|
+
function firstRootPath(result) {
|
|
89
|
+
if (!result || typeof result !== 'object')
|
|
90
|
+
return null;
|
|
91
|
+
const roots = result.roots;
|
|
92
|
+
if (!Array.isArray(roots) || roots.length === 0)
|
|
93
|
+
return null;
|
|
94
|
+
const first = roots[0];
|
|
95
|
+
if (typeof first?.uri !== 'string')
|
|
96
|
+
return null;
|
|
97
|
+
return fileUriToPath(first.uri);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* One MCP client's view of the server. Created fresh per stdio launch
|
|
101
|
+
* (direct mode) or per socket connection (daemon mode).
|
|
102
|
+
*/
|
|
103
|
+
class MCPSession {
|
|
104
|
+
transport;
|
|
105
|
+
engine;
|
|
106
|
+
clientSupportsRoots = false;
|
|
107
|
+
rootsAttempted = false;
|
|
108
|
+
resolvePromise = null;
|
|
109
|
+
explicitProjectPath;
|
|
110
|
+
constructor(transport, engine, opts = {}) {
|
|
111
|
+
this.transport = transport;
|
|
112
|
+
this.engine = engine;
|
|
113
|
+
this.explicitProjectPath = opts.explicitProjectPath ?? null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Start handling messages from the transport. Returns immediately — the
|
|
117
|
+
* session lives for as long as the transport is open.
|
|
118
|
+
*/
|
|
119
|
+
start() {
|
|
120
|
+
this.transport.start(this.handleMessage.bind(this));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Tear down the session. Does NOT touch the engine (the engine may serve
|
|
124
|
+
* other sessions) or call `process.exit` (the daemon decides when to exit).
|
|
125
|
+
*/
|
|
126
|
+
stop() {
|
|
127
|
+
this.transport.stop();
|
|
128
|
+
}
|
|
129
|
+
/** Underlying transport — exposed for daemon-side close hooks. */
|
|
130
|
+
getTransport() {
|
|
131
|
+
return this.transport;
|
|
132
|
+
}
|
|
133
|
+
async handleMessage(message) {
|
|
134
|
+
const isRequest = 'id' in message;
|
|
135
|
+
switch (message.method) {
|
|
136
|
+
case 'initialize':
|
|
137
|
+
if (isRequest)
|
|
138
|
+
await this.handleInitialize(message);
|
|
139
|
+
break;
|
|
140
|
+
case 'initialized':
|
|
141
|
+
// Notification that client has finished initialization — no action needed.
|
|
142
|
+
break;
|
|
143
|
+
case 'tools/list':
|
|
144
|
+
if (isRequest)
|
|
145
|
+
await this.handleToolsList(message);
|
|
146
|
+
break;
|
|
147
|
+
case 'tools/call':
|
|
148
|
+
if (isRequest)
|
|
149
|
+
await this.handleToolsCall(message);
|
|
150
|
+
break;
|
|
151
|
+
case 'ping':
|
|
152
|
+
if (isRequest)
|
|
153
|
+
this.transport.sendResult(message.id, {});
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
if (isRequest) {
|
|
157
|
+
this.transport.sendError(message.id, transport_1.ErrorCodes.MethodNotFound, `Method not found: ${message.method}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async handleInitialize(request) {
|
|
162
|
+
const params = request.params;
|
|
163
|
+
this.clientSupportsRoots = !!params?.capabilities?.roots;
|
|
164
|
+
// Explicit project signal, strongest first: client-provided rootUri /
|
|
165
|
+
// workspaceFolders (LSP-style), else the --path the server was launched
|
|
166
|
+
// with. cwd is NOT used here — we defer it so a roots/list answer can
|
|
167
|
+
// win over it. See issue #196.
|
|
168
|
+
let explicitPath = null;
|
|
169
|
+
if (params?.rootUri) {
|
|
170
|
+
explicitPath = fileUriToPath(params.rootUri);
|
|
171
|
+
}
|
|
172
|
+
else if (params?.workspaceFolders?.[0]?.uri) {
|
|
173
|
+
explicitPath = fileUriToPath(params.workspaceFolders[0].uri);
|
|
174
|
+
}
|
|
175
|
+
else if (this.explicitProjectPath) {
|
|
176
|
+
explicitPath = this.explicitProjectPath;
|
|
177
|
+
}
|
|
178
|
+
// Respond to the handshake BEFORE doing any heavy init — see issue #172.
|
|
179
|
+
this.transport.sendResult(request.id, {
|
|
180
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
181
|
+
capabilities: { tools: {} },
|
|
182
|
+
serverInfo: SERVER_INFO,
|
|
183
|
+
instructions: server_instructions_1.SERVER_INSTRUCTIONS,
|
|
184
|
+
});
|
|
185
|
+
if (explicitPath) {
|
|
186
|
+
// Kick off engine init in the background. If another session in the
|
|
187
|
+
// same daemon already opened the project, `ensureInitialized` is a
|
|
188
|
+
// ~free no-op — N concurrent clients pay exactly one open.
|
|
189
|
+
this.resolvePromise = this.engine.ensureInitialized(explicitPath);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async handleToolsList(request) {
|
|
193
|
+
await this.retryInitIfNeeded();
|
|
194
|
+
this.transport.sendResult(request.id, {
|
|
195
|
+
tools: this.engine.getToolHandler().getTools(),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async handleToolsCall(request) {
|
|
199
|
+
const params = request.params;
|
|
200
|
+
if (!params || !params.name) {
|
|
201
|
+
this.transport.sendError(request.id, transport_1.ErrorCodes.InvalidParams, 'Missing tool name');
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const toolName = params.name;
|
|
205
|
+
const toolArgs = params.arguments || {};
|
|
206
|
+
const tool = tools_1.tools.find((t) => t.name === toolName);
|
|
207
|
+
if (!tool) {
|
|
208
|
+
this.transport.sendError(request.id, transport_1.ErrorCodes.InvalidParams, `Unknown tool: ${toolName}`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
await this.retryInitIfNeeded();
|
|
212
|
+
const result = await this.engine.getToolHandler().execute(toolName, toolArgs);
|
|
213
|
+
this.transport.sendResult(request.id, result);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Lazy default-project resolution. Three layers:
|
|
217
|
+
* 1. await the in-flight init kicked off from `handleInitialize` (if any);
|
|
218
|
+
* 2. if still uninitialized and we never asked the client for its roots,
|
|
219
|
+
* do so now (one-shot); fall back to cwd if the client lacks roots;
|
|
220
|
+
* 3. last-resort: re-walk from the best candidate — picks up projects
|
|
221
|
+
* that were `codegraph init`'d *after* the server started.
|
|
222
|
+
*/
|
|
223
|
+
async retryInitIfNeeded() {
|
|
224
|
+
if (this.resolvePromise) {
|
|
225
|
+
try {
|
|
226
|
+
await this.resolvePromise;
|
|
227
|
+
}
|
|
228
|
+
catch { /* fall through to retry */ }
|
|
229
|
+
this.resolvePromise = null;
|
|
230
|
+
}
|
|
231
|
+
if (this.engine.hasDefaultCodeGraph())
|
|
232
|
+
return;
|
|
233
|
+
const hint = this.explicitProjectPath ?? this.engine.getProjectPath();
|
|
234
|
+
if (!hint && !this.rootsAttempted) {
|
|
235
|
+
this.rootsAttempted = true;
|
|
236
|
+
this.resolvePromise = this.clientSupportsRoots
|
|
237
|
+
? this.initFromRoots()
|
|
238
|
+
: this.engine.ensureInitialized(process.cwd());
|
|
239
|
+
try {
|
|
240
|
+
await this.resolvePromise;
|
|
241
|
+
}
|
|
242
|
+
catch { /* fall through */ }
|
|
243
|
+
this.resolvePromise = null;
|
|
244
|
+
if (this.engine.hasDefaultCodeGraph())
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
// Last resort: walk from the best candidate (sync open). Picks up
|
|
248
|
+
// projects that appeared after the server started.
|
|
249
|
+
const candidate = hint ?? process.cwd();
|
|
250
|
+
this.engine.retryInitializeSync(candidate);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Ask the client for its workspace root via `roots/list` and open the
|
|
254
|
+
* first one. Falls back to `process.cwd()` on timeout or empty answer.
|
|
255
|
+
*/
|
|
256
|
+
async initFromRoots() {
|
|
257
|
+
let target = process.cwd();
|
|
258
|
+
try {
|
|
259
|
+
const result = await this.transport.request('roots/list', undefined, ROOTS_LIST_TIMEOUT_MS);
|
|
260
|
+
const rootPath = firstRootPath(result);
|
|
261
|
+
if (rootPath) {
|
|
262
|
+
target = rootPath;
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
process.stderr.write('[CodeGraph MCP] Client returned no workspace roots; falling back to process cwd.\n');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
270
|
+
process.stderr.write(`[CodeGraph MCP] roots/list request failed (${msg}); falling back to process cwd.\n`);
|
|
271
|
+
}
|
|
272
|
+
await this.engine.ensureInitialized(target);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.MCPSession = MCPSession;
|
|
276
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/mcp/session.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2CAA6B;AAC7B,2CAAgG;AAEhG,mCAAgC;AAChC,+DAA4D;AAC5D,uCAAoD;AAEpD;;;GAGG;AACH,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,iCAAuB;CACjC,CAAC;AAEF,uDAAuD;AACvD,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC;;;GAGG;AACH,SAAS,aAAa,CAAC,GAAW;IAChC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,QAAQ,GAAG,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClE,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED,wEAAwE;AACxE,SAAS,aAAa,CAAC,MAAe;IACpC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACvD,MAAM,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|
6
6
|
import CodeGraph from '../index';
|
|
7
|
+
import type { PendingFile } from '../sync';
|
|
7
8
|
/**
|
|
8
9
|
* Calculate the recommended number of codegraph_explore calls based on project size.
|
|
9
10
|
* Larger codebases need more exploration calls to cover their surface area,
|
|
@@ -51,6 +52,19 @@ export interface ExploreOutputBudget {
|
|
|
51
52
|
includeBudgetNote: boolean;
|
|
52
53
|
}
|
|
53
54
|
export declare function getExploreOutputBudget(fileCount: number): ExploreOutputBudget;
|
|
55
|
+
/**
|
|
56
|
+
* Per-file staleness banner emitted at the top of a tool response when the
|
|
57
|
+
* file watcher has pending events for files referenced by the response.
|
|
58
|
+
* The agent uses this to fall back to Read for those specific files
|
|
59
|
+
* without waiting for the debounced sync (issue #403).
|
|
60
|
+
*/
|
|
61
|
+
export declare function formatStaleBanner(stale: PendingFile[]): string;
|
|
62
|
+
/**
|
|
63
|
+
* Compact footer listing pending files that are NOT referenced in this
|
|
64
|
+
* response. Gives the agent a complete project-wide freshness picture
|
|
65
|
+
* without bloating the main banner.
|
|
66
|
+
*/
|
|
67
|
+
export declare function formatStaleFooter(stale: PendingFile[]): string;
|
|
54
68
|
/**
|
|
55
69
|
* MCP Tool definition
|
|
56
70
|
*/
|
|
@@ -98,6 +112,7 @@ export declare class ToolHandler {
|
|
|
98
112
|
private cg;
|
|
99
113
|
private projectCache;
|
|
100
114
|
private defaultProjectHint;
|
|
115
|
+
private worktreeMismatchCache;
|
|
101
116
|
constructor(cg: CodeGraph | null);
|
|
102
117
|
/**
|
|
103
118
|
* Update the default CodeGraph instance (e.g. after lazy initialization)
|
|
@@ -112,10 +127,22 @@ export declare class ToolHandler {
|
|
|
112
127
|
* Whether a default CodeGraph instance is available
|
|
113
128
|
*/
|
|
114
129
|
hasDefaultCodeGraph(): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Optional allowlist of exposed tools, parsed from the CODEGRAPH_MCP_TOOLS
|
|
132
|
+
* env var (comma-separated short names, e.g. "trace,search,node,context").
|
|
133
|
+
* Unset/empty → every tool is exposed. Lets an operator (or an A/B harness)
|
|
134
|
+
* trim the tool surface without rebuilding the client config; the ablated
|
|
135
|
+
* tool is then truly absent from ListTools rather than merely denied on call.
|
|
136
|
+
* Matching is on the short form, so "trace" and "codegraph_trace" both work.
|
|
137
|
+
*/
|
|
138
|
+
private toolAllowlist;
|
|
139
|
+
/** Whether a tool name passes the CODEGRAPH_MCP_TOOLS allowlist (if any). */
|
|
140
|
+
private isToolAllowed;
|
|
115
141
|
/**
|
|
116
142
|
* Get tool definitions with dynamic descriptions based on project size.
|
|
117
143
|
* The codegraph_explore tool description includes a budget recommendation
|
|
118
|
-
* scaled to the number of indexed files.
|
|
144
|
+
* scaled to the number of indexed files. Honors the CODEGRAPH_MCP_TOOLS
|
|
145
|
+
* allowlist so a trimmed surface is reflected in ListTools.
|
|
119
146
|
*/
|
|
120
147
|
getTools(): ToolDefinition[];
|
|
121
148
|
/**
|
|
@@ -133,9 +160,53 @@ export declare class ToolHandler {
|
|
|
133
160
|
*/
|
|
134
161
|
closeAll(): void;
|
|
135
162
|
/**
|
|
136
|
-
* Validate that a value is a non-empty string
|
|
163
|
+
* Validate that a value is a non-empty string within length bounds.
|
|
164
|
+
*
|
|
165
|
+
* The `maxLength` cap protects against MCP clients that ship huge
|
|
166
|
+
* payloads (10MB+ query strings either by accident or maliciously).
|
|
167
|
+
* Without this, a single oversized input can pin the FTS5 index or
|
|
168
|
+
* exhaust memory before any real work runs.
|
|
137
169
|
*/
|
|
138
170
|
private validateString;
|
|
171
|
+
/**
|
|
172
|
+
* Validate an optional path-like string input. Returns the value if
|
|
173
|
+
* valid (or undefined), or a ToolResult with the error.
|
|
174
|
+
*/
|
|
175
|
+
private validateOptionalPath;
|
|
176
|
+
/**
|
|
177
|
+
* Cached git worktree/index mismatch for a tool call's effective project.
|
|
178
|
+
*
|
|
179
|
+
* The "effective project" is what the request targets: an explicit
|
|
180
|
+
* `projectPath` arg, else the directory the server resolved its default
|
|
181
|
+
* project from (`defaultProjectHint`), else cwd. Memoized per start path —
|
|
182
|
+
* see `worktreeMismatchCache`. Best-effort: if the project can't be resolved
|
|
183
|
+
* (e.g. nothing initialized yet), it reports "no mismatch" so a tool is never
|
|
184
|
+
* broken by this check.
|
|
185
|
+
*/
|
|
186
|
+
private worktreeMismatchFor;
|
|
187
|
+
/**
|
|
188
|
+
* Prefix a successful read-tool result with a compact worktree-mismatch
|
|
189
|
+
* notice when the resolved index belongs to a different git working tree than
|
|
190
|
+
* the caller's (issue #155). Without this, an agent in a nested worktree
|
|
191
|
+
* silently trusts main-branch results. No-op on error results and when there
|
|
192
|
+
* is no mismatch. `codegraph_status` is excluded — it embeds its own verbose
|
|
193
|
+
* warning — so it stays out of this path.
|
|
194
|
+
*/
|
|
195
|
+
private withWorktreeNotice;
|
|
196
|
+
/**
|
|
197
|
+
* Annotate a successful read-tool result with per-file staleness — the
|
|
198
|
+
* non-blocking answer to issue #403. The file watcher tracks every event
|
|
199
|
+
* it sees per path; here we intersect "files referenced in this response"
|
|
200
|
+
* against that pending set and prepend a compact banner so the agent can
|
|
201
|
+
* fall back to Read for those *specific* files without waiting for the
|
|
202
|
+
* debounced sync to fire. Other pending files in the project (not
|
|
203
|
+
* referenced by this response) get a small footer so the agent has a
|
|
204
|
+
* complete picture without bloating the banner.
|
|
205
|
+
*
|
|
206
|
+
* Cost when nothing is pending — the common case — is one boolean check.
|
|
207
|
+
* No I/O, no parsing of markdown beyond a per-pending-file substring scan.
|
|
208
|
+
*/
|
|
209
|
+
private withStalenessNotice;
|
|
139
210
|
/**
|
|
140
211
|
* Execute a tool by name
|
|
141
212
|
*/
|
|
@@ -164,6 +235,53 @@ export declare class ToolHandler {
|
|
|
164
235
|
* Handle codegraph_impact
|
|
165
236
|
*/
|
|
166
237
|
private handleImpact;
|
|
238
|
+
/**
|
|
239
|
+
* Handle codegraph_trace — shortest CALL PATH between two symbols.
|
|
240
|
+
*
|
|
241
|
+
* Exposes GraphTraverser.findPath: the chain of functions from `from` to `to`,
|
|
242
|
+
* each hop annotated with file:line and the call-site line. This is the
|
|
243
|
+
* capability grep/Read structurally cannot provide. When no static path
|
|
244
|
+
* exists, the chain has almost certainly broken at dynamic dispatch
|
|
245
|
+
* (callbacks, descriptors, metaclasses) — we say so and surface the start
|
|
246
|
+
* symbol's outgoing calls so the agent bridges the one missing hop with
|
|
247
|
+
* codegraph_node rather than blindly reading.
|
|
248
|
+
*/
|
|
249
|
+
private handleTrace;
|
|
250
|
+
/**
|
|
251
|
+
* Describe a synthesized (dynamic-dispatch) edge for human output: how the
|
|
252
|
+
* callback was wired up — the bridge static parsing can't see. Returns null
|
|
253
|
+
* for ordinary static edges. Used by trace + the node trail so a synthesized
|
|
254
|
+
* hop reads as "registered via onUpdate at App.tsx:3148", not a bare arrow.
|
|
255
|
+
*/
|
|
256
|
+
private synthEdgeNote;
|
|
257
|
+
/**
|
|
258
|
+
* Read one trimmed source line at "relpath:line" (relative to the project
|
|
259
|
+
* root). `cache` holds split file contents so a multi-hop trace reads each
|
|
260
|
+
* file at most once. Returns null if the file/line can't be resolved.
|
|
261
|
+
*/
|
|
262
|
+
private sourceLineAt;
|
|
263
|
+
/**
|
|
264
|
+
* Read a hop's body — filePath lines [startLine..endLine] — for inlining into
|
|
265
|
+
* a trace, capped (lines + chars) so the whole path stays path-scoped even on
|
|
266
|
+
* a 7-hop chain. Dedents to the body's own indentation and marks truncation.
|
|
267
|
+
* Shares `cache` with sourceLineAt so each file is read at most once per trace.
|
|
268
|
+
*/
|
|
269
|
+
private sourceRangeAt;
|
|
270
|
+
/**
|
|
271
|
+
* Flow-from-named-symbols: an agent's codegraph_explore query is a bag of
|
|
272
|
+
* symbol names that usually spans the flow it's investigating (e.g.
|
|
273
|
+
* "PmsProductController getList PmsProductService list PmsProductServiceImpl").
|
|
274
|
+
* Surface the longest call chain AMONG those named symbols — scoped to what the
|
|
275
|
+
* agent explicitly named, so (unlike a fuzzy relevance set) there's no
|
|
276
|
+
* wrong-feature wandering. Rides synthesized edges, so controller→service-
|
|
277
|
+
* interface→impl shows up. Returns '' if no chain of >=3 nodes exists.
|
|
278
|
+
*
|
|
279
|
+
* Ambiguous tokens (Java `list` → dozens of nodes) are disambiguated by
|
|
280
|
+
* CO-NAMING: the agent names the class too, so we keep only `list` candidates
|
|
281
|
+
* whose qualifiedName contains another named token (`PmsProductServiceImpl::list`),
|
|
282
|
+
* dropping unrelated `OmsOrderService::list`.
|
|
283
|
+
*/
|
|
284
|
+
private buildFlowFromNamedSymbols;
|
|
167
285
|
/**
|
|
168
286
|
* Handle codegraph_explore — deep exploration in a single call
|
|
169
287
|
*
|
|
@@ -180,6 +298,16 @@ export declare class ToolHandler {
|
|
|
180
298
|
* Handle codegraph_node
|
|
181
299
|
*/
|
|
182
300
|
private handleNode;
|
|
301
|
+
/**
|
|
302
|
+
* Build the "trail" for a symbol: its direct callees (what it calls) and
|
|
303
|
+
* callers (what calls it), each with file:line — so codegraph_node doubles as
|
|
304
|
+
* the structural Grep→Read→expand primitive: a spot PLUS where to go next.
|
|
305
|
+
* Capped to stay cheap. Walk the graph by calling codegraph_node on a trail
|
|
306
|
+
* entry; no Read needed for covered hops. Empty edges on a non-leaf often mean
|
|
307
|
+
* dynamic dispatch the static graph couldn't resolve — that absence is itself
|
|
308
|
+
* a signal (read that one hop) rather than a dead end.
|
|
309
|
+
*/
|
|
310
|
+
private formatTrail;
|
|
183
311
|
/**
|
|
184
312
|
* Handle codegraph_status
|
|
185
313
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,SAAuC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,SAAuC,MAAM,UAAU,CAAC;AAO/D,OAAO,KAAK,EAAE,WAAW,EAAE,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