@ulpi/codemap 0.3.12 → 0.3.14
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 +18 -1
- package/dist/index.js +77 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -183,6 +183,22 @@ codemap cycles
|
|
|
183
183
|
codemap cycles --json
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
+
### `codemap read <file>`
|
|
187
|
+
|
|
188
|
+
Read and return the full source of a file, or a specific line range.
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
codemap read src/routes/auth.ts
|
|
192
|
+
codemap read src/index.ts --from 10 --to 50
|
|
193
|
+
codemap read src/index.ts --json
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
| Option | Description |
|
|
197
|
+
|--------|-------------|
|
|
198
|
+
| `--from <line>` | Start line (1-based, inclusive) |
|
|
199
|
+
| `--to <line>` | End line (1-based, inclusive) |
|
|
200
|
+
| `--json` | Output as JSON (includes filePath, totalLines, from, to, content) |
|
|
201
|
+
|
|
186
202
|
### `codemap summary <file>`
|
|
187
203
|
|
|
188
204
|
Show file overview with symbols and size.
|
|
@@ -424,7 +440,7 @@ Add to `.mcp.json` in your project root:
|
|
|
424
440
|
}
|
|
425
441
|
```
|
|
426
442
|
|
|
427
|
-
`"codemap"` serves the current project automatically. `"codemap-frontend"` serves a different codebase via `--cwd`. Add as many as you need — each gets its own set of
|
|
443
|
+
`"codemap"` serves the current project automatically. `"codemap-frontend"` serves a different codebase via `--cwd`. Add as many as you need — each gets its own set of 13 tools (`search_code`, `read_file`, `get_dependencies`, etc.) scoped to that project.
|
|
428
444
|
|
|
429
445
|
#### Other Editors
|
|
430
446
|
|
|
@@ -436,6 +452,7 @@ Your AI agent will then have access to tools like `search_code`, `get_dependenci
|
|
|
436
452
|
|
|
437
453
|
| Tool | Description |
|
|
438
454
|
|------|-------------|
|
|
455
|
+
| `read_file` | Read full source or a line range (supports `from`/`to` params) |
|
|
439
456
|
| `search_code` | Search code using hybrid vector + BM25 |
|
|
440
457
|
| `search_symbols` | Find functions, classes, and types by name |
|
|
441
458
|
| `get_file_summary` | Get file overview with symbols and size |
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import "./chunk-WR342MP3.js";
|
|
|
5
5
|
import "./chunk-2OBAJYRP.js";
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
|
-
import
|
|
8
|
+
import path15 from "path";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
|
|
11
11
|
// ../../packages/intelligence/codemap-engine/dist/index.js
|
|
@@ -5924,13 +5924,10 @@ function registerInit(program2) {
|
|
|
5924
5924
|
console.log(` ${chalk3.cyan("codemap search")} Search your code`);
|
|
5925
5925
|
console.log(` ${chalk3.cyan("codemap serve")} Start MCP server`);
|
|
5926
5926
|
console.log();
|
|
5927
|
-
|
|
5927
|
+
await showAgentSnippet(program2.opts().cwd || process.cwd());
|
|
5928
5928
|
});
|
|
5929
5929
|
}
|
|
5930
|
-
|
|
5931
|
-
console.log(chalk3.bold("Add to your CLAUDE.md / agents.md / rules:"));
|
|
5932
|
-
console.log(chalk3.dim("\u2500".repeat(60)));
|
|
5933
|
-
console.log(`
|
|
5930
|
+
var AGENT_SNIPPET = `
|
|
5934
5931
|
## Code Intelligence (codemap)
|
|
5935
5932
|
|
|
5936
5933
|
This project is indexed with codemap for semantic code search,
|
|
@@ -5942,6 +5939,7 @@ symbol lookup, dependency analysis, and PageRank file ranking.
|
|
|
5942
5939
|
|------|-------------|
|
|
5943
5940
|
| \`mcp__codemap__search_code\` | Hybrid vector + BM25 semantic code search |
|
|
5944
5941
|
| \`mcp__codemap__search_symbols\` | Find functions, classes, types by name |
|
|
5942
|
+
| \`mcp__codemap__read_file\` | Read full source or a line range (\`from\`/\`to\` params) |
|
|
5945
5943
|
| \`mcp__codemap__get_file_summary\` | File overview with symbols and line count |
|
|
5946
5944
|
| \`mcp__codemap__get_index_stats\` | Index statistics (files, chunks, size) |
|
|
5947
5945
|
| \`mcp__codemap__get_dependencies\` | Files this file imports (outgoing) |
|
|
@@ -5959,6 +5957,7 @@ symbol lookup, dependency analysis, and PageRank file ranking.
|
|
|
5959
5957
|
|---------|-------------|
|
|
5960
5958
|
| \`codemap search <query>\` | Hybrid vector + BM25 semantic code search |
|
|
5961
5959
|
| \`codemap symbols <query>\` | Find functions, classes, types by name |
|
|
5960
|
+
| \`codemap read <file>\` | Read full source or line range (\`--from N --to M\`) |
|
|
5962
5961
|
| \`codemap summary <file>\` | File overview with symbols and line count |
|
|
5963
5962
|
| \`codemap status\` | Index statistics (files, chunks, size) |
|
|
5964
5963
|
| \`codemap deps <file>\` | Files this file imports (outgoing) |
|
|
@@ -5972,14 +5971,39 @@ symbol lookup, dependency analysis, and PageRank file ranking.
|
|
|
5972
5971
|
|
|
5973
5972
|
### When to Use
|
|
5974
5973
|
|
|
5974
|
+
- **Reading files**: \`read_file\` to read full source or a line range (e.g. lines 10\u201350) \u2014 works across all connected projects
|
|
5975
5975
|
- **Before editing**: \`search_code\` or \`search_symbols\` to find relevant files
|
|
5976
5976
|
- **Understanding impact**: \`get_dependents\` to see what breaks if you change a file
|
|
5977
5977
|
- **Architecture review**: \`get_coupling_metrics\` and \`find_cycles\` for code health
|
|
5978
5978
|
- **Navigation**: \`get_file_rank\` to identify the most important files
|
|
5979
|
-
|
|
5979
|
+
- **Cross-project**: Any \`codemap-<name>\` MCP servers (e.g. \`codemap-frontend\`) are connected projects \u2014 use their tools to search and trace dependencies across your stack
|
|
5980
|
+
`.trim();
|
|
5981
|
+
async function showAgentSnippet(projectDir) {
|
|
5982
|
+
console.log(chalk3.bold("Agent configuration snippet:"));
|
|
5983
|
+
console.log(chalk3.dim("\u2500".repeat(60)));
|
|
5984
|
+
console.log(AGENT_SNIPPET);
|
|
5980
5985
|
console.log();
|
|
5981
5986
|
console.log(chalk3.dim("\u2500".repeat(60)));
|
|
5982
|
-
|
|
5987
|
+
const claudeMdPath = path11.join(projectDir, "CLAUDE.md");
|
|
5988
|
+
const exists = fs13.existsSync(claudeMdPath);
|
|
5989
|
+
const prompt = exists ? `Append this to ${chalk3.cyan("CLAUDE.md")}? (Y/n): ` : `Create ${chalk3.cyan("CLAUDE.md")} with this content? (Y/n): `;
|
|
5990
|
+
const answer = await ask(prompt);
|
|
5991
|
+
if (answer.toLowerCase() !== "n") {
|
|
5992
|
+
if (exists) {
|
|
5993
|
+
const current = fs13.readFileSync(claudeMdPath, "utf-8");
|
|
5994
|
+
if (current.includes("## Code Intelligence (codemap)")) {
|
|
5995
|
+
console.log(chalk3.yellow("CLAUDE.md already contains a codemap section. Skipping."));
|
|
5996
|
+
} else {
|
|
5997
|
+
fs13.appendFileSync(claudeMdPath, "\n\n" + AGENT_SNIPPET + "\n");
|
|
5998
|
+
console.log(chalk3.green("Appended to ") + chalk3.cyan("CLAUDE.md"));
|
|
5999
|
+
}
|
|
6000
|
+
} else {
|
|
6001
|
+
fs13.writeFileSync(claudeMdPath, AGENT_SNIPPET + "\n");
|
|
6002
|
+
console.log(chalk3.green("Created ") + chalk3.cyan("CLAUDE.md"));
|
|
6003
|
+
}
|
|
6004
|
+
} else {
|
|
6005
|
+
console.log(chalk3.dim("Skipped. You can copy the snippet above manually."));
|
|
6006
|
+
}
|
|
5983
6007
|
console.log();
|
|
5984
6008
|
console.log(chalk3.bold("Multi-project setup"));
|
|
5985
6009
|
console.log();
|
|
@@ -7222,8 +7246,11 @@ if [ -f "$mcp_file" ]; then
|
|
|
7222
7246
|
for (const [name, config] of Object.entries(servers)) {
|
|
7223
7247
|
if (config.command !== 'codemap') continue;
|
|
7224
7248
|
const args = config.args || [];
|
|
7249
|
+
const env = config.env || {};
|
|
7225
7250
|
const cwdIdx = args.indexOf('--cwd');
|
|
7226
|
-
const cwd = cwdIdx >= 0 && cwdIdx + 1 < args.length
|
|
7251
|
+
const cwd = cwdIdx >= 0 && cwdIdx + 1 < args.length
|
|
7252
|
+
? args[cwdIdx + 1]
|
|
7253
|
+
: (env.CODEMAP_PROJECT_DIR || '');
|
|
7227
7254
|
console.log(name + '|' + cwd);
|
|
7228
7255
|
}
|
|
7229
7256
|
} catch {}
|
|
@@ -7371,9 +7398,47 @@ function uninstall() {
|
|
|
7371
7398
|
console.log(chalk17.dim("Restart Claude Code for changes to take effect."));
|
|
7372
7399
|
}
|
|
7373
7400
|
|
|
7401
|
+
// src/commands/read.ts
|
|
7402
|
+
import chalk18 from "chalk";
|
|
7403
|
+
import fs19 from "fs";
|
|
7404
|
+
import path14 from "path";
|
|
7405
|
+
function registerRead(program2) {
|
|
7406
|
+
program2.command("read <file>").description("Read and return the full source of a file (or a line range)").option("--json", "Output as JSON").option("--from <line>", "Start line (1-based)", parseInt).option("--to <line>", "End line (inclusive)", parseInt).action(async (file, opts) => {
|
|
7407
|
+
const projectDir = program2.opts().cwd || process.cwd();
|
|
7408
|
+
const fullPath = path14.resolve(projectDir, file);
|
|
7409
|
+
if (!fs19.existsSync(fullPath)) {
|
|
7410
|
+
console.error(chalk18.red(`File not found: ${file}`));
|
|
7411
|
+
process.exit(1);
|
|
7412
|
+
return;
|
|
7413
|
+
}
|
|
7414
|
+
const raw = fs19.readFileSync(fullPath, "utf-8");
|
|
7415
|
+
const allLines = raw.split("\n");
|
|
7416
|
+
const totalLines = allLines.length;
|
|
7417
|
+
const from = opts.from ?? 1;
|
|
7418
|
+
const to = opts.to ?? totalLines;
|
|
7419
|
+
const startIdx = Math.max(0, from - 1);
|
|
7420
|
+
const endIdx = Math.min(totalLines, to);
|
|
7421
|
+
const lines = allLines.slice(startIdx, endIdx);
|
|
7422
|
+
const content = lines.join("\n");
|
|
7423
|
+
if (opts.json) {
|
|
7424
|
+
console.log(JSON.stringify({
|
|
7425
|
+
filePath: file,
|
|
7426
|
+
totalLines,
|
|
7427
|
+
from,
|
|
7428
|
+
to: endIdx,
|
|
7429
|
+
lineCount: lines.length,
|
|
7430
|
+
sizeBytes: Buffer.byteLength(content, "utf-8"),
|
|
7431
|
+
content
|
|
7432
|
+
}, null, 2));
|
|
7433
|
+
return;
|
|
7434
|
+
}
|
|
7435
|
+
console.log(content);
|
|
7436
|
+
});
|
|
7437
|
+
}
|
|
7438
|
+
|
|
7374
7439
|
// src/index.ts
|
|
7375
|
-
var __dirname =
|
|
7376
|
-
var grammarsDir =
|
|
7440
|
+
var __dirname = path15.dirname(fileURLToPath(import.meta.url));
|
|
7441
|
+
var grammarsDir = path15.join(__dirname, "grammars");
|
|
7377
7442
|
setGrammarDir(grammarsDir);
|
|
7378
7443
|
var program = new Command();
|
|
7379
7444
|
program.name("codemap").description("Code intelligence CLI \u2014 hybrid search, dependency analysis, PageRank").version("0.3.5").option("--cwd <dir>", "Project directory (default: cwd)");
|
|
@@ -7395,4 +7460,5 @@ registerCoupling(program);
|
|
|
7395
7460
|
registerGraphStats(program);
|
|
7396
7461
|
registerRebuild(program);
|
|
7397
7462
|
registerStatusline(program);
|
|
7463
|
+
registerRead(program);
|
|
7398
7464
|
program.parse();
|