@rexy_mayderio/blast-radius-mcp 0.0.0-stage → 1.0.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 +77 -2
- package/dist/adapters/inbound/test/BlastRadiusTestDriver.d.ts +14 -0
- package/dist/adapters/inbound/test/BlastRadiusTestDriver.js +21 -0
- package/dist/adapters/outbound/memory/InMemoryGitAdapter.d.ts +20 -0
- package/dist/adapters/outbound/memory/InMemoryGitAdapter.js +56 -0
- package/dist/adapters/outbound/memory/InMemoryGraphAdapter.d.ts +22 -0
- package/dist/adapters/outbound/memory/InMemoryGraphAdapter.js +79 -0
- package/dist/adapters/outbound/memory/InMemoryParserAdapter.d.ts +9 -0
- package/dist/adapters/outbound/memory/InMemoryParserAdapter.js +22 -0
- package/dist/adapters/outbound/memory/InMemoryWorkspaceAdapter.d.ts +17 -0
- package/dist/adapters/outbound/memory/InMemoryWorkspaceAdapter.js +58 -0
- package/dist/application/errors.d.ts +6 -0
- package/dist/application/errors.js +8 -0
- package/dist/application/ports/inbound/AnalyzeBlastRadius.d.ts +40 -0
- package/dist/application/ports/inbound/AnalyzeBlastRadius.js +1 -0
- package/dist/application/ports/inbound/CalculateChangeRiskScore.d.ts +15 -0
- package/dist/application/ports/inbound/CalculateChangeRiskScore.js +1 -0
- package/dist/application/ports/inbound/DiffContractAgainstSpec.d.ts +17 -0
- package/dist/application/ports/inbound/DiffContractAgainstSpec.js +1 -0
- package/dist/application/ports/inbound/GetTargetedTestSuite.d.ts +14 -0
- package/dist/application/ports/inbound/GetTargetedTestSuite.js +1 -0
- package/dist/application/ports/inbound/PredictForgottenFiles.d.ts +16 -0
- package/dist/application/ports/inbound/PredictForgottenFiles.js +1 -0
- package/dist/application/ports/inbound/SimulateMigrationLockImpact.d.ts +11 -0
- package/dist/application/ports/inbound/SimulateMigrationLockImpact.js +1 -0
- package/dist/application/ports/inbound/TraceEnvVariableReach.d.ts +15 -0
- package/dist/application/ports/inbound/TraceEnvVariableReach.js +1 -0
- package/dist/application/ports/inbound/TraceSymbolConsumers.d.ts +23 -0
- package/dist/application/ports/inbound/TraceSymbolConsumers.js +1 -0
- package/dist/application/ports/outbound/GitPort.d.ts +13 -0
- package/dist/application/ports/outbound/GitPort.js +1 -0
- package/dist/application/ports/outbound/GraphStorePort.d.ts +29 -0
- package/dist/application/ports/outbound/GraphStorePort.js +1 -0
- package/dist/application/ports/outbound/SourceParserPort.d.ts +24 -0
- package/dist/application/ports/outbound/SourceParserPort.js +1 -0
- package/dist/application/ports/outbound/WorkspacePort.d.ts +11 -0
- package/dist/application/ports/outbound/WorkspacePort.js +1 -0
- package/dist/application/use-cases/AnalyzeBlastRadius.d.ts +30 -0
- package/dist/application/use-cases/AnalyzeBlastRadius.js +231 -0
- package/dist/application/use-cases/CalculateChangeRiskScore.d.ts +26 -0
- package/dist/application/use-cases/CalculateChangeRiskScore.js +92 -0
- package/dist/application/use-cases/DiffContract.d.ts +11 -0
- package/dist/application/use-cases/DiffContract.js +240 -0
- package/dist/application/use-cases/ExtractSymbols.d.ts +10 -0
- package/dist/application/use-cases/ExtractSymbols.js +9 -0
- package/dist/application/use-cases/GetTargetedTestSuite.d.ts +17 -0
- package/dist/application/use-cases/GetTargetedTestSuite.js +132 -0
- package/dist/application/use-cases/IndexWorkspace.d.ts +17 -0
- package/dist/application/use-cases/IndexWorkspace.js +119 -0
- package/dist/application/use-cases/LinkSymbols.d.ts +18 -0
- package/dist/application/use-cases/LinkSymbols.js +272 -0
- package/dist/application/use-cases/PredictForgottenFiles.d.ts +7 -0
- package/dist/application/use-cases/PredictForgottenFiles.js +58 -0
- package/dist/application/use-cases/SemanticChanges.d.ts +17 -0
- package/dist/application/use-cases/SemanticChanges.js +54 -0
- package/dist/application/use-cases/SemanticDiff.d.ts +17 -0
- package/dist/application/use-cases/SemanticDiff.js +32 -0
- package/dist/application/use-cases/SimulateMigrationLockImpact.d.ts +8 -0
- package/dist/application/use-cases/SimulateMigrationLockImpact.js +56 -0
- package/dist/application/use-cases/TagBoundaries.d.ts +15 -0
- package/dist/application/use-cases/TagBoundaries.js +9 -0
- package/dist/application/use-cases/TraceEnvVariableReach.d.ts +7 -0
- package/dist/application/use-cases/TraceEnvVariableReach.js +54 -0
- package/dist/application/use-cases/TraceSymbolConsumers.d.ts +13 -0
- package/dist/application/use-cases/TraceSymbolConsumers.js +53 -0
- package/dist/application/use-cases/TraverseCallers.d.ts +20 -0
- package/dist/application/use-cases/TraverseCallers.js +46 -0
- package/dist/application/use-cases/packageEntries.d.ts +2 -0
- package/dist/application/use-cases/packageEntries.js +76 -0
- package/dist/application/use-cases/resolveTargetBranch.d.ts +2 -0
- package/dist/application/use-cases/resolveTargetBranch.js +6 -0
- package/dist/clients/base-client.d.ts +18 -0
- package/dist/clients/base-client.js +55 -0
- package/dist/clients/git-client.d.ts +17 -0
- package/dist/clients/git-client.js +159 -0
- package/dist/clients/sqlite-graph-client.d.ts +51 -0
- package/dist/clients/sqlite-graph-client.js +210 -0
- package/dist/clients/treesitter-client.d.ts +12 -0
- package/dist/clients/treesitter-client.js +125 -0
- package/dist/clients/workspace-client.d.ts +21 -0
- package/dist/clients/workspace-client.js +158 -0
- package/dist/composition/createRuntime.d.ts +45 -0
- package/dist/composition/createRuntime.js +119 -0
- package/dist/composition/registerTools.d.ts +8 -0
- package/dist/composition/registerTools.js +31 -0
- package/dist/domain/Edge.d.ts +9 -0
- package/dist/domain/Edge.js +12 -0
- package/dist/domain/Limits.d.ts +58 -0
- package/dist/domain/Limits.js +70 -0
- package/dist/domain/Risk.d.ts +19 -0
- package/dist/domain/Risk.js +39 -0
- package/dist/domain/Symbol.d.ts +25 -0
- package/dist/domain/Symbol.js +23 -0
- package/dist/domain/errors.d.ts +7 -0
- package/dist/domain/errors.js +21 -0
- package/dist/domain/sourceFiles.d.ts +3 -0
- package/dist/domain/sourceFiles.js +27 -0
- package/dist/domain/testFiles.d.ts +2 -0
- package/dist/domain/testFiles.js +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/languages/boundaries-typescript.d.ts +7 -0
- package/dist/languages/boundaries-typescript.js +246 -0
- package/dist/languages/go.d.ts +2 -0
- package/dist/languages/go.js +70 -0
- package/dist/languages/index.d.ts +5 -0
- package/dist/languages/index.js +5 -0
- package/dist/languages/java.d.ts +2 -0
- package/dist/languages/java.js +117 -0
- package/dist/languages/proto.d.ts +15 -0
- package/dist/languages/proto.js +38 -0
- package/dist/languages/python.d.ts +2 -0
- package/dist/languages/python.js +125 -0
- package/dist/languages/typescript.d.ts +36 -0
- package/dist/languages/typescript.js +412 -0
- package/dist/scripts/smoke.d.ts +1 -0
- package/dist/scripts/smoke.js +39 -0
- package/dist/scripts/test-connections.d.ts +1 -0
- package/dist/scripts/test-connections.js +5 -0
- package/dist/tools/analyze-blast-radius.d.ts +38 -0
- package/dist/tools/analyze-blast-radius.js +68 -0
- package/dist/tools/calculate-change-risk-score.d.ts +25 -0
- package/dist/tools/calculate-change-risk-score.js +49 -0
- package/dist/tools/diff-contract-against-spec.d.ts +30 -0
- package/dist/tools/diff-contract-against-spec.js +49 -0
- package/dist/tools/format.d.ts +70 -0
- package/dist/tools/format.js +144 -0
- package/dist/tools/get-targeted-test-suite.d.ts +37 -0
- package/dist/tools/get-targeted-test-suite.js +52 -0
- package/dist/tools/predict-forgotten-files.d.ts +35 -0
- package/dist/tools/predict-forgotten-files.js +49 -0
- package/dist/tools/simulate-migration-lock-impact.d.ts +26 -0
- package/dist/tools/simulate-migration-lock-impact.js +46 -0
- package/dist/tools/trace-env-variable-reach.d.ts +27 -0
- package/dist/tools/trace-env-variable-reach.js +47 -0
- package/dist/tools/trace-symbol-consumers.d.ts +37 -0
- package/dist/tools/trace-symbol-consumers.js +62 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +6 -0
- package/package.json +35 -4
package/README.md
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
-
#
|
|
1
|
+
# blast-radius-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Local MCP server that maps a code change to callers, boundaries, tests, co-changed files, and a clamped risk score. It indexes the workspace with Tree-sitter and SQLite, then answers eight read-only tools over stdio.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js `>=22`
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Node.js `>=22`. Add this to Cursor or Claude `mcp.json`. `npx` downloads the package on first launch:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"blast-radius": {
|
|
17
|
+
"command": "npx",
|
|
18
|
+
"args": ["-y", "@rexy_mayderio/blast-radius-mcp"],
|
|
19
|
+
"env": {
|
|
20
|
+
"BLAST_RADIUS_ROOT": "/absolute/path/to/your/repo"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Restart the MCP server after saving that file.
|
|
28
|
+
|
|
29
|
+
## Workspace root
|
|
30
|
+
|
|
31
|
+
The repo to index is chosen once, when the process starts. Paths such as `source_file`, `spec_path`, and `migration_file_path` are relative to that root.
|
|
32
|
+
|
|
33
|
+
Set it with `BLAST_RADIUS_ROOT` in the MCP client env. To point the same server at another repo, change the variable and restart the process.
|
|
34
|
+
|
|
35
|
+
Resolution order:
|
|
36
|
+
|
|
37
|
+
1. `BLAST_RADIUS_ROOT`, when it is set and not empty.
|
|
38
|
+
2. `git rev-parse --show-toplevel` from the process working directory.
|
|
39
|
+
3. The process working directory.
|
|
40
|
+
|
|
41
|
+
Cursor launches MCP servers from its own working directory, so set `BLAST_RADIUS_ROOT` there. The git and cwd fallbacks apply when you start the process inside the repo.
|
|
42
|
+
|
|
43
|
+
## Develop this repo
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm install
|
|
47
|
+
npm run build
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
To run a local checkout instead of the published package, point `command` at `node` and `args` at `dist/index.js` inside that checkout. Keep `BLAST_RADIUS_ROOT` on the repo you want indexed.
|
|
51
|
+
|
|
52
|
+
## Cache
|
|
53
|
+
|
|
54
|
+
The server may write a derived symbol graph at `{root}/.mcp/blast_radius.db` (SQLite WAL). Another process waits up to 30 seconds for that file instead of exiting on `database is locked`. The path is gitignored. Tools do not edit source files or git objects.
|
|
55
|
+
|
|
56
|
+
## Secrets and scope
|
|
57
|
+
|
|
58
|
+
- Put configuration in the agent **mcp.json `env`** block — **not project `.env`**. This server does not load dotenv.
|
|
59
|
+
- `BLAST_RADIUS_ROOT` is set via mcp.json `env`. Tool arguments are paths inside that root.
|
|
60
|
+
- Scope: local workspace indexing and eight stdio tools only. No network I/O, no SaaS auth tokens, no source edits. Residual risk: the process reads local source and git history for the chosen root.
|
|
61
|
+
|
|
62
|
+
## Safety notes
|
|
63
|
+
|
|
64
|
+
- Tools never execute tests (`vitest` / `jest` / `pytest` / `go test` / `node --test` strings are returned only).
|
|
65
|
+
- Migration analysis never connects to a database and never executes SQL.
|
|
66
|
+
- Env tracing never prints live `process.env` values.
|
|
67
|
+
- Untrusted diffs are capped; paths are realpath-jailed inside the workspace root.
|
|
68
|
+
|
|
69
|
+
## Scripts
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm test
|
|
73
|
+
npm run build
|
|
74
|
+
npm run depcruise
|
|
75
|
+
npm run test:connections
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`test:connections` builds, then traces `AuthService.validateSession` in the local auth fixture.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AnalyzeBlastRadius, AnalyzeBlastRadiusInput, BlastRadiusOutput } from '../../../application/ports/inbound/AnalyzeBlastRadius.js';
|
|
2
|
+
import type { TraceConsumersInput, TraceConsumersOutput, TraceSymbolConsumers } from '../../../application/ports/inbound/TraceSymbolConsumers.js';
|
|
3
|
+
import type { TraverseCallers, TraverseCallersInput, TraverseCallersOutput } from '../../../application/use-cases/TraverseCallers.js';
|
|
4
|
+
export declare class BlastRadiusTestDriver {
|
|
5
|
+
private readonly ports;
|
|
6
|
+
constructor(ports: {
|
|
7
|
+
traverseCallers: TraverseCallers;
|
|
8
|
+
traceSymbolConsumers?: TraceSymbolConsumers;
|
|
9
|
+
analyzeBlastRadius?: AnalyzeBlastRadius;
|
|
10
|
+
});
|
|
11
|
+
traverseCallers(input: TraverseCallersInput): TraverseCallersOutput;
|
|
12
|
+
traceSymbolConsumers(input: TraceConsumersInput): Promise<TraceConsumersOutput>;
|
|
13
|
+
analyzeBlastRadius(input: AnalyzeBlastRadiusInput): Promise<BlastRadiusOutput>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class BlastRadiusTestDriver {
|
|
2
|
+
ports;
|
|
3
|
+
constructor(ports) {
|
|
4
|
+
this.ports = ports;
|
|
5
|
+
}
|
|
6
|
+
traverseCallers(input) {
|
|
7
|
+
return this.ports.traverseCallers.execute(input);
|
|
8
|
+
}
|
|
9
|
+
async traceSymbolConsumers(input) {
|
|
10
|
+
if (!this.ports.traceSymbolConsumers) {
|
|
11
|
+
throw new Error('traceSymbolConsumers port not configured');
|
|
12
|
+
}
|
|
13
|
+
return this.ports.traceSymbolConsumers.execute(input);
|
|
14
|
+
}
|
|
15
|
+
async analyzeBlastRadius(input) {
|
|
16
|
+
if (!this.ports.analyzeBlastRadius) {
|
|
17
|
+
throw new Error('analyzeBlastRadius port not configured');
|
|
18
|
+
}
|
|
19
|
+
return this.ports.analyzeBlastRadius.execute(input);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CommitTouch, GitPort } from '../../../application/ports/outbound/GitPort.js';
|
|
2
|
+
export declare class InMemoryGitAdapter implements GitPort {
|
|
3
|
+
private isRepo;
|
|
4
|
+
private working;
|
|
5
|
+
private diffs;
|
|
6
|
+
private history;
|
|
7
|
+
private revisions;
|
|
8
|
+
setRepo(isRepo: boolean): void;
|
|
9
|
+
setWorkingTree(files: string[]): void;
|
|
10
|
+
setDiff(targetBranch: string, diff: string): void;
|
|
11
|
+
setHistory(history: CommitTouch[]): void;
|
|
12
|
+
ensureRepo(): Promise<void>;
|
|
13
|
+
defaultBranch(): Promise<string>;
|
|
14
|
+
changedFiles(_targetBranch: string): Promise<string[]>;
|
|
15
|
+
showFile(revision: string, filePath: string): Promise<string | null>;
|
|
16
|
+
setRevisionFile(revision: string, filePath: string, content: string): void;
|
|
17
|
+
diffAgainst(targetBranch: string): Promise<string>;
|
|
18
|
+
logTouches(paths: string[], maxCommits: number): Promise<CommitTouch[]>;
|
|
19
|
+
workingTreeFiles(): Promise<string[]>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ApplicationError } from '../../../application/errors.js';
|
|
2
|
+
export class InMemoryGitAdapter {
|
|
3
|
+
isRepo = true;
|
|
4
|
+
working = [];
|
|
5
|
+
diffs = new Map();
|
|
6
|
+
history = [];
|
|
7
|
+
revisions = new Map();
|
|
8
|
+
setRepo(isRepo) {
|
|
9
|
+
this.isRepo = isRepo;
|
|
10
|
+
}
|
|
11
|
+
setWorkingTree(files) {
|
|
12
|
+
this.working = files;
|
|
13
|
+
}
|
|
14
|
+
setDiff(targetBranch, diff) {
|
|
15
|
+
this.diffs.set(targetBranch, diff);
|
|
16
|
+
}
|
|
17
|
+
setHistory(history) {
|
|
18
|
+
this.history = history;
|
|
19
|
+
}
|
|
20
|
+
async ensureRepo() {
|
|
21
|
+
if (!this.isRepo) {
|
|
22
|
+
throw new ApplicationError('NOT_A_REPOSITORY');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async defaultBranch() {
|
|
26
|
+
await this.ensureRepo();
|
|
27
|
+
return 'main';
|
|
28
|
+
}
|
|
29
|
+
async changedFiles(_targetBranch) {
|
|
30
|
+
await this.ensureRepo();
|
|
31
|
+
return [...this.working];
|
|
32
|
+
}
|
|
33
|
+
async showFile(revision, filePath) {
|
|
34
|
+
await this.ensureRepo();
|
|
35
|
+
return this.revisions.get(`${revision}:${normalize(filePath)}`) ?? null;
|
|
36
|
+
}
|
|
37
|
+
setRevisionFile(revision, filePath, content) {
|
|
38
|
+
this.revisions.set(`${revision}:${normalize(filePath)}`, content);
|
|
39
|
+
}
|
|
40
|
+
async diffAgainst(targetBranch) {
|
|
41
|
+
await this.ensureRepo();
|
|
42
|
+
return this.diffs.get(targetBranch) ?? '';
|
|
43
|
+
}
|
|
44
|
+
async logTouches(paths, maxCommits) {
|
|
45
|
+
await this.ensureRepo();
|
|
46
|
+
const wanted = new Set(paths);
|
|
47
|
+
return this.history.filter((touch) => touch.files.some((file) => wanted.has(file))).slice(0, maxCommits);
|
|
48
|
+
}
|
|
49
|
+
async workingTreeFiles() {
|
|
50
|
+
await this.ensureRepo();
|
|
51
|
+
return [...this.working];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function normalize(filePath) {
|
|
55
|
+
return filePath.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
56
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Edge } from '../../../domain/Edge.js';
|
|
2
|
+
import type { SymbolNode } from '../../../domain/Symbol.js';
|
|
3
|
+
import type { FileIndexRow, GraphStorePort, TestCaseRef } from '../../../application/ports/outbound/GraphStorePort.js';
|
|
4
|
+
export declare class InMemoryGraphAdapter implements GraphStorePort {
|
|
5
|
+
private readonly nodes;
|
|
6
|
+
private readonly edges;
|
|
7
|
+
private readonly hashes;
|
|
8
|
+
replaceFile(filePath: string, symbols: SymbolNode[], edges: Edge[]): void;
|
|
9
|
+
seed(symbols: SymbolNode[], edges: Edge[]): void;
|
|
10
|
+
getNode(symbolId: string): SymbolNode | null;
|
|
11
|
+
findByQualifiedName(filePath: string, name: string): SymbolNode | null;
|
|
12
|
+
findByName(name: string): SymbolNode[];
|
|
13
|
+
getIncomingEdges(symbolId: string): Edge[];
|
|
14
|
+
getOutgoingEdges(symbolId: string): Edge[];
|
|
15
|
+
listByFile(filePath: string): SymbolNode[];
|
|
16
|
+
listSymbols(): SymbolNode[];
|
|
17
|
+
listEdges(): Edge[];
|
|
18
|
+
listTestCases(runner: string): TestCaseRef[];
|
|
19
|
+
fileContentHash(filePath: string): string | null;
|
|
20
|
+
setFileHash(filePath: string, contentHash: string): void;
|
|
21
|
+
listIndexedFiles(): FileIndexRow[];
|
|
22
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export class InMemoryGraphAdapter {
|
|
2
|
+
nodes = new Map();
|
|
3
|
+
edges = new Map();
|
|
4
|
+
hashes = new Map();
|
|
5
|
+
replaceFile(filePath, symbols, edges) {
|
|
6
|
+
for (const [id, node] of this.nodes) {
|
|
7
|
+
if (node.filePath === filePath)
|
|
8
|
+
this.nodes.delete(id);
|
|
9
|
+
}
|
|
10
|
+
for (const [id, edge] of this.edges) {
|
|
11
|
+
const source = this.nodes.get(edge.sourceId);
|
|
12
|
+
const target = this.nodes.get(edge.targetId);
|
|
13
|
+
if (!source || !target || source.filePath === filePath || target.filePath === filePath) {
|
|
14
|
+
this.edges.delete(id);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
for (const symbol of symbols)
|
|
18
|
+
this.nodes.set(symbol.id, symbol);
|
|
19
|
+
for (const edge of edges)
|
|
20
|
+
this.edges.set(edge.id, edge);
|
|
21
|
+
}
|
|
22
|
+
seed(symbols, edges) {
|
|
23
|
+
for (const symbol of symbols)
|
|
24
|
+
this.nodes.set(symbol.id, symbol);
|
|
25
|
+
for (const edge of edges)
|
|
26
|
+
this.edges.set(edge.id, edge);
|
|
27
|
+
}
|
|
28
|
+
getNode(symbolId) {
|
|
29
|
+
return this.nodes.get(symbolId) ?? null;
|
|
30
|
+
}
|
|
31
|
+
findByQualifiedName(filePath, name) {
|
|
32
|
+
for (const node of this.nodes.values()) {
|
|
33
|
+
if (node.filePath === filePath && node.name === name)
|
|
34
|
+
return node;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
findByName(name) {
|
|
39
|
+
return [...this.nodes.values()].filter((node) => node.name === name);
|
|
40
|
+
}
|
|
41
|
+
getIncomingEdges(symbolId) {
|
|
42
|
+
return [...this.edges.values()].filter((edge) => edge.targetId === symbolId);
|
|
43
|
+
}
|
|
44
|
+
getOutgoingEdges(symbolId) {
|
|
45
|
+
return [...this.edges.values()].filter((edge) => edge.sourceId === symbolId);
|
|
46
|
+
}
|
|
47
|
+
listByFile(filePath) {
|
|
48
|
+
return [...this.nodes.values()].filter((node) => node.filePath === filePath);
|
|
49
|
+
}
|
|
50
|
+
listSymbols() {
|
|
51
|
+
return [...this.nodes.values()];
|
|
52
|
+
}
|
|
53
|
+
listEdges() {
|
|
54
|
+
return [...this.edges.values()];
|
|
55
|
+
}
|
|
56
|
+
listTestCases(runner) {
|
|
57
|
+
return [...this.nodes.values()]
|
|
58
|
+
.filter((node) => node.kind === 'test' && (runner === '*' || node.language === runner))
|
|
59
|
+
.map((node) => ({
|
|
60
|
+
symbolId: node.id,
|
|
61
|
+
name: node.name,
|
|
62
|
+
filePath: node.filePath,
|
|
63
|
+
runner,
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
fileContentHash(filePath) {
|
|
67
|
+
return this.hashes.get(filePath)?.contentHash ?? null;
|
|
68
|
+
}
|
|
69
|
+
setFileHash(filePath, contentHash) {
|
|
70
|
+
this.hashes.set(filePath, {
|
|
71
|
+
filePath,
|
|
72
|
+
contentHash,
|
|
73
|
+
indexedAt: new Date().toISOString(),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
listIndexedFiles() {
|
|
77
|
+
return [...this.hashes.values()];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ParseResult, SourceParserPort } from '../../../application/ports/outbound/SourceParserPort.js';
|
|
2
|
+
export declare class InMemoryParserAdapter implements SourceParserPort {
|
|
3
|
+
private readonly byFile;
|
|
4
|
+
private readonly languages;
|
|
5
|
+
seed(filePath: string, result: ParseResult): void;
|
|
6
|
+
setLanguages(languages: string[]): void;
|
|
7
|
+
parse(filePath: string, _source: string): ParseResult;
|
|
8
|
+
supportedLanguages(): string[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class InMemoryParserAdapter {
|
|
2
|
+
byFile = new Map();
|
|
3
|
+
languages = ['typescript', 'javascript'];
|
|
4
|
+
seed(filePath, result) {
|
|
5
|
+
this.byFile.set(filePath, result);
|
|
6
|
+
}
|
|
7
|
+
setLanguages(languages) {
|
|
8
|
+
this.languages.splice(0, this.languages.length, ...languages);
|
|
9
|
+
}
|
|
10
|
+
parse(filePath, _source) {
|
|
11
|
+
return (this.byFile.get(filePath) ?? {
|
|
12
|
+
symbols: [],
|
|
13
|
+
edges: [],
|
|
14
|
+
unresolvedRefCount: 0,
|
|
15
|
+
rawRefs: [],
|
|
16
|
+
language: 'unknown',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
supportedLanguages() {
|
|
20
|
+
return [...this.languages];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WorkspacePort } from '../../../application/ports/outbound/WorkspacePort.js';
|
|
2
|
+
import { MAX_FILE_BYTES } from '../../../domain/Limits.js';
|
|
3
|
+
import { SOURCE_EXT, isIgnored } from '../../../domain/sourceFiles.js';
|
|
4
|
+
export declare class InMemoryWorkspaceAdapter implements WorkspacePort {
|
|
5
|
+
readonly root: string;
|
|
6
|
+
private readonly files;
|
|
7
|
+
constructor(root?: string);
|
|
8
|
+
seed(files: Record<string, string>): void;
|
|
9
|
+
resolveInsideRoot(inputPath: string): string;
|
|
10
|
+
readText(relativePath: string): string;
|
|
11
|
+
writeText(relativePath: string, contents: string): void;
|
|
12
|
+
listSourceFiles(): string[];
|
|
13
|
+
fileSize(relativePath: string): number;
|
|
14
|
+
exists(relativePath: string): boolean;
|
|
15
|
+
relativePath(absolutePath: string): string;
|
|
16
|
+
}
|
|
17
|
+
export { SOURCE_EXT, isIgnored, MAX_FILE_BYTES };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { ApplicationError } from '../../../application/errors.js';
|
|
3
|
+
import { MAX_FILE_BYTES } from '../../../domain/Limits.js';
|
|
4
|
+
import { SOURCE_EXT, exceedsMaxFileBytes, isIgnored } from '../../../domain/sourceFiles.js';
|
|
5
|
+
export class InMemoryWorkspaceAdapter {
|
|
6
|
+
root;
|
|
7
|
+
files = new Map();
|
|
8
|
+
constructor(root = '/repo') {
|
|
9
|
+
this.root = path.resolve(root);
|
|
10
|
+
}
|
|
11
|
+
seed(files) {
|
|
12
|
+
for (const [relativePath, contents] of Object.entries(files)) {
|
|
13
|
+
this.files.set(normalizeRelative(relativePath), contents);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
resolveInsideRoot(inputPath) {
|
|
17
|
+
const abs = path.resolve(this.root, inputPath);
|
|
18
|
+
const rel = path.relative(this.root, abs);
|
|
19
|
+
if (rel.startsWith('..') || path.isAbsolute(rel)) {
|
|
20
|
+
throw new ApplicationError('PATH_ESCAPE');
|
|
21
|
+
}
|
|
22
|
+
return abs;
|
|
23
|
+
}
|
|
24
|
+
readText(relativePath) {
|
|
25
|
+
const rel = this.relativePath(this.resolveInsideRoot(relativePath));
|
|
26
|
+
const contents = this.files.get(rel);
|
|
27
|
+
if (contents === undefined) {
|
|
28
|
+
throw new ApplicationError('INVALID', `Missing file ${rel}`);
|
|
29
|
+
}
|
|
30
|
+
return contents;
|
|
31
|
+
}
|
|
32
|
+
writeText(relativePath, contents) {
|
|
33
|
+
const rel = this.relativePath(this.resolveInsideRoot(relativePath));
|
|
34
|
+
this.files.set(rel, contents);
|
|
35
|
+
}
|
|
36
|
+
listSourceFiles() {
|
|
37
|
+
return [...this.files.keys()].filter((filePath) => {
|
|
38
|
+
if (isIgnored(filePath))
|
|
39
|
+
return false;
|
|
40
|
+
if (exceedsMaxFileBytes(Buffer.byteLength(this.files.get(filePath) ?? '')))
|
|
41
|
+
return false;
|
|
42
|
+
return SOURCE_EXT.has(path.extname(filePath).toLowerCase());
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
fileSize(relativePath) {
|
|
46
|
+
return Buffer.byteLength(this.files.get(normalizeRelative(relativePath)) ?? '');
|
|
47
|
+
}
|
|
48
|
+
exists(relativePath) {
|
|
49
|
+
return this.files.has(normalizeRelative(relativePath));
|
|
50
|
+
}
|
|
51
|
+
relativePath(absolutePath) {
|
|
52
|
+
return normalizeRelative(path.relative(this.root, absolutePath));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function normalizeRelative(relativePath) {
|
|
56
|
+
return relativePath.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
57
|
+
}
|
|
58
|
+
export { SOURCE_EXT, isIgnored, MAX_FILE_BYTES };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { RiskLevel } from '../../../domain/Risk.js';
|
|
2
|
+
export type AnalyzeBlastRadiusInput = {
|
|
3
|
+
diff: string;
|
|
4
|
+
max_depth: number;
|
|
5
|
+
include_tests: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type ChangeKind = 'added' | 'removed' | 'signature_modified' | 'body_modified';
|
|
8
|
+
export type ModifiedSymbol = {
|
|
9
|
+
name: string;
|
|
10
|
+
file: string;
|
|
11
|
+
change: ChangeKind;
|
|
12
|
+
};
|
|
13
|
+
export type ImpactRow = {
|
|
14
|
+
name: string;
|
|
15
|
+
file: string;
|
|
16
|
+
line: number;
|
|
17
|
+
depth: number;
|
|
18
|
+
kind: string;
|
|
19
|
+
is_boundary: boolean;
|
|
20
|
+
route_label: string | null;
|
|
21
|
+
};
|
|
22
|
+
export type BlastRadiusOutput = {
|
|
23
|
+
modified_symbols: ModifiedSymbol[];
|
|
24
|
+
impact_summary: {
|
|
25
|
+
direct_callers: number;
|
|
26
|
+
indirect_callers: number;
|
|
27
|
+
affected_routes: number;
|
|
28
|
+
affected_db_models: number;
|
|
29
|
+
risk_level: RiskLevel;
|
|
30
|
+
risk_score: number;
|
|
31
|
+
};
|
|
32
|
+
impact_tree: ImpactRow[];
|
|
33
|
+
affected_test_files: string[];
|
|
34
|
+
unresolved_calls: number;
|
|
35
|
+
truncated: boolean;
|
|
36
|
+
omitted_count: number;
|
|
37
|
+
};
|
|
38
|
+
export interface AnalyzeBlastRadius {
|
|
39
|
+
execute(input: AnalyzeBlastRadiusInput): Promise<BlastRadiusOutput>;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RiskLevel } from '../../../domain/Risk.js';
|
|
2
|
+
export type CalculateChangeRiskScoreInput = {
|
|
3
|
+
target_branch?: string;
|
|
4
|
+
};
|
|
5
|
+
export type RiskScoreOutput = {
|
|
6
|
+
risk_score: number;
|
|
7
|
+
risk_level: RiskLevel;
|
|
8
|
+
depth_points: number;
|
|
9
|
+
api_points: number;
|
|
10
|
+
test_gap_points: number;
|
|
11
|
+
forgotten_points: number;
|
|
12
|
+
};
|
|
13
|
+
export interface CalculateChangeRiskScore {
|
|
14
|
+
execute(input: CalculateChangeRiskScoreInput): Promise<RiskScoreOutput>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ContractDriftCode = 'MISSING_IN_SPEC' | 'MISSING_IN_CODE' | 'TYPE_MISMATCH';
|
|
2
|
+
export type ContractDriftItem = {
|
|
3
|
+
code: ContractDriftCode;
|
|
4
|
+
name: string;
|
|
5
|
+
detail: string;
|
|
6
|
+
};
|
|
7
|
+
export type DiffContractInput = {
|
|
8
|
+
spec_path: string;
|
|
9
|
+
modified_controller?: string;
|
|
10
|
+
};
|
|
11
|
+
export type ContractDriftOutput = {
|
|
12
|
+
kind: 'openapi' | 'graphql' | 'protobuf';
|
|
13
|
+
drifts: ContractDriftItem[];
|
|
14
|
+
};
|
|
15
|
+
export interface DiffContractAgainstSpec {
|
|
16
|
+
execute(input: DiffContractInput): Promise<ContractDriftOutput>;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type TestRunner = 'jest' | 'vitest' | 'pytest' | 'go_test' | 'node_test';
|
|
2
|
+
export type GetTargetedTestSuiteInput = {
|
|
3
|
+
target_branch?: string;
|
|
4
|
+
runner: TestRunner;
|
|
5
|
+
};
|
|
6
|
+
export type TargetedTestsOutput = {
|
|
7
|
+
total_project_tests: number;
|
|
8
|
+
targeted_test_count: number;
|
|
9
|
+
execution_command: string;
|
|
10
|
+
coverage_confidence: number;
|
|
11
|
+
};
|
|
12
|
+
export interface GetTargetedTestSuite {
|
|
13
|
+
execute(input: GetTargetedTestSuiteInput): Promise<TargetedTestsOutput>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type ForgottenFile = {
|
|
2
|
+
file: string;
|
|
3
|
+
co_change_frequency: number;
|
|
4
|
+
support: number;
|
|
5
|
+
reason: string;
|
|
6
|
+
};
|
|
7
|
+
export type PredictForgottenFilesInput = {
|
|
8
|
+
min_confidence: number;
|
|
9
|
+
modified_files?: string[];
|
|
10
|
+
};
|
|
11
|
+
export type ForgottenFilesOutput = {
|
|
12
|
+
unmodified_co_changes: ForgottenFile[];
|
|
13
|
+
};
|
|
14
|
+
export interface PredictForgottenFiles {
|
|
15
|
+
execute(input: PredictForgottenFilesInput): Promise<ForgottenFilesOutput>;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type MigrationFinding = 'REWRITE' | 'LOCK_WRITES' | 'CDC_BREAK' | 'INDEX_GAP';
|
|
2
|
+
export type SimulateMigrationInput = {
|
|
3
|
+
migration_file_path: string;
|
|
4
|
+
};
|
|
5
|
+
export type MigrationImpactOutput = {
|
|
6
|
+
lock_risk: 'HIGH' | 'LOW';
|
|
7
|
+
findings: MigrationFinding[];
|
|
8
|
+
};
|
|
9
|
+
export interface SimulateMigrationLockImpact {
|
|
10
|
+
execute(input: SimulateMigrationInput): Promise<MigrationImpactOutput>;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type EnvReachSite = {
|
|
2
|
+
file: string;
|
|
3
|
+
line: number;
|
|
4
|
+
snippet: string;
|
|
5
|
+
};
|
|
6
|
+
export type TraceEnvInput = {
|
|
7
|
+
env_var_name: string;
|
|
8
|
+
};
|
|
9
|
+
export type EnvReachOutput = {
|
|
10
|
+
env_var_name: string;
|
|
11
|
+
sites: EnvReachSite[];
|
|
12
|
+
};
|
|
13
|
+
export interface TraceEnvVariableReach {
|
|
14
|
+
execute(input: TraceEnvInput): Promise<EnvReachOutput>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type TraceConsumersInput = {
|
|
2
|
+
symbol_name: string;
|
|
3
|
+
source_file: string;
|
|
4
|
+
max_depth: number;
|
|
5
|
+
};
|
|
6
|
+
export type CallerHit = {
|
|
7
|
+
name: string;
|
|
8
|
+
file: string;
|
|
9
|
+
line: number;
|
|
10
|
+
depth: number;
|
|
11
|
+
route: string;
|
|
12
|
+
};
|
|
13
|
+
export type TraceConsumersOutput = {
|
|
14
|
+
symbol: string;
|
|
15
|
+
callers: CallerHit[];
|
|
16
|
+
routes: string[];
|
|
17
|
+
event_handlers: string[];
|
|
18
|
+
truncated: boolean;
|
|
19
|
+
omitted_count: number;
|
|
20
|
+
};
|
|
21
|
+
export interface TraceSymbolConsumers {
|
|
22
|
+
execute(input: TraceConsumersInput): Promise<TraceConsumersOutput>;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type CommitTouch = {
|
|
2
|
+
commit: string;
|
|
3
|
+
files: string[];
|
|
4
|
+
};
|
|
5
|
+
export interface GitPort {
|
|
6
|
+
ensureRepo(): Promise<void>;
|
|
7
|
+
defaultBranch(): Promise<string>;
|
|
8
|
+
changedFiles(targetBranch: string): Promise<string[]>;
|
|
9
|
+
showFile(revision: string, filePath: string): Promise<string | null>;
|
|
10
|
+
diffAgainst(targetBranch: string): Promise<string>;
|
|
11
|
+
logTouches(paths: string[], maxCommits: number): Promise<CommitTouch[]>;
|
|
12
|
+
workingTreeFiles(): Promise<string[]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Edge } from '../../../domain/Edge.js';
|
|
2
|
+
import type { SymbolNode } from '../../../domain/Symbol.js';
|
|
3
|
+
export type TestCaseRef = {
|
|
4
|
+
symbolId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
filePath: string;
|
|
7
|
+
runner: string;
|
|
8
|
+
};
|
|
9
|
+
export type FileIndexRow = {
|
|
10
|
+
filePath: string;
|
|
11
|
+
contentHash: string;
|
|
12
|
+
indexedAt: string;
|
|
13
|
+
};
|
|
14
|
+
export interface GraphStorePort {
|
|
15
|
+
replaceFile(filePath: string, symbols: SymbolNode[], edges: Edge[]): void;
|
|
16
|
+
getNode(symbolId: string): SymbolNode | null;
|
|
17
|
+
findByQualifiedName(filePath: string, name: string): SymbolNode | null;
|
|
18
|
+
findByName(name: string): SymbolNode[];
|
|
19
|
+
getIncomingEdges(symbolId: string): Edge[];
|
|
20
|
+
getOutgoingEdges(symbolId: string): Edge[];
|
|
21
|
+
listByFile(filePath: string): SymbolNode[];
|
|
22
|
+
listSymbols(): SymbolNode[];
|
|
23
|
+
listEdges(): Edge[];
|
|
24
|
+
listTestCases(runner: string): TestCaseRef[];
|
|
25
|
+
fileContentHash(filePath: string): string | null;
|
|
26
|
+
setFileHash(filePath: string, contentHash: string): void;
|
|
27
|
+
listIndexedFiles(): FileIndexRow[];
|
|
28
|
+
databasePath?(): string;
|
|
29
|
+
}
|