@dimassetoid/septum-mcp 0.2.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -45
- package/package.json +8 -6
- package/src/cli/commands/check.ts +41 -26
- package/src/cli/commands/hook.ts +77 -105
- package/src/cli/commands/init.ts +35 -9
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +35 -9
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +15 -51
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +51 -27
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +46 -35
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +299 -178
- package/src/core/boundary/staged-auditor.ts +188 -34
- package/src/core/config/domain-ownership.ts +47 -0
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +82 -54
- package/src/core/config/schema.ts +24 -46
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +326 -543
- package/src/core/database/repositories/domain.repository.ts +48 -4
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -259
- package/src/core/database/repository.ts +138 -24
- package/src/core/database/schema.ts +28 -33
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +269 -0
- package/src/core/discovery/topology-detector.ts +153 -170
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +378 -212
- package/src/core/parser/behavioral-analyzer.ts +26 -22
- package/src/core/parser/boundary-tracker.ts +15 -0
- package/src/core/parser/extractors/base.ts +16 -4
- package/src/core/parser/extractors/csharp.ts +9 -5
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +400 -516
- package/src/core/parser/extractors/elysia-semantic.ts +172 -496
- package/src/core/parser/extractors/express-semantic.ts +195 -398
- package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
- package/src/core/parser/extractors/fastify-semantic.ts +216 -732
- package/src/core/parser/extractors/flask-semantic.ts +92 -388
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +210 -508
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -530
- package/src/core/parser/extractors/java.ts +7 -5
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +169 -333
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +17 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +9 -8
- package/src/core/parser/extractors/registry.ts +28 -5
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +10 -7
- package/src/core/parser/extractors/rust.ts +35 -17
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +75 -262
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +36 -216
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +23 -7
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
- package/src/core/parser/schema/schema-provider-registry.ts +1 -3
- package/src/core/parser/schema/schema-provider.interface.ts +2 -1
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +375 -311
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +162 -181
- package/src/core/resolver/interpretation-inputs.ts +65 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +133 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +74 -0
- package/src/core/resolver/module-resolver.ts +18 -7
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +94 -0
- package/src/core/resolver/slice-format.ts +22 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +477 -0
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +57 -278
- package/src/core/resources/ignore.ts +21 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +116 -0
- package/src/core/retrieval/context.ts +457 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/source-context.ts +448 -0
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +293 -0
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +225 -37
- package/src/index.ts +0 -3
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +253 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -1105
- package/src/mcp/server.ts +263 -597
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +69 -4
- package/src/mcp/tools/map.ts +126 -0
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +480 -26
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +102 -18
- package/src/mcp/workspace-watcher.ts +38 -19
- package/src/types/index.ts +47 -53
- package/src/cli/commands/topology.ts +0 -161
- package/src/core/database/repositories/environment.repository.ts +0 -207
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
- package/src/core/session/session-manager.ts +0 -107
- package/src/core/topology/environment-detector.ts +0 -973
- package/src/core/topology/types.ts +0 -83
- package/src/mcp/tools/check-boundary.ts +0 -387
- package/src/mcp/tools/domain.ts +0 -40
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-domain-catalog.ts +0 -226
- package/src/mcp/tools/get-environment-topology.ts +0 -138
- package/src/mcp/tools/get-feature-context.ts +0 -224
- package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
- package/src/mcp/tools/get-symbol-impact.ts +0 -64
- package/src/mcp/tools/get-symbol.ts +0 -175
- package/src/mcp/tools/locate-symbol.ts +0 -196
- package/src/mcp/tools/register-domain.ts +0 -75
- package/src/mcp/tools/register-feature.ts +0 -110
- package/src/mcp/tools/trace-vertical-slice.ts +0 -80
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { blankCommentsAndStrings } from "./boundary-tracker.ts";
|
|
1
2
|
export interface MethodBehavioralSummary {
|
|
3
|
+
analysis: "lexical_heuristic";
|
|
2
4
|
guards: string[];
|
|
3
5
|
hasTransaction: boolean;
|
|
4
6
|
emittedEvents: string[];
|
|
@@ -18,34 +20,35 @@ export class BehavioralAnalyzer {
|
|
|
18
20
|
const dispatchedJobs = new Set<string>();
|
|
19
21
|
const mutations = new Set<string>();
|
|
20
22
|
|
|
21
|
-
const
|
|
23
|
+
const originalLines = code.split("\n");
|
|
24
|
+
const lines = blankCommentsAndStrings(code, { hashComments: true }).split("\n");
|
|
22
25
|
|
|
23
|
-
for (const
|
|
24
|
-
const
|
|
26
|
+
for (const [index, line] of lines.entries()) {
|
|
27
|
+
const rawLine = originalLines[index]!;
|
|
28
|
+
// Only recover literal arguments after the executable prefix matched the mask.
|
|
29
|
+
const matchCode = (pattern: RegExp) => {
|
|
30
|
+
const match = pattern.exec(line);
|
|
31
|
+
return match ? pattern.exec(rawLine.slice(match.index)) : null;
|
|
32
|
+
};
|
|
25
33
|
if (!line || line.startsWith("//") || line.startsWith("#")) continue;
|
|
26
34
|
|
|
27
35
|
// 1. Transaction Boundaries
|
|
28
|
-
if (
|
|
29
|
-
line.includes("DB::transaction") ||
|
|
30
|
-
line.includes("DB::beginTransaction") ||
|
|
31
|
-
line.includes("this.db.transaction") ||
|
|
32
|
-
line.includes(".transaction(")
|
|
33
|
-
) {
|
|
36
|
+
if (/(?:\bDB::(?:transaction|beginTransaction)|\bthis\.db\.transaction|\.transaction)\s*\(/.test(line)) {
|
|
34
37
|
hasTransaction = true;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
// 2. Authorization Guards
|
|
38
41
|
// Laravel: $this->authorize('update', $order); or Gate::authorize(...)
|
|
39
|
-
const authMatch =
|
|
42
|
+
const authMatch = matchCode(/(?:\$this->authorize|Gate::authorize)\s*\(\s*['"]([^'"]+)['"]/);
|
|
40
43
|
if (authMatch) {
|
|
41
44
|
guards.add(authMatch[1]);
|
|
42
45
|
}
|
|
43
46
|
// Laravel: abort_if(!..., 403, '...');
|
|
44
|
-
if (
|
|
47
|
+
if (/\b(?:abort_if|abort_unless)\s*\(/.test(line)) {
|
|
45
48
|
guards.add("abort_guard");
|
|
46
49
|
}
|
|
47
50
|
// TS / NestJS: @UseGuards(AuthGuard, RolesGuard)
|
|
48
|
-
const guardDecoratorMatch =
|
|
51
|
+
const guardDecoratorMatch = matchCode(/@UseGuards\s*\(([^)]+)\)/);
|
|
49
52
|
if (guardDecoratorMatch) {
|
|
50
53
|
const guardNames = guardDecoratorMatch[1].split(",").map((g) => g.trim());
|
|
51
54
|
for (const g of guardNames) guards.add(g);
|
|
@@ -53,62 +56,63 @@ export class BehavioralAnalyzer {
|
|
|
53
56
|
|
|
54
57
|
// 3. Emitted Events
|
|
55
58
|
// Laravel: event(new OrderPlaced($order));
|
|
56
|
-
const eventNewMatch =
|
|
59
|
+
const eventNewMatch = matchCode(/\bevent\s*\(\s*new\s+([A-Za-z0-9_]+)/);
|
|
57
60
|
if (eventNewMatch) {
|
|
58
61
|
emittedEvents.add(eventNewMatch[1]);
|
|
59
62
|
}
|
|
60
63
|
// Laravel: Event::dispatch(new OrderPlaced($order)); or Event::dispatch('name');
|
|
61
|
-
const eventDispatchMatch =
|
|
64
|
+
const eventDispatchMatch = matchCode(/\bEvent::dispatch\s*\(\s*(?:new\s+)?([A-Za-z0-9_]+)/);
|
|
62
65
|
if (eventDispatchMatch) {
|
|
63
66
|
emittedEvents.add(eventDispatchMatch[1]);
|
|
64
67
|
}
|
|
65
68
|
// Laravel: broadcast(new OrderUpdated($order));
|
|
66
|
-
const broadcastMatch =
|
|
69
|
+
const broadcastMatch = matchCode(/\bbroadcast\s*\(\s*new\s+([A-Za-z0-9_]+)/);
|
|
67
70
|
if (broadcastMatch) {
|
|
68
71
|
emittedEvents.add(broadcastMatch[1]);
|
|
69
72
|
}
|
|
70
73
|
// EventEmitter: this.eventEmitter.emit('order.created', ...)
|
|
71
|
-
const nodeEmitMatch =
|
|
74
|
+
const nodeEmitMatch = matchCode(/(?:eventEmitter|\$emit)\.emit\s*\(\s*['"]([^'"]+)['"]/);
|
|
72
75
|
if (nodeEmitMatch) {
|
|
73
76
|
emittedEvents.add(nodeEmitMatch[1]);
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
// 4. Dispatched Background Jobs
|
|
77
80
|
// Laravel: ProcessPaymentJob::dispatch($order); or ProcessPayment::dispatchSync(...)
|
|
78
|
-
const jobDispatchStaticMatch =
|
|
81
|
+
const jobDispatchStaticMatch = matchCode(/\b([A-Z][a-zA-Z0-9_]*(?:Job|Queue|Task|Process)[a-zA-Z0-9_]*)::dispatch/);
|
|
79
82
|
if (jobDispatchStaticMatch) {
|
|
80
83
|
dispatchedJobs.add(jobDispatchStaticMatch[1]);
|
|
81
84
|
}
|
|
82
85
|
// Laravel: dispatch(new ProcessPayment($order));
|
|
83
|
-
const dispatchNewMatch =
|
|
86
|
+
const dispatchNewMatch = matchCode(/\bdispatch\s*\(\s*new\s+([A-Za-z0-9_]+)/);
|
|
84
87
|
if (dispatchNewMatch) {
|
|
85
88
|
dispatchedJobs.add(dispatchNewMatch[1]);
|
|
86
89
|
}
|
|
87
90
|
// BullMQ / Queue: queue.add('process-payment', ...)
|
|
88
|
-
const queueAddMatch =
|
|
91
|
+
const queueAddMatch = matchCode(/(?:queue|queueService)\.add\s*\(\s*['"]([^'"]+)['"]/);
|
|
89
92
|
if (queueAddMatch) {
|
|
90
93
|
dispatchedJobs.add(queueAddMatch[1]);
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
// 5. Model Mutations
|
|
94
97
|
// Laravel / ORM: $order->update([...]);
|
|
95
|
-
const updateMatch =
|
|
98
|
+
const updateMatch = matchCode(/\$([a-zA-Z0-9_]+)->update\s*\(/);
|
|
96
99
|
if (updateMatch) {
|
|
97
100
|
mutations.add(`${updateMatch[1]}.update()`);
|
|
98
101
|
}
|
|
99
102
|
// Laravel / ORM: $order->delete();
|
|
100
|
-
const deleteMatch =
|
|
103
|
+
const deleteMatch = matchCode(/\$([a-zA-Z0-9_]+)->delete\s*\(/);
|
|
101
104
|
if (deleteMatch) {
|
|
102
105
|
mutations.add(`${deleteMatch[1]}.delete()`);
|
|
103
106
|
}
|
|
104
107
|
// Direct property assignment: $order->status = 'completed';
|
|
105
|
-
const assignMatch =
|
|
108
|
+
const assignMatch = matchCode(/\$([a-zA-Z0-9_]+)->([a-zA-Z0-9_]+)\s*=(?![=>])\s*([^;]+);/);
|
|
106
109
|
if (assignMatch && !["this", "request"].includes(assignMatch[1])) {
|
|
107
110
|
mutations.add(`${assignMatch[1]}.${assignMatch[2]}`);
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
return {
|
|
115
|
+
analysis: "lexical_heuristic",
|
|
112
116
|
guards: Array.from(guards),
|
|
113
117
|
hasTransaction,
|
|
114
118
|
emittedEvents: Array.from(emittedEvents),
|
|
@@ -393,6 +393,21 @@ export function blankCommentsAndStrings(
|
|
|
393
393
|
continue;
|
|
394
394
|
}
|
|
395
395
|
|
|
396
|
+
// PHP heredoc/nowdoc is non-code, including quotes and comment-like text.
|
|
397
|
+
if (ch === "<" && content.slice(i, i + 3) === "<<<") {
|
|
398
|
+
const header = /^<<<[ \t]*['"]?([A-Za-z_]\w*)['"]?[ \t]*\r?\n/.exec(content.slice(i));
|
|
399
|
+
if (header) {
|
|
400
|
+
const rest = content.slice(i + header[0].length);
|
|
401
|
+
const ending = new RegExp(`^[ \\t]*${header[1]}\\b`, "m").exec(rest);
|
|
402
|
+
const end = ending ? i + header[0].length + ending.index + ending[0].length : len;
|
|
403
|
+
while (i < end) {
|
|
404
|
+
if (out[i] !== "\n" && out[i] !== "\r") out[i] = " ";
|
|
405
|
+
i++;
|
|
406
|
+
}
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
396
411
|
// Normal code state
|
|
397
412
|
if (ch === "/" && next === "/") {
|
|
398
413
|
out[i] = " ";
|
|
@@ -17,12 +17,17 @@ export function detectArchetype(filePath: string, archetypesMap: Record<string,
|
|
|
17
17
|
|
|
18
18
|
// Built-in convention heuristics
|
|
19
19
|
const lower = normalized.toLowerCase();
|
|
20
|
-
if (
|
|
20
|
+
if (/(?:^|\/)(?:tests?|__tests__)\/|(?:\.test\.|\.spec\.|_test\.go$|Test\.php$)/i.test(normalized)) {
|
|
21
|
+
return "unknown";
|
|
22
|
+
}
|
|
23
|
+
if (lower.includes("middleware") || lower.includes("cors_handler") || lower.includes("asgi") || lower.includes("wsgi")) return "middleware";
|
|
24
|
+
if (lower.includes("controller") || /(?:^|\/)handlers?\/|handler\.(?:go|ts|js|py|php)$/i.test(lower)) return "controller";
|
|
21
25
|
if (lower.endsWith("views.py") || (lower.includes("views/") && lower.endsWith(".py"))) return "controller";
|
|
22
|
-
if (lower.
|
|
26
|
+
if (/(?:^|\/)(?:console\/)?commands?\//i.test(lower) || /(?:^|\/)(?:tools?|use[-_]?cases?)\//i.test(lower)) return "action";
|
|
27
|
+
if (/(?:^|\/)models?\/|entities|entity/i.test(lower) || /models?\.(?:php|ts|js|py|go)$/i.test(lower)) return "model";
|
|
28
|
+
if (lower.includes("service") || /(?:^|\/)(?:adapters?|gateways?|providers?)\//i.test(lower)) return "service";
|
|
23
29
|
if (lower.includes("repository") || lower.includes("repo")) return "repository";
|
|
24
|
-
if (
|
|
25
|
-
if (lower.includes("action")) return "action";
|
|
30
|
+
if (/(?:^|\/)actions?\/|action\.(?:php|ts|js|py|go)$/i.test(lower)) return "action";
|
|
26
31
|
if (lower.includes("job") || lower.includes("queue")) return "job";
|
|
27
32
|
if (lower.includes("event")) return "event";
|
|
28
33
|
if (lower.includes("listener")) return "listener";
|
|
@@ -32,6 +37,13 @@ export function detectArchetype(filePath: string, archetypesMap: Record<string,
|
|
|
32
37
|
if (lower.includes(".blade.php") || lower.includes("views/") || lower.includes("templates/")) return "view";
|
|
33
38
|
if (lower.includes("route") || lower.includes("router")) return "route";
|
|
34
39
|
if (lower.includes("util") || lower.includes("helper")) return "util";
|
|
40
|
+
// Non-MVC structural archetypes (libraries, CLIs, compilers, MCP servers, engines)
|
|
41
|
+
if (/(?:^|\/)(?:parsers?|extractors?)\//i.test(lower) || /(?:parser|extractor|lexer|tokenizer)\.(?:ts|js|py|go|php|rs|rb|java|cs)$/i.test(lower)) return "parser";
|
|
42
|
+
if (/(?:^|\/)resolvers?\//i.test(lower) || /(?:resolver|tracer|locator)\.(?:ts|js|py|go|php|rs|rb|java|cs)$/i.test(lower)) return "resolver";
|
|
43
|
+
if (/(?:^|\/)(?:pipelines?|ingestion|workflows?)\//i.test(lower) || /(?:pipeline|ingestor|indexer)\.(?:ts|js|py|go|php|rs|rb|java|cs)$/i.test(lower)) return "pipeline";
|
|
44
|
+
if (/(?:^|\/)config\//i.test(lower) || /(?:config|settings|loader)\.(?:ts|js|py|go|php|rs|rb|java|cs)$/i.test(lower)) return "config";
|
|
45
|
+
if (/(?:server|watcher|daemon|manager|runtime|client)\.(?:ts|js|py|go|php|rs|rb|java|cs)$/i.test(lower)) return "server";
|
|
46
|
+
if (/(?:^|\/)(?:boundary|retrieval|discovery|telemetry)\//i.test(lower) || /(?:evaluator|auditor|detector|orchestrator)\.(?:ts|js|py|go|php|rs|rb|java|cs)$/i.test(lower)) return "service";
|
|
35
47
|
|
|
36
48
|
return "unknown";
|
|
37
49
|
}
|
|
@@ -80,7 +80,7 @@ export class CSharpExtractor implements CodeExtractor {
|
|
|
80
80
|
const methodName = nameNode.text;
|
|
81
81
|
const lineStart = member.startPosition.row + 1;
|
|
82
82
|
const lineEnd = Math.max(lineStart, member.endPosition.row + 1);
|
|
83
|
-
const headerLine = getNodeHeader(member);
|
|
83
|
+
const headerLine = getNodeHeader(member, content);
|
|
84
84
|
const nestingDepth = calculateAstControlFlowNesting(
|
|
85
85
|
member,
|
|
86
86
|
CSHARP_CONTROL_FLOW_NODES,
|
|
@@ -101,7 +101,8 @@ export class CSharpExtractor implements CodeExtractor {
|
|
|
101
101
|
member.type === "class_declaration" ||
|
|
102
102
|
member.type === "interface_declaration" ||
|
|
103
103
|
member.type === "struct_declaration" ||
|
|
104
|
-
member.type === "record_declaration"
|
|
104
|
+
member.type === "record_declaration" ||
|
|
105
|
+
member.type === "enum_declaration"
|
|
105
106
|
) {
|
|
106
107
|
processNode(member, typeName);
|
|
107
108
|
}
|
|
@@ -123,7 +124,8 @@ export class CSharpExtractor implements CodeExtractor {
|
|
|
123
124
|
statement: (lines[node.startPosition.row] ?? node.text).trim().replace(/;$/, ""),
|
|
124
125
|
line_number: node.startPosition.row + 1,
|
|
125
126
|
is_external: this.isExternalUsing(rawUsing),
|
|
126
|
-
imported_symbols: [leafSymbol
|
|
127
|
+
imported_symbols: [...new Set([leafSymbol, ...node.namedChildren
|
|
128
|
+
.filter(c => c.type === "name_equals").map(c => c.firstNamedChild?.text).filter((name): name is string => !!name)])],
|
|
127
129
|
});
|
|
128
130
|
return;
|
|
129
131
|
}
|
|
@@ -132,12 +134,14 @@ export class CSharpExtractor implements CodeExtractor {
|
|
|
132
134
|
node.type === "namespace_declaration" ||
|
|
133
135
|
node.type === "file_scoped_namespace_declaration"
|
|
134
136
|
) {
|
|
137
|
+
const name = node.childForFieldName("name")?.text;
|
|
138
|
+
const namespaceScope = name ? (parentScope ? `${parentScope}.${name}` : name) : parentScope;
|
|
135
139
|
const body =
|
|
136
140
|
node.childForFieldName("body") ??
|
|
137
141
|
node.namedChildren.find((c) => c.type === "declaration_list") ??
|
|
138
142
|
node;
|
|
139
143
|
for (const child of body.namedChildren) {
|
|
140
|
-
processNode(child,
|
|
144
|
+
processNode(child, namespaceScope);
|
|
141
145
|
}
|
|
142
146
|
return;
|
|
143
147
|
}
|
|
@@ -158,7 +162,7 @@ export class CSharpExtractor implements CodeExtractor {
|
|
|
158
162
|
const fullName = parentScope ? `${parentScope}.${baseName}` : baseName;
|
|
159
163
|
const lineStart = node.startPosition.row + 1;
|
|
160
164
|
const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
|
|
161
|
-
const headerLine = getNodeHeader(node);
|
|
165
|
+
const headerLine = getNodeHeader(node, content);
|
|
162
166
|
const kind =
|
|
163
167
|
node.type === "interface_declaration"
|
|
164
168
|
? "interface"
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type Parser from "web-tree-sitter";
|
|
2
|
+
import { readPythonStaticString as literal } from "../static-string.ts";
|
|
3
|
+
import {
|
|
4
|
+
pythonCallArgument, pythonCallUsesUnpacking, pythonImportedMember, pythonImportedName, pythonImports,
|
|
5
|
+
unwrapPythonCallWrapper,
|
|
6
|
+
type PythonImport,
|
|
7
|
+
} from "./python-route-ast.ts";
|
|
8
|
+
|
|
9
|
+
type Node = Parser.SyntaxNode;
|
|
10
|
+
export type DjangoViewTarget = { symbol: string; module?: string; line?: number };
|
|
11
|
+
type PathEntry = { kind: "path"; pattern: string; target: DjangoViewTarget; name?: string; line: number;
|
|
12
|
+
actionMap?: Map<string, string>; dispatch: "function" | "class"; methods?: string[]; schemaSymbol?: string };
|
|
13
|
+
type RouterEntry = { kind: "router"; pattern: string; target: DjangoViewTarget; line: number };
|
|
14
|
+
type Inclusion = { kind: "include"; pattern: string | undefined; module: string };
|
|
15
|
+
export type DjangoUrlEntry = PathEntry | RouterEntry | Inclusion;
|
|
16
|
+
|
|
17
|
+
function children(node?: Node | null): Node[] {
|
|
18
|
+
return node?.namedChildren.filter(child => child.type !== "comment") ?? [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function viewActions(node: Node): Map<string, string> | undefined {
|
|
22
|
+
if (node.type !== "dictionary") return undefined;
|
|
23
|
+
const map = new Map<string, string>();
|
|
24
|
+
for (const item of children(node)) {
|
|
25
|
+
const method = literal(item.childForFieldName("key"));
|
|
26
|
+
const action = literal(item.childForFieldName("value"));
|
|
27
|
+
if (!method || !action) return undefined;
|
|
28
|
+
map.set(method.toUpperCase(), action);
|
|
29
|
+
}
|
|
30
|
+
return map;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function readDjangoUrlconf(root: Node, signal?: AbortSignal): DjangoUrlEntry[] {
|
|
34
|
+
const imports = new Map<string, PythonImport>();
|
|
35
|
+
const routers = new Map<string, RouterEntry[]>();
|
|
36
|
+
const patterns = new Map<string, DjangoUrlEntry[]>();
|
|
37
|
+
const declarations = new Map<string, DjangoViewTarget>();
|
|
38
|
+
const bound = new Set<string>();
|
|
39
|
+
const forget = (name: string) => {
|
|
40
|
+
bound.add(name);
|
|
41
|
+
imports.delete(name);
|
|
42
|
+
routers.delete(name);
|
|
43
|
+
patterns.delete(name);
|
|
44
|
+
declarations.delete(name);
|
|
45
|
+
};
|
|
46
|
+
const callee = (name: string): string => pythonImportedName(name, imports) ?? (bound.has(name) ? "" : name);
|
|
47
|
+
const viewTarget = (node?: Node | null): DjangoViewTarget | undefined => {
|
|
48
|
+
if (!node || !["identifier", "attribute"].includes(node.type)) return undefined;
|
|
49
|
+
return pythonImportedMember(node.text, imports) ?? declarations.get(node.text);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const read = (node?: Node | null): DjangoUrlEntry[] | undefined => {
|
|
53
|
+
if (!node || node.hasError) return undefined;
|
|
54
|
+
if (node.type === "identifier") return patterns.get(node.text);
|
|
55
|
+
if (node.type === "list" || node.type === "tuple") return children(node).flatMap(item => read(item) ?? []);
|
|
56
|
+
if (node.type === "list_splat" || node.type === "parenthesized_expression") return read(children(node)[0]);
|
|
57
|
+
if (node.type === "binary_operator" && node.childForFieldName("operator")?.text === "+") {
|
|
58
|
+
const left = read(node.childForFieldName("left"));
|
|
59
|
+
const right = read(node.childForFieldName("right"));
|
|
60
|
+
return left || right ? [...(left ?? []), ...(right ?? [])] : undefined;
|
|
61
|
+
}
|
|
62
|
+
if (node.type === "attribute" && node.childForFieldName("attribute")?.text === "urls") {
|
|
63
|
+
const object = node.childForFieldName("object");
|
|
64
|
+
if (object?.type === "list_splat") return routers.get(children(object)[0]?.text ?? "")?.slice();
|
|
65
|
+
return routers.get(object?.text ?? "")?.slice();
|
|
66
|
+
}
|
|
67
|
+
if (node.type !== "call" || pythonCallUsesUnpacking(node)) return undefined;
|
|
68
|
+
const callName = callee(node.childForFieldName("function")?.text ?? "");
|
|
69
|
+
if (!/^(?:django\.urls(?:\.conf)?\.)?(?:path|re_path)$/.test(callName)) return undefined;
|
|
70
|
+
|
|
71
|
+
const pattern = literal(pythonCallArgument(node, "route", 0));
|
|
72
|
+
const view = pythonCallArgument(node, "view", 1);
|
|
73
|
+
if (!view) return undefined;
|
|
74
|
+
const fn = view.childForFieldName("function");
|
|
75
|
+
if (view.type === "call" && /^(?:django\.urls(?:\.conf)?\.)?include$/.test(callee(fn?.text ?? ""))) {
|
|
76
|
+
const arg = pythonCallArgument(view, "arg", 0);
|
|
77
|
+
const tuple = arg?.type === "tuple" ? children(arg) : [];
|
|
78
|
+
const included = tuple.length === 2 && literal(tuple[1]) !== undefined ? tuple[0] : arg;
|
|
79
|
+
const module = literal(included) ?? (included ? pythonImportedName(included.text, imports) : undefined);
|
|
80
|
+
if (module) return [{ kind: "include", pattern, module }];
|
|
81
|
+
const nested = read(included);
|
|
82
|
+
return nested?.flatMap((entry): DjangoUrlEntry[] => {
|
|
83
|
+
if (entry.kind === "include") {
|
|
84
|
+
return [{ ...entry, pattern: pattern === undefined || entry.pattern === undefined ? undefined : pattern + entry.pattern }];
|
|
85
|
+
}
|
|
86
|
+
return pattern === undefined ? [] : [{ ...entry, pattern: pattern + entry.pattern }];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (pattern === undefined) return undefined;
|
|
90
|
+
|
|
91
|
+
const unwrapped = unwrapPythonCallWrapper(view, callee);
|
|
92
|
+
const unwrappedFn = unwrapped.node.childForFieldName("function");
|
|
93
|
+
const asView = unwrapped.node.type === "call" && unwrappedFn?.type === "attribute" && unwrappedFn.childForFieldName("attribute")?.text === "as_view";
|
|
94
|
+
const target = viewTarget(asView ? unwrappedFn.childForFieldName("object") : unwrapped.node);
|
|
95
|
+
if (!target) return undefined;
|
|
96
|
+
const mapping = asView ? pythonCallArgument(unwrapped.node, "actions", 0) : undefined;
|
|
97
|
+
const actionMap = mapping ? viewActions(mapping) : undefined;
|
|
98
|
+
if (mapping && !actionMap) return undefined;
|
|
99
|
+
const schemaArg = asView ? pythonCallArgument(unwrapped.node, "schema") : undefined;
|
|
100
|
+
const schemaSymbol = schemaArg && ["identifier", "attribute"].includes(schemaArg.type) ? schemaArg.text : undefined;
|
|
101
|
+
return [{
|
|
102
|
+
kind: "path", pattern, target, name: literal(pythonCallArgument(node, "name", 3)),
|
|
103
|
+
line: node.startPosition.row + 1, actionMap, dispatch: asView ? "class" : "function",
|
|
104
|
+
methods: unwrapped.methods, schemaSymbol,
|
|
105
|
+
}];
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
for (const stmt of root.namedChildren) {
|
|
109
|
+
signal?.throwIfAborted();
|
|
110
|
+
for (const [name, binding] of pythonImports(stmt)) {
|
|
111
|
+
forget(name);
|
|
112
|
+
imports.set(name, binding);
|
|
113
|
+
}
|
|
114
|
+
const definition = stmt.type === "decorated_definition" ? stmt.childForFieldName("definition") : stmt;
|
|
115
|
+
if (definition?.type === "function_definition" || definition?.type === "class_definition") {
|
|
116
|
+
const name = definition.childForFieldName("name")?.text;
|
|
117
|
+
if (name) {
|
|
118
|
+
forget(name);
|
|
119
|
+
declarations.set(name, { symbol: name, line: definition.startPosition.row + 1 });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const node = stmt.type === "expression_statement" ? stmt.namedChild(0) : null;
|
|
124
|
+
if (node?.type === "assignment") {
|
|
125
|
+
const left = node.childForFieldName("left");
|
|
126
|
+
const right = node.childForFieldName("right");
|
|
127
|
+
if (left?.type !== "identifier" || !right) continue;
|
|
128
|
+
const alias = imports.get(right.text);
|
|
129
|
+
const inherited = routers.get(right.text);
|
|
130
|
+
const declaration = declarations.get(right.text);
|
|
131
|
+
const values = read(right);
|
|
132
|
+
const constructor = right.type === "call" ? callee(right.childForFieldName("function")?.text ?? "") : "";
|
|
133
|
+
forget(left.text);
|
|
134
|
+
if (alias) imports.set(left.text, alias);
|
|
135
|
+
if (inherited) routers.set(left.text, inherited);
|
|
136
|
+
if (declaration) declarations.set(left.text, declaration);
|
|
137
|
+
if (values) patterns.set(left.text, values);
|
|
138
|
+
if (/^(?:rest_framework\.routers\.)?(?:SimpleRouter|DefaultRouter)$/.test(constructor)) routers.set(left.text, []);
|
|
139
|
+
} else if (node?.type === "augmented_assignment" && node.childForFieldName("operator")?.text === "+=") {
|
|
140
|
+
const values = patterns.get(node.childForFieldName("left")?.text ?? "");
|
|
141
|
+
const added = read(node.childForFieldName("right"));
|
|
142
|
+
if (values && added) for (const entry of added.slice()) values.push(entry);
|
|
143
|
+
} else if (node?.type === "call" && !pythonCallUsesUnpacking(node)) {
|
|
144
|
+
const fn = node.childForFieldName("function");
|
|
145
|
+
if (fn?.type !== "attribute") continue;
|
|
146
|
+
const receiver = fn.childForFieldName("object")?.text ?? "";
|
|
147
|
+
const method = fn.childForFieldName("attribute")?.text;
|
|
148
|
+
if (method === "register") {
|
|
149
|
+
const router = routers.get(receiver);
|
|
150
|
+
const pattern = literal(pythonCallArgument(node, "prefix", 0));
|
|
151
|
+
const target = viewTarget(pythonCallArgument(node, "viewset", 1));
|
|
152
|
+
if (router && pattern !== undefined && target) {
|
|
153
|
+
router.push({ kind: "router", pattern, target, line: node.startPosition.row + 1 });
|
|
154
|
+
}
|
|
155
|
+
} else if (method === "append" || method === "extend") {
|
|
156
|
+
const values = patterns.get(receiver);
|
|
157
|
+
const added = read(pythonCallArgument(node, "", 0));
|
|
158
|
+
if (values && added) for (const entry of added.slice()) values.push(entry);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return patterns.get("urlpatterns") ?? [];
|
|
163
|
+
}
|