@optave/codegraph 3.1.4 → 3.2.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/README.md +29 -72
- package/package.json +10 -8
- package/src/ast-analysis/engine.js +260 -246
- package/src/ast-analysis/shared.js +2 -14
- package/src/ast-analysis/visitors/cfg-visitor.js +635 -649
- package/src/ast-analysis/visitors/complexity-visitor.js +135 -139
- package/src/ast-analysis/visitors/dataflow-visitor.js +230 -224
- package/src/cli/commands/ast.js +4 -7
- package/src/cli/commands/audit.js +11 -11
- package/src/cli/commands/batch.js +6 -5
- package/src/cli/commands/branch-compare.js +1 -1
- package/src/cli/commands/brief.js +12 -0
- package/src/cli/commands/build.js +1 -1
- package/src/cli/commands/cfg.js +5 -8
- package/src/cli/commands/check.js +28 -36
- package/src/cli/commands/children.js +9 -7
- package/src/cli/commands/co-change.js +5 -3
- package/src/cli/commands/communities.js +2 -6
- package/src/cli/commands/complexity.js +5 -3
- package/src/cli/commands/context.js +9 -8
- package/src/cli/commands/cycles.js +12 -8
- package/src/cli/commands/dataflow.js +5 -8
- package/src/cli/commands/deps.js +9 -8
- package/src/cli/commands/diff-impact.js +2 -6
- package/src/cli/commands/embed.js +1 -1
- package/src/cli/commands/export.js +34 -31
- package/src/cli/commands/exports.js +2 -6
- package/src/cli/commands/flow.js +5 -8
- package/src/cli/commands/fn-impact.js +9 -8
- package/src/cli/commands/impact.js +2 -6
- package/src/cli/commands/info.js +2 -2
- package/src/cli/commands/map.js +1 -1
- package/src/cli/commands/mcp.js +1 -1
- package/src/cli/commands/models.js +1 -1
- package/src/cli/commands/owners.js +5 -3
- package/src/cli/commands/path.js +2 -2
- package/src/cli/commands/plot.js +40 -31
- package/src/cli/commands/query.js +9 -8
- package/src/cli/commands/registry.js +2 -2
- package/src/cli/commands/roles.js +5 -8
- package/src/cli/commands/search.js +9 -3
- package/src/cli/commands/sequence.js +5 -8
- package/src/cli/commands/snapshot.js +6 -1
- package/src/cli/commands/stats.js +1 -1
- package/src/cli/commands/structure.js +5 -4
- package/src/cli/commands/triage.js +41 -30
- package/src/cli/commands/watch.js +1 -1
- package/src/cli/commands/where.js +2 -6
- package/src/cli/index.js +11 -5
- package/src/cli/shared/open-graph.js +13 -0
- package/src/cli/shared/options.js +22 -2
- package/src/cli.js +1 -1
- package/src/db/connection.js +140 -11
- package/src/{db.js → db/index.js} +12 -5
- package/src/db/migrations.js +42 -65
- package/src/db/query-builder.js +72 -9
- package/src/db/repository/base.js +1 -1
- package/src/db/repository/graph-read.js +3 -3
- package/src/db/repository/in-memory-repository.js +30 -28
- package/src/db/repository/nodes.js +10 -17
- package/src/domain/analysis/brief.js +155 -0
- package/src/domain/analysis/context.js +392 -0
- package/src/domain/analysis/dependencies.js +395 -0
- package/src/{analysis → domain/analysis}/exports.js +11 -6
- package/src/domain/analysis/impact.js +581 -0
- package/src/domain/analysis/module-map.js +348 -0
- package/src/{analysis → domain/analysis}/roles.js +12 -9
- package/src/{analysis → domain/analysis}/symbol-lookup.js +19 -11
- package/src/{builder → domain/graph/builder}/helpers.js +4 -4
- package/src/{builder → domain/graph/builder}/incremental.js +119 -93
- package/src/domain/graph/builder/pipeline.js +156 -0
- package/src/domain/graph/builder/stages/build-edges.js +376 -0
- package/src/{builder → domain/graph/builder}/stages/build-structure.js +4 -4
- package/src/{builder → domain/graph/builder}/stages/collect-files.js +2 -2
- package/src/{builder → domain/graph/builder}/stages/detect-changes.js +204 -183
- package/src/{builder → domain/graph/builder}/stages/finalize.js +4 -4
- package/src/domain/graph/builder/stages/insert-nodes.js +203 -0
- package/src/{builder → domain/graph/builder}/stages/parse-files.js +2 -2
- package/src/{builder → domain/graph/builder}/stages/resolve-imports.js +1 -1
- package/src/{builder → domain/graph/builder}/stages/run-analyses.js +2 -2
- package/src/{change-journal.js → domain/graph/change-journal.js} +1 -1
- package/src/{cycles.js → domain/graph/cycles.js} +4 -4
- package/src/{journal.js → domain/graph/journal.js} +1 -1
- package/src/{resolve.js → domain/graph/resolve.js} +2 -2
- package/src/{watcher.js → domain/graph/watcher.js} +7 -7
- package/src/{parser.js → domain/parser.js} +24 -15
- package/src/{queries.js → domain/queries.js} +17 -16
- package/src/{embeddings → domain/search}/generator.js +3 -3
- package/src/{embeddings → domain/search}/models.js +2 -2
- package/src/{embeddings → domain/search}/search/cli-formatter.js +1 -1
- package/src/{embeddings → domain/search}/search/filters.js +9 -5
- package/src/{embeddings → domain/search}/search/hybrid.js +1 -1
- package/src/{embeddings → domain/search}/search/keyword.js +13 -6
- package/src/{embeddings → domain/search}/search/prepare.js +15 -7
- package/src/{embeddings → domain/search}/search/semantic.js +1 -1
- package/src/{embeddings → domain/search}/strategies/structured.js +1 -1
- package/src/extractors/csharp.js +224 -207
- package/src/extractors/go.js +176 -172
- package/src/extractors/hcl.js +94 -78
- package/src/extractors/java.js +213 -207
- package/src/extractors/javascript.js +275 -305
- package/src/extractors/php.js +234 -221
- package/src/extractors/python.js +252 -250
- package/src/extractors/ruby.js +192 -185
- package/src/extractors/rust.js +182 -167
- package/src/{ast.js → features/ast.js} +13 -11
- package/src/{audit.js → features/audit.js} +20 -46
- package/src/{batch.js → features/batch.js} +5 -5
- package/src/{boundaries.js → features/boundaries.js} +100 -85
- package/src/{branch-compare.js → features/branch-compare.js} +3 -3
- package/src/{cfg.js → features/cfg.js} +141 -150
- package/src/{check.js → features/check.js} +13 -30
- package/src/{cochange.js → features/cochange.js} +5 -5
- package/src/{communities.js → features/communities.js} +72 -57
- package/src/{complexity.js → features/complexity.js} +154 -143
- package/src/{dataflow.js → features/dataflow.js} +155 -158
- package/src/{export.js → features/export.js} +6 -6
- package/src/{flow.js → features/flow.js} +4 -4
- package/src/{viewer.js → features/graph-enrichment.js} +8 -8
- package/src/{manifesto.js → features/manifesto.js} +15 -12
- package/src/{owners.js → features/owners.js} +6 -5
- package/src/features/sequence.js +300 -0
- package/src/features/shared/find-nodes.js +31 -0
- package/src/{snapshot.js → features/snapshot.js} +3 -3
- package/src/{structure.js → features/structure.js} +139 -108
- package/src/features/triage.js +141 -0
- package/src/graph/builders/dependency.js +33 -14
- package/src/graph/classifiers/risk.js +3 -2
- package/src/graph/classifiers/roles.js +6 -3
- package/src/index.cjs +16 -0
- package/src/index.js +40 -39
- package/src/{native.js → infrastructure/native.js} +1 -1
- package/src/mcp/middleware.js +1 -1
- package/src/mcp/server.js +68 -59
- package/src/mcp/tool-registry.js +15 -2
- package/src/mcp/tools/ast-query.js +1 -1
- package/src/mcp/tools/audit.js +1 -1
- package/src/mcp/tools/batch-query.js +1 -1
- package/src/mcp/tools/branch-compare.js +3 -1
- package/src/mcp/tools/brief.js +8 -0
- package/src/mcp/tools/cfg.js +1 -1
- package/src/mcp/tools/check.js +3 -3
- package/src/mcp/tools/co-changes.js +1 -1
- package/src/mcp/tools/code-owners.js +1 -1
- package/src/mcp/tools/communities.js +1 -1
- package/src/mcp/tools/complexity.js +1 -1
- package/src/mcp/tools/dataflow.js +2 -2
- package/src/mcp/tools/execution-flow.js +2 -2
- package/src/mcp/tools/export-graph.js +2 -2
- package/src/mcp/tools/find-cycles.js +2 -2
- package/src/mcp/tools/index.js +2 -0
- package/src/mcp/tools/list-repos.js +1 -1
- package/src/mcp/tools/sequence.js +1 -1
- package/src/mcp/tools/structure.js +1 -1
- package/src/mcp/tools/triage.js +2 -2
- package/src/{commands → presentation}/audit.js +2 -2
- package/src/{commands → presentation}/batch.js +1 -1
- package/src/{commands → presentation}/branch-compare.js +2 -2
- package/src/presentation/brief.js +51 -0
- package/src/{commands → presentation}/cfg.js +1 -1
- package/src/{commands → presentation}/check.js +2 -2
- package/src/{commands → presentation}/communities.js +1 -1
- package/src/{commands → presentation}/complexity.js +1 -1
- package/src/{commands → presentation}/dataflow.js +1 -1
- package/src/{commands → presentation}/flow.js +2 -2
- package/src/{commands → presentation}/manifesto.js +1 -1
- package/src/{commands → presentation}/owners.js +1 -1
- package/src/presentation/queries-cli/exports.js +53 -0
- package/src/presentation/queries-cli/impact.js +214 -0
- package/src/presentation/queries-cli/index.js +5 -0
- package/src/presentation/queries-cli/inspect.js +329 -0
- package/src/presentation/queries-cli/overview.js +196 -0
- package/src/presentation/queries-cli/path.js +65 -0
- package/src/presentation/queries-cli.js +27 -0
- package/src/{commands → presentation}/query.js +1 -1
- package/src/presentation/result-formatter.js +126 -3
- package/src/{commands → presentation}/sequence.js +2 -2
- package/src/{commands → presentation}/structure.js +1 -1
- package/src/presentation/table.js +0 -8
- package/src/{commands → presentation}/triage.js +1 -1
- package/src/{constants.js → shared/constants.js} +1 -1
- package/src/shared/file-utils.js +2 -2
- package/src/shared/generators.js +9 -5
- package/src/shared/hierarchy.js +1 -1
- package/src/{kinds.js → shared/kinds.js} +1 -1
- package/src/analysis/context.js +0 -408
- package/src/analysis/dependencies.js +0 -341
- package/src/analysis/impact.js +0 -463
- package/src/analysis/module-map.js +0 -322
- package/src/builder/pipeline.js +0 -130
- package/src/builder/stages/build-edges.js +0 -297
- package/src/builder/stages/insert-nodes.js +0 -195
- package/src/mcp.js +0 -2
- package/src/queries-cli.js +0 -866
- package/src/sequence.js +0 -289
- package/src/triage.js +0 -126
- /package/src/{builder → domain/graph/builder}/context.js +0 -0
- /package/src/{builder.js → domain/graph/builder.js} +0 -0
- /package/src/{embeddings → domain/search}/index.js +0 -0
- /package/src/{embeddings → domain/search}/stores/fts5.js +0 -0
- /package/src/{embeddings → domain/search}/stores/sqlite-blob.js +0 -0
- /package/src/{embeddings → domain/search}/strategies/source.js +0 -0
- /package/src/{embeddings → domain/search}/strategies/text-utils.js +0 -0
- /package/src/{config.js → infrastructure/config.js} +0 -0
- /package/src/{logger.js → infrastructure/logger.js} +0 -0
- /package/src/{registry.js → infrastructure/registry.js} +0 -0
- /package/src/{update-check.js → infrastructure/update-check.js} +0 -0
- /package/src/{commands → presentation}/cochange.js +0 -0
- /package/src/{errors.js → shared/errors.js} +0 -0
- /package/src/{paginate.js → shared/paginate.js} +0 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import {
|
|
2
|
+
childrenData,
|
|
3
|
+
contextData,
|
|
4
|
+
explainData,
|
|
5
|
+
kindIcon,
|
|
6
|
+
queryNameData,
|
|
7
|
+
whereData,
|
|
8
|
+
} from '../../domain/queries.js';
|
|
9
|
+
import { outputResult } from '../../infrastructure/result-formatter.js';
|
|
10
|
+
|
|
11
|
+
export function where(target, customDbPath, opts = {}) {
|
|
12
|
+
const data = whereData(target, customDbPath, opts);
|
|
13
|
+
if (outputResult(data, 'results', opts)) return;
|
|
14
|
+
|
|
15
|
+
if (data.results.length === 0) {
|
|
16
|
+
console.log(
|
|
17
|
+
data.mode === 'file'
|
|
18
|
+
? `No file matching "${target}" in graph`
|
|
19
|
+
: `No symbol matching "${target}" in graph`,
|
|
20
|
+
);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (data.mode === 'symbol') {
|
|
25
|
+
for (const r of data.results) {
|
|
26
|
+
const roleTag = r.role ? ` [${r.role}]` : '';
|
|
27
|
+
const tag = r.exported ? ' (exported)' : '';
|
|
28
|
+
console.log(`\n${kindIcon(r.kind)} ${r.name}${roleTag} ${r.file}:${r.line}${tag}`);
|
|
29
|
+
if (r.uses.length > 0) {
|
|
30
|
+
const useStrs = r.uses.map((u) => `${u.file}:${u.line}`);
|
|
31
|
+
console.log(` Used in: ${useStrs.join(', ')}`);
|
|
32
|
+
} else {
|
|
33
|
+
console.log(' No uses found');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
for (const r of data.results) {
|
|
38
|
+
console.log(`\n# ${r.file}`);
|
|
39
|
+
if (r.symbols.length > 0) {
|
|
40
|
+
const symStrs = r.symbols.map((s) => `${s.name}:${s.line}`);
|
|
41
|
+
console.log(` Symbols: ${symStrs.join(', ')}`);
|
|
42
|
+
}
|
|
43
|
+
if (r.imports.length > 0) {
|
|
44
|
+
console.log(` Imports: ${r.imports.join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
if (r.importedBy.length > 0) {
|
|
47
|
+
console.log(` Imported by: ${r.importedBy.join(', ')}`);
|
|
48
|
+
}
|
|
49
|
+
if (r.exported.length > 0) {
|
|
50
|
+
console.log(` Exported: ${r.exported.join(', ')}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
console.log();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function queryName(name, customDbPath, opts = {}) {
|
|
58
|
+
const data = queryNameData(name, customDbPath, {
|
|
59
|
+
noTests: opts.noTests,
|
|
60
|
+
limit: opts.limit,
|
|
61
|
+
offset: opts.offset,
|
|
62
|
+
});
|
|
63
|
+
if (outputResult(data, 'results', opts)) return;
|
|
64
|
+
|
|
65
|
+
if (data.results.length === 0) {
|
|
66
|
+
console.log(`No results for "${name}"`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
console.log(`\nResults for "${name}":\n`);
|
|
71
|
+
for (const r of data.results) {
|
|
72
|
+
console.log(` ${kindIcon(r.kind)} ${r.name} (${r.kind}) -- ${r.file}:${r.line}`);
|
|
73
|
+
if (r.callees.length > 0) {
|
|
74
|
+
console.log(` -> calls/uses:`);
|
|
75
|
+
for (const c of r.callees.slice(0, 15))
|
|
76
|
+
console.log(` -> ${c.name} (${c.edgeKind}) ${c.file}:${c.line}`);
|
|
77
|
+
if (r.callees.length > 15) console.log(` ... and ${r.callees.length - 15} more`);
|
|
78
|
+
}
|
|
79
|
+
if (r.callers.length > 0) {
|
|
80
|
+
console.log(` <- called by:`);
|
|
81
|
+
for (const c of r.callers.slice(0, 15))
|
|
82
|
+
console.log(` <- ${c.name} (${c.edgeKind}) ${c.file}:${c.line}`);
|
|
83
|
+
if (r.callers.length > 15) console.log(` ... and ${r.callers.length - 15} more`);
|
|
84
|
+
}
|
|
85
|
+
console.log();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function context(name, customDbPath, opts = {}) {
|
|
90
|
+
const data = contextData(name, customDbPath, opts);
|
|
91
|
+
if (outputResult(data, 'results', opts)) return;
|
|
92
|
+
|
|
93
|
+
if (data.results.length === 0) {
|
|
94
|
+
console.log(`No function/method/class matching "${name}"`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (const r of data.results) {
|
|
99
|
+
renderContextResult(r);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function children(name, customDbPath, opts = {}) {
|
|
104
|
+
const data = childrenData(name, customDbPath, opts);
|
|
105
|
+
if (outputResult(data, 'results', opts)) return;
|
|
106
|
+
|
|
107
|
+
if (data.results.length === 0) {
|
|
108
|
+
console.log(`No symbol matching "${name}"`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for (const r of data.results) {
|
|
112
|
+
console.log(`\n${kindIcon(r.kind)} ${r.name} ${r.file}:${r.line}`);
|
|
113
|
+
if (r.children.length === 0) {
|
|
114
|
+
console.log(' (no children)');
|
|
115
|
+
} else {
|
|
116
|
+
for (const c of r.children) {
|
|
117
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} :${c.line}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function renderContextResult(r) {
|
|
124
|
+
const lineRange = r.endLine ? `${r.line}-${r.endLine}` : `${r.line}`;
|
|
125
|
+
const roleTag = r.role ? ` [${r.role}]` : '';
|
|
126
|
+
console.log(`\n# ${r.name} (${r.kind})${roleTag} — ${r.file}:${lineRange}\n`);
|
|
127
|
+
|
|
128
|
+
if (r.signature) {
|
|
129
|
+
console.log('## Type/Shape Info');
|
|
130
|
+
if (r.signature.params != null) console.log(` Parameters: (${r.signature.params})`);
|
|
131
|
+
if (r.signature.returnType) console.log(` Returns: ${r.signature.returnType}`);
|
|
132
|
+
console.log();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (r.children && r.children.length > 0) {
|
|
136
|
+
console.log(`## Children (${r.children.length})`);
|
|
137
|
+
for (const c of r.children) {
|
|
138
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} :${c.line}`);
|
|
139
|
+
}
|
|
140
|
+
console.log();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (r.complexity) {
|
|
144
|
+
const cx = r.complexity;
|
|
145
|
+
const miPart = cx.maintainabilityIndex ? ` | MI: ${cx.maintainabilityIndex}` : '';
|
|
146
|
+
console.log('## Complexity');
|
|
147
|
+
console.log(
|
|
148
|
+
` Cognitive: ${cx.cognitive} | Cyclomatic: ${cx.cyclomatic} | Max Nesting: ${cx.maxNesting}${miPart}`,
|
|
149
|
+
);
|
|
150
|
+
console.log();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (r.source) {
|
|
154
|
+
console.log('## Source');
|
|
155
|
+
for (const line of r.source.split('\n')) {
|
|
156
|
+
console.log(` ${line}`);
|
|
157
|
+
}
|
|
158
|
+
console.log();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (r.callees.length > 0) {
|
|
162
|
+
console.log(`## Direct Dependencies (${r.callees.length})`);
|
|
163
|
+
for (const c of r.callees) {
|
|
164
|
+
const summary = c.summary ? ` — ${c.summary}` : '';
|
|
165
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}${summary}`);
|
|
166
|
+
if (c.source) {
|
|
167
|
+
for (const line of c.source.split('\n').slice(0, 10)) {
|
|
168
|
+
console.log(` | ${line}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
console.log();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (r.callers.length > 0) {
|
|
176
|
+
console.log(`## Callers (${r.callers.length})`);
|
|
177
|
+
for (const c of r.callers) {
|
|
178
|
+
const via = c.viaHierarchy ? ` (via ${c.viaHierarchy})` : '';
|
|
179
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}${via}`);
|
|
180
|
+
}
|
|
181
|
+
console.log();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (r.relatedTests.length > 0) {
|
|
185
|
+
console.log('## Related Tests');
|
|
186
|
+
for (const t of r.relatedTests) {
|
|
187
|
+
console.log(` ${t.file} — ${t.testCount} tests`);
|
|
188
|
+
for (const tn of t.testNames) {
|
|
189
|
+
console.log(` - ${tn}`);
|
|
190
|
+
}
|
|
191
|
+
if (t.source) {
|
|
192
|
+
console.log(' Source:');
|
|
193
|
+
for (const line of t.source.split('\n').slice(0, 20)) {
|
|
194
|
+
console.log(` | ${line}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
console.log();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (r.callees.length === 0 && r.callers.length === 0 && r.relatedTests.length === 0) {
|
|
202
|
+
console.log(' (no call edges or tests found — may be invoked dynamically or via re-exports)');
|
|
203
|
+
console.log();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function renderFileExplain(r) {
|
|
208
|
+
const publicCount = r.publicApi.length;
|
|
209
|
+
const internalCount = r.internal.length;
|
|
210
|
+
const lineInfo = r.lineCount ? `${r.lineCount} lines, ` : '';
|
|
211
|
+
console.log(`\n# ${r.file}`);
|
|
212
|
+
console.log(
|
|
213
|
+
` ${lineInfo}${r.symbolCount} symbols (${publicCount} exported, ${internalCount} internal)`,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
if (r.imports.length > 0) {
|
|
217
|
+
console.log(` Imports: ${r.imports.map((i) => i.file).join(', ')}`);
|
|
218
|
+
}
|
|
219
|
+
if (r.importedBy.length > 0) {
|
|
220
|
+
console.log(` Imported by: ${r.importedBy.map((i) => i.file).join(', ')}`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (r.publicApi.length > 0) {
|
|
224
|
+
console.log(`\n## Exported`);
|
|
225
|
+
for (const s of r.publicApi) {
|
|
226
|
+
const sig = s.signature?.params != null ? `(${s.signature.params})` : '';
|
|
227
|
+
const roleTag = s.role ? ` [${s.role}]` : '';
|
|
228
|
+
const summary = s.summary ? ` -- ${s.summary}` : '';
|
|
229
|
+
console.log(` ${kindIcon(s.kind)} ${s.name}${sig}${roleTag} :${s.line}${summary}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (r.internal.length > 0) {
|
|
234
|
+
console.log(`\n## Internal`);
|
|
235
|
+
for (const s of r.internal) {
|
|
236
|
+
const sig = s.signature?.params != null ? `(${s.signature.params})` : '';
|
|
237
|
+
const roleTag = s.role ? ` [${s.role}]` : '';
|
|
238
|
+
const summary = s.summary ? ` -- ${s.summary}` : '';
|
|
239
|
+
console.log(` ${kindIcon(s.kind)} ${s.name}${sig}${roleTag} :${s.line}${summary}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (r.dataFlow.length > 0) {
|
|
244
|
+
console.log(`\n## Data Flow`);
|
|
245
|
+
for (const df of r.dataFlow) {
|
|
246
|
+
console.log(` ${df.caller} -> ${df.callees.join(', ')}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
console.log();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function renderFunctionExplain(r, indent = '') {
|
|
253
|
+
const lineRange = r.endLine ? `${r.line}-${r.endLine}` : `${r.line}`;
|
|
254
|
+
const lineInfo = r.lineCount ? `${r.lineCount} lines` : '';
|
|
255
|
+
const summaryPart = r.summary ? ` | ${r.summary}` : '';
|
|
256
|
+
const roleTag = r.role ? ` [${r.role}]` : '';
|
|
257
|
+
const depthLevel = r._depth || 0;
|
|
258
|
+
const heading = depthLevel === 0 ? '#' : '##'.padEnd(depthLevel + 2, '#');
|
|
259
|
+
console.log(`\n${indent}${heading} ${r.name} (${r.kind})${roleTag} ${r.file}:${lineRange}`);
|
|
260
|
+
if (lineInfo || r.summary) {
|
|
261
|
+
console.log(`${indent} ${lineInfo}${summaryPart}`);
|
|
262
|
+
}
|
|
263
|
+
if (r.signature) {
|
|
264
|
+
if (r.signature.params != null) console.log(`${indent} Parameters: (${r.signature.params})`);
|
|
265
|
+
if (r.signature.returnType) console.log(`${indent} Returns: ${r.signature.returnType}`);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (r.complexity) {
|
|
269
|
+
const cx = r.complexity;
|
|
270
|
+
const miPart = cx.maintainabilityIndex ? ` MI=${cx.maintainabilityIndex}` : '';
|
|
271
|
+
console.log(
|
|
272
|
+
`${indent} Complexity: cognitive=${cx.cognitive} cyclomatic=${cx.cyclomatic} nesting=${cx.maxNesting}${miPart}`,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (r.callees.length > 0) {
|
|
277
|
+
console.log(`\n${indent} Calls (${r.callees.length}):`);
|
|
278
|
+
for (const c of r.callees) {
|
|
279
|
+
console.log(`${indent} ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (r.callers.length > 0) {
|
|
284
|
+
console.log(`\n${indent} Called by (${r.callers.length}):`);
|
|
285
|
+
for (const c of r.callers) {
|
|
286
|
+
console.log(`${indent} ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (r.relatedTests.length > 0) {
|
|
291
|
+
const label = r.relatedTests.length === 1 ? 'file' : 'files';
|
|
292
|
+
console.log(`\n${indent} Tests (${r.relatedTests.length} ${label}):`);
|
|
293
|
+
for (const t of r.relatedTests) {
|
|
294
|
+
console.log(`${indent} ${t.file}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (r.callees.length === 0 && r.callers.length === 0) {
|
|
299
|
+
console.log(`${indent} (no call edges found -- may be invoked dynamically or via re-exports)`);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (r.depDetails && r.depDetails.length > 0) {
|
|
303
|
+
console.log(`\n${indent} --- Dependencies (depth ${depthLevel + 1}) ---`);
|
|
304
|
+
for (const dep of r.depDetails) {
|
|
305
|
+
renderFunctionExplain(dep, `${indent} `);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
console.log();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function explain(target, customDbPath, opts = {}) {
|
|
312
|
+
const data = explainData(target, customDbPath, opts);
|
|
313
|
+
if (outputResult(data, 'results', opts)) return;
|
|
314
|
+
|
|
315
|
+
if (data.results.length === 0) {
|
|
316
|
+
console.log(`No ${data.kind === 'file' ? 'file' : 'function/symbol'} matching "${target}"`);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (data.kind === 'file') {
|
|
321
|
+
for (const r of data.results) {
|
|
322
|
+
renderFileExplain(r);
|
|
323
|
+
}
|
|
324
|
+
} else {
|
|
325
|
+
for (const r of data.results) {
|
|
326
|
+
renderFunctionExplain(r);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { kindIcon, moduleMapData, rolesData, statsData } from '../../domain/queries.js';
|
|
3
|
+
import { outputResult } from '../../infrastructure/result-formatter.js';
|
|
4
|
+
|
|
5
|
+
function printCountGrid(entries, padWidth) {
|
|
6
|
+
const parts = entries.map(([k, v]) => `${k} ${v}`);
|
|
7
|
+
for (let i = 0; i < parts.length; i += 3) {
|
|
8
|
+
const row = parts
|
|
9
|
+
.slice(i, i + 3)
|
|
10
|
+
.map((p) => p.padEnd(padWidth))
|
|
11
|
+
.join('');
|
|
12
|
+
console.log(` ${row}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function printNodes(data) {
|
|
17
|
+
console.log(`Nodes: ${data.nodes.total} total`);
|
|
18
|
+
const kindEntries = Object.entries(data.nodes.byKind).sort((a, b) => b[1] - a[1]);
|
|
19
|
+
printCountGrid(kindEntries, 18);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function printEdges(data) {
|
|
23
|
+
console.log(`\nEdges: ${data.edges.total} total`);
|
|
24
|
+
const edgeEntries = Object.entries(data.edges.byKind).sort((a, b) => b[1] - a[1]);
|
|
25
|
+
printCountGrid(edgeEntries, 18);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function printFiles(data) {
|
|
29
|
+
console.log(`\nFiles: ${data.files.total} (${data.files.languages} languages)`);
|
|
30
|
+
const langEntries = Object.entries(data.files.byLanguage).sort((a, b) => b[1] - a[1]);
|
|
31
|
+
printCountGrid(langEntries, 18);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function printCycles(data) {
|
|
35
|
+
console.log(
|
|
36
|
+
`\nCycles: ${data.cycles.fileLevel} file-level, ${data.cycles.functionLevel} function-level`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function printHotspots(data) {
|
|
41
|
+
if (data.hotspots.length > 0) {
|
|
42
|
+
console.log(`\nTop ${data.hotspots.length} coupling hotspots:`);
|
|
43
|
+
for (let i = 0; i < data.hotspots.length; i++) {
|
|
44
|
+
const h = data.hotspots[i];
|
|
45
|
+
console.log(
|
|
46
|
+
` ${String(i + 1).padStart(2)}. ${h.file.padEnd(35)} fan-in: ${String(h.fanIn).padStart(3)} fan-out: ${String(h.fanOut).padStart(3)}`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function printEmbeddings(data) {
|
|
53
|
+
if (data.embeddings) {
|
|
54
|
+
const e = data.embeddings;
|
|
55
|
+
console.log(
|
|
56
|
+
`\nEmbeddings: ${e.count} vectors (${e.model || 'unknown'}, ${e.dim || '?'}d) built ${e.builtAt || 'unknown'}`,
|
|
57
|
+
);
|
|
58
|
+
} else {
|
|
59
|
+
console.log('\nEmbeddings: not built');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function printQuality(data) {
|
|
64
|
+
if (data.quality) {
|
|
65
|
+
const q = data.quality;
|
|
66
|
+
const cc = q.callerCoverage;
|
|
67
|
+
const cf = q.callConfidence;
|
|
68
|
+
console.log(`\nGraph Quality: ${q.score}/100`);
|
|
69
|
+
console.log(
|
|
70
|
+
` Caller coverage: ${(cc.ratio * 100).toFixed(1)}% (${cc.covered}/${cc.total} functions have >=1 caller)`,
|
|
71
|
+
);
|
|
72
|
+
console.log(
|
|
73
|
+
` Call confidence: ${(cf.ratio * 100).toFixed(1)}% (${cf.highConf}/${cf.total} call edges are high-confidence)`,
|
|
74
|
+
);
|
|
75
|
+
if (q.falsePositiveWarnings.length > 0) {
|
|
76
|
+
console.log(' False-positive warnings:');
|
|
77
|
+
for (const fp of q.falsePositiveWarnings) {
|
|
78
|
+
console.log(` ! ${fp.name} (${fp.callerCount} callers) -- ${fp.file}:${fp.line}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function printRoles(data) {
|
|
85
|
+
if (data.roles && Object.keys(data.roles).length > 0) {
|
|
86
|
+
const total = Object.values(data.roles).reduce((a, b) => a + b, 0);
|
|
87
|
+
console.log(`\nRoles: ${total} classified symbols`);
|
|
88
|
+
const roleEntries = Object.entries(data.roles).sort((a, b) => b[1] - a[1]);
|
|
89
|
+
printCountGrid(roleEntries, 18);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function printComplexity(data) {
|
|
94
|
+
if (data.complexity) {
|
|
95
|
+
const cx = data.complexity;
|
|
96
|
+
const miPart = cx.avgMI != null ? ` | avg MI: ${cx.avgMI} | min MI: ${cx.minMI}` : '';
|
|
97
|
+
console.log(
|
|
98
|
+
`\nComplexity: ${cx.analyzed} functions | avg cognitive: ${cx.avgCognitive} | avg cyclomatic: ${cx.avgCyclomatic} | max cognitive: ${cx.maxCognitive}${miPart}`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function printCommunities(data) {
|
|
104
|
+
if (data.communities) {
|
|
105
|
+
const cm = data.communities;
|
|
106
|
+
console.log(
|
|
107
|
+
`\nCommunities: ${cm.communityCount} detected | modularity: ${cm.modularity} | drift: ${cm.driftScore}%`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function stats(customDbPath, opts = {}) {
|
|
113
|
+
const data = statsData(customDbPath, { noTests: opts.noTests });
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const { communitySummaryForStats } = await import('../../features/communities.js');
|
|
117
|
+
data.communities = communitySummaryForStats(customDbPath, { noTests: opts.noTests });
|
|
118
|
+
} catch {
|
|
119
|
+
/* graphology may not be available */
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (outputResult(data, null, opts)) return;
|
|
123
|
+
|
|
124
|
+
console.log('\n# Codegraph Stats\n');
|
|
125
|
+
printNodes(data);
|
|
126
|
+
printEdges(data);
|
|
127
|
+
printFiles(data);
|
|
128
|
+
printCycles(data);
|
|
129
|
+
printHotspots(data);
|
|
130
|
+
printEmbeddings(data);
|
|
131
|
+
printQuality(data);
|
|
132
|
+
printRoles(data);
|
|
133
|
+
printComplexity(data);
|
|
134
|
+
printCommunities(data);
|
|
135
|
+
console.log();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function moduleMap(customDbPath, limit = 20, opts = {}) {
|
|
139
|
+
const data = moduleMapData(customDbPath, limit, { noTests: opts.noTests });
|
|
140
|
+
if (outputResult(data, 'topNodes', opts)) return;
|
|
141
|
+
|
|
142
|
+
console.log(`\nModule map (top ${limit} most-connected nodes):\n`);
|
|
143
|
+
const dirs = new Map();
|
|
144
|
+
for (const n of data.topNodes) {
|
|
145
|
+
if (!dirs.has(n.dir)) dirs.set(n.dir, []);
|
|
146
|
+
dirs.get(n.dir).push(n);
|
|
147
|
+
}
|
|
148
|
+
for (const [dir, files] of [...dirs].sort()) {
|
|
149
|
+
console.log(` [${dir}/]`);
|
|
150
|
+
for (const f of files) {
|
|
151
|
+
const coupling = f.inEdges + f.outEdges;
|
|
152
|
+
const bar = '#'.repeat(Math.min(coupling, 40));
|
|
153
|
+
console.log(
|
|
154
|
+
` ${path.basename(f.file).padEnd(35)} <-${String(f.inEdges).padStart(3)} ->${String(f.outEdges).padStart(3)} =${String(coupling).padStart(3)} ${bar}`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
console.log(
|
|
159
|
+
`\n Total: ${data.stats.totalFiles} files, ${data.stats.totalNodes} symbols, ${data.stats.totalEdges} edges\n`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function roles(customDbPath, opts = {}) {
|
|
164
|
+
const data = rolesData(customDbPath, opts);
|
|
165
|
+
if (outputResult(data, 'symbols', opts)) return;
|
|
166
|
+
|
|
167
|
+
if (data.count === 0) {
|
|
168
|
+
console.log('No classified symbols found. Run "codegraph build" first.');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const total = data.count;
|
|
173
|
+
console.log(`\nNode roles (${total} symbols):\n`);
|
|
174
|
+
|
|
175
|
+
const summaryParts = Object.entries(data.summary)
|
|
176
|
+
.sort((a, b) => b[1] - a[1])
|
|
177
|
+
.map(([role, count]) => `${role}: ${count}`);
|
|
178
|
+
console.log(` ${summaryParts.join(' ')}\n`);
|
|
179
|
+
|
|
180
|
+
const byRole = {};
|
|
181
|
+
for (const s of data.symbols) {
|
|
182
|
+
if (!byRole[s.role]) byRole[s.role] = [];
|
|
183
|
+
byRole[s.role].push(s);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
for (const [role, symbols] of Object.entries(byRole)) {
|
|
187
|
+
console.log(`## ${role} (${symbols.length})`);
|
|
188
|
+
for (const s of symbols.slice(0, 30)) {
|
|
189
|
+
console.log(` ${kindIcon(s.kind)} ${s.name} ${s.file}:${s.line}`);
|
|
190
|
+
}
|
|
191
|
+
if (symbols.length > 30) {
|
|
192
|
+
console.log(` ... and ${symbols.length - 30} more`);
|
|
193
|
+
}
|
|
194
|
+
console.log();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { kindIcon, pathData } from '../../domain/queries.js';
|
|
2
|
+
import { outputResult } from '../../infrastructure/result-formatter.js';
|
|
3
|
+
|
|
4
|
+
function printNotFound(from, to, data) {
|
|
5
|
+
const dir = data.reverse ? 'reverse ' : '';
|
|
6
|
+
console.log(`No ${dir}path from "${from}" to "${to}" within ${data.maxDepth} hops.`);
|
|
7
|
+
if (data.fromCandidates.length > 1) {
|
|
8
|
+
console.log(
|
|
9
|
+
`\n "${from}" matched ${data.fromCandidates.length} symbols — using top match: ${data.fromCandidates[0].name} (${data.fromCandidates[0].file}:${data.fromCandidates[0].line})`,
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
if (data.toCandidates.length > 1) {
|
|
13
|
+
console.log(
|
|
14
|
+
` "${to}" matched ${data.toCandidates.length} symbols — using top match: ${data.toCandidates[0].name} (${data.toCandidates[0].file}:${data.toCandidates[0].line})`,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function printPathSteps(data) {
|
|
20
|
+
for (let i = 0; i < data.path.length; i++) {
|
|
21
|
+
const n = data.path[i];
|
|
22
|
+
const indent = ' '.repeat(i + 1);
|
|
23
|
+
if (i === 0) {
|
|
24
|
+
console.log(`${indent}${kindIcon(n.kind)} ${n.name} (${n.kind}) -- ${n.file}:${n.line}`);
|
|
25
|
+
} else {
|
|
26
|
+
console.log(
|
|
27
|
+
`${indent}--[${n.edgeKind}]--> ${kindIcon(n.kind)} ${n.name} (${n.kind}) -- ${n.file}:${n.line}`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (data.alternateCount > 0) {
|
|
32
|
+
console.log(
|
|
33
|
+
`\n (${data.alternateCount} alternate shortest ${data.alternateCount === 1 ? 'path' : 'paths'} at same depth)`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function symbolPath(from, to, customDbPath, opts = {}) {
|
|
39
|
+
const data = pathData(from, to, customDbPath, opts);
|
|
40
|
+
if (outputResult(data, null, opts)) return;
|
|
41
|
+
|
|
42
|
+
if (data.error) {
|
|
43
|
+
console.log(data.error);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!data.found) {
|
|
48
|
+
printNotFound(from, to, data);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (data.hops === 0) {
|
|
53
|
+
console.log(`\n"${from}" and "${to}" resolve to the same symbol (0 hops):`);
|
|
54
|
+
const n = data.path[0];
|
|
55
|
+
console.log(` ${kindIcon(n.kind)} ${n.name} (${n.kind}) -- ${n.file}:${n.line}\n`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const dir = data.reverse ? ' (reverse)' : '';
|
|
60
|
+
console.log(
|
|
61
|
+
`\nPath from ${from} to ${to} (${data.hops} ${data.hops === 1 ? 'hop' : 'hops'})${dir}:\n`,
|
|
62
|
+
);
|
|
63
|
+
printPathSteps(data);
|
|
64
|
+
console.log();
|
|
65
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* queries-cli.js — barrel re-export for backward compatibility.
|
|
3
|
+
*
|
|
4
|
+
* The actual implementations live in queries-cli/ split by concern:
|
|
5
|
+
* path.js — symbolPath
|
|
6
|
+
* overview.js — stats, moduleMap, roles
|
|
7
|
+
* inspect.js — where, queryName, context, children, explain
|
|
8
|
+
* impact.js — fileDeps, fnDeps, impactAnalysis, fnImpact, diffImpact
|
|
9
|
+
* exports.js — fileExports
|
|
10
|
+
*/
|
|
11
|
+
export {
|
|
12
|
+
children,
|
|
13
|
+
context,
|
|
14
|
+
diffImpact,
|
|
15
|
+
explain,
|
|
16
|
+
fileDeps,
|
|
17
|
+
fileExports,
|
|
18
|
+
fnDeps,
|
|
19
|
+
fnImpact,
|
|
20
|
+
impactAnalysis,
|
|
21
|
+
moduleMap,
|
|
22
|
+
queryName,
|
|
23
|
+
roles,
|
|
24
|
+
stats,
|
|
25
|
+
symbolPath,
|
|
26
|
+
where,
|
|
27
|
+
} from './queries-cli/index.js';
|