@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.
- package/README.md +38 -55
- package/package.json +7 -5
- package/src/cli/commands/check.ts +14 -10
- package/src/cli/commands/hook.ts +41 -6
- package/src/cli/commands/init.ts +10 -1
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +32 -4
- package/src/cli/index.ts +7 -0
- package/src/cli/templates/hooks.ts +3 -14
- package/src/cli/templates/skill.ts +17 -10
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +251 -114
- package/src/core/boundary/staged-auditor.ts +147 -55
- package/src/core/config/domain-ownership.ts +6 -4
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +1 -25
- package/src/core/config/schema.ts +24 -36
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +334 -572
- package/src/core/database/repositories/domain.repository.ts +2 -1
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -398
- package/src/core/database/repository.ts +68 -9
- package/src/core/database/schema.ts +26 -0
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +222 -58
- package/src/core/discovery/topology-detector.ts +93 -168
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +287 -88
- package/src/core/parser/extractors/base.ts +11 -3
- package/src/core/parser/extractors/csharp.ts +2 -2
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +397 -481
- package/src/core/parser/extractors/elysia-semantic.ts +172 -475
- package/src/core/parser/extractors/express-semantic.ts +195 -383
- package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
- package/src/core/parser/extractors/fastify-semantic.ts +216 -717
- package/src/core/parser/extractors/flask-semantic.ts +89 -352
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +205 -562
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -509
- package/src/core/parser/extractors/java.ts +2 -2
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +143 -335
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +1 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +5 -9
- package/src/core/parser/extractors/registry.ts +2 -0
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +2 -2
- package/src/core/parser/extractors/rust.ts +4 -4
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +72 -226
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +23 -216
- package/src/core/parser/language-capabilities.ts +1 -1
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +169 -414
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +60 -7
- package/src/core/resolver/interpretation-inputs.ts +60 -2
- package/src/core/resolver/languages/python.ts +31 -13
- package/src/core/resolver/languages/shared.ts +4 -1
- package/src/core/resolver/module-resolver.ts +10 -3
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +21 -6
- package/src/core/resolver/slice-format.ts +13 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +104 -8
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +31 -230
- package/src/core/resources/ignore.ts +0 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +11 -4
- package/src/core/retrieval/context.ts +363 -226
- package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +3 -3
- package/src/core/retrieval/typescript-references.ts +38 -7
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +192 -49
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +255 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -746
- package/src/mcp/server.ts +269 -429
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +68 -3
- package/src/mcp/tools/map.ts +104 -4
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +469 -17
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +88 -15
- package/src/mcp/workspace-watcher.ts +30 -11
- package/src/types/index.ts +12 -0
- package/src/mcp/tools/check-boundary.ts +0 -382
- package/src/mcp/tools/get-domain-catalog.ts +0 -39
- package/src/mcp/tools/get-symbol-impact.ts +0 -104
- package/src/mcp/tools/locate-symbol.ts +0 -236
- package/src/mcp/tools/register-domain.ts +0 -113
- package/src/mcp/tools/trace-vertical-slice.ts +0 -106
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import appHtmlPath from "./ui/app.html" with { type: "file" };
|
|
5
|
+
import type { WorkspaceManager } from "./workspace-manager.ts";
|
|
6
|
+
import { isWorkspaceInitialized, resolveServerWorkspace } from "./workspace-manager.ts";
|
|
7
|
+
import { handleGetDomainCatalog } from "./tools/map.ts";
|
|
8
|
+
import { runWorkspaceBoundary } from "./workspace-boundary.ts";
|
|
9
|
+
import { RESOURCE_LIMITS } from "../core/resources/limits.ts";
|
|
10
|
+
|
|
11
|
+
export const SEPTUM_RESOURCES = [
|
|
12
|
+
{
|
|
13
|
+
uri: "septum://domains",
|
|
14
|
+
name: "Septum Domain Catalog",
|
|
15
|
+
description: "Indexed domain catalog and cross-domain import adjacency for the server's initial workspace.",
|
|
16
|
+
mimeType: "application/json",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
uri: "septum://health",
|
|
20
|
+
name: "Septum Index Health",
|
|
21
|
+
description: "Index status, last synchronization, and indexed counts for the server's initial workspace.",
|
|
22
|
+
mimeType: "application/json",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
uri: "septum://boundaries",
|
|
26
|
+
name: "Septum Boundary Audit",
|
|
27
|
+
description: "Static boundary and circular-dependency audit of the server's initial workspace.",
|
|
28
|
+
mimeType: "application/json",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
uri: "septum://apps",
|
|
32
|
+
name: "Septum MCP Apps & Coverage Guide",
|
|
33
|
+
description: "Interactive Septum MCP App entrypoints, active workspace coverage/partial-init diagnostics, and actionable next steps.",
|
|
34
|
+
mimeType: "application/json",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
uri: "ui://septum/app.html",
|
|
38
|
+
name: "Septum Architecture UI",
|
|
39
|
+
description: "Interactive MCP App UI for Septum architecture navigation, vertical slices, and boundary audits.",
|
|
40
|
+
mimeType: "text/html;profile=mcp-app",
|
|
41
|
+
_meta: { ui: { prefersBorder: true } },
|
|
42
|
+
},
|
|
43
|
+
] as const;
|
|
44
|
+
|
|
45
|
+
export { SEPTUM_PROMPTS, listSeptumPrompts, getSeptumPrompt } from "./workflow-playbooks.ts";
|
|
46
|
+
|
|
47
|
+
export function listSeptumResources() {
|
|
48
|
+
return { resources: [...SEPTUM_RESOURCES] };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const DOMAIN_TEMPLATE = {
|
|
52
|
+
uriTemplate: "septum://domain/{name}",
|
|
53
|
+
name: "Septum Domain Detail",
|
|
54
|
+
description: "Compact indexed navigation for one domain in the server's initial workspace.",
|
|
55
|
+
mimeType: "application/json",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export function listSeptumResourceTemplates() {
|
|
59
|
+
return { resourceTemplates: [DOMAIN_TEMPLATE] };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function matchDomainResource(uri: string): string | undefined {
|
|
63
|
+
const match = /^septum:\/\/domain\/([^/?#]+)$/.exec(uri);
|
|
64
|
+
if (!match) return;
|
|
65
|
+
try {
|
|
66
|
+
const domain = decodeURIComponent(match[1]!);
|
|
67
|
+
if (domain.trim() && domain.length <= 256) return domain;
|
|
68
|
+
} catch { /* Invalid URI encoding. */ }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function readIndexHealth(manager: WorkspaceManager, root: string) {
|
|
72
|
+
const ctx = manager.peek(root);
|
|
73
|
+
if (!ctx) {
|
|
74
|
+
return {
|
|
75
|
+
workspace_root: root,
|
|
76
|
+
status: isWorkspaceInitialized(root) ? "inactive" : "not_indexed",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const syncState = ctx.repo.getMeta("sync_state") ?? "unindexed";
|
|
81
|
+
const syncError = ctx.repo.getMeta("sync_error") || undefined;
|
|
82
|
+
return {
|
|
83
|
+
workspace_root: ctx.root,
|
|
84
|
+
status: syncError ? "error" : syncState,
|
|
85
|
+
sync_state: syncState,
|
|
86
|
+
sync_error: syncError,
|
|
87
|
+
last_sync: ctx.repo.getMeta("last_sync"),
|
|
88
|
+
domains_count: ctx.repo.getAllDomains().length,
|
|
89
|
+
files_count: ctx.repo.countFiles(),
|
|
90
|
+
slices_count: ctx.repo.countVerticalSlices(),
|
|
91
|
+
watcher: {
|
|
92
|
+
mode: ctx.watcher.mode,
|
|
93
|
+
watch_count: ctx.watcher.watchCount,
|
|
94
|
+
pending_paths: ctx.watcher.pendingCount,
|
|
95
|
+
syncing: ctx.watcher.isBusy,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function jsonResource(uri: string, text: string) {
|
|
101
|
+
return { contents: [{ uri, mimeType: "application/json", text }] };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function buildAppsGuide(manager: WorkspaceManager, root: string) {
|
|
105
|
+
const initialized = isWorkspaceInitialized(root);
|
|
106
|
+
const health = readIndexHealth(manager, root);
|
|
107
|
+
const ctx = manager.peek(root);
|
|
108
|
+
|
|
109
|
+
let unsupportedFiles: string[] = [];
|
|
110
|
+
let skippedFiles: Array<{ path: string; reason?: string }> = [];
|
|
111
|
+
let slicesDirty = false;
|
|
112
|
+
if (ctx) {
|
|
113
|
+
try { unsupportedFiles = JSON.parse(ctx.repo.getMeta("unsupported_files") || "[]"); } catch { /* ignore */ }
|
|
114
|
+
try { skippedFiles = JSON.parse(ctx.repo.getMeta("skipped_files") || "[]"); } catch { /* ignore */ }
|
|
115
|
+
slicesDirty = ctx.repo.getMeta("slices_dirty") === "1";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const actionableActions: Array<{ action: string; reason: string; command?: string; tool?: string }> = [];
|
|
119
|
+
if (!initialized) {
|
|
120
|
+
actionableActions.push({
|
|
121
|
+
action: "Initialize Septum index",
|
|
122
|
+
reason: "Workspace has not been initialized yet.",
|
|
123
|
+
command: "septum init",
|
|
124
|
+
tool: "septum_map({ action: 'register', name: 'core', root: 'src', ingest_now: true })",
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
if (slicesDirty || health.sync_state !== "complete") {
|
|
128
|
+
actionableActions.push({
|
|
129
|
+
action: "Re-sync workspace index",
|
|
130
|
+
reason: slicesDirty ? "Entrypoint slice catalog is marked dirty." : `Index state is '${health.sync_state}'.`,
|
|
131
|
+
command: "septum sync",
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (unsupportedFiles.length > 0) {
|
|
135
|
+
actionableActions.push({
|
|
136
|
+
action: "Review unsupported files",
|
|
137
|
+
reason: `${unsupportedFiles.length} file(s) use extensions or languages not covered by Septum AST extractors.`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (skippedFiles.length > 0) {
|
|
141
|
+
actionableActions.push({
|
|
142
|
+
action: "Review skipped files",
|
|
143
|
+
reason: `${skippedFiles.length} file(s) were skipped during ingestion (e.g., outside registered domains or ignored).`,
|
|
144
|
+
tool: "septum_map({ action: 'register', name: '<domain>', root: '<dir>', ingest_now: true })",
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const coverageStatus = !initialized
|
|
150
|
+
? "not_indexed"
|
|
151
|
+
: (health.sync_state === "complete" && !slicesDirty && unsupportedFiles.length === 0 && skippedFiles.length === 0)
|
|
152
|
+
? "complete"
|
|
153
|
+
: "partial";
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
workspace_root: root,
|
|
157
|
+
ui_resource: "ui://septum/app.html",
|
|
158
|
+
open_via_tools: ["septum_map", "septum_slice", "septum_boundary"],
|
|
159
|
+
antigravity_entrypoints: [
|
|
160
|
+
{ type: "aux_pane", title: "Septum Architecture" },
|
|
161
|
+
{ type: "global", title: "Septum" },
|
|
162
|
+
],
|
|
163
|
+
coverage_status: coverageStatus,
|
|
164
|
+
health,
|
|
165
|
+
partial_details: {
|
|
166
|
+
unsupported_files_count: unsupportedFiles.length,
|
|
167
|
+
unsupported_files_sample: unsupportedFiles.slice(0, 15),
|
|
168
|
+
skipped_files_count: skippedFiles.length,
|
|
169
|
+
skipped_files_sample: skippedFiles.slice(0, 15),
|
|
170
|
+
slices_dirty: slicesDirty,
|
|
171
|
+
},
|
|
172
|
+
actionable_actions: actionableActions,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function parseResourceUri(uri: string): { baseUri: string; workspaceParam?: string } {
|
|
177
|
+
const qIdx = uri.indexOf("?");
|
|
178
|
+
if (qIdx === -1) return { baseUri: uri };
|
|
179
|
+
const baseUri = uri.slice(0, qIdx);
|
|
180
|
+
const params = new URLSearchParams(uri.slice(qIdx + 1));
|
|
181
|
+
const ws = params.get("workspace")?.trim();
|
|
182
|
+
return { baseUri, workspaceParam: ws || undefined };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function loadSeptumAppHtml(): string {
|
|
186
|
+
const envPath = process.env.SEPTUM_APP_HTML?.trim();
|
|
187
|
+
const candidates = [
|
|
188
|
+
...(envPath ? [resolve(envPath)] : []),
|
|
189
|
+
...(typeof appHtmlPath === "string" ? [appHtmlPath] : []),
|
|
190
|
+
resolve(import.meta.dir, "ui/app.html"),
|
|
191
|
+
resolve(process.cwd(), "src/mcp/ui/app.html"),
|
|
192
|
+
];
|
|
193
|
+
for (const candidate of candidates) {
|
|
194
|
+
if (existsSync(candidate)) {
|
|
195
|
+
return readFileSync(candidate, "utf8");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
throw new Error("Septum Architecture UI bundle not found. Run 'bun run build:ui' or set SEPTUM_APP_HTML.");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export async function readSeptumResource(manager: WorkspaceManager, uri: string, signal?: AbortSignal) {
|
|
202
|
+
const { baseUri, workspaceParam } = parseResourceUri(uri);
|
|
203
|
+
const validUri = SEPTUM_RESOURCES.some((r) => r.uri === baseUri);
|
|
204
|
+
const domain = matchDomainResource(baseUri);
|
|
205
|
+
if (!validUri && !domain) {
|
|
206
|
+
throw new McpError(-32002, "Resource not found", { uri });
|
|
207
|
+
}
|
|
208
|
+
signal?.throwIfAborted();
|
|
209
|
+
if (baseUri === "ui://septum/app.html") {
|
|
210
|
+
const html = loadSeptumAppHtml();
|
|
211
|
+
return {
|
|
212
|
+
contents: [
|
|
213
|
+
{
|
|
214
|
+
uri,
|
|
215
|
+
mimeType: "text/html;profile=mcp-app",
|
|
216
|
+
text: html,
|
|
217
|
+
_meta: { ui: { prefersBorder: true } },
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const root = workspaceParam
|
|
223
|
+
? resolveServerWorkspace({ workspacePath: workspaceParam, knownRoots: manager.activeRoots })
|
|
224
|
+
: (manager.lastRoot ?? manager.initialRoot ?? resolveServerWorkspace());
|
|
225
|
+
if (baseUri === "septum://apps") {
|
|
226
|
+
return jsonResource(uri, JSON.stringify(buildAppsGuide(manager, root), null, 2));
|
|
227
|
+
}
|
|
228
|
+
if (baseUri === "septum://health") {
|
|
229
|
+
return jsonResource(uri, JSON.stringify(readIndexHealth(manager, root)));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!isWorkspaceInitialized(root)) {
|
|
233
|
+
return jsonResource(uri, JSON.stringify({
|
|
234
|
+
status: "not_indexed",
|
|
235
|
+
workspace_root: root,
|
|
236
|
+
message: "Workspace is not initialized. Run 'septum init' or call septum_map(action='register').",
|
|
237
|
+
}, null, 2));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const lease = manager.acquire(root);
|
|
241
|
+
try {
|
|
242
|
+
const deadline = AbortSignal.timeout(RESOURCE_LIMITS.requestTimeoutMs);
|
|
243
|
+
const requestSignal = signal ? AbortSignal.any([signal, deadline]) : deadline;
|
|
244
|
+
const res = baseUri === "septum://boundaries"
|
|
245
|
+
? await runWorkspaceBoundary(manager, lease.context, { scope: "all", proposed_imports: [], proposed_imports_supplied: false, format: "json" }, {
|
|
246
|
+
signal: requestSignal,
|
|
247
|
+
})
|
|
248
|
+
: await manager.runInWorkspace(lease.context, async ctx =>
|
|
249
|
+
handleGetDomainCatalog(ctx.repo, ctx.config, { detail_level: "compact", domain, format: "json" }, ctx.root),
|
|
250
|
+
{ signal: requestSignal });
|
|
251
|
+
return jsonResource(uri, res.content[0]!.text);
|
|
252
|
+
} finally {
|
|
253
|
+
lease.release();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { extractSingleStringFallback } from "./shared.ts";
|
|
3
|
+
|
|
4
|
+
export function normalizeBoundaryArgs(raw: unknown): unknown {
|
|
5
|
+
if (Array.isArray(raw) && raw.length > 1 && raw.every((item) => typeof item === "string")) {
|
|
6
|
+
raw = { file_paths: raw };
|
|
7
|
+
}
|
|
8
|
+
const coerced = extractSingleStringFallback(raw, "file_path", [
|
|
9
|
+
"action",
|
|
10
|
+
"plan_ref",
|
|
11
|
+
"workspace_path",
|
|
12
|
+
"max_bytes",
|
|
13
|
+
"workspacePath",
|
|
14
|
+
"workspace",
|
|
15
|
+
"project_root",
|
|
16
|
+
"projectRoot",
|
|
17
|
+
"scope",
|
|
18
|
+
"domain",
|
|
19
|
+
"domain_name",
|
|
20
|
+
"domainName",
|
|
21
|
+
"feature_key",
|
|
22
|
+
"featureKey",
|
|
23
|
+
"feature",
|
|
24
|
+
"feature_name",
|
|
25
|
+
"featureName",
|
|
26
|
+
"name",
|
|
27
|
+
"key",
|
|
28
|
+
"format",
|
|
29
|
+
"output_format",
|
|
30
|
+
"outputFormat",
|
|
31
|
+
]);
|
|
32
|
+
if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
|
|
33
|
+
const obj = { ...(coerced as Record<string, unknown>) };
|
|
34
|
+
const aliases: Record<string, string> = {
|
|
35
|
+
filePath: "file_path",
|
|
36
|
+
file: "file_path",
|
|
37
|
+
path: "file_path",
|
|
38
|
+
from_file: "file_path",
|
|
39
|
+
fromFile: "file_path",
|
|
40
|
+
source_file: "file_path",
|
|
41
|
+
sourceFile: "file_path",
|
|
42
|
+
filePaths: "file_paths",
|
|
43
|
+
files: "file_paths",
|
|
44
|
+
paths: "file_paths",
|
|
45
|
+
proposedImports: "proposed_imports",
|
|
46
|
+
imports: "proposed_imports",
|
|
47
|
+
featureKey: "feature_key",
|
|
48
|
+
feature: "feature_key",
|
|
49
|
+
feature_name: "feature_key",
|
|
50
|
+
featureName: "feature_key",
|
|
51
|
+
name: "feature_key",
|
|
52
|
+
key: "feature_key",
|
|
53
|
+
domain_name: "domain",
|
|
54
|
+
domainName: "domain",
|
|
55
|
+
output_format: "format",
|
|
56
|
+
outputFormat: "format",
|
|
57
|
+
workspace: "workspace_path",
|
|
58
|
+
workspacePath: "workspace_path",
|
|
59
|
+
project_root: "workspace_path",
|
|
60
|
+
projectRoot: "workspace_path",
|
|
61
|
+
};
|
|
62
|
+
obj.proposed_imports_supplied ??= ["proposed_imports", "proposedImports", "imports", "to_file", "toFile"].some(key => Object.prototype.hasOwnProperty.call(obj, key));
|
|
63
|
+
for (const [alias, target] of Object.entries(aliases)) {
|
|
64
|
+
if (obj[alias] !== undefined && obj[target] === undefined) {
|
|
65
|
+
obj[target] = obj[alias];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (obj.feature_key !== undefined && obj.feature === undefined) {
|
|
70
|
+
obj.feature = obj.feature_key;
|
|
71
|
+
} else if (obj.feature !== undefined && obj.feature_key === undefined) {
|
|
72
|
+
obj.feature_key = obj.feature;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (obj.to_file || obj.toFile) {
|
|
76
|
+
const rawTo = obj.to_file ?? obj.toFile;
|
|
77
|
+
const toFiles = Array.isArray(rawTo) ? rawTo.map(String) : [String(rawTo)];
|
|
78
|
+
if (!obj.proposed_imports) {
|
|
79
|
+
obj.proposed_imports = toFiles;
|
|
80
|
+
} else if (Array.isArray(obj.proposed_imports)) {
|
|
81
|
+
obj.proposed_imports = [...obj.proposed_imports, ...toFiles];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (Array.isArray(obj.file_path) && !obj.file_paths) {
|
|
85
|
+
obj.file_paths = obj.file_path;
|
|
86
|
+
delete obj.file_path;
|
|
87
|
+
}
|
|
88
|
+
if (typeof obj.file_paths === "string" && !obj.file_path) {
|
|
89
|
+
obj.file_path = obj.file_paths;
|
|
90
|
+
delete obj.file_paths;
|
|
91
|
+
}
|
|
92
|
+
if (obj.scope === undefined) {
|
|
93
|
+
if (obj.staged === true) {
|
|
94
|
+
obj.scope = "staged";
|
|
95
|
+
} else if (obj.domain !== undefined && obj.file_path === undefined && obj.file_paths === undefined) {
|
|
96
|
+
obj.scope = "domain";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return obj;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const CheckBoundarySchema = z.preprocess(
|
|
103
|
+
normalizeBoundaryArgs,
|
|
104
|
+
z.object({
|
|
105
|
+
file_path: z.string().trim().min(1, "file_path cannot be blank").optional(),
|
|
106
|
+
file_paths: z.array(z.string().trim().min(1, "file_paths cannot contain blank paths")).optional(),
|
|
107
|
+
proposed_imports: z.array(z.string()).optional().default([]),
|
|
108
|
+
proposed_imports_supplied: z.boolean().optional().default(false),
|
|
109
|
+
scope: z.enum(["file", "all", "staged", "domain"]).optional(),
|
|
110
|
+
domain: z.string().trim().min(1, "domain cannot be blank").optional(),
|
|
111
|
+
staged: z.boolean().optional(),
|
|
112
|
+
format: z.enum(["json", "text"]).optional().default("text"),
|
|
113
|
+
workspace_path: z.string().optional(),
|
|
114
|
+
max_bytes: z.number().int().min(512).max(2 * 1024 * 1024).optional(),
|
|
115
|
+
}).superRefine((args, ctx) => {
|
|
116
|
+
const hasBatch = Boolean(args.file_paths?.length);
|
|
117
|
+
const hasTarget = args.file_path !== undefined || hasBatch;
|
|
118
|
+
const scope = args.scope ?? (args.staged ? "staged" : hasTarget ? "file" : args.domain ? "domain" : "all");
|
|
119
|
+
if (args.file_path !== undefined && hasBatch) {
|
|
120
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["file_paths"], message: "Use either file_path or file_paths, not both." });
|
|
121
|
+
}
|
|
122
|
+
if (args.staged && scope !== "staged") {
|
|
123
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["staged"], message: "staged=true requires scope='staged'." });
|
|
124
|
+
}
|
|
125
|
+
if (scope === "file" && !hasTarget) {
|
|
126
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["file_path"], message: "scope='file' requires file_path or non-empty file_paths." });
|
|
127
|
+
}
|
|
128
|
+
if (scope !== "file" && hasTarget) {
|
|
129
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["scope"], message: `scope='${scope}' does not accept file targets. Use scope='file' for proposed-import checks.` });
|
|
130
|
+
}
|
|
131
|
+
if (scope === "domain" && !args.domain) {
|
|
132
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["domain"], message: "scope='domain' requires a registered domain name." });
|
|
133
|
+
}
|
|
134
|
+
if (scope === "all" && args.domain) {
|
|
135
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["domain"], message: "scope='all' checks the entire repository. Use scope='domain' to filter a domain." });
|
|
136
|
+
}
|
|
137
|
+
if (scope !== "file" && args.proposed_imports.length) {
|
|
138
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["proposed_imports"], message: "proposed_imports requires a file target and scope='file'." });
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
export type CheckBoundaryArgs = z.infer<typeof CheckBoundarySchema>;
|
|
143
|
+
|
|
144
|
+
export const BoundaryToolSchema = CheckBoundarySchema;
|
|
145
|
+
export type BoundaryToolArgs = CheckBoundaryArgs;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { extractSingleStringFallback, withAliases } from "./shared.ts";
|
|
3
|
+
|
|
4
|
+
export function normalizeDomainCatalogArgs(raw: unknown): unknown {
|
|
5
|
+
const coerced = extractSingleStringFallback(raw, "domain", [
|
|
6
|
+
"workspace_path",
|
|
7
|
+
"workspacePath",
|
|
8
|
+
"workspace",
|
|
9
|
+
"project_root",
|
|
10
|
+
"projectRoot",
|
|
11
|
+
"target_path",
|
|
12
|
+
"path",
|
|
13
|
+
"archetype_filter",
|
|
14
|
+
"archetype",
|
|
15
|
+
"archetypeFilter",
|
|
16
|
+
"type",
|
|
17
|
+
"detail_level",
|
|
18
|
+
"detailLevel",
|
|
19
|
+
"mode",
|
|
20
|
+
"format",
|
|
21
|
+
"file_filter",
|
|
22
|
+
"fileFilter",
|
|
23
|
+
"file",
|
|
24
|
+
"filter",
|
|
25
|
+
]);
|
|
26
|
+
if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
|
|
27
|
+
const obj = withAliases(coerced, {
|
|
28
|
+
domain_name: "domain",
|
|
29
|
+
domainName: "domain",
|
|
30
|
+
name: "domain",
|
|
31
|
+
archetype: "archetype_filter",
|
|
32
|
+
archetypeFilter: "archetype_filter",
|
|
33
|
+
type: "archetype_filter",
|
|
34
|
+
detailLevel: "detail_level",
|
|
35
|
+
mode: "detail_level",
|
|
36
|
+
output_format: "format",
|
|
37
|
+
outputFormat: "format",
|
|
38
|
+
fileFilter: "file_filter",
|
|
39
|
+
file: "file_filter",
|
|
40
|
+
filter: "file_filter",
|
|
41
|
+
workspace: "workspace_path",
|
|
42
|
+
workspacePath: "workspace_path",
|
|
43
|
+
project_root: "workspace_path",
|
|
44
|
+
projectRoot: "workspace_path",
|
|
45
|
+
target_path: "workspace_path",
|
|
46
|
+
path: "workspace_path",
|
|
47
|
+
}) as Record<string, unknown>;
|
|
48
|
+
if (obj.domain !== undefined && obj.name === undefined) {
|
|
49
|
+
obj.name = obj.domain;
|
|
50
|
+
} else if (obj.name !== undefined && obj.domain === undefined) {
|
|
51
|
+
obj.domain = obj.name;
|
|
52
|
+
}
|
|
53
|
+
if (obj.archetype_filter !== undefined && obj.archetype === undefined) {
|
|
54
|
+
obj.archetype = obj.archetype_filter;
|
|
55
|
+
} else if (obj.archetype !== undefined && obj.archetype_filter === undefined) {
|
|
56
|
+
obj.archetype_filter = obj.archetype;
|
|
57
|
+
}
|
|
58
|
+
if (obj.full === true && obj.detail_level === undefined) {
|
|
59
|
+
obj.detail_level = "full";
|
|
60
|
+
}
|
|
61
|
+
if (obj.format === "compact" || obj.format === "full") {
|
|
62
|
+
if (obj.detail_level === undefined) obj.detail_level = obj.format;
|
|
63
|
+
delete obj.format;
|
|
64
|
+
}
|
|
65
|
+
return obj;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const GetDomainCatalogSchema = z.preprocess(
|
|
69
|
+
normalizeDomainCatalogArgs,
|
|
70
|
+
z.object({
|
|
71
|
+
domain: z.string().optional(),
|
|
72
|
+
name: z.string().optional(),
|
|
73
|
+
archetype_filter: z.string().optional(),
|
|
74
|
+
archetype: z.string().optional(),
|
|
75
|
+
detail_level: z.enum(["compact", "full"]).optional().default("compact"),
|
|
76
|
+
format: z.enum(["json", "text"]).optional().default("text"),
|
|
77
|
+
file_filter: z.string().optional(),
|
|
78
|
+
file_offset: z.number().int().nonnegative().optional(),
|
|
79
|
+
file_limit: z.number().int().min(1).max(100).optional(),
|
|
80
|
+
include_evidence: z.boolean().optional(),
|
|
81
|
+
include_capabilities: z.boolean().optional(),
|
|
82
|
+
workspace_path: z.string().optional(),
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
export type GetDomainCatalogArgs = z.infer<typeof GetDomainCatalogSchema>;
|
|
86
|
+
|
|
87
|
+
export function normalizeRegisterDomainArgs(raw: unknown): unknown {
|
|
88
|
+
const coerced = extractSingleStringFallback(raw, "domain", [
|
|
89
|
+
"root",
|
|
90
|
+
"root_path",
|
|
91
|
+
"rootPath",
|
|
92
|
+
"path",
|
|
93
|
+
"root_dir",
|
|
94
|
+
"workspace_path",
|
|
95
|
+
"workspacePath",
|
|
96
|
+
"workspace",
|
|
97
|
+
"project_root",
|
|
98
|
+
"projectRoot",
|
|
99
|
+
]);
|
|
100
|
+
if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
|
|
101
|
+
const obj = withAliases(coerced, {
|
|
102
|
+
name: "domain",
|
|
103
|
+
domain_name: "domain",
|
|
104
|
+
domainName: "domain",
|
|
105
|
+
root_path: "root",
|
|
106
|
+
rootPath: "root",
|
|
107
|
+
path: "root",
|
|
108
|
+
allowedDependencies: "allowed_dependencies",
|
|
109
|
+
allowed: "allowed_dependencies",
|
|
110
|
+
forbiddenDependencies: "forbidden_dependencies",
|
|
111
|
+
forbidden: "forbidden_dependencies",
|
|
112
|
+
archetype: "archetypes",
|
|
113
|
+
ingestNow: "ingest_now",
|
|
114
|
+
workspace: "workspace_path",
|
|
115
|
+
workspacePath: "workspace_path",
|
|
116
|
+
project_root: "workspace_path",
|
|
117
|
+
projectRoot: "workspace_path",
|
|
118
|
+
}) as Record<string, unknown>;
|
|
119
|
+
if (obj.domain !== undefined && obj.name === undefined) {
|
|
120
|
+
obj.name = obj.domain;
|
|
121
|
+
} else if (obj.name !== undefined && obj.domain === undefined) {
|
|
122
|
+
obj.domain = obj.name;
|
|
123
|
+
}
|
|
124
|
+
return obj;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const RegisterDomainSchema = z.preprocess(
|
|
128
|
+
normalizeRegisterDomainArgs,
|
|
129
|
+
z.object({
|
|
130
|
+
domain: z.string().min(1, "Domain name/identifier is required"),
|
|
131
|
+
name: z.string().optional(),
|
|
132
|
+
root: z.string().min(1, "Domain root path is required"),
|
|
133
|
+
description: z.string().optional(),
|
|
134
|
+
allowed_dependencies: z.array(z.string()).optional(),
|
|
135
|
+
forbidden_dependencies: z.array(z.string()).optional(),
|
|
136
|
+
archetypes: z.record(z.string()).optional(),
|
|
137
|
+
ingest_now: z.boolean().optional().default(false),
|
|
138
|
+
workspace_path: z.string().optional(),
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
export type RegisterDomainArgs = z.infer<typeof RegisterDomainSchema>;
|
|
142
|
+
|
|
143
|
+
export function normalizeMapToolArgs(raw: unknown): unknown {
|
|
144
|
+
const coerced = extractSingleStringFallback(raw, "domain", [
|
|
145
|
+
"workspace_path",
|
|
146
|
+
"workspacePath",
|
|
147
|
+
"workspace",
|
|
148
|
+
"project_root",
|
|
149
|
+
"projectRoot",
|
|
150
|
+
"target_path",
|
|
151
|
+
"path",
|
|
152
|
+
"action",
|
|
153
|
+
"detail_level",
|
|
154
|
+
"detailLevel",
|
|
155
|
+
"mode",
|
|
156
|
+
"format",
|
|
157
|
+
"archetype_filter",
|
|
158
|
+
"archetype",
|
|
159
|
+
"file_filter",
|
|
160
|
+
"fileFilter",
|
|
161
|
+
"root",
|
|
162
|
+
"root_path",
|
|
163
|
+
"rootPath",
|
|
164
|
+
]);
|
|
165
|
+
if (typeof coerced !== "object" || coerced === null || Array.isArray(coerced)) return coerced;
|
|
166
|
+
const obj = withAliases(coerced, {
|
|
167
|
+
domain_name: "domain",
|
|
168
|
+
domainName: "domain",
|
|
169
|
+
name: "domain",
|
|
170
|
+
archetype: "archetype_filter",
|
|
171
|
+
archetypeFilter: "archetype_filter",
|
|
172
|
+
type: "archetype_filter",
|
|
173
|
+
detailLevel: "detail_level",
|
|
174
|
+
mode: "detail_level",
|
|
175
|
+
output_format: "format",
|
|
176
|
+
outputFormat: "format",
|
|
177
|
+
fileFilter: "file_filter",
|
|
178
|
+
file: "file_filter",
|
|
179
|
+
filter: "file_filter",
|
|
180
|
+
root_path: "root",
|
|
181
|
+
rootPath: "root",
|
|
182
|
+
path: "root",
|
|
183
|
+
allowedDependencies: "allowed_dependencies",
|
|
184
|
+
allowed: "allowed_dependencies",
|
|
185
|
+
forbiddenDependencies: "forbidden_dependencies",
|
|
186
|
+
forbidden: "forbidden_dependencies",
|
|
187
|
+
archetypes: "archetypes",
|
|
188
|
+
ingestNow: "ingest_now",
|
|
189
|
+
workspace: "workspace_path",
|
|
190
|
+
workspacePath: "workspace_path",
|
|
191
|
+
project_root: "workspace_path",
|
|
192
|
+
projectRoot: "workspace_path",
|
|
193
|
+
}) as Record<string, unknown>;
|
|
194
|
+
|
|
195
|
+
if (obj.domain !== undefined && obj.name === undefined) {
|
|
196
|
+
obj.name = obj.domain;
|
|
197
|
+
} else if (obj.name !== undefined && obj.domain === undefined) {
|
|
198
|
+
obj.domain = obj.name;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (obj.archetype_filter !== undefined && obj.archetype === undefined) {
|
|
202
|
+
obj.archetype = obj.archetype_filter;
|
|
203
|
+
} else if (obj.archetype !== undefined && obj.archetype_filter === undefined) {
|
|
204
|
+
obj.archetype_filter = obj.archetype;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (obj.full === true && obj.detail_level === undefined) {
|
|
208
|
+
obj.detail_level = "full";
|
|
209
|
+
}
|
|
210
|
+
if (obj.format === "compact" || obj.format === "full") {
|
|
211
|
+
if (obj.detail_level === undefined) obj.detail_level = obj.format;
|
|
212
|
+
delete obj.format;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!obj.action) {
|
|
216
|
+
if (obj.root !== undefined || obj.ingest_now !== undefined) {
|
|
217
|
+
obj.action = "register";
|
|
218
|
+
} else {
|
|
219
|
+
obj.action = "catalog";
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return obj;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export const MapToolSchema = z.preprocess(
|
|
227
|
+
normalizeMapToolArgs,
|
|
228
|
+
z.object({
|
|
229
|
+
action: z.enum(["catalog", "register"]).optional().default("catalog"),
|
|
230
|
+
domain: z.string().optional(),
|
|
231
|
+
name: z.string().optional(),
|
|
232
|
+
detail_level: z.enum(["compact", "full"]).optional().default("compact"),
|
|
233
|
+
format: z.enum(["json", "text"]).optional().default("text"),
|
|
234
|
+
archetype_filter: z.string().optional(),
|
|
235
|
+
archetype: z.string().optional(),
|
|
236
|
+
file_filter: z.string().optional(),
|
|
237
|
+
file_offset: z.number().int().nonnegative().optional(),
|
|
238
|
+
file_limit: z.number().int().min(1).max(100).optional(),
|
|
239
|
+
include_evidence: z.boolean().optional(),
|
|
240
|
+
include_capabilities: z.boolean().optional(),
|
|
241
|
+
root: z.string().optional(),
|
|
242
|
+
description: z.string().optional(),
|
|
243
|
+
allowed_dependencies: z.array(z.string()).optional(),
|
|
244
|
+
forbidden_dependencies: z.array(z.string()).optional(),
|
|
245
|
+
archetypes: z.record(z.string()).optional(),
|
|
246
|
+
ingest_now: z.boolean().optional().default(false),
|
|
247
|
+
workspace_path: z.string().optional(),
|
|
248
|
+
})
|
|
249
|
+
);
|
|
250
|
+
export type MapToolArgs = z.infer<typeof MapToolSchema>;
|