@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
package/src/cli/commands/deps.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fileDeps } from '../../queries-cli.js';
|
|
1
|
+
import { fileDeps } from '../../presentation/queries-cli.js';
|
|
2
2
|
|
|
3
3
|
export const command = {
|
|
4
4
|
name: 'deps <file>',
|
|
@@ -6,11 +6,7 @@ export const command = {
|
|
|
6
6
|
queryOpts: true,
|
|
7
7
|
execute([file], opts, ctx) {
|
|
8
8
|
fileDeps(file, opts.db, {
|
|
9
|
-
|
|
10
|
-
json: opts.json,
|
|
11
|
-
limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
|
|
12
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
13
|
-
ndjson: opts.ndjson,
|
|
9
|
+
...ctx.resolveQueryOpts(opts),
|
|
14
10
|
});
|
|
15
11
|
},
|
|
16
12
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { diffImpact } from '../../queries-cli.js';
|
|
1
|
+
import { diffImpact } from '../../presentation/queries-cli.js';
|
|
2
2
|
|
|
3
3
|
export const command = {
|
|
4
4
|
name: 'diff-impact [ref]',
|
|
@@ -19,12 +19,8 @@ export const command = {
|
|
|
19
19
|
ref,
|
|
20
20
|
staged: opts.staged,
|
|
21
21
|
depth: parseInt(opts.depth, 10),
|
|
22
|
-
noTests: ctx.resolveNoTests(opts),
|
|
23
|
-
json: opts.json,
|
|
24
22
|
format: opts.format,
|
|
25
|
-
|
|
26
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
27
|
-
ndjson: opts.ndjson,
|
|
23
|
+
...ctx.resolveQueryOpts(opts),
|
|
28
24
|
});
|
|
29
25
|
},
|
|
30
26
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { buildEmbeddings, DEFAULT_MODEL, EMBEDDING_STRATEGIES } from '../../
|
|
2
|
+
import { buildEmbeddings, DEFAULT_MODEL, EMBEDDING_STRATEGIES } from '../../domain/search/index.js';
|
|
3
3
|
|
|
4
4
|
export const command = {
|
|
5
5
|
name: 'embed [dir]',
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import { openReadonlyOrFail } from '../../db.js';
|
|
3
2
|
import {
|
|
4
3
|
exportDOT,
|
|
5
4
|
exportGraphML,
|
|
@@ -7,7 +6,8 @@ import {
|
|
|
7
6
|
exportJSON,
|
|
8
7
|
exportMermaid,
|
|
9
8
|
exportNeo4jCSV,
|
|
10
|
-
} from '../../export.js';
|
|
9
|
+
} from '../../features/export.js';
|
|
10
|
+
import { openGraph } from '../shared/open-graph.js';
|
|
11
11
|
|
|
12
12
|
export const command = {
|
|
13
13
|
name: 'export',
|
|
@@ -23,7 +23,7 @@ export const command = {
|
|
|
23
23
|
['-o, --output <file>', 'Write to file instead of stdout'],
|
|
24
24
|
],
|
|
25
25
|
execute(_args, opts, ctx) {
|
|
26
|
-
const db =
|
|
26
|
+
const { db, close } = openGraph(opts);
|
|
27
27
|
const exportOpts = {
|
|
28
28
|
fileLevel: !opts.functions,
|
|
29
29
|
noTests: ctx.resolveNoTests(opts),
|
|
@@ -32,38 +32,41 @@ export const command = {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
let output;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
35
|
+
try {
|
|
36
|
+
switch (opts.format) {
|
|
37
|
+
case 'mermaid':
|
|
38
|
+
output = exportMermaid(db, exportOpts);
|
|
39
|
+
break;
|
|
40
|
+
case 'json':
|
|
41
|
+
output = JSON.stringify(exportJSON(db, exportOpts), null, 2);
|
|
42
|
+
break;
|
|
43
|
+
case 'graphml':
|
|
44
|
+
output = exportGraphML(db, exportOpts);
|
|
45
|
+
break;
|
|
46
|
+
case 'graphson':
|
|
47
|
+
output = JSON.stringify(exportGraphSON(db, exportOpts), null, 2);
|
|
48
|
+
break;
|
|
49
|
+
case 'neo4j': {
|
|
50
|
+
const csv = exportNeo4jCSV(db, exportOpts);
|
|
51
|
+
if (opts.output) {
|
|
52
|
+
const base = opts.output.replace(/\.[^.]+$/, '') || opts.output;
|
|
53
|
+
fs.writeFileSync(`${base}-nodes.csv`, csv.nodes, 'utf-8');
|
|
54
|
+
fs.writeFileSync(`${base}-relationships.csv`, csv.relationships, 'utf-8');
|
|
55
|
+
console.log(`Exported to ${base}-nodes.csv and ${base}-relationships.csv`);
|
|
56
|
+
} else {
|
|
57
|
+
output = `--- nodes.csv ---\n${csv.nodes}\n\n--- relationships.csv ---\n${csv.relationships}`;
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
57
60
|
}
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
default:
|
|
62
|
+
output = exportDOT(db, exportOpts);
|
|
63
|
+
break;
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
break;
|
|
65
|
+
} finally {
|
|
66
|
+
close();
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
if (output === undefined) return;
|
|
67
70
|
|
|
68
71
|
if (opts.output) {
|
|
69
72
|
fs.writeFileSync(opts.output, output, 'utf-8');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fileExports } from '../../queries-cli.js';
|
|
1
|
+
import { fileExports } from '../../presentation/queries-cli.js';
|
|
2
2
|
|
|
3
3
|
export const command = {
|
|
4
4
|
name: 'exports <file>',
|
|
@@ -7,12 +7,8 @@ export const command = {
|
|
|
7
7
|
options: [['--unused', 'Show only exports with zero consumers (dead exports)']],
|
|
8
8
|
execute([file], opts, ctx) {
|
|
9
9
|
fileExports(file, opts.db, {
|
|
10
|
-
noTests: ctx.resolveNoTests(opts),
|
|
11
|
-
json: opts.json,
|
|
12
10
|
unused: opts.unused || false,
|
|
13
|
-
|
|
14
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
15
|
-
ndjson: opts.ndjson,
|
|
11
|
+
...ctx.resolveQueryOpts(opts),
|
|
16
12
|
});
|
|
17
13
|
},
|
|
18
14
|
};
|
package/src/cli/commands/flow.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EVERY_SYMBOL_KIND } from '../../queries.js';
|
|
1
|
+
import { EVERY_SYMBOL_KIND } from '../../domain/queries.js';
|
|
2
2
|
|
|
3
3
|
export const command = {
|
|
4
4
|
name: 'flow [name]',
|
|
@@ -20,17 +20,13 @@ export const command = {
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
async execute([name], opts, ctx) {
|
|
23
|
-
const { flow } = await import('../../
|
|
23
|
+
const { flow } = await import('../../presentation/flow.js');
|
|
24
24
|
flow(name, opts.db, {
|
|
25
25
|
list: opts.list,
|
|
26
26
|
depth: parseInt(opts.depth, 10),
|
|
27
27
|
file: opts.file,
|
|
28
28
|
kind: opts.kind,
|
|
29
|
-
|
|
30
|
-
json: opts.json,
|
|
31
|
-
limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
|
|
32
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
33
|
-
ndjson: opts.ndjson,
|
|
29
|
+
...ctx.resolveQueryOpts(opts),
|
|
34
30
|
});
|
|
35
31
|
},
|
|
36
32
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EVERY_SYMBOL_KIND } from '../../queries.js';
|
|
2
|
-
import { fnImpact } from '../../queries-cli.js';
|
|
1
|
+
import { EVERY_SYMBOL_KIND } from '../../domain/queries.js';
|
|
2
|
+
import { fnImpact } from '../../presentation/queries-cli.js';
|
|
3
3
|
|
|
4
4
|
export const command = {
|
|
5
5
|
name: 'fn-impact <name>',
|
|
@@ -20,11 +20,7 @@ export const command = {
|
|
|
20
20
|
depth: parseInt(opts.depth, 10),
|
|
21
21
|
file: opts.file,
|
|
22
22
|
kind: opts.kind,
|
|
23
|
-
|
|
24
|
-
json: opts.json,
|
|
25
|
-
limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
|
|
26
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
27
|
-
ndjson: opts.ndjson,
|
|
23
|
+
...ctx.resolveQueryOpts(opts),
|
|
28
24
|
});
|
|
29
25
|
},
|
|
30
26
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { impactAnalysis } from '../../queries-cli.js';
|
|
1
|
+
import { impactAnalysis } from '../../presentation/queries-cli.js';
|
|
2
2
|
|
|
3
3
|
export const command = {
|
|
4
4
|
name: 'impact <file>',
|
|
@@ -6,11 +6,7 @@ export const command = {
|
|
|
6
6
|
queryOpts: true,
|
|
7
7
|
execute([file], opts, ctx) {
|
|
8
8
|
impactAnalysis(file, opts.db, {
|
|
9
|
-
|
|
10
|
-
json: opts.json,
|
|
11
|
-
limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
|
|
12
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
13
|
-
ndjson: opts.ndjson,
|
|
9
|
+
...ctx.resolveQueryOpts(opts),
|
|
14
10
|
});
|
|
15
11
|
},
|
|
16
12
|
};
|
package/src/cli/commands/info.js
CHANGED
|
@@ -3,9 +3,9 @@ export const command = {
|
|
|
3
3
|
description: 'Show codegraph engine info and diagnostics',
|
|
4
4
|
async execute(_args, _opts, ctx) {
|
|
5
5
|
const { getNativePackageVersion, isNativeAvailable, loadNative } = await import(
|
|
6
|
-
'../../native.js'
|
|
6
|
+
'../../infrastructure/native.js'
|
|
7
7
|
);
|
|
8
|
-
const { getActiveEngine } = await import('../../parser.js');
|
|
8
|
+
const { getActiveEngine } = await import('../../domain/parser.js');
|
|
9
9
|
|
|
10
10
|
const engine = ctx.program.opts().engine;
|
|
11
11
|
const { name: activeName, version: activeVersion } = getActiveEngine({ engine });
|
package/src/cli/commands/map.js
CHANGED
package/src/cli/commands/mcp.js
CHANGED
|
@@ -7,7 +7,7 @@ export const command = {
|
|
|
7
7
|
['--repos <names>', 'Comma-separated list of allowed repo names (restricts access)'],
|
|
8
8
|
],
|
|
9
9
|
async execute(_args, opts) {
|
|
10
|
-
const { startMCPServer } = await import('../../mcp.js');
|
|
10
|
+
const { startMCPServer } = await import('../../mcp/index.js');
|
|
11
11
|
const mcpOpts = {};
|
|
12
12
|
mcpOpts.multiRepo = opts.multiRepo || !!opts.repos;
|
|
13
13
|
if (opts.repos) {
|
|
@@ -12,7 +12,7 @@ export const command = {
|
|
|
12
12
|
['-j, --json', 'Output as JSON'],
|
|
13
13
|
],
|
|
14
14
|
async execute([target], opts, ctx) {
|
|
15
|
-
const { owners } = await import('../../
|
|
15
|
+
const { owners } = await import('../../presentation/owners.js');
|
|
16
16
|
owners(opts.db, {
|
|
17
17
|
owner: opts.owner,
|
|
18
18
|
boundary: opts.boundary,
|
package/src/cli/commands/path.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EVERY_SYMBOL_KIND } from '../../queries.js';
|
|
2
|
-
import { symbolPath } from '../../queries-cli.js';
|
|
1
|
+
import { EVERY_SYMBOL_KIND } from '../../domain/queries.js';
|
|
2
|
+
import { symbolPath } from '../../presentation/queries-cli.js';
|
|
3
3
|
|
|
4
4
|
export const command = {
|
|
5
5
|
name: 'path <from> <to>',
|
package/src/cli/commands/plot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { openGraph } from '../shared/open-graph.js';
|
|
4
4
|
|
|
5
5
|
export const command = {
|
|
6
6
|
name: 'plot',
|
|
@@ -22,43 +22,52 @@ export const command = {
|
|
|
22
22
|
['--color-by <mode>', 'Color nodes by: kind | role | community | complexity'],
|
|
23
23
|
],
|
|
24
24
|
async execute(_args, opts, ctx) {
|
|
25
|
-
const { generatePlotHTML, loadPlotConfig } = await import('../../
|
|
25
|
+
const { generatePlotHTML, loadPlotConfig } = await import('../../features/graph-enrichment.js');
|
|
26
26
|
const os = await import('node:os');
|
|
27
|
-
const db =
|
|
27
|
+
const { db, close } = openGraph(opts);
|
|
28
28
|
|
|
29
29
|
let plotCfg;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
let html;
|
|
31
|
+
try {
|
|
32
|
+
if (opts.config) {
|
|
33
|
+
try {
|
|
34
|
+
plotCfg = JSON.parse(fs.readFileSync(opts.config, 'utf-8'));
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.error(`Failed to load config: ${e.message}`);
|
|
37
|
+
process.exitCode = 1;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
plotCfg = loadPlotConfig(process.cwd());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (opts.cluster) plotCfg.clusterBy = opts.cluster;
|
|
45
|
+
if (opts.colorBy) plotCfg.colorBy = opts.colorBy;
|
|
46
|
+
if (opts.sizeBy) plotCfg.sizeBy = opts.sizeBy;
|
|
47
|
+
if (opts.seed) plotCfg.seedStrategy = opts.seed;
|
|
48
|
+
if (opts.seedCount) plotCfg.seedCount = parseInt(opts.seedCount, 10);
|
|
49
|
+
if (opts.overlay) {
|
|
50
|
+
const parts = opts.overlay.split(',').map((s) => s.trim());
|
|
51
|
+
if (!plotCfg.overlays) plotCfg.overlays = {};
|
|
52
|
+
if (parts.includes('complexity')) plotCfg.overlays.complexity = true;
|
|
53
|
+
if (parts.includes('risk')) plotCfg.overlays.risk = true;
|
|
38
54
|
}
|
|
39
|
-
} else {
|
|
40
|
-
plotCfg = loadPlotConfig(process.cwd());
|
|
41
|
-
}
|
|
42
55
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (parts.includes('complexity')) plotCfg.overlays.complexity = true;
|
|
52
|
-
if (parts.includes('risk')) plotCfg.overlays.risk = true;
|
|
56
|
+
html = generatePlotHTML(db, {
|
|
57
|
+
fileLevel: !opts.functions,
|
|
58
|
+
noTests: ctx.resolveNoTests(opts),
|
|
59
|
+
minConfidence: parseFloat(opts.minConfidence),
|
|
60
|
+
config: plotCfg,
|
|
61
|
+
});
|
|
62
|
+
} finally {
|
|
63
|
+
close();
|
|
53
64
|
}
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
db.close();
|
|
66
|
+
if (!html) {
|
|
67
|
+
console.error('generatePlotHTML returned no output');
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
62
71
|
|
|
63
72
|
const outPath = opts.output || path.join(os.tmpdir(), `codegraph-plot-${Date.now()}.html`);
|
|
64
73
|
fs.writeFileSync(outPath, html, 'utf-8');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EVERY_SYMBOL_KIND } from '../../queries.js';
|
|
2
|
-
import { fnDeps, symbolPath } from '../../queries-cli.js';
|
|
1
|
+
import { EVERY_SYMBOL_KIND } from '../../domain/queries.js';
|
|
2
|
+
import { fnDeps, symbolPath } from '../../presentation/queries-cli.js';
|
|
3
3
|
|
|
4
4
|
export const command = {
|
|
5
5
|
name: 'query <name>',
|
|
@@ -38,11 +38,7 @@ export const command = {
|
|
|
38
38
|
depth: parseInt(opts.depth, 10),
|
|
39
39
|
file: opts.file,
|
|
40
40
|
kind: opts.kind,
|
|
41
|
-
|
|
42
|
-
json: opts.json,
|
|
43
|
-
limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
|
|
44
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
45
|
-
ndjson: opts.ndjson,
|
|
41
|
+
...ctx.resolveQueryOpts(opts),
|
|
46
42
|
});
|
|
47
43
|
}
|
|
48
44
|
},
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { ConfigError } from '../../errors.js';
|
|
4
3
|
import {
|
|
5
4
|
listRepos,
|
|
6
5
|
pruneRegistry,
|
|
7
6
|
REGISTRY_PATH,
|
|
8
7
|
registerRepo,
|
|
9
8
|
unregisterRepo,
|
|
10
|
-
} from '../../registry.js';
|
|
9
|
+
} from '../../infrastructure/registry.js';
|
|
10
|
+
import { ConfigError } from '../../shared/errors.js';
|
|
11
11
|
|
|
12
12
|
export const command = {
|
|
13
13
|
name: 'registry',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { VALID_ROLES } from '../../queries.js';
|
|
2
|
-
import { roles } from '../../queries-cli.js';
|
|
1
|
+
import { VALID_ROLES } from '../../domain/queries.js';
|
|
2
|
+
import { roles } from '../../presentation/queries-cli.js';
|
|
3
3
|
|
|
4
4
|
export const command = {
|
|
5
5
|
name: 'roles',
|
|
@@ -24,11 +24,7 @@ export const command = {
|
|
|
24
24
|
roles(opts.db, {
|
|
25
25
|
role: opts.role,
|
|
26
26
|
file: opts.file,
|
|
27
|
-
|
|
28
|
-
json: opts.json,
|
|
29
|
-
limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
|
|
30
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
31
|
-
ndjson: opts.ndjson,
|
|
27
|
+
...ctx.resolveQueryOpts(opts),
|
|
32
28
|
});
|
|
33
29
|
},
|
|
34
30
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EVERY_SYMBOL_KIND } from '../../queries.js';
|
|
1
|
+
import { EVERY_SYMBOL_KIND } from '../../domain/queries.js';
|
|
2
2
|
|
|
3
3
|
export const command = {
|
|
4
4
|
name: 'sequence <name>',
|
|
@@ -16,17 +16,13 @@ export const command = {
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
async execute([name], opts, ctx) {
|
|
19
|
-
const { sequence } = await import('../../
|
|
19
|
+
const { sequence } = await import('../../presentation/sequence.js');
|
|
20
20
|
sequence(name, opts.db, {
|
|
21
21
|
depth: parseInt(opts.depth, 10),
|
|
22
22
|
file: opts.file,
|
|
23
23
|
kind: opts.kind,
|
|
24
|
-
noTests: ctx.resolveNoTests(opts),
|
|
25
|
-
json: opts.json,
|
|
26
24
|
dataflow: opts.dataflow,
|
|
27
|
-
|
|
28
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
29
|
-
ndjson: opts.ndjson,
|
|
25
|
+
...ctx.resolveQueryOpts(opts),
|
|
30
26
|
});
|
|
31
27
|
},
|
|
32
28
|
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
snapshotDelete,
|
|
3
|
+
snapshotList,
|
|
4
|
+
snapshotRestore,
|
|
5
|
+
snapshotSave,
|
|
6
|
+
} from '../../features/snapshot.js';
|
|
2
7
|
|
|
3
8
|
export const command = {
|
|
4
9
|
name: 'snapshot',
|
|
@@ -15,15 +15,16 @@ export const command = {
|
|
|
15
15
|
['--ndjson', 'Newline-delimited JSON output'],
|
|
16
16
|
],
|
|
17
17
|
async execute([dir], opts, ctx) {
|
|
18
|
-
const { structureData, formatStructure } = await import('../../
|
|
18
|
+
const { structureData, formatStructure } = await import('../../presentation/structure.js');
|
|
19
|
+
const qOpts = ctx.resolveQueryOpts(opts);
|
|
19
20
|
const data = structureData(opts.db, {
|
|
20
21
|
directory: dir,
|
|
21
22
|
depth: opts.depth ? parseInt(opts.depth, 10) : undefined,
|
|
22
23
|
sort: opts.sort,
|
|
23
24
|
full: opts.full,
|
|
24
|
-
noTests:
|
|
25
|
-
limit:
|
|
26
|
-
offset:
|
|
25
|
+
noTests: qOpts.noTests,
|
|
26
|
+
limit: qOpts.limit,
|
|
27
|
+
offset: qOpts.offset,
|
|
27
28
|
});
|
|
28
29
|
if (!ctx.outputResult(data, 'directories', opts)) {
|
|
29
30
|
console.log(formatStructure(data));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { EVERY_SYMBOL_KIND, VALID_ROLES } from '../../domain/queries.js';
|
|
2
|
+
import { ConfigError } from '../../shared/errors.js';
|
|
3
3
|
|
|
4
4
|
export const command = {
|
|
5
5
|
name: 'triage',
|
|
@@ -31,7 +31,7 @@ export const command = {
|
|
|
31
31
|
],
|
|
32
32
|
async execute(_args, opts, ctx) {
|
|
33
33
|
if (opts.level === 'file' || opts.level === 'directory') {
|
|
34
|
-
const { hotspotsData, formatHotspots } = await import('../../
|
|
34
|
+
const { hotspotsData, formatHotspots } = await import('../../presentation/structure.js');
|
|
35
35
|
const metric = opts.sort === 'risk' ? 'fan-in' : opts.sort;
|
|
36
36
|
const data = hotspotsData(opts.db, {
|
|
37
37
|
metric,
|
|
@@ -60,7 +60,7 @@ export const command = {
|
|
|
60
60
|
throw new ConfigError('Invalid --weights JSON', { cause: err });
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
const { triage } = await import('../../
|
|
63
|
+
const { triage } = await import('../../presentation/triage.js');
|
|
64
64
|
triage(opts.db, {
|
|
65
65
|
limit: parseInt(opts.limit, 10),
|
|
66
66
|
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { where } from '../../queries-cli.js';
|
|
1
|
+
import { where } from '../../presentation/queries-cli.js';
|
|
2
2
|
|
|
3
3
|
export const command = {
|
|
4
4
|
name: 'where [name]',
|
|
@@ -14,11 +14,7 @@ export const command = {
|
|
|
14
14
|
const target = opts.file || name;
|
|
15
15
|
where(target, opts.db, {
|
|
16
16
|
file: !!opts.file,
|
|
17
|
-
|
|
18
|
-
json: opts.json,
|
|
19
|
-
limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
|
|
20
|
-
offset: opts.offset ? parseInt(opts.offset, 10) : undefined,
|
|
21
|
-
ndjson: opts.ndjson,
|
|
17
|
+
...ctx.resolveQueryOpts(opts),
|
|
22
18
|
});
|
|
23
19
|
},
|
|
24
20
|
};
|
package/src/cli/index.js
CHANGED
|
@@ -2,10 +2,16 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { Command } from 'commander';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { setVerbose } from '../infrastructure/logger.js';
|
|
6
|
+
import { checkForUpdates, printUpdateNotification } from '../infrastructure/update-check.js';
|
|
7
|
+
import { ConfigError } from '../shared/errors.js';
|
|
8
|
+
import {
|
|
9
|
+
applyQueryOpts,
|
|
10
|
+
config,
|
|
11
|
+
formatSize,
|
|
12
|
+
resolveNoTests,
|
|
13
|
+
resolveQueryOpts,
|
|
14
|
+
} from './shared/options.js';
|
|
9
15
|
import { outputResult } from './shared/output.js';
|
|
10
16
|
|
|
11
17
|
const __cliDir = path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/i, '$1'));
|
|
@@ -35,7 +41,7 @@ program
|
|
|
35
41
|
});
|
|
36
42
|
|
|
37
43
|
/** Shared context passed to every command's execute(). */
|
|
38
|
-
const ctx = { config, resolveNoTests, formatSize, outputResult, program };
|
|
44
|
+
const ctx = { config, resolveNoTests, resolveQueryOpts, formatSize, outputResult, program };
|
|
39
45
|
|
|
40
46
|
/**
|
|
41
47
|
* Register a command definition onto a Commander parent.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { openReadonlyOrFail } from '../../db/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Open the graph database in readonly mode with a clean close() handle.
|
|
5
|
+
*
|
|
6
|
+
* @param {object} [opts]
|
|
7
|
+
* @param {string} [opts.db] - Custom path to graph.db
|
|
8
|
+
* @returns {{ db: import('better-sqlite3').Database, close: () => void }}
|
|
9
|
+
*/
|
|
10
|
+
export function openGraph(opts = {}) {
|
|
11
|
+
const db = openReadonlyOrFail(opts.db);
|
|
12
|
+
return { db, close: () => db.close() };
|
|
13
|
+
}
|