@prubbs88/codebase-cartographer 0.0.0-stage → 0.1.0
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 +106 -2
- package/dist/ask.d.ts +20 -0
- package/dist/ask.js +93 -0
- package/dist/ask.js.map +1 -0
- package/dist/graph/analysis.d.ts +2 -0
- package/dist/graph/analysis.js +8 -0
- package/dist/graph/analysis.js.map +1 -0
- package/dist/graph/rank.d.ts +9 -0
- package/dist/graph/rank.js +173 -0
- package/dist/graph/rank.js.map +1 -0
- package/dist/graph/resolve.d.ts +11 -0
- package/dist/graph/resolve.js +299 -0
- package/dist/graph/resolve.js.map +1 -0
- package/dist/graph/serialize.d.ts +16 -0
- package/dist/graph/serialize.js +38 -0
- package/dist/graph/serialize.js.map +1 -0
- package/dist/graph/types.d.ts +64 -0
- package/dist/graph/types.js +2 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +101 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/client.d.ts +13 -0
- package/dist/llm/client.js +46 -0
- package/dist/llm/client.js.map +1 -0
- package/dist/output/map.d.ts +2 -0
- package/dist/output/map.js +38 -0
- package/dist/output/map.js.map +1 -0
- package/dist/output/report.d.ts +22 -0
- package/dist/output/report.js +198 -0
- package/dist/output/report.js.map +1 -0
- package/dist/output/stats.d.ts +2 -0
- package/dist/output/stats.js +51 -0
- package/dist/output/stats.js.map +1 -0
- package/dist/parser/python.d.ts +2 -0
- package/dist/parser/python.js +366 -0
- package/dist/parser/python.js.map +1 -0
- package/dist/retrieval/chunk.d.ts +16 -0
- package/dist/retrieval/chunk.js +88 -0
- package/dist/retrieval/chunk.js.map +1 -0
- package/dist/retrieval/local-embed.d.ts +4 -0
- package/dist/retrieval/local-embed.js +53 -0
- package/dist/retrieval/local-embed.js.map +1 -0
- package/dist/retrieval/retrieve.d.ts +12 -0
- package/dist/retrieval/retrieve.js +85 -0
- package/dist/retrieval/retrieve.js.map +1 -0
- package/dist/scan.d.ts +2 -0
- package/dist/scan.js +46 -0
- package/dist/scan.js.map +1 -0
- package/dist/utils/module-name.d.ts +2 -0
- package/dist/utils/module-name.js +14 -0
- package/dist/utils/module-name.js.map +1 -0
- package/docs/benchmark.md +68 -0
- package/package.json +63 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieve.js","sourceRoot":"","sources":["../../src/retrieval/retrieve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAa1E,MAAM,UAAU,WAAW,CACzB,MAAe,EACf,UAA6B;IAE7B,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QACtD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE;YAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC5E,OAAO,KAAK,CAAC;IACf,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,MAAM;QAAE,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,QAAQ,CACtB,MAAe,EACf,QAAgB,EAChB,iBAA2B,EAC3B,IAAI,GAAG,CAAC,EACR,cAAc,GAAG,CAAC;IAElB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAqB,EAAE,CAAC;IAEpC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,K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C,CAAC,IAAI,EAAE,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/scan.d.ts
ADDED
package/dist/scan.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parsePythonFile } from "./parser/python.js";
|
|
4
|
+
const SKIP_DIRS = new Set([
|
|
5
|
+
".git", "node_modules", "__pycache__", ".venv", "venv", "env",
|
|
6
|
+
"dist", "build", ".tox", ".mypy_cache", ".pytest_cache", ".carto",
|
|
7
|
+
"site-packages", ".eggs", "eggs",
|
|
8
|
+
]);
|
|
9
|
+
export function scanPythonFiles(rootDir) {
|
|
10
|
+
const files = [];
|
|
11
|
+
const walk = (dir) => {
|
|
12
|
+
let entries;
|
|
13
|
+
try {
|
|
14
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
if (entry.isDirectory()) {
|
|
21
|
+
if (SKIP_DIRS.has(entry.name) || entry.name.endsWith(".egg-info"))
|
|
22
|
+
continue;
|
|
23
|
+
walk(path.join(dir, entry.name));
|
|
24
|
+
}
|
|
25
|
+
else if (entry.isFile() && entry.name.endsWith(".py")) {
|
|
26
|
+
const abs = path.join(dir, entry.name);
|
|
27
|
+
const rel = path.relative(rootDir, abs).split(path.sep).join("/");
|
|
28
|
+
files.push({ abs, rel });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
walk(rootDir);
|
|
33
|
+
files.sort((a, b) => a.rel.localeCompare(b.rel));
|
|
34
|
+
const parsed = [];
|
|
35
|
+
for (const { abs, rel } of files) {
|
|
36
|
+
try {
|
|
37
|
+
const source = fs.readFileSync(abs, "utf8");
|
|
38
|
+
parsed.push(parsePythonFile(abs, rel, source));
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
process.stderr.write(`warn: failed to parse ${rel}: ${err instanceof Error ? err.message : err}\n`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=scan.js.map
|
package/dist/scan.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../src/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK;IAC7D,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ;IACjE,eAAe,EAAE,OAAO,EAAE,MAAM;CACjC,CAAC,CAAC;AAEH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,MAAM,KAAK,GAAmC,EAAE,CAAC;IAEjD,MAAM,IAAI,GAAG,CAAC,GAAW,EAAQ,EAAE;QACjC,IAAI,OAAoB,CAAC;QACzB,IAAI,CAAC;YACH,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;QACT,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxB,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IA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GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACtG,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function toDottedModuleName(relPath) {
|
|
2
|
+
const withoutExt = relPath.replace(/\.py$/, "");
|
|
3
|
+
const parts = withoutExt.split("/");
|
|
4
|
+
if (parts[parts.length - 1] === "__init__")
|
|
5
|
+
parts.pop();
|
|
6
|
+
return parts.filter(Boolean).join(".");
|
|
7
|
+
}
|
|
8
|
+
export function packageOf(moduleName, isPackage) {
|
|
9
|
+
const parts = moduleName.split(".").filter(Boolean);
|
|
10
|
+
if (isPackage)
|
|
11
|
+
return parts;
|
|
12
|
+
return parts.slice(0, -1);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=module-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-name.js","sourceRoot":"","sources":["../../src/utils/module-name.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,UAAU;QAAE,KAAK,CAAC,GAAG,EAAE,CAAC;IACxD,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,UAAkB,EAAE,SAAkB;IAC9D,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Benchmark: fixed-window RAG vs. symbol-aware chunking vs. + call-graph expansion
|
|
2
|
+
|
|
3
|
+
**Date:** December 2025 · **Engine version:** 0.1.0 (Sprint 2) · **Retriever:** offline local hash embeddings (identical across all configs)
|
|
4
|
+
|
|
5
|
+
## Question
|
|
6
|
+
|
|
7
|
+
Naive RAG on codebases chunks files into fixed-size windows and retrieves by embedding
|
|
8
|
+
similarity. Cartographer instead chunks on **symbol boundaries** (function/class with its
|
|
9
|
+
call-graph context) and expands retrieval through the **call graph**. How much does that
|
|
10
|
+
matter for the core onboarding task: *"where in this codebase does X happen?"*
|
|
11
|
+
|
|
12
|
+
## Method
|
|
13
|
+
|
|
14
|
+
- **Repos:** [pallets/click](https://github.com/pallets/click), [pallets/flask](https://github.com/pallets/flask), [encode/django-rest-framework](https://github.com/encode/django-rest-framework) — 35 questions total, 11–12 per repo
|
|
15
|
+
- **Gold answers:** one specific symbol per question (e.g. `Flask.full_dispatch_request`), verified to exist in the parsed symbol table; harness fails loudly if a gold is missing
|
|
16
|
+
- **Configs:**
|
|
17
|
+
- `naive-window-rag` — 60-line windows (10-line overlap), embedding similarity only
|
|
18
|
+
- `carto-chunks` — symbol chunks with call-graph context, hybrid vector+lexical+role scoring, no expansion
|
|
19
|
+
- `carto-chunks+graph` — same, plus top matches pull in their callers/callees
|
|
20
|
+
- **All three use the same embedding function** (256-dim local hash TF vectors), isolating the effect of chunking and graph structure from embedding quality
|
|
21
|
+
- **Metrics:** MRR over the gold symbol; hit@k = fraction of questions where a chunk overlapping the gold symbol appears in the top k
|
|
22
|
+
|
|
23
|
+
## Results
|
|
24
|
+
|
|
25
|
+
| repo | questions | config | MRR | hit@1 | hit@3 | hit@5 | hit@10 | parse (s) |
|
|
26
|
+
|---|---|---|---|---|---|---|---|---|
|
|
27
|
+
| click | 11 | naive-window-rag | 0.156 | 0 | 2 | 3 | 5 | 0.6 |
|
|
28
|
+
| click | 11 | carto-chunks | 0.340 | 2 | 4 | 6 | 9 | 0.6 |
|
|
29
|
+
| click | 11 | carto-chunks+graph | 0.347 | 2 | 4 | 6 | 9 | 0.6 |
|
|
30
|
+
| flask | 12 | naive-window-rag | 0.280 | 1 | 4 | 6 | 8 | 0.1 |
|
|
31
|
+
| flask | 12 | carto-chunks | 0.522 | 2 | 11 | 11 | 12 | 0.1 |
|
|
32
|
+
| flask | 12 | carto-chunks+graph | 0.522 | 2 | 11 | 11 | 12 | 0.1 |
|
|
33
|
+
| django-rest-framework | 12 | naive-window-rag | 0.101 | 0 | 2 | 3 | 3 | 1.2 |
|
|
34
|
+
| django-rest-framework | 12 | carto-chunks | 0.294 | 2 | 5 | 6 | 6 | 1.2 |
|
|
35
|
+
| django-rest-framework | 12 | carto-chunks+graph | 0.294 | 2 | 5 | 6 | 6 | 1.2 |
|
|
36
|
+
|
|
37
|
+
| total (35 questions) | config | MRR | hit@1 | hit@3 | hit@5 | hit@10 |
|
|
38
|
+
|---|---|---|---|---|---|---|
|
|
39
|
+
| | naive-window-rag | 0.179 | 3% | 23% | 34% | 46% |
|
|
40
|
+
| | carto-chunks | **0.387** | **17%** | **57%** | **66%** | **77%** |
|
|
41
|
+
| | carto-chunks+graph | **0.389** | **17%** | **57%** | **66%** | **77%** |
|
|
42
|
+
|
|
43
|
+
## Reading the numbers
|
|
44
|
+
|
|
45
|
+
1. **Symbol-boundary chunking is the big win: 2.2× MRR (0.179 → 0.387) and nearly 2× hit@5 (34% → 66%)** over fixed-window RAG, with identical embeddings. Aligning retrieval units with function boundaries means the exact answer can *be* a chunk instead of being split across two windows.
|
|
46
|
+
2. **The largest gains are on the most framework-magic repo.** On django-rest-framework (heavy base-class dispatch, mixins, dynamic registration) naive RAG manages only 10% MRR — it retrieves generic windows that mention the topic. Symbol chunking more than doubles that.
|
|
47
|
+
3. **Honest finding on graph expansion:** expansion does not improve *retrieval ranking*, because it appends neighbors *after* the direct matches — by construction it can only add context, not reorder. Its value is downstream: those expanded chunks (marked "via call-graph expansion" in sources) are what let the model answer *"who calls this?"* and *"what breaks if I change it?"* follow-ups without another retrieval round. A better design would re-rank the merged pool; that's future work.
|
|
48
|
+
4. **3% hit@1 for naive RAG means: in a third of cases the first window you see is wrong.** For a new developer that's worse than grep — it teaches the wrong architecture with confidence.
|
|
49
|
+
|
|
50
|
+
## Limitations
|
|
51
|
+
|
|
52
|
+
- **Local hash embeddings** (256-dim bucketed TF) are weak; real embedding models will raise all numbers. The *relative* comparison is the point: same embedder, different chunking.
|
|
53
|
+
- **35 questions** authored by the tool's author — selection bias is real. The harness and question sets are checked in (`scripts/benchmark.ts`, `scripts/questions/`) so anyone can add questions or rerun on other repos.
|
|
54
|
+
- **Gold = single symbol.** Some questions legitimately have multiple valid answers; gold was chosen as the canonical one a maintainer would point to first.
|
|
55
|
+
- **Static resolution is incomplete** (~26–46% of call sites on these repos resolve), so the call-graph context attached to chunks is partially missing. Runtime tracing would improve it.
|
|
56
|
+
|
|
57
|
+
## Reproduce
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
git clone https://github.com/zerocopies/codebase-cartographer
|
|
61
|
+
cd codebase-cartographer && npm ci && npm run build
|
|
62
|
+
for r in pallets/click pallets/flask encode/django-rest-framework; do
|
|
63
|
+
git clone --depth 1 https://github.com/$r /tmp/bm_$(basename $r | tr '-' '_')
|
|
64
|
+
done
|
|
65
|
+
npx tsx scripts/benchmark.ts
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Flask is analyzed at `/tmp/bm_flask/src` (its package lives under `src/`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prubbs88/codebase-cartographer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Legacy codebase onboarding agent — maps Python codebases into a call graph so new developers understand them in days, not weeks.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"carto": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"docs/benchmark.md"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/zerocopies/codebase-cartographer.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/zerocopies/codebase-cartographer/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/zerocopies/codebase-cartographer#readme",
|
|
29
|
+
"keywords": [
|
|
30
|
+
"python",
|
|
31
|
+
"static-analysis",
|
|
32
|
+
"call-graph",
|
|
33
|
+
"code-intelligence",
|
|
34
|
+
"code-onboarding",
|
|
35
|
+
"dead-code",
|
|
36
|
+
"blast-radius",
|
|
37
|
+
"tree-sitter",
|
|
38
|
+
"rag",
|
|
39
|
+
"cli"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build",
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"dev": "tsx src/index.ts",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"lint": "eslint src test",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"bench": "tsx scripts/benchmark.ts"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"commander": "^13.1.0",
|
|
52
|
+
"tree-sitter": "^0.22.4",
|
|
53
|
+
"tree-sitter-python": "^0.23.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^22.10.0",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^8.18.0",
|
|
58
|
+
"@typescript-eslint/parser": "^8.18.0",
|
|
59
|
+
"eslint": "^9.17.0",
|
|
60
|
+
"prettier": "^3.4.2",
|
|
61
|
+
"tsx": "^4.19.2",
|
|
62
|
+
"typescript": "^5.7.2",
|
|
63
|
+
"vitest": "^2.1.8"
|
|
64
|
+
}
|
|
65
|
+
}
|