septum 0.1.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.
- package/LICENSE +21 -0
- package/README.md +100 -0
- package/bin/septum.ts +4 -0
- package/package.json +62 -0
- package/src/cli/commands/check.ts +161 -0
- package/src/cli/commands/hook.ts +188 -0
- package/src/cli/commands/ingest.ts +29 -0
- package/src/cli/commands/init.ts +211 -0
- package/src/cli/commands/locate.ts +61 -0
- package/src/cli/commands/query.ts +64 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/slice.ts +90 -0
- package/src/cli/commands/sync.ts +31 -0
- package/src/cli/index.ts +178 -0
- package/src/cli/templates/hooks.ts +75 -0
- package/src/cli/templates/rules.ts +38 -0
- package/src/cli/templates/skill.ts +66 -0
- package/src/core/boundary/evaluator.ts +210 -0
- package/src/core/config/loader.ts +84 -0
- package/src/core/config/schema.ts +39 -0
- package/src/core/database/client.ts +132 -0
- package/src/core/database/repositories/dependency.repository.ts +279 -0
- package/src/core/database/repositories/domain.repository.ts +198 -0
- package/src/core/database/repositories/file.repository.ts +99 -0
- package/src/core/database/repositories/meta.repository.ts +33 -0
- package/src/core/database/repositories/symbol.repository.ts +424 -0
- package/src/core/database/repository.ts +242 -0
- package/src/core/database/schema.sql +92 -0
- package/src/core/discovery/topology-detector.ts +418 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +438 -0
- package/src/core/parser/boundary-tracker.ts +128 -0
- package/src/core/parser/extractors/base.ts +60 -0
- package/src/core/parser/extractors/frontend.ts +194 -0
- package/src/core/parser/extractors/go.ts +176 -0
- package/src/core/parser/extractors/laravel-semantic.ts +426 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +199 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +119 -0
- package/src/core/parser/extractors/php.ts +149 -0
- package/src/core/parser/extractors/python.ts +226 -0
- package/src/core/parser/extractors/registry.ts +49 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +21 -0
- package/src/core/parser/extractors/typescript.ts +177 -0
- package/src/core/parser/tree-sitter.ts +39 -0
- package/src/core/resolver/call-graph-tracer.ts +668 -0
- package/src/core/resolver/module-resolver.ts +323 -0
- package/src/core/resolver/symbol-locator.ts +405 -0
- package/src/core/resolver/vertical-slice-tracer.ts +236 -0
- package/src/core/session/session-manager.ts +56 -0
- package/src/core/telemetry/telemetry.ts +86 -0
- package/src/index.ts +18 -0
- package/src/mcp/schemas.ts +68 -0
- package/src/mcp/server.ts +602 -0
- package/src/mcp/tools/check-boundary.ts +102 -0
- package/src/mcp/tools/get-domain-catalog.ts +91 -0
- package/src/mcp/tools/get-feature-context.ts +116 -0
- package/src/mcp/tools/get-symbol-hotspots.ts +49 -0
- package/src/mcp/tools/get-symbol-impact.ts +26 -0
- package/src/mcp/tools/get-symbol.ts +63 -0
- package/src/mcp/tools/locate-symbol.ts +74 -0
- package/src/mcp/tools/register-domain.ts +64 -0
- package/src/mcp/tools/trace-vertical-slice.ts +102 -0
- package/src/types/index.ts +296 -0
|
@@ -0,0 +1,194 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
}
|