@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.
Files changed (129) hide show
  1. package/README.md +38 -55
  2. package/package.json +7 -5
  3. package/src/cli/commands/check.ts +14 -10
  4. package/src/cli/commands/hook.ts +41 -6
  5. package/src/cli/commands/init.ts +10 -1
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +32 -4
  9. package/src/cli/index.ts +7 -0
  10. package/src/cli/templates/hooks.ts +3 -14
  11. package/src/cli/templates/skill.ts +17 -10
  12. package/src/core/boundary/audit.ts +383 -0
  13. package/src/core/boundary/evaluator.ts +251 -114
  14. package/src/core/boundary/staged-auditor.ts +147 -55
  15. package/src/core/config/domain-ownership.ts +6 -4
  16. package/src/core/config/domain-registration.ts +141 -0
  17. package/src/core/config/loader.ts +1 -25
  18. package/src/core/config/schema.ts +24 -36
  19. package/src/core/database/client.ts +2 -0
  20. package/src/core/database/repositories/dependency.repository.ts +334 -572
  21. package/src/core/database/repositories/domain.repository.ts +2 -1
  22. package/src/core/database/repositories/file.repository.ts +10 -0
  23. package/src/core/database/repositories/symbol.repository.ts +97 -398
  24. package/src/core/database/repository.ts +68 -9
  25. package/src/core/database/schema.ts +26 -0
  26. package/src/core/discovery/declarative-routes.ts +69 -0
  27. package/src/core/discovery/framework-detector.ts +149 -0
  28. package/src/core/discovery/navigation.ts +222 -58
  29. package/src/core/discovery/topology-detector.ts +93 -168
  30. package/src/core/errors.ts +19 -0
  31. package/src/core/ingestion/pipeline.ts +287 -88
  32. package/src/core/parser/extractors/base.ts +11 -3
  33. package/src/core/parser/extractors/csharp.ts +2 -2
  34. package/src/core/parser/extractors/django-routing.ts +163 -0
  35. package/src/core/parser/extractors/django-semantic.ts +397 -481
  36. package/src/core/parser/extractors/elysia-semantic.ts +172 -475
  37. package/src/core/parser/extractors/express-semantic.ts +195 -383
  38. package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
  39. package/src/core/parser/extractors/fastify-semantic.ts +216 -717
  40. package/src/core/parser/extractors/flask-semantic.ts +89 -352
  41. package/src/core/parser/extractors/go-routing.ts +344 -0
  42. package/src/core/parser/extractors/go-semantic.ts +205 -562
  43. package/src/core/parser/extractors/go.ts +6 -3
  44. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  45. package/src/core/parser/extractors/hono-semantic.ts +132 -509
  46. package/src/core/parser/extractors/java.ts +2 -2
  47. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  48. package/src/core/parser/extractors/laravel-semantic.ts +143 -335
  49. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  50. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  51. package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
  52. package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
  53. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  54. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  55. package/src/core/parser/extractors/php.ts +1 -1
  56. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  57. package/src/core/parser/extractors/python.ts +5 -9
  58. package/src/core/parser/extractors/registry.ts +2 -0
  59. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  60. package/src/core/parser/extractors/ruby.ts +2 -2
  61. package/src/core/parser/extractors/rust.ts +4 -4
  62. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  63. package/src/core/parser/extractors/symfony-semantic.ts +72 -226
  64. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  65. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  66. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  67. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  68. package/src/core/parser/extractors/typescript.ts +23 -216
  69. package/src/core/parser/language-capabilities.ts +1 -1
  70. package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
  71. package/src/core/parser/wasm-loader.ts +6 -2
  72. package/src/core/resolver/ast-method-tracer.ts +230 -0
  73. package/src/core/resolver/call-graph-helpers.ts +72 -0
  74. package/src/core/resolver/call-graph-tracer.ts +169 -414
  75. package/src/core/resolver/dependency-analysis.ts +593 -0
  76. package/src/core/resolver/import-candidates.ts +120 -0
  77. package/src/core/resolver/import-evidence.ts +88 -0
  78. package/src/core/resolver/import-resolver.ts +60 -7
  79. package/src/core/resolver/interpretation-inputs.ts +60 -2
  80. package/src/core/resolver/languages/python.ts +31 -13
  81. package/src/core/resolver/languages/shared.ts +4 -1
  82. package/src/core/resolver/module-resolver.ts +10 -3
  83. package/src/core/resolver/path-resolver.ts +6 -3
  84. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  85. package/src/core/resolver/slice-catalog.ts +21 -6
  86. package/src/core/resolver/slice-format.ts +13 -0
  87. package/src/core/resolver/slice-selection.ts +237 -0
  88. package/src/core/resolver/symbol-impact.ts +104 -8
  89. package/src/core/resolver/symbol-locator.ts +82 -15
  90. package/src/core/resolver/vertical-slice-tracer.ts +31 -230
  91. package/src/core/resources/ignore.ts +0 -1
  92. package/src/core/resources/limits.ts +2 -1
  93. package/src/core/resources/work-queue.ts +167 -4
  94. package/src/core/retrieval/context-page.ts +11 -4
  95. package/src/core/retrieval/context.ts +363 -226
  96. package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
  97. package/src/core/retrieval/symbol-details.ts +453 -0
  98. package/src/core/retrieval/symbol-evidence.ts +3 -3
  99. package/src/core/retrieval/typescript-references.ts +38 -7
  100. package/src/core/retrieval/universal-context.ts +182 -0
  101. package/src/core/telemetry/summary.ts +114 -0
  102. package/src/core/telemetry/telemetry.ts +192 -49
  103. package/src/mcp/formatters/compact-text.ts +439 -0
  104. package/src/mcp/resources-and-prompts.ts +255 -0
  105. package/src/mcp/schemas/boundary.ts +145 -0
  106. package/src/mcp/schemas/map.ts +250 -0
  107. package/src/mcp/schemas/shared.ts +52 -0
  108. package/src/mcp/schemas/slice.ts +60 -0
  109. package/src/mcp/schemas/symbol.ts +268 -0
  110. package/src/mcp/schemas.ts +5 -746
  111. package/src/mcp/server.ts +269 -429
  112. package/src/mcp/tool-catalog.ts +331 -0
  113. package/src/mcp/tools/boundary.ts +68 -3
  114. package/src/mcp/tools/map.ts +104 -4
  115. package/src/mcp/tools/slice.ts +101 -3
  116. package/src/mcp/tools/symbol.ts +469 -17
  117. package/src/mcp/ui/app-client.ts +899 -0
  118. package/src/mcp/ui/app.html +478 -0
  119. package/src/mcp/workflow-playbooks.ts +181 -0
  120. package/src/mcp/workspace-boundary.ts +50 -0
  121. package/src/mcp/workspace-manager.ts +88 -15
  122. package/src/mcp/workspace-watcher.ts +30 -11
  123. package/src/types/index.ts +12 -0
  124. package/src/mcp/tools/check-boundary.ts +0 -382
  125. package/src/mcp/tools/get-domain-catalog.ts +0 -39
  126. package/src/mcp/tools/get-symbol-impact.ts +0 -104
  127. package/src/mcp/tools/locate-symbol.ts +0 -236
  128. package/src/mcp/tools/register-domain.ts +0 -113
  129. package/src/mcp/tools/trace-vertical-slice.ts +0 -106
@@ -1,382 +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 type { BoundaryViolation } from "../../types/index.ts";
10
- import { CheckBoundarySchema, type CheckBoundaryArgs } from "../schemas.ts";
11
-
12
- export type { CheckBoundaryArgs } from "../schemas.ts";
13
-
14
- export async function handleCheckBoundary(
15
- evaluator: BoundaryEvaluator,
16
- config: ValidatedSeptumConfig,
17
- rawArgs: unknown,
18
- repo?: SeptumRepository,
19
- workspaceRoot?: string
20
- ) {
21
- return evaluateBoundary(evaluator, config, CheckBoundarySchema.parse(rawArgs ?? {}), repo, workspaceRoot);
22
- }
23
-
24
- export async function evaluateBoundary(
25
- evaluator: BoundaryEvaluator,
26
- config: ValidatedSeptumConfig,
27
- args: CheckBoundaryArgs,
28
- repo?: SeptumRepository,
29
- workspaceRoot?: string
30
- ) {
31
- if (args.domain) {
32
- const knownDomains = new Set([
33
- ...Object.keys(config.domains || {}),
34
- ...(repo?.getAllDomains?.().map((d) => d.name) ?? []),
35
- ]);
36
- const domain = [...knownDomains].find(name => name.toLowerCase() === args.domain!.toLowerCase());
37
- if (!domain) throw new Error(`Unknown boundary domain '${args.domain}'. Choose a registered domain.`);
38
- args.domain = domain;
39
- }
40
- const root = workspaceRoot || args.workspace_path || process.cwd();
41
- const proposedImports = args.proposed_imports ?? [];
42
- 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."] };
43
-
44
- const syncState = repo?.getMeta("sync_state");
45
- const syncError = repo?.getMeta("sync_error");
46
- if (!syncState || syncState === "running" || syncState === "error" || syncState !== "complete" || syncError) {
47
- return {
48
- content: [
49
- {
50
- type: "text" as const,
51
- text: JSON.stringify({
52
- status: "unknown",
53
- sync_state: syncState || "unindexed",
54
- sync_error: syncError || undefined,
55
- message: "Boundary audit is incomplete because workspace synchronization has not completed.",
56
- }),
57
- },
58
- ],
59
- };
60
- }
61
- const skipped = JSON.parse(repo?.getMeta("skipped_files") || "[]") as {path: string; reason: string}[];
62
- const unsupported = JSON.parse(repo?.getMeta("unsupported_files") || "[]") as string[];
63
- const requested = [...(Array.isArray(args.file_path) ? args.file_path : args.file_path ? [args.file_path] : []), ...(args.file_paths || [])]
64
- .map(file => relative(root, resolve(root, file)).replace(/\\/g, "/"));
65
- const relevantUnsupported = unsupported.filter(file =>
66
- (!args.domain || evaluator.resolveSourceDomain(file, config) === args.domain) &&
67
- (requested.length === 0 || requested.includes(file))
68
- );
69
- const relevantSkipped = skipped.filter(file =>
70
- (!args.domain || evaluator.resolveSourceDomain(file.path, config) === args.domain) &&
71
- (requested.length === 0 || requested.includes(file.path))
72
- );
73
- if (relevantSkipped.length > 0 && args.scope !== "staged" && !args.staged) {
74
- 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."})}] };
75
- }
76
- if (relevantUnsupported.length > 0 && args.scope !== "staged" && !args.staged) {
77
- 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." }) }] };
78
- }
79
-
80
- if (args.scope !== "staged" && !args.staged && repo) {
81
- const relevant = (file: string) => (!args.domain || evaluator.resolveSourceDomain(file,config) === args.domain) && (requested.length === 0 || requested.includes(file));
82
- const staleFiles = repo.getMeta("workspace_root") ? repo.getAllFiles().filter(file => relevant(file.path)).filter(file => {
83
- try { assertPathContained(file.path,root,"Boundary source"); return computeContentHash(readSourceFile(resolve(root,file.path))) !== file.content_hash; }
84
- catch { return true; }
85
- }).map(file => file.path) : [];
86
- const relationships = repo.getImportRelationships(root).filter(edge => relevant(edge.source.file));
87
- 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);
88
- const allProposed = requested.flatMap(file => proposedImports.map(target => evaluator.getResolver().resolveImport(target, file)));
89
- const proposed = allProposed.filter(result => !["resolved", "external"].includes(result.status) || result.coverage === "conditional");
90
- if (incomplete.length || proposed.length || staleFiles.length) {
91
- const known = evaluator.auditCodebase(config).filter(violation => relevant(violation.file));
92
- known.push(...requested.flatMap(file => evaluator.evaluate(file, proposedImports, config)));
93
- return { content: [{ type: "text" as const, text: JSON.stringify({
94
- status: known.length ? "rejected" : "unknown", violations: known, total_violations: known.length,
95
- circular_dependencies: known.filter(v => v.rule === "circular_dependency"), circular_dependencies_count: known.filter(v => v.rule === "circular_dependency").length,
96
- relationships: incomplete.slice(0, 10), proposed_resolutions: allProposed,
97
- diagnostic_accounting: { total: incomplete.length, returned: Math.min(10, incomplete.length), omitted: Math.max(0, incomplete.length - 10) },
98
- incomplete_reasons: {
99
- target_not_fully_indexed: incomplete.filter(edge => edge.index_coverage === "partial").length,
100
- stale_source: incomplete.filter(edge => edge.freshness !== "current").length,
101
- unresolved_or_unsupported: incomplete.filter(edge => !["resolved", "external"].includes(edge.resolution.status)).length,
102
- conditional_resolution: incomplete.filter(edge => edge.resolution.coverage === "conditional").length,
103
- multiple_domains: incomplete.filter(edge => edge.target_domains.length > 1).length,
104
- },
105
- next: ["Inspect the listed source imports; register/index uncovered target roots or narrow scope to a file/domain. Unknown is not approval."],
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, 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
- let violations = evaluator.auditCodebase(config);
200
- if (args.domain) {
201
- const targetDom = args.domain.toLowerCase();
202
- violations = violations.filter(
203
- (v) =>
204
- v.source_domain.toLowerCase() === targetDom ||
205
- v.target_domain.toLowerCase() === targetDom
206
- );
207
- }
208
-
209
- const circularDependencies = violations.filter((v) => v.rule === "circular_dependency");
210
- const domainBreakdown: Record<string, number> = {};
211
- for (const v of violations) {
212
- const pair = `${v.source_domain} -> ${v.target_domain}`;
213
- domainBreakdown[pair] = (domainBreakdown[pair] || 0) + 1;
214
- }
215
-
216
- const hasViolations = violations.length > 0;
217
- const domainCount = Object.keys(config?.domains || {}).length;
218
- const allIndexedFiles = repo && typeof repo.getAllFiles === "function" ? repo.getAllFiles() : [];
219
- const domainFileCount = args.domain && allIndexedFiles.length > 0
220
- ? allIndexedFiles.filter((f) => evaluator.resolveSourceDomain(f.path, config) === args.domain).length
221
- : null;
222
- const emptyScopedDomain = Boolean(args.domain && domainFileCount === 0);
223
-
224
- return {
225
- content: [
226
- {
227
- type: "text" as const,
228
- text: JSON.stringify(
229
- {
230
- status: hasViolations ? "rejected" : emptyScopedDomain ? "unknown" : "approved",
231
- scope: args.domain ? "domain" : "all",
232
- ...(args.domain ? { domain: args.domain } : {}),
233
- total_domains_checked: domainCount,
234
- total_violations: violations.length,
235
- circular_dependencies_count: circularDependencies.length,
236
- circular_dependencies: circularDependencies,
237
- domain_violation_breakdown: domainBreakdown,
238
- violations,
239
- message: hasViolations
240
- ? `${violations.length} boundary violation(s) (${circularDependencies.length} circular) detected${
241
- args.domain ? ` in domain '${args.domain}'` : " across codebase"
242
- }.`
243
- : emptyScopedDomain
244
- ? `Boundary check is incomplete: domain '${args.domain}' has 0 indexed files (it may be unindexed or shadowed by a parent domain).`
245
- : domainCount === 0
246
- ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]"
247
- : `All domain boundaries are clean${
248
- args.domain ? ` for domain '${args.domain}'` : ""
249
- }. Zero cross-domain leaks or circular dependencies detected.`,
250
- },
251
- null,
252
- 2
253
- ),
254
- },
255
- ],
256
- };
257
- }
258
-
259
- // Multi-file batch evaluation
260
- if (filesToCheck.length > 1) {
261
- const results = filesToCheck.map((filePath) => {
262
- const violations = evaluator.evaluate(filePath, proposedImports, config);
263
- const impact = repo?.getFileInboundImpact(filePath);
264
- return {
265
- file: filePath,
266
- evaluated_scope: evaluatedScope,
267
- status: violations.length > 0 ? "rejected" : "approved",
268
- violations,
269
- impact_summary: impact
270
- ? {
271
- direct_dependents: impact.direct_dependents_count,
272
- top_consumers: impact.top_consumers,
273
- symbols_count: impact.symbols_count,
274
- risk_level: impact.risk_level,
275
- }
276
- : undefined,
277
- };
278
- });
279
-
280
- const totalViolations = results.reduce((acc, r) => acc + r.violations.length, 0);
281
- const hasViolations = totalViolations > 0;
282
-
283
- return {
284
- content: [
285
- {
286
- type: "text" as const,
287
- text: JSON.stringify(
288
- {
289
- status: hasViolations ? "rejected" : "approved",
290
- total_checked: filesToCheck.length,
291
- total_violations: totalViolations,
292
- results,
293
- message: hasViolations
294
- ? `${totalViolations} boundary violation(s) detected across ${filesToCheck.length} file(s).`
295
- : Object.keys(config?.domains || {}).length === 0
296
- ? `All ${filesToCheck.length} file(s) approved. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]`
297
- : `All ${filesToCheck.length} file(s) approved. No boundary violations detected.`,
298
- },
299
- null,
300
- 2
301
- ),
302
- },
303
- ],
304
- };
305
- }
306
-
307
- // Single file evaluation (backward-compatible output)
308
- const singleFile = filesToCheck[0];
309
- const violations = evaluator.evaluate(singleFile, proposedImports, config);
310
- const impact = repo?.getFileInboundImpact(singleFile);
311
- const enforcementMode = config?.settings?.enforcement ?? "strict";
312
-
313
- if (violations.length > 0) {
314
- return {
315
- content: [
316
- {
317
- type: "text" as const,
318
- text: JSON.stringify(
319
- {
320
- status: "rejected",
321
- enforcement_mode: enforcementMode,
322
- file: singleFile,
323
- evaluated_scope: evaluatedScope,
324
- violations_count: violations.length,
325
- violations,
326
- impact_summary: 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
- message:
335
- Object.keys(config?.domains || {}).length === 0
336
- ? "Boundary integrity check failed: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts."
337
- : violations.some((v) => v.rule === "unmapped_domain")
338
- ? "Boundary integrity check failed: File does not belong to any declared bounded context."
339
- : "Boundary violation detected. Proposed imports violate bounded context architecture.",
340
- },
341
- null,
342
- 2
343
- ),
344
- },
345
- ],
346
- };
347
- }
348
-
349
- return {
350
- content: [
351
- {
352
- type: "text" as const,
353
- text: JSON.stringify(
354
- {
355
- status: "approved",
356
- enforcement_mode: enforcementMode,
357
- file: singleFile,
358
- evaluated_scope: evaluatedScope,
359
- impact_summary: impact
360
- ? {
361
- direct_dependents: impact.direct_dependents_count,
362
- top_consumers: impact.top_consumers,
363
- symbols_count: impact.symbols_count,
364
- risk_level: impact.risk_level,
365
- }
366
- : undefined,
367
- message:
368
- Object.keys(config?.domains || {}).length === 0
369
- ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]"
370
- : enforcementMode === "warn"
371
- ? "Approved under 'warn' enforcement (unlisted allowed_dependencies are not blocked; only explicit forbidden_dependencies are rejected)."
372
- : impact && impact.direct_dependents_count > 0
373
- ? `No boundary violations detected. Caution: ${impact.direct_dependents_count} dependent file(s) consume this file.`
374
- : "Proposal approved. Existing file imports were not audited.",
375
- },
376
- null,
377
- 2
378
- ),
379
- },
380
- ],
381
- };
382
- }
@@ -1,39 +0,0 @@
1
- import { buildNavigation, NAVIGATION_SCHEMA } from '../../core/discovery/navigation.ts';
2
- import { getParserCapabilities } from '../../core/parser/language-capabilities.ts';
3
- import { SemanticSliceExtractorRegistry } from '../../core/parser/extractors/registry.ts';
4
- import type { ValidatedSeptumConfig } from '../../core/config/schema.ts';
5
- import type { SeptumRepository } from '../../core/database/repository.ts';
6
- import type { GetDomainCatalogArgs } from '../schemas.ts';
7
- import { getCachedRuntimeVersion, type RuntimeVersionMeta } from '../../utils/version-check.ts';
8
-
9
- export type { GetDomainCatalogArgs };
10
-
11
- export function buildDomainCatalog(repo: SeptumRepository, _config: ValidatedSeptumConfig, args: GetDomainCatalogArgs,
12
- workspaceRoot?: string, runtimeVersion: RuntimeVersionMeta = getCachedRuntimeVersion()) {
13
- const root = workspaceRoot ?? args.workspace_path ?? repo.getMeta('workspace_root') ?? process.cwd();
14
- const navigation = buildNavigation(repo, args, root);
15
- if (args.include_evidence && (!args.file_filter || !('files' in navigation) || navigation.files.length !== 1 || navigation.accounting.matching_files !== 1)) {
16
- throw new Error('include_evidence requires file_filter matching exactly one indexed file.');
17
- }
18
- const evidence = args.include_evidence && 'files' in navigation
19
- ? repo.getImportRelationships(root, navigation.files[0]!.path) : [];
20
- return { ...navigation,
21
- ...(args.include_capabilities ? { parser_capabilities: { ...getParserCapabilities(args.detail_level === 'full'), semantic_adapters: SemanticSliceExtractorRegistry.getCapabilities() } } : {}),
22
- ...(args.include_evidence ? { evidence: evidence.slice(0, 20), evidence_accounting: { total: evidence.length, returned: Math.min(20, evidence.length), omitted: Math.max(0, evidence.length - 20) } } : {}),
23
- runtime_version: runtimeVersion,
24
- ...(runtimeVersion.update_available ? { update_notice: `Update available: ${runtimeVersion.latest_version}; ${runtimeVersion.upgrade_command}. Reload after updating.` } : {}),
25
- };
26
- }
27
-
28
- export function handleGetDomainCatalog(repo: SeptumRepository, config: ValidatedSeptumConfig, args: GetDomainCatalogArgs, workspaceRoot?: string) {
29
- const payload = buildDomainCatalog(repo, config, args, workspaceRoot);
30
- return { content: [{ type: 'text' as const, text: JSON.stringify(payload) }], metadata: { schema: payload.schema, status: payload.status }, runtime_version: payload.runtime_version };
31
- }
32
-
33
- export function buildUnindexedCatalog(root: string, runtimeVersion: RuntimeVersionMeta) {
34
- return { schema: NAVIGATION_SCHEMA, status: 'NOT_INDEXED', total_domains: 0, runtime_version: runtimeVersion,
35
- message: `Workspace '${root}' belum diinisialisasi. Register a domain or run septum init.`,
36
- suggested_action: { tool: 'septum_map', params: { action: 'register', name: 'core', root: 'src', ingest_now: true } },
37
- next: [{ tool: 'septum_map', args: { action: 'register', name: 'core', root: 'src', ingest_now: true } }],
38
- };
39
- }
@@ -1,104 +0,0 @@
1
- import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
2
- import type { SeptumRepository } from "../../core/database/repository.ts";
3
- import type { GetSymbolImpactArgs } from "../../types/index.ts";
4
- import { partitionResolutionWarnings } from "../../core/retrieval/resolution-warnings.ts";
5
- import { symbolWorkspace, withSymbolEvidence } from "../../core/retrieval/symbol-evidence.ts";
6
-
7
- export function handleGetSymbolImpact(
8
- repo: SeptumRepository,
9
- config: ValidatedSeptumConfig,
10
- args: GetSymbolImpactArgs,
11
- workspaceRoot?: string
12
- ) {
13
- const root = symbolWorkspace(repo, workspaceRoot || args.workspace_path);
14
- return withSymbolEvidence(repo, root, { operation: "impact", requested: args.symbol_ref },
15
- () => inspectImpact(repo, config, args, root));
16
- }
17
-
18
- function inspectImpact(
19
- repo: SeptumRepository,
20
- _config: ValidatedSeptumConfig,
21
- args: GetSymbolImpactArgs,
22
- workspaceRoot?: string
23
- ) {
24
- const symbol = (args.symbol_ref?.name || args.symbol || (args as unknown as Record<string, unknown>).query || "").toString().trim();
25
- if (!symbol) {
26
- throw new Error(
27
- "Missing required argument: 'symbol' (e.g. 'OrderService::cancelOrder', 'OrderService', or 'cancelOrder')"
28
- );
29
- }
30
-
31
- if (args.symbol_ref) {
32
- const file = repo.getFileByPath(args.symbol_ref.file_path);
33
- if (!file || file.content_hash !== args.symbol_ref.indexed_content_hash) {
34
- return { content: [{ type: "text" as const, text: JSON.stringify({
35
- target_symbol: symbol, status: "stale_reference", found_in_index: false,
36
- message: "Declaration reference is stale; locate the symbol again.",
37
- }) }] };
38
- }
39
- }
40
-
41
- const candidates = repo.findSymbolsByName(symbol, {
42
- domain: args.domain,
43
- filePath: args.file_path,
44
- reference: args.symbol_ref,
45
- });
46
- if (candidates.length > 1) {
47
- return { content: [{ type: "text" as const, text: JSON.stringify({
48
- status: "ambiguous", target_symbol: symbol, found_in_index: false,
49
- candidates: candidates.map(candidate => ({ name: candidate.name, file_path: candidate.file_path, symbol_ref: candidate.symbol_ref })),
50
- message: "Multiple declarations match; select a candidate with symbol_ref or narrow with file_path.",
51
- }, null, 2) }] };
52
- }
53
- const selectedCandidate = candidates[0];
54
- const impact = repo.getSymbolImpact(symbol, {
55
- domain: args.domain,
56
- filePath: args.file_path || selectedCandidate?.file_path,
57
- reference: args.symbol_ref || selectedCandidate?.symbol_ref,
58
- workspaceRoot: workspaceRoot || args.workspace_path,
59
- });
60
-
61
- const relationships = repo.getImportRelationships(workspaceRoot || args.workspace_path);
62
- const targetFiles = candidates.map(candidate => candidate.file_path);
63
- const importDependents = relationships.filter(edge => edge.resolution.status === "resolved" && edge.resolution.targets.some(target => target.files.some(file => targetFiles.includes(file))));
64
- const warnings = partitionResolutionWarnings(relationships, targetFiles);
65
- const callSites = impact.inbound_callers.filter(
66
- caller => caller.kind === "call" || caller.kind === "instantiation" || caller.kind === "heritage"
67
- );
68
- const firstResolution = importDependents[0]?.resolution;
69
- const compactImportDependents = importDependents.map(edge => ({
70
- source: {
71
- file: edge.source.file,
72
- line: edge.source.line,
73
- statement: edge.source.statement,
74
- },
75
- target_domains: edge.target_domains,
76
- resolution: {
77
- status: edge.resolution.status,
78
- reason: edge.resolution.reason,
79
- targets: edge.resolution.targets,
80
- },
81
- }));
82
- const payload = { ...impact, symbol_ref: selectedCandidate?.symbol_ref, coverage: "partial", inbound_callers_complete: false,
83
- call_sites: callSites,
84
- risk_scope: "advisory; incomplete static consumer evidence, not a refactoring safety verdict",
85
- relationship_limits: "Imports do not prove executed calls. Import-bound function call sites are static evidence; legacy hints remain inferred. Static calls do not prove runtime execution or a complete caller set.",
86
- ...(firstResolution ? { resolution_metadata: { resolver_revision: firstResolution.resolver_revision, config_revision: firstResolution.config_revision } } : {}),
87
- import_dependents: compactImportDependents,
88
- resolution_warnings: warnings.relevant,
89
- workspace_resolution_diagnostics: {
90
- count: warnings.workspace.length, returned_details: 0, omitted_details: warnings.workspace.length,
91
- reason: "Current resolved imports to unrelated indexed files are summarized separately; unresolved, ambiguous, unsupported and stale relationships remain conservatively in resolution_warnings.",
92
- },
93
- diagnostic_accounting: { total: warnings.relevant.length + warnings.workspace.length,
94
- target_or_possible_target: warnings.relevant.length, unrelated_workspace: warnings.workspace.length },
95
- };
96
- return {
97
- content: [
98
- {
99
- type: "text" as const,
100
- text: JSON.stringify(payload),
101
- },
102
- ],
103
- };
104
- }