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,188 +1,216 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
4
- import { ConfigLoader } from "../../core/config/loader.ts";
5
- import { SeptumDatabase } from "../../core/database/client.ts";
6
- import { SeptumRepository } from "../../core/database/repository.ts";
7
- import { ASTParserEngine } from "../../core/parser/tree-sitter.ts";
8
- import { SessionManager } from "../../core/session/session-manager.ts";
9
-
10
- export interface ToolPayload {
11
- tool_name: string;
12
- tool_input: {
13
- TargetFile?: string;
14
- file_path?: string;
15
- ReplacementContent?: string;
16
- CodeContent?: string;
17
- feature_key?: string;
18
- };
19
- }
20
-
21
- export async function handleHookCommand(args: string[]): Promise<void> {
22
- const subHook = args[1] || "pre-write";
23
-
24
- if (subHook === "pre-write") {
25
- await runPreWriteHook();
26
- } else {
27
- process.exit(0);
28
- }
29
- }
30
-
31
- async function runPreWriteHook(): Promise<void> {
32
- // If .septum/septum.db does not exist, pass through
33
- const dbPath = path.resolve(process.cwd(), ".septum", "septum.db");
34
- if (!fs.existsSync(dbPath)) {
35
- process.exit(0);
36
- }
37
-
38
- // Read JSON payload from stdin
39
- const stdinData = await readStdin();
40
- if (!stdinData.trim()) {
41
- process.exit(0);
42
- }
43
-
44
- let payload: ToolPayload;
45
- try {
46
- payload = JSON.parse(stdinData);
47
- } catch {
48
- // Non-JSON stdin, pass through
49
- process.exit(0);
50
- }
51
-
52
- const toolInput = payload.tool_input || {};
53
- const targetFile = toolInput.TargetFile || toolInput.file_path;
54
- const content = toolInput.ReplacementContent || toolInput.CodeContent || "";
55
-
56
- if (!targetFile) {
57
- process.exit(0);
58
- }
59
-
60
- const config = ConfigLoader.load();
61
- const db = new SeptumDatabase(config.settings.db_path);
62
- const repo = new SeptumRepository(db.raw);
63
- const evaluator = new BoundaryEvaluator(repo);
64
-
65
- try {
66
- const sourceDomain = evaluator.resolveSourceDomain(targetFile, config);
67
-
68
- // If file is not inside any domain, allow or check feature scope
69
- if (sourceDomain) {
70
- // -------------------------------------------------------------
71
- // GATE 3: Mandatory Catalog Consultation
72
- // Verify that the AI has consulted the domain catalog before writing
73
- // -------------------------------------------------------------
74
- const accessLogPath = path.resolve(process.cwd(), ".septum/catalog_access.json");
75
- let hasConsulted = false;
76
-
77
- if (fs.existsSync(accessLogPath)) {
78
- try {
79
- const rawAccess = JSON.parse(fs.readFileSync(accessLogPath, "utf-8"));
80
- const domainAccessedAt = rawAccess.domains?.[sourceDomain];
81
- if (domainAccessedAt) {
82
- hasConsulted = true;
83
- }
84
- } catch {
85
- // ignore parse error
86
- }
87
- }
88
-
89
- if (!hasConsulted) {
90
- console.error(
91
- `\n[SEPTUM GATE 3 VIOLATION - Mandatory Consultation Required]\n` +
92
- `✕ Operation blocked: You are attempting to write to domain '${sourceDomain}' (${targetFile}) ` +
93
- `without inspecting its authoritative catalog first.\n` +
94
- `▶ REQUIRED ACTION: Call tool 'septum_get_domain_catalog(domain: "${sourceDomain}")' ` +
95
- `or 'septum_get_feature_context' before writing code.\n`
96
- );
97
- db.close();
98
- process.exit(1);
99
- }
100
- }
101
-
102
- // -------------------------------------------------------------
103
- // GATE 1: Hard Touchpoint Lock (if features are defined)
104
- // -------------------------------------------------------------
105
- const features = config.features ?? {};
106
- const session = SessionManager.getActiveSession(process.cwd());
107
- const activeFeatureKey =
108
- toolInput.feature_key || process.env.SEPTUM_ACTIVE_FEATURE || session?.feature_key;
109
-
110
- if (activeFeatureKey && features[activeFeatureKey]) {
111
- const touchpointViolations = evaluator.checkFeatureTouchpoints(
112
- activeFeatureKey,
113
- targetFile,
114
- config
115
- );
116
-
117
- if (touchpointViolations.length > 0) {
118
- console.error(
119
- `\n[SEPTUM GATE 1 VIOLATION - Scope Touchpoint Lock]\n` +
120
- `✕ Operation blocked: File '${targetFile}' is outside the declared allowed_touchpoints for feature '${activeFeatureKey}'.\n` +
121
- `▶ REASON: ${touchpointViolations[0].message}\n` +
122
- `▶ REQUIRED ACTION: Only modify files declared in allowed_touchpoints for this feature.\n`
123
- );
124
- db.close();
125
- process.exit(1);
126
- }
127
- }
128
-
129
- // -------------------------------------------------------------
130
- // GATE 2: Real-time AST Import Interception
131
- // Extract imports from proposed content and check for boundary leaks
132
- // -------------------------------------------------------------
133
- if (content && sourceDomain) {
134
- const astEngine = new ASTParserEngine();
135
- const parsed = await astEngine.parseFile(targetFile, content);
136
-
137
- const proposedImports = parsed.dependencies.map((d) => d.target);
138
- const boundaryViolations = evaluator.checkProposedChanges(
139
- targetFile,
140
- proposedImports,
141
- config
142
- );
143
-
144
- if (boundaryViolations.length > 0) {
145
- const v = boundaryViolations[0];
146
- console.error(
147
- `\n[SEPTUM GATE 2 VIOLATION - Forbidden Cross-Domain Import]\n` +
148
- `✕ Operation blocked: Proposed code imports forbidden domain '${v.target_domain}' from '${v.source_domain}'.\n` +
149
- `▶ OFFENDING IMPORT: ${v.imported_target}\n` +
150
- `▶ RULE: ${v.rule}\n` +
151
- `▶ MESSAGE: ${v.message}\n` +
152
- `▶ REQUIRED ACTION: Decouple this dependency. Use an authorized Interface, Event, or Shared Kernel.\n`
153
- );
154
- db.close();
155
- process.exit(1);
156
- }
157
- }
158
-
159
- db.close();
160
- process.exit(0);
161
- } catch (err) {
162
- db.close();
163
- const message = err instanceof Error ? err.message : String(err);
164
- console.error(`\x1b[31m[Septum Hook Error]\x1b[0m ${message}`);
165
- process.exit(1);
166
- }
167
- }
168
-
169
- function readStdin(): Promise<string> {
170
- return new Promise((resolve) => {
171
- let data = "";
172
- if (process.stdin.isTTY) {
173
- resolve("");
174
- return;
175
- }
176
-
177
- process.stdin.setEncoding("utf-8");
178
- process.stdin.on("data", (chunk) => {
179
- data += chunk;
180
- });
181
- process.stdin.on("end", () => {
182
- resolve(data);
183
- });
184
- process.stdin.on("error", () => {
185
- resolve("");
186
- });
187
- });
188
- }
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
4
+ import { ConfigLoader } from "../../core/config/loader.ts";
5
+ import { SeptumDatabase } from "../../core/database/client.ts";
6
+ import { SeptumRepository } from "../../core/database/repository.ts";
7
+ import { ASTParserEngine } from "../../core/parser/tree-sitter.ts";
8
+ import { SessionManager } from "../../core/session/session-manager.ts";
9
+
10
+ export interface ToolPayload {
11
+ tool_name?: string;
12
+ tool_input?: {
13
+ TargetFile?: string;
14
+ file_path?: string;
15
+ filePath?: string;
16
+ path?: string;
17
+ ReplacementContent?: string;
18
+ CodeContent?: string;
19
+ new_string?: string;
20
+ content?: string;
21
+ ReplacementChunks?: Array<{ ReplacementContent?: string }>;
22
+ feature_key?: string;
23
+ };
24
+ arguments?: Record<string, unknown>;
25
+ TargetFile?: string;
26
+ file_path?: string;
27
+ filePath?: string;
28
+ path?: string;
29
+ ReplacementContent?: string;
30
+ CodeContent?: string;
31
+ }
32
+
33
+ export async function handleHookCommand(args: string[]): Promise<void> {
34
+ const subHook = args[1] || "pre-write";
35
+
36
+ if (subHook === "pre-write") {
37
+ await runPreWriteHook();
38
+ } else {
39
+ process.exit(0);
40
+ }
41
+ }
42
+
43
+ async function runPreWriteHook(): Promise<void> {
44
+ // If .septum/septum.db does not exist, pass through
45
+ const dbPath = path.resolve(process.cwd(), ".septum", "septum.db");
46
+ if (!fs.existsSync(dbPath)) {
47
+ process.exit(0);
48
+ }
49
+
50
+ // Read JSON payload from stdin
51
+ const stdinData = await readStdin();
52
+ if (!stdinData.trim()) {
53
+ process.exit(0);
54
+ }
55
+
56
+ let payload: ToolPayload;
57
+ try {
58
+ payload = JSON.parse(stdinData);
59
+ } catch {
60
+ // Non-JSON stdin, pass through
61
+ process.exit(0);
62
+ }
63
+
64
+ const toolInput: Record<string, any> =
65
+ payload.tool_input || payload.arguments || (payload as Record<string, any>) || {};
66
+ const targetFile: string | undefined =
67
+ toolInput.TargetFile || toolInput.file_path || toolInput.filePath || toolInput.path;
68
+ const chunkContent = Array.isArray(toolInput.ReplacementChunks)
69
+ ? toolInput.ReplacementChunks.map((c: any) => c?.ReplacementContent || "").join("\n")
70
+ : "";
71
+ const content: string =
72
+ toolInput.ReplacementContent ||
73
+ toolInput.CodeContent ||
74
+ toolInput.new_string ||
75
+ toolInput.content ||
76
+ chunkContent ||
77
+ "";
78
+
79
+ if (!targetFile) {
80
+ process.exit(0);
81
+ }
82
+
83
+ const config = ConfigLoader.load();
84
+ const db = new SeptumDatabase(config.settings.db_path);
85
+ const repo = new SeptumRepository(db.raw);
86
+ const evaluator = new BoundaryEvaluator(repo);
87
+
88
+ try {
89
+ const sourceDomain = evaluator.resolveSourceDomain(targetFile, config);
90
+
91
+ // If file is not inside any domain, allow or check feature scope
92
+ if (sourceDomain) {
93
+ // -------------------------------------------------------------
94
+ // GATE 3: Mandatory Catalog Consultation
95
+ // Verify that the AI has consulted the domain catalog before writing
96
+ // -------------------------------------------------------------
97
+ const accessLogPath = path.resolve(process.cwd(), ".septum/catalog_access.json");
98
+ let hasConsulted = false;
99
+
100
+ if (fs.existsSync(accessLogPath)) {
101
+ try {
102
+ const rawAccess = JSON.parse(fs.readFileSync(accessLogPath, "utf-8"));
103
+ const domainsMap: Record<string, string> = rawAccess.domains || {};
104
+ const lowerSource = sourceDomain.toLowerCase();
105
+ const domainAccessedAt =
106
+ domainsMap[sourceDomain] ||
107
+ domainsMap[lowerSource] ||
108
+ Object.entries(domainsMap).find(([k]) => k.toLowerCase() === lowerSource)?.[1];
109
+ if (domainAccessedAt) {
110
+ hasConsulted = true;
111
+ }
112
+ } catch {
113
+ // ignore parse error
114
+ }
115
+ }
116
+
117
+ if (!hasConsulted) {
118
+ console.error(
119
+ `\n[SEPTUM GATE 3 VIOLATION - Mandatory Consultation Required]\n` +
120
+ `✕ Operation blocked: You are attempting to write to domain '${sourceDomain}' (${targetFile}) ` +
121
+ `without inspecting its authoritative symbol & file-connection catalog first.\n` +
122
+ `▶ REQUIRED ACTION: Call tool 'septum_get_domain_catalog({ domain: "${sourceDomain}", detail_level: "compact" })' ` +
123
+ `or 'septum_get_feature_context' before writing code.\n`
124
+ );
125
+ db.close();
126
+ process.exit(1);
127
+ }
128
+ }
129
+
130
+ // -------------------------------------------------------------
131
+ // GATE 1: Hard Touchpoint Lock (if features are defined)
132
+ // -------------------------------------------------------------
133
+ const features = config.features ?? {};
134
+ const session = SessionManager.getActiveSession(process.cwd());
135
+ const activeFeatureKey =
136
+ toolInput.feature_key || process.env.SEPTUM_ACTIVE_FEATURE || session?.feature_key;
137
+
138
+ if (activeFeatureKey && features[activeFeatureKey]) {
139
+ const touchpointViolations = evaluator.checkFeatureTouchpoints(
140
+ activeFeatureKey,
141
+ targetFile,
142
+ config
143
+ );
144
+
145
+ if (touchpointViolations.length > 0) {
146
+ console.error(
147
+ `\n[SEPTUM GATE 1 VIOLATION - Scope Touchpoint Lock]\n` +
148
+ `✕ Operation blocked: File '${targetFile}' is outside the declared allowed_touchpoints for feature '${activeFeatureKey}'.\n` +
149
+ `▶ REASON: ${touchpointViolations[0].message}\n` +
150
+ `▶ REQUIRED ACTION: Only modify files declared in allowed_touchpoints for this feature.\n`
151
+ );
152
+ db.close();
153
+ process.exit(1);
154
+ }
155
+ }
156
+
157
+ // -------------------------------------------------------------
158
+ // GATE 2: Real-time AST Import Interception
159
+ // Extract imports from proposed content and check for boundary leaks
160
+ // -------------------------------------------------------------
161
+ if (content && sourceDomain) {
162
+ const astEngine = new ASTParserEngine();
163
+ const parsed = await astEngine.parseFile(targetFile, content);
164
+
165
+ const proposedImports = parsed.dependencies.map((d) => d.target);
166
+ const boundaryViolations = evaluator.checkProposedChanges(
167
+ targetFile,
168
+ proposedImports,
169
+ config
170
+ );
171
+
172
+ if (boundaryViolations.length > 0) {
173
+ const v = boundaryViolations[0];
174
+ console.error(
175
+ `\n[SEPTUM GATE 2 VIOLATION - Forbidden Cross-Domain Import]\n` +
176
+ `✕ Operation blocked: Proposed code imports forbidden domain '${v.target_domain}' from '${v.source_domain}'.\n` +
177
+ `▶ OFFENDING IMPORT: ${v.imported_target}\n` +
178
+ `▶ RULE: ${v.rule}\n` +
179
+ `▶ MESSAGE: ${v.message}\n` +
180
+ `▶ REQUIRED ACTION: Decouple this dependency. Use an authorized Interface, Event, or Shared Kernel.\n`
181
+ );
182
+ db.close();
183
+ process.exit(1);
184
+ }
185
+ }
186
+
187
+ db.close();
188
+ process.exit(0);
189
+ } catch (err) {
190
+ db.close();
191
+ const message = err instanceof Error ? err.message : String(err);
192
+ console.error(`\x1b[31m[Septum Hook Error]\x1b[0m ${message}`);
193
+ process.exit(1);
194
+ }
195
+ }
196
+
197
+ function readStdin(): Promise<string> {
198
+ return new Promise((resolve) => {
199
+ let data = "";
200
+ if (process.stdin.isTTY) {
201
+ resolve("");
202
+ return;
203
+ }
204
+
205
+ process.stdin.setEncoding("utf-8");
206
+ process.stdin.on("data", (chunk) => {
207
+ data += chunk;
208
+ });
209
+ process.stdin.on("end", () => {
210
+ resolve(data);
211
+ });
212
+ process.stdin.on("error", () => {
213
+ resolve("");
214
+ });
215
+ });
216
+ }
@@ -1,29 +1,29 @@
1
- import { ConfigLoader } from "../../core/config/loader.ts";
2
- import { SeptumDatabase } from "../../core/database/client.ts";
3
- import { SeptumRepository } from "../../core/database/repository.ts";
4
- import { IngestionPipeline } from "../../core/ingestion/pipeline.ts";
5
-
6
- export async function handleIngestCommand(): Promise<void> {
7
- console.log("[Septum] Starting codebase structural ingestion...");
8
-
9
- const config = ConfigLoader.load();
10
- const db = new SeptumDatabase(config.settings.db_path);
11
- const repo = new SeptumRepository(db.raw);
12
- const pipeline = new IngestionPipeline(repo);
13
-
14
- const metrics = await pipeline.run(config);
15
-
16
- console.log("=========================================");
17
- console.log(" Septum Ingestion Complete");
18
- console.log("=========================================");
19
- console.log(` Domains Processed: ${metrics.domains_processed}`);
20
- console.log(` Files Scanned: ${metrics.files_scanned}`);
21
- console.log(` Files Updated/Added: ${metrics.files_updated}`);
22
- console.log(` Files Cached/Skipped: ${metrics.files_skipped}`);
23
- console.log(` Symbols Indexed: ${metrics.symbols_indexed}`);
24
- console.log(` Dependencies Indexed: ${metrics.dependencies_indexed}`);
25
- console.log(` Execution Time: ${metrics.duration_ms} ms`);
26
- console.log("=========================================");
27
-
28
- db.close();
29
- }
1
+ import { ConfigLoader } from "../../core/config/loader.ts";
2
+ import { SeptumDatabase } from "../../core/database/client.ts";
3
+ import { SeptumRepository } from "../../core/database/repository.ts";
4
+ import { IngestionPipeline } from "../../core/ingestion/pipeline.ts";
5
+
6
+ export async function handleIngestCommand(): Promise<void> {
7
+ console.log("[Septum] Starting codebase structural ingestion...");
8
+
9
+ const config = ConfigLoader.load();
10
+ const db = new SeptumDatabase(config.settings.db_path);
11
+ const repo = new SeptumRepository(db.raw);
12
+ const pipeline = new IngestionPipeline(repo);
13
+
14
+ const metrics = await pipeline.run(config);
15
+
16
+ console.log("=========================================");
17
+ console.log(" Septum Ingestion Complete");
18
+ console.log("=========================================");
19
+ console.log(` Domains Processed: ${metrics.domains_processed}`);
20
+ console.log(` Files Scanned: ${metrics.files_scanned}`);
21
+ console.log(` Files Updated/Added: ${metrics.files_updated}`);
22
+ console.log(` Files Cached/Skipped: ${metrics.files_skipped}`);
23
+ console.log(` Symbols Indexed: ${metrics.symbols_indexed}`);
24
+ console.log(` Dependencies Indexed: ${metrics.dependencies_indexed}`);
25
+ console.log(` Execution Time: ${metrics.duration_ms} ms`);
26
+ console.log("=========================================");
27
+
28
+ db.close();
29
+ }