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,66 +1,66 @@
1
- export const SEPTUM_MAP_SKILL_TEMPLATE = `---
2
- name: septum-map
3
- description: Framework-agnostic codebase discovery, architectural domain mapping, and bounded-context initialization for Septum. Uses AI reasoning to map unknown project topologies (JS/TS, PHP, Python, Go), auto-registers bounded contexts into Septum's SQLite catalog, and enforces deterministic architectural boundaries.
4
- ---
5
-
6
- # \`septum-map\` — Framework-Agnostic Semantic Discovery & Bounded-Context Initialization
7
-
8
- > **Prinsip Utama:** AI Agent berperan sebagai *The Architect* untuk membedah topologi arsitektur proyek apa pun tanpa terikat pada framework tertentu, merumuskan batas bounded-context, dan mendaftarkannya langsung ke database deterministik (.septum/septum.db via septum_register_domain) agar AI coding berikutnya tidak mengalami context poisoning atau over-editing.
9
-
10
- ---
11
-
12
- ## 1. Landasan Riset & Filosofi Desain
13
-
14
- Skill ini berakar langsung pada riset rekayasa perangkat lunak terkemuka:
15
- 1. **Software Reflexion Models (Murphy, Notkin, & Sullivan, IEEE TSE):**
16
- Membedakan model arsitektur tingkat tinggi yang dirancang (*high-level intention*) dengan implementasi fisik di kode sumber. Septum mendeteksi *Divergences* (pelanggaran baru) dan *Absences* sebelum kode di-merge.
17
- 2. **Eliminasi Over-Editing (SWE-bench, RepoCoder - NeurIPS / ICLR):**
18
- Akar kegagalan agen AI terbesar adalah mengedit file di luar lokus tugas (*local scope myopia*). \`septum-map\` menetapkan *bounded context* dan *allowed touchpoints* sejak awal.
19
- 3. **Principle of Least Privilege & Object-Capabilities (Miller):**
20
- Agen hanya diberikan kapabilitas membaca dan mengubah file dalam domain/fitur aktif, memangkas *blast radius* kesalahan hingga mendekati nol.
21
- 4. **Hybrid Defense (SynCode / NeMo Guardrails):**
22
- Probabilistic AI digunakan untuk penalaran awal (*discovery & blueprinting*), sementara eksekusi dan penegakannya 100% deterministik (*Tree-sitter WASM, SQLite WAL, Pre-Commit Hooks*).
23
-
24
- ---
25
-
26
- ## 2. Kapan Wajib Menggunakan (Trigger Moments)
27
-
28
- Gunakan skill ini saat:
29
- 1. Menghubungkan Septum pertama kali ke repositori baru atau codebase yang belum terpetakan.
30
- 2. Memetakan ulang domain bisnis setelah terjadi refactoring arsitektur besar (*re-mapping*).
31
- 3. Mengonfigurasi fitur baru (\`features\` session) untuk mengunci daftar file yang boleh dimodifikasi (*allowed_touchpoints*) dan simbol yang wajib dipakai ulang (*reuse_symbols*).
32
- 4. Pengguna meminta inisialisasi cerdas berbasis pemahaman AI pada struktur proyek.
33
-
34
- ---
35
-
36
- ## 3. Alur Kerja 4 Langkah (The 4-Step Discovery Lifecycle)
37
-
38
- ### Langkah 1: Topological Scan (Maksimal 2 Tool Call)
39
- Analisis karakteristik proyek secara framework-agnostic:
40
- 1. **Periksa Manifest & Config Root:**
41
- * JS/TS: \`package.json\`, \`tsconfig.json\` (baca dependencies, path aliases).
42
- * PHP: \`composer.json\` (baca \`autoload.psr-4\`, framework dependencies).
43
- * Python: \`pyproject.toml\`, \`requirements.txt\`, \`setup.py\` (baca modules & framework).
44
- * Go: \`go.mod\` (baca module path).
45
- 2. **Petakan Direktori Tingkat Atas:**
46
- Identifikasi apakah proyek menggunakan pola:
47
- * *Domain-Driven / Vertical Slice:* \`src/domains/\`, \`app/Domain/\`, \`features/\`.
48
- * *Layered / Clean Architecture:* \`core/\`, \`infrastructure/\`, \`application/\`, \`interfaces/\`.
49
- * *Framework Conventional:* NestJS modules, Laravel app folders, FastAPI routers, Next.js route groups.
50
-
51
- ### Langkah 2: Semantic Blueprint Drafting & Domain Boundary Formulation
52
- Rumuskan spesifikasi domain dengan prinsip **Contract & Invariants (Bukan Prosedural)**:
53
- * **\`root\`:** Direktori fisik domain (gunakan path kanonikal).
54
- * **\`allowed_dependencies\`:** Domain mana saja yang sah diimpor (inbound whitelist).
55
- * **\`forbidden_dependencies\`:** Domain yang dilarang keras diimpor (outbound blacklist).
56
- * **\`archetypes\`:** Pola glob penamaan layer (\`service: "*Service.*"\`, \`model: "*Model.*"\`).
57
-
58
- ### Langkah 3: Human-in-the-Loop Approval Gate
59
- Tampilkan ringkasan domain boundary yang dirumuskan kepada pengguna / Tech Lead untuk disetujui atau disesuaikan sebelum didaftarkan.
60
-
61
- ### Langkah 4: Deterministic Registration & Ingestion
62
- Setelah disetujui:
63
- 1. Daftarkan domain secara langsung via tool MCP \`septum_register_domain(domain_name, root, ...)\` dengan opsi \`ingest_now: true\`.
64
- 2. Atau jalankan CLI \`septum ingest\` untuk mengekstrak seluruh simbol AST dan menyimpannya ke database SQLite \`.septum/septum.db\`.
65
- 3. Pastikan hook pre-commit terpasang aktif di \`.git/hooks/pre-commit\`.
66
- `;
1
+ export const SEPTUM_MAP_SKILL_TEMPLATE = `---
2
+ name: septum-map
3
+ description: Framework-agnostic codebase discovery, architectural domain mapping, and bounded-context initialization for Septum. Uses AI reasoning to map unknown project topologies (JS/TS, PHP, Python, Go), auto-registers bounded contexts into Septum's SQLite catalog, and enforces deterministic architectural boundaries.
4
+ ---
5
+
6
+ # \`septum-map\` — Framework-Agnostic Semantic Discovery & Bounded-Context Initialization
7
+
8
+ > **Prinsip Utama:** AI Agent berperan sebagai *The Architect* untuk membedah topologi arsitektur proyek apa pun tanpa terikat pada framework tertentu, merumuskan batas bounded-context, dan mendaftarkannya langsung ke database deterministik (.septum/septum.db via septum_register_domain) agar AI coding berikutnya tidak mengalami context poisoning atau over-editing.
9
+
10
+ ---
11
+
12
+ ## 1. Landasan Riset & Filosofi Desain
13
+
14
+ Skill ini berakar langsung pada riset rekayasa perangkat lunak terkemuka:
15
+ 1. **Software Reflexion Models (Murphy, Notkin, & Sullivan, IEEE TSE):**
16
+ Membedakan model arsitektur tingkat tinggi yang dirancang (*high-level intention*) dengan implementasi fisik di kode sumber. Septum mendeteksi *Divergences* (pelanggaran baru) dan *Absences* sebelum kode di-merge.
17
+ 2. **Eliminasi Over-Editing (SWE-bench, RepoCoder - NeurIPS / ICLR):**
18
+ Akar kegagalan agen AI terbesar adalah mengedit file di luar lokus tugas (*local scope myopia*). \`septum-map\` menetapkan *bounded context* dan *allowed touchpoints* sejak awal.
19
+ 3. **Principle of Least Privilege & Object-Capabilities (Miller):**
20
+ Agen hanya diberikan kapabilitas membaca dan mengubah file dalam domain/fitur aktif, memangkas *blast radius* kesalahan hingga mendekati nol.
21
+ 4. **Hybrid Defense (SynCode / NeMo Guardrails):**
22
+ Probabilistic AI digunakan untuk penalaran awal (*discovery & blueprinting*), sementara eksekusi dan penegakannya 100% deterministik (*Tree-sitter WASM, SQLite WAL, Pre-Commit Hooks*).
23
+
24
+ ---
25
+
26
+ ## 2. Kapan Wajib Menggunakan (Trigger Moments)
27
+
28
+ Gunakan skill ini saat:
29
+ 1. Menghubungkan Septum pertama kali ke repositori baru atau codebase yang belum terpetakan.
30
+ 2. Memetakan ulang domain bisnis setelah terjadi refactoring arsitektur besar (*re-mapping*).
31
+ 3. Mengonfigurasi fitur baru (\`features\` session) untuk mengunci daftar file yang boleh dimodifikasi (*allowed_touchpoints*) dan simbol yang wajib dipakai ulang (*reuse_symbols*).
32
+ 4. Pengguna meminta inisialisasi cerdas berbasis pemahaman AI pada struktur proyek.
33
+
34
+ ---
35
+
36
+ ## 3. Alur Kerja 4 Langkah (The 4-Step Discovery Lifecycle)
37
+
38
+ ### Langkah 1: Topological Scan (Maksimal 2 Tool Call)
39
+ Analisis karakteristik proyek secara framework-agnostic:
40
+ 1. **Periksa Manifest & Config Root:**
41
+ * JS/TS: \`package.json\`, \`tsconfig.json\` (baca dependencies, path aliases).
42
+ * PHP: \`composer.json\` (baca \`autoload.psr-4\`, framework dependencies).
43
+ * Python: \`pyproject.toml\`, \`requirements.txt\`, \`setup.py\` (baca modules & framework).
44
+ * Go: \`go.mod\` (baca module path).
45
+ 2. **Petakan Direktori Tingkat Atas:**
46
+ Identifikasi apakah proyek menggunakan pola:
47
+ * *Domain-Driven / Vertical Slice:* \`src/domains/\`, \`app/Domain/\`, \`features/\`.
48
+ * *Layered / Clean Architecture:* \`core/\`, \`infrastructure/\`, \`application/\`, \`interfaces/\`.
49
+ * *Framework Conventional:* NestJS modules, Laravel app folders, FastAPI routers, Next.js route groups.
50
+
51
+ ### Langkah 2: Semantic Blueprint Drafting & Domain Boundary Formulation
52
+ Rumuskan spesifikasi domain dengan prinsip **Contract & Invariants (Bukan Prosedural)**:
53
+ * **\`root\`:** Direktori fisik domain (gunakan path kanonikal).
54
+ * **\`allowed_dependencies\`:** Domain mana saja yang sah diimpor (inbound whitelist).
55
+ * **\`forbidden_dependencies\`:** Domain yang dilarang keras diimpor (outbound blacklist).
56
+ * **\`archetypes\`:** Pola glob penamaan layer (\`service: "*Service.*"\`, \`model: "*Model.*"\`).
57
+
58
+ ### Langkah 3: Human-in-the-Loop Approval Gate
59
+ Tampilkan ringkasan domain boundary yang dirumuskan kepada pengguna / Tech Lead untuk disetujui atau disesuaikan sebelum didaftarkan.
60
+
61
+ ### Langkah 4: Deterministic Registration & Ingestion
62
+ Setelah disetujui:
63
+ 1. Daftarkan domain secara langsung via tool MCP \`septum_register_domain(domain_name, root, ...)\` dengan opsi \`ingest_now: true\`.
64
+ 2. Atau jalankan CLI \`septum ingest\` untuk mengekstrak seluruh simbol AST dan menyimpannya ke database SQLite \`.septum/septum.db\`.
65
+ 3. Pastikan hook pre-commit terpasang aktif di \`.git/hooks/pre-commit\`.
66
+ `;
@@ -1,210 +1,210 @@
1
- import type { BoundaryViolation } from "../../types/index.ts";
2
- import type { ValidatedSeptumConfig } from "../config/schema.ts";
3
- import { ConfigLoader } from "../config/loader.ts";
4
- import type { SeptumRepository } from "../database/repository.ts";
5
- import { ModuleResolver } from "../resolver/module-resolver.ts";
6
-
7
- export class BoundaryEvaluator {
8
- private repo: SeptumRepository;
9
- private resolver: ModuleResolver;
10
-
11
- constructor(repo: SeptumRepository, resolver?: ModuleResolver) {
12
- this.repo = repo;
13
- this.resolver = resolver ?? new ModuleResolver(process.cwd(), repo);
14
- }
15
-
16
- public getResolver(): ModuleResolver {
17
- return this.resolver;
18
- }
19
-
20
- public evaluate(
21
- filePath: string,
22
- proposedImports: string[] = [],
23
- featureKey?: string,
24
- config?: ValidatedSeptumConfig
25
- ): BoundaryViolation[] {
26
- const activeConfig = config ?? ConfigLoader.loadFromDatabaseOrDefaults();
27
- const violations: BoundaryViolation[] = [];
28
-
29
- if (featureKey) {
30
- violations.push(...this.checkFeatureTouchpoints(featureKey, filePath, activeConfig));
31
- }
32
-
33
- if (proposedImports.length > 0) {
34
- violations.push(...this.checkProposedChanges(filePath, proposedImports, activeConfig));
35
- }
36
-
37
- return violations;
38
- }
39
-
40
- public auditCodebase(config: ValidatedSeptumConfig): BoundaryViolation[] {
41
- const violations: BoundaryViolation[] = [];
42
- const allDependencies = this.repo.getAllDependenciesWithDomains();
43
-
44
- for (const dep of allDependencies) {
45
- const targetDomain = this.resolveTargetDomain(dep.target, config, dep.source_file);
46
- if (!targetDomain || targetDomain === dep.source_domain) {
47
- continue;
48
- }
49
-
50
- const sourceDomainConfig = config.domains[dep.source_domain];
51
- if (!sourceDomainConfig) {
52
- continue;
53
- }
54
-
55
- const forbidden = sourceDomainConfig.forbidden_dependencies ?? [];
56
- const allowed = sourceDomainConfig.allowed_dependencies ?? [];
57
-
58
- // 1. Explicit forbidden check
59
- if (forbidden.includes(targetDomain)) {
60
- violations.push({
61
- file: dep.source_file,
62
- line: dep.line_number,
63
- source_domain: dep.source_domain,
64
- target_domain: targetDomain,
65
- imported_target: dep.target,
66
- rule: "forbidden_dependency",
67
- message: `Forbidden cross-domain dependency detected: '${dep.source_domain}' is strictly prohibited from importing domain '${targetDomain}'.`,
68
- });
69
- continue;
70
- }
71
-
72
- // 2. Strict enforcement allowed check
73
- if (config.settings.enforcement === "strict" && !allowed.includes(targetDomain)) {
74
- violations.push({
75
- file: dep.source_file,
76
- line: dep.line_number,
77
- source_domain: dep.source_domain,
78
- target_domain: targetDomain,
79
- imported_target: dep.target,
80
- rule: "disallowed_dependency",
81
- message: `Disallowed dependency: '${targetDomain}' is not declared in allowed_dependencies for domain '${dep.source_domain}'.`,
82
- });
83
- }
84
- }
85
-
86
- return violations;
87
- }
88
-
89
- public checkProposedChanges(
90
- sourceFilePath: string,
91
- proposedImports: string[],
92
- config: ValidatedSeptumConfig
93
- ): BoundaryViolation[] {
94
- const violations: BoundaryViolation[] = [];
95
- const sourceDomain = this.resolveSourceDomain(sourceFilePath, config);
96
-
97
- if (!sourceDomain) {
98
- return violations;
99
- }
100
-
101
- const sourceDomainConfig = config.domains[sourceDomain];
102
- if (!sourceDomainConfig) {
103
- return violations;
104
- }
105
-
106
- const forbidden = sourceDomainConfig.forbidden_dependencies ?? [];
107
- const allowed = sourceDomainConfig.allowed_dependencies ?? [];
108
-
109
- for (const statement of proposedImports) {
110
- const targetDomain = this.resolveTargetDomain(statement, config, sourceFilePath);
111
- if (!targetDomain || targetDomain === sourceDomain) {
112
- continue;
113
- }
114
-
115
- if (forbidden.includes(targetDomain)) {
116
- violations.push({
117
- file: sourceFilePath,
118
- line: 1,
119
- source_domain: sourceDomain,
120
- target_domain: targetDomain,
121
- imported_target: statement,
122
- rule: "forbidden_dependency",
123
- message: `Illegal import blocked: Domain '${sourceDomain}' is strictly forbidden from importing domain '${targetDomain}'.`,
124
- });
125
- } else if (config.settings.enforcement === "strict" && !allowed.includes(targetDomain)) {
126
- violations.push({
127
- file: sourceFilePath,
128
- line: 1,
129
- source_domain: sourceDomain,
130
- target_domain: targetDomain,
131
- imported_target: statement,
132
- rule: "disallowed_dependency",
133
- message: `Unlisted domain dependency: '${targetDomain}' must be explicitly added to allowed_dependencies before domain '${sourceDomain}' can import it.`,
134
- });
135
- }
136
- }
137
-
138
- return violations;
139
- }
140
-
141
- public resolveSourceDomain(filePath: string, config: ValidatedSeptumConfig): string | null {
142
- return this.resolver.resolveSourceDomain(filePath, config);
143
- }
144
-
145
- public resolveTargetDomain(
146
- targetStatement: string,
147
- config: ValidatedSeptumConfig,
148
- sourceFilePath?: string
149
- ): string | null {
150
- return this.resolver.resolveTargetDomain(targetStatement, sourceFilePath, config);
151
- }
152
-
153
- public checkFeatureTouchpoints(
154
- featureKey: string,
155
- targetFilePath: string,
156
- config: ValidatedSeptumConfig
157
- ): BoundaryViolation[] {
158
- const violations: BoundaryViolation[] = [];
159
- const features = config.features ?? {};
160
- const featureConfig = features[featureKey];
161
-
162
- if (!featureConfig) {
163
- violations.push({
164
- file: targetFilePath,
165
- line: 1,
166
- source_domain: "unknown",
167
- target_domain: "unknown",
168
- imported_target: targetFilePath,
169
- rule: "unknown_feature",
170
- message: `Feature '${featureKey}' is not defined in septum configuration.`,
171
- });
172
- return violations;
173
- }
174
-
175
- const normalizedTarget = targetFilePath.replace(/\\/g, "/").replace(/^\.\//, "");
176
- const allowedTouchpoints = featureConfig.allowed_touchpoints.map((tp) =>
177
- tp.replace(/\\/g, "/").replace(/^\.\//, "")
178
- );
179
-
180
- const isAllowed = allowedTouchpoints.some((pattern) => {
181
- if (pattern.endsWith("/**")) {
182
- const prefix = pattern.slice(0, -3);
183
- return normalizedTarget.startsWith(prefix);
184
- }
185
- if (pattern.endsWith("/*")) {
186
- const prefix = pattern.slice(0, -2);
187
- return normalizedTarget.startsWith(prefix);
188
- }
189
- return (
190
- normalizedTarget === pattern ||
191
- normalizedTarget.endsWith("/" + pattern) ||
192
- pattern.endsWith("/" + normalizedTarget)
193
- );
194
- });
195
-
196
- if (!isAllowed) {
197
- violations.push({
198
- file: targetFilePath,
199
- line: 1,
200
- source_domain: featureConfig.domain,
201
- target_domain: "unknown",
202
- imported_target: targetFilePath,
203
- rule: "touchpoint_violation",
204
- message: `Scope violation: File '${targetFilePath}' is outside the declared allowed_touchpoints for feature '${featureKey}'. Permitted: [${allowedTouchpoints.join(", ")}].`,
205
- });
206
- }
207
-
208
- return violations;
209
- }
210
- }
1
+ import type { BoundaryViolation } from "../../types/index.ts";
2
+ import type { ValidatedSeptumConfig } from "../config/schema.ts";
3
+ import { ConfigLoader } from "../config/loader.ts";
4
+ import type { SeptumRepository } from "../database/repository.ts";
5
+ import { ModuleResolver } from "../resolver/module-resolver.ts";
6
+
7
+ export class BoundaryEvaluator {
8
+ private repo: SeptumRepository;
9
+ private resolver: ModuleResolver;
10
+
11
+ constructor(repo: SeptumRepository, resolver?: ModuleResolver) {
12
+ this.repo = repo;
13
+ this.resolver = resolver ?? new ModuleResolver(process.cwd(), repo);
14
+ }
15
+
16
+ public getResolver(): ModuleResolver {
17
+ return this.resolver;
18
+ }
19
+
20
+ public evaluate(
21
+ filePath: string,
22
+ proposedImports: string[] = [],
23
+ featureKey?: string,
24
+ config?: ValidatedSeptumConfig
25
+ ): BoundaryViolation[] {
26
+ const activeConfig = config ?? ConfigLoader.loadFromDatabaseOrDefaults();
27
+ const violations: BoundaryViolation[] = [];
28
+
29
+ if (featureKey) {
30
+ violations.push(...this.checkFeatureTouchpoints(featureKey, filePath, activeConfig));
31
+ }
32
+
33
+ if (proposedImports.length > 0) {
34
+ violations.push(...this.checkProposedChanges(filePath, proposedImports, activeConfig));
35
+ }
36
+
37
+ return violations;
38
+ }
39
+
40
+ public auditCodebase(config: ValidatedSeptumConfig): BoundaryViolation[] {
41
+ const violations: BoundaryViolation[] = [];
42
+ const allDependencies = this.repo.getAllDependenciesWithDomains();
43
+
44
+ for (const dep of allDependencies) {
45
+ const targetDomain = this.resolveTargetDomain(dep.target, config, dep.source_file);
46
+ if (!targetDomain || targetDomain === dep.source_domain) {
47
+ continue;
48
+ }
49
+
50
+ const sourceDomainConfig = config.domains[dep.source_domain];
51
+ if (!sourceDomainConfig) {
52
+ continue;
53
+ }
54
+
55
+ const forbidden = sourceDomainConfig.forbidden_dependencies ?? [];
56
+ const allowed = sourceDomainConfig.allowed_dependencies ?? [];
57
+
58
+ // 1. Explicit forbidden check
59
+ if (forbidden.includes(targetDomain)) {
60
+ violations.push({
61
+ file: dep.source_file,
62
+ line: dep.line_number,
63
+ source_domain: dep.source_domain,
64
+ target_domain: targetDomain,
65
+ imported_target: dep.target,
66
+ rule: "forbidden_dependency",
67
+ message: `Forbidden cross-domain dependency detected: '${dep.source_domain}' is strictly prohibited from importing domain '${targetDomain}'.`,
68
+ });
69
+ continue;
70
+ }
71
+
72
+ // 2. Strict enforcement allowed check
73
+ if (config.settings.enforcement === "strict" && !allowed.includes(targetDomain)) {
74
+ violations.push({
75
+ file: dep.source_file,
76
+ line: dep.line_number,
77
+ source_domain: dep.source_domain,
78
+ target_domain: targetDomain,
79
+ imported_target: dep.target,
80
+ rule: "disallowed_dependency",
81
+ message: `Disallowed dependency: '${targetDomain}' is not declared in allowed_dependencies for domain '${dep.source_domain}'.`,
82
+ });
83
+ }
84
+ }
85
+
86
+ return violations;
87
+ }
88
+
89
+ public checkProposedChanges(
90
+ sourceFilePath: string,
91
+ proposedImports: string[],
92
+ config: ValidatedSeptumConfig
93
+ ): BoundaryViolation[] {
94
+ const violations: BoundaryViolation[] = [];
95
+ const sourceDomain = this.resolveSourceDomain(sourceFilePath, config);
96
+
97
+ if (!sourceDomain) {
98
+ return violations;
99
+ }
100
+
101
+ const sourceDomainConfig = config.domains[sourceDomain];
102
+ if (!sourceDomainConfig) {
103
+ return violations;
104
+ }
105
+
106
+ const forbidden = sourceDomainConfig.forbidden_dependencies ?? [];
107
+ const allowed = sourceDomainConfig.allowed_dependencies ?? [];
108
+
109
+ for (const statement of proposedImports) {
110
+ const targetDomain = this.resolveTargetDomain(statement, config, sourceFilePath);
111
+ if (!targetDomain || targetDomain === sourceDomain) {
112
+ continue;
113
+ }
114
+
115
+ if (forbidden.includes(targetDomain)) {
116
+ violations.push({
117
+ file: sourceFilePath,
118
+ line: 1,
119
+ source_domain: sourceDomain,
120
+ target_domain: targetDomain,
121
+ imported_target: statement,
122
+ rule: "forbidden_dependency",
123
+ message: `Illegal import blocked: Domain '${sourceDomain}' is strictly forbidden from importing domain '${targetDomain}'.`,
124
+ });
125
+ } else if (config.settings.enforcement === "strict" && !allowed.includes(targetDomain)) {
126
+ violations.push({
127
+ file: sourceFilePath,
128
+ line: 1,
129
+ source_domain: sourceDomain,
130
+ target_domain: targetDomain,
131
+ imported_target: statement,
132
+ rule: "disallowed_dependency",
133
+ message: `Unlisted domain dependency: '${targetDomain}' must be explicitly added to allowed_dependencies before domain '${sourceDomain}' can import it.`,
134
+ });
135
+ }
136
+ }
137
+
138
+ return violations;
139
+ }
140
+
141
+ public resolveSourceDomain(filePath: string, config: ValidatedSeptumConfig): string | null {
142
+ return this.resolver.resolveSourceDomain(filePath, config);
143
+ }
144
+
145
+ public resolveTargetDomain(
146
+ targetStatement: string,
147
+ config: ValidatedSeptumConfig,
148
+ sourceFilePath?: string
149
+ ): string | null {
150
+ return this.resolver.resolveTargetDomain(targetStatement, sourceFilePath, config);
151
+ }
152
+
153
+ public checkFeatureTouchpoints(
154
+ featureKey: string,
155
+ targetFilePath: string,
156
+ config: ValidatedSeptumConfig
157
+ ): BoundaryViolation[] {
158
+ const violations: BoundaryViolation[] = [];
159
+ const features = config.features ?? {};
160
+ const featureConfig = features[featureKey];
161
+
162
+ if (!featureConfig) {
163
+ violations.push({
164
+ file: targetFilePath,
165
+ line: 1,
166
+ source_domain: "unknown",
167
+ target_domain: "unknown",
168
+ imported_target: targetFilePath,
169
+ rule: "unknown_feature",
170
+ message: `Feature '${featureKey}' is not defined in septum configuration.`,
171
+ });
172
+ return violations;
173
+ }
174
+
175
+ const normalizedTarget = targetFilePath.replace(/\\/g, "/").replace(/^\.\//, "");
176
+ const allowedTouchpoints = featureConfig.allowed_touchpoints.map((tp) =>
177
+ tp.replace(/\\/g, "/").replace(/^\.\//, "")
178
+ );
179
+
180
+ const isAllowed = allowedTouchpoints.some((pattern) => {
181
+ if (pattern.endsWith("/**")) {
182
+ const prefix = pattern.slice(0, -3);
183
+ return normalizedTarget.startsWith(prefix);
184
+ }
185
+ if (pattern.endsWith("/*")) {
186
+ const prefix = pattern.slice(0, -2);
187
+ return normalizedTarget.startsWith(prefix);
188
+ }
189
+ return (
190
+ normalizedTarget === pattern ||
191
+ normalizedTarget.endsWith("/" + pattern) ||
192
+ pattern.endsWith("/" + normalizedTarget)
193
+ );
194
+ });
195
+
196
+ if (!isAllowed) {
197
+ violations.push({
198
+ file: targetFilePath,
199
+ line: 1,
200
+ source_domain: featureConfig.domain,
201
+ target_domain: "unknown",
202
+ imported_target: targetFilePath,
203
+ rule: "touchpoint_violation",
204
+ message: `Scope violation: File '${targetFilePath}' is outside the declared allowed_touchpoints for feature '${featureKey}'. Permitted: [${allowedTouchpoints.join(", ")}].`,
205
+ });
206
+ }
207
+
208
+ return violations;
209
+ }
210
+ }