@optave/codegraph 3.1.4 → 3.1.5
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 +26 -70
- package/package.json +10 -8
- package/src/ast-analysis/engine.js +32 -12
- package/src/ast-analysis/shared.js +2 -2
- package/src/cli/commands/ast.js +2 -6
- package/src/cli/commands/audit.js +9 -10
- package/src/cli/commands/batch.js +4 -4
- package/src/cli/commands/branch-compare.js +1 -1
- package/src/cli/commands/build.js +1 -1
- package/src/cli/commands/cfg.js +3 -7
- package/src/cli/commands/check.js +12 -17
- package/src/cli/commands/children.js +3 -6
- package/src/cli/commands/co-change.js +5 -3
- package/src/cli/commands/communities.js +2 -6
- package/src/cli/commands/complexity.js +3 -2
- package/src/cli/commands/context.js +3 -7
- package/src/cli/commands/cycles.js +12 -8
- package/src/cli/commands/dataflow.js +3 -7
- package/src/cli/commands/deps.js +2 -6
- 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 +3 -7
- package/src/cli/commands/fn-impact.js +3 -7
- 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 +1 -1
- package/src/cli/commands/path.js +2 -2
- package/src/cli/commands/plot.js +40 -31
- package/src/cli/commands/query.js +3 -7
- package/src/cli/commands/registry.js +2 -2
- package/src/cli/commands/roles.js +3 -7
- package/src/cli/commands/search.js +1 -1
- package/src/cli/commands/sequence.js +3 -7
- 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 +4 -4
- 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 +127 -4
- package/src/{db.js → db/index.js} +12 -5
- package/src/db/migrations.js +1 -1
- package/src/db/query-builder.js +15 -8
- 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 +4 -13
- package/src/db/repository/nodes.js +3 -8
- package/src/{analysis → domain/analysis}/context.js +6 -6
- package/src/{analysis → domain/analysis}/dependencies.js +5 -5
- package/src/{analysis → domain/analysis}/exports.js +8 -4
- package/src/{analysis → domain/analysis}/impact.js +61 -58
- package/src/{analysis → domain/analysis}/module-map.js +3 -3
- package/src/{analysis → domain/analysis}/roles.js +4 -4
- package/src/{analysis → domain/analysis}/symbol-lookup.js +13 -7
- package/src/{builder → domain/graph/builder}/helpers.js +3 -3
- package/src/{builder → domain/graph/builder}/incremental.js +3 -3
- package/src/{builder → domain/graph/builder}/pipeline.js +4 -4
- package/src/{builder → domain/graph/builder}/stages/build-edges.js +2 -2
- 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 +6 -6
- package/src/{builder → domain/graph/builder}/stages/finalize.js +4 -4
- package/src/{builder → domain/graph/builder}/stages/insert-nodes.js +1 -1
- 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} +5 -5
- package/src/{parser.js → domain/parser.js} +5 -5
- package/src/{queries.js → domain/queries.js} +16 -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/hybrid.js +1 -1
- package/src/{embeddings → domain/search}/search/keyword.js +1 -1
- package/src/{embeddings → domain/search}/search/prepare.js +2 -2
- package/src/{embeddings → domain/search}/search/semantic.js +1 -1
- package/src/{embeddings → domain/search}/strategies/structured.js +1 -1
- package/src/extractors/javascript.js +1 -1
- package/src/{ast.js → features/ast.js} +8 -8
- package/src/{audit.js → features/audit.js} +16 -44
- package/src/{batch.js → features/batch.js} +5 -5
- package/src/{boundaries.js → features/boundaries.js} +2 -2
- package/src/{branch-compare.js → features/branch-compare.js} +3 -3
- package/src/{cfg.js → features/cfg.js} +10 -10
- 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} +7 -7
- package/src/{complexity.js → features/complexity.js} +13 -13
- package/src/{dataflow.js → features/dataflow.js} +11 -11
- package/src/{export.js → features/export.js} +3 -3
- package/src/{flow.js → features/flow.js} +4 -4
- package/src/{viewer.js → features/graph-enrichment.js} +6 -6
- package/src/{manifesto.js → features/manifesto.js} +6 -6
- package/src/{owners.js → features/owners.js} +2 -2
- package/src/{sequence.js → features/sequence.js} +15 -15
- package/src/{snapshot.js → features/snapshot.js} +3 -3
- package/src/{structure.js → features/structure.js} +7 -7
- package/src/{triage.js → features/triage.js} +8 -8
- package/src/graph/builders/dependency.js +33 -14
- package/src/index.cjs +16 -0
- package/src/index.js +39 -39
- package/src/{native.js → infrastructure/native.js} +1 -1
- package/src/mcp/middleware.js +1 -1
- package/src/mcp/server.js +5 -5
- package/src/mcp/tool-registry.js +2 -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/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/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/{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 +46 -0
- package/src/presentation/queries-cli/impact.js +198 -0
- package/src/presentation/queries-cli/index.js +5 -0
- package/src/presentation/queries-cli/inspect.js +334 -0
- package/src/presentation/queries-cli/overview.js +197 -0
- package/src/presentation/queries-cli/path.js +58 -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/{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 +2 -2
- package/src/shared/hierarchy.js +1 -1
- package/src/mcp.js +0 -2
- package/src/queries-cli.js +0 -866
- /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}/search/filters.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/{kinds.js → shared/kinds.js} +0 -0
- /package/src/{paginate.js → shared/paginate.js} +0 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diffImpactData,
|
|
3
|
+
diffImpactMermaid,
|
|
4
|
+
fileDepsData,
|
|
5
|
+
fnDepsData,
|
|
6
|
+
fnImpactData,
|
|
7
|
+
impactAnalysisData,
|
|
8
|
+
kindIcon,
|
|
9
|
+
} from '../../domain/queries.js';
|
|
10
|
+
import { outputResult } from '../../infrastructure/result-formatter.js';
|
|
11
|
+
|
|
12
|
+
export function fileDeps(file, customDbPath, opts = {}) {
|
|
13
|
+
const data = fileDepsData(file, customDbPath, opts);
|
|
14
|
+
if (outputResult(data, 'results', opts)) return;
|
|
15
|
+
|
|
16
|
+
if (data.results.length === 0) {
|
|
17
|
+
console.log(`No file matching "${file}" in graph`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for (const r of data.results) {
|
|
22
|
+
console.log(`\n# ${r.file}\n`);
|
|
23
|
+
console.log(` -> Imports (${r.imports.length}):`);
|
|
24
|
+
for (const i of r.imports) {
|
|
25
|
+
const typeTag = i.typeOnly ? ' (type-only)' : '';
|
|
26
|
+
console.log(` -> ${i.file}${typeTag}`);
|
|
27
|
+
}
|
|
28
|
+
console.log(`\n <- Imported by (${r.importedBy.length}):`);
|
|
29
|
+
for (const i of r.importedBy) console.log(` <- ${i.file}`);
|
|
30
|
+
if (r.definitions.length > 0) {
|
|
31
|
+
console.log(`\n Definitions (${r.definitions.length}):`);
|
|
32
|
+
for (const d of r.definitions.slice(0, 30))
|
|
33
|
+
console.log(` ${kindIcon(d.kind)} ${d.name} :${d.line}`);
|
|
34
|
+
if (r.definitions.length > 30) console.log(` ... and ${r.definitions.length - 30} more`);
|
|
35
|
+
}
|
|
36
|
+
console.log();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function fnDeps(name, customDbPath, opts = {}) {
|
|
41
|
+
const data = fnDepsData(name, customDbPath, opts);
|
|
42
|
+
if (outputResult(data, 'results', opts)) return;
|
|
43
|
+
|
|
44
|
+
if (data.results.length === 0) {
|
|
45
|
+
console.log(`No function/method/class matching "${name}"`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
for (const r of data.results) {
|
|
50
|
+
console.log(`\n${kindIcon(r.kind)} ${r.name} (${r.kind}) -- ${r.file}:${r.line}\n`);
|
|
51
|
+
if (r.callees.length > 0) {
|
|
52
|
+
console.log(` -> Calls (${r.callees.length}):`);
|
|
53
|
+
for (const c of r.callees)
|
|
54
|
+
console.log(` -> ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
55
|
+
}
|
|
56
|
+
if (r.callers.length > 0) {
|
|
57
|
+
console.log(`\n <- Called by (${r.callers.length}):`);
|
|
58
|
+
for (const c of r.callers) {
|
|
59
|
+
const via = c.viaHierarchy ? ` (via ${c.viaHierarchy})` : '';
|
|
60
|
+
console.log(` <- ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}${via}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const [d, fns] of Object.entries(r.transitiveCallers)) {
|
|
64
|
+
console.log(
|
|
65
|
+
`\n ${'<-'.repeat(parseInt(d, 10))} Transitive callers (depth ${d}, ${fns.length}):`,
|
|
66
|
+
);
|
|
67
|
+
for (const n of fns.slice(0, 20))
|
|
68
|
+
console.log(
|
|
69
|
+
` ${' '.repeat(parseInt(d, 10) - 1)}<- ${kindIcon(n.kind)} ${n.name} ${n.file}:${n.line}`,
|
|
70
|
+
);
|
|
71
|
+
if (fns.length > 20) console.log(` ... and ${fns.length - 20} more`);
|
|
72
|
+
}
|
|
73
|
+
if (r.callees.length === 0 && r.callers.length === 0) {
|
|
74
|
+
console.log(` (no call edges found -- may be invoked dynamically or via re-exports)`);
|
|
75
|
+
}
|
|
76
|
+
console.log();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function impactAnalysis(file, customDbPath, opts = {}) {
|
|
81
|
+
const data = impactAnalysisData(file, customDbPath, opts);
|
|
82
|
+
if (outputResult(data, 'sources', opts)) return;
|
|
83
|
+
|
|
84
|
+
if (data.sources.length === 0) {
|
|
85
|
+
console.log(`No file matching "${file}" in graph`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
console.log(`\nImpact analysis for files matching "${file}":\n`);
|
|
90
|
+
for (const s of data.sources) console.log(` # ${s} (source)`);
|
|
91
|
+
|
|
92
|
+
const levels = data.levels;
|
|
93
|
+
if (Object.keys(levels).length === 0) {
|
|
94
|
+
console.log(` No dependents found.`);
|
|
95
|
+
} else {
|
|
96
|
+
for (const level of Object.keys(levels).sort((a, b) => a - b)) {
|
|
97
|
+
const nodes = levels[level];
|
|
98
|
+
console.log(
|
|
99
|
+
`\n ${'--'.repeat(parseInt(level, 10))} Level ${level} (${nodes.length} files):`,
|
|
100
|
+
);
|
|
101
|
+
for (const n of nodes.slice(0, 30))
|
|
102
|
+
console.log(` ${' '.repeat(parseInt(level, 10))}^ ${n.file}`);
|
|
103
|
+
if (nodes.length > 30) console.log(` ... and ${nodes.length - 30} more`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
console.log(`\n Total: ${data.totalDependents} files transitively depend on "${file}"\n`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function fnImpact(name, customDbPath, opts = {}) {
|
|
110
|
+
const data = fnImpactData(name, customDbPath, opts);
|
|
111
|
+
if (outputResult(data, 'results', opts)) return;
|
|
112
|
+
|
|
113
|
+
if (data.results.length === 0) {
|
|
114
|
+
console.log(`No function/method/class matching "${name}"`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (const r of data.results) {
|
|
119
|
+
console.log(`\nFunction impact: ${kindIcon(r.kind)} ${r.name} -- ${r.file}:${r.line}\n`);
|
|
120
|
+
if (Object.keys(r.levels).length === 0) {
|
|
121
|
+
console.log(` No callers found.`);
|
|
122
|
+
} else {
|
|
123
|
+
for (const [level, fns] of Object.entries(r.levels).sort((a, b) => a[0] - b[0])) {
|
|
124
|
+
const l = parseInt(level, 10);
|
|
125
|
+
console.log(` ${'--'.repeat(l)} Level ${level} (${fns.length} functions):`);
|
|
126
|
+
for (const f of fns.slice(0, 20))
|
|
127
|
+
console.log(` ${' '.repeat(l)}^ ${kindIcon(f.kind)} ${f.name} ${f.file}:${f.line}`);
|
|
128
|
+
if (fns.length > 20) console.log(` ... and ${fns.length - 20} more`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
console.log(`\n Total: ${r.totalDependents} functions transitively depend on ${r.name}\n`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function diffImpact(customDbPath, opts = {}) {
|
|
136
|
+
if (opts.format === 'mermaid') {
|
|
137
|
+
console.log(diffImpactMermaid(customDbPath, opts));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const data = diffImpactData(customDbPath, opts);
|
|
141
|
+
if (opts.format === 'json') opts = { ...opts, json: true };
|
|
142
|
+
if (outputResult(data, 'affectedFunctions', opts)) return;
|
|
143
|
+
|
|
144
|
+
if (data.error) {
|
|
145
|
+
console.log(data.error);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (data.changedFiles === 0) {
|
|
149
|
+
console.log('No changes detected.');
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (data.affectedFunctions.length === 0) {
|
|
153
|
+
console.log(
|
|
154
|
+
' No function-level changes detected (changes may be in imports, types, or config).',
|
|
155
|
+
);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
console.log(`\ndiff-impact: ${data.changedFiles} files changed\n`);
|
|
160
|
+
console.log(` ${data.affectedFunctions.length} functions changed:\n`);
|
|
161
|
+
for (const fn of data.affectedFunctions) {
|
|
162
|
+
console.log(` ${kindIcon(fn.kind)} ${fn.name} -- ${fn.file}:${fn.line}`);
|
|
163
|
+
if (fn.transitiveCallers > 0) console.log(` ^ ${fn.transitiveCallers} transitive callers`);
|
|
164
|
+
}
|
|
165
|
+
if (data.historicallyCoupled && data.historicallyCoupled.length > 0) {
|
|
166
|
+
console.log('\n Historically coupled (not in static graph):\n');
|
|
167
|
+
for (const c of data.historicallyCoupled) {
|
|
168
|
+
const pct = `${(c.jaccard * 100).toFixed(0)}%`;
|
|
169
|
+
console.log(
|
|
170
|
+
` ${c.file} <- coupled with ${c.coupledWith} (${pct}, ${c.commitCount} commits)`,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (data.ownership) {
|
|
175
|
+
console.log(`\n Affected owners: ${data.ownership.affectedOwners.join(', ')}`);
|
|
176
|
+
console.log(` Suggested reviewers: ${data.ownership.suggestedReviewers.join(', ')}`);
|
|
177
|
+
}
|
|
178
|
+
if (data.boundaryViolations && data.boundaryViolations.length > 0) {
|
|
179
|
+
console.log(`\n Boundary violations (${data.boundaryViolationCount}):\n`);
|
|
180
|
+
for (const v of data.boundaryViolations) {
|
|
181
|
+
console.log(` [${v.name}] ${v.file} -> ${v.targetFile}`);
|
|
182
|
+
if (v.message) console.log(` ${v.message}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (data.summary) {
|
|
186
|
+
let summaryLine = `\n Summary: ${data.summary.functionsChanged} functions changed -> ${data.summary.callersAffected} callers affected across ${data.summary.filesAffected} files`;
|
|
187
|
+
if (data.summary.historicallyCoupledCount > 0) {
|
|
188
|
+
summaryLine += `, ${data.summary.historicallyCoupledCount} historically coupled`;
|
|
189
|
+
}
|
|
190
|
+
if (data.summary.ownersAffected > 0) {
|
|
191
|
+
summaryLine += `, ${data.summary.ownersAffected} owners affected`;
|
|
192
|
+
}
|
|
193
|
+
if (data.summary.boundaryViolationCount > 0) {
|
|
194
|
+
summaryLine += `, ${data.summary.boundaryViolationCount} boundary violations`;
|
|
195
|
+
}
|
|
196
|
+
console.log(`${summaryLine}\n`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { fileExports } from './exports.js';
|
|
2
|
+
export { diffImpact, fileDeps, fnDeps, fnImpact, impactAnalysis } from './impact.js';
|
|
3
|
+
export { children, context, explain, queryName, where } from './inspect.js';
|
|
4
|
+
export { moduleMap, roles, stats } from './overview.js';
|
|
5
|
+
export { symbolPath } from './path.js';
|
|
@@ -0,0 +1,334 @@
|
|
|
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
|
+
const lineRange = r.endLine ? `${r.line}-${r.endLine}` : `${r.line}`;
|
|
100
|
+
const roleTag = r.role ? ` [${r.role}]` : '';
|
|
101
|
+
console.log(`\n# ${r.name} (${r.kind})${roleTag} — ${r.file}:${lineRange}\n`);
|
|
102
|
+
|
|
103
|
+
// Signature
|
|
104
|
+
if (r.signature) {
|
|
105
|
+
console.log('## Type/Shape Info');
|
|
106
|
+
if (r.signature.params != null) console.log(` Parameters: (${r.signature.params})`);
|
|
107
|
+
if (r.signature.returnType) console.log(` Returns: ${r.signature.returnType}`);
|
|
108
|
+
console.log();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Children
|
|
112
|
+
if (r.children && r.children.length > 0) {
|
|
113
|
+
console.log(`## Children (${r.children.length})`);
|
|
114
|
+
for (const c of r.children) {
|
|
115
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} :${c.line}`);
|
|
116
|
+
}
|
|
117
|
+
console.log();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Complexity
|
|
121
|
+
if (r.complexity) {
|
|
122
|
+
const cx = r.complexity;
|
|
123
|
+
const miPart = cx.maintainabilityIndex ? ` | MI: ${cx.maintainabilityIndex}` : '';
|
|
124
|
+
console.log('## Complexity');
|
|
125
|
+
console.log(
|
|
126
|
+
` Cognitive: ${cx.cognitive} | Cyclomatic: ${cx.cyclomatic} | Max Nesting: ${cx.maxNesting}${miPart}`,
|
|
127
|
+
);
|
|
128
|
+
console.log();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Source
|
|
132
|
+
if (r.source) {
|
|
133
|
+
console.log('## Source');
|
|
134
|
+
for (const line of r.source.split('\n')) {
|
|
135
|
+
console.log(` ${line}`);
|
|
136
|
+
}
|
|
137
|
+
console.log();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Callees
|
|
141
|
+
if (r.callees.length > 0) {
|
|
142
|
+
console.log(`## Direct Dependencies (${r.callees.length})`);
|
|
143
|
+
for (const c of r.callees) {
|
|
144
|
+
const summary = c.summary ? ` — ${c.summary}` : '';
|
|
145
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}${summary}`);
|
|
146
|
+
if (c.source) {
|
|
147
|
+
for (const line of c.source.split('\n').slice(0, 10)) {
|
|
148
|
+
console.log(` | ${line}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
console.log();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Callers
|
|
156
|
+
if (r.callers.length > 0) {
|
|
157
|
+
console.log(`## Callers (${r.callers.length})`);
|
|
158
|
+
for (const c of r.callers) {
|
|
159
|
+
const via = c.viaHierarchy ? ` (via ${c.viaHierarchy})` : '';
|
|
160
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}${via}`);
|
|
161
|
+
}
|
|
162
|
+
console.log();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Related tests
|
|
166
|
+
if (r.relatedTests.length > 0) {
|
|
167
|
+
console.log('## Related Tests');
|
|
168
|
+
for (const t of r.relatedTests) {
|
|
169
|
+
console.log(` ${t.file} — ${t.testCount} tests`);
|
|
170
|
+
for (const tn of t.testNames) {
|
|
171
|
+
console.log(` - ${tn}`);
|
|
172
|
+
}
|
|
173
|
+
if (t.source) {
|
|
174
|
+
console.log(' Source:');
|
|
175
|
+
for (const line of t.source.split('\n').slice(0, 20)) {
|
|
176
|
+
console.log(` | ${line}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
console.log();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (r.callees.length === 0 && r.callers.length === 0 && r.relatedTests.length === 0) {
|
|
184
|
+
console.log(
|
|
185
|
+
' (no call edges or tests found — may be invoked dynamically or via re-exports)',
|
|
186
|
+
);
|
|
187
|
+
console.log();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function children(name, customDbPath, opts = {}) {
|
|
193
|
+
const data = childrenData(name, customDbPath, opts);
|
|
194
|
+
if (outputResult(data, 'results', opts)) return;
|
|
195
|
+
|
|
196
|
+
if (data.results.length === 0) {
|
|
197
|
+
console.log(`No symbol matching "${name}"`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
for (const r of data.results) {
|
|
201
|
+
console.log(`\n${kindIcon(r.kind)} ${r.name} ${r.file}:${r.line}`);
|
|
202
|
+
if (r.children.length === 0) {
|
|
203
|
+
console.log(' (no children)');
|
|
204
|
+
} else {
|
|
205
|
+
for (const c of r.children) {
|
|
206
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} :${c.line}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function explain(target, customDbPath, opts = {}) {
|
|
213
|
+
const data = explainData(target, customDbPath, opts);
|
|
214
|
+
if (outputResult(data, 'results', opts)) return;
|
|
215
|
+
|
|
216
|
+
if (data.results.length === 0) {
|
|
217
|
+
console.log(`No ${data.kind === 'file' ? 'file' : 'function/symbol'} matching "${target}"`);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (data.kind === 'file') {
|
|
222
|
+
for (const r of data.results) {
|
|
223
|
+
const publicCount = r.publicApi.length;
|
|
224
|
+
const internalCount = r.internal.length;
|
|
225
|
+
const lineInfo = r.lineCount ? `${r.lineCount} lines, ` : '';
|
|
226
|
+
console.log(`\n# ${r.file}`);
|
|
227
|
+
console.log(
|
|
228
|
+
` ${lineInfo}${r.symbolCount} symbols (${publicCount} exported, ${internalCount} internal)`,
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
if (r.imports.length > 0) {
|
|
232
|
+
console.log(` Imports: ${r.imports.map((i) => i.file).join(', ')}`);
|
|
233
|
+
}
|
|
234
|
+
if (r.importedBy.length > 0) {
|
|
235
|
+
console.log(` Imported by: ${r.importedBy.map((i) => i.file).join(', ')}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (r.publicApi.length > 0) {
|
|
239
|
+
console.log(`\n## Exported`);
|
|
240
|
+
for (const s of r.publicApi) {
|
|
241
|
+
const sig = s.signature?.params != null ? `(${s.signature.params})` : '';
|
|
242
|
+
const roleTag = s.role ? ` [${s.role}]` : '';
|
|
243
|
+
const summary = s.summary ? ` -- ${s.summary}` : '';
|
|
244
|
+
console.log(` ${kindIcon(s.kind)} ${s.name}${sig}${roleTag} :${s.line}${summary}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (r.internal.length > 0) {
|
|
249
|
+
console.log(`\n## Internal`);
|
|
250
|
+
for (const s of r.internal) {
|
|
251
|
+
const sig = s.signature?.params != null ? `(${s.signature.params})` : '';
|
|
252
|
+
const roleTag = s.role ? ` [${s.role}]` : '';
|
|
253
|
+
const summary = s.summary ? ` -- ${s.summary}` : '';
|
|
254
|
+
console.log(` ${kindIcon(s.kind)} ${s.name}${sig}${roleTag} :${s.line}${summary}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (r.dataFlow.length > 0) {
|
|
259
|
+
console.log(`\n## Data Flow`);
|
|
260
|
+
for (const df of r.dataFlow) {
|
|
261
|
+
console.log(` ${df.caller} -> ${df.callees.join(', ')}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
console.log();
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
function printFunctionExplain(r, indent = '') {
|
|
268
|
+
const lineRange = r.endLine ? `${r.line}-${r.endLine}` : `${r.line}`;
|
|
269
|
+
const lineInfo = r.lineCount ? `${r.lineCount} lines` : '';
|
|
270
|
+
const summaryPart = r.summary ? ` | ${r.summary}` : '';
|
|
271
|
+
const roleTag = r.role ? ` [${r.role}]` : '';
|
|
272
|
+
const depthLevel = r._depth || 0;
|
|
273
|
+
const heading = depthLevel === 0 ? '#' : '##'.padEnd(depthLevel + 2, '#');
|
|
274
|
+
console.log(`\n${indent}${heading} ${r.name} (${r.kind})${roleTag} ${r.file}:${lineRange}`);
|
|
275
|
+
if (lineInfo || r.summary) {
|
|
276
|
+
console.log(`${indent} ${lineInfo}${summaryPart}`);
|
|
277
|
+
}
|
|
278
|
+
if (r.signature) {
|
|
279
|
+
if (r.signature.params != null)
|
|
280
|
+
console.log(`${indent} Parameters: (${r.signature.params})`);
|
|
281
|
+
if (r.signature.returnType) console.log(`${indent} Returns: ${r.signature.returnType}`);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (r.complexity) {
|
|
285
|
+
const cx = r.complexity;
|
|
286
|
+
const miPart = cx.maintainabilityIndex ? ` MI=${cx.maintainabilityIndex}` : '';
|
|
287
|
+
console.log(
|
|
288
|
+
`${indent} Complexity: cognitive=${cx.cognitive} cyclomatic=${cx.cyclomatic} nesting=${cx.maxNesting}${miPart}`,
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (r.callees.length > 0) {
|
|
293
|
+
console.log(`\n${indent} Calls (${r.callees.length}):`);
|
|
294
|
+
for (const c of r.callees) {
|
|
295
|
+
console.log(`${indent} ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (r.callers.length > 0) {
|
|
300
|
+
console.log(`\n${indent} Called by (${r.callers.length}):`);
|
|
301
|
+
for (const c of r.callers) {
|
|
302
|
+
console.log(`${indent} ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (r.relatedTests.length > 0) {
|
|
307
|
+
const label = r.relatedTests.length === 1 ? 'file' : 'files';
|
|
308
|
+
console.log(`\n${indent} Tests (${r.relatedTests.length} ${label}):`);
|
|
309
|
+
for (const t of r.relatedTests) {
|
|
310
|
+
console.log(`${indent} ${t.file}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (r.callees.length === 0 && r.callers.length === 0) {
|
|
315
|
+
console.log(
|
|
316
|
+
`${indent} (no call edges found -- may be invoked dynamically or via re-exports)`,
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Render recursive dependency details
|
|
321
|
+
if (r.depDetails && r.depDetails.length > 0) {
|
|
322
|
+
console.log(`\n${indent} --- Dependencies (depth ${depthLevel + 1}) ---`);
|
|
323
|
+
for (const dep of r.depDetails) {
|
|
324
|
+
printFunctionExplain(dep, `${indent} `);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
console.log();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
for (const r of data.results) {
|
|
331
|
+
printFunctionExplain(r);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|