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,161 +1,161 @@
1
- import { execSync } from "node:child_process";
2
- import * as fs from "node:fs";
3
- import * as path from "node:path";
4
- import { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
5
- import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
6
- import { ConfigLoader } from "../../core/config/loader.ts";
7
- import { SeptumDatabase } from "../../core/database/client.ts";
8
- import { SeptumRepository } from "../../core/database/repository.ts";
9
- import { ASTParserEngine } from "../../core/parser/tree-sitter.ts";
10
- import type { BoundaryViolation } from "../../types/index.ts";
11
-
12
- export interface CheckCommandOptions {
13
- strict?: boolean;
14
- staged?: boolean;
15
- feature?: string;
16
- }
17
-
18
- export async function handleCheckCommand(
19
- optionsOrStrict?: boolean | CheckCommandOptions
20
- ): Promise<void> {
21
- const options: CheckCommandOptions =
22
- typeof optionsOrStrict === "boolean" ? { strict: optionsOrStrict } : optionsOrStrict || {};
23
-
24
- console.log(
25
- options.staged
26
- ? "[Septum] Auditing git staged files against domain boundaries..."
27
- : "[Septum] Running codebase boundary integrity check..."
28
- );
29
-
30
- const config = ConfigLoader.load();
31
- const db = new SeptumDatabase(config.settings.db_path);
32
- const repo = new SeptumRepository(db.raw);
33
- const evaluator = new BoundaryEvaluator(repo);
34
-
35
- let violations: BoundaryViolation[] = [];
36
-
37
- if (options.staged) {
38
- violations = await auditStagedFiles(evaluator, config, options.feature);
39
- } else {
40
- violations = evaluator.auditCodebase(config);
41
- }
42
-
43
- if (violations.length === 0) {
44
- console.log("✓ All domain boundaries are clean. Zero cross-domain leaks detected.");
45
- db.close();
46
- return;
47
- }
48
-
49
- console.error(`\n[Septum Boundary Violation] Found ${violations.length} boundary violation(s):\n`);
50
-
51
- for (const v of violations) {
52
- console.error(` ✕ [${v.rule.toUpperCase()}] at ${v.file}:${v.line}`);
53
- console.error(` Source Domain: ${v.source_domain}`);
54
- console.error(` Target Domain: ${v.target_domain}`);
55
- console.error(` Import Target: ${v.imported_target}`);
56
- console.error(` Message: ${v.message}\n`);
57
- }
58
-
59
- db.close();
60
-
61
- const isStrict = options.strict || config.settings.enforcement === "strict";
62
- if (isStrict) {
63
- console.error("[Septum Failure] Process terminated with exit code 1 due to boundary violations.");
64
- process.exit(1);
65
- }
66
- }
67
-
68
- async function auditStagedFiles(
69
- evaluator: BoundaryEvaluator,
70
- config: ValidatedSeptumConfig,
71
- featureKey?: string
72
- ): Promise<BoundaryViolation[]> {
73
- const violations: BoundaryViolation[] = [];
74
- let stagedFiles: string[] = [];
75
-
76
- try {
77
- const gitOutput = execSync("git diff --cached --name-only --diff-filter=ACM", {
78
- encoding: "utf-8",
79
- timeout: 5000,
80
- maxBuffer: 10 * 1024 * 1024,
81
- });
82
- stagedFiles = gitOutput
83
- .split("\n")
84
- .map((f) => f.trim())
85
- .filter(Boolean);
86
- } catch (err) {
87
- const msg = err instanceof Error ? err.message : String(err);
88
- console.warn(`[Septum Warning] Could not retrieve git staged files: ${msg}`);
89
- return violations;
90
- }
91
-
92
- if (stagedFiles.length === 0) {
93
- console.log(" Notice: No staged files found in git repository.");
94
- return violations;
95
- }
96
-
97
- const astEngine = new ASTParserEngine();
98
-
99
- for (const relPath of stagedFiles) {
100
- const fullPath = path.resolve(process.cwd(), relPath);
101
- if (!fs.existsSync(fullPath)) continue;
102
-
103
- // 1. Feature touchpoint check if featureKey provided
104
- if (featureKey) {
105
- const tpViolations = evaluator.checkFeatureTouchpoints(featureKey, relPath, config);
106
- violations.push(...tpViolations);
107
- }
108
-
109
- const sourceDomain = evaluator.resolveSourceDomain(relPath, config);
110
- if (!sourceDomain) continue;
111
-
112
- const sourceConfig = config.domains[sourceDomain];
113
- if (!sourceConfig) continue;
114
-
115
- const forbidden = sourceConfig.forbidden_dependencies ?? [];
116
- const allowed = sourceConfig.allowed_dependencies ?? [];
117
-
118
- try {
119
- const content = fs.readFileSync(fullPath, "utf-8");
120
- const parsed = await astEngine.parseFile(fullPath, content);
121
-
122
- for (const dep of parsed.dependencies) {
123
- if (dep.is_external) continue;
124
-
125
- const targetDomain = evaluator.resolveTargetDomain(
126
- dep.target,
127
- config,
128
- relPath
129
- );
130
-
131
- if (!targetDomain || targetDomain === sourceDomain) continue;
132
-
133
- if (forbidden.includes(targetDomain)) {
134
- violations.push({
135
- file: relPath,
136
- line: dep.line_number,
137
- source_domain: sourceDomain,
138
- target_domain: targetDomain,
139
- imported_target: dep.target,
140
- rule: "forbidden_dependency",
141
- message: `Illegal import: Domain '${sourceDomain}' is strictly prohibited from importing domain '${targetDomain}'.`,
142
- });
143
- } else if (config.settings.enforcement === "strict" && !allowed.includes(targetDomain)) {
144
- violations.push({
145
- file: relPath,
146
- line: dep.line_number,
147
- source_domain: sourceDomain,
148
- target_domain: targetDomain,
149
- imported_target: dep.target,
150
- rule: "disallowed_dependency",
151
- message: `Disallowed dependency: '${targetDomain}' is not declared in allowed_dependencies for domain '${sourceDomain}'.`,
152
- });
153
- }
154
- }
155
- } catch {
156
- // Ignore unparseable files
157
- }
158
- }
159
-
160
- return violations;
161
- }
1
+ import { execSync } from "node:child_process";
2
+ import * as fs from "node:fs";
3
+ import * as path from "node:path";
4
+ import { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
5
+ import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
6
+ import { ConfigLoader } from "../../core/config/loader.ts";
7
+ import { SeptumDatabase } from "../../core/database/client.ts";
8
+ import { SeptumRepository } from "../../core/database/repository.ts";
9
+ import { ASTParserEngine } from "../../core/parser/tree-sitter.ts";
10
+ import type { BoundaryViolation } from "../../types/index.ts";
11
+
12
+ export interface CheckCommandOptions {
13
+ strict?: boolean;
14
+ staged?: boolean;
15
+ feature?: string;
16
+ }
17
+
18
+ export async function handleCheckCommand(
19
+ optionsOrStrict?: boolean | CheckCommandOptions
20
+ ): Promise<void> {
21
+ const options: CheckCommandOptions =
22
+ typeof optionsOrStrict === "boolean" ? { strict: optionsOrStrict } : optionsOrStrict || {};
23
+
24
+ console.log(
25
+ options.staged
26
+ ? "[Septum] Auditing git staged files against domain boundaries..."
27
+ : "[Septum] Running codebase boundary integrity check..."
28
+ );
29
+
30
+ const config = ConfigLoader.load();
31
+ const db = new SeptumDatabase(config.settings.db_path);
32
+ const repo = new SeptumRepository(db.raw);
33
+ const evaluator = new BoundaryEvaluator(repo);
34
+
35
+ let violations: BoundaryViolation[] = [];
36
+
37
+ if (options.staged) {
38
+ violations = await auditStagedFiles(evaluator, config, options.feature);
39
+ } else {
40
+ violations = evaluator.auditCodebase(config);
41
+ }
42
+
43
+ if (violations.length === 0) {
44
+ console.log("✓ All domain boundaries are clean. Zero cross-domain leaks detected.");
45
+ db.close();
46
+ return;
47
+ }
48
+
49
+ console.error(`\n[Septum Boundary Violation] Found ${violations.length} boundary violation(s):\n`);
50
+
51
+ for (const v of violations) {
52
+ console.error(` ✕ [${v.rule.toUpperCase()}] at ${v.file}:${v.line}`);
53
+ console.error(` Source Domain: ${v.source_domain}`);
54
+ console.error(` Target Domain: ${v.target_domain}`);
55
+ console.error(` Import Target: ${v.imported_target}`);
56
+ console.error(` Message: ${v.message}\n`);
57
+ }
58
+
59
+ db.close();
60
+
61
+ const isStrict = options.strict || config.settings.enforcement === "strict";
62
+ if (isStrict) {
63
+ console.error("[Septum Failure] Process terminated with exit code 1 due to boundary violations.");
64
+ process.exit(1);
65
+ }
66
+ }
67
+
68
+ async function auditStagedFiles(
69
+ evaluator: BoundaryEvaluator,
70
+ config: ValidatedSeptumConfig,
71
+ featureKey?: string
72
+ ): Promise<BoundaryViolation[]> {
73
+ const violations: BoundaryViolation[] = [];
74
+ let stagedFiles: string[] = [];
75
+
76
+ try {
77
+ const gitOutput = execSync("git diff --cached --name-only --diff-filter=ACM", {
78
+ encoding: "utf-8",
79
+ timeout: 5000,
80
+ maxBuffer: 10 * 1024 * 1024,
81
+ });
82
+ stagedFiles = gitOutput
83
+ .split("\n")
84
+ .map((f) => f.trim())
85
+ .filter(Boolean);
86
+ } catch (err) {
87
+ const msg = err instanceof Error ? err.message : String(err);
88
+ console.warn(`[Septum Warning] Could not retrieve git staged files: ${msg}`);
89
+ return violations;
90
+ }
91
+
92
+ if (stagedFiles.length === 0) {
93
+ console.log(" Notice: No staged files found in git repository.");
94
+ return violations;
95
+ }
96
+
97
+ const astEngine = new ASTParserEngine();
98
+
99
+ for (const relPath of stagedFiles) {
100
+ const fullPath = path.resolve(process.cwd(), relPath);
101
+ if (!fs.existsSync(fullPath)) continue;
102
+
103
+ // 1. Feature touchpoint check if featureKey provided
104
+ if (featureKey) {
105
+ const tpViolations = evaluator.checkFeatureTouchpoints(featureKey, relPath, config);
106
+ violations.push(...tpViolations);
107
+ }
108
+
109
+ const sourceDomain = evaluator.resolveSourceDomain(relPath, config);
110
+ if (!sourceDomain) continue;
111
+
112
+ const sourceConfig = config.domains[sourceDomain];
113
+ if (!sourceConfig) continue;
114
+
115
+ const forbidden = sourceConfig.forbidden_dependencies ?? [];
116
+ const allowed = sourceConfig.allowed_dependencies ?? [];
117
+
118
+ try {
119
+ const content = fs.readFileSync(fullPath, "utf-8");
120
+ const parsed = await astEngine.parseFile(fullPath, content);
121
+
122
+ for (const dep of parsed.dependencies) {
123
+ if (dep.is_external) continue;
124
+
125
+ const targetDomain = evaluator.resolveTargetDomain(
126
+ dep.target,
127
+ config,
128
+ relPath
129
+ );
130
+
131
+ if (!targetDomain || targetDomain === sourceDomain) continue;
132
+
133
+ if (forbidden.includes(targetDomain)) {
134
+ violations.push({
135
+ file: relPath,
136
+ line: dep.line_number,
137
+ source_domain: sourceDomain,
138
+ target_domain: targetDomain,
139
+ imported_target: dep.target,
140
+ rule: "forbidden_dependency",
141
+ message: `Illegal import: Domain '${sourceDomain}' is strictly prohibited from importing domain '${targetDomain}'.`,
142
+ });
143
+ } else if (config.settings.enforcement === "strict" && !allowed.includes(targetDomain)) {
144
+ violations.push({
145
+ file: relPath,
146
+ line: dep.line_number,
147
+ source_domain: sourceDomain,
148
+ target_domain: targetDomain,
149
+ imported_target: dep.target,
150
+ rule: "disallowed_dependency",
151
+ message: `Disallowed dependency: '${targetDomain}' is not declared in allowed_dependencies for domain '${sourceDomain}'.`,
152
+ });
153
+ }
154
+ }
155
+ } catch {
156
+ // Ignore unparseable files
157
+ }
158
+ }
159
+
160
+ return violations;
161
+ }