@kridaydave/code-mapper 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +1 -0
- package/bin/code-mapper.mjs +86 -0
- package/dist/graph/GraphAnalyzer.js +32 -65
- package/dist/graph/GraphAnalyzer.js.map +1 -1
- package/dist/graph/GraphBuilder.js +18 -45
- package/dist/graph/GraphBuilder.js.map +1 -1
- package/dist/index.js +100 -23
- package/dist/index.js.map +1 -1
- package/dist/mcp/cache.js +8 -17
- package/dist/mcp/cache.js.map +1 -1
- package/dist/mcp/resources.js +5 -1
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/tools.js +190 -35
- package/dist/mcp/tools.js.map +1 -1
- package/dist/parser/ComplexityAnalyzer.js +19 -2
- package/dist/parser/ComplexityAnalyzer.js.map +1 -1
- package/dist/parser/FileAnalyzer.js +8 -30
- package/dist/parser/FileAnalyzer.js.map +1 -1
- package/dist/parser/ProjectParser.js +8 -5
- package/dist/parser/ProjectParser.js.map +1 -1
- package/dist/parser/ProjectParser.test.js +1 -17
- package/dist/parser/ProjectParser.test.js.map +1 -1
- package/dist/tui/index.js +239 -0
- package/dist/tui/index.js.map +1 -0
- package/package.json +82 -35
- package/AGENTS.md +0 -174
- package/docs/PHASE2_PLAN.md +0 -435
- package/fixtures/test-project/calculator.ts +0 -28
- package/fixtures/test-project/index.ts +0 -2
- package/fixtures/test-project/math.ts +0 -11
- package/src/graph/Graph.test.ts +0 -222
- package/src/graph/GraphAnalyzer.ts +0 -502
- package/src/graph/GraphBuilder.ts +0 -258
- package/src/graph/types.ts +0 -42
- package/src/index.ts +0 -38
- package/src/mcp/cache.ts +0 -89
- package/src/mcp/resources.ts +0 -137
- package/src/mcp/tools.test.ts +0 -104
- package/src/mcp/tools.ts +0 -529
- package/src/parser/ComplexityAnalyzer.ts +0 -275
- package/src/parser/FileAnalyzer.ts +0 -215
- package/src/parser/ProjectParser.test.ts +0 -96
- package/src/parser/ProjectParser.ts +0 -172
- package/src/parser/types.ts +0 -77
- package/src/types/graphology-pagerank.d.ts +0 -20
- package/tsconfig.json +0 -17
- package/vitest.config.ts +0 -15
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { select } from "@inquirer/prompts";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import os from "os";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
const out = (msg) => process.stderr.write((msg ?? "") + "\n");
|
|
8
|
+
const colors = {
|
|
9
|
+
primary: chalk.cyan,
|
|
10
|
+
success: chalk.green,
|
|
11
|
+
warning: chalk.yellow,
|
|
12
|
+
error: chalk.red,
|
|
13
|
+
info: chalk.blue,
|
|
14
|
+
muted: chalk.gray,
|
|
15
|
+
bold: chalk.bold,
|
|
16
|
+
};
|
|
17
|
+
function getPackageRoot() {
|
|
18
|
+
const currentDir = process.cwd();
|
|
19
|
+
if (fs.existsSync(path.join(currentDir, "package.json"))) {
|
|
20
|
+
return currentDir;
|
|
21
|
+
}
|
|
22
|
+
return path.resolve(currentDir, "..");
|
|
23
|
+
}
|
|
24
|
+
function getConfigDir(clientId) {
|
|
25
|
+
const home = os.homedir();
|
|
26
|
+
switch (clientId) {
|
|
27
|
+
case "claude-desktop":
|
|
28
|
+
if (process.platform === "win32") {
|
|
29
|
+
return path.join(home, "AppData", "Roaming", "Claude");
|
|
30
|
+
}
|
|
31
|
+
else if (process.platform === "darwin") {
|
|
32
|
+
return path.join(home, "Library", "Application Support", "Claude");
|
|
33
|
+
}
|
|
34
|
+
return path.join(home, ".config", "Claude");
|
|
35
|
+
case "cursor":
|
|
36
|
+
if (process.platform === "win32") {
|
|
37
|
+
return path.join(home, "AppData", "Roaming", "Cursor", "User", "globalStorage");
|
|
38
|
+
}
|
|
39
|
+
else if (process.platform === "darwin") {
|
|
40
|
+
return path.join(home, "Library", "Application Support", "Cursor", "User", "globalStorage");
|
|
41
|
+
}
|
|
42
|
+
return path.join(home, ".config", "Cursor", "User", "globalStorage");
|
|
43
|
+
case "gemini-cli":
|
|
44
|
+
if (process.platform === "win32") {
|
|
45
|
+
return path.join(home, "AppData", "Roaming", "gemini-cli", "settings");
|
|
46
|
+
}
|
|
47
|
+
else if (process.platform === "darwin") {
|
|
48
|
+
return path.join(home, "Library", "Application Support", "gemini-cli");
|
|
49
|
+
}
|
|
50
|
+
return path.join(home, ".config", "gemini-cli");
|
|
51
|
+
case "claude-code":
|
|
52
|
+
return path.join(home, ".claude");
|
|
53
|
+
case "opencode":
|
|
54
|
+
return path.join(home, ".opencode");
|
|
55
|
+
default:
|
|
56
|
+
return home;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function getMcpConfigPath(clientId) {
|
|
60
|
+
const configDir = getConfigDir(clientId);
|
|
61
|
+
switch (clientId) {
|
|
62
|
+
case "claude-desktop":
|
|
63
|
+
return path.join(configDir, "settings.json");
|
|
64
|
+
case "cursor":
|
|
65
|
+
return path.join(configDir, "mcp.json");
|
|
66
|
+
case "gemini-cli":
|
|
67
|
+
return path.join(configDir, "config.json");
|
|
68
|
+
case "claude-code":
|
|
69
|
+
return path.join(configDir, "settings.json");
|
|
70
|
+
case "opencode":
|
|
71
|
+
return path.join(configDir, "settings.json");
|
|
72
|
+
default:
|
|
73
|
+
return path.join(configDir, "mcp.json");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function detectClients() {
|
|
77
|
+
const clients = [
|
|
78
|
+
{
|
|
79
|
+
id: "claude-desktop",
|
|
80
|
+
name: "Claude Desktop",
|
|
81
|
+
icon: "🧠",
|
|
82
|
+
configPath: getMcpConfigPath("claude-desktop"),
|
|
83
|
+
installed: false,
|
|
84
|
+
description: "Desktop app from Anthropic",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "cursor",
|
|
88
|
+
name: "Cursor",
|
|
89
|
+
icon: "📝",
|
|
90
|
+
configPath: getMcpConfigPath("cursor"),
|
|
91
|
+
installed: false,
|
|
92
|
+
description: "AI-powered code editor",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: "gemini-cli",
|
|
96
|
+
name: "Gemini CLI",
|
|
97
|
+
icon: "🌟",
|
|
98
|
+
configPath: getMcpConfigPath("gemini-cli"),
|
|
99
|
+
installed: false,
|
|
100
|
+
description: "Google's Gemini CLI",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "claude-code",
|
|
104
|
+
name: "Claude Code",
|
|
105
|
+
icon: "💻",
|
|
106
|
+
configPath: getMcpConfigPath("claude-code"),
|
|
107
|
+
installed: false,
|
|
108
|
+
description: "Anthropic's CLI tool",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: "opencode",
|
|
112
|
+
name: "Opencode",
|
|
113
|
+
icon: "🔓",
|
|
114
|
+
configPath: getMcpConfigPath("opencode"),
|
|
115
|
+
installed: false,
|
|
116
|
+
description: "AI coding assistant",
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
for (const client of clients) {
|
|
120
|
+
const configDir = getConfigDir(client.id);
|
|
121
|
+
try {
|
|
122
|
+
client.installed = fs.existsSync(configDir) || fs.existsSync(path.dirname(configDir));
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
client.installed = false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return clients;
|
|
129
|
+
}
|
|
130
|
+
function printWelcomeBanner() {
|
|
131
|
+
console.clear();
|
|
132
|
+
out(colors.primary.bold("╔════════════════════════════════════════════════════════════════╗"));
|
|
133
|
+
out(colors.primary.bold("║ ║"));
|
|
134
|
+
out(colors.primary.bold("║ 📊 CodeMapper MCP Server ║"));
|
|
135
|
+
out(colors.primary.bold("║ ║"));
|
|
136
|
+
out(colors.primary.bold("║ Analyze and visualize your codebase with AI assistance ║"));
|
|
137
|
+
out(colors.primary.bold("║ ║"));
|
|
138
|
+
out(colors.primary.bold("╚════════════════════════════════════════════════════════════════╝"));
|
|
139
|
+
out();
|
|
140
|
+
}
|
|
141
|
+
function printSuccess(message) {
|
|
142
|
+
out(colors.success(` ✓ ${message}`));
|
|
143
|
+
}
|
|
144
|
+
function printError(message) {
|
|
145
|
+
out(colors.error(` ✗ ${message}`));
|
|
146
|
+
}
|
|
147
|
+
function printInfo(message) {
|
|
148
|
+
out(colors.info(` ℹ ${message}`));
|
|
149
|
+
}
|
|
150
|
+
function writeClientConfig(client) {
|
|
151
|
+
try {
|
|
152
|
+
const configDir = path.dirname(client.configPath);
|
|
153
|
+
if (!fs.existsSync(configDir)) {
|
|
154
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
155
|
+
}
|
|
156
|
+
let existingConfig = {};
|
|
157
|
+
if (fs.existsSync(client.configPath)) {
|
|
158
|
+
try {
|
|
159
|
+
const content = fs.readFileSync(client.configPath, "utf-8");
|
|
160
|
+
existingConfig = JSON.parse(content);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
existingConfig = {};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (!existingConfig.mcpServers) {
|
|
167
|
+
existingConfig.mcpServers = {};
|
|
168
|
+
}
|
|
169
|
+
existingConfig.mcpServers["code-mapper"] = {
|
|
170
|
+
command: "npx",
|
|
171
|
+
args: ["code-mapper"],
|
|
172
|
+
};
|
|
173
|
+
fs.writeFileSync(client.configPath, JSON.stringify(existingConfig, null, 2));
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export async function startSetupWizard() {
|
|
181
|
+
printWelcomeBanner();
|
|
182
|
+
out(colors.bold("Detecting AI clients..."));
|
|
183
|
+
out();
|
|
184
|
+
const clients = detectClients();
|
|
185
|
+
const installedClients = clients.filter((c) => c.installed);
|
|
186
|
+
if (installedClients.length === 0) {
|
|
187
|
+
out(colors.warning(" No AI clients detected on your system."));
|
|
188
|
+
out(colors.muted(" CodeMapper will work when you configure it manually."));
|
|
189
|
+
out();
|
|
190
|
+
out(colors.info(" To configure manually, add to your MCP config:"));
|
|
191
|
+
out(colors.primary(' { "mcpServers": { "code-mapper": { "command": "npx", "args": ["code-mapper"] } } }'));
|
|
192
|
+
out();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
out(colors.success(` Found ${installedClients.length} client(s):`));
|
|
196
|
+
for (const client of installedClients) {
|
|
197
|
+
out(colors.success(` ${client.icon} ${client.name}`));
|
|
198
|
+
}
|
|
199
|
+
out();
|
|
200
|
+
const clientOptions = installedClients.map((client) => ({
|
|
201
|
+
name: `${client.icon} ${client.name}`,
|
|
202
|
+
value: client.id,
|
|
203
|
+
description: client.description,
|
|
204
|
+
}));
|
|
205
|
+
const selectedClientId = await select({
|
|
206
|
+
message: "Select a client to configure:",
|
|
207
|
+
choices: clientOptions,
|
|
208
|
+
});
|
|
209
|
+
if (!selectedClientId) {
|
|
210
|
+
out(colors.warning(" No client selected."));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const client = clients.find((c) => c.id === selectedClientId);
|
|
214
|
+
if (client) {
|
|
215
|
+
const success = writeClientConfig(client);
|
|
216
|
+
if (success) {
|
|
217
|
+
out();
|
|
218
|
+
printSuccess(`${client.icon} ${client.name} configured`);
|
|
219
|
+
printInfo(` Config written to: ${client.configPath}`);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
out();
|
|
223
|
+
printError(`${client.icon} ${client.name} - failed to write config`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
out();
|
|
227
|
+
out(colors.success.bold("🎉 Setup Complete!"));
|
|
228
|
+
out();
|
|
229
|
+
out(colors.muted("Your CodeMapper is ready. You can:"));
|
|
230
|
+
out();
|
|
231
|
+
out(colors.info(" 1. Restart your AI client"));
|
|
232
|
+
out(colors.info(' 2. Say: "Scan my codebase" or "Show me the dependency graph"'));
|
|
233
|
+
out();
|
|
234
|
+
out(colors.muted("To re-run this setup anytime:"));
|
|
235
|
+
out(colors.primary(" npx code-mapper --setup"));
|
|
236
|
+
out();
|
|
237
|
+
}
|
|
238
|
+
export default { startSetupWizard };
|
|
239
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tui/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,GAAG,GAAG,CAAC,GAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AAEvE,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,KAAK,CAAC,IAAI;IACnB,OAAO,EAAE,KAAK,CAAC,KAAK;IACpB,OAAO,EAAE,KAAK,CAAC,MAAM;IACrB,KAAK,EAAE,KAAK,CAAC,GAAG;IAChB,IAAI,EAAE,KAAK,CAAC,IAAI;IAChB,KAAK,EAAE,KAAK,CAAC,IAAI;IACjB,IAAI,EAAE,KAAK,CAAC,IAAI;CACjB,CAAC;AAWF,SAAS,cAAc;IACrB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACjC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;QACzD,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,YAAY,CAAC,QAAgB;IACpC,MAAM,IAAI,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,CAAC;IAC9D,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,OAAO,EAAE,CAAC;YACZ,GAAG,EAAE,CAAC;YACN,YAAY,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,aAAa,CAAC,CAAC;YACzD,SAAS,CAAC,wBAAwB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,GAAG,EAAE,CAAC;YACN,UAAU,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,2BAA2B,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,GAAG,EAAE,CAAC;IACN,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAC/C,GAAG,EAAE,CAAC;IACN,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC;IACxD,GAAG,EAAE,CAAC;IACN,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,CAAC;IAChD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,gEAAgE,CAAC,CAAC,CAAC;IACnF,GAAG,EAAE,CAAC;IACN,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;IACnD,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC;IACjD,GAAG,EAAE,CAAC;AACR,CAAC;AAED,eAAe,EAAE,gBAAgB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,35 +1,82 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@kridaydave/code-mapper",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "MCP server for codebase mapping and analysis with graph visualization",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"bin": {
|
|
8
|
-
"code-mapper": "./
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"start": "node dist/index.js",
|
|
13
|
-
"dev": "tsx src/index.ts",
|
|
14
|
-
"typecheck": "tsc --noEmit",
|
|
15
|
-
"test": "vitest run",
|
|
16
|
-
"test:watch": "vitest",
|
|
17
|
-
"test:cover": "vitest run --coverage"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
}
|
|
35
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@kridaydave/code-mapper",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "MCP server for codebase mapping and analysis with graph visualization",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"code-mapper": "./bin/code-mapper.mjs"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"start": "node dist/index.js",
|
|
13
|
+
"dev": "tsx src/index.ts",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"test": "vitest run",
|
|
16
|
+
"test:watch": "vitest",
|
|
17
|
+
"test:cover": "vitest run --coverage",
|
|
18
|
+
"setup": "node dist/tui/index.js",
|
|
19
|
+
"prepublishOnly": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"mcp",
|
|
23
|
+
"mcp-server",
|
|
24
|
+
"code-mapper",
|
|
25
|
+
"code-analysis",
|
|
26
|
+
"typescript",
|
|
27
|
+
"graph-visualization"
|
|
28
|
+
],
|
|
29
|
+
"author": "kridaydave",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/kridaydave/code-mapper.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/kridaydave/code-mapper/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/kridaydave/code-mapper#readme",
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@cfworker/json-schema": "^4.1.1",
|
|
41
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
42
|
+
"@inquirer/prompts": "^8.2.0",
|
|
43
|
+
"chalk": "^5.6.2",
|
|
44
|
+
"graphology": "^0.25.0",
|
|
45
|
+
"graphology-metrics": "^2.4.0",
|
|
46
|
+
"graphology-pagerank": "^1.1.0",
|
|
47
|
+
"graphology-shortest-path": "^2.1.0",
|
|
48
|
+
"ink": "^5.2.1",
|
|
49
|
+
"react": "^19.2.4",
|
|
50
|
+
"ts-morph": "^24.0.0",
|
|
51
|
+
"zod": "^4.0.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^22.0.0",
|
|
55
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
56
|
+
"tsx": "^4.19.0",
|
|
57
|
+
"typescript": "^5.6.0",
|
|
58
|
+
"vitest": "^4.1.2"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=18.0.0"
|
|
62
|
+
},
|
|
63
|
+
"os": [
|
|
64
|
+
"win32",
|
|
65
|
+
"darwin",
|
|
66
|
+
"linux"
|
|
67
|
+
],
|
|
68
|
+
"cpu": [
|
|
69
|
+
"x64",
|
|
70
|
+
"arm64"
|
|
71
|
+
],
|
|
72
|
+
"files": [
|
|
73
|
+
"bin",
|
|
74
|
+
"dist",
|
|
75
|
+
"README.md",
|
|
76
|
+
"LICENSE",
|
|
77
|
+
"CHANGELOG.md"
|
|
78
|
+
],
|
|
79
|
+
"publishConfig": {
|
|
80
|
+
"access": "public"
|
|
81
|
+
}
|
|
82
|
+
}
|
package/AGENTS.md
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
# Codebase Cartographer Agent Guidelines
|
|
2
|
-
|
|
3
|
-
## Build, Lint, and Test Commands
|
|
4
|
-
|
|
5
|
-
### Build Commands
|
|
6
|
-
- `npm run build` - Compiles TypeScript to JavaScript using tsc
|
|
7
|
-
- Output directory: ./dist (configured in tsconfig.json)
|
|
8
|
-
- Entry point: dist/index.js
|
|
9
|
-
|
|
10
|
-
### Development Commands
|
|
11
|
-
- `npm run dev` - Runs the MCP server directly with tsx for development
|
|
12
|
-
- Uses tsx for instant TypeScript execution without compilation
|
|
13
|
-
- Primary development workflow
|
|
14
|
-
|
|
15
|
-
### Production Commands
|
|
16
|
-
- `npm start` - Runs the compiled JavaScript from dist/index.js
|
|
17
|
-
- Used after running npm run build
|
|
18
|
-
|
|
19
|
-
### Testing Guidelines
|
|
20
|
-
No existing test framework is configured in this repository. For adding tests:
|
|
21
|
-
|
|
22
|
-
1. **Recommended Setup**:
|
|
23
|
-
```bash
|
|
24
|
-
npm install --save-dev vitest @vitest/coverage-v8
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
2. **Add to package.json**:
|
|
28
|
-
```json
|
|
29
|
-
"scripts": {
|
|
30
|
-
"test": "vitest run",
|
|
31
|
-
"test:watch": "vitest",
|
|
32
|
-
"test:cover": "vitest run --coverage"
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
3. **Test File Convention**:
|
|
37
|
-
- Place tests in __tests__ directory or alongside source files with .test.ts suffix
|
|
38
|
-
- Example: src/mcp/tools.test.ts
|
|
39
|
-
|
|
40
|
-
4. **Running Specific Tests**:
|
|
41
|
-
- Single test file: `npx vitest src/mcp/tools.test.ts`
|
|
42
|
-
- Test with pattern: `npx vitest run -t "scan_codebase"`
|
|
43
|
-
|
|
44
|
-
### Type Checking
|
|
45
|
-
- `npx tsc --noEmit` - Performs type checking without emitting files
|
|
46
|
-
- Already enabled via "strict": true in tsconfig.json
|
|
47
|
-
- Run as part of CI/CD pipeline
|
|
48
|
-
|
|
49
|
-
## Code Style Guidelines
|
|
50
|
-
|
|
51
|
-
### Import Order
|
|
52
|
-
1. Node.js built-in modules (`node:path`, `node:fs`)
|
|
53
|
-
2. External libraries (`@modelcontextprotocol/server`, `zod`, `ts-morph`)
|
|
54
|
-
3. Internal project imports (relative paths)
|
|
55
|
-
4. Sort alphabetically within each group
|
|
56
|
-
5. Prefer named imports over default imports when practical
|
|
57
|
-
|
|
58
|
-
Example:
|
|
59
|
-
```typescript
|
|
60
|
-
import { resolve } from "node:path";
|
|
61
|
-
import * as fs from "node:fs";
|
|
62
|
-
import { McpServer } from "@modelcontextprotocol/server";
|
|
63
|
-
import { z } from "zod";
|
|
64
|
-
import { ProjectParser } from "../parser/ProjectParser.js";
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Formatting
|
|
68
|
-
- Indentation: 2 spaces
|
|
69
|
-
- Line width: Maximum 100 characters (soft limit)
|
|
70
|
-
- Semicolons: Required
|
|
71
|
-
- Quotes: Single quotes for strings
|
|
72
|
-
- Trailing commas: Multiline objects and arrays
|
|
73
|
-
- Function spacing: Empty line between function declarations
|
|
74
|
-
- Brace style: Opening brace on same line, closing brace on new line
|
|
75
|
-
|
|
76
|
-
### Types and Interfaces
|
|
77
|
-
- Prefer interfaces for object shapes that may be extended
|
|
78
|
-
- Use type aliases for unions, primitives, and mapped types
|
|
79
|
-
- Enable strict null checks (`strict`: true in tsconfig)
|
|
80
|
-
- Explicit return types for exported functions
|
|
81
|
-
- Use `unknown` instead of `any` when type is truly unknown
|
|
82
|
-
- Specify generic constraints when possible
|
|
83
|
-
|
|
84
|
-
Example:
|
|
85
|
-
```typescript
|
|
86
|
-
interface FileInfo {
|
|
87
|
-
relativePath: string;
|
|
88
|
-
functions: FunctionInfo[];
|
|
89
|
-
classes: ClassInfo[];
|
|
90
|
-
imports: ImportInfo[];
|
|
91
|
-
exports: ExportInfo[];
|
|
92
|
-
totalLines: number;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
type GraphCallback = (node: GraphNode) => boolean | void;
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Naming Conventions
|
|
99
|
-
- Variables and functions: camelCase
|
|
100
|
-
- Classes and interfaces: PascalCase
|
|
101
|
-
- Constants: UPPER_SNAKE_CASE
|
|
102
|
-
- File names: kebab-case (.ts files)
|
|
103
|
-
- Acronyms: Treat as normal words (e.g., "getNodeID" not "getNodeId")
|
|
104
|
-
- Private properties: No underscore prefix (use TypeScript privacy modifiers)
|
|
105
|
-
|
|
106
|
-
Example:
|
|
107
|
-
```typescript
|
|
108
|
-
class ProjectParser {
|
|
109
|
-
private cache: Map<string, ParseResult> = new Map();
|
|
110
|
-
|
|
111
|
-
async parse(directory: string): Promise<ParseResult> {
|
|
112
|
-
// implementation
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private findFiles(directory: string): string[] {
|
|
116
|
-
// implementation
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Error Handling
|
|
122
|
-
- Use try/catch for asynchronous operations
|
|
123
|
-
- Provide meaningful error messages with context
|
|
124
|
-
- Don't catch errors unless you can handle or enhance them
|
|
125
|
-
- For MCP tools, errors are automatically caught and returned as error content
|
|
126
|
-
- Validate inputs early using Zod schemas (already implemented)
|
|
127
|
-
- Process exits with non-zero code for unrecoverable errors (see index.ts)
|
|
128
|
-
|
|
129
|
-
### Comments and Documentation
|
|
130
|
-
- JSDoc comments for all exported functions and classes
|
|
131
|
-
- Explain non-obvious logic with inline comments
|
|
132
|
-
- Keep comments up-to-date when modifying code
|
|
133
|
-
- Use TODO: and FIXME: comments for tracking work
|
|
134
|
-
- Document complex type manipulations
|
|
135
|
-
|
|
136
|
-
Example:
|
|
137
|
-
```typescript
|
|
138
|
-
/**
|
|
139
|
-
* Scans a directory and returns a summary of all files, functions, classes, and their relationships.
|
|
140
|
-
* Use this first before any other analysis.
|
|
141
|
-
*/
|
|
142
|
-
server.registerTool("scan_codebase", {
|
|
143
|
-
// ...
|
|
144
|
-
});
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Project-Specific Patterns
|
|
148
|
-
- MCP tool registration follows consistent pattern in tools.ts
|
|
149
|
-
- Shared cache pattern used in mcp/cache.ts for analyzer instances
|
|
150
|
-
- Error handling in main() function with process.exit(1) for fatal errors
|
|
151
|
-
- Shebang line in index.ts for direct execution
|
|
152
|
-
- Graph algorithms separated from MCP interface layer
|
|
153
|
-
- Parsing and analysis layers clearly separated
|
|
154
|
-
|
|
155
|
-
### Dependency Management
|
|
156
|
-
- Keep dependencies up-to-date with `npm update`
|
|
157
|
-
- Audit for vulnerabilities with `npm audit`
|
|
158
|
-
- Peer dependencies not used in this project
|
|
159
|
-
- Dev dependencies limited to TypeScript tooling
|
|
160
|
-
|
|
161
|
-
## MCP Protocol Implementation
|
|
162
|
-
All MCP tools follow this pattern:
|
|
163
|
-
1. Define tool name, description, and input/output schemas using Zod
|
|
164
|
-
2. Implement handler function with proper async/await
|
|
165
|
-
3. Return structured content with text and structuredContent fields
|
|
166
|
-
4. Handle edge cases (empty results, not found, etc.)
|
|
167
|
-
5. Use analyzer cache to avoid reprocessing same directories
|
|
168
|
-
|
|
169
|
-
## File Organization
|
|
170
|
-
- src/index.ts - MCP server entry point
|
|
171
|
-
- src/mcp/ - MCP-specific code (tools, resources, caching)
|
|
172
|
-
- src/parser/ - TS-Morph based code analysis
|
|
173
|
-
- src/graph/ - Graph theory algorithms and data structures
|
|
174
|
-
- Separation of concerns between parsing, analysis, and MCP interface
|