@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 zerocopies
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cartographer (carto)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Map a legacy Python codebase so a new developer understands it in days, not weeks.
|
|
4
|
+
|
|
5
|
+
`carto` parses every Python file in a repository, builds a static call graph, and
|
|
6
|
+
classifies every function and class by its **blast radius** — so you know what is
|
|
7
|
+
load-bearing, where to start reading, and what is probably dead code.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
Joining a team with a 500k-line monolith means weeks of reverse-engineering.
|
|
12
|
+
Existing tools give you grep and ctags. Cartographer gives you structure:
|
|
13
|
+
|
|
14
|
+
- **Entry points** — where execution actually starts (main blocks, HTTP routes, tasks)
|
|
15
|
+
- **Load-bearing code** — high blast radius: many callers, reached from many entry points
|
|
16
|
+
- **Dead-code suspects** — never called, not exported, not a test
|
|
17
|
+
- **Top hubs** — the functions everything else depends on
|
|
18
|
+
- **Module dependency map** — which files call which
|
|
19
|
+
- **Interactive dashboard** — `carto report` renders the whole analysis as one shareable HTML file
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g @prubbs88/codebase-cartographer
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
carto ingest path/to/repo # parse + build call graph + cache to .carto/
|
|
31
|
+
carto stats path/to/repo # summary: classification, hubs, dead code, entry points
|
|
32
|
+
carto map path/to/repo # module-level dependency summary
|
|
33
|
+
carto ask "question" # grounded Q&A with file:line citations
|
|
34
|
+
carto report path/to/repo # interactive HTML dashboard (.carto/report.html)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Interactive dashboard (`carto report`)
|
|
38
|
+
|
|
39
|
+
Generates a **single self-contained HTML file** — no server, no CDN, no
|
|
40
|
+
external assets — that you can open in any browser, commit to the repo, or
|
|
41
|
+
share with your team:
|
|
42
|
+
|
|
43
|
+
- stat cards (modules, symbols, call sites, resolution rate)
|
|
44
|
+
- **module map**: fan-in vs fan-out scatter — hubs, orchestrators, and balanced modules at a glance; click a bubble to filter symbols
|
|
45
|
+
- searchable symbol table with classification badges and blast-radius numbers
|
|
46
|
+
|
|
47
|
+
## Grounded Q&A (`carto ask`)
|
|
48
|
+
|
|
49
|
+
Run from inside the target repository (or pass the path as your cwd):
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
cd path/to/repo
|
|
53
|
+
carto ask "where do we validate JWTs?"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Every answer is grounded in retrieved code chunks and must cite `file:line`.
|
|
57
|
+
Retrieval is **call-graph aware**: besides the top-matching functions, the
|
|
58
|
+
prompt includes their callers and callees (`[via call-graph expansion]` in
|
|
59
|
+
source lists), so answers reflect call structure, not just text similarity.
|
|
60
|
+
|
|
61
|
+
Without configuration, `carto ask` runs fully offline and prints the retrieved
|
|
62
|
+
code context instead of a model answer. To get model answers, set:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
export CARTO_API_KEY=... # required (Mistral API key)
|
|
66
|
+
export CARTO_API_BASE=... # optional, default https://api.mistral.ai/v1
|
|
67
|
+
export CARTO_MODEL=... # optional, default mistral-small-latest
|
|
68
|
+
export CARTO_EMBED_MODEL=... # optional, default mistral-embed
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Flags: `--top <k>` (context chunks, default 6), `--no-llm` (context only).
|
|
72
|
+
|
|
73
|
+
Example output:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
Cartographer — /srv/legacy-app
|
|
77
|
+
|
|
78
|
+
87 modules · 1204 functions/classes · 3421 call sites
|
|
79
|
+
Call resolution: 78.4%
|
|
80
|
+
|
|
81
|
+
entry-points 12
|
|
82
|
+
load-bearing 96
|
|
83
|
+
core 402
|
|
84
|
+
peripheral 538
|
|
85
|
+
dead-code suspects 156
|
|
86
|
+
|
|
87
|
+
Top hubs (most depended-on):
|
|
88
|
+
utils/http.py:41 request (63 inbound calls)
|
|
89
|
+
...
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## How it works
|
|
93
|
+
|
|
94
|
+
1. **Parse** — tree-sitter-python AST extraction: functions, methods, classes, imports, calls, decorators, docstrings.
|
|
95
|
+
2. **Resolve** — call sites are resolved to definitions using: same-file scope → from-imports → module attribute access → `self`/`cls` methods → classmethod-style calls. Unresolved calls become typed external nodes rather than noise.
|
|
96
|
+
3. **Rank** — direct inbound calls + transitive reachability from entry points produce a blast-radius score; the top decile is flagged `load-bearing`.
|
|
97
|
+
4. **Classify** — zero-inbound, undecorated, non-test functions become `dead-code-suspect`.
|
|
98
|
+
|
|
99
|
+
## Status
|
|
100
|
+
|
|
101
|
+
- Sprint 1: analysis engine + CLI (`ingest` / `stats` / `map`)
|
|
102
|
+
- Sprint 2: `carto ask` — call-graph-grounded Q&A with file:line citations
|
|
103
|
+
- Sprint 2.5: `carto report` — self-contained HTML dashboard; benchmark harness vs naive RAG (`docs/benchmark.md`)
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
package/dist/ask.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Chunk } from "./retrieval/chunk.js";
|
|
2
|
+
import { type RetrievedChunk } from "./retrieval/retrieve.js";
|
|
3
|
+
import { type ChatMessage } from "./llm/client.js";
|
|
4
|
+
export interface AskOptions {
|
|
5
|
+
topK?: number;
|
|
6
|
+
noLlm?: boolean;
|
|
7
|
+
fetchImpl?: typeof fetch;
|
|
8
|
+
env?: NodeJS.ProcessEnv;
|
|
9
|
+
onProgress?: (message: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface AskResult {
|
|
12
|
+
answer: string | null;
|
|
13
|
+
matches: RetrievedChunk[];
|
|
14
|
+
usedLocalEmbeddings: boolean;
|
|
15
|
+
usedLlm: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function askQuestion(rootDir: string, question: string, options?: AskOptions): Promise<AskResult>;
|
|
18
|
+
export declare function buildPrompt(question: string, chunks: Chunk[]): ChatMessage[];
|
|
19
|
+
export declare function formatContextOnly(result: AskResult): string;
|
|
20
|
+
export declare function formatSources(matches: RetrievedChunk[]): string;
|
package/dist/ask.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { analyzeRepository } from "./graph/analysis.js";
|
|
2
|
+
import { buildChunks, chunkToText } from "./retrieval/chunk.js";
|
|
3
|
+
import { localEmbed } from "./retrieval/local-embed.js";
|
|
4
|
+
import { embedChunks, retrieve } from "./retrieval/retrieve.js";
|
|
5
|
+
import { chat, embedTexts, loadLlmConfig } from "./llm/client.js";
|
|
6
|
+
export async function askQuestion(rootDir, question, options = {}) {
|
|
7
|
+
const { topK = 6, noLlm = false, fetchImpl = fetch, env = process.env, onProgress = () => { } } = options;
|
|
8
|
+
onProgress("analyzing codebase...");
|
|
9
|
+
const analysis = analyzeRepository(rootDir);
|
|
10
|
+
const chunks = buildChunks(rootDir, analysis);
|
|
11
|
+
const config = loadLlmConfig(env);
|
|
12
|
+
let usedLocalEmbeddings = true;
|
|
13
|
+
if (config && !noLlm) {
|
|
14
|
+
onProgress("embedding with API...");
|
|
15
|
+
try {
|
|
16
|
+
const embeddings = await embedTexts(config, chunks.map(chunkToText), fetchImpl);
|
|
17
|
+
embedChunks(chunks, embeddings);
|
|
18
|
+
usedLocalEmbeddings = false;
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
onProgress(`embedding API failed (${err instanceof Error ? err.message : err}); falling back to local retrieval`);
|
|
22
|
+
embedChunks(chunks, null);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
embedChunks(chunks, null);
|
|
27
|
+
}
|
|
28
|
+
const questionEmbedding = usedLocalEmbeddings
|
|
29
|
+
? localEmbed(question)
|
|
30
|
+
: await embedQuestion(config, question, fetchImpl);
|
|
31
|
+
const { matches } = retrieve(chunks, question, questionEmbedding, topK);
|
|
32
|
+
if (noLlm || !config) {
|
|
33
|
+
return { answer: null, matches, usedLocalEmbeddings, usedLlm: false };
|
|
34
|
+
}
|
|
35
|
+
onProgress("asking model...");
|
|
36
|
+
const messages = buildPrompt(question, matches.map((m) => m.chunk));
|
|
37
|
+
const answer = await chat(config, messages, fetchImpl);
|
|
38
|
+
return { answer, matches, usedLocalEmbeddings, usedLlm: true };
|
|
39
|
+
}
|
|
40
|
+
async function embedQuestion(config, question, fetchImpl) {
|
|
41
|
+
const [embedding] = await embedTexts(config, [question], fetchImpl);
|
|
42
|
+
return embedding;
|
|
43
|
+
}
|
|
44
|
+
export function buildPrompt(question, chunks) {
|
|
45
|
+
const contextBlocks = chunks
|
|
46
|
+
.map((chunk, i) => {
|
|
47
|
+
const citation = `${chunk.file}:${chunk.startLine}-${chunk.endLine}`;
|
|
48
|
+
return `### Context [${i + 1}]: ${chunk.title} (${citation}) [${chunk.classification}]\n${chunk.context}\n\n\`\`\`python\n${chunk.code}\n\`\`\``;
|
|
49
|
+
})
|
|
50
|
+
.join("\n\n");
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
role: "system",
|
|
54
|
+
content: [
|
|
55
|
+
"You are a codebase navigation assistant. Answer the developer's question using ONLY the provided context.",
|
|
56
|
+
"Rules:",
|
|
57
|
+
"- Cite every claim as file:line (e.g. service.py:7-12) taken from the context headers.",
|
|
58
|
+
"- If the context does not contain the answer, say so explicitly and suggest which files might be relevant.",
|
|
59
|
+
"- Explain the call structure when relevant: who calls what, and which paths are load-bearing.",
|
|
60
|
+
"- Be concise. No preamble.",
|
|
61
|
+
].join("\n"),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
role: "user",
|
|
65
|
+
content: `Question: ${question}\n\n${contextBlocks}`,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
export function formatContextOnly(result) {
|
|
70
|
+
const lines = [];
|
|
71
|
+
lines.push("No API key configured (set CARTO_API_KEY). Showing retrieved context instead of a model answer:");
|
|
72
|
+
lines.push("");
|
|
73
|
+
for (const match of result.matches) {
|
|
74
|
+
const via = match.via === "graph-expansion" ? " [via call-graph expansion]" : "";
|
|
75
|
+
lines.push(`- ${match.chunk.title} [${match.chunk.classification}]${via}`);
|
|
76
|
+
}
|
|
77
|
+
lines.push("");
|
|
78
|
+
for (const match of result.matches) {
|
|
79
|
+
lines.push(`--- ${match.chunk.title} ---`);
|
|
80
|
+
lines.push(match.chunk.code);
|
|
81
|
+
lines.push("");
|
|
82
|
+
}
|
|
83
|
+
return lines.join("\n");
|
|
84
|
+
}
|
|
85
|
+
export function formatSources(matches) {
|
|
86
|
+
const lines = ["", "Sources:"];
|
|
87
|
+
for (const match of matches) {
|
|
88
|
+
const via = match.via === "graph-expansion" ? " (call-graph expansion)" : "";
|
|
89
|
+
lines.push(` ${match.chunk.file}:${match.chunk.startLine}-${match.chunk.endLine} ${match.chunk.title}${via}`);
|
|
90
|
+
}
|
|
91
|
+
return lines.join("\n");
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=ask.js.map
|
package/dist/ask.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.js","sourceRoot":"","sources":["../src/ask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAc,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAuB,MAAM,yBAAyB,CAAC;AACrF,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAoC,MAAM,iBAAiB,CAAC;AAiBpG,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAe,EAAE,QAAgB,EAAE,UAAsB,EAAE;IAC3F,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,UAAU,GAAG,G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,CAAC;QAC5B,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,KAAK,iBAAiB,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7E,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC,CAAC;IAClH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { scanPythonFiles } from "../scan.js";
|
|
2
|
+
import { analyze } from "./rank.js";
|
|
3
|
+
export function analyzeRepository(rootDir) {
|
|
4
|
+
const files = scanPythonFiles(rootDir);
|
|
5
|
+
const { symbols, edges, ranked, entryPoints, moduleDeps, resolutionRate } = analyze(files);
|
|
6
|
+
return { files, symbols, edges, ranked, entryPoints, moduleDeps, resolutionRate };
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=analysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analysis.js","sourceRoot":"","sources":["../../src/graph/analysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3F,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CallEdge, CodeSymbol, ParsedFile, RankedSymbol } from "./types.js";
|
|
2
|
+
export declare function analyze(files: ParsedFile[]): {
|
|
3
|
+
symbols: Map<string, CodeSymbol>;
|
|
4
|
+
edges: CallEdge[];
|
|
5
|
+
ranked: Map<string, RankedSymbol>;
|
|
6
|
+
entryPoints: Set<string>;
|
|
7
|
+
moduleDeps: Map<string, Map<string, number>>;
|
|
8
|
+
resolutionRate: number;
|
|
9
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { buildIndexes, resolveCalls } from "./resolve.js";
|
|
2
|
+
const ENTRY_DECORATOR_PATTERNS = [
|
|
3
|
+
"route", "get", "post", "put", "patch", "delete", "app.route", "blueprint.route",
|
|
4
|
+
"shared_task", "task", "app.task", "command", "click.command", "click.group",
|
|
5
|
+
"app.cli", "scheduler", "cron", "handler", "event", "on_", "receiver", "fixture",
|
|
6
|
+
];
|
|
7
|
+
const SAFE_NAMES = new Set(["main", "run", "cli", "handler", "setup", "teardown", "setUp", "tearDown"]);
|
|
8
|
+
export function analyze(files) {
|
|
9
|
+
const symbols = new Map();
|
|
10
|
+
const idx = buildIndexes(files, symbols);
|
|
11
|
+
const edges = resolveCalls(files, symbols, idx);
|
|
12
|
+
const entryPoints = detectEntryPoints(files, edges);
|
|
13
|
+
const { directInbound, outbound } = computeDegrees(edges);
|
|
14
|
+
const entryReach = computeEntryPointReach(edges, entryPoints);
|
|
15
|
+
const ranked = classify(symbols, edges, directInbound, outbound, entryReach, entryPoints);
|
|
16
|
+
const moduleDeps = computeModuleDeps(files, symbols, edges);
|
|
17
|
+
const total = edges.length;
|
|
18
|
+
const resolved = edges.filter((e) => e.resolved).length;
|
|
19
|
+
const resolutionRate = total === 0 ? 1 : resolved / total;
|
|
20
|
+
return { symbols, edges, ranked, entryPoints, moduleDeps, resolutionRate };
|
|
21
|
+
}
|
|
22
|
+
function detectEntryPoints(files, edges) {
|
|
23
|
+
const entryPoints = new Set();
|
|
24
|
+
const patternRes = ENTRY_DECORATOR_PATTERNS.map((p) => new RegExp(`(^|[^\\w])${p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^\\w]|$)`));
|
|
25
|
+
for (const file of files) {
|
|
26
|
+
for (const sym of file.symbols) {
|
|
27
|
+
if (sym.kind === "module")
|
|
28
|
+
continue;
|
|
29
|
+
const isRouteDecorator = sym.decorators.some((d) => {
|
|
30
|
+
const head = d.split("(")[0];
|
|
31
|
+
return patternRes.some((re) => re.test(head));
|
|
32
|
+
});
|
|
33
|
+
if (isRouteDecorator)
|
|
34
|
+
entryPoints.add(sym.id);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const edge of edges) {
|
|
38
|
+
if (edge.callerId.endsWith("::<module>") && edge.resolved) {
|
|
39
|
+
const callee = edge.calleeId;
|
|
40
|
+
if (callee.startsWith("external::"))
|
|
41
|
+
continue;
|
|
42
|
+
const name = callee.slice(callee.lastIndexOf("::") + 2);
|
|
43
|
+
if (name === "main" || name.endsWith(".main") || name === "run" || name === "app") {
|
|
44
|
+
entryPoints.add(callee);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return entryPoints;
|
|
49
|
+
}
|
|
50
|
+
function computeDegrees(edges) {
|
|
51
|
+
const directInbound = new Map();
|
|
52
|
+
const outbound = new Map();
|
|
53
|
+
for (const edge of edges) {
|
|
54
|
+
if (edge.resolved) {
|
|
55
|
+
directInbound.set(edge.calleeId, (directInbound.get(edge.calleeId) ?? 0) + 1);
|
|
56
|
+
}
|
|
57
|
+
outbound.set(edge.callerId, (outbound.get(edge.callerId) ?? 0) + 1);
|
|
58
|
+
}
|
|
59
|
+
return { directInbound, outbound };
|
|
60
|
+
}
|
|
61
|
+
function computeEntryPointReach(edges, entryPoints) {
|
|
62
|
+
const adjacency = new Map();
|
|
63
|
+
for (const edge of edges) {
|
|
64
|
+
if (!edge.resolved || edge.calleeId.startsWith("external::"))
|
|
65
|
+
continue;
|
|
66
|
+
const set = adjacency.get(edge.callerId) ?? new Set();
|
|
67
|
+
set.add(edge.calleeId);
|
|
68
|
+
adjacency.set(edge.callerId, set);
|
|
69
|
+
}
|
|
70
|
+
const reach = new Map();
|
|
71
|
+
for (const entry of entryPoints) {
|
|
72
|
+
const visited = new Set();
|
|
73
|
+
const queue = [entry];
|
|
74
|
+
while (queue.length > 0) {
|
|
75
|
+
const current = queue.pop();
|
|
76
|
+
const neighbors = adjacency.get(current);
|
|
77
|
+
if (!neighbors)
|
|
78
|
+
continue;
|
|
79
|
+
for (const next of neighbors) {
|
|
80
|
+
if (visited.has(next))
|
|
81
|
+
continue;
|
|
82
|
+
visited.add(next);
|
|
83
|
+
reach.set(next, (reach.get(next) ?? 0) + 1);
|
|
84
|
+
queue.push(next);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return reach;
|
|
89
|
+
}
|
|
90
|
+
function classify(symbols, edges, directInbound, outbound, entryReach, entryPoints) {
|
|
91
|
+
const scores = [];
|
|
92
|
+
for (const [id, sym] of symbols) {
|
|
93
|
+
if (sym.kind === "module" || id.startsWith("external::"))
|
|
94
|
+
continue;
|
|
95
|
+
const inbound = directInbound.get(id) ?? 0;
|
|
96
|
+
const reach = entryReach.get(id) ?? 0;
|
|
97
|
+
scores.push(inbound + 3 * reach);
|
|
98
|
+
}
|
|
99
|
+
scores.sort((a, b) => b - a);
|
|
100
|
+
const p90 = scores.length > 0 ? scores[Math.floor(scores.length * 0.1)] : 0;
|
|
101
|
+
const loadBearingThreshold = Math.max(3, p90);
|
|
102
|
+
const deadInbound = new Map();
|
|
103
|
+
for (const edge of edges) {
|
|
104
|
+
if (!edge.resolved)
|
|
105
|
+
continue;
|
|
106
|
+
deadInbound.set(edge.calleeId, (deadInbound.get(edge.calleeId) ?? 0) + 1);
|
|
107
|
+
}
|
|
108
|
+
const ranked = new Map();
|
|
109
|
+
for (const [id, sym] of symbols) {
|
|
110
|
+
if (sym.kind === "module")
|
|
111
|
+
continue;
|
|
112
|
+
if (id.startsWith("external::")) {
|
|
113
|
+
ranked.set(id, {
|
|
114
|
+
symbol: sym,
|
|
115
|
+
directInbound: 0,
|
|
116
|
+
outbound: 0,
|
|
117
|
+
entryPointReachCount: 0,
|
|
118
|
+
score: 0,
|
|
119
|
+
classification: "external",
|
|
120
|
+
});
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const inbound = directInbound.get(id) ?? 0;
|
|
124
|
+
const out = outbound.get(id) ?? 0;
|
|
125
|
+
const reach = entryReach.get(id) ?? 0;
|
|
126
|
+
const score = inbound + 3 * reach;
|
|
127
|
+
let classification;
|
|
128
|
+
if (entryPoints.has(id)) {
|
|
129
|
+
classification = "entry-point";
|
|
130
|
+
}
|
|
131
|
+
else if (score >= loadBearingThreshold || reach >= 2) {
|
|
132
|
+
classification = "load-bearing";
|
|
133
|
+
}
|
|
134
|
+
else if (inbound === 0 &&
|
|
135
|
+
(sym.kind === "function" || sym.kind === "method") &&
|
|
136
|
+
sym.decorators.length === 0 &&
|
|
137
|
+
!sym.name.startsWith("test_") &&
|
|
138
|
+
!sym.name.startsWith("_") &&
|
|
139
|
+
!SAFE_NAMES.has(sym.name) &&
|
|
140
|
+
!sym.name.startsWith("__")) {
|
|
141
|
+
classification = "dead-code-suspect";
|
|
142
|
+
}
|
|
143
|
+
else if (inbound <= 1 && out <= 1) {
|
|
144
|
+
classification = "peripheral";
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
classification = "core";
|
|
148
|
+
}
|
|
149
|
+
ranked.set(id, { symbol: sym, directInbound: inbound, outbound: out, entryPointReachCount: reach, score, classification });
|
|
150
|
+
}
|
|
151
|
+
return ranked;
|
|
152
|
+
}
|
|
153
|
+
function computeModuleDeps(files, symbols, edges) {
|
|
154
|
+
const fileOf = new Map();
|
|
155
|
+
for (const file of files) {
|
|
156
|
+
for (const sym of file.symbols)
|
|
157
|
+
fileOf.set(sym.id, file.path);
|
|
158
|
+
}
|
|
159
|
+
const deps = new Map();
|
|
160
|
+
for (const edge of edges) {
|
|
161
|
+
if (!edge.resolved)
|
|
162
|
+
continue;
|
|
163
|
+
const from = fileOf.get(edge.callerId);
|
|
164
|
+
const to = fileOf.get(edge.calleeId);
|
|
165
|
+
if (!from || !to || from === to)
|
|
166
|
+
continue;
|
|
167
|
+
const inner = deps.get(from) ?? new Map();
|
|
168
|
+
inner.set(to, (inner.get(to) ?? 0) + 1);
|
|
169
|
+
deps.set(from, inner);
|
|
170
|
+
}
|
|
171
|
+
return deps;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=rank.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rank.js","sourceRoot":"","sources":["../../src/graph/rank.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,MAAM,wBAAwB,GAAG;IAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,iBAAiB;IAChF,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa;IAC5E,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS;CACjF,CAAC;AAEF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAExG,MAAM,UAAU,OAAO,CAAC,KAAmB;IAQzC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC9C,MAAM,GAAG,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,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AED,SAAS,iBAAiB,CACxB,KAAmB,EACnB,OAAgC,EAChC,KAAiB;IAEjB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,GAAG,EAA+B,CAAC;IACpD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,SAAS;QAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,KAAK,EAAE;YAAE,SAAS;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAkB,CAAC;QAC1D,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CallEdge, CodeSymbol, ParsedFile, RawAssignment } from "./types.js";
|
|
2
|
+
export interface ResolutionIndexes {
|
|
3
|
+
moduleFiles: Map<string, string>;
|
|
4
|
+
symbolsByModule: Map<string, Map<string, CodeSymbol>>;
|
|
5
|
+
symbolsByFile: Map<string, Map<string, CodeSymbol>>;
|
|
6
|
+
methodsByClass: Map<string, Map<string, CodeSymbol>>;
|
|
7
|
+
classesBySimpleName: Map<string, CodeSymbol[]>;
|
|
8
|
+
}
|
|
9
|
+
export declare function buildIndexes(files: ParsedFile[], allSymbols: Map<string, CodeSymbol>): ResolutionIndexes;
|
|
10
|
+
export declare function resolveCalls(files: ParsedFile[], allSymbols: Map<string, CodeSymbol>, idx: ResolutionIndexes): CallEdge[];
|
|
11
|
+
export type { RawAssignment };
|