@stupidloud/codegraph 0.7.15 → 0.8.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.
Files changed (147) hide show
  1. package/README.md +82 -58
  2. package/dist/bin/codegraph.js +127 -24
  3. package/dist/bin/codegraph.js.map +1 -1
  4. package/dist/bin/node-version-check.d.ts +3 -0
  5. package/dist/bin/node-version-check.d.ts.map +1 -1
  6. package/dist/bin/node-version-check.js +5 -2
  7. package/dist/bin/node-version-check.js.map +1 -1
  8. package/dist/bin/uninstall.d.ts +7 -7
  9. package/dist/bin/uninstall.d.ts.map +1 -1
  10. package/dist/bin/uninstall.js +23 -135
  11. package/dist/bin/uninstall.js.map +1 -1
  12. package/dist/context/index.d.ts.map +1 -1
  13. package/dist/context/index.js +4 -2
  14. package/dist/context/index.js.map +1 -1
  15. package/dist/db/queries.d.ts.map +1 -1
  16. package/dist/db/queries.js +7 -1
  17. package/dist/db/queries.js.map +1 -1
  18. package/dist/extraction/index.d.ts +1 -1
  19. package/dist/extraction/index.d.ts.map +1 -1
  20. package/dist/extraction/index.js +63 -37
  21. package/dist/extraction/index.js.map +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +3 -2
  24. package/dist/index.js.map +1 -1
  25. package/dist/installer/claude-md-template.d.ts +10 -6
  26. package/dist/installer/claude-md-template.d.ts.map +1 -1
  27. package/dist/installer/claude-md-template.js +15 -40
  28. package/dist/installer/claude-md-template.js.map +1 -1
  29. package/dist/installer/config-writer.d.ts +17 -24
  30. package/dist/installer/config-writer.d.ts.map +1 -1
  31. package/dist/installer/config-writer.js +46 -239
  32. package/dist/installer/config-writer.js.map +1 -1
  33. package/dist/installer/index.d.ts +57 -4
  34. package/dist/installer/index.d.ts.map +1 -1
  35. package/dist/installer/index.js +286 -81
  36. package/dist/installer/index.js.map +1 -1
  37. package/dist/installer/instructions-template.d.ts +28 -0
  38. package/dist/installer/instructions-template.d.ts.map +1 -0
  39. package/dist/installer/instructions-template.js +65 -0
  40. package/dist/installer/instructions-template.js.map +1 -0
  41. package/dist/installer/targets/claude.d.ts +31 -0
  42. package/dist/installer/targets/claude.d.ts.map +1 -0
  43. package/dist/installer/targets/claude.js +308 -0
  44. package/dist/installer/targets/claude.js.map +1 -0
  45. package/dist/installer/targets/codex.d.ts +18 -0
  46. package/dist/installer/targets/codex.d.ts.map +1 -0
  47. package/dist/installer/targets/codex.js +185 -0
  48. package/dist/installer/targets/codex.js.map +1 -0
  49. package/dist/installer/targets/cursor.d.ts +35 -0
  50. package/dist/installer/targets/cursor.d.ts.map +1 -0
  51. package/dist/installer/targets/cursor.js +229 -0
  52. package/dist/installer/targets/cursor.js.map +1 -0
  53. package/dist/installer/targets/opencode.d.ts +30 -0
  54. package/dist/installer/targets/opencode.d.ts.map +1 -0
  55. package/dist/installer/targets/opencode.js +235 -0
  56. package/dist/installer/targets/opencode.js.map +1 -0
  57. package/dist/installer/targets/registry.d.ts +35 -0
  58. package/dist/installer/targets/registry.d.ts.map +1 -0
  59. package/dist/installer/targets/registry.js +83 -0
  60. package/dist/installer/targets/registry.js.map +1 -0
  61. package/dist/installer/targets/shared.d.ts +77 -0
  62. package/dist/installer/targets/shared.d.ts.map +1 -0
  63. package/dist/installer/targets/shared.js +246 -0
  64. package/dist/installer/targets/shared.js.map +1 -0
  65. package/dist/installer/targets/toml.d.ts +52 -0
  66. package/dist/installer/targets/toml.d.ts.map +1 -0
  67. package/dist/installer/targets/toml.js +147 -0
  68. package/dist/installer/targets/toml.js.map +1 -0
  69. package/dist/installer/targets/types.d.ts +116 -0
  70. package/dist/installer/targets/types.d.ts.map +1 -0
  71. package/dist/installer/targets/types.js +16 -0
  72. package/dist/installer/targets/types.js.map +1 -0
  73. package/dist/mcp/index.d.ts +12 -0
  74. package/dist/mcp/index.d.ts.map +1 -1
  75. package/dist/mcp/index.js +143 -20
  76. package/dist/mcp/index.js.map +1 -1
  77. package/dist/mcp/server-instructions.d.ts +1 -1
  78. package/dist/mcp/server-instructions.d.ts.map +1 -1
  79. package/dist/mcp/server-instructions.js +20 -5
  80. package/dist/mcp/server-instructions.js.map +1 -1
  81. package/dist/mcp/tools.d.ts +75 -5
  82. package/dist/mcp/tools.d.ts.map +1 -1
  83. package/dist/mcp/tools.js +472 -89
  84. package/dist/mcp/tools.js.map +1 -1
  85. package/dist/mcp/transport.d.ts +17 -0
  86. package/dist/mcp/transport.d.ts.map +1 -1
  87. package/dist/mcp/transport.js +63 -0
  88. package/dist/mcp/transport.js.map +1 -1
  89. package/dist/resolution/frameworks/index.d.ts +1 -0
  90. package/dist/resolution/frameworks/index.d.ts.map +1 -1
  91. package/dist/resolution/frameworks/index.js +5 -1
  92. package/dist/resolution/frameworks/index.js.map +1 -1
  93. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  94. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  95. package/dist/resolution/frameworks/nestjs.js +374 -0
  96. package/dist/resolution/frameworks/nestjs.js.map +1 -0
  97. package/dist/search/query-utils.d.ts.map +1 -1
  98. package/dist/search/query-utils.js +29 -26
  99. package/dist/search/query-utils.js.map +1 -1
  100. package/dist/sync/git-hooks.d.ts +45 -0
  101. package/dist/sync/git-hooks.d.ts.map +1 -0
  102. package/dist/sync/git-hooks.js +223 -0
  103. package/dist/sync/git-hooks.js.map +1 -0
  104. package/dist/sync/index.d.ts +4 -0
  105. package/dist/sync/index.d.ts.map +1 -1
  106. package/dist/sync/index.js +12 -1
  107. package/dist/sync/index.js.map +1 -1
  108. package/dist/sync/watch-policy.d.ts +48 -0
  109. package/dist/sync/watch-policy.d.ts.map +1 -0
  110. package/dist/sync/watch-policy.js +124 -0
  111. package/dist/sync/watch-policy.js.map +1 -0
  112. package/dist/sync/watcher.d.ts.map +1 -1
  113. package/dist/sync/watcher.js +10 -0
  114. package/dist/sync/watcher.js.map +1 -1
  115. package/dist/ui/glyphs.d.ts +42 -0
  116. package/dist/ui/glyphs.d.ts.map +1 -0
  117. package/dist/ui/glyphs.js +78 -0
  118. package/dist/ui/glyphs.js.map +1 -0
  119. package/dist/ui/shimmer-progress.d.ts +1 -0
  120. package/dist/ui/shimmer-progress.d.ts.map +1 -1
  121. package/dist/ui/shimmer-progress.js +7 -0
  122. package/dist/ui/shimmer-progress.js.map +1 -1
  123. package/dist/ui/shimmer-worker.js +20 -11
  124. package/dist/ui/shimmer-worker.js.map +1 -1
  125. package/dist/ui/types.d.ts +1 -0
  126. package/dist/ui/types.d.ts.map +1 -1
  127. package/dist/vectors/embedder.d.ts +11 -1
  128. package/dist/vectors/embedder.d.ts.map +1 -1
  129. package/dist/vectors/embedder.js +48 -18
  130. package/dist/vectors/embedder.js.map +1 -1
  131. package/dist/vectors/index.d.ts +1 -1
  132. package/dist/vectors/index.d.ts.map +1 -1
  133. package/dist/vectors/index.js.map +1 -1
  134. package/dist/vectors/manager.d.ts +5 -0
  135. package/dist/vectors/manager.d.ts.map +1 -1
  136. package/dist/vectors/manager.js +44 -23
  137. package/dist/vectors/manager.js.map +1 -1
  138. package/package.json +4 -3
  139. package/scripts/agent-eval/audit.sh +68 -0
  140. package/scripts/agent-eval/itrun.sh +107 -0
  141. package/scripts/agent-eval/parse-run.mjs +45 -0
  142. package/scripts/agent-eval/parse-session.mjs +93 -0
  143. package/scripts/agent-eval/run-agent.sh +34 -0
  144. package/scripts/agent-eval/run-all.sh +67 -0
  145. package/scripts/extract-release-notes.mjs +130 -0
  146. package/scripts/local-install.sh +41 -0
  147. package/scripts/release.sh +68 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/installer/targets/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE1C;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAElE;;;;;;;;;;;;GAYG;AACH,MA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+ * Agent target abstraction for the installer.
4
+ *
5
+ * Each MCP-capable agent (Claude Code, Cursor, Codex CLI, opencode, ...)
6
+ * implements this interface so the installer orchestrator can write the
7
+ * right MCP-server config + instructions file + permissions for that
8
+ * agent without baking client-specific paths into core code. Adding a
9
+ * new agent = one new file in `targets/` + one entry in `registry.ts`.
10
+ *
11
+ * Closes the Claude-locked installer issue (upstream #137). The
12
+ * runtime MCP server is already agent-agnostic; this brings the
13
+ * installer to the same surface.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/installer/targets/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG"}
@@ -25,6 +25,9 @@ export declare class MCPServer {
25
25
  private cg;
26
26
  private toolHandler;
27
27
  private projectPath;
28
+ private initPromise;
29
+ private clientSupportsRoots;
30
+ private rootsAttempted;
28
31
  constructor(projectPath?: string);
29
32
  /**
30
33
  * Start the MCP server
@@ -49,8 +52,17 @@ export declare class MCPServer {
49
52
  * Called lazily on tool calls that need the default project.
50
53
  * Re-walks parent directories each time so it picks up projects
51
54
  * initialized after the MCP server started.
55
+ *
56
+ * Awaits any in-flight background init (kicked off by handleInitialize) so
57
+ * we never open the SQLite file twice concurrently.
52
58
  */
53
59
  private retryInitIfNeeded;
60
+ /**
61
+ * Resolve the project root via the MCP `roots/list` request and initialize
62
+ * from the first root the client reports. Falls back to the process cwd if
63
+ * the client returns no usable root or doesn't answer in time. See issue #196.
64
+ */
65
+ private initFromRoots;
54
66
  /**
55
67
  * Start file watching on the active CodeGraph instance.
56
68
  * Logs sync activity to stderr for diagnostics.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAwCH;;;;;GAKG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,SA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A6C3B;;OAEG;YACW,gBAAgB;IA6D9B;;OAEG;YACW,eAAe;IAO7B;;OAEG;YACW,eAAe;CAqC9B;AAGD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
package/dist/mcp/index.js CHANGED
@@ -52,6 +52,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
52
52
  exports.ToolHandler = exports.tools = exports.StdioTransport = exports.MCPServer = void 0;
53
53
  const path = __importStar(require("path"));
54
54
  const index_1 = __importStar(require("../index"));
55
+ const sync_1 = require("../sync");
55
56
  const transport_1 = require("./transport");
56
57
  const tools_1 = require("./tools");
57
58
  const server_instructions_1 = require("./server-instructions");
@@ -85,6 +86,27 @@ const SERVER_INFO = {
85
86
  * MCP Protocol Version
86
87
  */
87
88
  const PROTOCOL_VERSION = '2024-11-05';
89
+ /**
90
+ * How long to wait for the client's `roots/list` response before giving up
91
+ * and falling back to the process cwd.
92
+ */
93
+ const ROOTS_LIST_TIMEOUT_MS = 5000;
94
+ /**
95
+ * Extract the first usable filesystem path from a `roots/list` result.
96
+ * Shape per MCP spec: `{ roots: [{ uri: "file:///path", name?: string }] }`.
97
+ * Returns null if the result is empty or malformed.
98
+ */
99
+ function firstRootPath(result) {
100
+ if (!result || typeof result !== 'object')
101
+ return null;
102
+ const roots = result.roots;
103
+ if (!Array.isArray(roots) || roots.length === 0)
104
+ return null;
105
+ const first = roots[0];
106
+ if (typeof first?.uri !== 'string')
107
+ return null;
108
+ return fileUriToPath(first.uri);
109
+ }
88
110
  /**
89
111
  * MCP Server for CodeGraph
90
112
  *
@@ -96,6 +118,16 @@ class MCPServer {
96
118
  cg = null;
97
119
  toolHandler;
98
120
  projectPath;
121
+ // In-flight background init kicked off from handleInitialize. Tracked so the
122
+ // sync retry path doesn't race against it (double-opening the SQLite file).
123
+ initPromise = null;
124
+ // Whether the client advertised the MCP `roots` capability during initialize.
125
+ // If so, and no explicit project path was given, we ask it for the workspace
126
+ // root via roots/list rather than guessing from the (often wrong) cwd.
127
+ clientSupportsRoots = false;
128
+ // Guards the one-shot deferred resolution (roots/list or cwd) so we don't
129
+ // re-issue roots/list on every tool call.
130
+ rootsAttempted = false;
99
131
  constructor(projectPath) {
100
132
  this.projectPath = projectPath || null;
101
133
  this.transport = new transport_1.StdioTransport();
@@ -131,6 +163,8 @@ class MCPServer {
131
163
  * are still possible.
132
164
  */
133
165
  async tryInitializeDefault(projectPath) {
166
+ // Record where we searched so a later "not initialized" error can name it.
167
+ this.toolHandler.setDefaultProjectHint(projectPath);
134
168
  // Walk up parent directories to find nearest .codegraph/
135
169
  const resolvedRoot = (0, index_1.findNearestCodeGraphRoot)(projectPath);
136
170
  if (!resolvedRoot) {
@@ -154,15 +188,43 @@ class MCPServer {
154
188
  * Called lazily on tool calls that need the default project.
155
189
  * Re-walks parent directories each time so it picks up projects
156
190
  * initialized after the MCP server started.
191
+ *
192
+ * Awaits any in-flight background init (kicked off by handleInitialize) so
193
+ * we never open the SQLite file twice concurrently.
157
194
  */
158
- retryInitIfNeeded() {
195
+ async retryInitIfNeeded() {
196
+ // Wait for the background init started during handleInitialize, if any.
197
+ if (this.initPromise) {
198
+ try {
199
+ await this.initPromise;
200
+ }
201
+ catch { /* errored init falls through to retry */ }
202
+ }
159
203
  // Already initialized successfully
160
204
  if (this.toolHandler.hasDefaultCodeGraph())
161
205
  return;
162
- // No project path to retry with
163
- if (!this.projectPath)
164
- return;
165
- const resolvedRoot = (0, index_1.findNearestCodeGraphRoot)(this.projectPath);
206
+ // No explicit path was given at initialize. Resolve it now, exactly once:
207
+ // ask the client via roots/list (if it advertised roots), else use cwd.
208
+ // Deferring to here lets a roots answer override the wrong cwd, and the
209
+ // one-shot guard means we never re-issue roots/list per tool call.
210
+ if (!this.projectPath && !this.rootsAttempted) {
211
+ this.rootsAttempted = true;
212
+ this.initPromise = (this.clientSupportsRoots
213
+ ? this.initFromRoots()
214
+ : this.tryInitializeDefault(process.cwd())).finally(() => { this.initPromise = null; });
215
+ try {
216
+ await this.initPromise;
217
+ }
218
+ catch { /* fall through to last-resort below */ }
219
+ if (this.toolHandler.hasDefaultCodeGraph())
220
+ return;
221
+ }
222
+ // Last resort: re-walk from the best candidate we have. Picks up projects
223
+ // initialized after the server started, and covers clients that sent no
224
+ // usable initialize signal at all.
225
+ const candidate = this.projectPath ?? process.cwd();
226
+ this.toolHandler.setDefaultProjectHint(candidate);
227
+ const resolvedRoot = (0, index_1.findNearestCodeGraphRoot)(candidate);
166
228
  if (!resolvedRoot)
167
229
  return;
168
230
  try {
@@ -183,6 +245,29 @@ class MCPServer {
183
245
  // Still failing — will retry on next tool call
184
246
  }
185
247
  }
248
+ /**
249
+ * Resolve the project root via the MCP `roots/list` request and initialize
250
+ * from the first root the client reports. Falls back to the process cwd if
251
+ * the client returns no usable root or doesn't answer in time. See issue #196.
252
+ */
253
+ async initFromRoots() {
254
+ let target = process.cwd();
255
+ try {
256
+ const result = await this.transport.request('roots/list', undefined, ROOTS_LIST_TIMEOUT_MS);
257
+ const rootPath = firstRootPath(result);
258
+ if (rootPath) {
259
+ target = rootPath;
260
+ }
261
+ else {
262
+ process.stderr.write('[CodeGraph MCP] Client returned no workspace roots; falling back to process cwd.\n');
263
+ }
264
+ }
265
+ catch (err) {
266
+ const msg = err instanceof Error ? err.message : String(err);
267
+ process.stderr.write(`[CodeGraph MCP] roots/list request failed (${msg}); falling back to process cwd.\n`);
268
+ }
269
+ await this.tryInitializeDefault(target);
270
+ }
186
271
  /**
187
272
  * Start file watching on the active CodeGraph instance.
188
273
  * Logs sync activity to stderr for diagnostics.
@@ -190,6 +275,15 @@ class MCPServer {
190
275
  startWatching() {
191
276
  if (!this.cg)
192
277
  return;
278
+ // When the watcher is intentionally disabled (e.g. WSL2 /mnt drives, or
279
+ // CODEGRAPH_NO_WATCH=1), say so explicitly and tell the user how to keep
280
+ // the graph fresh — otherwise the silent staleness is hard to diagnose.
281
+ const disabledReason = (0, sync_1.watchDisabledReason)(this.projectPath ?? process.cwd());
282
+ if (disabledReason) {
283
+ process.stderr.write(`[CodeGraph MCP] File watcher disabled — ${disabledReason}. ` +
284
+ `The graph will not auto-update; run \`codegraph sync\` (or install the git sync hooks via \`codegraph init\`) to refresh.\n`);
285
+ return;
286
+ }
193
287
  const started = this.cg.watch({
194
288
  onSyncComplete: (result) => {
195
289
  if (result.filesChanged > 0) {
@@ -203,6 +297,10 @@ class MCPServer {
203
297
  if (started) {
204
298
  process.stderr.write('[CodeGraph MCP] File watcher active — graph will auto-sync on changes\n');
205
299
  }
300
+ else {
301
+ // start() can also return false when recursive fs.watch isn't supported.
302
+ process.stderr.write('[CodeGraph MCP] File watcher unavailable on this platform — run `codegraph sync` to refresh the graph after changes.\n');
303
+ }
206
304
  }
207
305
  /**
208
306
  * Stop the server
@@ -260,24 +358,35 @@ class MCPServer {
260
358
  */
261
359
  async handleInitialize(request) {
262
360
  const params = request.params;
263
- // Extract project path from rootUri or workspaceFolders
264
- let projectPath = this.projectPath;
361
+ // Does the client support the MCP `roots` protocol? If so, and we have no
362
+ // explicit path, we ask it for the workspace root after the handshake
363
+ // instead of falling back to the (frequently wrong) cwd. See issue #196.
364
+ this.clientSupportsRoots = !!params?.capabilities?.roots;
365
+ // Explicit project signal, strongest first: a client-provided rootUri /
366
+ // workspaceFolders (LSP-style, non-standard but some clients send it), else
367
+ // the --path the server was launched with. cwd is NOT used here — we defer
368
+ // it so a roots/list answer can win over it.
369
+ let explicitPath = null;
265
370
  if (params?.rootUri) {
266
- projectPath = fileUriToPath(params.rootUri);
371
+ explicitPath = fileUriToPath(params.rootUri);
267
372
  }
268
373
  else if (params?.workspaceFolders?.[0]?.uri) {
269
- projectPath = fileUriToPath(params.workspaceFolders[0].uri);
374
+ explicitPath = fileUriToPath(params.workspaceFolders[0].uri);
270
375
  }
271
- // Fall back to current working directory if no path provided
272
- if (!projectPath) {
273
- projectPath = process.cwd();
376
+ else if (this.projectPath) {
377
+ explicitPath = this.projectPath;
274
378
  }
275
- // Try to initialize the default project (non-fatal if it fails)
276
- await this.tryInitializeDefault(projectPath);
277
- // We accept the client's protocol version but respond with our supported version.
278
- // The `instructions` field is surfaced by MCP clients in the agent's system
279
- // prompt automaticallyit's the right place for the universal tool-selection
280
- // playbook, ahead of individual tool descriptions.
379
+ // Respond to the handshake BEFORE doing any heavy initialization. Loading
380
+ // the SQLite DB and the tree-sitter WASM runtime can take many seconds on
381
+ // slow filesystems (Docker Desktop VirtioFS on macOS, WSL2). Clients like
382
+ // Claude Code time out the handshake at ~30s, which manifested as
383
+ // "MCP tools never appear" — the child was alive and had received the
384
+ // initialize but was still awaiting initGrammars(). See issue #172.
385
+ //
386
+ // We accept the client's protocol version but respond with our supported
387
+ // version. The `instructions` field is surfaced by MCP clients in the
388
+ // agent's system prompt automatically — it's the right place for the
389
+ // universal tool-selection playbook, ahead of individual tool descriptions.
281
390
  this.transport.sendResult(request.id, {
282
391
  protocolVersion: PROTOCOL_VERSION,
283
392
  capabilities: {
@@ -286,12 +395,26 @@ class MCPServer {
286
395
  serverInfo: SERVER_INFO,
287
396
  instructions: server_instructions_1.SERVER_INSTRUCTIONS,
288
397
  });
398
+ // If we know the project dir, kick off init in the background now. Tool
399
+ // calls that arrive before it finishes fall through to `retryInitIfNeeded`,
400
+ // which waits for this promise rather than racing it with a second open.
401
+ //
402
+ // If we DON'T know it (no rootUri, no --path), defer: the first tool call
403
+ // resolves it via roots/list (when the client supports roots) or cwd. This
404
+ // is the fix for issue #196 — clients that launch the server outside the
405
+ // project and don't pass a rootUri previously got a misleading "not
406
+ // initialized" error on every call.
407
+ if (explicitPath) {
408
+ this.initPromise = this.tryInitializeDefault(explicitPath).finally(() => {
409
+ this.initPromise = null;
410
+ });
411
+ }
289
412
  }
290
413
  /**
291
414
  * Handle tools/list request
292
415
  */
293
416
  async handleToolsList(request) {
294
- this.retryInitIfNeeded();
417
+ await this.retryInitIfNeeded();
295
418
  this.transport.sendResult(request.id, {
296
419
  tools: this.toolHandler.getTools(),
297
420
  });
@@ -315,7 +438,7 @@ class MCPServer {
315
438
  }
316
439
  // If the default project isn't initialized yet, retry in case it was
317
440
  // initialized after the MCP server started (e.g. user ran codegraph init)
318
- this.retryInitIfNeeded();
441
+ await this.retryInitIfNeeded();
319
442
  const result = await this.toolHandler.execute(toolName, toolArgs);
320
443
  this.transport.sendResult(request.id, result);
321
444
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2CAA6B;AAC7B,kDAA+D;AAC/D,2CAA8F;AAC9F,mCAA6C;AAC7C,+DAA4D;AAE5D;;;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,2EAA2E;QAC3E,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,iCAAiC;QACjC,OAAO,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,OAAO;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC;;;;;GAKG;AACH,MAAa,SAAS;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AC;QAED,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC;QAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;QAExC,uBAAuB;QACvB,MAAM,IAAI,GAAG,aAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,OAAO,CAAC,EAAE,EACV,sBAAU,CAAC,aAAa,EACxB,iBAAiB,QAAQ,EAAE,CAC5B,CAAC;YACF,OAAO;QACT,CAAC;QAED,qEAAqE;QACrE,0EAA0E;QAC1E,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAE/B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAElE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;CACF;AAxXD,8BAwXC;AAED,wBAAwB;AACxB,yCAA6C;AAApC,2GAAA,cAAc,OAAA;AACvB,iCAA6C;AAApC,8FAAA,KAAK,OAAA;AAAE,oGAAA,WAAW,OAAA"}
@@ -15,5 +15,5 @@
15
15
  * burn tokens. Reference only tools that exist on `main`; gate any
16
16
  * conditional tools behind feature checks if/when they ship.
17
17
  */
18
- export declare const SERVER_INSTRUCTIONS = "# Codegraph \u2014 code intelligence over an indexed knowledge graph\n\nCodegraph is a SQLite knowledge graph of every symbol, edge, and file\nin the workspace. Reads are sub-millisecond; the index lags writes by\nabout a second through the file watcher. Consult it BEFORE writing or\nediting code, not during.\n\n## Tool selection by intent\n\n- **\"What is the symbol named X?\"** \u2192 `codegraph_search`\n- **\"What's the deal with this task / feature / area?\"** \u2192 `codegraph_context` (PRIMARY \u2014 composes search + node + callers + callees in one call)\n- **\"What calls this?\"** \u2192 `codegraph_callers`\n- **\"What does this call?\"** \u2192 `codegraph_callees`\n- **\"What would changing this break?\"** \u2192 `codegraph_impact`\n- **\"Show me this symbol's source / signature / docstring.\"** \u2192 `codegraph_node`\n- **\"Survey an unfamiliar topic / pattern / module.\"** \u2192 `codegraph_explore` (heavier; deep dive)\n- **\"What's in directory X?\"** \u2192 `codegraph_files`\n- **\"Is the index ready / what's its size?\"** \u2192 `codegraph_status`\n\n## Common chains\n\n- **Onboarding**: `codegraph_context` first. If still unclear, `codegraph_explore` for breadth, then `codegraph_node` on specific symbols.\n- **Refactor planning**: `codegraph_search` \u2192 `codegraph_callers` \u2192 `codegraph_impact`. The blast-radius answer comes from impact, not from walking callers manually.\n- **Debugging a regression**: `codegraph_callers` of the suspected symbol; widen with `codegraph_impact` if an unexpected call appears.\n\n## Anti-patterns\n\n- **Don't grep first** when looking up a symbol by name \u2014 `codegraph_search` is faster and returns kind + location + signature.\n- **Don't chain `codegraph_search` + `codegraph_node`** when you just want context \u2014 `codegraph_context` is one round-trip.\n- **Don't use `codegraph_explore` for narrow questions** \u2014 it's a multi-call deep dive, expensive in tokens. Save it for genuine \"I'm new here\" surveys.\n- **Don't query the index immediately after editing a file** \u2014 the watcher needs ~500ms to debounce + sync. Wait for the next turn.\n\n## Limitations\n\n- Index lags file writes by ~1 second.\n- Cross-file resolution is best-effort name matching; ambiguous calls may return multiple candidates.\n- No live correctness validation \u2014 that's still the TypeScript compiler / test suite / linter's job. Codegraph supplements those with structural context they don't have.\n";
18
+ export declare const SERVER_INSTRUCTIONS = "# Codegraph \u2014 code intelligence over an indexed knowledge graph\n\nCodegraph is a SQLite knowledge graph of every symbol, edge, and file\nin the workspace. Reads are sub-millisecond; the index lags writes by\nabout a second through the file watcher. Consult it BEFORE writing or\nediting code, not during.\n\n## Answer directly \u2014 don't delegate exploration\n\nFor \"how does X work\", architecture, trace, or where-is-X questions,\nanswer DIRECTLY using 2-3 codegraph calls: `codegraph_context` first,\nthen ONE `codegraph_explore` for the source of the symbols it surfaces.\nCodegraph IS the pre-built search index \u2014 so delegating the lookup to a\nseparate file-reading sub-task/agent, or running your own grep + read\nloop, repeats work codegraph already did and costs more for the same\nanswer. Reach for raw Read/Grep only to confirm a specific detail\ncodegraph didn't cover. A direct codegraph answer is typically a handful\nof calls; a grep/read exploration is dozens.\n\n## Tool selection by intent\n\n- **\"How does X work? / trace X end to end / explain the Y system / architecture?\"** \u2192 `codegraph_explore` (PRIMARY for understanding \u2014 seed it with the key symbol names, read its output, don't grep+Read your way there)\n- **\"What is the symbol named X? / where is X defined?\"** \u2192 `codegraph_search` (pinpoint lookups)\n- **\"What's the deal with this task / feature / area?\"** \u2192 `codegraph_context` (lighter composed view of search + node + callers + callees)\n- **\"What calls this?\"** \u2192 `codegraph_callers`\n- **\"What does this call?\"** \u2192 `codegraph_callees`\n- **\"What would changing this break?\"** \u2192 `codegraph_impact`\n- **\"Show me this symbol's source / signature / docstring.\"** \u2192 `codegraph_node`\n- **\"Show me several related symbols' source / survey an area.\"** \u2192 `codegraph_explore` (ONE capped call; prefer over many codegraph_node/Read)\n- **\"What's in directory X?\"** \u2192 `codegraph_files`\n- **\"Is the index ready / what's its size?\"** \u2192 `codegraph_status`\n\n## Common chains\n\n- **Understanding / onboarding**: feed `codegraph_explore` the key symbol/file names and read its output (line-numbered source from many files in one call). If the question names nothing concrete, do ONE quick `codegraph_search` / `codegraph_context` to surface the names, then explore with them. Fill remaining gaps with `codegraph_node` / Read \u2014 don't drop back to grep+Read for the whole topic.\n- **Refactor planning**: `codegraph_search` \u2192 `codegraph_callers` \u2192 `codegraph_impact`. The blast-radius answer comes from impact, not from walking callers manually.\n- **Debugging a regression**: `codegraph_callers` of the suspected symbol; widen with `codegraph_impact` if an unexpected call appears.\n\n## Anti-patterns\n\n- **Don't search-then-Read your way through an understanding question** \u2014 feed the names you find into `codegraph_explore` instead of Reading the files one by one; it does that whole loop in one call and returns line numbers you can cite directly.\n- **Don't grep first** when looking up a symbol by name \u2014 `codegraph_search` is faster and returns kind + location + signature.\n- **Don't reach for `codegraph_explore` on a pinpoint \"where is X defined\" lookup** \u2014 `codegraph_search` is one cheap call.\n- **Don't chain `codegraph_search` + `codegraph_node`** when you just want context \u2014 `codegraph_context` is one round-trip.\n- **Don't loop `codegraph_node` over many symbols** \u2014 one `codegraph_explore` call returns them all grouped by file, while each separate call re-reads the whole context and costs far more. Use `codegraph_node` for a single symbol.\n- **Don't query the index immediately after editing a file** \u2014 the watcher needs ~500ms to debounce + sync. Wait for the next turn.\n\n## Limitations\n\n- Index lags file writes by ~1 second.\n- Cross-file resolution is best-effort name matching; ambiguous calls may return multiple candidates.\n- No live correctness validation \u2014 that's still the TypeScript compiler / test suite / linter's job. Codegraph supplements those with structural context they don't have.\n";
19
19
  //# sourceMappingURL=server-instructions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server-instructions.d.ts","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,s7EAqC/B,CAAC"}
1
+ {"version":3,"file":"server-instructions.d.ts","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,ymIAoD/B,CAAC"}
@@ -25,29 +25,44 @@ in the workspace. Reads are sub-millisecond; the index lags writes by
25
25
  about a second through the file watcher. Consult it BEFORE writing or
26
26
  editing code, not during.
27
27
 
28
+ ## Answer directly — don't delegate exploration
29
+
30
+ For "how does X work", architecture, trace, or where-is-X questions,
31
+ answer DIRECTLY using 2-3 codegraph calls: \`codegraph_context\` first,
32
+ then ONE \`codegraph_explore\` for the source of the symbols it surfaces.
33
+ Codegraph IS the pre-built search index — so delegating the lookup to a
34
+ separate file-reading sub-task/agent, or running your own grep + read
35
+ loop, repeats work codegraph already did and costs more for the same
36
+ answer. Reach for raw Read/Grep only to confirm a specific detail
37
+ codegraph didn't cover. A direct codegraph answer is typically a handful
38
+ of calls; a grep/read exploration is dozens.
39
+
28
40
  ## Tool selection by intent
29
41
 
30
- - **"What is the symbol named X?"** → \`codegraph_search\`
31
- - **"What's the deal with this task / feature / area?"** → \`codegraph_context\` (PRIMARY — composes search + node + callers + callees in one call)
42
+ - **"How does X work? / trace X end to end / explain the Y system / architecture?"** → \`codegraph_explore\` (PRIMARY for understanding — seed it with the key symbol names, read its output, don't grep+Read your way there)
43
+ - **"What is the symbol named X? / where is X defined?"** → \`codegraph_search\` (pinpoint lookups)
44
+ - **"What's the deal with this task / feature / area?"** → \`codegraph_context\` (lighter composed view of search + node + callers + callees)
32
45
  - **"What calls this?"** → \`codegraph_callers\`
33
46
  - **"What does this call?"** → \`codegraph_callees\`
34
47
  - **"What would changing this break?"** → \`codegraph_impact\`
35
48
  - **"Show me this symbol's source / signature / docstring."** → \`codegraph_node\`
36
- - **"Survey an unfamiliar topic / pattern / module."** → \`codegraph_explore\` (heavier; deep dive)
49
+ - **"Show me several related symbols' source / survey an area."** → \`codegraph_explore\` (ONE capped call; prefer over many codegraph_node/Read)
37
50
  - **"What's in directory X?"** → \`codegraph_files\`
38
51
  - **"Is the index ready / what's its size?"** → \`codegraph_status\`
39
52
 
40
53
  ## Common chains
41
54
 
42
- - **Onboarding**: \`codegraph_context\` first. If still unclear, \`codegraph_explore\` for breadth, then \`codegraph_node\` on specific symbols.
55
+ - **Understanding / onboarding**: feed \`codegraph_explore\` the key symbol/file names and read its output (line-numbered source from many files in one call). If the question names nothing concrete, do ONE quick \`codegraph_search\` / \`codegraph_context\` to surface the names, then explore with them. Fill remaining gaps with \`codegraph_node\` / Read — don't drop back to grep+Read for the whole topic.
43
56
  - **Refactor planning**: \`codegraph_search\` → \`codegraph_callers\` → \`codegraph_impact\`. The blast-radius answer comes from impact, not from walking callers manually.
44
57
  - **Debugging a regression**: \`codegraph_callers\` of the suspected symbol; widen with \`codegraph_impact\` if an unexpected call appears.
45
58
 
46
59
  ## Anti-patterns
47
60
 
61
+ - **Don't search-then-Read your way through an understanding question** — feed the names you find into \`codegraph_explore\` instead of Reading the files one by one; it does that whole loop in one call and returns line numbers you can cite directly.
48
62
  - **Don't grep first** when looking up a symbol by name — \`codegraph_search\` is faster and returns kind + location + signature.
63
+ - **Don't reach for \`codegraph_explore\` on a pinpoint "where is X defined" lookup** — \`codegraph_search\` is one cheap call.
49
64
  - **Don't chain \`codegraph_search\` + \`codegraph_node\`** when you just want context — \`codegraph_context\` is one round-trip.
50
- - **Don't use \`codegraph_explore\` for narrow questions** — it's a multi-call deep dive, expensive in tokens. Save it for genuine "I'm new here" surveys.
65
+ - **Don't loop \`codegraph_node\` over many symbols** — one \`codegraph_explore\` call returns them all grouped by file, while each separate call re-reads the whole context and costs far more. Use \`codegraph_node\` for a single symbol.
51
66
  - **Don't query the index immediately after editing a file** — the watcher needs ~500ms to debounce + sync. Wait for the next turn.
52
67
 
53
68
  ## Limitations
@@ -1 +1 @@
1
- {"version":3,"file":"server-instructions.js","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqClC,CAAC"}
1
+ {"version":3,"file":"server-instructions.js","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDlC,CAAC"}
@@ -10,6 +10,47 @@ import CodeGraph from '../index';
10
10
  * but smaller ones should use fewer to avoid unnecessary overhead.
11
11
  */
12
12
  export declare function getExploreBudget(fileCount: number): number;
13
+ /**
14
+ * Adaptive output budget for `codegraph_explore`, scaled to project size.
15
+ *
16
+ * Smaller codebases get a tighter total cap, fewer default files, smaller
17
+ * per-file cap, and tighter clustering — so a focused query on a 100-file
18
+ * project doesn't dump a whole file's worth of source into the agent's
19
+ * context. Larger codebases keep the generous defaults because the
20
+ * agent's native discovery cost (grep + find + many Reads) genuinely
21
+ * dwarfs a fat explore call at that scale.
22
+ *
23
+ * Meta-text (relationships map, "additional relevant files" list,
24
+ * completeness signal, budget note) is gated off for tiny projects
25
+ * where one rich call is the whole story and the extra prose is just
26
+ * overhead.
27
+ *
28
+ * Tier breakpoints mirror `getExploreBudget` so a project sits in the
29
+ * same tier across both knobs.
30
+ */
31
+ export interface ExploreOutputBudget {
32
+ /** Hard cap on total output characters. */
33
+ maxOutputChars: number;
34
+ /** Default `maxFiles` when the caller didn't specify one. */
35
+ defaultMaxFiles: number;
36
+ /** Cap on contiguous source returned per file (across all its clusters). */
37
+ maxCharsPerFile: number;
38
+ /** Cluster gap threshold in lines — tighter clustering on small projects. */
39
+ gapThreshold: number;
40
+ /** Max symbols listed in the per-file header (`#### path — sym(kind), ...`). */
41
+ maxSymbolsInFileHeader: number;
42
+ /** Max edges shown per relationship kind in the Relationships section. */
43
+ maxEdgesPerRelationshipKind: number;
44
+ /** Include the "Relationships" section. */
45
+ includeRelationships: boolean;
46
+ /** Include the "Additional relevant files (not shown)" trailing list. */
47
+ includeAdditionalFiles: boolean;
48
+ /** Include the "Complete source code is included above…" reminder. */
49
+ includeCompletenessSignal: boolean;
50
+ /** Include the explore-budget reminder at the end. */
51
+ includeBudgetNote: boolean;
52
+ }
53
+ export declare function getExploreOutputBudget(fileCount: number): ExploreOutputBudget;
13
54
  /**
14
55
  * MCP Tool definition
15
56
  */
@@ -56,11 +97,17 @@ export declare const tools: ToolDefinition[];
56
97
  export declare class ToolHandler {
57
98
  private cg;
58
99
  private projectCache;
100
+ private defaultProjectHint;
59
101
  constructor(cg: CodeGraph | null);
60
102
  /**
61
103
  * Update the default CodeGraph instance (e.g. after lazy initialization)
62
104
  */
63
105
  setDefaultCodeGraph(cg: CodeGraph): void;
106
+ /**
107
+ * Record the directory the server tried to resolve the default project from.
108
+ * Used only to make the "no default project" error actionable.
109
+ */
110
+ setDefaultProjectHint(searchedPath: string): void;
64
111
  /**
65
112
  * Whether a default CodeGraph instance is available
66
113
  */
@@ -117,14 +164,16 @@ export declare class ToolHandler {
117
164
  * Handle codegraph_impact
118
165
  */
119
166
  private handleImpact;
120
- /** Maximum output for explore tool — sized to stay under MCP client token limits (~10k tokens) */
121
- private static readonly EXPLORE_MAX_OUTPUT;
122
167
  /**
123
168
  * Handle codegraph_explore — deep exploration in a single call
124
169
  *
125
170
  * Strategy: find relevant symbols via graph traversal, group by file,
126
171
  * then read contiguous file sections covering all symbols per file.
127
172
  * This replaces multiple codegraph_node + Read calls.
173
+ *
174
+ * Output size is adaptive to project file count via
175
+ * `getExploreOutputBudget` — see #185 for why a fixed 35k cap was a
176
+ * tax on small projects while earning its keep on large ones.
128
177
  */
129
178
  private handleExplore;
130
179
  /**
@@ -160,9 +209,22 @@ export declare class ToolHandler {
160
209
  * Returns the best match and a note about alternatives if any.
161
210
  */
162
211
  /**
163
- * Check if a node matches a symbol query, supporting both simple names and
164
- * qualified "Parent.child" notation (e.g., "Session.request" matches a method
165
- * named "request" inside a class named "Session").
212
+ * Check if a node matches a symbol query.
213
+ *
214
+ * Accepts simple names (`run`) and three flavors of qualifier:
215
+ * - dotted `Session.request` (TS/JS/Python)
216
+ * - colon-pair `stage_apply::run` (Rust, C++, Ruby)
217
+ * - slash `configurator/stage_apply` (path-ish)
218
+ *
219
+ * Multi-level qualifiers compose: `crate::configurator::stage_apply::run`
220
+ * works. Rust path prefixes (`crate`, `super`, `self`) are stripped so
221
+ * the canonical `crate::module::symbol` form resolves.
222
+ *
223
+ * Resolution order, last part must always equal `node.name`:
224
+ * 1. Suffix-match against `qualifiedName` (handles class-scoped methods
225
+ * where the extractor builds the qualified name from the AST stack)
226
+ * 2. File-path containment (handles file-derived modules in Rust/
227
+ * Python — `stage_apply::run` matches a `run` in `stage_apply.rs`)
166
228
  */
167
229
  private matchesSymbol;
168
230
  private findSymbol;
@@ -178,6 +240,14 @@ export declare class ToolHandler {
178
240
  private formatSearchResults;
179
241
  private formatNodeList;
180
242
  private formatImpact;
243
+ /**
244
+ * Build a compact structural outline of a container symbol from its
245
+ * indexed children (methods, fields, properties, …) — name, kind,
246
+ * line number, and signature — so the agent gets the shape of a class
247
+ * without the full source of every method. Returns '' when the container
248
+ * has no indexed children, so the caller can fall back to full source.
249
+ */
250
+ private buildContainerOutline;
181
251
  private formatNodeDetails;
182
252
  private formatTaskContext;
183
253
  private textResult;
@@ -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;AAY/D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAM1D;AAgBD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAC3C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAUD;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,EAAE,c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