septum 0.1.0 → 0.1.2

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 (65) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +100 -100
  3. package/bin/septum.ts +4 -4
  4. package/package.json +63 -62
  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 +90 -90
  13. package/src/cli/commands/sync.ts +31 -31
  14. package/src/cli/index.ts +199 -178
  15. package/src/cli/templates/hooks.ts +75 -75
  16. package/src/cli/templates/rules.ts +38 -38
  17. package/src/cli/templates/skill.ts +66 -66
  18. package/src/core/boundary/evaluator.ts +210 -210
  19. package/src/core/config/loader.ts +84 -84
  20. package/src/core/config/schema.ts +39 -39
  21. package/src/core/database/client.ts +44 -132
  22. package/src/core/database/repositories/dependency.repository.ts +279 -279
  23. package/src/core/database/repositories/domain.repository.ts +198 -198
  24. package/src/core/database/repositories/file.repository.ts +99 -99
  25. package/src/core/database/repositories/meta.repository.ts +33 -33
  26. package/src/core/database/repositories/symbol.repository.ts +424 -424
  27. package/src/core/database/repository.ts +242 -242
  28. package/src/core/database/schema.ts +120 -0
  29. package/src/core/discovery/topology-detector.ts +418 -418
  30. package/src/core/ingestion/hasher.ts +5 -5
  31. package/src/core/ingestion/pipeline.ts +438 -438
  32. package/src/core/parser/boundary-tracker.ts +128 -128
  33. package/src/core/parser/extractors/base.ts +60 -60
  34. package/src/core/parser/extractors/frontend.ts +194 -194
  35. package/src/core/parser/extractors/go.ts +176 -176
  36. package/src/core/parser/extractors/laravel-semantic.ts +426 -426
  37. package/src/core/parser/extractors/mcp-cli-semantic.ts +199 -199
  38. package/src/core/parser/extractors/nestjs-semantic.ts +119 -119
  39. package/src/core/parser/extractors/php.ts +149 -149
  40. package/src/core/parser/extractors/python.ts +226 -226
  41. package/src/core/parser/extractors/registry.ts +49 -49
  42. package/src/core/parser/extractors/semantic-extractor.interface.ts +21 -21
  43. package/src/core/parser/extractors/typescript.ts +177 -177
  44. package/src/core/parser/tree-sitter.ts +39 -39
  45. package/src/core/resolver/call-graph-tracer.ts +668 -668
  46. package/src/core/resolver/module-resolver.ts +342 -323
  47. package/src/core/resolver/symbol-locator.ts +543 -405
  48. package/src/core/resolver/vertical-slice-tracer.ts +237 -236
  49. package/src/core/session/session-manager.ts +56 -56
  50. package/src/core/telemetry/telemetry.ts +86 -86
  51. package/src/index.ts +18 -18
  52. package/src/mcp/schemas.ts +68 -68
  53. package/src/mcp/server.ts +612 -602
  54. package/src/mcp/tools/check-boundary.ts +102 -102
  55. package/src/mcp/tools/get-domain-catalog.ts +91 -91
  56. package/src/mcp/tools/get-feature-context.ts +116 -116
  57. package/src/mcp/tools/get-symbol-hotspots.ts +49 -49
  58. package/src/mcp/tools/get-symbol-impact.ts +26 -26
  59. package/src/mcp/tools/get-symbol.ts +63 -63
  60. package/src/mcp/tools/locate-symbol.ts +74 -74
  61. package/src/mcp/tools/register-domain.ts +64 -64
  62. package/src/mcp/tools/trace-vertical-slice.ts +102 -102
  63. package/src/types/index.ts +296 -296
  64. package/src/version.ts +3 -0
  65. package/src/core/database/schema.sql +0 -92
@@ -1,188 +1,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
- 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
+ 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,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
+ }