archidocs 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +62 -13
  2. package/dist/cli/commands.d.ts +225 -4
  3. package/dist/cli/commands.js +129 -4
  4. package/dist/cli/init.d.ts +1 -1
  5. package/dist/cli/init.js +2 -2
  6. package/dist/cli/main.js +9 -14
  7. package/dist/core/compare.d.ts +2 -13
  8. package/dist/core/compare.js +2 -35
  9. package/dist/core/index.d.ts +2 -5
  10. package/dist/core/index.js +2 -5
  11. package/dist/core/rules.d.ts +10 -0
  12. package/dist/core/rules.js +186 -7
  13. package/dist/core/views/compare.d.ts +12 -0
  14. package/dist/core/views/compare.js +37 -0
  15. package/dist/core/{deployment-views.d.ts → views/deployment.d.ts} +4 -5
  16. package/dist/core/{deployment-views.js → views/deployment.js} +5 -7
  17. package/dist/core/{dynamic-views.d.ts → views/dynamic.d.ts} +1 -3
  18. package/dist/core/{dynamic-views.js → views/dynamic.js} +4 -8
  19. package/dist/core/views/generated.d.ts +18 -0
  20. package/dist/core/views/generated.js +92 -0
  21. package/dist/core/views/ids.d.ts +36 -0
  22. package/dist/core/views/ids.js +51 -0
  23. package/dist/core/views/index.d.ts +13 -0
  24. package/dist/core/views/index.js +12 -0
  25. package/dist/core/views/lens.d.ts +27 -0
  26. package/dist/core/views/lens.js +112 -0
  27. package/dist/core/views/model.d.ts +21 -0
  28. package/dist/core/views/model.js +69 -0
  29. package/dist/core/views/resolve.d.ts +42 -0
  30. package/dist/core/views/resolve.js +81 -0
  31. package/dist/core/{save-as-view.d.ts → views/save-as-view.d.ts} +2 -2
  32. package/dist/core/{save-as-view.js → views/save-as-view.js} +13 -10
  33. package/dist/core/{saved-views.d.ts → views/saved.d.ts} +4 -18
  34. package/dist/core/{saved-views.js → views/saved.js} +8 -103
  35. package/dist/core/views/types.d.ts +91 -0
  36. package/dist/core/views/types.js +2 -0
  37. package/dist/mcp/errors.d.ts +37 -0
  38. package/dist/mcp/errors.js +35 -0
  39. package/dist/mcp/index.d.ts +2 -1
  40. package/dist/mcp/index.js +1 -0
  41. package/dist/mcp/server.d.ts +1 -2
  42. package/dist/mcp/server.js +12 -12
  43. package/dist/render/layout.d.ts +20 -3
  44. package/dist/render/layout.js +49 -12
  45. package/dist/render/sequence-svg.d.ts +1 -1
  46. package/dist/render/sequence.d.ts +1 -1
  47. package/dist/render/svg.d.ts +1 -1
  48. package/dist/render/svg.js +4 -4
  49. package/dist/schema/adr.js +18 -13
  50. package/dist/schema/workspace.js +226 -130
  51. package/dist/viewer/assets/index-BXa5R96a.js +138 -0
  52. package/dist/viewer/assets/index-YFA-pYjQ.css +1 -0
  53. package/dist/viewer/assets/{layout.worker-Bg-OaLVN.js → layout.worker-BRHAGJrD.js} +1 -1
  54. package/dist/viewer/assets/{png-BDKIXtm5.js → png-CAaXWR-k.js} +1 -1
  55. package/dist/viewer/assets/{svg-Bulv5YWn.js → svg-BPVHfD36.js} +2 -2
  56. package/dist/viewer/index.html +2 -2
  57. package/guide/SKILL.md +1 -1
  58. package/guide/topics/bootstrap.md +1 -1
  59. package/guide/topics/relationships.md +1 -1
  60. package/package.json +4 -3
  61. package/schemas/adr.schema.json +18 -15
  62. package/schemas/model.schema.json +637 -1144
  63. package/schemas/project.schema.json +8 -4
  64. package/schemas/workspace.schema.json +39 -20
  65. package/dist/core/views.d.ts +0 -126
  66. package/dist/core/views.js +0 -217
  67. package/dist/viewer/assets/index-DvKgCpBr.css +0 -1
  68. package/dist/viewer/assets/index-gucix3xm.js +0 -113
@@ -0,0 +1,42 @@
1
+ import type { Bundle, BundleDynamicView, BundleStructuralView } from "../../schema/bundle.ts";
2
+ import { type DynamicResolution, type ResolvedDynamicView } from "./dynamic.ts";
3
+ import { ModelIndex } from "./model.ts";
4
+ import { type SavedResolution } from "./saved.ts";
5
+ import type { ListedKind, ResolvedView, ResolveOptions, ViewSummary } from "./types.ts";
6
+ /** Any View resolved: a Structural View, or a Dynamic View (`kind: "dynamic"`). */
7
+ export type AnyView = ResolvedView | ResolvedDynamicView;
8
+ /**
9
+ * Resolves any View by its id: a Generated View (`c1`, `c2`, `c2/<system>`,
10
+ * `c3/<service>`, only for a Service with Components, or `deployment/<env>`)
11
+ * or a Saved View (`project:view-id`), structural or dynamic. The two are
12
+ * told apart by `kind`; the options apply to a Structural View only. Returns
13
+ * undefined for an unknown id.
14
+ */
15
+ export declare function resolveView(bundle: Bundle, id: string, options?: ResolveOptions): AnyView | undefined;
16
+ /** Resolves a Structural View by id over an index of its Bundle; undefined for an unknown id or a Dynamic View's. */
17
+ export declare function resolveStructural(bundle: Bundle, model: ModelIndex, id: string, options?: ResolveOptions): ResolvedView | undefined;
18
+ /**
19
+ * Resolves one Saved View's definition with what `check` reports about it: a
20
+ * Structural View's `expand` and `collapse` entries that can't apply and its
21
+ * paths that find nothing, or a Dynamic View's Step problems.
22
+ */
23
+ export declare function checkView(bundle: Bundle, def: BundleStructuralView): SavedResolution;
24
+ export declare function checkView(bundle: Bundle, def: BundleDynamicView): DynamicResolution;
25
+ /**
26
+ * The picked nodes of a View, laid out again on their own: each pick with the
27
+ * containers it sits in, and the edges among them, Lens marks kept.
28
+ */
29
+ export declare function pickedView(view: ResolvedView, picks: readonly string[]): ResolvedView;
30
+ /**
31
+ * Every Generated View, in the order `c1`, `c2`, then `c2/<system>` and
32
+ * `c3/<service>` by id, then `deployment/<env>` by Environment id, then every
33
+ * Saved View by id. `kind` keeps one kind; `element` keeps the Views that
34
+ * show that Element as a node or a Deployment, and the
35
+ * Dynamic Views it takes part in (including as the broker of an event Step).
36
+ */
37
+ export declare function listViews(bundle: Bundle, filter?: {
38
+ kind?: ListedKind;
39
+ element?: string;
40
+ }): ViewSummary[];
41
+ /** Every Generated View, resolved, in `listViews` order. */
42
+ export declare function generatedViews(bundle: Bundle): ResolvedView[];
@@ -0,0 +1,81 @@
1
+ import { resolveDynamic, takesPart } from "./dynamic.js";
2
+ import { generatedViewIds, resolveGenerated, summarise } from "./generated.js";
3
+ import { applyLens } from "./lens.js";
4
+ import { ModelIndex } from "./model.js";
5
+ import { resolveSaved } from "./saved.js";
6
+ /**
7
+ * Resolves any View by its id: a Generated View (`c1`, `c2`, `c2/<system>`,
8
+ * `c3/<service>`, only for a Service with Components, or `deployment/<env>`)
9
+ * or a Saved View (`project:view-id`), structural or dynamic. The two are
10
+ * told apart by `kind`; the options apply to a Structural View only. Returns
11
+ * undefined for an unknown id.
12
+ */
13
+ export function resolveView(bundle, id, options = {}) {
14
+ const saved = bundle.views.find((v) => v.id === id);
15
+ if (saved?.kind === "dynamic")
16
+ return resolveDynamic(bundle, saved).view;
17
+ return resolveStructural(bundle, new ModelIndex(bundle), id, options);
18
+ }
19
+ /** Resolves a Structural View by id over an index of its Bundle; undefined for an unknown id or a Dynamic View's. */
20
+ export function resolveStructural(bundle, model, id, options = {}) {
21
+ const lens = options.lens ?? "own";
22
+ const view = unlensed(bundle, model, id, options.expand ?? [], lens);
23
+ if (view && typeof lens === "object")
24
+ applyLens(bundle, model, view, lens);
25
+ return view;
26
+ }
27
+ /** A Structural View with no Lens, except a Saved View's own when the choice is `"own"`. */
28
+ function unlensed(bundle, model, id, expand, lens) {
29
+ const saved = bundle.views.find((v) => v.id === id);
30
+ if (saved)
31
+ return saved.kind === "structural" ? resolveSaved(bundle, model, lens === "own" ? saved : { ...saved, lens: null }).view : undefined;
32
+ return resolveGenerated(bundle, model, id, expand);
33
+ }
34
+ export function checkView(bundle, def) {
35
+ return def.kind === "dynamic" ? resolveDynamic(bundle, def) : resolveSaved(bundle, new ModelIndex(bundle), def);
36
+ }
37
+ /**
38
+ * The picked nodes of a View, laid out again on their own: each pick with the
39
+ * containers it sits in, and the edges among them, Lens marks kept.
40
+ */
41
+ export function pickedView(view, picks) {
42
+ const parentOf = new Map(view.nodes.map((n) => [n.id, n.parent]));
43
+ const kept = new Set();
44
+ for (const pick of picks)
45
+ for (let at = parentOf.has(pick) ? pick : undefined; at; at = parentOf.get(at))
46
+ kept.add(at);
47
+ return { ...view, nodes: view.nodes.filter((n) => kept.has(n.id)), edges: view.edges.filter((e) => kept.has(e.from) && kept.has(e.to)) };
48
+ }
49
+ /**
50
+ * Every Generated View, in the order `c1`, `c2`, then `c2/<system>` and
51
+ * `c3/<service>` by id, then `deployment/<env>` by Environment id, then every
52
+ * Saved View by id. `kind` keeps one kind; `element` keeps the Views that
53
+ * show that Element as a node or a Deployment, and the
54
+ * Dynamic Views it takes part in (including as the broker of an event Step).
55
+ */
56
+ export function listViews(bundle, filter = {}) {
57
+ const model = new ModelIndex(bundle);
58
+ const ids = generatedViewIds(bundle).filter((id) => filter.kind === undefined || summarise(id, bundle).kind === filter.kind);
59
+ const generated = filter.element === undefined ? ids.map((id) => summarise(id, bundle)) : resolveAll(bundle, model, ids).filter((v) => shows(v, filter.element));
60
+ const element = filter.element;
61
+ const saved = bundle.views
62
+ .map((v) => ({ v, kind: v.kind === "dynamic" ? "dynamic" : v.level }))
63
+ .filter(({ kind }) => filter.kind === undefined || kind === filter.kind)
64
+ .filter(({ v }) => {
65
+ if (element === undefined)
66
+ return true;
67
+ if (v.kind === "dynamic")
68
+ return takesPart(resolveDynamic(bundle, v).view, element);
69
+ return shows(resolveSaved(bundle, model, v).view, element);
70
+ })
71
+ .map(({ v, kind }) => ({ id: v.id, kind, title: v.title }));
72
+ return [...generated, ...saved].map(({ id, kind, title }) => ({ id, kind, title }));
73
+ }
74
+ /** Whether a View draws an Element, as a node of its own or as a Deployment of it. */
75
+ const shows = (view, element) => view.nodes.some((n) => n.id === element || (n.kind === "deployment" && n.element === element));
76
+ /** Every Generated View, resolved, in `listViews` order. */
77
+ export function generatedViews(bundle) {
78
+ return resolveAll(bundle, new ModelIndex(bundle), generatedViewIds(bundle));
79
+ }
80
+ /** Resolves each id, skipping any that don't resolve (as when a Workspace with errors declares one id twice). */
81
+ const resolveAll = (bundle, model, ids) => ids.map((id) => resolveStructural(bundle, model, id)).filter((v) => v !== undefined);
@@ -1,5 +1,5 @@
1
- import type { Bundle, BundleLens } from "../schema/bundle.ts";
2
- import { type ViewDirection } from "./views.ts";
1
+ import type { Bundle, BundleLens } from "../../schema/bundle.ts";
2
+ import type { ViewDirection } from "./types.ts";
3
3
  /** What the viewer shows, as its URL holds it: the View, its open boxes, the Lens, the picks and a turned direction. */
4
4
  export interface Screen {
5
5
  view: string;
@@ -1,6 +1,8 @@
1
1
  import { stringify } from "yaml";
2
- import { resolveSaved } from "./saved-views.js";
3
- import { ModelIndex, pickedView, resolveView } from "./views.js";
2
+ import { parseViewId } from "./ids.js";
3
+ import { ModelIndex } from "./model.js";
4
+ import { pickedView, resolveStructural } from "./resolve.js";
5
+ import { resolveSaved } from "./saved.js";
4
6
  const kindLevel = { person: "c1", system: "c1", service: "c2", component: "c3" };
5
7
  const levelDepth = { c1: 1, c2: 2, c3: 3 };
6
8
  /**
@@ -14,7 +16,8 @@ const levelDepth = { c1: 1, c2: 2, c3: 3 };
14
16
  * A Deployment View is saved whole, over its Environment, its Lens as `lens:`.
15
17
  */
16
18
  export function saveAsView(bundle, screen, target) {
17
- const view = resolveView(bundle, screen.view, { expand: screen.open });
19
+ const model = new ModelIndex(bundle);
20
+ const view = resolveStructural(bundle, model, screen.view, { expand: screen.open });
18
21
  if (!view)
19
22
  throw new Error(`No View ${screen.view} to save.`);
20
23
  const own = bundle.views.find((v) => v.id === screen.view && v.kind === "structural");
@@ -24,7 +27,8 @@ export function saveAsView(bundle, screen, target) {
24
27
  if (view.kind === "deployment" && screen.picks.length > 0)
25
28
  throw new Error("Save as View keeps a whole Deployment View; clear the picks first.");
26
29
  if (view.kind === "deployment" && !own) {
27
- body = { level: "deployment", environment: screen.view.slice("deployment/".length) };
30
+ const ref = parseViewId(screen.view);
31
+ body = { level: "deployment", environment: ref?.form === "deployment" ? ref.environment : "" };
28
32
  }
29
33
  else if (own && screen.picks.length === 0) {
30
34
  body = {
@@ -35,7 +39,6 @@ export function saveAsView(bundle, screen, target) {
35
39
  };
36
40
  }
37
41
  else {
38
- const model = new ModelIndex(bundle);
39
42
  const kept = new Set((screen.picks.length === 0 ? view : pickedView(view, screen.picks)).nodes.map((n) => n.id));
40
43
  const depthOf = (id) => model.ancestry(id).length;
41
44
  const expand = screen.open
@@ -49,11 +52,11 @@ export function saveAsView(bundle, screen, target) {
49
52
  const selector = screen.lens ? lensSelector(screen.lens) : undefined;
50
53
  body = plain;
51
54
  if (selector) {
52
- const reached = nodesOf(bundle, { level, include: [selector] });
55
+ const reached = nodesOf(bundle, model, { level, include: [selector] });
53
56
  const include = [selector, ...ids.filter((id) => !reached.has(id))];
54
- const extra = [...nodesOf(bundle, { level, include, expand })].filter((id) => !kept.has(id)).sort();
57
+ const extra = [...nodesOf(bundle, model, { level, include, expand })].filter((id) => !kept.has(id)).sort();
55
58
  const withLens = { level, include, ...nonEmpty({ exclude: extra, expand }) };
56
- if (sameSet(nodesOf(bundle, withLens), kept))
59
+ if (sameSet(nodesOf(bundle, model, withLens), kept))
57
60
  body = withLens;
58
61
  }
59
62
  }
@@ -91,8 +94,8 @@ function writtenLens(lens) {
91
94
  return { ...lens };
92
95
  }
93
96
  /** The node ids the core engine resolves a definition to. */
94
- function nodesOf(bundle, def) {
95
- const resolved = resolveSaved(bundle, {
97
+ function nodesOf(bundle, model, def) {
98
+ const resolved = resolveSaved(bundle, model, {
96
99
  id: "screen:saved",
97
100
  project: "screen",
98
101
  kind: "structural",
@@ -1,5 +1,6 @@
1
- import type { Bundle, BundleLens, BundleStructuralView } from "../schema/bundle.ts";
2
- import { ModelIndex, type ResolvedView } from "./views.ts";
1
+ import type { Bundle, BundleStructuralView } from "../../schema/bundle.ts";
2
+ import { type ModelIndex } from "./model.ts";
3
+ import type { ResolvedView } from "./types.ts";
3
4
  /** An `expand` or `collapse` entry that can't apply: its id is not a node of the View, or it has no children. */
4
5
  export interface BadExpand {
5
6
  field: "expand" | "collapse";
@@ -30,19 +31,4 @@ export interface SavedResolution {
30
31
  * The Lens marks nodes and lights edges but never changes membership.
31
32
  * A Deployment View is resolved by `savedDeployment` instead.
32
33
  */
33
- export declare function resolveSaved(bundle: Bundle, def: BundleStructuralView): SavedResolution;
34
- /** A Lens in words, for tool text and a picture's key. */
35
- export declare const describeLens: (lens: BundleLens) => string;
36
- /**
37
- * Marks every node and lights every edge for the Lens. An Element the Lens
38
- * reaches marks the node that holds it, or that it holds, at its nearest
39
- * distance. An impact Lens lights an edge carrying the impact one hop
40
- * closer to its origin; a path Lens, an edge carrying a hop of a path; a
41
- * Team Lens, an edge between two hit nodes.
42
- */
43
- export declare function applyLens(bundle: Bundle, model: ModelIndex, view: ResolvedView, lens: BundleLens): {
44
- unresolved?: {
45
- from: string;
46
- to: string;
47
- };
48
- };
34
+ export declare function resolveSaved(bundle: Bundle, model: ModelIndex, def: BundleStructuralView): SavedResolution;
@@ -1,8 +1,9 @@
1
- import { resolveDeployment } from "./deployment-views.js";
2
- import { getImpact } from "./impact.js";
3
- import { pathsBetween } from "./paths.js";
4
- import { lifter } from "./query.js";
5
- import { build, ModelIndex } from "./views.js";
1
+ import { getImpact } from "../impact.js";
2
+ import { pathsBetween } from "../paths.js";
3
+ import { lifter } from "../query.js";
4
+ import { resolveDeployment } from "./deployment.js";
5
+ import { applyLens, nodesOn } from "./lens.js";
6
+ import { build } from "./model.js";
6
7
  const levelOf = { c1: "system", c2: "service", c3: "component" };
7
8
  /**
8
9
  * Resolves a Saved structural View:
@@ -14,8 +15,7 @@ const levelOf = { c1: "system", c2: "service", c3: "component" };
14
15
  * The Lens marks nodes and lights edges but never changes membership.
15
16
  * A Deployment View is resolved by `savedDeployment` instead.
16
17
  */
17
- export function resolveSaved(bundle, def) {
18
- const model = new ModelIndex(bundle);
18
+ export function resolveSaved(bundle, model, def) {
19
19
  if (def.level === "deployment")
20
20
  return savedDeployment(bundle, model, def);
21
21
  const kind = def.level;
@@ -96,7 +96,7 @@ function savedDeployment(bundle, model, def) {
96
96
  return true;
97
97
  return false;
98
98
  };
99
- const view = resolveDeployment(bundle, { id: def.id, title: def.title }, def.environment ?? "", {
99
+ const view = resolveDeployment(bundle, model, { id: def.id, title: def.title }, def.environment ?? "", {
100
100
  keep: (s) => !excluded.has(s),
101
101
  deployed: (d) => (included === undefined || included.has(d.service)) && (def.targets.length === 0 || under(d.target)),
102
102
  });
@@ -109,8 +109,6 @@ function savedDeployment(bundle, model, def) {
109
109
  }
110
110
  return { view, badExpand: [], unresolvedPaths };
111
111
  }
112
- /** A Lens in words, for tool text and a picture's key. */
113
- export const describeLens = (lens) => "impact" in lens ? `impact of ${lens.impact}, ${lens.direction}` : "team" in lens ? `Team ${lens.team}` : `paths from ${lens.path.from} to ${lens.path.to} (${lens.path.paths ?? "shortest"})`;
114
112
  /** The Elements one selector names; unknown ids name none (`unknown-element` reports them). */
115
113
  function selected(bundle, model, s) {
116
114
  if (typeof s === "string")
@@ -148,96 +146,3 @@ function selected(bundle, model, s) {
148
146
  }
149
147
  return { ids };
150
148
  }
151
- const nodesOn = (paths) => new Set(paths.flatMap((p) => p.hops.flatMap((h) => [h.from, h.to])));
152
- /**
153
- * Marks every node and lights every edge for the Lens. An Element the Lens
154
- * reaches marks the node that holds it, or that it holds, at its nearest
155
- * distance. An impact Lens lights an edge carrying the impact one hop
156
- * closer to its origin; a path Lens, an edge carrying a hop of a path; a
157
- * Team Lens, an edge between two hit nodes.
158
- */
159
- export function applyLens(bundle, model, view, lens) {
160
- view.lens = lens;
161
- /** Element ids the Lens reaches, with their distance when it has one. */
162
- const reached = new Map();
163
- /** For an impact Lens, which side of the origin each reached Element is on, at its nearest distance. */
164
- const sides = new Map();
165
- const carried = new Set();
166
- let unresolved;
167
- if ("impact" in lens) {
168
- if (model.byId.has(lens.impact)) {
169
- reached.set(lens.impact, 0);
170
- sides.set(lens.impact, "origin");
171
- const impact = getImpact(bundle, lens.impact, lens.direction);
172
- const rings = [...(impact.upstream ?? []).map((ring) => ["upstream", ring]), ...(impact.downstream ?? []).map((ring) => ["downstream", ring])];
173
- for (const [side, ring] of rings) {
174
- for (const e of ring.elements) {
175
- if (ring.distance < (reached.get(e.id) ?? Infinity)) {
176
- reached.set(e.id, ring.distance);
177
- sides.set(e.id, side);
178
- }
179
- for (const r of e.relationships)
180
- carried.add(r);
181
- }
182
- }
183
- }
184
- }
185
- else if ("team" in lens) {
186
- for (const e of model.elements)
187
- if (e.owner === lens.team)
188
- reached.set(e.id, undefined);
189
- for (const t of bundle.targets)
190
- if (t.owner === lens.team)
191
- reached.set(t.id, undefined);
192
- }
193
- else {
194
- const paths = pathsBetween(bundle, lens.path.from, lens.path.to, lens.path.paths ?? "shortest");
195
- for (const id of nodesOn(paths))
196
- reached.set(id, undefined);
197
- for (const p of paths)
198
- for (const h of p.hops)
199
- for (const r of h.relationships)
200
- carried.add(r);
201
- if (paths.length === 0 && model.byId.has(lens.path.from) && model.byId.has(lens.path.to))
202
- unresolved = { from: lens.path.from, to: lens.path.to };
203
- }
204
- // Each reached Element marks the nearest node holding it; an impact or path Lens also marks the nodes inside it.
205
- // A node stands for its own id, or for the Element it draws: a Deployment View draws one Service as several Deployments.
206
- const standing = new Map();
207
- for (const n of view.nodes)
208
- standing.set(n.element ?? n.id, [...(standing.get(n.element ?? n.id) ?? []), n.id]);
209
- const marks = new Map(view.nodes.map((n) => [n.id, { hit: false }]));
210
- const mark = (node, d, side) => {
211
- const m = marks.get(node);
212
- if (!m)
213
- return;
214
- m.hit = true;
215
- if (d !== undefined && d < (m.distance ?? Infinity)) {
216
- m.distance = d;
217
- if (side !== undefined)
218
- m.side = side;
219
- }
220
- };
221
- for (const [id, d] of reached) {
222
- const holder = model.ancestry(id).find((a) => standing.has(a));
223
- for (const n of holder === undefined ? [] : standing.get(holder))
224
- mark(n, d, sides.get(id));
225
- if (!("team" in lens))
226
- for (const n of view.nodes)
227
- if ((n.element ?? n.id) !== id && model.ancestry(n.element ?? n.id).includes(id))
228
- mark(n.id, d, sides.get(id));
229
- }
230
- for (const n of view.nodes)
231
- n.mark = marks.get(n.id);
232
- const markOf = new Map(view.nodes.map((n) => [n.id, n.mark]));
233
- for (const e of view.edges) {
234
- const [from, to] = [markOf.get(e.from), markOf.get(e.to)];
235
- if ("team" in lens)
236
- e.lit = from.hit && to.hit;
237
- else if ("impact" in lens)
238
- e.lit = e.relationships.some((r) => carried.has(r)) && from.distance !== undefined && to.distance !== undefined && Math.abs(from.distance - to.distance) === 1;
239
- else
240
- e.lit = e.relationships.some((r) => carried.has(r)) && from.hit && to.hit;
241
- }
242
- return unresolved ? { unresolved } : {};
243
- }
@@ -0,0 +1,91 @@
1
+ import type { BundleElement, BundleLens, BundleRelationship } from "../../schema/bundle.ts";
2
+ /** The most nodes a View may have before `oversized-view` warns. */
3
+ export declare const MAX_VIEW_NODES = 150;
4
+ /** The kinds of Structural View: the three levels, and the Deployment View. */
5
+ export type ViewKind = "c1" | "c2" | "c3" | "deployment";
6
+ /** How Compare marks a node or edge of a View between two Bundles. */
7
+ export type CompareMark = "added" | "removed" | "changed" | "unchanged";
8
+ /**
9
+ * One node of a resolved View: an Element, drawn as a box or as a container.
10
+ * A Deployment View also has Deployment Targets (`target`), Deployments
11
+ * (`deployment`, id `<service>@<target>`) and the System boxes inside each
12
+ * Target (`system`, id `<system>@<target>`).
13
+ */
14
+ export interface ViewNode {
15
+ id: string;
16
+ kind: BundleElement["kind"] | "target" | "deployment";
17
+ name: string;
18
+ /** The Element a Deployment or a Target's System box draws, when the node's id is not that Element's. */
19
+ element?: string;
20
+ /** A Deployment's Deployment Target. */
21
+ target?: string;
22
+ /** The nearest ancestor that is itself a node of this View, else null. */
23
+ parent: string | null;
24
+ /** True when the Element has children in the Model that this View hides inside it. */
25
+ collapsed: boolean;
26
+ /** True for an External System or Service. */
27
+ external: boolean;
28
+ /** Set on every node of a View with a Lens: whether the Lens hits it, and for an impact Lens its nearest distance. */
29
+ mark?: NodeMark;
30
+ /** Set on every node of a View drawn for Compare (`compareView`). */
31
+ change?: CompareMark;
32
+ }
33
+ /** How a Lens marks a node; a collapsed box is hit when anything inside it is. */
34
+ export interface NodeMark {
35
+ hit: boolean;
36
+ distance?: number;
37
+ /** For an impact Lens: the origin itself, or the side of it the node sits on, at its nearest distance. */
38
+ side?: ImpactSide;
39
+ }
40
+ export type ImpactSide = "origin" | "upstream" | "downstream";
41
+ /** The way a View draws: top to bottom, bottom to top, left to right or right to left. */
42
+ export type ViewDirection = "TB" | "BT" | "LR" | "RL";
43
+ /** An edge between two nodes, with the declared Relationships beneath it. */
44
+ export interface ViewEdge {
45
+ from: string;
46
+ to: string;
47
+ relationships: BundleRelationship[];
48
+ /** Set on every edge of a View with a Lens: whether the Lens lights it. */
49
+ lit?: boolean;
50
+ /** Set on every edge of a View drawn for Compare (`compareView`). */
51
+ change?: CompareMark;
52
+ }
53
+ /** A Structural View resolved to nodes and edges, sorted by id and by `from`, then `to`. */
54
+ export interface ResolvedView {
55
+ id: string;
56
+ kind: ViewKind;
57
+ title: string;
58
+ /** The way the View draws: a Saved View's own, else `TB` for a Deployment View, else `LR`. */
59
+ direction: ViewDirection;
60
+ /** A Deployment View's Environment. */
61
+ environment?: string;
62
+ /** A Saved View's Lens, if it carries one. */
63
+ lens?: BundleLens;
64
+ nodes: ViewNode[];
65
+ edges: ViewEdge[];
66
+ }
67
+ export interface ResolveOptions {
68
+ /**
69
+ * Systems and Services to open, showing their children; viewer state, not a
70
+ * different View. A box opens only while it is itself shown, so a Service
71
+ * stays shut inside a closed System. C1 opens nothing.
72
+ */
73
+ expand?: readonly string[];
74
+ /**
75
+ * The Lens over the View, which marks nodes and lights edges without
76
+ * changing which nodes the View holds: `"own"` (the default) is a Saved
77
+ * View's own Lens and none on any other View, `"none"` is no Lens, and a
78
+ * given Lens replaces the View's own.
79
+ */
80
+ lens?: LensChoice;
81
+ }
82
+ /** Which Lens a View is resolved with: its own, none, or this one. */
83
+ export type LensChoice = "own" | "none" | BundleLens;
84
+ /** The kinds a View is listed under: a Saved Structural View's is its `level`. */
85
+ export type ListedKind = ViewKind | "dynamic";
86
+ /** A View as listed, without its nodes and edges. */
87
+ export interface ViewSummary {
88
+ id: string;
89
+ kind: ListedKind;
90
+ title: string;
91
+ }
@@ -0,0 +1,2 @@
1
+ /** The most nodes a View may have before `oversized-view` warns. */
2
+ export const MAX_VIEW_NODES = 150;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The error codes a tool result can carry in `structuredContent.code`, each
3
+ * with what it means and what the caller should do. The server types its
4
+ * failures with these codes, and the docs list them on the MCP error page.
5
+ */
6
+ export declare const ERROR_CODES: {
7
+ readonly invalid_input: {
8
+ readonly meaning: "The arguments don't fit the tool's input: a field is missing, has the wrong type or isn't a valid id, or a write tool was given `at`.";
9
+ readonly action: "Read `message`, which names the field, and call again with corrected arguments.";
10
+ };
11
+ readonly not_found: {
12
+ readonly meaning: "An id, a Project, a View, a Deployment or a point in history (`at`, `from`, `since`) names nothing in the Model.";
13
+ readonly action: "Use one of `suggestions` if there are any. Otherwise find the id with `search_elements`, `list_views` or `list_history`.";
14
+ };
15
+ readonly ambiguous: {
16
+ readonly meaning: "A name matches more than one thing: a history `scope` that is both a Project and an Element, or a write that could mean more than one Relationship or Deployment.";
17
+ readonly action: "Narrow the call: pass `scope_kind`, or the Relationship's `id`. `suggestions` lists the candidates when there are any.";
18
+ };
19
+ readonly validation_failed: {
20
+ readonly meaning: "A write would add a check error, or remove something still referenced. Nothing was written.";
21
+ readonly action: "Fix what `issues` or `references` lists, each issue with a link to its rule's page, then write again.";
22
+ };
23
+ readonly read_only: {
24
+ readonly meaning: "A write tool was called on a server that can't write: one reading a published Workspace Bundle, or one over HTTP started without `--allow-writes`.";
25
+ readonly action: "Run `archidocs mcp` over a Workspace checkout, and add `--allow-writes` over HTTP.";
26
+ };
27
+ readonly source_unavailable: {
28
+ readonly meaning: "The server could not read the Workspace or the Workspace Bundle, or could not write the checkout.";
29
+ readonly action: "Check that the folder or URL the server was started with exists and is readable, then call again: each call tries anew.";
30
+ };
31
+ readonly history_unavailable: {
32
+ readonly meaning: "The call needs the Model's history (`at`, `get_changes`, `list_history`), and the source has none: no git repository, or a published site without a Revision index.";
33
+ readonly action: "Run the server over a git checkout with its full history, or publish the site with its Revisions.";
34
+ };
35
+ };
36
+ /** A code a failed tool result carries. */
37
+ export type ErrorCode = keyof typeof ERROR_CODES;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The error codes a tool result can carry in `structuredContent.code`, each
3
+ * with what it means and what the caller should do. The server types its
4
+ * failures with these codes, and the docs list them on the MCP error page.
5
+ */
6
+ export const ERROR_CODES = {
7
+ invalid_input: {
8
+ meaning: "The arguments don't fit the tool's input: a field is missing, has the wrong type or isn't a valid id, or a write tool was given `at`.",
9
+ action: "Read `message`, which names the field, and call again with corrected arguments.",
10
+ },
11
+ not_found: {
12
+ meaning: "An id, a Project, a View, a Deployment or a point in history (`at`, `from`, `since`) names nothing in the Model.",
13
+ action: "Use one of `suggestions` if there are any. Otherwise find the id with `search_elements`, `list_views` or `list_history`.",
14
+ },
15
+ ambiguous: {
16
+ meaning: "A name matches more than one thing: a history `scope` that is both a Project and an Element, or a write that could mean more than one Relationship or Deployment.",
17
+ action: "Narrow the call: pass `scope_kind`, or the Relationship's `id`. `suggestions` lists the candidates when there are any.",
18
+ },
19
+ validation_failed: {
20
+ meaning: "A write would add a check error, or remove something still referenced. Nothing was written.",
21
+ action: "Fix what `issues` or `references` lists, each issue with a link to its rule's page, then write again.",
22
+ },
23
+ read_only: {
24
+ meaning: "A write tool was called on a server that can't write: one reading a published Workspace Bundle, or one over HTTP started without `--allow-writes`.",
25
+ action: "Run `archidocs mcp` over a Workspace checkout, and add `--allow-writes` over HTTP.",
26
+ },
27
+ source_unavailable: {
28
+ meaning: "The server could not read the Workspace or the Workspace Bundle, or could not write the checkout.",
29
+ action: "Check that the folder or URL the server was started with exists and is readable, then call again: each call tries anew.",
30
+ },
31
+ history_unavailable: {
32
+ meaning: "The call needs the Model's history (`at`, `get_changes`, `list_history`), and the source has none: no git repository, or a published site without a Revision index.",
33
+ action: "Run the server over a git checkout with its full history, or publish the site with its Revisions.",
34
+ },
35
+ };
@@ -1,3 +1,4 @@
1
- export { createServer, type ServerOptions, type ErrorCode } from "./server.ts";
1
+ export { createServer, type ServerOptions } from "./server.ts";
2
+ export { ERROR_CODES, type ErrorCode } from "./errors.ts";
2
3
  export { bundleSource, checkoutSource, type BundleSource, type CheckoutSource, type Source, type Snapshot } from "./source.ts";
3
4
  export { serveHttp, DEFAULT_PORT, type HttpServer, type ServeHttpOptions } from "./http.ts";
package/dist/mcp/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { createServer } from "./server.js";
2
+ export { ERROR_CODES } from "./errors.js";
2
3
  export { bundleSource, checkoutSource } from "./source.js";
3
4
  export { serveHttp, DEFAULT_PORT } from "./http.js";
@@ -2,6 +2,7 @@ import { McpServer, type CallToolResult, type StandardSchemaWithJSON } from "@mo
2
2
  import { z } from "zod";
3
3
  import type { Snapshot, Source } from "./source.ts";
4
4
  import { type Past } from "./history.ts";
5
+ import type { ErrorCode } from "./errors.ts";
5
6
  export interface ServerOptions {
6
7
  source: Source;
7
8
  /** Base URL of a published viewer; when set, results carry `viewerUrl` links. */
@@ -13,8 +14,6 @@ export interface ServerOptions {
13
14
  */
14
15
  allowWrites?: boolean;
15
16
  }
16
- /** The typed error codes a tool result can carry in `structuredContent.code`. */
17
- export type ErrorCode = "not_found" | "ambiguous" | "invalid_input" | "validation_failed" | "read_only" | "source_unavailable" | "history_unavailable";
18
17
  export type ToolOutcome = {
19
18
  ok: true;
20
19
  data: Record<string, unknown>;