septum 0.1.3 → 0.1.5

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 (74) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +105 -102
  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 +188 -188
  7. package/src/cli/commands/ingest.ts +29 -29
  8. package/src/cli/commands/init.ts +211 -211
  9. package/src/cli/commands/locate.ts +61 -61
  10. package/src/cli/commands/query.ts +64 -64
  11. package/src/cli/commands/serve.ts +5 -5
  12. package/src/cli/commands/slice.ts +48 -90
  13. package/src/cli/commands/sync.ts +31 -31
  14. package/src/cli/commands/topology.ts +119 -0
  15. package/src/cli/index.ts +210 -199
  16. package/src/cli/templates/hooks.ts +75 -75
  17. package/src/cli/templates/rules.ts +38 -38
  18. package/src/cli/templates/skill.ts +69 -69
  19. package/src/core/boundary/evaluator.ts +232 -210
  20. package/src/core/config/loader.ts +97 -97
  21. package/src/core/config/schema.ts +39 -39
  22. package/src/core/database/client.ts +44 -44
  23. package/src/core/database/repositories/dependency.repository.ts +366 -349
  24. package/src/core/database/repositories/domain.repository.ts +218 -198
  25. package/src/core/database/repositories/environment.repository.ts +207 -0
  26. package/src/core/database/repositories/file.repository.ts +116 -106
  27. package/src/core/database/repositories/meta.repository.ts +33 -33
  28. package/src/core/database/repositories/symbol.repository.ts +443 -424
  29. package/src/core/database/repository.ts +264 -255
  30. package/src/core/database/schema.ts +34 -1
  31. package/src/core/discovery/topology-detector.ts +486 -486
  32. package/src/core/ingestion/hasher.ts +5 -5
  33. package/src/core/ingestion/pipeline.ts +584 -535
  34. package/src/core/parser/behavioral-analyzer.ts +119 -0
  35. package/src/core/parser/boundary-tracker.ts +288 -128
  36. package/src/core/parser/extractors/base.ts +62 -61
  37. package/src/core/parser/extractors/frontend.ts +194 -194
  38. package/src/core/parser/extractors/go.ts +229 -176
  39. package/src/core/parser/extractors/laravel-semantic.ts +1039 -585
  40. package/src/core/parser/extractors/mcp-cli-semantic.ts +199 -199
  41. package/src/core/parser/extractors/nestjs-semantic.ts +119 -119
  42. package/src/core/parser/extractors/php.ts +153 -149
  43. package/src/core/parser/extractors/python.ts +228 -226
  44. package/src/core/parser/extractors/registry.ts +70 -70
  45. package/src/core/parser/extractors/semantic-extractor.interface.ts +21 -21
  46. package/src/core/parser/extractors/typescript.ts +181 -177
  47. package/src/core/parser/schema/providers/laravel-migration-provider.ts +215 -0
  48. package/src/core/parser/schema/providers/prisma-schema-provider.ts +89 -0
  49. package/src/core/parser/schema/schema-provider-registry.ts +43 -0
  50. package/src/core/parser/schema/schema-provider.interface.ts +33 -0
  51. package/src/core/parser/tree-sitter.ts +41 -41
  52. package/src/core/resolver/call-graph-tracer.ts +666 -668
  53. package/src/core/resolver/module-resolver.ts +408 -342
  54. package/src/core/resolver/symbol-locator.ts +543 -543
  55. package/src/core/resolver/vertical-slice-tracer.ts +301 -252
  56. package/src/core/session/session-manager.ts +56 -56
  57. package/src/core/telemetry/telemetry.ts +86 -86
  58. package/src/core/topology/environment-detector.ts +860 -0
  59. package/src/core/topology/types.ts +83 -0
  60. package/src/index.ts +21 -18
  61. package/src/mcp/schemas.ts +578 -238
  62. package/src/mcp/server.ts +875 -656
  63. package/src/mcp/tools/check-boundary.ts +171 -152
  64. package/src/mcp/tools/get-domain-catalog.ts +145 -121
  65. package/src/mcp/tools/get-environment-topology.ts +141 -0
  66. package/src/mcp/tools/get-feature-context.ts +212 -116
  67. package/src/mcp/tools/get-symbol-hotspots.ts +60 -49
  68. package/src/mcp/tools/get-symbol-impact.ts +28 -26
  69. package/src/mcp/tools/get-symbol.ts +65 -63
  70. package/src/mcp/tools/locate-symbol.ts +171 -190
  71. package/src/mcp/tools/register-domain.ts +68 -64
  72. package/src/mcp/tools/register-feature.ts +100 -0
  73. package/src/mcp/tools/trace-vertical-slice.ts +74 -103
  74. package/src/types/index.ts +335 -299
@@ -1,176 +1,229 @@
1
- import type { ExtractedDependency, ExtractedSymbol, ParsedFileAST, Visibility } from "../../../types/index.ts";
2
- import { findBraceBlockEnd } from "../boundary-tracker.ts";
3
- import type { CodeExtractor } from "./base.ts";
4
-
5
- const GO_STDLIB_PREFIXES = new Set([
6
- "bufio",
7
- "bytes",
8
- "context",
9
- "crypto",
10
- "database",
11
- "encoding",
12
- "errors",
13
- "flag",
14
- "fmt",
15
- "html",
16
- "image",
17
- "io",
18
- "log",
19
- "math",
20
- "mime",
21
- "net",
22
- "os",
23
- "path",
24
- "plugin",
25
- "reflect",
26
- "regexp",
27
- "runtime",
28
- "sort",
29
- "strconv",
30
- "strings",
31
- "sync",
32
- "syscall",
33
- "testing",
34
- "text",
35
- "time",
36
- "unicode",
37
- "unsafe",
38
- ]);
39
-
40
- export class GoExtractor implements CodeExtractor {
41
- public canHandle(filePath: string): boolean {
42
- return /\.go$/i.test(filePath);
43
- }
44
-
45
- public async extract(filePath: string, content: string): Promise<ParsedFileAST> {
46
- const symbols: ExtractedSymbol[] = [];
47
- const dependencies: ExtractedDependency[] = [];
48
-
49
- const lines = content.split("\n");
50
-
51
- // 1. Extract Go Imports
52
- let inImportBlock = false;
53
-
54
- for (let i = 0; i < lines.length; i++) {
55
- const line = lines[i];
56
- const trimmed = line.trim();
57
- const lineNum = i + 1;
58
-
59
- if (trimmed.startsWith("//")) continue;
60
-
61
- if (trimmed === "import (") {
62
- inImportBlock = true;
63
- continue;
64
- }
65
-
66
- if (inImportBlock) {
67
- if (trimmed === ")") {
68
- inImportBlock = false;
69
- continue;
70
- }
71
-
72
- const blockMatch = /^(?:[\w.]+\s+)?["']([^"']+)["']/.exec(trimmed);
73
- if (blockMatch) {
74
- const importPath = blockMatch[1];
75
- const isExternal = this.isGoStdlib(importPath);
76
- dependencies.push({
77
- target: importPath,
78
- statement: trimmed,
79
- line_number: lineNum,
80
- is_external: isExternal,
81
- });
82
- }
83
- continue;
84
- }
85
-
86
- // Single line import: import "fmt" or import alias "pkg"
87
- const singleMatch = /^import\s+(?:[\w.]+\s+)?["']([^"']+)["']/.exec(trimmed);
88
- if (singleMatch) {
89
- const importPath = singleMatch[1];
90
- const isExternal = this.isGoStdlib(importPath);
91
- dependencies.push({
92
- target: importPath,
93
- statement: trimmed,
94
- line_number: lineNum,
95
- is_external: isExternal,
96
- });
97
- }
98
- }
99
-
100
- // 2. Extract Go Types, Structs, Interfaces, and Functions
101
- for (let i = 0; i < lines.length; i++) {
102
- const line = lines[i];
103
- const trimmed = line.trim();
104
- const lineNum = i + 1;
105
-
106
- if (trimmed.startsWith("//")) continue;
107
-
108
- // Struct or Interface: type User struct / type Reader interface
109
- const typeMatch = /^type\s+([A-Za-z0-9_]+)\s+(struct|interface)\b/.exec(trimmed);
110
- if (typeMatch) {
111
- const typeName = typeMatch[1];
112
- const kind = typeMatch[2] === "interface" ? "interface" : "class";
113
- const visibility: Visibility = /^[A-Z]/.test(typeName) ? "public" : "private";
114
- const endLine = findBraceBlockEnd(lines, i);
115
-
116
- symbols.push({
117
- name: typeName,
118
- kind,
119
- signature: trimmed.replace(/\{$/, "").trim(),
120
- visibility,
121
- line_start: lineNum,
122
- line_end: endLine,
123
- line_count: Math.max(1, endLine - lineNum + 1),
124
- });
125
- continue;
126
- }
127
-
128
- // Method with receiver: func (r *Repo) FindUser(...) (...)
129
- const methodMatch = /^func\s*\([^)]+\)\s*([A-Za-z0-9_]+)\s*\([^)]*\)/.exec(trimmed);
130
- if (methodMatch) {
131
- const methodName = methodMatch[1];
132
- const visibility: Visibility = /^[A-Z]/.test(methodName) ? "public" : "private";
133
- const endLine = findBraceBlockEnd(lines, i);
134
-
135
- symbols.push({
136
- name: methodName,
137
- kind: "method",
138
- signature: trimmed.replace(/\{$/, "").trim(),
139
- visibility,
140
- line_start: lineNum,
141
- line_end: endLine,
142
- line_count: Math.max(1, endLine - lineNum + 1),
143
- });
144
- continue;
145
- }
146
-
147
- // Function: func ProcessPayment(...) (...)
148
- const funcMatch = /^func\s+([A-Za-z0-9_]+)\s*\([^)]*\)/.exec(trimmed);
149
- if (funcMatch) {
150
- const funcName = funcMatch[1];
151
- const visibility: Visibility = /^[A-Z]/.test(funcName) ? "public" : "private";
152
- const endLine = findBraceBlockEnd(lines, i);
153
-
154
- symbols.push({
155
- name: funcName,
156
- kind: "function",
157
- signature: trimmed.replace(/\{$/, "").trim(),
158
- visibility,
159
- line_start: lineNum,
160
- line_end: endLine,
161
- line_count: Math.max(1, endLine - lineNum + 1),
162
- });
163
- }
164
- }
165
-
166
- return {
167
- symbols,
168
- dependencies,
169
- };
170
- }
171
-
172
- private isGoStdlib(importPath: string): boolean {
173
- const rootSegment = importPath.split("/")[0];
174
- return GO_STDLIB_PREFIXES.has(rootSegment) || !importPath.includes(".");
175
- }
176
- }
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import type { ExtractedDependency, ExtractedSymbol, ParsedFileAST, Visibility } from "../../../types/index.ts";
4
+ import { findBraceBlockEnd, calculateControlFlowNesting } from "../boundary-tracker.ts";
5
+ import type { CodeExtractor } from "./base.ts";
6
+
7
+ const GO_STDLIB_PREFIXES = new Set([
8
+ "bufio",
9
+ "bytes",
10
+ "context",
11
+ "crypto",
12
+ "database",
13
+ "encoding",
14
+ "errors",
15
+ "flag",
16
+ "fmt",
17
+ "html",
18
+ "image",
19
+ "io",
20
+ "log",
21
+ "math",
22
+ "mime",
23
+ "net",
24
+ "os",
25
+ "path",
26
+ "plugin",
27
+ "reflect",
28
+ "regexp",
29
+ "runtime",
30
+ "sort",
31
+ "strconv",
32
+ "strings",
33
+ "sync",
34
+ "syscall",
35
+ "testing",
36
+ "text",
37
+ "time",
38
+ "unicode",
39
+ "unsafe",
40
+ ]);
41
+
42
+ export class GoExtractor implements CodeExtractor {
43
+ public canHandle(filePath: string): boolean {
44
+ return /\.go$/i.test(filePath);
45
+ }
46
+
47
+ public async extract(filePath: string, content: string): Promise<ParsedFileAST> {
48
+ const symbols: ExtractedSymbol[] = [];
49
+ const dependencies: ExtractedDependency[] = [];
50
+
51
+ const lines = content.split("\n");
52
+
53
+ // 1. Extract Go Imports
54
+ let inImportBlock = false;
55
+
56
+ for (let i = 0; i < lines.length; i++) {
57
+ const line = lines[i];
58
+ const trimmed = line.trim();
59
+ const lineNum = i + 1;
60
+
61
+ if (trimmed.startsWith("//")) continue;
62
+
63
+ if (trimmed === "import (") {
64
+ inImportBlock = true;
65
+ continue;
66
+ }
67
+
68
+ if (inImportBlock) {
69
+ if (trimmed === ")") {
70
+ inImportBlock = false;
71
+ continue;
72
+ }
73
+
74
+ const blockMatch = /^(?:[\w.]+\s+)?["']([^"']+)["']/.exec(trimmed);
75
+ if (blockMatch) {
76
+ const importPath = blockMatch[1];
77
+ const isExternal = this.isExternalImport(importPath, filePath);
78
+ dependencies.push({
79
+ target: importPath,
80
+ statement: trimmed,
81
+ line_number: lineNum,
82
+ is_external: isExternal,
83
+ });
84
+ }
85
+ continue;
86
+ }
87
+
88
+ // Single line import: import "fmt" or import alias "pkg"
89
+ const singleMatch = /^import\s+(?:[\w.]+\s+)?["']([^"']+)["']/.exec(trimmed);
90
+ if (singleMatch) {
91
+ const importPath = singleMatch[1];
92
+ const isExternal = this.isExternalImport(importPath, filePath);
93
+ dependencies.push({
94
+ target: importPath,
95
+ statement: trimmed,
96
+ line_number: lineNum,
97
+ is_external: isExternal,
98
+ });
99
+ }
100
+ }
101
+
102
+ // 2. Extract Go Types, Structs, Interfaces, and Functions
103
+ for (let i = 0; i < lines.length; i++) {
104
+ const line = lines[i];
105
+ const trimmed = line.trim();
106
+ const lineNum = i + 1;
107
+
108
+ if (trimmed.startsWith("//")) continue;
109
+
110
+ // Struct or Interface: type User struct / type Reader interface
111
+ const typeMatch = /^type\s+([A-Za-z0-9_]+)\s+(struct|interface)\b/.exec(trimmed);
112
+ if (typeMatch) {
113
+ const typeName = typeMatch[1];
114
+ const kind = typeMatch[2] === "interface" ? "interface" : "class";
115
+ const visibility: Visibility = /^[A-Z]/.test(typeName) ? "public" : "private";
116
+ const endLine = findBraceBlockEnd(lines, i);
117
+
118
+ symbols.push({
119
+ name: typeName,
120
+ kind,
121
+ signature: trimmed.replace(/\{$/, "").trim(),
122
+ visibility,
123
+ line_start: lineNum,
124
+ line_end: endLine,
125
+ line_count: Math.max(1, endLine - lineNum + 1),
126
+ });
127
+ continue;
128
+ }
129
+
130
+ // Method with receiver: func (r *Repo) FindUser(...) (...)
131
+ const methodMatch = /^func\s*\([^)]+\)\s*([A-Za-z0-9_]+)\s*\([^)]*\)/.exec(trimmed);
132
+ if (methodMatch) {
133
+ const methodName = methodMatch[1];
134
+ const visibility: Visibility = /^[A-Z]/.test(methodName) ? "public" : "private";
135
+ const endLine = findBraceBlockEnd(lines, i);
136
+ const nestingDepth = calculateControlFlowNesting(lines, i, endLine - 1);
137
+
138
+ symbols.push({
139
+ name: methodName,
140
+ kind: "method",
141
+ signature: trimmed.replace(/\{$/, "").trim(),
142
+ visibility,
143
+ line_start: lineNum,
144
+ line_end: endLine,
145
+ line_count: Math.max(1, endLine - lineNum + 1),
146
+ nesting_depth: nestingDepth,
147
+ });
148
+ continue;
149
+ }
150
+
151
+ // Function: func ProcessPayment(...) (...)
152
+ const funcMatch = /^func\s+([A-Za-z0-9_]+)\s*\([^)]*\)/.exec(trimmed);
153
+ if (funcMatch) {
154
+ const funcName = funcMatch[1];
155
+ const visibility: Visibility = /^[A-Z]/.test(funcName) ? "public" : "private";
156
+ const endLine = findBraceBlockEnd(lines, i);
157
+ const nestingDepth = calculateControlFlowNesting(lines, i, endLine - 1);
158
+
159
+ symbols.push({
160
+ name: funcName,
161
+ kind: "function",
162
+ signature: trimmed.replace(/\{$/, "").trim(),
163
+ visibility,
164
+ line_start: lineNum,
165
+ line_end: endLine,
166
+ line_count: Math.max(1, endLine - lineNum + 1),
167
+ nesting_depth: nestingDepth,
168
+ });
169
+ }
170
+ }
171
+
172
+ return {
173
+ symbols,
174
+ dependencies,
175
+ };
176
+ }
177
+
178
+ private isExternalImport(importPath: string, filePath?: string): boolean {
179
+ if (this.isGoStdlib(importPath)) {
180
+ return true;
181
+ }
182
+ if (importPath.startsWith(".") || importPath.startsWith("/")) {
183
+ return false;
184
+ }
185
+ const modName = this.findGoModuleName(filePath);
186
+ if (modName) {
187
+ if (importPath === modName || importPath.startsWith(`${modName}/`)) {
188
+ return false;
189
+ }
190
+ return true;
191
+ }
192
+
193
+ if (
194
+ importPath.includes("/domains/") ||
195
+ importPath.includes("/internal/") ||
196
+ importPath.includes("/pkg/")
197
+ ) {
198
+ return false;
199
+ }
200
+
201
+ if (importPath.includes(".")) {
202
+ return true;
203
+ }
204
+
205
+ return false;
206
+ }
207
+
208
+ private findGoModuleName(filePath?: string): string | null {
209
+ if (!filePath) return null;
210
+ try {
211
+ let currentDir = path.dirname(path.resolve(filePath));
212
+ while (currentDir && currentDir !== path.dirname(currentDir)) {
213
+ const goModPath = path.join(currentDir, "go.mod");
214
+ if (fs.existsSync(goModPath)) {
215
+ const content = fs.readFileSync(goModPath, "utf-8");
216
+ const match = /^module\s+([^\s\r\n]+)/m.exec(content);
217
+ if (match) return match[1];
218
+ }
219
+ currentDir = path.dirname(currentDir);
220
+ }
221
+ } catch {}
222
+ return null;
223
+ }
224
+
225
+ private isGoStdlib(importPath: string): boolean {
226
+ const rootSegment = importPath.split("/")[0];
227
+ return GO_STDLIB_PREFIXES.has(rootSegment) || !importPath.includes(".");
228
+ }
229
+ }