@dimassetoid/septum-mcp 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +46 -45
  2. package/package.json +8 -6
  3. package/src/cli/commands/check.ts +41 -26
  4. package/src/cli/commands/hook.ts +77 -105
  5. package/src/cli/commands/init.ts +35 -9
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +35 -9
  9. package/src/cli/hook-payload.ts +43 -0
  10. package/src/cli/index.ts +15 -51
  11. package/src/cli/scaffold/harness-config.ts +48 -8
  12. package/src/cli/templates/hooks.ts +51 -27
  13. package/src/cli/templates/rules.ts +34 -49
  14. package/src/cli/templates/skill.ts +46 -35
  15. package/src/core/boundary/audit.ts +383 -0
  16. package/src/core/boundary/evaluator.ts +299 -178
  17. package/src/core/boundary/staged-auditor.ts +188 -34
  18. package/src/core/config/domain-ownership.ts +47 -0
  19. package/src/core/config/domain-registration.ts +141 -0
  20. package/src/core/config/loader.ts +82 -54
  21. package/src/core/config/schema.ts +24 -46
  22. package/src/core/database/client.ts +2 -0
  23. package/src/core/database/repositories/dependency.repository.ts +326 -543
  24. package/src/core/database/repositories/domain.repository.ts +48 -4
  25. package/src/core/database/repositories/file.repository.ts +10 -0
  26. package/src/core/database/repositories/symbol.repository.ts +97 -259
  27. package/src/core/database/repository.ts +138 -24
  28. package/src/core/database/schema.ts +28 -33
  29. package/src/core/discovery/declarative-routes.ts +69 -0
  30. package/src/core/discovery/framework-detector.ts +149 -0
  31. package/src/core/discovery/navigation.ts +269 -0
  32. package/src/core/discovery/topology-detector.ts +153 -170
  33. package/src/core/errors.ts +19 -0
  34. package/src/core/ingestion/pipeline.ts +378 -212
  35. package/src/core/parser/behavioral-analyzer.ts +26 -22
  36. package/src/core/parser/boundary-tracker.ts +15 -0
  37. package/src/core/parser/extractors/base.ts +16 -4
  38. package/src/core/parser/extractors/csharp.ts +9 -5
  39. package/src/core/parser/extractors/django-routing.ts +163 -0
  40. package/src/core/parser/extractors/django-semantic.ts +400 -516
  41. package/src/core/parser/extractors/elysia-semantic.ts +172 -496
  42. package/src/core/parser/extractors/express-semantic.ts +195 -398
  43. package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
  44. package/src/core/parser/extractors/fastify-semantic.ts +216 -732
  45. package/src/core/parser/extractors/flask-semantic.ts +92 -388
  46. package/src/core/parser/extractors/go-routing.ts +344 -0
  47. package/src/core/parser/extractors/go-semantic.ts +210 -508
  48. package/src/core/parser/extractors/go.ts +6 -3
  49. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  50. package/src/core/parser/extractors/hono-semantic.ts +132 -530
  51. package/src/core/parser/extractors/java.ts +7 -5
  52. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  53. package/src/core/parser/extractors/laravel-semantic.ts +169 -333
  54. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  55. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  56. package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
  57. package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
  58. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  59. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  60. package/src/core/parser/extractors/php.ts +17 -1
  61. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  62. package/src/core/parser/extractors/python.ts +9 -8
  63. package/src/core/parser/extractors/registry.ts +28 -5
  64. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  65. package/src/core/parser/extractors/ruby.ts +10 -7
  66. package/src/core/parser/extractors/rust.ts +35 -17
  67. package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
  68. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  69. package/src/core/parser/extractors/symfony-semantic.ts +75 -262
  70. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  71. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  72. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  73. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  74. package/src/core/parser/extractors/typescript.ts +36 -216
  75. package/src/core/parser/implementation-fingerprint.ts +97 -0
  76. package/src/core/parser/language-capabilities.ts +23 -7
  77. package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
  78. package/src/core/parser/schema/schema-provider-registry.ts +1 -3
  79. package/src/core/parser/schema/schema-provider.interface.ts +2 -1
  80. package/src/core/parser/semantic-revision.ts +3 -0
  81. package/src/core/parser/static-string.ts +51 -0
  82. package/src/core/parser/wasm-loader.ts +6 -2
  83. package/src/core/resolver/ast-method-tracer.ts +230 -0
  84. package/src/core/resolver/call-graph-helpers.ts +72 -0
  85. package/src/core/resolver/call-graph-tracer.ts +375 -311
  86. package/src/core/resolver/dependency-analysis.ts +593 -0
  87. package/src/core/resolver/import-candidates.ts +120 -0
  88. package/src/core/resolver/import-evidence.ts +88 -0
  89. package/src/core/resolver/import-resolver.ts +162 -181
  90. package/src/core/resolver/interpretation-inputs.ts +65 -0
  91. package/src/core/resolver/languages/go.ts +103 -0
  92. package/src/core/resolver/languages/managed.ts +200 -0
  93. package/src/core/resolver/languages/python.ts +133 -0
  94. package/src/core/resolver/languages/ruby.ts +40 -0
  95. package/src/core/resolver/languages/rust.ts +127 -0
  96. package/src/core/resolver/languages/shared.ts +74 -0
  97. package/src/core/resolver/module-resolver.ts +18 -7
  98. package/src/core/resolver/path-resolver.ts +6 -3
  99. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  100. package/src/core/resolver/slice-catalog.ts +94 -0
  101. package/src/core/resolver/slice-format.ts +22 -0
  102. package/src/core/resolver/slice-selection.ts +237 -0
  103. package/src/core/resolver/symbol-impact.ts +477 -0
  104. package/src/core/resolver/symbol-locator.ts +82 -15
  105. package/src/core/resolver/vertical-slice-tracer.ts +57 -278
  106. package/src/core/resources/ignore.ts +21 -1
  107. package/src/core/resources/limits.ts +2 -1
  108. package/src/core/resources/source-files.ts +143 -20
  109. package/src/core/resources/source-inventory.ts +55 -0
  110. package/src/core/resources/work-queue.ts +167 -4
  111. package/src/core/retrieval/context-page.ts +116 -0
  112. package/src/core/retrieval/context.ts +457 -0
  113. package/src/core/retrieval/resolution-warnings.ts +21 -0
  114. package/src/core/retrieval/source-context.ts +448 -0
  115. package/src/core/retrieval/symbol-details.ts +453 -0
  116. package/src/core/retrieval/symbol-evidence.ts +97 -0
  117. package/src/core/retrieval/typescript-references.ts +293 -0
  118. package/src/core/retrieval/universal-context.ts +182 -0
  119. package/src/core/telemetry/summary.ts +114 -0
  120. package/src/core/telemetry/telemetry.ts +225 -37
  121. package/src/index.ts +0 -3
  122. package/src/mcp/formatters/compact-text.ts +439 -0
  123. package/src/mcp/resources-and-prompts.ts +253 -0
  124. package/src/mcp/schemas/boundary.ts +145 -0
  125. package/src/mcp/schemas/map.ts +250 -0
  126. package/src/mcp/schemas/shared.ts +52 -0
  127. package/src/mcp/schemas/slice.ts +60 -0
  128. package/src/mcp/schemas/symbol.ts +268 -0
  129. package/src/mcp/schemas.ts +5 -1105
  130. package/src/mcp/server.ts +263 -597
  131. package/src/mcp/tool-catalog.ts +331 -0
  132. package/src/mcp/tools/boundary.ts +69 -4
  133. package/src/mcp/tools/map.ts +126 -0
  134. package/src/mcp/tools/slice.ts +101 -3
  135. package/src/mcp/tools/symbol.ts +480 -26
  136. package/src/mcp/ui/app-client.ts +899 -0
  137. package/src/mcp/ui/app.html +478 -0
  138. package/src/mcp/workflow-playbooks.ts +181 -0
  139. package/src/mcp/workspace-boundary.ts +50 -0
  140. package/src/mcp/workspace-manager.ts +102 -18
  141. package/src/mcp/workspace-watcher.ts +38 -19
  142. package/src/types/index.ts +47 -53
  143. package/src/cli/commands/topology.ts +0 -161
  144. package/src/core/database/repositories/environment.repository.ts +0 -207
  145. package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
  146. package/src/core/session/session-manager.ts +0 -107
  147. package/src/core/topology/environment-detector.ts +0 -973
  148. package/src/core/topology/types.ts +0 -83
  149. package/src/mcp/tools/check-boundary.ts +0 -387
  150. package/src/mcp/tools/domain.ts +0 -40
  151. package/src/mcp/tools/feature.ts +0 -67
  152. package/src/mcp/tools/get-domain-catalog.ts +0 -226
  153. package/src/mcp/tools/get-environment-topology.ts +0 -138
  154. package/src/mcp/tools/get-feature-context.ts +0 -224
  155. package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
  156. package/src/mcp/tools/get-symbol-impact.ts +0 -64
  157. package/src/mcp/tools/get-symbol.ts +0 -175
  158. package/src/mcp/tools/locate-symbol.ts +0 -196
  159. package/src/mcp/tools/register-domain.ts +0 -75
  160. package/src/mcp/tools/register-feature.ts +0 -110
  161. package/src/mcp/tools/trace-vertical-slice.ts +0 -80
@@ -1,83 +0,0 @@
1
- export type EnvironmentLayer =
2
- | "edge"
3
- | "gateway"
4
- | "host"
5
- | "runtime"
6
- | "storage"
7
- | "telemetry";
8
-
9
- export type LayerResolutionStatus = "DETECTED" | "AMBIGUOUS" | "UNRESOLVED" | "VERIFIED";
10
-
11
- export type CanonicalPlatformTag =
12
- | "shared_hosting"
13
- | "vps"
14
- | "docker"
15
- | "serverless"
16
- | "kubernetes"
17
- | "managed_db"
18
- | "cdn_edge"
19
- | "paas"
20
- | "static_cdn"
21
- | "unspecified";
22
-
23
- export interface EnvironmentLayerInfo {
24
- layer: EnvironmentLayer;
25
- platform?: string;
26
- canonical_tag?: CanonicalPlatformTag;
27
- status: LayerResolutionStatus;
28
- detected_from?: string[];
29
- evidence?: string[];
30
- constraints?: string[];
31
- unresolved_inquiry?: string;
32
- }
33
-
34
- export interface TopologyNode {
35
- id: string; // e.g. "edge:cloudflare", "host:api-vps", "host:worker-vps", "storage:central-db"
36
- layer: EnvironmentLayer;
37
- name: string; // e.g. "Cloudflare Perimeter", "API Backend VPS", "Postgres Cluster"
38
- platform: string; // e.g. "Cloudflare WAF", "Hostinger VPS", "AWS RDS Postgres"
39
- canonical_tag: CanonicalPlatformTag;
40
- domain_or_ip?: string; // e.g. "api.example.com", "10.0.0.5"
41
- role?: string; // e.g. "web_api", "queue_worker", "frontend_spa", "database_primary"
42
- status: LayerResolutionStatus;
43
- detected_from: string[];
44
- constraints: string[];
45
- connected_to?: string[]; // IDs of nodes this node interacts with
46
- unresolved_inquiry?: string;
47
- }
48
-
49
- export interface CrossLayerInterplay {
50
- title: string;
51
- involved_layers: EnvironmentLayer[];
52
- involved_node_ids?: string[];
53
- risk_or_rule: string;
54
- required_action: string;
55
- }
56
-
57
- export interface EnvironmentTopology {
58
- is_distributed: boolean;
59
- nodes: TopologyNode[];
60
- layers: Record<EnvironmentLayer, EnvironmentLayerInfo>;
61
- overall_status: "RESOLVED" | "NEEDS_CLARIFICATION";
62
- interplays: CrossLayerInterplay[];
63
- pending_inquiries: string[];
64
- architectural_summary: string;
65
- }
66
-
67
- export interface ResolveLayerInput {
68
- layer: EnvironmentLayer;
69
- platform: string;
70
- constraints?: string[];
71
- }
72
-
73
- export interface ResolveNodeInput {
74
- id: string;
75
- layer: EnvironmentLayer;
76
- name: string;
77
- platform: string;
78
- canonical_tag?: CanonicalPlatformTag;
79
- domain_or_ip?: string;
80
- role?: string;
81
- constraints?: string[];
82
- connected_to?: string[];
83
- }
@@ -1,387 +0,0 @@
1
- import { assertPathContained } from "../../core/resolver/path-resolver.ts";
2
- import { readSourceFile } from "../../core/resources/source-files.ts";
3
- import { computeContentHash } from "../../core/ingestion/hasher.ts";
4
- import { relative, resolve } from "node:path";
5
- import { auditStagedFiles } from "../../core/boundary/staged-auditor.ts";
6
- import type { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
7
- import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
8
- import type { SeptumRepository } from "../../core/database/repository.ts";
9
- import { SessionManager } from "../../core/session/session-manager.ts";
10
- import type { BoundaryViolation } from "../../types/index.ts";
11
- import { CheckBoundarySchema, type CheckBoundaryArgs } from "../schemas.ts";
12
-
13
- export type { CheckBoundaryArgs } from "../schemas.ts";
14
-
15
- export async function handleCheckBoundary(
16
- evaluator: BoundaryEvaluator,
17
- config: ValidatedSeptumConfig,
18
- rawArgs: CheckBoundaryArgs & Record<string, unknown>,
19
- repo?: SeptumRepository,
20
- workspaceRoot?: string
21
- ) {
22
- const args = CheckBoundarySchema.parse(rawArgs ?? {});
23
- if (args.domain) {
24
- const domain = Object.keys(config.domains || {}).find(name => name.toLowerCase() === args.domain!.toLowerCase());
25
- if (!domain) throw new Error(`Unknown boundary domain '${args.domain}'. Choose a registered domain.`);
26
- args.domain = domain;
27
- }
28
- const root = workspaceRoot || args.workspace_path || process.cwd();
29
- const proposedImports = args.proposed_imports ?? [];
30
-
31
- const activeSession = SessionManager.getActiveSession(root);
32
-
33
- let effectiveFeatureKey = args.feature_key;
34
- if (activeSession) {
35
- if (args.feature_key && args.feature_key !== activeSession.feature_key) {
36
- throw new Error(
37
- `Active feature lock is '${activeSession.feature_key}' (owner: ${activeSession.owner_id}). Cannot check boundaries for different feature '${args.feature_key}' while another feature is locked.`
38
- );
39
- }
40
- effectiveFeatureKey = activeSession.feature_key;
41
- if (!config.features) config.features = {};
42
- if (!config.features[activeSession.feature_key]) {
43
- config.features[activeSession.feature_key] = {
44
- domain: activeSession.domain,
45
- description: `Active session: ${activeSession.feature_key}`,
46
- allowed_touchpoints: activeSession.touchpoints,
47
- reuse_symbols: [],
48
- input_contract: {},
49
- output_contract: {},
50
- };
51
- }
52
- }
53
-
54
- const syncState = repo?.getMeta("sync_state");
55
- const syncError = repo?.getMeta("sync_error");
56
- if (!syncState || syncState === "running" || syncState === "error" || syncState !== "complete" || syncError) {
57
- return {
58
- content: [
59
- {
60
- type: "text" as const,
61
- text: JSON.stringify({
62
- status: "unknown",
63
- sync_state: syncState || "unindexed",
64
- sync_error: syncError || undefined,
65
- message: "Boundary audit is incomplete because workspace synchronization has not completed.",
66
- }),
67
- },
68
- ],
69
- };
70
- }
71
- const skipped = JSON.parse(repo?.getMeta("skipped_files") || "[]") as {path: string; reason: string}[];
72
- const unsupported = JSON.parse(repo?.getMeta("unsupported_files") || "[]") as string[];
73
- const requested = [...(Array.isArray(args.file_path) ? args.file_path : args.file_path ? [args.file_path] : []), ...(args.file_paths || [])]
74
- .map(file => relative(root, resolve(root, file)).replace(/\\/g, "/"));
75
- const relevantUnsupported = unsupported.filter(file =>
76
- (!args.domain || evaluator.resolveSourceDomain(file, config) === args.domain) &&
77
- (requested.length === 0 || requested.includes(file))
78
- );
79
- const relevantSkipped = skipped.filter(file =>
80
- (!args.domain || evaluator.resolveSourceDomain(file.path, config) === args.domain) &&
81
- (requested.length === 0 || requested.includes(file.path))
82
- );
83
- if (relevantSkipped.length > 0 && args.scope !== "staged" && !args.staged) {
84
- return { content: [{type: "text" as const, text: JSON.stringify({status: "unknown", skipped_files: relevantSkipped, message: "Boundary audit is incomplete because source files exceed resource limits."})}] };
85
- }
86
- if (relevantUnsupported.length > 0 && args.scope !== "staged" && !args.staged) {
87
- return { content: [{ type: "text" as const, text: JSON.stringify({ status: "unknown", unsupported_files: relevantUnsupported, message: "Boundary audit is incomplete because source files have no supported parser." }) }] };
88
- }
89
-
90
- if (args.scope !== "staged" && !args.staged && repo) {
91
- const relevant = (file: string) => (!args.domain || evaluator.resolveSourceDomain(file,config) === args.domain) && (requested.length === 0 || requested.includes(file));
92
- const staleFiles = repo.getMeta("workspace_root") ? repo.getAllFiles().filter(file => relevant(file.path)).filter(file => {
93
- try { assertPathContained(file.path,root,"Boundary source"); return computeContentHash(readSourceFile(resolve(root,file.path))) !== file.content_hash; }
94
- catch { return true; }
95
- }).map(file => file.path) : [];
96
- const relationships = repo.getImportRelationships(root).filter(edge => relevant(edge.source.file));
97
- 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);
98
- const proposed = requested.flatMap(file => proposedImports.map(target => evaluator.getResolver().resolveImport(target,file)))
99
- .filter(result => !["resolved","external"].includes(result.status) || result.coverage === "conditional");
100
- if (incomplete.length || proposed.length || staleFiles.length) {
101
- const known = evaluator.auditCodebase(config).filter(violation => relevant(violation.file));
102
- known.push(...requested.flatMap(file => evaluator.evaluate(file,proposedImports,effectiveFeatureKey,config)));
103
- return { content: [{ type: "text" as const, text: JSON.stringify({
104
- status: known.length ? "rejected" : "unknown", violations: known, total_violations: known.length,
105
- circular_dependencies: known.filter(v => v.rule === "circular_dependency"), circular_dependencies_count: known.filter(v => v.rule === "circular_dependency").length, relationships: incomplete, proposed_resolutions: proposed,
106
- stale_files: staleFiles,
107
- message: "Relevant import resolution is incomplete; an empty graph cannot prove boundary approval.",
108
- }) }] };
109
- }
110
- }
111
-
112
- const filesToCheck: string[] = [];
113
- if (args.file_paths && Array.isArray(args.file_paths) && args.file_paths.length > 0) {
114
- filesToCheck.push(...args.file_paths);
115
- } else if (args.file_path) {
116
- if (Array.isArray(args.file_path)) {
117
- filesToCheck.push(...args.file_path);
118
- } else if (typeof args.file_path === "string" && args.file_path.trim().length > 0) {
119
- filesToCheck.push(args.file_path.trim());
120
- }
121
- }
122
-
123
- // Repo-wide, domain-scoped, or git-staged boundary audit when neither file_path nor file_paths is provided
124
- if (filesToCheck.length === 0) {
125
- const effectiveScope =
126
- args.scope ?? (args.staged ? "staged" : args.domain ? "domain" : "all");
127
-
128
- if (effectiveScope === "staged") {
129
- const { files: stagedFiles, violations: stagedViolations, resolution_issues: resolutionIssues } = await auditStagedFiles(evaluator, config, root, effectiveFeatureKey, repo);
130
-
131
- if (stagedFiles.length === 0 && stagedViolations.length === 0) {
132
- return {
133
- content: [
134
- {
135
- type: "text" as const,
136
- text: JSON.stringify(
137
- {
138
- status: "approved",
139
- scope: "staged",
140
- total_checked: 0,
141
- total_violations: 0,
142
- circular_dependencies: [],
143
- domain_violation_breakdown: {},
144
- violations: [],
145
- message: "No git staged files found. Boundary check passed.",
146
- },
147
- null,
148
- 2
149
- ),
150
- },
151
- ],
152
- };
153
- }
154
-
155
- const filteredViolations = args.domain
156
- ? stagedViolations.filter(
157
- (v) =>
158
- v.source_domain.toLowerCase() === args.domain!.toLowerCase() ||
159
- v.target_domain.toLowerCase() === args.domain!.toLowerCase()
160
- )
161
- : stagedViolations;
162
-
163
- const circularDependencies = filteredViolations.filter((v) => v.rule === "circular_dependency");
164
- const domainBreakdown: Record<string, number> = {};
165
- for (const v of filteredViolations) {
166
- const pair = `${v.source_domain} -> ${v.target_domain}`;
167
- domainBreakdown[pair] = (domainBreakdown[pair] || 0) + 1;
168
- }
169
-
170
- const hasViolations = filteredViolations.length > 0;
171
- return {
172
- content: [
173
- {
174
- type: "text" as const,
175
- text: JSON.stringify(
176
- {
177
- status: hasViolations ? "rejected" : resolutionIssues.length ? "unknown" : "approved",
178
- resolution_issues: resolutionIssues,
179
- scope: "staged",
180
- total_checked: stagedFiles.length,
181
- total_violations: filteredViolations.length,
182
- circular_dependencies_count: circularDependencies.length,
183
- circular_dependencies: circularDependencies,
184
- domain_violation_breakdown: domainBreakdown,
185
- violations: filteredViolations,
186
- message: resolutionIssues.length && !hasViolations ? "Staged import resolution is incomplete; approval is unknown." : hasViolations
187
- ? `${filteredViolations.length} boundary violation(s) detected across ${stagedFiles.length} staged file(s).`
188
- : `All ${stagedFiles.length} staged file(s) approved. No boundary violations detected.`,
189
- },
190
- null,
191
- 2
192
- ),
193
- },
194
- ],
195
- };
196
- }
197
-
198
- // Scope: "all" or "domain"
199
- if (args.feature_key) {
200
- return {
201
- content: [
202
- {
203
- type: "text" as const,
204
- text: JSON.stringify(
205
- {
206
- status: "rejected",
207
- scope: effectiveScope,
208
- message: `Scope '${effectiveScope}' is an architectural audit across domains and does not support feature touchpoint validation ('feature_key'). Feature scopes only apply to 'file', 'batch', or 'staged'.`,
209
- },
210
- null,
211
- 2
212
- ),
213
- },
214
- ],
215
- };
216
- }
217
-
218
- let violations = evaluator.auditCodebase(config);
219
- if (args.domain) {
220
- const targetDom = args.domain.toLowerCase();
221
- violations = violations.filter(
222
- (v) =>
223
- v.source_domain.toLowerCase() === targetDom ||
224
- v.target_domain.toLowerCase() === targetDom
225
- );
226
- }
227
-
228
- const circularDependencies = violations.filter((v) => v.rule === "circular_dependency");
229
- const domainBreakdown: Record<string, number> = {};
230
- for (const v of violations) {
231
- const pair = `${v.source_domain} -> ${v.target_domain}`;
232
- domainBreakdown[pair] = (domainBreakdown[pair] || 0) + 1;
233
- }
234
-
235
- const hasViolations = violations.length > 0;
236
- const domainCount = Object.keys(config?.domains || {}).length;
237
-
238
- return {
239
- content: [
240
- {
241
- type: "text" as const,
242
- text: JSON.stringify(
243
- {
244
- status: hasViolations ? "rejected" : "approved",
245
- scope: args.domain ? "domain" : "all",
246
- ...(args.domain ? { domain: args.domain } : {}),
247
- total_domains_checked: domainCount,
248
- total_violations: violations.length,
249
- circular_dependencies_count: circularDependencies.length,
250
- circular_dependencies: circularDependencies,
251
- domain_violation_breakdown: domainBreakdown,
252
- violations,
253
- message: hasViolations
254
- ? `${violations.length} boundary violation(s) (${circularDependencies.length} circular) detected${
255
- args.domain ? ` in domain '${args.domain}'` : " across codebase"
256
- }.`
257
- : domainCount === 0
258
- ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_domain' with action='register' to initialize bounded contexts.]"
259
- : `All domain boundaries are clean${
260
- args.domain ? ` for domain '${args.domain}'` : ""
261
- }. Zero cross-domain leaks or circular dependencies detected.`,
262
- },
263
- null,
264
- 2
265
- ),
266
- },
267
- ],
268
- };
269
- }
270
-
271
- // Multi-file batch evaluation
272
- if (filesToCheck.length > 1) {
273
- const results = filesToCheck.map((filePath) => {
274
- const violations = evaluator.evaluate(filePath, proposedImports, effectiveFeatureKey, config);
275
- const impact = repo?.getFileInboundImpact(filePath);
276
- return {
277
- file: filePath,
278
- status: violations.length > 0 ? "rejected" : "approved",
279
- violations,
280
- impact_summary: impact
281
- ? {
282
- direct_dependents: impact.direct_dependents_count,
283
- top_consumers: impact.top_consumers,
284
- symbols_count: impact.symbols_count,
285
- risk_level: impact.risk_level,
286
- }
287
- : undefined,
288
- };
289
- });
290
-
291
- const totalViolations = results.reduce((acc, r) => acc + r.violations.length, 0);
292
- const hasViolations = totalViolations > 0;
293
-
294
- return {
295
- content: [
296
- {
297
- type: "text" as const,
298
- text: JSON.stringify(
299
- {
300
- status: hasViolations ? "rejected" : "approved",
301
- total_checked: filesToCheck.length,
302
- total_violations: totalViolations,
303
- results,
304
- message: hasViolations
305
- ? `${totalViolations} boundary violation(s) detected across ${filesToCheck.length} file(s).`
306
- : Object.keys(config?.domains || {}).length === 0
307
- ? `All ${filesToCheck.length} file(s) approved. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_domain' with action='register' to initialize bounded contexts.]`
308
- : `All ${filesToCheck.length} file(s) approved. No boundary violations detected.`,
309
- },
310
- null,
311
- 2
312
- ),
313
- },
314
- ],
315
- };
316
- }
317
-
318
- // Single file evaluation (backward-compatible output)
319
- const singleFile = filesToCheck[0];
320
- const violations = evaluator.evaluate(singleFile, proposedImports, effectiveFeatureKey, config);
321
- const impact = repo?.getFileInboundImpact(singleFile);
322
-
323
- if (violations.length > 0) {
324
- return {
325
- content: [
326
- {
327
- type: "text" as const,
328
- text: JSON.stringify(
329
- {
330
- status: "rejected",
331
- file: singleFile,
332
- violations_count: violations.length,
333
- violations,
334
- impact_summary: impact
335
- ? {
336
- direct_dependents: impact.direct_dependents_count,
337
- top_consumers: impact.top_consumers,
338
- symbols_count: impact.symbols_count,
339
- risk_level: impact.risk_level,
340
- }
341
- : undefined,
342
- message:
343
- Object.keys(config?.domains || {}).length === 0
344
- ? "Boundary integrity check failed: Domain catalog is currently unindexed. Run 'septum_domain' with action='register' to initialize bounded contexts."
345
- : violations.some((v) => v.rule === "unmapped_domain")
346
- ? "Boundary integrity check failed: File does not belong to any declared bounded context."
347
- : "Boundary violation detected. Proposed imports violate bounded context architecture.",
348
- },
349
- null,
350
- 2
351
- ),
352
- },
353
- ],
354
- };
355
- }
356
-
357
- return {
358
- content: [
359
- {
360
- type: "text" as const,
361
- text: JSON.stringify(
362
- {
363
- status: "approved",
364
- file: singleFile,
365
- impact_summary: impact
366
- ? {
367
- direct_dependents: impact.direct_dependents_count,
368
- top_consumers: impact.top_consumers,
369
- symbols_count: impact.symbols_count,
370
- risk_level: impact.risk_level,
371
- }
372
- : undefined,
373
- message:
374
- Object.keys(config?.domains || {}).length === 0
375
- ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_domain' with action='register' to initialize bounded contexts.]"
376
- : impact && impact.direct_dependents_count > 0
377
- ? `No boundary violations detected. Caution: ${impact.direct_dependents_count} dependent file(s) consume this file.`
378
- : "No boundary violations detected. Proposed imports are permissible.",
379
- },
380
- null,
381
- 2
382
- ),
383
- },
384
- ],
385
- };
386
- }
387
-
@@ -1,40 +0,0 @@
1
- import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
2
- import type { SeptumRepository } from "../../core/database/repository.ts";
3
- import type { DomainToolArgs } from "../schemas.ts";
4
- import { handleGetDomainCatalog } from "./get-domain-catalog.ts";
5
- import { handleRegisterDomain } from "./register-domain.ts";
6
- import { handleGetEnvironmentTopology } from "./get-environment-topology.ts";
7
-
8
- export type { DomainToolArgs };
9
-
10
- export async function handleDomainTool(
11
- repo: SeptumRepository,
12
- config: ValidatedSeptumConfig,
13
- args: DomainToolArgs,
14
- workspaceRoot?: string,
15
- signal?: AbortSignal
16
- ) {
17
- const action = args.action || "catalog";
18
-
19
- switch (action) {
20
- case "register":
21
- return await handleRegisterDomain(repo, config, args, workspaceRoot, signal);
22
-
23
- case "topology":
24
- return handleGetEnvironmentTopology(
25
- repo,
26
- config,
27
- {
28
- resolve: args.resolve,
29
- resolveNode: args.resolve_node,
30
- refresh: args.refresh,
31
- workspace_path: args.workspace_path,
32
- },
33
- workspaceRoot || args.workspace_path || process.cwd()
34
- );
35
-
36
- case "catalog":
37
- default:
38
- return handleGetDomainCatalog(repo, config, args, workspaceRoot);
39
- }
40
- }
@@ -1,67 +0,0 @@
1
- import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
2
- import type { SeptumRepository } from "../../core/database/repository.ts";
3
- import type { FeatureToolArgs } from "../schemas.ts";
4
- import { handleGetFeatureContext, handleClearFeatureContext } from "./get-feature-context.ts";
5
- import { handleRegisterFeature } from "./register-feature.ts";
6
-
7
- export type { FeatureToolArgs };
8
-
9
- export async function handleFeatureTool(
10
- repo: SeptumRepository,
11
- config: ValidatedSeptumConfig,
12
- args: FeatureToolArgs,
13
- workspaceRoot?: string
14
- ) {
15
- const action = args.action || "get";
16
-
17
- switch (action) {
18
- case "lock":
19
- return await handleRegisterFeature(
20
- repo,
21
- config,
22
- {
23
- feature_key: args.feature_key || args.feature || "",
24
- feature: args.feature || args.feature_key || "",
25
- domain: args.domain || args.domain_name || "",
26
- domain_name: args.domain_name || args.domain || "",
27
- description: args.description,
28
- allowed_touchpoints: args.allowed_touchpoints,
29
- reuse_symbols: args.reuse_symbols,
30
- input_contract: args.input_contract,
31
- output_contract: args.output_contract,
32
- workspace_path: args.workspace_path,
33
- },
34
- workspaceRoot || args.workspace_path || process.cwd()
35
- );
36
-
37
- case "release": {
38
- const cleared = handleClearFeatureContext(
39
- workspaceRoot || args.workspace_path || process.cwd(),
40
- Boolean(args.force)
41
- );
42
- return {
43
- content: [
44
- {
45
- type: "text" as const,
46
- text: cleared
47
- ? "Active feature session successfully released."
48
- : "No active feature session found to release.",
49
- },
50
- ],
51
- };
52
- }
53
-
54
- case "get":
55
- default:
56
- return handleGetFeatureContext(
57
- repo,
58
- config,
59
- {
60
- feature_key: args.feature_key || args.feature,
61
- feature: args.feature || args.feature_key,
62
- workspace_path: args.workspace_path,
63
- },
64
- workspaceRoot || args.workspace_path || process.cwd()
65
- );
66
- }
67
- }