archidocs 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -15
- package/dist/cli/commands.d.ts +19 -11
- package/dist/cli/commands.js +12 -10
- package/dist/cli/dev.d.ts +5 -6
- package/dist/cli/dev.js +12 -14
- package/dist/cli/diff-format.d.ts +1 -5
- package/dist/cli/init.d.ts +11 -1
- package/dist/cli/init.js +121 -10
- package/dist/cli/main.js +2 -324
- package/dist/cli/run.d.ts +18 -0
- package/dist/cli/run.js +312 -0
- package/dist/commands/build.d.ts +51 -0
- package/dist/commands/build.js +39 -0
- package/dist/commands/check.d.ts +8 -0
- package/dist/commands/check.js +5 -0
- package/dist/commands/diff.d.ts +29 -0
- package/dist/commands/diff.js +25 -0
- package/dist/commands/export.d.ts +41 -0
- package/dist/commands/export.js +47 -0
- package/dist/commands/history.d.ts +18 -0
- package/dist/commands/history.js +9 -0
- package/dist/commands/index.d.ts +11 -0
- package/dist/commands/index.js +11 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/load.d.ts +0 -2
- package/dist/core/load.js +5 -6
- package/dist/core/workspace-files.d.ts +13 -0
- package/dist/core/workspace-files.js +20 -0
- package/dist/git.d.ts +2 -0
- package/dist/git.js +14 -4
- package/dist/guide/index.d.ts +5 -4
- package/dist/guide/index.js +6 -5
- package/dist/history/git.d.ts +0 -10
- package/dist/history/git.js +1 -30
- package/dist/history/index.d.ts +15 -31
- package/dist/history/index.js +47 -43
- package/dist/history/points.d.ts +23 -0
- package/dist/history/points.js +28 -0
- package/dist/history/site.d.ts +30 -0
- package/dist/history/site.js +37 -0
- package/dist/mcp/announce.d.ts +25 -0
- package/dist/mcp/announce.js +54 -0
- package/dist/mcp/check.d.ts +17 -0
- package/dist/mcp/check.js +52 -0
- package/dist/mcp/history.d.ts +4 -4
- package/dist/mcp/history.js +56 -116
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/server.d.ts +6 -0
- package/dist/mcp/server.js +30 -21
- package/dist/mcp/site.d.ts +12 -0
- package/dist/mcp/site.js +46 -0
- package/dist/mcp/source.d.ts +14 -7
- package/dist/mcp/source.js +25 -99
- package/dist/mcp/writes.d.ts +2 -2
- package/dist/mcp/writes.js +3 -3
- package/dist/revisions/find.d.ts +64 -0
- package/dist/revisions/find.js +85 -0
- package/dist/revisions/index.d.ts +57 -0
- package/dist/revisions/index.js +24 -0
- package/dist/revisions/site.d.ts +82 -0
- package/dist/revisions/site.js +157 -0
- package/dist/revisions/text.d.ts +8 -0
- package/dist/revisions/text.js +17 -0
- package/dist/revisions/touching.d.ts +7 -0
- package/dist/revisions/touching.js +7 -0
- package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
- package/dist/viewer/assets/{png-CAaXWR-k.js → png-DMwnpRCt.js} +1 -1
- package/dist/viewer/assets/{svg-BPVHfD36.js → svg-DN6lMeZo.js} +1 -1
- package/dist/viewer/index.html +1 -1
- package/dist/workspace/index.d.ts +37 -0
- package/dist/workspace/index.js +52 -0
- package/guide/SKILL.md +2 -0
- package/package.json +1 -1
- package/dist/viewer/assets/index-BXa5R96a.js +0 -138
- /package/dist/{history → revisions}/migrate.d.ts +0 -0
- /package/dist/{history → revisions}/migrate.js +0 -0
package/dist/mcp/source.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { gitHead } from "../git.js";
|
|
5
|
-
import { Bundle } from "../schema/bundle.js";
|
|
1
|
+
import { checkoutAt } from "../workspace/index.js";
|
|
2
|
+
import { openSite } from "../revisions/index.js";
|
|
3
|
+
import { siteAt } from "./site.js";
|
|
6
4
|
/**
|
|
7
5
|
* A local checkout: the Bundle is built in memory and rebuilt when a file
|
|
8
6
|
* under the Workspace root changes or HEAD moves. Change is detected per
|
|
@@ -10,123 +8,51 @@ import { Bundle } from "../schema/bundle.js";
|
|
|
10
8
|
* next call with no watcher to start or stop.
|
|
11
9
|
*/
|
|
12
10
|
export function checkoutSource({ root }) {
|
|
11
|
+
const checkout = checkoutAt(root);
|
|
13
12
|
let cached;
|
|
14
13
|
return {
|
|
15
14
|
kind: "checkout",
|
|
16
15
|
root,
|
|
16
|
+
checkout,
|
|
17
17
|
writesAllowed: true,
|
|
18
18
|
async snapshot() {
|
|
19
|
-
const [files, head] = await Promise.all([fingerprint(
|
|
19
|
+
const [files, head] = await Promise.all([checkout.fingerprint(), checkout.head()]);
|
|
20
20
|
const key = `${head.commit}\n${head.builtAt}\n${files}`;
|
|
21
|
-
if (cached?.key !== key)
|
|
22
|
-
cached = { key, snapshot: await load(
|
|
23
|
-
}
|
|
21
|
+
if (cached?.key !== key)
|
|
22
|
+
cached = { key, snapshot: await checkout.load() };
|
|
24
23
|
return cached.snapshot;
|
|
25
24
|
},
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
|
-
/** How long
|
|
27
|
+
/** How long the site's latest Bundle and index are trusted before the site is asked again. */
|
|
29
28
|
const RECHECK_MS = 60_000;
|
|
30
|
-
const BUNDLE_FILE = "workspace.bundle.json";
|
|
31
29
|
/**
|
|
32
30
|
* A published Workspace Bundle, read-only. `location` is a URL or a path,
|
|
33
31
|
* naming either the Bundle file or the site (folder) that holds
|
|
34
|
-
* `workspace.bundle.json`. The
|
|
35
|
-
* HTTP the re-check is a conditional
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
32
|
+
* `workspace.bundle.json`. The Bundle and the site's Revision index are
|
|
33
|
+
* re-checked at most every 60 s; over HTTP the re-check is a conditional
|
|
34
|
+
* request when the host gave an ETag or Last-Modified, so an unchanged file
|
|
35
|
+
* costs a 304. A Bundle from an older Archidocs is migrated. A source that
|
|
36
|
+
* can't be read, or doesn't hold a Bundle this version can read, rejects and
|
|
37
|
+
* the tool returns `source_unavailable`; the next call tries again.
|
|
39
38
|
*/
|
|
40
39
|
export function bundleSource({ location }) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
let
|
|
44
|
-
const fetchUrl = async (href) => {
|
|
45
|
-
const headers = { accept: "application/json" };
|
|
46
|
-
if (cached?.etag)
|
|
47
|
-
headers["if-none-match"] = cached.etag;
|
|
48
|
-
if (cached?.lastModified)
|
|
49
|
-
headers["if-modified-since"] = cached.lastModified;
|
|
50
|
-
const response = await fetch(href, { headers, cache: "no-store" });
|
|
51
|
-
if (response.status === 304 && cached)
|
|
52
|
-
return cached;
|
|
53
|
-
if (!response.ok)
|
|
54
|
-
throw new Error(`${href} answered ${response.status} ${response.statusText}`.trim());
|
|
55
|
-
return {
|
|
56
|
-
snapshot: parse(await response.text(), href),
|
|
57
|
-
checkedAt: 0,
|
|
58
|
-
etag: response.headers.get("etag") ?? undefined,
|
|
59
|
-
lastModified: response.headers.get("last-modified") ?? undefined,
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
const readPath = async () => {
|
|
63
|
-
path ??= await bundlePath(location);
|
|
64
|
-
const s = await stat(path);
|
|
65
|
-
const fileKey = `${s.mtimeMs}\0${s.size}`;
|
|
66
|
-
if (cached?.fileKey === fileKey)
|
|
67
|
-
return cached;
|
|
68
|
-
return { snapshot: parse(await readFile(path, "utf8"), path), checkedAt: 0, fileKey };
|
|
69
|
-
};
|
|
40
|
+
const { reader, bundle } = siteAt(location);
|
|
41
|
+
const site = openSite(reader, { recheckMs: RECHECK_MS, bundle });
|
|
42
|
+
let held;
|
|
70
43
|
return {
|
|
71
44
|
kind: "bundle",
|
|
45
|
+
site,
|
|
72
46
|
get location() {
|
|
73
|
-
return
|
|
47
|
+
return site.location;
|
|
74
48
|
},
|
|
75
49
|
writesAllowed: false,
|
|
76
50
|
async snapshot() {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return cached.snapshot;
|
|
51
|
+
const latest = await site.latest();
|
|
52
|
+
// A Bundle is only ever published from a Workspace with no errors; check's warnings aren't kept in it.
|
|
53
|
+
if (held?.bundle !== latest)
|
|
54
|
+
held = { bundle: latest, issues: [] };
|
|
55
|
+
return held;
|
|
83
56
|
},
|
|
84
57
|
};
|
|
85
58
|
}
|
|
86
|
-
/** A site root URL becomes its `workspace.bundle.json`; a URL to a `.json` file is used as given. */
|
|
87
|
-
function bundleUrl(location) {
|
|
88
|
-
const url = new URL(location);
|
|
89
|
-
if (url.pathname.endsWith(".json"))
|
|
90
|
-
return url.href;
|
|
91
|
-
if (!url.pathname.endsWith("/"))
|
|
92
|
-
url.pathname += "/";
|
|
93
|
-
return new URL(BUNDLE_FILE, url).href;
|
|
94
|
-
}
|
|
95
|
-
/** A folder becomes its `workspace.bundle.json`; a file is used as given. */
|
|
96
|
-
async function bundlePath(location) {
|
|
97
|
-
const path = resolve(location);
|
|
98
|
-
return (await stat(path)).isDirectory() ? join(path, BUNDLE_FILE) : path;
|
|
99
|
-
}
|
|
100
|
-
function parse(text, from) {
|
|
101
|
-
let json;
|
|
102
|
-
try {
|
|
103
|
-
json = JSON.parse(text);
|
|
104
|
-
}
|
|
105
|
-
catch {
|
|
106
|
-
throw new Error(`${from} is not JSON.`);
|
|
107
|
-
}
|
|
108
|
-
const bundle = Bundle.safeParse(json);
|
|
109
|
-
if (!bundle.success)
|
|
110
|
-
throw new Error(`${from} is not a Workspace Bundle this version can read.`);
|
|
111
|
-
// A Bundle is only ever published from a Workspace with no errors; check's warnings aren't kept in it.
|
|
112
|
-
return { bundle: bundle.data, issues: [] };
|
|
113
|
-
}
|
|
114
|
-
/** Path, mtime and size of every `.yaml` and `.md` file (ADRs) under the root, in a stable order. */
|
|
115
|
-
async function fingerprint(root) {
|
|
116
|
-
const lines = [];
|
|
117
|
-
const dirs = [root];
|
|
118
|
-
for (let i = 0; i < dirs.length; i++) {
|
|
119
|
-
for (const entry of await readdir(dirs[i], { withFileTypes: true })) {
|
|
120
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
121
|
-
continue;
|
|
122
|
-
const path = join(dirs[i], entry.name);
|
|
123
|
-
if (entry.isDirectory())
|
|
124
|
-
dirs.push(path);
|
|
125
|
-
else if (entry.name.endsWith(".yaml") || entry.name.endsWith(".md")) {
|
|
126
|
-
const s = await stat(path);
|
|
127
|
-
lines.push(`${path}\0${s.mtimeMs}\0${s.size}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return lines.sort().join("\n");
|
|
132
|
-
}
|
package/dist/mcp/writes.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/server";
|
|
1
|
+
import type { CallToolResult, McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import type { Source } from "./source.ts";
|
|
3
3
|
/**
|
|
4
4
|
* The Model write tools: thin adapters over the YAML writer. Each edits the
|
|
@@ -7,4 +7,4 @@ import type { Source } from "./source.ts";
|
|
|
7
7
|
* They never touch git. With `readOnly` set (a Bundle source, or HTTP
|
|
8
8
|
* without --allow-writes) each returns `read_only` with that reason.
|
|
9
9
|
*/
|
|
10
|
-
export declare function registerWriteTools(server: McpServer, source: Source, readOnly: string | undefined): void;
|
|
10
|
+
export declare function registerWriteTools(server: McpServer, source: Source, readOnly: string | undefined, logged: (name: string, write: boolean, handle: (raw: unknown) => Promise<CallToolResult>) => (raw: unknown) => Promise<CallToolResult>): void;
|
package/dist/mcp/writes.js
CHANGED
|
@@ -30,7 +30,7 @@ const WriteOutput = z.object({
|
|
|
30
30
|
* They never touch git. With `readOnly` set (a Bundle source, or HTTP
|
|
31
31
|
* without --allow-writes) each returns `read_only` with that reason.
|
|
32
32
|
*/
|
|
33
|
-
export function registerWriteTools(server, source, readOnly) {
|
|
33
|
+
export function registerWriteTools(server, source, readOnly, logged) {
|
|
34
34
|
const fs = nodeFileSystem();
|
|
35
35
|
const writeTool = (name, config, toRequest) => {
|
|
36
36
|
server.registerTool(name, {
|
|
@@ -39,7 +39,7 @@ export function registerWriteTools(server, source, readOnly) {
|
|
|
39
39
|
inputSchema: advertise(config.input),
|
|
40
40
|
outputSchema: WriteOutput,
|
|
41
41
|
annotations: { readOnlyHint: false, destructiveHint: config.destructive ?? false, idempotentHint: config.idempotent ?? true, openWorldHint: false },
|
|
42
|
-
}, async (raw) => {
|
|
42
|
+
}, logged(name, true, async (raw) => {
|
|
43
43
|
if (readOnly !== undefined || source.kind !== "checkout")
|
|
44
44
|
return toResult({ ok: false, code: "read_only", message: readOnly ?? "Write tools need a checkout." });
|
|
45
45
|
if (takesAt(raw))
|
|
@@ -56,7 +56,7 @@ export function registerWriteTools(server, source, readOnly) {
|
|
|
56
56
|
return toResult({ ok: false, code: "source_unavailable", message: `Could not write the Workspace at ${source.root}: ${error instanceof Error ? error.message : String(error)}` });
|
|
57
57
|
}
|
|
58
58
|
return toResult(outcome(result));
|
|
59
|
-
});
|
|
59
|
+
}));
|
|
60
60
|
};
|
|
61
61
|
writeTool("upsert_element", {
|
|
62
62
|
title: "Add or update an Element",
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The point grammar: how a tag, a sha (or its prefix), a day or a time names
|
|
3
|
+
* a Revision. One reading for the viewer, MCP on a site and, through ticket
|
|
4
|
+
* 05, a checkout, so a point names the same Revision everywhere.
|
|
5
|
+
*/
|
|
6
|
+
/** What `find` needs of a Revision; the index's `RevisionEntry` is one. */
|
|
7
|
+
export interface Dated {
|
|
8
|
+
sha: string;
|
|
9
|
+
/** ISO 8601, as git's `%cI` writes it. */
|
|
10
|
+
date: string;
|
|
11
|
+
tags: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
/** The point grammar in one sentence, for every reference that takes a point. */
|
|
14
|
+
export declare const POINT_GRAMMAR = "a tag, a commit sha or its first 4 or more characters, or a date (`YYYY-MM-DD`) or time (ISO 8601, UTC unless it gives a zone)";
|
|
15
|
+
/** The Revision a point names, or why it names none. */
|
|
16
|
+
export type Found<R extends Dated> = {
|
|
17
|
+
ok: true;
|
|
18
|
+
revision: R;
|
|
19
|
+
}
|
|
20
|
+
/** `tags` to suggest; `first` is the first Revision when the point is a date or time before it. */
|
|
21
|
+
| {
|
|
22
|
+
ok: false;
|
|
23
|
+
kind: "not_found";
|
|
24
|
+
tags: string[];
|
|
25
|
+
first?: R;
|
|
26
|
+
}
|
|
27
|
+
/** `count` Revisions' shas start with the point; `candidates` are the newest 5 of them. */
|
|
28
|
+
| {
|
|
29
|
+
ok: false;
|
|
30
|
+
kind: "ambiguous";
|
|
31
|
+
count: number;
|
|
32
|
+
candidates: R[];
|
|
33
|
+
};
|
|
34
|
+
/** A stretch of time in ms since the epoch: from `start` up to, but not including, `end`. */
|
|
35
|
+
export interface Span {
|
|
36
|
+
start: number;
|
|
37
|
+
end: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The span a day or a time stands for, or undefined when the point is
|
|
41
|
+
* neither. A day (`YYYY-MM-DD`) is the UTC day `[00:00Z, next 00:00Z)`; a
|
|
42
|
+
* time is its one instant, read as UTC when it gives no zone.
|
|
43
|
+
*/
|
|
44
|
+
export declare function timeSpan(point: string): Span | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The Revision a point names, over Revisions listed newest first. In order:
|
|
47
|
+
* 1. an exact tag: the newest Revision carrying it;
|
|
48
|
+
* 2. a day or a time: the last Revision dated before the span's end;
|
|
49
|
+
* 3. hex of 4 to 64 characters, any case: the one Revision whose sha starts with it.
|
|
50
|
+
* Anything else, or nothing found, is `not_found`; hex that starts several shas is `ambiguous`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function find<R extends Dated>(revisions: readonly R[], point: string): Found<R>;
|
|
53
|
+
/**
|
|
54
|
+
* The time a point spans, for `since`/`until`/`at` filters: a tag or a sha
|
|
55
|
+
* spans its Revision's one instant, a day its whole UTC day, a time its one
|
|
56
|
+
* instant. A day or time spans itself even with no Revision in or before it.
|
|
57
|
+
* Keep a Revision dated `>=` the `since` span's start and `<` the `until` span's end.
|
|
58
|
+
*/
|
|
59
|
+
export declare function span<R extends Dated>(revisions: readonly R[], point: string): {
|
|
60
|
+
ok: true;
|
|
61
|
+
span: Span;
|
|
62
|
+
} | Exclude<Found<R>, {
|
|
63
|
+
ok: true;
|
|
64
|
+
}>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The point grammar: how a tag, a sha (or its prefix), a day or a time names
|
|
3
|
+
* a Revision. One reading for the viewer, MCP on a site and, through ticket
|
|
4
|
+
* 05, a checkout, so a point names the same Revision everywhere.
|
|
5
|
+
*/
|
|
6
|
+
/** The point grammar in one sentence, for every reference that takes a point. */
|
|
7
|
+
export const POINT_GRAMMAR = "a tag, a commit sha or its first 4 or more characters, or a date (`YYYY-MM-DD`) or time (ISO 8601, UTC unless it gives a zone)";
|
|
8
|
+
/** How many candidates or tags a failure carries. */
|
|
9
|
+
const MAX_LISTED = 5;
|
|
10
|
+
const DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
11
|
+
const TIME = /^(\d{4}-\d{2}-\d{2})[Tt ](\d{2}:\d{2})(:\d{2}(?:\.\d+)?)?([Zz]|[+-]\d{2}:?\d{2})?$/;
|
|
12
|
+
const HEX = /^[0-9a-f]{4,64}$/i;
|
|
13
|
+
const DAY_MS = 86_400_000;
|
|
14
|
+
/**
|
|
15
|
+
* The span a day or a time stands for, or undefined when the point is
|
|
16
|
+
* neither. A day (`YYYY-MM-DD`) is the UTC day `[00:00Z, next 00:00Z)`; a
|
|
17
|
+
* time is its one instant, read as UTC when it gives no zone.
|
|
18
|
+
*/
|
|
19
|
+
export function timeSpan(point) {
|
|
20
|
+
const day = DAY.exec(point);
|
|
21
|
+
if (day) {
|
|
22
|
+
const start = Date.parse(`${point}T00:00:00Z`);
|
|
23
|
+
// Date.parse takes 2026-02-30 as March 2nd; a day must read back as itself.
|
|
24
|
+
if (Number.isNaN(start) || new Date(start).toISOString().slice(0, 10) !== point)
|
|
25
|
+
return undefined;
|
|
26
|
+
return { start, end: start + DAY_MS };
|
|
27
|
+
}
|
|
28
|
+
const time = TIME.exec(point);
|
|
29
|
+
if (!time)
|
|
30
|
+
return undefined;
|
|
31
|
+
const [, date, minutes, seconds = ":00", zone = "Z"] = time;
|
|
32
|
+
const offset = zone.toUpperCase() === "Z" ? "Z" : `${zone.slice(0, 3)}:${zone.slice(-2)}`;
|
|
33
|
+
const at = Date.parse(`${date}T${minutes}${seconds}${offset}`);
|
|
34
|
+
if (Number.isNaN(at) || !timeSpan(date))
|
|
35
|
+
return undefined;
|
|
36
|
+
return instant(at);
|
|
37
|
+
}
|
|
38
|
+
const instant = (at) => ({ start: at, end: at + 1 });
|
|
39
|
+
/**
|
|
40
|
+
* The Revision a point names, over Revisions listed newest first. In order:
|
|
41
|
+
* 1. an exact tag: the newest Revision carrying it;
|
|
42
|
+
* 2. a day or a time: the last Revision dated before the span's end;
|
|
43
|
+
* 3. hex of 4 to 64 characters, any case: the one Revision whose sha starts with it.
|
|
44
|
+
* Anything else, or nothing found, is `not_found`; hex that starts several shas is `ambiguous`.
|
|
45
|
+
*/
|
|
46
|
+
export function find(revisions, point) {
|
|
47
|
+
const tagged = revisions.find((r) => r.tags.includes(point));
|
|
48
|
+
if (tagged)
|
|
49
|
+
return { ok: true, revision: tagged };
|
|
50
|
+
const span = timeSpan(point);
|
|
51
|
+
if (span) {
|
|
52
|
+
const last = revisions.find((r) => Date.parse(r.date) < span.end);
|
|
53
|
+
if (last)
|
|
54
|
+
return { ok: true, revision: last };
|
|
55
|
+
return notFound(revisions, revisions.at(-1));
|
|
56
|
+
}
|
|
57
|
+
if (HEX.test(point)) {
|
|
58
|
+
const prefix = point.toLowerCase();
|
|
59
|
+
const matches = revisions.filter((r) => r.sha.toLowerCase().startsWith(prefix));
|
|
60
|
+
if (matches.length === 1)
|
|
61
|
+
return { ok: true, revision: matches[0] };
|
|
62
|
+
if (matches.length > 1)
|
|
63
|
+
return { ok: false, kind: "ambiguous", count: matches.length, candidates: matches.slice(0, MAX_LISTED) };
|
|
64
|
+
}
|
|
65
|
+
return notFound(revisions);
|
|
66
|
+
}
|
|
67
|
+
function notFound(revisions, first) {
|
|
68
|
+
return { ok: false, kind: "not_found", tags: revisions.flatMap((r) => r.tags).slice(0, MAX_LISTED), ...(first ? { first } : {}) };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The time a point spans, for `since`/`until`/`at` filters: a tag or a sha
|
|
72
|
+
* spans its Revision's one instant, a day its whole UTC day, a time its one
|
|
73
|
+
* instant. A day or time spans itself even with no Revision in or before it.
|
|
74
|
+
* Keep a Revision dated `>=` the `since` span's start and `<` the `until` span's end.
|
|
75
|
+
*/
|
|
76
|
+
export function span(revisions, point) {
|
|
77
|
+
const tagged = revisions.find((r) => r.tags.includes(point));
|
|
78
|
+
if (!tagged) {
|
|
79
|
+
const own = timeSpan(point);
|
|
80
|
+
if (own)
|
|
81
|
+
return { ok: true, span: own };
|
|
82
|
+
}
|
|
83
|
+
const found = find(revisions, point);
|
|
84
|
+
return found.ok ? { ok: true, span: instant(Date.parse(found.revision.date)) } : found;
|
|
85
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Revision index and the layout of a published site. Browser-safe: the
|
|
3
|
+
* viewer imports it as MCP and the CLI do, so nothing here may import from
|
|
4
|
+
* `node:`. This file is the module's only entry.
|
|
5
|
+
*/
|
|
6
|
+
import type { ChangeCounts } from "../core/diff.ts";
|
|
7
|
+
/**
|
|
8
|
+
* The Revision index's own version, written under the JSON key
|
|
9
|
+
* `schemaVersion`. It is independent of the Bundle's `SCHEMA_VERSION`,
|
|
10
|
+
* though both are 1 today: either can change without the other.
|
|
11
|
+
*/
|
|
12
|
+
export declare const INDEX_VERSION = 1;
|
|
13
|
+
/** One Revision as the index records it; `bundle: false` marks a Revision whose Bundle was dropped. */
|
|
14
|
+
export interface RevisionEntry {
|
|
15
|
+
sha: string;
|
|
16
|
+
date: string;
|
|
17
|
+
subject: string;
|
|
18
|
+
author: string;
|
|
19
|
+
tags: string[];
|
|
20
|
+
/** Changes against the previous Revision (or an empty Model for the first). */
|
|
21
|
+
counts: ChangeCounts;
|
|
22
|
+
changedIds: string[];
|
|
23
|
+
bundle: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** What a preview site's index adds: the base branch and both sides' shas, so the viewer opens with Compare "base → PR". */
|
|
26
|
+
export interface PreviewMark {
|
|
27
|
+
base: string;
|
|
28
|
+
baseSha: string;
|
|
29
|
+
headSha: string;
|
|
30
|
+
}
|
|
31
|
+
/** The Revision index, as `bundles/index.json` and a checkout's cache hold it. */
|
|
32
|
+
export interface RevisionIndex {
|
|
33
|
+
/** {@link INDEX_VERSION}, not the Bundle's schema version. */
|
|
34
|
+
schemaVersion: number;
|
|
35
|
+
/** Newest first. */
|
|
36
|
+
revisions: RevisionEntry[];
|
|
37
|
+
/** Set by `build --preview`. */
|
|
38
|
+
preview?: PreviewMark;
|
|
39
|
+
}
|
|
40
|
+
/** A site's paths, relative to its root with `/` separators. */
|
|
41
|
+
export declare const LATEST_BUNDLE_PATH = "workspace.bundle.json";
|
|
42
|
+
/** The file that names the Workspace for the viewer's exports. */
|
|
43
|
+
export declare const SITE_FILE_PATH = "site.json";
|
|
44
|
+
/** The folder of past Bundles and the Revision index. */
|
|
45
|
+
export declare const BUNDLES_DIR = "bundles";
|
|
46
|
+
export declare const INDEX_PATH = "bundles/index.json";
|
|
47
|
+
/** A past Bundle's path: `bundles/<sha>.json`. */
|
|
48
|
+
export declare const pastBundlePath: (sha: string) => string;
|
|
49
|
+
/** A past Bundle's file name within `bundles/`. */
|
|
50
|
+
export declare const pastBundleFile: (sha: string) => string;
|
|
51
|
+
/** Whether a file name in `bundles/` is a past Bundle's, named by its full sha. */
|
|
52
|
+
export declare const isPastBundleFile: (name: string) => boolean;
|
|
53
|
+
export { find, span, timeSpan, POINT_GRAMMAR, type Dated, type Found, type Span } from "./find.ts";
|
|
54
|
+
export { touching } from "./touching.ts";
|
|
55
|
+
export { migrateBundle, migrations, type Migration } from "./migrate.ts";
|
|
56
|
+
export { fetchReader, openSite, readBundle, readIndex, type HistoryUnavailable, type Site, type SiteOptions, type SiteRead, type SiteReader, type UnavailableReason, type Validators, } from "./site.ts";
|
|
57
|
+
export { serializeBundle, serializeIndex, serializeSiteFile } from "./text.ts";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Revision index's own version, written under the JSON key
|
|
3
|
+
* `schemaVersion`. It is independent of the Bundle's `SCHEMA_VERSION`,
|
|
4
|
+
* though both are 1 today: either can change without the other.
|
|
5
|
+
*/
|
|
6
|
+
export const INDEX_VERSION = 1;
|
|
7
|
+
/** A site's paths, relative to its root with `/` separators. */
|
|
8
|
+
export const LATEST_BUNDLE_PATH = "workspace.bundle.json";
|
|
9
|
+
/** The file that names the Workspace for the viewer's exports. */
|
|
10
|
+
export const SITE_FILE_PATH = "site.json";
|
|
11
|
+
/** The folder of past Bundles and the Revision index. */
|
|
12
|
+
export const BUNDLES_DIR = "bundles";
|
|
13
|
+
export const INDEX_PATH = `${BUNDLES_DIR}/index.json`;
|
|
14
|
+
/** A past Bundle's path: `bundles/<sha>.json`. */
|
|
15
|
+
export const pastBundlePath = (sha) => `${BUNDLES_DIR}/${pastBundleFile(sha)}`;
|
|
16
|
+
/** A past Bundle's file name within `bundles/`. */
|
|
17
|
+
export const pastBundleFile = (sha) => `${sha}.json`;
|
|
18
|
+
/** Whether a file name in `bundles/` is a past Bundle's, named by its full sha. */
|
|
19
|
+
export const isPastBundleFile = (name) => /^[0-9a-f]{40,64}\.json$/.test(name);
|
|
20
|
+
export { find, span, timeSpan, POINT_GRAMMAR } from "./find.js";
|
|
21
|
+
export { touching } from "./touching.js";
|
|
22
|
+
export { migrateBundle, migrations } from "./migrate.js";
|
|
23
|
+
export { fetchReader, openSite, readBundle, readIndex, } from "./site.js";
|
|
24
|
+
export { serializeBundle, serializeIndex, serializeSiteFile } from "./text.js";
|
|
@@ -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;
|