@dimassetoid/septum-mcp 0.3.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +38 -55
  2. package/package.json +7 -5
  3. package/src/cli/commands/check.ts +14 -10
  4. package/src/cli/commands/hook.ts +41 -6
  5. package/src/cli/commands/init.ts +10 -1
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +32 -4
  9. package/src/cli/index.ts +7 -0
  10. package/src/cli/templates/hooks.ts +3 -14
  11. package/src/cli/templates/skill.ts +17 -10
  12. package/src/core/boundary/audit.ts +383 -0
  13. package/src/core/boundary/evaluator.ts +251 -114
  14. package/src/core/boundary/staged-auditor.ts +147 -55
  15. package/src/core/config/domain-ownership.ts +6 -4
  16. package/src/core/config/domain-registration.ts +141 -0
  17. package/src/core/config/loader.ts +1 -25
  18. package/src/core/config/schema.ts +24 -36
  19. package/src/core/database/client.ts +2 -0
  20. package/src/core/database/repositories/dependency.repository.ts +334 -572
  21. package/src/core/database/repositories/domain.repository.ts +2 -1
  22. package/src/core/database/repositories/file.repository.ts +10 -0
  23. package/src/core/database/repositories/symbol.repository.ts +97 -398
  24. package/src/core/database/repository.ts +68 -9
  25. package/src/core/database/schema.ts +26 -0
  26. package/src/core/discovery/declarative-routes.ts +69 -0
  27. package/src/core/discovery/framework-detector.ts +149 -0
  28. package/src/core/discovery/navigation.ts +222 -58
  29. package/src/core/discovery/topology-detector.ts +93 -168
  30. package/src/core/errors.ts +19 -0
  31. package/src/core/ingestion/pipeline.ts +287 -88
  32. package/src/core/parser/extractors/base.ts +11 -3
  33. package/src/core/parser/extractors/csharp.ts +2 -2
  34. package/src/core/parser/extractors/django-routing.ts +163 -0
  35. package/src/core/parser/extractors/django-semantic.ts +397 -481
  36. package/src/core/parser/extractors/elysia-semantic.ts +172 -475
  37. package/src/core/parser/extractors/express-semantic.ts +195 -383
  38. package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
  39. package/src/core/parser/extractors/fastify-semantic.ts +216 -717
  40. package/src/core/parser/extractors/flask-semantic.ts +89 -352
  41. package/src/core/parser/extractors/go-routing.ts +344 -0
  42. package/src/core/parser/extractors/go-semantic.ts +205 -562
  43. package/src/core/parser/extractors/go.ts +6 -3
  44. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  45. package/src/core/parser/extractors/hono-semantic.ts +132 -509
  46. package/src/core/parser/extractors/java.ts +2 -2
  47. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  48. package/src/core/parser/extractors/laravel-semantic.ts +143 -335
  49. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  50. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  51. package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
  52. package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
  53. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  54. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  55. package/src/core/parser/extractors/php.ts +1 -1
  56. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  57. package/src/core/parser/extractors/python.ts +5 -9
  58. package/src/core/parser/extractors/registry.ts +2 -0
  59. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  60. package/src/core/parser/extractors/ruby.ts +2 -2
  61. package/src/core/parser/extractors/rust.ts +4 -4
  62. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  63. package/src/core/parser/extractors/symfony-semantic.ts +72 -226
  64. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  65. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  66. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  67. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  68. package/src/core/parser/extractors/typescript.ts +23 -216
  69. package/src/core/parser/language-capabilities.ts +1 -1
  70. package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
  71. package/src/core/parser/wasm-loader.ts +6 -2
  72. package/src/core/resolver/ast-method-tracer.ts +230 -0
  73. package/src/core/resolver/call-graph-helpers.ts +72 -0
  74. package/src/core/resolver/call-graph-tracer.ts +169 -414
  75. package/src/core/resolver/dependency-analysis.ts +593 -0
  76. package/src/core/resolver/import-candidates.ts +120 -0
  77. package/src/core/resolver/import-evidence.ts +88 -0
  78. package/src/core/resolver/import-resolver.ts +60 -7
  79. package/src/core/resolver/interpretation-inputs.ts +60 -2
  80. package/src/core/resolver/languages/python.ts +31 -13
  81. package/src/core/resolver/languages/shared.ts +4 -1
  82. package/src/core/resolver/module-resolver.ts +10 -3
  83. package/src/core/resolver/path-resolver.ts +6 -3
  84. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  85. package/src/core/resolver/slice-catalog.ts +21 -6
  86. package/src/core/resolver/slice-format.ts +13 -0
  87. package/src/core/resolver/slice-selection.ts +237 -0
  88. package/src/core/resolver/symbol-impact.ts +104 -8
  89. package/src/core/resolver/symbol-locator.ts +82 -15
  90. package/src/core/resolver/vertical-slice-tracer.ts +31 -230
  91. package/src/core/resources/ignore.ts +0 -1
  92. package/src/core/resources/limits.ts +2 -1
  93. package/src/core/resources/work-queue.ts +167 -4
  94. package/src/core/retrieval/context-page.ts +11 -4
  95. package/src/core/retrieval/context.ts +363 -226
  96. package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
  97. package/src/core/retrieval/symbol-details.ts +453 -0
  98. package/src/core/retrieval/symbol-evidence.ts +3 -3
  99. package/src/core/retrieval/typescript-references.ts +38 -7
  100. package/src/core/retrieval/universal-context.ts +182 -0
  101. package/src/core/telemetry/summary.ts +114 -0
  102. package/src/core/telemetry/telemetry.ts +192 -49
  103. package/src/mcp/formatters/compact-text.ts +439 -0
  104. package/src/mcp/resources-and-prompts.ts +255 -0
  105. package/src/mcp/schemas/boundary.ts +145 -0
  106. package/src/mcp/schemas/map.ts +250 -0
  107. package/src/mcp/schemas/shared.ts +52 -0
  108. package/src/mcp/schemas/slice.ts +60 -0
  109. package/src/mcp/schemas/symbol.ts +268 -0
  110. package/src/mcp/schemas.ts +5 -746
  111. package/src/mcp/server.ts +269 -429
  112. package/src/mcp/tool-catalog.ts +331 -0
  113. package/src/mcp/tools/boundary.ts +68 -3
  114. package/src/mcp/tools/map.ts +104 -4
  115. package/src/mcp/tools/slice.ts +101 -3
  116. package/src/mcp/tools/symbol.ts +469 -17
  117. package/src/mcp/ui/app-client.ts +899 -0
  118. package/src/mcp/ui/app.html +478 -0
  119. package/src/mcp/workflow-playbooks.ts +181 -0
  120. package/src/mcp/workspace-boundary.ts +50 -0
  121. package/src/mcp/workspace-manager.ts +88 -15
  122. package/src/mcp/workspace-watcher.ts +30 -11
  123. package/src/types/index.ts +12 -0
  124. package/src/mcp/tools/check-boundary.ts +0 -382
  125. package/src/mcp/tools/get-domain-catalog.ts +0 -39
  126. package/src/mcp/tools/get-symbol-impact.ts +0 -104
  127. package/src/mcp/tools/locate-symbol.ts +0 -236
  128. package/src/mcp/tools/register-domain.ts +0 -113
  129. package/src/mcp/tools/trace-vertical-slice.ts +0 -106
@@ -1,31 +1,80 @@
1
- import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
2
- import type { SeptumRepository } from "../../core/database/repository.ts";
3
1
  import { existsSync } from "node:fs";
4
2
  import { resolve } from "node:path";
5
- import { computeContentHash } from "../../core/ingestion/hasher.ts";
6
- import { isPathContained } from "../../core/resolver/path-resolver.ts";
7
- import { readSourceFile } from "../../core/resources/source-files.ts";
8
- import { SymbolLocator } from "../../core/resolver/symbol-locator.ts";
9
- import type { GetSymbolArgs } from "../../types/index.ts";
10
- import { symbolWorkspace, withSymbolEvidence } from "../../core/retrieval/symbol-evidence.ts";
3
+ import type { ValidatedSeptumConfig } from "../config/schema.ts";
4
+ import type { SeptumRepository } from "../database/repository.ts";
5
+ import { computeContentHash } from "../ingestion/hasher.ts";
6
+ import { isPathContained } from "../resolver/path-resolver.ts";
7
+ import { SymbolLocator } from "../resolver/symbol-locator.ts";
8
+ import { readSourceFile } from "../resources/source-files.ts";
9
+ import type { GetSymbolArgs, SymbolReference } from "../../types/index.ts";
11
10
 
12
- export function handleGetSymbol(
11
+ export interface SymbolContextModeSelection {
12
+ mode: "deep" | "invalid_options" | "invalid_query" | "source";
13
+ symbol: string;
14
+ }
15
+
16
+ export function selectSymbolContextMode(
13
17
  repo: SeptumRepository,
14
- config: ValidatedSeptumConfig,
15
- args: GetSymbolArgs,
16
- workspaceRoot?: string
17
- ) {
18
- const root = symbolWorkspace(repo, workspaceRoot || args.workspace_path);
19
- return withSymbolEvidence(repo, root, { operation: "inspect", requested: args.symbol_ref },
20
- () => inspectSymbol(repo, config, args, root));
18
+ args: {
19
+ symbol?: string;
20
+ query?: string;
21
+ domain?: string;
22
+ file_path?: string;
23
+ symbol_ref?: SymbolReference;
24
+ context_mode?: string;
25
+ include_source?: boolean;
26
+ source_start_line?: number;
27
+ source_line_limit?: number;
28
+ continuation?: string;
29
+ budget_bytes?: number;
30
+ max_depth?: number;
31
+ }
32
+ ): SymbolContextModeSelection {
33
+ const symbol = (args.symbol_ref?.name || args.symbol || args.query || "").toString().trim();
34
+ if (!symbol) {
35
+ return { mode: "invalid_query", symbol: "" };
36
+ }
37
+ const candidates = repo.findSymbolsByName(symbol, {
38
+ domain: args.domain,
39
+ filePath: args.file_path,
40
+ reference: args.symbol_ref,
41
+ });
42
+ const targetPath = candidates.length === 1
43
+ ? candidates[0]!.file_path
44
+ : args.symbol_ref?.file_path || args.file_path;
45
+ const bounded =
46
+ args.context_mode === "source" ||
47
+ args.include_source !== undefined ||
48
+ args.source_start_line !== undefined ||
49
+ args.source_line_limit !== undefined;
50
+
51
+ if (args.context_mode === "deep" || (!bounded && (!targetPath || /\.(?:ts|mts|cts|tsx)$/.test(targetPath)))) {
52
+ return { mode: "deep", symbol };
53
+ }
54
+ if (args.continuation !== undefined || ((args.budget_bytes !== undefined || args.max_depth !== undefined) && bounded)) {
55
+ return { mode: "invalid_options", symbol };
56
+ }
57
+ return { mode: "source", symbol };
58
+ }
59
+
60
+ function indexLineOffsets(source: string): { lineStarts: number[]; lineEnds: number[] } {
61
+ const lineStarts = [0];
62
+ const lineEnds: number[] = [];
63
+ for (const match of source.matchAll(/\r\n|\n|\r/g)) {
64
+ const offset = match.index!;
65
+ lineEnds.push(offset);
66
+ lineStarts.push(offset + match[0].length);
67
+ }
68
+ lineEnds.push(source.length);
69
+ return { lineStarts, lineEnds };
21
70
  }
22
71
 
23
- function inspectSymbol(
72
+ export function inspectSourceContext(
24
73
  repo: SeptumRepository,
25
74
  _config: ValidatedSeptumConfig,
26
75
  args: GetSymbolArgs,
27
76
  workspaceRoot?: string
28
- ) {
77
+ ): Record<string, unknown> {
29
78
  const symbol = (args.symbol_ref?.name || args.symbol || (args as unknown as Record<string, unknown>).query || "").toString().trim();
30
79
  if (!symbol) {
31
80
  throw new Error(
@@ -36,26 +85,39 @@ function inspectSymbol(
36
85
  if (args.symbol_ref) {
37
86
  const file = repo.getFileByPath(args.symbol_ref.file_path);
38
87
  if (!file || file.content_hash !== args.symbol_ref.indexed_content_hash) {
39
- return { content: [{ type: "text" as const, text: JSON.stringify({
40
- symbol, status: "stale_reference", found: false,
88
+ return {
89
+ symbol,
90
+ status: "stale_reference",
91
+ found: false,
41
92
  message: "Declaration reference is stale; locate the symbol again.",
42
93
  ...(args.include_source ? { source_slice: { status: "stale", reason: "stale_reference" } } : {}),
43
- }) }] };
94
+ };
44
95
  }
45
96
  }
97
+
46
98
  const selectedCandidates = repo.findSymbolsByName(symbol, {
47
- domain: args.domain, filePath: args.file_path, reference: args.symbol_ref,
99
+ domain: args.domain,
100
+ filePath: args.file_path,
101
+ reference: args.symbol_ref,
48
102
  });
49
103
  if (selectedCandidates.length > 1) {
50
104
  const candidates = selectedCandidates.map(candidate => ({
51
- name: candidate.name, file_path: candidate.file_path, kind: candidate.kind, signature: candidate.signature,
52
- start_line: candidate.line_start, end_line: candidate.line_end, symbol_ref: candidate.symbol_ref,
105
+ name: candidate.name,
106
+ file_path: candidate.file_path,
107
+ kind: candidate.kind,
108
+ signature: candidate.signature,
109
+ start_line: candidate.line_start,
110
+ end_line: candidate.line_end,
111
+ symbol_ref: candidate.symbol_ref,
53
112
  }));
54
- return { content: [{ type: "text" as const, text: JSON.stringify({
55
- symbol, status: "ambiguous", found: false, candidates,
113
+ return {
114
+ symbol,
115
+ status: "ambiguous",
116
+ found: false,
117
+ candidates,
56
118
  ...(args.include_source ? { source_slice: { status: "ambiguous", candidates } } : {}),
57
119
  message: "Multiple matching declarations; select a candidate with symbol_ref or narrow with file_path.",
58
- }, null, 2) }] };
120
+ };
59
121
  }
60
122
 
61
123
  const details = repo.getSymbolDetails(symbol, {
@@ -117,14 +179,7 @@ function inspectSymbol(
117
179
  action_required: "septum sync",
118
180
  };
119
181
  } else {
120
- const lineStarts = [0];
121
- const lineEnds: number[] = [];
122
- for (const match of source.matchAll(/\r\n|\n|\r/g)) {
123
- const offset = match.index!;
124
- lineEnds.push(offset);
125
- lineStarts.push(offset + match[0].length);
126
- }
127
- lineEnds.push(source.length);
182
+ const { lineStarts, lineEnds } = indexLineOffsets(source);
128
183
  const startLine = args.source_start_line ?? details.exact_range.start_line;
129
184
  const limit = Math.min(args.source_line_limit ?? 120, 200);
130
185
  if (
@@ -139,12 +194,21 @@ function inspectSymbol(
139
194
  allowed_end_line: details.exact_range.end_line,
140
195
  };
141
196
  } else {
142
- const endLine = Math.min(details.exact_range.end_line, startLine + limit - 1, lineStarts.length);
143
- const truncated = endLine < details.exact_range.end_line;
144
- const sliceText = source.slice(lineStarts[startLine - 1], lineEnds[endLine - 1]);
197
+ let endLine = Math.min(details.exact_range.end_line, startLine + limit - 1, lineStarts.length);
198
+ let truncated = endLine < details.exact_range.end_line;
199
+ let sliceText = source.slice(lineStarts[startLine - 1], lineEnds[endLine - 1]);
200
+ if (args.budget_bytes !== undefined && Buffer.byteLength(sliceText, "utf8") > args.budget_bytes) {
201
+ while (endLine > startLine && Buffer.byteLength(sliceText, "utf8") > args.budget_bytes) {
202
+ endLine--;
203
+ sliceText = source.slice(lineStarts[startLine - 1], lineEnds[endLine - 1]);
204
+ }
205
+ if (Buffer.byteLength(sliceText, "utf8") > args.budget_bytes) {
206
+ sliceText = Buffer.from(sliceText, "utf8").subarray(0, args.budget_bytes).toString("utf8");
207
+ }
208
+ truncated = true;
209
+ }
145
210
  const lineCount = endLine - startLine + 1;
146
211
 
147
- // 1-hop Transitive Delegator Expansion (Hollow Slicing Prevention)
148
212
  let delegatedImpl: {
149
213
  symbol: string;
150
214
  file_path: string;
@@ -189,21 +253,13 @@ function inspectSymbol(
189
253
  }
190
254
  }
191
255
  }
192
- return {
193
- content: [
194
- {
195
- type: "text" as const,
196
- text: JSON.stringify(payload, null, 2),
197
- },
198
- ],
199
- };
256
+ return payload;
200
257
  }
201
258
 
202
- // Fallback to fuzzy SymbolLocator to provide actionable hints
203
259
  const locator = new SymbolLocator(repo);
204
260
  const fallback = locator.locate(symbol, args.domain, { filePath: args.file_path, reference: args.symbol_ref });
205
261
 
206
- const payload = {
262
+ return {
207
263
  symbol,
208
264
  found: false,
209
265
  message: `Symbol '${symbol}' was not found in the deterministic catalog.`,
@@ -221,15 +277,6 @@ function inspectSymbol(
221
277
  sibling_methods: fallback.sibling_methods,
222
278
  ...(args.include_source ? { source_slice: { status: "unavailable", reason: "symbol_not_found" } } : {}),
223
279
  };
224
-
225
- return {
226
- content: [
227
- {
228
- type: "text" as const,
229
- text: JSON.stringify(payload, null, 2),
230
- },
231
- ],
232
- };
233
280
  }
234
281
 
235
282
  function toPascalCase(identifier: string): string {
@@ -247,12 +294,6 @@ function resolveDelegatorImplementation(
247
294
  sliceText: string,
248
295
  details: any
249
296
  ): { symbol: string; file_path: string; start_line: number; end_line: number; text: string } | undefined {
250
- // 1. Check for PHP/TS/Python/Go delegator call patterns:
251
- // $this->property->execute(...) or ->handle(...)
252
- // this.property.execute(...) or .handle(...)
253
- // self.property.execute(...) (Python)
254
- // receiver.property.Execute(...) (Go)
255
- // ClassName::execute(...) or ClassName::handle(...)
256
297
  const phpPropMatch = /\$this->([a-zA-Z0-9_]+)\s*->\s*([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
257
298
  const tsPropMatch = /\bthis\.([a-zA-Z0-9_]+)\s*\.\s*([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
258
299
  const pySelfMatch = /\bself\.([a-zA-Z0-9_]+)\s*\.\s*([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
@@ -267,40 +308,28 @@ function resolveDelegatorImplementation(
267
308
  if (phpPropMatch) {
268
309
  const propName = phpPropMatch[1];
269
310
  targetMethodName = phpPropMatch[2];
270
-
271
311
  const ctorPropRegex = new RegExp(
272
312
  `(?:protected|private|public)\\s+(?:readonly\\s+)?(?:\\\\?[A-Za-z0-9_\\\\]+\\\\)?([A-Z][A-Za-z0-9_]*)\\s+\\\$${propName}\\b`,
273
313
  "i"
274
314
  );
275
315
  const ctorMatch = ctorPropRegex.exec(sourceCode);
276
- if (ctorMatch) {
277
- targetClassName = ctorMatch[1];
278
- } else {
279
- targetClassName = toPascalCase(propName);
280
- }
316
+ targetClassName = ctorMatch ? ctorMatch[1] : toPascalCase(propName);
281
317
  } else if (tsPropMatch) {
282
318
  const propName = tsPropMatch[1];
283
319
  targetMethodName = tsPropMatch[2];
284
320
  const tsPropRegex = new RegExp(`(?:private|protected|public|readonly)\\s+${propName}\\s*:\\s*([A-Z][A-Za-z0-9_]*)`, "i");
285
321
  const tsMatch = tsPropRegex.exec(sourceCode);
286
- if (tsMatch) {
287
- targetClassName = tsMatch[1];
288
- } else {
289
- targetClassName = toPascalCase(propName);
290
- }
322
+ targetClassName = tsMatch ? tsMatch[1] : toPascalCase(propName);
291
323
  } else if (pySelfMatch) {
292
324
  const propName = pySelfMatch[1];
293
325
  targetMethodName = pySelfMatch[2];
294
- // Check `self.prop = param` in `__init__` or direct `prop: TypeName` type annotation
295
326
  const assignMatch = new RegExp(`\\bself\\.${propName}\\s*=\\s*([a-zA-Z_][a-zA-Z0-9_]*)\\b`).exec(sourceCode);
296
327
  const paramName = assignMatch ? assignMatch[1] : propName;
297
- const typeHintRegex = new RegExp(`\\b(?:self\\.)?${paramName}\\s*:\\s*(?:[a-zA-Z0-9_]+\\.)?([A-Z][A-Za-z0-9_]*)\\b`);
328
+ const typeHintRegex = new RegExp(
329
+ `\\b(?:pub\\s+)?(?:self\\.)?${paramName}\\s*:\\s*(?:&(?:mut\\s+)?|(?:Arc|Box|Rc|Option)<)?(?:[a-zA-Z0-9_]+(?:\\.|::))*([A-Z][A-Za-z0-9_]*)\\b`
330
+ );
298
331
  const pyMatch = typeHintRegex.exec(sourceCode);
299
- if (pyMatch) {
300
- targetClassName = pyMatch[1];
301
- } else {
302
- targetClassName = toPascalCase(propName);
303
- }
332
+ targetClassName = pyMatch ? pyMatch[1] : toPascalCase(propName);
304
333
  } else if (goRecvSigMatch) {
305
334
  const recvVar = goRecvSigMatch[1];
306
335
  const goPropRegex = new RegExp(`\\b${recvVar}\\.([a-zA-Z_]\\w*)\\s*\\.\\s*([a-zA-Z_]\\w*)\\s*\\(`);
@@ -310,18 +339,42 @@ function resolveDelegatorImplementation(
310
339
  targetMethodName = goCallMatch[2];
311
340
  const fieldTypeRegex = new RegExp(`\\b${propName}\\s+\\*?(?:[a-zA-Z0-9_]+\\.)?([A-Z][A-Za-z0-9_]*)\\b`);
312
341
  const fieldMatch = fieldTypeRegex.exec(sourceCode);
313
- if (fieldMatch) {
314
- targetClassName = fieldMatch[1];
315
- } else {
316
- targetClassName = toPascalCase(propName);
317
- }
342
+ targetClassName = fieldMatch ? fieldMatch[1] : toPascalCase(propName);
318
343
  }
319
344
  } else if (staticMatch) {
320
345
  targetClassName = staticMatch[1];
321
346
  targetMethodName = staticMatch[2];
322
347
  }
323
348
 
324
- if (!targetClassName || !targetMethodName) return undefined;
349
+ if (!targetClassName || !targetMethodName) {
350
+ // Fallback: expand same-file local helper delegation for thin polyglot wrappers (Go/Python/PHP/Rust).
351
+ const currentFile = details?.file_path ? repo.getFileByPath(details.file_path) : undefined;
352
+ if (!currentFile) return undefined;
353
+ const localSymbols = repo.getSymbolsByFileId(currentFile.id).filter(
354
+ (s) =>
355
+ (s.kind === "function" || s.kind === "method") &&
356
+ s.line_start !== details.exact_range?.start_line
357
+ );
358
+ const bodyWithoutHeader = sliceText.split(/\r?\n/).slice(1).join("\n") || sliceText;
359
+ const localMatch = localSymbols.find((s) => {
360
+ const shortName = s.name.split(/::|@|\./).pop() || s.name;
361
+ if (shortName.length < 2) return false;
362
+ const escaped = shortName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
363
+ return new RegExp(`(?:\\b(?:self|this|\\$this|[a-zA-Z_]\\w*)\\s*(?:\\.|->|::)\\s*|\\b)${escaped}\\s*\\(`).test(bodyWithoutHeader);
364
+ });
365
+ if (!localMatch) return undefined;
366
+ const { lineStarts: sameStarts, lineEnds: sameEnds } = indexLineOffsets(sourceCode);
367
+ const lStart = localMatch.line_start;
368
+ const lEnd = Math.min(localMatch.line_end, sameStarts.length);
369
+ if (lStart > sameStarts.length || lEnd < lStart) return undefined;
370
+ return {
371
+ symbol: localMatch.name,
372
+ file_path: details.file_path,
373
+ start_line: lStart,
374
+ end_line: lEnd,
375
+ text: sourceCode.slice(sameStarts[lStart - 1], sameEnds[lEnd - 1]),
376
+ };
377
+ }
325
378
 
326
379
  const candidateQueries = [
327
380
  `${targetClassName}::${targetMethodName}`,
@@ -356,7 +409,9 @@ function resolveDelegatorImplementation(
356
409
  if (classMatches.length >= 1) {
357
410
  const cls = classMatches[0];
358
411
  const fileSymbols = repo.getSymbolsByFileId(cls.file_id);
359
- const methodSym = fileSymbols.find(s => s.kind === "method" && (s.name.endsWith(`::${targetMethodName}`) || s.name.endsWith(`@${targetMethodName}`) || s.name === targetMethodName));
412
+ const methodSym = fileSymbols.find(
413
+ s => s.kind === "method" && (s.name.endsWith(`::${targetMethodName}`) || s.name.endsWith(`@${targetMethodName}`) || s.name === targetMethodName)
414
+ );
360
415
  if (methodSym) {
361
416
  targetSymbol = { ...methodSym, file_path: cls.file_path };
362
417
  }
@@ -373,13 +428,7 @@ function resolveDelegatorImplementation(
373
428
  const targetFullPath = resolve(root, targetSymbol.file_path);
374
429
  if (!existsSync(targetFullPath)) return undefined;
375
430
  const targetSource = readSourceFile(targetFullPath);
376
- const targetStarts = [0];
377
- const targetEnds: number[] = [];
378
- for (const match of targetSource.matchAll(/\r\n|\n|\r/g)) {
379
- targetEnds.push(match.index!);
380
- targetStarts.push(match.index! + match[0].length);
381
- }
382
- targetEnds.push(targetSource.length);
431
+ const { lineStarts: targetStarts, lineEnds: targetEnds } = indexLineOffsets(targetSource);
383
432
 
384
433
  const tStart = targetSymbol.line_start;
385
434
  const tEnd = Math.min(targetSymbol.line_end, targetStarts.length);