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,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
+ }