@colbymchenry/codegraph 0.9.6 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -57
- package/dist/bin/codegraph.d.ts +25 -0
- package/dist/bin/node-version-check.d.ts +37 -0
- package/dist/bin/uninstall.d.ts +14 -0
- package/dist/context/formatter.d.ts +30 -0
- package/dist/context/index.d.ts +110 -0
- package/dist/db/index.d.ts +101 -0
- package/dist/db/migrations.d.ts +44 -0
- package/dist/db/queries.d.ts +344 -0
- package/dist/db/sqlite-adapter.d.ts +46 -0
- package/dist/directory.d.ts +57 -0
- package/dist/errors.d.ts +136 -0
- package/dist/extraction/dfm-extractor.d.ts +31 -0
- package/dist/extraction/generated-detection.d.ts +30 -0
- package/dist/extraction/grammars.d.ts +100 -0
- package/dist/extraction/index.d.ts +138 -0
- package/dist/extraction/languages/c-cpp.d.ts +4 -0
- package/dist/extraction/languages/csharp.d.ts +3 -0
- package/dist/extraction/languages/dart.d.ts +3 -0
- package/dist/extraction/languages/go.d.ts +3 -0
- package/dist/extraction/languages/index.d.ts +10 -0
- package/dist/extraction/languages/java.d.ts +3 -0
- package/dist/extraction/languages/javascript.d.ts +3 -0
- package/dist/extraction/languages/kotlin.d.ts +3 -0
- package/dist/extraction/languages/lua.d.ts +3 -0
- package/dist/extraction/languages/luau.d.ts +3 -0
- package/dist/extraction/languages/objc.d.ts +3 -0
- package/dist/extraction/languages/pascal.d.ts +3 -0
- package/dist/extraction/languages/php.d.ts +3 -0
- package/dist/extraction/languages/python.d.ts +3 -0
- package/dist/extraction/languages/ruby.d.ts +3 -0
- package/dist/extraction/languages/rust.d.ts +3 -0
- package/dist/extraction/languages/scala.d.ts +3 -0
- package/dist/extraction/languages/swift.d.ts +3 -0
- package/dist/extraction/languages/typescript.d.ts +3 -0
- package/dist/extraction/liquid-extractor.d.ts +52 -0
- package/dist/extraction/mybatis-extractor.d.ts +48 -0
- package/dist/extraction/parse-worker.d.ts +8 -0
- package/dist/extraction/svelte-extractor.d.ts +56 -0
- package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
- package/dist/extraction/tree-sitter-types.d.ts +193 -0
- package/dist/extraction/tree-sitter.d.ts +291 -0
- package/dist/extraction/vue-extractor.d.ts +36 -0
- package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
- package/dist/graph/index.d.ts +8 -0
- package/dist/graph/queries.d.ts +106 -0
- package/dist/graph/traversal.d.ts +127 -0
- package/dist/index.d.ts +492 -0
- package/dist/installer/config-writer.d.ts +28 -0
- package/dist/installer/index.d.ts +100 -0
- package/dist/installer/instructions-template.d.ts +18 -0
- package/dist/installer/targets/antigravity.d.ts +57 -0
- package/dist/installer/targets/claude.d.ts +56 -0
- package/dist/installer/targets/codex.d.ts +18 -0
- package/dist/installer/targets/cursor.d.ts +35 -0
- package/dist/installer/targets/gemini.d.ts +26 -0
- package/dist/installer/targets/hermes.d.ts +18 -0
- package/dist/installer/targets/kiro.d.ts +27 -0
- package/dist/installer/targets/opencode.d.ts +30 -0
- package/dist/installer/targets/registry.d.ts +35 -0
- package/dist/installer/targets/shared.d.ts +77 -0
- package/dist/installer/targets/toml.d.ts +52 -0
- package/dist/installer/targets/types.d.ts +101 -0
- package/dist/mcp/daemon-paths.d.ts +46 -0
- package/dist/mcp/daemon.d.ts +161 -0
- package/dist/mcp/engine.d.ts +105 -0
- package/dist/mcp/index.d.ts +112 -0
- package/dist/mcp/proxy.d.ts +81 -0
- package/dist/mcp/server-instructions.d.ts +19 -0
- package/dist/mcp/session.d.ts +77 -0
- package/dist/mcp/tools.d.ts +423 -0
- package/dist/mcp/transport.d.ts +188 -0
- package/dist/mcp/version.d.ts +19 -0
- package/dist/resolution/callback-synthesizer.d.ts +10 -0
- package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
- package/dist/resolution/frameworks/csharp.d.ts +8 -0
- package/dist/resolution/frameworks/drupal.d.ts +51 -0
- package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
- package/dist/resolution/frameworks/express.d.ts +8 -0
- package/dist/resolution/frameworks/fabric.d.ts +3 -0
- package/dist/resolution/frameworks/go.d.ts +8 -0
- package/dist/resolution/frameworks/index.d.ts +48 -0
- package/dist/resolution/frameworks/java.d.ts +8 -0
- package/dist/resolution/frameworks/laravel.d.ts +13 -0
- package/dist/resolution/frameworks/nestjs.d.ts +26 -0
- package/dist/resolution/frameworks/play.d.ts +19 -0
- package/dist/resolution/frameworks/python.d.ts +10 -0
- package/dist/resolution/frameworks/react-native.d.ts +3 -0
- package/dist/resolution/frameworks/react.d.ts +8 -0
- package/dist/resolution/frameworks/ruby.d.ts +8 -0
- package/dist/resolution/frameworks/rust.d.ts +8 -0
- package/dist/resolution/frameworks/svelte.d.ts +9 -0
- package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
- package/dist/resolution/frameworks/swift.d.ts +10 -0
- package/dist/resolution/frameworks/vue.d.ts +9 -0
- package/dist/resolution/go-module.d.ts +26 -0
- package/dist/resolution/import-resolver.d.ts +68 -0
- package/dist/resolution/index.d.ts +116 -0
- package/dist/resolution/lru-cache.d.ts +24 -0
- package/dist/resolution/name-matcher.d.ts +32 -0
- package/dist/resolution/path-aliases.d.ts +68 -0
- package/dist/resolution/strip-comments.d.ts +27 -0
- package/dist/resolution/swift-objc-bridge.d.ts +134 -0
- package/dist/resolution/types.d.ts +209 -0
- package/dist/search/query-parser.d.ts +57 -0
- package/dist/search/query-utils.d.ts +53 -0
- package/dist/sync/git-hooks.d.ts +45 -0
- package/dist/sync/index.d.ts +19 -0
- package/dist/sync/watch-policy.d.ts +48 -0
- package/dist/sync/watcher.d.ts +191 -0
- package/dist/sync/worktree.d.ts +54 -0
- package/dist/types.d.ts +369 -0
- package/dist/ui/glyphs.d.ts +42 -0
- package/dist/ui/shimmer-progress.d.ts +11 -0
- package/dist/ui/shimmer-worker.d.ts +2 -0
- package/dist/ui/types.d.ts +17 -0
- package/dist/utils.d.ts +205 -0
- package/npm-sdk.js +75 -0
- package/package.json +18 -7
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Definitions
|
|
3
|
+
*
|
|
4
|
+
* Defines the tools exposed by the CodeGraph MCP server.
|
|
5
|
+
*/
|
|
6
|
+
import type CodeGraph from '../index';
|
|
7
|
+
import type { PendingFile } from '../sync';
|
|
8
|
+
/**
|
|
9
|
+
* Calculate the recommended number of codegraph_explore calls based on project size.
|
|
10
|
+
* Larger codebases need more exploration calls to cover their surface area,
|
|
11
|
+
* but smaller ones should use fewer to avoid unnecessary overhead.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getExploreBudget(fileCount: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Adaptive output budget for `codegraph_explore`, scaled to project size.
|
|
16
|
+
*
|
|
17
|
+
* Smaller codebases get a tighter total cap, fewer default files, smaller
|
|
18
|
+
* per-file cap, and tighter clustering — so a focused query on a 100-file
|
|
19
|
+
* project doesn't dump a whole file's worth of source into the agent's
|
|
20
|
+
* context. Larger codebases keep the generous defaults because the
|
|
21
|
+
* agent's native discovery cost (grep + find + many Reads) genuinely
|
|
22
|
+
* dwarfs a fat explore call at that scale.
|
|
23
|
+
*
|
|
24
|
+
* Meta-text (relationships map, "additional relevant files" list,
|
|
25
|
+
* completeness signal, budget note) is gated off for tiny projects
|
|
26
|
+
* where one rich call is the whole story and the extra prose is just
|
|
27
|
+
* overhead.
|
|
28
|
+
*
|
|
29
|
+
* Tier breakpoints mirror `getExploreBudget` so a project sits in the
|
|
30
|
+
* same tier across both knobs.
|
|
31
|
+
*/
|
|
32
|
+
export interface ExploreOutputBudget {
|
|
33
|
+
/** Hard cap on total output characters. */
|
|
34
|
+
maxOutputChars: number;
|
|
35
|
+
/** Default `maxFiles` when the caller didn't specify one. */
|
|
36
|
+
defaultMaxFiles: number;
|
|
37
|
+
/** Cap on contiguous source returned per file (across all its clusters). */
|
|
38
|
+
maxCharsPerFile: number;
|
|
39
|
+
/** Cluster gap threshold in lines — tighter clustering on small projects. */
|
|
40
|
+
gapThreshold: number;
|
|
41
|
+
/** Max symbols listed in the per-file header (`#### path — sym(kind), ...`). */
|
|
42
|
+
maxSymbolsInFileHeader: number;
|
|
43
|
+
/** Max edges shown per relationship kind in the Relationships section. */
|
|
44
|
+
maxEdgesPerRelationshipKind: number;
|
|
45
|
+
/** Include the "Relationships" section. */
|
|
46
|
+
includeRelationships: boolean;
|
|
47
|
+
/** Include the "Additional relevant files (not shown)" trailing list. */
|
|
48
|
+
includeAdditionalFiles: boolean;
|
|
49
|
+
/** Include the "Complete source code is included above…" reminder. */
|
|
50
|
+
includeCompletenessSignal: boolean;
|
|
51
|
+
/** Include the explore-budget reminder at the end. */
|
|
52
|
+
includeBudgetNote: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Hard-drop test/spec/icon/i18n files from the relevant-file set unless
|
|
55
|
+
* the query itself mentions tests. Today they're only deprioritized in
|
|
56
|
+
* the sort, which on tiny repos still lets one slip into the top N (e.g.
|
|
57
|
+
* cobra's `command_test.go` displaced `args.go` and contributed ~10KB of
|
|
58
|
+
* pure noise to "How does cobra parse commands?"). Off by default; on
|
|
59
|
+
* for the very-tiny tier where one slip dominates the budget.
|
|
60
|
+
*/
|
|
61
|
+
excludeLowValueFiles: boolean;
|
|
62
|
+
}
|
|
63
|
+
export declare function getExploreOutputBudget(fileCount: number): ExploreOutputBudget;
|
|
64
|
+
/**
|
|
65
|
+
* Per-file staleness banner emitted at the top of a tool response when the
|
|
66
|
+
* file watcher has pending events for files referenced by the response.
|
|
67
|
+
* The agent uses this to fall back to Read for those specific files
|
|
68
|
+
* without waiting for the debounced sync (issue #403).
|
|
69
|
+
*/
|
|
70
|
+
export declare function formatStaleBanner(stale: PendingFile[]): string;
|
|
71
|
+
/**
|
|
72
|
+
* Compact footer listing pending files that are NOT referenced in this
|
|
73
|
+
* response. Gives the agent a complete project-wide freshness picture
|
|
74
|
+
* without bloating the main banner.
|
|
75
|
+
*/
|
|
76
|
+
export declare function formatStaleFooter(stale: PendingFile[]): string;
|
|
77
|
+
/**
|
|
78
|
+
* MCP Tool definition
|
|
79
|
+
*/
|
|
80
|
+
export interface ToolDefinition {
|
|
81
|
+
name: string;
|
|
82
|
+
description: string;
|
|
83
|
+
inputSchema: {
|
|
84
|
+
type: 'object';
|
|
85
|
+
properties: Record<string, PropertySchema>;
|
|
86
|
+
required?: string[];
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
interface PropertySchema {
|
|
90
|
+
type: string;
|
|
91
|
+
description: string;
|
|
92
|
+
enum?: string[];
|
|
93
|
+
default?: unknown;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Tool execution result
|
|
97
|
+
*/
|
|
98
|
+
export interface ToolResult {
|
|
99
|
+
content: Array<{
|
|
100
|
+
type: 'text';
|
|
101
|
+
text: string;
|
|
102
|
+
}>;
|
|
103
|
+
isError?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* All CodeGraph MCP tools
|
|
107
|
+
*
|
|
108
|
+
* Designed for minimal context usage - use codegraph_context as the primary tool,
|
|
109
|
+
* and only use other tools for targeted follow-up queries.
|
|
110
|
+
*
|
|
111
|
+
* All tools support cross-project queries via the optional `projectPath` parameter.
|
|
112
|
+
*/
|
|
113
|
+
export declare const tools: ToolDefinition[];
|
|
114
|
+
/**
|
|
115
|
+
* Allowlist-filtered tool definitions WITHOUT an engine — the static surface the
|
|
116
|
+
* proxy answers `tools/list` with before any project is open. Mirrors
|
|
117
|
+
* `ToolHandler.getTools()` in the no-CodeGraph case (the dynamic per-repo budget
|
|
118
|
+
* note in a description only adds once `cg` is loaded; the schemas are static).
|
|
119
|
+
*/
|
|
120
|
+
export declare function getStaticTools(): ToolDefinition[];
|
|
121
|
+
/**
|
|
122
|
+
* Tool handler that executes tools against a CodeGraph instance
|
|
123
|
+
*
|
|
124
|
+
* Supports cross-project queries via the projectPath parameter.
|
|
125
|
+
* Other projects are opened on-demand and cached for performance.
|
|
126
|
+
*/
|
|
127
|
+
export declare class ToolHandler {
|
|
128
|
+
private cg;
|
|
129
|
+
private projectCache;
|
|
130
|
+
private defaultProjectHint;
|
|
131
|
+
private worktreeMismatchCache;
|
|
132
|
+
private catchUpGate;
|
|
133
|
+
constructor(cg: CodeGraph | null);
|
|
134
|
+
/**
|
|
135
|
+
* Update the default CodeGraph instance (e.g. after lazy initialization)
|
|
136
|
+
*/
|
|
137
|
+
setDefaultCodeGraph(cg: CodeGraph): void;
|
|
138
|
+
/**
|
|
139
|
+
* Engine-only: register the catch-up sync promise so the next `execute()`
|
|
140
|
+
* call awaits it before serving. The handler swallows rejections (the
|
|
141
|
+
* engine logs them) so a sync failure never propagates as a tool error;
|
|
142
|
+
* we still want to serve a best-effort result over the same potentially-
|
|
143
|
+
* stale data, which is what would have happened without the gate.
|
|
144
|
+
*/
|
|
145
|
+
setCatchUpGate(p: Promise<void> | null): void;
|
|
146
|
+
/**
|
|
147
|
+
* Record the directory the server tried to resolve the default project from.
|
|
148
|
+
* Used only to make the "no default project" error actionable.
|
|
149
|
+
*/
|
|
150
|
+
setDefaultProjectHint(searchedPath: string): void;
|
|
151
|
+
/**
|
|
152
|
+
* Whether a default CodeGraph instance is available
|
|
153
|
+
*/
|
|
154
|
+
hasDefaultCodeGraph(): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Optional allowlist of exposed tools, parsed from the CODEGRAPH_MCP_TOOLS
|
|
157
|
+
* env var (comma-separated short names, e.g. "trace,search,node,context").
|
|
158
|
+
* Unset/empty → every tool is exposed. Lets an operator (or an A/B harness)
|
|
159
|
+
* trim the tool surface without rebuilding the client config; the ablated
|
|
160
|
+
* tool is then truly absent from ListTools rather than merely denied on call.
|
|
161
|
+
* Matching is on the short form, so "trace" and "codegraph_trace" both work.
|
|
162
|
+
*/
|
|
163
|
+
private toolAllowlist;
|
|
164
|
+
/** Whether a tool name passes the CODEGRAPH_MCP_TOOLS allowlist (if any). */
|
|
165
|
+
private isToolAllowed;
|
|
166
|
+
/**
|
|
167
|
+
* Get tool definitions with dynamic descriptions based on project size.
|
|
168
|
+
* The codegraph_explore tool description includes a budget recommendation
|
|
169
|
+
* scaled to the number of indexed files. Honors the CODEGRAPH_MCP_TOOLS
|
|
170
|
+
* allowlist so a trimmed surface is reflected in ListTools.
|
|
171
|
+
*/
|
|
172
|
+
getTools(): ToolDefinition[];
|
|
173
|
+
/**
|
|
174
|
+
* Get CodeGraph instance for a project
|
|
175
|
+
*
|
|
176
|
+
* If projectPath is provided, opens that project's CodeGraph (cached).
|
|
177
|
+
* Otherwise returns the default CodeGraph instance.
|
|
178
|
+
*
|
|
179
|
+
* Walks up parent directories to find the nearest .codegraph/ folder,
|
|
180
|
+
* similar to how git finds .git/ directories.
|
|
181
|
+
*/
|
|
182
|
+
private getCodeGraph;
|
|
183
|
+
/**
|
|
184
|
+
* Close all cached project connections
|
|
185
|
+
*/
|
|
186
|
+
closeAll(): void;
|
|
187
|
+
/**
|
|
188
|
+
* Validate that a value is a non-empty string within length bounds.
|
|
189
|
+
*
|
|
190
|
+
* The `maxLength` cap protects against MCP clients that ship huge
|
|
191
|
+
* payloads (10MB+ query strings either by accident or maliciously).
|
|
192
|
+
* Without this, a single oversized input can pin the FTS5 index or
|
|
193
|
+
* exhaust memory before any real work runs.
|
|
194
|
+
*/
|
|
195
|
+
private validateString;
|
|
196
|
+
/**
|
|
197
|
+
* Validate an optional path-like string input. Returns the value if
|
|
198
|
+
* valid (or undefined), or a ToolResult with the error.
|
|
199
|
+
*/
|
|
200
|
+
private validateOptionalPath;
|
|
201
|
+
/**
|
|
202
|
+
* Cached git worktree/index mismatch for a tool call's effective project.
|
|
203
|
+
*
|
|
204
|
+
* The "effective project" is what the request targets: an explicit
|
|
205
|
+
* `projectPath` arg, else the directory the server resolved its default
|
|
206
|
+
* project from (`defaultProjectHint`), else cwd. Memoized per start path —
|
|
207
|
+
* see `worktreeMismatchCache`. Best-effort: if the project can't be resolved
|
|
208
|
+
* (e.g. nothing initialized yet), it reports "no mismatch" so a tool is never
|
|
209
|
+
* broken by this check.
|
|
210
|
+
*/
|
|
211
|
+
private worktreeMismatchFor;
|
|
212
|
+
/**
|
|
213
|
+
* Prefix a successful read-tool result with a compact worktree-mismatch
|
|
214
|
+
* notice when the resolved index belongs to a different git working tree than
|
|
215
|
+
* the caller's (issue #155). Without this, an agent in a nested worktree
|
|
216
|
+
* silently trusts main-branch results. No-op on error results and when there
|
|
217
|
+
* is no mismatch. `codegraph_status` is excluded — it embeds its own verbose
|
|
218
|
+
* warning — so it stays out of this path.
|
|
219
|
+
*/
|
|
220
|
+
private withWorktreeNotice;
|
|
221
|
+
/**
|
|
222
|
+
* Annotate a successful read-tool result with per-file staleness — the
|
|
223
|
+
* non-blocking answer to issue #403. The file watcher tracks every event
|
|
224
|
+
* it sees per path; here we intersect "files referenced in this response"
|
|
225
|
+
* against that pending set and prepend a compact banner so the agent can
|
|
226
|
+
* fall back to Read for those *specific* files without waiting for the
|
|
227
|
+
* debounced sync to fire. Other pending files in the project (not
|
|
228
|
+
* referenced by this response) get a small footer so the agent has a
|
|
229
|
+
* complete picture without bloating the banner.
|
|
230
|
+
*
|
|
231
|
+
* Cost when nothing is pending — the common case — is one boolean check.
|
|
232
|
+
* No I/O, no parsing of markdown beyond a per-pending-file substring scan.
|
|
233
|
+
*/
|
|
234
|
+
private withStalenessNotice;
|
|
235
|
+
/**
|
|
236
|
+
* Execute a tool by name
|
|
237
|
+
*/
|
|
238
|
+
execute(toolName: string, args: Record<string, unknown>): Promise<ToolResult>;
|
|
239
|
+
/**
|
|
240
|
+
* Handle codegraph_search
|
|
241
|
+
*/
|
|
242
|
+
private handleSearch;
|
|
243
|
+
/**
|
|
244
|
+
* Handle codegraph_context
|
|
245
|
+
*/
|
|
246
|
+
private handleContext;
|
|
247
|
+
/**
|
|
248
|
+
* Detect a flow-style task ("how does X reach Y", "trace the path from A to B")
|
|
249
|
+
* and pre-run trace between the most likely endpoints, returning the trace
|
|
250
|
+
* body to splice into the context response. Returns '' for non-flow queries
|
|
251
|
+
* or when no plausible endpoint pair can be extracted.
|
|
252
|
+
*
|
|
253
|
+
* Conservative by design: only fires when the task has both a clear flow
|
|
254
|
+
* keyword AND at least two distinct PascalCase / camelCase identifiers.
|
|
255
|
+
* False positives waste a graph query; false negatives just fall back to
|
|
256
|
+
* the agent calling trace itself (existing path-proximity wiring handles
|
|
257
|
+
* disambiguation either way).
|
|
258
|
+
*/
|
|
259
|
+
private maybeInlineFlowTrace;
|
|
260
|
+
/**
|
|
261
|
+
* Heuristic to detect if a query looks like a feature request
|
|
262
|
+
*/
|
|
263
|
+
private looksLikeFeatureRequest;
|
|
264
|
+
/**
|
|
265
|
+
* Handle codegraph_callers
|
|
266
|
+
*/
|
|
267
|
+
private handleCallers;
|
|
268
|
+
/**
|
|
269
|
+
* Handle codegraph_callees
|
|
270
|
+
*/
|
|
271
|
+
private handleCallees;
|
|
272
|
+
/**
|
|
273
|
+
* Handle codegraph_impact
|
|
274
|
+
*/
|
|
275
|
+
private handleImpact;
|
|
276
|
+
/**
|
|
277
|
+
* Handle codegraph_trace — shortest CALL PATH between two symbols.
|
|
278
|
+
*
|
|
279
|
+
* Exposes GraphTraverser.findPath: the chain of functions from `from` to `to`,
|
|
280
|
+
* each hop annotated with file:line and the call-site line. This is the
|
|
281
|
+
* capability grep/Read structurally cannot provide. When no static path
|
|
282
|
+
* exists, the chain has almost certainly broken at dynamic dispatch
|
|
283
|
+
* (callbacks, descriptors, metaclasses) — we say so and surface the start
|
|
284
|
+
* symbol's outgoing calls so the agent bridges the one missing hop with
|
|
285
|
+
* codegraph_node rather than blindly reading.
|
|
286
|
+
*/
|
|
287
|
+
private handleTrace;
|
|
288
|
+
/**
|
|
289
|
+
* Describe a synthesized (dynamic-dispatch) edge for human output: how the
|
|
290
|
+
* callback was wired up — the bridge static parsing can't see. Returns null
|
|
291
|
+
* for ordinary static edges. Used by trace + the node trail so a synthesized
|
|
292
|
+
* hop reads as "registered via onUpdate at App.tsx:3148", not a bare arrow.
|
|
293
|
+
*/
|
|
294
|
+
private synthEdgeNote;
|
|
295
|
+
/**
|
|
296
|
+
* Read one trimmed source line at "relpath:line" (relative to the project
|
|
297
|
+
* root). `cache` holds split file contents so a multi-hop trace reads each
|
|
298
|
+
* file at most once. Returns null if the file/line can't be resolved.
|
|
299
|
+
*/
|
|
300
|
+
private sourceLineAt;
|
|
301
|
+
/**
|
|
302
|
+
* Read a hop's body — filePath lines [startLine..endLine] — for inlining into
|
|
303
|
+
* a trace, capped (lines + chars) so the whole path stays path-scoped even on
|
|
304
|
+
* a 7-hop chain. Dedents to the body's own indentation and marks truncation.
|
|
305
|
+
* Shares `cache` with sourceLineAt so each file is read at most once per trace.
|
|
306
|
+
*/
|
|
307
|
+
private sourceRangeAt;
|
|
308
|
+
/**
|
|
309
|
+
* Flow-from-named-symbols: an agent's codegraph_explore query is a bag of
|
|
310
|
+
* symbol names that usually spans the flow it's investigating (e.g.
|
|
311
|
+
* "PmsProductController getList PmsProductService list PmsProductServiceImpl").
|
|
312
|
+
* Surface the longest call chain AMONG those named symbols — scoped to what the
|
|
313
|
+
* agent explicitly named, so (unlike a fuzzy relevance set) there's no
|
|
314
|
+
* wrong-feature wandering. Rides synthesized edges, so controller→service-
|
|
315
|
+
* interface→impl shows up. Returns '' if no chain of >=3 nodes exists.
|
|
316
|
+
*
|
|
317
|
+
* Ambiguous tokens (Java `list` → dozens of nodes) are disambiguated by
|
|
318
|
+
* CO-NAMING: the agent names the class too, so we keep only `list` candidates
|
|
319
|
+
* whose qualifiedName contains another named token (`PmsProductServiceImpl::list`),
|
|
320
|
+
* dropping unrelated `OmsOrderService::list`.
|
|
321
|
+
*/
|
|
322
|
+
private buildFlowFromNamedSymbols;
|
|
323
|
+
/**
|
|
324
|
+
* Handle codegraph_explore — deep exploration in a single call
|
|
325
|
+
*
|
|
326
|
+
* Strategy: find relevant symbols via graph traversal, group by file,
|
|
327
|
+
* then read contiguous file sections covering all symbols per file.
|
|
328
|
+
* This replaces multiple codegraph_node + Read calls.
|
|
329
|
+
*
|
|
330
|
+
* Output size is adaptive to project file count via
|
|
331
|
+
* `getExploreOutputBudget` — see #185 for why a fixed 35k cap was a
|
|
332
|
+
* tax on small projects while earning its keep on large ones.
|
|
333
|
+
*/
|
|
334
|
+
private handleExplore;
|
|
335
|
+
/**
|
|
336
|
+
* Handle codegraph_node
|
|
337
|
+
*/
|
|
338
|
+
private handleNode;
|
|
339
|
+
/**
|
|
340
|
+
* Build the "trail" for a symbol: its direct callees (what it calls) and
|
|
341
|
+
* callers (what calls it), each with file:line — so codegraph_node doubles as
|
|
342
|
+
* the structural Grep→Read→expand primitive: a spot PLUS where to go next.
|
|
343
|
+
* Capped to stay cheap. Walk the graph by calling codegraph_node on a trail
|
|
344
|
+
* entry; no Read needed for covered hops. Empty edges on a non-leaf often mean
|
|
345
|
+
* dynamic dispatch the static graph couldn't resolve — that absence is itself
|
|
346
|
+
* a signal (read that one hop) rather than a dead end.
|
|
347
|
+
*/
|
|
348
|
+
private formatTrail;
|
|
349
|
+
/**
|
|
350
|
+
* Handle codegraph_status
|
|
351
|
+
*/
|
|
352
|
+
private handleStatus;
|
|
353
|
+
/**
|
|
354
|
+
* Handle codegraph_files - get project file structure from the index
|
|
355
|
+
*/
|
|
356
|
+
private handleFiles;
|
|
357
|
+
/**
|
|
358
|
+
* Convert glob pattern to regex
|
|
359
|
+
*/
|
|
360
|
+
private globToRegex;
|
|
361
|
+
/**
|
|
362
|
+
* Format files as a flat list
|
|
363
|
+
*/
|
|
364
|
+
private formatFilesFlat;
|
|
365
|
+
/**
|
|
366
|
+
* Format files grouped by language
|
|
367
|
+
*/
|
|
368
|
+
private formatFilesGrouped;
|
|
369
|
+
/**
|
|
370
|
+
* Format files as a tree structure
|
|
371
|
+
*/
|
|
372
|
+
private formatFilesTree;
|
|
373
|
+
/**
|
|
374
|
+
* Find a symbol by name, handling disambiguation when multiple matches exist.
|
|
375
|
+
* Returns the best match and a note about alternatives if any.
|
|
376
|
+
*/
|
|
377
|
+
/**
|
|
378
|
+
* Check if a node matches a symbol query.
|
|
379
|
+
*
|
|
380
|
+
* Accepts simple names (`run`) and three flavors of qualifier:
|
|
381
|
+
* - dotted `Session.request` (TS/JS/Python)
|
|
382
|
+
* - colon-pair `stage_apply::run` (Rust, C++, Ruby)
|
|
383
|
+
* - slash `configurator/stage_apply` (path-ish)
|
|
384
|
+
*
|
|
385
|
+
* Multi-level qualifiers compose: `crate::configurator::stage_apply::run`
|
|
386
|
+
* works. Rust path prefixes (`crate`, `super`, `self`) are stripped so
|
|
387
|
+
* the canonical `crate::module::symbol` form resolves.
|
|
388
|
+
*
|
|
389
|
+
* Resolution order, last part must always equal `node.name`:
|
|
390
|
+
* 1. Suffix-match against `qualifiedName` (handles class-scoped methods
|
|
391
|
+
* where the extractor builds the qualified name from the AST stack)
|
|
392
|
+
* 2. File-path containment (handles file-derived modules in Rust/
|
|
393
|
+
* Python — `stage_apply::run` matches a `run` in `stage_apply.rs`)
|
|
394
|
+
*/
|
|
395
|
+
private matchesSymbol;
|
|
396
|
+
private findSymbol;
|
|
397
|
+
/**
|
|
398
|
+
* Find ALL symbols matching a name. Used by callers/callees/impact to aggregate
|
|
399
|
+
* results across all matching symbols (e.g., multiple classes with an `execute` method).
|
|
400
|
+
*/
|
|
401
|
+
private findAllSymbols;
|
|
402
|
+
/**
|
|
403
|
+
* Truncate output if it exceeds the maximum length
|
|
404
|
+
*/
|
|
405
|
+
private truncateOutput;
|
|
406
|
+
private formatSearchResults;
|
|
407
|
+
private formatNodeList;
|
|
408
|
+
private formatImpact;
|
|
409
|
+
/**
|
|
410
|
+
* Build a compact structural outline of a container symbol from its
|
|
411
|
+
* indexed children (methods, fields, properties, …) — name, kind,
|
|
412
|
+
* line number, and signature — so the agent gets the shape of a class
|
|
413
|
+
* without the full source of every method. Returns '' when the container
|
|
414
|
+
* has no indexed children, so the caller can fall back to full source.
|
|
415
|
+
*/
|
|
416
|
+
private buildContainerOutline;
|
|
417
|
+
private formatNodeDetails;
|
|
418
|
+
private formatTaskContext;
|
|
419
|
+
private textResult;
|
|
420
|
+
private errorResult;
|
|
421
|
+
}
|
|
422
|
+
export {};
|
|
423
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP JSON-RPC Transports
|
|
3
|
+
*
|
|
4
|
+
* Two flavors share the same wire format (newline-delimited JSON-RPC 2.0):
|
|
5
|
+
*
|
|
6
|
+
* - `StdioTransport` — original transport; reads/writes the process's
|
|
7
|
+
* stdin/stdout. Used by direct-mode MCP servers.
|
|
8
|
+
* - `SocketTransport` — wraps a single `net.Socket`. Used by the shared-daemon
|
|
9
|
+
* architecture (see {@link ./daemon}) to multiplex multiple MCP clients onto
|
|
10
|
+
* one CodeGraph instance via per-connection sessions.
|
|
11
|
+
*
|
|
12
|
+
* Both implement {@link JsonRpcTransport} so the session-level protocol logic
|
|
13
|
+
* (initialize / tools/list / tools/call, plus server-initiated `roots/list`)
|
|
14
|
+
* is identical regardless of where the bytes come from.
|
|
15
|
+
*/
|
|
16
|
+
import type { Socket } from 'net';
|
|
17
|
+
/**
|
|
18
|
+
* JSON-RPC 2.0 Request
|
|
19
|
+
*/
|
|
20
|
+
export interface JsonRpcRequest {
|
|
21
|
+
jsonrpc: '2.0';
|
|
22
|
+
id: string | number;
|
|
23
|
+
method: string;
|
|
24
|
+
params?: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* JSON-RPC 2.0 Response
|
|
28
|
+
*/
|
|
29
|
+
export interface JsonRpcResponse {
|
|
30
|
+
jsonrpc: '2.0';
|
|
31
|
+
id: string | number | null;
|
|
32
|
+
result?: unknown;
|
|
33
|
+
error?: JsonRpcError;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* JSON-RPC 2.0 Error
|
|
37
|
+
*/
|
|
38
|
+
export interface JsonRpcError {
|
|
39
|
+
code: number;
|
|
40
|
+
message: string;
|
|
41
|
+
data?: unknown;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* JSON-RPC 2.0 Notification (no id, no response expected)
|
|
45
|
+
*/
|
|
46
|
+
export interface JsonRpcNotification {
|
|
47
|
+
jsonrpc: '2.0';
|
|
48
|
+
method: string;
|
|
49
|
+
params?: unknown;
|
|
50
|
+
}
|
|
51
|
+
export declare const ErrorCodes: {
|
|
52
|
+
readonly ParseError: -32700;
|
|
53
|
+
readonly InvalidRequest: -32600;
|
|
54
|
+
readonly MethodNotFound: -32601;
|
|
55
|
+
readonly InvalidParams: -32602;
|
|
56
|
+
readonly InternalError: -32603;
|
|
57
|
+
};
|
|
58
|
+
export type MessageHandler = (message: JsonRpcRequest | JsonRpcNotification) => Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Generic JSON-RPC transport interface — common surface for stdio and socket
|
|
61
|
+
* carriers. Anything below the session layer (initialize, tool dispatch, etc.)
|
|
62
|
+
* talks to this, not to a concrete transport class.
|
|
63
|
+
*/
|
|
64
|
+
export interface JsonRpcTransport {
|
|
65
|
+
start(handler: MessageHandler): void;
|
|
66
|
+
stop(): void;
|
|
67
|
+
send(response: JsonRpcResponse): void;
|
|
68
|
+
notify(method: string, params?: unknown): void;
|
|
69
|
+
request(method: string, params?: unknown, timeoutMs?: number): Promise<unknown>;
|
|
70
|
+
sendResult(id: string | number, result: unknown): void;
|
|
71
|
+
sendError(id: string | number | null, code: number, message: string, data?: unknown): void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Shared implementation of newline-delimited JSON-RPC 2.0 over any
|
|
75
|
+
* `Readable`/`Writable` stream pair. Stdio and socket transports both wrap
|
|
76
|
+
* this — the only difference between them is which streams get plugged in
|
|
77
|
+
* and how a "close" propagates back to the owning code.
|
|
78
|
+
*/
|
|
79
|
+
declare abstract class LineBasedJsonRpcTransport implements JsonRpcTransport {
|
|
80
|
+
protected messageHandler: MessageHandler | null;
|
|
81
|
+
protected pending: Map<string | number, {
|
|
82
|
+
resolve: (value: unknown) => void;
|
|
83
|
+
reject: (error: Error) => void;
|
|
84
|
+
}>;
|
|
85
|
+
protected nextRequestId: number;
|
|
86
|
+
protected stopped: boolean;
|
|
87
|
+
abstract start(handler: MessageHandler): void;
|
|
88
|
+
protected abstract write(line: string): void;
|
|
89
|
+
protected abstract idPrefix(): string;
|
|
90
|
+
abstract stop(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Send a server-initiated request to the client and await its response.
|
|
93
|
+
*
|
|
94
|
+
* MCP is bidirectional: the server can ask the client questions too. We use
|
|
95
|
+
* this for `roots/list` — the spec-blessed way to learn the workspace root
|
|
96
|
+
* when the client didn't pass one in `initialize` (see issue #196). Rejects
|
|
97
|
+
* on timeout so callers can fall back rather than hang forever.
|
|
98
|
+
*/
|
|
99
|
+
request(method: string, params?: unknown, timeoutMs?: number): Promise<unknown>;
|
|
100
|
+
send(response: JsonRpcResponse): void;
|
|
101
|
+
notify(method: string, params?: unknown): void;
|
|
102
|
+
sendResult(id: string | number, result: unknown): void;
|
|
103
|
+
sendError(id: string | number | null, code: number, message: string, data?: unknown): void;
|
|
104
|
+
/**
|
|
105
|
+
* Fail any in-flight server-initiated requests so their awaiters don't hang.
|
|
106
|
+
* Called from `stop()` in subclasses.
|
|
107
|
+
*/
|
|
108
|
+
protected rejectPending(reason: string): void;
|
|
109
|
+
/**
|
|
110
|
+
* Handle an incoming line of JSON. Both transports feed lines here.
|
|
111
|
+
*/
|
|
112
|
+
protected handleLine(line: string): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Resolve (or reject) the pending server-initiated request matching this
|
|
115
|
+
* response's id. Unknown ids are ignored — the client may echo something we
|
|
116
|
+
* never sent, or a request may have already timed out.
|
|
117
|
+
*/
|
|
118
|
+
private handleResponse;
|
|
119
|
+
/**
|
|
120
|
+
* Check if message is a valid JSON-RPC 2.0 message
|
|
121
|
+
*/
|
|
122
|
+
private isValidMessage;
|
|
123
|
+
}
|
|
124
|
+
export interface StdioTransportOptions {
|
|
125
|
+
/**
|
|
126
|
+
* If true, the transport calls `process.exit(0)` when stdin closes. Set to
|
|
127
|
+
* `false` in shared-daemon mode where the stdio "session" is just *one* of
|
|
128
|
+
* many clients — losing it shouldn't drag the daemon down. The default
|
|
129
|
+
* (true) matches the original single-process behavior callers rely on.
|
|
130
|
+
*/
|
|
131
|
+
exitOnClose?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Optional callback fired when the stdin stream closes. The daemon uses
|
|
134
|
+
* this to decrement its connected-clients refcount.
|
|
135
|
+
*/
|
|
136
|
+
onClose?: () => void;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Stdio Transport for MCP
|
|
140
|
+
*
|
|
141
|
+
* Reads JSON-RPC messages from stdin and writes responses to stdout. Used by
|
|
142
|
+
* the direct (single-process) MCP server path, where the MCP host launches
|
|
143
|
+
* one server per session and talks to it over the child's stdio. Also used by
|
|
144
|
+
* shared-daemon mode for the launcher's session (with `exitOnClose: false`)
|
|
145
|
+
* so the daemon outlives its launcher.
|
|
146
|
+
*/
|
|
147
|
+
export declare class StdioTransport extends LineBasedJsonRpcTransport {
|
|
148
|
+
private rl;
|
|
149
|
+
private opts;
|
|
150
|
+
constructor(opts?: StdioTransportOptions);
|
|
151
|
+
start(handler: MessageHandler): void;
|
|
152
|
+
stop(): void;
|
|
153
|
+
protected write(line: string): void;
|
|
154
|
+
protected idPrefix(): string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Socket Transport for MCP daemon sessions.
|
|
158
|
+
*
|
|
159
|
+
* Wraps a single `net.Socket` (Unix domain socket on POSIX, named pipe on
|
|
160
|
+
* Windows). One instance per connected MCP client. Unlike {@link StdioTransport},
|
|
161
|
+
* `stop()` and stream-close *don't* call `process.exit` — a daemon-side session
|
|
162
|
+
* ending must not bring down the whole daemon.
|
|
163
|
+
*/
|
|
164
|
+
export declare class SocketTransport extends LineBasedJsonRpcTransport {
|
|
165
|
+
private socket;
|
|
166
|
+
private prefix;
|
|
167
|
+
private buffer;
|
|
168
|
+
private closeHandlers;
|
|
169
|
+
constructor(socket: Socket, prefix?: string);
|
|
170
|
+
/**
|
|
171
|
+
* Register a callback fired exactly once when the socket closes (from either
|
|
172
|
+
* side). Used by the daemon to decrement its connected-clients refcount.
|
|
173
|
+
*/
|
|
174
|
+
onClose(handler: () => void): void;
|
|
175
|
+
start(handler: MessageHandler): void;
|
|
176
|
+
stop(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Write a one-shot line directly to the socket (no JSON-RPC framing applied
|
|
179
|
+
* by this class — caller produces the line). The daemon uses this for the
|
|
180
|
+
* hello/handshake line that precedes the JSON-RPC stream.
|
|
181
|
+
*/
|
|
182
|
+
writeRaw(line: string): void;
|
|
183
|
+
protected write(line: string): void;
|
|
184
|
+
protected idPrefix(): string;
|
|
185
|
+
private handleSocketClose;
|
|
186
|
+
}
|
|
187
|
+
export {};
|
|
188
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolved package version, computed once at module load.
|
|
3
|
+
*
|
|
4
|
+
* The version string is the rendezvous datum between cooperating daemon and
|
|
5
|
+
* proxy processes: the daemon advertises its version in the hello line, and
|
|
6
|
+
* the proxy refuses to share IPC across a mismatch (falls back to direct
|
|
7
|
+
* mode). Keeping the resolution in one place avoids drift between the CLI
|
|
8
|
+
* `--version` output (which reads `package.json` directly) and the daemon
|
|
9
|
+
* handshake.
|
|
10
|
+
*
|
|
11
|
+
* Resolution strategy: read the bundled `package.json` two levels up from
|
|
12
|
+
* this file — same relative position whether we're loaded from `src/mcp/` or
|
|
13
|
+
* the `dist/mcp/` output, since `tsc` preserves the layout. If reading fails
|
|
14
|
+
* (e.g. the package was unpacked oddly), fall back to "0.0.0-unknown" — a
|
|
15
|
+
* sentinel that will never match a real version, so the proxy harmlessly
|
|
16
|
+
* falls back to direct mode.
|
|
17
|
+
*/
|
|
18
|
+
export declare const CodeGraphPackageVersion: string;
|
|
19
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { QueryBuilder } from '../db/queries';
|
|
2
|
+
import type { ResolutionContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Synthesize dispatcher→callback edges (field observers + EventEmitters +
|
|
5
|
+
* React re-render + JSX children + Vue templates + RN event channel +
|
|
6
|
+
* Fabric native-impl + MyBatis Java↔XML + Gin middleware chain). Returns the
|
|
7
|
+
* count added. Never throws into indexing — callers wrap in try/catch.
|
|
8
|
+
*/
|
|
9
|
+
export declare function synthesizeCallbackEdges(queries: QueryBuilder, ctx: ResolutionContext): number;
|
|
10
|
+
//# sourceMappingURL=callback-synthesizer.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cargo Workspace Resolver Helper
|
|
3
|
+
*
|
|
4
|
+
* Parses a project's root Cargo.toml and member crate manifests to
|
|
5
|
+
* build a crate-name -> member-directory map. Used by the Rust
|
|
6
|
+
* resolver to resolve `use crate_name::...` references that point
|
|
7
|
+
* into workspace member crates.
|
|
8
|
+
*/
|
|
9
|
+
import { ResolutionContext } from '../types';
|
|
10
|
+
/**
|
|
11
|
+
* Build a map from crate-name aliases to workspace member directory paths.
|
|
12
|
+
* Example: "mytool-core" and "mytool_core" -> "crates/mytool-core"
|
|
13
|
+
*
|
|
14
|
+
* Supports glob members (e.g. `members = ["crates/*"]`) via picomatch
|
|
15
|
+
* when the context exposes `listDirectories`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getCargoWorkspaceCrateMap(context: ResolutionContext): Map<string, string>;
|
|
18
|
+
//# sourceMappingURL=cargo-workspace.d.ts.map
|