@dimassetoid/septum-mcp 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +46 -45
  2. package/package.json +8 -6
  3. package/src/cli/commands/check.ts +41 -26
  4. package/src/cli/commands/hook.ts +77 -105
  5. package/src/cli/commands/init.ts +35 -9
  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 +35 -9
  9. package/src/cli/hook-payload.ts +43 -0
  10. package/src/cli/index.ts +15 -51
  11. package/src/cli/scaffold/harness-config.ts +48 -8
  12. package/src/cli/templates/hooks.ts +51 -27
  13. package/src/cli/templates/rules.ts +34 -49
  14. package/src/cli/templates/skill.ts +46 -35
  15. package/src/core/boundary/audit.ts +383 -0
  16. package/src/core/boundary/evaluator.ts +299 -178
  17. package/src/core/boundary/staged-auditor.ts +188 -34
  18. package/src/core/config/domain-ownership.ts +47 -0
  19. package/src/core/config/domain-registration.ts +141 -0
  20. package/src/core/config/loader.ts +82 -54
  21. package/src/core/config/schema.ts +24 -46
  22. package/src/core/database/client.ts +2 -0
  23. package/src/core/database/repositories/dependency.repository.ts +326 -543
  24. package/src/core/database/repositories/domain.repository.ts +48 -4
  25. package/src/core/database/repositories/file.repository.ts +10 -0
  26. package/src/core/database/repositories/symbol.repository.ts +97 -259
  27. package/src/core/database/repository.ts +138 -24
  28. package/src/core/database/schema.ts +28 -33
  29. package/src/core/discovery/declarative-routes.ts +69 -0
  30. package/src/core/discovery/framework-detector.ts +149 -0
  31. package/src/core/discovery/navigation.ts +269 -0
  32. package/src/core/discovery/topology-detector.ts +153 -170
  33. package/src/core/errors.ts +19 -0
  34. package/src/core/ingestion/pipeline.ts +378 -212
  35. package/src/core/parser/behavioral-analyzer.ts +26 -22
  36. package/src/core/parser/boundary-tracker.ts +15 -0
  37. package/src/core/parser/extractors/base.ts +16 -4
  38. package/src/core/parser/extractors/csharp.ts +9 -5
  39. package/src/core/parser/extractors/django-routing.ts +163 -0
  40. package/src/core/parser/extractors/django-semantic.ts +400 -516
  41. package/src/core/parser/extractors/elysia-semantic.ts +172 -496
  42. package/src/core/parser/extractors/express-semantic.ts +195 -398
  43. package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
  44. package/src/core/parser/extractors/fastify-semantic.ts +216 -732
  45. package/src/core/parser/extractors/flask-semantic.ts +92 -388
  46. package/src/core/parser/extractors/go-routing.ts +344 -0
  47. package/src/core/parser/extractors/go-semantic.ts +210 -508
  48. package/src/core/parser/extractors/go.ts +6 -3
  49. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  50. package/src/core/parser/extractors/hono-semantic.ts +132 -530
  51. package/src/core/parser/extractors/java.ts +7 -5
  52. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  53. package/src/core/parser/extractors/laravel-semantic.ts +169 -333
  54. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  55. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  56. package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
  57. package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
  58. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  59. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  60. package/src/core/parser/extractors/php.ts +17 -1
  61. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  62. package/src/core/parser/extractors/python.ts +9 -8
  63. package/src/core/parser/extractors/registry.ts +28 -5
  64. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  65. package/src/core/parser/extractors/ruby.ts +10 -7
  66. package/src/core/parser/extractors/rust.ts +35 -17
  67. package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
  68. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  69. package/src/core/parser/extractors/symfony-semantic.ts +75 -262
  70. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  71. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  72. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  73. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  74. package/src/core/parser/extractors/typescript.ts +36 -216
  75. package/src/core/parser/implementation-fingerprint.ts +97 -0
  76. package/src/core/parser/language-capabilities.ts +23 -7
  77. package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
  78. package/src/core/parser/schema/schema-provider-registry.ts +1 -3
  79. package/src/core/parser/schema/schema-provider.interface.ts +2 -1
  80. package/src/core/parser/semantic-revision.ts +3 -0
  81. package/src/core/parser/static-string.ts +51 -0
  82. package/src/core/parser/wasm-loader.ts +6 -2
  83. package/src/core/resolver/ast-method-tracer.ts +230 -0
  84. package/src/core/resolver/call-graph-helpers.ts +72 -0
  85. package/src/core/resolver/call-graph-tracer.ts +375 -311
  86. package/src/core/resolver/dependency-analysis.ts +593 -0
  87. package/src/core/resolver/import-candidates.ts +120 -0
  88. package/src/core/resolver/import-evidence.ts +88 -0
  89. package/src/core/resolver/import-resolver.ts +162 -181
  90. package/src/core/resolver/interpretation-inputs.ts +65 -0
  91. package/src/core/resolver/languages/go.ts +103 -0
  92. package/src/core/resolver/languages/managed.ts +200 -0
  93. package/src/core/resolver/languages/python.ts +133 -0
  94. package/src/core/resolver/languages/ruby.ts +40 -0
  95. package/src/core/resolver/languages/rust.ts +127 -0
  96. package/src/core/resolver/languages/shared.ts +74 -0
  97. package/src/core/resolver/module-resolver.ts +18 -7
  98. package/src/core/resolver/path-resolver.ts +6 -3
  99. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  100. package/src/core/resolver/slice-catalog.ts +94 -0
  101. package/src/core/resolver/slice-format.ts +22 -0
  102. package/src/core/resolver/slice-selection.ts +237 -0
  103. package/src/core/resolver/symbol-impact.ts +477 -0
  104. package/src/core/resolver/symbol-locator.ts +82 -15
  105. package/src/core/resolver/vertical-slice-tracer.ts +57 -278
  106. package/src/core/resources/ignore.ts +21 -1
  107. package/src/core/resources/limits.ts +2 -1
  108. package/src/core/resources/source-files.ts +143 -20
  109. package/src/core/resources/source-inventory.ts +55 -0
  110. package/src/core/resources/work-queue.ts +167 -4
  111. package/src/core/retrieval/context-page.ts +116 -0
  112. package/src/core/retrieval/context.ts +457 -0
  113. package/src/core/retrieval/resolution-warnings.ts +21 -0
  114. package/src/core/retrieval/source-context.ts +448 -0
  115. package/src/core/retrieval/symbol-details.ts +453 -0
  116. package/src/core/retrieval/symbol-evidence.ts +97 -0
  117. package/src/core/retrieval/typescript-references.ts +293 -0
  118. package/src/core/retrieval/universal-context.ts +182 -0
  119. package/src/core/telemetry/summary.ts +114 -0
  120. package/src/core/telemetry/telemetry.ts +225 -37
  121. package/src/index.ts +0 -3
  122. package/src/mcp/formatters/compact-text.ts +439 -0
  123. package/src/mcp/resources-and-prompts.ts +253 -0
  124. package/src/mcp/schemas/boundary.ts +145 -0
  125. package/src/mcp/schemas/map.ts +250 -0
  126. package/src/mcp/schemas/shared.ts +52 -0
  127. package/src/mcp/schemas/slice.ts +60 -0
  128. package/src/mcp/schemas/symbol.ts +268 -0
  129. package/src/mcp/schemas.ts +5 -1105
  130. package/src/mcp/server.ts +263 -597
  131. package/src/mcp/tool-catalog.ts +331 -0
  132. package/src/mcp/tools/boundary.ts +69 -4
  133. package/src/mcp/tools/map.ts +126 -0
  134. package/src/mcp/tools/slice.ts +101 -3
  135. package/src/mcp/tools/symbol.ts +480 -26
  136. package/src/mcp/ui/app-client.ts +899 -0
  137. package/src/mcp/ui/app.html +478 -0
  138. package/src/mcp/workflow-playbooks.ts +181 -0
  139. package/src/mcp/workspace-boundary.ts +50 -0
  140. package/src/mcp/workspace-manager.ts +102 -18
  141. package/src/mcp/workspace-watcher.ts +38 -19
  142. package/src/types/index.ts +47 -53
  143. package/src/cli/commands/topology.ts +0 -161
  144. package/src/core/database/repositories/environment.repository.ts +0 -207
  145. package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
  146. package/src/core/session/session-manager.ts +0 -107
  147. package/src/core/topology/environment-detector.ts +0 -973
  148. package/src/core/topology/types.ts +0 -83
  149. package/src/mcp/tools/check-boundary.ts +0 -387
  150. package/src/mcp/tools/domain.ts +0 -40
  151. package/src/mcp/tools/feature.ts +0 -67
  152. package/src/mcp/tools/get-domain-catalog.ts +0 -226
  153. package/src/mcp/tools/get-environment-topology.ts +0 -138
  154. package/src/mcp/tools/get-feature-context.ts +0 -224
  155. package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
  156. package/src/mcp/tools/get-symbol-impact.ts +0 -64
  157. package/src/mcp/tools/get-symbol.ts +0 -175
  158. package/src/mcp/tools/locate-symbol.ts +0 -196
  159. package/src/mcp/tools/register-domain.ts +0 -75
  160. package/src/mcp/tools/register-feature.ts +0 -110
  161. package/src/mcp/tools/trace-vertical-slice.ts +0 -80
@@ -0,0 +1,448 @@
1
+ import { existsSync } from "node:fs";
2
+ import { resolve } from "node:path";
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";
10
+
11
+ export interface SymbolContextModeSelection {
12
+ mode: "deep" | "invalid_options" | "invalid_query" | "source";
13
+ symbol: string;
14
+ }
15
+
16
+ export function selectSymbolContextMode(
17
+ repo: SeptumRepository,
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 };
70
+ }
71
+
72
+ export function inspectSourceContext(
73
+ repo: SeptumRepository,
74
+ _config: ValidatedSeptumConfig,
75
+ args: GetSymbolArgs,
76
+ workspaceRoot?: string
77
+ ): Record<string, unknown> {
78
+ const symbol = (args.symbol_ref?.name || args.symbol || (args as unknown as Record<string, unknown>).query || "").toString().trim();
79
+ if (!symbol) {
80
+ throw new Error(
81
+ "Missing required argument: 'symbol' (e.g. 'OrderController::cancelOrder', 'OrderService', or 'cancelOrder')"
82
+ );
83
+ }
84
+
85
+ if (args.symbol_ref) {
86
+ const file = repo.getFileByPath(args.symbol_ref.file_path);
87
+ if (!file || file.content_hash !== args.symbol_ref.indexed_content_hash) {
88
+ return {
89
+ symbol,
90
+ status: "stale_reference",
91
+ found: false,
92
+ message: "Declaration reference is stale; locate the symbol again.",
93
+ ...(args.include_source ? { source_slice: { status: "stale", reason: "stale_reference" } } : {}),
94
+ };
95
+ }
96
+ }
97
+
98
+ const selectedCandidates = repo.findSymbolsByName(symbol, {
99
+ domain: args.domain,
100
+ filePath: args.file_path,
101
+ reference: args.symbol_ref,
102
+ });
103
+ if (selectedCandidates.length > 1) {
104
+ const candidates = selectedCandidates.map(candidate => ({
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,
112
+ }));
113
+ return {
114
+ symbol,
115
+ status: "ambiguous",
116
+ found: false,
117
+ candidates,
118
+ ...(args.include_source ? { source_slice: { status: "ambiguous", candidates } } : {}),
119
+ message: "Multiple matching declarations; select a candidate with symbol_ref or narrow with file_path.",
120
+ };
121
+ }
122
+
123
+ const details = repo.getSymbolDetails(symbol, {
124
+ domain: args.domain,
125
+ filePath: args.file_path,
126
+ reference: args.symbol_ref,
127
+ // This inspection path reads the complete file for outbound-call inference; keep source requests bounded.
128
+ includeDependencies: args.include_source ? false : args.include_dependencies,
129
+ workspaceRoot: workspaceRoot || args.workspace_path,
130
+ });
131
+
132
+ if (details) {
133
+ const payload: Record<string, unknown> = { ...details, context_mode: "source" };
134
+ if (args.include_source === false) {
135
+ if (Array.isArray(payload.relationships)) {
136
+ const allRels = payload.relationships as Array<any>;
137
+ const maxRels = 20;
138
+ payload.relationships = allRels.slice(0, maxRels).map((edge) => ({
139
+ target: edge?.resolution?.source?.target ?? edge?.target,
140
+ line: edge?.source?.line ?? edge?.line,
141
+ status: edge?.resolution?.status,
142
+ reason: edge?.resolution?.reason,
143
+ resolved_files: Array.isArray(edge?.resolution?.targets)
144
+ ? edge.resolution.targets.flatMap((t: any) => t.files ?? [])
145
+ : [],
146
+ }));
147
+ if (allRels.length > maxRels) {
148
+ payload.relationships_omitted = allRels.length - maxRels;
149
+ }
150
+ }
151
+ if (Array.isArray(payload.connected_files) && payload.connected_files.length > 20) {
152
+ payload.connected_files_omitted = payload.connected_files.length - 20;
153
+ payload.connected_files = payload.connected_files.slice(0, 20);
154
+ }
155
+ }
156
+ if (args.include_source) {
157
+ delete payload.dependencies_injected;
158
+ delete payload.outbound_calls;
159
+ delete payload.resolved_outbound_calls;
160
+ delete payload.connected_files;
161
+ const root = resolve(workspaceRoot || args.workspace_path || process.cwd());
162
+ const file = repo.getFileByPath(details.file_path);
163
+ const fullPath = resolve(root, details.file_path);
164
+ if (!file) {
165
+ payload.source_slice = { status: "unavailable", file_path: details.file_path, reason: "file_not_indexed" };
166
+ } else if (!isPathContained(fullPath, root)) {
167
+ payload.source_slice = { status: "out_of_scope", file_path: details.file_path };
168
+ } else {
169
+ try {
170
+ const source = readSourceFile(fullPath);
171
+ const currentHash = computeContentHash(source);
172
+ if (currentHash !== file.content_hash) {
173
+ payload.source_slice = {
174
+ status: "stale",
175
+ file_path: details.file_path,
176
+ indexed_content_hash: file.content_hash,
177
+ current_content_hash: currentHash,
178
+ message: "File has been modified on disk since last indexed. Run 'septum sync' to synchronize AST coordinates.",
179
+ action_required: "septum sync",
180
+ };
181
+ } else {
182
+ const { lineStarts, lineEnds } = indexLineOffsets(source);
183
+ const startLine = args.source_start_line ?? details.exact_range.start_line;
184
+ const limit = Math.min(args.source_line_limit ?? 120, 200);
185
+ if (
186
+ startLine < details.exact_range.start_line ||
187
+ startLine > details.exact_range.end_line ||
188
+ startLine > lineStarts.length
189
+ ) {
190
+ payload.source_slice = {
191
+ status: "invalid_range",
192
+ file_path: details.file_path,
193
+ allowed_start_line: details.exact_range.start_line,
194
+ allowed_end_line: details.exact_range.end_line,
195
+ };
196
+ } else {
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
+ }
210
+ const lineCount = endLine - startLine + 1;
211
+
212
+ let delegatedImpl: {
213
+ symbol: string;
214
+ file_path: string;
215
+ start_line: number;
216
+ end_line: number;
217
+ text: string;
218
+ } | undefined;
219
+
220
+ if (lineCount <= 15 || args.semantic_depth === 2) {
221
+ delegatedImpl = resolveDelegatorImplementation(
222
+ repo,
223
+ root,
224
+ source,
225
+ sliceText,
226
+ details
227
+ );
228
+ }
229
+
230
+ payload.source_slice = {
231
+ status: "current",
232
+ file_path: details.file_path,
233
+ indexed_content_hash: file.content_hash,
234
+ current_content_hash: currentHash,
235
+ start_line: startLine,
236
+ end_line: endLine,
237
+ text: sliceText,
238
+ truncated,
239
+ related_dependency_analysis: delegatedImpl ? "delegated_implementation_expanded" : "omitted_to_keep_source_read_bounded",
240
+ ...(delegatedImpl ? { delegated_implementation: delegatedImpl } : {}),
241
+ ...(truncated ? { next_start_line: endLine + 1 } : {}),
242
+ };
243
+ }
244
+ }
245
+ } catch (error) {
246
+ payload.source_slice = {
247
+ status: "unavailable",
248
+ file_path: details.file_path,
249
+ reason: error instanceof Error && error.name === "SourceFileLimitError"
250
+ ? "source_exceeds_read_limit"
251
+ : "source_unavailable",
252
+ };
253
+ }
254
+ }
255
+ }
256
+ return payload;
257
+ }
258
+
259
+ const locator = new SymbolLocator(repo);
260
+ const fallback = locator.locate(symbol, args.domain, { filePath: args.file_path, reference: args.symbol_ref });
261
+
262
+ return {
263
+ symbol,
264
+ found: false,
265
+ message: `Symbol '${symbol}' was not found in the deterministic catalog.`,
266
+ suggestions: fallback.suggestions.map((s) => ({
267
+ name: s.name,
268
+ similarity_score: Math.round(s.similarity_score * 100) / 100,
269
+ exact_range: {
270
+ start_line: s.line_start,
271
+ end_line: s.line_end,
272
+ total_lines: s.line_end - s.line_start + 1,
273
+ },
274
+ signature: s.signature,
275
+ file_path: s.file_path,
276
+ })),
277
+ sibling_methods: fallback.sibling_methods,
278
+ ...(args.include_source ? { source_slice: { status: "unavailable", reason: "symbol_not_found" } } : {}),
279
+ };
280
+ }
281
+
282
+ function toPascalCase(identifier: string): string {
283
+ return identifier
284
+ .split("_")
285
+ .filter(Boolean)
286
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
287
+ .join("");
288
+ }
289
+
290
+ function resolveDelegatorImplementation(
291
+ repo: SeptumRepository,
292
+ root: string,
293
+ sourceCode: string,
294
+ sliceText: string,
295
+ details: any
296
+ ): { symbol: string; file_path: string; start_line: number; end_line: number; text: string } | undefined {
297
+ const phpPropMatch = /\$this->([a-zA-Z0-9_]+)\s*->\s*([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
298
+ const tsPropMatch = /\bthis\.([a-zA-Z0-9_]+)\s*\.\s*([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
299
+ const pySelfMatch = /\bself\.([a-zA-Z0-9_]+)\s*\.\s*([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
300
+ const staticMatch = /([A-Z][a-zA-Z0-9_]*(?:Action|Service|Handler|UseCase))::([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
301
+ const goRecvSigMatch = /^func\s*\(\s*([a-zA-Z_]\w*)\s+\*?([A-Za-z_]\w*)(?:\[[^\]]+\])?\s*\)/m.exec(
302
+ details?.signature || sliceText
303
+ );
304
+
305
+ let targetClassName: string | undefined;
306
+ let targetMethodName: string | undefined;
307
+
308
+ if (phpPropMatch) {
309
+ const propName = phpPropMatch[1];
310
+ targetMethodName = phpPropMatch[2];
311
+ const ctorPropRegex = new RegExp(
312
+ `(?:protected|private|public)\\s+(?:readonly\\s+)?(?:\\\\?[A-Za-z0-9_\\\\]+\\\\)?([A-Z][A-Za-z0-9_]*)\\s+\\\$${propName}\\b`,
313
+ "i"
314
+ );
315
+ const ctorMatch = ctorPropRegex.exec(sourceCode);
316
+ targetClassName = ctorMatch ? ctorMatch[1] : toPascalCase(propName);
317
+ } else if (tsPropMatch) {
318
+ const propName = tsPropMatch[1];
319
+ targetMethodName = tsPropMatch[2];
320
+ const tsPropRegex = new RegExp(`(?:private|protected|public|readonly)\\s+${propName}\\s*:\\s*([A-Z][A-Za-z0-9_]*)`, "i");
321
+ const tsMatch = tsPropRegex.exec(sourceCode);
322
+ targetClassName = tsMatch ? tsMatch[1] : toPascalCase(propName);
323
+ } else if (pySelfMatch) {
324
+ const propName = pySelfMatch[1];
325
+ targetMethodName = pySelfMatch[2];
326
+ const assignMatch = new RegExp(`\\bself\\.${propName}\\s*=\\s*([a-zA-Z_][a-zA-Z0-9_]*)\\b`).exec(sourceCode);
327
+ const paramName = assignMatch ? assignMatch[1] : propName;
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
+ );
331
+ const pyMatch = typeHintRegex.exec(sourceCode);
332
+ targetClassName = pyMatch ? pyMatch[1] : toPascalCase(propName);
333
+ } else if (goRecvSigMatch) {
334
+ const recvVar = goRecvSigMatch[1];
335
+ const goPropRegex = new RegExp(`\\b${recvVar}\\.([a-zA-Z_]\\w*)\\s*\\.\\s*([a-zA-Z_]\\w*)\\s*\\(`);
336
+ const goCallMatch = goPropRegex.exec(sliceText);
337
+ if (goCallMatch) {
338
+ const propName = goCallMatch[1];
339
+ targetMethodName = goCallMatch[2];
340
+ const fieldTypeRegex = new RegExp(`\\b${propName}\\s+\\*?(?:[a-zA-Z0-9_]+\\.)?([A-Z][A-Za-z0-9_]*)\\b`);
341
+ const fieldMatch = fieldTypeRegex.exec(sourceCode);
342
+ targetClassName = fieldMatch ? fieldMatch[1] : toPascalCase(propName);
343
+ }
344
+ } else if (staticMatch) {
345
+ targetClassName = staticMatch[1];
346
+ targetMethodName = staticMatch[2];
347
+ }
348
+
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
+ }
378
+
379
+ const candidateQueries = [
380
+ `${targetClassName}::${targetMethodName}`,
381
+ `${targetClassName}@${targetMethodName}`,
382
+ targetMethodName,
383
+ ];
384
+
385
+ let targetSymbol: any = undefined;
386
+ for (const q of candidateQueries) {
387
+ const matches = repo.findSymbolsByName(q);
388
+ const exact = matches.find(
389
+ (m) =>
390
+ (m.name.includes(targetClassName!) ||
391
+ m.symbol_ref?.container === targetClassName ||
392
+ m.symbol_ref?.receiver === targetClassName) &&
393
+ (m.name.endsWith(`::${targetMethodName}`) ||
394
+ m.name.endsWith(`@${targetMethodName}`) ||
395
+ m.name === targetMethodName)
396
+ );
397
+ if (exact) {
398
+ targetSymbol = exact;
399
+ break;
400
+ }
401
+ if (q !== targetMethodName && matches.length === 1) {
402
+ targetSymbol = matches[0];
403
+ break;
404
+ }
405
+ }
406
+
407
+ if (!targetSymbol) {
408
+ const classMatches = repo.findSymbolsByName(targetClassName);
409
+ if (classMatches.length >= 1) {
410
+ const cls = classMatches[0];
411
+ const fileSymbols = repo.getSymbolsByFileId(cls.file_id);
412
+ const methodSym = fileSymbols.find(
413
+ s => s.kind === "method" && (s.name.endsWith(`::${targetMethodName}`) || s.name.endsWith(`@${targetMethodName}`) || s.name === targetMethodName)
414
+ );
415
+ if (methodSym) {
416
+ targetSymbol = { ...methodSym, file_path: cls.file_path };
417
+ }
418
+ }
419
+ }
420
+
421
+ if (!targetSymbol || !targetSymbol.file_path) return undefined;
422
+
423
+ if (targetSymbol.file_path === details.file_path && targetSymbol.line_start === details.exact_range.start_line) {
424
+ return undefined;
425
+ }
426
+
427
+ try {
428
+ const targetFullPath = resolve(root, targetSymbol.file_path);
429
+ if (!existsSync(targetFullPath)) return undefined;
430
+ const targetSource = readSourceFile(targetFullPath);
431
+ const { lineStarts: targetStarts, lineEnds: targetEnds } = indexLineOffsets(targetSource);
432
+
433
+ const tStart = targetSymbol.line_start;
434
+ const tEnd = Math.min(targetSymbol.line_end, targetStarts.length);
435
+ if (tStart > targetStarts.length || tEnd < tStart) return undefined;
436
+
437
+ const targetText = targetSource.slice(targetStarts[tStart - 1], targetEnds[tEnd - 1]);
438
+ return {
439
+ symbol: targetSymbol.name,
440
+ file_path: targetSymbol.file_path,
441
+ start_line: tStart,
442
+ end_line: tEnd,
443
+ text: targetText,
444
+ };
445
+ } catch {
446
+ return undefined;
447
+ }
448
+ }