@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
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
import { composeMountPrefixes } from "./route-prefixes.ts";
|
|
1
2
|
import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
|
|
2
3
|
import { readPythonStaticString as cleanLiteral } from "../static-string.ts";
|
|
3
4
|
import type Parser from "web-tree-sitter";
|
|
5
|
+
import {
|
|
6
|
+
pythonCallArgument, pythonCallUsesUnpacking, pythonLiteralMethods, resolvePythonRouterTarget,
|
|
7
|
+
visitPythonRouterModule, type PythonRouterTarget,
|
|
8
|
+
} from "./python-route-ast.ts";
|
|
4
9
|
import { parseSourceWithTreeSitter } from "../wasm-loader.ts";
|
|
5
10
|
import { readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
6
11
|
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
7
12
|
import * as fs from "node:fs";
|
|
8
13
|
import * as path from "node:path";
|
|
14
|
+
import { anyFileContains } from "./manifest-helpers.ts";
|
|
9
15
|
import type { SemanticSliceExtractor, VerticalSliceCandidate } from "./semantic-extractor.interface.ts";
|
|
10
16
|
|
|
11
17
|
interface ExtractedFlaskRoute {
|
|
12
18
|
file: string;
|
|
13
19
|
relPath: string;
|
|
14
|
-
|
|
20
|
+
routerKey: string;
|
|
15
21
|
httpMethods: string[];
|
|
16
22
|
rawPath: string;
|
|
17
23
|
actionName: string;
|
|
@@ -23,27 +29,25 @@ interface ExtractedFlaskRoute {
|
|
|
23
29
|
|
|
24
30
|
interface ExtractedBlueprintRegistration {
|
|
25
31
|
file: string;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
prefix: string | null | undefined;
|
|
30
|
-
line: number;
|
|
32
|
+
parent: string;
|
|
33
|
+
target: PythonRouterTarget;
|
|
34
|
+
// null represents a supplied prefix whose value is unknown. Undefined uses the blueprint default.
|
|
35
|
+
prefix: string | null | undefined;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
38
|
+
type Blueprint = { name: string; prefix: string | undefined; isApp: boolean };
|
|
39
|
+
type Node = Parser.SyntaxNode;
|
|
40
|
+
const verbs = /^(get|post|put|patch|delete|options|head)$/;
|
|
37
41
|
|
|
42
|
+
function routeMethods(call: Node, method: string): string[] {
|
|
43
|
+
if (verbs.test(method)) return [method.toUpperCase()];
|
|
44
|
+
const value = pythonCallArgument(call, "methods");
|
|
45
|
+
return !value || value.type === "none" ? ["GET"] : pythonLiteralMethods(value) ?? [];
|
|
46
|
+
}
|
|
38
47
|
|
|
39
|
-
function normalizeRouteUri(prefix: string,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!r.startsWith("/")) r = "/" + r;
|
|
43
|
-
if (r === "/" && p.length > 0) return p + "/";
|
|
44
|
-
if (r === "/" && p.length === 0) return "/";
|
|
45
|
-
const joined = `${p}${r}`;
|
|
46
|
-
return joined.startsWith("/") ? joined : `/${joined}`;
|
|
48
|
+
function normalizeRouteUri(prefix: string, path: string): string {
|
|
49
|
+
if (!path) return prefix || "/";
|
|
50
|
+
return prefix + "/" + path.replace(/^\/+/, "");
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
export class FlaskSemanticExtractor implements SemanticSliceExtractor {
|
|
@@ -53,31 +57,15 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
|
|
|
53
57
|
public canHandle(projectRoot: string, framework?: string): boolean {
|
|
54
58
|
if (framework === "flask") return true;
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const fullPath = path.join(projectRoot, manifest);
|
|
59
|
-
if (fs.existsSync(fullPath)) {
|
|
60
|
-
try {
|
|
61
|
-
const content = fs.readFileSync(fullPath, "utf-8").toLowerCase();
|
|
62
|
-
if (content.includes("flask")) return true;
|
|
63
|
-
} catch {}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Check entrypoint files
|
|
68
|
-
for (const entry of ["app.py", "main.py", "wsgi.py", "run.py", "server.py", "src/app.py", "app/__init__.py"]) {
|
|
69
|
-
const fullPath = path.join(projectRoot, entry);
|
|
70
|
-
if (fs.existsSync(fullPath)) {
|
|
71
|
-
try {
|
|
72
|
-
const content = fs.readFileSync(fullPath, "utf-8");
|
|
73
|
-
if (content.includes("from flask") || content.includes("import flask")) {
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
} catch {}
|
|
77
|
-
}
|
|
60
|
+
if (anyFileContains(projectRoot, ["requirements.txt", "pyproject.toml", "Pipfile", "setup.py"], ["flask"], true)) {
|
|
61
|
+
return true;
|
|
78
62
|
}
|
|
79
63
|
|
|
80
|
-
return
|
|
64
|
+
return anyFileContains(
|
|
65
|
+
projectRoot,
|
|
66
|
+
["app.py", "main.py", "wsgi.py", "run.py", "server.py", "src/app.py", "app/__init__.py"],
|
|
67
|
+
["from flask", "import flask"]
|
|
68
|
+
);
|
|
81
69
|
}
|
|
82
70
|
|
|
83
71
|
public async extractSlices(
|
|
@@ -91,217 +79,63 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
|
|
|
91
79
|
|
|
92
80
|
const allRoutes: ExtractedFlaskRoute[] = [];
|
|
93
81
|
const allRegistrations: ExtractedBlueprintRegistration[] = [];
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
{ bpName: string; prefix: string | null; isApp: boolean }
|
|
97
|
-
>();
|
|
98
|
-
const fileImports = new Map<string, Map<string, ImportBinding>>();
|
|
82
|
+
const blueprints = new Map<string, Blueprint>();
|
|
83
|
+
const fileRouters = new Map<string, Map<string, string>>();
|
|
99
84
|
|
|
100
85
|
for (const file of pyFiles) {
|
|
101
86
|
signal?.throwIfAborted();
|
|
102
87
|
const relPath = path.relative(projectRoot, file).replace(/\\/g, "/");
|
|
103
88
|
const content = readOptionalSourceFile(file, "utf-8");
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const parsed = await parseSourceWithTreeSitter("python", content, (root) => {
|
|
118
|
-
const walk = (node: Parser.SyntaxNode, visit: (node: Parser.SyntaxNode) => void) => {
|
|
119
|
-
visit(node);
|
|
120
|
-
for (const child of node.namedChildren) walk(child, visit);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// 1. Collect import statements
|
|
124
|
-
walk(root, (node) => {
|
|
125
|
-
if (node.type === "import_statement") {
|
|
126
|
-
for (const child of node.namedChildren) {
|
|
127
|
-
if (child.type === "dotted_name") {
|
|
128
|
-
const mod = child.text.trim();
|
|
129
|
-
const alias = mod.split(".").pop() || mod;
|
|
130
|
-
importsInFile.set(alias, { module: mod });
|
|
131
|
-
} else if (child.type === "aliased_import") {
|
|
132
|
-
const orig = child.childForFieldName("name")?.text?.trim();
|
|
133
|
-
const alias = child.childForFieldName("alias")?.text?.trim();
|
|
134
|
-
if (orig && alias) {
|
|
135
|
-
importsInFile.set(alias, { module: orig });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
} else if (node.type === "import_from_statement") {
|
|
140
|
-
const moduleName = node.childForFieldName("module_name")?.text?.trim() || "";
|
|
141
|
-
for (const child of node.namedChildren) {
|
|
142
|
-
if (child === node.childForFieldName("module_name")) continue;
|
|
143
|
-
if (child.type === "dotted_name") {
|
|
144
|
-
const sym = child.text.trim();
|
|
145
|
-
importsInFile.set(sym, { module: moduleName || sym, symbol: sym });
|
|
146
|
-
} else if (child.type === "aliased_import") {
|
|
147
|
-
const orig = child.childForFieldName("name")?.text?.trim();
|
|
148
|
-
const alias = child.childForFieldName("alias")?.text?.trim();
|
|
149
|
-
if (orig && alias) {
|
|
150
|
-
importsInFile.set(alias, { module: moduleName || orig, symbol: orig });
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// 2. Collect Flask App and Blueprint instantiations
|
|
158
|
-
walk(root, (node) => {
|
|
159
|
-
if (node.type !== "assignment" || node.parent?.parent?.type !== "module") return;
|
|
160
|
-
const leftName = node.childForFieldName("left")?.text ?? "";
|
|
161
|
-
const call = node.childForFieldName("right");
|
|
162
|
-
if (call?.type !== "call") return;
|
|
163
|
-
const fnText = call.childForFieldName("function")?.text ?? "";
|
|
164
|
-
const isBlueprint = /Blueprint$/.test(fnText);
|
|
165
|
-
const isApp = /Flask$/.test(fnText);
|
|
166
|
-
if (!isBlueprint && !isApp) return;
|
|
167
|
-
|
|
168
|
-
const args = call.childForFieldName("arguments")?.namedChildren ?? [];
|
|
169
|
-
let bpName = leftName;
|
|
170
|
-
let prefix: string | null = "";
|
|
171
|
-
|
|
172
|
-
if (isBlueprint && args.length > 0) {
|
|
173
|
-
const firstArg = args[0];
|
|
174
|
-
if (firstArg.type !== "keyword_argument") {
|
|
175
|
-
const lit = cleanLiteral(firstArg);
|
|
176
|
-
if (lit) bpName = lit;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const prefixKw = args.find(
|
|
181
|
-
(child) => child.type === "keyword_argument" && child.childForFieldName("name")?.text === "url_prefix"
|
|
182
|
-
);
|
|
183
|
-
if (prefixKw) {
|
|
184
|
-
const value = prefixKw.childForFieldName("value");
|
|
185
|
-
prefix = value?.type === "none" ? "" : cleanLiteral(value) ?? null;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
localBlueprints.set(`${relPath}#${leftName}`, {
|
|
189
|
-
bpName,
|
|
190
|
-
prefix: prefix?.replace(/\/+$/, "") ?? null,
|
|
191
|
-
isApp,
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// 3. Collect register_blueprint calls
|
|
196
|
-
walk(root, (node) => {
|
|
197
|
-
if (node.type !== "call") return;
|
|
198
|
-
const fn = node.childForFieldName("function");
|
|
199
|
-
if (fn?.type !== "attribute" || fn.childForFieldName("attribute")?.text !== "register_blueprint") return;
|
|
200
|
-
const parentVar = fn.childForFieldName("object")?.text ?? "";
|
|
201
|
-
const args = node.childForFieldName("arguments")?.namedChildren ?? [];
|
|
202
|
-
const firstArg = args[0];
|
|
203
|
-
if (!firstArg || firstArg.type === "keyword_argument") return;
|
|
204
|
-
|
|
205
|
-
const targetExpr = firstArg.text.trim();
|
|
206
|
-
const prefixKw = args.find(
|
|
207
|
-
(c) => c.type === "keyword_argument" && c.childForFieldName("name")?.text === "url_prefix"
|
|
89
|
+
if (!content || !/@\s*[A-Za-z_]\w*\.(?:route|get|post|put|patch|delete|options|head|trace)\b|register_blueprint|add_url_rule|Blueprint|Flask/.test(content)) continue;
|
|
90
|
+
|
|
91
|
+
const parsed = await parseSourceWithTreeSitter("python", content, root => {
|
|
92
|
+
const readRoute = (key: string, call: Node, method: string, handler: Node, line: number) => {
|
|
93
|
+
if (pythonCallUsesUnpacking(call)) return;
|
|
94
|
+
const rawPath = cleanLiteral(pythonCallArgument(call, "rule", 0));
|
|
95
|
+
const httpMethods = routeMethods(call, method);
|
|
96
|
+
const actionName = handler.childForFieldName("name")?.text;
|
|
97
|
+
if (rawPath === undefined || !httpMethods.length || !actionName) return;
|
|
98
|
+
|
|
99
|
+
const endpoint = cleanLiteral(pythonCallArgument(call, "endpoint", method === "add_url_rule" ? 1 : undefined));
|
|
100
|
+
const template = handler.childForFieldName("body")?.descendantsOfType("call").find(node =>
|
|
101
|
+
node.childForFieldName("function")?.text === "render_template",
|
|
208
102
|
);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
relPath,
|
|
214
|
-
parentVar,
|
|
215
|
-
targetExpr,
|
|
216
|
-
prefix: incPrefix === undefined ? undefined : incPrefix?.replace(/\/+$/, "") ?? null,
|
|
217
|
-
line: node.startPosition.row + 1,
|
|
103
|
+
allRoutes.push({
|
|
104
|
+
file, relPath, routerKey: key, httpMethods, rawPath, actionName, endpoint,
|
|
105
|
+
lineIndex: line, actionLine: handler.startPosition.row + 1,
|
|
106
|
+
templateEgress: template ? cleanLiteral(pythonCallArgument(template, "template_name_or_list", 0)) : undefined,
|
|
218
107
|
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// 4. Collect route handler definitions
|
|
222
|
-
walk(root, (node) => {
|
|
223
|
-
if (node.type !== "decorated_definition" || node.parent?.type !== "module") return;
|
|
224
|
-
const fn = node.childForFieldName("definition");
|
|
225
|
-
if (fn?.type !== "function_definition") return;
|
|
226
|
-
|
|
227
|
-
for (const decorator of node.namedChildren.filter((child) => child.type === "decorator")) {
|
|
228
|
-
const call = decorator.namedChildren[0];
|
|
229
|
-
const attr = call?.childForFieldName("function");
|
|
230
|
-
if (call?.type !== "call" || attr?.type !== "attribute") continue;
|
|
231
|
-
|
|
232
|
-
const decoratorMethod = attr.childForFieldName("attribute")?.text ?? "";
|
|
233
|
-
const isRoute = decoratorMethod === "route";
|
|
234
|
-
const isShorthand = /^(get|post|put|patch|delete|options|head)$/i.test(decoratorMethod);
|
|
235
|
-
if (!isRoute && !isShorthand) continue;
|
|
236
|
-
|
|
237
|
-
const args = call.childForFieldName("arguments")?.namedChildren ?? [];
|
|
238
|
-
const rawPath = cleanLiteral(args[0]);
|
|
239
|
-
if (rawPath === undefined) continue;
|
|
240
|
-
|
|
241
|
-
const routerVar = attr.childForFieldName("object")?.text ?? "";
|
|
242
|
-
const actionName = fn.childForFieldName("name")?.text ?? "";
|
|
243
|
-
|
|
244
|
-
// Determine HTTP methods
|
|
245
|
-
let httpMethods: string[] = [];
|
|
246
|
-
if (isRoute) {
|
|
247
|
-
const methodsKw = args.find(
|
|
248
|
-
(c) => c.type === "keyword_argument" && c.childForFieldName("name")?.text === "methods"
|
|
249
|
-
);
|
|
250
|
-
if (methodsKw) {
|
|
251
|
-
const val = methodsKw.childForFieldName("value");
|
|
252
|
-
if (val && (val.type === "list" || val.type === "tuple")) {
|
|
253
|
-
for (const m of val.namedChildren) {
|
|
254
|
-
const lit = cleanLiteral(m)?.toUpperCase();
|
|
255
|
-
if (lit) httpMethods.push(lit);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (httpMethods.length === 0) {
|
|
260
|
-
httpMethods = ["GET"];
|
|
261
|
-
}
|
|
262
|
-
} else {
|
|
263
|
-
httpMethods = [decoratorMethod.toUpperCase()];
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Extract optional endpoint
|
|
267
|
-
const endpointKw = args.find(
|
|
268
|
-
(c) => c.type === "keyword_argument" && c.childForFieldName("name")?.text === "endpoint"
|
|
269
|
-
);
|
|
270
|
-
const endpoint = cleanLiteral(endpointKw?.childForFieldName("value"));
|
|
108
|
+
};
|
|
271
109
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
110
|
+
const module = visitPythonRouterModule(root, relPath, {
|
|
111
|
+
constructorCall(key, name, constructor, call) {
|
|
112
|
+
if (!/^(?:flask(?:\.app|\.blueprints)?\.)?(?:Flask|Blueprint)$/.test(constructor)) return false;
|
|
113
|
+
const isApp = constructor.endsWith("Flask");
|
|
114
|
+
const declaredName = isApp ? name : cleanLiteral(pythonCallArgument(call, "name", 0)) ?? name;
|
|
115
|
+
const prefixArg = isApp ? undefined : pythonCallArgument(call, "url_prefix", 5);
|
|
116
|
+
const prefix = !isApp && pythonCallUsesUnpacking(call) ? undefined :
|
|
117
|
+
prefixArg && prefixArg.type !== "none" ? cleanLiteral(prefixArg) : "";
|
|
118
|
+
blueprints.set(key, { name: declaredName, prefix: prefix?.replace(/\/+$/, ""), isApp });
|
|
119
|
+
return true;
|
|
120
|
+
},
|
|
121
|
+
routerCall({ key, call, method, line }, targets) {
|
|
122
|
+
if (method === "add_url_rule") {
|
|
123
|
+
const handler = targets.function(pythonCallArgument(call, "view_func", 2)?.text ?? "");
|
|
124
|
+
if (handler) readRoute(key, call, method, handler, line);
|
|
125
|
+
} else if (method === "register_blueprint") {
|
|
126
|
+
const target = targets.router(pythonCallArgument(call, "blueprint", 0)?.text ?? "");
|
|
127
|
+
if (!target) return;
|
|
128
|
+
const prefixArg = pythonCallArgument(call, "url_prefix");
|
|
129
|
+
const prefix = pythonCallUsesUnpacking(call) ? null :
|
|
130
|
+
prefixArg && prefixArg.type !== "none" ? cleanLiteral(prefixArg)?.replace(/\/+$/, "") ?? null : undefined;
|
|
131
|
+
allRegistrations.push({ file, parent: key, target, prefix });
|
|
288
132
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
rawPath,
|
|
296
|
-
actionName,
|
|
297
|
-
endpoint,
|
|
298
|
-
lineIndex: decorator.startPosition.row + 1,
|
|
299
|
-
actionLine: fn.startPosition.row + 1,
|
|
300
|
-
templateEgress,
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
|
|
133
|
+
},
|
|
134
|
+
decorator({ key, call, method, line }, handler) {
|
|
135
|
+
if (method === "route" || verbs.test(method)) readRoute(key, call, method, handler, line);
|
|
136
|
+
},
|
|
137
|
+
}, signal);
|
|
138
|
+
fileRouters.set(relPath, module.routers);
|
|
305
139
|
return { symbols: [], dependencies: [] };
|
|
306
140
|
});
|
|
307
141
|
|
|
@@ -310,116 +144,19 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
|
|
|
310
144
|
}
|
|
311
145
|
}
|
|
312
146
|
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
let targetKey: string | undefined;
|
|
322
|
-
|
|
323
|
-
if (reg.targetExpr.includes(".")) {
|
|
324
|
-
const [objName, propName] = reg.targetExpr.split(".");
|
|
325
|
-
const binding = importsInFile.get(objName);
|
|
326
|
-
if (binding) {
|
|
327
|
-
const subTarget = binding.module ? `${binding.module}.${binding.symbol || objName}` : objName;
|
|
328
|
-
let res = resolver.resolve(subTarget, reg.file);
|
|
329
|
-
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
330
|
-
targetKey = `${res.targets[0].files[0]}#${propName}`;
|
|
331
|
-
} else if (binding.module) {
|
|
332
|
-
res = resolver.resolve(binding.module, reg.file);
|
|
333
|
-
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
334
|
-
targetKey = `${res.targets[0].files[0]}#${propName}`;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
} else {
|
|
339
|
-
const binding = importsInFile.get(reg.targetExpr);
|
|
340
|
-
if (binding) {
|
|
341
|
-
const subTarget =
|
|
342
|
-
binding.module && binding.symbol ? `${binding.module}.${binding.symbol}` : binding.module || binding.symbol!;
|
|
343
|
-
let res = resolver.resolve(subTarget, reg.file);
|
|
344
|
-
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
345
|
-
targetKey = `${res.targets[0].files[0]}#${binding.symbol || reg.targetExpr}`;
|
|
346
|
-
} else if (binding.module) {
|
|
347
|
-
res = resolver.resolve(binding.module, reg.file);
|
|
348
|
-
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
349
|
-
targetKey = `${res.targets[0].files[0]}#${binding.symbol || reg.targetExpr}`;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
} else {
|
|
353
|
-
// Local blueprint inside same file
|
|
354
|
-
const candidate = `${reg.relPath}#${reg.targetExpr}`;
|
|
355
|
-
if (localBlueprints.has(candidate)) {
|
|
356
|
-
targetKey = candidate;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
147
|
+
const roots = new Map([...blueprints].map(([key, blueprint]) => [key, blueprint.prefix]));
|
|
148
|
+
const mounts = allRegistrations.flatMap(({ file, parent, target, prefix }) => {
|
|
149
|
+
const child = resolvePythonRouterTarget(target, file, resolver, fileRouters);
|
|
150
|
+
const blueprint = child ? blueprints.get(child) : undefined;
|
|
151
|
+
if (!child || !blueprint || blueprint.isApp) return [];
|
|
152
|
+
return [{ parent, child, prefix: prefix === undefined ? blueprint.prefix : prefix ?? undefined }];
|
|
153
|
+
});
|
|
154
|
+
const prefixesByRouter = composeMountPrefixes(roots, mounts, signal);
|
|
360
155
|
|
|
361
|
-
if (targetKey) {
|
|
362
|
-
if (!routerChildren.has(parentKey)) routerChildren.set(parentKey, []);
|
|
363
|
-
routerChildren.get(parentKey)!.push({ childKey: targetKey, prefix: reg.prefix });
|
|
364
|
-
|
|
365
|
-
if (!incomingRegistrations.has(targetKey)) incomingRegistrations.set(targetKey, []);
|
|
366
|
-
incomingRegistrations.get(targetKey)!.push({ parentKey, prefix: reg.prefix });
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// 6. Compute Effective Prefixes for Each Router/Blueprint
|
|
371
|
-
const effectivePrefixesByRouter = new Map<string, string[]>();
|
|
372
|
-
|
|
373
|
-
const allRouterKeys = new Set<string>([
|
|
374
|
-
...localBlueprints.keys(),
|
|
375
|
-
...allRoutes.map((r) => `${r.relPath}#${r.routerVar}`),
|
|
376
|
-
]);
|
|
377
|
-
|
|
378
|
-
// Find root routers
|
|
379
|
-
for (const routerKey of allRouterKeys) {
|
|
380
|
-
const incoming = incomingRegistrations.get(routerKey);
|
|
381
|
-
if (!incoming || incoming.length === 0) {
|
|
382
|
-
const local = localBlueprints.get(routerKey);
|
|
383
|
-
effectivePrefixesByRouter.set(routerKey, local?.prefix === null ? [] : [local?.prefix ?? ""]);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Propagate prefixes along registration edges via BFS
|
|
388
|
-
const queue = Array.from(effectivePrefixesByRouter.keys());
|
|
389
|
-
const visitedEdges = new Set<string>();
|
|
390
|
-
|
|
391
|
-
while (queue.length > 0) {
|
|
392
|
-
const current = queue.shift()!;
|
|
393
|
-
const currentPrefixes = effectivePrefixesByRouter.get(current) ?? [""];
|
|
394
|
-
const children = routerChildren.get(current) ?? [];
|
|
395
|
-
|
|
396
|
-
for (const child of children) {
|
|
397
|
-
const edgeKey = `${current}->${child.childKey}:${child.prefix}`;
|
|
398
|
-
if (visitedEdges.has(edgeKey)) continue;
|
|
399
|
-
visitedEdges.add(edgeKey);
|
|
400
|
-
|
|
401
|
-
const childPrefix = child.prefix === undefined ? localBlueprints.get(child.childKey)?.prefix ?? null : child.prefix;
|
|
402
|
-
const nextPrefixes = childPrefix === null ? [] : currentPrefixes.map((p) => {
|
|
403
|
-
const combined = `${p ? (p.startsWith("/") ? p : `/${p}`) : ""}${
|
|
404
|
-
childPrefix ? (childPrefix.startsWith("/") ? childPrefix : `/${childPrefix}`) : ""
|
|
405
|
-
}`;
|
|
406
|
-
return combined.replace(/\/+/g, "/").replace(/\/+$/, "");
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
const existing = effectivePrefixesByRouter.get(child.childKey) ?? [];
|
|
410
|
-
const merged = Array.from(new Set([...existing, ...nextPrefixes]));
|
|
411
|
-
effectivePrefixesByRouter.set(child.childKey, merged);
|
|
412
|
-
queue.push(child.childKey);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// 7. Generate Vertical Slices (Level 0 – Level 3)
|
|
417
156
|
for (const route of allRoutes) {
|
|
418
|
-
const
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
const bpMeta = localBlueprints.get(routerKey);
|
|
422
|
-
const controllerClass = bpMeta?.bpName || path.basename(route.file, ".py");
|
|
157
|
+
const prefixes = prefixesByRouter.get(route.routerKey) ?? [];
|
|
158
|
+
const bpMeta = blueprints.get(route.routerKey);
|
|
159
|
+
const controllerClass = bpMeta?.name || path.basename(route.file, ".py");
|
|
423
160
|
|
|
424
161
|
for (const prefix of prefixes) {
|
|
425
162
|
const fullUri = normalizeRouteUri(prefix, route.rawPath);
|
|
@@ -456,7 +193,7 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
|
|
|
456
193
|
});
|
|
457
194
|
}
|
|
458
195
|
|
|
459
|
-
const routeName = route.endpoint || (bpMeta ? `${bpMeta.
|
|
196
|
+
const routeName = route.endpoint || (bpMeta ? `${bpMeta.name}.${route.actionName}` : route.actionName);
|
|
460
197
|
|
|
461
198
|
slices.push({
|
|
462
199
|
domain_id: domainId ?? null,
|