@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.
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 +253 -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
@@ -0,0 +1,331 @@
1
+ import type { Tool } from "@modelcontextprotocol/sdk/types.js";
2
+ import type { WorkspaceContext } from "./workspace-manager.ts";
3
+ import { MapToolSchema, SymbolToolSchema, SliceToolSchema, BoundaryToolSchema } from "./schemas.ts";
4
+ import { handleMapTool } from "./tools/map.ts";
5
+ import { handleSymbolTool } from "./tools/symbol.ts";
6
+ import { handleSliceTool } from "./tools/slice.ts";
7
+ import { handleBoundaryTool } from "./tools/boundary.ts";
8
+
9
+ function defineTool<Name extends string, Args>(
10
+ definition: Omit<Tool, "name"> & {
11
+ name: Name;
12
+ schema: { parse(input: unknown): Args };
13
+ _meta?: Record<string, unknown>;
14
+ execute(ctx: WorkspaceContext, args: Args, signal?: AbortSignal): ReturnType<typeof handleMapTool> | ReturnType<typeof handleSymbolTool> | ReturnType<typeof handleSliceTool> | ReturnType<typeof handleBoundaryTool>;
15
+ },
16
+ ) {
17
+ const { name, description, inputSchema, _meta, schema, execute } = definition;
18
+ return {
19
+ name, description, inputSchema, _meta,
20
+ parse(input: unknown) {
21
+ const args = schema.parse(input ?? {});
22
+ return { name, args, execute: (ctx: WorkspaceContext, signal?: AbortSignal) => execute(ctx, args, signal) };
23
+ },
24
+ };
25
+ }
26
+
27
+ const SEPTUM_APP_URI = "ui://septum/app.html";
28
+
29
+ export const TOOL_CATALOG = [
30
+ defineTool({
31
+ name: "septum_map",
32
+ schema: MapToolSchema,
33
+ execute: (ctx, args, signal) => handleMapTool(ctx.repo, ctx.config, args, ctx.root, signal),
34
+ _meta: {
35
+ ui: { resourceUri: SEPTUM_APP_URI },
36
+ "com.google.antigravity/ui": {
37
+ entrypoints: [
38
+ { type: "aux_pane", title: "Septum Architecture" },
39
+ { type: "global", title: "Septum" },
40
+ ],
41
+ },
42
+ },
43
+ description:
44
+ "Inspect workspace architecture or register domains. action='catalog' (default) returns domain topology, cross-domain import adjacency, file neighborhoods, static entrypoints, and index health. action='register' adds a bounded-context domain and optionally ingests it. Use file_filter to focus files, include_evidence=true for one file's import details, septum_symbol for declarations/source, or septum_slice for entrypoint traces. Example: {action:'catalog',domain:'mcp'}.",
45
+ inputSchema: {
46
+ type: "object",
47
+ properties: {
48
+ action: {
49
+ type: "string",
50
+ enum: ["catalog", "register"],
51
+ default: "catalog",
52
+ description: "Sub-operation to execute: 'catalog' (inspect domain/macro map) or 'register' (dynamically register bounded-context domain).",
53
+ },
54
+ domain: {
55
+ type: "string",
56
+ description: "Target domain name (e.g. 'orders', 'core'). If omitted in catalog action, returns project-wide Macro Semantic Map.",
57
+ },
58
+ detail_level: {
59
+ type: "string",
60
+ enum: ["compact", "full"],
61
+ default: "compact",
62
+ description: "Navigation extent: compact selects up to 40 files (or submodule zoom-in for large domains >25 files), full up to 100. Neither includes signatures or source; use septum_symbol for declaration inspection.",
63
+ },
64
+ format: {
65
+ type: "string",
66
+ enum: ["text", "json"],
67
+ default: "text",
68
+ description: "Output format: 'text' (default token-efficient compact markdown summary) or 'json' (structured navigation/v1 payload).",
69
+ },
70
+ archetype_filter: {
71
+ type: "string",
72
+ description: "Optional archetype filter (e.g. 'service', 'model', 'controller', 'repository').",
73
+ },
74
+ file_filter: {
75
+ type: "string",
76
+ description: "Optional substring filter to inspect specific file(s) within the domain.",
77
+ },
78
+ file_offset: { type: "integer", minimum: 0, description: "Start of the catalog file page; copy next_file_offset from pagination." },
79
+ file_limit: { type: "integer", minimum: 1, maximum: 100, description: "Optional navigation selection limit. Small scopes return together; pagination appears only when files remain." },
80
+ include_evidence: { type: "boolean", description: "Opt in to up to 20 raw import-evidence records; requires file_filter matching exactly one file." },
81
+ include_capabilities: { type: "boolean", description: "Opt in to language/parser capabilities; omitted from navigation by default." },
82
+ root: {
83
+ type: "string",
84
+ description: "Root directory path for domain registration (action='register').",
85
+ },
86
+ description: {
87
+ type: "string",
88
+ description: "Architectural purpose of the domain (action='register').",
89
+ },
90
+ allowed_dependencies: {
91
+ type: "array",
92
+ items: { type: "string" },
93
+ description: "List of domain names this domain is allowed to import (action='register').",
94
+ },
95
+ forbidden_dependencies: {
96
+ type: "array",
97
+ items: { type: "string" },
98
+ description: "List of domain names strictly forbidden from being imported (action='register').",
99
+ },
100
+ archetypes: {
101
+ type: "object",
102
+ description: "Layer archetypes mapping (action='register').",
103
+ },
104
+ ingest_now: {
105
+ type: "boolean",
106
+ default: false,
107
+ description: "Whether to immediately run AST ingestion on domain files upon registration.",
108
+ },
109
+ workspace_path: {
110
+ type: "string",
111
+ description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
112
+ },
113
+ },
114
+ required: [],
115
+ },
116
+ }),
117
+ defineTool({
118
+ name: "septum_symbol",
119
+ schema: SymbolToolSchema,
120
+ execute: (ctx, args, signal) => handleSymbolTool(ctx.repo, ctx.config, args, ctx.pipeline, ctx.root, signal),
121
+ description:
122
+ "Find indexed symbols, read declaration context/source, or check refactor impact. action='locate' (default) searches declarations by name or call syntax. action='context' (alias 'inspect') returns declaration source plus supporting TypeScript references (within budget_bytes) or bounded polyglot source; check freshness, diagnostics, and omissions in the result. action='impact' lists import dependents, static call sites, and inferred caller hints (incomplete static evidence). Use septum_map for domain/file navigation and septum_slice for entrypoints. Example: {action:'context',query:'handleOrder',file_path:'src/orders.ts'}.",
123
+ inputSchema: {
124
+ type: "object",
125
+ properties: {
126
+ action: {
127
+ type: "string",
128
+ enum: ["locate", "context", "inspect", "impact"],
129
+ default: "locate",
130
+ description: "'locate' finds declarations; 'context' (or 'inspect') retrieves declaration source along with local/import-bound supporting declarations for TypeScript within budget_bytes, or bounded source for polyglot files; 'impact' reports static caller hints. Example: {action:'context',query:'submit',file_path:'src/submit.ts'}.",
131
+ },
132
+ query: {
133
+ type: "string",
134
+ description: "Symbol name, call syntax (e.g. 'OrderController::cancelOrder'), or search query.",
135
+ },
136
+ domain: {
137
+ type: "string",
138
+ description: "Optional domain filter (e.g. 'orders').",
139
+ },
140
+ file_path: {
141
+ type: "string",
142
+ description: "Exact indexed repository-relative file path. Use it to select one candidate when names are ambiguous.",
143
+ },
144
+ symbol_ref: {
145
+ type: "object",
146
+ description: "Declaration reference returned by locate or catalog. Stale indexed fingerprints are refused.",
147
+ properties: {
148
+ file_path: { type: "string", minLength: 1 },
149
+ language: { type: "string", minLength: 1 },
150
+ name: { type: "string", minLength: 1 },
151
+ kind: { type: "string", minLength: 1 },
152
+ signature: { type: "string" },
153
+ start_line: { type: "integer", minimum: 1 },
154
+ end_line: { type: "integer", minimum: 1 },
155
+ indexed_content_hash: { type: "string", minLength: 1 },
156
+ container: { type: "string" },
157
+ receiver: { type: "string" },
158
+ },
159
+ required: ["file_path", "language", "name", "kind", "signature", "start_line", "end_line", "indexed_content_hash"],
160
+ },
161
+ include_source: {
162
+ type: "boolean",
163
+ description: "Explicit true selects bounded source; explicit false selects declaration details without source. Omit for deep TypeScript context or default polyglot source. Source hashes must match disk.",
164
+ },
165
+ source_start_line: {
166
+ type: "number",
167
+ minimum: 1,
168
+ description: "First line to return within the selected symbol range.",
169
+ },
170
+ source_line_limit: {
171
+ type: "number",
172
+ minimum: 1,
173
+ maximum: 200,
174
+ description: "Select bounded source inspection with this line limit (capped at 200). Bounded mode uses 120 lines when omitted.",
175
+ },
176
+ context_mode: {
177
+ type: "string", enum: ["deep", "source"],
178
+ description: "Explicit context mode. deep selects referenced TypeScript declarations; source selects bounded source inspection. Omit for legacy automatic selection.",
179
+ },
180
+ include_dependencies: {
181
+ type: "boolean",
182
+ default: true,
183
+ description: "Whether to include injected dependencies and outbound calls.",
184
+ },
185
+ budget_bytes: {
186
+ type: "integer",
187
+ minimum: 2048,
188
+ maximum: 2097152,
189
+ default: 16384,
190
+ description: "For deep TypeScript context (including inspect alias): maximum UTF-8 bytes of the serialized MCP tool result, including evidence and continuation. Do not combine with bounded source options.",
191
+ },
192
+ max_depth: {
193
+ type: "integer",
194
+ minimum: 1,
195
+ maximum: 4,
196
+ default: 2,
197
+ description: "For deep TypeScript context: maximum import edge depth to traverse from the target declaration (default: 2, min: 1, max: 4).",
198
+ },
199
+ continuation: {
200
+ type: "string",
201
+ minLength: 1,
202
+ maxLength: 4096,
203
+ description: "For action='context': copy the previous page token with the same target and budget.",
204
+ },
205
+ limit: {
206
+ type: "number",
207
+ description: "Maximum results to return for locate (default: 10).",
208
+ },
209
+ format: {
210
+ type: "string",
211
+ enum: ["text", "json"],
212
+ default: "text",
213
+ description: "Output format: 'text' (default token-efficient compact summary) or 'json' (structured payload).",
214
+ },
215
+ workspace_path: {
216
+ type: "string",
217
+ description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
218
+ },
219
+ },
220
+ required: [],
221
+ },
222
+ }),
223
+ defineTool({
224
+ name: "septum_slice",
225
+ schema: SliceToolSchema,
226
+ execute: (ctx, args, signal) => handleSliceTool(ctx.repo, ctx.config, args, ctx.root, signal),
227
+ _meta: {
228
+ ui: { resourceUri: SEPTUM_APP_URI },
229
+ },
230
+ description:
231
+ "Trace a cataloged static entrypoint (HTTP route, handler, job, CLI command, or event) to related nodes with relationship evidence and diagnostics. Static matches do not establish runtime execution order or complete reachability. Use septum_symbol for declarations and septum_boundary for import policy. Example: {query:'POST /orders/{id}/pay',max_depth:5} or {query:'OrderController@pay'}.",
232
+ inputSchema: {
233
+ type: "object",
234
+ properties: {
235
+ query: {
236
+ type: "string",
237
+ description: "Route URI (e.g. 'POST /orders/{id}/pay'), action (e.g. 'OrderController@pay'), or high-level task intent.",
238
+ },
239
+ controller_file: {
240
+ type: "string",
241
+ minLength: 1,
242
+ description: "Exact catalog controller/handler file copied from an ambiguity candidate. Filters target selection.",
243
+ },
244
+ max_depth: {
245
+ type: "number",
246
+ default: 5,
247
+ minimum: 1,
248
+ maximum: 8,
249
+ description: "Maximum depth to trace (default: 5, min: 1, max: 8). Use 6-8 for deep Event/Job/Queue traces.",
250
+ },
251
+ format: {
252
+ type: "string",
253
+ enum: ["text", "json"],
254
+ default: "text",
255
+ description: "Output format: 'text' (default token-efficient compact summary) or 'json' (structured payload).",
256
+ },
257
+ workspace_path: {
258
+ type: "string",
259
+ description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
260
+ },
261
+ },
262
+ required: ["query"],
263
+ },
264
+ }),
265
+ defineTool({
266
+ name: "septum_boundary",
267
+ schema: BoundaryToolSchema,
268
+ execute: (ctx, args, signal) => handleBoundaryTool(ctx.evaluator, ctx.config, args, ctx.repo, ctx.root),
269
+ _meta: {
270
+ ui: { resourceUri: SEPTUM_APP_URI },
271
+ },
272
+ description:
273
+ "Validate proposed or staged imports against domain boundaries and circular-dependency rules. When to use: (1) scope='file' with proposed_imports BEFORE writing new import statements, (2) scope='staged' BEFORE git commit to catch cross-domain leaks, (3) scope='all' or 'domain' for codebase audits. When NOT to use: do NOT use to read source code or locate symbols. Status 'approved' confirms zero violations; 'rejected' requires refactoring. Example: {scope:'file',file_path:'src/order/service.ts',proposed_imports:['../billing/repo']}.",
274
+ inputSchema: {
275
+ type: "object",
276
+ properties: {
277
+ max_bytes: {
278
+ type: "integer",
279
+ minimum: 512,
280
+ maximum: 2097152,
281
+ description: "Optional maximum UTF-8 byte size of the serialized tool result. Narrow the scope if the complete verdict and evidence exceed it.",
282
+ },
283
+ scope: {
284
+ type: "string",
285
+ enum: ["file", "staged", "all", "domain"],
286
+ default: "file",
287
+ description: "'file' evaluates proposed imports against domain policies; 'staged' audits git index changes; 'domain' checks a specific domain's violations; 'all' audits the entire workspace.",
288
+ },
289
+ file_path: {
290
+ type: "string",
291
+ description: "Path of the file being edited or created (scope='file' only). Use either file_path or file_paths.",
292
+ },
293
+ file_paths: {
294
+ type: "array",
295
+ items: { type: "string" },
296
+ description: "Non-empty list of file paths for batch proposed-import checks (scope='file' only).",
297
+ },
298
+ proposed_imports: {
299
+ type: "array",
300
+ items: { type: "string" },
301
+ description: "List of proposed import statements or target symbols (scope='file' only).",
302
+ },
303
+ domain: {
304
+ type: "string",
305
+ description: "Registered domain name, required for scope='domain'; optional for staged/file checks.",
306
+ },
307
+ staged: {
308
+ type: "boolean",
309
+ description: "Convenience flag equivalent to scope='staged'.",
310
+ },
311
+ format: {
312
+ type: "string",
313
+ enum: ["text", "json"],
314
+ default: "text",
315
+ description: "Output format: 'text' (default token-efficient compact summary) or 'json' (structured payload).",
316
+ },
317
+ workspace_path: {
318
+ type: "string",
319
+ description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
320
+ },
321
+ },
322
+ required: [],
323
+ },
324
+ }),
325
+ ];
326
+
327
+ export function parseToolRequest(name: string, args: unknown) {
328
+ const tool = TOOL_CATALOG.find(entry => entry.name === name);
329
+ if (!tool) throw new Error(`Unknown tool: '${name}'`);
330
+ return tool.parse(args);
331
+ }
@@ -1,10 +1,11 @@
1
1
  import type { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
2
+ import { evaluateBoundary as auditBoundary } from "../../core/boundary/audit.ts";
2
3
  import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
3
4
  import type { SeptumRepository } from "../../core/database/repository.ts";
4
- import type { BoundaryToolArgs } from "../schemas.ts";
5
- import { evaluateBoundary } from "./check-boundary.ts";
5
+ import { formatBoundaryAsText } from "../formatters/compact-text.ts";
6
+ import { CheckBoundarySchema, type BoundaryToolArgs, type CheckBoundaryArgs } from "../schemas.ts";
6
7
 
7
- export type { BoundaryToolArgs };
8
+ export type { BoundaryToolArgs, CheckBoundaryArgs };
8
9
 
9
10
  export async function handleBoundaryTool(
10
11
  evaluator: BoundaryEvaluator,
@@ -15,3 +16,67 @@ export async function handleBoundaryTool(
15
16
  ) {
16
17
  return await evaluateBoundary(evaluator, config, args, repo, workspaceRoot);
17
18
  }
19
+
20
+ export async function handleCheckBoundary(
21
+ evaluator: BoundaryEvaluator,
22
+ config: ValidatedSeptumConfig,
23
+ rawArgs: unknown,
24
+ repo?: SeptumRepository,
25
+ workspaceRoot?: string,
26
+ ) {
27
+ return evaluateBoundary(evaluator, config, CheckBoundarySchema.parse(rawArgs ?? {}), repo, workspaceRoot);
28
+ }
29
+
30
+ export async function evaluateBoundary(
31
+ evaluator: BoundaryEvaluator,
32
+ config: ValidatedSeptumConfig,
33
+ args: CheckBoundaryArgs,
34
+ repo?: SeptumRepository,
35
+ workspaceRoot?: string,
36
+ ) {
37
+ const effectiveRoot = workspaceRoot ?? args.workspace_path ?? evaluator.getResolver().getProjectRoot();
38
+ const audit = await auditBoundary(
39
+ evaluator, config, args, repo, effectiveRoot,
40
+ );
41
+ return renderBoundaryAudit(audit, args.max_bytes, args.format ?? "text", effectiveRoot);
42
+ }
43
+
44
+ export function renderBoundaryAudit(
45
+ { payload, kind }: Awaited<ReturnType<typeof auditBoundary>>,
46
+ maxBytes?: number,
47
+ format: "json" | "text" = "text",
48
+ workspaceRoot?: string,
49
+ ) {
50
+ const structuredPayload = workspaceRoot
51
+ ? { workspace_root: workspaceRoot, ...(payload as Record<string, unknown>) }
52
+ : (payload as Record<string, unknown>);
53
+ const rendered = format === "json"
54
+ ? JSON.stringify(structuredPayload, null, kind === "evaluated" ? 2 : undefined)
55
+ : formatBoundaryAsText(structuredPayload as Record<string, any>);
56
+ const result = {
57
+ content: [{ type: "text" as const, text: rendered }],
58
+ structuredContent: structuredPayload,
59
+ metadata: { status: payload.status, format },
60
+ };
61
+ if (maxBytes === undefined) return result;
62
+
63
+ const compact = format === "json"
64
+ ? { ...result, content: [{ type: "text" as const, text: JSON.stringify(structuredPayload) }] }
65
+ : result;
66
+ const requiredBytes = Buffer.byteLength(JSON.stringify(compact));
67
+ if (requiredBytes <= maxBytes) return compact;
68
+
69
+ const errPayload = {
70
+ status: "unknown",
71
+ code: "BUDGET_RESPONSE_TOO_LARGE",
72
+ required_bytes: requiredBytes,
73
+ max_bytes: maxBytes,
74
+ message: "Increase max_bytes or narrow the audit scope.",
75
+ };
76
+ return {
77
+ isError: true,
78
+ content: [{ type: "text" as const, text: format === "json" ? JSON.stringify(errPayload) : formatBoundaryAsText(errPayload) }],
79
+ structuredContent: errPayload,
80
+ metadata: { status: "unknown" as const, code: "BUDGET_RESPONSE_TOO_LARGE", format },
81
+ };
82
+ }
@@ -1,10 +1,14 @@
1
+ import { registerDomainPolicy } from "../../core/config/domain-registration.ts";
1
2
  import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
2
3
  import type { SeptumRepository } from "../../core/database/repository.ts";
3
- import type { MapToolArgs } from "../schemas.ts";
4
- import { handleGetDomainCatalog } from "./get-domain-catalog.ts";
5
- import { handleRegisterDomain } from "./register-domain.ts";
4
+ import { buildNavigation, NAVIGATION_SCHEMA } from "../../core/discovery/navigation.ts";
5
+ import { SemanticSliceExtractorRegistry } from "../../core/parser/extractors/registry.ts";
6
+ import { getParserCapabilities } from "../../core/parser/language-capabilities.ts";
7
+ import { getCachedRuntimeVersion, type RuntimeVersionMeta } from "../../utils/version-check.ts";
8
+ import { formatMapAsText } from "../formatters/compact-text.ts";
9
+ import type { GetDomainCatalogArgs, MapToolArgs, RegisterDomainArgs } from "../schemas.ts";
6
10
 
7
- export type { MapToolArgs };
11
+ export type { GetDomainCatalogArgs, MapToolArgs, RegisterDomainArgs };
8
12
 
9
13
  export async function handleMapTool(
10
14
  repo: SeptumRepository,
@@ -24,3 +28,99 @@ export async function handleMapTool(
24
28
  return handleGetDomainCatalog(repo, config, args, workspaceRoot);
25
29
  }
26
30
  }
31
+
32
+ export function buildDomainCatalog(
33
+ repo: SeptumRepository,
34
+ _config: ValidatedSeptumConfig,
35
+ args: GetDomainCatalogArgs,
36
+ workspaceRoot?: string,
37
+ runtimeVersion: RuntimeVersionMeta = getCachedRuntimeVersion()
38
+ ) {
39
+ const root = workspaceRoot ?? args.workspace_path ?? repo.getMeta("workspace_root") ?? process.cwd();
40
+ const navigation = buildNavigation(repo, args, root);
41
+ if (args.include_evidence && (!args.file_filter || !("files" in navigation) || navigation.files.length !== 1 || navigation.accounting.matching_files !== 1)) {
42
+ throw new Error("include_evidence requires file_filter matching exactly one indexed file.");
43
+ }
44
+ const evidence = args.include_evidence && "files" in navigation
45
+ ? repo.getImportRelationships(root, navigation.files[0]!.path) : [];
46
+ return {
47
+ workspace_root: root,
48
+ ...navigation,
49
+ ...(args.include_capabilities ? { parser_capabilities: { ...getParserCapabilities(args.detail_level === "full"), semantic_adapters: SemanticSliceExtractorRegistry.getCapabilities() } } : {}),
50
+ ...(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) } } : {}),
51
+ runtime_version: runtimeVersion,
52
+ ...(runtimeVersion.update_available ? { update_notice: `Update available: ${runtimeVersion.latest_version}; ${runtimeVersion.upgrade_command}. Reload after updating.` } : {}),
53
+ };
54
+ }
55
+
56
+ export function handleGetDomainCatalog(
57
+ repo: SeptumRepository,
58
+ config: ValidatedSeptumConfig,
59
+ args: GetDomainCatalogArgs,
60
+ workspaceRoot?: string
61
+ ) {
62
+ const payload = buildDomainCatalog(repo, config, args, workspaceRoot);
63
+ const format = args.format ?? "text";
64
+ const text = format === "json" ? JSON.stringify(payload) : formatMapAsText(payload);
65
+ return {
66
+ content: [{ type: "text" as const, text }],
67
+ structuredContent: payload,
68
+ metadata: { schema: payload.schema, status: payload.status, format },
69
+ runtime_version: payload.runtime_version,
70
+ };
71
+ }
72
+
73
+ export function buildUnindexedCatalog(root: string, runtimeVersion: RuntimeVersionMeta) {
74
+ return {
75
+ schema: NAVIGATION_SCHEMA,
76
+ status: "NOT_INDEXED",
77
+ total_domains: 0,
78
+ runtime_version: runtimeVersion,
79
+ message: `Workspace '${root}' belum diinisialisasi. Register a domain or run septum init.`,
80
+ suggested_action: { tool: "septum_map", params: { action: "register", name: "core", root: "src", ingest_now: true } },
81
+ next: [{ tool: "septum_map", args: { action: "register", name: "core", root: "src", ingest_now: true } }],
82
+ };
83
+ }
84
+
85
+ export async function handleRegisterDomain(
86
+ repo: SeptumRepository,
87
+ config: ValidatedSeptumConfig,
88
+ args: Partial<RegisterDomainArgs>,
89
+ workspaceRoot: string = process.cwd(),
90
+ signal?: AbortSignal
91
+ ) {
92
+ const result = await registerDomainPolicy(repo, config, args, workspaceRoot, signal);
93
+ config.domains[result.domain] = result.config;
94
+
95
+ return {
96
+ content: [
97
+ {
98
+ type: "text" as const,
99
+ text: JSON.stringify(
100
+ {
101
+ status: "success",
102
+ policy_owner: result.policyOwner,
103
+ message: `Domain '${result.domain}' successfully registered in ${
104
+ result.policyOwner === "database" ? "SQLite" : "septum.config.json"
105
+ }.${args.ingest_now ? " Initial ingestion completed." : ""}`,
106
+ domain_id: result.domainId,
107
+ domain: result.domain,
108
+ name: result.domain,
109
+ config: result.config,
110
+ ...(result.conflictPending
111
+ ? {
112
+ index_status: { sync_state: "error", code: "DOMAIN_ROOT_CONFLICT" },
113
+ next: [
114
+ "Resolve any remaining duplicate roots, then sync before using indexed facts. Registration success only records this policy change.",
115
+ ],
116
+ }
117
+ : {}),
118
+ ...(result.ingestionMetrics ? { ingestion_metrics: result.ingestionMetrics } : {}),
119
+ },
120
+ null,
121
+ 2
122
+ ),
123
+ },
124
+ ],
125
+ };
126
+ }
@@ -1,9 +1,13 @@
1
1
  import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
2
2
  import type { SeptumRepository } from "../../core/database/repository.ts";
3
- import type { SliceToolArgs } from "../schemas.ts";
4
- import { handleTraceVerticalSlice } from "./trace-vertical-slice.ts";
3
+ import { SeptumError } from "../../core/errors.ts";
4
+ import { VerticalSliceTracer } from "../../core/resolver/vertical-slice-tracer.ts";
5
+ import { formatSliceNode, SLICE_RELATIONSHIP_LIMITS } from "../../core/resolver/slice-format.ts";
6
+ import type { VerticalSliceTraceResponse } from "../../types/index.ts";
7
+ import { formatSliceAsText } from "../formatters/compact-text.ts";
8
+ import type { SliceToolArgs, TraceVerticalSliceArgs } from "../schemas.ts";
5
9
 
6
- export type { SliceToolArgs };
10
+ export type { SliceToolArgs, TraceVerticalSliceArgs };
7
11
 
8
12
  export function handleSliceTool(
9
13
  repo: SeptumRepository,
@@ -14,3 +18,97 @@ export function handleSliceTool(
14
18
  ) {
15
19
  return handleTraceVerticalSlice(repo, config, args, workspaceRoot, signal);
16
20
  }
21
+
22
+ export function handleTraceVerticalSlice(
23
+ repo: SeptumRepository,
24
+ config: ValidatedSeptumConfig,
25
+ args: Partial<TraceVerticalSliceArgs> & { route?: string },
26
+ workspaceRoot?: string,
27
+ signal?: AbortSignal
28
+ ) {
29
+ const query = (args.query || args.symbol || args.route || "").toString().trim();
30
+
31
+ if (!query) {
32
+ throw new SeptumError(
33
+ "INVALID_QUERY",
34
+ "Missing required argument: 'query' (e.g. 'POST /orders/{id}/status', 'OrderController@updateStatus', or task intent 'Ubah status order di dashboard')"
35
+ );
36
+ }
37
+
38
+ const root =
39
+ workspaceRoot ||
40
+ args.workspace_path ||
41
+ ((config.settings as Record<string, unknown>)?.workspace_root as string) ||
42
+ process.cwd();
43
+ const maxDepth = Math.min(Math.max(Math.trunc(Number(args.max_depth ?? 5)), 1), 8);
44
+ const tracer = new VerticalSliceTracer(repo, root, config.settings.ignore_patterns, false);
45
+
46
+ return tracer.traceAsync(query, maxDepth, signal, args.controller_file).then((result: VerticalSliceTraceResponse) => {
47
+ const chain = result.chain || result.slice || [];
48
+
49
+ let summary = "";
50
+ if (result.found && chain.length > 0) {
51
+ summary = chain.map(formatSliceNode).join("\n");
52
+ } else if (result.found && result.entrypoint) {
53
+ summary = `[ENTRYPOINT] ${result.entrypoint.method} ${result.entrypoint.uri}; catalog handler ${result.entrypoint.controller}@${result.entrypoint.action} [unknown; unknown]`;
54
+ } else if (result.diagnostics?.length) {
55
+ summary = ` [UNKNOWN] ${result.message || `No matching slice in the available static catalog for '${query}'.`}`.trim();
56
+ } else {
57
+ summary = `[NOT FOUND] No matching slice in the available static catalog for '${query}'; this does not prove the route is absent at runtime.`;
58
+ }
59
+ if (result.diagnostics?.includes("ambiguous_target")) {
60
+ summary = `[AMBIGUOUS] ${result.message}`;
61
+ } else if (result.diagnostics?.length && result.found) {
62
+ summary = `[UNKNOWN: ${result.diagnostics.join(", ")}]\n${summary}`;
63
+ }
64
+
65
+ const nextHints = result.next ?? [
66
+ result.found && result.entrypoint?.action && result.entrypoint?.file
67
+ ? `Use septum_symbol(action='context', query='${result.entrypoint.action}', file_path='${result.entrypoint.file}') to inspect handler source/contracts; read the selected mode, freshness and omissions.`
68
+ : result.found
69
+ ? "Inspect the selected implementation and unresolved relationships before planning edits."
70
+ : "Refine the query or synchronize the workspace; no match does not prove runtime absence.",
71
+ ];
72
+
73
+ const payload = {
74
+ workspace_root: root,
75
+ status: result.diagnostics?.includes("ambiguous_target") ? "ambiguous" : result.diagnostics?.length ? "unknown" : result.found ? "success" : "not_found",
76
+ coverage: result.coverage,
77
+ diagnostics: result.diagnostics,
78
+ next: nextHints,
79
+ controller_file_filter: args.controller_file ?? null,
80
+ query,
81
+ found: result.found,
82
+ confidence: result.confidence,
83
+ confidence_scope: "query_to_catalog_target_only",
84
+ relationship_limits: SLICE_RELATIONSHIP_LIMITS,
85
+ execution_order: "not_established",
86
+ branch_scope: "Static relationships can span mutually exclusive handler actions; this is not one executed branch.",
87
+ is_exact_match: result.is_exact_match,
88
+ architecture_style: result.architecture_style,
89
+ max_depth_applied: result.max_depth_applied ?? maxDepth,
90
+ entrypoint: result.entrypoint || null,
91
+ chain,
92
+ alternatives: result.alternatives || [],
93
+ candidate_count: result.candidate_count,
94
+ alternatives_omitted: result.alternatives_omitted,
95
+ summary,
96
+ message: result.message || summary,
97
+ };
98
+
99
+ const format = args.format ?? "text";
100
+ const text = format === "json" ? JSON.stringify(payload) : formatSliceAsText(payload);
101
+ return {
102
+ content: [{ type: "text" as const, text }],
103
+ structuredContent: payload,
104
+ metadata: {
105
+ status: payload.status,
106
+ found: payload.found,
107
+ confidence: payload.confidence,
108
+ query: payload.query,
109
+ chain_length: payload.chain.length,
110
+ format,
111
+ },
112
+ };
113
+ });
114
+ }