@optave/codegraph 3.1.1 → 3.1.2
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/package.json +7 -7
- package/src/ast-analysis/engine.js +365 -0
- package/src/ast-analysis/metrics.js +118 -0
- package/src/ast-analysis/visitor-utils.js +176 -0
- package/src/ast-analysis/visitor.js +162 -0
- package/src/ast-analysis/visitors/ast-store-visitor.js +150 -0
- package/src/ast-analysis/visitors/cfg-visitor.js +792 -0
- package/src/ast-analysis/visitors/complexity-visitor.js +243 -0
- package/src/ast-analysis/visitors/dataflow-visitor.js +358 -0
- package/src/ast.js +13 -140
- package/src/audit.js +2 -87
- package/src/batch.js +0 -25
- package/src/boundaries.js +1 -1
- package/src/branch-compare.js +1 -96
- package/src/builder.js +48 -179
- package/src/cfg.js +89 -883
- package/src/check.js +1 -84
- package/src/cli.js +20 -19
- package/src/cochange.js +1 -39
- package/src/commands/audit.js +88 -0
- package/src/commands/batch.js +26 -0
- package/src/commands/branch-compare.js +97 -0
- package/src/commands/cfg.js +55 -0
- package/src/commands/check.js +82 -0
- package/src/commands/cochange.js +37 -0
- package/src/commands/communities.js +69 -0
- package/src/commands/complexity.js +77 -0
- package/src/commands/dataflow.js +110 -0
- package/src/commands/flow.js +70 -0
- package/src/commands/manifesto.js +77 -0
- package/src/commands/owners.js +52 -0
- package/src/commands/query.js +21 -0
- package/src/commands/sequence.js +33 -0
- package/src/commands/structure.js +64 -0
- package/src/commands/triage.js +49 -0
- package/src/communities.js +12 -83
- package/src/complexity.js +42 -356
- package/src/cycles.js +1 -1
- package/src/dataflow.js +12 -665
- package/src/db/repository/build-stmts.js +104 -0
- package/src/db/repository/cfg.js +83 -0
- package/src/db/repository/cochange.js +41 -0
- package/src/db/repository/complexity.js +15 -0
- package/src/db/repository/dataflow.js +12 -0
- package/src/db/repository/edges.js +259 -0
- package/src/db/repository/embeddings.js +40 -0
- package/src/db/repository/graph-read.js +39 -0
- package/src/db/repository/index.js +42 -0
- package/src/db/repository/nodes.js +236 -0
- package/src/db.js +40 -1
- package/src/embedder.js +14 -34
- package/src/export.js +1 -1
- package/src/extractors/javascript.js +130 -5
- package/src/flow.js +2 -70
- package/src/index.js +23 -19
- package/src/{result-formatter.js → infrastructure/result-formatter.js} +1 -1
- package/src/kinds.js +1 -0
- package/src/manifesto.js +0 -76
- package/src/owners.js +1 -56
- package/src/queries-cli.js +1 -1
- package/src/queries.js +79 -280
- package/src/sequence.js +5 -44
- package/src/structure.js +16 -75
- package/src/triage.js +1 -54
- package/src/viewer.js +1 -1
- package/src/watcher.js +7 -4
- package/src/db/repository.js +0 -134
- /package/src/{test-filter.js → infrastructure/test-filter.js} +0 -0
package/src/index.js
CHANGED
|
@@ -8,13 +8,11 @@
|
|
|
8
8
|
// AST node queries
|
|
9
9
|
export { AST_NODE_KINDS, astQuery, astQueryData } from './ast.js';
|
|
10
10
|
// Audit (composite report)
|
|
11
|
-
export {
|
|
11
|
+
export { auditData } from './audit.js';
|
|
12
12
|
// Batch querying
|
|
13
13
|
export {
|
|
14
14
|
BATCH_COMMANDS,
|
|
15
|
-
batch,
|
|
16
15
|
batchData,
|
|
17
|
-
batchQuery,
|
|
18
16
|
multiBatchData,
|
|
19
17
|
splitTargets,
|
|
20
18
|
} from './batch.js';
|
|
@@ -29,13 +27,12 @@ export {
|
|
|
29
27
|
buildCFGData,
|
|
30
28
|
buildFunctionCFG,
|
|
31
29
|
CFG_RULES,
|
|
32
|
-
cfg,
|
|
33
30
|
cfgData,
|
|
34
31
|
cfgToDOT,
|
|
35
32
|
cfgToMermaid,
|
|
36
33
|
} from './cfg.js';
|
|
37
34
|
// Check (CI validation predicates)
|
|
38
|
-
export {
|
|
35
|
+
export { checkData } from './check.js';
|
|
39
36
|
// Co-change analysis
|
|
40
37
|
export {
|
|
41
38
|
analyzeCoChanges,
|
|
@@ -45,12 +42,23 @@ export {
|
|
|
45
42
|
computeCoChanges,
|
|
46
43
|
scanGitHistory,
|
|
47
44
|
} from './cochange.js';
|
|
45
|
+
export { audit } from './commands/audit.js';
|
|
46
|
+
export { batch, batchQuery } from './commands/batch.js';
|
|
47
|
+
export { cfg } from './commands/cfg.js';
|
|
48
|
+
export { check } from './commands/check.js';
|
|
49
|
+
export { communities } from './commands/communities.js';
|
|
50
|
+
export { complexity } from './commands/complexity.js';
|
|
51
|
+
export { dataflow } from './commands/dataflow.js';
|
|
52
|
+
export { manifesto } from './commands/manifesto.js';
|
|
53
|
+
export { owners } from './commands/owners.js';
|
|
54
|
+
export { sequence } from './commands/sequence.js';
|
|
55
|
+
export { formatHotspots, formatModuleBoundaries, formatStructure } from './commands/structure.js';
|
|
56
|
+
export { triage } from './commands/triage.js';
|
|
48
57
|
// Community detection
|
|
49
|
-
export {
|
|
58
|
+
export { communitiesData, communitySummaryForStats } from './communities.js';
|
|
50
59
|
// Complexity metrics
|
|
51
60
|
export {
|
|
52
61
|
COMPLEXITY_RULES,
|
|
53
|
-
complexity,
|
|
54
62
|
complexityData,
|
|
55
63
|
computeFunctionComplexity,
|
|
56
64
|
computeHalsteadMetrics,
|
|
@@ -69,7 +77,6 @@ export { findCycles, formatCycles } from './cycles.js';
|
|
|
69
77
|
// Dataflow analysis
|
|
70
78
|
export {
|
|
71
79
|
buildDataflowEdges,
|
|
72
|
-
dataflow,
|
|
73
80
|
dataflowData,
|
|
74
81
|
dataflowImpactData,
|
|
75
82
|
dataflowPathData,
|
|
@@ -123,14 +130,18 @@ export {
|
|
|
123
130
|
} from './export.js';
|
|
124
131
|
// Execution flow tracing
|
|
125
132
|
export { entryPointType, flowData, listEntryPointsData } from './flow.js';
|
|
133
|
+
// Result formatting
|
|
134
|
+
export { outputResult } from './infrastructure/result-formatter.js';
|
|
135
|
+
// Test file detection
|
|
136
|
+
export { isTestFile, TEST_PATTERN } from './infrastructure/test-filter.js';
|
|
126
137
|
// Logger
|
|
127
138
|
export { setVerbose } from './logger.js';
|
|
128
139
|
// Manifesto rule engine
|
|
129
|
-
export {
|
|
140
|
+
export { manifestoData, RULE_DEFS } from './manifesto.js';
|
|
130
141
|
// Native engine
|
|
131
142
|
export { isNativeAvailable } from './native.js';
|
|
132
143
|
// Ownership (CODEOWNERS)
|
|
133
|
-
export { matchOwners,
|
|
144
|
+
export { matchOwners, ownersData, ownersForFiles, parseCodeowners } from './owners.js';
|
|
134
145
|
// Pagination utilities
|
|
135
146
|
export { MCP_DEFAULTS, MCP_MAX_LIMIT, paginate, paginateResult, printNdjson } from './paginate.js';
|
|
136
147
|
// Unified parser API
|
|
@@ -198,10 +209,8 @@ export {
|
|
|
198
209
|
saveRegistry,
|
|
199
210
|
unregisterRepo,
|
|
200
211
|
} from './registry.js';
|
|
201
|
-
// Result formatting
|
|
202
|
-
export { outputResult } from './result-formatter.js';
|
|
203
212
|
// Sequence diagram generation
|
|
204
|
-
export {
|
|
213
|
+
export { sequenceData, sequenceToMermaid } from './sequence.js';
|
|
205
214
|
// Snapshot management
|
|
206
215
|
export {
|
|
207
216
|
snapshotDelete,
|
|
@@ -216,17 +225,12 @@ export {
|
|
|
216
225
|
buildStructure,
|
|
217
226
|
classifyNodeRoles,
|
|
218
227
|
FRAMEWORK_ENTRY_PREFIXES,
|
|
219
|
-
formatHotspots,
|
|
220
|
-
formatModuleBoundaries,
|
|
221
|
-
formatStructure,
|
|
222
228
|
hotspotsData,
|
|
223
229
|
moduleBoundariesData,
|
|
224
230
|
structureData,
|
|
225
231
|
} from './structure.js';
|
|
226
|
-
// Test file detection
|
|
227
|
-
export { isTestFile, TEST_PATTERN } from './test-filter.js';
|
|
228
232
|
// Triage — composite risk audit
|
|
229
|
-
export {
|
|
233
|
+
export { triageData } from './triage.js';
|
|
230
234
|
// Interactive HTML viewer
|
|
231
235
|
export { generatePlotHTML, loadPlotConfig } from './viewer.js';
|
|
232
236
|
// Watch mode
|
package/src/kinds.js
CHANGED
package/src/manifesto.js
CHANGED
|
@@ -4,7 +4,6 @@ import { findCycles } from './cycles.js';
|
|
|
4
4
|
import { openReadonlyOrFail } from './db.js';
|
|
5
5
|
import { debug } from './logger.js';
|
|
6
6
|
import { paginateResult } from './paginate.js';
|
|
7
|
-
import { outputResult } from './result-formatter.js';
|
|
8
7
|
|
|
9
8
|
// ─── Rule Definitions ─────────────────────────────────────────────────
|
|
10
9
|
|
|
@@ -428,78 +427,3 @@ export function manifestoData(customDbPath, opts = {}) {
|
|
|
428
427
|
db.close();
|
|
429
428
|
}
|
|
430
429
|
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* CLI formatter — prints manifesto results and exits with code 1 on failure.
|
|
434
|
-
*/
|
|
435
|
-
export function manifesto(customDbPath, opts = {}) {
|
|
436
|
-
const data = manifestoData(customDbPath, opts);
|
|
437
|
-
|
|
438
|
-
if (outputResult(data, 'violations', opts)) {
|
|
439
|
-
if (!data.passed) process.exit(1);
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
console.log('\n# Manifesto Rules\n');
|
|
444
|
-
|
|
445
|
-
// Rules table
|
|
446
|
-
console.log(
|
|
447
|
-
` ${'Rule'.padEnd(20)} ${'Level'.padEnd(10)} ${'Status'.padEnd(8)} ${'Warn'.padStart(6)} ${'Fail'.padStart(6)} ${'Violations'.padStart(11)}`,
|
|
448
|
-
);
|
|
449
|
-
console.log(
|
|
450
|
-
` ${'─'.repeat(20)} ${'─'.repeat(10)} ${'─'.repeat(8)} ${'─'.repeat(6)} ${'─'.repeat(6)} ${'─'.repeat(11)}`,
|
|
451
|
-
);
|
|
452
|
-
|
|
453
|
-
for (const rule of data.rules) {
|
|
454
|
-
const warn = rule.thresholds.warn != null ? String(rule.thresholds.warn) : '—';
|
|
455
|
-
const fail = rule.thresholds.fail != null ? String(rule.thresholds.fail) : '—';
|
|
456
|
-
const statusIcon = rule.status === 'pass' ? 'pass' : rule.status === 'warn' ? 'WARN' : 'FAIL';
|
|
457
|
-
console.log(
|
|
458
|
-
` ${rule.name.padEnd(20)} ${rule.level.padEnd(10)} ${statusIcon.padEnd(8)} ${warn.padStart(6)} ${fail.padStart(6)} ${String(rule.violationCount).padStart(11)}`,
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// Summary
|
|
463
|
-
const s = data.summary;
|
|
464
|
-
console.log(
|
|
465
|
-
`\n ${s.total} rules | ${s.passed} passed | ${s.warned} warned | ${s.failed} failed | ${s.violationCount} violations`,
|
|
466
|
-
);
|
|
467
|
-
|
|
468
|
-
// Violations detail
|
|
469
|
-
if (data.violations.length > 0) {
|
|
470
|
-
const failViolations = data.violations.filter((v) => v.level === 'fail');
|
|
471
|
-
const warnViolations = data.violations.filter((v) => v.level === 'warn');
|
|
472
|
-
|
|
473
|
-
if (failViolations.length > 0) {
|
|
474
|
-
console.log(`\n## Failures (${failViolations.length})\n`);
|
|
475
|
-
for (const v of failViolations.slice(0, 20)) {
|
|
476
|
-
const loc = v.line ? `${v.file}:${v.line}` : v.file;
|
|
477
|
-
console.log(
|
|
478
|
-
` [FAIL] ${v.rule}: ${v.name} (${v.value}) at ${loc} — threshold ${v.threshold}`,
|
|
479
|
-
);
|
|
480
|
-
}
|
|
481
|
-
if (failViolations.length > 20) {
|
|
482
|
-
console.log(` ... and ${failViolations.length - 20} more`);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
if (warnViolations.length > 0) {
|
|
487
|
-
console.log(`\n## Warnings (${warnViolations.length})\n`);
|
|
488
|
-
for (const v of warnViolations.slice(0, 20)) {
|
|
489
|
-
const loc = v.line ? `${v.file}:${v.line}` : v.file;
|
|
490
|
-
console.log(
|
|
491
|
-
` [WARN] ${v.rule}: ${v.name} (${v.value}) at ${loc} — threshold ${v.threshold}`,
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
if (warnViolations.length > 20) {
|
|
495
|
-
console.log(` ... and ${warnViolations.length - 20} more`);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
console.log();
|
|
501
|
-
|
|
502
|
-
if (!data.passed) {
|
|
503
|
-
process.exit(1);
|
|
504
|
-
}
|
|
505
|
-
}
|
package/src/owners.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { findDbPath, openReadonlyOrFail } from './db.js';
|
|
4
|
-
import {
|
|
5
|
-
import { isTestFile } from './test-filter.js';
|
|
4
|
+
import { isTestFile } from './infrastructure/test-filter.js';
|
|
6
5
|
|
|
7
6
|
// ─── CODEOWNERS Parsing ──────────────────────────────────────────────
|
|
8
7
|
|
|
@@ -303,57 +302,3 @@ export function ownersData(customDbPath, opts = {}) {
|
|
|
303
302
|
db.close();
|
|
304
303
|
}
|
|
305
304
|
}
|
|
306
|
-
|
|
307
|
-
// ─── CLI Display ─────────────────────────────────────────────────────
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* CLI display function for the `owners` command.
|
|
311
|
-
* @param {string} [customDbPath]
|
|
312
|
-
* @param {object} [opts]
|
|
313
|
-
*/
|
|
314
|
-
export function owners(customDbPath, opts = {}) {
|
|
315
|
-
const data = ownersData(customDbPath, opts);
|
|
316
|
-
if (outputResult(data, null, opts)) return;
|
|
317
|
-
|
|
318
|
-
if (!data.codeownersFile) {
|
|
319
|
-
console.log('No CODEOWNERS file found.');
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
console.log(`\nCODEOWNERS: ${data.codeownersFile}\n`);
|
|
324
|
-
|
|
325
|
-
const s = data.summary;
|
|
326
|
-
console.log(
|
|
327
|
-
` Coverage: ${s.coveragePercent}% (${s.ownedFiles}/${s.totalFiles} files owned, ${s.ownerCount} owners)\n`,
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
if (s.byOwner.length > 0) {
|
|
331
|
-
console.log(' Owners:\n');
|
|
332
|
-
for (const o of s.byOwner) {
|
|
333
|
-
console.log(` ${o.owner} ${o.fileCount} files`);
|
|
334
|
-
}
|
|
335
|
-
console.log();
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (data.files.length > 0 && opts.owner) {
|
|
339
|
-
console.log(` Files owned by ${opts.owner}:\n`);
|
|
340
|
-
for (const f of data.files) {
|
|
341
|
-
console.log(` ${f.file}`);
|
|
342
|
-
}
|
|
343
|
-
console.log();
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (data.boundaries.length > 0) {
|
|
347
|
-
console.log(` Cross-owner boundaries: ${data.boundaries.length} edges\n`);
|
|
348
|
-
const shown = data.boundaries.slice(0, 30);
|
|
349
|
-
for (const b of shown) {
|
|
350
|
-
const srcOwner = b.from.owners.join(', ') || '(unowned)';
|
|
351
|
-
const tgtOwner = b.to.owners.join(', ') || '(unowned)';
|
|
352
|
-
console.log(` ${b.from.name} [${srcOwner}] -> ${b.to.name} [${tgtOwner}]`);
|
|
353
|
-
}
|
|
354
|
-
if (data.boundaries.length > 30) {
|
|
355
|
-
console.log(` ... and ${data.boundaries.length - 30} more`);
|
|
356
|
-
}
|
|
357
|
-
console.log();
|
|
358
|
-
}
|
|
359
|
-
}
|
package/src/queries-cli.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import path from 'node:path';
|
|
10
|
+
import { outputResult } from './infrastructure/result-formatter.js';
|
|
10
11
|
import {
|
|
11
12
|
childrenData,
|
|
12
13
|
contextData,
|
|
@@ -26,7 +27,6 @@ import {
|
|
|
26
27
|
statsData,
|
|
27
28
|
whereData,
|
|
28
29
|
} from './queries.js';
|
|
29
|
-
import { outputResult } from './result-formatter.js';
|
|
30
30
|
|
|
31
31
|
// ─── symbolPath ─────────────────────────────────────────────────────────
|
|
32
32
|
|