@dimassetoid/septum-mcp 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +124 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +122 -0
- package/src/cli/commands/hook.ts +268 -0
- package/src/cli/commands/init.ts +553 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +41 -0
- package/src/cli/commands/topology.ts +161 -0
- package/src/cli/index.ts +167 -0
- package/src/cli/scaffold/harness-config.ts +621 -0
- package/src/cli/templates/hooks.ts +75 -0
- package/src/cli/templates/rules.ts +50 -0
- package/src/cli/templates/skill.ts +51 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +442 -0
- package/src/core/boundary/staged-auditor.ts +58 -0
- package/src/core/config/loader.ts +122 -0
- package/src/core/config/schema.ts +69 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +712 -0
- package/src/core/database/repositories/domain.repository.ts +330 -0
- package/src/core/database/repositories/environment.repository.ts +207 -0
- package/src/core/database/repositories/file.repository.ts +117 -0
- package/src/core/database/repositories/meta.repository.ts +33 -0
- package/src/core/database/repositories/symbol.repository.ts +508 -0
- package/src/core/database/repository.ts +303 -0
- package/src/core/database/schema.ts +154 -0
- package/src/core/discovery/topology-detector.ts +805 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +623 -0
- package/src/core/parser/behavioral-analyzer.ts +119 -0
- package/src/core/parser/boundary-tracker.ts +443 -0
- package/src/core/parser/extractors/base.ts +67 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +244 -0
- package/src/core/parser/extractors/django-semantic.ts +687 -0
- package/src/core/parser/extractors/elysia-semantic.ts +538 -0
- package/src/core/parser/extractors/express-semantic.ts +444 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +736 -0
- package/src/core/parser/extractors/fastify-semantic.ts +774 -0
- package/src/core/parser/extractors/flask-semantic.ts +515 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +611 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +567 -0
- package/src/core/parser/extractors/java.ts +225 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1122 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +368 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +543 -0
- package/src/core/parser/extractors/php.ts +569 -0
- package/src/core/parser/extractors/python.ts +498 -0
- package/src/core/parser/extractors/registry.ts +78 -0
- package/src/core/parser/extractors/ruby.ts +234 -0
- package/src/core/parser/extractors/rust.ts +286 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +22 -0
- package/src/core/parser/extractors/symfony-semantic.ts +354 -0
- package/src/core/parser/extractors/typescript.ts +826 -0
- package/src/core/parser/language-capabilities.ts +71 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +216 -0
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +90 -0
- package/src/core/parser/schema/schema-provider-registry.ts +43 -0
- package/src/core/parser/schema/schema-provider.interface.ts +33 -0
- package/src/core/parser/tree-sitter.ts +63 -0
- package/src/core/parser/wasm-assets.ts +25 -0
- package/src/core/parser/wasm-loader.ts +274 -0
- package/src/core/resolver/call-graph-tracer.ts +724 -0
- package/src/core/resolver/import-resolver.ts +437 -0
- package/src/core/resolver/module-resolver.ts +482 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- package/src/core/resolver/symbol-locator.ts +276 -0
- package/src/core/resolver/symbol-reference.ts +53 -0
- package/src/core/resolver/vertical-slice-tracer.ts +366 -0
- package/src/core/resources/ignore.ts +123 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +62 -0
- package/src/core/resources/work-queue.ts +74 -0
- package/src/core/session/session-manager.ts +107 -0
- package/src/core/telemetry/telemetry.ts +97 -0
- package/src/core/topology/environment-detector.ts +973 -0
- package/src/core/topology/types.ts +83 -0
- package/src/index.ts +21 -0
- package/src/mcp/schemas.ts +1105 -0
- package/src/mcp/server.ts +774 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +387 -0
- package/src/mcp/tools/domain.ts +40 -0
- package/src/mcp/tools/feature.ts +67 -0
- package/src/mcp/tools/get-domain-catalog.ts +226 -0
- package/src/mcp/tools/get-environment-topology.ts +138 -0
- package/src/mcp/tools/get-feature-context.ts +224 -0
- package/src/mcp/tools/get-symbol-hotspots.ts +54 -0
- package/src/mcp/tools/get-symbol-impact.ts +64 -0
- package/src/mcp/tools/get-symbol.ts +175 -0
- package/src/mcp/tools/locate-symbol.ts +196 -0
- package/src/mcp/tools/register-domain.ts +75 -0
- package/src/mcp/tools/register-feature.ts +110 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +93 -0
- package/src/mcp/tools/trace-vertical-slice.ts +80 -0
- package/src/mcp/workspace-manager.ts +159 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +456 -0
- package/src/types/wasm.d.ts +4 -0
- package/src/utils/version-check.ts +209 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
import type Parser from "web-tree-sitter";
|
|
2
|
+
import { parseSourceWithTreeSitter } from "../wasm-loader.ts";
|
|
3
|
+
import { readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
4
|
+
import { isIgnoredDirectory } from "../../resources/ignore.ts";
|
|
5
|
+
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import type { SemanticSliceExtractor, VerticalSliceCandidate } from "./semantic-extractor.interface.ts";
|
|
9
|
+
|
|
10
|
+
interface ExtractedRoute {
|
|
11
|
+
file: string;
|
|
12
|
+
relPath: string;
|
|
13
|
+
routerVar: string;
|
|
14
|
+
httpMethod: string;
|
|
15
|
+
rawPath: string;
|
|
16
|
+
actionName: string;
|
|
17
|
+
params: string;
|
|
18
|
+
lineIndex: number;
|
|
19
|
+
actionLine: number;
|
|
20
|
+
validationSchema?: string;
|
|
21
|
+
guardSymbol?: string;
|
|
22
|
+
dependencies: string[];
|
|
23
|
+
responseModel?: string;
|
|
24
|
+
service?: { symbol: string; line: number };
|
|
25
|
+
model?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ExtractedInclusion {
|
|
29
|
+
file: string;
|
|
30
|
+
relPath: string;
|
|
31
|
+
parentVar: string;
|
|
32
|
+
targetExpr: string;
|
|
33
|
+
prefix: string;
|
|
34
|
+
line: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface ImportBinding {
|
|
38
|
+
module: string;
|
|
39
|
+
symbol?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function cleanLiteral(node: Parser.SyntaxNode | null | undefined): string | undefined {
|
|
43
|
+
if (!node) return undefined;
|
|
44
|
+
if (node.type === "string") {
|
|
45
|
+
const raw = node.text.trim();
|
|
46
|
+
const match = raw.match(/^[rRbBuU]*('''|"""|'|")([\s\S]*?)\1$/);
|
|
47
|
+
if (match) return match[2];
|
|
48
|
+
return raw.replace(/^[rRbBuU]*['"]|['"]$/g, "");
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function normalizeRouteUri(prefix: string, rawPath: string): string {
|
|
54
|
+
const p = (prefix ?? "").trim().replace(/\/+$/, "");
|
|
55
|
+
let r = (rawPath ?? "").trim();
|
|
56
|
+
if (!r.startsWith("/")) r = "/" + r;
|
|
57
|
+
if (r === "/" && p.length > 0) return p + "/";
|
|
58
|
+
if (r === "/" && p.length === 0) return "/";
|
|
59
|
+
const joined = `${p}${r}`;
|
|
60
|
+
return joined.startsWith("/") ? joined : `/${joined}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function extractSchemaType(rawType: string): string | undefined {
|
|
64
|
+
const clean = rawType.replace(/^(?:typing\.)?(?:Optional|List|Union)\[(.*)\]$/, "$1").trim();
|
|
65
|
+
const name = clean.split(/[\[,|]/)[0].trim().replace(/^.*?\./, "");
|
|
66
|
+
if (!name || !/^[A-Z]/.test(name)) return undefined;
|
|
67
|
+
const builtins = new Set([
|
|
68
|
+
"Str", "Int", "Float", "Bool", "Dict", "List", "Set", "Tuple", "Bytes",
|
|
69
|
+
"Optional", "Any", "Union", "Request", "Response", "BackgroundTasks",
|
|
70
|
+
"UploadFile", "Header", "Query", "Path", "Body", "Cookie", "Security", "Session", "Depends", "None"
|
|
71
|
+
]);
|
|
72
|
+
if (builtins.has(name)) return undefined;
|
|
73
|
+
return name;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function extractDependsFromNode(node: Parser.SyntaxNode | null | undefined, out: Array<{ symbol: string; isGuard: boolean }>): void {
|
|
77
|
+
if (!node) return;
|
|
78
|
+
const walk = (n: Parser.SyntaxNode) => {
|
|
79
|
+
if (n.type === "call" && /Depends$/.test(n.childForFieldName("function")?.text ?? "")) {
|
|
80
|
+
const arg = n.childForFieldName("arguments")?.namedChildren[0]?.text?.trim();
|
|
81
|
+
if (arg) {
|
|
82
|
+
const isGuard = /auth|user|token|permission|guard|role|credential/i.test(arg);
|
|
83
|
+
out.push({ symbol: arg, isGuard });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const child of n.namedChildren) walk(child);
|
|
87
|
+
};
|
|
88
|
+
walk(node);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class FastApiSemanticExtractor implements SemanticSliceExtractor {
|
|
92
|
+
public readonly id = "fastapi";
|
|
93
|
+
public readonly name = "FastAPI Semantic Slice Extractor";
|
|
94
|
+
|
|
95
|
+
public canHandle(projectRoot: string, framework?: string): boolean {
|
|
96
|
+
if (framework === "fastapi") return true;
|
|
97
|
+
|
|
98
|
+
// Check configuration manifests
|
|
99
|
+
for (const manifest of ["requirements.txt", "pyproject.toml", "Pipfile", "setup.py"]) {
|
|
100
|
+
const fullPath = path.join(projectRoot, manifest);
|
|
101
|
+
if (fs.existsSync(fullPath)) {
|
|
102
|
+
try {
|
|
103
|
+
const content = fs.readFileSync(fullPath, "utf-8").toLowerCase();
|
|
104
|
+
if (content.includes("fastapi")) return true;
|
|
105
|
+
} catch {}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Check entrypoint files
|
|
110
|
+
for (const entry of ["main.py", "app.py", "api.py", "src/main.py", "app/main.py"]) {
|
|
111
|
+
const fullPath = path.join(projectRoot, entry);
|
|
112
|
+
if (fs.existsSync(fullPath)) {
|
|
113
|
+
try {
|
|
114
|
+
const content = fs.readFileSync(fullPath, "utf-8");
|
|
115
|
+
if (content.includes("from fastapi") || content.includes("import fastapi")) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
} catch {}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public async extractSlices(projectRoot: string, domainId?: number, signal?: AbortSignal): Promise<VerticalSliceCandidate[]> {
|
|
126
|
+
const slices: VerticalSliceCandidate[] = [];
|
|
127
|
+
const pyFiles = this.findPythonFiles(projectRoot);
|
|
128
|
+
const resolver = new ImportResolver(projectRoot);
|
|
129
|
+
|
|
130
|
+
const allRoutes: ExtractedRoute[] = [];
|
|
131
|
+
const allInclusions: ExtractedInclusion[] = [];
|
|
132
|
+
const localRouters = new Map<
|
|
133
|
+
string,
|
|
134
|
+
{ prefix: string; isApp: boolean; guards?: string[]; dependencies?: string[] }
|
|
135
|
+
>();
|
|
136
|
+
const fileImports = new Map<string, Map<string, ImportBinding>>();
|
|
137
|
+
|
|
138
|
+
for (const file of pyFiles) {
|
|
139
|
+
signal?.throwIfAborted();
|
|
140
|
+
const relPath = path.relative(projectRoot, file).replace(/\\/g, "/");
|
|
141
|
+
const content = readOptionalSourceFile(file, "utf-8");
|
|
142
|
+
if (!content || (!content.includes("@") && !content.includes("include_router") && !content.includes("APIRouter") && !content.includes("FastAPI"))) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const importsInFile = new Map<string, ImportBinding>();
|
|
147
|
+
fileImports.set(relPath, importsInFile);
|
|
148
|
+
|
|
149
|
+
const parsed = await parseSourceWithTreeSitter("python", content, (root) => {
|
|
150
|
+
const walk = (node: Parser.SyntaxNode, visit: (node: Parser.SyntaxNode) => void) => {
|
|
151
|
+
visit(node);
|
|
152
|
+
for (const child of node.namedChildren) walk(child, visit);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// 1. Collect import statements
|
|
156
|
+
walk(root, (node) => {
|
|
157
|
+
if (node.type === "import_statement") {
|
|
158
|
+
for (const child of node.namedChildren) {
|
|
159
|
+
if (child.type === "dotted_name") {
|
|
160
|
+
const mod = child.text.trim();
|
|
161
|
+
const alias = mod.split(".").pop() || mod;
|
|
162
|
+
importsInFile.set(alias, { module: mod });
|
|
163
|
+
} else if (child.type === "aliased_import") {
|
|
164
|
+
const orig = child.childForFieldName("name")?.text?.trim();
|
|
165
|
+
const alias = child.childForFieldName("alias")?.text?.trim();
|
|
166
|
+
if (orig && alias) {
|
|
167
|
+
importsInFile.set(alias, { module: orig });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
} else if (node.type === "import_from_statement") {
|
|
172
|
+
const moduleName = node.childForFieldName("module_name")?.text?.trim() || "";
|
|
173
|
+
for (const child of node.namedChildren) {
|
|
174
|
+
if (child === node.childForFieldName("module_name")) continue;
|
|
175
|
+
if (child.type === "dotted_name") {
|
|
176
|
+
const sym = child.text.trim();
|
|
177
|
+
importsInFile.set(sym, { module: moduleName || sym, symbol: sym });
|
|
178
|
+
} else if (child.type === "aliased_import") {
|
|
179
|
+
const orig = child.childForFieldName("name")?.text?.trim();
|
|
180
|
+
const alias = child.childForFieldName("alias")?.text?.trim();
|
|
181
|
+
if (orig && alias) {
|
|
182
|
+
importsInFile.set(alias, { module: moduleName || orig, symbol: orig });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// 2. Collect router & app definitions
|
|
190
|
+
walk(root, (node) => {
|
|
191
|
+
if (node.type !== "assignment" || node.parent?.parent?.type !== "module") return;
|
|
192
|
+
const leftName = node.childForFieldName("left")?.text ?? "";
|
|
193
|
+
const call = node.childForFieldName("right");
|
|
194
|
+
if (call?.type !== "call") return;
|
|
195
|
+
const fnText = call.childForFieldName("function")?.text ?? "";
|
|
196
|
+
const isRouter = /APIRouter$/.test(fnText);
|
|
197
|
+
const isApp = /FastAPI$/.test(fnText);
|
|
198
|
+
if (!isRouter && !isApp) return;
|
|
199
|
+
|
|
200
|
+
const args = call.childForFieldName("arguments")?.namedChildren ?? [];
|
|
201
|
+
const keyword = args.find(
|
|
202
|
+
(child) => child.type === "keyword_argument" && child.childForFieldName("name")?.text === "prefix"
|
|
203
|
+
);
|
|
204
|
+
const prefix = cleanLiteral(keyword?.childForFieldName("value")) ?? "";
|
|
205
|
+
|
|
206
|
+
// Router-level dependencies: router = APIRouter(dependencies=[Depends(...)])
|
|
207
|
+
const depsKw = args.find(
|
|
208
|
+
(child) => child.type === "keyword_argument" && child.childForFieldName("name")?.text === "dependencies"
|
|
209
|
+
);
|
|
210
|
+
const routerGuards: string[] = [];
|
|
211
|
+
const routerDeps: string[] = [];
|
|
212
|
+
if (depsKw) {
|
|
213
|
+
const extracted: Array<{ symbol: string; isGuard: boolean }> = [];
|
|
214
|
+
extractDependsFromNode(depsKw.childForFieldName("value"), extracted);
|
|
215
|
+
for (const item of extracted) {
|
|
216
|
+
if (item.isGuard) routerGuards.push(item.symbol);
|
|
217
|
+
else routerDeps.push(item.symbol);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
localRouters.set(`${relPath}#${leftName}`, {
|
|
222
|
+
prefix: prefix.replace(/\/+$/, ""),
|
|
223
|
+
isApp,
|
|
224
|
+
guards: routerGuards,
|
|
225
|
+
dependencies: routerDeps,
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// 3. Collect include_router calls
|
|
230
|
+
walk(root, (node) => {
|
|
231
|
+
if (node.type !== "call") return;
|
|
232
|
+
const fn = node.childForFieldName("function");
|
|
233
|
+
if (fn?.type !== "attribute" || fn.childForFieldName("attribute")?.text !== "include_router") return;
|
|
234
|
+
const parentVar = fn.childForFieldName("object")?.text ?? "";
|
|
235
|
+
const args = node.childForFieldName("arguments")?.namedChildren ?? [];
|
|
236
|
+
const firstArg = args[0];
|
|
237
|
+
if (!firstArg || firstArg.type === "keyword_argument") return;
|
|
238
|
+
|
|
239
|
+
const targetExpr = firstArg.text.trim();
|
|
240
|
+
const prefixKw = args.find(
|
|
241
|
+
(c) => c.type === "keyword_argument" && c.childForFieldName("name")?.text === "prefix"
|
|
242
|
+
);
|
|
243
|
+
const incPrefix = cleanLiteral(prefixKw?.childForFieldName("value")) ?? "";
|
|
244
|
+
allInclusions.push({
|
|
245
|
+
file,
|
|
246
|
+
relPath,
|
|
247
|
+
parentVar,
|
|
248
|
+
targetExpr,
|
|
249
|
+
prefix: incPrefix.replace(/\/+$/, ""),
|
|
250
|
+
line: node.startPosition.row + 1,
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// 4. Collect route handler definitions
|
|
255
|
+
walk(root, (node) => {
|
|
256
|
+
if (node.type !== "decorated_definition" || node.parent?.type !== "module") return;
|
|
257
|
+
const fn = node.childForFieldName("definition");
|
|
258
|
+
if (fn?.type !== "function_definition") return;
|
|
259
|
+
|
|
260
|
+
for (const decorator of node.namedChildren.filter((child) => child.type === "decorator")) {
|
|
261
|
+
const call = decorator.namedChildren[0];
|
|
262
|
+
const attr = call?.childForFieldName("function");
|
|
263
|
+
if (call?.type !== "call" || attr?.type !== "attribute") continue;
|
|
264
|
+
const method = attr.childForFieldName("attribute")?.text ?? "";
|
|
265
|
+
if (!/^(get|post|put|patch|delete|options|head)$/.test(method)) continue;
|
|
266
|
+
|
|
267
|
+
const args = call.childForFieldName("arguments")?.namedChildren ?? [];
|
|
268
|
+
const rawPath = cleanLiteral(args[0]);
|
|
269
|
+
if (rawPath === undefined) continue;
|
|
270
|
+
|
|
271
|
+
const routerVar = attr.childForFieldName("object")?.text ?? "";
|
|
272
|
+
const actionName = fn.childForFieldName("name")?.text ?? "";
|
|
273
|
+
const paramsText = fn.childForFieldName("parameters")?.text ?? "";
|
|
274
|
+
|
|
275
|
+
// Extract Pydantic validation schema from typed parameters
|
|
276
|
+
let validationSchema: string | undefined;
|
|
277
|
+
const paramsNode = fn.childForFieldName("parameters");
|
|
278
|
+
if (paramsNode) {
|
|
279
|
+
for (const param of paramsNode.namedChildren) {
|
|
280
|
+
if (param.type === "typed_parameter" || param.type === "typed_default_parameter") {
|
|
281
|
+
const typeNode = param.childForFieldName("type");
|
|
282
|
+
if (typeNode) {
|
|
283
|
+
const detected = extractSchemaType(typeNode.text);
|
|
284
|
+
if (detected && !validationSchema) {
|
|
285
|
+
validationSchema = detected;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Fallback schema regex
|
|
293
|
+
if (!validationSchema) {
|
|
294
|
+
const schemaMatch = paramsText.match(
|
|
295
|
+
/[a-zA-Z0-9_]+\s*:\s*([A-Z][a-zA-Z0-9_]*(?:Schema|In|Request|Create|Update|DTO|Body))/
|
|
296
|
+
);
|
|
297
|
+
if (schemaMatch) validationSchema = schemaMatch[1];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Extract guards and dependencies from Depends(...)
|
|
301
|
+
let guardSymbol: string | undefined;
|
|
302
|
+
const inboundDeps: string[] = [];
|
|
303
|
+
if (paramsNode) {
|
|
304
|
+
for (const param of paramsNode.namedChildren) {
|
|
305
|
+
let valNode: Parser.SyntaxNode | null = null;
|
|
306
|
+
if (param.type === "typed_default_parameter" || param.type === "default_parameter") {
|
|
307
|
+
valNode = param.childForFieldName("value");
|
|
308
|
+
}
|
|
309
|
+
if (valNode?.type === "call" && /Depends$/.test(valNode.childForFieldName("function")?.text ?? "")) {
|
|
310
|
+
const depArg = valNode.childForFieldName("arguments")?.namedChildren[0];
|
|
311
|
+
const sym = depArg?.text?.trim();
|
|
312
|
+
if (sym) {
|
|
313
|
+
if (/auth|user|token|permission|guard|role|credential/i.test(sym)) {
|
|
314
|
+
guardSymbol = sym;
|
|
315
|
+
} else {
|
|
316
|
+
inboundDeps.push(sym);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Fallback guard regex
|
|
324
|
+
if (!guardSymbol) {
|
|
325
|
+
const guardMatch = paramsText.match(
|
|
326
|
+
/Depends\s*\(\s*([a-zA-Z0-9_]*(?:auth|user|token|permission|guard)[a-zA-Z0-9_]*)\s*\)/i
|
|
327
|
+
);
|
|
328
|
+
if (guardMatch) guardSymbol = guardMatch[1];
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Extract dependencies from decorator: @router.get("/", dependencies=[Depends(...)])
|
|
332
|
+
const decDepsKw = args.find(
|
|
333
|
+
(c) => c.type === "keyword_argument" && c.childForFieldName("name")?.text === "dependencies"
|
|
334
|
+
);
|
|
335
|
+
if (decDepsKw) {
|
|
336
|
+
const decExtracted: Array<{ symbol: string; isGuard: boolean }> = [];
|
|
337
|
+
extractDependsFromNode(decDepsKw.childForFieldName("value"), decExtracted);
|
|
338
|
+
for (const item of decExtracted) {
|
|
339
|
+
if (item.isGuard && !guardSymbol) guardSymbol = item.symbol;
|
|
340
|
+
else inboundDeps.push(item.symbol);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Extract response_model
|
|
345
|
+
const rmKw = args.find(
|
|
346
|
+
(c) => c.type === "keyword_argument" && c.childForFieldName("name")?.text === "response_model"
|
|
347
|
+
);
|
|
348
|
+
const responseModel = rmKw?.childForFieldName("value")?.text?.trim();
|
|
349
|
+
|
|
350
|
+
const route: ExtractedRoute = {
|
|
351
|
+
file,
|
|
352
|
+
relPath,
|
|
353
|
+
routerVar,
|
|
354
|
+
httpMethod: method.toUpperCase(),
|
|
355
|
+
rawPath,
|
|
356
|
+
actionName,
|
|
357
|
+
params: paramsText,
|
|
358
|
+
lineIndex: decorator.startPosition.row + 1,
|
|
359
|
+
actionLine: fn.startPosition.row + 1,
|
|
360
|
+
validationSchema,
|
|
361
|
+
guardSymbol,
|
|
362
|
+
dependencies: inboundDeps,
|
|
363
|
+
responseModel,
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const body = fn.childForFieldName("body");
|
|
367
|
+
if (body) {
|
|
368
|
+
walk(body, (child) => {
|
|
369
|
+
if (child.type !== "call") return;
|
|
370
|
+
const called = child.childForFieldName("function")?.text ?? "";
|
|
371
|
+
const service = called.match(/^([a-zA-Z0-9_]+_service|[A-Z][a-zA-Z0-9_]*Service)\.([a-zA-Z0-9_]+)$/);
|
|
372
|
+
if (service && !route.service) {
|
|
373
|
+
route.service = { symbol: `${service[1]}::${service[2]}`, line: child.startPosition.row + 1 };
|
|
374
|
+
}
|
|
375
|
+
if (/^(db\.(add|query)|session\.query)$/.test(called)) {
|
|
376
|
+
const argument = child.childForFieldName("arguments")?.namedChildren[0];
|
|
377
|
+
if (argument?.type === "identifier" && /^[A-Z]/.test(argument.text)) {
|
|
378
|
+
route.model = argument.text;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
allRoutes.push(route);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
return { symbols: [], dependencies: [] };
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
if (parsed?.status !== "parsed") {
|
|
392
|
+
throw new Error(`FastAPI AST unavailable or degraded: ${relPath}`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// 5. Build Inclusion Graph and Resolve Cross-File Router Targets
|
|
397
|
+
// Adjacency: parentKey -> Array<{ childKey: string; prefix: string }>
|
|
398
|
+
const routerChildren = new Map<string, Array<{ childKey: string; prefix: string }>>();
|
|
399
|
+
const incomingInclusions = new Map<string, Array<{ parentKey: string; prefix: string }>>();
|
|
400
|
+
|
|
401
|
+
for (const inc of allInclusions) {
|
|
402
|
+
const parentKey = `${inc.relPath}#${inc.parentVar}`;
|
|
403
|
+
const importsInFile = fileImports.get(inc.relPath) ?? new Map<string, ImportBinding>();
|
|
404
|
+
|
|
405
|
+
let targetKey: string | undefined;
|
|
406
|
+
|
|
407
|
+
if (inc.targetExpr.includes(".")) {
|
|
408
|
+
const [objName, propName] = inc.targetExpr.split(".");
|
|
409
|
+
const binding = importsInFile.get(objName);
|
|
410
|
+
if (binding) {
|
|
411
|
+
// Try resolving submodule target first: e.g. from app.routers import orders -> orders.router
|
|
412
|
+
const subTarget = binding.module ? `${binding.module}.${binding.symbol || objName}` : objName;
|
|
413
|
+
let res = resolver.resolve(subTarget, inc.file);
|
|
414
|
+
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
415
|
+
targetKey = `${res.targets[0].files[0]}#${propName}`;
|
|
416
|
+
} else if (binding.module) {
|
|
417
|
+
res = resolver.resolve(binding.module, inc.file);
|
|
418
|
+
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
419
|
+
targetKey = `${res.targets[0].files[0]}#${propName}`;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
} else {
|
|
424
|
+
const binding = importsInFile.get(inc.targetExpr);
|
|
425
|
+
if (binding) {
|
|
426
|
+
// Try resolving submoduleTarget first (binding.module + "." + binding.symbol)
|
|
427
|
+
const subTarget = binding.module && binding.symbol ? `${binding.module}.${binding.symbol}` : (binding.module || binding.symbol!);
|
|
428
|
+
let res = resolver.resolve(subTarget, inc.file);
|
|
429
|
+
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
430
|
+
targetKey = `${res.targets[0].files[0]}#router`;
|
|
431
|
+
} else if (binding.module) {
|
|
432
|
+
res = resolver.resolve(binding.module, inc.file);
|
|
433
|
+
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
434
|
+
targetKey = `${res.targets[0].files[0]}#${binding.symbol || "router"}`;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
} else {
|
|
438
|
+
// Local router inside same file
|
|
439
|
+
const candidate = `${inc.relPath}#${inc.targetExpr}`;
|
|
440
|
+
if (localRouters.has(candidate)) {
|
|
441
|
+
targetKey = candidate;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (targetKey) {
|
|
447
|
+
if (!routerChildren.has(parentKey)) routerChildren.set(parentKey, []);
|
|
448
|
+
routerChildren.get(parentKey)!.push({ childKey: targetKey, prefix: inc.prefix });
|
|
449
|
+
|
|
450
|
+
if (!incomingInclusions.has(targetKey)) incomingInclusions.set(targetKey, []);
|
|
451
|
+
incomingInclusions.get(targetKey)!.push({ parentKey, prefix: inc.prefix });
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// 6. Compute Effective Prefixes for Each Router
|
|
456
|
+
// A router is a root if it has no incoming inclusions or is an explicit FastAPI app
|
|
457
|
+
const effectivePrefixesByRouter = new Map<string, string[]>();
|
|
458
|
+
|
|
459
|
+
const allRouterKeys = new Set<string>([
|
|
460
|
+
...localRouters.keys(),
|
|
461
|
+
...allRoutes.map((r) => `${r.relPath}#${r.routerVar}`),
|
|
462
|
+
]);
|
|
463
|
+
|
|
464
|
+
// Find root routers
|
|
465
|
+
for (const routerKey of allRouterKeys) {
|
|
466
|
+
const incoming = incomingInclusions.get(routerKey);
|
|
467
|
+
if (!incoming || incoming.length === 0) {
|
|
468
|
+
const local = localRouters.get(routerKey)?.prefix ?? "";
|
|
469
|
+
effectivePrefixesByRouter.set(routerKey, [local]);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// Propagate prefixes along inclusion edges
|
|
474
|
+
const queue = Array.from(effectivePrefixesByRouter.keys());
|
|
475
|
+
const visitedEdges = new Set<string>();
|
|
476
|
+
|
|
477
|
+
while (queue.length > 0) {
|
|
478
|
+
const current = queue.shift()!;
|
|
479
|
+
const currentPrefixes = effectivePrefixesByRouter.get(current) ?? [""];
|
|
480
|
+
const children = routerChildren.get(current) ?? [];
|
|
481
|
+
|
|
482
|
+
for (const child of children) {
|
|
483
|
+
const edgeKey = `${current}->${child.childKey}:${child.prefix}`;
|
|
484
|
+
if (visitedEdges.has(edgeKey)) continue;
|
|
485
|
+
visitedEdges.add(edgeKey);
|
|
486
|
+
|
|
487
|
+
const childLocal = localRouters.get(child.childKey)?.prefix ?? "";
|
|
488
|
+
const nextPrefixes = currentPrefixes.map((p) => {
|
|
489
|
+
const combined = `${p ? (p.startsWith("/") ? p : `/${p}`) : ""}${child.prefix ? (child.prefix.startsWith("/") ? child.prefix : `/${child.prefix}`) : ""}${childLocal ? (childLocal.startsWith("/") ? childLocal : `/${childLocal}`) : ""}`;
|
|
490
|
+
return combined.replace(/\/+/g, "/").replace(/\/+$/, "");
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
const existing = effectivePrefixesByRouter.get(child.childKey) ?? [];
|
|
494
|
+
const merged = Array.from(new Set([...existing, ...nextPrefixes]));
|
|
495
|
+
effectivePrefixesByRouter.set(child.childKey, merged);
|
|
496
|
+
queue.push(child.childKey);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// 7. Generate Vertical Slices
|
|
501
|
+
for (const route of allRoutes) {
|
|
502
|
+
const routerKey = `${route.relPath}#${route.routerVar}`;
|
|
503
|
+
let prefixes = effectivePrefixesByRouter.get(routerKey);
|
|
504
|
+
if (!prefixes || prefixes.length === 0) {
|
|
505
|
+
prefixes = [localRouters.get(routerKey)?.prefix ?? ""];
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
for (const prefix of prefixes) {
|
|
509
|
+
const fullUri = normalizeRouteUri(prefix, route.rawPath);
|
|
510
|
+
|
|
511
|
+
const chain: Array<{ stage: string; symbol: string; file?: string; line?: number; description?: string }> = [
|
|
512
|
+
{
|
|
513
|
+
stage: "ingress",
|
|
514
|
+
symbol: `${route.httpMethod} ${fullUri}`,
|
|
515
|
+
file: route.relPath,
|
|
516
|
+
line: route.lineIndex,
|
|
517
|
+
description: `FastAPI Route: ${route.httpMethod} ${fullUri}`,
|
|
518
|
+
},
|
|
519
|
+
];
|
|
520
|
+
|
|
521
|
+
const routerMeta = localRouters.get(routerKey);
|
|
522
|
+
const effectiveGuards = Array.from(new Set([
|
|
523
|
+
...(route.guardSymbol ? [route.guardSymbol] : []),
|
|
524
|
+
...(routerMeta?.guards ?? []),
|
|
525
|
+
]));
|
|
526
|
+
const effectiveDeps = Array.from(new Set([
|
|
527
|
+
...route.dependencies,
|
|
528
|
+
...(routerMeta?.dependencies ?? []),
|
|
529
|
+
]));
|
|
530
|
+
|
|
531
|
+
for (const guard of effectiveGuards) {
|
|
532
|
+
chain.push({
|
|
533
|
+
stage: "guard",
|
|
534
|
+
symbol: guard,
|
|
535
|
+
description: `Auth / Security Dependency: ${guard}`,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (route.validationSchema) {
|
|
540
|
+
chain.push({
|
|
541
|
+
stage: "validation",
|
|
542
|
+
symbol: route.validationSchema,
|
|
543
|
+
description: `Pydantic Schema Validation: ${route.validationSchema}`,
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const controllerSymbol = `${path.basename(route.file, ".py")}::${route.actionName}`;
|
|
548
|
+
chain.push({
|
|
549
|
+
stage: "controller",
|
|
550
|
+
symbol: controllerSymbol,
|
|
551
|
+
file: route.relPath,
|
|
552
|
+
line: route.actionLine,
|
|
553
|
+
description: `FastAPI Route Handler: ${route.actionName}`,
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
for (const dep of effectiveDeps) {
|
|
557
|
+
chain.push({
|
|
558
|
+
stage: "dependency",
|
|
559
|
+
symbol: dep,
|
|
560
|
+
description: `FastAPI Inbound Dependency: ${dep}`,
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (route.service) {
|
|
565
|
+
const serviceName = route.service.symbol.split("::")[0];
|
|
566
|
+
const serviceMethod = route.service.symbol.split("::")[1];
|
|
567
|
+
const importsInFile = fileImports.get(route.relPath);
|
|
568
|
+
const binding = importsInFile?.get(serviceName);
|
|
569
|
+
let serviceFile: string | undefined;
|
|
570
|
+
let serviceLine: number = route.service.line;
|
|
571
|
+
let persistenceModel: { name: string; file?: string; line?: number } | undefined;
|
|
572
|
+
|
|
573
|
+
if (binding?.module) {
|
|
574
|
+
const subTarget = binding.symbol ? `${binding.module}.${binding.symbol}` : binding.module;
|
|
575
|
+
let res = resolver.resolve(subTarget, route.file);
|
|
576
|
+
if (res.status !== "resolved" && binding.module) {
|
|
577
|
+
res = resolver.resolve(binding.module, route.file);
|
|
578
|
+
}
|
|
579
|
+
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
580
|
+
serviceFile = res.targets[0].files[0];
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (serviceFile) {
|
|
585
|
+
const fullServicePath = path.resolve(projectRoot, serviceFile);
|
|
586
|
+
const serviceContent = readOptionalSourceFile(fullServicePath, "utf-8");
|
|
587
|
+
if (serviceContent) {
|
|
588
|
+
const fnMatch = new RegExp(`(?:def|async\\s+def)\\s+${serviceMethod}\\s*\\(`).exec(serviceContent);
|
|
589
|
+
if (fnMatch) {
|
|
590
|
+
serviceLine = serviceContent.slice(0, fnMatch.index).split("\n").length;
|
|
591
|
+
}
|
|
592
|
+
// Scan service for ORM persistence (SQLAlchemy, Tortoise, SQLModel)
|
|
593
|
+
let modelName: string | undefined;
|
|
594
|
+
const directOrmMatch =
|
|
595
|
+
serviceContent.match(/(?:db\.(?:add|query)|session\.(?:query|add)|select)\s*\(\s*([A-Z][a-zA-Z0-9_]+)/) ||
|
|
596
|
+
serviceContent.match(/\b([A-Z][a-zA-Z0-9_]+)\.(?:create|filter|get|save|all)\s*\(/);
|
|
597
|
+
if (directOrmMatch) {
|
|
598
|
+
modelName = directOrmMatch[1];
|
|
599
|
+
} else {
|
|
600
|
+
const varAddMatch = serviceContent.match(/(?:db|session)\.add\s*\(\s*([a-zA-Z0-9_]+)\s*\)/);
|
|
601
|
+
if (varAddMatch) {
|
|
602
|
+
const varName = varAddMatch[1];
|
|
603
|
+
const instMatch = serviceContent.match(new RegExp(`\\b${varName}\\s*=\\s*([A-Z][a-zA-Z0-9_]+)\\s*\\(`));
|
|
604
|
+
if (instMatch) {
|
|
605
|
+
modelName = instMatch[1];
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (!modelName) {
|
|
609
|
+
const impMatch = serviceContent.match(/from\s+[a-zA-Z0-9_.]+\s+import\s+[^\\n]*\b([A-Z][a-zA-Z0-9_]+)\b/);
|
|
610
|
+
if (impMatch && serviceContent.includes("db.add") && new RegExp(`\\b${impMatch[1]}\\s*\\(`).test(serviceContent)) {
|
|
611
|
+
modelName = impMatch[1];
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (modelName) {
|
|
617
|
+
let modelFile: string | undefined;
|
|
618
|
+
const modelImportMatch = serviceContent.match(
|
|
619
|
+
new RegExp(`from\\s+([a-zA-Z0-9_.]+)\\s+import\\s+[^\\n]*\\b${modelName}\\b`)
|
|
620
|
+
);
|
|
621
|
+
if (modelImportMatch) {
|
|
622
|
+
const mRes = resolver.resolve(modelImportMatch[1], fullServicePath);
|
|
623
|
+
if (mRes.status === "resolved" && mRes.targets[0]?.files?.[0]) {
|
|
624
|
+
modelFile = mRes.targets[0].files[0];
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
persistenceModel = { name: modelName, file: modelFile };
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
chain.push({
|
|
633
|
+
stage: "service",
|
|
634
|
+
symbol: route.service.symbol,
|
|
635
|
+
file: serviceFile || route.relPath,
|
|
636
|
+
line: serviceLine,
|
|
637
|
+
description: serviceFile
|
|
638
|
+
? "Domain Service Invocation"
|
|
639
|
+
: "Syntactic member call; receiver binding and runtime execution unproven",
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
if (persistenceModel) {
|
|
643
|
+
chain.push({
|
|
644
|
+
stage: "model",
|
|
645
|
+
symbol: persistenceModel.name,
|
|
646
|
+
...(persistenceModel.file ? { file: persistenceModel.file } : {}),
|
|
647
|
+
description: "SQLAlchemy / ORM Model Persistence",
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (route.model && !chain.some((n) => n.stage === "model")) {
|
|
653
|
+
const importsInFile = fileImports.get(route.relPath);
|
|
654
|
+
const binding = importsInFile?.get(route.model);
|
|
655
|
+
let modelFile: string | undefined;
|
|
656
|
+
if (binding?.module) {
|
|
657
|
+
const mRes = resolver.resolve(binding.module, route.file);
|
|
658
|
+
if (mRes.status === "resolved" && mRes.targets[0]?.files?.[0]) {
|
|
659
|
+
modelFile = mRes.targets[0].files[0];
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
chain.push({
|
|
663
|
+
stage: "model",
|
|
664
|
+
symbol: route.model,
|
|
665
|
+
...(modelFile ? { file: modelFile } : {}),
|
|
666
|
+
description: modelFile ? "SQLAlchemy / ORM Model Persistence" : "ORM argument hint; persistence unproven",
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if (route.responseModel) {
|
|
671
|
+
chain.push({
|
|
672
|
+
stage: "response_schema",
|
|
673
|
+
symbol: route.responseModel,
|
|
674
|
+
description: `FastAPI Response Model: ${route.responseModel}`,
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
const evidencedChain = chain.map((node) => ({
|
|
679
|
+
...node,
|
|
680
|
+
relationship: {
|
|
681
|
+
kind:
|
|
682
|
+
node.stage === "ingress" || node.stage === "controller"
|
|
683
|
+
? "route_binding"
|
|
684
|
+
: node.stage === "validation" || node.stage === "model" || node.stage === "response_schema"
|
|
685
|
+
? "schema_binding"
|
|
686
|
+
: "calls",
|
|
687
|
+
derivation: node.file && node.line ? "source" : "inferred",
|
|
688
|
+
source: node.file && node.line ? { file: node.file, line: node.line } : undefined,
|
|
689
|
+
reason: node.description ?? "static adapter evidence",
|
|
690
|
+
},
|
|
691
|
+
}));
|
|
692
|
+
|
|
693
|
+
slices.push({
|
|
694
|
+
domain_id: domainId ?? null,
|
|
695
|
+
feature_key: null,
|
|
696
|
+
http_method: route.httpMethod,
|
|
697
|
+
route_uri: fullUri,
|
|
698
|
+
route_name: `${route.routerVar}.${route.actionName}`,
|
|
699
|
+
controller_class: path.basename(route.file, ".py"),
|
|
700
|
+
action_name: route.actionName,
|
|
701
|
+
controller_file: route.relPath,
|
|
702
|
+
controller_line: route.actionLine,
|
|
703
|
+
architecture_style: "fastapi-api",
|
|
704
|
+
entry_kind: "http_route",
|
|
705
|
+
execution_chain_json: JSON.stringify(evidencedChain),
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
return slices;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
private findPythonFiles(dir: string): string[] {
|
|
714
|
+
const results: string[] = [];
|
|
715
|
+
const traverse = (currentDir: string) => {
|
|
716
|
+
if (!fs.existsSync(currentDir)) return;
|
|
717
|
+
try {
|
|
718
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
719
|
+
for (const entry of entries) {
|
|
720
|
+
if (isIgnoredDirectory(entry.name)) continue;
|
|
721
|
+
|
|
722
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
723
|
+
if (entry.isDirectory()) {
|
|
724
|
+
traverse(fullPath);
|
|
725
|
+
} else if (entry.isFile() && entry.name.endsWith(".py")) {
|
|
726
|
+
results.push(fullPath);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
} catch {}
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
traverse(dir);
|
|
733
|
+
return results;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|