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
|
@@ -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[];
|