@dimassetoid/septum-mcp 0.0.0-stage → 0.3.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 (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +142 -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 +133 -0
  7. package/src/cli/commands/hook.ts +205 -0
  8. package/src/cli/commands/init.ts +570 -0
  9. package/src/cli/commands/serve.ts +5 -0
  10. package/src/cli/commands/sync.ts +39 -0
  11. package/src/cli/hook-payload.ts +43 -0
  12. package/src/cli/index.ts +124 -0
  13. package/src/cli/scaffold/harness-config.ts +661 -0
  14. package/src/cli/templates/hooks.ts +110 -0
  15. package/src/cli/templates/rules.ts +35 -0
  16. package/src/cli/templates/skill.ts +55 -0
  17. package/src/cli/ui/prompts.ts +122 -0
  18. package/src/core/boundary/evaluator.ts +426 -0
  19. package/src/core/boundary/staged-auditor.ts +120 -0
  20. package/src/core/config/domain-ownership.ts +45 -0
  21. package/src/core/config/loader.ts +174 -0
  22. package/src/core/config/schema.ts +59 -0
  23. package/src/core/database/client.ts +60 -0
  24. package/src/core/database/repositories/dependency.repository.ts +733 -0
  25. package/src/core/database/repositories/domain.repository.ts +373 -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 +647 -0
  29. package/src/core/database/repository.ts +358 -0
  30. package/src/core/database/schema.ts +123 -0
  31. package/src/core/discovery/navigation.ts +105 -0
  32. package/src/core/discovery/topology-detector.ts +863 -0
  33. package/src/core/ingestion/hasher.ts +5 -0
  34. package/src/core/ingestion/pipeline.ts +590 -0
  35. package/src/core/parser/behavioral-analyzer.ts +123 -0
  36. package/src/core/parser/boundary-tracker.ts +458 -0
  37. package/src/core/parser/extractors/base.ts +71 -0
  38. package/src/core/parser/extractors/blade.ts +159 -0
  39. package/src/core/parser/extractors/csharp.ts +248 -0
  40. package/src/core/parser/extractors/django-semantic.ts +655 -0
  41. package/src/core/parser/extractors/elysia-semantic.ts +517 -0
  42. package/src/core/parser/extractors/express-semantic.ts +429 -0
  43. package/src/core/parser/extractors/fastapi-semantic.ts +702 -0
  44. package/src/core/parser/extractors/fastify-semantic.ts +759 -0
  45. package/src/core/parser/extractors/flask-semantic.ts +482 -0
  46. package/src/core/parser/extractors/frontend.ts +149 -0
  47. package/src/core/parser/extractors/go-semantic.ts +670 -0
  48. package/src/core/parser/extractors/go.ts +491 -0
  49. package/src/core/parser/extractors/hono-semantic.ts +546 -0
  50. package/src/core/parser/extractors/java.ts +227 -0
  51. package/src/core/parser/extractors/laravel-semantic.ts +1150 -0
  52. package/src/core/parser/extractors/mcp-cli-semantic.ts +367 -0
  53. package/src/core/parser/extractors/nestjs-semantic.ts +527 -0
  54. package/src/core/parser/extractors/php.ts +585 -0
  55. package/src/core/parser/extractors/python.ts +503 -0
  56. package/src/core/parser/extractors/registry.ts +99 -0
  57. package/src/core/parser/extractors/ruby.ts +237 -0
  58. package/src/core/parser/extractors/rust.ts +304 -0
  59. package/src/core/parser/extractors/semantic-extractor.interface.ts +24 -0
  60. package/src/core/parser/extractors/symfony-semantic.ts +321 -0
  61. package/src/core/parser/extractors/typescript.ts +839 -0
  62. package/src/core/parser/implementation-fingerprint.ts +97 -0
  63. package/src/core/parser/language-capabilities.ts +87 -0
  64. package/src/core/parser/schema/providers/laravel-migration-provider.ts +239 -0
  65. package/src/core/parser/schema/schema-provider-registry.ts +41 -0
  66. package/src/core/parser/schema/schema-provider.interface.ts +34 -0
  67. package/src/core/parser/semantic-revision.ts +3 -0
  68. package/src/core/parser/static-string.ts +51 -0
  69. package/src/core/parser/tree-sitter.ts +63 -0
  70. package/src/core/parser/wasm-assets.ts +25 -0
  71. package/src/core/parser/wasm-loader.ts +274 -0
  72. package/src/core/resolver/call-graph-tracer.ts +1033 -0
  73. package/src/core/resolver/import-resolver.ts +365 -0
  74. package/src/core/resolver/interpretation-inputs.ts +7 -0
  75. package/src/core/resolver/languages/go.ts +103 -0
  76. package/src/core/resolver/languages/managed.ts +200 -0
  77. package/src/core/resolver/languages/python.ts +115 -0
  78. package/src/core/resolver/languages/ruby.ts +40 -0
  79. package/src/core/resolver/languages/rust.ts +127 -0
  80. package/src/core/resolver/languages/shared.ts +71 -0
  81. package/src/core/resolver/module-resolver.ts +486 -0
  82. package/src/core/resolver/path-resolver.ts +200 -0
  83. package/src/core/resolver/slice-catalog.ts +79 -0
  84. package/src/core/resolver/slice-format.ts +9 -0
  85. package/src/core/resolver/symbol-impact.ts +381 -0
  86. package/src/core/resolver/symbol-locator.ts +276 -0
  87. package/src/core/resolver/symbol-reference.ts +53 -0
  88. package/src/core/resolver/vertical-slice-tracer.ts +344 -0
  89. package/src/core/resources/ignore.ts +144 -0
  90. package/src/core/resources/limits.ts +14 -0
  91. package/src/core/resources/source-files.ts +185 -0
  92. package/src/core/resources/source-inventory.ts +55 -0
  93. package/src/core/resources/work-queue.ts +74 -0
  94. package/src/core/retrieval/context-page.ts +109 -0
  95. package/src/core/retrieval/context.ts +320 -0
  96. package/src/core/retrieval/resolution-warnings.ts +21 -0
  97. package/src/core/retrieval/symbol-evidence.ts +97 -0
  98. package/src/core/retrieval/typescript-references.ts +262 -0
  99. package/src/core/telemetry/telemetry.ts +142 -0
  100. package/src/index.ts +18 -0
  101. package/src/mcp/schemas.ts +746 -0
  102. package/src/mcp/server.ts +600 -0
  103. package/src/mcp/tools/boundary.ts +17 -0
  104. package/src/mcp/tools/check-boundary.ts +382 -0
  105. package/src/mcp/tools/get-domain-catalog.ts +39 -0
  106. package/src/mcp/tools/get-symbol-impact.ts +104 -0
  107. package/src/mcp/tools/get-symbol.ts +399 -0
  108. package/src/mcp/tools/locate-symbol.ts +236 -0
  109. package/src/mcp/tools/map.ts +26 -0
  110. package/src/mcp/tools/register-domain.ts +113 -0
  111. package/src/mcp/tools/slice.ts +16 -0
  112. package/src/mcp/tools/symbol.ts +95 -0
  113. package/src/mcp/tools/trace-vertical-slice.ts +106 -0
  114. package/src/mcp/workspace-manager.ts +170 -0
  115. package/src/mcp/workspace-watcher.ts +202 -0
  116. package/src/types/index.ts +438 -0
  117. package/src/types/wasm.d.ts +4 -0
  118. package/src/utils/version-check.ts +209 -0
  119. package/src/version.ts +1 -0
@@ -0,0 +1,237 @@
1
+ import { getLanguageCapability } from "../language-capabilities.ts";
2
+ import type { ExtractedDependency, ExtractedSymbol, ParsedFileAST, Visibility } from "../../../types/index.ts";
3
+ import { calculateAstControlFlowNesting, getNodeHeader, parseSourceWithTreeSitter } from "../wasm-loader.ts";
4
+ import type { CodeExtractor } from "./base.ts";
5
+ import type Parser from "web-tree-sitter";
6
+
7
+ const RUBY_CONTROL_FLOW_NODES = new Set([
8
+ "if",
9
+ "unless",
10
+ "for",
11
+ "while",
12
+ "until",
13
+ "case",
14
+ ]);
15
+
16
+ const RUBY_FUNCTION_BOUNDARY_NODES = new Set([
17
+ "method",
18
+ "singleton_method",
19
+ ]);
20
+
21
+ export class RubyExtractor implements CodeExtractor {
22
+ public canHandle(filePath: string): boolean {
23
+ return getLanguageCapability(filePath)?.extractor === "ruby";
24
+ }
25
+
26
+ public async extract(filePath: string, content: string): Promise<ParsedFileAST> {
27
+ const astResult = await parseSourceWithTreeSitter("ruby", content, (rootNode) =>
28
+ this.extractFromAst(rootNode, filePath, content),
29
+ () => this.extractFallback(filePath, content)
30
+ );
31
+ if (astResult) {
32
+ return astResult;
33
+ }
34
+
35
+ return { ...this.extractFallback(filePath, content), status: "degraded" };
36
+ }
37
+
38
+ private isExternalRequire(target: string, isRelative: boolean): boolean {
39
+ if (isRelative || target.startsWith("./") || target.startsWith("../")) {
40
+ return false;
41
+ }
42
+ return true;
43
+ }
44
+
45
+ private extractFromAst(
46
+ rootNode: Parser.SyntaxNode,
47
+ filePath: string,
48
+ content: string
49
+ ): ParsedFileAST {
50
+ const symbols: ExtractedSymbol[] = [];
51
+ const dependencies: ExtractedDependency[] = [];
52
+ const lines = content.split("\n");
53
+
54
+ const processBlock = (node: Parser.SyntaxNode, scopeName?: string, visibility: Visibility = "public"): void => {
55
+ let currentVisibility: Visibility = visibility;
56
+
57
+ for (const child of node.namedChildren) {
58
+ // Track visibility modifiers: private, protected, public
59
+ if (child.type === "identifier" || child.type === "call" || child.type === "command") {
60
+ const text = child.text.trim();
61
+ if (text === "private") {
62
+ currentVisibility = "private";
63
+ continue;
64
+ } else if (text === "protected") {
65
+ currentVisibility = "protected";
66
+ continue;
67
+ } else if (text === "public") {
68
+ currentVisibility = "public";
69
+ continue;
70
+ }
71
+
72
+ // Check for require / require_relative calls
73
+ const methodChild = child.childForFieldName("method") ?? child.namedChildren[0];
74
+ const methodName = methodChild?.text;
75
+ if (methodName === "private" || methodName === "protected" || methodName === "public") {
76
+ const args = child.childForFieldName("arguments");
77
+ if (args?.namedChildren.some(c => c.type === "method" || c.type === "singleton_method")) {
78
+ processBlock(args, scopeName, methodName);
79
+ continue;
80
+ }
81
+ }
82
+ if ((methodName === "require" || methodName === "require_relative") && !child.childForFieldName("receiver")) {
83
+ const argsNode = child.childForFieldName("arguments") ?? child.namedChildren[1];
84
+ if (argsNode) {
85
+ const arg = argsNode.namedChildren[0];
86
+ const literal = arg?.type === "string" && !arg.namedChildren.some(c => c.type === "interpolation")
87
+ && !arg.text.includes("\\") && argsNode.namedChildren.length === 1;
88
+ const rawTarget = literal ? arg.text.slice(1, -1) : `dynamic:${child.text}`;
89
+ const isRel = methodName === "require_relative";
90
+ const leaf = rawTarget.split("/").pop() || rawTarget;
91
+
92
+ dependencies.push({
93
+ target: rawTarget,
94
+ statement: child.text.trim(),
95
+ line_number: child.startPosition.row + 1,
96
+ is_external: literal ? this.isExternalRequire(rawTarget, isRel) : false,
97
+ ...(literal ? { imported_symbols: [leaf] } : {}),
98
+ });
99
+ }
100
+ }
101
+ }
102
+
103
+ if (child.type === "class" || child.type === "module") {
104
+ const nameNode =
105
+ child.childForFieldName("name") ??
106
+ child.namedChildren.find((c) => c.type === "constant" || c.type === "scope_resolution");
107
+ if (!nameNode) continue;
108
+
109
+ const baseName = nameNode.text;
110
+ const fullName = scopeName ? `${scopeName}::${baseName}` : baseName;
111
+ const lineStart = child.startPosition.row + 1;
112
+ const lineEnd = Math.max(lineStart, child.endPosition.row + 1);
113
+ const headerLine = getNodeHeader(child);
114
+ const kind = child.type === "class" ? "class" : "interface";
115
+
116
+ symbols.push({
117
+ name: fullName,
118
+ kind,
119
+ signature: headerLine || `${child.type} ${fullName}`,
120
+ visibility: "public",
121
+ line_start: lineStart,
122
+ line_end: lineEnd,
123
+ line_count: Math.max(1, lineEnd - lineStart + 1),
124
+ nesting_depth: 1,
125
+ });
126
+
127
+ const bodyNode =
128
+ child.childForFieldName("body") ??
129
+ child.namedChildren.find((c) => c.type === "body_statement") ??
130
+ child;
131
+ processBlock(bodyNode, fullName);
132
+ continue;
133
+ }
134
+
135
+ if (child.type === "method" || child.type === "singleton_method") {
136
+ const nameNode =
137
+ child.childForFieldName("name") ??
138
+ child.namedChildren.find((c) => c.type === "identifier" || c.type === "constant");
139
+ if (!nameNode) continue;
140
+
141
+ const methodName = nameNode.text;
142
+ const isClassMethod = child.type === "singleton_method";
143
+ const fullName = scopeName
144
+ ? `${scopeName}${isClassMethod ? "." : "#"}${methodName}`
145
+ : methodName;
146
+ const lineStart = child.startPosition.row + 1;
147
+ const lineEnd = Math.max(lineStart, child.endPosition.row + 1);
148
+ const headerLine = getNodeHeader(child);
149
+ const nestingDepth = calculateAstControlFlowNesting(
150
+ child,
151
+ RUBY_CONTROL_FLOW_NODES,
152
+ RUBY_FUNCTION_BOUNDARY_NODES
153
+ );
154
+
155
+ symbols.push({
156
+ name: fullName,
157
+ kind: scopeName ? "method" : "function",
158
+ signature: headerLine || `def ${methodName}`,
159
+ visibility: currentVisibility,
160
+ line_start: lineStart,
161
+ line_end: lineEnd,
162
+ line_count: Math.max(1, lineEnd - lineStart + 1),
163
+ nesting_depth: nestingDepth,
164
+ });
165
+ continue;
166
+ }
167
+ }
168
+ };
169
+
170
+ processBlock(rootNode);
171
+
172
+ return { symbols, dependencies };
173
+ }
174
+
175
+ private extractFallback(filePath: string, content: string): ParsedFileAST {
176
+ const symbols: ExtractedSymbol[] = [];
177
+ const dependencies: ExtractedDependency[] = [];
178
+ const lines = content.split("\n");
179
+
180
+ for (let i = 0; i < lines.length; i++) {
181
+ const line = lines[i];
182
+ const trimmed = line.trim();
183
+ const lineNum = i + 1;
184
+
185
+ if (!trimmed || trimmed.startsWith("#")) continue;
186
+
187
+ const requireMatch = /^(?:require|require_relative)\s+["']([^"']+)["']/.exec(trimmed);
188
+ if (requireMatch) {
189
+ const target = requireMatch[1].trim();
190
+ const isRel = trimmed.startsWith("require_relative");
191
+ const leaf = target.split("/").pop() || target;
192
+ dependencies.push({
193
+ target,
194
+ statement: trimmed,
195
+ line_number: lineNum,
196
+ is_external: this.isExternalRequire(target, isRel),
197
+ imported_symbols: [leaf],
198
+ });
199
+ continue;
200
+ }
201
+
202
+ const classMatch = /^(?:class|module)\s+([a-zA-Z0-9_:]+)/.exec(trimmed);
203
+ if (classMatch) {
204
+ const name = classMatch[1];
205
+ symbols.push({
206
+ name,
207
+ kind: trimmed.startsWith("class") ? "class" : "interface",
208
+ signature: trimmed,
209
+ visibility: "public",
210
+ line_start: lineNum,
211
+ line_end: lineNum, // best effort in fallback
212
+ line_count: 1,
213
+ nesting_depth: 1,
214
+ });
215
+ continue;
216
+ }
217
+
218
+ const defMatch = /^def\s+([a-zA-Z0-9_.:]+)/.exec(trimmed);
219
+ if (defMatch) {
220
+ const name = defMatch[1];
221
+ symbols.push({
222
+ name,
223
+ kind: "method",
224
+ signature: trimmed,
225
+ visibility: "public",
226
+ line_start: lineNum,
227
+ line_end: lineNum,
228
+ line_count: 1,
229
+ nesting_depth: 1,
230
+ });
231
+ continue;
232
+ }
233
+ }
234
+
235
+ return { symbols, dependencies };
236
+ }
237
+ }
@@ -0,0 +1,304 @@
1
+ import { getLanguageCapability } from "../language-capabilities.ts";
2
+ import type { ExtractedDependency, ExtractedSymbol, ParsedFileAST, Visibility } from "../../../types/index.ts";
3
+ import { findBraceBlockEnd } from "../boundary-tracker.ts";
4
+ import { calculateAstControlFlowNesting, getNodeHeader, parseSourceWithTreeSitter } from "../wasm-loader.ts";
5
+ import type { CodeExtractor } from "./base.ts";
6
+ import type Parser from "web-tree-sitter";
7
+
8
+ const RUST_CONTROL_FLOW_NODES = new Set([
9
+ "if_expression",
10
+ "match_expression",
11
+ "for_expression",
12
+ "while_expression",
13
+ "loop_expression",
14
+ ]);
15
+
16
+ const RUST_FUNCTION_BOUNDARY_NODES = new Set([
17
+ "function_item",
18
+ "closure_expression",
19
+ ]);
20
+
21
+ export class RustExtractor implements CodeExtractor {
22
+ public canHandle(filePath: string): boolean {
23
+ return getLanguageCapability(filePath)?.extractor === "rust";
24
+ }
25
+
26
+ public async extract(filePath: string, content: string): Promise<ParsedFileAST> {
27
+ const astResult = await parseSourceWithTreeSitter("rust", content, (rootNode) =>
28
+ this.extractFromAst(rootNode, filePath, content),
29
+ () => this.extractFallback(filePath, content)
30
+ );
31
+ if (astResult) {
32
+ return astResult;
33
+ }
34
+
35
+ return { ...this.extractFallback(filePath, content), status: "degraded" };
36
+ }
37
+
38
+ private isExternalUse(target: string): boolean {
39
+ const trimmed = target.trim();
40
+ if (trimmed.startsWith("crate::") || trimmed.startsWith("super::") || trimmed.startsWith("self::")) {
41
+ return false;
42
+ }
43
+ return true;
44
+ }
45
+
46
+ private extractFromAst(
47
+ rootNode: Parser.SyntaxNode,
48
+ filePath: string,
49
+ content: string
50
+ ): ParsedFileAST {
51
+ const symbols: ExtractedSymbol[] = [];
52
+ const dependencies: ExtractedDependency[] = [];
53
+ const lines = content.split("\n");
54
+
55
+ const getVisibility = (node: Parser.SyntaxNode): Visibility => {
56
+ for (const child of node.namedChildren) {
57
+ if (child.type === "visibility_modifier") {
58
+ return "public";
59
+ }
60
+ }
61
+ return "private";
62
+ };
63
+
64
+ const processItem = (node: Parser.SyntaxNode, scopeName?: string, isMethod = false, inheritedVisibility?: Visibility): void => {
65
+ const qualify = (name: string) => scopeName ? `${scopeName}::${name}` : name;
66
+ if (node.type === "mod_item") {
67
+ const name = node.childForFieldName("name");
68
+ const body = node.childForFieldName("body");
69
+ if (name && body) {
70
+ for (const child of body.namedChildren) processItem(child, qualify(name.text));
71
+ } else if (name) {
72
+ dependencies.push({ target: `mod:${name.text}`, statement: node.text.trim(),
73
+ line_number: node.startPosition.row + 1, is_external: false, imported_symbols: [name.text] });
74
+ }
75
+ return;
76
+ }
77
+ if (node.type === "use_declaration") {
78
+ const argument = node.childForFieldName("argument");
79
+ const addUse = (item: Parser.SyntaxNode, prefix = ""): void => {
80
+ if (item.type === "line_comment" || item.type === "block_comment") return;
81
+ if (item.type === "scoped_use_list") {
82
+ const scope = item.childForFieldName("path")?.text;
83
+ const list = item.childForFieldName("list");
84
+ const nestedPrefix = [prefix, scope].filter(Boolean).join("::");
85
+ if (list) for (const child of list.namedChildren) addUse(child, nestedPrefix);
86
+ return;
87
+ }
88
+ if (item.type === "use_list") {
89
+ for (const child of item.namedChildren) addUse(child, prefix);
90
+ return;
91
+ }
92
+ const alias = item.type === "use_as_clause" ? item.childForFieldName("alias")?.text : undefined;
93
+ const importPath = item.type === "use_as_clause" ? item.childForFieldName("path")?.text : item.text;
94
+ if (!importPath) return;
95
+ const target = importPath === "self" && prefix ? prefix : [prefix, importPath].filter(Boolean).join("::");
96
+ const leaf = target.split("::").pop()!;
97
+ dependencies.push({
98
+ target,
99
+ statement: node.text.trim().replace(/;$/, ""),
100
+ line_number: node.startPosition.row + 1,
101
+ is_external: this.isExternalUse(target),
102
+ imported_symbols: [...new Set([leaf, ...(alias ? [alias] : [])])],
103
+ });
104
+ };
105
+ if (argument) addUse(argument);
106
+ return;
107
+ }
108
+
109
+ if (node.type === "function_item" || node.type === "function_signature_item") {
110
+ const nameNode =
111
+ node.childForFieldName("name") ??
112
+ node.namedChildren.find((c) => c.type === "identifier");
113
+ if (!nameNode) return;
114
+
115
+ const fnName = nameNode.text;
116
+ const lineStart = node.startPosition.row + 1;
117
+ const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
118
+ const headerLine = getNodeHeader(node);
119
+ const nestingDepth = calculateAstControlFlowNesting(
120
+ node,
121
+ RUST_CONTROL_FLOW_NODES,
122
+ RUST_FUNCTION_BOUNDARY_NODES
123
+ );
124
+
125
+ symbols.push({
126
+ name: qualify(fnName),
127
+ kind: isMethod ? "method" : "function",
128
+ signature: headerLine || `fn ${fnName}()`,
129
+ visibility: inheritedVisibility ?? getVisibility(node),
130
+ line_start: lineStart,
131
+ line_end: lineEnd,
132
+ line_count: Math.max(1, lineEnd - lineStart + 1),
133
+ nesting_depth: nestingDepth,
134
+ });
135
+ return;
136
+ }
137
+
138
+ if (node.type === "struct_item") {
139
+ const nameNode =
140
+ node.childForFieldName("name") ??
141
+ node.namedChildren.find((c) => c.type === "type_identifier");
142
+ if (!nameNode) return;
143
+
144
+ const structName = nameNode.text;
145
+ const lineStart = node.startPosition.row + 1;
146
+ const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
147
+ const headerLine = getNodeHeader(node);
148
+
149
+ symbols.push({
150
+ name: qualify(structName),
151
+ kind: "struct",
152
+ signature: headerLine || `struct ${structName}`,
153
+ visibility: getVisibility(node),
154
+ line_start: lineStart,
155
+ line_end: lineEnd,
156
+ line_count: Math.max(1, lineEnd - lineStart + 1),
157
+ nesting_depth: 1,
158
+ });
159
+ return;
160
+ }
161
+
162
+ if (node.type === "enum_item") {
163
+ const nameNode =
164
+ node.childForFieldName("name") ??
165
+ node.namedChildren.find((c) => c.type === "type_identifier");
166
+ if (!nameNode) return;
167
+
168
+ const enumName = nameNode.text;
169
+ const lineStart = node.startPosition.row + 1;
170
+ const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
171
+ const headerLine = getNodeHeader(node);
172
+
173
+ symbols.push({
174
+ name: qualify(enumName),
175
+ kind: "enum",
176
+ signature: headerLine || `enum ${enumName}`,
177
+ visibility: getVisibility(node),
178
+ line_start: lineStart,
179
+ line_end: lineEnd,
180
+ line_count: Math.max(1, lineEnd - lineStart + 1),
181
+ nesting_depth: 1,
182
+ });
183
+ return;
184
+ }
185
+
186
+ if (node.type === "trait_item") {
187
+ const nameNode =
188
+ node.childForFieldName("name") ??
189
+ node.namedChildren.find((c) => c.type === "type_identifier");
190
+ if (!nameNode) return;
191
+
192
+ const traitName = nameNode.text;
193
+ const lineStart = node.startPosition.row + 1;
194
+ const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
195
+ const headerLine = getNodeHeader(node);
196
+
197
+ symbols.push({
198
+ name: qualify(traitName),
199
+ kind: "interface",
200
+ signature: headerLine || `trait ${traitName}`,
201
+ visibility: getVisibility(node),
202
+ line_start: lineStart,
203
+ line_end: lineEnd,
204
+ line_count: Math.max(1, lineEnd - lineStart + 1),
205
+ nesting_depth: 1,
206
+ });
207
+ const body = node.childForFieldName("body");
208
+ if (body) {
209
+ for (const child of body.namedChildren) {
210
+ processItem(child, qualify(traitName), true, getVisibility(node));
211
+ }
212
+ }
213
+ return;
214
+ }
215
+
216
+ if (node.type === "impl_item") {
217
+ const typeNode =
218
+ node.childForFieldName("type") ??
219
+ node.namedChildren.find((c) => c.type === "type_identifier" || c.type === "generic_type");
220
+ const implTarget = typeNode ? typeNode.text : undefined;
221
+
222
+ const bodyNode =
223
+ node.childForFieldName("body") ??
224
+ node.namedChildren.find((c) => c.type === "declaration_list");
225
+ if (bodyNode) {
226
+ for (const item of bodyNode.namedChildren) {
227
+ processItem(item, implTarget ? qualify(implTarget) : scopeName, true);
228
+ }
229
+ }
230
+ return;
231
+ }
232
+ };
233
+
234
+ for (const node of rootNode.namedChildren) {
235
+ processItem(node);
236
+ }
237
+
238
+ return { symbols, dependencies };
239
+ }
240
+
241
+ private extractFallback(filePath: string, content: string): ParsedFileAST {
242
+ const symbols: ExtractedSymbol[] = [];
243
+ const dependencies: ExtractedDependency[] = [];
244
+ const lines = content.split("\n");
245
+
246
+ for (let i = 0; i < lines.length; i++) {
247
+ const line = lines[i];
248
+ const trimmed = line.trim();
249
+ const lineNum = i + 1;
250
+
251
+ if (!trimmed || trimmed.startsWith("//")) continue;
252
+
253
+ const useMatch = /^(?:pub\s+)?use\s+([^;]+);/.exec(trimmed);
254
+ if (useMatch) {
255
+ const target = useMatch[1].trim();
256
+ const leaf = target.split("::").pop()?.replace(/[{}\s]/g, "") || target;
257
+ dependencies.push({
258
+ target,
259
+ statement: trimmed,
260
+ line_number: lineNum,
261
+ is_external: this.isExternalUse(target),
262
+ imported_symbols: [leaf],
263
+ });
264
+ continue;
265
+ }
266
+
267
+ const fnMatch = /^(?:pub(?:\([^)]+\))?\s+)?(?:async\s+)?fn\s+([a-zA-Z0-9_]+)/.exec(trimmed);
268
+ if (fnMatch) {
269
+ const name = fnMatch[1];
270
+ const lineEnd = findBraceBlockEnd(lines, i);
271
+ symbols.push({
272
+ name,
273
+ kind: "function",
274
+ signature: trimmed.replace(/\{$/, "").trim(),
275
+ visibility: trimmed.startsWith("pub") ? "public" : "private",
276
+ line_start: lineNum,
277
+ line_end: lineEnd,
278
+ line_count: Math.max(1, lineEnd - lineNum + 1),
279
+ nesting_depth: 1,
280
+ });
281
+ continue;
282
+ }
283
+
284
+ const structMatch = /^(?:pub(?:\([^)]+\))?\s+)?struct\s+([a-zA-Z0-9_]+)/.exec(trimmed);
285
+ if (structMatch) {
286
+ const name = structMatch[1];
287
+ const lineEnd = trimmed.endsWith(";") ? lineNum : findBraceBlockEnd(lines, i);
288
+ symbols.push({
289
+ name,
290
+ kind: "struct",
291
+ signature: trimmed.replace(/\{$/, "").trim(),
292
+ visibility: trimmed.startsWith("pub") ? "public" : "private",
293
+ line_start: lineNum,
294
+ line_end: lineEnd,
295
+ line_count: Math.max(1, lineEnd - lineNum + 1),
296
+ nesting_depth: 1,
297
+ });
298
+ continue;
299
+ }
300
+ }
301
+
302
+ return { symbols, dependencies };
303
+ }
304
+ }
@@ -0,0 +1,24 @@
1
+ import type { VerticalSliceRecord } from "../../../types/index.ts";
2
+ import type { SourceInventory } from "../../resources/source-inventory.ts";
3
+
4
+ export type VerticalSliceCandidate = Omit<VerticalSliceRecord, "id" | "created_at">;
5
+
6
+ export interface SemanticSliceExtractor {
7
+ readonly id: string;
8
+ readonly name: string;
9
+
10
+ /**
11
+ * Determines if this extractor can handle the project topology.
12
+ */
13
+ canHandle(projectRoot: string, framework?: string): boolean;
14
+
15
+ /**
16
+ * Extracts vertical slices from the codebase.
17
+ */
18
+ extractSlices(
19
+ projectRoot: string,
20
+ domainId?: number,
21
+ signal?: AbortSignal,
22
+ inventory?: SourceInventory
23
+ ): Promise<VerticalSliceCandidate[]> | VerticalSliceCandidate[];
24
+ }