@dimassetoid/septum-mcp 0.3.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +38 -55
  2. package/package.json +7 -5
  3. package/src/cli/commands/check.ts +14 -10
  4. package/src/cli/commands/hook.ts +41 -6
  5. package/src/cli/commands/init.ts +10 -1
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +32 -4
  9. package/src/cli/index.ts +7 -0
  10. package/src/cli/templates/hooks.ts +3 -14
  11. package/src/cli/templates/skill.ts +17 -10
  12. package/src/core/boundary/audit.ts +383 -0
  13. package/src/core/boundary/evaluator.ts +251 -114
  14. package/src/core/boundary/staged-auditor.ts +147 -55
  15. package/src/core/config/domain-ownership.ts +6 -4
  16. package/src/core/config/domain-registration.ts +141 -0
  17. package/src/core/config/loader.ts +1 -25
  18. package/src/core/config/schema.ts +24 -36
  19. package/src/core/database/client.ts +2 -0
  20. package/src/core/database/repositories/dependency.repository.ts +334 -572
  21. package/src/core/database/repositories/domain.repository.ts +2 -1
  22. package/src/core/database/repositories/file.repository.ts +10 -0
  23. package/src/core/database/repositories/symbol.repository.ts +97 -398
  24. package/src/core/database/repository.ts +68 -9
  25. package/src/core/database/schema.ts +26 -0
  26. package/src/core/discovery/declarative-routes.ts +69 -0
  27. package/src/core/discovery/framework-detector.ts +149 -0
  28. package/src/core/discovery/navigation.ts +222 -58
  29. package/src/core/discovery/topology-detector.ts +93 -168
  30. package/src/core/errors.ts +19 -0
  31. package/src/core/ingestion/pipeline.ts +287 -88
  32. package/src/core/parser/extractors/base.ts +11 -3
  33. package/src/core/parser/extractors/csharp.ts +2 -2
  34. package/src/core/parser/extractors/django-routing.ts +163 -0
  35. package/src/core/parser/extractors/django-semantic.ts +397 -481
  36. package/src/core/parser/extractors/elysia-semantic.ts +172 -475
  37. package/src/core/parser/extractors/express-semantic.ts +195 -383
  38. package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
  39. package/src/core/parser/extractors/fastify-semantic.ts +216 -717
  40. package/src/core/parser/extractors/flask-semantic.ts +89 -352
  41. package/src/core/parser/extractors/go-routing.ts +344 -0
  42. package/src/core/parser/extractors/go-semantic.ts +205 -562
  43. package/src/core/parser/extractors/go.ts +6 -3
  44. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  45. package/src/core/parser/extractors/hono-semantic.ts +132 -509
  46. package/src/core/parser/extractors/java.ts +2 -2
  47. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  48. package/src/core/parser/extractors/laravel-semantic.ts +143 -335
  49. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  50. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  51. package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
  52. package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
  53. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  54. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  55. package/src/core/parser/extractors/php.ts +1 -1
  56. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  57. package/src/core/parser/extractors/python.ts +5 -9
  58. package/src/core/parser/extractors/registry.ts +2 -0
  59. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  60. package/src/core/parser/extractors/ruby.ts +2 -2
  61. package/src/core/parser/extractors/rust.ts +4 -4
  62. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  63. package/src/core/parser/extractors/symfony-semantic.ts +72 -226
  64. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  65. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  66. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  67. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  68. package/src/core/parser/extractors/typescript.ts +23 -216
  69. package/src/core/parser/language-capabilities.ts +1 -1
  70. package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
  71. package/src/core/parser/wasm-loader.ts +6 -2
  72. package/src/core/resolver/ast-method-tracer.ts +230 -0
  73. package/src/core/resolver/call-graph-helpers.ts +72 -0
  74. package/src/core/resolver/call-graph-tracer.ts +169 -414
  75. package/src/core/resolver/dependency-analysis.ts +593 -0
  76. package/src/core/resolver/import-candidates.ts +120 -0
  77. package/src/core/resolver/import-evidence.ts +88 -0
  78. package/src/core/resolver/import-resolver.ts +60 -7
  79. package/src/core/resolver/interpretation-inputs.ts +60 -2
  80. package/src/core/resolver/languages/python.ts +31 -13
  81. package/src/core/resolver/languages/shared.ts +4 -1
  82. package/src/core/resolver/module-resolver.ts +10 -3
  83. package/src/core/resolver/path-resolver.ts +6 -3
  84. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  85. package/src/core/resolver/slice-catalog.ts +21 -6
  86. package/src/core/resolver/slice-format.ts +13 -0
  87. package/src/core/resolver/slice-selection.ts +237 -0
  88. package/src/core/resolver/symbol-impact.ts +104 -8
  89. package/src/core/resolver/symbol-locator.ts +82 -15
  90. package/src/core/resolver/vertical-slice-tracer.ts +31 -230
  91. package/src/core/resources/ignore.ts +0 -1
  92. package/src/core/resources/limits.ts +2 -1
  93. package/src/core/resources/work-queue.ts +167 -4
  94. package/src/core/retrieval/context-page.ts +11 -4
  95. package/src/core/retrieval/context.ts +363 -226
  96. package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
  97. package/src/core/retrieval/symbol-details.ts +453 -0
  98. package/src/core/retrieval/symbol-evidence.ts +3 -3
  99. package/src/core/retrieval/typescript-references.ts +38 -7
  100. package/src/core/retrieval/universal-context.ts +182 -0
  101. package/src/core/telemetry/summary.ts +114 -0
  102. package/src/core/telemetry/telemetry.ts +192 -49
  103. package/src/mcp/formatters/compact-text.ts +439 -0
  104. package/src/mcp/resources-and-prompts.ts +255 -0
  105. package/src/mcp/schemas/boundary.ts +145 -0
  106. package/src/mcp/schemas/map.ts +250 -0
  107. package/src/mcp/schemas/shared.ts +52 -0
  108. package/src/mcp/schemas/slice.ts +60 -0
  109. package/src/mcp/schemas/symbol.ts +268 -0
  110. package/src/mcp/schemas.ts +5 -746
  111. package/src/mcp/server.ts +269 -429
  112. package/src/mcp/tool-catalog.ts +331 -0
  113. package/src/mcp/tools/boundary.ts +68 -3
  114. package/src/mcp/tools/map.ts +104 -4
  115. package/src/mcp/tools/slice.ts +101 -3
  116. package/src/mcp/tools/symbol.ts +469 -17
  117. package/src/mcp/ui/app-client.ts +899 -0
  118. package/src/mcp/ui/app.html +478 -0
  119. package/src/mcp/workflow-playbooks.ts +181 -0
  120. package/src/mcp/workspace-boundary.ts +50 -0
  121. package/src/mcp/workspace-manager.ts +88 -15
  122. package/src/mcp/workspace-watcher.ts +30 -11
  123. package/src/types/index.ts +12 -0
  124. package/src/mcp/tools/check-boundary.ts +0 -382
  125. package/src/mcp/tools/get-domain-catalog.ts +0 -39
  126. package/src/mcp/tools/get-symbol-impact.ts +0 -104
  127. package/src/mcp/tools/locate-symbol.ts +0 -236
  128. package/src/mcp/tools/register-domain.ts +0 -113
  129. package/src/mcp/tools/trace-vertical-slice.ts +0 -106
@@ -0,0 +1,380 @@
1
+ import ts from "typescript";
2
+ import type {
3
+ ExtractedDependency,
4
+ ExtractedSymbol,
5
+ ParsedFileAST,
6
+ SymbolKind,
7
+ Visibility,
8
+ } from "../../../types/index.ts";
9
+
10
+ function scriptKindForPath(filePath: string): ts.ScriptKind {
11
+ const lower = filePath.toLowerCase();
12
+ if (lower.endsWith(".tsx")) return ts.ScriptKind.TSX;
13
+ if (lower.endsWith(".jsx") || lower.endsWith(".js")) return ts.ScriptKind.JSX;
14
+ if (lower.endsWith(".mjs") || lower.endsWith(".cjs")) return ts.ScriptKind.JS;
15
+ return ts.ScriptKind.TS;
16
+ }
17
+
18
+ function hasExportModifier(node: ts.Node): boolean {
19
+ const mods = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;
20
+ return Boolean(mods?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword));
21
+ }
22
+
23
+ function memberVisibility(node: ts.Node, name: string): Visibility {
24
+ if (name.startsWith("#")) return "private";
25
+ const mods = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;
26
+ if (mods?.some((m) => m.kind === ts.SyntaxKind.PrivateKeyword)) return "private";
27
+ if (mods?.some((m) => m.kind === ts.SyntaxKind.ProtectedKeyword)) return "protected";
28
+ return "public";
29
+ }
30
+
31
+ function nodeLineRange(source: ts.SourceFile, node: ts.Node): { start: number; end: number; count: number } {
32
+ const start = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
33
+ const end = Math.max(start, source.getLineAndCharacterOfPosition(node.end).line + 1);
34
+ return { start, end, count: Math.max(1, end - start + 1) };
35
+ }
36
+
37
+ function headerText(source: ts.SourceFile, node: ts.Node, body?: ts.Node): string {
38
+ const start = node.getStart(source);
39
+ const end = body ? body.getStart(source) : node.end;
40
+ return source.text.slice(start, end).trim().replace(/;$/, "");
41
+ }
42
+
43
+ function extractBindingNames(name: ts.BindingName): string[] {
44
+ if (ts.isIdentifier(name)) return [name.text];
45
+ const out: string[] = [];
46
+ for (const el of name.elements) {
47
+ if (ts.isBindingElement(el)) {
48
+ out.push(...extractBindingNames(el.name));
49
+ }
50
+ }
51
+ return out;
52
+ }
53
+
54
+ /**
55
+ * Fallback AST extractor backed by the official TypeScript compiler parser.
56
+ * Used when tree-sitter-wasms reports syntax_recovery on valid modern TS/TSX syntax.
57
+ * Returns null if the TypeScript compiler also reports syntactic errors.
58
+ */
59
+ export function extractWithTypeScriptCompiler(filePath: string, content: string): ParsedFileAST | null {
60
+ const source = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, scriptKindForPath(filePath));
61
+ const host: ts.CompilerHost = {
62
+ getSourceFile: (name) => (name === filePath ? source : undefined),
63
+ getDefaultLibFileName: () => "",
64
+ writeFile: () => {},
65
+ getCurrentDirectory: () => "",
66
+ getDirectories: () => [],
67
+ fileExists: (name) => name === filePath,
68
+ readFile: (name) => (name === filePath ? content : undefined),
69
+ getCanonicalFileName: (name) => name,
70
+ useCaseSensitiveFileNames: () => true,
71
+ getNewLine: () => "\n",
72
+ };
73
+ const program = ts.createProgram(
74
+ [filePath],
75
+ { allowJs: true, noLib: true, noResolve: true, jsx: ts.JsxEmit.Preserve },
76
+ host
77
+ );
78
+ if (program.getSyntacticDiagnostics(source).length > 0) {
79
+ return null;
80
+ }
81
+
82
+ const lines = content.split("\n");
83
+ const dependencies: ExtractedDependency[] = [];
84
+ const symbols: ExtractedSymbol[] = [];
85
+
86
+ const collectDependencies = (node: ts.Node): void => {
87
+ if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
88
+ const target = node.moduleSpecifier.text.trim();
89
+ if (target) {
90
+ const imported = new Set<string>();
91
+ const clause = node.importClause;
92
+ if (clause?.name) imported.add(clause.name.text);
93
+ if (clause?.namedBindings) {
94
+ if (ts.isNamespaceImport(clause.namedBindings)) {
95
+ imported.add(clause.namedBindings.name.text);
96
+ } else if (ts.isNamedImports(clause.namedBindings)) {
97
+ for (const el of clause.namedBindings.elements) {
98
+ imported.add((el.propertyName ?? el.name).text);
99
+ imported.add(el.name.text);
100
+ }
101
+ }
102
+ }
103
+ const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
104
+ dependencies.push({
105
+ target,
106
+ statement: (lines[line - 1] ?? node.getText(source)).trim(),
107
+ line_number: line,
108
+ is_external: !target.startsWith(".") && !target.startsWith("/"),
109
+ ...(imported.size > 0 ? { imported_symbols: Array.from(imported) } : {}),
110
+ });
111
+ }
112
+ } else if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
113
+ const target = node.moduleSpecifier.text.trim();
114
+ if (target) {
115
+ const exported = new Set<string>();
116
+ if (node.exportClause) {
117
+ if (ts.isNamespaceExport(node.exportClause)) {
118
+ exported.add(node.exportClause.name.text);
119
+ } else if (ts.isNamedExports(node.exportClause)) {
120
+ for (const el of node.exportClause.elements) {
121
+ exported.add((el.propertyName ?? el.name).text);
122
+ exported.add(el.name.text);
123
+ }
124
+ }
125
+ }
126
+ const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
127
+ dependencies.push({
128
+ target,
129
+ statement: (lines[line - 1] ?? node.getText(source)).trim(),
130
+ line_number: line,
131
+ is_external: !target.startsWith(".") && !target.startsWith("/"),
132
+ ...(exported.size > 0 ? { imported_symbols: Array.from(exported) } : {}),
133
+ });
134
+ }
135
+ } else if (ts.isCallExpression(node)) {
136
+ const isReqOrDynImport =
137
+ (ts.isIdentifier(node.expression) && node.expression.text === "require") ||
138
+ node.expression.kind === ts.SyntaxKind.ImportKeyword;
139
+ if (isReqOrDynImport && node.arguments.length > 0) {
140
+ const arg = node.arguments[0]!;
141
+ const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
142
+ if (ts.isStringLiteralLike(arg) && arg.text.trim()) {
143
+ const target = arg.text.trim();
144
+ dependencies.push({
145
+ target,
146
+ statement: (lines[line - 1] ?? node.getText(source)).trim(),
147
+ line_number: line,
148
+ is_external: !target.startsWith(".") && !target.startsWith("/"),
149
+ });
150
+ } else {
151
+ dependencies.push({
152
+ target: `dynamic:${node.getText(source)}`,
153
+ statement: node.getText(source),
154
+ line_number: line,
155
+ is_external: false,
156
+ });
157
+ }
158
+ }
159
+ }
160
+ ts.forEachChild(node, collectDependencies);
161
+ };
162
+
163
+ const extractClassMembers = (className: string, members: ts.NodeArray<ts.ClassElement | ts.TypeElement>): void => {
164
+ for (const member of members) {
165
+ const range = nodeLineRange(source, member);
166
+ if (ts.isConstructorDeclaration(member)) {
167
+ for (const param of member.parameters) {
168
+ const mods = ts.canHaveModifiers(param) ? ts.getModifiers(param) : undefined;
169
+ if (!mods?.some((m) =>
170
+ m.kind === ts.SyntaxKind.PublicKeyword ||
171
+ m.kind === ts.SyntaxKind.PrivateKeyword ||
172
+ m.kind === ts.SyntaxKind.ProtectedKeyword ||
173
+ m.kind === ts.SyntaxKind.ReadonlyKeyword
174
+ )) {
175
+ continue;
176
+ }
177
+ if (ts.isIdentifier(param.name)) {
178
+ const pName = param.name.text;
179
+ const vis = memberVisibility(param, pName);
180
+ const pRange = nodeLineRange(source, param);
181
+ const typeStr = param.type ? `: ${param.type.getText(source)}` : "";
182
+ symbols.push({
183
+ name: `${className}::${pName}`,
184
+ kind: "property",
185
+ signature: `${vis} ${pName}${typeStr}`,
186
+ visibility: vis,
187
+ line_start: pRange.start,
188
+ line_end: pRange.end,
189
+ line_count: pRange.count,
190
+ });
191
+ }
192
+ }
193
+ const paramsText = `(${member.parameters.map((p) => p.getText(source)).join(", ")})`;
194
+ symbols.push({
195
+ name: `${className}::constructor`,
196
+ kind: "method",
197
+ signature: `public constructor${paramsText}`,
198
+ visibility: "public",
199
+ line_start: range.start,
200
+ line_end: range.end,
201
+ line_count: range.count,
202
+ });
203
+ continue;
204
+ }
205
+
206
+ if (ts.isMethodDeclaration(member) || ts.isMethodSignature(member)) {
207
+ const mName = member.name ? (ts.isIdentifier(member.name) || ts.isStringLiteral(member.name) ? member.name.text : member.name.getText(source)) : undefined;
208
+ if (!mName) continue;
209
+ const vis = memberVisibility(member, mName);
210
+ const paramsText = `(${member.parameters.map((p) => p.getText(source)).join(", ")})`;
211
+ const retText = member.type ? `: ${member.type.getText(source)}` : "";
212
+ symbols.push({
213
+ name: `${className}::${mName}`,
214
+ kind: "method",
215
+ signature: `${vis} ${mName}${paramsText}${retText}`,
216
+ visibility: vis,
217
+ line_start: range.start,
218
+ line_end: range.end,
219
+ line_count: range.count,
220
+ });
221
+ } else if (ts.isPropertyDeclaration(member) || ts.isPropertySignature(member)) {
222
+ const pName = member.name ? (ts.isIdentifier(member.name) || ts.isStringLiteral(member.name) ? member.name.text : member.name.getText(source)) : undefined;
223
+ if (!pName) continue;
224
+ const vis = memberVisibility(member, pName);
225
+ const typeStr = member.type ? `: ${member.type.getText(source)}` : "";
226
+ symbols.push({
227
+ name: `${className}::${pName}`,
228
+ kind: "property",
229
+ signature: `${vis} ${pName}${typeStr}`,
230
+ visibility: vis,
231
+ line_start: range.start,
232
+ line_end: range.end,
233
+ line_count: range.count,
234
+ });
235
+ }
236
+ }
237
+ };
238
+
239
+ const processStatement = (stmt: ts.Statement, namespacePrefix = ""): void => {
240
+ const range = nodeLineRange(source, stmt);
241
+ const prefix = (name: string) => (namespacePrefix ? `${namespacePrefix}::${name}` : name);
242
+
243
+ if (ts.isModuleDeclaration(stmt) && ts.isIdentifier(stmt.name) && stmt.body && ts.isModuleBlock(stmt.body)) {
244
+ const nextPrefix = prefix(stmt.name.text);
245
+ for (const child of stmt.body.statements) {
246
+ processStatement(child, nextPrefix);
247
+ }
248
+ return;
249
+ }
250
+
251
+ if (ts.isExportDeclaration(stmt) && !stmt.moduleSpecifier && stmt.exportClause && ts.isNamedExports(stmt.exportClause)) {
252
+ for (const el of stmt.exportClause.elements) {
253
+ if (el.propertyName) {
254
+ symbols.push({
255
+ name: prefix(el.name.text),
256
+ kind: "constant",
257
+ signature: `export { ${el.propertyName.text} as ${el.name.text} }`,
258
+ visibility: "public",
259
+ line_start: range.start,
260
+ line_end: range.end,
261
+ line_count: range.count,
262
+ });
263
+ }
264
+ }
265
+ return;
266
+ }
267
+
268
+ if (ts.isClassDeclaration(stmt) || ts.isInterfaceDeclaration(stmt)) {
269
+ const name = stmt.name?.text;
270
+ if (!name) return;
271
+ const fullName = prefix(name);
272
+ const kind: SymbolKind = ts.isInterfaceDeclaration(stmt) ? "interface" : "class";
273
+ const braceOpen = stmt.members.pos > 0 ? stmt.members[0] : undefined;
274
+ symbols.push({
275
+ name: fullName,
276
+ kind,
277
+ signature: headerText(source, stmt, braceOpen),
278
+ visibility: "public",
279
+ line_start: range.start,
280
+ line_end: range.end,
281
+ line_count: range.count,
282
+ });
283
+ extractClassMembers(fullName, stmt.members);
284
+ return;
285
+ }
286
+
287
+ if (ts.isTypeAliasDeclaration(stmt) || ts.isEnumDeclaration(stmt)) {
288
+ const name = stmt.name.text;
289
+ symbols.push({
290
+ name: prefix(name),
291
+ kind: ts.isEnumDeclaration(stmt) ? "enum" : "type",
292
+ signature: headerText(source, stmt),
293
+ visibility: "public",
294
+ line_start: range.start,
295
+ line_end: range.end,
296
+ line_count: range.count,
297
+ });
298
+ return;
299
+ }
300
+
301
+ if (ts.isFunctionDeclaration(stmt) && stmt.name) {
302
+ const fnName = stmt.name.text;
303
+ const paramsText = `(${stmt.parameters.map((p) => p.getText(source)).join(", ")})`;
304
+ const retText = stmt.type ? `: ${stmt.type.getText(source)}` : "";
305
+ symbols.push({
306
+ name: prefix(fnName),
307
+ kind: "function",
308
+ signature: `${fnName}${paramsText}${retText}`,
309
+ visibility: "public",
310
+ line_start: range.start,
311
+ line_end: range.end,
312
+ line_count: range.count,
313
+ });
314
+ return;
315
+ }
316
+
317
+ if (ts.isVariableStatement(stmt)) {
318
+ const isExported = hasExportModifier(stmt);
319
+ const isConst = Boolean(stmt.declarationList.flags & ts.NodeFlags.Const);
320
+ const declKeyword = isConst ? "const" : stmt.declarationList.flags & ts.NodeFlags.Let ? "let" : "var";
321
+ for (const decl of stmt.declarationList.declarations) {
322
+ const dRange = nodeLineRange(source, decl);
323
+ const startLine = stmt.declarationList.declarations.length === 1 ? range.start : dRange.start;
324
+ if (!ts.isIdentifier(decl.name)) {
325
+ for (const vName of extractBindingNames(decl.name)) {
326
+ symbols.push({
327
+ name: prefix(vName),
328
+ kind: isConst ? "constant" : "variable",
329
+ signature: `${declKeyword} ${vName}`,
330
+ visibility: isExported ? "public" : "private",
331
+ line_start: range.start,
332
+ line_end: dRange.end,
333
+ line_count: Math.max(1, dRange.end - range.start + 1),
334
+ });
335
+ }
336
+ continue;
337
+ }
338
+ const varName = decl.name.text;
339
+ const typeStr = decl.type ? `: ${decl.type.getText(source)}` : "";
340
+ if (decl.initializer && (ts.isArrowFunction(decl.initializer) || ts.isFunctionExpression(decl.initializer))) {
341
+ const fn = decl.initializer;
342
+ const paramsText = `(${fn.parameters.map((p) => p.getText(source)).join(", ")})`;
343
+ const retText = fn.type ? `: ${fn.type.getText(source)}` : typeStr;
344
+ symbols.push({
345
+ name: prefix(varName),
346
+ kind: "function",
347
+ signature: `${varName}${paramsText}${retText}`,
348
+ visibility: isExported ? "public" : "private",
349
+ line_start: Math.min(range.start, startLine),
350
+ line_end: dRange.end,
351
+ line_count: Math.max(1, dRange.end - Math.min(range.start, startLine) + 1),
352
+ });
353
+ } else {
354
+ symbols.push({
355
+ name: prefix(varName),
356
+ kind: isConst ? "constant" : "variable",
357
+ signature: `${declKeyword} ${varName}${typeStr}`,
358
+ visibility: isExported ? "public" : "private",
359
+ line_start: Math.min(range.start, startLine),
360
+ line_end: dRange.end,
361
+ line_count: Math.max(1, dRange.end - Math.min(range.start, startLine) + 1),
362
+ });
363
+ }
364
+ }
365
+ }
366
+ };
367
+
368
+ collectDependencies(source);
369
+ for (const stmt of source.statements) {
370
+ processStatement(stmt);
371
+ }
372
+
373
+ return {
374
+ status: "parsed",
375
+ extraction: { method: "fallback", coverage: "partial" },
376
+ diagnostics: [],
377
+ symbols,
378
+ dependencies,
379
+ };
380
+ }
@@ -0,0 +1,207 @@
1
+ import type { ExtractedDependency, ExtractedSymbol, ParsedFileAST, Visibility } from "../../../types/index.ts";
2
+ import { blankCommentsAndStrings, calculateControlFlowNesting, findBraceBlockEnd } from "../boundary-tracker.ts";
3
+
4
+ export function extractTypeScriptFallback(content: string): ParsedFileAST {
5
+ const symbols: ExtractedSymbol[] = [];
6
+ const dependencies: ExtractedDependency[] = [];
7
+
8
+ const rawLines = content.split("\n");
9
+ const cleanContent = blankCommentsAndStrings(content);
10
+ const cleanLines = cleanContent.split("\n");
11
+
12
+ const importRegex =
13
+ /^\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*\))/;
14
+
15
+ for (let i = 0; i < rawLines.length; i++) {
16
+ if (!cleanLines[i]?.trim()) continue;
17
+ const line = rawLines[i];
18
+ const match = importRegex.exec(line);
19
+ if (match) {
20
+ const target = match[2] || match[4] || match[5];
21
+ const clause = match[1] || match[3] || "";
22
+ if (target) {
23
+ const importedSymbols = clause
24
+ .replace(/[{}*]/g, " ")
25
+ .split(/,|\bas\b/)
26
+ .map((s) => s.trim())
27
+ .filter((s) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(s) && s !== "type");
28
+ const isExternal = !target.startsWith(".") && !target.startsWith("/");
29
+ dependencies.push({
30
+ target,
31
+ statement: line.trim(),
32
+ line_number: i + 1,
33
+ is_external: isExternal,
34
+ ...(importedSymbols.length > 0 ? { imported_symbols: Array.from(new Set(importedSymbols)) } : {}),
35
+ });
36
+ }
37
+ }
38
+ }
39
+
40
+ let currentClass: string | null = null;
41
+ let currentClassDepth = 0;
42
+ let braceDepth = 0;
43
+
44
+ for (let i = 0; i < cleanLines.length; i++) {
45
+ const cleanTrimmed = cleanLines[i].trim();
46
+ const rawTrimmed = rawLines[i].trim();
47
+ const lineNum = i + 1;
48
+
49
+ if (currentClass && braceDepth < currentClassDepth) {
50
+ currentClass = null;
51
+ currentClassDepth = 0;
52
+ }
53
+
54
+ if (cleanTrimmed && braceDepth === 0) {
55
+ const classMatch =
56
+ /^(?:export\s+)?(?:default\s+)?(?:abstract\s+)?\b(class|interface)\s+([A-Za-z_$][A-Za-z0-9_$]*)\b/.exec(
57
+ cleanTrimmed
58
+ );
59
+ if (classMatch) {
60
+ currentClass = classMatch[2];
61
+ currentClassDepth = braceDepth + 1;
62
+ const endLine = findBraceBlockEnd(cleanLines, i);
63
+ symbols.push({
64
+ name: classMatch[2],
65
+ kind: classMatch[1] as "class" | "interface",
66
+ signature: rawTrimmed.replace(/\{$/, "").trim(),
67
+ visibility: "public",
68
+ line_start: lineNum,
69
+ line_end: endLine,
70
+ line_count: Math.max(1, endLine - lineNum + 1),
71
+ });
72
+ } else {
73
+ const typeMatch = /^(?:export\s+)?\btype\s+([A-Za-z_$][A-Za-z0-9_$]*)\b\s*=/.exec(cleanTrimmed);
74
+ if (typeMatch) {
75
+ const endLine = cleanTrimmed.endsWith(";") ? lineNum : findBraceBlockEnd(cleanLines, i);
76
+ symbols.push({
77
+ name: typeMatch[1],
78
+ kind: "type",
79
+ signature: rawTrimmed.replace(/;$/, "").trim(),
80
+ visibility: "public",
81
+ line_start: lineNum,
82
+ line_end: endLine,
83
+ line_count: Math.max(1, endLine - lineNum + 1),
84
+ });
85
+ }
86
+
87
+ const enumMatch = /^(?:export\s+)?(?:const\s+)?\benum\s+([A-Za-z_$][A-Za-z0-9_$]*)\b/.exec(cleanTrimmed);
88
+ if (enumMatch) {
89
+ const endLine = findBraceBlockEnd(cleanLines, i);
90
+ symbols.push({
91
+ name: enumMatch[1],
92
+ kind: "enum",
93
+ signature: rawTrimmed.replace(/\{$/, "").trim(),
94
+ visibility: "public",
95
+ line_start: lineNum,
96
+ line_end: endLine,
97
+ line_count: Math.max(1, endLine - lineNum + 1),
98
+ });
99
+ }
100
+
101
+ const fnMatch =
102
+ /^(?:export\s+)?(?:default\s+)?(?:async\s+)?\bfunction\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(
103
+ cleanTrimmed
104
+ );
105
+ if (fnMatch) {
106
+ const name = fnMatch[1];
107
+ const params = fnMatch[2];
108
+ const retType = fnMatch[3] ? `: ${fnMatch[3].trim()}` : "";
109
+ const endLine = findBraceBlockEnd(cleanLines, i);
110
+ const nestingDepth = calculateControlFlowNesting(rawLines, i, endLine - 1);
111
+ symbols.push({
112
+ name,
113
+ kind: "function",
114
+ signature: `${name}(${params})${retType}`,
115
+ visibility: "public",
116
+ line_start: lineNum,
117
+ line_end: endLine,
118
+ line_count: Math.max(1, endLine - lineNum + 1),
119
+ nesting_depth: nestingDepth,
120
+ });
121
+ }
122
+
123
+ const varMatch =
124
+ /^(?:export\s+)?\b(const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*(?::\s*([^=;]+))?\s*=\s*(.*)$/.exec(
125
+ cleanTrimmed
126
+ );
127
+ if (varMatch) {
128
+ const declKind = varMatch[1];
129
+ const varName = varMatch[2];
130
+ const typeStr = varMatch[3] ? `: ${varMatch[3].trim()}` : "";
131
+ const rhs = varMatch[4].trim();
132
+ const isArrowOrFn = /^(?:async\s+)?(?:\([^)]*\)|[A-Za-z_$][A-Za-z0-9_$]*)\s*=>|^function\b/.test(rhs);
133
+ symbols.push({
134
+ name: varName,
135
+ kind: isArrowOrFn ? "function" : declKind === "const" ? "constant" : "variable",
136
+ signature: `${declKind} ${varName}${typeStr}`,
137
+ visibility: cleanTrimmed.startsWith("export ") ? "public" : "private",
138
+ line_start: lineNum,
139
+ line_end: lineNum,
140
+ line_count: 1,
141
+ });
142
+ }
143
+ }
144
+ } else if (cleanTrimmed && currentClass && braceDepth === currentClassDepth) {
145
+ const methodMatch =
146
+ /^(?:(public|protected|private)\s+)?(?:static\s+)?(?:readonly\s+)?(?:async\s+)?\b([A-Za-z_$][A-Za-z0-9_$]*)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(
147
+ cleanTrimmed
148
+ );
149
+ if (
150
+ methodMatch &&
151
+ !["if", "for", "while", "switch", "catch", "function", "return"].includes(methodMatch[2])
152
+ ) {
153
+ const vis = (methodMatch[1] as Visibility) || "public";
154
+ const name = methodMatch[2];
155
+ const params = methodMatch[3];
156
+ const retType = methodMatch[4] ? `: ${methodMatch[4].trim()}` : "";
157
+ const endLine = findBraceBlockEnd(cleanLines, i);
158
+ const nestingDepth = calculateControlFlowNesting(rawLines, i, endLine - 1);
159
+ symbols.push({
160
+ name: `${currentClass}::${name}`,
161
+ kind: "method",
162
+ signature: `${vis} ${name}(${params})${retType}`,
163
+ visibility: vis,
164
+ line_start: lineNum,
165
+ line_end: endLine,
166
+ line_count: Math.max(1, endLine - lineNum + 1),
167
+ nesting_depth: nestingDepth,
168
+ });
169
+ } else {
170
+ const propMatch =
171
+ /^(?:(public|protected|private)\s+)?(?:static\s+)?(?:readonly\s+)?\b([A-Za-z_$][A-Za-z0-9_$]*)\s*(?:\?|\!)?\s*(?::\s*([^;={]+))?(?:\s*=[^;]+)?;\s*$/.exec(
172
+ cleanTrimmed
173
+ );
174
+ if (
175
+ propMatch &&
176
+ !["return", "const", "let", "var", "throw", "import", "export", "continue", "break"].includes(
177
+ propMatch[2]
178
+ )
179
+ ) {
180
+ const vis = (propMatch[1] as Visibility) || "public";
181
+ const propName = propMatch[2];
182
+ const typeStr = propMatch[3] ? `: ${propMatch[3].trim()}` : "";
183
+ symbols.push({
184
+ name: `${currentClass}::${propName}`,
185
+ kind: "property",
186
+ signature: `${vis} ${propName}${typeStr}`,
187
+ visibility: vis,
188
+ line_start: lineNum,
189
+ line_end: lineNum,
190
+ line_count: 1,
191
+ });
192
+ }
193
+ }
194
+ }
195
+
196
+ for (const ch of cleanLines[i]) {
197
+ if (ch === "{") braceDepth++;
198
+ else if (ch === "}") braceDepth = Math.max(0, braceDepth - 1);
199
+ }
200
+ if (currentClass && braceDepth < currentClassDepth) {
201
+ currentClass = null;
202
+ currentClassDepth = 0;
203
+ }
204
+ }
205
+
206
+ return { symbols, dependencies };
207
+ }
@@ -0,0 +1,58 @@
1
+ import ts from "typescript";
2
+ import type { ExecutionChainNode } from "../../../types/index.ts";
3
+ import { lineOf, nameText, nodes, TypeScriptBindings, type Handler } from "./typescript-bindings.ts";
4
+
5
+ /** Selected handler-local service and persistence hints for Hono and Elysia. */
6
+ export function routeContext(
7
+ handler: Handler,
8
+ bindings: TypeScriptBindings,
9
+ fileOf: (node: ts.Node) => string,
10
+ ): ExecutionChainNode[] {
11
+ const calls = (body?: ts.Node): ts.CallExpression[] => {
12
+ if (!body) return [];
13
+ return [body, ...nodes(body, true)].filter(ts.isCallExpression);
14
+ };
15
+ const context: ExecutionChainNode[] = [];
16
+ const handlerCalls = calls(handler.node.body);
17
+ let serviceCalls: ts.CallExpression[] = [];
18
+ const serviceCall = handlerCalls.find(call =>
19
+ ts.isPropertyAccessExpression(call.expression) && ts.isIdentifier(call.expression.expression) &&
20
+ /(?:service|usecase)$/i.test(call.expression.expression.text),
21
+ );
22
+ if (serviceCall && ts.isPropertyAccessExpression(serviceCall.expression)) {
23
+ const receiver = serviceCall.expression.expression;
24
+ const method = serviceCall.expression.name.text;
25
+ const symbol = receiver.getText() + "::" + method;
26
+ const definition = bindings.definition(receiver);
27
+ const member = definition && ts.isClassLike(definition) ? definition.members.find(candidate =>
28
+ ts.isMethodDeclaration(candidate) && nameText(candidate.name) === method,
29
+ ) : undefined;
30
+ const location = member ?? serviceCall;
31
+ context.push({
32
+ stage: "service", symbol, file: fileOf(location), line: lineOf(location),
33
+ description: "Service call by receiver naming pattern",
34
+ });
35
+ if (member && ts.isMethodDeclaration(member)) serviceCalls = calls(member.body);
36
+ }
37
+
38
+ for (const call of [...handlerCalls, ...serviceCalls]) {
39
+ const callee = call.expression;
40
+ if (!ts.isPropertyAccessExpression(callee)) continue;
41
+ const owner = callee.expression;
42
+ const prisma = ts.isPropertyAccessExpression(owner) && ts.isIdentifier(owner.expression) &&
43
+ owner.expression.text === "prisma" && /^(find|create|update|delete|upsert)/.test(callee.name.text);
44
+ const drizzle = ts.isIdentifier(owner) && owner.text === "db" && /^(insert|select|update|delete)$/.test(callee.name.text);
45
+ const argument = call.arguments[0];
46
+ const entityName = prisma ? owner.name.text : drizzle && argument && ts.isIdentifier(argument) ? argument.text : undefined;
47
+ if (!entityName) continue;
48
+ const symbol = entityName[0]!.toUpperCase() + entityName.slice(1);
49
+ context.push({
50
+ stage: "repository", symbol: symbol + "Repository", file: fileOf(call), line: lineOf(call),
51
+ description: prisma ? "Prisma query naming pattern" : "Drizzle query naming pattern",
52
+ }, {
53
+ stage: "entity", symbol, file: fileOf(call), line: lineOf(call), description: "Entity inferred from query naming",
54
+ });
55
+ break;
56
+ }
57
+ return context;
58
+ }