@dimassetoid/septum-mcp 0.2.1 → 0.5.0

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 (161) hide show
  1. package/README.md +46 -45
  2. package/package.json +8 -6
  3. package/src/cli/commands/check.ts +41 -26
  4. package/src/cli/commands/hook.ts +77 -105
  5. package/src/cli/commands/init.ts +35 -9
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +35 -9
  9. package/src/cli/hook-payload.ts +43 -0
  10. package/src/cli/index.ts +15 -51
  11. package/src/cli/scaffold/harness-config.ts +48 -8
  12. package/src/cli/templates/hooks.ts +51 -27
  13. package/src/cli/templates/rules.ts +34 -49
  14. package/src/cli/templates/skill.ts +46 -35
  15. package/src/core/boundary/audit.ts +383 -0
  16. package/src/core/boundary/evaluator.ts +299 -178
  17. package/src/core/boundary/staged-auditor.ts +188 -34
  18. package/src/core/config/domain-ownership.ts +47 -0
  19. package/src/core/config/domain-registration.ts +141 -0
  20. package/src/core/config/loader.ts +82 -54
  21. package/src/core/config/schema.ts +24 -46
  22. package/src/core/database/client.ts +2 -0
  23. package/src/core/database/repositories/dependency.repository.ts +326 -543
  24. package/src/core/database/repositories/domain.repository.ts +48 -4
  25. package/src/core/database/repositories/file.repository.ts +10 -0
  26. package/src/core/database/repositories/symbol.repository.ts +97 -259
  27. package/src/core/database/repository.ts +138 -24
  28. package/src/core/database/schema.ts +28 -33
  29. package/src/core/discovery/declarative-routes.ts +69 -0
  30. package/src/core/discovery/framework-detector.ts +149 -0
  31. package/src/core/discovery/navigation.ts +269 -0
  32. package/src/core/discovery/topology-detector.ts +153 -170
  33. package/src/core/errors.ts +19 -0
  34. package/src/core/ingestion/pipeline.ts +378 -212
  35. package/src/core/parser/behavioral-analyzer.ts +26 -22
  36. package/src/core/parser/boundary-tracker.ts +15 -0
  37. package/src/core/parser/extractors/base.ts +16 -4
  38. package/src/core/parser/extractors/csharp.ts +9 -5
  39. package/src/core/parser/extractors/django-routing.ts +163 -0
  40. package/src/core/parser/extractors/django-semantic.ts +400 -516
  41. package/src/core/parser/extractors/elysia-semantic.ts +172 -496
  42. package/src/core/parser/extractors/express-semantic.ts +195 -398
  43. package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
  44. package/src/core/parser/extractors/fastify-semantic.ts +216 -732
  45. package/src/core/parser/extractors/flask-semantic.ts +92 -388
  46. package/src/core/parser/extractors/go-routing.ts +344 -0
  47. package/src/core/parser/extractors/go-semantic.ts +210 -508
  48. package/src/core/parser/extractors/go.ts +6 -3
  49. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  50. package/src/core/parser/extractors/hono-semantic.ts +132 -530
  51. package/src/core/parser/extractors/java.ts +7 -5
  52. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  53. package/src/core/parser/extractors/laravel-semantic.ts +169 -333
  54. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  55. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  56. package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
  57. package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
  58. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  59. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  60. package/src/core/parser/extractors/php.ts +17 -1
  61. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  62. package/src/core/parser/extractors/python.ts +9 -8
  63. package/src/core/parser/extractors/registry.ts +28 -5
  64. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  65. package/src/core/parser/extractors/ruby.ts +10 -7
  66. package/src/core/parser/extractors/rust.ts +35 -17
  67. package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
  68. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  69. package/src/core/parser/extractors/symfony-semantic.ts +75 -262
  70. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  71. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  72. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  73. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  74. package/src/core/parser/extractors/typescript.ts +36 -216
  75. package/src/core/parser/implementation-fingerprint.ts +97 -0
  76. package/src/core/parser/language-capabilities.ts +23 -7
  77. package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
  78. package/src/core/parser/schema/schema-provider-registry.ts +1 -3
  79. package/src/core/parser/schema/schema-provider.interface.ts +2 -1
  80. package/src/core/parser/semantic-revision.ts +3 -0
  81. package/src/core/parser/static-string.ts +51 -0
  82. package/src/core/parser/wasm-loader.ts +6 -2
  83. package/src/core/resolver/ast-method-tracer.ts +230 -0
  84. package/src/core/resolver/call-graph-helpers.ts +72 -0
  85. package/src/core/resolver/call-graph-tracer.ts +375 -311
  86. package/src/core/resolver/dependency-analysis.ts +593 -0
  87. package/src/core/resolver/import-candidates.ts +120 -0
  88. package/src/core/resolver/import-evidence.ts +88 -0
  89. package/src/core/resolver/import-resolver.ts +162 -181
  90. package/src/core/resolver/interpretation-inputs.ts +65 -0
  91. package/src/core/resolver/languages/go.ts +103 -0
  92. package/src/core/resolver/languages/managed.ts +200 -0
  93. package/src/core/resolver/languages/python.ts +133 -0
  94. package/src/core/resolver/languages/ruby.ts +40 -0
  95. package/src/core/resolver/languages/rust.ts +127 -0
  96. package/src/core/resolver/languages/shared.ts +74 -0
  97. package/src/core/resolver/module-resolver.ts +18 -7
  98. package/src/core/resolver/path-resolver.ts +6 -3
  99. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  100. package/src/core/resolver/slice-catalog.ts +94 -0
  101. package/src/core/resolver/slice-format.ts +22 -0
  102. package/src/core/resolver/slice-selection.ts +237 -0
  103. package/src/core/resolver/symbol-impact.ts +477 -0
  104. package/src/core/resolver/symbol-locator.ts +82 -15
  105. package/src/core/resolver/vertical-slice-tracer.ts +57 -278
  106. package/src/core/resources/ignore.ts +21 -1
  107. package/src/core/resources/limits.ts +2 -1
  108. package/src/core/resources/source-files.ts +143 -20
  109. package/src/core/resources/source-inventory.ts +55 -0
  110. package/src/core/resources/work-queue.ts +167 -4
  111. package/src/core/retrieval/context-page.ts +116 -0
  112. package/src/core/retrieval/context.ts +457 -0
  113. package/src/core/retrieval/resolution-warnings.ts +21 -0
  114. package/src/core/retrieval/source-context.ts +448 -0
  115. package/src/core/retrieval/symbol-details.ts +453 -0
  116. package/src/core/retrieval/symbol-evidence.ts +97 -0
  117. package/src/core/retrieval/typescript-references.ts +293 -0
  118. package/src/core/retrieval/universal-context.ts +182 -0
  119. package/src/core/telemetry/summary.ts +114 -0
  120. package/src/core/telemetry/telemetry.ts +225 -37
  121. package/src/index.ts +0 -3
  122. package/src/mcp/formatters/compact-text.ts +439 -0
  123. package/src/mcp/resources-and-prompts.ts +253 -0
  124. package/src/mcp/schemas/boundary.ts +145 -0
  125. package/src/mcp/schemas/map.ts +250 -0
  126. package/src/mcp/schemas/shared.ts +52 -0
  127. package/src/mcp/schemas/slice.ts +60 -0
  128. package/src/mcp/schemas/symbol.ts +268 -0
  129. package/src/mcp/schemas.ts +5 -1105
  130. package/src/mcp/server.ts +263 -597
  131. package/src/mcp/tool-catalog.ts +331 -0
  132. package/src/mcp/tools/boundary.ts +69 -4
  133. package/src/mcp/tools/map.ts +126 -0
  134. package/src/mcp/tools/slice.ts +101 -3
  135. package/src/mcp/tools/symbol.ts +480 -26
  136. package/src/mcp/ui/app-client.ts +899 -0
  137. package/src/mcp/ui/app.html +478 -0
  138. package/src/mcp/workflow-playbooks.ts +181 -0
  139. package/src/mcp/workspace-boundary.ts +50 -0
  140. package/src/mcp/workspace-manager.ts +102 -18
  141. package/src/mcp/workspace-watcher.ts +38 -19
  142. package/src/types/index.ts +47 -53
  143. package/src/cli/commands/topology.ts +0 -161
  144. package/src/core/database/repositories/environment.repository.ts +0 -207
  145. package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
  146. package/src/core/session/session-manager.ts +0 -107
  147. package/src/core/topology/environment-detector.ts +0 -973
  148. package/src/core/topology/types.ts +0 -83
  149. package/src/mcp/tools/check-boundary.ts +0 -387
  150. package/src/mcp/tools/domain.ts +0 -40
  151. package/src/mcp/tools/feature.ts +0 -67
  152. package/src/mcp/tools/get-domain-catalog.ts +0 -226
  153. package/src/mcp/tools/get-environment-topology.ts +0 -138
  154. package/src/mcp/tools/get-feature-context.ts +0 -224
  155. package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
  156. package/src/mcp/tools/get-symbol-impact.ts +0 -64
  157. package/src/mcp/tools/get-symbol.ts +0 -175
  158. package/src/mcp/tools/locate-symbol.ts +0 -196
  159. package/src/mcp/tools/register-domain.ts +0 -75
  160. package/src/mcp/tools/register-feature.ts +0 -110
  161. package/src/mcp/tools/trace-vertical-slice.ts +0 -80
@@ -0,0 +1,383 @@
1
+ import type { ImportEvidence } from "../resolver/import-evidence.ts";
2
+ import { relative, resolve } from "node:path";
3
+ import { auditStagedFiles } from "../boundary/staged-auditor.ts";
4
+ import type { BoundaryEvaluator } from "../boundary/evaluator.ts";
5
+ import { ConfigLoader } from "../config/loader.ts";
6
+ import type { ValidatedSeptumConfig } from "../config/schema.ts";
7
+ import type { SeptumRepository } from "../database/repository.ts";
8
+ import type { BoundaryViolation } from "../../types/index.ts";
9
+
10
+ export interface BoundaryAuditRequest {
11
+ file_path?: string;
12
+ file_paths?: string[];
13
+ proposed_imports?: string[];
14
+ proposed_imports_supplied?: boolean;
15
+ scope?: "file" | "all" | "staged" | "domain";
16
+ domain?: string;
17
+ staged?: boolean;
18
+ }
19
+
20
+ interface BoundaryAuditPayload {
21
+ status: "approved" | "rejected" | "unknown";
22
+ message: string;
23
+ violations?: BoundaryViolation[];
24
+ unsupported_files?: string[];
25
+ skipped_files?: { path: string; reason: string }[];
26
+ relationships?: ReturnType<SeptumRepository["getImportRelationships"]>;
27
+ }
28
+
29
+ function incompleteEvidence<T extends BoundaryAuditPayload>(payload: T) {
30
+ return { payload, kind: "incomplete_evidence" as const };
31
+ }
32
+
33
+ function evaluated<T extends BoundaryAuditPayload>(payload: T) {
34
+ return { payload, kind: "evaluated" as const };
35
+ }
36
+
37
+ function summarizeViolations(violations: BoundaryViolation[]) {
38
+ const circularDependencies = violations.filter((v) => v.rule === "circular_dependency");
39
+ const domainBreakdown: Record<string, number> = {};
40
+ for (const v of violations) {
41
+ const pair = `${v.source_domain} -> ${v.target_domain}`;
42
+ domainBreakdown[pair] = (domainBreakdown[pair] || 0) + 1;
43
+ }
44
+ return {
45
+ circular_dependencies_count: circularDependencies.length,
46
+ circular_dependencies: circularDependencies,
47
+ domain_violation_breakdown: domainBreakdown,
48
+ };
49
+ }
50
+
51
+ export async function evaluateBoundary(
52
+ evaluator: BoundaryEvaluator,
53
+ loadedConfig: ValidatedSeptumConfig,
54
+ args: BoundaryAuditRequest,
55
+ repo: SeptumRepository | undefined,
56
+ root: string
57
+ ) {
58
+ // Ingestion retains or discovers domains when file policy does not name any.
59
+ // Use those indexed policies while keeping the explicitly loaded settings.
60
+ const config = repo && Object.keys(loadedConfig.domains).length === 0
61
+ ? { ...loadedConfig, domains: ConfigLoader.loadFromRepository(repo).domains }
62
+ : loadedConfig;
63
+ if (args.domain) {
64
+ const knownDomains = new Set([
65
+ ...Object.keys(config.domains || {}),
66
+ ...(repo?.getAllDomains?.().map((d) => d.name) ?? []),
67
+ ]);
68
+ const domain = [...knownDomains].find(name => name.toLowerCase() === args.domain!.toLowerCase());
69
+ if (!domain) throw new Error(`Unknown boundary domain '${args.domain}'. Choose a registered domain.`);
70
+ args = { ...args, domain };
71
+ }
72
+ const proposedImports = args.proposed_imports ?? [];
73
+ const evaluatedScope = { mode: "proposal", proposed_imports_supplied: args.proposed_imports_supplied, existing_imports_checked: false, omissions: ["Existing file imports are not certified by proposal approval."] };
74
+
75
+ const requested = [...(Array.isArray(args.file_path) ? args.file_path : args.file_path ? [args.file_path] : []), ...(args.file_paths || [])]
76
+ .map(file => relative(root, resolve(root, file)).replace(/\\/g, "/"));
77
+ const effectiveScope = requested.length > 0
78
+ ? "file"
79
+ : (args.scope ?? (args.staged ? "staged" : args.domain ? "domain" : "all"));
80
+
81
+ const syncState = repo?.getMeta("sync_state");
82
+ const syncError = repo?.getMeta("sync_error");
83
+ if (!syncState || syncState === "running" || syncState === "error" || syncState !== "complete" || syncError) {
84
+ return incompleteEvidence({
85
+ status: "unknown",
86
+ scope: effectiveScope,
87
+ ...(args.domain ? { domain: args.domain } : {}),
88
+ sync_state: syncState || "unindexed",
89
+ sync_error: syncError || undefined,
90
+ message: "Boundary audit is incomplete because workspace synchronization has not completed.",
91
+ });
92
+ }
93
+ const skipped = JSON.parse(repo?.getMeta("skipped_files") || "[]") as {path: string; reason: string}[];
94
+ const unsupported = JSON.parse(repo?.getMeta("unsupported_files") || "[]") as string[];
95
+ const relevantUnsupported = unsupported.filter(file =>
96
+ (!args.domain || evaluator.resolveSourceDomain(file, config) === args.domain) &&
97
+ (requested.length === 0 || requested.includes(file))
98
+ );
99
+ const relevantSkipped = skipped.filter(file =>
100
+ (!args.domain || evaluator.resolveSourceDomain(file.path, config) === args.domain) &&
101
+ (requested.length === 0 || requested.includes(file.path))
102
+ );
103
+ if (relevantSkipped.length > 0 && args.scope !== "staged" && !args.staged) {
104
+ return incompleteEvidence({status: "unknown", scope: effectiveScope, ...(args.domain ? { domain: args.domain } : {}), skipped_files: relevantSkipped, message: "Boundary audit is incomplete because source files exceed resource limits."});
105
+ }
106
+ if (relevantUnsupported.length > 0 && args.scope !== "staged" && !args.staged) {
107
+ return incompleteEvidence({ status: "unknown", scope: effectiveScope, ...(args.domain ? { domain: args.domain } : {}), unsupported_files: relevantUnsupported, message: "Boundary audit is incomplete because source files have no supported parser." });
108
+ }
109
+
110
+ let evidence: ImportEvidence | undefined;
111
+ if (args.scope !== "staged" && !args.staged && repo) {
112
+ const relevant = (file: string) => (!args.domain || evaluator.resolveSourceDomain(file,config) === args.domain) && (requested.length === 0 || requested.includes(file));
113
+ evidence = repo.getImportEvidence(root, repo.getMeta("workspace_root") ? relevant : undefined);
114
+ const staleFiles = evidence.staleFiles;
115
+ const relationships = evidence.relationships.filter(edge => relevant(edge.source.file));
116
+ const incomplete = relationships.filter(edge => edge.index_coverage === "partial" || edge.freshness !== "current" || !["resolved","external"].includes(edge.resolution.status) || edge.resolution.coverage === "conditional" || edge.target_domains.length > 1);
117
+ const allProposed = requested.flatMap(file => proposedImports.map(target => evaluator.getResolver().resolveImport(target, file)));
118
+ const proposed = allProposed.filter(result => !["resolved", "external"].includes(result.status) || result.coverage === "conditional");
119
+ if (incomplete.length || proposed.length || staleFiles.length) {
120
+ const known = evaluator.auditCodebase(config, evidence).filter(violation => relevant(violation.file));
121
+ known.push(...requested.flatMap(file => evaluator.evaluate(file, proposedImports, config, evidence)));
122
+ return incompleteEvidence({
123
+ status: known.length ? "rejected" : "unknown",
124
+ scope: effectiveScope,
125
+ ...(args.domain ? { domain: args.domain } : {}),
126
+ violations: known, total_violations: known.length,
127
+ circular_dependencies: known.filter(v => v.rule === "circular_dependency"), circular_dependencies_count: known.filter(v => v.rule === "circular_dependency").length,
128
+ relationships: incomplete.slice(0, 10), proposed_resolutions: allProposed,
129
+ diagnostic_accounting: { total: incomplete.length, returned: Math.min(10, incomplete.length), omitted: Math.max(0, incomplete.length - 10) },
130
+ incomplete_reasons: {
131
+ target_not_fully_indexed: incomplete.filter(edge => edge.index_coverage === "partial").length,
132
+ stale_source: incomplete.filter(edge => edge.freshness !== "current").length,
133
+ unresolved_or_unsupported: incomplete.filter(edge => !["resolved", "external"].includes(edge.resolution.status)).length,
134
+ conditional_resolution: incomplete.filter(edge => edge.resolution.coverage === "conditional").length,
135
+ multiple_domains: incomplete.filter(edge => edge.target_domains.length > 1).length,
136
+ },
137
+ next: ["Inspect the listed source imports; register/index uncovered target roots or narrow scope to a file/domain. Unknown is not approval."],
138
+ stale_files: staleFiles,
139
+ message: "Relevant import resolution is incomplete; an empty graph cannot prove boundary approval.",
140
+ });
141
+ }
142
+ }
143
+
144
+ const filesToCheck: string[] = [];
145
+ if (args.file_paths && Array.isArray(args.file_paths) && args.file_paths.length > 0) {
146
+ filesToCheck.push(...args.file_paths);
147
+ } else if (args.file_path) {
148
+ if (Array.isArray(args.file_path)) {
149
+ filesToCheck.push(...args.file_path);
150
+ } else if (typeof args.file_path === "string" && args.file_path.trim().length > 0) {
151
+ filesToCheck.push(args.file_path.trim());
152
+ }
153
+ }
154
+
155
+ // Repo-wide, domain-scoped, or git-staged boundary audit when neither file_path nor file_paths is provided
156
+ if (filesToCheck.length === 0) {
157
+ const effectiveScope =
158
+ args.scope ?? (args.staged ? "staged" : args.domain ? "domain" : "all");
159
+
160
+ if (effectiveScope === "staged") {
161
+ const {
162
+ files: stagedFiles,
163
+ violations: stagedViolations,
164
+ resolution_issues: resolutionIssues,
165
+ background_resolution_issues_count: backgroundResolutionIssuesCount,
166
+ } = await auditStagedFiles(evaluator, config, root, repo);
167
+ const enforcementMode = config?.settings?.enforcement ?? "strict";
168
+
169
+ if (stagedFiles.length === 0 && stagedViolations.length === 0) {
170
+ return evaluated({
171
+ status: "approved",
172
+ scope: "staged",
173
+ enforcement_mode: enforcementMode,
174
+ total_checked: 0,
175
+ total_violations: 0,
176
+ circular_dependencies_count: 0,
177
+ circular_dependencies: [],
178
+ domain_violation_breakdown: {},
179
+ violations: [],
180
+ message: "No git staged files found. Boundary check passed.",
181
+ });
182
+ }
183
+
184
+ const filteredViolations = args.domain
185
+ ? stagedViolations.filter(
186
+ (v) =>
187
+ v.source_domain.toLowerCase() === args.domain!.toLowerCase() ||
188
+ v.target_domain.toLowerCase() === args.domain!.toLowerCase()
189
+ )
190
+ : stagedViolations;
191
+
192
+ const hasViolations = filteredViolations.length > 0;
193
+ return evaluated({
194
+ status: hasViolations ? "rejected" : resolutionIssues.length ? "unknown" : "approved",
195
+ resolution_issues: resolutionIssues,
196
+ ...(backgroundResolutionIssuesCount > 0
197
+ ? { background_resolution_issues_count: backgroundResolutionIssuesCount }
198
+ : {}),
199
+ scope: "staged",
200
+ enforcement_mode: enforcementMode,
201
+ total_checked: stagedFiles.length,
202
+ total_violations: filteredViolations.length,
203
+ ...summarizeViolations(filteredViolations),
204
+ violations: filteredViolations,
205
+ message: resolutionIssues.length && !hasViolations
206
+ ? "Staged import resolution is incomplete; approval is unknown."
207
+ : hasViolations
208
+ ? `${filteredViolations.length} boundary violation(s) detected across ${stagedFiles.length} staged file(s).`
209
+ : `All ${stagedFiles.length} staged file(s) approved. No boundary violations detected.`,
210
+ });
211
+ }
212
+
213
+ // Scope: "all" or "domain"
214
+ const auditResult = evaluator.auditCodebaseWithWarnings(config, evidence);
215
+ let violations = auditResult.violations;
216
+ let warnings = auditResult.warnings;
217
+ if (args.domain) {
218
+ const targetDom = args.domain.toLowerCase();
219
+ violations = violations.filter(
220
+ (v) =>
221
+ v.source_domain.toLowerCase() === targetDom ||
222
+ v.target_domain.toLowerCase() === targetDom
223
+ );
224
+ warnings = warnings.filter(
225
+ (w) =>
226
+ w.source_domain.toLowerCase() === targetDom ||
227
+ w.target_domain.toLowerCase() === targetDom
228
+ );
229
+ }
230
+
231
+ const summary = summarizeViolations(violations);
232
+ const hasViolations = violations.length > 0;
233
+ const hasWarnings = warnings.length > 0;
234
+ const domainCount = Object.keys(config?.domains || {}).length;
235
+ const allIndexedFiles = repo ? repo.getAllFiles() : [];
236
+ const emptyScopedDomain = Boolean(args.domain && repo && !allIndexedFiles.some(
237
+ (file) => evaluator.resolveSourceDomain(file.path, config) === args.domain,
238
+ ));
239
+ const emptyWorkspace = Boolean(repo && allIndexedFiles.length === 0);
240
+ const uncoveredFiles: string[] = !args.domain && repo
241
+ ? JSON.parse(repo.getMeta("uncovered_files") || "[]")
242
+ : [];
243
+ const hasUncoveredWorkspaceFiles = !args.domain && uncoveredFiles.length > 0;
244
+
245
+ return evaluated({
246
+ status: hasViolations ? "rejected" : emptyScopedDomain || emptyWorkspace || domainCount === 0 ? "unknown" : "approved",
247
+ scope: args.domain ? "domain" : "all",
248
+ enforcement_mode: config?.settings?.enforcement ?? "strict",
249
+ ...(args.domain ? { domain: args.domain } : {}),
250
+ total_domains_checked: domainCount,
251
+ total_violations: violations.length,
252
+ total_warnings: warnings.length,
253
+ ...summary,
254
+ violations,
255
+ ...(hasWarnings ? { warnings } : {}),
256
+ ...(hasUncoveredWorkspaceFiles ? { uncovered_files_count: uncoveredFiles.length } : {}),
257
+ message: hasViolations
258
+ ? `${violations.length} boundary violation(s) (${summary.circular_dependencies_count} circular) detected${
259
+ args.domain ? ` in domain '${args.domain}'` : " across codebase"
260
+ }.${hasWarnings ? ` Also ${warnings.length} unlisted dependency warning(s) in 'warn' mode.` : ""}`
261
+ : emptyScopedDomain
262
+ ? `Boundary check is incomplete: domain '${args.domain}' has 0 indexed files (it may be unindexed or shadowed by a parent domain).`
263
+ : emptyWorkspace
264
+ ? "Boundary check is incomplete: 0 source files are indexed across the workspace; an empty graph cannot prove boundary approval."
265
+ : domainCount === 0
266
+ ? "Boundary check is incomplete: no domain policies are available. Initialize or register domains before auditing."
267
+ : hasWarnings
268
+ ? `No blocking boundary violations detected${
269
+ args.domain ? ` for domain '${args.domain}'` : ""
270
+ }, but ${warnings.length} unlisted dependency warning(s) were found under 'warn' enforcement.`
271
+ : hasUncoveredWorkspaceFiles
272
+ ? `All registered domain boundaries are clean across ${allIndexedFiles.length} indexed file(s) (${uncoveredFiles.length} uncovered file(s) outside registered domains were not audited).`
273
+ : `All domain boundaries are clean${
274
+ args.domain ? ` for domain '${args.domain}'` : ""
275
+ }. Zero cross-domain leaks or circular dependencies detected.`,
276
+ });
277
+ }
278
+
279
+ const enforcementMode = config?.settings?.enforcement ?? "strict";
280
+
281
+ // Multi-file batch evaluation
282
+ if (filesToCheck.length > 1) {
283
+ const results = filesToCheck.map((filePath) => {
284
+ const violations = evaluator.evaluate(filePath, proposedImports, config, evidence);
285
+ const impact = repo?.getFileInboundImpact(filePath, evidence?.relationships);
286
+ return {
287
+ file: filePath,
288
+ evaluated_scope: evaluatedScope,
289
+ status: violations.length > 0 ? "rejected" : "approved",
290
+ total_violations: violations.length,
291
+ violations,
292
+ impact_summary: impact
293
+ ? {
294
+ direct_dependents: impact.direct_dependents_count,
295
+ top_consumers: impact.top_consumers,
296
+ symbols_count: impact.symbols_count,
297
+ risk_level: impact.risk_level,
298
+ }
299
+ : undefined,
300
+ };
301
+ });
302
+
303
+ const totalViolations = results.reduce((acc, r) => acc + r.violations.length, 0);
304
+ const hasViolations = totalViolations > 0;
305
+
306
+ return evaluated({
307
+ status: hasViolations ? "rejected" : "approved",
308
+ scope: "file",
309
+ enforcement_mode: enforcementMode,
310
+ total_checked: filesToCheck.length,
311
+ total_violations: totalViolations,
312
+ violations: results.flatMap((r) => r.violations),
313
+ results,
314
+ message: hasViolations
315
+ ? `${totalViolations} boundary violation(s) detected across ${filesToCheck.length} file(s).`
316
+ : Object.keys(config?.domains || {}).length === 0
317
+ ? `All ${filesToCheck.length} file(s) approved. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]`
318
+ : `All ${filesToCheck.length} file(s) approved. No boundary violations detected.`,
319
+ });
320
+ }
321
+
322
+ // Single file evaluation
323
+ const singleFile = filesToCheck[0];
324
+ const violations = evaluator.evaluate(singleFile, proposedImports, config, evidence);
325
+ const impact = repo?.getFileInboundImpact(singleFile, evidence?.relationships);
326
+ const impactSummary = impact
327
+ ? {
328
+ direct_dependents: impact.direct_dependents_count,
329
+ top_consumers: impact.top_consumers,
330
+ symbols_count: impact.symbols_count,
331
+ risk_level: impact.risk_level,
332
+ }
333
+ : undefined;
334
+
335
+ const newViolations = violations.filter((v) => !v.pre_existing);
336
+ const preExistingViolations = violations.filter((v) => v.pre_existing);
337
+
338
+ if (newViolations.length > 0) {
339
+ return evaluated({
340
+ status: "rejected",
341
+ scope: "file",
342
+ enforcement_mode: enforcementMode,
343
+ file: singleFile,
344
+ evaluated_scope: evaluatedScope,
345
+ total_violations: newViolations.length,
346
+ violations_count: newViolations.length,
347
+ violations: newViolations,
348
+ ...(preExistingViolations.length > 0 ? { pre_existing_violations: preExistingViolations } : {}),
349
+ impact_summary: impactSummary,
350
+ message:
351
+ Object.keys(config?.domains || {}).length === 0
352
+ ? "Boundary integrity check failed: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts."
353
+ : newViolations.some((v) => v.rule === "unmapped_domain")
354
+ ? "Boundary integrity check failed: File does not belong to any declared bounded context."
355
+ : "Boundary violation detected. Proposed imports violate bounded context architecture.",
356
+ });
357
+ }
358
+
359
+ return evaluated({
360
+ status: "approved",
361
+ scope: "file",
362
+ enforcement_mode: enforcementMode,
363
+ file: singleFile,
364
+ evaluated_scope: evaluatedScope,
365
+ total_violations: 0,
366
+ violations: [],
367
+ ...(preExistingViolations.length > 0 ? {
368
+ pre_existing_violations: preExistingViolations,
369
+ pre_existing_violations_count: preExistingViolations.length,
370
+ } : {}),
371
+ impact_summary: impactSummary,
372
+ message:
373
+ preExistingViolations.length > 0
374
+ ? `Approved. Proposed imports do not introduce new boundary violations (${preExistingViolations.length} pre-existing circular dependencies noted in codebase).`
375
+ : Object.keys(config?.domains || {}).length === 0
376
+ ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]"
377
+ : enforcementMode === "warn"
378
+ ? "Approved under 'warn' enforcement (unlisted allowed_dependencies are not blocked; only explicit forbidden_dependencies are rejected)."
379
+ : impact && impact.direct_dependents_count > 0
380
+ ? `No boundary violations detected. Caution: ${impact.direct_dependents_count} dependent file(s) consume this file.`
381
+ : "Proposal approved. Existing file imports were not audited.",
382
+ });
383
+ }