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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -0
  3. package/bin/septum.ts +4 -0
  4. package/package.json +62 -0
  5. package/src/cli/commands/check.ts +161 -0
  6. package/src/cli/commands/hook.ts +188 -0
  7. package/src/cli/commands/ingest.ts +29 -0
  8. package/src/cli/commands/init.ts +211 -0
  9. package/src/cli/commands/locate.ts +61 -0
  10. package/src/cli/commands/query.ts +64 -0
  11. package/src/cli/commands/serve.ts +5 -0
  12. package/src/cli/commands/slice.ts +90 -0
  13. package/src/cli/commands/sync.ts +31 -0
  14. package/src/cli/index.ts +178 -0
  15. package/src/cli/templates/hooks.ts +75 -0
  16. package/src/cli/templates/rules.ts +38 -0
  17. package/src/cli/templates/skill.ts +66 -0
  18. package/src/core/boundary/evaluator.ts +210 -0
  19. package/src/core/config/loader.ts +84 -0
  20. package/src/core/config/schema.ts +39 -0
  21. package/src/core/database/client.ts +132 -0
  22. package/src/core/database/repositories/dependency.repository.ts +279 -0
  23. package/src/core/database/repositories/domain.repository.ts +198 -0
  24. package/src/core/database/repositories/file.repository.ts +99 -0
  25. package/src/core/database/repositories/meta.repository.ts +33 -0
  26. package/src/core/database/repositories/symbol.repository.ts +424 -0
  27. package/src/core/database/repository.ts +242 -0
  28. package/src/core/database/schema.sql +92 -0
  29. package/src/core/discovery/topology-detector.ts +418 -0
  30. package/src/core/ingestion/hasher.ts +5 -0
  31. package/src/core/ingestion/pipeline.ts +438 -0
  32. package/src/core/parser/boundary-tracker.ts +128 -0
  33. package/src/core/parser/extractors/base.ts +60 -0
  34. package/src/core/parser/extractors/frontend.ts +194 -0
  35. package/src/core/parser/extractors/go.ts +176 -0
  36. package/src/core/parser/extractors/laravel-semantic.ts +426 -0
  37. package/src/core/parser/extractors/mcp-cli-semantic.ts +199 -0
  38. package/src/core/parser/extractors/nestjs-semantic.ts +119 -0
  39. package/src/core/parser/extractors/php.ts +149 -0
  40. package/src/core/parser/extractors/python.ts +226 -0
  41. package/src/core/parser/extractors/registry.ts +49 -0
  42. package/src/core/parser/extractors/semantic-extractor.interface.ts +21 -0
  43. package/src/core/parser/extractors/typescript.ts +177 -0
  44. package/src/core/parser/tree-sitter.ts +39 -0
  45. package/src/core/resolver/call-graph-tracer.ts +668 -0
  46. package/src/core/resolver/module-resolver.ts +323 -0
  47. package/src/core/resolver/symbol-locator.ts +405 -0
  48. package/src/core/resolver/vertical-slice-tracer.ts +236 -0
  49. package/src/core/session/session-manager.ts +56 -0
  50. package/src/core/telemetry/telemetry.ts +86 -0
  51. package/src/index.ts +18 -0
  52. package/src/mcp/schemas.ts +68 -0
  53. package/src/mcp/server.ts +602 -0
  54. package/src/mcp/tools/check-boundary.ts +102 -0
  55. package/src/mcp/tools/get-domain-catalog.ts +91 -0
  56. package/src/mcp/tools/get-feature-context.ts +116 -0
  57. package/src/mcp/tools/get-symbol-hotspots.ts +49 -0
  58. package/src/mcp/tools/get-symbol-impact.ts +26 -0
  59. package/src/mcp/tools/get-symbol.ts +63 -0
  60. package/src/mcp/tools/locate-symbol.ts +74 -0
  61. package/src/mcp/tools/register-domain.ts +64 -0
  62. package/src/mcp/tools/trace-vertical-slice.ts +102 -0
  63. package/src/types/index.ts +296 -0
@@ -0,0 +1,177 @@
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
+ export class TypeScriptExtractor implements CodeExtractor {
6
+ public canHandle(filePath: string): boolean {
7
+ return /\.(ts|tsx|js|jsx|mjs|cjs)$/i.test(filePath);
8
+ }
9
+
10
+ public async extract(filePath: string, content: string): Promise<ParsedFileAST> {
11
+ const symbols: ExtractedSymbol[] = [];
12
+ const dependencies: ExtractedDependency[] = [];
13
+
14
+ const lines = content.split("\n");
15
+
16
+ // 1. Extract Imports / Dependencies
17
+ const importRegex = /(?:import\s+(?:(?:[\w*\s{},]+)\s+from\s+)?['"]([^'"]+)['"]|require\s*\(\s*['"]([^'"]+)['"]\s*\))/g;
18
+ for (let i = 0; i < lines.length; i++) {
19
+ const line = lines[i];
20
+ let match: RegExpExecArray | null;
21
+ while ((match = importRegex.exec(line)) !== null) {
22
+ const target = match[1] || match[2];
23
+ if (target) {
24
+ const isExternal = !target.startsWith(".") && !target.startsWith("/");
25
+ dependencies.push({
26
+ target,
27
+ statement: line.trim(),
28
+ line_number: i + 1,
29
+ is_external: isExternal,
30
+ });
31
+ }
32
+ }
33
+ }
34
+
35
+ // 2. Extract Symbols (Classes, Interfaces, Types, Functions, Methods)
36
+ let currentClass: string | null = null;
37
+ let currentClassEndLine = 0;
38
+
39
+ for (let i = 0; i < lines.length; i++) {
40
+ const line = lines[i];
41
+ const trimmed = line.trim();
42
+ const lineNum = i + 1;
43
+
44
+ if (currentClass && lineNum > currentClassEndLine) {
45
+ currentClass = null;
46
+ currentClassEndLine = 0;
47
+ }
48
+
49
+ // Class / Interface / Type definition
50
+ const classMatch = /(?:export\s+)?(?:default\s+)?(?:abstract\s+)?(class|interface)\s+([A-Za-z0-9_]+)/.exec(trimmed);
51
+ if (classMatch) {
52
+ currentClass = classMatch[2];
53
+ const endLine = findBraceBlockEnd(lines, i);
54
+ currentClassEndLine = endLine;
55
+ symbols.push({
56
+ name: classMatch[2],
57
+ kind: classMatch[1] as "class" | "interface",
58
+ signature: trimmed.replace(/\{$/, "").trim(),
59
+ visibility: "public",
60
+ line_start: lineNum,
61
+ line_end: endLine,
62
+ line_count: Math.max(1, endLine - lineNum + 1),
63
+ });
64
+ continue;
65
+ }
66
+
67
+ // Type Alias
68
+ const typeMatch = /(?:export\s+)?type\s+([A-Za-z0-9_]+)\s*=/.exec(trimmed);
69
+ if (typeMatch) {
70
+ const endLine = trimmed.endsWith(";") ? lineNum : findBraceBlockEnd(lines, i);
71
+ symbols.push({
72
+ name: typeMatch[1],
73
+ kind: "type",
74
+ signature: trimmed.replace(/;$/, "").trim(),
75
+ visibility: "public",
76
+ line_start: lineNum,
77
+ line_end: endLine,
78
+ line_count: Math.max(1, endLine - lineNum + 1),
79
+ });
80
+ continue;
81
+ }
82
+
83
+ // Enum Declaration
84
+ const enumMatch = /(?:export\s+)?(?:const\s+)?enum\s+([A-Za-z0-9_]+)/.exec(trimmed);
85
+ if (enumMatch) {
86
+ const endLine = findBraceBlockEnd(lines, i);
87
+ symbols.push({
88
+ name: enumMatch[1],
89
+ kind: "enum",
90
+ signature: trimmed.replace(/\{$/, "").trim(),
91
+ visibility: "public",
92
+ line_start: lineNum,
93
+ line_end: endLine,
94
+ line_count: Math.max(1, endLine - lineNum + 1),
95
+ });
96
+ continue;
97
+ }
98
+
99
+ // Function Declaration
100
+ const fnMatch = /(?:export\s+)?(?:async\s+)?function\s+([A-Za-z0-9_]+)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(trimmed);
101
+ if (fnMatch) {
102
+ const name = fnMatch[1];
103
+ const params = fnMatch[2];
104
+ const retType = fnMatch[3] ? `: ${fnMatch[3].trim()}` : "";
105
+ const endLine = findBraceBlockEnd(lines, i);
106
+ symbols.push({
107
+ name,
108
+ kind: "function",
109
+ signature: `${name}(${params})${retType}`,
110
+ visibility: "public",
111
+ line_start: lineNum,
112
+ line_end: endLine,
113
+ line_count: Math.max(1, endLine - lineNum + 1),
114
+ });
115
+ continue;
116
+ }
117
+
118
+ // Exported Constants / Variables at module level
119
+ const constMatch = /^export\s+(?:const|let|var)\s+([A-Za-z0-9_]+)\s*(?::\s*([^=;]+))?\s*=/.exec(trimmed);
120
+ if (constMatch) {
121
+ const varName = constMatch[1];
122
+ const typeStr = constMatch[2] ? `: ${constMatch[2].trim()}` : "";
123
+ symbols.push({
124
+ name: varName,
125
+ kind: "property",
126
+ signature: `const ${varName}${typeStr}`,
127
+ visibility: "public",
128
+ line_start: lineNum,
129
+ line_end: lineNum,
130
+ line_count: 1,
131
+ });
132
+ continue;
133
+ }
134
+
135
+ // Method or Property in class
136
+ if (currentClass) {
137
+ // Class property: public foo: string; or private bar = 1;
138
+ const propMatch = /^(?:(public|protected|private)\s+)?(?:readonly\s+)?([A-Za-z0-9_]+)\s*(?:\?|\!)?\s*(?::\s*([^;={]+))?(?:\s*=[^;]+)?;\s*$/.exec(trimmed);
139
+ if (propMatch && !["return", "const", "let", "var", "throw", "import"].includes(propMatch[2])) {
140
+ const vis = (propMatch[1] as Visibility) || "public";
141
+ const propName = propMatch[2];
142
+ const typeStr = propMatch[3] ? `: ${propMatch[3].trim()}` : "";
143
+ symbols.push({
144
+ name: `${currentClass}::${propName}`,
145
+ kind: "property",
146
+ signature: `${vis} ${propName}${typeStr}`,
147
+ visibility: vis,
148
+ line_start: lineNum,
149
+ line_end: lineNum,
150
+ line_count: 1,
151
+ });
152
+ continue;
153
+ }
154
+
155
+ const methodMatch = /^(?:(public|protected|private)\s+)?(?:static\s+)?(?:async\s+)?([A-Za-z0-9_]+)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(trimmed);
156
+ if (methodMatch && !["if", "for", "while", "switch", "catch"].includes(methodMatch[2])) {
157
+ const vis = (methodMatch[1] as Visibility) || "public";
158
+ const name = methodMatch[2];
159
+ const params = methodMatch[3];
160
+ const retType = methodMatch[4] ? `: ${methodMatch[4].trim()}` : "";
161
+ const endLine = findBraceBlockEnd(lines, i);
162
+ symbols.push({
163
+ name: `${currentClass}::${name}`,
164
+ kind: "method",
165
+ signature: `${vis} ${name}(${params})${retType}`,
166
+ visibility: vis,
167
+ line_start: lineNum,
168
+ line_end: endLine,
169
+ line_count: Math.max(1, endLine - lineNum + 1),
170
+ });
171
+ }
172
+ }
173
+ }
174
+
175
+ return { symbols, dependencies };
176
+ }
177
+ }
@@ -0,0 +1,39 @@
1
+ import type { ParsedFileAST } from "../../types/index.ts";
2
+ import type { CodeExtractor } from "./extractors/base.ts";
3
+ import { FrontendExtractor } from "./extractors/frontend.ts";
4
+ import { GoExtractor } from "./extractors/go.ts";
5
+ import { PHPExtractor } from "./extractors/php.ts";
6
+ import { PythonExtractor } from "./extractors/python.ts";
7
+ import { TypeScriptExtractor } from "./extractors/typescript.ts";
8
+
9
+ export class ASTParserEngine {
10
+ private extractors: CodeExtractor[];
11
+
12
+ constructor() {
13
+ this.extractors = [
14
+ new FrontendExtractor(),
15
+ new TypeScriptExtractor(),
16
+ new PHPExtractor(),
17
+ new PythonExtractor(),
18
+ new GoExtractor(),
19
+ ];
20
+ }
21
+
22
+ public async parseFile(filePath: string, content: string): Promise<ParsedFileAST> {
23
+ for (const extractor of this.extractors) {
24
+ if (extractor.canHandle(filePath)) {
25
+ return extractor.extract(filePath, content);
26
+ }
27
+ }
28
+
29
+ // Default fallback extractor for unknown file types
30
+ return {
31
+ symbols: [],
32
+ dependencies: [],
33
+ };
34
+ }
35
+
36
+ public registerExtractor(extractor: CodeExtractor): void {
37
+ this.extractors.unshift(extractor);
38
+ }
39
+ }