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.
- package/README.md +62 -13
- package/dist/cli/commands.d.ts +231 -10
- package/dist/cli/commands.js +134 -9
- 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 +1 -1
- package/dist/cli/init.js +2 -2
- package/dist/cli/main.js +2 -329
- package/dist/cli/run.d.ts +18 -0
- package/dist/cli/run.js +283 -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/compare.d.ts +2 -13
- package/dist/core/compare.js +2 -35
- package/dist/core/index.d.ts +3 -6
- package/dist/core/index.js +3 -6
- package/dist/core/load.d.ts +0 -2
- package/dist/core/load.js +5 -6
- package/dist/core/rules.d.ts +10 -0
- package/dist/core/rules.js +186 -7
- package/dist/core/views/compare.d.ts +12 -0
- package/dist/core/views/compare.js +37 -0
- package/dist/core/{deployment-views.d.ts → views/deployment.d.ts} +4 -5
- package/dist/core/{deployment-views.js → views/deployment.js} +5 -7
- package/dist/core/{dynamic-views.d.ts → views/dynamic.d.ts} +1 -3
- package/dist/core/{dynamic-views.js → views/dynamic.js} +4 -8
- package/dist/core/views/generated.d.ts +18 -0
- package/dist/core/views/generated.js +92 -0
- package/dist/core/views/ids.d.ts +36 -0
- package/dist/core/views/ids.js +51 -0
- package/dist/core/views/index.d.ts +13 -0
- package/dist/core/views/index.js +12 -0
- package/dist/core/views/lens.d.ts +27 -0
- package/dist/core/views/lens.js +112 -0
- package/dist/core/views/model.d.ts +21 -0
- package/dist/core/views/model.js +69 -0
- package/dist/core/views/resolve.d.ts +42 -0
- package/dist/core/views/resolve.js +81 -0
- package/dist/core/{save-as-view.d.ts → views/save-as-view.d.ts} +2 -2
- package/dist/core/{save-as-view.js → views/save-as-view.js} +13 -10
- package/dist/core/{saved-views.d.ts → views/saved.d.ts} +4 -18
- package/dist/core/{saved-views.js → views/saved.js} +8 -103
- package/dist/core/views/types.d.ts +91 -0
- package/dist/core/views/types.js +2 -0
- 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/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/errors.d.ts +37 -0
- package/dist/mcp/errors.js +35 -0
- package/dist/mcp/history.d.ts +4 -4
- package/dist/mcp/history.js +56 -116
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/server.d.ts +1 -2
- package/dist/mcp/server.js +30 -29
- 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/render/layout.d.ts +20 -3
- package/dist/render/layout.js +49 -12
- package/dist/render/sequence-svg.d.ts +1 -1
- package/dist/render/sequence.d.ts +1 -1
- package/dist/render/svg.d.ts +1 -1
- package/dist/render/svg.js +4 -4
- 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/schema/adr.js +18 -13
- package/dist/schema/workspace.js +226 -130
- package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
- package/dist/viewer/assets/index-YFA-pYjQ.css +1 -0
- package/dist/viewer/assets/{layout.worker-Bg-OaLVN.js → layout.worker-BRHAGJrD.js} +1 -1
- package/dist/viewer/assets/{png-BDKIXtm5.js → png-DMwnpRCt.js} +1 -1
- package/dist/viewer/assets/{svg-Bulv5YWn.js → svg-DN6lMeZo.js} +2 -2
- package/dist/viewer/index.html +2 -2
- package/dist/workspace/index.d.ts +37 -0
- package/dist/workspace/index.js +52 -0
- package/guide/SKILL.md +1 -1
- package/guide/topics/bootstrap.md +1 -1
- package/guide/topics/relationships.md +1 -1
- package/package.json +4 -3
- package/schemas/adr.schema.json +18 -15
- package/schemas/model.schema.json +637 -1144
- package/schemas/project.schema.json +8 -4
- package/schemas/workspace.schema.json +39 -20
- package/dist/core/views.d.ts +0 -126
- package/dist/core/views.js +0 -217
- package/dist/viewer/assets/index-DvKgCpBr.css +0 -1
- package/dist/viewer/assets/index-gucix3xm.js +0 -113
- /package/dist/{history → revisions}/migrate.d.ts +0 -0
- /package/dist/{history → revisions}/migrate.js +0 -0
package/dist/history/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { type ChangeCounts } from "../core/index.ts";
|
|
2
1
|
import { Bundle } from "../schema/bundle.ts";
|
|
2
|
+
import { type PreviewMark, type RevisionIndex } from "../revisions/index.ts";
|
|
3
3
|
import { type CommitInfo } from "./git.ts";
|
|
4
|
-
|
|
5
|
-
export {
|
|
4
|
+
import { type SiteContent } from "./site.ts";
|
|
5
|
+
export { migrateBundle, migrations, type Migration } from "../revisions/index.ts";
|
|
6
|
+
export { type CommitInfo } from "./git.ts";
|
|
7
|
+
export { writeSite, type PastBundle, type SiteContent } from "./site.ts";
|
|
8
|
+
export { resolvePoint, pointMessage, type PointFailure, type ResolvedPoint } from "./points.ts";
|
|
6
9
|
/** The cache a checkout keeps past Bundles and their index entries in, under the repo root. */
|
|
7
10
|
export declare const CACHE_DIR: string;
|
|
8
11
|
/** Where a Workspace's history lives: its git repo and the Workspace root within it. */
|
|
@@ -11,23 +14,6 @@ export interface History {
|
|
|
11
14
|
/** The Workspace root relative to the repo root, with `/` separators; "" when they are the same folder. */
|
|
12
15
|
workspacePath: string;
|
|
13
16
|
}
|
|
14
|
-
/** One Revision as the index records it; `bundle: false` marks a Revision whose Bundle was dropped. */
|
|
15
|
-
export interface RevisionEntry {
|
|
16
|
-
sha: string;
|
|
17
|
-
date: string;
|
|
18
|
-
subject: string;
|
|
19
|
-
author: string;
|
|
20
|
-
tags: string[];
|
|
21
|
-
/** Changes against the previous Revision (or an empty Model for the first). */
|
|
22
|
-
counts: ChangeCounts;
|
|
23
|
-
changedIds: string[];
|
|
24
|
-
bundle: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface RevisionIndex {
|
|
27
|
-
schemaVersion: number;
|
|
28
|
-
/** Newest first. */
|
|
29
|
-
revisions: RevisionEntry[];
|
|
30
|
-
}
|
|
31
17
|
export declare const history: (repoRoot: string, workspaceRoot: string) => History;
|
|
32
18
|
/**
|
|
33
19
|
* The Revisions: first-parent default-branch commits that changed something
|
|
@@ -66,19 +52,22 @@ export declare function buildHistory(h: History, options?: {
|
|
|
66
52
|
}): Promise<BuildResult>;
|
|
67
53
|
/** Past Bundles a published site keeps by default: the latest 200 Revisions, plus every tagged one. */
|
|
68
54
|
export declare const DEFAULT_KEEP = 200;
|
|
55
|
+
/** The latest Bundle and the Workspace's name, which a site holds beside its history. */
|
|
56
|
+
export type Latest = Pick<SiteContent, "bundle" | "workspace">;
|
|
69
57
|
export interface PublishResult {
|
|
70
58
|
revisions: number;
|
|
71
59
|
kept: number;
|
|
72
60
|
}
|
|
73
61
|
/**
|
|
74
|
-
* Writes
|
|
75
|
-
* Revision and `bundles/index.json`
|
|
62
|
+
* Writes a site through {@link writeSite}: the latest Bundle and its name,
|
|
63
|
+
* `bundles/<sha>.json` for each kept Revision and `bundles/index.json`
|
|
64
|
+
* listing every Revision. Kept are the
|
|
76
65
|
* latest `keep` Revisions plus every tagged one; the others stay in the
|
|
77
66
|
* index with `bundle: false`. Bundles come from the checkout's cache,
|
|
78
67
|
* backfilled from git first, so nothing is fetched. A Bundle file left in
|
|
79
68
|
* the folder by an earlier build is removed once its Revision is dropped.
|
|
80
69
|
*/
|
|
81
|
-
export declare function publishHistory(h: History, out: string, { keep }?: {
|
|
70
|
+
export declare function publishHistory(h: History, out: string, latest: Latest, { keep }?: {
|
|
82
71
|
keep?: number | "all";
|
|
83
72
|
}): Promise<PublishResult>;
|
|
84
73
|
/** The two sides a preview site Compares: the base branch's latest Revision and the PR head. */
|
|
@@ -97,18 +86,13 @@ export interface PreviewSides {
|
|
|
97
86
|
* yet) and HEAD. It never fetches; a missing `origin/<base>` is an error.
|
|
98
87
|
*/
|
|
99
88
|
export declare function previewSides(h: History, base: string): Promise<PreviewSides>;
|
|
100
|
-
/** What a preview site's `bundles/index.json` adds: the base branch and both sides' shas, so the viewer opens with Compare "base → PR". */
|
|
101
|
-
export interface PreviewMark {
|
|
102
|
-
base: string;
|
|
103
|
-
baseSha: string;
|
|
104
|
-
headSha: string;
|
|
105
|
-
}
|
|
106
89
|
/**
|
|
107
|
-
* Writes a preview site
|
|
90
|
+
* Writes a preview site through {@link writeSite}: the head as the latest
|
|
91
|
+
* Bundle, and in a cleared `bundles/` the base's Bundle, the head's (the
|
|
108
92
|
* checkout as built) and an index of the two, newest first, marked with
|
|
109
93
|
* `preview`. The head's counts are against the base.
|
|
110
94
|
*/
|
|
111
|
-
export declare function publishPreview(h: History, out: string, sides: PreviewSides, head: Bundle): Promise<PreviewMark>;
|
|
95
|
+
export declare function publishPreview(h: History, out: string, sides: PreviewSides, head: Bundle, workspace?: string): Promise<PreviewMark>;
|
|
112
96
|
/** The base branch origin/HEAD names, else `main`. */
|
|
113
97
|
export declare function defaultBaseBranch(repoRoot: string): Promise<string>;
|
|
114
98
|
/** A point in time that names no commit, or history that can't be read. */
|
package/dist/history/index.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, join, relative, sep } from "node:path";
|
|
3
|
-
import { changedIds, countChanges, diff, load
|
|
3
|
+
import { changedIds, countChanges, diff, load } from "../core/index.js";
|
|
4
4
|
import { Bundle, SCHEMA_VERSION } from "../schema/bundle.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { git } from "../git.js";
|
|
6
|
+
import { BUNDLES_DIR, INDEX_PATH, INDEX_VERSION, pastBundleFile, serializeBundle, serializeIndex, timeSpan } from "../revisions/index.js";
|
|
7
|
+
import { commitInfo, defaultBranch, firstParentCommitsTouching, gitFileSystem, joinRepo, tagsByCommit } from "./git.js";
|
|
8
|
+
import { pointMessage, resolvePoint } from "./points.js";
|
|
9
|
+
import { writeSite } from "./site.js";
|
|
10
|
+
export { migrateBundle, migrations } from "../revisions/index.js";
|
|
11
|
+
export {} from "./git.js";
|
|
12
|
+
export { writeSite } from "./site.js";
|
|
13
|
+
export { resolvePoint, pointMessage } from "./points.js";
|
|
8
14
|
/** The cache a checkout keeps past Bundles and their index entries in, under the repo root. */
|
|
9
15
|
export const CACHE_DIR = join(".archidocs", "cache");
|
|
10
16
|
export const history = (repoRoot, workspaceRoot) => ({
|
|
11
17
|
repoRoot,
|
|
12
18
|
workspacePath: relative(repoRoot, workspaceRoot).split(sep).join("/"),
|
|
13
19
|
});
|
|
14
|
-
const bundlesDir = (h) => join(h.repoRoot, CACHE_DIR,
|
|
15
|
-
const bundleFile = (h, sha) => join(bundlesDir(h),
|
|
16
|
-
const indexFile = (h) => join(
|
|
20
|
+
const bundlesDir = (h) => join(h.repoRoot, CACHE_DIR, BUNDLES_DIR);
|
|
21
|
+
const bundleFile = (h, sha) => join(bundlesDir(h), pastBundleFile(sha));
|
|
22
|
+
const indexFile = (h) => join(h.repoRoot, CACHE_DIR, INDEX_PATH);
|
|
17
23
|
/**
|
|
18
24
|
* The Revisions: first-parent default-branch commits that changed something
|
|
19
25
|
* under the Workspace root, newest first.
|
|
@@ -64,13 +70,13 @@ async function readCached(h, sha) {
|
|
|
64
70
|
export async function readIndex(h) {
|
|
65
71
|
try {
|
|
66
72
|
const index = JSON.parse(await readFile(indexFile(h), "utf8"));
|
|
67
|
-
if (index.schemaVersion ===
|
|
73
|
+
if (index.schemaVersion === INDEX_VERSION && Array.isArray(index.revisions))
|
|
68
74
|
return index;
|
|
69
75
|
}
|
|
70
76
|
catch {
|
|
71
77
|
// No index yet, or an unreadable one: start again.
|
|
72
78
|
}
|
|
73
|
-
return { schemaVersion:
|
|
79
|
+
return { schemaVersion: INDEX_VERSION, revisions: [] };
|
|
74
80
|
}
|
|
75
81
|
/**
|
|
76
82
|
* Backfills cached Bundles and index entries for every Revision, or those
|
|
@@ -115,47 +121,40 @@ export async function buildHistory(h, options = {}) {
|
|
|
115
121
|
.sort((a, b) => order.get(a.sha) - order.get(b.sha))
|
|
116
122
|
.map(({ sha, date, subject, author, tags: t, counts, changedIds: ids, bundle }) => ({ sha, date, subject, author, tags: t, counts, changedIds: ids, bundle }));
|
|
117
123
|
await mkdir(dirname(indexFile(h)), { recursive: true });
|
|
118
|
-
await writeFile(indexFile(h),
|
|
124
|
+
await writeFile(indexFile(h), serializeIndex({ schemaVersion: INDEX_VERSION, revisions: revisionsOut }));
|
|
119
125
|
}
|
|
120
126
|
return { revisions: inScope.length, built };
|
|
121
127
|
}
|
|
128
|
+
/** Where `--since` starts: a day's start, a time as given (UTC without a zone), else the commit date of the commit the point names. */
|
|
122
129
|
async function sinceTime(h, since) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return Date.parse((await commitInfo(h.repoRoot, sha)).date);
|
|
130
|
+
const own = timeSpan(since);
|
|
131
|
+
if (own)
|
|
132
|
+
return own.start;
|
|
133
|
+
const point = await resolvePoint(h, since);
|
|
134
|
+
if (!point.ok)
|
|
135
|
+
throw new HistoryError(pointMessage(since, point));
|
|
136
|
+
return Date.parse((await commitInfo(h.repoRoot, point.sha)).date);
|
|
131
137
|
}
|
|
132
138
|
/** Past Bundles a published site keeps by default: the latest 200 Revisions, plus every tagged one. */
|
|
133
139
|
export const DEFAULT_KEEP = 200;
|
|
134
140
|
/**
|
|
135
|
-
* Writes
|
|
136
|
-
* Revision and `bundles/index.json`
|
|
141
|
+
* Writes a site through {@link writeSite}: the latest Bundle and its name,
|
|
142
|
+
* `bundles/<sha>.json` for each kept Revision and `bundles/index.json`
|
|
143
|
+
* listing every Revision. Kept are the
|
|
137
144
|
* latest `keep` Revisions plus every tagged one; the others stay in the
|
|
138
145
|
* index with `bundle: false`. Bundles come from the checkout's cache,
|
|
139
146
|
* backfilled from git first, so nothing is fetched. A Bundle file left in
|
|
140
147
|
* the folder by an earlier build is removed once its Revision is dropped.
|
|
141
148
|
*/
|
|
142
|
-
export async function publishHistory(h, out, { keep = DEFAULT_KEEP } = {}) {
|
|
143
|
-
const dir = join(out, "bundles");
|
|
149
|
+
export async function publishHistory(h, out, latest, { keep = DEFAULT_KEEP } = {}) {
|
|
144
150
|
const hasCommits = await gitHasCommits(h.repoRoot);
|
|
145
151
|
if (hasCommits)
|
|
146
152
|
await buildHistory(h);
|
|
147
|
-
const
|
|
148
|
-
const revisionsOut =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (/^[0-9a-f]{40,64}\.json$/.test(file) && !keptFiles.has(file))
|
|
153
|
-
await rm(join(dir, file));
|
|
154
|
-
}
|
|
155
|
-
for (const file of keptFiles)
|
|
156
|
-
await copyFile(join(bundlesDir(h), file), join(dir, file));
|
|
157
|
-
await writeFile(join(dir, "index.json"), JSON.stringify({ schemaVersion: SCHEMA_VERSION, revisions: revisionsOut }, null, 2) + "\n");
|
|
158
|
-
return { revisions: revisionsOut.length, kept: keptFiles.size };
|
|
153
|
+
const cached = hasCommits ? await readIndex(h) : { schemaVersion: INDEX_VERSION, revisions: [] };
|
|
154
|
+
const revisionsOut = cached.revisions.map((entry, i) => ({ ...entry, bundle: keep === "all" || i < keep || entry.tags.length > 0 }));
|
|
155
|
+
const past = revisionsOut.filter((e) => e.bundle).map((e) => ({ sha: e.sha, from: bundleFile(h, e.sha) }));
|
|
156
|
+
await writeSite(out, { ...latest, index: { schemaVersion: INDEX_VERSION, revisions: revisionsOut }, past });
|
|
157
|
+
return { revisions: revisionsOut.length, kept: past.length };
|
|
159
158
|
}
|
|
160
159
|
/**
|
|
161
160
|
* Finds a preview's sides from what the checkout already has: the latest
|
|
@@ -182,12 +181,12 @@ export async function previewSides(h, base) {
|
|
|
182
181
|
};
|
|
183
182
|
}
|
|
184
183
|
/**
|
|
185
|
-
* Writes a preview site
|
|
184
|
+
* Writes a preview site through {@link writeSite}: the head as the latest
|
|
185
|
+
* Bundle, and in a cleared `bundles/` the base's Bundle, the head's (the
|
|
186
186
|
* checkout as built) and an index of the two, newest first, marked with
|
|
187
187
|
* `preview`. The head's counts are against the base.
|
|
188
188
|
*/
|
|
189
|
-
export async function publishPreview(h, out, sides, head) {
|
|
190
|
-
const dir = join(out, "bundles");
|
|
189
|
+
export async function publishPreview(h, out, sides, head, workspace) {
|
|
191
190
|
const tags = await tagsByCommit(h.repoRoot);
|
|
192
191
|
const entry = (rev, before, after) => {
|
|
193
192
|
const changes = diff(before, after);
|
|
@@ -199,11 +198,16 @@ export async function publishPreview(h, out, sides, head) {
|
|
|
199
198
|
if (sides.head.sha !== baseRevision.sha)
|
|
200
199
|
revisionsOut.push(entry(baseRevision, sides.beforeBase, baseBundle));
|
|
201
200
|
const preview = { base: sides.base, baseSha: baseRevision.sha, headSha: sides.head.sha };
|
|
202
|
-
await
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
201
|
+
await writeSite(out, {
|
|
202
|
+
bundle: head,
|
|
203
|
+
...(workspace === undefined ? {} : { workspace }),
|
|
204
|
+
index: { schemaVersion: INDEX_VERSION, preview, revisions: revisionsOut },
|
|
205
|
+
past: [
|
|
206
|
+
{ sha: baseRevision.sha, bundle: baseBundle },
|
|
207
|
+
{ sha: sides.head.sha, bundle: head },
|
|
208
|
+
],
|
|
209
|
+
clear: true,
|
|
210
|
+
});
|
|
207
211
|
return preview;
|
|
208
212
|
}
|
|
209
213
|
/** The base branch origin/HEAD names, else `main`. */
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Dated, type Found } from "../revisions/index.ts";
|
|
2
|
+
import type { History } from "./index.ts";
|
|
3
|
+
/** Why a point names no commit on a checkout: `find`'s failure over the default branch's Revisions. */
|
|
4
|
+
export type PointFailure = Exclude<Found<Dated>, {
|
|
5
|
+
ok: true;
|
|
6
|
+
}>;
|
|
7
|
+
/** The commit a point names; `ref` is true when git resolved it as a ref, false when it named a Revision by date or sha prefix. */
|
|
8
|
+
export type ResolvedPoint = {
|
|
9
|
+
ok: true;
|
|
10
|
+
sha: string;
|
|
11
|
+
ref: boolean;
|
|
12
|
+
} | PointFailure;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves a point on a checkout to a commit, in this order:
|
|
15
|
+
* 1. a git ref (tag, branch, sha, `HEAD~1`), to its commit, Revision or not;
|
|
16
|
+
* 2. a date or a time, to the last Revision on the default branch at or before it;
|
|
17
|
+
* 3. hex, to the one Revision whose sha starts with it (several are `ambiguous`).
|
|
18
|
+
* Anything else is `not_found`, suggesting up to 5 tags. Dates and hex go
|
|
19
|
+
* through the point grammar's `find`, so they name what they name on a site.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolvePoint(h: History, point: string): Promise<ResolvedPoint>;
|
|
22
|
+
/** The CLI's words for a point that names no commit, after `archidocs: `. */
|
|
23
|
+
export declare function pointMessage(point: string, failure: PointFailure): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { git } from "../git.js";
|
|
2
|
+
import { find } from "../revisions/index.js";
|
|
3
|
+
import { defaultBranch, firstParentCommitsTouching, tagsByCommit } from "./git.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a point on a checkout to a commit, in this order:
|
|
6
|
+
* 1. a git ref (tag, branch, sha, `HEAD~1`), to its commit, Revision or not;
|
|
7
|
+
* 2. a date or a time, to the last Revision on the default branch at or before it;
|
|
8
|
+
* 3. hex, to the one Revision whose sha starts with it (several are `ambiguous`).
|
|
9
|
+
* Anything else is `not_found`, suggesting up to 5 tags. Dates and hex go
|
|
10
|
+
* through the point grammar's `find`, so they name what they name on a site.
|
|
11
|
+
*/
|
|
12
|
+
export async function resolvePoint(h, point) {
|
|
13
|
+
const sha = await revParse(h.repoRoot, point);
|
|
14
|
+
if (sha)
|
|
15
|
+
return { ok: true, sha, ref: true };
|
|
16
|
+
const [commits, tags] = await Promise.all([defaultBranch(h.repoRoot).then((branch) => firstParentCommitsTouching(h.repoRoot, branch, h.workspacePath)), tagsByCommit(h.repoRoot)]);
|
|
17
|
+
const revisions = commits.map(({ sha, date }) => ({ sha, date, tags: tags.get(sha) ?? [] }));
|
|
18
|
+
const found = find(revisions, point);
|
|
19
|
+
return found.ok ? { ok: true, sha: found.revision.sha, ref: false } : found;
|
|
20
|
+
}
|
|
21
|
+
/** The CLI's words for a point that names no commit, after `archidocs: `. */
|
|
22
|
+
export function pointMessage(point, failure) {
|
|
23
|
+
if (failure.kind === "ambiguous")
|
|
24
|
+
return `"${point}" is the start of ${failure.count} Revisions' shas; give more of it.`;
|
|
25
|
+
const message = `Unknown ref or date "${point}"; a date names the last Revision at or before it.`;
|
|
26
|
+
return failure.first ? `${message} The first Revision is ${failure.first.sha.slice(0, 7)}, ${failure.first.date}.` : message;
|
|
27
|
+
}
|
|
28
|
+
const revParse = async (repoRoot, point) => (await git(repoRoot, "rev-parse", "--verify", "--quiet", "--end-of-options", `${point}^{commit}`).catch(() => "")).trim() || undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Bundle } from "../schema/bundle.ts";
|
|
2
|
+
import { type RevisionIndex } from "../revisions/index.ts";
|
|
3
|
+
/** A past Bundle to place in `bundles/`: copied from a file (the checkout's cache) or serialized from a Bundle. */
|
|
4
|
+
export type PastBundle = {
|
|
5
|
+
sha: string;
|
|
6
|
+
from: string;
|
|
7
|
+
} | {
|
|
8
|
+
sha: string;
|
|
9
|
+
bundle: Bundle;
|
|
10
|
+
};
|
|
11
|
+
export interface SiteContent {
|
|
12
|
+
/** The latest Bundle, `workspace.bundle.json`. */
|
|
13
|
+
bundle: Bundle;
|
|
14
|
+
/** The Workspace's name for `site.json`; none for `--bundle-only`. */
|
|
15
|
+
workspace?: string;
|
|
16
|
+
/** The Revision index, `bundles/index.json`; none for `--bundle-only`. */
|
|
17
|
+
index?: RevisionIndex;
|
|
18
|
+
/** The past Bundles the index keeps. */
|
|
19
|
+
past?: PastBundle[];
|
|
20
|
+
/** Clear `bundles/` before writing, as a preview does, instead of removing only the past Bundles no longer kept. */
|
|
21
|
+
clear?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Writes a site to `out`: the latest Bundle, `site.json` when there is a
|
|
25
|
+
* name, the Revision index and each past Bundle. With an index, a past
|
|
26
|
+
* Bundle file left in `bundles/` by an earlier build is removed once it is
|
|
27
|
+
* no longer kept. The only code that writes a site's files; the viewer's
|
|
28
|
+
* own files are copied in by `build`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeSite(out: string, { bundle, workspace, index, past, clear }: SiteContent): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { copyFile, mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { BUNDLES_DIR, INDEX_PATH, isPastBundleFile, LATEST_BUNDLE_PATH, pastBundleFile, pastBundlePath, serializeBundle, serializeIndex, serializeSiteFile, SITE_FILE_PATH, } from "../revisions/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Writes a site to `out`: the latest Bundle, `site.json` when there is a
|
|
6
|
+
* name, the Revision index and each past Bundle. With an index, a past
|
|
7
|
+
* Bundle file left in `bundles/` by an earlier build is removed once it is
|
|
8
|
+
* no longer kept. The only code that writes a site's files; the viewer's
|
|
9
|
+
* own files are copied in by `build`.
|
|
10
|
+
*/
|
|
11
|
+
export async function writeSite(out, { bundle, workspace, index, past = [], clear = false }) {
|
|
12
|
+
await mkdir(out, { recursive: true });
|
|
13
|
+
if (workspace !== undefined)
|
|
14
|
+
await writeFile(join(out, SITE_FILE_PATH), serializeSiteFile(workspace));
|
|
15
|
+
await writeFile(join(out, LATEST_BUNDLE_PATH), serializeBundle(bundle));
|
|
16
|
+
if (!index)
|
|
17
|
+
return;
|
|
18
|
+
const dir = join(out, BUNDLES_DIR);
|
|
19
|
+
if (clear)
|
|
20
|
+
await rm(dir, { recursive: true, force: true });
|
|
21
|
+
await mkdir(dir, { recursive: true });
|
|
22
|
+
const kept = new Set(past.map((p) => pastBundleFile(p.sha)));
|
|
23
|
+
if (!clear) {
|
|
24
|
+
for (const file of await readdir(dir)) {
|
|
25
|
+
if (isPastBundleFile(file) && !kept.has(file))
|
|
26
|
+
await rm(join(dir, file));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
for (const p of past) {
|
|
30
|
+
const to = join(out, pastBundlePath(p.sha));
|
|
31
|
+
if ("from" in p)
|
|
32
|
+
await copyFile(p.from, to);
|
|
33
|
+
else
|
|
34
|
+
await writeFile(to, serializeBundle(p.bundle));
|
|
35
|
+
}
|
|
36
|
+
await writeFile(join(out, INDEX_PATH), serializeIndex(index));
|
|
37
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error codes a tool result can carry in `structuredContent.code`, each
|
|
3
|
+
* with what it means and what the caller should do. The server types its
|
|
4
|
+
* failures with these codes, and the docs list them on the MCP error page.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ERROR_CODES: {
|
|
7
|
+
readonly invalid_input: {
|
|
8
|
+
readonly meaning: "The arguments don't fit the tool's input: a field is missing, has the wrong type or isn't a valid id, or a write tool was given `at`.";
|
|
9
|
+
readonly action: "Read `message`, which names the field, and call again with corrected arguments.";
|
|
10
|
+
};
|
|
11
|
+
readonly not_found: {
|
|
12
|
+
readonly meaning: "An id, a Project, a View, a Deployment or a point in history (`at`, `from`, `since`) names nothing in the Model.";
|
|
13
|
+
readonly action: "Use one of `suggestions` if there are any. Otherwise find the id with `search_elements`, `list_views` or `list_history`.";
|
|
14
|
+
};
|
|
15
|
+
readonly ambiguous: {
|
|
16
|
+
readonly meaning: "A name matches more than one thing: a history `scope` that is both a Project and an Element, or a write that could mean more than one Relationship or Deployment.";
|
|
17
|
+
readonly action: "Narrow the call: pass `scope_kind`, or the Relationship's `id`. `suggestions` lists the candidates when there are any.";
|
|
18
|
+
};
|
|
19
|
+
readonly validation_failed: {
|
|
20
|
+
readonly meaning: "A write would add a check error, or remove something still referenced. Nothing was written.";
|
|
21
|
+
readonly action: "Fix what `issues` or `references` lists, each issue with a link to its rule's page, then write again.";
|
|
22
|
+
};
|
|
23
|
+
readonly read_only: {
|
|
24
|
+
readonly meaning: "A write tool was called on a server that can't write: one reading a published Workspace Bundle, or one over HTTP started without `--allow-writes`.";
|
|
25
|
+
readonly action: "Run `archidocs mcp` over a Workspace checkout, and add `--allow-writes` over HTTP.";
|
|
26
|
+
};
|
|
27
|
+
readonly source_unavailable: {
|
|
28
|
+
readonly meaning: "The server could not read the Workspace or the Workspace Bundle, or could not write the checkout.";
|
|
29
|
+
readonly action: "Check that the folder or URL the server was started with exists and is readable, then call again: each call tries anew.";
|
|
30
|
+
};
|
|
31
|
+
readonly history_unavailable: {
|
|
32
|
+
readonly meaning: "The call needs the Model's history (`at`, `get_changes`, `list_history`), and the source has none: no git repository, or a published site without a Revision index.";
|
|
33
|
+
readonly action: "Run the server over a git checkout with its full history, or publish the site with its Revisions.";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** A code a failed tool result carries. */
|
|
37
|
+
export type ErrorCode = keyof typeof ERROR_CODES;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error codes a tool result can carry in `structuredContent.code`, each
|
|
3
|
+
* with what it means and what the caller should do. The server types its
|
|
4
|
+
* failures with these codes, and the docs list them on the MCP error page.
|
|
5
|
+
*/
|
|
6
|
+
export const ERROR_CODES = {
|
|
7
|
+
invalid_input: {
|
|
8
|
+
meaning: "The arguments don't fit the tool's input: a field is missing, has the wrong type or isn't a valid id, or a write tool was given `at`.",
|
|
9
|
+
action: "Read `message`, which names the field, and call again with corrected arguments.",
|
|
10
|
+
},
|
|
11
|
+
not_found: {
|
|
12
|
+
meaning: "An id, a Project, a View, a Deployment or a point in history (`at`, `from`, `since`) names nothing in the Model.",
|
|
13
|
+
action: "Use one of `suggestions` if there are any. Otherwise find the id with `search_elements`, `list_views` or `list_history`.",
|
|
14
|
+
},
|
|
15
|
+
ambiguous: {
|
|
16
|
+
meaning: "A name matches more than one thing: a history `scope` that is both a Project and an Element, or a write that could mean more than one Relationship or Deployment.",
|
|
17
|
+
action: "Narrow the call: pass `scope_kind`, or the Relationship's `id`. `suggestions` lists the candidates when there are any.",
|
|
18
|
+
},
|
|
19
|
+
validation_failed: {
|
|
20
|
+
meaning: "A write would add a check error, or remove something still referenced. Nothing was written.",
|
|
21
|
+
action: "Fix what `issues` or `references` lists, each issue with a link to its rule's page, then write again.",
|
|
22
|
+
},
|
|
23
|
+
read_only: {
|
|
24
|
+
meaning: "A write tool was called on a server that can't write: one reading a published Workspace Bundle, or one over HTTP started without `--allow-writes`.",
|
|
25
|
+
action: "Run `archidocs mcp` over a Workspace checkout, and add `--allow-writes` over HTTP.",
|
|
26
|
+
},
|
|
27
|
+
source_unavailable: {
|
|
28
|
+
meaning: "The server could not read the Workspace or the Workspace Bundle, or could not write the checkout.",
|
|
29
|
+
action: "Check that the folder or URL the server was started with exists and is readable, then call again: each call tries anew.",
|
|
30
|
+
},
|
|
31
|
+
history_unavailable: {
|
|
32
|
+
meaning: "The call needs the Model's history (`at`, `get_changes`, `list_history`), and the source has none: no git repository, or a published site without a Revision index.",
|
|
33
|
+
action: "Run the server over a git checkout with its full history, or publish the site with its Revisions.",
|
|
34
|
+
},
|
|
35
|
+
};
|
package/dist/mcp/history.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RevisionEntry } from "../
|
|
1
|
+
import { type RevisionEntry, type Span } from "../revisions/index.ts";
|
|
2
2
|
import type { Snapshot, Source } from "./source.ts";
|
|
3
3
|
/** Why a point in time can't be answered: it names no commit, or its Bundle can't be had. */
|
|
4
4
|
export type PastFailure = {
|
|
@@ -27,10 +27,10 @@ export interface Past {
|
|
|
27
27
|
ok: true;
|
|
28
28
|
revisions: RevisionEntry[];
|
|
29
29
|
} | PastFailure>;
|
|
30
|
-
/** The time a
|
|
31
|
-
|
|
30
|
+
/** The time a point spans: a commit's one instant, a whole UTC day, or a time's instant. */
|
|
31
|
+
span(point: string): Promise<{
|
|
32
32
|
ok: true;
|
|
33
|
-
|
|
33
|
+
span: Span;
|
|
34
34
|
} | PastFailure>;
|
|
35
35
|
}
|
|
36
36
|
export declare function pastOf(source: Source): Past;
|