septum 0.1.4 → 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 (67) 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 +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 -48
  13. package/src/cli/commands/sync.ts +31 -31
  14. package/src/cli/index.ts +210 -210
  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 +69 -69
  18. package/src/core/boundary/evaluator.ts +232 -210
  19. package/src/core/config/loader.ts +97 -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 +366 -349
  23. package/src/core/database/repositories/domain.repository.ts +218 -198
  24. package/src/core/database/repositories/file.repository.ts +116 -106
  25. package/src/core/database/repositories/meta.repository.ts +33 -33
  26. package/src/core/database/repositories/symbol.repository.ts +443 -443
  27. package/src/core/database/repository.ts +264 -260
  28. package/src/core/database/schema.ts +153 -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 +584 -535
  32. package/src/core/parser/boundary-tracker.ts +288 -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 +194 -194
  36. package/src/core/parser/extractors/go.ts +229 -180
  37. package/src/core/parser/extractors/laravel-semantic.ts +1039 -901
  38. package/src/core/parser/extractors/mcp-cli-semantic.ts +199 -199
  39. package/src/core/parser/extractors/nestjs-semantic.ts +119 -119
  40. package/src/core/parser/extractors/php.ts +153 -153
  41. package/src/core/parser/extractors/python.ts +228 -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 +181 -181
  45. package/src/core/parser/tree-sitter.ts +41 -41
  46. package/src/core/resolver/call-graph-tracer.ts +666 -668
  47. package/src/core/resolver/module-resolver.ts +408 -342
  48. package/src/core/resolver/path-resolver.ts +147 -147
  49. package/src/core/resolver/symbol-locator.ts +543 -543
  50. package/src/core/resolver/vertical-slice-tracer.ts +301 -285
  51. package/src/core/session/session-manager.ts +56 -56
  52. package/src/core/telemetry/telemetry.ts +86 -86
  53. package/src/index.ts +21 -21
  54. package/src/mcp/schemas.ts +578 -286
  55. package/src/mcp/server.ts +875 -716
  56. package/src/mcp/tools/check-boundary.ts +171 -152
  57. package/src/mcp/tools/get-domain-catalog.ts +145 -121
  58. package/src/mcp/tools/get-feature-context.ts +212 -116
  59. package/src/mcp/tools/get-symbol-hotspots.ts +60 -59
  60. package/src/mcp/tools/get-symbol-impact.ts +28 -26
  61. package/src/mcp/tools/get-symbol.ts +65 -63
  62. package/src/mcp/tools/locate-symbol.ts +171 -190
  63. package/src/mcp/tools/register-domain.ts +68 -64
  64. package/src/mcp/tools/register-feature.ts +100 -0
  65. package/src/mcp/tools/trace-vertical-slice.ts +74 -48
  66. package/src/types/index.ts +335 -315
  67. package/src/version.ts +3 -3
@@ -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
+ }