@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
@@ -12,8 +12,10 @@ import {
12
12
  calculateControlFlowNesting,
13
13
  findBraceBlockEnd,
14
14
  } from "../boundary-tracker.ts";
15
- import { calculateAstControlFlowNesting, getNodeHeader, parseSourceWithTreeSitter } from "../wasm-loader.ts";
15
+ import { getNodeHeader, calculateAstControlFlowNesting, parseSourceWithTreeSitter } from "../wasm-loader.ts";
16
16
  import type { CodeExtractor } from "./base.ts";
17
+ import { extractWithTypeScriptCompiler } from "./typescript-compiler-fallback.ts";
18
+ import { extractTypeScriptFallback } from "./typescript-fallback.ts";
17
19
 
18
20
  const TS_CONTROL_FLOW_NODES = new Set([
19
21
  "if_statement",
@@ -47,6 +49,15 @@ export class TypeScriptExtractor implements CodeExtractor {
47
49
  () => this.extractFallback(content)
48
50
  );
49
51
 
52
+ if (treeSitterResult && treeSitterResult.status !== "degraded") {
53
+ return treeSitterResult;
54
+ }
55
+
56
+ const compilerAst = extractWithTypeScriptCompiler(filePath, content);
57
+ if (compilerAst) {
58
+ return compilerAst;
59
+ }
60
+
50
61
  if (treeSitterResult) {
51
62
  return treeSitterResult;
52
63
  }
@@ -55,209 +66,7 @@ export class TypeScriptExtractor implements CodeExtractor {
55
66
  }
56
67
 
57
68
  private extractFallback(content: string): ParsedFileAST {
58
- const symbols: ExtractedSymbol[] = [];
59
- const dependencies: ExtractedDependency[] = [];
60
-
61
- const rawLines = content.split("\n");
62
- const cleanContent = blankCommentsAndStrings(content);
63
- const cleanLines = cleanContent.split("\n");
64
-
65
- const importRegex =
66
- /^\s*(?:(?:import|export)\s+(?:type\s+)?(?:([\w*\s{},]+)\s+from\s+)?['"]([^'"]+)['"]|(?:const|let|var)\s+([\w\s{},:$]+)\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)|require\s*\(\s*['"]([^'"]+)['"]\s*\))/;
67
-
68
- for (let i = 0; i < rawLines.length; i++) {
69
- if (!cleanLines[i]?.trim()) continue;
70
- const line = rawLines[i];
71
- const match = importRegex.exec(line);
72
- if (match) {
73
- const target = match[2] || match[4] || match[5];
74
- const clause = match[1] || match[3] || "";
75
- if (target) {
76
- const importedSymbols = clause
77
- .replace(/[{}*]/g, " ")
78
- .split(/,|\bas\b/)
79
- .map((s) => s.trim())
80
- .filter((s) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(s) && s !== "type");
81
- const isExternal = !target.startsWith(".") && !target.startsWith("/");
82
- dependencies.push({
83
- target,
84
- statement: line.trim(),
85
- line_number: i + 1,
86
- is_external: isExternal,
87
- ...(importedSymbols.length > 0 ? { imported_symbols: Array.from(new Set(importedSymbols)) } : {}),
88
- });
89
- }
90
- }
91
- }
92
-
93
- // 2. Extract Symbols using cleanLines + brace depth tracking
94
- let currentClass: string | null = null;
95
- let currentClassDepth = 0;
96
- let braceDepth = 0;
97
-
98
- for (let i = 0; i < cleanLines.length; i++) {
99
- const cleanTrimmed = cleanLines[i].trim();
100
- const rawTrimmed = rawLines[i].trim();
101
- const lineNum = i + 1;
102
-
103
- if (currentClass && braceDepth < currentClassDepth) {
104
- currentClass = null;
105
- currentClassDepth = 0;
106
- }
107
-
108
- if (cleanTrimmed && braceDepth === 0) {
109
- const classMatch =
110
- /^(?:export\s+)?(?:default\s+)?(?:abstract\s+)?\b(class|interface)\s+([A-Za-z_$][A-Za-z0-9_$]*)\b/.exec(
111
- cleanTrimmed
112
- );
113
- if (classMatch) {
114
- currentClass = classMatch[2];
115
- currentClassDepth = braceDepth + 1;
116
- const endLine = findBraceBlockEnd(cleanLines, i);
117
- symbols.push({
118
- name: classMatch[2],
119
- kind: classMatch[1] as "class" | "interface",
120
- signature: rawTrimmed.replace(/\{$/, "").trim(),
121
- visibility: "public",
122
- line_start: lineNum,
123
- line_end: endLine,
124
- line_count: Math.max(1, endLine - lineNum + 1),
125
- });
126
- } else {
127
- const typeMatch = /^(?:export\s+)?\btype\s+([A-Za-z_$][A-Za-z0-9_$]*)\b\s*=/.exec(cleanTrimmed);
128
- if (typeMatch) {
129
- const endLine = cleanTrimmed.endsWith(";") ? lineNum : findBraceBlockEnd(cleanLines, i);
130
- symbols.push({
131
- name: typeMatch[1],
132
- kind: "type",
133
- signature: rawTrimmed.replace(/;$/, "").trim(),
134
- visibility: "public",
135
- line_start: lineNum,
136
- line_end: endLine,
137
- line_count: Math.max(1, endLine - lineNum + 1),
138
- });
139
- }
140
-
141
- const enumMatch = /^(?:export\s+)?(?:const\s+)?\benum\s+([A-Za-z_$][A-Za-z0-9_$]*)\b/.exec(cleanTrimmed);
142
- if (enumMatch) {
143
- const endLine = findBraceBlockEnd(cleanLines, i);
144
- symbols.push({
145
- name: enumMatch[1],
146
- kind: "enum",
147
- signature: rawTrimmed.replace(/\{$/, "").trim(),
148
- visibility: "public",
149
- line_start: lineNum,
150
- line_end: endLine,
151
- line_count: Math.max(1, endLine - lineNum + 1),
152
- });
153
- }
154
-
155
- const fnMatch =
156
- /^(?:export\s+)?(?:default\s+)?(?:async\s+)?\bfunction\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(
157
- cleanTrimmed
158
- );
159
- if (fnMatch) {
160
- const name = fnMatch[1];
161
- const params = fnMatch[2];
162
- const retType = fnMatch[3] ? `: ${fnMatch[3].trim()}` : "";
163
- const endLine = findBraceBlockEnd(cleanLines, i);
164
- const nestingDepth = calculateControlFlowNesting(rawLines, i, endLine - 1);
165
- symbols.push({
166
- name,
167
- kind: "function",
168
- signature: `${name}(${params})${retType}`,
169
- visibility: "public",
170
- line_start: lineNum,
171
- line_end: endLine,
172
- line_count: Math.max(1, endLine - lineNum + 1),
173
- nesting_depth: nestingDepth,
174
- });
175
- }
176
-
177
- const varMatch =
178
- /^(?:export\s+)?\b(const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*(?::\s*([^=;]+))?\s*=\s*(.*)$/.exec(
179
- cleanTrimmed
180
- );
181
- if (varMatch) {
182
- const declKind = varMatch[1];
183
- const varName = varMatch[2];
184
- const typeStr = varMatch[3] ? `: ${varMatch[3].trim()}` : "";
185
- const rhs = varMatch[4].trim();
186
- const isArrowOrFn = /^(?:async\s+)?(?:\([^)]*\)|[A-Za-z_$][A-Za-z0-9_$]*)\s*=>|^function\b/.test(rhs);
187
- symbols.push({
188
- name: varName,
189
- kind: isArrowOrFn ? "function" : declKind === "const" ? "constant" : "variable",
190
- signature: `${declKind} ${varName}${typeStr}`,
191
- visibility: cleanTrimmed.startsWith("export ") ? "public" : "private",
192
- line_start: lineNum,
193
- line_end: lineNum,
194
- line_count: 1,
195
- });
196
- }
197
- }
198
- } else if (cleanTrimmed && currentClass && braceDepth === currentClassDepth) {
199
- const methodMatch =
200
- /^(?:(public|protected|private)\s+)?(?:static\s+)?(?:readonly\s+)?(?:async\s+)?\b([A-Za-z_$][A-Za-z0-9_$]*)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(
201
- cleanTrimmed
202
- );
203
- if (
204
- methodMatch &&
205
- !["if", "for", "while", "switch", "catch", "function", "return"].includes(methodMatch[2])
206
- ) {
207
- const vis = (methodMatch[1] as Visibility) || "public";
208
- const name = methodMatch[2];
209
- const params = methodMatch[3];
210
- const retType = methodMatch[4] ? `: ${methodMatch[4].trim()}` : "";
211
- const endLine = findBraceBlockEnd(cleanLines, i);
212
- const nestingDepth = calculateControlFlowNesting(rawLines, i, endLine - 1);
213
- symbols.push({
214
- name: `${currentClass}::${name}`,
215
- kind: "method",
216
- signature: `${vis} ${name}(${params})${retType}`,
217
- visibility: vis,
218
- line_start: lineNum,
219
- line_end: endLine,
220
- line_count: Math.max(1, endLine - lineNum + 1),
221
- nesting_depth: nestingDepth,
222
- });
223
- } else {
224
- const propMatch =
225
- /^(?:(public|protected|private)\s+)?(?:static\s+)?(?:readonly\s+)?\b([A-Za-z_$][A-Za-z0-9_$]*)\s*(?:\?|\!)?\s*(?::\s*([^;={]+))?(?:\s*=[^;]+)?;\s*$/.exec(
226
- cleanTrimmed
227
- );
228
- if (
229
- propMatch &&
230
- !["return", "const", "let", "var", "throw", "import", "export", "continue", "break"].includes(
231
- propMatch[2]
232
- )
233
- ) {
234
- const vis = (propMatch[1] as Visibility) || "public";
235
- const propName = propMatch[2];
236
- const typeStr = propMatch[3] ? `: ${propMatch[3].trim()}` : "";
237
- symbols.push({
238
- name: `${currentClass}::${propName}`,
239
- kind: "property",
240
- signature: `${vis} ${propName}${typeStr}`,
241
- visibility: vis,
242
- line_start: lineNum,
243
- line_end: lineNum,
244
- line_count: 1,
245
- });
246
- }
247
- }
248
- }
249
-
250
- for (const ch of cleanLines[i]) {
251
- if (ch === "{") braceDepth++;
252
- else if (ch === "}") braceDepth = Math.max(0, braceDepth - 1);
253
- }
254
- if (currentClass && braceDepth < currentClassDepth) {
255
- currentClass = null;
256
- currentClassDepth = 0;
257
- }
258
- }
259
-
260
- return { symbols, dependencies };
69
+ return extractTypeScriptFallback(content);
261
70
  }
262
71
 
263
72
  private extractFromAst(rootNode: Parser.SyntaxNode, content: string): ParsedFileAST {
@@ -267,7 +76,11 @@ export class TypeScriptExtractor implements CodeExtractor {
267
76
 
268
77
  const stripQuotes = (raw: string): string => raw.replace(/^['"`]|['"`]$/g, "");
269
78
 
270
- const walkDependencies = (node: Parser.SyntaxNode): void => {
79
+ const depNodeTypes = /\b(?:require|import)\s*\(/.test(content)
80
+ ? ["import_statement", "export_statement", "call_expression"]
81
+ : ["import_statement", "export_statement"];
82
+
83
+ for (const node of rootNode.descendantsOfType(depNodeTypes)) {
271
84
  if (node.type === "import_statement") {
272
85
  const sourceNode =
273
86
  node.childForFieldName("source") ??
@@ -286,7 +99,7 @@ export class TypeScriptExtractor implements CodeExtractor {
286
99
  });
287
100
  }
288
101
  }
289
- return;
102
+ continue;
290
103
  }
291
104
 
292
105
  if (node.type === "export_statement") {
@@ -307,7 +120,7 @@ export class TypeScriptExtractor implements CodeExtractor {
307
120
  });
308
121
  }
309
122
  }
310
- return;
123
+ continue;
311
124
  }
312
125
 
313
126
  if (node.type === "call_expression") {
@@ -334,13 +147,7 @@ export class TypeScriptExtractor implements CodeExtractor {
334
147
  }
335
148
  }
336
149
  }
337
-
338
- for (const child of node.namedChildren) {
339
- walkDependencies(child);
340
- }
341
- };
342
-
343
- walkDependencies(rootNode);
150
+ }
344
151
 
345
152
  const processTopLevelNode = (stmtNode: Parser.SyntaxNode, isExported: boolean, outerStartRow?: number): void => {
346
153
  const startRow = outerStartRow ?? stmtNode.startPosition.row;
@@ -387,6 +194,19 @@ export class TypeScriptExtractor implements CodeExtractor {
387
194
  return;
388
195
  }
389
196
 
197
+ if (stmtNode.type === "internal_module") {
198
+ const name = stmtNode.childForFieldName("name");
199
+ const body = stmtNode.childForFieldName("body");
200
+ if (name && body && name.type !== "string") {
201
+ const firstSymbol = symbols.length;
202
+ for (const child of body.namedChildren) processTopLevelNode(child, false);
203
+ for (let i = firstSymbol; i < symbols.length; i++) {
204
+ symbols[i].name = `${name.text}::${symbols[i].name}`;
205
+ }
206
+ }
207
+ return;
208
+ }
209
+
390
210
  if (
391
211
  stmtNode.type === "class_declaration" ||
392
212
  stmtNode.type === "abstract_class_declaration" ||
@@ -402,7 +222,7 @@ export class TypeScriptExtractor implements CodeExtractor {
402
222
  symbols.push({
403
223
  name: className,
404
224
  kind,
405
- signature: getNodeHeader(stmtNode),
225
+ signature: getNodeHeader(stmtNode, content),
406
226
  visibility: "public",
407
227
  line_start: lineStart,
408
228
  line_end: lineEnd,
@@ -429,7 +249,7 @@ export class TypeScriptExtractor implements CodeExtractor {
429
249
  symbols.push({
430
250
  name: nameNode.text,
431
251
  kind: stmtNode.type === "enum_declaration" ? "enum" : "type",
432
- signature: getNodeHeader(stmtNode),
252
+ signature: getNodeHeader(stmtNode, content),
433
253
  visibility: "public",
434
254
  line_start: lineStart,
435
255
  line_end: lineEnd,
@@ -0,0 +1,97 @@
1
+ import { createHash } from "node:crypto";
2
+ import { closeSync, existsSync, openSync, readFileSync, readSync, readdirSync, realpathSync, statSync } from "node:fs";
3
+ import { dirname, join, relative, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { WASM_ASSETS } from "./wasm-assets.ts";
6
+
7
+ /** Content identity, independent of checkout paths, mtimes and release counters. */
8
+ export function fingerprintImplementation(options: {
9
+ sourceRoot?: string;
10
+ executablePath?: string;
11
+ assets?: Record<string, string>;
12
+ }): string {
13
+ const hash = createHash("sha256");
14
+ const chunk = Buffer.allocUnsafe(256 * 1024);
15
+ const addFile = (label: string, file: string): void => {
16
+ const expectedSize = statSync(file).size;
17
+ hash.update(JSON.stringify([label, expectedSize]));
18
+ // Bound memory while hashing standalone executables, which include the Bun runtime.
19
+ const fd = openSync(file, "r");
20
+ try {
21
+ let total = 0;
22
+ for (;;) {
23
+ const size = readSync(fd, chunk, 0, chunk.length, null);
24
+ if (!size) break;
25
+ hash.update(chunk.subarray(0, size));
26
+ total += size;
27
+ }
28
+ if (total !== expectedSize) throw new Error(`Implementation changed while fingerprinting '${label}'. Restart Septum.`);
29
+ } finally { closeSync(fd); }
30
+ hash.update("\0");
31
+ };
32
+ if (options.executablePath) {
33
+ addFile("executable", options.executablePath);
34
+ } else if (options.sourceRoot) {
35
+ const root = resolve(options.sourceRoot);
36
+ const ancestors = new Set<string>();
37
+ const visit = (directory: string, base = root, prefix = ""): void => {
38
+ const identity = realpathSync(directory);
39
+ if (ancestors.has(identity)) throw new Error(`Implementation directory cycle at '${directory}'.`);
40
+ ancestors.add(identity);
41
+ try {
42
+ for (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
43
+ const file = join(directory, entry.name);
44
+ const info = entry.isSymbolicLink() ? statSync(file) : entry;
45
+ if (info.isDirectory()) visit(file, base, prefix);
46
+ else if (info.isFile()) addFile([prefix, relative(base, file).replace(/\\/g, "/")].filter(Boolean).join("/"), file);
47
+ }
48
+ } finally { ancestors.delete(identity); }
49
+ };
50
+ visit(join(root, "src"));
51
+ visit(join(root, "bin"));
52
+ for (const name of ["package.json", "bun.lock", "bun.lockb"]) {
53
+ const file = join(root, name);
54
+ if (existsSync(file)) addFile(name, file);
55
+ }
56
+ // Include installed bytes: local dependency patches can change analysis
57
+ // without changing a package manifest or lockfile.
58
+ const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
59
+ for (const name of Object.keys(manifest.dependencies ?? {}).sort()) {
60
+ let directory = root;
61
+ while (!existsSync(join(directory, "node_modules", name, "package.json"))) {
62
+ const parent = dirname(directory);
63
+ if (parent === directory) throw new Error(`Cannot fingerprint installed dependency '${name}'.`);
64
+ directory = parent;
65
+ }
66
+ const packageRoot = join(directory, "node_modules", name);
67
+ visit(packageRoot, packageRoot, `dependency:${name}`);
68
+ }
69
+ } else {
70
+ throw new Error("Implementation fingerprint requires sourceRoot or executablePath.");
71
+ }
72
+ for (const [name, file] of Object.entries(options.assets ?? {}).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
73
+ // Embedded WASM paths support readFileSync in compiled Bun executables.
74
+ hash.update(JSON.stringify(["asset", name]));
75
+ hash.update(readFileSync(file));
76
+ hash.update("\0");
77
+ }
78
+ hash.update(JSON.stringify(["runtime", Bun.version, process.platform, process.arch]));
79
+ return `sha256:${hash.digest("hex")}`;
80
+ }
81
+
82
+ const standalone = typeof Bun.isStandaloneExecutable === "boolean"
83
+ ? Bun.isStandaloneExecutable : Bun.embeddedFiles.length > 0;
84
+ const assets = Object.fromEntries(Object.entries(WASM_ASSETS).map(([name, embedded]) => {
85
+ const override = process.env.SEPTUM_WASM_DIR;
86
+ const candidates = override ? [join(override, name), join(override, "out", name), embedded] : [embedded];
87
+ return [name, candidates.find(file => existsSync(file)) ?? embedded];
88
+ }));
89
+
90
+ // One identity per loaded process. A daemon must restart to load changed implementation code.
91
+ export const ANALYSIS_FINGERPRINT = fingerprintImplementation(standalone ? {
92
+ executablePath: process.platform === "linux" ? "/proc/self/exe" : process.execPath,
93
+ assets,
94
+ } : {
95
+ sourceRoot: resolve(dirname(fileURLToPath(import.meta.url)), "../../.."),
96
+ assets,
97
+ });
@@ -1,8 +1,8 @@
1
1
  import * as path from "node:path";
2
2
  import grammarPackage from "tree-sitter-wasms/package.json";
3
+ import { ANALYSIS_FINGERPRINT } from "./implementation-fingerprint.ts";
3
4
 
4
- // Keep this revision aligned with ingestion invalidation; coverage is never implied by parse success.
5
- export const PARSER_REVISION = "4";
5
+ export const PARSER_FINGERPRINT = ANALYSIS_FINGERPRINT;
6
6
 
7
7
  type LanguageDefinition = {
8
8
  id: string;
@@ -22,10 +22,10 @@ export const LANGUAGE_CAPABILITIES: readonly LanguageDefinition[] = [
22
22
  { id: "php", extensions: [".php"], aliases: [], extractor: "php", method: "tree-sitter", grammar: "php", limits: "Selected declarations/imports; partial PSR-4/domain resolution, no runtime reflection." },
23
23
  { id: "python", extensions: [".py"], aliases: ["py"], extractor: "python", method: "tree-sitter", grammar: "python", limits: "Selected declarations/imports; package resolution and dynamic attributes incomplete." },
24
24
  { id: "go", extensions: [".go"], aliases: ["golang"], extractor: "go", method: "tree-sitter", grammar: "go", limits: "Selected declarations/imports; no complete module/package or receiver resolution." },
25
- { id: "rust", extensions: [".rs"], aliases: ["rs"], extractor: "rust", method: "tree-sitter", grammar: "rust", limits: "Selected items/use declarations; no Cargo resolution, macro expansion or trait dispatch proof." },
26
- { id: "java", extensions: [".java"], aliases: [], extractor: "java", method: "tree-sitter", grammar: "java", limits: "Selected declarations; imports currently marked external, no JVM package resolution." },
27
- { id: "csharp", extensions: [".cs"], aliases: ["cs", "c_sharp"], extractor: "csharp", method: "tree-sitter", grammar: "c_sharp", limits: "Regression support for selected declarations; imports marked external, no assembly resolution." },
28
- { id: "ruby", extensions: [".rb"], aliases: ["rb"], extractor: "ruby", method: "tree-sitter", grammar: "ruby", limits: "Selected declarations/requires; no load-order or metaprogramming evaluation." },
25
+ { id: "rust", extensions: [".rs"], aliases: ["rs"], extractor: "rust", method: "tree-sitter", grammar: "rust", limits: "Literal Cargo/module/path dependency resolution; cfg remains conditional, no macro expansion or trait dispatch proof." },
26
+ { id: "java", extensions: [".java"], aliases: [], extractor: "java", method: "tree-sitter", grammar: "java", limits: "Local source types/packages and literal Maven/Gradle project roots; no complete binary classpath or build execution." },
27
+ { id: "csharp", extensions: [".cs"], aliases: ["cs", "c_sharp"], extractor: "csharp", method: "tree-sitter", grammar: "c_sharp", limits: "Local namespaces/types and literal project references; conditional MSBuild inputs remain uncertain, no assembly namespace inference from package names." },
28
+ { id: "ruby", extensions: [".rb"], aliases: ["rb"], extractor: "ruby", method: "tree-sitter", grammar: "ruby", limits: "Literal require_relative, conventional lib roots and declared gems; no dynamic load-path, Zeitwerk configuration or metaprogramming execution." },
29
29
  { id: "frontend", extensions: [".vue", ".astro", ".svelte"], aliases: [], extractor: "frontend", method: "embedded-script", limits: "Scans script/frontmatter as TypeScript; no whole-template AST validation." },
30
30
  { id: "kotlin", extensions: [".kt"], aliases: [], extractor: null, method: "unsupported", limits: "Recognized for unsupported-file diagnostics; no registered grammar or extractor." },
31
31
  { id: "scala", extensions: [".scala"], aliases: [], extractor: null, method: "unsupported", limits: "Recognized only; no registered grammar or extractor." },
@@ -37,6 +37,21 @@ export function getLanguageCapability(filePath: string): LanguageDefinition | un
37
37
  return LANGUAGE_CAPABILITIES.find(language => language.extensions.some(ext => lower.endsWith(ext)));
38
38
  }
39
39
 
40
+ export function getOperationCapabilities(filePath: string) {
41
+ const language = getLanguageCapability(filePath);
42
+ const declarations = language?.extractor ? "partial" : "unsupported";
43
+ return {
44
+ language: language?.id ?? "unknown",
45
+ declarations,
46
+ import_resolution: language && ["typescript", "javascript", "php", "python", "go", "rust", "java", "csharp", "ruby", "frontend"].includes(language.id) ? "partial" : "unsupported",
47
+ source_context: declarations,
48
+ deep_context: /\.(?:ts|mts|cts|tsx)$/.test(filePath) ? "bounded_references" : "unsupported",
49
+ caller_analysis: language?.extractor ? "lexical_heuristic" : "unsupported",
50
+ runtime_dispatch: "unverified",
51
+ limits: language?.limits ?? "No registered language extractor.",
52
+ };
53
+ }
54
+
40
55
  export function grammarFileForKey(keyOrPath: string): string | null {
41
56
  const key = keyOrPath.trim().toLowerCase();
42
57
  if (key.endsWith(".wasm")) return key;
@@ -49,7 +64,7 @@ export function grammarFileForKey(keyOrPath: string): string | null {
49
64
 
50
65
  export function getParserCapabilities(full: boolean) {
51
66
  const common = {
52
- parser_revision: PARSER_REVISION,
67
+ parser_revision: PARSER_FINGERPRINT,
53
68
  grammar_package: `${grammarPackage.name}@${grammarPackage.version}`,
54
69
  coverage: "partial",
55
70
  status_contract: "parsed = parser/scanner completed; degraded = recovery/fallback; unsupported = no extractor. None implies complete extraction or runtime correctness.",
@@ -61,6 +76,7 @@ export function getParserCapabilities(full: boolean) {
61
76
  coverage: l.extractor ? "partial" : "none",
62
77
  grammars: [...new Set(l.extensions.map(grammarFileForKey).filter(Boolean))],
63
78
  limits: l.limits,
79
+ operations: getOperationCapabilities(`source${l.extensions[0]}`),
64
80
  evidence: l.method === "tree-sitter" ? "tests/unit/language-capabilities.test.ts; tests/unit/parser-recovery.test.ts" : "tests/unit/language-capabilities.test.ts",
65
81
  })),
66
82
  } : {
@@ -1,6 +1,8 @@
1
+ import { blankCommentsAndStrings } from "../../boundary-tracker.ts";
1
2
  import { readOptionalSourceFile } from "../../../resources/source-files.ts";
2
3
  import * as fs from "node:fs";
3
4
  import * as path from "node:path";
5
+ import { warnIfUnexpectedParserError } from "../../extractors/manifest-helpers.ts";
4
6
  import type {
5
7
  SchemaFieldSummary,
6
8
  SchemaMetadata,
@@ -27,23 +29,26 @@ export class LaravelMigrationSchemaProvider implements StackSchemaProvider {
27
29
  const tableName = this.resolveTableName(projectRoot, entitySymbol, entityFilePath);
28
30
  if (!tableName) return null;
29
31
 
30
- const migrationFiles = this.findMigrationFilesForTable(migrationsDir, tableName);
32
+ const migrationFiles = this.findMigrationFiles(migrationsDir);
31
33
  if (migrationFiles.length === 0) return null;
32
34
 
33
35
  const fieldsMap = new Map<string, SchemaFieldSummary>();
34
- let primarySourceFile = migrationFiles[0];
36
+ let primarySourceFile: string | undefined;
35
37
 
36
38
  for (const migFile of migrationFiles) {
37
39
  const fullPath = path.join(migrationsDir, migFile);
38
40
  try {
39
41
  const content = readOptionalSourceFile(fullPath, "utf-8");
40
- this.extractColumnsFromMigration(content, tableName, fieldsMap);
42
+ const before = JSON.stringify([...fieldsMap]);
43
+ if (!this.extractColumnsFromMigration(content, tableName, fieldsMap)) return null;
44
+ if (JSON.stringify([...fieldsMap]) !== before) primarySourceFile = migFile;
41
45
  } catch {
42
- // Skip unreadable files
46
+ // An unreadable migration can change the summary; do not certify older fields.
47
+ return null;
43
48
  }
44
49
  }
45
50
 
46
- if (fieldsMap.size === 0) return null;
51
+ if (fieldsMap.size === 0 || !primarySourceFile) return null;
47
52
 
48
53
  const relSourceFile = path.relative(projectRoot, path.join(migrationsDir, primarySourceFile));
49
54
 
@@ -52,6 +57,7 @@ export class LaravelMigrationSchemaProvider implements StackSchemaProvider {
52
57
  tableName,
53
58
  schemaSourceFile: relSourceFile,
54
59
  fields: Array.from(fieldsMap.values()),
60
+ interpretation: "static_migration_summary",
55
61
  };
56
62
  }
57
63
 
@@ -68,11 +74,14 @@ export class LaravelMigrationSchemaProvider implements StackSchemaProvider {
68
74
  if (fs.existsSync(fullEntityPath)) {
69
75
  try {
70
76
  const content = readOptionalSourceFile(fullEntityPath, "utf-8");
71
- const tableMatch = /protected\s+\$table\s*=\s*['"]([^'"]+)['"]/.exec(content);
72
- if (tableMatch) {
73
- return tableMatch[1];
77
+ const mask = blankCommentsAndStrings(content);
78
+ for (const tableMatch of content.matchAll(/protected\s+\$table\s*=\s*['"]([^'"]+)['"]/g)) {
79
+ if (/protected\s+\$table\s*=/.test(mask.slice(tableMatch.index, tableMatch.index + tableMatch[0].length))) return tableMatch[1]!;
74
80
  }
75
- } catch {}
81
+ if (/protected\s+\$table\s*=/.test(mask)) return "";
82
+ } catch (err: unknown) {
83
+ warnIfUnexpectedParserError(`Failed to read entity file ${fullEntityPath}`, err);
84
+ }
76
85
  }
77
86
  }
78
87
 
@@ -97,55 +106,71 @@ export class LaravelMigrationSchemaProvider implements StackSchemaProvider {
97
106
  return `${snake}s`;
98
107
  }
99
108
 
100
- private findMigrationFilesForTable(migrationsDir: string, tableName: string): string[] {
101
- const files = fs.readdirSync(migrationsDir).filter((f) => f.endsWith(".php")).sort();
102
- const matched: string[] = [];
103
-
104
- // Priority 1: *_create_${tableName}_table.php
105
- const createTarget = `_create_${tableName}_table.php`;
106
- for (const f of files) {
107
- if (f.endsWith(createTarget)) {
108
- matched.push(f);
109
- }
110
- }
111
-
112
- // Priority 2: Other migration files altering this table
113
- for (const f of files) {
114
- if (matched.includes(f)) continue;
115
- if (f.includes(`_${tableName}_`)) {
116
- matched.push(f);
117
- }
118
- }
119
-
120
- // If still not found by filename, do a lightweight content search
121
- if (matched.length === 0) {
122
- for (const f of files) {
123
- try {
124
- const content = readOptionalSourceFile(path.join(migrationsDir, f), "utf-8");
125
- if (
126
- content.includes(`Schema::create('${tableName}'`) ||
127
- content.includes(`Schema::create("${tableName}"`) ||
128
- content.includes(`Schema::table('${tableName}'`) ||
129
- content.includes(`Schema::table("${tableName}"`)
130
- ) {
131
- matched.push(f);
132
- }
133
- } catch {}
134
- }
135
- }
136
-
137
- return matched;
109
+ private findMigrationFiles(migrationsDir: string): string[] {
110
+ return fs.readdirSync(migrationsDir).filter(file => file.endsWith(".php")).sort();
138
111
  }
139
112
 
140
113
  private extractColumnsFromMigration(
141
114
  content: string,
142
115
  tableName: string,
143
116
  fieldsMap: Map<string, SchemaFieldSummary>
144
- ): void {
145
- const lines = content.split("\n");
146
-
147
- for (const rawLine of lines) {
117
+ ): boolean {
118
+ const mask = blankCommentsAndStrings(content, { hashComments: true });
119
+ const blockEnd = (start: number) => {
120
+ let depth = 0;
121
+ for (let i = start; i < mask.length; i++) {
122
+ if (mask[i] === "{") depth++;
123
+ if (mask[i] === "}" && --depth === 0) return i;
124
+ }
125
+ return mask.length;
126
+ };
127
+ const up = /function\s+up\s*\([^)]*\)[^{]*\{/.exec(mask);
128
+ if (!up && /function\s+down\s*\(/.test(mask)) return true;
129
+ const start = up ? up.index + up[0].length : 0;
130
+ const end = up ? blockEnd(start - 1) : mask.length;
131
+ const operations = /Schema::(create|table|dropIfExists|drop|rename)\s*\(/g;
132
+ operations.lastIndex = start;
133
+ let operation: RegExpExecArray | null;
134
+ const bodies: string[] = [];
135
+ while ((operation = operations.exec(mask)) && operation.index < end) {
136
+ const argsStart = operations.lastIndex;
137
+ const literal = /^\s*['"]([^'"]+)['"]/.exec(content.slice(argsStart));
138
+ if (!literal) return false; // Dynamic table names cannot yield a reliable static summary.
139
+ if (operation[1] === "rename") {
140
+ const names = /^\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]/.exec(content.slice(argsStart));
141
+ if (!names || names[1] === tableName || names[2] === tableName) return false;
142
+ }
143
+ if (literal[1] !== tableName) continue;
144
+ const kind = operation[1];
145
+ if (["drop", "dropIfExists", "rename"].includes(kind!)) {
146
+ bodies.push("__reset__");
147
+ continue;
148
+ }
149
+ const open = mask.indexOf("{", argsStart);
150
+ const close = open >= 0 ? blockEnd(open) : -1;
151
+ if (open < 0 || close >= end) return false;
152
+ if (kind === "create") bodies.push("__reset__");
153
+ const bodyMask = mask.slice(open + 1, close);
154
+ const body = content.slice(open + 1, close);
155
+ // Copy executable statements only; quoted/comment decoys cannot provide a table call.
156
+ for (const statement of bodyMask.matchAll(/\$table->[^;]+;/g)) {
157
+ bodies.push(body.slice(statement.index!, statement.index! + statement[0].length));
158
+ }
159
+ operations.lastIndex = close + 1;
160
+ }
161
+ for (const rawLine of bodies) {
148
162
  const line = rawLine.trim();
163
+ if (line === "__reset__") { fieldsMap.clear(); continue; }
164
+ const drop = /\$table->dropColumn\s*\(\s*['"]([^'"]+)['"]/.exec(line);
165
+ if (drop) { fieldsMap.delete(drop[1]!); continue; }
166
+ const rename = /\$table->renameColumn\s*\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]/.exec(line);
167
+ if (rename) {
168
+ const field = fieldsMap.get(rename[1]!);
169
+ fieldsMap.delete(rename[1]!);
170
+ if (field) fieldsMap.set(rename[2]!, { ...field, name: rename[2]! });
171
+ continue;
172
+ }
173
+ if (/\$table->(?:dropColumn|renameColumn)\s*\(/.test(line)) return false;
149
174
  if (!line.includes("$table->")) continue;
150
175
 
151
176
  // Special shorthand: $table->id();
@@ -212,5 +237,6 @@ export class LaravelMigrationSchemaProvider implements StackSchemaProvider {
212
237
  });
213
238
  }
214
239
  }
240
+ return true;
215
241
  }
216
242
  }