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,126 @@
|
|
|
1
|
+
import type { CompareMark } from "./compare.ts";
|
|
2
|
+
import type { Bundle, BundleElement, BundleLens, BundleRelationship } from "../schema/bundle.ts";
|
|
3
|
+
/** The most nodes a View may have before `oversized-view` warns. */
|
|
4
|
+
export declare const MAX_VIEW_NODES = 150;
|
|
5
|
+
/** The kinds of Generated structural View, and the Deployment View. */
|
|
6
|
+
export type ViewKind = "c1" | "c2" | "c3" | "deployment";
|
|
7
|
+
/**
|
|
8
|
+
* One node of a resolved View: an Element, drawn as a box or as a container.
|
|
9
|
+
* A Deployment View also has Deployment Targets (`target`), Deployments
|
|
10
|
+
* (`deployment`, id `<service>@<target>`) and the System boxes inside each
|
|
11
|
+
* Target (`system`, id `<system>@<target>`).
|
|
12
|
+
*/
|
|
13
|
+
export interface ViewNode {
|
|
14
|
+
id: string;
|
|
15
|
+
kind: BundleElement["kind"] | "target" | "deployment";
|
|
16
|
+
name: string;
|
|
17
|
+
/** The Element a Deployment or a Target's System box draws, when the node's id is not that Element's. */
|
|
18
|
+
element?: string;
|
|
19
|
+
/** The nearest ancestor that is itself a node of this View, else null. */
|
|
20
|
+
parent: string | null;
|
|
21
|
+
/** True when the Element has children in the Model that this View hides inside it. */
|
|
22
|
+
collapsed: boolean;
|
|
23
|
+
/** True for an External System or Service. */
|
|
24
|
+
external: boolean;
|
|
25
|
+
/** Set on every node of a View with a Lens: whether the Lens hits it, and for an impact Lens its nearest distance. */
|
|
26
|
+
mark?: NodeMark;
|
|
27
|
+
/** Set on every node of a View drawn for Compare (`compareView`). */
|
|
28
|
+
change?: CompareMark;
|
|
29
|
+
}
|
|
30
|
+
/** How a Lens marks a node; a collapsed box is hit when anything inside it is. */
|
|
31
|
+
export interface NodeMark {
|
|
32
|
+
hit: boolean;
|
|
33
|
+
distance?: number;
|
|
34
|
+
/** For an impact Lens: the origin itself, or the side of it the node sits on, at its nearest distance. */
|
|
35
|
+
side?: ImpactSide;
|
|
36
|
+
}
|
|
37
|
+
export type ImpactSide = "origin" | "upstream" | "downstream";
|
|
38
|
+
/** A Saved View's drawing direction. */
|
|
39
|
+
export type ViewDirection = "TB" | "BT" | "LR" | "RL";
|
|
40
|
+
/** An edge between two nodes, with the declared Relationships beneath it. */
|
|
41
|
+
export interface ViewEdge {
|
|
42
|
+
from: string;
|
|
43
|
+
to: string;
|
|
44
|
+
relationships: BundleRelationship[];
|
|
45
|
+
/** Set on every edge of a View with a Lens: whether the Lens lights it. */
|
|
46
|
+
lit?: boolean;
|
|
47
|
+
/** Set on every edge of a View drawn for Compare (`compareView`). */
|
|
48
|
+
change?: CompareMark;
|
|
49
|
+
}
|
|
50
|
+
/** A View resolved to nodes and edges, sorted by id and by `from`, then `to`. */
|
|
51
|
+
export interface ResolvedView {
|
|
52
|
+
id: string;
|
|
53
|
+
kind: ViewKind;
|
|
54
|
+
title: string;
|
|
55
|
+
/** A Saved View's own direction, if it sets one. */
|
|
56
|
+
direction?: ViewDirection;
|
|
57
|
+
/** A Saved View's Lens, if it carries one. */
|
|
58
|
+
lens?: BundleLens;
|
|
59
|
+
nodes: ViewNode[];
|
|
60
|
+
edges: ViewEdge[];
|
|
61
|
+
}
|
|
62
|
+
export interface ResolveOptions {
|
|
63
|
+
/**
|
|
64
|
+
* Systems and Services to open, showing their children; viewer state, not a
|
|
65
|
+
* different View. A box opens only while it is itself shown, so a Service
|
|
66
|
+
* stays shut inside a closed System. C1 opens nothing.
|
|
67
|
+
*/
|
|
68
|
+
expand?: readonly string[];
|
|
69
|
+
/**
|
|
70
|
+
* A Lens over the View, as the viewer holds it: marks nodes and lights
|
|
71
|
+
* edges without changing which nodes the View holds. It replaces a Saved
|
|
72
|
+
* View's own Lens; null clears a Saved View's own Lens.
|
|
73
|
+
*/
|
|
74
|
+
lens?: BundleLens | null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolves a View by id: a Generated View (`c1`, `c2`, `c2/<system>`,
|
|
78
|
+
* `c3/<service>`, only for a Service with Components, or `deployment/<env>`)
|
|
79
|
+
* or a Saved structural or Deployment View (`project:view-id`). Returns
|
|
80
|
+
* undefined for an unknown id.
|
|
81
|
+
*/
|
|
82
|
+
export declare function resolveView(bundle: Bundle, id: string, options?: ResolveOptions): ResolvedView | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* The picked nodes of a View, laid out again on their own: each pick with the
|
|
85
|
+
* containers it sits in, and the edges among them, Lens marks kept.
|
|
86
|
+
*/
|
|
87
|
+
export declare function pickedView(view: ResolvedView, picks: readonly string[]): ResolvedView;
|
|
88
|
+
/** The kinds a View is listed under: a Saved structural View's is its `level`. */
|
|
89
|
+
export type ListedKind = ViewKind | "dynamic";
|
|
90
|
+
/** A View as listed, without its nodes and edges. */
|
|
91
|
+
export interface ViewSummary {
|
|
92
|
+
id: string;
|
|
93
|
+
kind: ListedKind;
|
|
94
|
+
title: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Every Generated View, in the order `c1`, `c2`, then `c2/<system>` and
|
|
98
|
+
* `c3/<service>` by id, then `deployment/<env>` by Environment id, then every
|
|
99
|
+
* Saved View by id. `kind` keeps one kind; `element` keeps the Views that
|
|
100
|
+
* show that Element as a node or a Deployment, and the
|
|
101
|
+
* Dynamic Views it takes part in (including as the broker of an event Step).
|
|
102
|
+
*/
|
|
103
|
+
export declare function listViews(bundle: Bundle, filter?: {
|
|
104
|
+
kind?: ListedKind;
|
|
105
|
+
element?: string;
|
|
106
|
+
}): ViewSummary[];
|
|
107
|
+
/** Every Generated View, resolved, in `listViews` order. */
|
|
108
|
+
export declare function generatedViews(bundle: Bundle): ResolvedView[];
|
|
109
|
+
/**
|
|
110
|
+
* Builds a View from the set of Elements it shows: each Relationship's ends
|
|
111
|
+
* are lifted to their nearest shown ancestor-or-self, and the Relationships
|
|
112
|
+
* landing on one pair form one edge. An edge is kept when `keep` accepts the
|
|
113
|
+
* declared Relationship and its ends are two different nodes.
|
|
114
|
+
*/
|
|
115
|
+
export declare function build(model: ModelIndex, head: Pick<ResolvedView, "id" | "kind" | "title">, shown: Set<string>, keep: (r: BundleRelationship) => boolean): ResolvedView;
|
|
116
|
+
/** Lookups over a Bundle's Elements. */
|
|
117
|
+
export declare class ModelIndex {
|
|
118
|
+
readonly elements: BundleElement[];
|
|
119
|
+
readonly relationships: BundleRelationship[];
|
|
120
|
+
readonly byId: Map<string, BundleElement>;
|
|
121
|
+
private readonly childrenOf;
|
|
122
|
+
constructor(bundle: Bundle);
|
|
123
|
+
children(id: string): BundleElement[];
|
|
124
|
+
/** The Element itself, then its parent, and so on up to the top level. Unknown ids yield only themselves. */
|
|
125
|
+
ancestry(id: string): string[];
|
|
126
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { resolveDeployment } from "./deployment-views.js";
|
|
2
|
+
import { resolveDynamic, takesPart } from "./dynamic-views.js";
|
|
3
|
+
import { applyLens, resolveSaved } from "./saved-views.js";
|
|
4
|
+
/** The most nodes a View may have before `oversized-view` warns. */
|
|
5
|
+
export const MAX_VIEW_NODES = 150;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves a View by id: a Generated View (`c1`, `c2`, `c2/<system>`,
|
|
8
|
+
* `c3/<service>`, only for a Service with Components, or `deployment/<env>`)
|
|
9
|
+
* or a Saved structural or Deployment View (`project:view-id`). Returns
|
|
10
|
+
* undefined for an unknown id.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveView(bundle, id, options = {}) {
|
|
13
|
+
const view = resolveUnlensed(bundle, id, options);
|
|
14
|
+
if (view && options.lens)
|
|
15
|
+
applyLens(bundle, new ModelIndex(bundle), view, options.lens);
|
|
16
|
+
return view;
|
|
17
|
+
}
|
|
18
|
+
function resolveUnlensed(bundle, id, options) {
|
|
19
|
+
const saved = bundle.views.find((v) => v.id === id);
|
|
20
|
+
if (saved)
|
|
21
|
+
return saved.kind === "structural" ? resolveSaved(bundle, options.lens === undefined ? saved : { ...saved, lens: null }).view : undefined;
|
|
22
|
+
const model = new ModelIndex(bundle);
|
|
23
|
+
if (id === "c1")
|
|
24
|
+
return landscape(model, "c1", "C1 Landscape", []);
|
|
25
|
+
if (id === "c2")
|
|
26
|
+
return landscape(model, "c2", "C2 Landscape", options.expand ?? []);
|
|
27
|
+
const slash = id.indexOf("/");
|
|
28
|
+
if (slash < 0)
|
|
29
|
+
return undefined;
|
|
30
|
+
const scope = id.slice(0, slash);
|
|
31
|
+
if (scope === "deployment") {
|
|
32
|
+
const env = bundle.environments.find((e) => e.id === id.slice(slash + 1));
|
|
33
|
+
return env ? resolveDeployment(bundle, { id, title: `${env.name} (Deployment)` }, env.id) : undefined;
|
|
34
|
+
}
|
|
35
|
+
const focus = model.byId.get(id.slice(slash + 1));
|
|
36
|
+
if (!focus)
|
|
37
|
+
return undefined;
|
|
38
|
+
const expand = options.expand ?? [];
|
|
39
|
+
if (scope === "c2" && focus.kind === "system")
|
|
40
|
+
return focused(model, { id, kind: "c2", title: `${focus.name} (C2)` }, focus, expand);
|
|
41
|
+
if (scope === "c3" && focus.kind === "service" && model.children(focus.id).length > 0)
|
|
42
|
+
return focused(model, { id, kind: "c3", title: `${focus.name} (C3)` }, focus, expand);
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The picked nodes of a View, laid out again on their own: each pick with the
|
|
47
|
+
* containers it sits in, and the edges among them, Lens marks kept.
|
|
48
|
+
*/
|
|
49
|
+
export function pickedView(view, picks) {
|
|
50
|
+
const parentOf = new Map(view.nodes.map((n) => [n.id, n.parent]));
|
|
51
|
+
const kept = new Set();
|
|
52
|
+
for (const pick of picks)
|
|
53
|
+
for (let at = parentOf.has(pick) ? pick : undefined; at; at = parentOf.get(at))
|
|
54
|
+
kept.add(at);
|
|
55
|
+
return { ...view, nodes: view.nodes.filter((n) => kept.has(n.id)), edges: view.edges.filter((e) => kept.has(e.from) && kept.has(e.to)) };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Every Generated View, in the order `c1`, `c2`, then `c2/<system>` and
|
|
59
|
+
* `c3/<service>` by id, then `deployment/<env>` by Environment id, then every
|
|
60
|
+
* Saved View by id. `kind` keeps one kind; `element` keeps the Views that
|
|
61
|
+
* show that Element as a node or a Deployment, and the
|
|
62
|
+
* Dynamic Views it takes part in (including as the broker of an event Step).
|
|
63
|
+
*/
|
|
64
|
+
export function listViews(bundle, filter = {}) {
|
|
65
|
+
const ids = generatedViewIds(bundle).filter((id) => filter.kind === undefined || id.split("/")[0] === filter.kind);
|
|
66
|
+
const generated = filter.element === undefined ? ids.map((id) => summarise(id, bundle)) : resolveAll(bundle, ids).filter((v) => shows(v, filter.element));
|
|
67
|
+
const element = filter.element;
|
|
68
|
+
const saved = bundle.views
|
|
69
|
+
.map((v) => ({ v, kind: v.kind === "dynamic" ? "dynamic" : v.level }))
|
|
70
|
+
.filter(({ kind }) => filter.kind === undefined || kind === filter.kind)
|
|
71
|
+
.filter(({ v }) => {
|
|
72
|
+
if (element === undefined)
|
|
73
|
+
return true;
|
|
74
|
+
if (v.kind === "dynamic")
|
|
75
|
+
return takesPart(resolveDynamic(bundle, v).view, element);
|
|
76
|
+
return shows(resolveSaved(bundle, v).view, element);
|
|
77
|
+
})
|
|
78
|
+
.map(({ v, kind }) => ({ id: v.id, kind, title: v.title }));
|
|
79
|
+
return [...generated, ...saved].map(({ id, kind, title }) => ({ id, kind, title }));
|
|
80
|
+
}
|
|
81
|
+
/** Whether a View draws an Element, as a node of its own or as a Deployment of it. */
|
|
82
|
+
const shows = (view, element) => view.nodes.some((n) => n.id === element || (n.kind === "deployment" && n.element === element));
|
|
83
|
+
/** Every Generated View, resolved, in `listViews` order. */
|
|
84
|
+
export function generatedViews(bundle) {
|
|
85
|
+
return resolveAll(bundle, generatedViewIds(bundle));
|
|
86
|
+
}
|
|
87
|
+
/** Resolves each id, skipping any that don't resolve (as when a Workspace with errors declares one id twice). */
|
|
88
|
+
const resolveAll = (bundle, ids) => ids.map((id) => resolveView(bundle, id)).filter((v) => v !== undefined);
|
|
89
|
+
function generatedViewIds(bundle) {
|
|
90
|
+
const parents = new Set(bundle.elements.map((e) => e.parent));
|
|
91
|
+
const ids = (prefix, keep) => [...new Set(bundle.elements.filter(keep).map((e) => `${prefix}/${e.id}`))].sort();
|
|
92
|
+
const deployment = bundle.environments.map((e) => `deployment/${e.id}`).sort();
|
|
93
|
+
return ["c1", "c2", ...ids("c2", (e) => e.kind === "system"), ...ids("c3", (e) => e.kind === "service" && parents.has(e.id)), ...deployment];
|
|
94
|
+
}
|
|
95
|
+
/** A Generated View's id, kind and title without resolving it; `id` must be one `generatedViewIds` gave. */
|
|
96
|
+
function summarise(id, bundle) {
|
|
97
|
+
if (id === "c1")
|
|
98
|
+
return { id, kind: "c1", title: "C1 Landscape" };
|
|
99
|
+
if (id === "c2")
|
|
100
|
+
return { id, kind: "c2", title: "C2 Landscape" };
|
|
101
|
+
if (id.startsWith("deployment/"))
|
|
102
|
+
return { id, kind: "deployment", title: `${bundle.environments.find((e) => `deployment/${e.id}` === id).name} (Deployment)` };
|
|
103
|
+
const [kind, elementId] = [id.slice(0, 2), id.slice(3)];
|
|
104
|
+
return { id, kind, title: `${bundle.elements.find((e) => e.id === elementId).name} (${kind.toUpperCase()})` };
|
|
105
|
+
}
|
|
106
|
+
/** Every top-level Element, each standing for everything beneath it, with the `expand`ed boxes open. */
|
|
107
|
+
function landscape(model, kind, title, expand) {
|
|
108
|
+
const shown = new Set(model.elements.filter((e) => e.parent === null).map((e) => e.id));
|
|
109
|
+
open(model, shown, expand);
|
|
110
|
+
return build(model, { id: kind, kind, title }, shown, () => true);
|
|
111
|
+
}
|
|
112
|
+
/** Adds the children of each `expand`ed System or Service that is shown, repeating so a Service opens once its System has. */
|
|
113
|
+
function open(model, shown, expand) {
|
|
114
|
+
const pending = new Set(expand.filter((id) => ["system", "service"].includes(model.byId.get(id)?.kind ?? "")));
|
|
115
|
+
for (let grew = true; grew;) {
|
|
116
|
+
grew = false;
|
|
117
|
+
for (const id of pending) {
|
|
118
|
+
if (!shown.has(id))
|
|
119
|
+
continue;
|
|
120
|
+
for (const child of model.children(id))
|
|
121
|
+
shown.add(child.id);
|
|
122
|
+
pending.delete(id);
|
|
123
|
+
grew = true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* One Element opened as a container around its children, plus its direct
|
|
129
|
+
* neighbours: every Element outside it with a Relationship to anything
|
|
130
|
+
* inside it, collapsed to its highest ancestor that does not contain the
|
|
131
|
+
* focus. Only Relationships touching the focus become edges.
|
|
132
|
+
*/
|
|
133
|
+
function focused(model, head, focus, expand) {
|
|
134
|
+
const inside = (id) => model.ancestry(id).includes(focus.id);
|
|
135
|
+
const touches = (r) => inside(r.from) || inside(r.to);
|
|
136
|
+
const shown = new Set([focus.id, ...model.children(focus.id).map((c) => c.id)]);
|
|
137
|
+
for (const r of model.relationships) {
|
|
138
|
+
if (!touches(r))
|
|
139
|
+
continue;
|
|
140
|
+
for (const end of [r.from, r.to]) {
|
|
141
|
+
if (inside(end) || !model.byId.has(end))
|
|
142
|
+
continue;
|
|
143
|
+
const separating = model.ancestry(end).filter((a) => !model.ancestry(focus.id).includes(a));
|
|
144
|
+
shown.add(separating.at(-1));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
open(model, shown, expand);
|
|
148
|
+
return build(model, head, shown, touches);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Builds a View from the set of Elements it shows: each Relationship's ends
|
|
152
|
+
* are lifted to their nearest shown ancestor-or-self, and the Relationships
|
|
153
|
+
* landing on one pair form one edge. An edge is kept when `keep` accepts the
|
|
154
|
+
* declared Relationship and its ends are two different nodes.
|
|
155
|
+
*/
|
|
156
|
+
export function build(model, head, shown, keep) {
|
|
157
|
+
const lift = (id) => model.ancestry(id).find((a) => shown.has(a));
|
|
158
|
+
const edges = new Map();
|
|
159
|
+
for (const r of model.relationships) {
|
|
160
|
+
if (!keep(r))
|
|
161
|
+
continue;
|
|
162
|
+
const from = lift(r.from);
|
|
163
|
+
const to = lift(r.to);
|
|
164
|
+
if (from === undefined || to === undefined || from === to)
|
|
165
|
+
continue;
|
|
166
|
+
const key = `${from}\0${to}`;
|
|
167
|
+
const edge = edges.get(key) ?? { from, to, relationships: [] };
|
|
168
|
+
edge.relationships.push(r);
|
|
169
|
+
edges.set(key, edge);
|
|
170
|
+
}
|
|
171
|
+
const nodes = [...shown]
|
|
172
|
+
.map((id) => model.byId.get(id))
|
|
173
|
+
.filter((e) => e !== undefined)
|
|
174
|
+
.map((e) => ({
|
|
175
|
+
id: e.id,
|
|
176
|
+
kind: e.kind,
|
|
177
|
+
name: e.name,
|
|
178
|
+
parent: model.ancestry(e.id).slice(1).find((a) => shown.has(a)) ?? null,
|
|
179
|
+
collapsed: model.children(e.id).some((c) => !shown.has(c.id)),
|
|
180
|
+
external: "external" in e && e.external,
|
|
181
|
+
}))
|
|
182
|
+
.sort((a, b) => cmp(a.id, b.id));
|
|
183
|
+
return { ...head, nodes, edges: [...edges.values()].sort((a, b) => cmp(a.from, b.from) || cmp(a.to, b.to)) };
|
|
184
|
+
}
|
|
185
|
+
/** Lookups over a Bundle's Elements. */
|
|
186
|
+
export class ModelIndex {
|
|
187
|
+
elements;
|
|
188
|
+
relationships;
|
|
189
|
+
byId;
|
|
190
|
+
childrenOf = new Map();
|
|
191
|
+
constructor(bundle) {
|
|
192
|
+
this.elements = bundle.elements;
|
|
193
|
+
this.relationships = bundle.relationships;
|
|
194
|
+
this.byId = new Map(bundle.elements.map((e) => [e.id, e]));
|
|
195
|
+
for (const e of bundle.elements) {
|
|
196
|
+
if (e.parent === null)
|
|
197
|
+
continue;
|
|
198
|
+
const list = this.childrenOf.get(e.parent) ?? [];
|
|
199
|
+
list.push(e);
|
|
200
|
+
this.childrenOf.set(e.parent, list);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
children(id) {
|
|
204
|
+
return this.childrenOf.get(id) ?? [];
|
|
205
|
+
}
|
|
206
|
+
/** The Element itself, then its parent, and so on up to the top level. Unknown ids yield only themselves. */
|
|
207
|
+
ancestry(id) {
|
|
208
|
+
const out = [id];
|
|
209
|
+
const seen = new Set(out);
|
|
210
|
+
for (let p = this.byId.get(id)?.parent; p != null && !seen.has(p) && this.byId.has(p); p = this.byId.get(p)?.parent) {
|
|
211
|
+
out.push(p);
|
|
212
|
+
seen.add(p);
|
|
213
|
+
}
|
|
214
|
+
return out;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Position {
|
|
2
|
+
line: number;
|
|
3
|
+
column: number;
|
|
4
|
+
}
|
|
5
|
+
export interface ParsedYaml {
|
|
6
|
+
/** The plain data, or undefined when the file could not be parsed. */
|
|
7
|
+
data: unknown;
|
|
8
|
+
syntaxError?: Position & {
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
/** Where the node at a path starts; `key` asks for the map key rather than its value. */
|
|
12
|
+
positionOf(path: readonly PropertyKey[], options?: {
|
|
13
|
+
key?: boolean;
|
|
14
|
+
}): Position;
|
|
15
|
+
}
|
|
16
|
+
export declare function parseYaml(text: string): ParsedYaml;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { isMap, isSeq, LineCounter, parseDocument } from "yaml";
|
|
2
|
+
export function parseYaml(text) {
|
|
3
|
+
const lineCounter = new LineCounter();
|
|
4
|
+
const doc = parseDocument(text, { lineCounter, prettyErrors: false, uniqueKeys: true });
|
|
5
|
+
const toPosition = (offset) => {
|
|
6
|
+
const { line, col } = lineCounter.linePos(offset);
|
|
7
|
+
return { line, column: col };
|
|
8
|
+
};
|
|
9
|
+
const positionOf = (path, options = {}) => toPosition(offsetOf(doc, path, options.key ?? false));
|
|
10
|
+
const [error] = doc.errors;
|
|
11
|
+
if (error) {
|
|
12
|
+
const pos = toPosition(error.pos[0]);
|
|
13
|
+
return { data: undefined, syntaxError: { ...pos, message: firstLine(error.message) }, positionOf };
|
|
14
|
+
}
|
|
15
|
+
return { data: doc.toJS() ?? {}, positionOf };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Finds the deepest node along `path` and returns its start offset. If the
|
|
19
|
+
* path runs out of nodes (a missing field), the last node found is used.
|
|
20
|
+
*/
|
|
21
|
+
function offsetOf(doc, path, wantKey) {
|
|
22
|
+
let node = doc.contents;
|
|
23
|
+
let offset = node?.range?.[0] ?? 0;
|
|
24
|
+
for (const [i, segment] of path.entries()) {
|
|
25
|
+
const last = i === path.length - 1;
|
|
26
|
+
if (isMap(node)) {
|
|
27
|
+
const pair = node.items.find((p) => p.key?.value === segment);
|
|
28
|
+
if (!pair)
|
|
29
|
+
return offset;
|
|
30
|
+
const key = pair.key;
|
|
31
|
+
if (last && wantKey)
|
|
32
|
+
return key.range?.[0] ?? offset;
|
|
33
|
+
offset = key.range?.[0] ?? offset;
|
|
34
|
+
node = pair.value;
|
|
35
|
+
if (node?.range && !(last && wantKey))
|
|
36
|
+
offset = node.range[0];
|
|
37
|
+
}
|
|
38
|
+
else if (isSeq(node) && typeof segment === "number") {
|
|
39
|
+
node = node.items[segment];
|
|
40
|
+
if (!node?.range)
|
|
41
|
+
return offset;
|
|
42
|
+
offset = node.range[0];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return offset;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return offset;
|
|
49
|
+
}
|
|
50
|
+
function firstLine(message) {
|
|
51
|
+
return message.split("\n")[0].trim();
|
|
52
|
+
}
|
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** HEAD's sha and commit time, so a Bundle built twice at one commit is byte-identical. Both null outside git or before the first commit. */
|
|
2
|
+
export declare function gitHead(cwd: string): Promise<{
|
|
3
|
+
commit: string | null;
|
|
4
|
+
builtAt: string | null;
|
|
5
|
+
}>;
|
|
6
|
+
/** The top folder of the git checkout holding `cwd`, or null outside git. */
|
|
7
|
+
export declare function gitTopLevel(cwd: string): Promise<string | null>;
|
package/dist/git.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
/** HEAD's sha and commit time, so a Bundle built twice at one commit is byte-identical. Both null outside git or before the first commit. */
|
|
4
|
+
export async function gitHead(cwd) {
|
|
5
|
+
try {
|
|
6
|
+
const { stdout } = await promisify(execFile)("git", ["log", "-1", "--format=%H %cI"], { cwd });
|
|
7
|
+
const [commit, builtAt] = stdout.trim().split(" ");
|
|
8
|
+
return { commit: commit || null, builtAt: builtAt || null };
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return { commit: null, builtAt: null };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** The top folder of the git checkout holding `cwd`, or null outside git. */
|
|
15
|
+
export async function gitTopLevel(cwd) {
|
|
16
|
+
try {
|
|
17
|
+
const { stdout } = await promisify(execFile)("git", ["rev-parse", "--show-toplevel"], { cwd });
|
|
18
|
+
return stdout.trim() || null;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** The skill's name, as its stub and the full SKILL.md both declare it. */
|
|
2
|
+
export declare const SKILL_NAME = "archidocs-authoring";
|
|
3
|
+
/** The guide's topics, in the order they are listed. `rules` is generated from the rule registry. */
|
|
4
|
+
export declare const topics: readonly [{
|
|
5
|
+
readonly id: "bootstrap";
|
|
6
|
+
readonly summary: "Declare an existing codebase's Services, Relationships and Deployments in one pass, from an approved inventory.";
|
|
7
|
+
}, {
|
|
8
|
+
readonly id: "add-service";
|
|
9
|
+
readonly summary: "Add one Service with its Components, Relationships and Deployments.";
|
|
10
|
+
}, {
|
|
11
|
+
readonly id: "relationships";
|
|
12
|
+
readonly summary: "Declare a dependency, including async ones through a broker (`via`, `channel`) and cross-Project ones.";
|
|
13
|
+
}, {
|
|
14
|
+
readonly id: "deployments";
|
|
15
|
+
readonly summary: "Add Deployment Targets and Deployments, with their URLs, per Environment.";
|
|
16
|
+
}, {
|
|
17
|
+
readonly id: "dynamic-view";
|
|
18
|
+
readonly summary: "Draft a scenario as Steps over existing Relationships, adding missing ones.";
|
|
19
|
+
}, {
|
|
20
|
+
readonly id: "saved-view";
|
|
21
|
+
readonly summary: "Save a structural or Deployment View with selectors and a Lens.";
|
|
22
|
+
}, {
|
|
23
|
+
readonly id: "propose-adr";
|
|
24
|
+
readonly summary: "Propose an ADR linked to the Elements and Views it affects.";
|
|
25
|
+
}, {
|
|
26
|
+
readonly id: "change";
|
|
27
|
+
readonly summary: "Rename, move or remove, working through refused removals by their references.";
|
|
28
|
+
}, {
|
|
29
|
+
readonly id: "rules";
|
|
30
|
+
readonly summary: "Every `check` rule id: what it means, a failing example and the fix.";
|
|
31
|
+
}];
|
|
32
|
+
export type TopicId = (typeof topics)[number]["id"];
|
|
33
|
+
export type GuideResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
topic: TopicId | null;
|
|
36
|
+
text: string;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
message: string;
|
|
40
|
+
suggestion?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The guide as `get_authoring_guide` and `archidocs guide` serve it: with no
|
|
44
|
+
* topic, SKILL.md followed by the list of topics; with one, that topic's
|
|
45
|
+
* reference file.
|
|
46
|
+
*/
|
|
47
|
+
export declare function authoringGuide(topic?: string): Promise<GuideResult>;
|
|
48
|
+
/**
|
|
49
|
+
* The thin SKILL.md that `archidocs init` installs in a repo. It only points
|
|
50
|
+
* at the served guide, so it never goes stale, and uses only the portable
|
|
51
|
+
* frontmatter fields.
|
|
52
|
+
*/
|
|
53
|
+
export declare const skillStub = "---\nname: archidocs-authoring\ndescription: Edit the Archidocs architecture Model. Use when bootstrapping a Project from code, adding or changing Services, Relationships, Deployments or Views, or proposing an ADR.\n---\n\n# Archidocs authoring\n\nBefore editing the Model, load the full guide: call the `get_authoring_guide` tool of the Archidocs MCP server, or run `archidocs guide` when no Archidocs MCP server is connected. It lists the topics; load the one for the task with `get_authoring_guide(topic)` or `archidocs guide <topic>`, and follow it.\n";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { ruleCatalogue } from "../core/catalogue.js";
|
|
3
|
+
import { suggest } from "../core/suggest.js";
|
|
4
|
+
/**
|
|
5
|
+
* The authoring guide's Markdown, shipped beside the code in `guide/`. The
|
|
6
|
+
* module runs from dist/guide/ when installed and from src/guide/ in this
|
|
7
|
+
* repo; both sit two levels below the package root.
|
|
8
|
+
*/
|
|
9
|
+
const GUIDE_DIR = new URL("../../guide/", import.meta.url);
|
|
10
|
+
/** The skill's name, as its stub and the full SKILL.md both declare it. */
|
|
11
|
+
export const SKILL_NAME = "archidocs-authoring";
|
|
12
|
+
/** The guide's topics, in the order they are listed. `rules` is generated from the rule registry. */
|
|
13
|
+
export const topics = [
|
|
14
|
+
{ id: "bootstrap", summary: "Declare an existing codebase's Services, Relationships and Deployments in one pass, from an approved inventory." },
|
|
15
|
+
{ id: "add-service", summary: "Add one Service with its Components, Relationships and Deployments." },
|
|
16
|
+
{ id: "relationships", summary: "Declare a dependency, including async ones through a broker (`via`, `channel`) and cross-Project ones." },
|
|
17
|
+
{ id: "deployments", summary: "Add Deployment Targets and Deployments, with their URLs, per Environment." },
|
|
18
|
+
{ id: "dynamic-view", summary: "Draft a scenario as Steps over existing Relationships, adding missing ones." },
|
|
19
|
+
{ id: "saved-view", summary: "Save a structural or Deployment View with selectors and a Lens." },
|
|
20
|
+
{ id: "propose-adr", summary: "Propose an ADR linked to the Elements and Views it affects." },
|
|
21
|
+
{ id: "change", summary: "Rename, move or remove, working through refused removals by their references." },
|
|
22
|
+
{ id: "rules", summary: "Every `check` rule id: what it means, a failing example and the fix." },
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* The guide as `get_authoring_guide` and `archidocs guide` serve it: with no
|
|
26
|
+
* topic, SKILL.md followed by the list of topics; with one, that topic's
|
|
27
|
+
* reference file.
|
|
28
|
+
*/
|
|
29
|
+
export async function authoringGuide(topic) {
|
|
30
|
+
if (topic === undefined) {
|
|
31
|
+
const skill = await readFile(new URL("SKILL.md", GUIDE_DIR), "utf8");
|
|
32
|
+
const list = ["## Topics", "", ...topics.map((t) => `- \`${t.id}\`: ${t.summary}`)];
|
|
33
|
+
return { ok: true, topic: null, text: `${skill.trimEnd()}\n\n${list.join("\n")}\n` };
|
|
34
|
+
}
|
|
35
|
+
const found = topics.find((t) => t.id === topic);
|
|
36
|
+
if (!found) {
|
|
37
|
+
const suggestion = suggest(topic, topics.map((t) => t.id));
|
|
38
|
+
return { ok: false, message: `Unknown topic "${topic}"${suggestion ? `; did you mean "${suggestion}"?` : ""} Topics: ${topics.map((t) => t.id).join(", ")}.`, ...(suggestion ? { suggestion } : {}) };
|
|
39
|
+
}
|
|
40
|
+
if (found.id === "rules")
|
|
41
|
+
return { ok: true, topic: found.id, text: ruleCatalogue() };
|
|
42
|
+
return { ok: true, topic: found.id, text: await readFile(new URL(`topics/${found.id}.md`, GUIDE_DIR), "utf8") };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The thin SKILL.md that `archidocs init` installs in a repo. It only points
|
|
46
|
+
* at the served guide, so it never goes stale, and uses only the portable
|
|
47
|
+
* frontmatter fields.
|
|
48
|
+
*/
|
|
49
|
+
export const skillStub = `---
|
|
50
|
+
name: ${SKILL_NAME}
|
|
51
|
+
description: Edit the Archidocs architecture Model. Use when bootstrapping a Project from code, adding or changing Services, Relationships, Deployments or Views, or proposing an ADR.
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
# Archidocs authoring
|
|
55
|
+
|
|
56
|
+
Before editing the Model, load the full guide: call the \`get_authoring_guide\` tool of the Archidocs MCP server, or run \`archidocs guide\` when no Archidocs MCP server is connected. It lists the topics; load the one for the task with \`get_authoring_guide(topic)\` or \`archidocs guide <topic>\`, and follow it.
|
|
57
|
+
`;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { FileSystem } from "../core/fs.ts";
|
|
2
|
+
/** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
|
|
3
|
+
export declare function git(cwd: string, ...args: string[]): Promise<string>;
|
|
4
|
+
/**
|
|
5
|
+
* A read-only FileSystem over the tree of one commit. Paths are absolute
|
|
6
|
+
* under `repoRoot`, as on disk; files are read with `git show`, so no
|
|
7
|
+
* worktree is needed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function gitFileSystem(repoRoot: string, commit: string): Promise<FileSystem>;
|
|
10
|
+
/** A commit's sha, committer date (ISO 8601), author name and subject. */
|
|
11
|
+
export interface CommitInfo {
|
|
12
|
+
sha: string;
|
|
13
|
+
date: string;
|
|
14
|
+
author: string;
|
|
15
|
+
subject: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function commitInfo(repoRoot: string, sha: string): Promise<CommitInfo>;
|
|
18
|
+
/**
|
|
19
|
+
* The default branch: what `origin/HEAD` points at, else a local `main` or
|
|
20
|
+
* `master`, else HEAD.
|
|
21
|
+
*/
|
|
22
|
+
export declare function defaultBranch(repoRoot: string): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* First-parent commits on `branch`, newest first, that changed something
|
|
25
|
+
* under `path` (relative to the repo root; "" is the whole repo) against
|
|
26
|
+
* their first parent. A merge counts by what it brought to the branch.
|
|
27
|
+
*/
|
|
28
|
+
export declare function firstParentCommitsTouching(repoRoot: string, branch: string, path: string): Promise<CommitInfo[]>;
|
|
29
|
+
/** Tag names by the commit they point at. */
|
|
30
|
+
export declare function tagsByCommit(repoRoot: string): Promise<Map<string, string[]>>;
|
|
31
|
+
/** Whether `point` is a date (`YYYY-MM-DD` or a full ISO 8601 time) rather than a ref. */
|
|
32
|
+
export declare const isDate: (point: string) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Resolves a point in time to a commit sha: a date to the last first-parent
|
|
35
|
+
* default-branch commit at or before it, anything else as a git ref.
|
|
36
|
+
* Undefined when there is no such commit.
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolvePoint(repoRoot: string, point: string): Promise<string | undefined>;
|
|
39
|
+
export declare const joinRepo: (repoRoot: string, rel: string) => string;
|