@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,21 +1,18 @@
|
|
|
1
|
+
import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
|
|
1
2
|
import * as fs from "node:fs";
|
|
2
3
|
import * as path from "node:path";
|
|
3
4
|
import type Parser from "web-tree-sitter";
|
|
5
|
+
import { visitSymfonyRoutes } from "./symfony-routing.ts";
|
|
4
6
|
import { readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
5
7
|
import { parseSourceWithTreeSitter } from "../wasm-loader.ts";
|
|
6
8
|
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
9
|
+
import { hasComposerDependency } from "./manifest-helpers.ts";
|
|
7
10
|
import type {
|
|
8
11
|
SemanticSliceExtractor,
|
|
9
12
|
VerticalSliceCandidate,
|
|
10
13
|
} from "./semantic-extractor.interface.ts";
|
|
11
14
|
import type { ExecutionChainNode } from "../../../types/index.ts";
|
|
12
15
|
|
|
13
|
-
interface ParsedRouteAttribute {
|
|
14
|
-
path: string;
|
|
15
|
-
name?: string;
|
|
16
|
-
methods: string[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
16
|
interface InjectedService {
|
|
20
17
|
symbol: string;
|
|
21
18
|
file?: string;
|
|
@@ -36,37 +33,27 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
36
33
|
) {
|
|
37
34
|
return true;
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
reqs["symfony/framework-bundle"] ||
|
|
46
|
-
reqs["symfony/symfony"] ||
|
|
47
|
-
reqs["symfony/routing"]
|
|
48
|
-
) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
} catch {}
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
36
|
+
return hasComposerDependency(projectRoot, [
|
|
37
|
+
"symfony/framework-bundle",
|
|
38
|
+
"symfony/symfony",
|
|
39
|
+
"symfony/routing",
|
|
40
|
+
]);
|
|
54
41
|
}
|
|
55
42
|
|
|
56
43
|
public async extractSlices(
|
|
57
44
|
projectRoot: string = this.projectRoot,
|
|
58
45
|
domainId?: number,
|
|
59
|
-
signal?: AbortSignal
|
|
46
|
+
signal?: AbortSignal, inventory?: SourceInventory
|
|
60
47
|
): Promise<VerticalSliceCandidate[]> {
|
|
61
48
|
const root = path.resolve(projectRoot);
|
|
62
|
-
const controllerFiles =
|
|
49
|
+
const controllerFiles = listSourceFiles(fs.existsSync(path.join(root, 'src/Controller')) ? path.join(root, 'src/Controller') : path.join(root, 'src'), /\.php$/, inventory);
|
|
63
50
|
const slices: VerticalSliceCandidate[] = [];
|
|
64
51
|
const resolver = new ImportResolver(root);
|
|
65
52
|
|
|
66
53
|
for (const file of controllerFiles) {
|
|
67
54
|
signal?.throwIfAborted();
|
|
68
55
|
const content = readOptionalSourceFile(file, "utf-8");
|
|
69
|
-
if (!content ||
|
|
56
|
+
if (!content || !/#\[[\s\S]*?\bRoute\b/.test(content)) continue;
|
|
70
57
|
|
|
71
58
|
const relPath = path.relative(root, file).replace(/\\/g, "/");
|
|
72
59
|
|
|
@@ -74,114 +61,65 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
74
61
|
"php",
|
|
75
62
|
content,
|
|
76
63
|
(rootNode) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const bodyNode = node.childForFieldName("body");
|
|
101
|
-
if (!bodyNode) continue;
|
|
102
|
-
|
|
103
|
-
for (const member of bodyNode.namedChildren) {
|
|
104
|
-
if (member.type !== "method_declaration") continue;
|
|
105
|
-
|
|
106
|
-
const methodNameNode = member.childForFieldName("name");
|
|
107
|
-
if (!methodNameNode) continue;
|
|
108
|
-
const methodName = methodNameNode.text;
|
|
109
|
-
const methodLine = member.startPosition.row + 1;
|
|
110
|
-
|
|
111
|
-
const methodAttr = this.extractRouteAttributeFromNode(member);
|
|
112
|
-
if (!methodAttr) continue;
|
|
113
|
-
|
|
114
|
-
// Compose final URI
|
|
115
|
-
const fullUri = this.composeUri(classPrefix, methodAttr.path);
|
|
116
|
-
const fullRouteName = this.composeRouteName(classNamePrefix, methodAttr.name);
|
|
117
|
-
const targetMethods = methodAttr.methods.length > 0 ? methodAttr.methods : ["GET"];
|
|
118
|
-
|
|
119
|
-
// Extract injected services and request parameters
|
|
120
|
-
const { requestParam, services } = this.extractParameters(member, root, file, resolver);
|
|
121
|
-
|
|
122
|
-
for (const httpMethod of targetMethods) {
|
|
123
|
-
const chain: ExecutionChainNode[] = [
|
|
124
|
-
{
|
|
125
|
-
stage: "ingress",
|
|
126
|
-
symbol: `${httpMethod} ${fullUri}`,
|
|
127
|
-
file: relPath,
|
|
128
|
-
description: fullRouteName ? `HTTP Ingress: ${fullRouteName}` : `HTTP Ingress`,
|
|
129
|
-
},
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
if (requestParam) {
|
|
133
|
-
chain.push({
|
|
134
|
-
stage: "validation",
|
|
135
|
-
symbol: requestParam,
|
|
136
|
-
file: relPath,
|
|
137
|
-
description: "Symfony Request Injection",
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
chain.push({
|
|
142
|
-
stage: "controller",
|
|
143
|
-
symbol: `${fullClassName}::${methodName}`,
|
|
144
|
-
file: relPath,
|
|
145
|
-
line: methodLine,
|
|
146
|
-
description: "Symfony Controller Action",
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
for (const svc of services) {
|
|
150
|
-
chain.push({
|
|
151
|
-
stage: "service",
|
|
152
|
-
symbol: svc.symbol,
|
|
153
|
-
file: svc.file,
|
|
154
|
-
description: "Domain Service Invocation",
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Egress
|
|
159
|
-
const returnTypeNode = member.childForFieldName("return_type");
|
|
160
|
-
const returnType = returnTypeNode?.text?.replace(/^:\s*/, "") || "Response";
|
|
161
|
-
chain.push({
|
|
162
|
-
stage: "egress",
|
|
163
|
-
symbol: returnType,
|
|
164
|
-
description: "HTTP Response Egress",
|
|
165
|
-
});
|
|
64
|
+
visitSymfonyRoutes(rootNode, ({ uri, name, methods, className, action, resolveClass }) => {
|
|
65
|
+
const methodName = action.childForFieldName("name")?.text;
|
|
66
|
+
if (!methodName) return;
|
|
67
|
+
const methodLine = (action.children.find(child => child.type === "function") ?? action).startPosition.row + 1;
|
|
68
|
+
const { requestParam, services } = this.extractParameters(action, file, resolver, resolveClass);
|
|
69
|
+
const returnType = action.childForFieldName("return_type")?.text || "Response";
|
|
70
|
+
|
|
71
|
+
for (const httpMethod of methods) {
|
|
72
|
+
const chain: ExecutionChainNode[] = [{
|
|
73
|
+
stage: "ingress",
|
|
74
|
+
symbol: `${httpMethod} ${uri}`,
|
|
75
|
+
file: relPath,
|
|
76
|
+
description: name ? `HTTP Ingress: ${name}` : "HTTP Ingress",
|
|
77
|
+
}];
|
|
78
|
+
|
|
79
|
+
if (requestParam) {
|
|
80
|
+
chain.push({
|
|
81
|
+
stage: "validation",
|
|
82
|
+
symbol: requestParam,
|
|
83
|
+
file: relPath,
|
|
84
|
+
description: "Symfony Request Injection",
|
|
85
|
+
});
|
|
86
|
+
}
|
|
166
87
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
88
|
+
chain.push({
|
|
89
|
+
stage: "controller",
|
|
90
|
+
symbol: `${className}::${methodName}`,
|
|
91
|
+
file: relPath,
|
|
92
|
+
line: methodLine,
|
|
93
|
+
description: "Symfony Controller Action",
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
for (const service of services) {
|
|
97
|
+
chain.push({
|
|
98
|
+
stage: "service",
|
|
99
|
+
symbol: service.symbol,
|
|
100
|
+
file: service.file,
|
|
101
|
+
description: "Symfony Action Parameter",
|
|
102
|
+
});
|
|
182
103
|
}
|
|
104
|
+
|
|
105
|
+
chain.push({ stage: "egress", symbol: returnType, description: "HTTP Response Egress" });
|
|
106
|
+
|
|
107
|
+
slices.push({
|
|
108
|
+
domain_id: domainId ?? null,
|
|
109
|
+
feature_key: name || null,
|
|
110
|
+
http_method: httpMethod,
|
|
111
|
+
route_uri: uri,
|
|
112
|
+
route_name: name || null,
|
|
113
|
+
controller_class: className,
|
|
114
|
+
action_name: methodName,
|
|
115
|
+
controller_file: relPath,
|
|
116
|
+
controller_line: methodLine,
|
|
117
|
+
architecture_style: "mvc",
|
|
118
|
+
entry_kind: "http_route",
|
|
119
|
+
execution_chain_json: JSON.stringify(chain),
|
|
120
|
+
});
|
|
183
121
|
}
|
|
184
|
-
}
|
|
122
|
+
}, signal);
|
|
185
123
|
return { symbols: [], dependencies: [] };
|
|
186
124
|
},
|
|
187
125
|
() => ({ symbols: [], dependencies: [] })
|
|
@@ -191,126 +129,11 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
191
129
|
return slices;
|
|
192
130
|
}
|
|
193
131
|
|
|
194
|
-
private collectControllerFiles(root: string): string[] {
|
|
195
|
-
const files: string[] = [];
|
|
196
|
-
const controllerDir = path.join(root, "src/Controller");
|
|
197
|
-
|
|
198
|
-
const scanDir = (dir: string, depth = 0) => {
|
|
199
|
-
if (depth > 5 || !fs.existsSync(dir)) return;
|
|
200
|
-
try {
|
|
201
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
202
|
-
for (const entry of entries) {
|
|
203
|
-
if (entry.name.startsWith(".") || entry.name === "vendor" || entry.name === "var" || entry.name === "tests") {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
const fullPath = path.join(dir, entry.name);
|
|
207
|
-
if (entry.isDirectory()) {
|
|
208
|
-
scanDir(fullPath, depth + 1);
|
|
209
|
-
} else if (entry.isFile() && entry.name.endsWith(".php")) {
|
|
210
|
-
files.push(fullPath);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
} catch {}
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
if (fs.existsSync(controllerDir)) {
|
|
217
|
-
scanDir(controllerDir);
|
|
218
|
-
} else {
|
|
219
|
-
const srcDir = path.join(root, "src");
|
|
220
|
-
if (fs.existsSync(srcDir)) {
|
|
221
|
-
scanDir(srcDir);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return files;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
private extractRouteAttributeFromNode(node: Parser.SyntaxNode): ParsedRouteAttribute | null {
|
|
229
|
-
const attrList = node.namedChildren.find((c) => c.type === "attribute_list");
|
|
230
|
-
if (!attrList) return null;
|
|
231
|
-
|
|
232
|
-
for (const group of attrList.namedChildren.filter((c) => c.type === "attribute_group")) {
|
|
233
|
-
for (const attr of group.namedChildren.filter((c) => c.type === "attribute")) {
|
|
234
|
-
const nameNode = attr.namedChildren.find((c) => c.type === "name");
|
|
235
|
-
if (nameNode?.text !== "Route") continue;
|
|
236
|
-
|
|
237
|
-
const argsNode = attr.namedChildren.find((c) => c.type === "arguments");
|
|
238
|
-
if (!argsNode) return { path: "", methods: ["GET"] };
|
|
239
|
-
|
|
240
|
-
let routePath = "";
|
|
241
|
-
let routeName: string | undefined;
|
|
242
|
-
const methods: string[] = [];
|
|
243
|
-
|
|
244
|
-
for (const arg of argsNode.namedChildren.filter((c) => c.type === "argument")) {
|
|
245
|
-
const argNameNode = arg.namedChildren.find((c) => c.type === "name");
|
|
246
|
-
if (!argNameNode) {
|
|
247
|
-
// Positional argument: path
|
|
248
|
-
routePath = this.cleanLiteral(arg.namedChildren[0]?.text);
|
|
249
|
-
} else {
|
|
250
|
-
const argName = argNameNode.text;
|
|
251
|
-
const valNode = arg.namedChildren[1];
|
|
252
|
-
if (argName === "path") {
|
|
253
|
-
routePath = this.cleanLiteral(valNode?.text);
|
|
254
|
-
} else if (argName === "name") {
|
|
255
|
-
routeName = this.cleanLiteral(valNode?.text);
|
|
256
|
-
} else if (argName === "methods") {
|
|
257
|
-
if (valNode?.type === "array_creation_expression") {
|
|
258
|
-
for (const elem of valNode.namedChildren) {
|
|
259
|
-
const m = this.cleanLiteral(elem.text).toUpperCase();
|
|
260
|
-
if (m) methods.push(m);
|
|
261
|
-
}
|
|
262
|
-
} else if (valNode) {
|
|
263
|
-
methods.push(this.cleanLiteral(valNode.text).toUpperCase());
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return {
|
|
270
|
-
path: routePath,
|
|
271
|
-
name: routeName,
|
|
272
|
-
methods: methods.length > 0 ? methods : ["GET"],
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return null;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private cleanLiteral(text?: string): string {
|
|
281
|
-
if (!text) return "";
|
|
282
|
-
const trimmed = text.trim();
|
|
283
|
-
if (
|
|
284
|
-
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
285
|
-
(trimmed.startsWith("'") && trimmed.endsWith("'"))
|
|
286
|
-
) {
|
|
287
|
-
return trimmed.slice(1, -1);
|
|
288
|
-
}
|
|
289
|
-
return trimmed;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
private composeUri(classPrefix: string, methodPath: string): string {
|
|
293
|
-
const cleanPrefix = classPrefix.replace(/^\/+|\/+$/g, "");
|
|
294
|
-
const cleanPath = methodPath.replace(/^\/+|\/+$/g, "");
|
|
295
|
-
|
|
296
|
-
if (!cleanPrefix && !cleanPath) return "/";
|
|
297
|
-
if (!cleanPrefix) return `/${cleanPath}`;
|
|
298
|
-
if (!cleanPath) return `/${cleanPrefix}`;
|
|
299
|
-
return `/${cleanPrefix}/${cleanPath}`;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
private composeRouteName(prefix?: string, name?: string): string | undefined {
|
|
303
|
-
if (!prefix && !name) return undefined;
|
|
304
|
-
if (!prefix) return name;
|
|
305
|
-
if (!name) return prefix;
|
|
306
|
-
return `${prefix}${name}`;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
132
|
private extractParameters(
|
|
310
133
|
methodNode: Parser.SyntaxNode,
|
|
311
|
-
projectRoot: string,
|
|
312
134
|
currentFile: string,
|
|
313
|
-
resolver: ImportResolver
|
|
135
|
+
resolver: ImportResolver,
|
|
136
|
+
resolveClass: (name: string) => string | undefined
|
|
314
137
|
): { requestParam?: string; services: InjectedService[] } {
|
|
315
138
|
const services: InjectedService[] = [];
|
|
316
139
|
let requestParam: string | undefined;
|
|
@@ -323,28 +146,18 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
323
146
|
const typeNode = param.childForFieldName("type");
|
|
324
147
|
if (!typeNode) continue;
|
|
325
148
|
|
|
326
|
-
const rawType = typeNode.text.replace(
|
|
327
|
-
|
|
149
|
+
const rawType = typeNode.text.replace(/^\?/, "");
|
|
150
|
+
if (!/^[a-z_\\][a-z0-9_\\]*$/i.test(rawType)) continue;
|
|
151
|
+
const resolvedType = resolveClass(rawType);
|
|
152
|
+
const shortType = (resolvedType ?? rawType).split("\\").at(-1)!;
|
|
328
153
|
|
|
329
154
|
if (/Request$/i.test(shortType)) {
|
|
330
155
|
requestParam = shortType;
|
|
331
156
|
} else if (/(Service|Repository|Handler|Manager|Client)$/i.test(shortType)) {
|
|
332
|
-
|
|
333
|
-
let fqn = rawType;
|
|
334
|
-
if (!rawType.includes("\\")) {
|
|
335
|
-
const fileContent = readOptionalSourceFile(currentFile, "utf-8");
|
|
336
|
-
const useMatch = new RegExp(`use\\s+([^;]+?\\\\${rawType})(?:\\s+as\\s+[A-Za-z0-9_]+)?;`, "i").exec(fileContent);
|
|
337
|
-
if (useMatch) {
|
|
338
|
-
fqn = useMatch[1].trim();
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
const res = resolver.resolve(fqn, currentFile);
|
|
342
|
-
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
343
|
-
filePath = res.targets[0].files[0];
|
|
344
|
-
}
|
|
157
|
+
const resolved = resolvedType ? resolver.resolve(resolvedType, currentFile) : undefined;
|
|
345
158
|
services.push({
|
|
346
159
|
symbol: shortType,
|
|
347
|
-
file:
|
|
160
|
+
file: resolved?.status === "resolved" ? resolved.targets[0]?.files[0] : undefined,
|
|
348
161
|
});
|
|
349
162
|
}
|
|
350
163
|
}
|