@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
|
@@ -18,10 +18,29 @@ export async function auditStagedFiles(
|
|
|
18
18
|
config: ValidatedSeptumConfig,
|
|
19
19
|
workspaceRoot: string,
|
|
20
20
|
repo?: SeptumRepository
|
|
21
|
-
): Promise<{
|
|
21
|
+
): Promise<{
|
|
22
|
+
files: string[];
|
|
23
|
+
violations: BoundaryViolation[];
|
|
24
|
+
resolution_issues: ImportResolution[];
|
|
25
|
+
background_resolution_issues_count: number;
|
|
26
|
+
}> {
|
|
22
27
|
const gitRoot = execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd: workspaceRoot, encoding: "utf8" }).trim();
|
|
23
28
|
// Freeze the index as a Git tree. Every source/config/target is read from this tree.
|
|
24
29
|
const tree = execFileSync("git", ["write-tree"], { cwd: gitRoot, encoding: "utf8", timeout: 5000 }).trim();
|
|
30
|
+
const rawPrefix = relative(gitRoot, workspaceRoot).replace(/\\/g, "/");
|
|
31
|
+
const prefix = rawPrefix === "." ? "" : rawPrefix;
|
|
32
|
+
const inside = (file: string) => !prefix || file === prefix || file.startsWith(prefix + "/");
|
|
33
|
+
const hasHead = (() => { try { execFileSync("git", ["rev-parse", "--verify", "HEAD"], { cwd: gitRoot, stdio: "ignore" }); return true; } catch { return false; } })();
|
|
34
|
+
const emptyTree = execFileSync("git", ["hash-object", "-t", "tree", "--stdin"], { cwd: gitRoot, input: "", encoding: "utf8" }).trim();
|
|
35
|
+
const stagedPaths = (filter: string) => execFileSync("git", ["diff-tree", "--root", "--no-commit-id", "-r", "--name-only", `--diff-filter=${filter}`, "-z", hasHead ? "HEAD" : emptyTree, tree], {
|
|
36
|
+
cwd: gitRoot, encoding: "utf-8", timeout: 5000, maxBuffer: 10 * 1024 * 1024,
|
|
37
|
+
}).split("\0").filter(Boolean).map(f => f.replace(/\\/g, "/")).filter(inside);
|
|
38
|
+
const files = stagedPaths("ACMR").map(file => (prefix ? relative(prefix, file) : file).replace(/\\/g, "/"));
|
|
39
|
+
const deleted = stagedPaths("D").map(file => (prefix ? relative(prefix, file) : file).replace(/\\/g, "/"));
|
|
40
|
+
if (files.length === 0 && deleted.length === 0) {
|
|
41
|
+
return { files: [], violations: [], resolution_issues: [], background_resolution_issues_count: 0 };
|
|
42
|
+
}
|
|
43
|
+
|
|
25
44
|
const scratch = mkdtempSync(join(tmpdir(), "septum-staged-"));
|
|
26
45
|
const snapshot = join(scratch, "tree");
|
|
27
46
|
try {
|
|
@@ -32,14 +51,15 @@ export async function auditStagedFiles(
|
|
|
32
51
|
const indexedPaths: string[] = [];
|
|
33
52
|
const blobs: Array<{ oid: string; file: string; size: number }> = [];
|
|
34
53
|
for (const entry of entries) {
|
|
35
|
-
const match = /^(\d+) blob ([a-f0-9]+)\s+(\d
|
|
36
|
-
if (!match
|
|
37
|
-
const [, , oid, sizeText, file] = match;
|
|
54
|
+
const match = /^(\d+) (?:blob|commit) ([a-f0-9]+)\s+(\d+|-)\t([\s\S]+)$/.exec(entry);
|
|
55
|
+
if (!match) continue;
|
|
56
|
+
const [, mode, oid, sizeText, file] = match;
|
|
38
57
|
// Only source and interpretation inputs need bytes in the parser snapshot.
|
|
39
58
|
// Keep the complete path inventory so omitted assets cannot masquerade as source.
|
|
40
59
|
indexedPaths.push(file!);
|
|
41
60
|
const needed = ASTParserEngine.isSourceFile(file!) || isResolutionInput(file!);
|
|
42
61
|
if (!needed) continue;
|
|
62
|
+
if (!["100644", "100755"].includes(mode!)) throw new Error("Cannot certify staged view containing symlinks or submodules.");
|
|
43
63
|
const size = Number(sizeText);
|
|
44
64
|
totalBytes += size;
|
|
45
65
|
if (size > RESOURCE_LIMITS.sourceBytes || totalBytes > 128 * 1024 * 1024) throw new Error("Staged view exceeds resource limits.");
|
|
@@ -47,74 +67,146 @@ export async function auditStagedFiles(
|
|
|
47
67
|
if (!destination.startsWith(snapshot + "/")) throw new Error("Invalid staged path.");
|
|
48
68
|
blobs.push({ oid: oid!, file: file!, size });
|
|
49
69
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
const parser = new ASTParserEngine();
|
|
71
|
+
const interpretationChanged = [...files, ...deleted].some(isResolutionInput);
|
|
72
|
+
const changed = new Set(files);
|
|
73
|
+
const canUseFastPath =
|
|
74
|
+
!interpretationChanged &&
|
|
75
|
+
repo?.getMeta("sync_state") === "complete" &&
|
|
76
|
+
repo.getMeta("parser_revision") === PARSER_FINGERPRINT;
|
|
77
|
+
|
|
78
|
+
const indexedFileSet = canUseFastPath
|
|
79
|
+
? new Set(repo!.getAllFiles().map(f => f.path))
|
|
80
|
+
: undefined;
|
|
81
|
+
const unstagedModified = canUseFastPath
|
|
82
|
+
? new Set(
|
|
83
|
+
execFileSync("git", ["diff-files", "--name-only", "-z"], {
|
|
84
|
+
cwd: gitRoot,
|
|
85
|
+
encoding: "utf8",
|
|
86
|
+
timeout: 5000,
|
|
87
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
88
|
+
})
|
|
89
|
+
.split("\0")
|
|
90
|
+
.filter(Boolean)
|
|
91
|
+
.map(f => f.replace(/\\/g, "/"))
|
|
92
|
+
.filter(inside)
|
|
93
|
+
.map(f => (prefix ? relative(prefix, f) : f).replace(/\\/g, "/"))
|
|
94
|
+
)
|
|
95
|
+
: undefined;
|
|
96
|
+
|
|
97
|
+
const blobsToFetch: Array<{ oid: string; file: string; size: number }> = [];
|
|
98
|
+
const placeholderFiles: string[] = [];
|
|
99
|
+
for (const blob of blobs) {
|
|
100
|
+
const relFile = (prefix ? relative(prefix, blob.file) : blob.file).replace(/\\/g, "/");
|
|
101
|
+
const needsBytes =
|
|
102
|
+
!canUseFastPath ||
|
|
103
|
+
changed.has(relFile) ||
|
|
104
|
+
isResolutionInput(blob.file) ||
|
|
105
|
+
isResolutionInput(relFile) ||
|
|
106
|
+
!indexedFileSet!.has(relFile) ||
|
|
107
|
+
unstagedModified!.has(relFile);
|
|
108
|
+
if (needsBytes) {
|
|
109
|
+
blobsToFetch.push(blob);
|
|
110
|
+
} else {
|
|
111
|
+
placeholderFiles.push(blob.file);
|
|
67
112
|
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
for (const file of placeholderFiles) {
|
|
68
116
|
const destination = resolve(snapshot, file);
|
|
69
117
|
mkdirSync(dirname(destination), { recursive: true });
|
|
70
|
-
|
|
71
|
-
|
|
118
|
+
closeSync(openSync(destination, "w"));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (blobsToFetch.length > 0) {
|
|
122
|
+
// One raw-blob process, spooled to disk to bound JS memory. checkout-index
|
|
123
|
+
// applies smudge/EOL/encoding filters; archive applies export attributes.
|
|
124
|
+
// Neither is a faithful raw index snapshot for parsing and resolution.
|
|
125
|
+
const batchPath = join(scratch, "blobs");
|
|
126
|
+
const fd = openSync(batchPath, "w");
|
|
127
|
+
try {
|
|
128
|
+
execFileSync("git", ["cat-file", "--batch"], { cwd: gitRoot, timeout: 30000,
|
|
129
|
+
input: blobsToFetch.map(blob => blob.oid + "\n").join(""), stdio: ["pipe", fd, "pipe"] });
|
|
130
|
+
} finally { closeSync(fd); }
|
|
131
|
+
const batch = Bun.file(batchPath);
|
|
132
|
+
let offset = 0;
|
|
133
|
+
for (const { oid, file, size } of blobsToFetch) {
|
|
134
|
+
const header = `${oid} blob ${size}\n`;
|
|
135
|
+
const length = header.length + size + 1;
|
|
136
|
+
const record = Buffer.from(await batch.slice(offset, offset + length).arrayBuffer());
|
|
137
|
+
if (record.length !== length || record.subarray(0, header.length).toString() !== header || record[length - 1] !== 10) {
|
|
138
|
+
throw new Error("Invalid staged blob batch.");
|
|
139
|
+
}
|
|
140
|
+
const destination = resolve(snapshot, file);
|
|
141
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
142
|
+
writeFileSync(destination, record.subarray(header.length, length - 1));
|
|
143
|
+
offset += length;
|
|
144
|
+
}
|
|
72
145
|
}
|
|
73
|
-
const rawPrefix = relative(gitRoot, workspaceRoot).replace(/\\/g, "/");
|
|
74
|
-
const prefix = rawPrefix === "." ? "" : rawPrefix;
|
|
75
|
-
const inside = (file: string) => !prefix || file === prefix || file.startsWith(prefix + "/");
|
|
76
|
-
const hasHead = (() => { try { execFileSync("git", ["rev-parse", "--verify", "HEAD"], { cwd: gitRoot, stdio: "ignore" }); return true; } catch { return false; } })();
|
|
77
|
-
const emptyTree = execFileSync("git", ["hash-object", "-t", "tree", "--stdin"], { cwd: gitRoot, input: "", encoding: "utf8" }).trim();
|
|
78
|
-
const stagedPaths = (filter: string) => execFileSync("git", ["diff-tree", "--root", "--no-commit-id", "-r", "--name-only", `--diff-filter=${filter}`, "-z", hasHead ? "HEAD" : emptyTree, tree], {
|
|
79
|
-
cwd: gitRoot, encoding: "utf-8", timeout: 5000, maxBuffer: 10 * 1024 * 1024,
|
|
80
|
-
}).split("\0").filter(Boolean).map(f => f.replace(/\\/g, "/")).filter(inside);
|
|
81
|
-
const files = stagedPaths("ACMR").map(file => (prefix ? relative(prefix, file) : file).replace(/\\/g, "/"));
|
|
82
|
-
const deleted = stagedPaths("D").map(file => (prefix ? relative(prefix, file) : file).replace(/\\/g, "/"));
|
|
83
146
|
const snapshotRoot = join(snapshot, prefix);
|
|
84
147
|
evaluator = evaluator.withResolver(new ModuleResolver(snapshotRoot));
|
|
85
148
|
const violations: BoundaryViolation[] = [];
|
|
86
149
|
const resolutionIssues: ImportResolution[] = [];
|
|
150
|
+
let backgroundResolutionIssuesCount = 0;
|
|
87
151
|
const stagedDependencies: ReturnType<SeptumRepository["getAllDependenciesWithDomains"]> = [];
|
|
88
|
-
const parser = new ASTParserEngine();
|
|
89
|
-
const interpretationChanged = [...files, ...deleted].some(isResolutionInput);
|
|
90
|
-
const changed = new Set(files);
|
|
91
152
|
const sourceFiles = indexedPaths.filter(inside).map(file => (prefix ? relative(prefix, file) : file).replace(/\\/g, "/"));
|
|
153
|
+
const repoDepsByFile = canUseFastPath
|
|
154
|
+
? (() => {
|
|
155
|
+
const map = new Map<string, ReturnType<SeptumRepository["getAllDependenciesWithDomains"]>>();
|
|
156
|
+
for (const dep of repo!.getAllDependenciesWithDomains()) {
|
|
157
|
+
const list = map.get(dep.source_file) ?? [];
|
|
158
|
+
list.push(dep);
|
|
159
|
+
map.set(dep.source_file, list);
|
|
160
|
+
}
|
|
161
|
+
return map;
|
|
162
|
+
})()
|
|
163
|
+
: undefined;
|
|
164
|
+
|
|
92
165
|
for (const file of sourceFiles) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
166
|
+
const sourceDomain = evaluator.resolveSourceDomain(file, config);
|
|
167
|
+
if (!ASTParserEngine.isSourceFile(file) || !sourceDomain) continue;
|
|
168
|
+
let dependencies: Array<{ target: string; statement: string; line_number: number; is_external: boolean }>;
|
|
169
|
+
if (canUseFastPath && !changed.has(file) && indexedFileSet!.has(file) && !unstagedModified!.has(file)) {
|
|
170
|
+
dependencies = repoDepsByFile!.get(file) ?? [];
|
|
171
|
+
} else {
|
|
172
|
+
const content = await Bun.file(resolve(snapshotRoot, file)).text();
|
|
173
|
+
const existing = repo?.getFileByPath(file);
|
|
174
|
+
const reusable = !changed.has(file) && !interpretationChanged &&
|
|
175
|
+
repo?.getMeta("sync_state") === "complete" && repo.getMeta("parser_revision") === PARSER_FINGERPRINT &&
|
|
176
|
+
existing?.content_hash === computeContentHash(content);
|
|
177
|
+
dependencies = reusable ? repo!.getDependenciesByFileId(existing!.id) : await (async () => {
|
|
178
|
+
const parsed = await parser.parseFile(resolve(snapshotRoot, file), content);
|
|
179
|
+
if (parsed.status === "unsupported" || parsed.status === "degraded") {
|
|
180
|
+
throw new Error(`Cannot reliably parse staged file '${file}': ${parsed.status}.`);
|
|
181
|
+
}
|
|
182
|
+
return parsed.dependencies;
|
|
183
|
+
})();
|
|
184
|
+
}
|
|
106
185
|
for (const dependency of dependencies) {
|
|
107
|
-
stagedDependencies.push({ source_file: file, source_domain:
|
|
108
|
-
const
|
|
109
|
-
const resolution = evaluator.getResolver().resolveImport(dependency.target,file,dependency.statement);
|
|
186
|
+
stagedDependencies.push({ source_file: file, source_domain: sourceDomain, target: dependency.target, statement: dependency.statement, line_number: dependency.line_number, is_external: dependency.is_external });
|
|
187
|
+
const isRelevantFile = changed.has(file) || interpretationChanged;
|
|
188
|
+
const resolution = evaluator.getResolver().resolveImport(dependency.target, file, dependency.statement);
|
|
189
|
+
const needsViolationCheck = isRelevantFile || !["resolved", "external"].includes(resolution.status) || resolution.coverage === "conditional";
|
|
190
|
+
const found = needsViolationCheck
|
|
191
|
+
? evaluator.checkProposedChanges(file, [dependency.target], config, [dependency.statement]).map(violation => ({ ...violation, line: dependency.line_number }))
|
|
192
|
+
: [];
|
|
110
193
|
if (found.length === 0 && (!["resolved","external"].includes(resolution.status) || resolution.coverage === "conditional")) {
|
|
111
|
-
|
|
194
|
+
if (isRelevantFile) {
|
|
195
|
+
resolutionIssues.push(resolution);
|
|
196
|
+
} else {
|
|
197
|
+
backgroundResolutionIssuesCount++;
|
|
198
|
+
}
|
|
112
199
|
}
|
|
113
|
-
if (
|
|
200
|
+
if (isRelevantFile) violations.push(...found);
|
|
114
201
|
}
|
|
115
202
|
}
|
|
116
203
|
const staged = new Set([...files, ...deleted]);
|
|
117
204
|
violations.push(...evaluator.detectCircularDependencies(config, stagedDependencies, interpretationChanged ? new Set(sourceFiles) : staged));
|
|
118
|
-
return {
|
|
205
|
+
return {
|
|
206
|
+
files: Array.from(staged),
|
|
207
|
+
violations,
|
|
208
|
+
resolution_issues: resolutionIssues,
|
|
209
|
+
background_resolution_issues_count: backgroundResolutionIssuesCount,
|
|
210
|
+
};
|
|
119
211
|
} finally { rmSync(scratch, { recursive: true, force: true }); }
|
|
120
212
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { lstatSync, realpathSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
import { SeptumError } from "../errors.ts";
|
|
3
4
|
|
|
4
5
|
// SQLite's built-in NOCASE/LOWER folds ASCII, not all Unicode case pairs.
|
|
5
6
|
export function domainNameKey(name: string): string {
|
|
6
7
|
return name.replace(/[A-Z]/g, letter => letter.toLowerCase());
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export class DomainRootConflictError extends
|
|
10
|
-
readonly code = "DOMAIN_ROOT_CONFLICT";
|
|
10
|
+
export class DomainRootConflictError extends SeptumError {
|
|
11
11
|
constructor(readonly owner: string, readonly contender: string, readonly root: string) {
|
|
12
|
-
super(
|
|
13
|
-
|
|
12
|
+
super(
|
|
13
|
+
"DOMAIN_ROOT_CONFLICT",
|
|
14
|
+
`Domain root conflict: '${owner}' and '${contender}' both own '${root}'. Update the existing domain by name, or move one domain to a distinct root. Nested roots are allowed; no domains were merged or deleted.`
|
|
15
|
+
);
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import type { SeptumRepository } from "../database/repository.ts";
|
|
4
|
+
import { IngestionPipeline, type IngestionMetrics } from "../ingestion/pipeline.ts";
|
|
5
|
+
import { assertPathContained } from "../resolver/path-resolver.ts";
|
|
6
|
+
import { assertUniqueDomainRoots, domainNameKey, domainRootIdentity } from "./domain-ownership.ts";
|
|
7
|
+
import { ConfigLoader } from "./loader.ts";
|
|
8
|
+
import { SeptumConfigSchema, type ValidatedSeptumConfig } from "./schema.ts";
|
|
9
|
+
import type { DomainConfig } from "../../types/index.ts";
|
|
10
|
+
|
|
11
|
+
export interface DomainRegistrationInput {
|
|
12
|
+
domain?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
root?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
allowed_dependencies?: string[];
|
|
17
|
+
forbidden_dependencies?: string[];
|
|
18
|
+
archetypes?: Record<string, string>;
|
|
19
|
+
ingest_now?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DomainRegistrationResult {
|
|
23
|
+
policyOwner: "database" | "file";
|
|
24
|
+
domainId: number;
|
|
25
|
+
domain: string;
|
|
26
|
+
config: ValidatedSeptumConfig["domains"][string];
|
|
27
|
+
ingestionMetrics: IngestionMetrics | null;
|
|
28
|
+
conflictPending: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function registerDomainPolicy(
|
|
32
|
+
repo: SeptumRepository,
|
|
33
|
+
config: ValidatedSeptumConfig,
|
|
34
|
+
args: DomainRegistrationInput,
|
|
35
|
+
workspaceRoot: string = process.cwd(),
|
|
36
|
+
signal?: AbortSignal
|
|
37
|
+
): Promise<DomainRegistrationResult> {
|
|
38
|
+
signal?.throwIfAborted();
|
|
39
|
+
const domainName = (args.domain || args.name || "").trim();
|
|
40
|
+
if (!domainName || !args.root) {
|
|
41
|
+
throw new Error("Missing required arguments: 'domain' (or 'name') and 'root' are required.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// SV-02: Enforce workspace containment (reject traversal/absolute/symlink escape)
|
|
45
|
+
assertPathContained(args.root, workspaceRoot, "Domain root");
|
|
46
|
+
const absDomainRoot = resolve(workspaceRoot, args.root);
|
|
47
|
+
try {
|
|
48
|
+
const rootStat = statSync(absDomainRoot);
|
|
49
|
+
if (!rootStat.isDirectory()) {
|
|
50
|
+
throw new Error(`Domain root '${args.root}' is not a directory.`);
|
|
51
|
+
}
|
|
52
|
+
} catch (err: any) {
|
|
53
|
+
if (err?.code !== "ENOENT") {
|
|
54
|
+
if (err instanceof Error && err.message.endsWith("is not a directory.")) throw err;
|
|
55
|
+
throw new Error(`Failed to access domain root '${args.root}' for domain '${domainName}': ${err?.message || err}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
signal?.throwIfAborted();
|
|
59
|
+
|
|
60
|
+
const domainConfig: DomainConfig = {
|
|
61
|
+
root: args.root,
|
|
62
|
+
description: args.description || `Domain: ${domainName}`,
|
|
63
|
+
allowed_dependencies: args.allowed_dependencies,
|
|
64
|
+
forbidden_dependencies: args.forbidden_dependencies,
|
|
65
|
+
archetypes: args.archetypes,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const proposed = domainRootIdentity(args.root, workspaceRoot);
|
|
69
|
+
const memoryClaims = Object.fromEntries(
|
|
70
|
+
Object.entries(config.domains).filter(
|
|
71
|
+
([name, claim]) => domainNameKey(name) !== domainNameKey(domainName) && domainRootIdentity(claim.root, workspaceRoot) === proposed
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
assertUniqueDomainRoots({ ...memoryClaims, [domainName]: domainConfig }, workspaceRoot);
|
|
75
|
+
|
|
76
|
+
const policyFile = join(workspaceRoot, "septum.config.json");
|
|
77
|
+
const policySource = existsSync(policyFile) ? readFileSync(policyFile, "utf8") : undefined;
|
|
78
|
+
if (policySource !== undefined) {
|
|
79
|
+
const policy = SeptumConfigSchema.parse(JSON.parse(policySource));
|
|
80
|
+
const existing = Object.entries(policy.domains).find(([name]) => domainNameKey(name) === domainNameKey(domainName))?.[1];
|
|
81
|
+
domainConfig.allowed_dependencies ??= existing?.allowed_dependencies ?? [];
|
|
82
|
+
domainConfig.forbidden_dependencies ??= existing?.forbidden_dependencies ?? [];
|
|
83
|
+
domainConfig.archetypes ??= existing?.archetypes ?? {};
|
|
84
|
+
domainConfig.description = args.description ?? existing?.description ?? domainConfig.description;
|
|
85
|
+
const diskClaims = Object.fromEntries(
|
|
86
|
+
Object.entries(policy.domains).filter(
|
|
87
|
+
([name, claim]) => domainNameKey(name) !== domainNameKey(domainName) && domainRootIdentity(claim.root, workspaceRoot) === proposed
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
assertUniqueDomainRoots({ ...diskClaims, [domainName]: domainConfig }, workspaceRoot);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const domainId = repo.runInTransaction(() => {
|
|
94
|
+
const id = repo.domains.upsertDomain(domainName, domainConfig, workspaceRoot);
|
|
95
|
+
const stored = repo.domains.getDomainByName(domainName)!;
|
|
96
|
+
if (policySource !== undefined) {
|
|
97
|
+
ConfigLoader.writeDomain(
|
|
98
|
+
workspaceRoot,
|
|
99
|
+
stored.name,
|
|
100
|
+
{
|
|
101
|
+
...domainConfig,
|
|
102
|
+
allowed_dependencies: JSON.parse(stored.allowed_deps_json),
|
|
103
|
+
forbidden_dependencies: JSON.parse(stored.forbidden_deps_json),
|
|
104
|
+
archetypes: JSON.parse(stored.archetypes_json),
|
|
105
|
+
},
|
|
106
|
+
policySource
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
repo.rebindFilesToDomain(stored.root_path || domainConfig.root, id);
|
|
110
|
+
return id;
|
|
111
|
+
}, true);
|
|
112
|
+
|
|
113
|
+
const stored = repo.domains.getDomainByName(domainName);
|
|
114
|
+
const canonicalName = stored?.name || domainName;
|
|
115
|
+
const finalConfig: ValidatedSeptumConfig["domains"][string] = {
|
|
116
|
+
root: stored?.root_path || domainConfig.root,
|
|
117
|
+
description: domainConfig.description,
|
|
118
|
+
allowed_dependencies: stored ? JSON.parse(stored.allowed_deps_json || "[]") : (domainConfig.allowed_dependencies || []),
|
|
119
|
+
forbidden_dependencies: stored ? JSON.parse(stored.forbidden_deps_json || "[]") : (domainConfig.forbidden_dependencies || []),
|
|
120
|
+
archetypes: stored ? JSON.parse(stored.archetypes_json || "{}") : (domainConfig.archetypes || {}),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
let ingestionMetrics: IngestionMetrics | null = null;
|
|
124
|
+
if (args.ingest_now) {
|
|
125
|
+
const nextConfig: ValidatedSeptumConfig = {
|
|
126
|
+
...config,
|
|
127
|
+
domains: { ...config.domains, [canonicalName]: finalConfig },
|
|
128
|
+
};
|
|
129
|
+
const pipeline = new IngestionPipeline(repo, workspaceRoot);
|
|
130
|
+
ingestionMetrics = await pipeline.run(nextConfig, { signal });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
policyOwner: policySource === undefined ? "database" : "file",
|
|
135
|
+
domainId,
|
|
136
|
+
domain: canonicalName,
|
|
137
|
+
config: finalConfig,
|
|
138
|
+
ingestionMetrics,
|
|
139
|
+
conflictPending: repo.getMeta("sync_error_code") === "DOMAIN_ROOT_CONFLICT",
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -97,31 +97,7 @@ export class ConfigLoader {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
public static getDefaultConfig(): ValidatedSeptumConfig {
|
|
100
|
-
return {
|
|
101
|
-
version: "1.0",
|
|
102
|
-
settings: {
|
|
103
|
-
enforcement: "warn",
|
|
104
|
-
db_path: ".septum/septum.db",
|
|
105
|
-
ignore_patterns: [
|
|
106
|
-
"node_modules/**",
|
|
107
|
-
"vendor/**",
|
|
108
|
-
"dist/**",
|
|
109
|
-
"build/**",
|
|
110
|
-
"out/**",
|
|
111
|
-
"target/**",
|
|
112
|
-
"coverage/**",
|
|
113
|
-
".venv/**",
|
|
114
|
-
"venv/**",
|
|
115
|
-
"__pycache__/**",
|
|
116
|
-
"tests/**",
|
|
117
|
-
"scripts/**",
|
|
118
|
-
"bin/**",
|
|
119
|
-
".git/**",
|
|
120
|
-
".septum/**",
|
|
121
|
-
],
|
|
122
|
-
},
|
|
123
|
-
domains: {},
|
|
124
|
-
};
|
|
100
|
+
return SeptumConfigSchema.parse({});
|
|
125
101
|
}
|
|
126
102
|
|
|
127
103
|
public static loadFromRepository(repo: SeptumRepository): ValidatedSeptumConfig {
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
+
export const DEFAULT_IGNORE_PATTERNS = [
|
|
4
|
+
"node_modules/**",
|
|
5
|
+
"vendor/**",
|
|
6
|
+
"dist/**",
|
|
7
|
+
"build/**",
|
|
8
|
+
"out/**",
|
|
9
|
+
"target/**",
|
|
10
|
+
"coverage/**",
|
|
11
|
+
".venv/**",
|
|
12
|
+
"venv/**",
|
|
13
|
+
"__pycache__/**",
|
|
14
|
+
"tests/**",
|
|
15
|
+
"scripts/**",
|
|
16
|
+
"bin/**",
|
|
17
|
+
".git/**",
|
|
18
|
+
".septum/**",
|
|
19
|
+
];
|
|
20
|
+
|
|
3
21
|
export const DomainConfigSchema = z.object({
|
|
4
22
|
root: z.string().min(1, "root path cannot be empty"),
|
|
5
23
|
description: z.string().optional(),
|
|
@@ -12,47 +30,17 @@ export const SeptumConfigSchema = z.object({
|
|
|
12
30
|
version: z.string().default("1.0"),
|
|
13
31
|
settings: z
|
|
14
32
|
.object({
|
|
15
|
-
enforcement: z.enum(["strict", "warn"]).default("
|
|
33
|
+
enforcement: z.enum(["strict", "warn"]).default("warn"),
|
|
16
34
|
db_path: z.string().default(".septum/septum.db"),
|
|
17
35
|
ignore_patterns: z
|
|
18
36
|
.array(z.string())
|
|
19
|
-
.default([
|
|
20
|
-
"node_modules/**",
|
|
21
|
-
"vendor/**",
|
|
22
|
-
"dist/**",
|
|
23
|
-
"build/**",
|
|
24
|
-
"out/**",
|
|
25
|
-
"target/**",
|
|
26
|
-
"coverage/**",
|
|
27
|
-
".venv/**",
|
|
28
|
-
"venv/**",
|
|
29
|
-
"__pycache__/**",
|
|
30
|
-
"tests/**",
|
|
31
|
-
"scripts/**",
|
|
32
|
-
"bin/**",
|
|
33
|
-
".git/**",
|
|
34
|
-
]),
|
|
37
|
+
.default(() => [...DEFAULT_IGNORE_PATTERNS]),
|
|
35
38
|
})
|
|
36
|
-
.default({
|
|
37
|
-
enforcement: "
|
|
39
|
+
.default(() => ({
|
|
40
|
+
enforcement: "warn" as const,
|
|
38
41
|
db_path: ".septum/septum.db",
|
|
39
|
-
ignore_patterns: [
|
|
40
|
-
|
|
41
|
-
"vendor/**",
|
|
42
|
-
"dist/**",
|
|
43
|
-
"build/**",
|
|
44
|
-
"out/**",
|
|
45
|
-
"target/**",
|
|
46
|
-
"coverage/**",
|
|
47
|
-
".venv/**",
|
|
48
|
-
"venv/**",
|
|
49
|
-
"__pycache__/**",
|
|
50
|
-
"tests/**",
|
|
51
|
-
"scripts/**",
|
|
52
|
-
"bin/**",
|
|
53
|
-
".git/**",
|
|
54
|
-
],
|
|
55
|
-
}),
|
|
42
|
+
ignore_patterns: [...DEFAULT_IGNORE_PATTERNS],
|
|
43
|
+
})),
|
|
56
44
|
domains: z.record(DomainConfigSchema).default({}),
|
|
57
45
|
});
|
|
58
46
|
|
|
@@ -32,6 +32,8 @@ export class SeptumDatabase {
|
|
|
32
32
|
this.db.run("PRAGMA busy_timeout = 5000;");
|
|
33
33
|
this.db.run("PRAGMA foreign_keys = ON;");
|
|
34
34
|
this.db.run("PRAGMA synchronous = NORMAL;");
|
|
35
|
+
this.db.run("PRAGMA temp_store = MEMORY;");
|
|
36
|
+
this.db.run("PRAGMA cache_size = -16000;");
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
private initSchema(): void {
|