@dimassetoid/septum-mcp 0.2.1 → 0.5.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 +46 -45
- package/package.json +8 -6
- package/src/cli/commands/check.ts +41 -26
- package/src/cli/commands/hook.ts +77 -105
- package/src/cli/commands/init.ts +35 -9
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +35 -9
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +15 -51
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +51 -27
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +46 -35
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +299 -178
- package/src/core/boundary/staged-auditor.ts +188 -34
- package/src/core/config/domain-ownership.ts +47 -0
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +82 -54
- package/src/core/config/schema.ts +24 -46
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +326 -543
- package/src/core/database/repositories/domain.repository.ts +48 -4
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -259
- package/src/core/database/repository.ts +138 -24
- package/src/core/database/schema.ts +28 -33
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +269 -0
- package/src/core/discovery/topology-detector.ts +153 -170
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +378 -212
- package/src/core/parser/behavioral-analyzer.ts +26 -22
- package/src/core/parser/boundary-tracker.ts +15 -0
- package/src/core/parser/extractors/base.ts +16 -4
- package/src/core/parser/extractors/csharp.ts +9 -5
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +400 -516
- package/src/core/parser/extractors/elysia-semantic.ts +172 -496
- package/src/core/parser/extractors/express-semantic.ts +195 -398
- package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
- package/src/core/parser/extractors/fastify-semantic.ts +216 -732
- package/src/core/parser/extractors/flask-semantic.ts +92 -388
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +210 -508
- 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 -530
- package/src/core/parser/extractors/java.ts +7 -5
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +169 -333
- 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 +84 -336
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
- 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 +17 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +9 -8
- package/src/core/parser/extractors/registry.ts +28 -5
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +10 -7
- package/src/core/parser/extractors/rust.ts +35 -17
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +75 -262
- 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 +36 -216
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +23 -7
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
- package/src/core/parser/schema/schema-provider-registry.ts +1 -3
- package/src/core/parser/schema/schema-provider.interface.ts +2 -1
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- 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 +375 -311
- 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 +162 -181
- package/src/core/resolver/interpretation-inputs.ts +65 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +133 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +74 -0
- package/src/core/resolver/module-resolver.ts +18 -7
- 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 +94 -0
- package/src/core/resolver/slice-format.ts +22 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +477 -0
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +57 -278
- package/src/core/resources/ignore.ts +21 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +116 -0
- package/src/core/retrieval/context.ts +457 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/source-context.ts +448 -0
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +293 -0
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +225 -37
- package/src/index.ts +0 -3
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +253 -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 -1105
- package/src/mcp/server.ts +263 -597
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +69 -4
- package/src/mcp/tools/map.ts +126 -0
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +480 -26
- 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 +102 -18
- package/src/mcp/workspace-watcher.ts +38 -19
- package/src/types/index.ts +47 -53
- package/src/cli/commands/topology.ts +0 -161
- package/src/core/database/repositories/environment.repository.ts +0 -207
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
- package/src/core/session/session-manager.ts +0 -107
- package/src/core/topology/environment-detector.ts +0 -973
- package/src/core/topology/types.ts +0 -83
- package/src/mcp/tools/check-boundary.ts +0 -387
- package/src/mcp/tools/domain.ts +0 -40
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-domain-catalog.ts +0 -226
- package/src/mcp/tools/get-environment-topology.ts +0 -138
- package/src/mcp/tools/get-feature-context.ts +0 -224
- package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
- package/src/mcp/tools/get-symbol-impact.ts +0 -64
- package/src/mcp/tools/get-symbol.ts +0 -175
- package/src/mcp/tools/locate-symbol.ts +0 -196
- package/src/mcp/tools/register-domain.ts +0 -75
- package/src/mcp/tools/register-feature.ts +0 -110
- package/src/mcp/tools/trace-vertical-slice.ts +0 -80
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { discoverDeclarativeRoutesFromFiles, type DiscoveredRoute } from "../discovery/declarative-routes.ts";
|
|
2
2
|
import { readOptionalSourceFile } from "../resources/source-files.ts";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { ImportCandidateResolver } from "./import-candidates.ts";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { relative, resolve } from "node:path";
|
|
5
6
|
import type {
|
|
6
7
|
ExecutionChainNode,
|
|
7
8
|
FileRecord,
|
|
@@ -9,20 +10,13 @@ import type {
|
|
|
9
10
|
VerticalSliceRecord,
|
|
10
11
|
} from "../../types/index.ts";
|
|
11
12
|
import type { SeptumRepository } from "../database/repository.ts";
|
|
13
|
+
import { detectPipelineStage, extractImportedSymbolNames as extractImportedNames } from "./call-graph-helpers.ts";
|
|
14
|
+
import { traverseAstMethodGraph } from "./ast-method-tracer.ts";
|
|
15
|
+
import { traversePolyglotMethodDependencies } from "./polyglot-slice-tracer.ts";
|
|
12
16
|
|
|
13
|
-
export
|
|
14
|
-
method: string;
|
|
15
|
-
uri: string;
|
|
16
|
-
file: string;
|
|
17
|
-
line: number;
|
|
18
|
-
middlewareSymbols: string[];
|
|
19
|
-
handlerSymbol?: string;
|
|
20
|
-
handlerClass?: string;
|
|
21
|
-
handlerMethod?: string;
|
|
22
|
-
}
|
|
17
|
+
export type { DiscoveredRoute };
|
|
23
18
|
|
|
24
19
|
export class CallGraphTracer {
|
|
25
|
-
private importEvidence?: ReturnType<SeptumRepository["getImportRelationships"]>;
|
|
26
20
|
private fileMapByNormPath: Map<string, FileRecord> = new Map();
|
|
27
21
|
private fileMapById: Map<number, FileRecord> = new Map();
|
|
28
22
|
private symbolsByFileId: Map<number, SymbolRecord[]> = new Map();
|
|
@@ -31,15 +25,41 @@ export class CallGraphTracer {
|
|
|
31
25
|
Array<{ target: string; statement: string; line_number: number; is_external: boolean }>
|
|
32
26
|
> = new Map();
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
private readonly importCandidates: ImportCandidateResolver;
|
|
29
|
+
|
|
30
|
+
constructor(private repo: SeptumRepository, private projectRoot: string = process.cwd()) {
|
|
31
|
+
this.importCandidates = new ImportCandidateResolver(repo, projectRoot, this.fileMapByNormPath, path => this.fileForPath(path));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private fileForPath(path: string): FileRecord | undefined {
|
|
35
|
+
const key = this.normalizeFilePath(path);
|
|
36
|
+
const cached = this.fileMapByNormPath.get(key);
|
|
37
|
+
if (cached) return cached;
|
|
38
|
+
const file = this.repo.getFileByPath(path.replace(/\\/g, "/").replace(/^\.\//, ""));
|
|
39
|
+
if (!file) return undefined;
|
|
40
|
+
this.fileMapByNormPath.set(key, file);
|
|
41
|
+
this.fileMapById.set(file.id, file);
|
|
42
|
+
return file;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private fileSymbols(fileId: number): SymbolRecord[] {
|
|
46
|
+
if (!this.symbolsByFileId.has(fileId)) this.symbolsByFileId.set(fileId, this.repo.getSymbolsByFileId(fileId));
|
|
47
|
+
return this.symbolsByFileId.get(fileId)!;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private fileDependencies(fileId: number) {
|
|
51
|
+
if (!this.dependenciesByFileId.has(fileId)) this.dependenciesByFileId.set(fileId, this.repo.getDependenciesByFileId(fileId));
|
|
52
|
+
return this.dependenciesByFileId.get(fileId)!;
|
|
53
|
+
}
|
|
35
54
|
|
|
36
55
|
/**
|
|
37
|
-
* Initializes
|
|
56
|
+
* Initializes file lookup maps from SQLite repository data.
|
|
57
|
+
* Symbols and dependencies are loaded lazily per file on demand to keep memory bounded on large repos.
|
|
38
58
|
*/
|
|
39
59
|
public initMaps(): void {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.
|
|
60
|
+
this.fileMapByNormPath.clear(); this.fileMapById.clear();
|
|
61
|
+
this.symbolsByFileId.clear(); this.dependenciesByFileId.clear();
|
|
62
|
+
this.importCandidates.reset();
|
|
43
63
|
|
|
44
64
|
// Map files
|
|
45
65
|
const allFiles = this.repo.getAllFiles();
|
|
@@ -48,182 +68,106 @@ export class CallGraphTracer {
|
|
|
48
68
|
this.fileMapByNormPath.set(norm, f);
|
|
49
69
|
this.fileMapById.set(f.id, f);
|
|
50
70
|
}
|
|
51
|
-
|
|
52
|
-
// Map symbols
|
|
53
|
-
for (const s of allSymbolsWithFiles) {
|
|
54
|
-
const existing = this.symbolsByFileId.get(s.file_id) || [];
|
|
55
|
-
existing.push(s);
|
|
56
|
-
this.symbolsByFileId.set(s.file_id, existing);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Map dependencies
|
|
60
|
-
for (const d of allDeps) {
|
|
61
|
-
const file = this.fileMapByNormPath.get(this.normalizeFilePath(d.source_file));
|
|
62
|
-
if (file) {
|
|
63
|
-
const existing = this.dependenciesByFileId.get(file.id) || [];
|
|
64
|
-
existing.push({
|
|
65
|
-
target: d.target,
|
|
66
|
-
statement: d.statement,
|
|
67
|
-
line_number: d.line_number,
|
|
68
|
-
is_external: d.is_external,
|
|
69
|
-
});
|
|
70
|
-
this.dependenciesByFileId.set(file.id, existing);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
public discoverDeclarativeRoutes(): DiscoveredRoute[] {
|
|
79
|
-
const discovered: DiscoveredRoute[] = [];
|
|
80
|
-
|
|
81
|
-
for (const [normPath, file] of this.fileMapByNormPath.entries()) {
|
|
82
|
-
const isRouteFile =
|
|
83
|
-
file.archetype === "route" ||
|
|
84
|
-
/routes?|router|endpoints?/i.test(normPath) ||
|
|
85
|
-
/\.(routes?|router)\.[tj]sx?$/i.test(normPath);
|
|
86
|
-
|
|
87
|
-
if (!isRouteFile) continue;
|
|
88
|
-
|
|
89
|
-
const fullPath = resolve(this.projectRoot, file.path);
|
|
90
|
-
if (!existsSync(fullPath)) continue;
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
const content = readOptionalSourceFile(fullPath, "utf-8");
|
|
94
|
-
const lines = content.split("\n");
|
|
95
|
-
|
|
96
|
-
for (let i = 0; i < lines.length; i++) {
|
|
97
|
-
const line = lines[i];
|
|
98
|
-
// Pattern: router.post('/api/orders', validateMiddleware, controller.action)
|
|
99
|
-
// or app.get('/orders', handler)
|
|
100
|
-
const match = line.match(
|
|
101
|
-
/(?:router|app|server|api)\.(get|post|put|patch|delete|options|head)\s*\(\s*['"`]([^'"`]+)['"`]\s*,\s*(.+)\)/i
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
if (match) {
|
|
105
|
-
const method = match[1].toUpperCase();
|
|
106
|
-
const uri = match[2];
|
|
107
|
-
const rawArgs = match[3];
|
|
108
|
-
|
|
109
|
-
const argTokens = rawArgs
|
|
110
|
-
.split(",")
|
|
111
|
-
.map((t) => t.trim())
|
|
112
|
-
.filter((t) => t.length > 0 && !t.startsWith("//"));
|
|
113
|
-
|
|
114
|
-
const middlewareSymbols: string[] = [];
|
|
115
|
-
let handlerSymbol: string | undefined;
|
|
116
|
-
let handlerClass: string | undefined;
|
|
117
|
-
let handlerMethod: string | undefined;
|
|
118
|
-
|
|
119
|
-
if (argTokens.length === 1) {
|
|
120
|
-
handlerSymbol = argTokens[0];
|
|
121
|
-
} else if (argTokens.length > 1) {
|
|
122
|
-
handlerSymbol = argTokens[argTokens.length - 1];
|
|
123
|
-
middlewareSymbols.push(...argTokens.slice(0, argTokens.length - 1));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (handlerSymbol) {
|
|
127
|
-
// Extract Class.method or classInstance.method
|
|
128
|
-
const parts = handlerSymbol.split(".");
|
|
129
|
-
if (parts.length === 2) {
|
|
130
|
-
handlerClass = parts[0];
|
|
131
|
-
handlerMethod = parts[1];
|
|
132
|
-
} else if (handlerSymbol.includes("::")) {
|
|
133
|
-
const colParts = handlerSymbol.split("::");
|
|
134
|
-
handlerClass = colParts[0];
|
|
135
|
-
handlerMethod = colParts[1];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
discovered.push({
|
|
140
|
-
method,
|
|
141
|
-
uri,
|
|
142
|
-
file: file.path,
|
|
143
|
-
line: i + 1,
|
|
144
|
-
middlewareSymbols,
|
|
145
|
-
handlerSymbol,
|
|
146
|
-
handlerClass,
|
|
147
|
-
handlerMethod,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
} catch (err: unknown) {
|
|
152
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
153
|
-
console.error(`[Septum CallGraph Warning] Route discovery failed for ${file.path}: ${msg}`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return discovered;
|
|
73
|
+
/** Legacy route modules sometimes receive their router as an ambient global. */
|
|
74
|
+
public discoverDeclarativeRoutes(excluded?: ReadonlySet<string>): DiscoveredRoute[] {
|
|
75
|
+
return discoverDeclarativeRoutesFromFiles(this.projectRoot, this.fileMapByNormPath, excluded);
|
|
158
76
|
}
|
|
159
77
|
|
|
160
|
-
|
|
161
|
-
* Build execution chains for all discovered entrypoints and controller actions.
|
|
162
|
-
*/
|
|
163
|
-
public traceAllSlices(maxDepth: number = 5): Array<Omit<VerticalSliceRecord, "id" | "created_at">> {
|
|
78
|
+
public traceAllSlices(maxDepth = 5, options: { includeInferredControllers?: boolean; excludeEntrypointFiles?: ReadonlySet<string> } = {}): Array<Omit<VerticalSliceRecord, "id" | "created_at">> {
|
|
164
79
|
const effectiveMaxDepth = Math.min(Math.max(Math.trunc(maxDepth || 5), 1), 8);
|
|
165
80
|
this.initMaps();
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
// 1. Trace from declarative routes
|
|
170
|
-
for (const route of declarativeRoutes) {
|
|
81
|
+
const coveredFiles = options.excludeEntrypointFiles;
|
|
82
|
+
const slices = this.discoverDeclarativeRoutes(coveredFiles).map(route => {
|
|
171
83
|
const chain = this.traceChainFromRoute(route, effectiveMaxDepth);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
slices.push(sliceRecord);
|
|
180
|
-
}
|
|
84
|
+
chain[0].relationship = { kind: "route_binding", derivation: "inferred", reason: "ambient_router_convention" };
|
|
85
|
+
return this.buildSliceRecordFromChain(route.method, route.uri, chain, "clean");
|
|
86
|
+
});
|
|
87
|
+
if (options.includeInferredControllers === false) return slices;
|
|
88
|
+
const coveredActions = new Set<string>();
|
|
89
|
+
for (const s of slices) {
|
|
90
|
+
if (s.controller_file) coveredActions.add(`${s.controller_file}\0${s.action_name.toLowerCase()}`);
|
|
181
91
|
}
|
|
182
|
-
|
|
183
92
|
// 2. Trace controllers if routes were not explicitly bound or found
|
|
184
93
|
for (const [normPath, file] of this.fileMapByNormPath.entries()) {
|
|
94
|
+
// Python web frameworks manage routing declaratively via URLconf (Django) or decorators (FastAPI/Flask).
|
|
95
|
+
// Do not synthesize speculative HTTP endpoints on Python view/handler files by convention.
|
|
96
|
+
if (normPath.endsWith(".py")) continue;
|
|
97
|
+
|
|
185
98
|
const isController =
|
|
186
99
|
file.archetype === "controller" ||
|
|
187
100
|
/controller/i.test(normPath) ||
|
|
188
101
|
normPath.endsWith("Controller.ts") ||
|
|
189
102
|
normPath.endsWith("Controller.js");
|
|
190
103
|
|
|
191
|
-
if (!isController) continue;
|
|
104
|
+
if (!isController || coveredFiles?.has(file.path)) continue;
|
|
192
105
|
|
|
193
|
-
const symbols = this.
|
|
106
|
+
const symbols = this.fileSymbols(file.id);
|
|
194
107
|
const methods = symbols.filter((s) => s.kind === "method" || s.kind === "function");
|
|
108
|
+
if (methods.length === 0) continue;
|
|
109
|
+
|
|
110
|
+
const defaultCtrlName =
|
|
111
|
+
symbols.find((s) => s.kind === "class")?.name ||
|
|
112
|
+
file.path.split("/").pop()?.replace(/\.[^.]+$/, "") ||
|
|
113
|
+
"Controller";
|
|
114
|
+
|
|
115
|
+
// Outbound dependencies depend only on controllerFile, not on individual methods;
|
|
116
|
+
// compute once per controller file instead of repeating BFS per method.
|
|
117
|
+
const outboundChain: ExecutionChainNode[] = [
|
|
118
|
+
{ stage: "ingress", symbol: "", description: "" },
|
|
119
|
+
{ stage: "controller", symbol: "", description: "" },
|
|
120
|
+
];
|
|
121
|
+
this.traverseOutboundDependencies(file, outboundChain, effectiveMaxDepth);
|
|
122
|
+
const outboundTail = outboundChain.slice(2);
|
|
195
123
|
|
|
196
124
|
for (const m of methods) {
|
|
125
|
+
const parts = m.name.split("::");
|
|
126
|
+
const action = parts.pop()!;
|
|
197
127
|
// Skip constructors or private helpers
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
:
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
128
|
+
if (action === "constructor" || action.startsWith("_")) continue;
|
|
129
|
+
|
|
130
|
+
const actionKey = `${file.path}\0${action.toLowerCase()}`;
|
|
131
|
+
if (coveredActions.has(actionKey)) continue;
|
|
132
|
+
|
|
133
|
+
const ctrlName = parts.pop() || defaultCtrlName;
|
|
134
|
+
const defaultMethod = /create|store|save|add/i.test(action)
|
|
135
|
+
? "POST"
|
|
136
|
+
: /update|edit|patch/i.test(action)
|
|
137
|
+
? "PUT"
|
|
138
|
+
: /delete|remove|destroy/i.test(action)
|
|
139
|
+
? "DELETE"
|
|
140
|
+
: "GET";
|
|
141
|
+
const inferredUri = this.inferRouteUri(file.path, action);
|
|
142
|
+
|
|
143
|
+
const chain: ExecutionChainNode[] = [
|
|
144
|
+
{
|
|
145
|
+
stage: "ingress",
|
|
146
|
+
symbol: `${defaultMethod} ${inferredUri}`,
|
|
147
|
+
file: file.path,
|
|
148
|
+
line: m.line_start,
|
|
149
|
+
relationship: { kind: "route_binding", derivation: "inferred", reason: "controller_convention" },
|
|
150
|
+
description: `Inferred Ingress: ${defaultMethod} ${inferredUri}`,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
stage: "controller",
|
|
154
|
+
symbol: `${ctrlName}::${action}`,
|
|
155
|
+
file: file.path,
|
|
156
|
+
line: m.line_start,
|
|
157
|
+
description: `Controller Action: ${ctrlName}::${action}`,
|
|
158
|
+
},
|
|
159
|
+
...outboundTail,
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
coveredActions.add(actionKey);
|
|
163
|
+
slices.push(
|
|
164
|
+
this.buildSliceRecordFromChain(
|
|
220
165
|
defaultMethod,
|
|
221
166
|
inferredUri,
|
|
222
167
|
chain,
|
|
223
168
|
"clean"
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
}
|
|
169
|
+
)
|
|
170
|
+
);
|
|
227
171
|
}
|
|
228
172
|
}
|
|
229
173
|
|
|
@@ -278,7 +222,7 @@ export class CallGraphTracer {
|
|
|
278
222
|
}
|
|
279
223
|
|
|
280
224
|
if (controllerFile) {
|
|
281
|
-
const syms = this.
|
|
225
|
+
const syms = this.fileSymbols(controllerFile.id);
|
|
282
226
|
const methodSym = syms.find(
|
|
283
227
|
(s) => s.name.toLowerCase() === actionMethod.toLowerCase()
|
|
284
228
|
);
|
|
@@ -315,19 +259,21 @@ export class CallGraphTracer {
|
|
|
315
259
|
): ExecutionChainNode[] {
|
|
316
260
|
const effectiveMaxDepth = Math.min(Math.max(Math.trunc(maxDepth || 5), 1), 8);
|
|
317
261
|
const chain: ExecutionChainNode[] = [];
|
|
318
|
-
const syms = this.
|
|
319
|
-
const
|
|
262
|
+
const syms = this.fileSymbols(controllerFile.id);
|
|
263
|
+
const parts = method.name.split("::");
|
|
264
|
+
const action = parts.pop()!;
|
|
265
|
+
const ctrlName = parts.pop() ||
|
|
320
266
|
syms.find((s) => s.kind === "class")?.name ||
|
|
321
267
|
controllerFile.path.split("/").pop()?.replace(/\.[^.]+$/, "") ||
|
|
322
268
|
"Controller";
|
|
323
269
|
|
|
324
270
|
// Stage 1: Ingress (inferred)
|
|
325
|
-
const inferredUri = this.inferRouteUri(controllerFile.path,
|
|
326
|
-
const defaultMethod = /create|store|save|add/i.test(
|
|
271
|
+
const inferredUri = this.inferRouteUri(controllerFile.path, action);
|
|
272
|
+
const defaultMethod = /create|store|save|add/i.test(action)
|
|
327
273
|
? "POST"
|
|
328
|
-
: /update|edit|patch/i.test(
|
|
274
|
+
: /update|edit|patch/i.test(action)
|
|
329
275
|
? "PUT"
|
|
330
|
-
: /delete|remove|destroy/i.test(
|
|
276
|
+
: /delete|remove|destroy/i.test(action)
|
|
331
277
|
? "DELETE"
|
|
332
278
|
: "GET";
|
|
333
279
|
|
|
@@ -336,16 +282,17 @@ export class CallGraphTracer {
|
|
|
336
282
|
symbol: `${defaultMethod} ${inferredUri}`,
|
|
337
283
|
file: controllerFile.path,
|
|
338
284
|
line: method.line_start,
|
|
285
|
+
relationship: { kind: "route_binding", derivation: "inferred", reason: "controller_convention" },
|
|
339
286
|
description: `Inferred Ingress: ${defaultMethod} ${inferredUri}`,
|
|
340
287
|
});
|
|
341
288
|
|
|
342
289
|
// Stage 3: Controller
|
|
343
290
|
chain.push({
|
|
344
291
|
stage: "controller",
|
|
345
|
-
symbol: `${ctrlName}::${
|
|
292
|
+
symbol: `${ctrlName}::${action}`,
|
|
346
293
|
file: controllerFile.path,
|
|
347
294
|
line: method.line_start,
|
|
348
|
-
description: `Controller Action: ${ctrlName}::${
|
|
295
|
+
description: `Controller Action: ${ctrlName}::${action}`,
|
|
349
296
|
});
|
|
350
297
|
|
|
351
298
|
// Forward reachability BFS
|
|
@@ -363,10 +310,7 @@ export class CallGraphTracer {
|
|
|
363
310
|
maxDepth: number = 5
|
|
364
311
|
): ExecutionChainNode[] {
|
|
365
312
|
const effectiveMaxDepth = Math.min(Math.max(Math.trunc(maxDepth || 5), 1), 8);
|
|
366
|
-
|
|
367
|
-
this.initMaps();
|
|
368
|
-
}
|
|
369
|
-
const startFile = this.fileMapByNormPath.get(this.normalizeFilePath(controllerFilePath));
|
|
313
|
+
const startFile = this.fileForPath(controllerFilePath);
|
|
370
314
|
if (!startFile) {
|
|
371
315
|
return existingChain.slice(0, CallGraphTracer.MAX_CHAIN_NODES);
|
|
372
316
|
}
|
|
@@ -376,6 +320,221 @@ export class CallGraphTracer {
|
|
|
376
320
|
return chain;
|
|
377
321
|
}
|
|
378
322
|
|
|
323
|
+
/**
|
|
324
|
+
* AST-scoped Call Tracing: Only expands dependencies referenced inside the specific target method body & signature.
|
|
325
|
+
* Completely filters out unused file-level imports to prevent context bloat and cognitive noise.
|
|
326
|
+
*/
|
|
327
|
+
public expandChainFromMethod(
|
|
328
|
+
controllerFilePath: string,
|
|
329
|
+
actionName: string,
|
|
330
|
+
existingChain: ExecutionChainNode[],
|
|
331
|
+
maxDepth: number = 5
|
|
332
|
+
): ExecutionChainNode[] {
|
|
333
|
+
const effectiveMaxDepth = Math.min(Math.max(Math.trunc(maxDepth || 5), 1), 8);
|
|
334
|
+
const startFile = this.fileForPath(controllerFilePath);
|
|
335
|
+
if (!startFile) {
|
|
336
|
+
return existingChain.slice(0, CallGraphTracer.MAX_CHAIN_NODES);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const symbols = this.fileSymbols(startFile.id);
|
|
340
|
+
const candidates = symbols.filter(
|
|
341
|
+
(s) => (s.kind === "method" || s.kind === "function") && (s.name.endsWith(`::${actionName}`) || s.name.endsWith(`@${actionName}`) || s.name === actionName)
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
const line = existingChain.find(node => node.stage === "controller" && node.file === controllerFilePath)?.line;
|
|
345
|
+
const matches = line ? candidates.filter(s => s.line_start <= line && line <= s.line_end) : [];
|
|
346
|
+
if (candidates.length > 1 && matches.length !== 1) return existingChain;
|
|
347
|
+
const methodSymbol = matches[0] ?? candidates[0];
|
|
348
|
+
if (!methodSymbol) {
|
|
349
|
+
return this.expandChainFromFile(controllerFilePath, existingChain, maxDepth);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const fullPath = resolve(this.projectRoot, startFile.path);
|
|
353
|
+
if (!existsSync(fullPath)) {
|
|
354
|
+
return existingChain.slice(0, CallGraphTracer.MAX_CHAIN_NODES);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
let methodBody = "";
|
|
358
|
+
try {
|
|
359
|
+
const fileContent = readOptionalSourceFile(fullPath, "utf-8");
|
|
360
|
+
const lines = fileContent.split(/\r?\n/);
|
|
361
|
+
const start = Math.max(0, methodSymbol.line_start - 1);
|
|
362
|
+
const end = Math.min(lines.length, methodSymbol.line_end);
|
|
363
|
+
const owner = symbols.find(s => s.kind === "class" && s.line_start <= methodSymbol.line_start && s.line_end >= methodSymbol.line_end);
|
|
364
|
+
const ownerSource = owner ? lines.slice(owner.line_start - 1, owner.line_end).join("\n") : fileContent;
|
|
365
|
+
methodBody = this.scopeWithInjectedTypes(ownerSource, lines.slice(start, end).join("\n"));
|
|
366
|
+
} catch {
|
|
367
|
+
return this.expandChainFromFile(controllerFilePath, existingChain, maxDepth);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const chain = [...existingChain];
|
|
371
|
+
// Method-scoped vertical slices stop at 1-hop direct collaborators (Option A).
|
|
372
|
+
this.traverseMethodScopedDependencies(startFile, methodBody, methodSymbol, chain, 1);
|
|
373
|
+
return chain;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
private extractScopeForCollaborator(
|
|
377
|
+
collaboratorFile: FileRecord,
|
|
378
|
+
callerScopeText: string
|
|
379
|
+
): string {
|
|
380
|
+
const symbols = this.fileSymbols(collaboratorFile.id);
|
|
381
|
+
const methods = symbols.filter((s) => s.kind === "method" || s.kind === "function");
|
|
382
|
+
if (methods.length === 0) return "";
|
|
383
|
+
|
|
384
|
+
// Find methods whose short name is referenced in callerScopeText
|
|
385
|
+
let matchedMethods = methods.filter((m) => {
|
|
386
|
+
const shortName = m.name.split("::").pop() || "";
|
|
387
|
+
return shortName.length > 2 && callerScopeText.includes(shortName);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// If no direct method name match, check for standard action execution methods: execute / handle
|
|
391
|
+
if (matchedMethods.length === 0) {
|
|
392
|
+
if (callerScopeText.includes("execute") || callerScopeText.includes("handle")) {
|
|
393
|
+
matchedMethods = methods.filter((m) => {
|
|
394
|
+
const shortName = m.name.split("::").pop() || "";
|
|
395
|
+
return shortName === "execute" || shortName === "handle";
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (matchedMethods.length === 0) return "";
|
|
401
|
+
|
|
402
|
+
const fullPath = resolve(this.projectRoot, collaboratorFile.path);
|
|
403
|
+
if (!existsSync(fullPath)) return "";
|
|
404
|
+
|
|
405
|
+
try {
|
|
406
|
+
const fileContent = readOptionalSourceFile(fullPath, "utf-8");
|
|
407
|
+
const lines = fileContent.split(/\r?\n/);
|
|
408
|
+
let scope = "";
|
|
409
|
+
for (const m of matchedMethods) {
|
|
410
|
+
const start = Math.max(0, m.line_start - 1);
|
|
411
|
+
const end = Math.min(lines.length, m.line_end);
|
|
412
|
+
scope += (m.signature || "") + "\n" + lines.slice(start, end).join("\n") + "\n";
|
|
413
|
+
}
|
|
414
|
+
return this.scopeWithInjectedTypes(fileContent, scope);
|
|
415
|
+
} catch {
|
|
416
|
+
return "";
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Static hints for explicitly typed properties used by this scope. */
|
|
421
|
+
private scopeWithInjectedTypes(source: string, scope: string): string {
|
|
422
|
+
const types = new Set<string>();
|
|
423
|
+
for (const match of scope.matchAll(/(?:\bthis\.([A-Za-z_]\w*)|\$this->([A-Za-z_]\w*))/g)) {
|
|
424
|
+
const property = match[1] ?? match[2]!;
|
|
425
|
+
const tsType = new RegExp(`\\b${property}\\s*[?!]?\\s*:\\s*([A-Za-z_]\\w*)\\b`, "g");
|
|
426
|
+
const phpType = new RegExp(`\\b(?:public|protected|private)\\s+(?:readonly\\s+)?([\\\\A-Za-z_]\\w*(?:\\\\\\w+)*)\\s+\\$${property}\\b`, "g");
|
|
427
|
+
for (const declaration of source.matchAll(tsType)) types.add(declaration[1]!);
|
|
428
|
+
for (const declaration of source.matchAll(phpType)) types.add(declaration[1]!.split("\\").pop()!);
|
|
429
|
+
}
|
|
430
|
+
return scope + "\n" + [...types].join("\n");
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
private isExecutableSymbol(s: SymbolRecord): boolean {
|
|
434
|
+
if (
|
|
435
|
+
s.kind === "class" ||
|
|
436
|
+
s.kind === "function" ||
|
|
437
|
+
s.kind === "method" ||
|
|
438
|
+
s.kind === "struct" ||
|
|
439
|
+
s.kind === "trait" ||
|
|
440
|
+
s.kind === "component" ||
|
|
441
|
+
s.kind === "view"
|
|
442
|
+
) {
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
if (
|
|
446
|
+
s.kind === "interface" ||
|
|
447
|
+
s.kind === "type" ||
|
|
448
|
+
s.kind === "property" ||
|
|
449
|
+
s.kind === "constant" ||
|
|
450
|
+
s.kind === "enum"
|
|
451
|
+
) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
if (s.kind === "variable") {
|
|
455
|
+
if (/^[A-Z0-9_]{3,}$/.test(s.name)) return false;
|
|
456
|
+
if (/(?:Schema|Config|Options|Settings|Params)$/i.test(s.name)) return false;
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
private resolveExecutableSymbol(
|
|
463
|
+
fileSymbols: SymbolRecord[],
|
|
464
|
+
importedNames: string[]
|
|
465
|
+
): SymbolRecord | undefined {
|
|
466
|
+
if (importedNames.length > 0) {
|
|
467
|
+
const matched = fileSymbols.find((s) => importedNames.includes(s.name) && this.isExecutableSymbol(s));
|
|
468
|
+
if (matched) return matched;
|
|
469
|
+
|
|
470
|
+
// If imported symbols match in this file but none are executable (e.g. types/constants),
|
|
471
|
+
// then this import was solely for non-executable definitions.
|
|
472
|
+
const nonExecutableMatched = fileSymbols.some((s) => importedNames.includes(s.name));
|
|
473
|
+
if (nonExecutableMatched) {
|
|
474
|
+
return undefined;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const executable = fileSymbols.filter((s) => this.isExecutableSymbol(s));
|
|
479
|
+
return (
|
|
480
|
+
executable.find((s) => s.kind === "class" || s.kind === "struct") ||
|
|
481
|
+
executable.find((s) => s.kind === "function" || s.kind === "method") ||
|
|
482
|
+
executable[0]
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
public traverseMethodScopedDependencies(
|
|
487
|
+
startFile: FileRecord,
|
|
488
|
+
methodBody: string,
|
|
489
|
+
methodSymbol: SymbolRecord,
|
|
490
|
+
chain: ExecutionChainNode[],
|
|
491
|
+
maxDepth: number = 5
|
|
492
|
+
): void {
|
|
493
|
+
const effectiveMaxDepth = Math.min(Math.max(Math.trunc(maxDepth || 5), 1), 8);
|
|
494
|
+
const hasWorkspaceRoot = Boolean(this.repo.getMeta?.("workspace_root"));
|
|
495
|
+
if (/\.[cm]?[jt]sx?$/i.test(startFile.path)) {
|
|
496
|
+
traverseAstMethodGraph(
|
|
497
|
+
{
|
|
498
|
+
projectRoot: this.projectRoot,
|
|
499
|
+
maxChainNodes: CallGraphTracer.MAX_CHAIN_NODES,
|
|
500
|
+
hasWorkspaceRoot,
|
|
501
|
+
fileSymbols: (fileId) => this.fileSymbols(fileId),
|
|
502
|
+
fileDependencies: (fileId) => this.fileDependencies(fileId),
|
|
503
|
+
resolveImportTargets: (from, spec) => this.resolveImportTargets(from, spec),
|
|
504
|
+
resolveImportToFile: (from, spec) => this.resolveImportToFile(from, spec),
|
|
505
|
+
resolveExecutableSymbol: (symbols, names) => this.resolveExecutableSymbol(symbols, names),
|
|
506
|
+
isExecutableSymbol: (symbol) => this.isExecutableSymbol(symbol),
|
|
507
|
+
detectStage: (filePath, archetype) => this.detectStage(filePath, archetype),
|
|
508
|
+
},
|
|
509
|
+
startFile,
|
|
510
|
+
methodSymbol,
|
|
511
|
+
chain,
|
|
512
|
+
effectiveMaxDepth
|
|
513
|
+
);
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
traversePolyglotMethodDependencies(
|
|
518
|
+
{
|
|
519
|
+
projectRoot: this.projectRoot,
|
|
520
|
+
maxChainNodes: CallGraphTracer.MAX_CHAIN_NODES,
|
|
521
|
+
hasWorkspaceRoot,
|
|
522
|
+
fileSymbols: (fileId) => this.fileSymbols(fileId),
|
|
523
|
+
fileDependencies: (fileId) => this.fileDependencies(fileId),
|
|
524
|
+
extractImportedSymbolNames: (stmt) => this.extractImportedSymbolNames(stmt),
|
|
525
|
+
resolveImportTargets: (from, target) => this.resolveImportTargets(from, target),
|
|
526
|
+
resolveImportToFile: (from, target) => this.resolveImportToFile(from, target),
|
|
527
|
+
resolveExecutableSymbol: (symbols, names) => this.resolveExecutableSymbol(symbols, names),
|
|
528
|
+
isExecutableSymbol: (symbol) => this.isExecutableSymbol(symbol),
|
|
529
|
+
detectStage: (filePath, archetype) => this.detectStage(filePath, archetype),
|
|
530
|
+
},
|
|
531
|
+
startFile,
|
|
532
|
+
methodBody,
|
|
533
|
+
methodSymbol,
|
|
534
|
+
chain
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
|
|
379
538
|
/**
|
|
380
539
|
* Traverse outbound dependencies using BFS with cycle detection, max hop limit, and node ceiling.
|
|
381
540
|
*/
|
|
@@ -395,9 +554,10 @@ export class CallGraphTracer {
|
|
|
395
554
|
const current = queue.shift()!;
|
|
396
555
|
if (current.depth > effectiveMaxDepth) break;
|
|
397
556
|
|
|
398
|
-
const deps = this.
|
|
557
|
+
const deps = this.fileDependencies(current.file.id);
|
|
399
558
|
|
|
400
559
|
for (const dep of deps) {
|
|
560
|
+
if (/^\s*(?:import|export)\s+type\b/.test(dep.statement)) continue;
|
|
401
561
|
if (chain.length >= CallGraphTracer.MAX_CHAIN_NODES) break;
|
|
402
562
|
const resolvedFiles = this.repo.getMeta?.("workspace_root") ? this.resolveImportTargets(current.file.path, dep.target)
|
|
403
563
|
: dep.is_external ? [] : [this.resolveImportToFile(current.file.path, dep.target)].filter((file): file is FileRecord => !!file);
|
|
@@ -407,15 +567,14 @@ export class CallGraphTracer {
|
|
|
407
567
|
visitedFiles.add(resolvedFile.path);
|
|
408
568
|
|
|
409
569
|
const stage = this.detectStage(resolvedFile.path, resolvedFile.archetype);
|
|
410
|
-
const fileSymbols = this.
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
570
|
+
const fileSymbols = this.fileSymbols(resolvedFile.id);
|
|
571
|
+
const importedNames = this.extractImportedSymbolNames(dep.statement);
|
|
572
|
+
const mainSymbol = this.resolveExecutableSymbol(fileSymbols, importedNames);
|
|
573
|
+
if (!mainSymbol) {
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
415
576
|
|
|
416
|
-
const symbolDisplay = mainSymbol
|
|
417
|
-
? mainSymbol.name
|
|
418
|
-
: resolvedFile.path.split("/").pop()?.replace(/\.[^.]+$/, "") || "Module";
|
|
577
|
+
const symbolDisplay = mainSymbol.name;
|
|
419
578
|
|
|
420
579
|
// Prevent adding duplicate stages if already present, or add as refinement
|
|
421
580
|
const existingStageNode = chain.find(
|
|
@@ -427,7 +586,7 @@ export class CallGraphTracer {
|
|
|
427
586
|
stage,
|
|
428
587
|
symbol: symbolDisplay,
|
|
429
588
|
file: resolvedFile.path,
|
|
430
|
-
line: mainSymbol
|
|
589
|
+
line: mainSymbol.line_start || 1,
|
|
431
590
|
description: `${stage.toUpperCase()} (dependency, not a proven call): ${symbolDisplay}`,
|
|
432
591
|
relationship: { kind: "imports", derivation: "source", source: { file: current.file.path, line: dep.line_number, statement: dep.statement }, reason: "static import; stage classification is inferred" },
|
|
433
592
|
});
|
|
@@ -463,118 +622,23 @@ export class CallGraphTracer {
|
|
|
463
622
|
}
|
|
464
623
|
}
|
|
465
624
|
|
|
625
|
+
private extractImportedSymbolNames(statement: string): string[] {
|
|
626
|
+
return extractImportedNames(statement);
|
|
627
|
+
}
|
|
628
|
+
|
|
466
629
|
/**
|
|
467
630
|
* Detect generic pipeline stage from file path and archetype.
|
|
468
631
|
*/
|
|
469
632
|
public detectStage(filePath: string, archetype: string): string {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
if (
|
|
473
|
-
archetype === "validation" ||
|
|
474
|
-
archetype === "dto" ||
|
|
475
|
-
/validation|middleware|dto|request|schema/i.test(norm)
|
|
476
|
-
) {
|
|
477
|
-
return "validation";
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
if (archetype === "controller" || /controller|handler/i.test(norm)) {
|
|
481
|
-
return "controller";
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (
|
|
485
|
-
archetype === "service" ||
|
|
486
|
-
archetype === "use_case" ||
|
|
487
|
-
/use-?cases?|interactor|application|workflow/i.test(norm)
|
|
488
|
-
) {
|
|
489
|
-
return "use_case";
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
if (
|
|
493
|
-
archetype === "model" ||
|
|
494
|
-
archetype === "entity" ||
|
|
495
|
-
/domain|entities|entity|aggregate/i.test(norm)
|
|
496
|
-
) {
|
|
497
|
-
return "entity";
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
if (
|
|
501
|
-
archetype === "repository" ||
|
|
502
|
-
/repositories|repository|database|persistence|egress|adapter/i.test(norm)
|
|
503
|
-
) {
|
|
504
|
-
return "repository";
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
return "service";
|
|
633
|
+
return detectPipelineStage(filePath, archetype);
|
|
508
634
|
}
|
|
509
635
|
|
|
510
|
-
/**
|
|
511
|
-
* Resolve an import target path (relative or alias) to a FileRecord in the catalog.
|
|
512
|
-
*/
|
|
513
636
|
public resolveImportTargets(sourceFilePath: string, importTarget: string): FileRecord[] {
|
|
514
|
-
|
|
515
|
-
if (evidence && (evidence.freshness !== "current" || evidence.index_coverage !== "complete")) return [];
|
|
516
|
-
const result = evidence?.resolution ?? new ImportResolver(this.projectRoot, this.repo.getAllDomains?.().map(domain => domain.root_path) ?? []).resolve(importTarget,sourceFilePath);
|
|
517
|
-
if (result.status !== "resolved" || result.coverage === "conditional") return [];
|
|
518
|
-
return result.targets.flatMap(target => target.files).flatMap(file => {
|
|
519
|
-
const indexed = this.fileMapByNormPath.get(this.normalizeFilePath(file));
|
|
520
|
-
return indexed ? [indexed] : [];
|
|
521
|
-
});
|
|
637
|
+
return this.importCandidates.resolveImportTargets(sourceFilePath, importTarget);
|
|
522
638
|
}
|
|
523
639
|
|
|
524
640
|
public resolveImportToFile(sourceFilePath: string, importTarget: string): FileRecord | undefined {
|
|
525
|
-
|
|
526
|
-
const targets = this.resolveImportTargets(sourceFilePath,importTarget);
|
|
527
|
-
return targets.length === 1 ? targets[0] : undefined;
|
|
528
|
-
}
|
|
529
|
-
// 1. Relative import (./ or ../)
|
|
530
|
-
if (importTarget.startsWith(".")) {
|
|
531
|
-
const sourceDir = dirname(sourceFilePath);
|
|
532
|
-
const combined = normalize(join(sourceDir, importTarget)).replace(/\\/g, "/");
|
|
533
|
-
|
|
534
|
-
const candidates = [
|
|
535
|
-
combined,
|
|
536
|
-
`${combined}.ts`,
|
|
537
|
-
`${combined}.tsx`,
|
|
538
|
-
`${combined}.js`,
|
|
539
|
-
`${combined}.jsx`,
|
|
540
|
-
`${combined}/index.ts`,
|
|
541
|
-
`${combined}/index.js`,
|
|
542
|
-
];
|
|
543
|
-
|
|
544
|
-
for (const cand of candidates) {
|
|
545
|
-
const found = this.fileMapByNormPath.get(this.normalizeFilePath(cand));
|
|
546
|
-
if (found) return found;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// 2. Alias import (@/... or src/...)
|
|
551
|
-
const cleanAlias = importTarget.replace(/^@\//, "src/");
|
|
552
|
-
const aliasCandidates = [
|
|
553
|
-
cleanAlias,
|
|
554
|
-
`${cleanAlias}.ts`,
|
|
555
|
-
`${cleanAlias}.tsx`,
|
|
556
|
-
`${cleanAlias}.js`,
|
|
557
|
-
`${cleanAlias}.jsx`,
|
|
558
|
-
`${cleanAlias}/index.ts`,
|
|
559
|
-
`${cleanAlias}/index.js`,
|
|
560
|
-
];
|
|
561
|
-
|
|
562
|
-
for (const cand of aliasCandidates) {
|
|
563
|
-
const found = this.fileMapByNormPath.get(this.normalizeFilePath(cand));
|
|
564
|
-
if (found) return found;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
// 3. Basename search fallback
|
|
568
|
-
const baseTarget = importTarget.split("/").pop()?.replace(/\.[^.]+$/, "");
|
|
569
|
-
if (baseTarget && baseTarget.length > 3) {
|
|
570
|
-
for (const [norm, file] of this.fileMapByNormPath.entries()) {
|
|
571
|
-
if (norm.includes(`/${baseTarget.toLowerCase()}.`) || norm.endsWith(`/${baseTarget.toLowerCase()}`)) {
|
|
572
|
-
return file;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
return undefined;
|
|
641
|
+
return this.importCandidates.resolveImportToFile(sourceFilePath, importTarget);
|
|
578
642
|
}
|
|
579
643
|
|
|
580
644
|
/**
|
|
@@ -590,12 +654,12 @@ export class CallGraphTracer {
|
|
|
590
654
|
if (relativeToFile) {
|
|
591
655
|
const file = this.fileMapByNormPath.get(this.normalizeFilePath(relativeToFile));
|
|
592
656
|
if (file) {
|
|
593
|
-
const deps = this.
|
|
657
|
+
const deps = this.fileDependencies(file.id);
|
|
594
658
|
for (const dep of deps) {
|
|
595
659
|
if (dep.target.includes(cleanSymbol) || dep.statement.includes(cleanSymbol)) {
|
|
596
660
|
const targetFile = this.resolveImportToFile(relativeToFile, dep.target);
|
|
597
661
|
if (targetFile) {
|
|
598
|
-
const syms = this.
|
|
662
|
+
const syms = this.fileSymbols(targetFile.id);
|
|
599
663
|
const s = syms.find((sym) => sym.name === cleanSymbol);
|
|
600
664
|
return {
|
|
601
665
|
file: targetFile.path,
|
|
@@ -607,15 +671,11 @@ export class CallGraphTracer {
|
|
|
607
671
|
}
|
|
608
672
|
}
|
|
609
673
|
|
|
610
|
-
// Global symbol search
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
if (file) {
|
|
616
|
-
return { file: file.path, line: match.line_start };
|
|
617
|
-
}
|
|
618
|
-
}
|
|
674
|
+
// Global symbol search via indexed SQLite lookup (avoids loading all symbols into RAM)
|
|
675
|
+
const exactMatches = this.repo.findSymbolsByName(cleanSymbol);
|
|
676
|
+
const exactMatch = exactMatches.find((s) => s.name === cleanSymbol);
|
|
677
|
+
if (exactMatch) {
|
|
678
|
+
return { file: exactMatch.file_path, line: exactMatch.line_start };
|
|
619
679
|
}
|
|
620
680
|
|
|
621
681
|
return null;
|
|
@@ -637,12 +697,12 @@ export class CallGraphTracer {
|
|
|
637
697
|
if (contextFile) {
|
|
638
698
|
const srcFile = this.fileMapByNormPath.get(this.normalizeFilePath(contextFile));
|
|
639
699
|
if (srcFile) {
|
|
640
|
-
const deps = this.
|
|
700
|
+
const deps = this.fileDependencies(srcFile.id);
|
|
641
701
|
for (const d of deps) {
|
|
642
702
|
if (d.statement.toLowerCase().includes(cleanIdent) || d.target.toLowerCase().includes(cleanIdent)) {
|
|
643
703
|
const resolved = this.resolveImportToFile(contextFile, d.target);
|
|
644
704
|
if (resolved) {
|
|
645
|
-
const syms = this.
|
|
705
|
+
const syms = this.fileSymbols(resolved.id);
|
|
646
706
|
const sym = syms.find(
|
|
647
707
|
(s) => s.name.toLowerCase() === ident.toLowerCase() || s.name.toLowerCase().includes(cleanIdent)
|
|
648
708
|
);
|
|
@@ -662,7 +722,7 @@ export class CallGraphTracer {
|
|
|
662
722
|
// 2. Try match file path
|
|
663
723
|
for (const [norm, file] of this.fileMapByNormPath.entries()) {
|
|
664
724
|
if (norm.toLowerCase().includes(cleanIdent) && norm.toLowerCase().includes("controller")) {
|
|
665
|
-
const syms = this.
|
|
725
|
+
const syms = this.fileSymbols(file.id);
|
|
666
726
|
return { file, symbol: syms.find((s) => s.kind === "class") };
|
|
667
727
|
}
|
|
668
728
|
}
|
|
@@ -696,7 +756,7 @@ export class CallGraphTracer {
|
|
|
696
756
|
controller_file: controllerNode?.file || null,
|
|
697
757
|
controller_line: controllerNode?.line || 0,
|
|
698
758
|
architecture_style: architectureStyle,
|
|
699
|
-
entry_kind: "
|
|
759
|
+
entry_kind: "inferred_http_route",
|
|
700
760
|
execution_chain_json: JSON.stringify(chain),
|
|
701
761
|
};
|
|
702
762
|
}
|
|
@@ -709,7 +769,11 @@ export class CallGraphTracer {
|
|
|
709
769
|
.replace(/\.[^.]+$/, "")
|
|
710
770
|
.toLowerCase();
|
|
711
771
|
|
|
712
|
-
const resource = base
|
|
772
|
+
const resource = base
|
|
773
|
+
? base.endsWith("s")
|
|
774
|
+
? `/${base}`
|
|
775
|
+
: `/${base}s`
|
|
776
|
+
: "/resource";
|
|
713
777
|
if (/store|create/i.test(methodName)) return resource;
|
|
714
778
|
if (/show|get|find/i.test(methodName)) return `${resource}/:id`;
|
|
715
779
|
if (/update|edit|patch/i.test(methodName)) return `${resource}/:id`;
|