@dimassetoid/septum-mcp 0.3.0 → 0.5.1
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 +38 -55
- package/package.json +7 -5
- package/src/cli/commands/check.ts +14 -10
- package/src/cli/commands/hook.ts +41 -6
- package/src/cli/commands/init.ts +10 -1
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +32 -4
- package/src/cli/index.ts +7 -0
- package/src/cli/templates/hooks.ts +3 -14
- package/src/cli/templates/skill.ts +17 -10
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +251 -114
- package/src/core/boundary/staged-auditor.ts +147 -55
- package/src/core/config/domain-ownership.ts +6 -4
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +1 -25
- package/src/core/config/schema.ts +24 -36
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +334 -572
- package/src/core/database/repositories/domain.repository.ts +2 -1
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -398
- package/src/core/database/repository.ts +68 -9
- package/src/core/database/schema.ts +26 -0
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +222 -58
- package/src/core/discovery/topology-detector.ts +93 -168
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +287 -88
- package/src/core/parser/extractors/base.ts +11 -3
- package/src/core/parser/extractors/csharp.ts +2 -2
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +397 -481
- package/src/core/parser/extractors/elysia-semantic.ts +172 -475
- package/src/core/parser/extractors/express-semantic.ts +195 -383
- package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
- package/src/core/parser/extractors/fastify-semantic.ts +216 -717
- package/src/core/parser/extractors/flask-semantic.ts +89 -352
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +205 -562
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -509
- package/src/core/parser/extractors/java.ts +2 -2
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +143 -335
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +1 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +5 -9
- package/src/core/parser/extractors/registry.ts +2 -0
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +2 -2
- package/src/core/parser/extractors/rust.ts +4 -4
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +72 -226
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +23 -216
- package/src/core/parser/language-capabilities.ts +1 -1
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +169 -414
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +60 -7
- package/src/core/resolver/interpretation-inputs.ts +60 -2
- package/src/core/resolver/languages/python.ts +31 -13
- package/src/core/resolver/languages/shared.ts +4 -1
- package/src/core/resolver/module-resolver.ts +10 -3
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +21 -6
- package/src/core/resolver/slice-format.ts +13 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +104 -8
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +31 -230
- package/src/core/resources/ignore.ts +0 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +11 -4
- package/src/core/retrieval/context.ts +363 -226
- package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +3 -3
- package/src/core/retrieval/typescript-references.ts +38 -7
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +192 -49
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +255 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -746
- package/src/mcp/server.ts +269 -429
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +68 -3
- package/src/mcp/tools/map.ts +104 -4
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +469 -17
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +88 -15
- package/src/mcp/workspace-watcher.ts +30 -11
- package/src/types/index.ts +12 -0
- package/src/mcp/tools/check-boundary.ts +0 -382
- package/src/mcp/tools/get-domain-catalog.ts +0 -39
- package/src/mcp/tools/get-symbol-impact.ts +0 -104
- package/src/mcp/tools/locate-symbol.ts +0 -236
- package/src/mcp/tools/register-domain.ts +0 -113
- package/src/mcp/tools/trace-vertical-slice.ts +0 -106
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import type {
|
|
3
|
+
FileConnectionsSummary,
|
|
4
|
+
GetSymbolImpactResponse,
|
|
5
|
+
ImportRelationship,
|
|
6
|
+
SymbolReference,
|
|
7
|
+
} from "../../types/index.ts";
|
|
8
|
+
import { collectImportEvidence, type ImportEvidence, type IndexedDependency } from "./import-evidence.ts";
|
|
9
|
+
import { analyzeSymbolImpact } from "./symbol-impact.ts";
|
|
10
|
+
|
|
11
|
+
function escapeRegExp(str: string): string {
|
|
12
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DependencyQueryStore {
|
|
16
|
+
getWorkspaceRootMeta(): string | undefined;
|
|
17
|
+
getIndexedFilesForEvidence(sourceFile?: string): Array<{ path: string; content_hash: string; domain_id: number }>;
|
|
18
|
+
getDomainsForEvidence(): Array<{ name: string; root_path: string }>;
|
|
19
|
+
hasIndexedFile(path: string): boolean;
|
|
20
|
+
getAllDependenciesWithDomains(sourceFile?: string): Array<IndexedDependency & { resolved_target_file?: string | null }>;
|
|
21
|
+
getDependenciesForFiles(filePaths: string[]): IndexedDependency[];
|
|
22
|
+
getIndexedFilesByPaths(filePaths: string[]): Array<{ path: string; content_hash: string; domain_id: number }>;
|
|
23
|
+
getAllFileSummaries(): Array<{ id: number; domain_id: number; path: string }>;
|
|
24
|
+
getAllInternalDependencyTargets(): Array<{ source_file_id: number; target_symbol_or_path: string }>;
|
|
25
|
+
findImpactMethodCandidates(trimmed: string, container: string, method: string, domain?: string): Array<{
|
|
26
|
+
name: string;
|
|
27
|
+
kind: string;
|
|
28
|
+
signature: string;
|
|
29
|
+
line_start: number;
|
|
30
|
+
line_end: number;
|
|
31
|
+
file_path: string;
|
|
32
|
+
domain_name?: string | null;
|
|
33
|
+
}>;
|
|
34
|
+
findImpactContainerCandidates(trimmed: string, container: string, domain?: string): Array<{
|
|
35
|
+
name: string;
|
|
36
|
+
kind: string;
|
|
37
|
+
line_start: number;
|
|
38
|
+
line_end: number;
|
|
39
|
+
file_path: string;
|
|
40
|
+
domain_name?: string | null;
|
|
41
|
+
}>;
|
|
42
|
+
queryDependenciesForImpact(patterns: {
|
|
43
|
+
container: string;
|
|
44
|
+
trimmed: string;
|
|
45
|
+
stems: string[];
|
|
46
|
+
}): Array<{
|
|
47
|
+
file: string;
|
|
48
|
+
line_number: number;
|
|
49
|
+
target_symbol_or_path: string;
|
|
50
|
+
import_statement: string;
|
|
51
|
+
domain_name?: string | null;
|
|
52
|
+
}>;
|
|
53
|
+
findSameDirectoryPackageFiles(dirs: string[]): Array<{ path: string; domain_name: string | null }>;
|
|
54
|
+
findSymbolsForFiles(filePaths: string[]): Array<{
|
|
55
|
+
name: string;
|
|
56
|
+
kind: string;
|
|
57
|
+
signature: string;
|
|
58
|
+
line_start: number;
|
|
59
|
+
line_end: number;
|
|
60
|
+
path: string;
|
|
61
|
+
}>;
|
|
62
|
+
findFileSymbolNames(cleanPath: string): string[];
|
|
63
|
+
queryDependenciesForFileInbound(cleanPath: string, baseName: string, symbolNames: string[]): Array<{
|
|
64
|
+
file: string;
|
|
65
|
+
target: string;
|
|
66
|
+
stmt: string;
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function buildImportEvidence(
|
|
71
|
+
store: DependencyQueryStore,
|
|
72
|
+
workspaceRoot?: string,
|
|
73
|
+
sourceFile?: string,
|
|
74
|
+
verifyFile?: (file: string) => boolean
|
|
75
|
+
): ImportEvidence {
|
|
76
|
+
const root = workspaceRoot ?? store.getWorkspaceRootMeta();
|
|
77
|
+
if (!root) return { dependencies: [], relationships: [], staleFiles: [] };
|
|
78
|
+
const files = store.getIndexedFilesForEvidence(sourceFile);
|
|
79
|
+
const domains = store.getDomainsForEvidence().sort((a, b) => b.root_path.length - a.root_path.length);
|
|
80
|
+
const dependencies = store.getAllDependenciesWithDomains(sourceFile);
|
|
81
|
+
return collectImportEvidence({
|
|
82
|
+
root,
|
|
83
|
+
files,
|
|
84
|
+
domains,
|
|
85
|
+
dependencies,
|
|
86
|
+
verifyFile,
|
|
87
|
+
hasAdditionalIndexedFile: sourceFile === undefined ? undefined : (file) => store.hasIndexedFile(file),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function buildImportRelationships(
|
|
92
|
+
store: DependencyQueryStore,
|
|
93
|
+
workspaceRoot?: string,
|
|
94
|
+
sourceFile?: string
|
|
95
|
+
): ImportRelationship[] {
|
|
96
|
+
return buildImportEvidence(store, workspaceRoot, sourceFile).relationships;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function buildScopedImportRelationships(
|
|
100
|
+
store: DependencyQueryStore,
|
|
101
|
+
workspaceRoot?: string,
|
|
102
|
+
options: {
|
|
103
|
+
sourceFiles?: ReadonlySet<string>;
|
|
104
|
+
targetCandidateFiles?: ReadonlySet<string>;
|
|
105
|
+
sourceOrTargetPaths?: ReadonlySet<string>;
|
|
106
|
+
} = {}
|
|
107
|
+
): ImportRelationship[] {
|
|
108
|
+
const { sourceFiles, targetCandidateFiles, sourceOrTargetPaths } = options;
|
|
109
|
+
if (!sourceFiles && !targetCandidateFiles && !sourceOrTargetPaths) {
|
|
110
|
+
return buildImportRelationships(store, workspaceRoot);
|
|
111
|
+
}
|
|
112
|
+
const root = workspaceRoot ?? store.getWorkspaceRootMeta();
|
|
113
|
+
if (!root) return [];
|
|
114
|
+
|
|
115
|
+
let dependencies: IndexedDependency[];
|
|
116
|
+
if (sourceOrTargetPaths) {
|
|
117
|
+
const targetTokens = new Set<string>();
|
|
118
|
+
for (const p of sourceOrTargetPaths) {
|
|
119
|
+
const clean = p.replace(/\\/g, "/");
|
|
120
|
+
const parts = clean.split("/");
|
|
121
|
+
const file = parts.pop() ?? "";
|
|
122
|
+
const stem = file.replace(/\.[^.]+$/, "").toLowerCase();
|
|
123
|
+
if (stem.length >= 2) targetTokens.add(stem);
|
|
124
|
+
const parent = (parts.pop() ?? "").toLowerCase();
|
|
125
|
+
if (parent.length >= 2) targetTokens.add(parent);
|
|
126
|
+
}
|
|
127
|
+
const tokenList = Array.from(targetTokens);
|
|
128
|
+
const allDeps = store.getAllDependenciesWithDomains();
|
|
129
|
+
dependencies = allDeps.filter((dep) => {
|
|
130
|
+
if (sourceOrTargetPaths.has(dep.source_file)) return true;
|
|
131
|
+
if (dep.is_external) return false;
|
|
132
|
+
if (dep.resolved_target_file != null) {
|
|
133
|
+
return sourceOrTargetPaths.has(dep.resolved_target_file);
|
|
134
|
+
}
|
|
135
|
+
if (tokenList.length === 0) return false;
|
|
136
|
+
const lowerTarget = dep.target.toLowerCase();
|
|
137
|
+
return tokenList.some((tok) => lowerTarget.includes(tok));
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
const scopedSources = new Set<string>(sourceFiles);
|
|
141
|
+
if (targetCandidateFiles && targetCandidateFiles.size > 0) {
|
|
142
|
+
for (const targetFile of targetCandidateFiles) {
|
|
143
|
+
const cleanPath = targetFile.replace(/\\/g, "/");
|
|
144
|
+
scopedSources.add(cleanPath);
|
|
145
|
+
const parts = cleanPath.split("/");
|
|
146
|
+
const rawBase = parts.pop()?.replace(/\.[^.]+$/, "") || "";
|
|
147
|
+
const parentDir = parts.pop() || "";
|
|
148
|
+
const symbolNames = store.findFileSymbolNames(cleanPath);
|
|
149
|
+
for (const row of store.queryDependenciesForFileInbound(cleanPath, rawBase, symbolNames)) {
|
|
150
|
+
scopedSources.add(row.file);
|
|
151
|
+
}
|
|
152
|
+
if (parentDir.length >= 3 && parentDir !== rawBase) {
|
|
153
|
+
for (const row of store.queryDependenciesForFileInbound(cleanPath, parentDir, [])) {
|
|
154
|
+
scopedSources.add(row.file);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const sourceList = Array.from(scopedSources);
|
|
160
|
+
if (sourceList.length === 0) return [];
|
|
161
|
+
dependencies = store.getDependenciesForFiles(sourceList);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (dependencies.length === 0) return [];
|
|
165
|
+
|
|
166
|
+
const uniqueSources = Array.from(new Set(dependencies.map((d) => d.source_file)));
|
|
167
|
+
const files = store.getIndexedFilesByPaths(uniqueSources);
|
|
168
|
+
const domains = store.getDomainsForEvidence().sort((a, b) => b.root_path.length - a.root_path.length);
|
|
169
|
+
return collectImportEvidence({
|
|
170
|
+
root,
|
|
171
|
+
files,
|
|
172
|
+
domains,
|
|
173
|
+
dependencies,
|
|
174
|
+
hasAdditionalIndexedFile: (file) => store.hasIndexedFile(file),
|
|
175
|
+
}).relationships;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function buildDomainFileConnections(
|
|
179
|
+
store: DependencyQueryStore,
|
|
180
|
+
domainId?: number,
|
|
181
|
+
workspaceRoot?: string
|
|
182
|
+
): Map<string, FileConnectionsSummary> {
|
|
183
|
+
const root = workspaceRoot ?? store.getWorkspaceRootMeta();
|
|
184
|
+
if (root) {
|
|
185
|
+
const files = store.getAllFileSummaries();
|
|
186
|
+
const edges = buildImportRelationships(store, root);
|
|
187
|
+
return new Map(
|
|
188
|
+
files
|
|
189
|
+
.filter((f) => domainId === undefined || f.domain_id === domainId)
|
|
190
|
+
.map((file) => {
|
|
191
|
+
const imports = edges
|
|
192
|
+
.filter((edge) => edge.source.file === file.path && edge.resolution.status === "resolved")
|
|
193
|
+
.flatMap((edge) => edge.resolution.targets.flatMap((target) => target.files));
|
|
194
|
+
const inbound = edges
|
|
195
|
+
.filter(
|
|
196
|
+
(edge) =>
|
|
197
|
+
edge.resolution.status === "resolved" &&
|
|
198
|
+
edge.resolution.targets.some((target) => target.files.includes(file.path))
|
|
199
|
+
)
|
|
200
|
+
.map((edge) => edge.source.file);
|
|
201
|
+
return [
|
|
202
|
+
file.path,
|
|
203
|
+
{
|
|
204
|
+
imports_from: [...new Set(imports)].sort(),
|
|
205
|
+
imported_by: [...new Set(inbound)].sort(),
|
|
206
|
+
imported_by_count: new Set(inbound).size,
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const allFiles = store.getAllFileSummaries();
|
|
214
|
+
const fileById = new Map<number, { id: number; domain_id: number; path: string }>();
|
|
215
|
+
const fileByNormPath = new Map<string, string>();
|
|
216
|
+
const fileByNoExtPath = new Map<string, string>();
|
|
217
|
+
|
|
218
|
+
for (const f of allFiles) {
|
|
219
|
+
const norm = f.path.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
220
|
+
fileById.set(f.id, { ...f, path: norm });
|
|
221
|
+
fileByNormPath.set(norm.toLowerCase(), f.path);
|
|
222
|
+
const noExt = norm.replace(/\.[^/.]+$/, "").toLowerCase();
|
|
223
|
+
fileByNoExtPath.set(noExt, f.path);
|
|
224
|
+
if (noExt.endsWith("/index")) {
|
|
225
|
+
fileByNoExtPath.set(noExt.slice(0, -"/index".length), f.path);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const resolveInternalTarget = (sourcePath: string, rawTarget: string): string | null => {
|
|
230
|
+
const cleaned = rawTarget.trim().replace(/^['"]|['"]$/g, "").replace(/\\/g, "/");
|
|
231
|
+
if (!cleaned) return null;
|
|
232
|
+
|
|
233
|
+
if (cleaned.startsWith(".")) {
|
|
234
|
+
const srcDir = posix.dirname(sourcePath.replace(/\\/g, "/"));
|
|
235
|
+
const joined = posix.normalize(posix.join(srcDir, cleaned)).replace(/^\.\//, "");
|
|
236
|
+
const lowerJoined = joined.toLowerCase();
|
|
237
|
+
const exact = fileByNormPath.get(lowerJoined) ?? fileByNoExtPath.get(lowerJoined.replace(/\.[^/.]+$/, ""));
|
|
238
|
+
if (exact) return exact;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const aliasClean = cleaned.replace(/^@\//, "src/").replace(/^\.\//, "");
|
|
242
|
+
const lowerAlias = aliasClean.toLowerCase();
|
|
243
|
+
const byAlias = fileByNormPath.get(lowerAlias) ?? fileByNoExtPath.get(lowerAlias.replace(/\.[^/.]+$/, ""));
|
|
244
|
+
if (byAlias) return byAlias;
|
|
245
|
+
|
|
246
|
+
for (const [noExt, origPath] of fileByNoExtPath.entries()) {
|
|
247
|
+
if (noExt.endsWith(`/${lowerAlias}`)) {
|
|
248
|
+
return origPath;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const importsFromMap = new Map<string, Set<string>>();
|
|
255
|
+
const importedByMap = new Map<string, Set<string>>();
|
|
256
|
+
for (const f of allFiles) {
|
|
257
|
+
importsFromMap.set(f.path, new Set());
|
|
258
|
+
importedByMap.set(f.path, new Set());
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
for (const dep of store.getAllInternalDependencyTargets()) {
|
|
262
|
+
const srcFile = fileById.get(dep.source_file_id);
|
|
263
|
+
if (!srcFile) continue;
|
|
264
|
+
const resolvedTarget = resolveInternalTarget(srcFile.path, dep.target_symbol_or_path);
|
|
265
|
+
if (resolvedTarget && resolvedTarget !== srcFile.path) {
|
|
266
|
+
importsFromMap.get(srcFile.path)?.add(resolvedTarget);
|
|
267
|
+
if (!importedByMap.has(resolvedTarget)) {
|
|
268
|
+
importedByMap.set(resolvedTarget, new Set());
|
|
269
|
+
}
|
|
270
|
+
importedByMap.get(resolvedTarget)?.add(srcFile.path);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const result = new Map<string, FileConnectionsSummary>();
|
|
275
|
+
for (const f of allFiles) {
|
|
276
|
+
if (domainId !== undefined && f.domain_id !== domainId) continue;
|
|
277
|
+
const importsFrom = Array.from(importsFromMap.get(f.path) ?? []).sort();
|
|
278
|
+
const importedBy = Array.from(importedByMap.get(f.path) ?? []).sort();
|
|
279
|
+
result.set(f.path, {
|
|
280
|
+
imports_from: importsFrom,
|
|
281
|
+
imported_by_count: importedBy.length,
|
|
282
|
+
imported_by: importedBy,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export function buildFileConnections(
|
|
290
|
+
store: DependencyQueryStore,
|
|
291
|
+
filePath: string,
|
|
292
|
+
workspaceRoot?: string
|
|
293
|
+
): FileConnectionsSummary {
|
|
294
|
+
const clean = filePath.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
295
|
+
const allConns = buildDomainFileConnections(store, undefined, workspaceRoot);
|
|
296
|
+
return (
|
|
297
|
+
allConns.get(clean) ??
|
|
298
|
+
allConns.get(filePath) ?? {
|
|
299
|
+
imports_from: [],
|
|
300
|
+
imported_by_count: 0,
|
|
301
|
+
imported_by: [],
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function buildSymbolImpact(
|
|
307
|
+
store: DependencyQueryStore,
|
|
308
|
+
symbolQuery: string,
|
|
309
|
+
options: { domain?: string; workspaceRoot?: string; filePath?: string; reference?: SymbolReference } = {}
|
|
310
|
+
): GetSymbolImpactResponse {
|
|
311
|
+
const trimmed = symbolQuery.trim();
|
|
312
|
+
if (!trimmed) {
|
|
313
|
+
return {
|
|
314
|
+
target_symbol: symbolQuery,
|
|
315
|
+
found_in_index: false,
|
|
316
|
+
warning: "Empty symbol query provided.",
|
|
317
|
+
impact_summary: {
|
|
318
|
+
total_dependents: 0,
|
|
319
|
+
risk_level: "unknown",
|
|
320
|
+
affected_files_count: 0,
|
|
321
|
+
},
|
|
322
|
+
inbound_callers: [],
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
let targetContainer = trimmed;
|
|
327
|
+
let targetMethod = "";
|
|
328
|
+
if (trimmed.includes("::")) {
|
|
329
|
+
const parts = trimmed.split("::");
|
|
330
|
+
targetContainer = parts[0];
|
|
331
|
+
targetMethod = parts[1];
|
|
332
|
+
} else if (trimmed.includes("@")) {
|
|
333
|
+
const parts = trimmed.split("@");
|
|
334
|
+
targetContainer = parts[0];
|
|
335
|
+
targetMethod = parts[1];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
let targetSymRows: Array<{
|
|
339
|
+
name: string;
|
|
340
|
+
kind: string;
|
|
341
|
+
line_start: number;
|
|
342
|
+
line_end: number;
|
|
343
|
+
file_path: string;
|
|
344
|
+
domain_name?: string | null;
|
|
345
|
+
}>;
|
|
346
|
+
|
|
347
|
+
if (targetMethod) {
|
|
348
|
+
targetSymRows = store
|
|
349
|
+
.findImpactMethodCandidates(trimmed, targetContainer, targetMethod, options.domain)
|
|
350
|
+
.filter((row) => {
|
|
351
|
+
if (row.name !== targetMethod) return true;
|
|
352
|
+
const receiver = row.signature.match(/^func\s*\(\s*(?:[A-Za-z_]\w*\s+)?\*?([A-Za-z_]\w*)(?:\[[^\]]+\])?\s*\)/);
|
|
353
|
+
return receiver?.[1] === targetContainer;
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
if (targetSymRows.length === 0) {
|
|
357
|
+
return {
|
|
358
|
+
target_symbol: trimmed,
|
|
359
|
+
found_in_index: false,
|
|
360
|
+
warning: `Symbol '${trimmed}' was not found in Septum index${options.domain ? ` for domain '${options.domain}'` : ""}. Method does not exist.`,
|
|
361
|
+
impact_summary: {
|
|
362
|
+
total_dependents: 0,
|
|
363
|
+
risk_level: "unknown",
|
|
364
|
+
affected_files_count: 0,
|
|
365
|
+
},
|
|
366
|
+
inbound_callers: [],
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
} else {
|
|
370
|
+
targetSymRows = store.findImpactContainerCandidates(trimmed, targetContainer, options.domain);
|
|
371
|
+
if (targetSymRows.length === 0) {
|
|
372
|
+
return {
|
|
373
|
+
target_symbol: trimmed,
|
|
374
|
+
found_in_index: false,
|
|
375
|
+
warning: `Symbol '${trimmed}' was not found in Septum index${options.domain ? ` for domain '${options.domain}'` : ""}.`,
|
|
376
|
+
impact_summary: {
|
|
377
|
+
total_dependents: 0,
|
|
378
|
+
risk_level: "unknown",
|
|
379
|
+
affected_files_count: 0,
|
|
380
|
+
},
|
|
381
|
+
inbound_callers: [],
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const targetFilePath = (options.filePath ?? options.reference?.file_path)?.replace(/\\/g, "/");
|
|
387
|
+
if (targetFilePath) {
|
|
388
|
+
targetSymRows = targetSymRows.filter((r) => r.file_path.replace(/\\/g, "/") === targetFilePath);
|
|
389
|
+
if (targetSymRows.length === 0) {
|
|
390
|
+
return {
|
|
391
|
+
target_symbol: trimmed,
|
|
392
|
+
found_in_index: false,
|
|
393
|
+
warning: `Symbol '${trimmed}' was not found in Septum index for file '${targetFilePath}'${options.domain ? ` in domain '${options.domain}'` : ""}.`,
|
|
394
|
+
impact_summary: {
|
|
395
|
+
total_dependents: 0,
|
|
396
|
+
risk_level: "unknown",
|
|
397
|
+
affected_files_count: 0,
|
|
398
|
+
},
|
|
399
|
+
inbound_callers: [],
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const definingFiles = new Set<string>(targetSymRows.map((r) => r.file_path.replace(/\\/g, "/")));
|
|
405
|
+
const domainByFile = new Map<string, string>();
|
|
406
|
+
for (const row of targetSymRows) {
|
|
407
|
+
if (row.domain_name) domainByFile.set(row.file_path.replace(/\\/g, "/"), row.domain_name);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const definingFileStems = Array.from(
|
|
411
|
+
new Set(
|
|
412
|
+
Array.from(definingFiles)
|
|
413
|
+
.map((p) => p.split("/").pop()?.replace(/\.[^.]+$/, "") || "")
|
|
414
|
+
.filter((s) => s.length >= 2)
|
|
415
|
+
)
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
const rawDepRows = store.queryDependenciesForImpact({
|
|
419
|
+
container: targetContainer,
|
|
420
|
+
trimmed,
|
|
421
|
+
stems: definingFileStems,
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
const isTargetedFile = Boolean(targetFilePath);
|
|
425
|
+
const matchesDefiningFile = (df: string, stmt: string, target: string): boolean => {
|
|
426
|
+
const normStmt = stmt.replace(/\\/g, "/");
|
|
427
|
+
const normTarget = target.replace(/\\/g, "/");
|
|
428
|
+
const clean = df.replace(/\.[^.]+$/, "");
|
|
429
|
+
const parts = clean.split("/");
|
|
430
|
+
const suffixes: string[] = [];
|
|
431
|
+
for (let i = 0; i < parts.length; i++) {
|
|
432
|
+
suffixes.push(parts.slice(i).join("/"));
|
|
433
|
+
}
|
|
434
|
+
if (suffixes.some((s) => {
|
|
435
|
+
const escaped = escapeRegExp(s);
|
|
436
|
+
const r = new RegExp(`(?:^|[\\\\/\"\x27.@:])(?:${escaped})(?:$|[\\\\/\"\x27;:.()\\s]|\\.[^\\\\/]+)`, "i");
|
|
437
|
+
return r.test(normStmt) || r.test(normTarget);
|
|
438
|
+
})) {
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
// Support barrel imports (e.g. `@/lib/api/links` -> `.../links/get-links-for-workspace.ts`)
|
|
442
|
+
// only when the target specifier itself ends at the barrel directory or its `/index`.
|
|
443
|
+
if (parts.length > 1) {
|
|
444
|
+
const dirClean = parts.slice(0, -1).join("/");
|
|
445
|
+
const dirParts = dirClean.split("/");
|
|
446
|
+
for (let i = 0; i < dirParts.length; i++) {
|
|
447
|
+
const dirSuffix = escapeRegExp(dirParts.slice(i).join("/"));
|
|
448
|
+
const barrelRe = new RegExp(`(?:^|[\\\\/]|@/)(?:${dirSuffix})(?:/index(?:\\.[^\\\\/]+)?)?$`, "i");
|
|
449
|
+
if (barrelRe.test(normTarget)) return true;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return false;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const targetContainerShort = targetContainer.split(/[\\/]/).pop() ?? targetContainer;
|
|
456
|
+
const containerWordRegex = targetContainerShort !== targetContainer
|
|
457
|
+
? new RegExp(`\\b(?:${escapeRegExp(targetContainer)}|${escapeRegExp(targetContainerShort)})\\b`)
|
|
458
|
+
: new RegExp(`\\b${escapeRegExp(targetContainer)}\\b`);
|
|
459
|
+
const depRows = rawDepRows.filter((row) => {
|
|
460
|
+
const normCallerFile = String(row.file).replace(/\\/g, "/");
|
|
461
|
+
if (row.domain_name) domainByFile.set(normCallerFile, String(row.domain_name));
|
|
462
|
+
if (definingFiles.has(normCallerFile)) return false;
|
|
463
|
+
|
|
464
|
+
const stmt = String(row.import_statement || "");
|
|
465
|
+
const target = String(row.target_symbol_or_path || "");
|
|
466
|
+
|
|
467
|
+
if (containerWordRegex.test(stmt) || containerWordRegex.test(target)) {
|
|
468
|
+
if (isTargetedFile) {
|
|
469
|
+
const matchesDefining = Array.from(definingFiles).some((df) => matchesDefiningFile(df, stmt, target));
|
|
470
|
+
if (!matchesDefining) return false;
|
|
471
|
+
}
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (!stmt.includes("{")) {
|
|
476
|
+
for (const stem of definingFileStems) {
|
|
477
|
+
const stemRegex = new RegExp(`(?:^|[\\\\/])${escapeRegExp(stem)}(?:\\.[^\\\\/]+)?$`);
|
|
478
|
+
if (stemRegex.test(target)) return true;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return false;
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
const implicitPackageFiles = new Set<string>();
|
|
486
|
+
const implicitLangDirs = new Set<string>();
|
|
487
|
+
for (const df of definingFiles) {
|
|
488
|
+
if (/\.(go|php|java|cs)$/i.test(df)) {
|
|
489
|
+
const dir = posix.dirname(df);
|
|
490
|
+
implicitLangDirs.add(dir === "." ? "" : dir);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
if (implicitLangDirs.size > 0) {
|
|
494
|
+
for (const r of store.findSameDirectoryPackageFiles(Array.from(implicitLangDirs))) {
|
|
495
|
+
const norm = r.path.replace(/\\/g, "/");
|
|
496
|
+
if (r.domain_name) domainByFile.set(norm, r.domain_name);
|
|
497
|
+
if (!definingFiles.has(norm) && /\.(go|php|java|cs)$/i.test(norm)) {
|
|
498
|
+
implicitPackageFiles.add(norm);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const uniqueCallerFiles = Array.from(new Set(depRows.map((r) => String(r.file))));
|
|
504
|
+
const allSymbolLookupFiles = Array.from(
|
|
505
|
+
new Set([...uniqueCallerFiles, ...definingFiles, ...implicitPackageFiles])
|
|
506
|
+
);
|
|
507
|
+
const callerSymbolsByFile = new Map<
|
|
508
|
+
string,
|
|
509
|
+
Array<{ name: string; kind: string; signature: string; line_start: number; line_end: number }>
|
|
510
|
+
>();
|
|
511
|
+
|
|
512
|
+
if (allSymbolLookupFiles.length > 0) {
|
|
513
|
+
for (const sym of store.findSymbolsForFiles(allSymbolLookupFiles)) {
|
|
514
|
+
const list = callerSymbolsByFile.get(sym.path) || [];
|
|
515
|
+
list.push(sym);
|
|
516
|
+
callerSymbolsByFile.set(sym.path, list);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return analyzeSymbolImpact({
|
|
521
|
+
query: trimmed,
|
|
522
|
+
container: targetContainer,
|
|
523
|
+
method: targetMethod,
|
|
524
|
+
targets: targetSymRows,
|
|
525
|
+
dependencies: depRows,
|
|
526
|
+
samePackageFiles: implicitPackageFiles,
|
|
527
|
+
symbolsByFile: callerSymbolsByFile,
|
|
528
|
+
domainsByFile: domainByFile,
|
|
529
|
+
workspaceRoot: options.workspaceRoot,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export function buildFileInboundImpact(
|
|
534
|
+
store: DependencyQueryStore,
|
|
535
|
+
filePath: string,
|
|
536
|
+
precomputedRelationships?: ImportRelationship[]
|
|
537
|
+
): {
|
|
538
|
+
direct_dependents_count: number;
|
|
539
|
+
top_consumers: string[];
|
|
540
|
+
symbols_count: number;
|
|
541
|
+
risk_level: "low" | "medium" | "high";
|
|
542
|
+
} {
|
|
543
|
+
const cleanPath = filePath.replace(/\\/g, "/");
|
|
544
|
+
const baseName = cleanPath.split("/").pop()?.replace(/\.[^.]+$/, "") || "";
|
|
545
|
+
const symbols = store.findFileSymbolNames(cleanPath);
|
|
546
|
+
|
|
547
|
+
const matchedFiles = new Set<string>();
|
|
548
|
+
const relationships = precomputedRelationships ?? buildScopedImportRelationships(store, undefined, {
|
|
549
|
+
targetCandidateFiles: new Set([cleanPath]),
|
|
550
|
+
});
|
|
551
|
+
if (relationships.length > 0) {
|
|
552
|
+
for (const edge of relationships) {
|
|
553
|
+
if (edge.freshness !== "current" || edge.resolution.status !== "resolved") continue;
|
|
554
|
+
if (edge.source.file === cleanPath) continue;
|
|
555
|
+
if (edge.resolution.targets.some((t) => t.files.includes(cleanPath))) {
|
|
556
|
+
matchedFiles.add(edge.source.file);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
} else {
|
|
560
|
+
const depRows = store.queryDependenciesForFileInbound(cleanPath, baseName, symbols);
|
|
561
|
+
const baseBoundary =
|
|
562
|
+
baseName.length >= 3
|
|
563
|
+
? new RegExp(`(?:^|[\\/\\\\.])${escapeRegExp(baseName)}(?:\\.[^.\\/\\\\]+)?$`, "i")
|
|
564
|
+
: null;
|
|
565
|
+
const symNames = symbols
|
|
566
|
+
.slice(0, 8)
|
|
567
|
+
.map((s) => s.split("::").pop() || s)
|
|
568
|
+
.filter((n) => n.length >= 4)
|
|
569
|
+
.map((n) => new RegExp(`\\b${escapeRegExp(n)}\\b`));
|
|
570
|
+
|
|
571
|
+
for (const row of depRows) {
|
|
572
|
+
const targetMatches =
|
|
573
|
+
row.target.includes(cleanPath) ||
|
|
574
|
+
(baseBoundary !== null && baseBoundary.test(row.target)) ||
|
|
575
|
+
symNames.some((re) => re.test(row.target) || re.test(row.stmt));
|
|
576
|
+
if (targetMatches) {
|
|
577
|
+
matchedFiles.add(row.file);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
const consumerList = Array.from(matchedFiles);
|
|
583
|
+
let riskLevel: "low" | "medium" | "high" = "low";
|
|
584
|
+
if (consumerList.length >= 5) riskLevel = "high";
|
|
585
|
+
else if (consumerList.length >= 2) riskLevel = "medium";
|
|
586
|
+
|
|
587
|
+
return {
|
|
588
|
+
direct_dependents_count: consumerList.length,
|
|
589
|
+
top_consumers: consumerList.slice(0, 5),
|
|
590
|
+
symbols_count: symbols.length,
|
|
591
|
+
risk_level: riskLevel,
|
|
592
|
+
};
|
|
593
|
+
}
|