@vpxa/kb 0.1.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/LICENSE +21 -0
- package/README.md +1140 -0
- package/bin/kb.mjs +10 -0
- package/package.json +67 -0
- package/packages/analyzers/dist/blast-radius-analyzer.d.ts +23 -0
- package/packages/analyzers/dist/blast-radius-analyzer.js +114 -0
- package/packages/analyzers/dist/dependency-analyzer.d.ts +29 -0
- package/packages/analyzers/dist/dependency-analyzer.js +425 -0
- package/packages/analyzers/dist/diagram-generator.d.ts +13 -0
- package/packages/analyzers/dist/diagram-generator.js +86 -0
- package/packages/analyzers/dist/entry-point-analyzer.d.ts +19 -0
- package/packages/analyzers/dist/entry-point-analyzer.js +239 -0
- package/packages/analyzers/dist/index.d.ts +14 -0
- package/packages/analyzers/dist/index.js +23 -0
- package/packages/analyzers/dist/knowledge-producer.d.ts +32 -0
- package/packages/analyzers/dist/knowledge-producer.js +113 -0
- package/packages/analyzers/dist/pattern-analyzer.d.ts +12 -0
- package/packages/analyzers/dist/pattern-analyzer.js +359 -0
- package/packages/analyzers/dist/regex-call-graph.d.ts +17 -0
- package/packages/analyzers/dist/regex-call-graph.js +428 -0
- package/packages/analyzers/dist/structure-analyzer.d.ts +11 -0
- package/packages/analyzers/dist/structure-analyzer.js +258 -0
- package/packages/analyzers/dist/symbol-analyzer.d.ts +10 -0
- package/packages/analyzers/dist/symbol-analyzer.js +442 -0
- package/packages/analyzers/dist/ts-call-graph.d.ts +27 -0
- package/packages/analyzers/dist/ts-call-graph.js +160 -0
- package/packages/analyzers/dist/types.d.ts +98 -0
- package/packages/analyzers/dist/types.js +1 -0
- package/packages/chunker/dist/call-graph-extractor.d.ts +22 -0
- package/packages/chunker/dist/call-graph-extractor.js +90 -0
- package/packages/chunker/dist/chunker-factory.d.ts +7 -0
- package/packages/chunker/dist/chunker-factory.js +36 -0
- package/packages/chunker/dist/chunker.interface.d.ts +10 -0
- package/packages/chunker/dist/chunker.interface.js +1 -0
- package/packages/chunker/dist/code-chunker.d.ts +14 -0
- package/packages/chunker/dist/code-chunker.js +134 -0
- package/packages/chunker/dist/generic-chunker.d.ts +12 -0
- package/packages/chunker/dist/generic-chunker.js +72 -0
- package/packages/chunker/dist/index.d.ts +8 -0
- package/packages/chunker/dist/index.js +21 -0
- package/packages/chunker/dist/markdown-chunker.d.ts +14 -0
- package/packages/chunker/dist/markdown-chunker.js +122 -0
- package/packages/chunker/dist/treesitter-chunker.d.ts +47 -0
- package/packages/chunker/dist/treesitter-chunker.js +234 -0
- package/packages/cli/dist/commands/analyze.d.ts +3 -0
- package/packages/cli/dist/commands/analyze.js +112 -0
- package/packages/cli/dist/commands/context-cmds.d.ts +3 -0
- package/packages/cli/dist/commands/context-cmds.js +155 -0
- package/packages/cli/dist/commands/environment.d.ts +3 -0
- package/packages/cli/dist/commands/environment.js +204 -0
- package/packages/cli/dist/commands/execution.d.ts +3 -0
- package/packages/cli/dist/commands/execution.js +137 -0
- package/packages/cli/dist/commands/graph.d.ts +3 -0
- package/packages/cli/dist/commands/graph.js +81 -0
- package/packages/cli/dist/commands/init.d.ts +8 -0
- package/packages/cli/dist/commands/init.js +87 -0
- package/packages/cli/dist/commands/knowledge.d.ts +3 -0
- package/packages/cli/dist/commands/knowledge.js +139 -0
- package/packages/cli/dist/commands/search.d.ts +3 -0
- package/packages/cli/dist/commands/search.js +267 -0
- package/packages/cli/dist/commands/system.d.ts +3 -0
- package/packages/cli/dist/commands/system.js +241 -0
- package/packages/cli/dist/commands/workspace.d.ts +3 -0
- package/packages/cli/dist/commands/workspace.js +388 -0
- package/packages/cli/dist/context.d.ts +5 -0
- package/packages/cli/dist/context.js +14 -0
- package/packages/cli/dist/helpers.d.ts +52 -0
- package/packages/cli/dist/helpers.js +458 -0
- package/packages/cli/dist/index.d.ts +8 -0
- package/packages/cli/dist/index.js +69 -0
- package/packages/cli/dist/kb-init.d.ts +57 -0
- package/packages/cli/dist/kb-init.js +82 -0
- package/packages/cli/dist/types.d.ts +7 -0
- package/packages/cli/dist/types.js +1 -0
- package/packages/core/dist/constants.d.ts +49 -0
- package/packages/core/dist/constants.js +43 -0
- package/packages/core/dist/content-detector.d.ts +9 -0
- package/packages/core/dist/content-detector.js +79 -0
- package/packages/core/dist/errors.d.ts +18 -0
- package/packages/core/dist/errors.js +40 -0
- package/packages/core/dist/index.d.ts +6 -0
- package/packages/core/dist/index.js +9 -0
- package/packages/core/dist/logger.d.ts +9 -0
- package/packages/core/dist/logger.js +34 -0
- package/packages/core/dist/types.d.ts +108 -0
- package/packages/core/dist/types.js +1 -0
- package/packages/embeddings/dist/embedder.interface.d.ts +24 -0
- package/packages/embeddings/dist/embedder.interface.js +1 -0
- package/packages/embeddings/dist/index.d.ts +3 -0
- package/packages/embeddings/dist/index.js +5 -0
- package/packages/embeddings/dist/onnx-embedder.d.ts +24 -0
- package/packages/embeddings/dist/onnx-embedder.js +82 -0
- package/packages/indexer/dist/file-hasher.d.ts +11 -0
- package/packages/indexer/dist/file-hasher.js +13 -0
- package/packages/indexer/dist/filesystem-crawler.d.ts +27 -0
- package/packages/indexer/dist/filesystem-crawler.js +125 -0
- package/packages/indexer/dist/graph-extractor.d.ts +22 -0
- package/packages/indexer/dist/graph-extractor.js +111 -0
- package/packages/indexer/dist/incremental-indexer.d.ts +47 -0
- package/packages/indexer/dist/incremental-indexer.js +278 -0
- package/packages/indexer/dist/index.d.ts +5 -0
- package/packages/indexer/dist/index.js +14 -0
- package/packages/server/dist/api.d.ts +8 -0
- package/packages/server/dist/api.js +9 -0
- package/packages/server/dist/config.d.ts +3 -0
- package/packages/server/dist/config.js +75 -0
- package/packages/server/dist/curated-manager.d.ts +86 -0
- package/packages/server/dist/curated-manager.js +357 -0
- package/packages/server/dist/index.d.ts +2 -0
- package/packages/server/dist/index.js +134 -0
- package/packages/server/dist/replay-interceptor.d.ts +11 -0
- package/packages/server/dist/replay-interceptor.js +38 -0
- package/packages/server/dist/resources/resources.d.ts +4 -0
- package/packages/server/dist/resources/resources.js +40 -0
- package/packages/server/dist/server.d.ts +21 -0
- package/packages/server/dist/server.js +247 -0
- package/packages/server/dist/tools/analyze.tools.d.ts +11 -0
- package/packages/server/dist/tools/analyze.tools.js +288 -0
- package/packages/server/dist/tools/forge.tools.d.ts +12 -0
- package/packages/server/dist/tools/forge.tools.js +501 -0
- package/packages/server/dist/tools/forget.tool.d.ts +4 -0
- package/packages/server/dist/tools/forget.tool.js +43 -0
- package/packages/server/dist/tools/graph.tool.d.ts +4 -0
- package/packages/server/dist/tools/graph.tool.js +110 -0
- package/packages/server/dist/tools/list.tool.d.ts +4 -0
- package/packages/server/dist/tools/list.tool.js +56 -0
- package/packages/server/dist/tools/lookup.tool.d.ts +4 -0
- package/packages/server/dist/tools/lookup.tool.js +53 -0
- package/packages/server/dist/tools/onboard.tool.d.ts +5 -0
- package/packages/server/dist/tools/onboard.tool.js +112 -0
- package/packages/server/dist/tools/produce.tool.d.ts +3 -0
- package/packages/server/dist/tools/produce.tool.js +74 -0
- package/packages/server/dist/tools/read.tool.d.ts +4 -0
- package/packages/server/dist/tools/read.tool.js +49 -0
- package/packages/server/dist/tools/reindex.tool.d.ts +7 -0
- package/packages/server/dist/tools/reindex.tool.js +70 -0
- package/packages/server/dist/tools/remember.tool.d.ts +4 -0
- package/packages/server/dist/tools/remember.tool.js +45 -0
- package/packages/server/dist/tools/replay.tool.d.ts +3 -0
- package/packages/server/dist/tools/replay.tool.js +89 -0
- package/packages/server/dist/tools/search.tool.d.ts +5 -0
- package/packages/server/dist/tools/search.tool.js +331 -0
- package/packages/server/dist/tools/status.tool.d.ts +4 -0
- package/packages/server/dist/tools/status.tool.js +68 -0
- package/packages/server/dist/tools/toolkit.tools.d.ts +35 -0
- package/packages/server/dist/tools/toolkit.tools.js +1674 -0
- package/packages/server/dist/tools/update.tool.d.ts +4 -0
- package/packages/server/dist/tools/update.tool.js +42 -0
- package/packages/server/dist/tools/utility.tools.d.ts +15 -0
- package/packages/server/dist/tools/utility.tools.js +461 -0
- package/packages/store/dist/graph-store.interface.d.ts +104 -0
- package/packages/store/dist/graph-store.interface.js +1 -0
- package/packages/store/dist/index.d.ts +6 -0
- package/packages/store/dist/index.js +9 -0
- package/packages/store/dist/lance-store.d.ts +32 -0
- package/packages/store/dist/lance-store.js +258 -0
- package/packages/store/dist/sqlite-graph-store.d.ts +43 -0
- package/packages/store/dist/sqlite-graph-store.js +374 -0
- package/packages/store/dist/store-factory.d.ts +9 -0
- package/packages/store/dist/store-factory.js +14 -0
- package/packages/store/dist/store.interface.d.ts +48 -0
- package/packages/store/dist/store.interface.js +1 -0
- package/packages/tools/dist/batch.d.ts +21 -0
- package/packages/tools/dist/batch.js +45 -0
- package/packages/tools/dist/changelog.d.ts +34 -0
- package/packages/tools/dist/changelog.js +112 -0
- package/packages/tools/dist/check.d.ts +26 -0
- package/packages/tools/dist/check.js +59 -0
- package/packages/tools/dist/checkpoint.d.ts +17 -0
- package/packages/tools/dist/checkpoint.js +43 -0
- package/packages/tools/dist/codemod.d.ts +37 -0
- package/packages/tools/dist/codemod.js +69 -0
- package/packages/tools/dist/compact.d.ts +41 -0
- package/packages/tools/dist/compact.js +60 -0
- package/packages/tools/dist/data-transform.d.ts +10 -0
- package/packages/tools/dist/data-transform.js +124 -0
- package/packages/tools/dist/dead-symbols.d.ts +21 -0
- package/packages/tools/dist/dead-symbols.js +71 -0
- package/packages/tools/dist/delegate.d.ts +34 -0
- package/packages/tools/dist/delegate.js +130 -0
- package/packages/tools/dist/diff-parse.d.ts +26 -0
- package/packages/tools/dist/diff-parse.js +153 -0
- package/packages/tools/dist/digest.d.ts +53 -0
- package/packages/tools/dist/digest.js +242 -0
- package/packages/tools/dist/encode.d.ts +14 -0
- package/packages/tools/dist/encode.js +46 -0
- package/packages/tools/dist/env-info.d.ts +28 -0
- package/packages/tools/dist/env-info.js +58 -0
- package/packages/tools/dist/eval.d.ts +13 -0
- package/packages/tools/dist/eval.js +79 -0
- package/packages/tools/dist/evidence-map.d.ts +79 -0
- package/packages/tools/dist/evidence-map.js +203 -0
- package/packages/tools/dist/file-summary.d.ts +32 -0
- package/packages/tools/dist/file-summary.js +106 -0
- package/packages/tools/dist/file-walk.d.ts +4 -0
- package/packages/tools/dist/file-walk.js +75 -0
- package/packages/tools/dist/find-examples.d.ts +25 -0
- package/packages/tools/dist/find-examples.js +48 -0
- package/packages/tools/dist/find.d.ts +47 -0
- package/packages/tools/dist/find.js +120 -0
- package/packages/tools/dist/forge-classify.d.ts +44 -0
- package/packages/tools/dist/forge-classify.js +319 -0
- package/packages/tools/dist/forge-ground.d.ts +64 -0
- package/packages/tools/dist/forge-ground.js +184 -0
- package/packages/tools/dist/git-context.d.ts +22 -0
- package/packages/tools/dist/git-context.js +46 -0
- package/packages/tools/dist/graph-query.d.ts +89 -0
- package/packages/tools/dist/graph-query.js +194 -0
- package/packages/tools/dist/health.d.ts +14 -0
- package/packages/tools/dist/health.js +118 -0
- package/packages/tools/dist/http-request.d.ts +23 -0
- package/packages/tools/dist/http-request.js +58 -0
- package/packages/tools/dist/index.d.ts +49 -0
- package/packages/tools/dist/index.js +273 -0
- package/packages/tools/dist/lane.d.ts +39 -0
- package/packages/tools/dist/lane.js +227 -0
- package/packages/tools/dist/measure.d.ts +38 -0
- package/packages/tools/dist/measure.js +119 -0
- package/packages/tools/dist/onboard.d.ts +41 -0
- package/packages/tools/dist/onboard.js +1139 -0
- package/packages/tools/dist/parse-output.d.ts +80 -0
- package/packages/tools/dist/parse-output.js +158 -0
- package/packages/tools/dist/process-manager.d.ts +18 -0
- package/packages/tools/dist/process-manager.js +69 -0
- package/packages/tools/dist/queue.d.ts +38 -0
- package/packages/tools/dist/queue.js +126 -0
- package/packages/tools/dist/regex-test.d.ts +31 -0
- package/packages/tools/dist/regex-test.js +39 -0
- package/packages/tools/dist/rename.d.ts +29 -0
- package/packages/tools/dist/rename.js +70 -0
- package/packages/tools/dist/replay.d.ts +56 -0
- package/packages/tools/dist/replay.js +108 -0
- package/packages/tools/dist/schema-validate.d.ts +23 -0
- package/packages/tools/dist/schema-validate.js +141 -0
- package/packages/tools/dist/scope-map.d.ts +52 -0
- package/packages/tools/dist/scope-map.js +72 -0
- package/packages/tools/dist/snippet.d.ts +34 -0
- package/packages/tools/dist/snippet.js +80 -0
- package/packages/tools/dist/stash.d.ts +12 -0
- package/packages/tools/dist/stash.js +60 -0
- package/packages/tools/dist/stratum-card.d.ts +31 -0
- package/packages/tools/dist/stratum-card.js +239 -0
- package/packages/tools/dist/symbol.d.ts +28 -0
- package/packages/tools/dist/symbol.js +87 -0
- package/packages/tools/dist/test-run.d.ts +23 -0
- package/packages/tools/dist/test-run.js +55 -0
- package/packages/tools/dist/text-utils.d.ts +16 -0
- package/packages/tools/dist/text-utils.js +31 -0
- package/packages/tools/dist/time-utils.d.ts +18 -0
- package/packages/tools/dist/time-utils.js +135 -0
- package/packages/tools/dist/trace.d.ts +24 -0
- package/packages/tools/dist/trace.js +114 -0
- package/packages/tools/dist/truncation.d.ts +22 -0
- package/packages/tools/dist/truncation.js +45 -0
- package/packages/tools/dist/watch.d.ts +30 -0
- package/packages/tools/dist/watch.js +61 -0
- package/packages/tools/dist/web-fetch.d.ts +45 -0
- package/packages/tools/dist/web-fetch.js +249 -0
- package/packages/tools/dist/web-search.d.ts +23 -0
- package/packages/tools/dist/web-search.js +46 -0
- package/packages/tools/dist/workset.d.ts +45 -0
- package/packages/tools/dist/workset.js +77 -0
- package/packages/tui/dist/App.d.ts +8 -0
- package/packages/tui/dist/App.js +52659 -0
- package/packages/tui/dist/index.d.ts +19 -0
- package/packages/tui/dist/index.js +54742 -0
- package/packages/tui/dist/panels/CuratedPanel.d.ts +8 -0
- package/packages/tui/dist/panels/CuratedPanel.js +34452 -0
- package/packages/tui/dist/panels/LogPanel.d.ts +3 -0
- package/packages/tui/dist/panels/LogPanel.js +51894 -0
- package/packages/tui/dist/panels/SearchPanel.d.ts +10 -0
- package/packages/tui/dist/panels/SearchPanel.js +34985 -0
- package/packages/tui/dist/panels/StatusPanel.d.ts +8 -0
- package/packages/tui/dist/panels/StatusPanel.js +34465 -0
- package/skills/knowledge-base/SKILL.md +316 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AnalysisResult, IAnalyzer, SymbolAnalyzerOptions } from './types.js';
|
|
2
|
+
export declare class SymbolAnalyzer implements IAnalyzer<SymbolAnalyzerOptions> {
|
|
3
|
+
readonly name = "symbols";
|
|
4
|
+
analyze(rootPath: string, options?: SymbolAnalyzerOptions): Promise<AnalysisResult>;
|
|
5
|
+
private collectFiles;
|
|
6
|
+
private extractSymbols;
|
|
7
|
+
private groupByKind;
|
|
8
|
+
private formatMarkdown;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=symbol-analyzer.d.ts.map
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { extname, join, relative } from "node:path";
|
|
3
|
+
const CODE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
4
|
+
".ts",
|
|
5
|
+
".tsx",
|
|
6
|
+
".js",
|
|
7
|
+
".jsx",
|
|
8
|
+
".java",
|
|
9
|
+
".py",
|
|
10
|
+
".go",
|
|
11
|
+
".cs",
|
|
12
|
+
".rb",
|
|
13
|
+
".kt",
|
|
14
|
+
".scala",
|
|
15
|
+
".rs",
|
|
16
|
+
".php",
|
|
17
|
+
".swift"
|
|
18
|
+
]);
|
|
19
|
+
const DEFAULT_EXCLUDES = /* @__PURE__ */ new Set([
|
|
20
|
+
"node_modules",
|
|
21
|
+
".git",
|
|
22
|
+
"dist",
|
|
23
|
+
"build",
|
|
24
|
+
"coverage",
|
|
25
|
+
".turbo",
|
|
26
|
+
".cache",
|
|
27
|
+
"cdk.out",
|
|
28
|
+
"__pycache__",
|
|
29
|
+
".venv",
|
|
30
|
+
"target",
|
|
31
|
+
"bin",
|
|
32
|
+
"obj",
|
|
33
|
+
".gradle",
|
|
34
|
+
"venv",
|
|
35
|
+
"env"
|
|
36
|
+
]);
|
|
37
|
+
const TS_PATTERNS = {
|
|
38
|
+
exported: [
|
|
39
|
+
{ pattern: /^export\s+(?:async\s+)?function\s+(\w+)/gm, kind: "function" },
|
|
40
|
+
{ pattern: /^export\s+(?:default\s+)?class\s+(\w+)/gm, kind: "class" },
|
|
41
|
+
{ pattern: /^export\s+interface\s+(\w+)/gm, kind: "interface" },
|
|
42
|
+
{ pattern: /^export\s+type\s+(\w+)/gm, kind: "type" },
|
|
43
|
+
{ pattern: /^export\s+(?:const|let)\s+(\w+)/gm, kind: "const" },
|
|
44
|
+
{ pattern: /^export\s+enum\s+(\w+)/gm, kind: "enum" }
|
|
45
|
+
],
|
|
46
|
+
local: [
|
|
47
|
+
{ pattern: /^(?:async\s+)?function\s+(\w+)/gm, kind: "function" },
|
|
48
|
+
{ pattern: /^class\s+(\w+)/gm, kind: "class" },
|
|
49
|
+
{ pattern: /^interface\s+(\w+)/gm, kind: "interface" },
|
|
50
|
+
{ pattern: /^type\s+(\w+)/gm, kind: "type" },
|
|
51
|
+
{ pattern: /^(?:const|let)\s+(\w+)\s*=/gm, kind: "const" },
|
|
52
|
+
{ pattern: /^enum\s+(\w+)/gm, kind: "enum" }
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
const JAVA_PATTERNS = {
|
|
56
|
+
exported: [
|
|
57
|
+
{
|
|
58
|
+
pattern: /^[ \t]*public\s+(?:static\s+)?(?:abstract\s+)?class\s+(\w+)/gm,
|
|
59
|
+
kind: "class"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
pattern: /^[ \t]*public\s+(?:static\s+)?interface\s+(\w+)/gm,
|
|
63
|
+
kind: "interface"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
pattern: /^[ \t]*public\s+(?:static\s+)?enum\s+(\w+)/gm,
|
|
67
|
+
kind: "enum"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
pattern: /^[ \t]*public\s+(?:static\s+)?(?:synchronized\s+)?(?:final\s+)?(?:abstract\s+)?(?:\w+(?:<[^>]*>)?(?:\[\])*)\s+(\w+)\s*\(/gm,
|
|
71
|
+
kind: "function"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
local: [
|
|
75
|
+
{
|
|
76
|
+
pattern: /^[ \t]*(?:private|protected)\s+(?:static\s+)?(?:abstract\s+)?class\s+(\w+)/gm,
|
|
77
|
+
kind: "class"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
pattern: /^[ \t]*(?:private|protected)\s+(?:static\s+)?(?:synchronized\s+)?(?:final\s+)?(?:\w+(?:<[^>]*>)?(?:\[\])*)\s+(\w+)\s*\(/gm,
|
|
81
|
+
kind: "function"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
pattern: /^[ \t]*(?:private|protected)\s+(?:static\s+)?(?:final\s+)?(?:\w+(?:<[^>]*>)?)\s+(\w+)\s*[;=]/gm,
|
|
85
|
+
kind: "variable"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
skipIndentFilter: true
|
|
89
|
+
};
|
|
90
|
+
const PYTHON_PATTERNS = {
|
|
91
|
+
exported: [
|
|
92
|
+
// Top-level functions (no leading whitespace = module-level = "exported")
|
|
93
|
+
{ pattern: /^def\s+(\w+)\s*\(/gm, kind: "function" },
|
|
94
|
+
{ pattern: /^async\s+def\s+(\w+)\s*\(/gm, kind: "function" },
|
|
95
|
+
{ pattern: /^class\s+(\w+)/gm, kind: "class" }
|
|
96
|
+
],
|
|
97
|
+
local: [
|
|
98
|
+
// Indented methods inside classes
|
|
99
|
+
{ pattern: /^[ \t]+def\s+(\w+)\s*\(/gm, kind: "function" },
|
|
100
|
+
{ pattern: /^[ \t]+async\s+def\s+(\w+)\s*\(/gm, kind: "function" }
|
|
101
|
+
],
|
|
102
|
+
skipIndentFilter: true
|
|
103
|
+
};
|
|
104
|
+
const GO_PATTERNS = {
|
|
105
|
+
exported: [
|
|
106
|
+
// Exported = starts with uppercase
|
|
107
|
+
{ pattern: /^func\s+([A-Z]\w*)\s*\(/gm, kind: "function" },
|
|
108
|
+
// Method with receiver
|
|
109
|
+
{ pattern: /^func\s+\([^)]+\)\s+([A-Z]\w*)\s*\(/gm, kind: "function" },
|
|
110
|
+
{ pattern: /^type\s+([A-Z]\w*)\s+struct\b/gm, kind: "class" },
|
|
111
|
+
{ pattern: /^type\s+([A-Z]\w*)\s+interface\b/gm, kind: "interface" },
|
|
112
|
+
{ pattern: /^type\s+([A-Z]\w*)\s+/gm, kind: "type" }
|
|
113
|
+
],
|
|
114
|
+
local: [
|
|
115
|
+
{ pattern: /^func\s+([a-z]\w*)\s*\(/gm, kind: "function" },
|
|
116
|
+
{ pattern: /^func\s+\([^)]+\)\s+([a-z]\w*)\s*\(/gm, kind: "function" },
|
|
117
|
+
{ pattern: /^type\s+([a-z]\w*)\s+struct\b/gm, kind: "class" },
|
|
118
|
+
{ pattern: /^type\s+([a-z]\w*)\s+/gm, kind: "type" }
|
|
119
|
+
],
|
|
120
|
+
skipIndentFilter: true
|
|
121
|
+
};
|
|
122
|
+
const CSHARP_PATTERNS = {
|
|
123
|
+
exported: [
|
|
124
|
+
{
|
|
125
|
+
pattern: /^[ \t]*public\s+(?:static\s+)?(?:partial\s+)?(?:abstract\s+)?class\s+(\w+)/gm,
|
|
126
|
+
kind: "class"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
pattern: /^[ \t]*public\s+(?:static\s+)?interface\s+(\w+)/gm,
|
|
130
|
+
kind: "interface"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
pattern: /^[ \t]*public\s+(?:static\s+)?enum\s+(\w+)/gm,
|
|
134
|
+
kind: "enum"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
pattern: /^[ \t]*public\s+(?:static\s+)?(?:virtual\s+)?(?:override\s+)?(?:async\s+)?(?:\w+(?:<[^>]*>)?(?:\[\])?)\s+(\w+)\s*\(/gm,
|
|
138
|
+
kind: "function"
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
local: [
|
|
142
|
+
{
|
|
143
|
+
pattern: /^[ \t]*(?:private|protected|internal)\s+(?:static\s+)?(?:abstract\s+)?class\s+(\w+)/gm,
|
|
144
|
+
kind: "class"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
pattern: /^[ \t]*(?:private|protected|internal)\s+(?:static\s+)?(?:async\s+)?(?:\w+(?:<[^>]*>)?)\s+(\w+)\s*\(/gm,
|
|
148
|
+
kind: "function"
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
skipIndentFilter: true
|
|
152
|
+
};
|
|
153
|
+
const KOTLIN_PATTERNS = {
|
|
154
|
+
exported: [
|
|
155
|
+
{ pattern: /^(?:open\s+|data\s+|sealed\s+)?class\s+(\w+)/gm, kind: "class" },
|
|
156
|
+
{ pattern: /^(?:fun|suspend\s+fun)\s+(\w+)\s*[(<]/gm, kind: "function" },
|
|
157
|
+
{ pattern: /^interface\s+(\w+)/gm, kind: "interface" },
|
|
158
|
+
{ pattern: /^object\s+(\w+)/gm, kind: "class" },
|
|
159
|
+
{ pattern: /^enum\s+class\s+(\w+)/gm, kind: "enum" }
|
|
160
|
+
],
|
|
161
|
+
local: [
|
|
162
|
+
{ pattern: /^[ \t]+(?:private|internal)\s+(?:fun|suspend\s+fun)\s+(\w+)/gm, kind: "function" },
|
|
163
|
+
{ pattern: /^[ \t]+(?:private|internal)\s+(?:val|var)\s+(\w+)/gm, kind: "variable" }
|
|
164
|
+
],
|
|
165
|
+
skipIndentFilter: true
|
|
166
|
+
};
|
|
167
|
+
const RUBY_PATTERNS = {
|
|
168
|
+
exported: [
|
|
169
|
+
{ pattern: /^class\s+(\w+)/gm, kind: "class" },
|
|
170
|
+
{ pattern: /^module\s+(\w+)/gm, kind: "class" },
|
|
171
|
+
{ pattern: /^[ \t]+def\s+self\.(\w+)/gm, kind: "function" }
|
|
172
|
+
],
|
|
173
|
+
local: [{ pattern: /^[ \t]+def\s+(\w+)/gm, kind: "function" }],
|
|
174
|
+
skipIndentFilter: true
|
|
175
|
+
};
|
|
176
|
+
const RUST_PATTERNS = {
|
|
177
|
+
exported: [
|
|
178
|
+
{ pattern: /^pub\s+(?:async\s+)?fn\s+(\w+)/gm, kind: "function" },
|
|
179
|
+
{ pattern: /^pub\s+struct\s+(\w+)/gm, kind: "class" },
|
|
180
|
+
{ pattern: /^pub\s+trait\s+(\w+)/gm, kind: "interface" },
|
|
181
|
+
{ pattern: /^pub\s+enum\s+(\w+)/gm, kind: "enum" },
|
|
182
|
+
{ pattern: /^pub\s+type\s+(\w+)/gm, kind: "type" }
|
|
183
|
+
],
|
|
184
|
+
local: [
|
|
185
|
+
{ pattern: /^(?:async\s+)?fn\s+(\w+)/gm, kind: "function" },
|
|
186
|
+
{ pattern: /^struct\s+(\w+)/gm, kind: "class" },
|
|
187
|
+
{ pattern: /^trait\s+(\w+)/gm, kind: "interface" },
|
|
188
|
+
{ pattern: /^enum\s+(\w+)/gm, kind: "enum" }
|
|
189
|
+
],
|
|
190
|
+
skipIndentFilter: true
|
|
191
|
+
};
|
|
192
|
+
const PHP_PATTERNS = {
|
|
193
|
+
exported: [
|
|
194
|
+
{ pattern: /^[ \t]*(?:abstract\s+)?class\s+(\w+)/gm, kind: "class" },
|
|
195
|
+
{ pattern: /^[ \t]*interface\s+(\w+)/gm, kind: "interface" },
|
|
196
|
+
{ pattern: /^[ \t]*public\s+(?:static\s+)?function\s+(\w+)/gm, kind: "function" },
|
|
197
|
+
{ pattern: /^function\s+(\w+)\s*\(/gm, kind: "function" }
|
|
198
|
+
],
|
|
199
|
+
local: [
|
|
200
|
+
{
|
|
201
|
+
pattern: /^[ \t]*(?:private|protected)\s+(?:static\s+)?function\s+(\w+)/gm,
|
|
202
|
+
kind: "function"
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
skipIndentFilter: true
|
|
206
|
+
};
|
|
207
|
+
const SWIFT_PATTERNS = {
|
|
208
|
+
exported: [
|
|
209
|
+
{ pattern: /^[ \t]*(?:open|public)\s+class\s+(\w+)/gm, kind: "class" },
|
|
210
|
+
{ pattern: /^[ \t]*(?:open|public)\s+struct\s+(\w+)/gm, kind: "class" },
|
|
211
|
+
{ pattern: /^[ \t]*(?:open|public)\s+protocol\s+(\w+)/gm, kind: "interface" },
|
|
212
|
+
{ pattern: /^[ \t]*(?:open|public)\s+enum\s+(\w+)/gm, kind: "enum" },
|
|
213
|
+
{ pattern: /^[ \t]*(?:open|public)\s+func\s+(\w+)/gm, kind: "function" }
|
|
214
|
+
],
|
|
215
|
+
local: [
|
|
216
|
+
{ pattern: /^[ \t]*(?:private|fileprivate|internal)\s+func\s+(\w+)/gm, kind: "function" },
|
|
217
|
+
{ pattern: /^[ \t]*(?:private|fileprivate|internal)\s+class\s+(\w+)/gm, kind: "class" }
|
|
218
|
+
],
|
|
219
|
+
skipIndentFilter: true
|
|
220
|
+
};
|
|
221
|
+
const SCALA_PATTERNS = {
|
|
222
|
+
exported: [
|
|
223
|
+
{ pattern: /^[ \t]*(?:case\s+)?class\s+(\w+)/gm, kind: "class" },
|
|
224
|
+
{ pattern: /^[ \t]*object\s+(\w+)/gm, kind: "class" },
|
|
225
|
+
{ pattern: /^[ \t]*trait\s+(\w+)/gm, kind: "interface" },
|
|
226
|
+
{ pattern: /^[ \t]*def\s+(\w+)/gm, kind: "function" }
|
|
227
|
+
],
|
|
228
|
+
local: [],
|
|
229
|
+
skipIndentFilter: true
|
|
230
|
+
};
|
|
231
|
+
function getLangPatterns(ext) {
|
|
232
|
+
switch (ext) {
|
|
233
|
+
case ".ts":
|
|
234
|
+
case ".tsx":
|
|
235
|
+
case ".js":
|
|
236
|
+
case ".jsx":
|
|
237
|
+
return TS_PATTERNS;
|
|
238
|
+
case ".java":
|
|
239
|
+
return JAVA_PATTERNS;
|
|
240
|
+
case ".py":
|
|
241
|
+
return PYTHON_PATTERNS;
|
|
242
|
+
case ".go":
|
|
243
|
+
return GO_PATTERNS;
|
|
244
|
+
case ".cs":
|
|
245
|
+
return CSHARP_PATTERNS;
|
|
246
|
+
case ".kt":
|
|
247
|
+
return KOTLIN_PATTERNS;
|
|
248
|
+
case ".rb":
|
|
249
|
+
return RUBY_PATTERNS;
|
|
250
|
+
case ".rs":
|
|
251
|
+
return RUST_PATTERNS;
|
|
252
|
+
case ".php":
|
|
253
|
+
return PHP_PATTERNS;
|
|
254
|
+
case ".swift":
|
|
255
|
+
return SWIFT_PATTERNS;
|
|
256
|
+
case ".scala":
|
|
257
|
+
return SCALA_PATTERNS;
|
|
258
|
+
default:
|
|
259
|
+
return TS_PATTERNS;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function extractSignature(lines, startLine) {
|
|
263
|
+
let sig = "";
|
|
264
|
+
let parenDepth = 0;
|
|
265
|
+
let foundOpen = false;
|
|
266
|
+
for (let i = startLine; i < Math.min(startLine + 5, lines.length); i++) {
|
|
267
|
+
const line = lines[i].trim();
|
|
268
|
+
sig += (sig ? " " : "") + line;
|
|
269
|
+
for (const ch of line) {
|
|
270
|
+
if (ch === "(") {
|
|
271
|
+
parenDepth++;
|
|
272
|
+
foundOpen = true;
|
|
273
|
+
}
|
|
274
|
+
if (ch === ")") parenDepth--;
|
|
275
|
+
}
|
|
276
|
+
if (foundOpen && parenDepth <= 0) {
|
|
277
|
+
return sig.replace(/\s*\{.*$/, "").replace(/\s*:\s*$/, "").trim();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return sig.trim() || void 0;
|
|
281
|
+
}
|
|
282
|
+
class SymbolAnalyzer {
|
|
283
|
+
name = "symbols";
|
|
284
|
+
async analyze(rootPath, options = {}) {
|
|
285
|
+
const { format = "markdown", filter } = options;
|
|
286
|
+
const startTime = Date.now();
|
|
287
|
+
const files = await this.collectFiles(rootPath);
|
|
288
|
+
let symbols = [];
|
|
289
|
+
for (const filePath of files) {
|
|
290
|
+
const content = await readFile(filePath, "utf-8");
|
|
291
|
+
const fileSymbols = this.extractSymbols(
|
|
292
|
+
content,
|
|
293
|
+
relative(rootPath, filePath).replace(/\\/g, "/")
|
|
294
|
+
);
|
|
295
|
+
symbols.push(...fileSymbols);
|
|
296
|
+
}
|
|
297
|
+
if (filter) {
|
|
298
|
+
const filterLower = filter.toLowerCase();
|
|
299
|
+
symbols = symbols.filter((s) => s.name.toLowerCase().includes(filterLower));
|
|
300
|
+
}
|
|
301
|
+
const output = format === "json" ? JSON.stringify(symbols, null, 2) : this.formatMarkdown(symbols, rootPath);
|
|
302
|
+
return {
|
|
303
|
+
output,
|
|
304
|
+
data: {
|
|
305
|
+
symbols,
|
|
306
|
+
byKind: this.groupByKind(symbols),
|
|
307
|
+
exportedCount: symbols.filter((s) => s.exported).length,
|
|
308
|
+
totalCount: symbols.length
|
|
309
|
+
},
|
|
310
|
+
meta: {
|
|
311
|
+
analyzedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
312
|
+
scope: rootPath,
|
|
313
|
+
fileCount: files.length,
|
|
314
|
+
durationMs: Date.now() - startTime
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
async collectFiles(dirPath) {
|
|
319
|
+
const files = [];
|
|
320
|
+
const walk = async (dir) => {
|
|
321
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
322
|
+
for (const entry of entries) {
|
|
323
|
+
if (DEFAULT_EXCLUDES.has(entry.name)) continue;
|
|
324
|
+
if (entry.name.startsWith(".")) continue;
|
|
325
|
+
const fullPath = join(dir, entry.name);
|
|
326
|
+
if (entry.isDirectory()) {
|
|
327
|
+
await walk(fullPath);
|
|
328
|
+
} else if (CODE_EXTENSIONS.has(extname(entry.name))) {
|
|
329
|
+
files.push(fullPath);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
await walk(dirPath);
|
|
334
|
+
return files;
|
|
335
|
+
}
|
|
336
|
+
extractSymbols(content, filePath) {
|
|
337
|
+
const symbols = [];
|
|
338
|
+
const lines = content.split("\n");
|
|
339
|
+
const exportedNames = /* @__PURE__ */ new Set();
|
|
340
|
+
const ext = extname(filePath);
|
|
341
|
+
const lang = getLangPatterns(ext);
|
|
342
|
+
for (const { pattern, kind } of lang.exported) {
|
|
343
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
344
|
+
let match;
|
|
345
|
+
while ((match = regex.exec(content)) !== null) {
|
|
346
|
+
const name = match[1];
|
|
347
|
+
exportedNames.add(name);
|
|
348
|
+
const line = content.slice(0, match.index).split("\n").length;
|
|
349
|
+
const signature = kind === "function" || kind === "method" ? extractSignature(lines, line - 1) : void 0;
|
|
350
|
+
symbols.push({ name, kind, exported: true, filePath, line, signature });
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
for (const { pattern, kind } of lang.local) {
|
|
354
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
355
|
+
let match;
|
|
356
|
+
while ((match = regex.exec(content)) !== null) {
|
|
357
|
+
const name = match[1];
|
|
358
|
+
if (exportedNames.has(name)) continue;
|
|
359
|
+
if (!lang.skipIndentFilter) {
|
|
360
|
+
const lineIdx = content.slice(0, match.index).split("\n").length - 1;
|
|
361
|
+
const lineContent = lines[lineIdx] ?? "";
|
|
362
|
+
if (lineContent.startsWith(" ") || lineContent.startsWith(" ")) continue;
|
|
363
|
+
}
|
|
364
|
+
const line = content.slice(0, match.index).split("\n").length;
|
|
365
|
+
const signature = kind === "function" || kind === "method" ? extractSignature(lines, line - 1) : void 0;
|
|
366
|
+
symbols.push({ name, kind, exported: false, filePath, line, signature });
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return symbols;
|
|
370
|
+
}
|
|
371
|
+
groupByKind(symbols) {
|
|
372
|
+
const groups = {};
|
|
373
|
+
for (const s of symbols) {
|
|
374
|
+
groups[s.kind] = (groups[s.kind] ?? 0) + 1;
|
|
375
|
+
}
|
|
376
|
+
return groups;
|
|
377
|
+
}
|
|
378
|
+
formatMarkdown(symbols, rootPath) {
|
|
379
|
+
const lines = [];
|
|
380
|
+
const exported = symbols.filter((s) => s.exported).length;
|
|
381
|
+
lines.push(`## Symbols: ${rootPath}
|
|
382
|
+
`);
|
|
383
|
+
lines.push(`**${symbols.length} symbols** (${exported} exported)
|
|
384
|
+
`);
|
|
385
|
+
const kindCounts = {};
|
|
386
|
+
for (const s of symbols) {
|
|
387
|
+
kindCounts[s.kind] = (kindCounts[s.kind] ?? 0) + 1;
|
|
388
|
+
}
|
|
389
|
+
const kindSummary = Object.entries(kindCounts).sort((a, b) => b[1] - a[1]).map(([kind, count]) => {
|
|
390
|
+
const plural = kind === "class" ? "classes" : `${kind}s`;
|
|
391
|
+
return `${count} ${plural}`;
|
|
392
|
+
}).join(", ");
|
|
393
|
+
lines.push(`**Breakdown**: ${kindSummary}
|
|
394
|
+
`);
|
|
395
|
+
const byFile = {};
|
|
396
|
+
for (const s of symbols) {
|
|
397
|
+
if (!byFile[s.filePath]) byFile[s.filePath] = [];
|
|
398
|
+
byFile[s.filePath].push(s);
|
|
399
|
+
}
|
|
400
|
+
lines.push(`**${Object.keys(byFile).length} files** with symbols
|
|
401
|
+
`);
|
|
402
|
+
let totalOutputBytes = 0;
|
|
403
|
+
const MAX_OUTPUT_BYTES = 80 * 1024;
|
|
404
|
+
const sortedFiles = Object.entries(byFile).sort((a, b) => {
|
|
405
|
+
const aExports = a[1].filter((s) => s.exported).length;
|
|
406
|
+
const bExports = b[1].filter((s) => s.exported).length;
|
|
407
|
+
return bExports - aExports;
|
|
408
|
+
});
|
|
409
|
+
for (const [file, fileSymbols] of sortedFiles) {
|
|
410
|
+
const exportedSyms = fileSymbols.filter((s) => s.exported);
|
|
411
|
+
if (exportedSyms.length === 0) continue;
|
|
412
|
+
const fileSection = [`### ${file}
|
|
413
|
+
`];
|
|
414
|
+
for (const s of exportedSyms) {
|
|
415
|
+
const sig = s.signature ? ` \u2014 \`${s.signature}\`` : "";
|
|
416
|
+
fileSection.push(`- \u{1F4E4} \`${s.kind}\` **${s.name}** (line ${s.line})${sig}`);
|
|
417
|
+
}
|
|
418
|
+
const internalCount = fileSymbols.length - exportedSyms.length;
|
|
419
|
+
if (internalCount > 0) {
|
|
420
|
+
fileSection.push(
|
|
421
|
+
`- _${internalCount} internal ${internalCount === 1 ? "symbol" : "symbols"}_`
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
fileSection.push("");
|
|
425
|
+
const sectionText = fileSection.join("\n");
|
|
426
|
+
totalOutputBytes += sectionText.length;
|
|
427
|
+
if (totalOutputBytes > MAX_OUTPUT_BYTES) {
|
|
428
|
+
lines.push(
|
|
429
|
+
`
|
|
430
|
+
_Output truncated at 80KB. ${Object.keys(byFile).length - lines.filter((l) => l.startsWith("### ")).length} files omitted._`
|
|
431
|
+
);
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
lines.push(sectionText);
|
|
435
|
+
}
|
|
436
|
+
return lines.join("\n");
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
export {
|
|
440
|
+
SymbolAnalyzer
|
|
441
|
+
};
|
|
442
|
+
//# sourceMappingURL=symbol-analyzer.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript Compiler API-based call graph extractor.
|
|
3
|
+
*
|
|
4
|
+
* Uses ts.createProgram to build a real type-checked program, then walks
|
|
5
|
+
* the AST to find function call sites and resolve them to their declaration files.
|
|
6
|
+
* Produces module-level call edges: which modules call functions in which other modules.
|
|
7
|
+
*/
|
|
8
|
+
export interface ModuleCallEdge {
|
|
9
|
+
/** Caller module (relative path) */
|
|
10
|
+
from: string;
|
|
11
|
+
/** Callee module (relative path) */
|
|
12
|
+
to: string;
|
|
13
|
+
/** Function/symbol names called across this edge */
|
|
14
|
+
symbols: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface CallGraphResult {
|
|
17
|
+
edges: ModuleCallEdge[];
|
|
18
|
+
fileCount: number;
|
|
19
|
+
edgeCount: number;
|
|
20
|
+
durationMs: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extract module-level call graph from a TypeScript/JavaScript project.
|
|
24
|
+
* Returns null if TypeScript compiler is unavailable or no TS files found.
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractTsCallGraph(rootPath: string): Promise<CallGraphResult | null>;
|
|
27
|
+
//# sourceMappingURL=ts-call-graph.d.ts.map
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { extname, join, relative } from "node:path";
|
|
3
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
4
|
+
"node_modules",
|
|
5
|
+
".git",
|
|
6
|
+
"dist",
|
|
7
|
+
"build",
|
|
8
|
+
"coverage",
|
|
9
|
+
".turbo",
|
|
10
|
+
".cache",
|
|
11
|
+
"cdk.out"
|
|
12
|
+
]);
|
|
13
|
+
async function extractTsCallGraph(rootPath) {
|
|
14
|
+
const startTime = Date.now();
|
|
15
|
+
if (!hasTsConfig(rootPath)) return null;
|
|
16
|
+
let ts;
|
|
17
|
+
try {
|
|
18
|
+
ts = await import("typescript");
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const sourceFiles = collectTsFiles(rootPath);
|
|
23
|
+
if (sourceFiles.length === 0) return null;
|
|
24
|
+
const cappedFiles = sourceFiles.slice(0, 800);
|
|
25
|
+
const compilerOptions = loadCompilerOptions(ts, rootPath);
|
|
26
|
+
const program = ts.createProgram(cappedFiles, {
|
|
27
|
+
...compilerOptions,
|
|
28
|
+
noEmit: true,
|
|
29
|
+
skipLibCheck: true,
|
|
30
|
+
allowJs: true,
|
|
31
|
+
target: ts.ScriptTarget.ESNext,
|
|
32
|
+
module: ts.ModuleKind.ESNext,
|
|
33
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
34
|
+
});
|
|
35
|
+
const checker = program.getTypeChecker();
|
|
36
|
+
const edgeMap = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const sourceFile of program.getSourceFiles()) {
|
|
38
|
+
const fileName = sourceFile.fileName;
|
|
39
|
+
if (sourceFile.isDeclarationFile) continue;
|
|
40
|
+
if (fileName.includes("node_modules")) continue;
|
|
41
|
+
const callerRel = relative(rootPath, fileName).replace(/\\/g, "/");
|
|
42
|
+
if (callerRel.startsWith("..")) continue;
|
|
43
|
+
visitNode(ts, sourceFile, sourceFile, checker, rootPath, callerRel, edgeMap);
|
|
44
|
+
}
|
|
45
|
+
const edges = [];
|
|
46
|
+
for (const [key, syms] of edgeMap) {
|
|
47
|
+
const [from, to] = key.split("|");
|
|
48
|
+
edges.push({ from, to, symbols: [...syms].sort().slice(0, 10) });
|
|
49
|
+
}
|
|
50
|
+
edges.sort((a, b) => b.symbols.length - a.symbols.length);
|
|
51
|
+
return {
|
|
52
|
+
edges,
|
|
53
|
+
fileCount: cappedFiles.length,
|
|
54
|
+
edgeCount: edges.length,
|
|
55
|
+
durationMs: Date.now() - startTime
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function hasTsConfig(rootPath) {
|
|
59
|
+
if (existsSync(join(rootPath, "tsconfig.json"))) return true;
|
|
60
|
+
if (existsSync(join(rootPath, "tsconfig.build.json"))) return true;
|
|
61
|
+
try {
|
|
62
|
+
for (const entry of readdirSync(rootPath, { withFileTypes: true })) {
|
|
63
|
+
if (entry.isDirectory() && !SKIP_DIRS.has(entry.name) && !entry.name.startsWith(".")) {
|
|
64
|
+
if (existsSync(join(rootPath, entry.name, "tsconfig.json"))) return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
function loadCompilerOptions(ts, rootPath) {
|
|
72
|
+
const tsconfigPath = join(rootPath, "tsconfig.json");
|
|
73
|
+
if (!existsSync(tsconfigPath)) return {};
|
|
74
|
+
try {
|
|
75
|
+
const configFile = ts.readConfigFile(tsconfigPath, (p) => readFileSync(p, "utf-8"));
|
|
76
|
+
if (configFile.error) return {};
|
|
77
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, rootPath);
|
|
78
|
+
return parsed.options;
|
|
79
|
+
} catch {
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function collectTsFiles(rootPath) {
|
|
84
|
+
const files = [];
|
|
85
|
+
const tsExts = /* @__PURE__ */ new Set([".ts", ".tsx"]);
|
|
86
|
+
const walk = (dir, depth) => {
|
|
87
|
+
if (depth > 10) return;
|
|
88
|
+
try {
|
|
89
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
90
|
+
if (SKIP_DIRS.has(entry.name) || entry.name.startsWith(".")) continue;
|
|
91
|
+
const fullPath = join(dir, entry.name);
|
|
92
|
+
if (entry.isDirectory()) {
|
|
93
|
+
walk(fullPath, depth + 1);
|
|
94
|
+
} else if (tsExts.has(extname(entry.name))) {
|
|
95
|
+
if (entry.name.endsWith(".d.ts")) continue;
|
|
96
|
+
if (/\.(test|spec)\.[jt]sx?$/.test(entry.name)) continue;
|
|
97
|
+
const relDir = relative(rootPath, dir).replace(/\\/g, "/");
|
|
98
|
+
if (relDir.split("/").some((s) => s === "test" || s === "tests" || s === "__tests__" || s === "spec"))
|
|
99
|
+
continue;
|
|
100
|
+
files.push(fullPath);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
walk(rootPath, 0);
|
|
107
|
+
return files;
|
|
108
|
+
}
|
|
109
|
+
function visitNode(ts, node, sourceFile, checker, rootPath, callerRel, edgeMap) {
|
|
110
|
+
if (ts.isCallExpression(node) || ts.isNewExpression(node)) {
|
|
111
|
+
const expr = node.expression;
|
|
112
|
+
resolveCallTarget(ts, expr, checker, rootPath, callerRel, edgeMap);
|
|
113
|
+
}
|
|
114
|
+
ts.forEachChild(node, (child) => {
|
|
115
|
+
visitNode(ts, child, sourceFile, checker, rootPath, callerRel, edgeMap);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function remapDistToSource(rel) {
|
|
119
|
+
const distMatch = rel.match(/^(.+?)\/dist\/(.+)$/);
|
|
120
|
+
if (!distMatch) return rel;
|
|
121
|
+
const [, prefix, rest] = distMatch;
|
|
122
|
+
const srcFile = rest.replace(/\.d\.(m?ts|cts)$/, ".ts");
|
|
123
|
+
return `${prefix}/src/${srcFile}`;
|
|
124
|
+
}
|
|
125
|
+
function resolveCallTarget(ts, expr, checker, rootPath, callerRel, edgeMap) {
|
|
126
|
+
try {
|
|
127
|
+
let symbol;
|
|
128
|
+
let symbolName;
|
|
129
|
+
if (ts.isIdentifier(expr)) {
|
|
130
|
+
symbol = checker.getSymbolAtLocation(expr);
|
|
131
|
+
symbolName = expr.text;
|
|
132
|
+
} else if (ts.isPropertyAccessExpression(expr)) {
|
|
133
|
+
symbol = checker.getSymbolAtLocation(expr.name);
|
|
134
|
+
symbolName = expr.name.text;
|
|
135
|
+
}
|
|
136
|
+
if (!symbol || !symbolName) return;
|
|
137
|
+
if (symbol.flags & ts.SymbolFlags.Alias) {
|
|
138
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
139
|
+
}
|
|
140
|
+
const declarations = symbol.getDeclarations();
|
|
141
|
+
if (!declarations || declarations.length === 0) return;
|
|
142
|
+
const declFile = declarations[0].getSourceFile().fileName;
|
|
143
|
+
if (declFile.includes("node_modules")) return;
|
|
144
|
+
let calleeRel = relative(rootPath, declFile).replace(/\\/g, "/");
|
|
145
|
+
calleeRel = remapDistToSource(calleeRel);
|
|
146
|
+
if (calleeRel === callerRel || calleeRel.startsWith("..")) return;
|
|
147
|
+
const key = `${callerRel}|${calleeRel}`;
|
|
148
|
+
const existing = edgeMap.get(key);
|
|
149
|
+
if (existing) {
|
|
150
|
+
existing.add(symbolName);
|
|
151
|
+
} else {
|
|
152
|
+
edgeMap.set(key, /* @__PURE__ */ new Set([symbolName]));
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
extractTsCallGraph
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=ts-call-graph.js.map
|