archidocs 0.0.0-stage → 1.2.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.
- package/LICENSE +21 -0
- package/README.md +181 -2
- package/dist/cli/commands.d.ts +322 -0
- package/dist/cli/commands.js +174 -0
- package/dist/cli/dev.d.ts +31 -0
- package/dist/cli/dev.js +156 -0
- package/dist/cli/diff-format.d.ts +9 -0
- package/dist/cli/diff-format.js +50 -0
- package/dist/cli/format.d.ts +15 -0
- package/dist/cli/format.js +64 -0
- package/dist/cli/init.d.ts +17 -0
- package/dist/cli/init.js +82 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +330 -0
- package/dist/core/adr.d.ts +28 -0
- package/dist/core/adr.js +88 -0
- package/dist/core/adrs.d.ts +20 -0
- package/dist/core/adrs.js +86 -0
- package/dist/core/catalogue.d.ts +7 -0
- package/dist/core/catalogue.js +35 -0
- package/dist/core/compare.d.ts +21 -0
- package/dist/core/compare.js +62 -0
- package/dist/core/deployment-views.d.ts +28 -0
- package/dist/core/deployment-views.js +108 -0
- package/dist/core/deployments.d.ts +18 -0
- package/dist/core/deployments.js +21 -0
- package/dist/core/diff.d.ts +44 -0
- package/dist/core/diff.js +138 -0
- package/dist/core/dynamic-views.d.ts +73 -0
- package/dist/core/dynamic-views.js +162 -0
- package/dist/core/files.d.ts +2 -0
- package/dist/core/files.js +1 -0
- package/dist/core/fs.d.ts +19 -0
- package/dist/core/fs.js +21 -0
- package/dist/core/history-scope.d.ts +40 -0
- package/dist/core/history-scope.js +63 -0
- package/dist/core/impact.d.ts +34 -0
- package/dist/core/impact.js +62 -0
- package/dist/core/index.d.ts +20 -0
- package/dist/core/index.js +18 -0
- package/dist/core/load.d.ts +32 -0
- package/dist/core/load.js +465 -0
- package/dist/core/model.d.ts +150 -0
- package/dist/core/model.js +1 -0
- package/dist/core/ownership.d.ts +34 -0
- package/dist/core/ownership.js +65 -0
- package/dist/core/paths.d.ts +47 -0
- package/dist/core/paths.js +115 -0
- package/dist/core/query.d.ts +51 -0
- package/dist/core/query.js +77 -0
- package/dist/core/refs.d.ts +31 -0
- package/dist/core/refs.js +50 -0
- package/dist/core/rules.d.ts +41 -0
- package/dist/core/rules.js +1033 -0
- package/dist/core/save-as-view.d.ts +45 -0
- package/dist/core/save-as-view.js +114 -0
- package/dist/core/saved-views.d.ts +48 -0
- package/dist/core/saved-views.js +243 -0
- package/dist/core/schema-check.d.ts +13 -0
- package/dist/core/schema-check.js +79 -0
- package/dist/core/search.d.ts +27 -0
- package/dist/core/search.js +63 -0
- package/dist/core/suggest.d.ts +3 -0
- package/dist/core/suggest.js +30 -0
- package/dist/core/views.d.ts +126 -0
- package/dist/core/views.js +217 -0
- package/dist/core/yaml.d.ts +16 -0
- package/dist/core/yaml.js +52 -0
- package/dist/git.d.ts +7 -0
- package/dist/git.js +23 -0
- package/dist/guide/index.d.ts +53 -0
- package/dist/guide/index.js +57 -0
- package/dist/history/git.d.ts +39 -0
- package/dist/history/git.js +126 -0
- package/dist/history/index.d.ts +118 -0
- package/dist/history/index.js +223 -0
- package/dist/history/migrate.d.ts +16 -0
- package/dist/history/migrate.js +30 -0
- package/dist/mcp/history.d.ts +36 -0
- package/dist/mcp/history.js +175 -0
- package/dist/mcp/http.d.ts +23 -0
- package/dist/mcp/http.js +85 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/server.d.ts +54 -0
- package/dist/mcp/server.js +824 -0
- package/dist/mcp/source.d.ts +50 -0
- package/dist/mcp/source.js +132 -0
- package/dist/mcp/writes.d.ts +10 -0
- package/dist/mcp/writes.js +267 -0
- package/dist/render/font.d.ts +14 -0
- package/dist/render/font.js +11 -0
- package/dist/render/index.d.ts +8 -0
- package/dist/render/index.js +8 -0
- package/dist/render/layout.d.ts +53 -0
- package/dist/render/layout.js +199 -0
- package/dist/render/node.d.ts +3 -0
- package/dist/render/node.js +8 -0
- package/dist/render/png.d.ts +11 -0
- package/dist/render/png.js +29 -0
- package/dist/render/sequence-svg.d.ts +33 -0
- package/dist/render/sequence-svg.js +98 -0
- package/dist/render/sequence.d.ts +103 -0
- package/dist/render/sequence.js +142 -0
- package/dist/render/svg.d.ts +36 -0
- package/dist/render/svg.js +222 -0
- package/dist/render/teams.d.ts +12 -0
- package/dist/render/teams.js +31 -0
- package/dist/render/text.d.ts +15 -0
- package/dist/render/text.js +29 -0
- package/dist/render/tokens.d.ts +53 -0
- package/dist/render/tokens.js +71 -0
- package/dist/schema/adr.d.ts +36 -0
- package/dist/schema/adr.js +27 -0
- package/dist/schema/bundle.d.ts +726 -0
- package/dist/schema/bundle.js +171 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.js +4 -0
- package/dist/schema/json-schema.d.ts +8 -0
- package/dist/schema/json-schema.js +19 -0
- package/dist/schema/workspace.d.ts +1066 -0
- package/dist/schema/workspace.js +271 -0
- package/dist/viewer/assets/index-DvKgCpBr.css +1 -0
- package/dist/viewer/assets/index-gucix3xm.js +113 -0
- package/dist/viewer/assets/index_bg-Blvrv-U2.wasm +0 -0
- package/dist/viewer/assets/index_bg-D3t31u3-.js +1 -0
- package/dist/viewer/assets/layout.worker-Bg-OaLVN.js +26 -0
- package/dist/viewer/assets/overpass-latin-QyaMbcmi.woff2 +0 -0
- package/dist/viewer/assets/overpass-latin-ext-DSRhPfzW.woff2 +0 -0
- package/dist/viewer/assets/overpass-mono-latin-BTquVRaO.woff2 +0 -0
- package/dist/viewer/assets/overpass-mono-latin-ext-D47EiU4_.woff2 +0 -0
- package/dist/viewer/assets/png-BDKIXtm5.js +1 -0
- package/dist/viewer/assets/svg-Bulv5YWn.js +2 -0
- package/dist/viewer/favicon.svg +1 -0
- package/dist/viewer/index.html +53 -0
- package/dist/writer/adrs.d.ts +21 -0
- package/dist/writer/adrs.js +72 -0
- package/dist/writer/deployments.d.ts +51 -0
- package/dist/writer/deployments.js +145 -0
- package/dist/writer/diff.d.ts +6 -0
- package/dist/writer/diff.js +77 -0
- package/dist/writer/document.d.ts +25 -0
- package/dist/writer/document.js +79 -0
- package/dist/writer/edit.d.ts +78 -0
- package/dist/writer/edit.js +63 -0
- package/dist/writer/index.d.ts +67 -0
- package/dist/writer/index.js +310 -0
- package/dist/writer/overlay.d.ts +7 -0
- package/dist/writer/overlay.js +26 -0
- package/dist/writer/views.d.ts +29 -0
- package/dist/writer/views.js +78 -0
- package/dist/writer/workspace.d.ts +25 -0
- package/dist/writer/workspace.js +56 -0
- package/guide/SKILL.md +36 -0
- package/guide/topics/add-service.md +30 -0
- package/guide/topics/bootstrap.md +28 -0
- package/guide/topics/change.md +32 -0
- package/guide/topics/deployments.md +36 -0
- package/guide/topics/dynamic-view.md +39 -0
- package/guide/topics/propose-adr.md +12 -0
- package/guide/topics/relationships.md +39 -0
- package/guide/topics/saved-view.md +36 -0
- package/package.json +75 -4
- package/schemas/adr.schema.json +82 -0
- package/schemas/model.schema.json +1381 -0
- package/schemas/project.schema.json +24 -0
- package/schemas/workspace.schema.json +72 -0
|
@@ -0,0 +1,824 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { getDeployments } from "../core/deployments.js";
|
|
4
|
+
import { withDocs } from "../core/rules.js";
|
|
5
|
+
import { search } from "../core/search.js";
|
|
6
|
+
import { changeKinds, countChanges, deriveEdges, diff, filterChanges, findPaths, getImpact, levelOf, listOwned, resolveScope, scopeMatcher, } from "../core/index.js";
|
|
7
|
+
import { suggest } from "../core/suggest.js";
|
|
8
|
+
import { listViews, resolveView } from "../core/views.js";
|
|
9
|
+
import { resolveDynamic, resolveDynamicView, takesPart } from "../core/dynamic-views.js";
|
|
10
|
+
import { describeLens } from "../core/saved-views.js";
|
|
11
|
+
import { listAdrs } from "../core/adrs.js";
|
|
12
|
+
import { AdrStatus } from "../schema/adr.js";
|
|
13
|
+
import { BundleAdr, BundleDeployment, BundleElement, BundleLens, BundleRelationship } from "../schema/bundle.js";
|
|
14
|
+
import { pastOf } from "./history.js";
|
|
15
|
+
import { registerWriteTools } from "./writes.js";
|
|
16
|
+
import { authoringGuide, topics } from "../guide/index.js";
|
|
17
|
+
const ok = (data, text) => ({ ok: true, data, text });
|
|
18
|
+
const fail = (code, message, suggestions) => ({ ok: false, code, message, ...(suggestions ? { suggestions } : {}) });
|
|
19
|
+
/**
|
|
20
|
+
* The Archidocs MCP server: stateless tools over one Source. Every result is
|
|
21
|
+
* `structuredContent` plus a compact Markdown copy; a lookup that fails is a
|
|
22
|
+
* tool result with `isError` and `{code, message, suggestions?}`. Only a
|
|
23
|
+
* malformed request (unknown tool, arguments that are not an object) is a
|
|
24
|
+
* protocol error. Write tools return `read_only` unless both the source and
|
|
25
|
+
* the transport allow writes.
|
|
26
|
+
*/
|
|
27
|
+
export function createServer(options) {
|
|
28
|
+
const { source } = options;
|
|
29
|
+
const server = new McpServer({ name: "archidocs", version: "0.0.0" }, { capabilities: { tools: {} } });
|
|
30
|
+
const writesAllowed = source.writesAllowed && options.allowWrites !== false;
|
|
31
|
+
const readOnlyReason = source.kind === "bundle"
|
|
32
|
+
? `This server reads a published Bundle (${source.location}); write tools need a checkout.`
|
|
33
|
+
: "Write tools are off over HTTP; restart the server with --allow-writes to allow them.";
|
|
34
|
+
const past = pastOf(source);
|
|
35
|
+
/**
|
|
36
|
+
* Registers a tool. A read tool also takes `at` (a ref or a date) and runs
|
|
37
|
+
* over the Bundle there; a write tool refuses `at`.
|
|
38
|
+
*/
|
|
39
|
+
const tool = (name, config, run) => {
|
|
40
|
+
const input = config.write ? config.input : config.input.extend({ at: At.optional() });
|
|
41
|
+
server.registerTool(name, {
|
|
42
|
+
title: config.title,
|
|
43
|
+
description: config.description,
|
|
44
|
+
inputSchema: advertise(input),
|
|
45
|
+
outputSchema: config.output,
|
|
46
|
+
annotations: { readOnlyHint: !config.write, openWorldHint: false },
|
|
47
|
+
}, async (raw) => {
|
|
48
|
+
if (config.write && !writesAllowed)
|
|
49
|
+
return toResult(fail("read_only", readOnlyReason));
|
|
50
|
+
if (config.write && takesAt(raw))
|
|
51
|
+
return toResult(fail("invalid_input", atRefused));
|
|
52
|
+
const args = input.safeParse(raw ?? {});
|
|
53
|
+
if (!args.success)
|
|
54
|
+
return toResult(fail("invalid_input", z.prettifyError(args.error)));
|
|
55
|
+
const { at, ...rest } = args.data;
|
|
56
|
+
let snapshot;
|
|
57
|
+
try {
|
|
58
|
+
snapshot = await source.snapshot();
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return toResult(fail("source_unavailable", `Could not read the Workspace from ${where(source)}: ${error instanceof Error ? error.message : String(error)}`));
|
|
62
|
+
}
|
|
63
|
+
const current = snapshot;
|
|
64
|
+
if (at !== undefined) {
|
|
65
|
+
const then = await past.at(at, snapshot);
|
|
66
|
+
if (!then.ok)
|
|
67
|
+
return toResult(then);
|
|
68
|
+
snapshot = then.snapshot;
|
|
69
|
+
}
|
|
70
|
+
return toResult(await run(rest, snapshot, { past, at, current }));
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
tool("get_workspace_info", {
|
|
74
|
+
title: "Workspace info",
|
|
75
|
+
description: "Where this server reads the Workspace from, the commit it reflects, whether write tools are allowed, and how big the Model is.",
|
|
76
|
+
input: z.object({}),
|
|
77
|
+
output: z.object({
|
|
78
|
+
source: z.discriminatedUnion("kind", [
|
|
79
|
+
z.object({ kind: z.literal("checkout"), root: z.string() }),
|
|
80
|
+
z.object({ kind: z.literal("bundle"), location: z.string() }),
|
|
81
|
+
]),
|
|
82
|
+
commit: z.string().nullable(),
|
|
83
|
+
writesAllowed: z.boolean(),
|
|
84
|
+
counts: z.object({ projects: z.number(), elements: z.number(), teams: z.number(), environments: z.number() }),
|
|
85
|
+
issues: z.object({ errors: z.number(), warnings: z.number() }),
|
|
86
|
+
viewerUrl: z.string().optional(),
|
|
87
|
+
}),
|
|
88
|
+
}, (_, { bundle, issues }) => {
|
|
89
|
+
const counts = { projects: bundle.projects.length, elements: bundle.elements.length, teams: bundle.teams.length, environments: bundle.environments.length };
|
|
90
|
+
const errors = issues.filter((i) => i.severity === "error").length;
|
|
91
|
+
const data = {
|
|
92
|
+
source: source.kind === "checkout" ? { kind: source.kind, root: source.root } : { kind: source.kind, location: source.location },
|
|
93
|
+
commit: bundle.commit,
|
|
94
|
+
writesAllowed,
|
|
95
|
+
counts,
|
|
96
|
+
issues: { errors, warnings: issues.length - errors },
|
|
97
|
+
...(options.viewerUrl ? { viewerUrl: options.viewerUrl } : {}),
|
|
98
|
+
};
|
|
99
|
+
const at = bundle.commit ? `at ${bundle.commit.slice(0, 7)}` : "with no commit";
|
|
100
|
+
return ok(data, [
|
|
101
|
+
`Workspace from a ${source.kind === "checkout" ? "checkout" : "Bundle"} ${at} (${where(source)}); writes ${writesAllowed ? "allowed" : "off"}.`,
|
|
102
|
+
`- ${counts.projects} Projects, ${counts.elements} Elements, ${counts.teams} Teams, ${counts.environments} Environments`,
|
|
103
|
+
`- ${errors} errors, ${issues.length - errors} warnings from check`,
|
|
104
|
+
].join("\n"));
|
|
105
|
+
});
|
|
106
|
+
tool("get_element", {
|
|
107
|
+
title: "Get Element",
|
|
108
|
+
description: "One Element by qualified id (project:id): its fields, Owner Team, parent and children, the Relationships declared on it in and out, the edges derived onto it from its descendants', a Service's Deployments with their URLs, the Dynamic Views it takes part in (as a participant, or as the broker of an event Step), the ADRs linking it or its descendants (as list_adrs gives them), and the file and line it is declared at.",
|
|
109
|
+
input: z.object({ id: QualifiedId }),
|
|
110
|
+
output: z.object({
|
|
111
|
+
element: BundleElement,
|
|
112
|
+
owner: z.object({ id: z.string(), name: z.string() }).nullable(),
|
|
113
|
+
parent: ElementSummary.nullable(),
|
|
114
|
+
children: z.array(ElementSummary),
|
|
115
|
+
deployments: z.array(DeploymentResult),
|
|
116
|
+
relationships: z.object({ in: z.array(BundleRelationship), out: z.array(BundleRelationship) }),
|
|
117
|
+
derived: z.object({ in: z.array(Edge), out: z.array(Edge) }),
|
|
118
|
+
dynamicViews: z.array(z.object({ id: z.string(), title: z.string() })),
|
|
119
|
+
adrs: z.array(AdrSummary),
|
|
120
|
+
viewerUrl: z.string().optional(),
|
|
121
|
+
}),
|
|
122
|
+
}, ({ id }, { bundle }) => {
|
|
123
|
+
const element = bundle.elements.find((e) => e.id === id);
|
|
124
|
+
if (!element)
|
|
125
|
+
return notFound("Element", id, bundle.elements.map((e) => e.id));
|
|
126
|
+
const parent = bundle.elements.find((e) => e.id === element.parent);
|
|
127
|
+
const children = bundle.elements.filter((e) => e.parent === id);
|
|
128
|
+
const team = bundle.teams.find((t) => t.id === element.owner);
|
|
129
|
+
const deployments = getDeployments(bundle, id).map(deploymentResult);
|
|
130
|
+
const relationships = { in: bundle.relationships.filter((r) => r.to === id), out: bundle.relationships.filter((r) => r.from === id) };
|
|
131
|
+
// Edges at the Element's level that carry at least one Relationship declared beneath either end.
|
|
132
|
+
const derived = deriveEdges(bundle, levelOf(element)).filter((e) => e.relationships.some((r) => r.from !== e.from || r.to !== e.to));
|
|
133
|
+
const derivedEdges = { in: derived.filter((e) => e.to === id), out: derived.filter((e) => e.from === id) };
|
|
134
|
+
const dynamicViews = bundle.views.flatMap((v) => (v.kind === "dynamic" && takesPart(resolveDynamic(bundle, v).view, id) ? [{ id: v.id, title: v.title }] : []));
|
|
135
|
+
const data = {
|
|
136
|
+
element,
|
|
137
|
+
owner: team ? { id: team.id, name: team.name } : null,
|
|
138
|
+
parent: parent ? summary(parent) : null,
|
|
139
|
+
children: children.map(summary),
|
|
140
|
+
deployments,
|
|
141
|
+
relationships,
|
|
142
|
+
derived: derivedEdges,
|
|
143
|
+
dynamicViews,
|
|
144
|
+
adrs: listAdrs(bundle, { element: id }).map(adrSummary),
|
|
145
|
+
...viewerLink(options.viewerUrl, id),
|
|
146
|
+
};
|
|
147
|
+
const fields = [
|
|
148
|
+
["description", element.description],
|
|
149
|
+
["type", element.kind === "service" && element.type !== "app" ? element.type : null],
|
|
150
|
+
["technology", "technology" in element ? element.technology : null],
|
|
151
|
+
["external", "external" in element && element.external ? "yes" : null],
|
|
152
|
+
["tags", element.tags.join(", ")],
|
|
153
|
+
["links", element.links.map((l) => `[${l.label}](${l.url})`).join(", ")],
|
|
154
|
+
["children", children.map(label).join(", ")],
|
|
155
|
+
["deployments", deployments.map((d) => `${d.environment} on ${d.target}${d.url ? ` (${d.url})` : ""}`).join(", ")],
|
|
156
|
+
["uses", relationships.out.map((r) => `${r.to}${r.description ? ` (${r.description})` : ""}`).join(", ")],
|
|
157
|
+
["used by", relationships.in.map((r) => `${r.from}${r.description ? ` (${r.description})` : ""}`).join(", ")],
|
|
158
|
+
["ADRs", data.adrs.map((a) => `${a.id} ${a.title} (${statusLabel(a)})`).join(", ")],
|
|
159
|
+
[
|
|
160
|
+
"derived",
|
|
161
|
+
[...derivedEdges.out.map((e) => `→ ${e.to} (${count(e.relationships.length, "Relationship")})`), ...derivedEdges.in.map((e) => `← ${e.from} (${count(e.relationships.length, "Relationship")})`)].join(", "),
|
|
162
|
+
],
|
|
163
|
+
["Dynamic Views", dynamicViews.map((v) => v.id).join(", ")],
|
|
164
|
+
];
|
|
165
|
+
return ok(data, [
|
|
166
|
+
`${kindName[element.kind]} ${label(element)}, owned by ${element.owner || "no Team"}${parent ? `, in ${parent.id}` : ""}; ${element.source.file}:${element.source.line}.`,
|
|
167
|
+
...fields.filter(([, v]) => v).map(([k, v]) => `- ${k}: ${String(v)}`),
|
|
168
|
+
].join("\n"));
|
|
169
|
+
});
|
|
170
|
+
tool("search_elements", {
|
|
171
|
+
title: "Search Elements",
|
|
172
|
+
description: "Find Elements whose qualified id or name contains the query, or the Service behind a URL or host (a Deployment's url or an endpoint; a longer URL below one also matches). Case-insensitive. Exact matches come first, then prefixes, then the rest, each by id. A URL match carries the Deployment it matched.",
|
|
173
|
+
input: z.object({
|
|
174
|
+
query: z.string().min(1),
|
|
175
|
+
kind: z.enum(["person", "system", "service", "component"]).optional(),
|
|
176
|
+
limit: Limit,
|
|
177
|
+
}),
|
|
178
|
+
output: z.object({
|
|
179
|
+
query: z.string(),
|
|
180
|
+
total: z.number(),
|
|
181
|
+
truncated: z.boolean(),
|
|
182
|
+
elements: z.array(ElementSummary.extend({
|
|
183
|
+
owner: z.string(),
|
|
184
|
+
parent: z.string().nullable(),
|
|
185
|
+
deployment: z.object({ environment: z.string(), target: z.string(), url: z.string() }).optional(),
|
|
186
|
+
viewerUrl: z.string().optional(),
|
|
187
|
+
})),
|
|
188
|
+
}),
|
|
189
|
+
}, ({ query, kind, limit }, { bundle }) => {
|
|
190
|
+
const ranked = search(bundle, query, { kind }).map(({ element: e, deployment }) => ({
|
|
191
|
+
id: e.id,
|
|
192
|
+
kind: e.kind,
|
|
193
|
+
name: e.name,
|
|
194
|
+
owner: e.owner,
|
|
195
|
+
parent: e.parent,
|
|
196
|
+
...(deployment ? { deployment } : {}),
|
|
197
|
+
...viewerLink(options.viewerUrl, e.id),
|
|
198
|
+
}));
|
|
199
|
+
const { items, total, truncated } = page(ranked, limit);
|
|
200
|
+
const head = total === 0
|
|
201
|
+
? `No Elements match "${query}".`
|
|
202
|
+
: `${total} ${total === 1 ? "Element matches" : "Elements match"} "${query}"${truncated ? `; showing the first ${limit}` : ""}.`;
|
|
203
|
+
return ok({ query, total, truncated, elements: items }, [
|
|
204
|
+
head,
|
|
205
|
+
...items.map((e) => `- ${label(e)}: ${kindName[e.kind]}, ${e.owner || "no Team"}${e.deployment ? `; URL ${e.deployment.url} in ${e.deployment.environment}` : ""}`),
|
|
206
|
+
].join("\n"));
|
|
207
|
+
});
|
|
208
|
+
tool("get_deployments", {
|
|
209
|
+
title: "Get Deployments",
|
|
210
|
+
description: "Where a Service runs: each Deployment's Environment, its full Deployment Target chain (outermost first), main url and named endpoints. Pass `environment` for one Environment, e.g. a Service's URL in staging.",
|
|
211
|
+
input: z.object({
|
|
212
|
+
service: QualifiedId.describe("The Service's qualified id, project:id"),
|
|
213
|
+
environment: z.string().min(1).optional().describe("An Environment id, such as prod or staging"),
|
|
214
|
+
limit: Limit,
|
|
215
|
+
}),
|
|
216
|
+
output: z.object({
|
|
217
|
+
service: ElementSummary,
|
|
218
|
+
environment: z.string().nullable(),
|
|
219
|
+
total: z.number(),
|
|
220
|
+
truncated: z.boolean(),
|
|
221
|
+
deployments: z.array(DeploymentResult),
|
|
222
|
+
}),
|
|
223
|
+
}, ({ service: id, environment, limit }, { bundle }) => {
|
|
224
|
+
const service = bundle.elements.find((e) => e.id === id);
|
|
225
|
+
if (!service)
|
|
226
|
+
return notFound("Service", id, bundle.elements.filter((e) => e.kind === "service").map((e) => e.id));
|
|
227
|
+
if (service.kind !== "service")
|
|
228
|
+
return fail("invalid_input", `"${id}" is a ${kindName[service.kind]}, not a Service; only Services have Deployments.`);
|
|
229
|
+
if (environment !== undefined && !bundle.environments.some((e) => e.id === environment)) {
|
|
230
|
+
const near = suggest(environment, bundle.environments.map((e) => e.id));
|
|
231
|
+
return fail("not_found", `No Environment "${environment}".`, near ? [near] : undefined);
|
|
232
|
+
}
|
|
233
|
+
const { items, total, truncated } = page(getDeployments(bundle, id, environment).map(deploymentResult), limit);
|
|
234
|
+
const where = environment ? ` in ${environment}` : "";
|
|
235
|
+
const head = total === 0 ? `${label(service)} has no Deployments${where}.` : `${label(service)} has ${total} Deployment${total === 1 ? "" : "s"}${where}${truncated ? `; showing the first ${limit}` : ""}.`;
|
|
236
|
+
return ok({ service: summary(service), environment: environment ?? null, total, truncated, deployments: items }, [
|
|
237
|
+
head,
|
|
238
|
+
...items.map((d) => {
|
|
239
|
+
const chain = d.targetPath.length ? d.targetPath.map((t) => t.id).join(" › ") : d.target;
|
|
240
|
+
const urls = [d.url ?? "no URL", ...d.endpoints.map((e) => `${e.name}: ${e.url}`)].join("; ");
|
|
241
|
+
return `- ${d.environment} on ${chain}: ${urls}`;
|
|
242
|
+
}),
|
|
243
|
+
].join("\n"));
|
|
244
|
+
});
|
|
245
|
+
tool("list_teams", {
|
|
246
|
+
title: "List Teams",
|
|
247
|
+
description: "Every Team defined in the Workspace, with how many Elements each owns.",
|
|
248
|
+
input: z.object({ limit: Limit }),
|
|
249
|
+
output: z.object({
|
|
250
|
+
total: z.number(),
|
|
251
|
+
truncated: z.boolean(),
|
|
252
|
+
teams: z.array(z.object({ id: z.string(), name: z.string(), description: z.string().nullable(), links: z.array(z.object({ label: z.string(), url: z.string() })), elements: z.number() })),
|
|
253
|
+
}),
|
|
254
|
+
}, ({ limit }, { bundle }) => {
|
|
255
|
+
const teams = bundle.teams.map((t) => ({ id: t.id, name: t.name, description: t.description, links: t.links, elements: bundle.elements.filter((e) => e.owner === t.id).length }));
|
|
256
|
+
const { items, total, truncated } = page(teams, limit);
|
|
257
|
+
return ok({ total, truncated, teams: items }, [
|
|
258
|
+
listHead(total, "Team", truncated, limit),
|
|
259
|
+
...items.map((t) => `- ${label(t)}: owns ${t.elements} Element${t.elements === 1 ? "" : "s"}${t.description ? `; ${t.description}` : ""}`),
|
|
260
|
+
].join("\n"));
|
|
261
|
+
});
|
|
262
|
+
tool("list_environments", {
|
|
263
|
+
title: "List Environments",
|
|
264
|
+
description: "Every Environment defined in the Workspace.",
|
|
265
|
+
input: z.object({ limit: Limit }),
|
|
266
|
+
output: z.object({
|
|
267
|
+
total: z.number(),
|
|
268
|
+
truncated: z.boolean(),
|
|
269
|
+
environments: z.array(z.object({ id: z.string(), name: z.string(), description: z.string().nullable() })),
|
|
270
|
+
}),
|
|
271
|
+
}, ({ limit }, { bundle }) => {
|
|
272
|
+
const environments = bundle.environments.map((e) => ({ id: e.id, name: e.name, description: e.description }));
|
|
273
|
+
const { items, total, truncated } = page(environments, limit);
|
|
274
|
+
return ok({ total, truncated, environments: items }, [listHead(total, "Environment", truncated, limit), ...items.map((e) => `- ${label(e)}${e.description ? `: ${e.description}` : ""}`)].join("\n"));
|
|
275
|
+
});
|
|
276
|
+
tool("list_views", {
|
|
277
|
+
title: "List Views",
|
|
278
|
+
description: "The Generated Views: c1 and c2 (the Landscapes), c2/<system> and c3/<service> (Services with Components); then the Saved Views (project:view-id), structural ones listed under their level and Dynamic Views under `dynamic`. With `element`, only the Views that show that Element as a node, and the Dynamic Views it takes part in (as a participant, or as the broker an event Step runs via).",
|
|
279
|
+
input: z.object({
|
|
280
|
+
kind: ViewKind.optional(),
|
|
281
|
+
element: QualifiedId.optional().describe("Only Views containing this Element (project:id)"),
|
|
282
|
+
limit: Limit,
|
|
283
|
+
}),
|
|
284
|
+
output: z.object({ total: z.number(), truncated: z.boolean(), views: z.array(ViewSummary) }),
|
|
285
|
+
}, ({ kind, element, limit }, { bundle }) => {
|
|
286
|
+
if (element !== undefined && !bundle.elements.some((e) => e.id === element))
|
|
287
|
+
return notFound("Element", element, bundle.elements.map((e) => e.id));
|
|
288
|
+
const { items, total, truncated } = page(listViews(bundle, { kind, element }), limit);
|
|
289
|
+
return ok({ total, truncated, views: items }, [listHead(total, "View", truncated, limit), ...items.map((v) => `- ${v.id}: ${v.title}`)].join("\n"));
|
|
290
|
+
});
|
|
291
|
+
tool("get_view", {
|
|
292
|
+
title: "Get View",
|
|
293
|
+
description: "One View by id (c1, c2, c2/<system>, c3/<service>, deployment/<environment>, or a Saved View's project:view-id) as nodes and edges. Neighbours outside the focus are collapsed to the highest level that still separates them; each edge carries the declared Relationships beneath it. A Deployment View nests Deployment Targets (kind `target`), a System box per System inside each Target (id `<system>@<target>`) and the Deployments (kind `deployment`, id `<service>@<target>`, `element` the Service); a consumer Deployment connects to the provider's Deployments under their deepest shared Target, else to all of them, and a related Service with no Deployment there is a node outside every Target. A Saved View with a Lens also returns the Lens, a `mark` ({hit, distance?, side?}, `side` being origin, upstream or downstream for an impact Lens) per node and `lit` per edge; the Lens never changes which nodes the View holds. A Dynamic View instead returns `participants` in drawing order and `steps` [{n, kind: call|return|event, from, to, relationship, interaction, via?, channel?, description, note?}]: an event is drawn publisher → subscriber while `relationship` is the stored subscriber → publisher subscription; a return replies over the sync `relationship` the other way. Steps that don't resolve are left out (`check` reports them).",
|
|
294
|
+
input: z.object({ id: z.string().min(1).describe("A View id, such as c1, c2/shop:checkout, c3/shop:cart or architecture:purchase") }),
|
|
295
|
+
output: ViewSummary.extend({
|
|
296
|
+
direction: z.enum(["TB", "BT", "LR", "RL"]).optional(),
|
|
297
|
+
lens: BundleLens.optional(),
|
|
298
|
+
nodes: z
|
|
299
|
+
.array(z.object({
|
|
300
|
+
id: z.string(),
|
|
301
|
+
kind: z.enum([...ElementKind.options, "target", "deployment"]),
|
|
302
|
+
name: z.string(),
|
|
303
|
+
element: z.string().optional(),
|
|
304
|
+
parent: z.string().nullable(),
|
|
305
|
+
collapsed: z.boolean(),
|
|
306
|
+
external: z.boolean(),
|
|
307
|
+
mark: z.object({ hit: z.boolean(), distance: z.number().optional(), side: z.enum(["origin", "upstream", "downstream"]).optional() }).optional(),
|
|
308
|
+
}))
|
|
309
|
+
.optional(),
|
|
310
|
+
edges: z.array(z.object({ from: z.string(), to: z.string(), relationships: z.array(BundleRelationship), lit: z.boolean().optional() })).optional(),
|
|
311
|
+
participants: z.array(z.string()).optional(),
|
|
312
|
+
steps: z
|
|
313
|
+
.array(z.object({
|
|
314
|
+
n: z.number(),
|
|
315
|
+
kind: z.enum(["call", "return", "event"]),
|
|
316
|
+
from: z.string(),
|
|
317
|
+
to: z.string(),
|
|
318
|
+
relationship: BundleRelationship,
|
|
319
|
+
interaction: z.enum(["sync", "async"]),
|
|
320
|
+
via: z.string().optional(),
|
|
321
|
+
channel: z.string().optional(),
|
|
322
|
+
description: z.string(),
|
|
323
|
+
note: z.string().optional(),
|
|
324
|
+
}))
|
|
325
|
+
.optional(),
|
|
326
|
+
}),
|
|
327
|
+
}, ({ id }, { bundle }) => {
|
|
328
|
+
const dynamic = resolveDynamicView(bundle, id);
|
|
329
|
+
if (dynamic) {
|
|
330
|
+
return ok({ ...dynamic }, [
|
|
331
|
+
`${dynamic.title} (${dynamic.id}): ${count(dynamic.participants.length, "participant")}, ${count(dynamic.steps.length, "Step")}.`,
|
|
332
|
+
`Participants: ${dynamic.participants.join(", ")}`,
|
|
333
|
+
...(dynamic.steps.length ? ["Steps:", ...dynamic.steps.map(stepLine)] : []),
|
|
334
|
+
].join("\n"));
|
|
335
|
+
}
|
|
336
|
+
const view = resolveView(bundle, id);
|
|
337
|
+
if (!view)
|
|
338
|
+
return notFound("View", id, listViews(bundle).map((v) => v.id));
|
|
339
|
+
const edgeCount = `${view.edges.length} edge${view.edges.length === 1 ? "" : "s"}`;
|
|
340
|
+
return ok({ ...view }, [
|
|
341
|
+
`${view.title} (${view.id}): ${view.nodes.length} node${view.nodes.length === 1 ? "" : "s"}, ${edgeCount}.`,
|
|
342
|
+
...(view.lens ? [`Lens: ${describeLens(view.lens)}.`] : []),
|
|
343
|
+
"Nodes:",
|
|
344
|
+
...view.nodes.map(nodeLine),
|
|
345
|
+
...(view.edges.length ? ["Edges:", ...view.edges.map((e) => `- ${e.from} → ${e.to}: ${e.relationships.map(relationshipLabel).join("; ")}${e.lit ? " (lit)" : ""}`)] : []),
|
|
346
|
+
].join("\n"));
|
|
347
|
+
});
|
|
348
|
+
tool("find_paths", {
|
|
349
|
+
title: "Find paths",
|
|
350
|
+
description: "How two Elements are connected: the Relationships directly between them both ways, declared or derived from their descendants' (each derived edge lists the declared Relationships beneath it), and the shortest paths each way up to max_hops, each hop with its Relationships. Compared at the levels of the two Elements given. A `via` broker counts as a hop.",
|
|
351
|
+
input: z.object({
|
|
352
|
+
from: QualifiedId,
|
|
353
|
+
to: QualifiedId,
|
|
354
|
+
max_hops: z.number().int().min(1).max(10).default(4).describe("The longest path to look for, in hops"),
|
|
355
|
+
limit: Limit,
|
|
356
|
+
}),
|
|
357
|
+
output: z.object({
|
|
358
|
+
from: z.string(),
|
|
359
|
+
to: z.string(),
|
|
360
|
+
maxHops: z.number(),
|
|
361
|
+
direct: z.array(z.object({ from: z.string(), to: z.string(), derived: z.boolean(), relationships: z.array(BundleRelationship) })),
|
|
362
|
+
total: z.number(),
|
|
363
|
+
truncated: z.boolean(),
|
|
364
|
+
paths: z.array(z.object({ hops: z.array(Edge) })),
|
|
365
|
+
}),
|
|
366
|
+
}, ({ from, to, max_hops, limit }, { bundle }) => {
|
|
367
|
+
const missing = unknownElement(bundle, from, to);
|
|
368
|
+
if (missing)
|
|
369
|
+
return missing;
|
|
370
|
+
if (from === to)
|
|
371
|
+
return fail("invalid_input", "`from` and `to` name the same Element.");
|
|
372
|
+
const result = findPaths(bundle, from, to, { maxHops: max_hops });
|
|
373
|
+
const { items, total, truncated } = page(result.paths, limit);
|
|
374
|
+
const head = `${from} and ${to}: ${result.direct.length ? `${count(result.direct.length, "direct edge")}` : "no direct Relationships"}; ${total ? `${count(total, "shortest path")} within ${max_hops} hops` : `no path within ${max_hops} hops`}${truncated ? `; showing the first ${limit}` : ""}.`;
|
|
375
|
+
return ok({ from, to, maxHops: max_hops, direct: result.direct, total, truncated, paths: items }, [
|
|
376
|
+
head,
|
|
377
|
+
...result.direct.map((d) => `- direct ${d.from} → ${d.to}${d.derived ? " (derived)" : ""}: ${d.relationships.map(relationshipLabel).join(", ")}`),
|
|
378
|
+
...items.map((p) => `- ${count(p.hops.length, "hop")}: ${[p.hops[0].from, ...p.hops.map((h) => h.to)].join(" → ")}`),
|
|
379
|
+
].join("\n"));
|
|
380
|
+
});
|
|
381
|
+
tool("get_impact", {
|
|
382
|
+
title: "Get impact",
|
|
383
|
+
description: "Who an outage of an Element affects: the transitive upstream (what depends on it) or downstream (what it depends on) set, grouped by distance, with each Element's Owner and the Relationships that carry the impact from the ring before. Includes the Relationships of the Element's descendants; a `via` broker is a dependency of both its subscriber and its publisher. Logical Model only.",
|
|
384
|
+
input: z.object({
|
|
385
|
+
id: QualifiedId,
|
|
386
|
+
direction: z.enum(["upstream", "downstream", "both"]),
|
|
387
|
+
max_depth: z.number().int().min(1).optional().describe("The furthest distance to follow; unlimited when left out"),
|
|
388
|
+
limit: Limit,
|
|
389
|
+
}),
|
|
390
|
+
output: z.object({
|
|
391
|
+
id: z.string(),
|
|
392
|
+
direction: z.enum(["upstream", "downstream", "both"]),
|
|
393
|
+
maxDepth: z.number().nullable(),
|
|
394
|
+
upstream: ImpactSide.optional(),
|
|
395
|
+
downstream: ImpactSide.optional(),
|
|
396
|
+
}),
|
|
397
|
+
}, ({ id, direction, max_depth, limit }, { bundle }) => {
|
|
398
|
+
const missing = unknownElement(bundle, id);
|
|
399
|
+
if (missing)
|
|
400
|
+
return missing;
|
|
401
|
+
const result = getImpact(bundle, id, direction, max_depth === undefined ? {} : { maxDepth: max_depth });
|
|
402
|
+
const sides = ["upstream", "downstream"].flatMap((side) => (result[side] ? [[side, pageRings(result[side], limit)]] : []));
|
|
403
|
+
const element = bundle.elements.find((e) => e.id === id);
|
|
404
|
+
return ok({ id, direction, maxDepth: result.maxDepth, ...Object.fromEntries(sides) }, [
|
|
405
|
+
`Impact of ${label(element)}: ${sides.map(([side, s]) => `${s.total} ${side}${s.truncated ? ` (showing ${limit})` : ""}`).join(", ")}.`,
|
|
406
|
+
...sides.flatMap(([side, s]) => [
|
|
407
|
+
`${side[0].toUpperCase()}${side.slice(1)}:`,
|
|
408
|
+
...(s.rings.length ? s.rings.map((r) => `- ${r.distance}: ${r.elements.map((e) => `${e.id} (${e.owner || "no Team"})`).join(", ")}`) : ["- nothing"]),
|
|
409
|
+
]),
|
|
410
|
+
].join("\n"));
|
|
411
|
+
});
|
|
412
|
+
tool("list_owned", {
|
|
413
|
+
title: "List owned",
|
|
414
|
+
description: "The Elements and Deployment Targets a Team owns, grouped by kind, each with counts of the other Teams upstream (depending on it) and downstream (it depends on). An Element is listed under its own Owner, whoever owns its parent.",
|
|
415
|
+
input: z.object({
|
|
416
|
+
team: z.string().min(1).describe("A Team id"),
|
|
417
|
+
kind: OwnedKindSchema.optional(),
|
|
418
|
+
limit: Limit,
|
|
419
|
+
}),
|
|
420
|
+
output: z.object({
|
|
421
|
+
team: z.string(),
|
|
422
|
+
kind: OwnedKindSchema.nullable(),
|
|
423
|
+
total: z.number(),
|
|
424
|
+
truncated: z.boolean(),
|
|
425
|
+
groups: z.array(z.object({
|
|
426
|
+
kind: OwnedKindSchema,
|
|
427
|
+
total: z.number(),
|
|
428
|
+
items: z.array(z.object({ id: z.string(), name: z.string(), parent: z.string().nullable(), upstreamTeams: z.number(), downstreamTeams: z.number() })),
|
|
429
|
+
})),
|
|
430
|
+
}),
|
|
431
|
+
}, ({ team, kind, limit }, { bundle }) => {
|
|
432
|
+
const found = bundle.teams.find((t) => t.id === team);
|
|
433
|
+
if (!found)
|
|
434
|
+
return notFound("Team", team, bundle.teams.map((t) => t.id));
|
|
435
|
+
const result = listOwned(bundle, team, kind);
|
|
436
|
+
let left = limit;
|
|
437
|
+
const groups = result.groups
|
|
438
|
+
.map((g) => {
|
|
439
|
+
const items = g.items.slice(0, Math.max(left, 0));
|
|
440
|
+
left -= items.length;
|
|
441
|
+
return { ...g, items };
|
|
442
|
+
})
|
|
443
|
+
.filter((g) => g.items.length);
|
|
444
|
+
const truncated = result.total > limit;
|
|
445
|
+
const teams = (n, way) => `${n} ${way} Team${n === 1 ? "" : "s"}`;
|
|
446
|
+
return ok({ ...result, truncated, groups }, [
|
|
447
|
+
`${label(found)} owns ${count(result.total, "item")}${kind ? ` of kind ${kind}` : ""}${truncated ? `; showing the first ${limit}` : ""}.`,
|
|
448
|
+
...groups.flatMap((g) => [
|
|
449
|
+
`${ownedKindName[g.kind]}:`,
|
|
450
|
+
...g.items.map((i) => {
|
|
451
|
+
const parentElement = bundle.elements.find((e) => e.id === i.parent);
|
|
452
|
+
const elsewhere = parentElement && parentElement.owner !== team ? `, in ${i.parent}` : "";
|
|
453
|
+
return `- ${label(i)}${elsewhere}: ${teams(i.upstreamTeams, "upstream")}, ${teams(i.downstreamTeams, "downstream")}`;
|
|
454
|
+
}),
|
|
455
|
+
]),
|
|
456
|
+
].join("\n"));
|
|
457
|
+
});
|
|
458
|
+
tool("list_adrs", {
|
|
459
|
+
title: "List ADRs",
|
|
460
|
+
description: "Architecture decision records, newest first (by date, then number). With `element`, only the ADRs that link that Element or Deployment Target or any of its descendants (not its ancestors), each with `matchedVia`: the linked ids that matched. `status` filters on the effective status, so `superseded` finds ADRs replaced by an accepted one. Superseded ADRs are included and carry `supersededBy`.",
|
|
461
|
+
input: z.object({
|
|
462
|
+
element: QualifiedId.optional().describe("Only ADRs linking this Element or Deployment Target (project:id), or its descendants"),
|
|
463
|
+
status: AdrStatus.optional().describe("Only ADRs with this effective status"),
|
|
464
|
+
tag: z.string().min(1).optional(),
|
|
465
|
+
limit: Limit,
|
|
466
|
+
}),
|
|
467
|
+
output: z.object({ total: z.number(), truncated: z.boolean(), adrs: z.array(AdrSummary) }),
|
|
468
|
+
}, ({ element, status, tag, limit }, { bundle }) => {
|
|
469
|
+
if (element !== undefined) {
|
|
470
|
+
const known = [...bundle.elements, ...bundle.targets].map((e) => e.id);
|
|
471
|
+
if (!known.includes(element))
|
|
472
|
+
return notFound("Element or Deployment Target", element, known);
|
|
473
|
+
}
|
|
474
|
+
const { items, total, truncated } = page(listAdrs(bundle, { element, status, tag }).map(adrSummary), limit);
|
|
475
|
+
const filters = [element ? `for ${element}` : "", status ? `with status ${status}` : "", tag ? `tagged ${tag}` : ""].filter(Boolean).join(", ");
|
|
476
|
+
return ok({ total, truncated, adrs: items }, [
|
|
477
|
+
`${total} ADR${total === 1 ? "" : "s"}${filters ? ` ${filters}` : ""}${truncated ? `; showing the first ${limit}` : ""}.`,
|
|
478
|
+
...items.map((a) => `- ${a.id} ${a.title}: ${statusLabel(a)}, ${a.date}${a.matchedVia ? ` (via ${a.matchedVia.join(", ")})` : ""}`),
|
|
479
|
+
].join("\n"));
|
|
480
|
+
});
|
|
481
|
+
tool("get_adr", {
|
|
482
|
+
title: "Get ADR",
|
|
483
|
+
description: "One ADR by id (project:NNNN): its title, status as written and effective status, date, linked Elements, Targets and Saved Views, supersedes and the derived supersededBy, decision-makers, consulted, informed, tags, the full markdown body and its file.",
|
|
484
|
+
input: z.object({ id: z.string().min(1).describe("An ADR id, project:NNNN") }),
|
|
485
|
+
output: BundleAdr,
|
|
486
|
+
}, ({ id }, { bundle }) => {
|
|
487
|
+
const adr = bundle.adrs.find((a) => a.id === id);
|
|
488
|
+
if (!adr)
|
|
489
|
+
return notFound("ADR", id, bundle.adrs.map((a) => a.id));
|
|
490
|
+
const fields = [
|
|
491
|
+
["elements", adr.elements.join(", ")],
|
|
492
|
+
["views", adr.views.join(", ")],
|
|
493
|
+
["supersedes", adr.supersedes.join(", ")],
|
|
494
|
+
["decision-makers", adr.decisionMakers.join(", ")],
|
|
495
|
+
["consulted", adr.consulted.join(", ")],
|
|
496
|
+
["informed", adr.informed.join(", ")],
|
|
497
|
+
["tags", adr.tags.join(", ")],
|
|
498
|
+
];
|
|
499
|
+
return ok({ ...adr }, [
|
|
500
|
+
`ADR ${adr.id} (${adr.title}): ${adr.status}, ${adr.date}; ${adr.source.file}.`,
|
|
501
|
+
...(adr.supersededBy.length ? [`Superseded by ${adr.supersededBy.join(", ")}.`] : []),
|
|
502
|
+
...fields.filter(([, v]) => v).map(([k, v]) => `- ${k}: ${v}`),
|
|
503
|
+
"",
|
|
504
|
+
adr.body.trimEnd(),
|
|
505
|
+
].join("\n"));
|
|
506
|
+
});
|
|
507
|
+
tool("get_changes", {
|
|
508
|
+
title: "Get Changes",
|
|
509
|
+
description: "What changed in the Model between two points in time, each a ref (sha, tag or branch) or a date: a flat list of Changes (added, removed or changed), each with the fields that differ and the whole item before and after. `to` defaults to `at`, else the Workspace the server is reading. `scope` narrows to an Element (with its descendants and the Relationships, Deployments and ADRs touching them), a Team (what it owns at either side) or a Project; pass `scope_kind` when a Team and a Project share the id. `kinds` keeps only some item kinds.",
|
|
510
|
+
input: z.object({
|
|
511
|
+
from: Point.describe("The point to compare from: a ref or a date"),
|
|
512
|
+
to: Point.optional().describe("The point to compare to; defaults to `at`, else the current Workspace"),
|
|
513
|
+
scope: z.string().min(1).optional().describe("An Element (project:id), a Team id or a Project id"),
|
|
514
|
+
scope_kind: ScopeKind.optional(),
|
|
515
|
+
kinds: z.array(ChangeKindSchema).min(1).optional().describe(`Only these item kinds: ${changeKinds.join(", ")}`),
|
|
516
|
+
limit: Limit,
|
|
517
|
+
}),
|
|
518
|
+
output: z.object({
|
|
519
|
+
from: z.object({ point: z.string(), commit: z.string() }),
|
|
520
|
+
to: z.object({ point: z.string().nullable(), commit: z.string().nullable() }),
|
|
521
|
+
scope: z.object({ kind: ScopeKind, id: z.string() }).nullable(),
|
|
522
|
+
total: z.number(),
|
|
523
|
+
truncated: z.boolean(),
|
|
524
|
+
counts: z.record(z.string(), z.object({ added: z.number(), removed: z.number(), changed: z.number() })),
|
|
525
|
+
changes: z.array(ChangeRecord),
|
|
526
|
+
}),
|
|
527
|
+
}, async ({ from, to, scope, scope_kind, kinds, limit }, snapshot, { past, at }) => {
|
|
528
|
+
const before = await past.at(from, snapshot);
|
|
529
|
+
if (!before.ok)
|
|
530
|
+
return before;
|
|
531
|
+
let after = snapshot;
|
|
532
|
+
if (to !== undefined) {
|
|
533
|
+
const then = await past.at(to, snapshot);
|
|
534
|
+
if (!then.ok)
|
|
535
|
+
return then;
|
|
536
|
+
after = then.snapshot;
|
|
537
|
+
}
|
|
538
|
+
const sides = [before.snapshot.bundle, after.bundle];
|
|
539
|
+
let resolved;
|
|
540
|
+
if (scope !== undefined) {
|
|
541
|
+
const found = resolveScope(scope, sides, scope_kind);
|
|
542
|
+
if (!found.ok)
|
|
543
|
+
return scopeFailure(scope, found);
|
|
544
|
+
resolved = found.scope;
|
|
545
|
+
}
|
|
546
|
+
const changes = filterChanges(diff(before.snapshot.bundle, after.bundle), { before: before.snapshot.bundle, after: after.bundle, scope: resolved, kinds });
|
|
547
|
+
const { items, total, truncated } = page(changes, limit);
|
|
548
|
+
const toPoint = to ?? at ?? null;
|
|
549
|
+
const short = (sha) => (sha ? sha.slice(0, 7) : "no commit");
|
|
550
|
+
return ok({
|
|
551
|
+
from: { point: from, commit: before.commit },
|
|
552
|
+
to: { point: toPoint, commit: after.bundle.commit },
|
|
553
|
+
scope: resolved ?? null,
|
|
554
|
+
total,
|
|
555
|
+
truncated,
|
|
556
|
+
counts: countsByKind(changes),
|
|
557
|
+
changes: items,
|
|
558
|
+
}, [
|
|
559
|
+
`${count(total, "Change")} from ${from} (${short(before.commit)}) to ${toPoint ?? "the current Workspace"} (${short(after.bundle.commit)})${resolved ? ` in ${resolved.kind} ${resolved.id}` : ""}${truncated ? `; showing the first ${limit}` : ""}.`,
|
|
560
|
+
...items.map(changeLine),
|
|
561
|
+
].join("\n"));
|
|
562
|
+
});
|
|
563
|
+
tool("list_history", {
|
|
564
|
+
title: "List history",
|
|
565
|
+
description: "The Revisions (default-branch commits that changed the Workspace), newest first, each with sha, date, subject, author, tags, change counts against the Revision before, and whether its Bundle can be read with `at`. `scope` keeps the Revisions that touched an Element or its descendants, a Team or what it owns, or a Project (as they are at `at`, else now). `since` and `until` are refs or dates, inclusive; with `at`, Revisions after it are left out. Read from the Revision index, so it is cheap.",
|
|
566
|
+
input: z.object({
|
|
567
|
+
scope: z.string().min(1).optional().describe("An Element (project:id), a Team id or a Project id"),
|
|
568
|
+
scope_kind: ScopeKind.optional(),
|
|
569
|
+
since: Point.optional().describe("The earliest point: a ref or a date"),
|
|
570
|
+
until: Point.optional().describe("The latest point: a ref or a date"),
|
|
571
|
+
limit: Limit,
|
|
572
|
+
}),
|
|
573
|
+
output: z.object({
|
|
574
|
+
scope: z.object({ kind: ScopeKind, id: z.string() }).nullable(),
|
|
575
|
+
total: z.number(),
|
|
576
|
+
truncated: z.boolean(),
|
|
577
|
+
revisions: z.array(RevisionRecord),
|
|
578
|
+
}),
|
|
579
|
+
}, async ({ scope, scope_kind, since, until, limit }, { bundle }, { past, at }) => {
|
|
580
|
+
const listed = await past.index();
|
|
581
|
+
if (!listed.ok)
|
|
582
|
+
return listed;
|
|
583
|
+
let revisions = listed.revisions;
|
|
584
|
+
for (const [point, edge, keep] of [
|
|
585
|
+
[since, "start", (t, d) => d >= t],
|
|
586
|
+
[until, "end", (t, d) => d <= t],
|
|
587
|
+
[at, "end", (t, d) => d <= t],
|
|
588
|
+
]) {
|
|
589
|
+
if (point === undefined)
|
|
590
|
+
continue;
|
|
591
|
+
const time = await past.time(point, edge);
|
|
592
|
+
if (!time.ok)
|
|
593
|
+
return time;
|
|
594
|
+
revisions = revisions.filter((r) => keep(time.time, Date.parse(r.date)));
|
|
595
|
+
}
|
|
596
|
+
let resolved;
|
|
597
|
+
if (scope !== undefined) {
|
|
598
|
+
const found = resolveScope(scope, [bundle], scope_kind, listed.revisions.flatMap((r) => r.changedIds));
|
|
599
|
+
if (!found.ok)
|
|
600
|
+
return scopeFailure(scope, found);
|
|
601
|
+
resolved = found.scope;
|
|
602
|
+
const touched = scopeMatcher(resolved, [bundle]);
|
|
603
|
+
revisions = revisions.filter((r) => touched(r.changedIds));
|
|
604
|
+
}
|
|
605
|
+
const { items, total, truncated } = page(revisions.map(({ sha, date, subject, author, tags, counts, bundle: kept }) => ({ sha, date, subject, author, tags, counts, bundle: kept })), limit);
|
|
606
|
+
const tally = ({ added, removed, changed }) => [added && `+${added}`, removed && `-${removed}`, changed && `~${changed}`].filter(Boolean).join(" ") || "no Changes";
|
|
607
|
+
return ok({ scope: resolved ?? null, total, truncated, revisions: items }, [
|
|
608
|
+
`${count(total, "Revision")}${resolved ? ` touching ${resolved.kind} ${resolved.id}` : ""}${truncated ? `; showing the first ${limit}` : ""}.`,
|
|
609
|
+
...items.map((r) => `- ${r.sha.slice(0, 7)} ${r.date.slice(0, 10)} ${r.subject} (${r.author})${r.tags.length ? ` [${r.tags.join(", ")}]` : ""}: ${tally(r.counts)}${r.bundle ? "" : " (Bundle not kept)"}`),
|
|
610
|
+
].join("\n"));
|
|
611
|
+
});
|
|
612
|
+
tool("check", {
|
|
613
|
+
title: "Check the Workspace",
|
|
614
|
+
description: "Validate the Workspace as it is on disk, as `archidocs check` does, and return its issues. Use it after editing YAML with your own file tools.",
|
|
615
|
+
input: z.object({}),
|
|
616
|
+
output: z.object({ issues: z.array(IssueRecord), summary: z.object({ errors: z.number(), warnings: z.number() }) }),
|
|
617
|
+
write: true,
|
|
618
|
+
}, (_, { issues }) => {
|
|
619
|
+
const errors = issues.filter((i) => i.severity === "error").length;
|
|
620
|
+
const summary = { errors, warnings: issues.length - errors };
|
|
621
|
+
const plural = (n, noun) => `${n} ${noun}${n === 1 ? "" : "s"}`;
|
|
622
|
+
return ok({ issues: issues.map(withDocs), summary }, [
|
|
623
|
+
`${plural(errors, "error")}, ${plural(summary.warnings, "warning")}.`,
|
|
624
|
+
...issues.map((i) => `- ${i.file}:${i.line} ${i.severity} ${i.rule}: ${i.message}`),
|
|
625
|
+
].join("\n"));
|
|
626
|
+
});
|
|
627
|
+
const GuideInput = z.object({
|
|
628
|
+
topic: z.string().min(1).optional().describe(`One topic's reference file: ${topics.map((t) => t.id).join(", ")}`),
|
|
629
|
+
// Taken like every read tool's, but the guide ships with this Archidocs, so it is the same at every point.
|
|
630
|
+
at: At.optional(),
|
|
631
|
+
});
|
|
632
|
+
server.registerTool("get_authoring_guide", {
|
|
633
|
+
title: "Authoring guide",
|
|
634
|
+
description: "How to edit the Model with the write tools. With no topic: the archidocs-authoring skill (the Model, the edit loop) and its list of topics. With a topic: that flow's reference file; `rules` is the catalogue of every check rule. Load it before writing.",
|
|
635
|
+
inputSchema: advertise(GuideInput),
|
|
636
|
+
outputSchema: z.object({ topic: z.string().nullable(), topics: z.array(z.object({ id: z.string(), summary: z.string() })), text: z.string() }),
|
|
637
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
638
|
+
},
|
|
639
|
+
// The guide ships with this version, so it answers whatever the state of the source.
|
|
640
|
+
async (raw) => {
|
|
641
|
+
const args = GuideInput.safeParse(raw ?? {});
|
|
642
|
+
if (!args.success)
|
|
643
|
+
return toResult(fail("invalid_input", z.prettifyError(args.error)));
|
|
644
|
+
const guide = await authoringGuide(args.data.topic);
|
|
645
|
+
if (!guide.ok)
|
|
646
|
+
return toResult(fail("not_found", guide.message, guide.suggestion ? [guide.suggestion] : undefined));
|
|
647
|
+
return toResult(ok({ topic: guide.topic, topics: topics.map((t) => ({ ...t })), text: guide.text }, guide.text));
|
|
648
|
+
});
|
|
649
|
+
registerWriteTools(server, source, writesAllowed ? undefined : readOnlyReason);
|
|
650
|
+
return server;
|
|
651
|
+
}
|
|
652
|
+
const Point = z.string().min(1);
|
|
653
|
+
const ScopeKind = z.enum(["element", "team", "project"]).describe("What `scope` names, when a Team and a Project share the id");
|
|
654
|
+
const ChangeKindSchema = z.enum(changeKinds);
|
|
655
|
+
const ChangeRecord = z.object({
|
|
656
|
+
type: z.enum(["added", "removed", "changed"]),
|
|
657
|
+
kind: ChangeKindSchema,
|
|
658
|
+
id: z.string(),
|
|
659
|
+
fields: z.array(z.string()),
|
|
660
|
+
before: z.record(z.string(), z.unknown()).nullable(),
|
|
661
|
+
after: z.record(z.string(), z.unknown()).nullable(),
|
|
662
|
+
});
|
|
663
|
+
const RevisionRecord = z.object({
|
|
664
|
+
sha: z.string(),
|
|
665
|
+
date: z.string(),
|
|
666
|
+
subject: z.string(),
|
|
667
|
+
author: z.string(),
|
|
668
|
+
tags: z.array(z.string()),
|
|
669
|
+
counts: z.object({ added: z.number(), removed: z.number(), changed: z.number() }),
|
|
670
|
+
bundle: z.boolean().describe("Whether the Bundle at this Revision can be read with `at`"),
|
|
671
|
+
});
|
|
672
|
+
const changeSign = { added: "+", removed: "-", changed: "~" };
|
|
673
|
+
const changeLine = (c) => `${changeSign[c.type]} ${c.kind} ${c.id}${c.fields.length ? `: ${c.fields.join(", ")}` : ""}`;
|
|
674
|
+
/** Counts of Changes by type for each item kind that has any, in the order kinds are listed. */
|
|
675
|
+
function countsByKind(changes) {
|
|
676
|
+
return Object.fromEntries(changeKinds.flatMap((k) => {
|
|
677
|
+
const of = changes.filter((c) => c.kind === k);
|
|
678
|
+
return of.length ? [[k, countChanges(of)]] : [];
|
|
679
|
+
}));
|
|
680
|
+
}
|
|
681
|
+
/** `not_found` or `ambiguous` for a scope that names nothing, or both a Team and a Project. */
|
|
682
|
+
function scopeFailure(scope, found) {
|
|
683
|
+
if (found.reason === "ambiguous")
|
|
684
|
+
return fail("ambiguous", `"${scope}" is both a ${found.candidates.map((c) => c.kind).join(" and a ")}; pass scope_kind to pick one.`, found.candidates.map((c) => c.kind));
|
|
685
|
+
return notFound("Element, Team or Project", scope, found.known);
|
|
686
|
+
}
|
|
687
|
+
const At = z.string().min(1).describe("A point in time to answer at: a ref (sha, tag or branch) or a date (YYYY-MM-DD, the last Revision on or before it). Leave out for the current Workspace.");
|
|
688
|
+
/** Whether a call's raw arguments carry `at`, which write tools never take. */
|
|
689
|
+
export const takesAt = (raw) => raw !== null && typeof raw === "object" && "at" in raw;
|
|
690
|
+
export const atRefused = "Write tools never take `at`: they edit the Workspace as it is now.";
|
|
691
|
+
const IssueRecord = z.object({
|
|
692
|
+
file: z.string(),
|
|
693
|
+
line: z.number(),
|
|
694
|
+
column: z.number().optional(),
|
|
695
|
+
rule: z.string(),
|
|
696
|
+
severity: z.enum(["error", "warning"]),
|
|
697
|
+
message: z.string(),
|
|
698
|
+
docs: z.string().describe("The rule's page on the docs site"),
|
|
699
|
+
});
|
|
700
|
+
const where = (source) => (source.kind === "checkout" ? source.root : source.location);
|
|
701
|
+
const ElementKind = z.enum(["person", "system", "service", "component"]);
|
|
702
|
+
const ViewKind = z.enum(["c1", "c2", "c3", "deployment", "dynamic"]);
|
|
703
|
+
const ViewSummary = z.object({ id: z.string(), kind: ViewKind, title: z.string() });
|
|
704
|
+
const nodeKind = (n) => (n.kind === "deployment" ? `Deployment of ${n.element}` : n.kind === "target" ? "Deployment Target" : kindName[n.kind]);
|
|
705
|
+
const nodeLine = (n) => `- ${label(n)}: ${nodeKind(n)}${n.external ? ", external" : ""}${n.parent ? ` in ${n.parent}` : ""}${n.collapsed ? ", collapsed" : ""}${n.mark?.hit ? `, hit${n.mark.distance === undefined ? "" : ` at distance ${n.mark.distance}`}${n.mark.side === undefined || n.mark.side === "origin" ? "" : ` ${n.mark.side}`}` : ""}`;
|
|
706
|
+
/** A Step as one line: a return drawn dashed (⇠), an event with its broker and channel. */
|
|
707
|
+
const stepLine = (s) => {
|
|
708
|
+
const how = s.kind === "event" ? ` (event${s.via ? ` via ${s.via}` : ""}${s.channel ? ` · ${s.channel}` : ""})` : s.kind === "return" ? " (return)" : s.interaction === "async" ? " (async)" : "";
|
|
709
|
+
return `${s.n}. ${s.from} ${s.kind === "return" ? "⇠" : "→"} ${s.to}${how}: ${s.description}${s.note ? ` (${s.note})` : ""}`;
|
|
710
|
+
};
|
|
711
|
+
const relationshipLabel = (r) => r.description ?? r.id ?? `${r.from} → ${r.to}`;
|
|
712
|
+
const Limit = z.number().int().min(1).default(50).describe("The most items to return; `truncated` says whether there were more");
|
|
713
|
+
function page(all, limit) {
|
|
714
|
+
return { items: all.slice(0, limit), total: all.length, truncated: all.length > limit };
|
|
715
|
+
}
|
|
716
|
+
const listHead = (total, noun, truncated, limit) => `${total} ${noun}${total === 1 ? "" : "s"}${truncated ? `; showing the first ${limit}` : ""}.`;
|
|
717
|
+
const QualifiedId = z.string().min(1).describe("A qualified id, project:id");
|
|
718
|
+
const ElementSummary = z.object({ id: z.string(), kind: z.enum(["person", "system", "service", "component"]), name: z.string() });
|
|
719
|
+
/** A Deployment as tools return it: its Service is implied by the question. */
|
|
720
|
+
const DeploymentResult = BundleDeployment.omit({ service: true }).extend({
|
|
721
|
+
targetPath: z.array(z.object({ id: z.string(), name: z.string(), kind: z.string() })),
|
|
722
|
+
});
|
|
723
|
+
const deploymentResult = (d) => ({
|
|
724
|
+
environment: d.environment,
|
|
725
|
+
target: d.target,
|
|
726
|
+
targetPath: d.targetPath,
|
|
727
|
+
url: d.url,
|
|
728
|
+
endpoints: d.endpoints,
|
|
729
|
+
owner: d.owner,
|
|
730
|
+
source: d.source,
|
|
731
|
+
});
|
|
732
|
+
const summary = (e) => ({ id: e.id, kind: e.kind, name: e.name });
|
|
733
|
+
const label = (e) => `${e.id} (${e.name})`;
|
|
734
|
+
const kindName = { person: "Person", system: "System", service: "Service", component: "Component" };
|
|
735
|
+
const AdrSummary = BundleAdr.pick({ id: true, title: true, status: true, effectiveStatus: true, date: true, elements: true, views: true, supersedes: true, supersededBy: true, tags: true }).extend({
|
|
736
|
+
matchedVia: z.array(z.string()).optional().describe("With `element`: the linked ids that matched"),
|
|
737
|
+
});
|
|
738
|
+
const adrSummary = (a) => ({
|
|
739
|
+
id: a.id,
|
|
740
|
+
title: a.title,
|
|
741
|
+
status: a.status,
|
|
742
|
+
effectiveStatus: a.effectiveStatus,
|
|
743
|
+
date: a.date,
|
|
744
|
+
elements: a.elements,
|
|
745
|
+
views: a.views,
|
|
746
|
+
supersedes: a.supersedes,
|
|
747
|
+
supersededBy: a.supersededBy,
|
|
748
|
+
tags: a.tags,
|
|
749
|
+
...(a.matchedVia ? { matchedVia: a.matchedVia } : {}),
|
|
750
|
+
});
|
|
751
|
+
const statusLabel = (a) => a.supersededBy.length ? `superseded by ${a.supersededBy.join(", ")}` : a.effectiveStatus;
|
|
752
|
+
const Edge = z.object({ from: z.string(), to: z.string(), relationships: z.array(BundleRelationship) });
|
|
753
|
+
const ImpactSide = z.object({
|
|
754
|
+
total: z.number(),
|
|
755
|
+
truncated: z.boolean(),
|
|
756
|
+
rings: z.array(z.object({
|
|
757
|
+
distance: z.number(),
|
|
758
|
+
elements: z.array(ElementSummary.extend({ owner: z.string(), relationships: z.array(BundleRelationship) })),
|
|
759
|
+
})),
|
|
760
|
+
});
|
|
761
|
+
const OwnedKindSchema = z.enum(["person", "system", "service", "component", "target"]);
|
|
762
|
+
const ownedKindName = { person: "Person", system: "System", service: "Service", component: "Component", target: "Deployment Target" };
|
|
763
|
+
const count = (n, noun) => `${n} ${noun}${n === 1 ? "" : "s"}`;
|
|
764
|
+
/** The impact rings cut to `limit` Elements in all, nearest first. */
|
|
765
|
+
function pageRings(rings, limit) {
|
|
766
|
+
const total = rings.reduce((n, r) => n + r.elements.length, 0);
|
|
767
|
+
let left = limit;
|
|
768
|
+
const kept = rings
|
|
769
|
+
.map((r) => {
|
|
770
|
+
const elements = r.elements.slice(0, Math.max(left, 0));
|
|
771
|
+
left -= elements.length;
|
|
772
|
+
return { ...r, elements };
|
|
773
|
+
})
|
|
774
|
+
.filter((r) => r.elements.length);
|
|
775
|
+
return { total, truncated: total > limit, rings: kept };
|
|
776
|
+
}
|
|
777
|
+
/** `not_found` for the first of `ids` that names no Element, else nothing. */
|
|
778
|
+
function unknownElement(bundle, ...ids) {
|
|
779
|
+
const known = bundle.elements.map((e) => e.id);
|
|
780
|
+
const missing = ids.find((id) => !known.includes(id));
|
|
781
|
+
return missing === undefined ? undefined : notFound("Element", missing, known);
|
|
782
|
+
}
|
|
783
|
+
/** `{viewerUrl}` for an Element when a viewer base URL is configured, else nothing. */
|
|
784
|
+
function viewerLink(base, id) {
|
|
785
|
+
if (!base)
|
|
786
|
+
return {};
|
|
787
|
+
const url = new URL(base);
|
|
788
|
+
url.hash = `/element/${id}`;
|
|
789
|
+
return { viewerUrl: url.href };
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* `not_found` for an unknown id, suggesting every qualified id with the same
|
|
793
|
+
* bare id (a missing or wrong Project) and the nearest one by spelling.
|
|
794
|
+
*/
|
|
795
|
+
function notFound(what, id, known) {
|
|
796
|
+
const bare = id.slice(id.indexOf(":") + 1);
|
|
797
|
+
const sameBare = known.filter((k) => k.slice(k.indexOf(":") + 1) === bare);
|
|
798
|
+
const near = suggest(id, known);
|
|
799
|
+
const suggestions = [...new Set([...sameBare, ...(near ? [near] : [])])].slice(0, 5);
|
|
800
|
+
return fail("not_found", `No ${what} "${id}".`, suggestions.length ? suggestions : undefined);
|
|
801
|
+
}
|
|
802
|
+
export function toResult(outcome) {
|
|
803
|
+
if (outcome.ok)
|
|
804
|
+
return { content: [{ type: "text", text: outcome.text }], structuredContent: outcome.data };
|
|
805
|
+
const error = { code: outcome.code, message: outcome.message, ...(outcome.suggestions ? { suggestions: outcome.suggestions } : {}), ...outcome.details };
|
|
806
|
+
const hint = outcome.suggestions?.length ? `\nDid you mean: ${outcome.suggestions.join(", ")}?` : "";
|
|
807
|
+
const detail = outcome.detailText ? `\n${outcome.detailText}` : "";
|
|
808
|
+
return { content: [{ type: "text", text: `${error.code}: ${error.message}${hint}${detail}` }], structuredContent: error, isError: true };
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Advertises `schema` in `tools/list` but lets every object through to the
|
|
812
|
+
* handler, which parses it itself. The SDK would otherwise turn bad arguments
|
|
813
|
+
* into a plain-text error; this way they become a typed `invalid_input`.
|
|
814
|
+
*/
|
|
815
|
+
export function advertise(schema) {
|
|
816
|
+
return {
|
|
817
|
+
"~standard": {
|
|
818
|
+
version: 1,
|
|
819
|
+
vendor: "archidocs",
|
|
820
|
+
validate: (value) => ({ value }),
|
|
821
|
+
jsonSchema: schema["~standard"].jsonSchema,
|
|
822
|
+
},
|
|
823
|
+
};
|
|
824
|
+
}
|