@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,746 +1,5 @@
1
- import { z } from "zod";
2
-
3
- function withAliases(raw: unknown, aliases: Record<string, string>): unknown {
4
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return raw;
5
- const obj = { ...(raw as Record<string, unknown>) };
6
- for (const [alias, target] of Object.entries(aliases)) {
7
- if (obj[alias] !== undefined && obj[target] === undefined) {
8
- obj[target] = obj[alias];
9
- }
10
- }
11
- return obj;
12
- }
13
-
14
- export function extractSingleStringFallback(
15
- raw: unknown,
16
- targetField: string,
17
- ignoredKeys: string[] = ["workspace_path", "workspacePath", "workspace", "project_root", "projectRoot"]
18
- ): unknown {
19
- if (typeof raw === "string") {
20
- return { [targetField]: raw };
21
- }
22
- if (Array.isArray(raw) && raw.length === 1 && typeof raw[0] === "string") {
23
- return { [targetField]: raw[0] };
24
- }
25
- if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
26
- const obj = { ...(raw as Record<string, unknown>) };
27
- if (obj[targetField] !== undefined && typeof obj[targetField] === "string" && (obj[targetField] as string).trim() !== "") {
28
- return obj;
29
- }
30
- const nonIgnoredEntries = Object.entries(obj).filter(
31
- ([key, val]) => !ignoredKeys.includes(key) && typeof val === "string" && (val as string).trim() !== ""
32
- );
33
- if (nonIgnoredEntries.length === 1) {
34
- obj[targetField] = nonIgnoredEntries[0][1];
35
- }
36
- return obj;
37
- }
38
- return raw;
39
- }
40
-
41
- export function normalizeBoundaryArgs(raw: unknown): unknown {
42
- if (Array.isArray(raw) && raw.length > 1 && raw.every((item) => typeof item === "string")) {
43
- raw = { file_paths: raw };
44
- }
45
- const coerced = extractSingleStringFallback(raw, "file_path", [
46
- "action",
47
- "plan_ref",
48
- "workspace_path",
49
- "workspacePath",
50
- "workspace",
51
- "project_root",
52
- "projectRoot",
53
- "scope",
54
- "domain",
55
- "domain_name",
56
- "domainName",
57
- "feature_key",
58
- "featureKey",
59
- "feature",
60
- "feature_name",
61
- "featureName",
62
- "name",
63
- "key",
64
- ]);
65
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
66
- const obj = { ...(coerced as Record<string, unknown>) };
67
- const aliases: Record<string, string> = {
68
- filePath: "file_path",
69
- file: "file_path",
70
- path: "file_path",
71
- from_file: "file_path",
72
- fromFile: "file_path",
73
- source_file: "file_path",
74
- sourceFile: "file_path",
75
- filePaths: "file_paths",
76
- files: "file_paths",
77
- paths: "file_paths",
78
- proposedImports: "proposed_imports",
79
- imports: "proposed_imports",
80
- featureKey: "feature_key",
81
- feature: "feature_key",
82
- feature_name: "feature_key",
83
- featureName: "feature_key",
84
- name: "feature_key",
85
- key: "feature_key",
86
- domain_name: "domain",
87
- domainName: "domain",
88
- workspace: "workspace_path",
89
- workspacePath: "workspace_path",
90
- project_root: "workspace_path",
91
- projectRoot: "workspace_path",
92
- };
93
- obj.proposed_imports_supplied ??= ["proposed_imports", "proposedImports", "imports", "to_file", "toFile"].some(key => Object.prototype.hasOwnProperty.call(obj, key));
94
- for (const [alias, target] of Object.entries(aliases)) {
95
- if (obj[alias] !== undefined && obj[target] === undefined) {
96
- obj[target] = obj[alias];
97
- }
98
- }
99
-
100
- if (obj.feature_key !== undefined && obj.feature === undefined) {
101
- obj.feature = obj.feature_key;
102
- } else if (obj.feature !== undefined && obj.feature_key === undefined) {
103
- obj.feature_key = obj.feature;
104
- }
105
-
106
- if (obj.to_file || obj.toFile) {
107
- const rawTo = obj.to_file ?? obj.toFile;
108
- const toFiles = Array.isArray(rawTo) ? rawTo.map(String) : [String(rawTo)];
109
- if (!obj.proposed_imports) {
110
- obj.proposed_imports = toFiles;
111
- } else if (Array.isArray(obj.proposed_imports)) {
112
- obj.proposed_imports = [...obj.proposed_imports, ...toFiles];
113
- }
114
- }
115
- if (Array.isArray(obj.file_path) && !obj.file_paths) {
116
- obj.file_paths = obj.file_path;
117
- delete obj.file_path;
118
- }
119
- if (typeof obj.file_paths === "string" && !obj.file_path) {
120
- obj.file_path = obj.file_paths;
121
- delete obj.file_paths;
122
- }
123
- if (obj.scope === undefined) {
124
- if (obj.staged === true) {
125
- obj.scope = "staged";
126
- } else if (obj.domain !== undefined && obj.file_path === undefined && obj.file_paths === undefined) {
127
- obj.scope = "domain";
128
- }
129
- }
130
- return obj;
131
- }
132
-
133
- export function normalizeDomainCatalogArgs(raw: unknown): unknown {
134
- const coerced = extractSingleStringFallback(raw, "domain", [
135
- "workspace_path",
136
- "workspacePath",
137
- "workspace",
138
- "project_root",
139
- "projectRoot",
140
- "target_path",
141
- "path",
142
- "archetype_filter",
143
- "archetype",
144
- "archetypeFilter",
145
- "type",
146
- "detail_level",
147
- "detailLevel",
148
- "mode",
149
- "format",
150
- "file_filter",
151
- "fileFilter",
152
- "file",
153
- "filter",
154
- ]);
155
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
156
- const obj = withAliases(coerced, {
157
- domain_name: "domain",
158
- domainName: "domain",
159
- name: "domain",
160
- archetype: "archetype_filter",
161
- archetypeFilter: "archetype_filter",
162
- type: "archetype_filter",
163
- detailLevel: "detail_level",
164
- mode: "detail_level",
165
- format: "detail_level",
166
- fileFilter: "file_filter",
167
- file: "file_filter",
168
- filter: "file_filter",
169
- workspace: "workspace_path",
170
- workspacePath: "workspace_path",
171
- project_root: "workspace_path",
172
- projectRoot: "workspace_path",
173
- target_path: "workspace_path",
174
- path: "workspace_path",
175
- }) as Record<string, unknown>;
176
- if (obj.domain !== undefined && obj.name === undefined) {
177
- obj.name = obj.domain;
178
- } else if (obj.name !== undefined && obj.domain === undefined) {
179
- obj.domain = obj.name;
180
- }
181
- if (obj.archetype_filter !== undefined && obj.archetype === undefined) {
182
- obj.archetype = obj.archetype_filter;
183
- } else if (obj.archetype !== undefined && obj.archetype_filter === undefined) {
184
- obj.archetype_filter = obj.archetype;
185
- }
186
- if (obj.full === true && obj.detail_level === undefined) {
187
- obj.detail_level = "full";
188
- }
189
- return obj;
190
- }
191
-
192
- export const GetDomainCatalogSchema = z.preprocess(
193
- normalizeDomainCatalogArgs,
194
- z.object({
195
- domain: z.string().optional(),
196
- name: z.string().optional(),
197
- archetype_filter: z.string().optional(),
198
- archetype: z.string().optional(),
199
- detail_level: z.enum(["compact", "full"]).optional().default("compact"),
200
- file_filter: z.string().optional(),
201
- file_offset: z.number().int().nonnegative().optional(),
202
- file_limit: z.number().int().min(1).max(100).optional(),
203
- include_evidence: z.boolean().optional(),
204
- include_capabilities: z.boolean().optional(),
205
- workspace_path: z.string().optional(),
206
- })
207
- );
208
- export type GetDomainCatalogArgs = z.infer<typeof GetDomainCatalogSchema>;
209
-
210
- export function normalizeLocateSymbolArgs(raw: unknown): unknown {
211
- const coerced = extractSingleStringFallback(raw, "query", [
212
- "workspace_path",
213
- "workspacePath",
214
- "workspace",
215
- "project_root",
216
- "projectRoot",
217
- "target_path",
218
- "path",
219
- "domain",
220
- "domain_name",
221
- "domainName",
222
- "file_path",
223
- "filePath",
224
- ]);
225
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
226
- const obj = withAliases(coerced, {
227
- symbol: "query",
228
- name: "query",
229
- symbol_name: "query",
230
- symbolName: "query",
231
- target: "query",
232
- domain_name: "domain",
233
- domainName: "domain",
234
- max: "limit",
235
- workspace: "workspace_path",
236
- workspacePath: "workspace_path",
237
- project_root: "workspace_path",
238
- projectRoot: "workspace_path",
239
- target_path: "workspace_path",
240
- path: "workspace_path",
241
- }) as Record<string, unknown>;
242
- if (obj.query !== undefined && obj.symbol === undefined) {
243
- obj.symbol = obj.query;
244
- } else if (obj.symbol !== undefined && obj.query === undefined) {
245
- obj.query = obj.symbol;
246
- }
247
- if (!obj.query && !obj.symbol && typeof obj.symbol_ref === "object" && obj.symbol_ref !== null) {
248
- obj.query = (obj.symbol_ref as Record<string, unknown>).name;
249
- obj.symbol = obj.query;
250
- }
251
- return obj;
252
- }
253
-
254
- export const SymbolReferenceSchema = z.object({
255
- file_path: z.string().min(1), language: z.string().min(1), name: z.string().min(1), kind: z.string().min(1),
256
- signature: z.string(), start_line: z.number().int().positive(), end_line: z.number().int().positive(),
257
- indexed_content_hash: z.string().min(1), container: z.string().optional(), receiver: z.string().optional(),
258
- }).refine(ref => ref.end_line >= ref.start_line, { message: "end_line must be at or after start_line" });
259
-
260
- export const LocateSymbolSchema = z.preprocess(
261
- normalizeLocateSymbolArgs,
262
- z.object({
263
- query: z.string().min(1, "query is required"),
264
- symbol: z.string().optional(),
265
- domain: z.string().optional(),
266
- symbol_ref: SymbolReferenceSchema.optional(),
267
- file_path: z.string().min(1).optional(),
268
- limit: z.number().int().min(1).max(50).optional().default(10),
269
- workspace_path: z.string().optional(),
270
- })
271
- );
272
- export type LocateSymbolArgs = z.infer<typeof LocateSymbolSchema>;
273
-
274
- export function normalizeGetSymbolArgs(raw: unknown): unknown {
275
- const coerced = extractSingleStringFallback(raw, "symbol", [
276
- "workspace_path",
277
- "workspacePath",
278
- "workspace",
279
- "project_root",
280
- "projectRoot",
281
- "domain",
282
- "domain_name",
283
- "domainName",
284
- "file_path",
285
- "filePath",
286
- ]);
287
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
288
- const obj = withAliases(coerced, {
289
- query: "symbol",
290
- name: "symbol",
291
- symbol_name: "symbol",
292
- symbolName: "symbol",
293
- target: "symbol",
294
- domain_name: "domain",
295
- domainName: "domain",
296
- includeDependencies: "include_dependencies",
297
- include_deps: "include_dependencies",
298
- includeDeps: "include_dependencies",
299
- dependencies: "include_dependencies",
300
- deps: "include_dependencies",
301
- workspace: "workspace_path",
302
- workspacePath: "workspace_path",
303
- project_root: "workspace_path",
304
- projectRoot: "workspace_path",
305
- }) as Record<string, unknown>;
306
- if (obj.symbol !== undefined && obj.query === undefined) {
307
- obj.query = obj.symbol;
308
- } else if (obj.query !== undefined && obj.symbol === undefined) {
309
- obj.symbol = obj.query;
310
- }
311
- if (!obj.query && !obj.symbol && typeof obj.symbol_ref === "object" && obj.symbol_ref !== null) {
312
- obj.query = (obj.symbol_ref as Record<string, unknown>).name;
313
- obj.symbol = obj.query;
314
- }
315
- return obj;
316
- }
317
-
318
- export const GetSymbolSchema = z.preprocess(
319
- normalizeGetSymbolArgs,
320
- z.object({
321
- symbol: z.string().min(1, "symbol is required"),
322
- query: z.string().optional(),
323
- domain: z.string().optional(),
324
- symbol_ref: SymbolReferenceSchema.optional(),
325
- include_dependencies: z.boolean().optional().default(true),
326
- workspace_path: z.string().optional(),
327
- file_path: z.string().min(1).optional(),
328
- include_source: z.boolean().optional().default(false),
329
- source_start_line: z.number().int().positive().optional(),
330
- source_line_limit: z.number().int().positive().max(200).optional().default(120),
331
- })
332
- );
333
- export type GetSymbolArgs = z.infer<typeof GetSymbolSchema>;
334
-
335
- export function normalizeGetSymbolImpactArgs(raw: unknown): unknown {
336
- const coerced = extractSingleStringFallback(raw, "symbol");
337
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
338
- const obj = withAliases(coerced, {
339
- query: "symbol",
340
- name: "symbol",
341
- symbol_name: "symbol",
342
- symbolName: "symbol",
343
- file_path: "symbol",
344
- filePath: "symbol",
345
- file: "symbol",
346
- path: "symbol",
347
- target: "symbol",
348
- workspace: "workspace_path",
349
- workspacePath: "workspace_path",
350
- project_root: "workspace_path",
351
- projectRoot: "workspace_path",
352
- }) as Record<string, unknown>;
353
- if (obj.symbol !== undefined && obj.query === undefined) {
354
- obj.query = obj.symbol;
355
- } else if (obj.query !== undefined && obj.symbol === undefined) {
356
- obj.symbol = obj.query;
357
- }
358
- return obj;
359
- }
360
-
361
- export const GetSymbolImpactSchema = z.preprocess(
362
- normalizeGetSymbolImpactArgs,
363
- z.object({
364
- symbol: z.string().min(1, "symbol is required"),
365
- query: z.string().optional(),
366
- domain: z.string().optional(),
367
- workspace_path: z.string().optional(),
368
- })
369
- );
370
- export type GetSymbolImpactArgs = z.infer<typeof GetSymbolImpactSchema>;
371
-
372
- export function normalizeTraceVerticalSliceArgs(raw: unknown): unknown {
373
- const coerced = extractSingleStringFallback(raw, "query", [
374
- "workspace_path", "workspacePath", "workspace", "project_root", "projectRoot", "controller_file",
375
- ]);
376
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
377
- const obj = withAliases(coerced, {
378
- route: "query",
379
- uri: "query",
380
- route_uri: "query",
381
- routeUri: "query",
382
- entry_file: "query",
383
- entryFile: "query",
384
- file_path: "query",
385
- filePath: "query",
386
- file: "query",
387
- path: "query",
388
- symbol: "query",
389
- name: "query",
390
- feature: "query",
391
- feature_key: "query",
392
- featureKey: "query",
393
- maxDepth: "max_depth",
394
- depth: "max_depth",
395
- workspace: "workspace_path",
396
- workspacePath: "workspace_path",
397
- project_root: "workspace_path",
398
- projectRoot: "workspace_path",
399
- }) as Record<string, unknown>;
400
- if (obj.query !== undefined && obj.symbol === undefined) {
401
- obj.symbol = obj.query;
402
- } else if (obj.symbol !== undefined && obj.query === undefined) {
403
- obj.query = obj.symbol;
404
- }
405
- if (obj.max_depth !== undefined && obj.max_depth !== null && !Number.isNaN(Number(obj.max_depth))) {
406
- obj.max_depth = Math.min(Math.max(Math.trunc(Number(obj.max_depth)), 1), 8);
407
- }
408
- return obj;
409
- }
410
-
411
- export const TraceVerticalSliceSchema = z.preprocess(
412
- normalizeTraceVerticalSliceArgs,
413
- z.object({
414
- query: z.string().min(1, "query is required"),
415
- symbol: z.string().optional(),
416
- controller_file: z.string().min(1).optional(),
417
- max_depth: z.number().int().min(1).max(8).optional().default(5),
418
- workspace_path: z.string().optional(),
419
- })
420
- );
421
- export type TraceVerticalSliceArgs = z.infer<typeof TraceVerticalSliceSchema>;
422
-
423
- export const CheckBoundarySchema = z.preprocess(
424
- normalizeBoundaryArgs,
425
- z.object({
426
- file_path: z.string().trim().min(1, "file_path cannot be blank").optional(),
427
- file_paths: z.array(z.string().trim().min(1, "file_paths cannot contain blank paths")).optional(),
428
- proposed_imports: z.array(z.string()).optional().default([]),
429
- proposed_imports_supplied: z.boolean().optional().default(false),
430
- scope: z.enum(["file", "all", "staged", "domain"]).optional(),
431
- domain: z.string().trim().min(1, "domain cannot be blank").optional(),
432
- staged: z.boolean().optional(),
433
- workspace_path: z.string().optional(),
434
- }).superRefine((args, ctx) => {
435
- const hasBatch = Boolean(args.file_paths?.length);
436
- const hasTarget = args.file_path !== undefined || hasBatch;
437
- const scope = args.scope ?? (args.staged ? "staged" : hasTarget ? "file" : args.domain ? "domain" : "all");
438
- if (args.file_path !== undefined && hasBatch) {
439
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["file_paths"], message: "Use either file_path or file_paths, not both." });
440
- }
441
- if (args.staged && scope !== "staged") {
442
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["staged"], message: "staged=true requires scope='staged'." });
443
- }
444
- if (scope === "file" && !hasTarget) {
445
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["file_path"], message: "scope='file' requires file_path or non-empty file_paths." });
446
- }
447
- if (scope !== "file" && hasTarget) {
448
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["scope"], message: `scope='${scope}' does not accept file targets. Use scope='file' for proposed-import checks.` });
449
- }
450
- if (scope === "domain" && !args.domain) {
451
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["domain"], message: "scope='domain' requires a registered domain name." });
452
- }
453
- if (scope === "all" && args.domain) {
454
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["domain"], message: "scope='all' checks the entire repository. Use scope='domain' to filter a domain." });
455
- }
456
- if (scope !== "file" && args.proposed_imports.length) {
457
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["proposed_imports"], message: "proposed_imports requires a file target and scope='file'." });
458
- }
459
- })
460
- );
461
- export type CheckBoundaryArgs = z.infer<typeof CheckBoundarySchema>;
462
-
463
- export function normalizeRegisterDomainArgs(raw: unknown): unknown {
464
- const coerced = extractSingleStringFallback(raw, "domain", [
465
- "root",
466
- "root_path",
467
- "rootPath",
468
- "path",
469
- "root_dir",
470
- "workspace_path",
471
- "workspacePath",
472
- "workspace",
473
- "project_root",
474
- "projectRoot",
475
- ]);
476
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
477
- const obj = withAliases(coerced, {
478
- name: "domain",
479
- domain_name: "domain",
480
- domainName: "domain",
481
- root_path: "root",
482
- rootPath: "root",
483
- path: "root",
484
- allowedDependencies: "allowed_dependencies",
485
- allowed: "allowed_dependencies",
486
- forbiddenDependencies: "forbidden_dependencies",
487
- forbidden: "forbidden_dependencies",
488
- archetype: "archetypes",
489
- ingestNow: "ingest_now",
490
- workspace: "workspace_path",
491
- workspacePath: "workspace_path",
492
- project_root: "workspace_path",
493
- projectRoot: "workspace_path",
494
- }) as Record<string, unknown>;
495
- if (obj.domain !== undefined && obj.name === undefined) {
496
- obj.name = obj.domain;
497
- } else if (obj.name !== undefined && obj.domain === undefined) {
498
- obj.domain = obj.name;
499
- }
500
- return obj;
501
- }
502
-
503
- export const RegisterDomainSchema = z.preprocess(
504
- normalizeRegisterDomainArgs,
505
- z.object({
506
- domain: z.string().min(1, "Domain name/identifier is required"),
507
- name: z.string().optional(),
508
- root: z.string().min(1, "Domain root path is required"),
509
- description: z.string().optional(),
510
- allowed_dependencies: z.array(z.string()).optional(),
511
- forbidden_dependencies: z.array(z.string()).optional(),
512
- archetypes: z.record(z.string()).optional(),
513
- ingest_now: z.boolean().optional().default(false),
514
- workspace_path: z.string().optional(),
515
- })
516
- );
517
- export type RegisterDomainArgs = z.infer<typeof RegisterDomainSchema>;
518
-
519
- // =========================================================================
520
- // 4 UNIFIED TOOLS SCHEMAS & NORMALIZERS
521
- // =========================================================================
522
-
523
- // 1. septum_map
524
- export function normalizeMapToolArgs(raw: unknown): unknown {
525
- const coerced = extractSingleStringFallback(raw, "domain", [
526
- "workspace_path",
527
- "workspacePath",
528
- "workspace",
529
- "project_root",
530
- "projectRoot",
531
- "target_path",
532
- "path",
533
- "action",
534
- "detail_level",
535
- "detailLevel",
536
- "mode",
537
- "format",
538
- "archetype_filter",
539
- "archetype",
540
- "file_filter",
541
- "fileFilter",
542
- "root",
543
- "root_path",
544
- "rootPath",
545
- ]);
546
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
547
- const obj = withAliases(coerced, {
548
- domain_name: "domain",
549
- domainName: "domain",
550
- name: "domain",
551
- archetype: "archetype_filter",
552
- archetypeFilter: "archetype_filter",
553
- type: "archetype_filter",
554
- detailLevel: "detail_level",
555
- mode: "detail_level",
556
- format: "detail_level",
557
- fileFilter: "file_filter",
558
- file: "file_filter",
559
- filter: "file_filter",
560
- root_path: "root",
561
- rootPath: "root",
562
- path: "root",
563
- allowedDependencies: "allowed_dependencies",
564
- allowed: "allowed_dependencies",
565
- forbiddenDependencies: "forbidden_dependencies",
566
- forbidden: "forbidden_dependencies",
567
- archetypes: "archetypes",
568
- ingestNow: "ingest_now",
569
- workspace: "workspace_path",
570
- workspacePath: "workspace_path",
571
- project_root: "workspace_path",
572
- projectRoot: "workspace_path",
573
- }) as Record<string, unknown>;
574
-
575
- if (obj.domain !== undefined && obj.name === undefined) {
576
- obj.name = obj.domain;
577
- } else if (obj.name !== undefined && obj.domain === undefined) {
578
- obj.domain = obj.name;
579
- }
580
-
581
- if (obj.archetype_filter !== undefined && obj.archetype === undefined) {
582
- obj.archetype = obj.archetype_filter;
583
- } else if (obj.archetype !== undefined && obj.archetype_filter === undefined) {
584
- obj.archetype_filter = obj.archetype;
585
- }
586
-
587
- if (obj.full === true && obj.detail_level === undefined) {
588
- obj.detail_level = "full";
589
- }
590
-
591
- if (!obj.action) {
592
- if (obj.root !== undefined || obj.ingest_now !== undefined) {
593
- obj.action = "register";
594
- } else {
595
- obj.action = "catalog";
596
- }
597
- }
598
-
599
- return obj;
600
- }
601
-
602
- export const MapToolSchema = z.preprocess(
603
- normalizeMapToolArgs,
604
- z.object({
605
- action: z.enum(["catalog", "register"]).optional().default("catalog"),
606
- domain: z.string().optional(),
607
- name: z.string().optional(),
608
- detail_level: z.enum(["compact", "full"]).optional().default("compact"),
609
- archetype_filter: z.string().optional(),
610
- archetype: z.string().optional(),
611
- file_filter: z.string().optional(),
612
- file_offset: z.number().int().nonnegative().optional(),
613
- file_limit: z.number().int().min(1).max(100).optional(),
614
- include_evidence: z.boolean().optional(),
615
- include_capabilities: z.boolean().optional(),
616
- root: z.string().optional(),
617
- description: z.string().optional(),
618
- allowed_dependencies: z.array(z.string()).optional(),
619
- forbidden_dependencies: z.array(z.string()).optional(),
620
- archetypes: z.record(z.string()).optional(),
621
- ingest_now: z.boolean().optional().default(false),
622
- workspace_path: z.string().optional(),
623
- })
624
- );
625
- export type MapToolArgs = z.infer<typeof MapToolSchema>;
626
-
627
- // 2. septum_symbol
628
- export function normalizeSymbolToolArgs(raw: unknown): unknown {
629
- const coerced = extractSingleStringFallback(raw, "query", [
630
- "workspace_path",
631
- "workspacePath",
632
- "workspace",
633
- "project_root",
634
- "projectRoot",
635
- "action",
636
- "domain",
637
- "domain_name",
638
- "domainName",
639
- "file_path",
640
- "filePath",
641
- "limit",
642
- ]);
643
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
644
- const obj = withAliases(coerced, {
645
- symbol: "query",
646
- name: "query",
647
- symbol_name: "query",
648
- symbolName: "query",
649
- target: "query",
650
- domain_name: "domain",
651
- domainName: "domain",
652
- includeDependencies: "include_dependencies",
653
- include_deps: "include_dependencies",
654
- includeDeps: "include_dependencies",
655
- dependencies: "include_dependencies",
656
- deps: "include_dependencies",
657
- max: "limit",
658
- workspace: "workspace_path",
659
- workspacePath: "workspace_path",
660
- project_root: "workspace_path",
661
- projectRoot: "workspace_path",
662
- filePath: "file_path",
663
- sourceStartLine: "source_start_line",
664
- sourceLineLimit: "source_line_limit",
665
- semanticDepth: "semantic_depth",
666
- }) as Record<string, unknown>;
667
-
668
- if (obj.query !== undefined && obj.symbol === undefined) {
669
- obj.symbol = obj.query;
670
- } else if (obj.symbol !== undefined && obj.query === undefined) {
671
- obj.query = obj.symbol;
672
- }
673
-
674
- if (!obj.action) {
675
- if (obj.budget_bytes !== undefined || obj.continuation !== undefined || obj.context_mode !== undefined) {
676
- obj.action = "context";
677
- } else if (obj.include_dependencies !== undefined || obj.include_source !== undefined ||
678
- obj.source_start_line !== undefined || obj.source_line_limit !== undefined) {
679
- obj.action = "context";
680
- } else {
681
- obj.action = "locate";
682
- }
683
- }
684
-
685
- if (!obj.query && !obj.symbol && typeof obj.symbol_ref === "object" && obj.symbol_ref !== null) {
686
- obj.query = (obj.symbol_ref as Record<string, unknown>).name;
687
- obj.symbol = obj.query;
688
- }
689
- if (obj.action === "inspect") obj.action = "context";
690
- return obj;
691
- }
692
-
693
- export const SymbolToolSchema = z.preprocess(
694
- normalizeSymbolToolArgs,
695
- z.object({
696
- action: z.enum(["locate", "inspect", "impact", "context"]).optional().default("locate"),
697
- query: z.string().optional(),
698
- symbol: z.string().optional(),
699
- domain: z.string().optional(),
700
- symbol_ref: SymbolReferenceSchema.optional(),
701
- include_dependencies: z.boolean().optional().default(true),
702
- limit: z.number().int().positive().optional(),
703
- workspace_path: z.string().optional(),
704
- file_path: z.string().min(1).optional(),
705
- include_source: z.boolean().optional(),
706
- source_start_line: z.number().int().positive().optional(),
707
- source_line_limit: z.number().int().positive().max(200).optional(),
708
- semantic_depth: z.number().int().min(1).max(2).optional(),
709
- context_mode: z.enum(["deep", "source"]).optional(),
710
- budget_bytes: z.number().int().min(2048).max(2 * 1024 * 1024).optional(),
711
- continuation: z.string().min(1).max(4096).optional(),
712
- }).superRefine((args, ctx) => {
713
- if (args.symbol_ref && args.action !== "locate" && args.action !== "inspect" && args.action !== "impact" && args.action !== "context") {
714
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["symbol_ref"], message: "symbol_ref is supported only for locate, inspect, impact, and context." });
715
- }
716
- if (args.action !== "context" && (args.budget_bytes !== undefined || args.continuation !== undefined)) {
717
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["action"], message: "budget_bytes and continuation are supported only for context." });
718
- }
719
- if (args.context_mode !== undefined && args.action !== "context") {
720
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["context_mode"], message: "context_mode requires action='context' or its inspect alias." });
721
- }
722
- if (args.context_mode === "deep" && (args.include_source !== undefined || args.source_start_line !== undefined || args.source_line_limit !== undefined)) {
723
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["context_mode"], message: "Deep context does not accept bounded source options." });
724
- }
725
- })
726
- );
727
- export type SymbolToolArgs = z.infer<typeof SymbolToolSchema>;
728
-
729
- // 3. septum_slice
730
- export const SliceToolSchema = TraceVerticalSliceSchema;
731
- export type SliceToolArgs = TraceVerticalSliceArgs;
732
-
733
- // 4. septum_boundary
734
- export const BoundaryToolSchema = CheckBoundarySchema;
735
- export type BoundaryToolArgs = CheckBoundaryArgs;
736
-
737
- export function parseToolRequest(name: string, args: unknown) {
738
- switch (name) {
739
- case "septum_map": return { name, args: MapToolSchema.parse(args ?? {}) } as const;
740
- case "septum_symbol": return { name, args: SymbolToolSchema.parse(args ?? {}) } as const;
741
- case "septum_slice": return { name, args: SliceToolSchema.parse(args ?? {}) } as const;
742
- case "septum_boundary": return { name, args: BoundaryToolSchema.parse(args ?? {}) } as const;
743
- default: throw new Error(`Unknown tool: '${name}'`);
744
- }
745
- }
746
-
1
+ export { extractSingleStringFallback, SymbolReferenceSchema } from "./schemas/shared.ts";
2
+ export * from "./schemas/boundary.ts";
3
+ export * from "./schemas/map.ts";
4
+ export * from "./schemas/symbol.ts";
5
+ export * from "./schemas/slice.ts";