@dimassetoid/septum-mcp 0.3.0 → 0.5.1
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.
- package/README.md +38 -55
- package/package.json +7 -5
- package/src/cli/commands/check.ts +14 -10
- package/src/cli/commands/hook.ts +41 -6
- package/src/cli/commands/init.ts +10 -1
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +32 -4
- package/src/cli/index.ts +7 -0
- package/src/cli/templates/hooks.ts +3 -14
- package/src/cli/templates/skill.ts +17 -10
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +251 -114
- package/src/core/boundary/staged-auditor.ts +147 -55
- package/src/core/config/domain-ownership.ts +6 -4
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +1 -25
- package/src/core/config/schema.ts +24 -36
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +334 -572
- package/src/core/database/repositories/domain.repository.ts +2 -1
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -398
- package/src/core/database/repository.ts +68 -9
- package/src/core/database/schema.ts +26 -0
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +222 -58
- package/src/core/discovery/topology-detector.ts +93 -168
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +287 -88
- package/src/core/parser/extractors/base.ts +11 -3
- package/src/core/parser/extractors/csharp.ts +2 -2
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +397 -481
- package/src/core/parser/extractors/elysia-semantic.ts +172 -475
- package/src/core/parser/extractors/express-semantic.ts +195 -383
- package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
- package/src/core/parser/extractors/fastify-semantic.ts +216 -717
- package/src/core/parser/extractors/flask-semantic.ts +89 -352
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +205 -562
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -509
- package/src/core/parser/extractors/java.ts +2 -2
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +143 -335
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +1 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +5 -9
- package/src/core/parser/extractors/registry.ts +2 -0
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +2 -2
- package/src/core/parser/extractors/rust.ts +4 -4
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +72 -226
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +23 -216
- package/src/core/parser/language-capabilities.ts +1 -1
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +169 -414
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +60 -7
- package/src/core/resolver/interpretation-inputs.ts +60 -2
- package/src/core/resolver/languages/python.ts +31 -13
- package/src/core/resolver/languages/shared.ts +4 -1
- package/src/core/resolver/module-resolver.ts +10 -3
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +21 -6
- package/src/core/resolver/slice-format.ts +13 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +104 -8
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +31 -230
- package/src/core/resources/ignore.ts +0 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +11 -4
- package/src/core/retrieval/context.ts +363 -226
- package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +3 -3
- package/src/core/retrieval/typescript-references.ts +38 -7
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +192 -49
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +255 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -746
- package/src/mcp/server.ts +269 -429
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +68 -3
- package/src/mcp/tools/map.ts +104 -4
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +469 -17
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +88 -15
- package/src/mcp/workspace-watcher.ts +30 -11
- package/src/types/index.ts +12 -0
- package/src/mcp/tools/check-boundary.ts +0 -382
- package/src/mcp/tools/get-domain-catalog.ts +0 -39
- package/src/mcp/tools/get-symbol-impact.ts +0 -104
- package/src/mcp/tools/locate-symbol.ts +0 -236
- package/src/mcp/tools/register-domain.ts +0 -113
- 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
|
|
21
|
+
private repo?: SeptumRepository;
|
|
13
22
|
private resolver: ModuleResolver;
|
|
14
23
|
|
|
15
|
-
constructor(repo
|
|
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.
|
|
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
|
|
48
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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 =
|
|
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?:
|
|
133
|
-
|
|
134
|
-
|
|
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
|
|
145
|
-
if (!preloadedDeps && this.repo
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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 =
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
308
|
-
const cycleStartIndex =
|
|
309
|
-
if (cycleStartIndex !==
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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:
|
|
502
|
+
imported_target: target,
|
|
395
503
|
rule: "forbidden_dependency",
|
|
396
|
-
message:
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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:
|
|
538
|
+
imported_target: target,
|
|
405
539
|
rule: "disallowed_dependency",
|
|
406
|
-
message:
|
|
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
|
|
548
|
+
return { violation: null, warning: null };
|
|
412
549
|
}
|
|
413
550
|
|
|
414
551
|
public resolveSourceDomain(filePath: string, config: ValidatedSeptumConfig): string | null {
|