@dimassetoid/septum-mcp 0.2.1 → 0.3.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 -28
- package/package.json +4 -4
- package/src/cli/commands/check.ts +27 -16
- package/src/cli/commands/hook.ts +38 -101
- package/src/cli/commands/init.ts +26 -9
- package/src/cli/commands/sync.ts +4 -6
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +9 -52
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +49 -14
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +39 -35
- package/src/core/boundary/evaluator.ts +67 -83
- package/src/core/boundary/staged-auditor.ts +102 -40
- package/src/core/config/domain-ownership.ts +45 -0
- package/src/core/config/loader.ts +81 -29
- package/src/core/config/schema.ts +0 -10
- package/src/core/database/repositories/dependency.repository.ts +169 -148
- package/src/core/database/repositories/domain.repository.ts +46 -3
- package/src/core/database/repositories/symbol.repository.ts +226 -87
- package/src/core/database/repository.ts +73 -18
- package/src/core/database/schema.ts +2 -33
- package/src/core/discovery/navigation.ts +105 -0
- package/src/core/discovery/topology-detector.ts +60 -2
- package/src/core/ingestion/pipeline.ts +96 -129
- 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 +7 -3
- package/src/core/parser/extractors/csharp.ts +7 -3
- package/src/core/parser/extractors/django-semantic.ts +4 -36
- package/src/core/parser/extractors/elysia-semantic.ts +3 -24
- package/src/core/parser/extractors/express-semantic.ts +3 -18
- package/src/core/parser/extractors/fastapi-semantic.ts +19 -53
- package/src/core/parser/extractors/fastify-semantic.ts +3 -18
- package/src/core/parser/extractors/flask-semantic.ts +22 -55
- package/src/core/parser/extractors/go-semantic.ts +92 -33
- package/src/core/parser/extractors/hono-semantic.ts +3 -24
- package/src/core/parser/extractors/java.ts +5 -3
- package/src/core/parser/extractors/laravel-semantic.ts +44 -16
- package/src/core/parser/extractors/mcp-cli-semantic.ts +6 -7
- package/src/core/parser/extractors/nestjs-semantic.ts +3 -19
- package/src/core/parser/extractors/php.ts +16 -0
- package/src/core/parser/extractors/python.ts +9 -4
- package/src/core/parser/extractors/registry.ts +26 -5
- package/src/core/parser/extractors/ruby.ts +8 -5
- package/src/core/parser/extractors/rust.ts +31 -13
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-semantic.ts +4 -37
- package/src/core/parser/extractors/typescript.ts +14 -1
- 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 +73 -50
- 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/resolver/call-graph-tracer.ts +337 -28
- package/src/core/resolver/import-resolver.ts +107 -179
- package/src/core/resolver/interpretation-inputs.ts +7 -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 +115 -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 +71 -0
- package/src/core/resolver/module-resolver.ts +8 -4
- package/src/core/resolver/slice-catalog.ts +79 -0
- package/src/core/resolver/slice-format.ts +9 -0
- package/src/core/resolver/symbol-impact.ts +381 -0
- package/src/core/resolver/vertical-slice-tracer.ts +93 -115
- package/src/core/resources/ignore.ts +22 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/retrieval/context-page.ts +109 -0
- package/src/core/retrieval/context.ts +320 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +262 -0
- package/src/core/telemetry/telemetry.ts +54 -9
- package/src/index.ts +0 -3
- package/src/mcp/schemas.ts +61 -420
- package/src/mcp/server.ts +116 -290
- package/src/mcp/tools/boundary.ts +2 -2
- package/src/mcp/tools/check-boundary.ts +55 -60
- package/src/mcp/tools/get-domain-catalog.ts +32 -219
- package/src/mcp/tools/get-symbol-impact.ts +45 -5
- package/src/mcp/tools/get-symbol.ts +227 -3
- package/src/mcp/tools/locate-symbol.ts +54 -14
- package/src/mcp/tools/{domain.ts → map.ts} +4 -18
- package/src/mcp/tools/register-domain.ts +41 -3
- package/src/mcp/tools/symbol.ts +23 -21
- package/src/mcp/tools/trace-vertical-slice.ts +36 -10
- package/src/mcp/workspace-manager.ts +15 -4
- package/src/mcp/workspace-watcher.ts +8 -8
- package/src/types/index.ts +35 -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/feature.ts +0 -67
- 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/register-feature.ts +0 -110
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
2
|
+
import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
|
|
2
3
|
import * as fs from "node:fs";
|
|
3
4
|
import * as path from "node:path";
|
|
4
5
|
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
@@ -28,7 +29,7 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
28
29
|
public readonly id = "laravel";
|
|
29
30
|
public readonly name = "Laravel MVC Semantic Extractor";
|
|
30
31
|
|
|
31
|
-
constructor(private projectRoot: string = process.cwd()) {}
|
|
32
|
+
constructor(private projectRoot: string = process.cwd(), private inventory?: SourceInventory) {}
|
|
32
33
|
|
|
33
34
|
public canHandle(projectRoot: string, framework?: string): boolean {
|
|
34
35
|
if (framework === "laravel") return true;
|
|
@@ -44,8 +45,15 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
44
45
|
*/
|
|
45
46
|
public extractSlices(
|
|
46
47
|
projectRootOrDomainId?: string | number,
|
|
47
|
-
maybeDomainId?: number
|
|
48
|
+
maybeDomainId?: number,
|
|
49
|
+
signal?: AbortSignal,
|
|
50
|
+
inventory?: SourceInventory
|
|
48
51
|
): LaravelSemanticExtractionResult {
|
|
52
|
+
// The registry reuses one adapter across workspaces. Keep helpers bound to
|
|
53
|
+
// this invocation's root without mutating the shared adapter instance.
|
|
54
|
+
if (typeof projectRootOrDomainId === "string" && (inventory || path.resolve(projectRootOrDomainId) !== path.resolve(this.projectRoot))) {
|
|
55
|
+
return new LaravelSemanticExtractor(projectRootOrDomainId, inventory).extractSlices(maybeDomainId, undefined, signal);
|
|
56
|
+
}
|
|
49
57
|
let root = this.projectRoot;
|
|
50
58
|
let domainId: number | undefined;
|
|
51
59
|
|
|
@@ -59,11 +67,12 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
59
67
|
const routeFiles = [
|
|
60
68
|
path.join(root, "routes/web.php"),
|
|
61
69
|
path.join(root, "routes/api.php"),
|
|
62
|
-
].filter((f) => fs.existsSync(f));
|
|
70
|
+
].filter((f) => fs.existsSync(f) && (!this.inventory || this.inventory.files.includes(f)));
|
|
63
71
|
|
|
64
72
|
const parsedRoutes: ParsedRoute[] = [];
|
|
65
73
|
|
|
66
74
|
for (const routeFile of routeFiles) {
|
|
75
|
+
signal?.throwIfAborted();
|
|
67
76
|
const content = readOptionalSourceFile(routeFile, "utf-8");
|
|
68
77
|
const relativeRouteFile = path.relative(root, routeFile).replace(/\\/g, "/");
|
|
69
78
|
const routesFromFile = this.parseRoutesContent(content);
|
|
@@ -273,7 +282,7 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
273
282
|
controller_line: controllerInfo.line,
|
|
274
283
|
architecture_style: "mvc",
|
|
275
284
|
entry_kind: "http_route",
|
|
276
|
-
execution_chain_json: JSON.stringify(chain),
|
|
285
|
+
execution_chain_json: JSON.stringify(chain.map(node => (node.guards || node.mutations || node.emits || node.dispatches || node.transactions) ? { ...node, semantic_analysis: "lexical_heuristic" } : node)),
|
|
277
286
|
});
|
|
278
287
|
}
|
|
279
288
|
|
|
@@ -290,11 +299,13 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
290
299
|
*/
|
|
291
300
|
public parseRoutesContent(content: string): ParsedRoute[] {
|
|
292
301
|
const routes: ParsedRoute[] = [];
|
|
302
|
+
const executable = blankCommentsAndStrings(content, { hashComments: true });
|
|
293
303
|
|
|
294
304
|
// 1. Process Route::resource
|
|
295
305
|
const resourceRegex = /Route::resource\s*\(\s*['"]([^'"]+)['"]\s*,\s*([\\A-Za-z0-9_]+)::class\s*\)/gi;
|
|
296
306
|
let resMatch;
|
|
297
307
|
while ((resMatch = resourceRegex.exec(content)) !== null) {
|
|
308
|
+
if (executable.slice(resMatch.index, resMatch.index + "Route::resource".length).toLowerCase() !== "route::resource") continue;
|
|
298
309
|
const baseUri = resMatch[1].replace(/^\//, "");
|
|
299
310
|
const controllerClass = resMatch[2];
|
|
300
311
|
const resourceActions = [
|
|
@@ -322,6 +333,7 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
322
333
|
const apiResourceRegex = /Route::apiResource\s*\(\s*['"]([^'"]+)['"]\s*,\s*([\\A-Za-z0-9_]+)::class\s*\)/gi;
|
|
323
334
|
let apiResMatch;
|
|
324
335
|
while ((apiResMatch = apiResourceRegex.exec(content)) !== null) {
|
|
336
|
+
if (executable.slice(apiResMatch.index, apiResMatch.index + "Route::apiResource".length).toLowerCase() !== "route::apiresource") continue;
|
|
325
337
|
const baseUri = apiResMatch[1].replace(/^\//, "");
|
|
326
338
|
const controllerClass = apiResMatch[2];
|
|
327
339
|
const apiResourceActions = [
|
|
@@ -549,16 +561,26 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
549
561
|
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
550
562
|
resolvedFilePath = path.resolve(this.projectRoot, res.targets[0].files[0]);
|
|
551
563
|
}
|
|
564
|
+
if (!resolvedFilePath) return { line: 0 };
|
|
552
565
|
} else if (routeFilePath && fs.existsSync(sourceRef)) {
|
|
553
566
|
const routeContent = readOptionalSourceFile(sourceRef, "utf-8");
|
|
554
|
-
const
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
|
|
567
|
+
const executable = blankCommentsAndStrings(routeContent, { hashComments: true });
|
|
568
|
+
const bindings = [...executable.matchAll(/\buse\s+([\\A-Za-z0-9_]+)(?:\s+as\s+([A-Za-z0-9_]+))?\s*;/gi)]
|
|
569
|
+
.filter(match => (match[2] || match[1]!.split("\\").pop())?.toLowerCase() === controllerClass.toLowerCase());
|
|
570
|
+
if (bindings.length > 1) return { line: 0 };
|
|
571
|
+
if (bindings.length === 1) {
|
|
572
|
+
const fqn = bindings[0]![1]!;
|
|
558
573
|
const res = resolver.resolve(fqn, sourceRef);
|
|
559
574
|
if (res.status === "resolved" && res.targets[0]?.files?.[0]) {
|
|
560
575
|
resolvedFilePath = path.resolve(this.projectRoot, res.targets[0].files[0]);
|
|
561
576
|
}
|
|
577
|
+
// Existing source-only fixtures may omit composer.json. A conventional
|
|
578
|
+
// App namespace maps to its exact conventional path, never the alias.
|
|
579
|
+
if (!resolvedFilePath && !fs.existsSync(path.join(this.projectRoot, "composer.json")) && fqn.startsWith("App\\Http\\Controllers\\")) {
|
|
580
|
+
const conventional = path.join(this.projectRoot, "app", fqn.slice(4).replace(/\\/g, "/") + ".php");
|
|
581
|
+
if (fs.existsSync(conventional)) resolvedFilePath = conventional;
|
|
582
|
+
}
|
|
583
|
+
if (!resolvedFilePath) return { line: 0 };
|
|
562
584
|
}
|
|
563
585
|
}
|
|
564
586
|
|
|
@@ -580,7 +602,7 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
580
602
|
}
|
|
581
603
|
|
|
582
604
|
if (resolvedFilePath && fs.existsSync(resolvedFilePath)) {
|
|
583
|
-
const lines = readOptionalSourceFile(resolvedFilePath, "utf-8").split("\n");
|
|
605
|
+
const lines = blankCommentsAndStrings(readOptionalSourceFile(resolvedFilePath, "utf-8"), { hashComments: true }).split("\n");
|
|
584
606
|
let targetLine = 1;
|
|
585
607
|
for (let i = 0; i < lines.length; i++) {
|
|
586
608
|
if (new RegExp(`function\\s+${actionName}\\s*\\(`, "i").test(lines[i])) {
|
|
@@ -886,7 +908,7 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
886
908
|
const jobsDir = path.join(root, "app/Jobs");
|
|
887
909
|
if (!fs.existsSync(jobsDir)) return [];
|
|
888
910
|
|
|
889
|
-
const jobFiles =
|
|
911
|
+
const jobFiles = listSourceFiles(jobsDir, /\.php$/, this.inventory).filter(file => path.dirname(file) === jobsDir).map(file => path.basename(file));
|
|
890
912
|
const slices: Array<Omit<VerticalSliceRecord, "id" | "created_at">> = [];
|
|
891
913
|
|
|
892
914
|
for (const file of jobFiles) {
|
|
@@ -948,7 +970,7 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
948
970
|
controller_line: 1,
|
|
949
971
|
architecture_style: "clean",
|
|
950
972
|
entry_kind: "queue_job",
|
|
951
|
-
execution_chain_json: JSON.stringify(chain),
|
|
973
|
+
execution_chain_json: JSON.stringify(chain.map(node => (node.guards || node.mutations || node.emits || node.dispatches || node.transactions) ? { ...node, semantic_analysis: "lexical_heuristic" } : node)),
|
|
952
974
|
});
|
|
953
975
|
}
|
|
954
976
|
|
|
@@ -962,7 +984,7 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
962
984
|
const commandsDir = path.join(root, "app/Console/Commands");
|
|
963
985
|
if (!fs.existsSync(commandsDir)) return [];
|
|
964
986
|
|
|
965
|
-
const files =
|
|
987
|
+
const files = listSourceFiles(commandsDir, /\.php$/, this.inventory).filter(file => path.dirname(file) === commandsDir).map(file => path.basename(file));
|
|
966
988
|
const slices: Array<Omit<VerticalSliceRecord, "id" | "created_at">> = [];
|
|
967
989
|
|
|
968
990
|
for (const file of files) {
|
|
@@ -975,6 +997,10 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
975
997
|
const sigMatch = content.match(/protected\s+\$signature\s*=\s*['"]([^'"]+)['"]/);
|
|
976
998
|
const commandSignature = sigMatch ? sigMatch[1].split(/\s+/)[0] : this.toSnakeCase(className);
|
|
977
999
|
|
|
1000
|
+
const handleMatch = content.match(/\bfunction\s+handle\s*\(/);
|
|
1001
|
+
const handleLine = handleMatch && handleMatch.index !== undefined
|
|
1002
|
+
? content.slice(0, handleMatch.index).split("\n").length
|
|
1003
|
+
: 1;
|
|
978
1004
|
const actionBody = this.extractActionBody(content, "handle");
|
|
979
1005
|
const behavior = BehavioralAnalyzer.analyzeMethod(actionBody);
|
|
980
1006
|
|
|
@@ -983,12 +1009,14 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
983
1009
|
stage: "ingress",
|
|
984
1010
|
symbol: `CLI ${commandSignature}`,
|
|
985
1011
|
file: path.relative(this.projectRoot, fullPath),
|
|
1012
|
+
line: handleLine,
|
|
986
1013
|
description: `Console Command: ${commandSignature}`,
|
|
987
1014
|
},
|
|
988
1015
|
{
|
|
989
1016
|
stage: "controller",
|
|
990
1017
|
symbol: `${className}::handle`,
|
|
991
1018
|
file: path.relative(this.projectRoot, fullPath),
|
|
1019
|
+
line: handleLine,
|
|
992
1020
|
description: "Command Execution Handler",
|
|
993
1021
|
mutations: behavior.mutations.length ? behavior.mutations : undefined,
|
|
994
1022
|
transactions: behavior.hasTransaction,
|
|
@@ -1024,10 +1052,10 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
1024
1052
|
controller_class: className,
|
|
1025
1053
|
action_name: "handle",
|
|
1026
1054
|
controller_file: path.relative(this.projectRoot, fullPath),
|
|
1027
|
-
controller_line:
|
|
1055
|
+
controller_line: handleLine,
|
|
1028
1056
|
architecture_style: "clean",
|
|
1029
1057
|
entry_kind: "scheduled_command",
|
|
1030
|
-
execution_chain_json: JSON.stringify(chain),
|
|
1058
|
+
execution_chain_json: JSON.stringify(chain.map(node => (node.guards || node.mutations || node.emits || node.dispatches || node.transactions) ? { ...node, semantic_analysis: "lexical_heuristic" } : node)),
|
|
1031
1059
|
});
|
|
1032
1060
|
}
|
|
1033
1061
|
|
|
@@ -1041,7 +1069,7 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
1041
1069
|
const listenersDir = path.join(root, "app/Listeners");
|
|
1042
1070
|
if (!fs.existsSync(listenersDir)) return [];
|
|
1043
1071
|
|
|
1044
|
-
const files =
|
|
1072
|
+
const files = listSourceFiles(listenersDir, /\.php$/, this.inventory).filter(file => path.dirname(file) === listenersDir).map(file => path.basename(file));
|
|
1045
1073
|
const slices: Array<Omit<VerticalSliceRecord, "id" | "created_at">> = [];
|
|
1046
1074
|
|
|
1047
1075
|
for (const file of files) {
|
|
@@ -1106,7 +1134,7 @@ export class LaravelSemanticExtractor implements SemanticSliceExtractor {
|
|
|
1106
1134
|
controller_line: 1,
|
|
1107
1135
|
architecture_style: "clean",
|
|
1108
1136
|
entry_kind: "event_listener",
|
|
1109
|
-
execution_chain_json: JSON.stringify(chain),
|
|
1137
|
+
execution_chain_json: JSON.stringify(chain.map(node => (node.guards || node.mutations || node.emits || node.dispatches || node.transactions) ? { ...node, semantic_analysis: "lexical_heuristic" } : node)),
|
|
1110
1138
|
});
|
|
1111
1139
|
}
|
|
1112
1140
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
|
|
1
2
|
import { readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
2
3
|
import * as fs from "node:fs";
|
|
3
4
|
import * as path from "node:path";
|
|
@@ -30,7 +31,7 @@ export class McpCliSemanticExtractor implements SemanticSliceExtractor {
|
|
|
30
31
|
return false;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
public extractSlices(projectRoot: string, domainId?: number): VerticalSliceCandidate[] {
|
|
34
|
+
public extractSlices(projectRoot: string, domainId?: number, signal?: AbortSignal, inventory?: SourceInventory): VerticalSliceCandidate[] {
|
|
34
35
|
const slices: VerticalSliceCandidate[] = [];
|
|
35
36
|
const { toolPrefix, cliBinName } = this.resolveProjectNaming(projectRoot);
|
|
36
37
|
const registeredTools = this.scanRegisteredMcpToolNames(projectRoot);
|
|
@@ -39,9 +40,7 @@ export class McpCliSemanticExtractor implements SemanticSliceExtractor {
|
|
|
39
40
|
const mcpToolsDir = path.join(projectRoot, "src/mcp/tools");
|
|
40
41
|
if (fs.existsSync(mcpToolsDir)) {
|
|
41
42
|
try {
|
|
42
|
-
const toolFiles =
|
|
43
|
-
.readdirSync(mcpToolsDir)
|
|
44
|
-
.filter((f) => f.endsWith(".ts") || f.endsWith(".js"));
|
|
43
|
+
const toolFiles = listSourceFiles(mcpToolsDir, /\.[jt]s$/, inventory).filter(file => path.dirname(file) === mcpToolsDir).map(file => path.basename(file));
|
|
45
44
|
|
|
46
45
|
for (const file of toolFiles) {
|
|
47
46
|
const fullPath = path.join(mcpToolsDir, file);
|
|
@@ -140,9 +139,7 @@ export class McpCliSemanticExtractor implements SemanticSliceExtractor {
|
|
|
140
139
|
const cliCommandsDir = path.join(projectRoot, "src/cli/commands");
|
|
141
140
|
if (fs.existsSync(cliCommandsDir)) {
|
|
142
141
|
try {
|
|
143
|
-
const commandFiles =
|
|
144
|
-
.readdirSync(cliCommandsDir)
|
|
145
|
-
.filter((f) => f.endsWith(".ts") || f.endsWith(".js"));
|
|
142
|
+
const commandFiles = listSourceFiles(cliCommandsDir, /\.[jt]s$/, inventory).filter(file => path.dirname(file) === cliCommandsDir).map(file => path.basename(file));
|
|
146
143
|
|
|
147
144
|
for (const file of commandFiles) {
|
|
148
145
|
const fullPath = path.join(cliCommandsDir, file);
|
|
@@ -322,10 +319,12 @@ export class McpCliSemanticExtractor implements SemanticSliceExtractor {
|
|
|
322
319
|
let match: RegExpExecArray | null;
|
|
323
320
|
|
|
324
321
|
while ((match = importRegex.exec(content)) !== null) {
|
|
322
|
+
if (/^import\s+type\b/.test(match[0])) continue;
|
|
325
323
|
const clause = match[1];
|
|
326
324
|
const spec = match[2];
|
|
327
325
|
const identifiers = clause
|
|
328
326
|
.split(",")
|
|
327
|
+
.filter(s => !/^\s*type\s+/.test(s))
|
|
329
328
|
.map((s) => s.trim().split(/\s+as\s+/)[0].trim())
|
|
330
329
|
.filter(Boolean);
|
|
331
330
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
|
|
1
2
|
import { readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
2
|
-
import { isIgnoredDirectory } from "../../resources/ignore.ts";
|
|
3
3
|
import { parseWithTreeSitter } from "../wasm-loader.ts";
|
|
4
4
|
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
5
5
|
import type Parser from "web-tree-sitter";
|
|
@@ -48,14 +48,14 @@ export class NestJsSemanticExtractor implements SemanticSliceExtractor {
|
|
|
48
48
|
public async extractSlices(
|
|
49
49
|
projectRoot: string,
|
|
50
50
|
domainId?: number,
|
|
51
|
-
signal?: AbortSignal
|
|
51
|
+
signal?: AbortSignal, inventory?: SourceInventory
|
|
52
52
|
): Promise<VerticalSliceCandidate[]> {
|
|
53
53
|
const slices: VerticalSliceCandidate[] = [];
|
|
54
54
|
const srcDir = path.join(projectRoot, "src");
|
|
55
55
|
if (!fs.existsSync(srcDir)) return slices;
|
|
56
56
|
|
|
57
57
|
const resolver = new ImportResolver(projectRoot);
|
|
58
|
-
const controllerFiles =
|
|
58
|
+
const controllerFiles = listSourceFiles(srcDir, /\.controller\.(ts|js)$/, inventory);
|
|
59
59
|
|
|
60
60
|
for (const file of controllerFiles) {
|
|
61
61
|
if (signal?.aborted) throw new Error("semantic_extraction_cancelled");
|
|
@@ -524,20 +524,4 @@ export class NestJsSemanticExtractor implements SemanticSliceExtractor {
|
|
|
524
524
|
|
|
525
525
|
return null;
|
|
526
526
|
}
|
|
527
|
-
|
|
528
|
-
private findFilesRecursively(dir: string, pattern: RegExp): string[] {
|
|
529
|
-
const results: string[] = [];
|
|
530
|
-
try {
|
|
531
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
532
|
-
for (const entry of entries) {
|
|
533
|
-
const full = path.join(dir, entry.name);
|
|
534
|
-
if (entry.isDirectory() && !isIgnoredDirectory(entry.name)) {
|
|
535
|
-
results.push(...this.findFilesRecursively(full, pattern));
|
|
536
|
-
} else if (entry.isFile() && pattern.test(entry.name)) {
|
|
537
|
-
results.push(full);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
} catch {}
|
|
541
|
-
return results;
|
|
542
|
-
}
|
|
543
527
|
}
|
|
@@ -485,6 +485,22 @@ export class PHPExtractor implements CodeExtractor {
|
|
|
485
485
|
line_count: mCount,
|
|
486
486
|
nesting_depth: nestingDepth,
|
|
487
487
|
});
|
|
488
|
+
if (methodName.toLowerCase() === "__construct" && paramsNode) {
|
|
489
|
+
for (const param of paramsNode.namedChildren) {
|
|
490
|
+
if (param.type !== "property_promotion_parameter") continue;
|
|
491
|
+
const propName = param.childForFieldName("name");
|
|
492
|
+
if (!propName) continue;
|
|
493
|
+
symbols.push({
|
|
494
|
+
name: `${containerName}::${propName.text}`,
|
|
495
|
+
kind: "property",
|
|
496
|
+
signature: param.text,
|
|
497
|
+
visibility: this.extractPhpVisibility(param),
|
|
498
|
+
line_start: param.startPosition.row + 1,
|
|
499
|
+
line_end: param.endPosition.row + 1,
|
|
500
|
+
line_count: param.endPosition.row - param.startPosition.row + 1,
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
}
|
|
488
504
|
continue;
|
|
489
505
|
}
|
|
490
506
|
|
|
@@ -290,7 +290,7 @@ export class PythonExtractor implements CodeExtractor {
|
|
|
290
290
|
? "protected"
|
|
291
291
|
: "public";
|
|
292
292
|
|
|
293
|
-
const
|
|
293
|
+
const extractImports = (node: Parser.SyntaxNode): void => {
|
|
294
294
|
if (node.type === "import_from_statement") {
|
|
295
295
|
const modNode =
|
|
296
296
|
node.childForFieldName("module_name") ??
|
|
@@ -316,7 +316,7 @@ export class PythonExtractor implements CodeExtractor {
|
|
|
316
316
|
|
|
317
317
|
dependencies.push({
|
|
318
318
|
target: modulePath,
|
|
319
|
-
statement:
|
|
319
|
+
statement: node.text.trim(),
|
|
320
320
|
line_number: node.startPosition.row + 1,
|
|
321
321
|
is_external: isExternal,
|
|
322
322
|
...(importedSymbols.length > 0 ? { imported_symbols: Array.from(new Set(importedSymbols)) } : {}),
|
|
@@ -333,7 +333,7 @@ export class PythonExtractor implements CodeExtractor {
|
|
|
333
333
|
const shortName = modulePath.split(".").pop() || modulePath;
|
|
334
334
|
dependencies.push({
|
|
335
335
|
target: modulePath,
|
|
336
|
-
statement:
|
|
336
|
+
statement: node.text.trim(),
|
|
337
337
|
line_number: node.startPosition.row + 1,
|
|
338
338
|
is_external: PYTHON_STDLIB_AND_EXTERNALS.has(topPackage),
|
|
339
339
|
imported_symbols: [shortName],
|
|
@@ -347,7 +347,7 @@ export class PythonExtractor implements CodeExtractor {
|
|
|
347
347
|
const shortName = alias?.text?.trim() || modulePath.split(".").pop() || modulePath;
|
|
348
348
|
dependencies.push({
|
|
349
349
|
target: modulePath,
|
|
350
|
-
statement:
|
|
350
|
+
statement: node.text.trim(),
|
|
351
351
|
line_number: node.startPosition.row + 1,
|
|
352
352
|
is_external: PYTHON_STDLIB_AND_EXTERNALS.has(topPackage),
|
|
353
353
|
imported_symbols: [shortName],
|
|
@@ -358,6 +358,11 @@ export class PythonExtractor implements CodeExtractor {
|
|
|
358
358
|
return;
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
+
for (const child of node.namedChildren) extractImports(child);
|
|
362
|
+
};
|
|
363
|
+
extractImports(rootNode);
|
|
364
|
+
|
|
365
|
+
const processNode = (node: Parser.SyntaxNode, currentClass: string | null, pendingDecorators?: string[]): void => {
|
|
361
366
|
if (node.type === "decorated_definition") {
|
|
362
367
|
const decorators: string[] = [];
|
|
363
368
|
for (const child of node.namedChildren) {
|
|
@@ -14,6 +14,15 @@ import { ExpressSemanticExtractor } from "./express-semantic.ts";
|
|
|
14
14
|
import { FastifySemanticExtractor } from "./fastify-semantic.ts";
|
|
15
15
|
import { HonoSemanticExtractor } from "./hono-semantic.ts";
|
|
16
16
|
import { ElysiaSemanticExtractor } from "./elysia-semantic.ts";
|
|
17
|
+
import { scanSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
|
|
18
|
+
import { shouldIgnoreSourcePath } from "../../resources/ignore.ts";
|
|
19
|
+
|
|
20
|
+
export interface AdapterExtractionResult { id: string; slices: number }
|
|
21
|
+
interface ExtractionOptions {
|
|
22
|
+
ignorePatterns?: string[];
|
|
23
|
+
inventory?: SourceInventory;
|
|
24
|
+
onResult?: (result: AdapterExtractionResult) => void;
|
|
25
|
+
}
|
|
17
26
|
|
|
18
27
|
export class SemanticSliceExtractorRegistry {
|
|
19
28
|
private static extractors: SemanticSliceExtractor[] = [
|
|
@@ -31,8 +40,16 @@ export class SemanticSliceExtractorRegistry {
|
|
|
31
40
|
new GoSemanticExtractor(),
|
|
32
41
|
];
|
|
33
42
|
|
|
34
|
-
public static getCapabilities() {
|
|
35
|
-
return this.extractors.map(
|
|
43
|
+
public static getCapabilities(projectRoot?: string, framework?: string) {
|
|
44
|
+
return this.extractors.map(extractor => {
|
|
45
|
+
let applicable: boolean | null = null;
|
|
46
|
+
let diagnostic: string | undefined;
|
|
47
|
+
try { if (projectRoot) applicable = extractor.canHandle(projectRoot, framework); }
|
|
48
|
+
catch (error) { diagnostic = error instanceof Error ? error.message : String(error); }
|
|
49
|
+
return { id: extractor.id, name: extractor.name, coverage: "partial", registered: true, applicable,
|
|
50
|
+
extraction: "not_established_by_registration", ...(diagnostic ? { diagnostic } : {}),
|
|
51
|
+
};
|
|
52
|
+
});
|
|
36
53
|
}
|
|
37
54
|
|
|
38
55
|
/**
|
|
@@ -58,18 +75,22 @@ export class SemanticSliceExtractorRegistry {
|
|
|
58
75
|
projectRoot: string,
|
|
59
76
|
framework?: string,
|
|
60
77
|
domainId?: number,
|
|
61
|
-
signal?: AbortSignal
|
|
78
|
+
signal?: AbortSignal,
|
|
79
|
+
options: ExtractionOptions = {}
|
|
62
80
|
): Promise<VerticalSliceCandidate[]> {
|
|
63
81
|
const matched = this.getExtractors(projectRoot, framework);
|
|
82
|
+
const sources = options.inventory ?? scanSourceFiles(projectRoot, { ignorePatterns: options.ignorePatterns, signal });
|
|
64
83
|
const combinedSlices: VerticalSliceCandidate[] = [];
|
|
65
84
|
|
|
66
85
|
for (const extractor of matched) {
|
|
67
86
|
signal?.throwIfAborted();
|
|
68
87
|
let slices: VerticalSliceCandidate[];
|
|
69
|
-
try { slices = await extractor.extractSlices(projectRoot, domainId, signal); }
|
|
88
|
+
try { slices = await extractor.extractSlices(projectRoot, domainId, signal, sources); }
|
|
70
89
|
catch (error) { signal?.throwIfAborted(); throw new Error(`Semantic adapter '${extractor.id}' failed: ${error instanceof Error ? error.message : String(error)}`); }
|
|
71
90
|
signal?.throwIfAborted();
|
|
72
|
-
|
|
91
|
+
const selected = slices.filter(slice => !slice.controller_file || !shouldIgnoreSourcePath(slice.controller_file, options.ignorePatterns));
|
|
92
|
+
options.onResult?.({ id: extractor.id, slices: selected.length });
|
|
93
|
+
combinedSlices.push(...selected);
|
|
73
94
|
}
|
|
74
95
|
|
|
75
96
|
return combinedSlices;
|
|
@@ -79,19 +79,22 @@ export class RubyExtractor implements CodeExtractor {
|
|
|
79
79
|
continue;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
if (methodName === "require" || methodName === "require_relative") {
|
|
82
|
+
if ((methodName === "require" || methodName === "require_relative") && !child.childForFieldName("receiver")) {
|
|
83
83
|
const argsNode = child.childForFieldName("arguments") ?? child.namedChildren[1];
|
|
84
84
|
if (argsNode) {
|
|
85
|
-
const
|
|
85
|
+
const arg = argsNode.namedChildren[0];
|
|
86
|
+
const literal = arg?.type === "string" && !arg.namedChildren.some(c => c.type === "interpolation")
|
|
87
|
+
&& !arg.text.includes("\\") && argsNode.namedChildren.length === 1;
|
|
88
|
+
const rawTarget = literal ? arg.text.slice(1, -1) : `dynamic:${child.text}`;
|
|
86
89
|
const isRel = methodName === "require_relative";
|
|
87
90
|
const leaf = rawTarget.split("/").pop() || rawTarget;
|
|
88
91
|
|
|
89
92
|
dependencies.push({
|
|
90
93
|
target: rawTarget,
|
|
91
|
-
statement:
|
|
94
|
+
statement: child.text.trim(),
|
|
92
95
|
line_number: child.startPosition.row + 1,
|
|
93
|
-
is_external: this.isExternalRequire(rawTarget, isRel),
|
|
94
|
-
imported_symbols: [leaf],
|
|
96
|
+
is_external: literal ? this.isExternalRequire(rawTarget, isRel) : false,
|
|
97
|
+
...(literal ? { imported_symbols: [leaf] } : {}),
|
|
95
98
|
});
|
|
96
99
|
}
|
|
97
100
|
}
|
|
@@ -68,23 +68,41 @@ export class RustExtractor implements CodeExtractor {
|
|
|
68
68
|
const body = node.childForFieldName("body");
|
|
69
69
|
if (name && body) {
|
|
70
70
|
for (const child of body.namedChildren) processItem(child, qualify(name.text));
|
|
71
|
+
} else if (name) {
|
|
72
|
+
dependencies.push({ target: `mod:${name.text}`, statement: node.text.trim(),
|
|
73
|
+
line_number: node.startPosition.row + 1, is_external: false, imported_symbols: [name.text] });
|
|
71
74
|
}
|
|
72
75
|
return;
|
|
73
76
|
}
|
|
74
77
|
if (node.type === "use_declaration") {
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
const argument = node.childForFieldName("argument");
|
|
79
|
+
const addUse = (item: Parser.SyntaxNode, prefix = ""): void => {
|
|
80
|
+
if (item.type === "line_comment" || item.type === "block_comment") return;
|
|
81
|
+
if (item.type === "scoped_use_list") {
|
|
82
|
+
const scope = item.childForFieldName("path")?.text;
|
|
83
|
+
const list = item.childForFieldName("list");
|
|
84
|
+
const nestedPrefix = [prefix, scope].filter(Boolean).join("::");
|
|
85
|
+
if (list) for (const child of list.namedChildren) addUse(child, nestedPrefix);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (item.type === "use_list") {
|
|
89
|
+
for (const child of item.namedChildren) addUse(child, prefix);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const alias = item.type === "use_as_clause" ? item.childForFieldName("alias")?.text : undefined;
|
|
93
|
+
const importPath = item.type === "use_as_clause" ? item.childForFieldName("path")?.text : item.text;
|
|
94
|
+
if (!importPath) return;
|
|
95
|
+
const target = importPath === "self" && prefix ? prefix : [prefix, importPath].filter(Boolean).join("::");
|
|
96
|
+
const leaf = target.split("::").pop()!;
|
|
97
|
+
dependencies.push({
|
|
98
|
+
target,
|
|
99
|
+
statement: node.text.trim().replace(/;$/, ""),
|
|
100
|
+
line_number: node.startPosition.row + 1,
|
|
101
|
+
is_external: this.isExternalUse(target),
|
|
102
|
+
imported_symbols: [...new Set([leaf, ...(alias ? [alias] : [])])],
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
if (argument) addUse(argument);
|
|
88
106
|
return;
|
|
89
107
|
}
|
|
90
108
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { VerticalSliceRecord } from "../../../types/index.ts";
|
|
2
|
+
import type { SourceInventory } from "../../resources/source-inventory.ts";
|
|
2
3
|
|
|
3
4
|
export type VerticalSliceCandidate = Omit<VerticalSliceRecord, "id" | "created_at">;
|
|
4
5
|
|
|
@@ -17,6 +18,7 @@ export interface SemanticSliceExtractor {
|
|
|
17
18
|
extractSlices(
|
|
18
19
|
projectRoot: string,
|
|
19
20
|
domainId?: number,
|
|
20
|
-
signal?: AbortSignal
|
|
21
|
+
signal?: AbortSignal,
|
|
22
|
+
inventory?: SourceInventory
|
|
21
23
|
): Promise<VerticalSliceCandidate[]> | VerticalSliceCandidate[];
|
|
22
24
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
|
|
1
2
|
import * as fs from "node:fs";
|
|
2
3
|
import * as path from "node:path";
|
|
3
4
|
import type Parser from "web-tree-sitter";
|
|
@@ -56,10 +57,10 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
56
57
|
public async extractSlices(
|
|
57
58
|
projectRoot: string = this.projectRoot,
|
|
58
59
|
domainId?: number,
|
|
59
|
-
signal?: AbortSignal
|
|
60
|
+
signal?: AbortSignal, inventory?: SourceInventory
|
|
60
61
|
): Promise<VerticalSliceCandidate[]> {
|
|
61
62
|
const root = path.resolve(projectRoot);
|
|
62
|
-
const controllerFiles =
|
|
63
|
+
const controllerFiles = listSourceFiles(fs.existsSync(path.join(root, 'src/Controller')) ? path.join(root, 'src/Controller') : path.join(root, 'src'), /\.php$/, inventory);
|
|
63
64
|
const slices: VerticalSliceCandidate[] = [];
|
|
64
65
|
const resolver = new ImportResolver(root);
|
|
65
66
|
|
|
@@ -165,7 +166,7 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
165
166
|
});
|
|
166
167
|
|
|
167
168
|
slices.push({
|
|
168
|
-
domain_id: domainId ??
|
|
169
|
+
domain_id: domainId ?? null,
|
|
169
170
|
feature_key: fullRouteName || null,
|
|
170
171
|
http_method: httpMethod,
|
|
171
172
|
route_uri: fullUri,
|
|
@@ -191,40 +192,6 @@ export class SymfonySemanticExtractor implements SemanticSliceExtractor {
|
|
|
191
192
|
return slices;
|
|
192
193
|
}
|
|
193
194
|
|
|
194
|
-
private collectControllerFiles(root: string): string[] {
|
|
195
|
-
const files: string[] = [];
|
|
196
|
-
const controllerDir = path.join(root, "src/Controller");
|
|
197
|
-
|
|
198
|
-
const scanDir = (dir: string, depth = 0) => {
|
|
199
|
-
if (depth > 5 || !fs.existsSync(dir)) return;
|
|
200
|
-
try {
|
|
201
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
202
|
-
for (const entry of entries) {
|
|
203
|
-
if (entry.name.startsWith(".") || entry.name === "vendor" || entry.name === "var" || entry.name === "tests") {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
const fullPath = path.join(dir, entry.name);
|
|
207
|
-
if (entry.isDirectory()) {
|
|
208
|
-
scanDir(fullPath, depth + 1);
|
|
209
|
-
} else if (entry.isFile() && entry.name.endsWith(".php")) {
|
|
210
|
-
files.push(fullPath);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
} catch {}
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
if (fs.existsSync(controllerDir)) {
|
|
217
|
-
scanDir(controllerDir);
|
|
218
|
-
} else {
|
|
219
|
-
const srcDir = path.join(root, "src");
|
|
220
|
-
if (fs.existsSync(srcDir)) {
|
|
221
|
-
scanDir(srcDir);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return files;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
195
|
private extractRouteAttributeFromNode(node: Parser.SyntaxNode): ParsedRouteAttribute | null {
|
|
229
196
|
const attrList = node.namedChildren.find((c) => c.type === "attribute_list");
|
|
230
197
|
if (!attrList) return null;
|
|
@@ -306,8 +306,8 @@ export class TypeScriptExtractor implements CodeExtractor {
|
|
|
306
306
|
...(importedSymbols.length > 0 ? { imported_symbols: importedSymbols } : {}),
|
|
307
307
|
});
|
|
308
308
|
}
|
|
309
|
+
return;
|
|
309
310
|
}
|
|
310
|
-
return;
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
if (node.type === "call_expression") {
|
|
@@ -387,6 +387,19 @@ export class TypeScriptExtractor implements CodeExtractor {
|
|
|
387
387
|
return;
|
|
388
388
|
}
|
|
389
389
|
|
|
390
|
+
if (stmtNode.type === "internal_module") {
|
|
391
|
+
const name = stmtNode.childForFieldName("name");
|
|
392
|
+
const body = stmtNode.childForFieldName("body");
|
|
393
|
+
if (name && body && name.type !== "string") {
|
|
394
|
+
const firstSymbol = symbols.length;
|
|
395
|
+
for (const child of body.namedChildren) processTopLevelNode(child, false);
|
|
396
|
+
for (let i = firstSymbol; i < symbols.length; i++) {
|
|
397
|
+
symbols[i].name = `${name.text}::${symbols[i].name}`;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
|
|
390
403
|
if (
|
|
391
404
|
stmtNode.type === "class_declaration" ||
|
|
392
405
|
stmtNode.type === "abstract_class_declaration" ||
|