@dimassetoid/septum-mcp 0.3.0 → 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 +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 +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 -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,114 @@
|
|
|
1
|
+
import type Parser from "web-tree-sitter";
|
|
2
|
+
import { children, importsFor, literal, phpSections } from "./php-ast-helpers.ts";
|
|
3
|
+
|
|
4
|
+
type Node = Parser.SyntaxNode;
|
|
5
|
+
type RouteAttribute = { path: string; name?: string; methods: string[] };
|
|
6
|
+
type ResolveClass = (name: string) => string | undefined;
|
|
7
|
+
|
|
8
|
+
const routeClasses = new Set([
|
|
9
|
+
"symfony\\component\\routing\\attribute\\route",
|
|
10
|
+
"symfony\\component\\routing\\annotation\\route",
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
function routeAttributes(node: Node, resolveClass: ResolveClass): Node[] {
|
|
14
|
+
return children(node.childForFieldName("attributes")).flatMap(group =>
|
|
15
|
+
children(group).filter(attribute => {
|
|
16
|
+
const name = children(attribute)[0];
|
|
17
|
+
return attribute.type === "attribute" && !!name &&
|
|
18
|
+
routeClasses.has(resolveClass(name.text)?.toLowerCase() ?? "");
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function readAttribute(node: Node): RouteAttribute | undefined {
|
|
24
|
+
if (node.hasError) return undefined;
|
|
25
|
+
const fields = new Map<string, Node>();
|
|
26
|
+
const positional = ["path", "name", "requirements", "options", "defaults", "host", "methods"];
|
|
27
|
+
let position = 0;
|
|
28
|
+
for (const arg of children(node.childForFieldName("parameters"))) {
|
|
29
|
+
const label = arg.childForFieldName("name");
|
|
30
|
+
const key = label?.text ?? positional[position++];
|
|
31
|
+
const values = children(arg).slice(label ? 1 : 0);
|
|
32
|
+
if (arg.type !== "argument" || values.length !== 1 || values[0]?.type === "variadic_unpacking") return undefined;
|
|
33
|
+
if (key && fields.has(key)) return undefined;
|
|
34
|
+
if (key) fields.set(key, values[0]!);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const pathNode = fields.get("path");
|
|
38
|
+
const nameNode = fields.get("name");
|
|
39
|
+
const path = !pathNode || pathNode.type === "null" ? "" : literal(pathNode);
|
|
40
|
+
const name = literal(nameNode);
|
|
41
|
+
if (path === undefined || (nameNode && nameNode.type !== "null" && name === undefined)) return undefined;
|
|
42
|
+
|
|
43
|
+
const methodNode = fields.get("methods");
|
|
44
|
+
const values = methodNode?.type === "array_creation_expression"
|
|
45
|
+
? children(methodNode).map(item => {
|
|
46
|
+
const parts = children(item);
|
|
47
|
+
return parts.length === 1 ? literal(parts[0]) : undefined;
|
|
48
|
+
})
|
|
49
|
+
: methodNode ? [literal(methodNode)] : [];
|
|
50
|
+
if (!values.every((value): value is string => value !== undefined && /^[a-z][a-z-]*$/i.test(value))) return undefined;
|
|
51
|
+
return { path, name, methods: values.map(value => value.toUpperCase()) };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function visitSymfonyRoutes(
|
|
55
|
+
root: Node,
|
|
56
|
+
visit: (route: {
|
|
57
|
+
uri: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
methods: string[];
|
|
60
|
+
className: string;
|
|
61
|
+
action: Node;
|
|
62
|
+
resolveClass: ResolveClass;
|
|
63
|
+
}) => void,
|
|
64
|
+
signal?: AbortSignal,
|
|
65
|
+
): void {
|
|
66
|
+
for (const { namespace, statements } of phpSections(root)) {
|
|
67
|
+
const imports = importsFor(statements);
|
|
68
|
+
const resolveClass: ResolveClass = name => {
|
|
69
|
+
if (name.startsWith("\\")) return name.slice(1);
|
|
70
|
+
const [head, ...tail] = name.split("\\");
|
|
71
|
+
const key = head!.toLowerCase();
|
|
72
|
+
if (key === "namespace" && tail.length) return [namespace, ...tail].filter(Boolean).join("\\");
|
|
73
|
+
if (!imports.has(key)) return [namespace, name].filter(Boolean).join("\\");
|
|
74
|
+
const imported = imports.get(key);
|
|
75
|
+
return imported ? [imported, ...tail].join("\\") : undefined;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
for (const node of statements) {
|
|
79
|
+
signal?.throwIfAborted();
|
|
80
|
+
if (node.type !== "class_declaration" || children(node).some(child => child.type === "abstract_modifier")) continue;
|
|
81
|
+
const name = node.childForFieldName("name")?.text;
|
|
82
|
+
if (!name) continue;
|
|
83
|
+
const className = [namespace, name].filter(Boolean).join("\\");
|
|
84
|
+
const classAttributes = routeAttributes(node, resolveClass);
|
|
85
|
+
const methods = children(node.childForFieldName("body"))
|
|
86
|
+
.filter(member => member.type === "method_declaration" && member.childForFieldName("body"))
|
|
87
|
+
.map(action => ({ action, attributes: routeAttributes(action, resolveClass) }));
|
|
88
|
+
|
|
89
|
+
const emit = (action: Node, attributes: Node[], prefix?: RouteAttribute) => {
|
|
90
|
+
for (const attribute of attributes) {
|
|
91
|
+
signal?.throwIfAborted();
|
|
92
|
+
const route = readAttribute(attribute);
|
|
93
|
+
if (!route) continue;
|
|
94
|
+
const methods = [...new Set([...(prefix?.methods ?? []), ...route.methods])];
|
|
95
|
+
const uri = "/" + [prefix?.path, route.path].filter(Boolean).join("").replace(/^\/+/, "");
|
|
96
|
+
visit({
|
|
97
|
+
uri, name: route.name === undefined ? undefined : (prefix?.name ?? "") + route.name,
|
|
98
|
+
methods: methods.length ? methods : ["ANY"], className, action, resolveClass,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (methods.some(method => method.attributes.length)) {
|
|
104
|
+
const prefixAttribute = classAttributes[0];
|
|
105
|
+
const prefix = prefixAttribute && readAttribute(prefixAttribute);
|
|
106
|
+
if (prefixAttribute && !prefix) continue;
|
|
107
|
+
for (const { action, attributes } of methods) emit(action, attributes, prefix);
|
|
108
|
+
} else {
|
|
109
|
+
const invokable = methods.find(({ action }) => action.childForFieldName("name")?.text.toLowerCase() === "__invoke");
|
|
110
|
+
if (invokable) emit(invokable.action, classAttributes);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -2,21 +2,17 @@ import { listSourceFiles, type SourceInventory } from "../../resources/source-in
|
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import type Parser from "web-tree-sitter";
|
|
5
|
+
import { visitSymfonyRoutes } from "./symfony-routing.ts";
|
|
5
6
|
import { readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
6
7
|
import { parseSourceWithTreeSitter } from "../wasm-loader.ts";
|
|
7
8
|
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
9
|
+
import { hasComposerDependency } from "./manifest-helpers.ts";
|
|
8
10
|
import type {
|
|
9
11
|
SemanticSliceExtractor,
|
|
10
12
|
VerticalSliceCandidate,
|
|
11
13
|
} from "./semantic-extractor.interface.ts";
|
|
12
14
|
import type { ExecutionChainNode } from "../../../types/index.ts";
|
|
13
15
|
|
|
14
|
-
interface ParsedRouteAttribute {
|
|
15
|
-
path: string;
|
|
16
|
-
name?: string;
|
|
17
|
-
methods: string[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
16
|
interface InjectedService {
|
|
21
17
|
symbol: string;
|
|
22
18
|
file?: string;
|
|
@@ -37,21 +33,11 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
37
33
|
) {
|
|
38
34
|
return true;
|
|
39
35
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
reqs["symfony/framework-bundle"] ||
|
|
47
|
-
reqs["symfony/symfony"] ||
|
|
48
|
-
reqs["symfony/routing"]
|
|
49
|
-
) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
} catch {}
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
36
|
+
return hasComposerDependency(projectRoot, [
|
|
37
|
+
"symfony/framework-bundle",
|
|
38
|
+
"symfony/symfony",
|
|
39
|
+
"symfony/routing",
|
|
40
|
+
]);
|
|
55
41
|
}
|
|
56
42
|
|
|
57
43
|
public async extractSlices(
|
|
@@ -67,7 +53,7 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
67
53
|
for (const file of controllerFiles) {
|
|
68
54
|
signal?.throwIfAborted();
|
|
69
55
|
const content = readOptionalSourceFile(file, "utf-8");
|
|
70
|
-
if (!content ||
|
|
56
|
+
if (!content || !/#\[[\s\S]*?\bRoute\b/.test(content)) continue;
|
|
71
57
|
|
|
72
58
|
const relPath = path.relative(root, file).replace(/\\/g, "/");
|
|
73
59
|
|
|
@@ -75,114 +61,65 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
75
61
|
"php",
|
|
76
62
|
content,
|
|
77
63
|
(rootNode) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const bodyNode = node.childForFieldName("body");
|
|
102
|
-
if (!bodyNode) continue;
|
|
103
|
-
|
|
104
|
-
for (const member of bodyNode.namedChildren) {
|
|
105
|
-
if (member.type !== "method_declaration") continue;
|
|
106
|
-
|
|
107
|
-
const methodNameNode = member.childForFieldName("name");
|
|
108
|
-
if (!methodNameNode) continue;
|
|
109
|
-
const methodName = methodNameNode.text;
|
|
110
|
-
const methodLine = member.startPosition.row + 1;
|
|
111
|
-
|
|
112
|
-
const methodAttr = this.extractRouteAttributeFromNode(member);
|
|
113
|
-
if (!methodAttr) continue;
|
|
114
|
-
|
|
115
|
-
// Compose final URI
|
|
116
|
-
const fullUri = this.composeUri(classPrefix, methodAttr.path);
|
|
117
|
-
const fullRouteName = this.composeRouteName(classNamePrefix, methodAttr.name);
|
|
118
|
-
const targetMethods = methodAttr.methods.length > 0 ? methodAttr.methods : ["GET"];
|
|
119
|
-
|
|
120
|
-
// Extract injected services and request parameters
|
|
121
|
-
const { requestParam, services } = this.extractParameters(member, root, file, resolver);
|
|
122
|
-
|
|
123
|
-
for (const httpMethod of targetMethods) {
|
|
124
|
-
const chain: ExecutionChainNode[] = [
|
|
125
|
-
{
|
|
126
|
-
stage: "ingress",
|
|
127
|
-
symbol: `${httpMethod} ${fullUri}`,
|
|
128
|
-
file: relPath,
|
|
129
|
-
description: fullRouteName ? `HTTP Ingress: ${fullRouteName}` : `HTTP Ingress`,
|
|
130
|
-
},
|
|
131
|
-
];
|
|
132
|
-
|
|
133
|
-
if (requestParam) {
|
|
134
|
-
chain.push({
|
|
135
|
-
stage: "validation",
|
|
136
|
-
symbol: requestParam,
|
|
137
|
-
file: relPath,
|
|
138
|
-
description: "Symfony Request Injection",
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
chain.push({
|
|
143
|
-
stage: "controller",
|
|
144
|
-
symbol: `${fullClassName}::${methodName}`,
|
|
145
|
-
file: relPath,
|
|
146
|
-
line: methodLine,
|
|
147
|
-
description: "Symfony Controller Action",
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
for (const svc of services) {
|
|
151
|
-
chain.push({
|
|
152
|
-
stage: "service",
|
|
153
|
-
symbol: svc.symbol,
|
|
154
|
-
file: svc.file,
|
|
155
|
-
description: "Domain Service Invocation",
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Egress
|
|
160
|
-
const returnTypeNode = member.childForFieldName("return_type");
|
|
161
|
-
const returnType = returnTypeNode?.text?.replace(/^:\s*/, "") || "Response";
|
|
162
|
-
chain.push({
|
|
163
|
-
stage: "egress",
|
|
164
|
-
symbol: returnType,
|
|
165
|
-
description: "HTTP Response Egress",
|
|
166
|
-
});
|
|
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
|
+
}
|
|
167
87
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
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
|
+
});
|
|
183
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
|
+
});
|
|
184
121
|
}
|
|
185
|
-
}
|
|
122
|
+
}, signal);
|
|
186
123
|
return { symbols: [], dependencies: [] };
|
|
187
124
|
},
|
|
188
125
|
() => ({ symbols: [], dependencies: [] })
|
|
@@ -192,92 +129,11 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
192
129
|
return slices;
|
|
193
130
|
}
|
|
194
131
|
|
|
195
|
-
private extractRouteAttributeFromNode(node: Parser.SyntaxNode): ParsedRouteAttribute | null {
|
|
196
|
-
const attrList = node.namedChildren.find((c) => c.type === "attribute_list");
|
|
197
|
-
if (!attrList) return null;
|
|
198
|
-
|
|
199
|
-
for (const group of attrList.namedChildren.filter((c) => c.type === "attribute_group")) {
|
|
200
|
-
for (const attr of group.namedChildren.filter((c) => c.type === "attribute")) {
|
|
201
|
-
const nameNode = attr.namedChildren.find((c) => c.type === "name");
|
|
202
|
-
if (nameNode?.text !== "Route") continue;
|
|
203
|
-
|
|
204
|
-
const argsNode = attr.namedChildren.find((c) => c.type === "arguments");
|
|
205
|
-
if (!argsNode) return { path: "", methods: ["GET"] };
|
|
206
|
-
|
|
207
|
-
let routePath = "";
|
|
208
|
-
let routeName: string | undefined;
|
|
209
|
-
const methods: string[] = [];
|
|
210
|
-
|
|
211
|
-
for (const arg of argsNode.namedChildren.filter((c) => c.type === "argument")) {
|
|
212
|
-
const argNameNode = arg.namedChildren.find((c) => c.type === "name");
|
|
213
|
-
if (!argNameNode) {
|
|
214
|
-
// Positional argument: path
|
|
215
|
-
routePath = this.cleanLiteral(arg.namedChildren[0]?.text);
|
|
216
|
-
} else {
|
|
217
|
-
const argName = argNameNode.text;
|
|
218
|
-
const valNode = arg.namedChildren[1];
|
|
219
|
-
if (argName === "path") {
|
|
220
|
-
routePath = this.cleanLiteral(valNode?.text);
|
|
221
|
-
} else if (argName === "name") {
|
|
222
|
-
routeName = this.cleanLiteral(valNode?.text);
|
|
223
|
-
} else if (argName === "methods") {
|
|
224
|
-
if (valNode?.type === "array_creation_expression") {
|
|
225
|
-
for (const elem of valNode.namedChildren) {
|
|
226
|
-
const m = this.cleanLiteral(elem.text).toUpperCase();
|
|
227
|
-
if (m) methods.push(m);
|
|
228
|
-
}
|
|
229
|
-
} else if (valNode) {
|
|
230
|
-
methods.push(this.cleanLiteral(valNode.text).toUpperCase());
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
path: routePath,
|
|
238
|
-
name: routeName,
|
|
239
|
-
methods: methods.length > 0 ? methods : ["GET"],
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return null;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
private cleanLiteral(text?: string): string {
|
|
248
|
-
if (!text) return "";
|
|
249
|
-
const trimmed = text.trim();
|
|
250
|
-
if (
|
|
251
|
-
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
252
|
-
(trimmed.startsWith("'") && trimmed.endsWith("'"))
|
|
253
|
-
) {
|
|
254
|
-
return trimmed.slice(1, -1);
|
|
255
|
-
}
|
|
256
|
-
return trimmed;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
private composeUri(classPrefix: string, methodPath: string): string {
|
|
260
|
-
const cleanPrefix = classPrefix.replace(/^\/+|\/+$/g, "");
|
|
261
|
-
const cleanPath = methodPath.replace(/^\/+|\/+$/g, "");
|
|
262
|
-
|
|
263
|
-
if (!cleanPrefix && !cleanPath) return "/";
|
|
264
|
-
if (!cleanPrefix) return `/${cleanPath}`;
|
|
265
|
-
if (!cleanPath) return `/${cleanPrefix}`;
|
|
266
|
-
return `/${cleanPrefix}/${cleanPath}`;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
private composeRouteName(prefix?: string, name?: string): string | undefined {
|
|
270
|
-
if (!prefix && !name) return undefined;
|
|
271
|
-
if (!prefix) return name;
|
|
272
|
-
if (!name) return prefix;
|
|
273
|
-
return `${prefix}${name}`;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
132
|
private extractParameters(
|
|
277
133
|
methodNode: Parser.SyntaxNode,
|
|
278
|
-
projectRoot: string,
|
|
279
134
|
currentFile: string,
|
|
280
|
-
resolver: ImportResolver
|
|
135
|
+
resolver: ImportResolver,
|
|
136
|
+
resolveClass: (name: string) => string | undefined
|
|
281
137
|
): { requestParam?: string; services: InjectedService[] } {
|
|
282
138
|
const services: InjectedService[] = [];
|
|
283
139
|
let requestParam: string | undefined;
|
|
@@ -290,28 +146,18 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
290
146
|
const typeNode = param.childForFieldName("type");
|
|
291
147
|
if (!typeNode) continue;
|
|
292
148
|
|
|
293
|
-
const rawType = typeNode.text.replace(
|
|
294
|
-
|
|
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)!;
|
|
295
153
|
|
|
296
154
|
if (/Request$/i.test(shortType)) {
|
|
297
155
|
requestParam = shortType;
|
|
298
156
|
} else if (/(Service|Repository|Handler|Manager|Client)$/i.test(shortType)) {
|
|
299
|
-
|
|
300
|
-
let fqn = rawType;
|
|
301
|
-
if (!rawType.includes("\\")) {
|
|
302
|
-
const fileContent = readOptionalSourceFile(currentFile, "utf-8");
|
|
303
|
-
const useMatch = new RegExp(`use\\s+([^;]+?\\\\${rawType})(?:\\s+as\\s+[A-Za-z0-9_]+)?;`, "i").exec(fileContent);
|
|
304
|
-
if (useMatch) {
|
|
305
|
-
fqn = useMatch[1].trim();
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
const res = resolver.resolve(fqn, currentFile);
|
|
309
|
-
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
310
|
-
filePath = res.targets[0].files[0];
|
|
311
|
-
}
|
|
157
|
+
const resolved = resolvedType ? resolver.resolve(resolvedType, currentFile) : undefined;
|
|
312
158
|
services.push({
|
|
313
159
|
symbol: shortType,
|
|
314
|
-
file:
|
|
160
|
+
file: resolved?.status === "resolved" ? resolved.targets[0]?.files[0] : undefined,
|
|
315
161
|
});
|
|
316
162
|
}
|
|
317
163
|
}
|