septum 0.1.4 → 0.1.6

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 (70) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +105 -105
  3. package/bin/septum.ts +4 -4
  4. package/package.json +63 -63
  5. package/src/cli/commands/check.ts +161 -161
  6. package/src/cli/commands/hook.ts +216 -188
  7. package/src/cli/commands/ingest.ts +29 -29
  8. package/src/cli/commands/init.ts +213 -211
  9. package/src/cli/commands/locate.ts +61 -61
  10. package/src/cli/commands/query.ts +104 -64
  11. package/src/cli/commands/serve.ts +5 -5
  12. package/src/cli/commands/slice.ts +50 -48
  13. package/src/cli/commands/sync.ts +31 -31
  14. package/src/cli/index.ts +220 -210
  15. package/src/cli/templates/hooks.ts +75 -75
  16. package/src/cli/templates/rules.ts +50 -38
  17. package/src/cli/templates/skill.ts +65 -69
  18. package/src/core/boundary/evaluator.ts +429 -210
  19. package/src/core/config/loader.ts +117 -97
  20. package/src/core/config/schema.ts +39 -39
  21. package/src/core/database/client.ts +44 -44
  22. package/src/core/database/repositories/dependency.repository.ts +552 -349
  23. package/src/core/database/repositories/domain.repository.ts +275 -198
  24. package/src/core/database/repositories/file.repository.ts +117 -106
  25. package/src/core/database/repositories/meta.repository.ts +33 -33
  26. package/src/core/database/repositories/symbol.repository.ts +482 -443
  27. package/src/core/database/repository.ts +281 -260
  28. package/src/core/database/schema.ts +154 -153
  29. package/src/core/discovery/topology-detector.ts +486 -486
  30. package/src/core/ingestion/hasher.ts +5 -5
  31. package/src/core/ingestion/pipeline.ts +606 -535
  32. package/src/core/parser/boundary-tracker.ts +433 -288
  33. package/src/core/parser/extractors/base.ts +62 -62
  34. package/src/core/parser/extractors/blade.ts +158 -158
  35. package/src/core/parser/extractors/frontend.ts +147 -194
  36. package/src/core/parser/extractors/go.ts +408 -180
  37. package/src/core/parser/extractors/laravel-semantic.ts +1045 -901
  38. package/src/core/parser/extractors/mcp-cli-semantic.ts +328 -199
  39. package/src/core/parser/extractors/nestjs-semantic.ts +134 -119
  40. package/src/core/parser/extractors/php.ts +415 -153
  41. package/src/core/parser/extractors/python.ts +460 -228
  42. package/src/core/parser/extractors/registry.ts +70 -70
  43. package/src/core/parser/extractors/semantic-extractor.interface.ts +21 -21
  44. package/src/core/parser/extractors/typescript.ts +668 -181
  45. package/src/core/parser/tree-sitter.ts +41 -41
  46. package/src/core/parser/wasm-loader.ts +271 -0
  47. package/src/core/resolver/call-graph-tracer.ts +698 -668
  48. package/src/core/resolver/module-resolver.ts +479 -342
  49. package/src/core/resolver/path-resolver.ts +147 -147
  50. package/src/core/resolver/symbol-locator.ts +543 -543
  51. package/src/core/resolver/vertical-slice-tracer.ts +323 -285
  52. package/src/core/session/session-manager.ts +56 -56
  53. package/src/core/telemetry/telemetry.ts +86 -86
  54. package/src/core/topology/environment-detector.ts +109 -6
  55. package/src/index.ts +21 -21
  56. package/src/mcp/schemas.ts +695 -286
  57. package/src/mcp/server.ts +927 -716
  58. package/src/mcp/tools/check-boundary.ts +307 -152
  59. package/src/mcp/tools/get-domain-catalog.ts +155 -121
  60. package/src/mcp/tools/get-environment-topology.ts +3 -6
  61. package/src/mcp/tools/get-feature-context.ts +227 -116
  62. package/src/mcp/tools/get-symbol-hotspots.ts +54 -59
  63. package/src/mcp/tools/get-symbol-impact.ts +28 -26
  64. package/src/mcp/tools/get-symbol.ts +65 -63
  65. package/src/mcp/tools/locate-symbol.ts +169 -190
  66. package/src/mcp/tools/register-domain.ts +59 -64
  67. package/src/mcp/tools/register-feature.ts +91 -0
  68. package/src/mcp/tools/trace-vertical-slice.ts +74 -48
  69. package/src/types/index.ts +366 -315
  70. package/src/version.ts +3 -3
@@ -1,194 +1,147 @@
1
- import type {
2
- ExtractedDependency,
3
- ExtractedSymbol,
4
- ParsedFileAST,
5
- } from "../../../types/index.ts";
6
- import type { CodeExtractor } from "./base.ts";
7
-
8
- export class FrontendExtractor implements CodeExtractor {
9
- public canHandle(filePath: string): boolean {
10
- return /\.(vue|astro|svelte)$/i.test(filePath);
11
- }
12
-
13
- public async extract(filePath: string, content: string): Promise<ParsedFileAST> {
14
- const symbols: ExtractedSymbol[] = [];
15
- const dependencies: ExtractedDependency[] = [];
16
-
17
- const isVue = /\.vue$/i.test(filePath);
18
- const isAstro = /\.astro$/i.test(filePath);
19
- const isSvelte = /\.svelte$/i.test(filePath);
20
-
21
- if (isVue) {
22
- this.extractVue(content, symbols, dependencies);
23
- } else if (isAstro) {
24
- this.extractAstro(content, symbols, dependencies);
25
- } else if (isSvelte) {
26
- this.extractSvelte(content, symbols, dependencies);
27
- }
28
-
29
- return { symbols, dependencies };
30
- }
31
-
32
- private extractVue(
33
- content: string,
34
- symbols: ExtractedSymbol[],
35
- dependencies: ExtractedDependency[]
36
- ): void {
37
- // Match <script> and <script setup> blocks
38
- const scriptRegex = /<script(\s+[^>]*?)?>([\s\S]*?)<\/script>/gi;
39
- let match: RegExpExecArray | null;
40
-
41
- while ((match = scriptRegex.exec(content)) !== null) {
42
- const fullMatch = match[0];
43
- const attributes = match[1] || "";
44
- const scriptBody = match[2];
45
- const isSetup = /\bsetup\b/i.test(attributes);
46
-
47
- // Calculate start line of the script body
48
- const beforeMatch = content.slice(0, match.index);
49
- const tagOpenMatch = fullMatch.match(/<script(\s+[^>]*?)?>/i);
50
- const tagOpenLen = tagOpenMatch ? tagOpenMatch[0].length : 0;
51
- const scriptStartOffset = match.index + tagOpenLen;
52
- const startLine = content.slice(0, scriptStartOffset).split("\n").length;
53
-
54
- // Extract symbols and dependencies from this script block
55
- this.extractScriptContent(scriptBody, startLine, symbols, dependencies);
56
-
57
- if (isSetup) {
58
- symbols.push({
59
- name: "<script setup>",
60
- kind: "method",
61
- signature: "script setup",
62
- visibility: "public",
63
- line_start: startLine,
64
- line_end: startLine + scriptBody.split("\n").length,
65
- line_count: scriptBody.split("\n").length,
66
- });
67
- }
68
- }
69
-
70
- // Vue defineProps / defineEmits detection
71
- const definePropsMatch = content.match(/defineProps\s*<([^>]+)>/);
72
- if (definePropsMatch) {
73
- const line = content.slice(0, content.indexOf(definePropsMatch[0])).split("\n").length;
74
- symbols.push({
75
- name: "Props",
76
- kind: "interface",
77
- signature: `defineProps<${definePropsMatch[1]}>`,
78
- visibility: "public",
79
- line_start: line,
80
- line_end: line,
81
- line_count: 1,
82
- });
83
- }
84
- }
85
-
86
- private extractAstro(
87
- content: string,
88
- symbols: ExtractedSymbol[],
89
- dependencies: ExtractedDependency[]
90
- ): void {
91
- // Astro frontmatter is between the first --- and the second ---
92
- const frontmatterMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
93
- if (frontmatterMatch) {
94
- const scriptBody = frontmatterMatch[1];
95
- const startLine = 2; // Line 1 is '---'
96
- this.extractScriptContent(scriptBody, startLine, symbols, dependencies);
97
- }
98
- }
99
-
100
- private extractSvelte(
101
- content: string,
102
- symbols: ExtractedSymbol[],
103
- dependencies: ExtractedDependency[]
104
- ): void {
105
- const scriptRegex = /<script(\s+[^>]*?)?>([\s\S]*?)<\/script>/gi;
106
- let match: RegExpExecArray | null;
107
-
108
- while ((match = scriptRegex.exec(content)) !== null) {
109
- const fullMatch = match[0];
110
- const scriptBody = match[2];
111
- const tagOpenMatch = fullMatch.match(/<script(\s+[^>]*?)?>/i);
112
- const tagOpenLen = tagOpenMatch ? tagOpenMatch[0].length : 0;
113
- const scriptStartOffset = match.index + tagOpenLen;
114
- const startLine = content.slice(0, scriptStartOffset).split("\n").length;
115
-
116
- this.extractScriptContent(scriptBody, startLine, symbols, dependencies);
117
- }
118
- }
119
-
120
- private extractScriptContent(
121
- scriptContent: string,
122
- lineOffset: number,
123
- symbols: ExtractedSymbol[],
124
- dependencies: ExtractedDependency[]
125
- ): void {
126
- const lines = scriptContent.split("\n");
127
-
128
- // 1. Extract Imports
129
- const importRegex = /(?:import\s+(?:(?:[\w*\s{},]+)\s+from\s+)?['"]([^'"]+)['"]|require\s*\(\s*['"]([^'"]+)['"]\s*\))/g;
130
- for (let i = 0; i < lines.length; i++) {
131
- const line = lines[i];
132
- let match: RegExpExecArray | null;
133
- while ((match = importRegex.exec(line)) !== null) {
134
- const target = match[1] || match[2];
135
- if (target) {
136
- const isExternal = !target.startsWith(".") && !target.startsWith("/");
137
- dependencies.push({
138
- target,
139
- statement: line.trim(),
140
- line_number: lineOffset + i,
141
- is_external: isExternal,
142
- });
143
- }
144
- }
145
- }
146
-
147
- // 2. Extract Functions / Methods / Classes / Components
148
- const funcRegex = /(?:export\s+)?(?:default\s+)?(?:async\s+)?function\s+([a-zA-Z0-9_]+)/g;
149
- const constFuncRegex = /(?:export\s+)?const\s+([a-zA-Z0-9_]+)\s*=\s*(?:async\s*)?(?:\([^)]*\)|[a-zA-Z0-9_]+)\s*=>/g;
150
- const classRegex = /(?:export\s+)?class\s+([a-zA-Z0-9_]+)/g;
151
-
152
- for (let i = 0; i < lines.length; i++) {
153
- const line = lines[i];
154
- const currentLineNum = lineOffset + i;
155
-
156
- let m: RegExpExecArray | null;
157
- while ((m = funcRegex.exec(line)) !== null) {
158
- symbols.push({
159
- name: m[1],
160
- kind: "function",
161
- signature: line.trim(),
162
- visibility: line.includes("export") ? "public" : "private",
163
- line_start: currentLineNum,
164
- line_end: currentLineNum,
165
- line_count: 1,
166
- });
167
- }
168
-
169
- while ((m = constFuncRegex.exec(line)) !== null) {
170
- symbols.push({
171
- name: m[1],
172
- kind: "function",
173
- signature: line.trim(),
174
- visibility: line.includes("export") ? "public" : "private",
175
- line_start: currentLineNum,
176
- line_end: currentLineNum,
177
- line_count: 1,
178
- });
179
- }
180
-
181
- while ((m = classRegex.exec(line)) !== null) {
182
- symbols.push({
183
- name: m[1],
184
- kind: "class",
185
- signature: line.trim(),
186
- visibility: line.includes("export") ? "public" : "private",
187
- line_start: currentLineNum,
188
- line_end: currentLineNum,
189
- line_count: 1,
190
- });
191
- }
192
- }
193
- }
194
- }
1
+ import type {
2
+ ExtractedDependency,
3
+ ExtractedSymbol,
4
+ ParsedFileAST,
5
+ } from "../../../types/index.ts";
6
+ import type { CodeExtractor } from "./base.ts";
7
+ import { TypeScriptExtractor } from "./typescript.ts";
8
+
9
+ export class FrontendExtractor implements CodeExtractor {
10
+ private readonly tsExtractor = new TypeScriptExtractor();
11
+
12
+ public canHandle(filePath: string): boolean {
13
+ return /\.(vue|astro|svelte)$/i.test(filePath);
14
+ }
15
+
16
+ public async extract(filePath: string, content: string): Promise<ParsedFileAST> {
17
+ const symbols: ExtractedSymbol[] = [];
18
+ const dependencies: ExtractedDependency[] = [];
19
+
20
+ const isVue = /\.vue$/i.test(filePath);
21
+ const isAstro = /\.astro$/i.test(filePath);
22
+ const isSvelte = /\.svelte$/i.test(filePath);
23
+
24
+ if (isVue) {
25
+ await this.extractVue(content, symbols, dependencies);
26
+ } else if (isAstro) {
27
+ await this.extractAstro(content, symbols, dependencies);
28
+ } else if (isSvelte) {
29
+ await this.extractSvelte(content, symbols, dependencies);
30
+ }
31
+
32
+ return { symbols, dependencies };
33
+ }
34
+
35
+ private async extractVue(
36
+ content: string,
37
+ symbols: ExtractedSymbol[],
38
+ dependencies: ExtractedDependency[]
39
+ ): Promise<void> {
40
+ const scriptRegex = /<script(\s+[^>]*?)?>([\s\S]*?)<\/script>/gi;
41
+ let match: RegExpExecArray | null;
42
+
43
+ while ((match = scriptRegex.exec(content)) !== null) {
44
+ const fullMatch = match[0];
45
+ const attributes = match[1] || "";
46
+ const scriptBody = match[2];
47
+ const isSetup = /\bsetup\b/i.test(attributes);
48
+
49
+ const tagOpenMatch = fullMatch.match(/<script(\s+[^>]*?)?>/i);
50
+ const tagOpenLen = tagOpenMatch ? tagOpenMatch[0].length : 0;
51
+ const scriptStartOffset = match.index + tagOpenLen;
52
+ const startLine = content.slice(0, scriptStartOffset).split("\n").length;
53
+
54
+ await this.extractScriptContent(scriptBody, startLine, symbols, dependencies);
55
+
56
+ if (isSetup) {
57
+ const scriptLines = scriptBody.split("\n").length;
58
+ symbols.push({
59
+ name: "<script setup>",
60
+ kind: "method",
61
+ signature: "script setup",
62
+ visibility: "public",
63
+ line_start: startLine,
64
+ line_end: startLine + scriptLines - 1,
65
+ line_count: Math.max(1, scriptLines),
66
+ });
67
+ }
68
+ }
69
+
70
+ const definePropsMatch = content.match(/defineProps\s*<([^>]+)>/);
71
+ if (definePropsMatch) {
72
+ const line = content.slice(0, content.indexOf(definePropsMatch[0])).split("\n").length;
73
+ const propLines = definePropsMatch[0].split("\n").length;
74
+ symbols.push({
75
+ name: "Props",
76
+ kind: "interface",
77
+ signature: `defineProps<${definePropsMatch[1]}>`,
78
+ visibility: "public",
79
+ line_start: line,
80
+ line_end: line + propLines - 1,
81
+ line_count: Math.max(1, propLines),
82
+ });
83
+ }
84
+ }
85
+
86
+ private async extractAstro(
87
+ content: string,
88
+ symbols: ExtractedSymbol[],
89
+ dependencies: ExtractedDependency[]
90
+ ): Promise<void> {
91
+ const frontmatterMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
92
+ if (frontmatterMatch) {
93
+ const scriptBody = frontmatterMatch[1];
94
+ const startLine = 2;
95
+ await this.extractScriptContent(scriptBody, startLine, symbols, dependencies);
96
+ }
97
+ }
98
+
99
+ private async extractSvelte(
100
+ content: string,
101
+ symbols: ExtractedSymbol[],
102
+ dependencies: ExtractedDependency[]
103
+ ): Promise<void> {
104
+ const scriptRegex = /<script(\s+[^>]*?)?>([\s\S]*?)<\/script>/gi;
105
+ let match: RegExpExecArray | null;
106
+
107
+ while ((match = scriptRegex.exec(content)) !== null) {
108
+ const fullMatch = match[0];
109
+ const scriptBody = match[2];
110
+ const tagOpenMatch = fullMatch.match(/<script(\s+[^>]*?)?>/i);
111
+ const tagOpenLen = tagOpenMatch ? tagOpenMatch[0].length : 0;
112
+ const scriptStartOffset = match.index + tagOpenLen;
113
+ const startLine = content.slice(0, scriptStartOffset).split("\n").length;
114
+
115
+ await this.extractScriptContent(scriptBody, startLine, symbols, dependencies);
116
+ }
117
+ }
118
+
119
+ private async extractScriptContent(
120
+ scriptContent: string,
121
+ startLine: number,
122
+ symbols: ExtractedSymbol[],
123
+ dependencies: ExtractedDependency[]
124
+ ): Promise<void> {
125
+ const parsed = await this.tsExtractor.extract("component-script.ts", scriptContent);
126
+ const delta = Math.max(0, startLine - 1);
127
+
128
+ for (const dep of parsed.dependencies) {
129
+ dependencies.push({
130
+ ...dep,
131
+ line_number: dep.line_number + delta,
132
+ });
133
+ }
134
+
135
+ for (const sym of parsed.symbols) {
136
+ const shiftedStart = sym.line_start + delta;
137
+ const shiftedEnd = Math.max(shiftedStart, sym.line_end + delta);
138
+ symbols.push({
139
+ ...sym,
140
+ line_start: shiftedStart,
141
+ line_end: shiftedEnd,
142
+ line_count: Math.max(1, shiftedEnd - shiftedStart + 1),
143
+ });
144
+ }
145
+ }
146
+ }
147
+