@stupidloud/codegraph 0.7.7
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/LICENSE +21 -0
- package/README.md +482 -0
- package/dist/bin/codegraph.d.ts +21 -0
- package/dist/bin/codegraph.d.ts.map +1 -0
- package/dist/bin/codegraph.js +1296 -0
- package/dist/bin/codegraph.js.map +1 -0
- package/dist/bin/node-version-check.d.ts +17 -0
- package/dist/bin/node-version-check.d.ts.map +1 -0
- package/dist/bin/node-version-check.js +39 -0
- package/dist/bin/node-version-check.js.map +1 -0
- package/dist/bin/uninstall.d.ts +14 -0
- package/dist/bin/uninstall.d.ts.map +1 -0
- package/dist/bin/uninstall.js +148 -0
- package/dist/bin/uninstall.js.map +1 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +342 -0
- package/dist/config.js.map +1 -0
- package/dist/context/formatter.d.ts +30 -0
- package/dist/context/formatter.d.ts.map +1 -0
- package/dist/context/formatter.js +244 -0
- package/dist/context/formatter.js.map +1 -0
- package/dist/context/index.d.ts +99 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +1075 -0
- package/dist/context/index.js.map +1 -0
- package/dist/db/index.d.ts +72 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +200 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/migrations.d.ts +44 -0
- package/dist/db/migrations.d.ts.map +1 -0
- package/dist/db/migrations.js +160 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/db/queries.d.ts +253 -0
- package/dist/db/queries.d.ts.map +1 -0
- package/dist/db/queries.js +1202 -0
- package/dist/db/queries.js.map +1 -0
- package/dist/db/schema.sql +169 -0
- package/dist/db/sqlite-adapter.d.ts +52 -0
- package/dist/db/sqlite-adapter.d.ts.map +1 -0
- package/dist/db/sqlite-adapter.js +237 -0
- package/dist/db/sqlite-adapter.js.map +1 -0
- package/dist/directory.d.ts +57 -0
- package/dist/directory.d.ts.map +1 -0
- package/dist/directory.js +264 -0
- package/dist/directory.js.map +1 -0
- package/dist/errors.d.ts +136 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +219 -0
- package/dist/errors.js.map +1 -0
- package/dist/extraction/dfm-extractor.d.ts +31 -0
- package/dist/extraction/dfm-extractor.d.ts.map +1 -0
- package/dist/extraction/dfm-extractor.js +151 -0
- package/dist/extraction/dfm-extractor.js.map +1 -0
- package/dist/extraction/grammars.d.ts +78 -0
- package/dist/extraction/grammars.d.ts.map +1 -0
- package/dist/extraction/grammars.js +322 -0
- package/dist/extraction/grammars.js.map +1 -0
- package/dist/extraction/index.d.ts +130 -0
- package/dist/extraction/index.d.ts.map +1 -0
- package/dist/extraction/index.js +1279 -0
- package/dist/extraction/index.js.map +1 -0
- package/dist/extraction/languages/c-cpp.d.ts +4 -0
- package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
- package/dist/extraction/languages/c-cpp.js +126 -0
- package/dist/extraction/languages/c-cpp.js.map +1 -0
- package/dist/extraction/languages/csharp.d.ts +3 -0
- package/dist/extraction/languages/csharp.d.ts.map +1 -0
- package/dist/extraction/languages/csharp.js +72 -0
- package/dist/extraction/languages/csharp.js.map +1 -0
- package/dist/extraction/languages/dart.d.ts +3 -0
- package/dist/extraction/languages/dart.d.ts.map +1 -0
- package/dist/extraction/languages/dart.js +192 -0
- package/dist/extraction/languages/dart.js.map +1 -0
- package/dist/extraction/languages/go.d.ts +3 -0
- package/dist/extraction/languages/go.d.ts.map +1 -0
- package/dist/extraction/languages/go.js +58 -0
- package/dist/extraction/languages/go.js.map +1 -0
- package/dist/extraction/languages/index.d.ts +10 -0
- package/dist/extraction/languages/index.d.ts.map +1 -0
- package/dist/extraction/languages/index.js +45 -0
- package/dist/extraction/languages/index.js.map +1 -0
- package/dist/extraction/languages/java.d.ts +3 -0
- package/dist/extraction/languages/java.d.ts.map +1 -0
- package/dist/extraction/languages/java.js +64 -0
- package/dist/extraction/languages/java.js.map +1 -0
- package/dist/extraction/languages/javascript.d.ts +3 -0
- package/dist/extraction/languages/javascript.d.ts.map +1 -0
- package/dist/extraction/languages/javascript.js +90 -0
- package/dist/extraction/languages/javascript.js.map +1 -0
- package/dist/extraction/languages/kotlin.d.ts +3 -0
- package/dist/extraction/languages/kotlin.d.ts.map +1 -0
- package/dist/extraction/languages/kotlin.js +253 -0
- package/dist/extraction/languages/kotlin.js.map +1 -0
- package/dist/extraction/languages/pascal.d.ts +3 -0
- package/dist/extraction/languages/pascal.d.ts.map +1 -0
- package/dist/extraction/languages/pascal.js +66 -0
- package/dist/extraction/languages/pascal.js.map +1 -0
- package/dist/extraction/languages/php.d.ts +3 -0
- package/dist/extraction/languages/php.d.ts.map +1 -0
- package/dist/extraction/languages/php.js +107 -0
- package/dist/extraction/languages/php.js.map +1 -0
- package/dist/extraction/languages/python.d.ts +3 -0
- package/dist/extraction/languages/python.d.ts.map +1 -0
- package/dist/extraction/languages/python.js +56 -0
- package/dist/extraction/languages/python.js.map +1 -0
- package/dist/extraction/languages/ruby.d.ts +3 -0
- package/dist/extraction/languages/ruby.d.ts.map +1 -0
- package/dist/extraction/languages/ruby.js +114 -0
- package/dist/extraction/languages/ruby.js.map +1 -0
- package/dist/extraction/languages/rust.d.ts +3 -0
- package/dist/extraction/languages/rust.d.ts.map +1 -0
- package/dist/extraction/languages/rust.js +109 -0
- package/dist/extraction/languages/rust.js.map +1 -0
- package/dist/extraction/languages/scala.d.ts +3 -0
- package/dist/extraction/languages/scala.d.ts.map +1 -0
- package/dist/extraction/languages/scala.js +139 -0
- package/dist/extraction/languages/scala.js.map +1 -0
- package/dist/extraction/languages/swift.d.ts +3 -0
- package/dist/extraction/languages/swift.d.ts.map +1 -0
- package/dist/extraction/languages/swift.js +91 -0
- package/dist/extraction/languages/swift.js.map +1 -0
- package/dist/extraction/languages/typescript.d.ts +3 -0
- package/dist/extraction/languages/typescript.d.ts.map +1 -0
- package/dist/extraction/languages/typescript.js +129 -0
- package/dist/extraction/languages/typescript.js.map +1 -0
- package/dist/extraction/liquid-extractor.d.ts +52 -0
- package/dist/extraction/liquid-extractor.d.ts.map +1 -0
- package/dist/extraction/liquid-extractor.js +313 -0
- package/dist/extraction/liquid-extractor.js.map +1 -0
- package/dist/extraction/parse-worker.d.ts +8 -0
- package/dist/extraction/parse-worker.d.ts.map +1 -0
- package/dist/extraction/parse-worker.js +94 -0
- package/dist/extraction/parse-worker.js.map +1 -0
- package/dist/extraction/svelte-extractor.d.ts +56 -0
- package/dist/extraction/svelte-extractor.d.ts.map +1 -0
- package/dist/extraction/svelte-extractor.js +272 -0
- package/dist/extraction/svelte-extractor.js.map +1 -0
- package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
- package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
- package/dist/extraction/tree-sitter-helpers.js +103 -0
- package/dist/extraction/tree-sitter-helpers.js.map +1 -0
- package/dist/extraction/tree-sitter-types.d.ts +179 -0
- package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
- package/dist/extraction/tree-sitter-types.js +10 -0
- package/dist/extraction/tree-sitter-types.js.map +1 -0
- package/dist/extraction/tree-sitter.d.ts +233 -0
- package/dist/extraction/tree-sitter.d.ts.map +1 -0
- package/dist/extraction/tree-sitter.js +2393 -0
- package/dist/extraction/tree-sitter.js.map +1 -0
- package/dist/extraction/vue-extractor.d.ts +36 -0
- package/dist/extraction/vue-extractor.d.ts.map +1 -0
- package/dist/extraction/vue-extractor.js +163 -0
- package/dist/extraction/vue-extractor.js.map +1 -0
- package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
- package/dist/graph/index.d.ts +8 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +13 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/queries.d.ts +106 -0
- package/dist/graph/queries.d.ts.map +1 -0
- package/dist/graph/queries.js +366 -0
- package/dist/graph/queries.js.map +1 -0
- package/dist/graph/traversal.d.ts +127 -0
- package/dist/graph/traversal.d.ts.map +1 -0
- package/dist/graph/traversal.js +493 -0
- package/dist/graph/traversal.js.map +1 -0
- package/dist/index.d.ts +504 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +982 -0
- package/dist/index.js.map +1 -0
- package/dist/installer/claude-md-template.d.ts +10 -0
- package/dist/installer/claude-md-template.d.ts.map +1 -0
- package/dist/installer/claude-md-template.js +46 -0
- package/dist/installer/claude-md-template.js.map +1 -0
- package/dist/installer/config-writer.d.ts +36 -0
- package/dist/installer/config-writer.d.ts.map +1 -0
- package/dist/installer/config-writer.js +304 -0
- package/dist/installer/config-writer.js.map +1 -0
- package/dist/installer/index.d.ts +12 -0
- package/dist/installer/index.d.ts.map +1 -0
- package/dist/installer/index.js +201 -0
- package/dist/installer/index.js.map +1 -0
- package/dist/mcp/index.d.ts +82 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +330 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server-instructions.d.ts +19 -0
- package/dist/mcp/server-instructions.d.ts.map +1 -0
- package/dist/mcp/server-instructions.js +59 -0
- package/dist/mcp/server-instructions.js.map +1 -0
- package/dist/mcp/tools.d.ts +187 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +1250 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/transport.d.ts +89 -0
- package/dist/mcp/transport.d.ts.map +1 -0
- package/dist/mcp/transport.js +170 -0
- package/dist/mcp/transport.js.map +1 -0
- package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
- package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
- package/dist/resolution/frameworks/cargo-workspace.js +225 -0
- package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
- package/dist/resolution/frameworks/csharp.d.ts +8 -0
- package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
- package/dist/resolution/frameworks/csharp.js +213 -0
- package/dist/resolution/frameworks/csharp.js.map +1 -0
- package/dist/resolution/frameworks/express.d.ts +8 -0
- package/dist/resolution/frameworks/express.d.ts.map +1 -0
- package/dist/resolution/frameworks/express.js +225 -0
- package/dist/resolution/frameworks/express.js.map +1 -0
- package/dist/resolution/frameworks/go.d.ts +8 -0
- package/dist/resolution/frameworks/go.d.ts.map +1 -0
- package/dist/resolution/frameworks/go.js +158 -0
- package/dist/resolution/frameworks/go.js.map +1 -0
- package/dist/resolution/frameworks/index.d.ts +41 -0
- package/dist/resolution/frameworks/index.d.ts.map +1 -0
- package/dist/resolution/frameworks/index.js +129 -0
- package/dist/resolution/frameworks/index.js.map +1 -0
- package/dist/resolution/frameworks/java.d.ts +8 -0
- package/dist/resolution/frameworks/java.d.ts.map +1 -0
- package/dist/resolution/frameworks/java.js +177 -0
- package/dist/resolution/frameworks/java.js.map +1 -0
- package/dist/resolution/frameworks/laravel.d.ts +13 -0
- package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
- package/dist/resolution/frameworks/laravel.js +248 -0
- package/dist/resolution/frameworks/laravel.js.map +1 -0
- package/dist/resolution/frameworks/python.d.ts +10 -0
- package/dist/resolution/frameworks/python.d.ts.map +1 -0
- package/dist/resolution/frameworks/python.js +278 -0
- package/dist/resolution/frameworks/python.js.map +1 -0
- package/dist/resolution/frameworks/react.d.ts +8 -0
- package/dist/resolution/frameworks/react.d.ts.map +1 -0
- package/dist/resolution/frameworks/react.js +272 -0
- package/dist/resolution/frameworks/react.js.map +1 -0
- package/dist/resolution/frameworks/ruby.d.ts +8 -0
- package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
- package/dist/resolution/frameworks/ruby.js +198 -0
- package/dist/resolution/frameworks/ruby.js.map +1 -0
- package/dist/resolution/frameworks/rust.d.ts +8 -0
- package/dist/resolution/frameworks/rust.d.ts.map +1 -0
- package/dist/resolution/frameworks/rust.js +207 -0
- package/dist/resolution/frameworks/rust.js.map +1 -0
- package/dist/resolution/frameworks/svelte.d.ts +9 -0
- package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
- package/dist/resolution/frameworks/svelte.js +249 -0
- package/dist/resolution/frameworks/svelte.js.map +1 -0
- package/dist/resolution/frameworks/swift.d.ts +10 -0
- package/dist/resolution/frameworks/swift.d.ts.map +1 -0
- package/dist/resolution/frameworks/swift.js +376 -0
- package/dist/resolution/frameworks/swift.js.map +1 -0
- package/dist/resolution/frameworks/vue.d.ts +9 -0
- package/dist/resolution/frameworks/vue.d.ts.map +1 -0
- package/dist/resolution/frameworks/vue.js +306 -0
- package/dist/resolution/frameworks/vue.js.map +1 -0
- package/dist/resolution/import-resolver.d.ts +40 -0
- package/dist/resolution/import-resolver.d.ts.map +1 -0
- package/dist/resolution/import-resolver.js +663 -0
- package/dist/resolution/import-resolver.js.map +1 -0
- package/dist/resolution/index.d.ts +106 -0
- package/dist/resolution/index.d.ts.map +1 -0
- package/dist/resolution/index.js +709 -0
- package/dist/resolution/index.js.map +1 -0
- package/dist/resolution/name-matcher.d.ts +32 -0
- package/dist/resolution/name-matcher.d.ts.map +1 -0
- package/dist/resolution/name-matcher.js +384 -0
- package/dist/resolution/name-matcher.js.map +1 -0
- package/dist/resolution/path-aliases.d.ts +68 -0
- package/dist/resolution/path-aliases.d.ts.map +1 -0
- package/dist/resolution/path-aliases.js +238 -0
- package/dist/resolution/path-aliases.js.map +1 -0
- package/dist/resolution/strip-comments.d.ts +27 -0
- package/dist/resolution/strip-comments.d.ts.map +1 -0
- package/dist/resolution/strip-comments.js +441 -0
- package/dist/resolution/strip-comments.js.map +1 -0
- package/dist/resolution/types.d.ts +172 -0
- package/dist/resolution/types.d.ts.map +1 -0
- package/dist/resolution/types.js +8 -0
- package/dist/resolution/types.js.map +1 -0
- package/dist/search/query-parser.d.ts +57 -0
- package/dist/search/query-parser.d.ts.map +1 -0
- package/dist/search/query-parser.js +177 -0
- package/dist/search/query-parser.js.map +1 -0
- package/dist/search/query-utils.d.ts +53 -0
- package/dist/search/query-utils.d.ts.map +1 -0
- package/dist/search/query-utils.js +347 -0
- package/dist/search/query-utils.js.map +1 -0
- package/dist/sync/index.d.ts +13 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +17 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/watcher.d.ts +81 -0
- package/dist/sync/watcher.d.ts.map +1 -0
- package/dist/sync/watcher.js +184 -0
- package/dist/sync/watcher.js.map +1 -0
- package/dist/types.d.ts +438 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +263 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/shimmer-progress.d.ts +11 -0
- package/dist/ui/shimmer-progress.d.ts.map +1 -0
- package/dist/ui/shimmer-progress.js +90 -0
- package/dist/ui/shimmer-progress.js.map +1 -0
- package/dist/ui/shimmer-worker.d.ts +2 -0
- package/dist/ui/shimmer-worker.d.ts.map +1 -0
- package/dist/ui/shimmer-worker.js +112 -0
- package/dist/ui/shimmer-worker.js.map +1 -0
- package/dist/ui/types.d.ts +17 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui/types.js +3 -0
- package/dist/ui/types.js.map +1 -0
- package/dist/utils.d.ts +205 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +549 -0
- package/dist/utils.js.map +1 -0
- package/dist/vectors/embedder.d.ts +121 -0
- package/dist/vectors/embedder.d.ts.map +1 -0
- package/dist/vectors/embedder.js +237 -0
- package/dist/vectors/embedder.js.map +1 -0
- package/dist/vectors/index.d.ts +9 -0
- package/dist/vectors/index.d.ts.map +1 -0
- package/dist/vectors/index.js +20 -0
- package/dist/vectors/index.js.map +1 -0
- package/dist/vectors/manager.d.ts +124 -0
- package/dist/vectors/manager.d.ts.map +1 -0
- package/dist/vectors/manager.js +322 -0
- package/dist/vectors/manager.js.map +1 -0
- package/dist/vectors/search.d.ts +143 -0
- package/dist/vectors/search.d.ts.map +1 -0
- package/dist/vectors/search.js +460 -0
- package/dist/vectors/search.js.map +1 -0
- package/dist/visualizer/public/index.html +1994 -0
- package/dist/visualizer/server.d.ts +46 -0
- package/dist/visualizer/server.d.ts.map +1 -0
- package/dist/visualizer/server.js +491 -0
- package/dist/visualizer/server.js.map +1 -0
- package/package.json +60 -0
- package/scripts/patch-tree-sitter-dart.js +112 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CodeGraph Interactive Installer
|
|
4
|
+
*
|
|
5
|
+
* Uses @clack/prompts for a polished interactive CLI experience.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.runInstaller = runInstaller;
|
|
42
|
+
const child_process_1 = require("child_process");
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const config_writer_1 = require("./config-writer");
|
|
46
|
+
// Dynamic import helper — tsc compiles import() to require() in CJS mode,
|
|
47
|
+
// which fails for ESM-only packages. This bypasses the transformation.
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
49
|
+
const importESM = new Function('specifier', 'return import(specifier)');
|
|
50
|
+
/**
|
|
51
|
+
* Format a number with commas
|
|
52
|
+
*/
|
|
53
|
+
function formatNumber(n) {
|
|
54
|
+
return n.toLocaleString();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the package version
|
|
58
|
+
*/
|
|
59
|
+
function getVersion() {
|
|
60
|
+
try {
|
|
61
|
+
const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
|
|
62
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
63
|
+
return packageJson.version;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return '0.0.0';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Run the interactive installer
|
|
71
|
+
*/
|
|
72
|
+
async function runInstaller() {
|
|
73
|
+
const clack = await importESM('@clack/prompts');
|
|
74
|
+
clack.intro(`CodeGraph v${getVersion()}`);
|
|
75
|
+
// Step 1: Install globally
|
|
76
|
+
const shouldInstallGlobally = await clack.confirm({
|
|
77
|
+
message: 'Install codegraph globally? (Required for MCP server)',
|
|
78
|
+
initialValue: true,
|
|
79
|
+
});
|
|
80
|
+
if (clack.isCancel(shouldInstallGlobally)) {
|
|
81
|
+
clack.cancel('Installation cancelled.');
|
|
82
|
+
process.exit(0);
|
|
83
|
+
}
|
|
84
|
+
if (shouldInstallGlobally) {
|
|
85
|
+
const s = clack.spinner();
|
|
86
|
+
s.start('Installing codegraph globally...');
|
|
87
|
+
try {
|
|
88
|
+
(0, child_process_1.execSync)('npm install -g @stupidloud/codegraph', { stdio: 'pipe' });
|
|
89
|
+
s.stop('Installed codegraph globally');
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
s.stop('Could not install globally (permission denied)');
|
|
93
|
+
clack.log.warn('Try: sudo npm install -g @stupidloud/codegraph');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
clack.log.info('Skipped global install — MCP server may not work without it');
|
|
98
|
+
}
|
|
99
|
+
// Step 2: Installation location
|
|
100
|
+
const location = await clack.select({
|
|
101
|
+
message: 'Where would you like to install?',
|
|
102
|
+
options: [
|
|
103
|
+
{ value: 'global', label: 'Global', hint: '~/.claude — available in all projects' },
|
|
104
|
+
{ value: 'local', label: 'Local', hint: './.claude — this project only' },
|
|
105
|
+
],
|
|
106
|
+
initialValue: 'global',
|
|
107
|
+
});
|
|
108
|
+
if (clack.isCancel(location)) {
|
|
109
|
+
clack.cancel('Installation cancelled.');
|
|
110
|
+
process.exit(0);
|
|
111
|
+
}
|
|
112
|
+
// Step 3: Auto-allow permissions
|
|
113
|
+
const autoAllow = await clack.confirm({
|
|
114
|
+
message: 'Auto-allow CodeGraph commands? (Skips permission prompts)',
|
|
115
|
+
initialValue: true,
|
|
116
|
+
});
|
|
117
|
+
if (clack.isCancel(autoAllow)) {
|
|
118
|
+
clack.cancel('Installation cancelled.');
|
|
119
|
+
process.exit(0);
|
|
120
|
+
}
|
|
121
|
+
// Step 4: Write configuration files
|
|
122
|
+
writeConfigs(clack, location, autoAllow);
|
|
123
|
+
// Step 5: For local install, initialize the project
|
|
124
|
+
if (location === 'local') {
|
|
125
|
+
await initializeLocalProject(clack);
|
|
126
|
+
}
|
|
127
|
+
// Done
|
|
128
|
+
if (location === 'global') {
|
|
129
|
+
clack.note('cd your-project\ncodegraph init -i', 'Quick start');
|
|
130
|
+
}
|
|
131
|
+
clack.outro('Done! Restart Claude Code to use CodeGraph.');
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Write all configuration files and log results
|
|
135
|
+
*/
|
|
136
|
+
function writeConfigs(clack, location, autoAllow) {
|
|
137
|
+
const locationLabel = location === 'global' ? '~/.claude' : './.claude';
|
|
138
|
+
// MCP config
|
|
139
|
+
const mcpAction = (0, config_writer_1.hasMcpConfig)(location) ? 'Updated' : 'Added';
|
|
140
|
+
(0, config_writer_1.writeMcpConfig)(location);
|
|
141
|
+
clack.log.success(`${mcpAction} MCP server in ${locationLabel}.json`);
|
|
142
|
+
// Permissions
|
|
143
|
+
if (autoAllow) {
|
|
144
|
+
const permAction = (0, config_writer_1.hasPermissions)(location) ? 'Updated' : 'Added';
|
|
145
|
+
(0, config_writer_1.writePermissions)(location);
|
|
146
|
+
clack.log.success(`${permAction} permissions in ${locationLabel}/settings.json`);
|
|
147
|
+
}
|
|
148
|
+
// CLAUDE.md
|
|
149
|
+
const claudeMdResult = (0, config_writer_1.writeClaudeMd)(location);
|
|
150
|
+
const claudeMdPath = `${locationLabel}/CLAUDE.md`;
|
|
151
|
+
if (claudeMdResult.created) {
|
|
152
|
+
clack.log.success(`Created ${claudeMdPath}`);
|
|
153
|
+
}
|
|
154
|
+
else if (claudeMdResult.updated) {
|
|
155
|
+
clack.log.success(`Updated ${claudeMdPath}`);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
clack.log.success(`Added CodeGraph instructions to ${claudeMdPath}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Initialize CodeGraph in the current project (for local installs)
|
|
163
|
+
*/
|
|
164
|
+
async function initializeLocalProject(clack) {
|
|
165
|
+
const projectPath = process.cwd();
|
|
166
|
+
// Lazy-load CodeGraph (requires native modules)
|
|
167
|
+
let CodeGraph;
|
|
168
|
+
try {
|
|
169
|
+
CodeGraph = (await Promise.resolve().then(() => __importStar(require('../index')))).default;
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
173
|
+
clack.log.error(`Could not load native modules: ${msg}`);
|
|
174
|
+
clack.log.info('Skipping project initialization. Run "codegraph init -i" later.');
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
// Check if already initialized
|
|
178
|
+
if (CodeGraph.isInitialized(projectPath)) {
|
|
179
|
+
clack.log.info('CodeGraph already initialized in this project');
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// Initialize
|
|
183
|
+
const cg = await CodeGraph.init(projectPath);
|
|
184
|
+
clack.log.success('Created .codegraph/ directory');
|
|
185
|
+
// Index the project with shimmer progress (worker thread for smooth animation)
|
|
186
|
+
const { createShimmerProgress } = await Promise.resolve().then(() => __importStar(require('../ui/shimmer-progress')));
|
|
187
|
+
process.stdout.write(`\x1b[2m│\x1b[0m\n`);
|
|
188
|
+
const progress = createShimmerProgress();
|
|
189
|
+
const result = await cg.indexAll({
|
|
190
|
+
onProgress: progress.onProgress,
|
|
191
|
+
});
|
|
192
|
+
await progress.stop();
|
|
193
|
+
if (result.filesErrored > 0) {
|
|
194
|
+
clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files (${formatNumber(result.filesErrored)} failed, ${formatNumber(result.nodesCreated)} symbols)`);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files (${formatNumber(result.nodesCreated)} symbols)`);
|
|
198
|
+
}
|
|
199
|
+
cg.close();
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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IACT,CAAC;IAED,aAAa;IACb,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC7C,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;IAEnD,+EAA+E;IAC/E,MAAM,EAAE,qBAAqB,EAAE,GAAG,wDAAa,wBAAwB,GAAC,CAAC;IACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAC;IAEzC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC;QAC/B,UAAU,EAAE,QAAQ,CAAC,UAAU;KAChC,CAAC,CAAC;IAEH,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEtB,IAAI,MAAM,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;QAC5B,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,YAAY,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IACtK,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IACzH,CAAC;IAED,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CodeGraph MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Model Context Protocol server that exposes CodeGraph functionality
|
|
5
|
+
* as tools for AI assistants like Claude.
|
|
6
|
+
*
|
|
7
|
+
* @module mcp
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { MCPServer } from 'codegraph';
|
|
12
|
+
*
|
|
13
|
+
* const server = new MCPServer('/path/to/project');
|
|
14
|
+
* await server.start();
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* MCP Server for CodeGraph
|
|
19
|
+
*
|
|
20
|
+
* Implements the Model Context Protocol to expose CodeGraph
|
|
21
|
+
* functionality as tools that can be called by AI assistants.
|
|
22
|
+
*/
|
|
23
|
+
export declare class MCPServer {
|
|
24
|
+
private transport;
|
|
25
|
+
private cg;
|
|
26
|
+
private toolHandler;
|
|
27
|
+
private projectPath;
|
|
28
|
+
constructor(projectPath?: string);
|
|
29
|
+
/**
|
|
30
|
+
* Start the MCP server
|
|
31
|
+
*
|
|
32
|
+
* Note: CodeGraph initialization is deferred until the initialize request
|
|
33
|
+
* is received, which includes the rootUri from the client.
|
|
34
|
+
*/
|
|
35
|
+
start(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Try to initialize CodeGraph for the default project.
|
|
38
|
+
*
|
|
39
|
+
* Walks up parent directories to find the nearest .codegraph/ folder,
|
|
40
|
+
* similar to how git finds .git/ directories.
|
|
41
|
+
*
|
|
42
|
+
* If initialization fails, the error is recorded but the server continues
|
|
43
|
+
* to work — cross-project queries and retries on subsequent tool calls
|
|
44
|
+
* are still possible.
|
|
45
|
+
*/
|
|
46
|
+
private tryInitializeDefault;
|
|
47
|
+
/**
|
|
48
|
+
* Retry initialization of the default project if it previously failed.
|
|
49
|
+
* Called lazily on tool calls that need the default project.
|
|
50
|
+
* Re-walks parent directories each time so it picks up projects
|
|
51
|
+
* initialized after the MCP server started.
|
|
52
|
+
*/
|
|
53
|
+
private retryInitIfNeeded;
|
|
54
|
+
/**
|
|
55
|
+
* Start file watching on the active CodeGraph instance.
|
|
56
|
+
* Logs sync activity to stderr for diagnostics.
|
|
57
|
+
*/
|
|
58
|
+
private startWatching;
|
|
59
|
+
/**
|
|
60
|
+
* Stop the server
|
|
61
|
+
*/
|
|
62
|
+
stop(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Handle incoming JSON-RPC messages
|
|
65
|
+
*/
|
|
66
|
+
private handleMessage;
|
|
67
|
+
/**
|
|
68
|
+
* Handle initialize request
|
|
69
|
+
*/
|
|
70
|
+
private handleInitialize;
|
|
71
|
+
/**
|
|
72
|
+
* Handle tools/list request
|
|
73
|
+
*/
|
|
74
|
+
private handleToolsList;
|
|
75
|
+
/**
|
|
76
|
+
* Handle tools/call request
|
|
77
|
+
*/
|
|
78
|
+
private handleToolsCall;
|
|
79
|
+
}
|
|
80
|
+
export { StdioTransport } from './transport';
|
|
81
|
+
export { tools, ToolHandler } from './tools';
|
|
82
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,SAAS,CAAiB;IAClC,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAAgB;gBAEvB,WAAW,CAAC,EAAE,MAAM;IAOhC;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAe5B;;;;;;;;;OASG;YACW,oBAAoB;IAsBlC;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAwBzB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAqBrB;;OAEG;IACH,IAAI,IAAI,IAAI;IAYZ;;OAEG;YACW,aAAa;IA6C3B;;OAEG;YACW,gBAAgB;IAqC9B;;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"}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CodeGraph MCP Server
|
|
4
|
+
*
|
|
5
|
+
* Model Context Protocol server that exposes CodeGraph functionality
|
|
6
|
+
* as tools for AI assistants like Claude.
|
|
7
|
+
*
|
|
8
|
+
* @module mcp
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { MCPServer } from 'codegraph';
|
|
13
|
+
*
|
|
14
|
+
* const server = new MCPServer('/path/to/project');
|
|
15
|
+
* await server.start();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
23
|
+
}
|
|
24
|
+
Object.defineProperty(o, k2, desc);
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
35
|
+
var ownKeys = function(o) {
|
|
36
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
37
|
+
var ar = [];
|
|
38
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
39
|
+
return ar;
|
|
40
|
+
};
|
|
41
|
+
return ownKeys(o);
|
|
42
|
+
};
|
|
43
|
+
return function (mod) {
|
|
44
|
+
if (mod && mod.__esModule) return mod;
|
|
45
|
+
var result = {};
|
|
46
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
47
|
+
__setModuleDefault(result, mod);
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
})();
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
exports.ToolHandler = exports.tools = exports.StdioTransport = exports.MCPServer = void 0;
|
|
53
|
+
const path = __importStar(require("path"));
|
|
54
|
+
const index_1 = __importStar(require("../index"));
|
|
55
|
+
const transport_1 = require("./transport");
|
|
56
|
+
const tools_1 = require("./tools");
|
|
57
|
+
const server_instructions_1 = require("./server-instructions");
|
|
58
|
+
/**
|
|
59
|
+
* Convert a file:// URI to a filesystem path.
|
|
60
|
+
* Handles URL encoding and Windows drive letter paths.
|
|
61
|
+
*/
|
|
62
|
+
function fileUriToPath(uri) {
|
|
63
|
+
try {
|
|
64
|
+
const url = new URL(uri);
|
|
65
|
+
let filePath = decodeURIComponent(url.pathname);
|
|
66
|
+
// On Windows, file:///C:/path produces pathname /C:/path — strip leading /
|
|
67
|
+
if (process.platform === 'win32' && /^\/[a-zA-Z]:/.test(filePath)) {
|
|
68
|
+
filePath = filePath.slice(1);
|
|
69
|
+
}
|
|
70
|
+
return path.resolve(filePath);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Fallback for non-standard URIs
|
|
74
|
+
return uri.replace(/^file:\/\/\/?/, '');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* MCP Server Info
|
|
79
|
+
*/
|
|
80
|
+
const SERVER_INFO = {
|
|
81
|
+
name: 'codegraph',
|
|
82
|
+
version: '0.1.0',
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* MCP Protocol Version
|
|
86
|
+
*/
|
|
87
|
+
const PROTOCOL_VERSION = '2024-11-05';
|
|
88
|
+
/**
|
|
89
|
+
* MCP Server for CodeGraph
|
|
90
|
+
*
|
|
91
|
+
* Implements the Model Context Protocol to expose CodeGraph
|
|
92
|
+
* functionality as tools that can be called by AI assistants.
|
|
93
|
+
*/
|
|
94
|
+
class MCPServer {
|
|
95
|
+
transport;
|
|
96
|
+
cg = null;
|
|
97
|
+
toolHandler;
|
|
98
|
+
projectPath;
|
|
99
|
+
constructor(projectPath) {
|
|
100
|
+
this.projectPath = projectPath || null;
|
|
101
|
+
this.transport = new transport_1.StdioTransport();
|
|
102
|
+
// Create ToolHandler eagerly — cross-project queries work even without a default project
|
|
103
|
+
this.toolHandler = new tools_1.ToolHandler(null);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Start the MCP server
|
|
107
|
+
*
|
|
108
|
+
* Note: CodeGraph initialization is deferred until the initialize request
|
|
109
|
+
* is received, which includes the rootUri from the client.
|
|
110
|
+
*/
|
|
111
|
+
async start() {
|
|
112
|
+
// Start listening for messages immediately - don't check initialization yet
|
|
113
|
+
// We'll get the project path from the initialize request's rootUri
|
|
114
|
+
this.transport.start(this.handleMessage.bind(this));
|
|
115
|
+
// Keep the process running
|
|
116
|
+
process.on('SIGINT', () => this.stop());
|
|
117
|
+
process.on('SIGTERM', () => this.stop());
|
|
118
|
+
// When the parent process (Claude Code) exits, stdin closes.
|
|
119
|
+
// Detect this and shut down gracefully to prevent orphaned processes.
|
|
120
|
+
process.stdin.on('end', () => this.stop());
|
|
121
|
+
process.stdin.on('close', () => this.stop());
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Try to initialize CodeGraph for the default project.
|
|
125
|
+
*
|
|
126
|
+
* Walks up parent directories to find the nearest .codegraph/ folder,
|
|
127
|
+
* similar to how git finds .git/ directories.
|
|
128
|
+
*
|
|
129
|
+
* If initialization fails, the error is recorded but the server continues
|
|
130
|
+
* to work — cross-project queries and retries on subsequent tool calls
|
|
131
|
+
* are still possible.
|
|
132
|
+
*/
|
|
133
|
+
async tryInitializeDefault(projectPath) {
|
|
134
|
+
// Walk up parent directories to find nearest .codegraph/
|
|
135
|
+
const resolvedRoot = (0, index_1.findNearestCodeGraphRoot)(projectPath);
|
|
136
|
+
if (!resolvedRoot) {
|
|
137
|
+
this.projectPath = projectPath;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this.projectPath = resolvedRoot;
|
|
141
|
+
try {
|
|
142
|
+
this.cg = await index_1.default.open(resolvedRoot);
|
|
143
|
+
this.toolHandler.setDefaultCodeGraph(this.cg);
|
|
144
|
+
this.startWatching();
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
// Log the error so transient failures are diagnosable (see issue #47)
|
|
148
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
149
|
+
process.stderr.write(`[CodeGraph MCP] Failed to open project at ${resolvedRoot}: ${msg}\n`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Retry initialization of the default project if it previously failed.
|
|
154
|
+
* Called lazily on tool calls that need the default project.
|
|
155
|
+
* Re-walks parent directories each time so it picks up projects
|
|
156
|
+
* initialized after the MCP server started.
|
|
157
|
+
*/
|
|
158
|
+
retryInitIfNeeded() {
|
|
159
|
+
// Already initialized successfully
|
|
160
|
+
if (this.toolHandler.hasDefaultCodeGraph())
|
|
161
|
+
return;
|
|
162
|
+
// No project path to retry with
|
|
163
|
+
if (!this.projectPath)
|
|
164
|
+
return;
|
|
165
|
+
const resolvedRoot = (0, index_1.findNearestCodeGraphRoot)(this.projectPath);
|
|
166
|
+
if (!resolvedRoot)
|
|
167
|
+
return;
|
|
168
|
+
try {
|
|
169
|
+
// Close any previously failed instance to avoid leaking resources
|
|
170
|
+
if (this.cg) {
|
|
171
|
+
try {
|
|
172
|
+
this.cg.close();
|
|
173
|
+
}
|
|
174
|
+
catch { /* ignore */ }
|
|
175
|
+
this.cg = null;
|
|
176
|
+
}
|
|
177
|
+
this.cg = index_1.default.openSync(resolvedRoot);
|
|
178
|
+
this.projectPath = resolvedRoot;
|
|
179
|
+
this.toolHandler.setDefaultCodeGraph(this.cg);
|
|
180
|
+
this.startWatching();
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// Still failing — will retry on next tool call
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Start file watching on the active CodeGraph instance.
|
|
188
|
+
* Logs sync activity to stderr for diagnostics.
|
|
189
|
+
*/
|
|
190
|
+
startWatching() {
|
|
191
|
+
if (!this.cg)
|
|
192
|
+
return;
|
|
193
|
+
const started = this.cg.watch({
|
|
194
|
+
onSyncComplete: (result) => {
|
|
195
|
+
if (result.filesChanged > 0) {
|
|
196
|
+
process.stderr.write(`[CodeGraph MCP] Auto-synced ${result.filesChanged} file(s) in ${result.durationMs}ms\n`);
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
onSyncError: (err) => {
|
|
200
|
+
process.stderr.write(`[CodeGraph MCP] Auto-sync error: ${err.message}\n`);
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
if (started) {
|
|
204
|
+
process.stderr.write('[CodeGraph MCP] File watcher active — graph will auto-sync on changes\n');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Stop the server
|
|
209
|
+
*/
|
|
210
|
+
stop() {
|
|
211
|
+
// Close all cached cross-project connections first
|
|
212
|
+
this.toolHandler.closeAll();
|
|
213
|
+
// Close the main CodeGraph instance
|
|
214
|
+
if (this.cg) {
|
|
215
|
+
this.cg.close();
|
|
216
|
+
this.cg = null;
|
|
217
|
+
}
|
|
218
|
+
this.transport.stop();
|
|
219
|
+
process.exit(0);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Handle incoming JSON-RPC messages
|
|
223
|
+
*/
|
|
224
|
+
async handleMessage(message) {
|
|
225
|
+
// Check if it's a request (has id) or notification (no id)
|
|
226
|
+
const isRequest = 'id' in message;
|
|
227
|
+
switch (message.method) {
|
|
228
|
+
case 'initialize':
|
|
229
|
+
if (isRequest) {
|
|
230
|
+
await this.handleInitialize(message);
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
case 'initialized':
|
|
234
|
+
// Notification that client has finished initialization
|
|
235
|
+
// No action needed - the client is ready
|
|
236
|
+
break;
|
|
237
|
+
case 'tools/list':
|
|
238
|
+
if (isRequest) {
|
|
239
|
+
await this.handleToolsList(message);
|
|
240
|
+
}
|
|
241
|
+
break;
|
|
242
|
+
case 'tools/call':
|
|
243
|
+
if (isRequest) {
|
|
244
|
+
await this.handleToolsCall(message);
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
case 'ping':
|
|
248
|
+
if (isRequest) {
|
|
249
|
+
this.transport.sendResult(message.id, {});
|
|
250
|
+
}
|
|
251
|
+
break;
|
|
252
|
+
default:
|
|
253
|
+
if (isRequest) {
|
|
254
|
+
this.transport.sendError(message.id, transport_1.ErrorCodes.MethodNotFound, `Method not found: ${message.method}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Handle initialize request
|
|
260
|
+
*/
|
|
261
|
+
async handleInitialize(request) {
|
|
262
|
+
const params = request.params;
|
|
263
|
+
// Extract project path from rootUri or workspaceFolders
|
|
264
|
+
let projectPath = this.projectPath;
|
|
265
|
+
if (params?.rootUri) {
|
|
266
|
+
projectPath = fileUriToPath(params.rootUri);
|
|
267
|
+
}
|
|
268
|
+
else if (params?.workspaceFolders?.[0]?.uri) {
|
|
269
|
+
projectPath = fileUriToPath(params.workspaceFolders[0].uri);
|
|
270
|
+
}
|
|
271
|
+
// Fall back to current working directory if no path provided
|
|
272
|
+
if (!projectPath) {
|
|
273
|
+
projectPath = process.cwd();
|
|
274
|
+
}
|
|
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 automatically — it's the right place for the universal tool-selection
|
|
280
|
+
// playbook, ahead of individual tool descriptions.
|
|
281
|
+
this.transport.sendResult(request.id, {
|
|
282
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
283
|
+
capabilities: {
|
|
284
|
+
tools: {},
|
|
285
|
+
},
|
|
286
|
+
serverInfo: SERVER_INFO,
|
|
287
|
+
instructions: server_instructions_1.SERVER_INSTRUCTIONS,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Handle tools/list request
|
|
292
|
+
*/
|
|
293
|
+
async handleToolsList(request) {
|
|
294
|
+
this.retryInitIfNeeded();
|
|
295
|
+
this.transport.sendResult(request.id, {
|
|
296
|
+
tools: this.toolHandler.getTools(),
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Handle tools/call request
|
|
301
|
+
*/
|
|
302
|
+
async handleToolsCall(request) {
|
|
303
|
+
const params = request.params;
|
|
304
|
+
if (!params || !params.name) {
|
|
305
|
+
this.transport.sendError(request.id, transport_1.ErrorCodes.InvalidParams, 'Missing tool name');
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const toolName = params.name;
|
|
309
|
+
const toolArgs = params.arguments || {};
|
|
310
|
+
// Validate tool exists
|
|
311
|
+
const tool = tools_1.tools.find(t => t.name === toolName);
|
|
312
|
+
if (!tool) {
|
|
313
|
+
this.transport.sendError(request.id, transport_1.ErrorCodes.InvalidParams, `Unknown tool: ${toolName}`);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
// If the default project isn't initialized yet, retry in case it was
|
|
317
|
+
// initialized after the MCP server started (e.g. user ran codegraph init)
|
|
318
|
+
this.retryInitIfNeeded();
|
|
319
|
+
const result = await this.toolHandler.execute(toolName, toolArgs);
|
|
320
|
+
this.transport.sendResult(request.id, result);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
exports.MCPServer = MCPServer;
|
|
324
|
+
// Export for use in CLI
|
|
325
|
+
var transport_2 = require("./transport");
|
|
326
|
+
Object.defineProperty(exports, "StdioTransport", { enumerable: true, get: function () { return transport_2.StdioTransport; } });
|
|
327
|
+
var tools_2 = require("./tools");
|
|
328
|
+
Object.defineProperty(exports, "tools", { enumerable: true, get: function () { return tools_2.tools; } });
|
|
329
|
+
Object.defineProperty(exports, "ToolHandler", { enumerable: true, get: function () { return tools_2.ToolHandler; } });
|
|
330
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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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B,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,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEzB,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;AAlRD,8BAkRC;AAED,wBAAwB;AACxB,yCAA6C;AAApC,2GAAA,cAAc,OAAA;AACvB,iCAA6C;AAApC,8FAAA,KAAK,OAAA;AAAE,oGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-level instructions emitted in the MCP `initialize` response.
|
|
3
|
+
*
|
|
4
|
+
* MCP clients (Claude Code, Cursor, opencode, LangChain, OpenAI Agent
|
|
5
|
+
* SDK, …) surface this text in the agent's system prompt automatically,
|
|
6
|
+
* giving the agent a high-level playbook for the codegraph toolset
|
|
7
|
+
* before it sees individual tool descriptions.
|
|
8
|
+
*
|
|
9
|
+
* Goals when editing this:
|
|
10
|
+
* - Tool selection by intent (which tool for which question)
|
|
11
|
+
* - Common chains (refactor planning = X then Y)
|
|
12
|
+
* - Anti-patterns (don't grep when codegraph_search is faster)
|
|
13
|
+
*
|
|
14
|
+
* Keep it tight. The agent reads this every session — long instructions
|
|
15
|
+
* burn tokens. Reference only tools that exist on `main`; gate any
|
|
16
|
+
* conditional tools behind feature checks if/when they ship.
|
|
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";
|
|
19
|
+
//# sourceMappingURL=server-instructions.d.ts.map
|
|
@@ -0,0 +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"}
|