@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.
Files changed (106) hide show
  1. package/README.md +46 -28
  2. package/package.json +4 -4
  3. package/src/cli/commands/check.ts +27 -16
  4. package/src/cli/commands/hook.ts +38 -101
  5. package/src/cli/commands/init.ts +26 -9
  6. package/src/cli/commands/sync.ts +4 -6
  7. package/src/cli/hook-payload.ts +43 -0
  8. package/src/cli/index.ts +9 -52
  9. package/src/cli/scaffold/harness-config.ts +48 -8
  10. package/src/cli/templates/hooks.ts +49 -14
  11. package/src/cli/templates/rules.ts +34 -49
  12. package/src/cli/templates/skill.ts +39 -35
  13. package/src/core/boundary/evaluator.ts +67 -83
  14. package/src/core/boundary/staged-auditor.ts +102 -40
  15. package/src/core/config/domain-ownership.ts +45 -0
  16. package/src/core/config/loader.ts +81 -29
  17. package/src/core/config/schema.ts +0 -10
  18. package/src/core/database/repositories/dependency.repository.ts +169 -148
  19. package/src/core/database/repositories/domain.repository.ts +46 -3
  20. package/src/core/database/repositories/symbol.repository.ts +226 -87
  21. package/src/core/database/repository.ts +73 -18
  22. package/src/core/database/schema.ts +2 -33
  23. package/src/core/discovery/navigation.ts +105 -0
  24. package/src/core/discovery/topology-detector.ts +60 -2
  25. package/src/core/ingestion/pipeline.ts +96 -129
  26. package/src/core/parser/behavioral-analyzer.ts +26 -22
  27. package/src/core/parser/boundary-tracker.ts +15 -0
  28. package/src/core/parser/extractors/base.ts +7 -3
  29. package/src/core/parser/extractors/csharp.ts +7 -3
  30. package/src/core/parser/extractors/django-semantic.ts +4 -36
  31. package/src/core/parser/extractors/elysia-semantic.ts +3 -24
  32. package/src/core/parser/extractors/express-semantic.ts +3 -18
  33. package/src/core/parser/extractors/fastapi-semantic.ts +19 -53
  34. package/src/core/parser/extractors/fastify-semantic.ts +3 -18
  35. package/src/core/parser/extractors/flask-semantic.ts +22 -55
  36. package/src/core/parser/extractors/go-semantic.ts +92 -33
  37. package/src/core/parser/extractors/hono-semantic.ts +3 -24
  38. package/src/core/parser/extractors/java.ts +5 -3
  39. package/src/core/parser/extractors/laravel-semantic.ts +44 -16
  40. package/src/core/parser/extractors/mcp-cli-semantic.ts +6 -7
  41. package/src/core/parser/extractors/nestjs-semantic.ts +3 -19
  42. package/src/core/parser/extractors/php.ts +16 -0
  43. package/src/core/parser/extractors/python.ts +9 -4
  44. package/src/core/parser/extractors/registry.ts +26 -5
  45. package/src/core/parser/extractors/ruby.ts +8 -5
  46. package/src/core/parser/extractors/rust.ts +31 -13
  47. package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
  48. package/src/core/parser/extractors/symfony-semantic.ts +4 -37
  49. package/src/core/parser/extractors/typescript.ts +14 -1
  50. package/src/core/parser/implementation-fingerprint.ts +97 -0
  51. package/src/core/parser/language-capabilities.ts +23 -7
  52. package/src/core/parser/schema/providers/laravel-migration-provider.ts +73 -50
  53. package/src/core/parser/schema/schema-provider-registry.ts +1 -3
  54. package/src/core/parser/schema/schema-provider.interface.ts +2 -1
  55. package/src/core/parser/semantic-revision.ts +3 -0
  56. package/src/core/parser/static-string.ts +51 -0
  57. package/src/core/resolver/call-graph-tracer.ts +337 -28
  58. package/src/core/resolver/import-resolver.ts +107 -179
  59. package/src/core/resolver/interpretation-inputs.ts +7 -0
  60. package/src/core/resolver/languages/go.ts +103 -0
  61. package/src/core/resolver/languages/managed.ts +200 -0
  62. package/src/core/resolver/languages/python.ts +115 -0
  63. package/src/core/resolver/languages/ruby.ts +40 -0
  64. package/src/core/resolver/languages/rust.ts +127 -0
  65. package/src/core/resolver/languages/shared.ts +71 -0
  66. package/src/core/resolver/module-resolver.ts +8 -4
  67. package/src/core/resolver/slice-catalog.ts +79 -0
  68. package/src/core/resolver/slice-format.ts +9 -0
  69. package/src/core/resolver/symbol-impact.ts +381 -0
  70. package/src/core/resolver/vertical-slice-tracer.ts +93 -115
  71. package/src/core/resources/ignore.ts +22 -1
  72. package/src/core/resources/source-files.ts +143 -20
  73. package/src/core/resources/source-inventory.ts +55 -0
  74. package/src/core/retrieval/context-page.ts +109 -0
  75. package/src/core/retrieval/context.ts +320 -0
  76. package/src/core/retrieval/resolution-warnings.ts +21 -0
  77. package/src/core/retrieval/symbol-evidence.ts +97 -0
  78. package/src/core/retrieval/typescript-references.ts +262 -0
  79. package/src/core/telemetry/telemetry.ts +54 -9
  80. package/src/index.ts +0 -3
  81. package/src/mcp/schemas.ts +61 -420
  82. package/src/mcp/server.ts +116 -290
  83. package/src/mcp/tools/boundary.ts +2 -2
  84. package/src/mcp/tools/check-boundary.ts +55 -60
  85. package/src/mcp/tools/get-domain-catalog.ts +32 -219
  86. package/src/mcp/tools/get-symbol-impact.ts +45 -5
  87. package/src/mcp/tools/get-symbol.ts +227 -3
  88. package/src/mcp/tools/locate-symbol.ts +54 -14
  89. package/src/mcp/tools/{domain.ts → map.ts} +4 -18
  90. package/src/mcp/tools/register-domain.ts +41 -3
  91. package/src/mcp/tools/symbol.ts +23 -21
  92. package/src/mcp/tools/trace-vertical-slice.ts +36 -10
  93. package/src/mcp/workspace-manager.ts +15 -4
  94. package/src/mcp/workspace-watcher.ts +8 -8
  95. package/src/types/index.ts +35 -53
  96. package/src/cli/commands/topology.ts +0 -161
  97. package/src/core/database/repositories/environment.repository.ts +0 -207
  98. package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
  99. package/src/core/session/session-manager.ts +0 -107
  100. package/src/core/topology/environment-detector.ts +0 -973
  101. package/src/core/topology/types.ts +0 -83
  102. package/src/mcp/tools/feature.ts +0 -67
  103. package/src/mcp/tools/get-environment-topology.ts +0 -138
  104. package/src/mcp/tools/get-feature-context.ts +0 -224
  105. package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
  106. package/src/mcp/tools/register-feature.ts +0 -110
@@ -1,7 +1,8 @@
1
+ import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
2
+ import { readPythonStaticString as cleanLiteral } from "../static-string.ts";
1
3
  import type Parser from "web-tree-sitter";
2
4
  import { parseSourceWithTreeSitter } from "../wasm-loader.ts";
3
5
  import { readOptionalSourceFile } from "../../resources/source-files.ts";
4
- import { isIgnoredDirectory } from "../../resources/ignore.ts";
5
6
  import { ImportResolver } from "../../resolver/import-resolver.ts";
6
7
  import * as fs from "node:fs";
7
8
  import * as path from "node:path";
@@ -25,7 +26,7 @@ interface ExtractedBlueprintRegistration {
25
26
  relPath: string;
26
27
  parentVar: string;
27
28
  targetExpr: string;
28
- prefix: string;
29
+ prefix: string | null | undefined; // undefined: no override; null: unresolved expression.
29
30
  line: number;
30
31
  }
31
32
 
@@ -34,16 +35,6 @@ interface ImportBinding {
34
35
  symbol?: string;
35
36
  }
36
37
 
37
- function cleanLiteral(node: Parser.SyntaxNode | null | undefined): string | undefined {
38
- if (!node) return undefined;
39
- if (node.type === "string") {
40
- const raw = node.text.trim();
41
- const match = raw.match(/^[rRbBuU]*('''|"""|'|")([\s\S]*?)\1$/);
42
- if (match) return match[2];
43
- return raw.replace(/^[rRbBuU]*['"]|['"]$/g, "");
44
- }
45
- return undefined;
46
- }
47
38
 
48
39
  function normalizeRouteUri(prefix: string, rawPath: string): string {
49
40
  const p = (prefix ?? "").trim().replace(/\/+$/, "");
@@ -92,17 +83,17 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
92
83
  public async extractSlices(
93
84
  projectRoot: string,
94
85
  domainId?: number,
95
- signal?: AbortSignal
86
+ signal?: AbortSignal, inventory?: SourceInventory
96
87
  ): Promise<VerticalSliceCandidate[]> {
97
88
  const slices: VerticalSliceCandidate[] = [];
98
- const pyFiles = this.findPythonFiles(projectRoot);
89
+ const pyFiles = listSourceFiles(projectRoot, /\.py$/, inventory);
99
90
  const resolver = new ImportResolver(projectRoot);
100
91
 
101
92
  const allRoutes: ExtractedFlaskRoute[] = [];
102
93
  const allRegistrations: ExtractedBlueprintRegistration[] = [];
103
94
  const localBlueprints = new Map<
104
95
  string,
105
- { bpName: string; prefix: string; isApp: boolean }
96
+ { bpName: string; prefix: string | null; isApp: boolean }
106
97
  >();
107
98
  const fileImports = new Map<string, Map<string, ImportBinding>>();
108
99
 
@@ -176,7 +167,7 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
176
167
 
177
168
  const args = call.childForFieldName("arguments")?.namedChildren ?? [];
178
169
  let bpName = leftName;
179
- let prefix = "";
170
+ let prefix: string | null = "";
180
171
 
181
172
  if (isBlueprint && args.length > 0) {
182
173
  const firstArg = args[0];
@@ -190,12 +181,13 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
190
181
  (child) => child.type === "keyword_argument" && child.childForFieldName("name")?.text === "url_prefix"
191
182
  );
192
183
  if (prefixKw) {
193
- prefix = cleanLiteral(prefixKw.childForFieldName("value")) ?? "";
184
+ const value = prefixKw.childForFieldName("value");
185
+ prefix = value?.type === "none" ? "" : cleanLiteral(value) ?? null;
194
186
  }
195
187
 
196
188
  localBlueprints.set(`${relPath}#${leftName}`, {
197
189
  bpName,
198
- prefix: prefix.replace(/\/+$/, ""),
190
+ prefix: prefix?.replace(/\/+$/, "") ?? null,
199
191
  isApp,
200
192
  });
201
193
  });
@@ -214,13 +206,14 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
214
206
  const prefixKw = args.find(
215
207
  (c) => c.type === "keyword_argument" && c.childForFieldName("name")?.text === "url_prefix"
216
208
  );
217
- const incPrefix = cleanLiteral(prefixKw?.childForFieldName("value")) ?? "";
209
+ const prefixValue = prefixKw?.childForFieldName("value");
210
+ const incPrefix = !prefixKw || prefixValue?.type === "none" ? undefined : cleanLiteral(prefixValue) ?? null;
218
211
  allRegistrations.push({
219
212
  file,
220
213
  relPath,
221
214
  parentVar,
222
215
  targetExpr,
223
- prefix: incPrefix.replace(/\/+$/, ""),
216
+ prefix: incPrefix === undefined ? undefined : incPrefix?.replace(/\/+$/, "") ?? null,
224
217
  line: node.startPosition.row + 1,
225
218
  });
226
219
  });
@@ -318,8 +311,8 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
318
311
  }
319
312
 
320
313
  // 5. Build Inclusion Graph and Resolve Cross-File Blueprint Targets
321
- const routerChildren = new Map<string, Array<{ childKey: string; prefix: string }>>();
322
- const incomingRegistrations = new Map<string, Array<{ parentKey: string; prefix: string }>>();
314
+ const routerChildren = new Map<string, Array<{ childKey: string; prefix: string | null | undefined }>>();
315
+ const incomingRegistrations = new Map<string, Array<{ parentKey: string; prefix: string | null | undefined }>>();
323
316
 
324
317
  for (const reg of allRegistrations) {
325
318
  const parentKey = `${reg.relPath}#${reg.parentVar}`;
@@ -386,8 +379,8 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
386
379
  for (const routerKey of allRouterKeys) {
387
380
  const incoming = incomingRegistrations.get(routerKey);
388
381
  if (!incoming || incoming.length === 0) {
389
- const local = localBlueprints.get(routerKey)?.prefix ?? "";
390
- effectivePrefixesByRouter.set(routerKey, [local]);
382
+ const local = localBlueprints.get(routerKey);
383
+ effectivePrefixesByRouter.set(routerKey, local?.prefix === null ? [] : [local?.prefix ?? ""]);
391
384
  }
392
385
  }
393
386
 
@@ -405,11 +398,11 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
405
398
  if (visitedEdges.has(edgeKey)) continue;
406
399
  visitedEdges.add(edgeKey);
407
400
 
408
- const childLocal = localBlueprints.get(child.childKey)?.prefix ?? "";
409
- const nextPrefixes = currentPrefixes.map((p) => {
401
+ const childPrefix = child.prefix === undefined ? localBlueprints.get(child.childKey)?.prefix ?? null : child.prefix;
402
+ const nextPrefixes = childPrefix === null ? [] : currentPrefixes.map((p) => {
410
403
  const combined = `${p ? (p.startsWith("/") ? p : `/${p}`) : ""}${
411
- child.prefix ? (child.prefix.startsWith("/") ? child.prefix : `/${child.prefix}`) : ""
412
- }${childLocal ? (childLocal.startsWith("/") ? childLocal : `/${childLocal}`) : ""}`;
404
+ childPrefix ? (childPrefix.startsWith("/") ? childPrefix : `/${childPrefix}`) : ""
405
+ }`;
413
406
  return combined.replace(/\/+/g, "/").replace(/\/+$/, "");
414
407
  });
415
408
 
@@ -423,10 +416,7 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
423
416
  // 7. Generate Vertical Slices (Level 0 – Level 3)
424
417
  for (const route of allRoutes) {
425
418
  const routerKey = `${route.relPath}#${route.routerVar}`;
426
- let prefixes = effectivePrefixesByRouter.get(routerKey);
427
- if (!prefixes || prefixes.length === 0) {
428
- prefixes = [localBlueprints.get(routerKey)?.prefix ?? ""];
429
- }
419
+ const prefixes = effectivePrefixesByRouter.get(routerKey) ?? [];
430
420
 
431
421
  const bpMeta = localBlueprints.get(routerKey);
432
422
  const controllerClass = bpMeta?.bpName || path.basename(route.file, ".py");
@@ -488,28 +478,5 @@ export class FlaskSemanticExtractor implements SemanticSliceExtractor {
488
478
 
489
479
  return slices;
490
480
  }
491
-
492
- private findPythonFiles(dir: string): string[] {
493
- const results: string[] = [];
494
- const traverse = (currentDir: string) => {
495
- if (!fs.existsSync(currentDir)) return;
496
- try {
497
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
498
- for (const entry of entries) {
499
- if (isIgnoredDirectory(entry.name)) continue;
500
-
501
- const fullPath = path.join(currentDir, entry.name);
502
- if (entry.isDirectory()) {
503
- traverse(fullPath);
504
- } else if (entry.isFile() && entry.name.endsWith(".py")) {
505
- results.push(fullPath);
506
- }
507
- }
508
- } catch {}
509
- };
510
-
511
- traverse(dir);
512
- return results;
513
- }
514
481
  }
515
482
 
@@ -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 * as fs from "node:fs";
4
4
  import * as path from "node:path";
5
5
  import type { SemanticSliceExtractor, VerticalSliceCandidate } from "./semantic-extractor.interface.ts";
@@ -22,12 +22,12 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
22
22
  }
23
23
 
24
24
  const goMod = path.join(projectRoot, "go.mod");
25
- if (fs.existsSync(goMod)) {
25
+ if (fs.existsSync(goMod) || listSourceFiles(projectRoot, /(?:^|[\\/])go\.mod$/).length > 0) {
26
26
  return true;
27
27
  }
28
28
 
29
29
  // Check Go source files for HTTP framework or standard library imports
30
- const goFiles = this.findGoFiles(projectRoot, 3);
30
+ const goFiles = listSourceFiles(projectRoot, /\.go$/).filter(file => !file.endsWith('_test.go'));
31
31
  for (const file of goFiles) {
32
32
  try {
33
33
  const content = fs.readFileSync(file, "utf-8");
@@ -46,9 +46,9 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
46
46
  return false;
47
47
  }
48
48
 
49
- public extractSlices(projectRoot: string, domainId?: number): VerticalSliceCandidate[] {
49
+ public extractSlices(projectRoot: string, domainId?: number, signal?: AbortSignal, inventory?: SourceInventory): VerticalSliceCandidate[] {
50
50
  const slices: VerticalSliceCandidate[] = [];
51
- const goFiles = this.findGoFiles(projectRoot);
51
+ const goFiles = listSourceFiles(projectRoot, /\.go$/, inventory).filter(file => !file.endsWith('_test.go'));
52
52
 
53
53
  interface HandlerInfo {
54
54
  name: string;
@@ -59,6 +59,8 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
59
59
  boundDto?: string;
60
60
  serviceCall?: string;
61
61
  repoCall?: string;
62
+ receiverVar?: string;
63
+ body: string;
62
64
  }
63
65
 
64
66
  interface GoStructInfo {
@@ -77,12 +79,21 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
77
79
  line: number;
78
80
  body: string;
79
81
  params?: string;
82
+ receiverVar?: string;
80
83
  }
81
84
 
82
85
  // 1. Catalog all handler functions & methods across .go files
83
86
  const handlers = new Map<string, HandlerInfo>();
84
87
  const goStructs = new Map<string, GoStructInfo>();
85
88
  const goMethods = new Map<string, GoMethodInfo>();
89
+ const constructors = new Map<string, string>();
90
+ const rootGoMod = path.join(projectRoot, "go.mod");
91
+ const discoveredGoMods = fs.existsSync(rootGoMod) ? [rootGoMod] : listSourceFiles(projectRoot, /(?:^|[\\/])go\.mod$/, inventory);
92
+ const goModPath = discoveredGoMods[0];
93
+ const moduleRoot = goModPath ? path.dirname(goModPath) : projectRoot;
94
+ const moduleName = goModPath && fs.existsSync(goModPath)
95
+ ? readOptionalSourceFile(goModPath, "utf-8").match(/^module\s+(\S+)/m)?.[1]
96
+ : undefined;
86
97
 
87
98
  for (const file of goFiles) {
88
99
  const content = readOptionalSourceFile(file, "utf-8");
@@ -150,7 +161,7 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
150
161
 
151
162
  // Detect repo/db calls: h.repo.Save(...) or db.Create(&order)
152
163
  let repoCall: string | undefined;
153
- const rMatch = fnBody.match(/(?:([a-zA-Z0-9_]+(?:Repo|Repository))\s*\.\s*([A-Z][a-zA-Z0-9_]+)|db\s*\.\s*(?:Create|Save|Find|First|Update|Delete)\s*\(\s*&?([A-Z][a-zA-Z0-9_]+)\s*\))/i);
164
+ const rMatch = fnBody.match(/(?:([a-zA-Z0-9_]+(?:Repo|Repository))\s*\.\s*([A-Z][a-zA-Z0-9_]+)\s*\(|db\s*\.\s*(?:Create|Save|Find|First|Update|Delete)\s*\(\s*&?([A-Z][a-zA-Z0-9_]+)\s*\))/i);
154
165
  if (rMatch) {
155
166
  repoCall = rMatch[1] ? `${rMatch[1]}::${rMatch[2]}` : `DB::${rMatch[3]}`;
156
167
  }
@@ -164,6 +175,8 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
164
175
  boundDto,
165
176
  serviceCall,
166
177
  repoCall,
178
+ receiverVar: fMatch[0].match(/^func\s*\(\s*(\w+)/)?.[1],
179
+ body: fnBody,
167
180
  };
168
181
 
169
182
  if (receiver) {
@@ -205,20 +218,66 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
205
218
  const bEnd = this.findGoBraceBlockEnd(content, bStart - 1);
206
219
  const bText = content.slice(bStart, bEnd);
207
220
  const params = afMatch[3];
221
+ const returnType = afMatch[0].match(/\)\s+\*?([A-Z][a-zA-Z0-9_]*)\s*\{$/)?.[1];
222
+ if (!rcv && returnType) {
223
+ constructors.set(`${path.dirname(file)}:${fn}`, returnType);
224
+ }
208
225
  if (rcv) {
209
- goMethods.set(`${rcv}.${fn}`, { receiver: rcv, name: fn, file, relPath, line: fLine, body: bText, params });
226
+ goMethods.set(`${rcv}.${fn}`, { receiver: rcv, name: fn, file, relPath, line: fLine, body: bText, params,
227
+ receiverVar: afMatch[0].match(/^func\s*\(\s*(\w+)/)?.[1] });
210
228
  } else {
211
229
  goMethods.set(fn, { name: fn, file, relPath, line: fLine, body: bText, params });
212
230
  }
213
231
  }
214
232
  }
215
233
 
234
+ // Resolve calls through declared fields, regardless of the field's local name.
235
+ for (const handler of handlers.values()) {
236
+ if (!handler.receiver || !handler.receiverVar) continue;
237
+ const fields = goStructs.get(handler.receiver)?.fields;
238
+ const calls = /\b([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)\s*\.\s*([A-Z][a-zA-Z0-9_]*)\s*\(/g;
239
+ for (const call of handler.body.matchAll(calls)) {
240
+ const fieldType = fields?.get(call[2]);
241
+ if (call[1] === handler.receiverVar && fieldType && /(?:Service|Usecase|UC)$/i.test(fieldType)) {
242
+ handler.serviceCall = `${call[2]}::${call[3]}`;
243
+ break;
244
+ }
245
+ }
246
+ }
247
+
248
+ // Collect Chi r.Route("/prefix", func(sub chi.Router) { helper(sub, ...) }) delegations across package files
249
+ const delegatedRoutePrefixes = new Map<string, string>();
250
+ for (const file of goFiles) {
251
+ const content = readOptionalSourceFile(file, "utf-8");
252
+ if (!content) continue;
253
+ const chiBlockRegex = /([a-zA-Z0-9_]+)\.Route\s*\(\s*["']([^"']*)["']\s*,\s*func\s*\(\s*([a-zA-Z0-9_]+)\s+chi\.Router\s*\)\s*\{/g;
254
+ let cbMatch: RegExpExecArray | null;
255
+ while ((cbMatch = chiBlockRegex.exec(content)) !== null) {
256
+ const prefixRaw = cbMatch[2].replace(/\/+$/, "");
257
+ const prefix = prefixRaw ? (prefixRaw.startsWith("/") ? prefixRaw : `/${prefixRaw}`) : "";
258
+ const subRouter = cbMatch[3];
259
+ const blockStart = cbMatch.index + cbMatch[0].length;
260
+ const blockEnd = this.findGoBraceBlockEnd(content, blockStart - 1);
261
+ const blockBody = content.slice(blockStart, blockEnd);
262
+ const callRegex = new RegExp(`\\b([a-zA-Z_][a-zA-Z0-9_]*)\\s*\\(\\s*${subRouter}\\b`, "g");
263
+ for (const call of blockBody.matchAll(callRegex)) {
264
+ delegatedRoutePrefixes.set(`${path.dirname(file)}:${call[1]}`, prefix);
265
+ }
266
+ }
267
+ }
268
+
216
269
  // 2. Extract route registrations per file with lexical block scoping
217
270
  for (const file of goFiles) {
218
271
  const content = readOptionalSourceFile(file, "utf-8");
219
272
  if (!content) continue;
220
273
 
221
274
  const relPath = path.relative(projectRoot, file).replace(/\\/g, "/");
275
+ const importedPackages = new Map<string, string>();
276
+ for (const spec of content.matchAll(/^\s*(?:import\s+)?(?:(\w+)\s+)?"([^"\n]+)"/gm)) {
277
+ if (moduleName && spec[2].startsWith(`${moduleName}/`)) {
278
+ importedPackages.set(spec[1] || path.basename(spec[2]), path.join(moduleRoot, spec[2].slice(moduleName.length + 1)));
279
+ }
280
+ }
222
281
 
223
282
  // Find router/setup functions and methods to scope groups and variable types
224
283
  const setupFuncRegex =
@@ -228,6 +287,7 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
228
287
  while ((funcMatch = setupFuncRegex.exec(content)) !== null) {
229
288
  const receiverVar = funcMatch[1];
230
289
  const receiverType = funcMatch[2];
290
+ const funcName = funcMatch[3];
231
291
  const funcParams = funcMatch[4];
232
292
  const funcStart = funcMatch.index;
233
293
  const bodyStart = funcStart + funcMatch[0].length;
@@ -259,8 +319,23 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
259
319
  }
260
320
  }
261
321
 
322
+ // A factory call is typed by its declared return, never by the function name.
323
+ for (const call of funcBody.matchAll(/\b(\w+)\s*:=\s*(?:(\w+)\.)?([A-Z]\w*)\s*\(/g)) {
324
+ const directory = call[2] ? importedPackages.get(call[2]) : path.dirname(file);
325
+ const typeName = directory && constructors.get(`${directory}:${call[3]}`);
326
+ scopedVarReceivers.delete(call[1]);
327
+ if (typeName) scopedVarReceivers.set(call[1], typeName);
328
+ }
329
+
262
330
  // Scoped router groups: groupVar -> accumulatedPrefix
263
331
  const scopedGroupPrefixes = new Map<string, string>();
332
+ const delegatedPrefix = delegatedRoutePrefixes.get(`${path.dirname(file)}:${funcName}`);
333
+ if (delegatedPrefix) {
334
+ const chiParamMatch = funcParams.match(/\b([a-zA-Z0-9_]+)\s+chi\.Router\b/);
335
+ if (chiParamMatch) {
336
+ scopedGroupPrefixes.set(chiParamMatch[1], delegatedPrefix);
337
+ }
338
+ }
264
339
 
265
340
  // Gin / Echo groups: v1 := r.Group("/api/v1")
266
341
  const groupRegex = /([a-zA-Z0-9_]+)\s*:=\s*([a-zA-Z0-9_]+)\.Group\s*\(\s*["']([^"']*)["']/g;
@@ -289,9 +364,9 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
289
364
  }
290
365
 
291
366
  // 3. Extract route registrations within this function scope
292
- // Method 1: Gin / Echo / Chi HTTP method calls: r.GET("/ping", pingHandler), v1.POST("/orders", h.CreateOrder)
367
+ // Method 1: Gin / Echo / Chi HTTP method calls: r.GET("/ping", pingHandler), v1.POST("/orders", h.CreateOrder), r.With(mw).Get("/x", h.Get)
293
368
  const routeRegex =
294
- /([a-zA-Z0-9_]+)\.(GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD|Get|Post|Put|Patch|Delete|Options|Head)\s*\(\s*["']([^"']*)["']\s*,\s*(?:[a-zA-Z0-9_.]+\s*,\s*)*(?:func\s*\([^)]*\)|([a-zA-Z0-9_.]+))/g;
369
+ /([a-zA-Z0-9_]+)(?:\s*\.\s*With\s*\([^)]*\))*\s*\.\s*(GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD|Get|Post|Put|Patch|Delete|Options|Head)\s*\(\s*["']([^"']*)["']\s*,\s*(?:[a-zA-Z0-9_.]+\s*,\s*)*(?:func\s*\([^)]*\)|([a-zA-Z0-9_.]+))/g;
295
370
  let rMatch: RegExpExecArray | null;
296
371
 
297
372
  while ((rMatch = routeRegex.exec(funcBody)) !== null) {
@@ -467,11 +542,18 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
467
542
  // Scan service body for repo or DB persistence
468
543
  if (targetMethod?.body) {
469
544
  const rMatch = targetMethod.body.match(
470
- /(?:(?:[a-zA-Z0-9_]+\.)?([a-zA-Z0-9_]*(?:repo|repository))\s*\.\s*([A-Z][a-zA-Z0-9_]+)|db\s*\.\s*(?:Create|Save|Find|First|Update|Delete)\s*\(\s*&?([A-Z][a-zA-Z0-9_]+)\s*\))/i
545
+ /(?:(?:[a-zA-Z0-9_]+\.)?([a-zA-Z0-9_]*(?:repo|repository))\s*\.\s*([A-Z][a-zA-Z0-9_]+)\s*\(|db\s*\.\s*(?:Create|Save|Find|First|Update|Delete)\s*\(\s*&?([A-Z][a-zA-Z0-9_]+)\s*\))/i
471
546
  );
472
547
  if (rMatch && !repoCall) {
473
548
  repoCall = rMatch[1] ? `${rMatch[1]}::${rMatch[2]}` : `DB::${rMatch[3]}`;
474
549
  }
550
+ for (const call of targetMethod.body.matchAll(/\b(\w+)\.(\w+)\s*\.\s*([A-Z]\w*)\s*\(/g)) {
551
+ const fieldType = targetStruct?.fields.get(call[2]);
552
+ if (call[1] === targetMethod.receiverVar && fieldType && /(?:Repo|Repository)$/i.test(fieldType)) {
553
+ repoCall = `${call[2]}::${call[3]}`;
554
+ break;
555
+ }
556
+ }
475
557
  }
476
558
  }
477
559
 
@@ -585,27 +667,4 @@ export class GoSemanticExtractor implements SemanticSliceExtractor {
585
667
 
586
668
  return content.length;
587
669
  }
588
-
589
- private findGoFiles(dir: string, maxDepth: number = 10): string[] {
590
- const results: string[] = [];
591
- const traverse = (currentDir: string, currentDepth: number) => {
592
- if (currentDepth > maxDepth || !fs.existsSync(currentDir)) return;
593
- try {
594
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
595
- for (const entry of entries) {
596
- if (isIgnoredDirectory(entry.name)) continue;
597
-
598
- const fullPath = path.join(currentDir, entry.name);
599
- if (entry.isDirectory()) {
600
- traverse(fullPath, currentDepth + 1);
601
- } else if (entry.isFile() && entry.name.endsWith(".go") && !entry.name.endsWith("_test.go")) {
602
- results.push(fullPath);
603
- }
604
- }
605
- } catch {}
606
- };
607
-
608
- traverse(dir, 0);
609
- return results;
610
- }
611
670
  }
@@ -1,7 +1,7 @@
1
+ import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
1
2
  import type Parser from "web-tree-sitter";
2
3
  import { parseWithTreeSitter } from "../wasm-loader.ts";
3
4
  import { readOptionalSourceFile } from "../../resources/source-files.ts";
4
- import { isIgnoredDirectory } from "../../resources/ignore.ts";
5
5
  import { ImportResolver } from "../../resolver/import-resolver.ts";
6
6
  import * as fs from "node:fs";
7
7
  import * as path from "node:path";
@@ -84,10 +84,10 @@ export class HonoSemanticExtractor implements SemanticSliceExtractor {
84
84
  public async extractSlices(
85
85
  projectRoot: string,
86
86
  domainId?: number,
87
- signal?: AbortSignal
87
+ signal?: AbortSignal, inventory?: SourceInventory
88
88
  ): Promise<VerticalSliceCandidate[]> {
89
89
  const slices: VerticalSliceCandidate[] = [];
90
- const sourceFiles = this.findSourceFiles(projectRoot);
90
+ const sourceFiles = listSourceFiles(projectRoot, /\.(?:[cm]?[jt]sx?)$/, inventory).filter(file => !file.endsWith('.d.ts'));
91
91
  const resolver = new ImportResolver(projectRoot);
92
92
 
93
93
  const allRoutes: ExtractedRoute[] = [];
@@ -542,26 +542,5 @@ export class HonoSemanticExtractor implements SemanticSliceExtractor {
542
542
 
543
543
  return prefixesByRouter;
544
544
  }
545
-
546
- private findSourceFiles(dir: string): string[] {
547
- const results: string[] = [];
548
- const traverse = (current: string) => {
549
- if (!fs.existsSync(current)) return;
550
- try {
551
- const entries = fs.readdirSync(current, { withFileTypes: true });
552
- for (const entry of entries) {
553
- if (isIgnoredDirectory(entry.name)) continue;
554
- const full = path.join(current, entry.name);
555
- if (entry.isDirectory()) {
556
- traverse(full);
557
- } else if (entry.isFile() && /\.(ts|js|tsx|jsx)$/.test(entry.name) && !entry.name.endsWith(".d.ts")) {
558
- results.push(full);
559
- }
560
- }
561
- } catch {}
562
- };
563
- traverse(dir);
564
- return results;
565
- }
566
545
  }
567
546
 
@@ -97,7 +97,8 @@ export class JavaExtractor implements CodeExtractor {
97
97
  } else if (
98
98
  member.type === "class_declaration" ||
99
99
  member.type === "interface_declaration" ||
100
- member.type === "enum_declaration"
100
+ member.type === "enum_declaration" ||
101
+ member.type === "record_declaration"
101
102
  ) {
102
103
  processTopLevel(member, className);
103
104
  }
@@ -107,12 +108,13 @@ export class JavaExtractor implements CodeExtractor {
107
108
  const processTopLevel = (node: Parser.SyntaxNode, parentName?: string): void => {
108
109
  if (node.type === "import_declaration") {
109
110
  const pathNode = node.namedChildren.find((c) => c.type === "scoped_identifier" || c.type === "identifier");
110
- const rawImport = pathNode ? pathNode.text : (lines[node.startPosition.row] ?? "").replace(/^import\s+|;$/g, "").trim();
111
+ const rawImport = pathNode ? pathNode.text + (node.namedChildren.some(c => c.type === "asterisk") ? ".*" : "")
112
+ : node.text.replace(/^import\s+(?:static\s+)?|;$/g, "").trim();
111
113
  const leafSymbol = rawImport.split(".").pop() || rawImport;
112
114
 
113
115
  dependencies.push({
114
116
  target: rawImport,
115
- statement: (lines[node.startPosition.row] ?? node.text).trim().replace(/;$/, ""),
117
+ statement: node.text.trim().replace(/;$/, ""),
116
118
  line_number: node.startPosition.row + 1,
117
119
  is_external: this.isExternalImport(rawImport),
118
120
  imported_symbols: [leafSymbol],