@dimassetoid/septum-mcp 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +46 -45
  2. package/package.json +8 -6
  3. package/src/cli/commands/check.ts +41 -26
  4. package/src/cli/commands/hook.ts +77 -105
  5. package/src/cli/commands/init.ts +35 -9
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +35 -9
  9. package/src/cli/hook-payload.ts +43 -0
  10. package/src/cli/index.ts +15 -51
  11. package/src/cli/scaffold/harness-config.ts +48 -8
  12. package/src/cli/templates/hooks.ts +51 -27
  13. package/src/cli/templates/rules.ts +34 -49
  14. package/src/cli/templates/skill.ts +46 -35
  15. package/src/core/boundary/audit.ts +383 -0
  16. package/src/core/boundary/evaluator.ts +299 -178
  17. package/src/core/boundary/staged-auditor.ts +188 -34
  18. package/src/core/config/domain-ownership.ts +47 -0
  19. package/src/core/config/domain-registration.ts +141 -0
  20. package/src/core/config/loader.ts +82 -54
  21. package/src/core/config/schema.ts +24 -46
  22. package/src/core/database/client.ts +2 -0
  23. package/src/core/database/repositories/dependency.repository.ts +326 -543
  24. package/src/core/database/repositories/domain.repository.ts +48 -4
  25. package/src/core/database/repositories/file.repository.ts +10 -0
  26. package/src/core/database/repositories/symbol.repository.ts +97 -259
  27. package/src/core/database/repository.ts +138 -24
  28. package/src/core/database/schema.ts +28 -33
  29. package/src/core/discovery/declarative-routes.ts +69 -0
  30. package/src/core/discovery/framework-detector.ts +149 -0
  31. package/src/core/discovery/navigation.ts +269 -0
  32. package/src/core/discovery/topology-detector.ts +153 -170
  33. package/src/core/errors.ts +19 -0
  34. package/src/core/ingestion/pipeline.ts +378 -212
  35. package/src/core/parser/behavioral-analyzer.ts +26 -22
  36. package/src/core/parser/boundary-tracker.ts +15 -0
  37. package/src/core/parser/extractors/base.ts +16 -4
  38. package/src/core/parser/extractors/csharp.ts +9 -5
  39. package/src/core/parser/extractors/django-routing.ts +163 -0
  40. package/src/core/parser/extractors/django-semantic.ts +400 -516
  41. package/src/core/parser/extractors/elysia-semantic.ts +172 -496
  42. package/src/core/parser/extractors/express-semantic.ts +195 -398
  43. package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
  44. package/src/core/parser/extractors/fastify-semantic.ts +216 -732
  45. package/src/core/parser/extractors/flask-semantic.ts +92 -388
  46. package/src/core/parser/extractors/go-routing.ts +344 -0
  47. package/src/core/parser/extractors/go-semantic.ts +210 -508
  48. package/src/core/parser/extractors/go.ts +6 -3
  49. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  50. package/src/core/parser/extractors/hono-semantic.ts +132 -530
  51. package/src/core/parser/extractors/java.ts +7 -5
  52. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  53. package/src/core/parser/extractors/laravel-semantic.ts +169 -333
  54. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  55. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  56. package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
  57. package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
  58. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  59. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  60. package/src/core/parser/extractors/php.ts +17 -1
  61. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  62. package/src/core/parser/extractors/python.ts +9 -8
  63. package/src/core/parser/extractors/registry.ts +28 -5
  64. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  65. package/src/core/parser/extractors/ruby.ts +10 -7
  66. package/src/core/parser/extractors/rust.ts +35 -17
  67. package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
  68. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  69. package/src/core/parser/extractors/symfony-semantic.ts +75 -262
  70. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  71. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  72. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  73. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  74. package/src/core/parser/extractors/typescript.ts +36 -216
  75. package/src/core/parser/implementation-fingerprint.ts +97 -0
  76. package/src/core/parser/language-capabilities.ts +23 -7
  77. package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
  78. package/src/core/parser/schema/schema-provider-registry.ts +1 -3
  79. package/src/core/parser/schema/schema-provider.interface.ts +2 -1
  80. package/src/core/parser/semantic-revision.ts +3 -0
  81. package/src/core/parser/static-string.ts +51 -0
  82. package/src/core/parser/wasm-loader.ts +6 -2
  83. package/src/core/resolver/ast-method-tracer.ts +230 -0
  84. package/src/core/resolver/call-graph-helpers.ts +72 -0
  85. package/src/core/resolver/call-graph-tracer.ts +375 -311
  86. package/src/core/resolver/dependency-analysis.ts +593 -0
  87. package/src/core/resolver/import-candidates.ts +120 -0
  88. package/src/core/resolver/import-evidence.ts +88 -0
  89. package/src/core/resolver/import-resolver.ts +162 -181
  90. package/src/core/resolver/interpretation-inputs.ts +65 -0
  91. package/src/core/resolver/languages/go.ts +103 -0
  92. package/src/core/resolver/languages/managed.ts +200 -0
  93. package/src/core/resolver/languages/python.ts +133 -0
  94. package/src/core/resolver/languages/ruby.ts +40 -0
  95. package/src/core/resolver/languages/rust.ts +127 -0
  96. package/src/core/resolver/languages/shared.ts +74 -0
  97. package/src/core/resolver/module-resolver.ts +18 -7
  98. package/src/core/resolver/path-resolver.ts +6 -3
  99. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  100. package/src/core/resolver/slice-catalog.ts +94 -0
  101. package/src/core/resolver/slice-format.ts +22 -0
  102. package/src/core/resolver/slice-selection.ts +237 -0
  103. package/src/core/resolver/symbol-impact.ts +477 -0
  104. package/src/core/resolver/symbol-locator.ts +82 -15
  105. package/src/core/resolver/vertical-slice-tracer.ts +57 -278
  106. package/src/core/resources/ignore.ts +21 -1
  107. package/src/core/resources/limits.ts +2 -1
  108. package/src/core/resources/source-files.ts +143 -20
  109. package/src/core/resources/source-inventory.ts +55 -0
  110. package/src/core/resources/work-queue.ts +167 -4
  111. package/src/core/retrieval/context-page.ts +116 -0
  112. package/src/core/retrieval/context.ts +457 -0
  113. package/src/core/retrieval/resolution-warnings.ts +21 -0
  114. package/src/core/retrieval/source-context.ts +448 -0
  115. package/src/core/retrieval/symbol-details.ts +453 -0
  116. package/src/core/retrieval/symbol-evidence.ts +97 -0
  117. package/src/core/retrieval/typescript-references.ts +293 -0
  118. package/src/core/retrieval/universal-context.ts +182 -0
  119. package/src/core/telemetry/summary.ts +114 -0
  120. package/src/core/telemetry/telemetry.ts +225 -37
  121. package/src/index.ts +0 -3
  122. package/src/mcp/formatters/compact-text.ts +439 -0
  123. package/src/mcp/resources-and-prompts.ts +253 -0
  124. package/src/mcp/schemas/boundary.ts +145 -0
  125. package/src/mcp/schemas/map.ts +250 -0
  126. package/src/mcp/schemas/shared.ts +52 -0
  127. package/src/mcp/schemas/slice.ts +60 -0
  128. package/src/mcp/schemas/symbol.ts +268 -0
  129. package/src/mcp/schemas.ts +5 -1105
  130. package/src/mcp/server.ts +263 -597
  131. package/src/mcp/tool-catalog.ts +331 -0
  132. package/src/mcp/tools/boundary.ts +69 -4
  133. package/src/mcp/tools/map.ts +126 -0
  134. package/src/mcp/tools/slice.ts +101 -3
  135. package/src/mcp/tools/symbol.ts +480 -26
  136. package/src/mcp/ui/app-client.ts +899 -0
  137. package/src/mcp/ui/app.html +478 -0
  138. package/src/mcp/workflow-playbooks.ts +181 -0
  139. package/src/mcp/workspace-boundary.ts +50 -0
  140. package/src/mcp/workspace-manager.ts +102 -18
  141. package/src/mcp/workspace-watcher.ts +38 -19
  142. package/src/types/index.ts +47 -53
  143. package/src/cli/commands/topology.ts +0 -161
  144. package/src/core/database/repositories/environment.repository.ts +0 -207
  145. package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
  146. package/src/core/session/session-manager.ts +0 -107
  147. package/src/core/topology/environment-detector.ts +0 -973
  148. package/src/core/topology/types.ts +0 -83
  149. package/src/mcp/tools/check-boundary.ts +0 -387
  150. package/src/mcp/tools/domain.ts +0 -40
  151. package/src/mcp/tools/feature.ts +0 -67
  152. package/src/mcp/tools/get-domain-catalog.ts +0 -226
  153. package/src/mcp/tools/get-environment-topology.ts +0 -138
  154. package/src/mcp/tools/get-feature-context.ts +0 -224
  155. package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
  156. package/src/mcp/tools/get-symbol-impact.ts +0 -64
  157. package/src/mcp/tools/get-symbol.ts +0 -175
  158. package/src/mcp/tools/locate-symbol.ts +0 -196
  159. package/src/mcp/tools/register-domain.ts +0 -75
  160. package/src/mcp/tools/register-feature.ts +0 -110
  161. package/src/mcp/tools/trace-vertical-slice.ts +0 -80
@@ -1,1105 +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 normalizeFeatureContextArgs(raw: unknown): unknown {
42
- const coerced = extractSingleStringFallback(raw, "feature_key");
43
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
44
- const obj = { ...(coerced as Record<string, unknown>) };
45
-
46
- const aliases: Record<string, string> = {
47
- feature: "feature_key",
48
- featureKey: "feature_key",
49
- feature_name: "feature_key",
50
- featureName: "feature_key",
51
- feat: "feature_key",
52
- name: "feature_key",
53
- key: "feature_key",
54
- task: "feature_key",
55
- task_name: "feature_key",
56
- target: "feature_key",
57
- context: "feature_key",
58
- slug: "feature_key",
59
- workspace: "workspace_path",
60
- workspacePath: "workspace_path",
61
- project_root: "workspace_path",
62
- projectRoot: "workspace_path",
63
- };
64
-
65
- for (const [alias, target] of Object.entries(aliases)) {
66
- if (obj[alias] !== undefined && obj[target] === undefined) {
67
- obj[target] = obj[alias];
68
- }
69
- }
70
-
71
- // Populate feature as backward-compatible alias
72
- if (obj.feature_key !== undefined && obj.feature === undefined) {
73
- obj.feature = obj.feature_key;
74
- } else if (obj.feature !== undefined && obj.feature_key === undefined) {
75
- obj.feature_key = obj.feature;
76
- }
77
-
78
- return obj;
79
- }
80
-
81
- export function normalizeBoundaryArgs(raw: unknown): unknown {
82
- if (Array.isArray(raw) && raw.length > 1 && raw.every((item) => typeof item === "string")) {
83
- raw = { file_paths: raw };
84
- }
85
- const coerced = extractSingleStringFallback(raw, "file_path", [
86
- "workspace_path",
87
- "workspacePath",
88
- "workspace",
89
- "project_root",
90
- "projectRoot",
91
- "scope",
92
- "domain",
93
- "domain_name",
94
- "domainName",
95
- "feature_key",
96
- "featureKey",
97
- "feature",
98
- "feature_name",
99
- "featureName",
100
- "name",
101
- "key",
102
- ]);
103
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
104
- const obj = { ...(coerced as Record<string, unknown>) };
105
- const aliases: Record<string, string> = {
106
- filePath: "file_path",
107
- file: "file_path",
108
- path: "file_path",
109
- from_file: "file_path",
110
- fromFile: "file_path",
111
- source_file: "file_path",
112
- sourceFile: "file_path",
113
- filePaths: "file_paths",
114
- files: "file_paths",
115
- paths: "file_paths",
116
- proposedImports: "proposed_imports",
117
- imports: "proposed_imports",
118
- featureKey: "feature_key",
119
- feature: "feature_key",
120
- feature_name: "feature_key",
121
- featureName: "feature_key",
122
- name: "feature_key",
123
- key: "feature_key",
124
- domain_name: "domain",
125
- domainName: "domain",
126
- workspace: "workspace_path",
127
- workspacePath: "workspace_path",
128
- project_root: "workspace_path",
129
- projectRoot: "workspace_path",
130
- };
131
- for (const [alias, target] of Object.entries(aliases)) {
132
- if (obj[alias] !== undefined && obj[target] === undefined) {
133
- obj[target] = obj[alias];
134
- }
135
- }
136
-
137
- if (obj.feature_key !== undefined && obj.feature === undefined) {
138
- obj.feature = obj.feature_key;
139
- } else if (obj.feature !== undefined && obj.feature_key === undefined) {
140
- obj.feature_key = obj.feature;
141
- }
142
-
143
- if (obj.to_file || obj.toFile) {
144
- const rawTo = obj.to_file ?? obj.toFile;
145
- const toFiles = Array.isArray(rawTo) ? rawTo.map(String) : [String(rawTo)];
146
- if (!obj.proposed_imports) {
147
- obj.proposed_imports = toFiles;
148
- } else if (Array.isArray(obj.proposed_imports)) {
149
- obj.proposed_imports = [...obj.proposed_imports, ...toFiles];
150
- }
151
- }
152
- if (Array.isArray(obj.file_path) && !obj.file_paths) {
153
- obj.file_paths = obj.file_path;
154
- delete obj.file_path;
155
- }
156
- if (typeof obj.file_paths === "string" && !obj.file_path) {
157
- obj.file_path = obj.file_paths;
158
- delete obj.file_paths;
159
- }
160
- if (obj.scope === undefined) {
161
- if (obj.staged === true) {
162
- obj.scope = "staged";
163
- } else if (obj.domain !== undefined && obj.file_path === undefined && obj.file_paths === undefined) {
164
- obj.scope = "domain";
165
- }
166
- }
167
- return obj;
168
- }
169
-
170
- export function normalizeDomainCatalogArgs(raw: unknown): unknown {
171
- const coerced = extractSingleStringFallback(raw, "domain", [
172
- "workspace_path",
173
- "workspacePath",
174
- "workspace",
175
- "project_root",
176
- "projectRoot",
177
- "target_path",
178
- "path",
179
- "archetype_filter",
180
- "archetype",
181
- "archetypeFilter",
182
- "type",
183
- "detail_level",
184
- "detailLevel",
185
- "mode",
186
- "format",
187
- "file_filter",
188
- "fileFilter",
189
- "file",
190
- "filter",
191
- ]);
192
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
193
- const obj = withAliases(coerced, {
194
- domain_name: "domain",
195
- domainName: "domain",
196
- name: "domain",
197
- archetype: "archetype_filter",
198
- archetypeFilter: "archetype_filter",
199
- type: "archetype_filter",
200
- detailLevel: "detail_level",
201
- mode: "detail_level",
202
- format: "detail_level",
203
- fileFilter: "file_filter",
204
- file: "file_filter",
205
- filter: "file_filter",
206
- workspace: "workspace_path",
207
- workspacePath: "workspace_path",
208
- project_root: "workspace_path",
209
- projectRoot: "workspace_path",
210
- target_path: "workspace_path",
211
- path: "workspace_path",
212
- }) as Record<string, unknown>;
213
- if (obj.domain !== undefined && obj.name === undefined) {
214
- obj.name = obj.domain;
215
- } else if (obj.name !== undefined && obj.domain === undefined) {
216
- obj.domain = obj.name;
217
- }
218
- if (obj.archetype_filter !== undefined && obj.archetype === undefined) {
219
- obj.archetype = obj.archetype_filter;
220
- } else if (obj.archetype !== undefined && obj.archetype_filter === undefined) {
221
- obj.archetype_filter = obj.archetype;
222
- }
223
- if (obj.full === true && obj.detail_level === undefined) {
224
- obj.detail_level = "full";
225
- }
226
- return obj;
227
- }
228
-
229
- export const GetDomainCatalogSchema = z.preprocess(
230
- normalizeDomainCatalogArgs,
231
- z.object({
232
- domain: z.string().optional(),
233
- name: z.string().optional(),
234
- archetype_filter: z.string().optional(),
235
- archetype: z.string().optional(),
236
- detail_level: z.enum(["compact", "full"]).optional().default("compact"),
237
- file_filter: z.string().optional(),
238
- workspace_path: z.string().optional(),
239
- })
240
- );
241
- export type GetDomainCatalogArgs = z.infer<typeof GetDomainCatalogSchema>;
242
-
243
- export const GetFeatureContextSchema = z.preprocess(
244
- normalizeFeatureContextArgs,
245
- z.object({
246
- feature_key: z.string().optional(),
247
- feature: z.string().optional(),
248
- workspace_path: z.string().optional(),
249
- })
250
- );
251
- export type GetFeatureContextArgs = z.infer<typeof GetFeatureContextSchema>;
252
-
253
- export const ClearFeatureContextSchema = z
254
- .object({
255
- workspace_path: z.string().optional(),
256
- })
257
- .passthrough();
258
- export type ClearFeatureContextArgs = z.infer<typeof ClearFeatureContextSchema>;
259
-
260
- export function normalizeLocateSymbolArgs(raw: unknown): unknown {
261
- const coerced = extractSingleStringFallback(raw, "query", [
262
- "workspace_path",
263
- "workspacePath",
264
- "workspace",
265
- "project_root",
266
- "projectRoot",
267
- "target_path",
268
- "path",
269
- "domain",
270
- "domain_name",
271
- "domainName",
272
- ]);
273
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
274
- const obj = withAliases(coerced, {
275
- symbol: "query",
276
- name: "query",
277
- symbol_name: "query",
278
- symbolName: "query",
279
- target: "query",
280
- domain_name: "domain",
281
- domainName: "domain",
282
- max: "limit",
283
- workspace: "workspace_path",
284
- workspacePath: "workspace_path",
285
- project_root: "workspace_path",
286
- projectRoot: "workspace_path",
287
- target_path: "workspace_path",
288
- path: "workspace_path",
289
- }) as Record<string, unknown>;
290
- if (obj.query !== undefined && obj.symbol === undefined) {
291
- obj.symbol = obj.query;
292
- } else if (obj.symbol !== undefined && obj.query === undefined) {
293
- obj.query = obj.symbol;
294
- }
295
- if (!obj.query && !obj.symbol && typeof obj.symbol_ref === "object" && obj.symbol_ref !== null) {
296
- obj.query = (obj.symbol_ref as Record<string, unknown>).name;
297
- obj.symbol = obj.query;
298
- }
299
- return obj;
300
- }
301
-
302
- export const SymbolReferenceSchema = z.object({
303
- file_path: z.string().min(1), language: z.string().min(1), name: z.string().min(1), kind: z.string().min(1),
304
- signature: z.string(), start_line: z.number().int().positive(), end_line: z.number().int().positive(),
305
- indexed_content_hash: z.string().min(1), container: z.string().optional(), receiver: z.string().optional(),
306
- }).refine(ref => ref.end_line >= ref.start_line, { message: "end_line must be at or after start_line" });
307
-
308
- export const LocateSymbolSchema = z.preprocess(
309
- normalizeLocateSymbolArgs,
310
- z.object({
311
- query: z.string().min(1, "query is required"),
312
- symbol: z.string().optional(),
313
- domain: z.string().optional(),
314
- symbol_ref: SymbolReferenceSchema.optional(),
315
- file_path: z.string().min(1).optional(),
316
- limit: z.number().int().min(1).max(50).optional().default(10),
317
- workspace_path: z.string().optional(),
318
- })
319
- );
320
- export type LocateSymbolArgs = z.infer<typeof LocateSymbolSchema>;
321
-
322
- export function normalizeGetSymbolArgs(raw: unknown): unknown {
323
- const coerced = extractSingleStringFallback(raw, "symbol", [
324
- "workspace_path",
325
- "workspacePath",
326
- "workspace",
327
- "project_root",
328
- "projectRoot",
329
- "domain",
330
- "domain_name",
331
- "domainName",
332
- ]);
333
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
334
- const obj = withAliases(coerced, {
335
- query: "symbol",
336
- name: "symbol",
337
- symbol_name: "symbol",
338
- symbolName: "symbol",
339
- target: "symbol",
340
- domain_name: "domain",
341
- domainName: "domain",
342
- includeDependencies: "include_dependencies",
343
- include_deps: "include_dependencies",
344
- includeDeps: "include_dependencies",
345
- dependencies: "include_dependencies",
346
- deps: "include_dependencies",
347
- workspace: "workspace_path",
348
- workspacePath: "workspace_path",
349
- project_root: "workspace_path",
350
- projectRoot: "workspace_path",
351
- }) as Record<string, unknown>;
352
- if (obj.symbol !== undefined && obj.query === undefined) {
353
- obj.query = obj.symbol;
354
- } else if (obj.query !== undefined && obj.symbol === undefined) {
355
- obj.symbol = obj.query;
356
- }
357
- if (!obj.query && !obj.symbol && typeof obj.symbol_ref === "object" && obj.symbol_ref !== null) {
358
- obj.query = (obj.symbol_ref as Record<string, unknown>).name;
359
- obj.symbol = obj.query;
360
- }
361
- return obj;
362
- }
363
-
364
- export const GetSymbolSchema = z.preprocess(
365
- normalizeGetSymbolArgs,
366
- z.object({
367
- symbol: z.string().min(1, "symbol is required"),
368
- query: z.string().optional(),
369
- domain: z.string().optional(),
370
- symbol_ref: SymbolReferenceSchema.optional(),
371
- include_dependencies: z.boolean().optional().default(true),
372
- workspace_path: z.string().optional(),
373
- file_path: z.string().min(1).optional(),
374
- include_source: z.boolean().optional().default(false),
375
- source_start_line: z.number().int().positive().optional(),
376
- source_line_limit: z.number().int().positive().max(200).optional().default(120),
377
- })
378
- );
379
- export type GetSymbolArgs = z.infer<typeof GetSymbolSchema>;
380
-
381
- export function normalizeGetSymbolImpactArgs(raw: unknown): unknown {
382
- const coerced = extractSingleStringFallback(raw, "symbol");
383
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
384
- const obj = withAliases(coerced, {
385
- query: "symbol",
386
- name: "symbol",
387
- symbol_name: "symbol",
388
- symbolName: "symbol",
389
- file_path: "symbol",
390
- filePath: "symbol",
391
- file: "symbol",
392
- path: "symbol",
393
- target: "symbol",
394
- workspace: "workspace_path",
395
- workspacePath: "workspace_path",
396
- project_root: "workspace_path",
397
- projectRoot: "workspace_path",
398
- }) as Record<string, unknown>;
399
- if (obj.symbol !== undefined && obj.query === undefined) {
400
- obj.query = obj.symbol;
401
- } else if (obj.query !== undefined && obj.symbol === undefined) {
402
- obj.symbol = obj.query;
403
- }
404
- return obj;
405
- }
406
-
407
- export const GetSymbolImpactSchema = z.preprocess(
408
- normalizeGetSymbolImpactArgs,
409
- z.object({
410
- symbol: z.string().min(1, "symbol is required"),
411
- query: z.string().optional(),
412
- domain: z.string().optional(),
413
- workspace_path: z.string().optional(),
414
- })
415
- );
416
- export type GetSymbolImpactArgs = z.infer<typeof GetSymbolImpactSchema>;
417
-
418
- export function normalizeTraceVerticalSliceArgs(raw: unknown): unknown {
419
- const coerced = extractSingleStringFallback(raw, "query");
420
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
421
- const obj = withAliases(coerced, {
422
- route: "query",
423
- uri: "query",
424
- route_uri: "query",
425
- routeUri: "query",
426
- entry_file: "query",
427
- entryFile: "query",
428
- file_path: "query",
429
- filePath: "query",
430
- file: "query",
431
- path: "query",
432
- symbol: "query",
433
- name: "query",
434
- feature: "query",
435
- feature_key: "query",
436
- featureKey: "query",
437
- maxDepth: "max_depth",
438
- depth: "max_depth",
439
- workspace: "workspace_path",
440
- workspacePath: "workspace_path",
441
- project_root: "workspace_path",
442
- projectRoot: "workspace_path",
443
- }) as Record<string, unknown>;
444
- if (obj.query !== undefined && obj.symbol === undefined) {
445
- obj.symbol = obj.query;
446
- } else if (obj.symbol !== undefined && obj.query === undefined) {
447
- obj.query = obj.symbol;
448
- }
449
- if (obj.max_depth !== undefined && obj.max_depth !== null && !Number.isNaN(Number(obj.max_depth))) {
450
- obj.max_depth = Math.min(Math.max(Math.trunc(Number(obj.max_depth)), 1), 8);
451
- }
452
- return obj;
453
- }
454
-
455
- export const TraceVerticalSliceSchema = z.preprocess(
456
- normalizeTraceVerticalSliceArgs,
457
- z.object({
458
- query: z.string().min(1, "query is required"),
459
- symbol: z.string().optional(),
460
- max_depth: z.number().int().min(1).max(8).optional().default(5),
461
- workspace_path: z.string().optional(),
462
- })
463
- );
464
- export type TraceVerticalSliceArgs = z.infer<typeof TraceVerticalSliceSchema>;
465
-
466
- export const CheckBoundarySchema = z.preprocess(
467
- normalizeBoundaryArgs,
468
- z.object({
469
- file_path: z.string().trim().min(1, "file_path cannot be blank").optional(),
470
- file_paths: z.array(z.string().trim().min(1, "file_paths cannot contain blank paths")).optional(),
471
- proposed_imports: z.array(z.string()).optional().default([]),
472
- feature_key: z.string().optional(),
473
- scope: z.enum(["file", "all", "staged", "domain"]).optional(),
474
- domain: z.string().trim().min(1, "domain cannot be blank").optional(),
475
- staged: z.boolean().optional(),
476
- workspace_path: z.string().optional(),
477
- }).superRefine((args, ctx) => {
478
- const hasBatch = Boolean(args.file_paths?.length);
479
- const hasTarget = args.file_path !== undefined || hasBatch;
480
- const scope = args.scope ?? (args.staged ? "staged" : hasTarget ? "file" : args.domain ? "domain" : "all");
481
- if (args.file_path !== undefined && hasBatch) {
482
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["file_paths"], message: "Use either file_path or file_paths, not both." });
483
- }
484
- if (args.staged && scope !== "staged") {
485
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["staged"], message: "staged=true requires scope='staged'." });
486
- }
487
- if (scope === "file" && !hasTarget) {
488
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["file_path"], message: "scope='file' requires file_path or non-empty file_paths." });
489
- }
490
- if (scope !== "file" && hasTarget) {
491
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["scope"], message: `scope='${scope}' does not accept file targets. Use scope='file' for proposed-import checks.` });
492
- }
493
- if (scope === "domain" && !args.domain) {
494
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["domain"], message: "scope='domain' requires a registered domain name." });
495
- }
496
- if (scope === "all" && args.domain) {
497
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["domain"], message: "scope='all' checks the entire repository. Use scope='domain' to filter a domain." });
498
- }
499
- if (scope !== "file" && args.proposed_imports.length) {
500
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["proposed_imports"], message: "proposed_imports requires a file target and scope='file'." });
501
- }
502
- })
503
- );
504
- export type CheckBoundaryArgs = z.infer<typeof CheckBoundarySchema>;
505
-
506
- export const GetSymbolHotspotsSchema = z.preprocess(
507
- (args) =>
508
- withAliases(args, {
509
- domain_name: "domain",
510
- domainName: "domain",
511
- max: "limit",
512
- nesting: "min_nesting",
513
- minNesting: "min_nesting",
514
- lines: "min_lines",
515
- minLines: "min_lines",
516
- sortBy: "sort_by",
517
- workspace: "workspace_path",
518
- workspacePath: "workspace_path",
519
- project_root: "workspace_path",
520
- projectRoot: "workspace_path",
521
- }),
522
- z.object({
523
- min_lines: z.number().int().nonnegative().optional(),
524
- min_nesting: z.number().int().positive().optional(),
525
- kind: z.string().optional(),
526
- domain: z.string().optional(),
527
- limit: z.number().int().positive().optional().default(30),
528
- sort_by: z.enum(["lines", "nesting", "risk_score"]).optional(),
529
- workspace_path: z.string().optional(),
530
- })
531
- );
532
- export type GetSymbolHotspotsArgs = z.infer<typeof GetSymbolHotspotsSchema>;
533
-
534
- export function normalizeRegisterDomainArgs(raw: unknown): unknown {
535
- const coerced = extractSingleStringFallback(raw, "domain", [
536
- "root",
537
- "root_path",
538
- "rootPath",
539
- "path",
540
- "root_dir",
541
- "workspace_path",
542
- "workspacePath",
543
- "workspace",
544
- "project_root",
545
- "projectRoot",
546
- ]);
547
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
548
- const obj = withAliases(coerced, {
549
- name: "domain",
550
- domain_name: "domain",
551
- domainName: "domain",
552
- root_path: "root",
553
- rootPath: "root",
554
- path: "root",
555
- allowedDependencies: "allowed_dependencies",
556
- allowed: "allowed_dependencies",
557
- forbiddenDependencies: "forbidden_dependencies",
558
- forbidden: "forbidden_dependencies",
559
- archetype: "archetypes",
560
- ingestNow: "ingest_now",
561
- workspace: "workspace_path",
562
- workspacePath: "workspace_path",
563
- project_root: "workspace_path",
564
- projectRoot: "workspace_path",
565
- }) as Record<string, unknown>;
566
- if (obj.domain !== undefined && obj.name === undefined) {
567
- obj.name = obj.domain;
568
- } else if (obj.name !== undefined && obj.domain === undefined) {
569
- obj.domain = obj.name;
570
- }
571
- return obj;
572
- }
573
-
574
- export const RegisterDomainSchema = z.preprocess(
575
- normalizeRegisterDomainArgs,
576
- z.object({
577
- domain: z.string().min(1, "Domain name/identifier is required"),
578
- name: z.string().optional(),
579
- root: z.string().min(1, "Domain root path is required"),
580
- description: z.string().optional(),
581
- allowed_dependencies: z.array(z.string()).optional(),
582
- forbidden_dependencies: z.array(z.string()).optional(),
583
- archetypes: z.record(z.string()).optional(),
584
- ingest_now: z.boolean().optional().default(false),
585
- workspace_path: z.string().optional(),
586
- })
587
- );
588
- export type RegisterDomainArgs = z.infer<typeof RegisterDomainSchema>;
589
-
590
- export function normalizeRegisterFeatureArgs(raw: unknown): unknown {
591
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return raw;
592
- const obj = { ...(raw as Record<string, unknown>) };
593
-
594
- const aliases: Record<string, string> = {
595
- feature: "feature_key",
596
- featureKey: "feature_key",
597
- feature_name: "feature_key",
598
- featureName: "feature_key",
599
- feat: "feature_key",
600
- name: "feature_key",
601
- key: "feature_key",
602
- domain_name: "domain",
603
- domainName: "domain",
604
- touchpoints: "allowed_touchpoints",
605
- allowedTouchpoints: "allowed_touchpoints",
606
- touchpoint: "allowed_touchpoints",
607
- files: "allowed_touchpoints",
608
- allowed_files: "allowed_touchpoints",
609
- reuseSymbols: "reuse_symbols",
610
- reuse: "reuse_symbols",
611
- symbols: "reuse_symbols",
612
- inputContract: "input_contract",
613
- outputContract: "output_contract",
614
- workspace: "workspace_path",
615
- workspacePath: "workspace_path",
616
- project_root: "workspace_path",
617
- projectRoot: "workspace_path",
618
- };
619
-
620
- for (const [alias, target] of Object.entries(aliases)) {
621
- if (obj[alias] !== undefined && obj[target] === undefined) {
622
- obj[target] = obj[alias];
623
- }
624
- }
625
-
626
- // Symmetrical contract: feature_key <-> feature
627
- if (obj.feature_key !== undefined && obj.feature === undefined) {
628
- obj.feature = obj.feature_key;
629
- } else if (obj.feature !== undefined && obj.feature_key === undefined) {
630
- obj.feature_key = obj.feature;
631
- }
632
-
633
- // Symmetrical contract: domain <-> domain_name
634
- if (obj.domain !== undefined && obj.domain_name === undefined) {
635
- obj.domain_name = obj.domain;
636
- } else if (obj.domain_name !== undefined && obj.domain === undefined) {
637
- obj.domain = obj.domain_name;
638
- }
639
-
640
- // Array coercion for allowed_touchpoints
641
- if (typeof obj.allowed_touchpoints === "string") {
642
- obj.allowed_touchpoints = [obj.allowed_touchpoints];
643
- } else if (!Array.isArray(obj.allowed_touchpoints) && obj.allowed_touchpoints !== undefined) {
644
- obj.allowed_touchpoints = [];
645
- }
646
-
647
- // Array coercion for reuse_symbols
648
- if (typeof obj.reuse_symbols === "string") {
649
- obj.reuse_symbols = [obj.reuse_symbols];
650
- }
651
-
652
- return obj;
653
- }
654
-
655
- export const RegisterFeatureSchema = z.preprocess(
656
- normalizeRegisterFeatureArgs,
657
- z.object({
658
- feature_key: z.string().min(1, "Feature key is required"),
659
- feature: z.string().optional(),
660
- domain: z.string().min(1, "Domain name is required"),
661
- domain_name: z.string().optional(),
662
- description: z.string().optional(),
663
- allowed_touchpoints: z.array(z.string()).default([]),
664
- reuse_symbols: z.array(z.string()).optional(),
665
- input_contract: z.record(z.unknown()).optional(),
666
- output_contract: z.record(z.unknown()).optional(),
667
- workspace_path: z.string().optional(),
668
- })
669
- );
670
- export type RegisterFeatureArgs = z.infer<typeof RegisterFeatureSchema>;
671
-
672
- function normalizeTopologyArgs(raw: unknown): unknown {
673
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return raw;
674
- const obj = withAliases(raw, {
675
- workspace: "workspace_path",
676
- workspacePath: "workspace_path",
677
- project_root: "workspace_path",
678
- projectRoot: "workspace_path",
679
- }) as Record<string, unknown>;
680
- if (obj.resolve_node !== undefined && obj.resolveNode === undefined) {
681
- obj.resolveNode = obj.resolve_node;
682
- }
683
- if (obj.resolve_layer !== undefined && obj.resolve === undefined) {
684
- obj.resolve = obj.resolve_layer;
685
- }
686
- if (obj.resolveLayer !== undefined && obj.resolve === undefined) {
687
- obj.resolve = obj.resolveLayer;
688
- }
689
- if (typeof obj.resolveNode === "object" && obj.resolveNode !== null) {
690
- obj.resolveNode = withAliases(obj.resolveNode, {
691
- canonicalTag: "canonical_tag",
692
- domainOrIp: "domain_or_ip",
693
- connectedTo: "connected_to",
694
- nodeId: "id",
695
- node_id: "id",
696
- nodeName: "name",
697
- node_name: "name",
698
- });
699
- }
700
- return obj;
701
- }
702
-
703
- export const GetEnvironmentTopologySchema = z.preprocess(
704
- (args) => normalizeTopologyArgs(args),
705
- z.object({
706
- resolve: z
707
- .object({
708
- layer: z.enum(["edge", "gateway", "host", "runtime", "storage", "telemetry"]),
709
- platform: z.string().min(1, "platform name cannot be empty"),
710
- constraints: z.array(z.string()).optional(),
711
- })
712
- .optional(),
713
- resolveNode: z
714
- .object({
715
- id: z.string().min(1, "Node id cannot be empty"),
716
- layer: z.enum(["edge", "gateway", "host", "runtime", "storage", "telemetry"]),
717
- name: z.string().min(1, "Node name cannot be empty"),
718
- platform: z.string().min(1, "Platform cannot be empty"),
719
- canonical_tag: z
720
- .enum([
721
- "shared_hosting",
722
- "vps",
723
- "docker",
724
- "serverless",
725
- "kubernetes",
726
- "managed_db",
727
- "cdn_edge",
728
- "paas",
729
- "static_cdn",
730
- "unspecified",
731
- ])
732
- .optional(),
733
- domain_or_ip: z.string().optional(),
734
- role: z.string().optional(),
735
- constraints: z.array(z.string()).optional(),
736
- connected_to: z.array(z.string()).optional(),
737
- })
738
- .optional(),
739
- refresh: z.boolean().optional().default(false),
740
- workspace_path: z.string().optional(),
741
- })
742
- );
743
- export type GetEnvironmentTopologyArgs = z.infer<typeof GetEnvironmentTopologySchema>;
744
-
745
- // =========================================================================
746
- // 5 UNIFIED TOOLS SCHEMAS & NORMALIZERS (Refactored Clean-Break MCP Engine)
747
- // =========================================================================
748
-
749
- // 1. septum_domain
750
- export function normalizeDomainToolArgs(raw: unknown): unknown {
751
- const coerced = extractSingleStringFallback(raw, "domain", [
752
- "workspace_path",
753
- "workspacePath",
754
- "workspace",
755
- "project_root",
756
- "projectRoot",
757
- "target_path",
758
- "path",
759
- "action",
760
- "detail_level",
761
- "detailLevel",
762
- "mode",
763
- "format",
764
- "archetype_filter",
765
- "archetype",
766
- "file_filter",
767
- "fileFilter",
768
- "root",
769
- "root_path",
770
- "rootPath",
771
- ]);
772
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
773
- const obj = withAliases(coerced, {
774
- domain_name: "domain",
775
- domainName: "domain",
776
- name: "domain",
777
- archetype: "archetype_filter",
778
- archetypeFilter: "archetype_filter",
779
- type: "archetype_filter",
780
- detailLevel: "detail_level",
781
- mode: "detail_level",
782
- format: "detail_level",
783
- fileFilter: "file_filter",
784
- file: "file_filter",
785
- filter: "file_filter",
786
- root_path: "root",
787
- rootPath: "root",
788
- path: "root",
789
- allowedDependencies: "allowed_dependencies",
790
- allowed: "allowed_dependencies",
791
- forbiddenDependencies: "forbidden_dependencies",
792
- forbidden: "forbidden_dependencies",
793
- archetypes: "archetypes",
794
- ingestNow: "ingest_now",
795
- resolveLayer: "resolve",
796
- resolve_layer: "resolve",
797
- resolveNode: "resolve_node",
798
- workspace: "workspace_path",
799
- workspacePath: "workspace_path",
800
- project_root: "workspace_path",
801
- projectRoot: "workspace_path",
802
- }) as Record<string, unknown>;
803
-
804
- if (obj.domain !== undefined && obj.name === undefined) {
805
- obj.name = obj.domain;
806
- } else if (obj.name !== undefined && obj.domain === undefined) {
807
- obj.domain = obj.name;
808
- }
809
-
810
- if (obj.archetype_filter !== undefined && obj.archetype === undefined) {
811
- obj.archetype = obj.archetype_filter;
812
- } else if (obj.archetype !== undefined && obj.archetype_filter === undefined) {
813
- obj.archetype_filter = obj.archetype;
814
- }
815
-
816
- if (obj.full === true && obj.detail_level === undefined) {
817
- obj.detail_level = "full";
818
- }
819
-
820
- if (typeof obj.resolve_node === "object" && obj.resolve_node !== null) {
821
- obj.resolve_node = withAliases(obj.resolve_node, {
822
- canonicalTag: "canonical_tag",
823
- domainOrIp: "domain_or_ip",
824
- connectedTo: "connected_to",
825
- nodeId: "id",
826
- node_id: "id",
827
- nodeName: "name",
828
- node_name: "name",
829
- });
830
- }
831
-
832
- if (!obj.action) {
833
- if (obj.root !== undefined || obj.ingest_now !== undefined) {
834
- obj.action = "register";
835
- } else if (obj.resolve !== undefined || obj.resolve_node !== undefined || obj.resolveNode !== undefined || obj.refresh !== undefined) {
836
- obj.action = "topology";
837
- } else {
838
- obj.action = "catalog";
839
- }
840
- }
841
-
842
- return obj;
843
- }
844
-
845
- export const DomainToolSchema = z.preprocess(
846
- normalizeDomainToolArgs,
847
- z.object({
848
- action: z.enum(["catalog", "register", "topology"]).optional().default("catalog"),
849
- domain: z.string().optional(),
850
- name: z.string().optional(),
851
- detail_level: z.enum(["compact", "full"]).optional().default("compact"),
852
- archetype_filter: z.string().optional(),
853
- archetype: z.string().optional(),
854
- file_filter: z.string().optional(),
855
- root: z.string().optional(),
856
- description: z.string().optional(),
857
- allowed_dependencies: z.array(z.string()).optional(),
858
- forbidden_dependencies: z.array(z.string()).optional(),
859
- archetypes: z.record(z.string()).optional(),
860
- ingest_now: z.boolean().optional().default(false),
861
- resolve: z
862
- .object({
863
- layer: z.enum(["edge", "gateway", "host", "runtime", "storage", "telemetry"]),
864
- platform: z.string().min(1, "platform name cannot be empty"),
865
- constraints: z.array(z.string()).optional(),
866
- })
867
- .optional(),
868
- resolve_node: z
869
- .object({
870
- id: z.string().min(1, "Node id cannot be empty"),
871
- layer: z.enum(["edge", "gateway", "host", "runtime", "storage", "telemetry"]),
872
- name: z.string().min(1, "Node name cannot be empty"),
873
- platform: z.string().min(1, "Platform cannot be empty"),
874
- canonical_tag: z
875
- .enum([
876
- "shared_hosting",
877
- "vps",
878
- "docker",
879
- "serverless",
880
- "kubernetes",
881
- "managed_db",
882
- "cdn_edge",
883
- "paas",
884
- "static_cdn",
885
- "unspecified",
886
- ])
887
- .optional(),
888
- domain_or_ip: z.string().optional(),
889
- role: z.string().optional(),
890
- constraints: z.array(z.string()).optional(),
891
- connected_to: z.array(z.string()).optional(),
892
- })
893
- .optional(),
894
- resolveNode: z.any().optional(),
895
- refresh: z.boolean().optional().default(false),
896
- workspace_path: z.string().optional(),
897
- })
898
- );
899
- export type DomainToolArgs = z.infer<typeof DomainToolSchema>;
900
-
901
- // 2. septum_symbol
902
- export function normalizeSymbolToolArgs(raw: unknown): unknown {
903
- const coerced = extractSingleStringFallback(raw, "query", [
904
- "workspace_path",
905
- "workspacePath",
906
- "workspace",
907
- "project_root",
908
- "projectRoot",
909
- "action",
910
- "domain",
911
- "domain_name",
912
- "domainName",
913
- "min_lines",
914
- "min_nesting",
915
- "sort_by",
916
- "limit",
917
- ]);
918
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
919
- const obj = withAliases(coerced, {
920
- symbol: "query",
921
- name: "query",
922
- symbol_name: "query",
923
- symbolName: "query",
924
- target: "query",
925
- domain_name: "domain",
926
- domainName: "domain",
927
- includeDependencies: "include_dependencies",
928
- include_deps: "include_dependencies",
929
- includeDeps: "include_dependencies",
930
- dependencies: "include_dependencies",
931
- deps: "include_dependencies",
932
- max: "limit",
933
- nesting: "min_nesting",
934
- minNesting: "min_nesting",
935
- lines: "min_lines",
936
- minLines: "min_lines",
937
- sortBy: "sort_by",
938
- workspace: "workspace_path",
939
- workspacePath: "workspace_path",
940
- project_root: "workspace_path",
941
- projectRoot: "workspace_path",
942
- filePath: "file_path",
943
- sourceStartLine: "source_start_line",
944
- sourceLineLimit: "source_line_limit",
945
- }) as Record<string, unknown>;
946
-
947
- if (obj.query !== undefined && obj.symbol === undefined) {
948
- obj.symbol = obj.query;
949
- } else if (obj.symbol !== undefined && obj.query === undefined) {
950
- obj.query = obj.symbol;
951
- }
952
-
953
- if (!obj.action) {
954
- if (obj.min_lines !== undefined || obj.min_nesting !== undefined || obj.kind !== undefined || (obj.sort_by && !obj.query)) {
955
- obj.action = "hotspots";
956
- } else if (obj.include_dependencies !== undefined) {
957
- obj.action = "inspect";
958
- } else {
959
- obj.action = "locate";
960
- }
961
- }
962
-
963
- if (!obj.query && !obj.symbol && typeof obj.symbol_ref === "object" && obj.symbol_ref !== null) {
964
- obj.query = (obj.symbol_ref as Record<string, unknown>).name;
965
- obj.symbol = obj.query;
966
- }
967
- return obj;
968
- }
969
-
970
- export const SymbolToolSchema = z.preprocess(
971
- normalizeSymbolToolArgs,
972
- z.object({
973
- action: z.enum(["locate", "inspect", "impact", "hotspots"]).optional().default("locate"),
974
- query: z.string().optional(),
975
- symbol: z.string().optional(),
976
- domain: z.string().optional(),
977
- symbol_ref: SymbolReferenceSchema.optional(),
978
- include_dependencies: z.boolean().optional().default(true),
979
- limit: z.number().int().positive().optional(),
980
- min_lines: z.number().int().nonnegative().optional(),
981
- min_nesting: z.number().int().positive().optional(),
982
- kind: z.string().optional(),
983
- sort_by: z.enum(["lines", "nesting", "risk_score", "line_count"]).optional(),
984
- workspace_path: z.string().optional(),
985
- file_path: z.string().min(1).optional(),
986
- include_source: z.boolean().optional().default(false),
987
- source_start_line: z.number().int().positive().optional(),
988
- source_line_limit: z.number().int().positive().max(200).optional().default(120),
989
- }).superRefine((args, ctx) => {
990
- if (args.symbol_ref && args.action !== "locate" && args.action !== "inspect" && args.action !== "impact") {
991
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["symbol_ref"], message: "symbol_ref is supported only for locate, inspect, and impact." });
992
- }
993
- })
994
- );
995
- export type SymbolToolArgs = z.infer<typeof SymbolToolSchema>;
996
-
997
- // 3. septum_slice
998
- export const SliceToolSchema = TraceVerticalSliceSchema;
999
- export type SliceToolArgs = TraceVerticalSliceArgs;
1000
-
1001
- // 4. septum_boundary
1002
- export const BoundaryToolSchema = CheckBoundarySchema;
1003
- export type BoundaryToolArgs = CheckBoundaryArgs;
1004
-
1005
- // 5. septum_feature
1006
- export function normalizeFeatureToolArgs(raw: unknown): unknown {
1007
- const coerced = extractSingleStringFallback(raw, "feature_key", [
1008
- "workspace_path",
1009
- "workspacePath",
1010
- "workspace",
1011
- "project_root",
1012
- "projectRoot",
1013
- "action",
1014
- "domain",
1015
- "domain_name",
1016
- "domainName",
1017
- "force",
1018
- ]);
1019
- if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
1020
- const obj = { ...(coerced as Record<string, unknown>) };
1021
-
1022
- const aliases: Record<string, string> = {
1023
- feature: "feature_key",
1024
- featureKey: "feature_key",
1025
- feature_name: "feature_key",
1026
- featureName: "feature_key",
1027
- feat: "feature_key",
1028
- name: "feature_key",
1029
- key: "feature_key",
1030
- domain_name: "domain",
1031
- domainName: "domain",
1032
- touchpoints: "allowed_touchpoints",
1033
- allowedTouchpoints: "allowed_touchpoints",
1034
- touchpoint: "allowed_touchpoints",
1035
- files: "allowed_touchpoints",
1036
- allowed_files: "allowed_touchpoints",
1037
- reuseSymbols: "reuse_symbols",
1038
- reuse: "reuse_symbols",
1039
- symbols: "reuse_symbols",
1040
- inputContract: "input_contract",
1041
- outputContract: "output_contract",
1042
- workspace: "workspace_path",
1043
- workspacePath: "workspace_path",
1044
- project_root: "workspace_path",
1045
- projectRoot: "workspace_path",
1046
- };
1047
-
1048
- for (const [alias, target] of Object.entries(aliases)) {
1049
- if (obj[alias] !== undefined && obj[target] === undefined) {
1050
- obj[target] = obj[alias];
1051
- }
1052
- }
1053
-
1054
- if (obj.feature_key !== undefined && obj.feature === undefined) {
1055
- obj.feature = obj.feature_key;
1056
- } else if (obj.feature !== undefined && obj.feature_key === undefined) {
1057
- obj.feature_key = obj.feature;
1058
- }
1059
-
1060
- if (obj.domain !== undefined && obj.domain_name === undefined) {
1061
- obj.domain_name = obj.domain;
1062
- } else if (obj.domain_name !== undefined && obj.domain === undefined) {
1063
- obj.domain = obj.domain_name;
1064
- }
1065
-
1066
- if (typeof obj.allowed_touchpoints === "string") {
1067
- obj.allowed_touchpoints = [obj.allowed_touchpoints];
1068
- } else if (!Array.isArray(obj.allowed_touchpoints) && obj.allowed_touchpoints !== undefined) {
1069
- obj.allowed_touchpoints = [];
1070
- }
1071
-
1072
- if (typeof obj.reuse_symbols === "string") {
1073
- obj.reuse_symbols = [obj.reuse_symbols];
1074
- }
1075
-
1076
- if (!obj.action) {
1077
- if (obj.allowed_touchpoints !== undefined || obj.domain !== undefined || obj.reuse_symbols !== undefined) {
1078
- obj.action = "lock";
1079
- } else {
1080
- obj.action = "get";
1081
- }
1082
- }
1083
-
1084
- return obj;
1085
- }
1086
-
1087
- export const FeatureToolSchema = z.preprocess(
1088
- normalizeFeatureToolArgs,
1089
- z.object({
1090
- action: z.enum(["get", "lock", "release"]).optional().default("get"),
1091
- feature_key: z.string().optional(),
1092
- feature: z.string().optional(),
1093
- domain: z.string().optional(),
1094
- domain_name: z.string().optional(),
1095
- description: z.string().optional(),
1096
- allowed_touchpoints: z.array(z.string()).optional(),
1097
- reuse_symbols: z.array(z.string()).optional(),
1098
- input_contract: z.record(z.unknown()).optional(),
1099
- output_contract: z.record(z.unknown()).optional(),
1100
- force: z.boolean().optional().default(false),
1101
- workspace_path: z.string().optional(),
1102
- })
1103
- );
1104
- export type FeatureToolArgs = z.infer<typeof FeatureToolSchema>;
1105
-
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";