@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.
- 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 +253 -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
|
@@ -10,27 +10,29 @@ Septum indexes selected source declarations, imports, domain ownership and stati
|
|
|
10
10
|
|
|
11
11
|
## Select the tool
|
|
12
12
|
|
|
13
|
+
All 4 tools default to \`format: "text"\` (token-efficient compact markdown summary); pass \`format: "json"\` when structured JSON is required.
|
|
14
|
+
|
|
13
15
|
| Need | Request | Read from the result |
|
|
14
16
|
| --- | --- | --- |
|
|
15
|
-
| Workspace/domain/file navigation | \`septum_map\`, \`action: "catalog"\`, \`detail_level: "compact"\`, optional \`domain\`/\`file_filter\` | \`
|
|
16
|
-
| Domain policy registration | \`septum_map\`, \`action: "register"\`, \`
|
|
17
|
-
| Declaration lookup | \`septum_symbol\`, \`action: "locate"\`, \`query\` | Indexed coordinates, \`symbol_ref\`,
|
|
18
|
-
| TypeScript reference context | \`septum_symbol\`, \`action: "context"\`, \`context_mode: "deep"\` |
|
|
17
|
+
| Workspace/domain/file navigation | \`septum_map\`, \`action: "catalog"\`, \`detail_level: "compact"\`, optional \`domain\`/\`file_filter\`/\`format\` | \`submodules\` + aggregated dependencies (for large domains >25 files), files/anchors, directed \`dependencies\`, static \`entrypoints\`, \`health\`, \`next\` |
|
|
18
|
+
| Domain policy registration | \`septum_map\`, \`action: "register"\`, \`domain\`, \`root\`, dependency lists | Recorded policy, \`policy_owner\` and any ingestion result |
|
|
19
|
+
| Declaration lookup | \`septum_symbol\`, \`action: "locate"\`, \`query\` | Indexed coordinates, \`symbol_ref\`, token/camelCase-ranked suggestions and retrieval freshness |
|
|
20
|
+
| TypeScript reference context | \`septum_symbol\`, \`action: "context"\`, \`context_mode: "deep"\`, optional \`max_depth\` (1–4, default 2) | True hop-ordered (\`hop 0→1→2\`, direct local/imported callees & contracts first) source/contracts, diagnostics, accounting and continuation |
|
|
19
21
|
| Source/signature inspection | \`septum_symbol\`, \`action: "context"\`, \`context_mode: "source"\` | Source slice or signature/dependency details and source status |
|
|
20
|
-
| Potential consumers | \`septum_symbol\`, \`action: "impact"\` |
|
|
21
|
-
| Supported route/handler/job/CLI/event | \`septum_slice\`, \`query\`, optional \`controller_file
|
|
22
|
+
| Potential consumers | \`septum_symbol\`, \`action: "impact"\` | Separated \`call_sites\`, \`runtime_imports\`, \`type_only_imports\`, warnings and uncertainty |
|
|
23
|
+
| Supported route/handler/job/CLI/event | \`septum_slice\`, \`query\`, optional \`controller_file\`, \`max_depth\`, \`format\` | Catalog target (\`exact\` match for \`METHOD target\`), indented parent-attributed chain and diagnostics |
|
|
22
24
|
| Proposed imports | \`septum_boundary\`, \`scope: "file"\`, \`file_path\`, \`proposed_imports\` | Proposal decision and evaluated scope |
|
|
23
25
|
| Existing indexed or staged imports | \`septum_boundary\`, \`scope: "all" / "domain" / "staged"\` | Scoped violations, incomplete resolution and recovery hints |
|
|
24
26
|
|
|
25
27
|
## Context selection
|
|
26
28
|
|
|
27
|
-
Deep context supports indexed \`.ts\`, \`.mts\` and \`.cts\` declarations. It follows bounded supported references and can project public type contracts. It does not establish a complete business dependency closure.
|
|
29
|
+
Deep context supports indexed \`.ts\`, \`.tsx\`, \`.mts\` and \`.cts\` declarations. It follows bounded supported references up to \`max_depth\` import edges (default \`2\`, max \`4\`), ranks items hop-first (\`depth 0 → 1 → 2\`, direct calls and contracts ahead of transitive helpers), and can project public type contracts. It does not establish a complete business dependency closure.
|
|
28
30
|
|
|
29
|
-
Use \`budget_bytes\` only for deep context. Do not combine
|
|
31
|
+
Use \`budget_bytes\` and \`max_depth\` only for deep context. Do not combine them with \`include_source\`, \`source_start_line\` or \`source_line_limit\`. Those options select bounded source inspection when no explicit mode is supplied. \`inspect\` is an alias for \`context\`.
|
|
30
32
|
|
|
31
|
-
Source mode includes target source by default. Use \`include_source: false\` for signature/dependency details. When a source slice is truncated, follow \`next_start_line\`. One-hop delegation expansion is heuristic; inspect the selected dependency before treating it as a callee.
|
|
33
|
+
Source mode includes target source by default. Use \`include_source: false\` for signature/dependency details. When a source slice is truncated, follow \`next_start_line\`. One-hop delegation expansion (including same-file local helper delegation for polyglot files) is heuristic; inspect the selected dependency before treating it as a callee.
|
|
32
34
|
|
|
33
|
-
For deep-context pages, pass the returned \`continuation\` with unchanged target, workspace, configuration and budget. Restart retrieval on invalid/stale continuation. Capacity omissions are distinct from pagination.
|
|
35
|
+
For deep-context pages, pass the returned \`continuation\` with unchanged target, workspace, configuration, \`max_depth\` and budget. Restart retrieval on invalid/stale continuation. Capacity omissions are distinct from pagination.
|
|
34
36
|
|
|
35
37
|
## Workflow and evidence limits
|
|
36
38
|
|
|
@@ -49,6 +51,11 @@ Language declaration support does not imply equivalent module resolution. Rust/C
|
|
|
49
51
|
|
|
50
52
|
Set \`workspace_path\` when selecting among repositories. If the MCP tools are unavailable or insufficient, use direct source inspection and appropriate project verification.
|
|
51
53
|
|
|
54
|
+
## Resources & Prompts
|
|
55
|
+
|
|
56
|
+
- **MCP Resources (initial workspace):** \`septum://domains\`, \`septum://health\`, \`septum://boundaries\`, and \`septum://domain/{name}\` provide read-only JSON snapshots for the server's initial workspace; use the 4 MCP tools with \`workspace_path\` for multi-root queries.
|
|
57
|
+
- **MCP Prompts:** \`septum-pre-edit-check\` and \`septum-architecture-audit\` provide step-by-step verification playbooks.
|
|
58
|
+
|
|
52
59
|
Describe the operation and observed result. Do not promise token savings, response speed, memory savings, complete caller discovery or universal language/framework coverage.
|
|
53
60
|
`;
|
|
54
61
|
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import type { ImportEvidence } from "../resolver/import-evidence.ts";
|
|
2
|
+
import { relative, resolve } from "node:path";
|
|
3
|
+
import { auditStagedFiles } from "../boundary/staged-auditor.ts";
|
|
4
|
+
import type { BoundaryEvaluator } from "../boundary/evaluator.ts";
|
|
5
|
+
import { ConfigLoader } from "../config/loader.ts";
|
|
6
|
+
import type { ValidatedSeptumConfig } from "../config/schema.ts";
|
|
7
|
+
import type { SeptumRepository } from "../database/repository.ts";
|
|
8
|
+
import type { BoundaryViolation } from "../../types/index.ts";
|
|
9
|
+
|
|
10
|
+
export interface BoundaryAuditRequest {
|
|
11
|
+
file_path?: string;
|
|
12
|
+
file_paths?: string[];
|
|
13
|
+
proposed_imports?: string[];
|
|
14
|
+
proposed_imports_supplied?: boolean;
|
|
15
|
+
scope?: "file" | "all" | "staged" | "domain";
|
|
16
|
+
domain?: string;
|
|
17
|
+
staged?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface BoundaryAuditPayload {
|
|
21
|
+
status: "approved" | "rejected" | "unknown";
|
|
22
|
+
message: string;
|
|
23
|
+
violations?: BoundaryViolation[];
|
|
24
|
+
unsupported_files?: string[];
|
|
25
|
+
skipped_files?: { path: string; reason: string }[];
|
|
26
|
+
relationships?: ReturnType<SeptumRepository["getImportRelationships"]>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function incompleteEvidence<T extends BoundaryAuditPayload>(payload: T) {
|
|
30
|
+
return { payload, kind: "incomplete_evidence" as const };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function evaluated<T extends BoundaryAuditPayload>(payload: T) {
|
|
34
|
+
return { payload, kind: "evaluated" as const };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function summarizeViolations(violations: BoundaryViolation[]) {
|
|
38
|
+
const circularDependencies = violations.filter((v) => v.rule === "circular_dependency");
|
|
39
|
+
const domainBreakdown: Record<string, number> = {};
|
|
40
|
+
for (const v of violations) {
|
|
41
|
+
const pair = `${v.source_domain} -> ${v.target_domain}`;
|
|
42
|
+
domainBreakdown[pair] = (domainBreakdown[pair] || 0) + 1;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
circular_dependencies_count: circularDependencies.length,
|
|
46
|
+
circular_dependencies: circularDependencies,
|
|
47
|
+
domain_violation_breakdown: domainBreakdown,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function evaluateBoundary(
|
|
52
|
+
evaluator: BoundaryEvaluator,
|
|
53
|
+
loadedConfig: ValidatedSeptumConfig,
|
|
54
|
+
args: BoundaryAuditRequest,
|
|
55
|
+
repo: SeptumRepository | undefined,
|
|
56
|
+
root: string
|
|
57
|
+
) {
|
|
58
|
+
// Ingestion retains or discovers domains when file policy does not name any.
|
|
59
|
+
// Use those indexed policies while keeping the explicitly loaded settings.
|
|
60
|
+
const config = repo && Object.keys(loadedConfig.domains).length === 0
|
|
61
|
+
? { ...loadedConfig, domains: ConfigLoader.loadFromRepository(repo).domains }
|
|
62
|
+
: loadedConfig;
|
|
63
|
+
if (args.domain) {
|
|
64
|
+
const knownDomains = new Set([
|
|
65
|
+
...Object.keys(config.domains || {}),
|
|
66
|
+
...(repo?.getAllDomains?.().map((d) => d.name) ?? []),
|
|
67
|
+
]);
|
|
68
|
+
const domain = [...knownDomains].find(name => name.toLowerCase() === args.domain!.toLowerCase());
|
|
69
|
+
if (!domain) throw new Error(`Unknown boundary domain '${args.domain}'. Choose a registered domain.`);
|
|
70
|
+
args = { ...args, domain };
|
|
71
|
+
}
|
|
72
|
+
const proposedImports = args.proposed_imports ?? [];
|
|
73
|
+
const evaluatedScope = { mode: "proposal", proposed_imports_supplied: args.proposed_imports_supplied, existing_imports_checked: false, omissions: ["Existing file imports are not certified by proposal approval."] };
|
|
74
|
+
|
|
75
|
+
const requested = [...(Array.isArray(args.file_path) ? args.file_path : args.file_path ? [args.file_path] : []), ...(args.file_paths || [])]
|
|
76
|
+
.map(file => relative(root, resolve(root, file)).replace(/\\/g, "/"));
|
|
77
|
+
const effectiveScope = requested.length > 0
|
|
78
|
+
? "file"
|
|
79
|
+
: (args.scope ?? (args.staged ? "staged" : args.domain ? "domain" : "all"));
|
|
80
|
+
|
|
81
|
+
const syncState = repo?.getMeta("sync_state");
|
|
82
|
+
const syncError = repo?.getMeta("sync_error");
|
|
83
|
+
if (!syncState || syncState === "running" || syncState === "error" || syncState !== "complete" || syncError) {
|
|
84
|
+
return incompleteEvidence({
|
|
85
|
+
status: "unknown",
|
|
86
|
+
scope: effectiveScope,
|
|
87
|
+
...(args.domain ? { domain: args.domain } : {}),
|
|
88
|
+
sync_state: syncState || "unindexed",
|
|
89
|
+
sync_error: syncError || undefined,
|
|
90
|
+
message: "Boundary audit is incomplete because workspace synchronization has not completed.",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const skipped = JSON.parse(repo?.getMeta("skipped_files") || "[]") as {path: string; reason: string}[];
|
|
94
|
+
const unsupported = JSON.parse(repo?.getMeta("unsupported_files") || "[]") as string[];
|
|
95
|
+
const relevantUnsupported = unsupported.filter(file =>
|
|
96
|
+
(!args.domain || evaluator.resolveSourceDomain(file, config) === args.domain) &&
|
|
97
|
+
(requested.length === 0 || requested.includes(file))
|
|
98
|
+
);
|
|
99
|
+
const relevantSkipped = skipped.filter(file =>
|
|
100
|
+
(!args.domain || evaluator.resolveSourceDomain(file.path, config) === args.domain) &&
|
|
101
|
+
(requested.length === 0 || requested.includes(file.path))
|
|
102
|
+
);
|
|
103
|
+
if (relevantSkipped.length > 0 && args.scope !== "staged" && !args.staged) {
|
|
104
|
+
return incompleteEvidence({status: "unknown", scope: effectiveScope, ...(args.domain ? { domain: args.domain } : {}), skipped_files: relevantSkipped, message: "Boundary audit is incomplete because source files exceed resource limits."});
|
|
105
|
+
}
|
|
106
|
+
if (relevantUnsupported.length > 0 && args.scope !== "staged" && !args.staged) {
|
|
107
|
+
return incompleteEvidence({ status: "unknown", scope: effectiveScope, ...(args.domain ? { domain: args.domain } : {}), unsupported_files: relevantUnsupported, message: "Boundary audit is incomplete because source files have no supported parser." });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let evidence: ImportEvidence | undefined;
|
|
111
|
+
if (args.scope !== "staged" && !args.staged && repo) {
|
|
112
|
+
const relevant = (file: string) => (!args.domain || evaluator.resolveSourceDomain(file,config) === args.domain) && (requested.length === 0 || requested.includes(file));
|
|
113
|
+
evidence = repo.getImportEvidence(root, repo.getMeta("workspace_root") ? relevant : undefined);
|
|
114
|
+
const staleFiles = evidence.staleFiles;
|
|
115
|
+
const relationships = evidence.relationships.filter(edge => relevant(edge.source.file));
|
|
116
|
+
const incomplete = relationships.filter(edge => edge.index_coverage === "partial" || edge.freshness !== "current" || !["resolved","external"].includes(edge.resolution.status) || edge.resolution.coverage === "conditional" || edge.target_domains.length > 1);
|
|
117
|
+
const allProposed = requested.flatMap(file => proposedImports.map(target => evaluator.getResolver().resolveImport(target, file)));
|
|
118
|
+
const proposed = allProposed.filter(result => !["resolved", "external"].includes(result.status) || result.coverage === "conditional");
|
|
119
|
+
if (incomplete.length || proposed.length || staleFiles.length) {
|
|
120
|
+
const known = evaluator.auditCodebase(config, evidence).filter(violation => relevant(violation.file));
|
|
121
|
+
known.push(...requested.flatMap(file => evaluator.evaluate(file, proposedImports, config, evidence)));
|
|
122
|
+
return incompleteEvidence({
|
|
123
|
+
status: known.length ? "rejected" : "unknown",
|
|
124
|
+
scope: effectiveScope,
|
|
125
|
+
...(args.domain ? { domain: args.domain } : {}),
|
|
126
|
+
violations: known, total_violations: known.length,
|
|
127
|
+
circular_dependencies: known.filter(v => v.rule === "circular_dependency"), circular_dependencies_count: known.filter(v => v.rule === "circular_dependency").length,
|
|
128
|
+
relationships: incomplete.slice(0, 10), proposed_resolutions: allProposed,
|
|
129
|
+
diagnostic_accounting: { total: incomplete.length, returned: Math.min(10, incomplete.length), omitted: Math.max(0, incomplete.length - 10) },
|
|
130
|
+
incomplete_reasons: {
|
|
131
|
+
target_not_fully_indexed: incomplete.filter(edge => edge.index_coverage === "partial").length,
|
|
132
|
+
stale_source: incomplete.filter(edge => edge.freshness !== "current").length,
|
|
133
|
+
unresolved_or_unsupported: incomplete.filter(edge => !["resolved", "external"].includes(edge.resolution.status)).length,
|
|
134
|
+
conditional_resolution: incomplete.filter(edge => edge.resolution.coverage === "conditional").length,
|
|
135
|
+
multiple_domains: incomplete.filter(edge => edge.target_domains.length > 1).length,
|
|
136
|
+
},
|
|
137
|
+
next: ["Inspect the listed source imports; register/index uncovered target roots or narrow scope to a file/domain. Unknown is not approval."],
|
|
138
|
+
stale_files: staleFiles,
|
|
139
|
+
message: "Relevant import resolution is incomplete; an empty graph cannot prove boundary approval.",
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const filesToCheck: string[] = [];
|
|
145
|
+
if (args.file_paths && Array.isArray(args.file_paths) && args.file_paths.length > 0) {
|
|
146
|
+
filesToCheck.push(...args.file_paths);
|
|
147
|
+
} else if (args.file_path) {
|
|
148
|
+
if (Array.isArray(args.file_path)) {
|
|
149
|
+
filesToCheck.push(...args.file_path);
|
|
150
|
+
} else if (typeof args.file_path === "string" && args.file_path.trim().length > 0) {
|
|
151
|
+
filesToCheck.push(args.file_path.trim());
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Repo-wide, domain-scoped, or git-staged boundary audit when neither file_path nor file_paths is provided
|
|
156
|
+
if (filesToCheck.length === 0) {
|
|
157
|
+
const effectiveScope =
|
|
158
|
+
args.scope ?? (args.staged ? "staged" : args.domain ? "domain" : "all");
|
|
159
|
+
|
|
160
|
+
if (effectiveScope === "staged") {
|
|
161
|
+
const {
|
|
162
|
+
files: stagedFiles,
|
|
163
|
+
violations: stagedViolations,
|
|
164
|
+
resolution_issues: resolutionIssues,
|
|
165
|
+
background_resolution_issues_count: backgroundResolutionIssuesCount,
|
|
166
|
+
} = await auditStagedFiles(evaluator, config, root, repo);
|
|
167
|
+
const enforcementMode = config?.settings?.enforcement ?? "strict";
|
|
168
|
+
|
|
169
|
+
if (stagedFiles.length === 0 && stagedViolations.length === 0) {
|
|
170
|
+
return evaluated({
|
|
171
|
+
status: "approved",
|
|
172
|
+
scope: "staged",
|
|
173
|
+
enforcement_mode: enforcementMode,
|
|
174
|
+
total_checked: 0,
|
|
175
|
+
total_violations: 0,
|
|
176
|
+
circular_dependencies_count: 0,
|
|
177
|
+
circular_dependencies: [],
|
|
178
|
+
domain_violation_breakdown: {},
|
|
179
|
+
violations: [],
|
|
180
|
+
message: "No git staged files found. Boundary check passed.",
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const filteredViolations = args.domain
|
|
185
|
+
? stagedViolations.filter(
|
|
186
|
+
(v) =>
|
|
187
|
+
v.source_domain.toLowerCase() === args.domain!.toLowerCase() ||
|
|
188
|
+
v.target_domain.toLowerCase() === args.domain!.toLowerCase()
|
|
189
|
+
)
|
|
190
|
+
: stagedViolations;
|
|
191
|
+
|
|
192
|
+
const hasViolations = filteredViolations.length > 0;
|
|
193
|
+
return evaluated({
|
|
194
|
+
status: hasViolations ? "rejected" : resolutionIssues.length ? "unknown" : "approved",
|
|
195
|
+
resolution_issues: resolutionIssues,
|
|
196
|
+
...(backgroundResolutionIssuesCount > 0
|
|
197
|
+
? { background_resolution_issues_count: backgroundResolutionIssuesCount }
|
|
198
|
+
: {}),
|
|
199
|
+
scope: "staged",
|
|
200
|
+
enforcement_mode: enforcementMode,
|
|
201
|
+
total_checked: stagedFiles.length,
|
|
202
|
+
total_violations: filteredViolations.length,
|
|
203
|
+
...summarizeViolations(filteredViolations),
|
|
204
|
+
violations: filteredViolations,
|
|
205
|
+
message: resolutionIssues.length && !hasViolations
|
|
206
|
+
? "Staged import resolution is incomplete; approval is unknown."
|
|
207
|
+
: hasViolations
|
|
208
|
+
? `${filteredViolations.length} boundary violation(s) detected across ${stagedFiles.length} staged file(s).`
|
|
209
|
+
: `All ${stagedFiles.length} staged file(s) approved. No boundary violations detected.`,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Scope: "all" or "domain"
|
|
214
|
+
const auditResult = evaluator.auditCodebaseWithWarnings(config, evidence);
|
|
215
|
+
let violations = auditResult.violations;
|
|
216
|
+
let warnings = auditResult.warnings;
|
|
217
|
+
if (args.domain) {
|
|
218
|
+
const targetDom = args.domain.toLowerCase();
|
|
219
|
+
violations = violations.filter(
|
|
220
|
+
(v) =>
|
|
221
|
+
v.source_domain.toLowerCase() === targetDom ||
|
|
222
|
+
v.target_domain.toLowerCase() === targetDom
|
|
223
|
+
);
|
|
224
|
+
warnings = warnings.filter(
|
|
225
|
+
(w) =>
|
|
226
|
+
w.source_domain.toLowerCase() === targetDom ||
|
|
227
|
+
w.target_domain.toLowerCase() === targetDom
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const summary = summarizeViolations(violations);
|
|
232
|
+
const hasViolations = violations.length > 0;
|
|
233
|
+
const hasWarnings = warnings.length > 0;
|
|
234
|
+
const domainCount = Object.keys(config?.domains || {}).length;
|
|
235
|
+
const allIndexedFiles = repo ? repo.getAllFiles() : [];
|
|
236
|
+
const emptyScopedDomain = Boolean(args.domain && repo && !allIndexedFiles.some(
|
|
237
|
+
(file) => evaluator.resolveSourceDomain(file.path, config) === args.domain,
|
|
238
|
+
));
|
|
239
|
+
const emptyWorkspace = Boolean(repo && allIndexedFiles.length === 0);
|
|
240
|
+
const uncoveredFiles: string[] = !args.domain && repo
|
|
241
|
+
? JSON.parse(repo.getMeta("uncovered_files") || "[]")
|
|
242
|
+
: [];
|
|
243
|
+
const hasUncoveredWorkspaceFiles = !args.domain && uncoveredFiles.length > 0;
|
|
244
|
+
|
|
245
|
+
return evaluated({
|
|
246
|
+
status: hasViolations ? "rejected" : emptyScopedDomain || emptyWorkspace || domainCount === 0 ? "unknown" : "approved",
|
|
247
|
+
scope: args.domain ? "domain" : "all",
|
|
248
|
+
enforcement_mode: config?.settings?.enforcement ?? "strict",
|
|
249
|
+
...(args.domain ? { domain: args.domain } : {}),
|
|
250
|
+
total_domains_checked: domainCount,
|
|
251
|
+
total_violations: violations.length,
|
|
252
|
+
total_warnings: warnings.length,
|
|
253
|
+
...summary,
|
|
254
|
+
violations,
|
|
255
|
+
...(hasWarnings ? { warnings } : {}),
|
|
256
|
+
...(hasUncoveredWorkspaceFiles ? { uncovered_files_count: uncoveredFiles.length } : {}),
|
|
257
|
+
message: hasViolations
|
|
258
|
+
? `${violations.length} boundary violation(s) (${summary.circular_dependencies_count} circular) detected${
|
|
259
|
+
args.domain ? ` in domain '${args.domain}'` : " across codebase"
|
|
260
|
+
}.${hasWarnings ? ` Also ${warnings.length} unlisted dependency warning(s) in 'warn' mode.` : ""}`
|
|
261
|
+
: emptyScopedDomain
|
|
262
|
+
? `Boundary check is incomplete: domain '${args.domain}' has 0 indexed files (it may be unindexed or shadowed by a parent domain).`
|
|
263
|
+
: emptyWorkspace
|
|
264
|
+
? "Boundary check is incomplete: 0 source files are indexed across the workspace; an empty graph cannot prove boundary approval."
|
|
265
|
+
: domainCount === 0
|
|
266
|
+
? "Boundary check is incomplete: no domain policies are available. Initialize or register domains before auditing."
|
|
267
|
+
: hasWarnings
|
|
268
|
+
? `No blocking boundary violations detected${
|
|
269
|
+
args.domain ? ` for domain '${args.domain}'` : ""
|
|
270
|
+
}, but ${warnings.length} unlisted dependency warning(s) were found under 'warn' enforcement.`
|
|
271
|
+
: hasUncoveredWorkspaceFiles
|
|
272
|
+
? `All registered domain boundaries are clean across ${allIndexedFiles.length} indexed file(s) (${uncoveredFiles.length} uncovered file(s) outside registered domains were not audited).`
|
|
273
|
+
: `All domain boundaries are clean${
|
|
274
|
+
args.domain ? ` for domain '${args.domain}'` : ""
|
|
275
|
+
}. Zero cross-domain leaks or circular dependencies detected.`,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const enforcementMode = config?.settings?.enforcement ?? "strict";
|
|
280
|
+
|
|
281
|
+
// Multi-file batch evaluation
|
|
282
|
+
if (filesToCheck.length > 1) {
|
|
283
|
+
const results = filesToCheck.map((filePath) => {
|
|
284
|
+
const violations = evaluator.evaluate(filePath, proposedImports, config, evidence);
|
|
285
|
+
const impact = repo?.getFileInboundImpact(filePath, evidence?.relationships);
|
|
286
|
+
return {
|
|
287
|
+
file: filePath,
|
|
288
|
+
evaluated_scope: evaluatedScope,
|
|
289
|
+
status: violations.length > 0 ? "rejected" : "approved",
|
|
290
|
+
total_violations: violations.length,
|
|
291
|
+
violations,
|
|
292
|
+
impact_summary: impact
|
|
293
|
+
? {
|
|
294
|
+
direct_dependents: impact.direct_dependents_count,
|
|
295
|
+
top_consumers: impact.top_consumers,
|
|
296
|
+
symbols_count: impact.symbols_count,
|
|
297
|
+
risk_level: impact.risk_level,
|
|
298
|
+
}
|
|
299
|
+
: undefined,
|
|
300
|
+
};
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const totalViolations = results.reduce((acc, r) => acc + r.violations.length, 0);
|
|
304
|
+
const hasViolations = totalViolations > 0;
|
|
305
|
+
|
|
306
|
+
return evaluated({
|
|
307
|
+
status: hasViolations ? "rejected" : "approved",
|
|
308
|
+
scope: "file",
|
|
309
|
+
enforcement_mode: enforcementMode,
|
|
310
|
+
total_checked: filesToCheck.length,
|
|
311
|
+
total_violations: totalViolations,
|
|
312
|
+
violations: results.flatMap((r) => r.violations),
|
|
313
|
+
results,
|
|
314
|
+
message: hasViolations
|
|
315
|
+
? `${totalViolations} boundary violation(s) detected across ${filesToCheck.length} file(s).`
|
|
316
|
+
: Object.keys(config?.domains || {}).length === 0
|
|
317
|
+
? `All ${filesToCheck.length} file(s) approved. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]`
|
|
318
|
+
: `All ${filesToCheck.length} file(s) approved. No boundary violations detected.`,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Single file evaluation
|
|
323
|
+
const singleFile = filesToCheck[0];
|
|
324
|
+
const violations = evaluator.evaluate(singleFile, proposedImports, config, evidence);
|
|
325
|
+
const impact = repo?.getFileInboundImpact(singleFile, evidence?.relationships);
|
|
326
|
+
const impactSummary = impact
|
|
327
|
+
? {
|
|
328
|
+
direct_dependents: impact.direct_dependents_count,
|
|
329
|
+
top_consumers: impact.top_consumers,
|
|
330
|
+
symbols_count: impact.symbols_count,
|
|
331
|
+
risk_level: impact.risk_level,
|
|
332
|
+
}
|
|
333
|
+
: undefined;
|
|
334
|
+
|
|
335
|
+
const newViolations = violations.filter((v) => !v.pre_existing);
|
|
336
|
+
const preExistingViolations = violations.filter((v) => v.pre_existing);
|
|
337
|
+
|
|
338
|
+
if (newViolations.length > 0) {
|
|
339
|
+
return evaluated({
|
|
340
|
+
status: "rejected",
|
|
341
|
+
scope: "file",
|
|
342
|
+
enforcement_mode: enforcementMode,
|
|
343
|
+
file: singleFile,
|
|
344
|
+
evaluated_scope: evaluatedScope,
|
|
345
|
+
total_violations: newViolations.length,
|
|
346
|
+
violations_count: newViolations.length,
|
|
347
|
+
violations: newViolations,
|
|
348
|
+
...(preExistingViolations.length > 0 ? { pre_existing_violations: preExistingViolations } : {}),
|
|
349
|
+
impact_summary: impactSummary,
|
|
350
|
+
message:
|
|
351
|
+
Object.keys(config?.domains || {}).length === 0
|
|
352
|
+
? "Boundary integrity check failed: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts."
|
|
353
|
+
: newViolations.some((v) => v.rule === "unmapped_domain")
|
|
354
|
+
? "Boundary integrity check failed: File does not belong to any declared bounded context."
|
|
355
|
+
: "Boundary violation detected. Proposed imports violate bounded context architecture.",
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return evaluated({
|
|
360
|
+
status: "approved",
|
|
361
|
+
scope: "file",
|
|
362
|
+
enforcement_mode: enforcementMode,
|
|
363
|
+
file: singleFile,
|
|
364
|
+
evaluated_scope: evaluatedScope,
|
|
365
|
+
total_violations: 0,
|
|
366
|
+
violations: [],
|
|
367
|
+
...(preExistingViolations.length > 0 ? {
|
|
368
|
+
pre_existing_violations: preExistingViolations,
|
|
369
|
+
pre_existing_violations_count: preExistingViolations.length,
|
|
370
|
+
} : {}),
|
|
371
|
+
impact_summary: impactSummary,
|
|
372
|
+
message:
|
|
373
|
+
preExistingViolations.length > 0
|
|
374
|
+
? `Approved. Proposed imports do not introduce new boundary violations (${preExistingViolations.length} pre-existing circular dependencies noted in codebase).`
|
|
375
|
+
: Object.keys(config?.domains || {}).length === 0
|
|
376
|
+
? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]"
|
|
377
|
+
: enforcementMode === "warn"
|
|
378
|
+
? "Approved under 'warn' enforcement (unlisted allowed_dependencies are not blocked; only explicit forbidden_dependencies are rejected)."
|
|
379
|
+
: impact && impact.direct_dependents_count > 0
|
|
380
|
+
? `No boundary violations detected. Caution: ${impact.direct_dependents_count} dependent file(s) consume this file.`
|
|
381
|
+
: "Proposal approved. Existing file imports were not audited.",
|
|
382
|
+
});
|
|
383
|
+
}
|