@dimassetoid/septum-mcp 0.0.0-stage → 0.2.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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -2
  3. package/bin/septum.ts +4 -0
  4. package/package.json +70 -4
  5. package/scripts/postinstall.ts +25 -0
  6. package/src/cli/commands/check.ts +122 -0
  7. package/src/cli/commands/hook.ts +268 -0
  8. package/src/cli/commands/init.ts +553 -0
  9. package/src/cli/commands/serve.ts +5 -0
  10. package/src/cli/commands/sync.ts +41 -0
  11. package/src/cli/commands/topology.ts +161 -0
  12. package/src/cli/index.ts +167 -0
  13. package/src/cli/scaffold/harness-config.ts +621 -0
  14. package/src/cli/templates/hooks.ts +75 -0
  15. package/src/cli/templates/rules.ts +50 -0
  16. package/src/cli/templates/skill.ts +51 -0
  17. package/src/cli/ui/prompts.ts +122 -0
  18. package/src/core/boundary/evaluator.ts +442 -0
  19. package/src/core/boundary/staged-auditor.ts +58 -0
  20. package/src/core/config/loader.ts +122 -0
  21. package/src/core/config/schema.ts +69 -0
  22. package/src/core/database/client.ts +60 -0
  23. package/src/core/database/repositories/dependency.repository.ts +712 -0
  24. package/src/core/database/repositories/domain.repository.ts +330 -0
  25. package/src/core/database/repositories/environment.repository.ts +207 -0
  26. package/src/core/database/repositories/file.repository.ts +117 -0
  27. package/src/core/database/repositories/meta.repository.ts +33 -0
  28. package/src/core/database/repositories/symbol.repository.ts +508 -0
  29. package/src/core/database/repository.ts +303 -0
  30. package/src/core/database/schema.ts +154 -0
  31. package/src/core/discovery/topology-detector.ts +805 -0
  32. package/src/core/ingestion/hasher.ts +5 -0
  33. package/src/core/ingestion/pipeline.ts +623 -0
  34. package/src/core/parser/behavioral-analyzer.ts +119 -0
  35. package/src/core/parser/boundary-tracker.ts +443 -0
  36. package/src/core/parser/extractors/base.ts +67 -0
  37. package/src/core/parser/extractors/blade.ts +159 -0
  38. package/src/core/parser/extractors/csharp.ts +244 -0
  39. package/src/core/parser/extractors/django-semantic.ts +687 -0
  40. package/src/core/parser/extractors/elysia-semantic.ts +538 -0
  41. package/src/core/parser/extractors/express-semantic.ts +444 -0
  42. package/src/core/parser/extractors/fastapi-semantic.ts +736 -0
  43. package/src/core/parser/extractors/fastify-semantic.ts +774 -0
  44. package/src/core/parser/extractors/flask-semantic.ts +515 -0
  45. package/src/core/parser/extractors/frontend.ts +149 -0
  46. package/src/core/parser/extractors/go-semantic.ts +611 -0
  47. package/src/core/parser/extractors/go.ts +491 -0
  48. package/src/core/parser/extractors/hono-semantic.ts +567 -0
  49. package/src/core/parser/extractors/java.ts +225 -0
  50. package/src/core/parser/extractors/laravel-semantic.ts +1122 -0
  51. package/src/core/parser/extractors/mcp-cli-semantic.ts +368 -0
  52. package/src/core/parser/extractors/nestjs-semantic.ts +543 -0
  53. package/src/core/parser/extractors/php.ts +569 -0
  54. package/src/core/parser/extractors/python.ts +498 -0
  55. package/src/core/parser/extractors/registry.ts +78 -0
  56. package/src/core/parser/extractors/ruby.ts +234 -0
  57. package/src/core/parser/extractors/rust.ts +286 -0
  58. package/src/core/parser/extractors/semantic-extractor.interface.ts +22 -0
  59. package/src/core/parser/extractors/symfony-semantic.ts +354 -0
  60. package/src/core/parser/extractors/typescript.ts +826 -0
  61. package/src/core/parser/language-capabilities.ts +71 -0
  62. package/src/core/parser/schema/providers/laravel-migration-provider.ts +216 -0
  63. package/src/core/parser/schema/providers/prisma-schema-provider.ts +90 -0
  64. package/src/core/parser/schema/schema-provider-registry.ts +43 -0
  65. package/src/core/parser/schema/schema-provider.interface.ts +33 -0
  66. package/src/core/parser/tree-sitter.ts +63 -0
  67. package/src/core/parser/wasm-assets.ts +25 -0
  68. package/src/core/parser/wasm-loader.ts +274 -0
  69. package/src/core/resolver/call-graph-tracer.ts +724 -0
  70. package/src/core/resolver/import-resolver.ts +437 -0
  71. package/src/core/resolver/module-resolver.ts +482 -0
  72. package/src/core/resolver/path-resolver.ts +200 -0
  73. package/src/core/resolver/symbol-locator.ts +276 -0
  74. package/src/core/resolver/symbol-reference.ts +53 -0
  75. package/src/core/resolver/vertical-slice-tracer.ts +366 -0
  76. package/src/core/resources/ignore.ts +123 -0
  77. package/src/core/resources/limits.ts +14 -0
  78. package/src/core/resources/source-files.ts +62 -0
  79. package/src/core/resources/work-queue.ts +74 -0
  80. package/src/core/session/session-manager.ts +107 -0
  81. package/src/core/telemetry/telemetry.ts +97 -0
  82. package/src/core/topology/environment-detector.ts +973 -0
  83. package/src/core/topology/types.ts +83 -0
  84. package/src/index.ts +21 -0
  85. package/src/mcp/schemas.ts +1105 -0
  86. package/src/mcp/server.ts +774 -0
  87. package/src/mcp/tools/boundary.ts +17 -0
  88. package/src/mcp/tools/check-boundary.ts +387 -0
  89. package/src/mcp/tools/domain.ts +40 -0
  90. package/src/mcp/tools/feature.ts +67 -0
  91. package/src/mcp/tools/get-domain-catalog.ts +226 -0
  92. package/src/mcp/tools/get-environment-topology.ts +138 -0
  93. package/src/mcp/tools/get-feature-context.ts +224 -0
  94. package/src/mcp/tools/get-symbol-hotspots.ts +54 -0
  95. package/src/mcp/tools/get-symbol-impact.ts +64 -0
  96. package/src/mcp/tools/get-symbol.ts +175 -0
  97. package/src/mcp/tools/locate-symbol.ts +196 -0
  98. package/src/mcp/tools/register-domain.ts +75 -0
  99. package/src/mcp/tools/register-feature.ts +110 -0
  100. package/src/mcp/tools/slice.ts +16 -0
  101. package/src/mcp/tools/symbol.ts +93 -0
  102. package/src/mcp/tools/trace-vertical-slice.ts +80 -0
  103. package/src/mcp/workspace-manager.ts +159 -0
  104. package/src/mcp/workspace-watcher.ts +202 -0
  105. package/src/types/index.ts +456 -0
  106. package/src/types/wasm.d.ts +4 -0
  107. package/src/utils/version-check.ts +209 -0
  108. package/src/version.ts +1 -0
@@ -0,0 +1,569 @@
1
+ import { getLanguageCapability } from "../language-capabilities.ts";
2
+ import type Parser from "web-tree-sitter";
3
+ import type {
4
+ ExtractedDependency,
5
+ ExtractedSymbol,
6
+ ParsedFileAST,
7
+ SymbolKind,
8
+ Visibility,
9
+ } from "../../../types/index.ts";
10
+ import {
11
+ blankCommentsAndStrings,
12
+ calculateControlFlowNesting,
13
+ findBraceBlockEnd,
14
+ } from "../boundary-tracker.ts";
15
+ import { calculateAstControlFlowNesting, getNodeHeader, parseSourceWithTreeSitter } from "../wasm-loader.ts";
16
+ import type { CodeExtractor } from "./base.ts";
17
+
18
+ const PHP_CONTROL_FLOW_NODES = new Set([
19
+ "if_statement",
20
+ "for_statement",
21
+ "foreach_statement",
22
+ "while_statement",
23
+ "do_statement",
24
+ "switch_statement",
25
+ "try_statement",
26
+ "catch_clause",
27
+ "match_expression",
28
+ "conditional_expression",
29
+ ]);
30
+
31
+ const PHP_FUNCTION_BOUNDARY_NODES = new Set([
32
+ "function_definition",
33
+ "method_declaration",
34
+ "anonymous_function_creation_expression",
35
+ "arrow_function",
36
+ ]);
37
+
38
+ export class PHPExtractor implements CodeExtractor {
39
+ public canHandle(filePath: string): boolean {
40
+ return getLanguageCapability(filePath)?.extractor === "php";
41
+ }
42
+
43
+ public async extract(_filePath: string, content: string): Promise<ParsedFileAST> {
44
+ const astResult = await parseSourceWithTreeSitter("php", content, (rootNode) =>
45
+ this.extractFromAst(rootNode, content),
46
+ () => this.extractFallback(content)
47
+ );
48
+ if (astResult) {
49
+ return astResult;
50
+ }
51
+
52
+ return { ...this.extractFallback(content), status: "degraded" };
53
+ }
54
+
55
+ private isExternalNamespace(cleaned: string): boolean {
56
+ return (
57
+ cleaned.startsWith("Illuminate\\") ||
58
+ cleaned.startsWith("Symfony\\") ||
59
+ cleaned.startsWith("Psr\\") ||
60
+ cleaned.startsWith("Composer\\")
61
+ );
62
+ }
63
+
64
+ private extractFallback(content: string): ParsedFileAST {
65
+ const symbols: ExtractedSymbol[] = [];
66
+ const dependencies: ExtractedDependency[] = [];
67
+
68
+ const lines = content.split("\n");
69
+ const cleanLines = blankCommentsAndStrings(content, { hashComments: true }).split("\n");
70
+
71
+ let currentNamespace = "";
72
+ let currentContainer: string | null = null;
73
+ let currentContainerEndLine = 0;
74
+
75
+ // Detect namespace
76
+ const nsRegex = /^\s*namespace\s+([^;{]+)[;{]/;
77
+ for (const cl of cleanLines) {
78
+ const nsMatch = nsRegex.exec(cl);
79
+ if (nsMatch) {
80
+ currentNamespace = nsMatch[1].trim();
81
+ break;
82
+ }
83
+ }
84
+
85
+ // 1. Extract PHP use / import statements (excluding inside class bodies)
86
+ const useRegex = /^\s*use\s+([^;]+);/;
87
+ for (let i = 0; i < lines.length; i++) {
88
+ if (!cleanLines[i]?.trim()) continue;
89
+ const line = lines[i];
90
+ const match = useRegex.exec(cleanLines[i]);
91
+ if (match) {
92
+ // Check if inside a class container
93
+ const lineNum = i + 1;
94
+ let isInsideClass = false;
95
+ let tempContainerEnd = 0;
96
+ for (let j = 0; j < i; j++) {
97
+ const cMatch = /^(?:abstract\s+|final\s+|readonly\s+)*\b(class|interface|trait|enum)\s+([A-Za-z0-9_]+)\b/.exec(cleanLines[j].trim());
98
+ if (cMatch) {
99
+ tempContainerEnd = findBraceBlockEnd(cleanLines, j);
100
+ }
101
+ }
102
+ if (tempContainerEnd >= lineNum) {
103
+ isInsideClass = true;
104
+ }
105
+ if (isInsideClass) continue;
106
+
107
+ const rawBody = match[1].trim();
108
+ // Check grouped imports: prefix\{A, B as C}
109
+ const groupMatch = /^([A-Za-z0-9_\\]+)\s*\\\{\s*([^}]+)\s*\}/.exec(rawBody);
110
+ if (groupMatch) {
111
+ const prefix = groupMatch[1].trim();
112
+ const items = groupMatch[2].split(",");
113
+ for (const item of items) {
114
+ const trimmedItem = item.trim();
115
+ if (!trimmedItem) continue;
116
+ const aliasMatch = /\bas\s+([A-Za-z0-9_]+)$/i.exec(trimmedItem);
117
+ const rawTarget = trimmedItem.replace(/\s+as\s+[A-Za-z0-9_]+$/i, "").trim();
118
+ const target = `${prefix}\\${rawTarget}`;
119
+ const shortName = rawTarget.split("\\").pop() || rawTarget;
120
+ const importedSymbols = Array.from(new Set([shortName, ...(aliasMatch ? [aliasMatch[1]] : [])])).filter(Boolean);
121
+ dependencies.push({
122
+ target,
123
+ statement: line.trim(),
124
+ line_number: i + 1,
125
+ is_external: this.isExternalNamespace(target),
126
+ ...(importedSymbols.length > 0 ? { imported_symbols: importedSymbols } : {}),
127
+ });
128
+ }
129
+ continue;
130
+ }
131
+
132
+ const fullTarget = rawBody;
133
+ const cleaned = fullTarget.replace(/^(function|const)\s+/, "").replace(/\s+as\s+[A-Za-z0-9_]+$/i, "").trim();
134
+ const aliasMatch = /\bas\s+([A-Za-z0-9_]+)$/i.exec(fullTarget);
135
+ const shortName = cleaned.split("\\").pop() || cleaned;
136
+ const importedSymbols = Array.from(new Set([shortName, ...(aliasMatch ? [aliasMatch[1]] : [])])).filter(Boolean);
137
+
138
+ dependencies.push({
139
+ target: cleaned,
140
+ statement: line.trim(),
141
+ line_number: i + 1,
142
+ is_external: this.isExternalNamespace(cleaned),
143
+ ...(importedSymbols.length > 0 ? { imported_symbols: importedSymbols } : {}),
144
+ });
145
+ }
146
+ }
147
+
148
+ // 2. Extract PHP Class / Interface / Trait / Enum
149
+ for (let i = 0; i < cleanLines.length; i++) {
150
+ const trimmed = cleanLines[i].trim();
151
+ const rawTrimmed = lines[i].trim();
152
+ const lineNum = i + 1;
153
+
154
+ if (!trimmed) continue;
155
+
156
+ const inlineNs = nsRegex.exec(trimmed);
157
+ if (inlineNs) {
158
+ currentNamespace = inlineNs[1].trim();
159
+ }
160
+
161
+ if (currentContainer && lineNum > currentContainerEndLine) {
162
+ currentContainer = null;
163
+ currentContainerEndLine = 0;
164
+ }
165
+
166
+ const classMatch = /^(?:abstract\s+|final\s+|readonly\s+)*\b(class|interface|trait|enum)\s+([A-Za-z0-9_]+)\b/.exec(
167
+ trimmed
168
+ );
169
+ if (classMatch) {
170
+ const shortClassName = classMatch[2];
171
+ currentContainer = currentNamespace ? `${currentNamespace}\\${shortClassName}` : shortClassName;
172
+ const endLine = findBraceBlockEnd(cleanLines, i);
173
+ currentContainerEndLine = endLine;
174
+ symbols.push({
175
+ name: currentContainer,
176
+ kind: classMatch[1] as SymbolKind,
177
+ signature: rawTrimmed.replace(/\{$/, "").trim(),
178
+ visibility: "public",
179
+ line_start: lineNum,
180
+ line_end: endLine,
181
+ line_count: Math.max(1, endLine - lineNum + 1),
182
+ });
183
+ continue;
184
+ }
185
+
186
+ if (currentContainer) {
187
+ const constMatch = /^(?:(public|protected|private)\s+)?\bconst\s+([A-Za-z0-9_]+)\s*=/.exec(trimmed);
188
+ if (constMatch) {
189
+ const vis = (constMatch[1] as Visibility) || "public";
190
+ const constName = constMatch[2];
191
+ symbols.push({
192
+ name: `${currentContainer}::${constName}`,
193
+ kind: "property",
194
+ signature: `${vis} const ${constName}`,
195
+ visibility: vis,
196
+ line_start: lineNum,
197
+ line_end: lineNum,
198
+ line_count: 1,
199
+ });
200
+ continue;
201
+ }
202
+
203
+ const propMatch =
204
+ /^(?:(public|protected|private)\s+)?(?:readonly\s+)?(?:static\s+)?(?:\??[A-Za-z0-9_\\]+\s+)?\$([A-Za-z0-9_]+)(?:\s*=[^;]+)?;\s*$/.exec(
205
+ trimmed
206
+ );
207
+ if (propMatch && !trimmed.includes("function ")) {
208
+ const vis = (propMatch[1] as Visibility) || "public";
209
+ const propName = `$${propMatch[2]}`;
210
+ symbols.push({
211
+ name: `${currentContainer}::${propName}`,
212
+ kind: "property",
213
+ signature: `${vis} ${rawTrimmed.replace(/;\s*$/, "")}`,
214
+ visibility: vis,
215
+ line_start: lineNum,
216
+ line_end: lineNum,
217
+ line_count: 1,
218
+ });
219
+ continue;
220
+ }
221
+
222
+ const methodMatch =
223
+ /^(?:(public|protected|private)\s+)?(?:static\s+)?(?:final\s+)?\bfunction\s+([A-Za-z0-9_]+)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(
224
+ trimmed
225
+ );
226
+ if (methodMatch) {
227
+ const vis = (methodMatch[1] as Visibility) || "public";
228
+ const name = methodMatch[2];
229
+ const params = methodMatch[3].trim();
230
+ const retType = methodMatch[4] ? `: ${methodMatch[4].trim()}` : "";
231
+ const endLine = findBraceBlockEnd(cleanLines, i);
232
+ const nestingDepth = calculateControlFlowNesting(lines, i, endLine - 1);
233
+ symbols.push({
234
+ name: `${currentContainer}::${name}`,
235
+ kind: "method",
236
+ signature: `${vis} function ${name}(${params})${retType}`,
237
+ visibility: vis,
238
+ line_start: lineNum,
239
+ line_end: endLine,
240
+ line_count: Math.max(1, endLine - lineNum + 1),
241
+ nesting_depth: nestingDepth,
242
+ });
243
+ continue;
244
+ }
245
+ }
246
+
247
+ const funcMatch = /^(?:final\s+)?\bfunction\s+([A-Za-z0-9_]+)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(trimmed);
248
+ if (funcMatch && !currentContainer) {
249
+ const shortFnName = funcMatch[1];
250
+ const fnName = currentNamespace ? `${currentNamespace}\\${shortFnName}` : shortFnName;
251
+ const params = funcMatch[2].trim();
252
+ const retType = funcMatch[3] ? `: ${funcMatch[3].trim()}` : "";
253
+ const endLine = findBraceBlockEnd(cleanLines, i);
254
+ const nestingDepth = calculateControlFlowNesting(lines, i, endLine - 1);
255
+ symbols.push({
256
+ name: fnName,
257
+ kind: "function",
258
+ signature: `function ${fnName}${params}${retType}`,
259
+ visibility: "public",
260
+ line_start: lineNum,
261
+ line_end: endLine,
262
+ line_count: Math.max(1, endLine - lineNum + 1),
263
+ nesting_depth: nestingDepth,
264
+ });
265
+ }
266
+ }
267
+
268
+ return { symbols, dependencies };
269
+ }
270
+
271
+ private extractFromAst(rootNode: Parser.SyntaxNode, content: string): ParsedFileAST {
272
+ const symbols: ExtractedSymbol[] = [];
273
+ const dependencies: ExtractedDependency[] = [];
274
+ const lines = content.split("\n");
275
+
276
+ const walk = (node: Parser.SyntaxNode, currentNamespace: string): void => {
277
+ if (node.type === "namespace_use_declaration") {
278
+ const rawStmt = (lines[node.startPosition.row] ?? node.text).trim();
279
+ const useGroupNode = node.namedChildren.find((c) => c.type === "namespace_use_group");
280
+ const prefixNode = node.namedChildren.find((c) => c.type === "namespace_name");
281
+
282
+ if (useGroupNode && prefixNode) {
283
+ const prefix = prefixNode.text.replace(/^\\/, "");
284
+ for (const clause of useGroupNode.namedChildren.filter((c) => c.type === "namespace_use_group_clause")) {
285
+ const clauseNameNode = clause.namedChildren.find((c) => c.type === "namespace_name" || c.type === "name");
286
+ if (!clauseNameNode) continue;
287
+ const clauseName = clauseNameNode.text.replace(/^\\/, "");
288
+ const aliasClause = clause.namedChildren.find((c) => c.type === "namespace_aliasing_clause");
289
+ const aliasNode = aliasClause?.namedChildren.find((c) => c.type === "name");
290
+ const alias = aliasNode?.text;
291
+ const target = `${prefix}\\${clauseName}`;
292
+ const shortName = clauseName.split("\\").pop() || clauseName;
293
+ const importedSymbols = Array.from(new Set([shortName, ...(alias ? [alias] : [])])).filter(Boolean);
294
+
295
+ dependencies.push({
296
+ target,
297
+ statement: rawStmt,
298
+ line_number: clause.startPosition.row + 1,
299
+ is_external: this.isExternalNamespace(target),
300
+ ...(importedSymbols.length > 0 ? { imported_symbols: importedSymbols } : {}),
301
+ });
302
+ }
303
+ return;
304
+ }
305
+
306
+ const useClauses = node.namedChildren.filter((c) => c.type === "namespace_use_clause");
307
+ if (useClauses.length > 0) {
308
+ for (const clause of useClauses) {
309
+ const qualifiedNode = clause.namedChildren.find((c) => c.type === "qualified_name" || c.type === "name");
310
+ const target = (qualifiedNode ? qualifiedNode.text : clause.text.replace(/\s+as\s+[A-Za-z0-9_]+$/i, ""))
311
+ .replace(/^(function|const)\s+/i, "")
312
+ .replace(/^\\/, "")
313
+ .trim();
314
+ const aliasClause = clause.namedChildren.find((c) => c.type === "namespace_aliasing_clause");
315
+ const aliasNode = aliasClause?.namedChildren.find((c) => c.type === "name");
316
+ const alias = aliasNode?.text;
317
+ const shortName = target.split("\\").pop() || target;
318
+ const importedSymbols = Array.from(new Set([shortName, ...(alias ? [alias] : [])])).filter(Boolean);
319
+
320
+ dependencies.push({
321
+ target,
322
+ statement: rawStmt,
323
+ line_number: clause.startPosition.row + 1,
324
+ is_external: this.isExternalNamespace(target),
325
+ ...(importedSymbols.length > 0 ? { imported_symbols: importedSymbols } : {}),
326
+ });
327
+ }
328
+ return;
329
+ }
330
+
331
+ // Fallback for unexpected use format
332
+ const bodyMatch = /^\s*use\s+([^;]+);/i.exec(node.text.replace(/\r?\n/g, " "));
333
+ if (bodyMatch) {
334
+ const fullTarget = bodyMatch[1].trim();
335
+ const cleaned = fullTarget.replace(/^(function|const)\s+/i, "").replace(/\s+as\s+[A-Za-z0-9_]+$/i, "").replace(/^\\/, "").trim();
336
+ const aliasMatch = /\bas\s+([A-Za-z0-9_]+)$/i.exec(fullTarget);
337
+ const shortName = cleaned.split("\\").pop() || cleaned;
338
+ const importedSymbols = Array.from(
339
+ new Set([shortName, ...(aliasMatch ? [aliasMatch[1]] : [])])
340
+ ).filter(Boolean);
341
+
342
+ dependencies.push({
343
+ target: cleaned,
344
+ statement: rawStmt,
345
+ line_number: node.startPosition.row + 1,
346
+ is_external: this.isExternalNamespace(cleaned),
347
+ ...(importedSymbols.length > 0 ? { imported_symbols: importedSymbols } : {}),
348
+ });
349
+ }
350
+ return;
351
+ }
352
+
353
+ if (
354
+ node.type === "class_declaration" ||
355
+ node.type === "interface_declaration" ||
356
+ node.type === "trait_declaration" ||
357
+ node.type === "enum_declaration"
358
+ ) {
359
+ const nameNode = node.childForFieldName("name") ?? node.namedChildren.find((c) => c.type === "name");
360
+ if (!nameNode) return;
361
+
362
+ const rawName = nameNode.text;
363
+ const containerName = currentNamespace ? `${currentNamespace}\\${rawName}` : rawName;
364
+ const kindMap: Record<string, SymbolKind> = {
365
+ class_declaration: "class",
366
+ interface_declaration: "interface",
367
+ trait_declaration: "trait",
368
+ enum_declaration: "enum",
369
+ };
370
+ const lineStart = node.startPosition.row + 1;
371
+ const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
372
+ const headerLine = getNodeHeader(node);
373
+
374
+ symbols.push({
375
+ name: containerName,
376
+ kind: kindMap[node.type] ?? "class",
377
+ signature: headerLine || `${kindMap[node.type]} ${containerName}`,
378
+ visibility: "public",
379
+ line_start: lineStart,
380
+ line_end: lineEnd,
381
+ line_count: Math.max(1, lineEnd - lineStart + 1),
382
+ });
383
+
384
+ const bodyNode =
385
+ node.childForFieldName("body") ?? node.namedChildren.find((c) => c.type === "declaration_list" || c.type === "enum_declaration_list");
386
+ if (bodyNode) {
387
+ this.extractPhpContainerMembers(containerName, bodyNode, lines, symbols);
388
+ }
389
+ return;
390
+ }
391
+
392
+ if (node.type === "function_definition") {
393
+ const nameNode = node.childForFieldName("name") ?? node.namedChildren.find((c) => c.type === "name");
394
+ if (!nameNode) return;
395
+
396
+ const fnShortName = nameNode.text;
397
+ const fnName = currentNamespace ? `${currentNamespace}\\${fnShortName}` : fnShortName;
398
+ const paramsNode = node.childForFieldName("parameters") ?? node.namedChildren.find((c) => c.type === "formal_parameters");
399
+ const retNode = node.childForFieldName("return_type");
400
+ const paramsText = paramsNode ? paramsNode.text : "()";
401
+ const retText = retNode ? `: ${retNode.text.replace(/^:\s*/, "")}` : "";
402
+ const lineStart = node.startPosition.row + 1;
403
+ const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
404
+ const nestingDepth = calculateAstControlFlowNesting(
405
+ node,
406
+ PHP_CONTROL_FLOW_NODES,
407
+ PHP_FUNCTION_BOUNDARY_NODES
408
+ );
409
+
410
+ symbols.push({
411
+ name: fnName,
412
+ kind: "function",
413
+ signature: `function ${fnName}${paramsText}${retText}`,
414
+ visibility: "public",
415
+ line_start: lineStart,
416
+ line_end: lineEnd,
417
+ line_count: Math.max(1, lineEnd - lineStart + 1),
418
+ nesting_depth: nestingDepth,
419
+ });
420
+ return;
421
+ }
422
+
423
+ for (const child of node.namedChildren) {
424
+ walk(child, currentNamespace);
425
+ }
426
+ };
427
+
428
+ let activeNamespace = "";
429
+ for (const topChild of rootNode.namedChildren) {
430
+ if (topChild.type === "namespace_definition") {
431
+ const bodyNode = topChild.childForFieldName("body");
432
+ const nameNode = topChild.childForFieldName("name") ?? topChild.namedChildren.find((c) => c.type === "namespace_name");
433
+ const nsName = nameNode ? nameNode.text.replace(/^\\/, "") : "";
434
+ if (bodyNode) {
435
+ for (const bodyChild of bodyNode.namedChildren) {
436
+ walk(bodyChild, nsName);
437
+ }
438
+ } else {
439
+ activeNamespace = nsName;
440
+ }
441
+ continue;
442
+ }
443
+ walk(topChild, activeNamespace);
444
+ }
445
+
446
+ return { symbols, dependencies };
447
+ }
448
+
449
+ private extractPhpContainerMembers(
450
+ containerName: string,
451
+ bodyNode: Parser.SyntaxNode,
452
+ lines: string[],
453
+ symbols: ExtractedSymbol[]
454
+ ): void {
455
+ for (const member of bodyNode.namedChildren) {
456
+ const mStart = member.startPosition.row + 1;
457
+ const mEnd = Math.max(mStart, member.endPosition.row + 1);
458
+ const mCount = Math.max(1, mEnd - mStart + 1);
459
+ const vis = this.extractPhpVisibility(member);
460
+
461
+ if (member.type === "method_declaration") {
462
+ const nameNode = member.childForFieldName("name") ?? member.namedChildren.find((c) => c.type === "name");
463
+ if (!nameNode) continue;
464
+
465
+ const methodName = nameNode.text;
466
+ const paramsNode =
467
+ member.childForFieldName("parameters") ??
468
+ member.namedChildren.find((c) => c.type === "formal_parameters");
469
+ const retNode = member.childForFieldName("return_type");
470
+ const paramsText = paramsNode ? paramsNode.text : "()";
471
+ const retText = retNode ? `: ${retNode.text.replace(/^:\s*/, "")}` : "";
472
+ const nestingDepth = calculateAstControlFlowNesting(
473
+ member,
474
+ PHP_CONTROL_FLOW_NODES,
475
+ PHP_FUNCTION_BOUNDARY_NODES
476
+ );
477
+
478
+ symbols.push({
479
+ name: `${containerName}::${methodName}`,
480
+ kind: "method",
481
+ signature: `${vis} function ${methodName}${paramsText}${retText}`,
482
+ visibility: vis,
483
+ line_start: mStart,
484
+ line_end: mEnd,
485
+ line_count: mCount,
486
+ nesting_depth: nestingDepth,
487
+ });
488
+ continue;
489
+ }
490
+
491
+ if (member.type === "property_declaration") {
492
+ const propElems = member.namedChildren.filter((c) => c.type === "property_element");
493
+ if (propElems.length > 0) {
494
+ for (const propElem of propElems) {
495
+ const varNode =
496
+ propElem.namedChildren.find((c) => c.type === "variable_name") ??
497
+ propElem;
498
+ const rawText = varNode.text;
499
+ const propName = rawText.startsWith("$") ? rawText : `$${rawText}`;
500
+ const rawLine = (lines[member.startPosition.row] ?? member.text).trim().replace(/;\s*$/, "");
501
+
502
+ symbols.push({
503
+ name: `${containerName}::${propName}`,
504
+ kind: "property",
505
+ signature: rawLine.startsWith(vis) ? rawLine : `${vis} ${rawLine}`,
506
+ visibility: vis,
507
+ line_start: propElem.startPosition.row + 1,
508
+ line_end: propElem.endPosition.row + 1,
509
+ line_count: Math.max(1, propElem.endPosition.row - propElem.startPosition.row + 1),
510
+ });
511
+ }
512
+ }
513
+ continue;
514
+ }
515
+
516
+ if (member.type === "const_declaration") {
517
+ const constElems = member.namedChildren.filter((c) => c.type === "const_element");
518
+ for (const constElem of (constElems.length > 0 ? constElems : [member])) {
519
+ const nameNode =
520
+ constElem.childForFieldName("name") ??
521
+ constElem.namedChildren.find((c) => c.type === "name");
522
+ if (!nameNode) continue;
523
+
524
+ const constName = nameNode.text;
525
+ symbols.push({
526
+ name: `${containerName}::${constName}`,
527
+ kind: "property",
528
+ signature: `${vis} const ${constName}`,
529
+ visibility: vis,
530
+ line_start: constElem.startPosition.row + 1,
531
+ line_end: constElem.endPosition.row + 1,
532
+ line_count: Math.max(1, constElem.endPosition.row - constElem.startPosition.row + 1),
533
+ });
534
+ }
535
+ continue;
536
+ }
537
+
538
+ if (member.type === "enum_case") {
539
+ const nameNode = member.childForFieldName("name") ?? member.namedChildren.find((c) => c.type === "name");
540
+ if (!nameNode) continue;
541
+
542
+ const caseName = nameNode.text;
543
+ symbols.push({
544
+ name: `${containerName}::${caseName}`,
545
+ kind: "property",
546
+ signature: (lines[member.startPosition.row] ?? member.text).trim().replace(/;\s*$/, ""),
547
+ visibility: "public",
548
+ line_start: mStart,
549
+ line_end: mEnd,
550
+ line_count: mCount,
551
+ });
552
+ continue;
553
+ }
554
+ }
555
+ }
556
+
557
+ private extractPhpVisibility(node: Parser.SyntaxNode): Visibility {
558
+ for (const child of node.children) {
559
+ if (child.type === "visibility_modifier") {
560
+ const t = child.text.trim().toLowerCase();
561
+ if (t === "private" || t === "protected" || t === "public") {
562
+ return t;
563
+ }
564
+ }
565
+ }
566
+ return "public";
567
+ }
568
+ }
569
+