archidocs 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +62 -13
  2. package/dist/cli/commands.d.ts +231 -10
  3. package/dist/cli/commands.js +134 -9
  4. package/dist/cli/dev.d.ts +5 -6
  5. package/dist/cli/dev.js +12 -14
  6. package/dist/cli/diff-format.d.ts +1 -5
  7. package/dist/cli/init.d.ts +1 -1
  8. package/dist/cli/init.js +2 -2
  9. package/dist/cli/main.js +2 -329
  10. package/dist/cli/run.d.ts +18 -0
  11. package/dist/cli/run.js +283 -0
  12. package/dist/commands/build.d.ts +51 -0
  13. package/dist/commands/build.js +39 -0
  14. package/dist/commands/check.d.ts +8 -0
  15. package/dist/commands/check.js +5 -0
  16. package/dist/commands/diff.d.ts +29 -0
  17. package/dist/commands/diff.js +25 -0
  18. package/dist/commands/export.d.ts +41 -0
  19. package/dist/commands/export.js +47 -0
  20. package/dist/commands/history.d.ts +18 -0
  21. package/dist/commands/history.js +9 -0
  22. package/dist/commands/index.d.ts +11 -0
  23. package/dist/commands/index.js +11 -0
  24. package/dist/core/compare.d.ts +2 -13
  25. package/dist/core/compare.js +2 -35
  26. package/dist/core/index.d.ts +3 -6
  27. package/dist/core/index.js +3 -6
  28. package/dist/core/load.d.ts +0 -2
  29. package/dist/core/load.js +5 -6
  30. package/dist/core/rules.d.ts +10 -0
  31. package/dist/core/rules.js +186 -7
  32. package/dist/core/views/compare.d.ts +12 -0
  33. package/dist/core/views/compare.js +37 -0
  34. package/dist/core/{deployment-views.d.ts → views/deployment.d.ts} +4 -5
  35. package/dist/core/{deployment-views.js → views/deployment.js} +5 -7
  36. package/dist/core/{dynamic-views.d.ts → views/dynamic.d.ts} +1 -3
  37. package/dist/core/{dynamic-views.js → views/dynamic.js} +4 -8
  38. package/dist/core/views/generated.d.ts +18 -0
  39. package/dist/core/views/generated.js +92 -0
  40. package/dist/core/views/ids.d.ts +36 -0
  41. package/dist/core/views/ids.js +51 -0
  42. package/dist/core/views/index.d.ts +13 -0
  43. package/dist/core/views/index.js +12 -0
  44. package/dist/core/views/lens.d.ts +27 -0
  45. package/dist/core/views/lens.js +112 -0
  46. package/dist/core/views/model.d.ts +21 -0
  47. package/dist/core/views/model.js +69 -0
  48. package/dist/core/views/resolve.d.ts +42 -0
  49. package/dist/core/views/resolve.js +81 -0
  50. package/dist/core/{save-as-view.d.ts → views/save-as-view.d.ts} +2 -2
  51. package/dist/core/{save-as-view.js → views/save-as-view.js} +13 -10
  52. package/dist/core/{saved-views.d.ts → views/saved.d.ts} +4 -18
  53. package/dist/core/{saved-views.js → views/saved.js} +8 -103
  54. package/dist/core/views/types.d.ts +91 -0
  55. package/dist/core/views/types.js +2 -0
  56. package/dist/core/workspace-files.d.ts +13 -0
  57. package/dist/core/workspace-files.js +20 -0
  58. package/dist/git.d.ts +2 -0
  59. package/dist/git.js +14 -4
  60. package/dist/history/git.d.ts +0 -10
  61. package/dist/history/git.js +1 -30
  62. package/dist/history/index.d.ts +15 -31
  63. package/dist/history/index.js +47 -43
  64. package/dist/history/points.d.ts +23 -0
  65. package/dist/history/points.js +28 -0
  66. package/dist/history/site.d.ts +30 -0
  67. package/dist/history/site.js +37 -0
  68. package/dist/mcp/errors.d.ts +37 -0
  69. package/dist/mcp/errors.js +35 -0
  70. package/dist/mcp/history.d.ts +4 -4
  71. package/dist/mcp/history.js +56 -116
  72. package/dist/mcp/index.d.ts +2 -1
  73. package/dist/mcp/index.js +1 -0
  74. package/dist/mcp/server.d.ts +1 -2
  75. package/dist/mcp/server.js +30 -29
  76. package/dist/mcp/site.d.ts +12 -0
  77. package/dist/mcp/site.js +46 -0
  78. package/dist/mcp/source.d.ts +14 -7
  79. package/dist/mcp/source.js +25 -99
  80. package/dist/render/layout.d.ts +20 -3
  81. package/dist/render/layout.js +49 -12
  82. package/dist/render/sequence-svg.d.ts +1 -1
  83. package/dist/render/sequence.d.ts +1 -1
  84. package/dist/render/svg.d.ts +1 -1
  85. package/dist/render/svg.js +4 -4
  86. package/dist/revisions/find.d.ts +64 -0
  87. package/dist/revisions/find.js +85 -0
  88. package/dist/revisions/index.d.ts +57 -0
  89. package/dist/revisions/index.js +24 -0
  90. package/dist/revisions/site.d.ts +82 -0
  91. package/dist/revisions/site.js +157 -0
  92. package/dist/revisions/text.d.ts +8 -0
  93. package/dist/revisions/text.js +17 -0
  94. package/dist/revisions/touching.d.ts +7 -0
  95. package/dist/revisions/touching.js +7 -0
  96. package/dist/schema/adr.js +18 -13
  97. package/dist/schema/workspace.js +226 -130
  98. package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
  99. package/dist/viewer/assets/index-YFA-pYjQ.css +1 -0
  100. package/dist/viewer/assets/{layout.worker-Bg-OaLVN.js → layout.worker-BRHAGJrD.js} +1 -1
  101. package/dist/viewer/assets/{png-BDKIXtm5.js → png-DMwnpRCt.js} +1 -1
  102. package/dist/viewer/assets/{svg-Bulv5YWn.js → svg-DN6lMeZo.js} +2 -2
  103. package/dist/viewer/index.html +2 -2
  104. package/dist/workspace/index.d.ts +37 -0
  105. package/dist/workspace/index.js +52 -0
  106. package/guide/SKILL.md +1 -1
  107. package/guide/topics/bootstrap.md +1 -1
  108. package/guide/topics/relationships.md +1 -1
  109. package/package.json +4 -3
  110. package/schemas/adr.schema.json +18 -15
  111. package/schemas/model.schema.json +637 -1144
  112. package/schemas/project.schema.json +8 -4
  113. package/schemas/workspace.schema.json +39 -20
  114. package/dist/core/views.d.ts +0 -126
  115. package/dist/core/views.js +0 -217
  116. package/dist/viewer/assets/index-DvKgCpBr.css +0 -1
  117. package/dist/viewer/assets/index-gucix3xm.js +0 -113
  118. /package/dist/{history → revisions}/migrate.d.ts +0 -0
  119. /package/dist/{history → revisions}/migrate.js +0 -0
@@ -0,0 +1,82 @@
1
+ import type { Bundle } from "../schema/bundle.ts";
2
+ import { type Migration } from "./migrate.ts";
3
+ import { type RevisionEntry, type RevisionIndex } from "./index.ts";
4
+ /**
5
+ * A Bundle read from a site, latest or past: migrated to this Archidocs's
6
+ * schema and parsed. Undefined when it is newer than this Archidocs, a
7
+ * migration is missing, or it is not a Bundle at all.
8
+ */
9
+ export declare function readBundle(raw: unknown, chain?: Readonly<Record<number, Migration>>): Bundle | undefined;
10
+ /** A Revision index this version can read: {@link INDEX_VERSION} and an array of Revisions. Undefined otherwise. */
11
+ export declare function readIndex(raw: unknown): RevisionIndex | undefined;
12
+ /** What a host gave to tell whether a file has changed: an ETag, a Last-Modified date, or neither. */
13
+ export interface Validators {
14
+ etag?: string;
15
+ lastModified?: string;
16
+ }
17
+ /** A file read from a site: its text, unchanged since the validators sent, or not there (a 404 or ENOENT). */
18
+ export type SiteRead = {
19
+ kind: "text";
20
+ text: string;
21
+ validators: Validators;
22
+ } | {
23
+ kind: "not_modified";
24
+ } | {
25
+ kind: "missing";
26
+ };
27
+ /**
28
+ * Reads files below a site's root. A failure other than a missing file
29
+ * throws, and its message names where it read from.
30
+ */
31
+ export interface SiteReader {
32
+ /** Reads `path`, below the root with `/` separators; with validators, may answer "not modified". */
33
+ read(path: string, validators?: Validators): Promise<SiteRead>;
34
+ /** Where `path` is read from, a URL or a file path, for messages. */
35
+ location(path: string): string;
36
+ }
37
+ /**
38
+ * A browser-safe {@link SiteReader} over `fetch`, rooted at `base` (a URL
39
+ * or a relative path such as `"./"`). It never uses the HTTP cache: the
40
+ * validators it is given go out as `If-None-Match` and `If-Modified-Since`.
41
+ */
42
+ export declare function fetchReader(base: string): SiteReader;
43
+ /** Why a site can't give history: a past Bundle dropped by retention, missing, unreadable or unmigratable, or an unreadable index. */
44
+ export type UnavailableReason = "dropped" | "missing" | "unreadable" | "unmigratable" | "index";
45
+ /** History the site can't give, with a reason and a message naming what is wrong. */
46
+ export interface HistoryUnavailable {
47
+ ok: false;
48
+ code: "history_unavailable";
49
+ reason: UnavailableReason;
50
+ message: string;
51
+ }
52
+ export interface SiteOptions {
53
+ /** How long the latest Bundle and the index are trusted before the site is asked again; `Infinity` asks once. */
54
+ recheckMs: number;
55
+ /** The latest Bundle's path below the root. */
56
+ bundle?: string;
57
+ /** The migration chain; tests only, to migrate Bundles at a made-up older schema. */
58
+ migrations?: Readonly<Record<number, Migration>>;
59
+ }
60
+ /** A published site: its latest Bundle, its Revision index and its past Bundles. */
61
+ export interface Site {
62
+ /** Where the latest Bundle is read from. */
63
+ readonly location: string;
64
+ /** The latest Bundle. Rejects when it is missing, not JSON, or not a Bundle this version can read. */
65
+ latest(): Promise<Bundle>;
66
+ /** The Revision index; `index: undefined` when the site has none, which is no history. */
67
+ index(): Promise<{
68
+ ok: true;
69
+ index: RevisionIndex | undefined;
70
+ } | HistoryUnavailable>;
71
+ /** A past Revision's Bundle, fetched once; a failure is dropped so the next call asks again. */
72
+ bundle(revision: RevisionEntry): Promise<{
73
+ ok: true;
74
+ bundle: Bundle;
75
+ } | HistoryUnavailable>;
76
+ }
77
+ /**
78
+ * Opens a published site through `reader`. The latest Bundle and the index
79
+ * are re-checked at most every `recheckMs`, with conditional requests when
80
+ * the host gave validators; past Bundles never change, so each is read once.
81
+ */
82
+ export declare function openSite(reader: SiteReader, { recheckMs, bundle: latestPath, migrations: chain }: SiteOptions): Site;
@@ -0,0 +1,157 @@
1
+ import { migrateBundle, migrations } from "./migrate.js";
2
+ import { INDEX_PATH, INDEX_VERSION, LATEST_BUNDLE_PATH, pastBundlePath } from "./index.js";
3
+ /**
4
+ * A Bundle read from a site, latest or past: migrated to this Archidocs's
5
+ * schema and parsed. Undefined when it is newer than this Archidocs, a
6
+ * migration is missing, or it is not a Bundle at all.
7
+ */
8
+ export function readBundle(raw, chain = migrations) {
9
+ return migrateBundle(raw, chain);
10
+ }
11
+ /** A Revision index this version can read: {@link INDEX_VERSION} and an array of Revisions. Undefined otherwise. */
12
+ export function readIndex(raw) {
13
+ if (raw === null || typeof raw !== "object")
14
+ return undefined;
15
+ const { schemaVersion, revisions, preview } = raw;
16
+ if (schemaVersion !== INDEX_VERSION || !Array.isArray(revisions))
17
+ return undefined;
18
+ return {
19
+ schemaVersion,
20
+ revisions: revisions,
21
+ ...(typeof preview?.baseSha === "string" ? { preview: preview } : {}),
22
+ };
23
+ }
24
+ /**
25
+ * A browser-safe {@link SiteReader} over `fetch`, rooted at `base` (a URL
26
+ * or a relative path such as `"./"`). It never uses the HTTP cache: the
27
+ * validators it is given go out as `If-None-Match` and `If-Modified-Since`.
28
+ */
29
+ export function fetchReader(base) {
30
+ const root = base.endsWith("/") ? base : `${base}/`;
31
+ const location = (path) => `${root}${path}`;
32
+ return {
33
+ location,
34
+ async read(path, validators) {
35
+ const where = location(path);
36
+ const headers = { accept: "application/json" };
37
+ if (validators?.etag)
38
+ headers["if-none-match"] = validators.etag;
39
+ if (validators?.lastModified)
40
+ headers["if-modified-since"] = validators.lastModified;
41
+ const response = await fetch(where, { headers, cache: "no-store" });
42
+ if (response.status === 304)
43
+ return { kind: "not_modified" };
44
+ if (response.status === 404)
45
+ return { kind: "missing" };
46
+ if (!response.ok)
47
+ throw new Error(`${where} answered ${response.status} ${response.statusText}`.trim());
48
+ const etag = response.headers.get("etag");
49
+ const lastModified = response.headers.get("last-modified");
50
+ return { kind: "text", text: await response.text(), validators: { ...(etag ? { etag } : {}), ...(lastModified ? { lastModified } : {}) } };
51
+ },
52
+ };
53
+ }
54
+ const unavailable = (reason, message) => ({ ok: false, code: "history_unavailable", reason, message });
55
+ const errorText = (error) => (error instanceof Error ? error.message : String(error));
56
+ /**
57
+ * One file re-read at most every `recheckMs`, sending the validators of the
58
+ * text it holds. `interpret` turns the text (undefined when missing) into a
59
+ * value; only values `keep` accepts are held, so a failure is asked again.
60
+ */
61
+ function rechecked(reader, path, recheckMs, interpret, keep = () => true) {
62
+ let held;
63
+ return async () => {
64
+ const now = Date.now();
65
+ if (held && now - held.at < recheckMs)
66
+ return held.value;
67
+ const read = await reader.read(path, held?.validators);
68
+ if (read.kind === "not_modified") {
69
+ if (!held)
70
+ throw new Error(`${reader.location(path)} answered "not modified" to a request with no validators.`);
71
+ held = { ...held, at: now };
72
+ return held.value;
73
+ }
74
+ const value = interpret(read.kind === "text" ? read.text : undefined);
75
+ if (keep(value))
76
+ held = { value, at: now, validators: read.kind === "text" ? read.validators : {} };
77
+ return value;
78
+ };
79
+ }
80
+ const parseJson = (text) => {
81
+ try {
82
+ return { ok: true, value: JSON.parse(text) };
83
+ }
84
+ catch {
85
+ return { ok: false };
86
+ }
87
+ };
88
+ /**
89
+ * Opens a published site through `reader`. The latest Bundle and the index
90
+ * are re-checked at most every `recheckMs`, with conditional requests when
91
+ * the host gave validators; past Bundles never change, so each is read once.
92
+ */
93
+ export function openSite(reader, { recheckMs, bundle: latestPath = LATEST_BUNDLE_PATH, migrations: chain = migrations }) {
94
+ const location = reader.location(latestPath);
95
+ const latest = rechecked(reader, latestPath, recheckMs, (text) => {
96
+ if (text === undefined)
97
+ throw new Error(`${location} was not found.`);
98
+ const json = parseJson(text);
99
+ if (!json.ok)
100
+ throw new Error(`${location} is not JSON.`);
101
+ const read = readBundle(json.value, chain);
102
+ if (!read)
103
+ throw new Error(`${location} is not a Workspace Bundle this version can read.`);
104
+ return read;
105
+ });
106
+ const index = rechecked(reader, INDEX_PATH, recheckMs, (text) => {
107
+ if (text === undefined)
108
+ return { ok: true, index: undefined };
109
+ const json = parseJson(text);
110
+ if (!json.ok)
111
+ return unavailable("index", `The site has no readable Revision index (${INDEX_PATH}): ${reader.location(INDEX_PATH)} is not JSON.`);
112
+ const read = readIndex(json.value);
113
+ return read ? { ok: true, index: read } : unavailable("index", `The site's ${INDEX_PATH} holds no Revisions.`);
114
+ }, (value) => value.ok);
115
+ const pending = new Map();
116
+ const past = async (sha) => {
117
+ const short = sha.slice(0, 7);
118
+ let read;
119
+ try {
120
+ read = await reader.read(pastBundlePath(sha));
121
+ }
122
+ catch (error) {
123
+ return unavailable("unreadable", `The Bundle at ${short} can't be read from the site: ${errorText(error)}`);
124
+ }
125
+ if (read.kind !== "text")
126
+ return unavailable("missing", `The Bundle at ${short} can't be read from the site: ${reader.location(pastBundlePath(sha))} was not found.`);
127
+ const json = parseJson(read.text);
128
+ if (!json.ok)
129
+ return unavailable("unreadable", `The Bundle at ${short} can't be read from the site: ${reader.location(pastBundlePath(sha))} is not JSON.`);
130
+ const bundle = readBundle(json.value, chain);
131
+ return bundle ? { ok: true, bundle } : unavailable("unmigratable", `The Bundle at ${short} has a schema this Archidocs can't read or migrate.`);
132
+ };
133
+ return {
134
+ location,
135
+ latest,
136
+ async index() {
137
+ try {
138
+ return await index();
139
+ }
140
+ catch (error) {
141
+ return unavailable("index", `The site has no readable Revision index (${INDEX_PATH}): ${errorText(error)}`);
142
+ }
143
+ },
144
+ bundle(revision) {
145
+ if (revision.bundle === false)
146
+ return Promise.resolve(unavailable("dropped", `The Bundle at ${revision.sha.slice(0, 7)} (${revision.date}) was not kept on this site.`));
147
+ let read = pending.get(revision.sha);
148
+ if (!read) {
149
+ read = past(revision.sha);
150
+ pending.set(revision.sha, read);
151
+ // A failure may be a host's hiccup; ask again next time.
152
+ void read.then((r) => !r.ok && pending.delete(revision.sha));
153
+ }
154
+ return read;
155
+ },
156
+ };
157
+ }
@@ -0,0 +1,8 @@
1
+ import { Bundle } from "../schema/bundle.ts";
2
+ import type { RevisionIndex } from "./index.ts";
3
+ /** The Bundle as written to `workspace.bundle.json` (and to `bundles/<sha>.json`): stable key order, two-space indent. */
4
+ export declare function serializeBundle(bundle: Bundle): string;
5
+ /** `site.json`: the Workspace's name, for the viewer's exports. */
6
+ export declare function serializeSiteFile(workspace: string): string;
7
+ /** `bundles/index.json`: `schemaVersion`, then `preview` when set, then the Revisions; two-space indent. */
8
+ export declare function serializeIndex({ schemaVersion, preview, revisions }: RevisionIndex): string;
@@ -0,0 +1,17 @@
1
+ import { Bundle } from "../schema/bundle.js";
2
+ /*
3
+ * The text of a site's small files. Every writer, and `dev`, which serves a
4
+ * site from memory, takes its bytes from here, so all of them agree.
5
+ */
6
+ /** The Bundle as written to `workspace.bundle.json` (and to `bundles/<sha>.json`): stable key order, two-space indent. */
7
+ export function serializeBundle(bundle) {
8
+ return JSON.stringify(Bundle.parse(bundle), null, 2) + "\n";
9
+ }
10
+ /** `site.json`: the Workspace's name, for the viewer's exports. */
11
+ export function serializeSiteFile(workspace) {
12
+ return JSON.stringify({ workspace }) + "\n";
13
+ }
14
+ /** `bundles/index.json`: `schemaVersion`, then `preview` when set, then the Revisions; two-space indent. */
15
+ export function serializeIndex({ schemaVersion, preview, revisions }) {
16
+ return JSON.stringify(preview ? { schemaVersion, preview, revisions } : { schemaVersion, revisions }, null, 2) + "\n";
17
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The Revisions whose changed ids satisfy `matches`, newest first as the
3
+ * index lists them. `matches` is usually core's `scopeMatcher`.
4
+ */
5
+ export declare function touching<R extends {
6
+ changedIds: string[];
7
+ }>(revisions: readonly R[], matches: (ids: string[]) => boolean): R[];
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The Revisions whose changed ids satisfy `matches`, newest first as the
3
+ * index lists them. `matches` is usually core's `scopeMatcher`.
4
+ */
5
+ export function touching(revisions, matches) {
6
+ return revisions.filter((r) => matches(r.changedIds));
7
+ }
@@ -8,20 +8,25 @@ export const ADR_FILENAME = /^(\d{4})-[a-z0-9][a-z0-9-]*\.md$/;
8
8
  export const AdrRef = z
9
9
  .string()
10
10
  .regex(/^([a-z0-9][a-z0-9-]*:)?\d{4}$/, "must be an ADR number (NNNN), or `project:NNNN` for one in another Project")
11
- .describe("An ADR number in this Project, or `project:NNNN` for one in another Project");
12
- const people = z.array(z.string()).describe("People or Team ids; not checked");
11
+ .describe("An ADR number in this Project, or `project:NNNN` for one in another Project.");
12
+ const people = z.array(z.string());
13
13
  /**
14
14
  * An ADR's frontmatter, with field names following MADR v4. The title is the
15
15
  * body's first `# ` heading, not a field.
16
16
  */
17
- export const AdrFrontmatter = z.strictObject({
18
- status: AdrStatus,
19
- date: z.iso.date("must be an ISO date (YYYY-MM-DD)").describe("The date of the last status change"),
20
- "decision-makers": people.optional(),
21
- consulted: people.optional(),
22
- informed: people.optional(),
23
- tags: z.array(z.string()).optional(),
24
- elements: z.array(Ref).optional().describe("Elements and Deployment Targets the decision affects"),
25
- views: z.array(Ref).optional().describe("Saved Views the decision affects"),
26
- supersedes: z.array(AdrRef).optional().describe("ADRs this one replaces once accepted"),
27
- });
17
+ export const AdrFrontmatter = z
18
+ .strictObject({
19
+ status: AdrStatus.describe("Where the decision stands. `proposed`: awaiting acceptance in a pull request. `accepted`: in force. `rejected`: turned down, and kept for its reasoning. `deprecated`: no longer in force, with no ADR replacing it. `superseded`: never written by hand; it is derived once an accepted ADR lists this one in `supersedes`."),
20
+ date: z.iso.date("must be an ISO date (YYYY-MM-DD)").describe("The date of the last status change, as `YYYY-MM-DD`."),
21
+ "decision-makers": people.optional().describe("Who made the decision: people's names or Team ids. Not checked."),
22
+ consulted: people.optional().describe("Who was asked for input: people's names or Team ids. Not checked."),
23
+ informed: people.optional().describe("Who was told of the decision: people's names or Team ids. Not checked."),
24
+ tags: z.array(z.string()).optional().describe("Free-form labels for the ADR."),
25
+ elements: z.array(Ref).optional().describe("The Elements and Deployment Targets the decision affects, each as an id in this Project or `project:id`."),
26
+ views: z.array(Ref).optional().describe("The Saved Views the decision affects, each as an id in this Project or `project:id`."),
27
+ supersedes: z
28
+ .array(AdrRef)
29
+ .optional()
30
+ .describe("The ADRs this one replaces once it is accepted, each as a four-digit number in this Project or `project:NNNN`. Only an accepted or deprecated ADR can be superseded."),
31
+ })
32
+ .describe("An ADR's frontmatter. The ADR's title is the first `# ` heading of its body, not a field.");