@dimassetoid/septum-mcp 0.3.0 → 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 (129) hide show
  1. package/README.md +38 -55
  2. package/package.json +7 -5
  3. package/src/cli/commands/check.ts +14 -10
  4. package/src/cli/commands/hook.ts +41 -6
  5. package/src/cli/commands/init.ts +10 -1
  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 +32 -4
  9. package/src/cli/index.ts +7 -0
  10. package/src/cli/templates/hooks.ts +3 -14
  11. package/src/cli/templates/skill.ts +17 -10
  12. package/src/core/boundary/audit.ts +383 -0
  13. package/src/core/boundary/evaluator.ts +251 -114
  14. package/src/core/boundary/staged-auditor.ts +147 -55
  15. package/src/core/config/domain-ownership.ts +6 -4
  16. package/src/core/config/domain-registration.ts +141 -0
  17. package/src/core/config/loader.ts +1 -25
  18. package/src/core/config/schema.ts +24 -36
  19. package/src/core/database/client.ts +2 -0
  20. package/src/core/database/repositories/dependency.repository.ts +334 -572
  21. package/src/core/database/repositories/domain.repository.ts +2 -1
  22. package/src/core/database/repositories/file.repository.ts +10 -0
  23. package/src/core/database/repositories/symbol.repository.ts +97 -398
  24. package/src/core/database/repository.ts +68 -9
  25. package/src/core/database/schema.ts +26 -0
  26. package/src/core/discovery/declarative-routes.ts +69 -0
  27. package/src/core/discovery/framework-detector.ts +149 -0
  28. package/src/core/discovery/navigation.ts +222 -58
  29. package/src/core/discovery/topology-detector.ts +93 -168
  30. package/src/core/errors.ts +19 -0
  31. package/src/core/ingestion/pipeline.ts +287 -88
  32. package/src/core/parser/extractors/base.ts +11 -3
  33. package/src/core/parser/extractors/csharp.ts +2 -2
  34. package/src/core/parser/extractors/django-routing.ts +163 -0
  35. package/src/core/parser/extractors/django-semantic.ts +397 -481
  36. package/src/core/parser/extractors/elysia-semantic.ts +172 -475
  37. package/src/core/parser/extractors/express-semantic.ts +195 -383
  38. package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
  39. package/src/core/parser/extractors/fastify-semantic.ts +216 -717
  40. package/src/core/parser/extractors/flask-semantic.ts +89 -352
  41. package/src/core/parser/extractors/go-routing.ts +344 -0
  42. package/src/core/parser/extractors/go-semantic.ts +205 -562
  43. package/src/core/parser/extractors/go.ts +6 -3
  44. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  45. package/src/core/parser/extractors/hono-semantic.ts +132 -509
  46. package/src/core/parser/extractors/java.ts +2 -2
  47. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  48. package/src/core/parser/extractors/laravel-semantic.ts +143 -335
  49. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  50. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  51. package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
  52. package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
  53. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  54. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  55. package/src/core/parser/extractors/php.ts +1 -1
  56. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  57. package/src/core/parser/extractors/python.ts +5 -9
  58. package/src/core/parser/extractors/registry.ts +2 -0
  59. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  60. package/src/core/parser/extractors/ruby.ts +2 -2
  61. package/src/core/parser/extractors/rust.ts +4 -4
  62. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  63. package/src/core/parser/extractors/symfony-semantic.ts +72 -226
  64. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  65. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  66. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  67. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  68. package/src/core/parser/extractors/typescript.ts +23 -216
  69. package/src/core/parser/language-capabilities.ts +1 -1
  70. package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
  71. package/src/core/parser/wasm-loader.ts +6 -2
  72. package/src/core/resolver/ast-method-tracer.ts +230 -0
  73. package/src/core/resolver/call-graph-helpers.ts +72 -0
  74. package/src/core/resolver/call-graph-tracer.ts +169 -414
  75. package/src/core/resolver/dependency-analysis.ts +593 -0
  76. package/src/core/resolver/import-candidates.ts +120 -0
  77. package/src/core/resolver/import-evidence.ts +88 -0
  78. package/src/core/resolver/import-resolver.ts +60 -7
  79. package/src/core/resolver/interpretation-inputs.ts +60 -2
  80. package/src/core/resolver/languages/python.ts +31 -13
  81. package/src/core/resolver/languages/shared.ts +4 -1
  82. package/src/core/resolver/module-resolver.ts +10 -3
  83. package/src/core/resolver/path-resolver.ts +6 -3
  84. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  85. package/src/core/resolver/slice-catalog.ts +21 -6
  86. package/src/core/resolver/slice-format.ts +13 -0
  87. package/src/core/resolver/slice-selection.ts +237 -0
  88. package/src/core/resolver/symbol-impact.ts +104 -8
  89. package/src/core/resolver/symbol-locator.ts +82 -15
  90. package/src/core/resolver/vertical-slice-tracer.ts +31 -230
  91. package/src/core/resources/ignore.ts +0 -1
  92. package/src/core/resources/limits.ts +2 -1
  93. package/src/core/resources/work-queue.ts +167 -4
  94. package/src/core/retrieval/context-page.ts +11 -4
  95. package/src/core/retrieval/context.ts +363 -226
  96. package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
  97. package/src/core/retrieval/symbol-details.ts +453 -0
  98. package/src/core/retrieval/symbol-evidence.ts +3 -3
  99. package/src/core/retrieval/typescript-references.ts +38 -7
  100. package/src/core/retrieval/universal-context.ts +182 -0
  101. package/src/core/telemetry/summary.ts +114 -0
  102. package/src/core/telemetry/telemetry.ts +192 -49
  103. package/src/mcp/formatters/compact-text.ts +439 -0
  104. package/src/mcp/resources-and-prompts.ts +253 -0
  105. package/src/mcp/schemas/boundary.ts +145 -0
  106. package/src/mcp/schemas/map.ts +250 -0
  107. package/src/mcp/schemas/shared.ts +52 -0
  108. package/src/mcp/schemas/slice.ts +60 -0
  109. package/src/mcp/schemas/symbol.ts +268 -0
  110. package/src/mcp/schemas.ts +5 -746
  111. package/src/mcp/server.ts +269 -429
  112. package/src/mcp/tool-catalog.ts +331 -0
  113. package/src/mcp/tools/boundary.ts +68 -3
  114. package/src/mcp/tools/map.ts +104 -4
  115. package/src/mcp/tools/slice.ts +101 -3
  116. package/src/mcp/tools/symbol.ts +469 -17
  117. package/src/mcp/ui/app-client.ts +899 -0
  118. package/src/mcp/ui/app.html +478 -0
  119. package/src/mcp/workflow-playbooks.ts +181 -0
  120. package/src/mcp/workspace-boundary.ts +50 -0
  121. package/src/mcp/workspace-manager.ts +88 -15
  122. package/src/mcp/workspace-watcher.ts +30 -11
  123. package/src/types/index.ts +12 -0
  124. package/src/mcp/tools/check-boundary.ts +0 -382
  125. package/src/mcp/tools/get-domain-catalog.ts +0 -39
  126. package/src/mcp/tools/get-symbol-impact.ts +0 -104
  127. package/src/mcp/tools/locate-symbol.ts +0 -236
  128. package/src/mcp/tools/register-domain.ts +0 -113
  129. package/src/mcp/tools/trace-vertical-slice.ts +0 -106
@@ -1,6 +1,7 @@
1
+ import type { ImportEvidence, IndexedDependency } from "../resolver/import-evidence.ts";
1
2
  import { posix, relative, resolve, isAbsolute } from "node:path";
2
3
  import { existsSync } from "node:fs";
3
- import type { BoundaryViolation } from "../../types/index.ts";
4
+ import type { BoundaryViolation, ImportResolution } from "../../types/index.ts";
4
5
  import type { ValidatedSeptumConfig } from "../config/schema.ts";
5
6
  import { ConfigLoader } from "../config/loader.ts";
6
7
  import type { SeptumRepository } from "../database/repository.ts";
@@ -8,11 +9,19 @@ import { ModuleResolver } from "../resolver/module-resolver.ts";
8
9
  import { matchesSimpleGlob } from "../parser/extractors/base.ts";
9
10
  import { assertUniqueDomainRoots } from "../config/domain-ownership.ts";
10
11
 
12
+ function dependencyKey(file: string, line: number, target: string, statement: string): string {
13
+ return JSON.stringify([file, line, target, statement]);
14
+ }
15
+
16
+ function indexedDependencyKey(dependency: IndexedDependency): string {
17
+ return dependencyKey(dependency.source_file, dependency.line_number, dependency.target, dependency.statement);
18
+ }
19
+
11
20
  export class BoundaryEvaluator {
12
- private repo: SeptumRepository;
21
+ private repo?: SeptumRepository;
13
22
  private resolver: ModuleResolver;
14
23
 
15
- constructor(repo: SeptumRepository, resolver?: ModuleResolver) {
24
+ constructor(repo?: SeptumRepository, resolver?: ModuleResolver) {
16
25
  this.repo = repo;
17
26
  this.resolver = resolver ?? new ModuleResolver(process.cwd(), repo);
18
27
  }
@@ -28,15 +37,16 @@ export class BoundaryEvaluator {
28
37
  public evaluate(
29
38
  filePath: string,
30
39
  proposedImports: string[] = [],
31
- config?: ValidatedSeptumConfig
40
+ config?: ValidatedSeptumConfig,
41
+ snapshot?: ImportEvidence
32
42
  ): BoundaryViolation[] {
33
43
  let activeConfig = config;
34
44
  if (!activeConfig) {
35
- const fromRepo = ConfigLoader.loadFromRepository(this.repo);
45
+ const fromRepo = this.repo ? ConfigLoader.loadFromRepository(this.repo) : undefined;
36
46
  activeConfig =
37
- Object.keys(fromRepo.domains).length > 0
47
+ fromRepo && Object.keys(fromRepo.domains).length > 0
38
48
  ? fromRepo
39
- : ConfigLoader.loadFromDatabaseOrDefaults();
49
+ : ConfigLoader.load(undefined, this.resolver.getProjectRoot());
40
50
  }
41
51
  assertUniqueDomainRoots(activeConfig.domains, this.resolver.getProjectRoot());
42
52
  const violations: BoundaryViolation[] = [];
@@ -44,8 +54,19 @@ export class BoundaryEvaluator {
44
54
  if (proposedImports.length > 0) {
45
55
  violations.push(...this.checkProposedChanges(filePath, proposedImports, activeConfig));
46
56
  const sourceDomain = this.resolveSourceDomain(filePath, activeConfig);
47
- if (sourceDomain && typeof this.repo.getAllDependenciesWithDomains === "function") {
48
- const existingDeps = this.repo.getAllDependenciesWithDomains().filter(
57
+ if (sourceDomain && typeof this.repo?.getAllDependenciesWithDomains === "function") {
58
+ // Resolutions from import-evidence (requires workspace_root meta) — optional, used for
59
+ // richer cycle detection. Falls back to raw indexed deps when unavailable (e.g. in tests).
60
+ const indexed = this.repo?.getMeta?.("workspace_root");
61
+ const auditEvidence = snapshot ?? (indexed && this.repo ? this.repo.getImportEvidence(this.resolver.getProjectRoot()) : undefined);
62
+ const evidence = indexed ? auditEvidence?.relationships : undefined;
63
+ const resolutions = evidence && new Map(evidence.filter(edge => edge.freshness === "current").map(edge => [
64
+ dependencyKey(edge.source.file, edge.source.line, edge.resolution.source.target, edge.source.statement),
65
+ edge.resolution,
66
+ ]));
67
+
68
+ const allDeps = auditEvidence?.dependencies ?? this.repo.getAllDependenciesWithDomains();
69
+ const existingDeps = allDeps.filter(
49
70
  (dep) => dep.source_file !== filePath
50
71
  );
51
72
  const proposedDeps = proposedImports.map((statement) => ({
@@ -56,95 +77,109 @@ export class BoundaryEvaluator {
56
77
  statement,
57
78
  is_external: false,
58
79
  }));
59
- violations.push(
60
- ...this.detectCircularDependencies(
61
- activeConfig,
62
- [...existingDeps, ...proposedDeps],
63
- new Set([filePath])
64
- )
80
+
81
+ const detectedCycles = this.detectCircularDependencies(
82
+ activeConfig,
83
+ [...existingDeps, ...proposedDeps],
84
+ new Set([filePath]),
85
+ resolutions
65
86
  );
87
+
88
+ if (detectedCycles.length > 0) {
89
+ // Baseline: detect cycles that already exist in the indexed graph, independent of
90
+ // workspace_root / import-evidence so the tagging works even in in-memory test repos.
91
+ const baselineCycles = this.detectCircularDependencies(
92
+ activeConfig,
93
+ allDeps,
94
+ undefined, // no relevantFiles filter — capture all pre-existing cycles
95
+ resolutions
96
+ );
97
+ // Normalize cycle messages to a rotation-agnostic canonical form:
98
+ // extract the node list, sort it, then join. This handles DFS start-node differences.
99
+ const extractCycleNodeSet = (msg: string): string => {
100
+ const match = /detected: (.+)\.$/.exec(msg);
101
+ if (!match) return msg;
102
+ // "a -> b -> a" → split, dedupe, sort
103
+ const nodes = match[1]!.split(" -> ").filter((n, i, arr) => !(i === arr.length - 1 && n === arr[0]));
104
+ return nodes.sort().join(",");
105
+ };
106
+ const baselineCanonicals = new Set(baselineCycles.map((c) => extractCycleNodeSet(c.message)));
107
+
108
+ for (const cycle of detectedCycles) {
109
+ if (baselineCanonicals.has(extractCycleNodeSet(cycle.message))) {
110
+ cycle.pre_existing = true;
111
+ }
112
+ violations.push(cycle);
113
+ }
114
+ }
66
115
  }
67
116
  }
68
117
 
69
118
  return violations;
70
119
  }
71
120
 
72
- public auditCodebase(config: ValidatedSeptumConfig): BoundaryViolation[] {
121
+ public auditCodebase(config: ValidatedSeptumConfig, snapshot?: ImportEvidence): BoundaryViolation[] {
122
+ return this.auditCodebaseWithWarnings(config, snapshot).violations;
123
+ }
124
+
125
+ public auditCodebaseWithWarnings(
126
+ config: ValidatedSeptumConfig,
127
+ snapshot?: ImportEvidence
128
+ ): { violations: BoundaryViolation[]; warnings: BoundaryViolation[] } {
73
129
  assertUniqueDomainRoots(config.domains, this.resolver.getProjectRoot());
74
130
  const violations: BoundaryViolation[] = [];
75
- const allDependencies = this.repo.getAllDependenciesWithDomains();
76
-
77
- const evidence = this.repo.getMeta?.("workspace_root") ? this.repo.getImportRelationships(this.resolver.getProjectRoot()) : undefined;
78
- const key = (file: string, line: number, target: string) => JSON.stringify([file, line, target]);
79
- const current = new Set(evidence?.filter(edge => edge.freshness === "current").map(edge => key(edge.source.file, edge.source.line, edge.resolution.source.target)));
80
- const resolved = new Set(evidence?.filter(edge => edge.freshness === "current" && edge.resolution.status === "resolved" && edge.resolution.coverage !== "conditional").map(edge => key(edge.source.file, edge.source.line, edge.resolution.source.target)));
131
+ const warnings: BoundaryViolation[] = [];
132
+ const indexed = this.repo?.getMeta?.("workspace_root");
133
+ const auditEvidence = snapshot ?? (indexed && this.repo ? this.repo.getImportEvidence(this.resolver.getProjectRoot()) : undefined);
134
+ const allDependencies = auditEvidence?.dependencies ?? this.repo?.getAllDependenciesWithDomains() ?? [];
135
+ const evidence = indexed ? auditEvidence?.relationships : undefined;
136
+ const resolutions = evidence && new Map(evidence.filter(edge => edge.freshness === "current").map(edge => [
137
+ dependencyKey(edge.source.file, edge.source.line, edge.resolution.source.target, edge.source.statement),
138
+ edge.resolution,
139
+ ]));
81
140
  for (const dep of allDependencies) {
82
- if (evidence && !resolved.has(key(dep.source_file, dep.line_number, dep.target))) continue;
83
- const targetDomain = this.resolveTargetDomain(dep.target, config, dep.source_file, dep.statement);
84
- if (!targetDomain || targetDomain === dep.source_domain) {
85
- continue;
86
- }
87
-
88
- const sourceDomainConfig = config.domains[dep.source_domain];
89
- if (!sourceDomainConfig) {
90
- continue;
91
- }
92
-
93
- const forbidden = sourceDomainConfig.forbidden_dependencies ?? [];
94
- const allowed = sourceDomainConfig.allowed_dependencies ?? [];
95
-
96
- // 1. Explicit forbidden check
97
- if (forbidden.includes(targetDomain)) {
98
- violations.push({
99
- file: dep.source_file,
100
- line: dep.line_number,
101
- source_domain: dep.source_domain,
102
- target_domain: targetDomain,
103
- imported_target: dep.target,
104
- rule: "forbidden_dependency",
105
- message: `Forbidden cross-domain dependency detected: '${dep.source_domain}' is strictly prohibited from importing domain '${targetDomain}'.`,
106
- });
107
- continue;
108
- }
109
-
110
- // 2. Strict enforcement allowed check
111
- if (config.settings.enforcement === "strict" && !allowed.includes(targetDomain)) {
112
- violations.push({
113
- file: dep.source_file,
114
- line: dep.line_number,
115
- source_domain: dep.source_domain,
116
- target_domain: targetDomain,
117
- imported_target: dep.target,
118
- rule: "disallowed_dependency",
119
- message: `Disallowed dependency: '${targetDomain}' is not declared in allowed_dependencies for domain '${dep.source_domain}'.`,
120
- });
121
- }
141
+ const resolution = resolutions?.get(indexedDependencyKey(dep));
142
+ if (resolutions && (resolution?.status !== "resolved" || resolution.coverage === "conditional")) continue;
143
+ const evaluation = this.evaluateDependencyRuleWithWarning({
144
+ sourceFile: dep.source_file,
145
+ sourceDomain: dep.source_domain,
146
+ line: dep.line_number,
147
+ target: dep.target,
148
+ statement: dep.statement,
149
+ config,
150
+ mode: "audit",
151
+ resolution,
152
+ });
153
+ if (evaluation.violation) violations.push(evaluation.violation);
154
+ if (evaluation.warning) warnings.push(evaluation.warning);
122
155
  }
123
156
 
124
- const currentDependencies = evidence ? allDependencies.filter(dep => current.has(key(dep.source_file, dep.line_number, dep.target))) : allDependencies;
125
- violations.push(...this.detectCircularDependencies(config, currentDependencies));
157
+ const currentDependencies = resolutions ? allDependencies.filter(dep => resolutions.has(indexedDependencyKey(dep))) : allDependencies;
158
+ violations.push(...this.detectCircularDependencies(config, currentDependencies, undefined, resolutions));
126
159
 
127
- return violations;
160
+ return { violations, warnings };
128
161
  }
129
162
 
130
163
  public detectCircularDependencies(
131
164
  config: ValidatedSeptumConfig,
132
- preloadedDeps?: Array<{
133
- source_file: string;
134
- source_domain: string;
135
- line_number: number;
136
- target: string;
137
- statement: string;
138
- is_external: boolean;
139
- }>,
140
- relevantFiles?: ReadonlySet<string>
165
+ preloadedDeps?: IndexedDependency[],
166
+ relevantFiles?: ReadonlySet<string>,
167
+ resolutions?: ReadonlyMap<string, ImportResolution>,
141
168
  ): BoundaryViolation[] {
142
169
  assertUniqueDomainRoots(config.domains, this.resolver.getProjectRoot());
143
170
  const violations: BoundaryViolation[] = [];
144
- let allDependencies = preloadedDeps ?? this.repo.getAllDependenciesWithDomains();
145
- if (!preloadedDeps && this.repo.getMeta?.("workspace_root")) {
171
+ let allDependencies = preloadedDeps ?? this.repo?.getAllDependenciesWithDomains() ?? [];
172
+ if (!preloadedDeps && this.repo?.getMeta?.("workspace_root")) {
146
173
  const current = this.repo.getImportRelationships(this.resolver.getProjectRoot());
147
- allDependencies = allDependencies.filter(dep => current.some(edge => edge.source.file === dep.source_file && edge.source.line === dep.line_number && edge.freshness === "current"));
174
+ const currentEdgeKeys = new Set<string>();
175
+ for (const edge of current) {
176
+ if (edge.freshness === "current") {
177
+ currentEdgeKeys.add(`${edge.source.file}\0${edge.source.line}`);
178
+ }
179
+ }
180
+ allDependencies = allDependencies.filter((dep) =>
181
+ currentEdgeKeys.has(`${dep.source_file}\0${dep.line_number}`)
182
+ );
148
183
  }
149
184
 
150
185
  // Prepare file lookup maps for internal file-to-file resolution
@@ -161,7 +196,7 @@ export class BoundaryEvaluator {
161
196
  }
162
197
  };
163
198
 
164
- if (typeof this.repo.getAllFiles === "function") {
199
+ if (typeof this.repo?.getAllFiles === "function") {
165
200
  for (const f of this.repo.getAllFiles()) {
166
201
  registerKnownFile(f.path);
167
202
  }
@@ -171,7 +206,7 @@ export class BoundaryEvaluator {
171
206
  }
172
207
 
173
208
  const resolveTargetFile = (sourceFile: string, rawTarget: string, statement?: string): string | null => {
174
- if (this.repo.getMeta?.("workspace_root") || existsSync(resolve(this.resolver.getProjectRoot(), sourceFile))) {
209
+ if (this.repo?.getMeta?.("workspace_root") || existsSync(resolve(this.resolver.getProjectRoot(), sourceFile))) {
175
210
  const result = this.resolver.resolveImport(rawTarget,sourceFile,statement);
176
211
  const files = result.targets.flatMap(target => target.files);
177
212
  return result.status === "resolved" && result.coverage !== "conditional" && files.length === 1 ? files[0]! : null;
@@ -217,12 +252,16 @@ export class BoundaryEvaluator {
217
252
  };
218
253
 
219
254
  for (const dep of allDependencies) {
220
- if (this.repo.getMeta?.("workspace_root")) {
221
- const result = this.resolver.resolveImport(dep.target,dep.source_file,dep.statement);
222
- if (result.status !== "resolved" || result.coverage === "conditional") continue;
255
+ const indexed = this.repo?.getMeta?.("workspace_root");
256
+ const resolution = resolutions?.get(indexedDependencyKey(dep)) ??
257
+ (indexed ? this.resolver.resolveImport(dep.target, dep.source_file, dep.statement) : undefined);
258
+ if (resolution) {
259
+ if (resolution.status !== "resolved" || resolution.coverage === "conditional") continue;
223
260
  } else if (dep.is_external) continue;
224
261
 
225
- const targetDomain = this.resolveTargetDomain(dep.target, config, dep.source_file, dep.statement);
262
+ const targetDomain = resolution
263
+ ? this.resolver.resolveDomainFromEvidence(resolution, config)
264
+ : this.resolveTargetDomain(dep.target, config, dep.source_file, dep.statement);
226
265
 
227
266
  // 1. Domain-to-domain edge (exclude virtual/top-level aggregator "root" domain and type-only imports)
228
267
  if (
@@ -255,7 +294,10 @@ export class BoundaryEvaluator {
255
294
  continue;
256
295
  }
257
296
 
258
- const targetFile = resolveTargetFile(dep.source_file, dep.target, dep.statement);
297
+ const targetFiles = resolution?.targets.flatMap(target => target.files);
298
+ const targetFile = targetFiles
299
+ ? targetFiles.length === 1 ? targetFiles[0] : null
300
+ : resolveTargetFile(dep.source_file, dep.target, dep.statement);
259
301
  if (targetFile && targetFile !== dep.source_file) {
260
302
  let outMap = fileGraph.get(dep.source_file);
261
303
  if (!outMap) {
@@ -280,7 +322,7 @@ export class BoundaryEvaluator {
280
322
  kindLabel: "file" | "domain"
281
323
  ) => {
282
324
  const visited = new Set<string>();
283
- const inStack = new Set<string>();
325
+ const stackIndex = new Map<string, number>();
284
326
  const stack: string[] = [];
285
327
  const reportedCycles = new Set<string>();
286
328
 
@@ -296,7 +338,7 @@ export class BoundaryEvaluator {
296
338
 
297
339
  const dfs = (node: string) => {
298
340
  visited.add(node);
299
- inStack.add(node);
341
+ stackIndex.set(node, stack.length);
300
342
  stack.push(node);
301
343
 
302
344
  const neighbors = graph.get(node);
@@ -304,9 +346,9 @@ export class BoundaryEvaluator {
304
346
  for (const [nextNode, edgeMeta] of neighbors.entries()) {
305
347
  if (!visited.has(nextNode)) {
306
348
  dfs(nextNode);
307
- } else if (inStack.has(nextNode)) {
308
- const cycleStartIndex = stack.indexOf(nextNode);
309
- if (cycleStartIndex !== -1) {
349
+ } else {
350
+ const cycleStartIndex = stackIndex.get(nextNode);
351
+ if (cycleStartIndex !== undefined) {
310
352
  const cycleNodes = stack.slice(cycleStartIndex);
311
353
  const sig = canonicalizeCycle(cycleNodes);
312
354
  const cycleEdges = cycleNodes.map((source, index) => graph.get(source)?.get(cycleNodes[(index + 1) % cycleNodes.length]));
@@ -333,7 +375,7 @@ export class BoundaryEvaluator {
333
375
  }
334
376
 
335
377
  stack.pop();
336
- inStack.delete(node);
378
+ stackIndex.delete(node);
337
379
  };
338
380
 
339
381
  for (const startNode of graph.keys()) {
@@ -371,44 +413,139 @@ export class BoundaryEvaluator {
371
413
  return violations;
372
414
  }
373
415
 
416
+ for (const [index, statement] of proposedImports.entries()) {
417
+ const violation = this.evaluateDependencyRule({
418
+ sourceFile: sourceFilePath,
419
+ sourceDomain,
420
+ line: 1,
421
+ target: statement,
422
+ statement: importStatements?.[index],
423
+ config,
424
+ mode: "proposal",
425
+ });
426
+ if (violation) violations.push(violation);
427
+ }
428
+
429
+ return violations;
430
+ }
431
+
432
+ private evaluateDependencyRule(params: {
433
+ sourceFile: string;
434
+ sourceDomain: string;
435
+ line: number;
436
+ target: string;
437
+ statement?: string;
438
+ config: ValidatedSeptumConfig;
439
+ mode: "audit" | "proposal";
440
+ resolution?: ImportResolution;
441
+ }): BoundaryViolation | null {
442
+ return this.evaluateDependencyRuleWithWarning(params).violation;
443
+ }
444
+
445
+ private evaluateDependencyRuleWithWarning(params: {
446
+ sourceFile: string;
447
+ sourceDomain: string;
448
+ line: number;
449
+ target: string;
450
+ statement?: string;
451
+ config: ValidatedSeptumConfig;
452
+ mode: "audit" | "proposal";
453
+ resolution?: ImportResolution;
454
+ }): { violation: BoundaryViolation | null; warning: BoundaryViolation | null } {
455
+ const { sourceFile, sourceDomain, line, target, statement, config, mode, resolution: evidence } = params;
374
456
  const sourceDomainConfig = config.domains[sourceDomain];
375
- if (!sourceDomainConfig) {
376
- return violations;
457
+ if (!sourceDomainConfig) return { violation: null, warning: null };
458
+
459
+ const targetDomain = evidence
460
+ ? this.resolver.resolveDomainFromEvidence(evidence, config)
461
+ : this.resolveTargetDomain(target, config, sourceFile, statement);
462
+ if (!targetDomain) {
463
+ if (
464
+ config.settings.enforcement === "strict" &&
465
+ (this.repo?.getMeta?.("workspace_root") || existsSync(resolve(this.resolver.getProjectRoot(), sourceFile)))
466
+ ) {
467
+ const resolution = evidence ?? this.resolver.resolveImport(target, sourceFile, statement);
468
+ if (
469
+ resolution.status === "resolved" &&
470
+ resolution.coverage !== "conditional" &&
471
+ resolution.targets.some((t) => t.kind === "file" && t.files.length > 0)
472
+ ) {
473
+ return {
474
+ violation: {
475
+ file: sourceFile,
476
+ line,
477
+ source_domain: sourceDomain,
478
+ target_domain: "unmapped",
479
+ imported_target: target,
480
+ rule: "unmapped_domain",
481
+ message: `Unmapped internal target: '${target}' resolves inside the workspace outside any declared bounded context.`,
482
+ },
483
+ warning: null,
484
+ };
485
+ }
486
+ }
487
+ return { violation: null, warning: null };
377
488
  }
378
489
 
490
+ if (targetDomain === sourceDomain) return { violation: null, warning: null };
491
+
379
492
  const forbidden = sourceDomainConfig.forbidden_dependencies ?? [];
380
493
  const allowed = sourceDomainConfig.allowed_dependencies ?? [];
381
494
 
382
- for (const [index, statement] of proposedImports.entries()) {
383
- const targetDomain = this.resolveTargetDomain(statement, config, sourceFilePath, importStatements?.[index]);
384
- if (!targetDomain || targetDomain === sourceDomain) {
385
- continue;
386
- }
387
-
388
- if (forbidden.includes(targetDomain)) {
389
- violations.push({
390
- file: sourceFilePath,
391
- line: 1,
495
+ if (forbidden.includes(targetDomain)) {
496
+ return {
497
+ violation: {
498
+ file: sourceFile,
499
+ line,
392
500
  source_domain: sourceDomain,
393
501
  target_domain: targetDomain,
394
- imported_target: statement,
502
+ imported_target: target,
395
503
  rule: "forbidden_dependency",
396
- message: `Illegal import blocked: Domain '${sourceDomain}' is strictly forbidden from importing domain '${targetDomain}'.`,
397
- });
398
- } else if (config.settings.enforcement === "strict" && !allowed.includes(targetDomain)) {
399
- violations.push({
400
- file: sourceFilePath,
401
- line: 1,
504
+ message:
505
+ mode === "proposal"
506
+ ? `Illegal import blocked: Domain '${sourceDomain}' is strictly forbidden from importing domain '${targetDomain}'.`
507
+ : `Forbidden cross-domain dependency detected: '${sourceDomain}' is strictly prohibited from importing domain '${targetDomain}'.`,
508
+ },
509
+ warning: null,
510
+ };
511
+ }
512
+
513
+ if (!allowed.includes(targetDomain)) {
514
+ if (config.settings.enforcement === "strict") {
515
+ return {
516
+ violation: {
517
+ file: sourceFile,
518
+ line,
519
+ source_domain: sourceDomain,
520
+ target_domain: targetDomain,
521
+ imported_target: target,
522
+ rule: "disallowed_dependency",
523
+ message:
524
+ mode === "proposal"
525
+ ? `Unlisted domain dependency: '${targetDomain}' must be explicitly added to allowed_dependencies before domain '${sourceDomain}' can import it.`
526
+ : `Disallowed dependency: '${targetDomain}' is not declared in allowed_dependencies for domain '${sourceDomain}'.`,
527
+ },
528
+ warning: null,
529
+ };
530
+ }
531
+ return {
532
+ violation: null,
533
+ warning: {
534
+ file: sourceFile,
535
+ line,
402
536
  source_domain: sourceDomain,
403
537
  target_domain: targetDomain,
404
- imported_target: statement,
538
+ imported_target: target,
405
539
  rule: "disallowed_dependency",
406
- message: `Unlisted domain dependency: '${targetDomain}' must be explicitly added to allowed_dependencies before domain '${sourceDomain}' can import it.`,
407
- });
408
- }
540
+ message:
541
+ mode === "proposal"
542
+ ? `Unlisted dependency warning (warn mode): '${targetDomain}' is not declared in allowed_dependencies for domain '${sourceDomain}'.`
543
+ : `Unlisted dependency warning (warn mode): '${targetDomain}' is not declared in allowed_dependencies for domain '${sourceDomain}'.`,
544
+ },
545
+ };
409
546
  }
410
547
 
411
- return violations;
548
+ return { violation: null, warning: null };
412
549
  }
413
550
 
414
551
  public resolveSourceDomain(filePath: string, config: ValidatedSeptumConfig): string | null {