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/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,25 @@
|
|
|
1
|
+
import type { CallToolResult } from "@modelcontextprotocol/server";
|
|
2
|
+
import type { Source } from "./source.ts";
|
|
3
|
+
/** Where the server's log lines go: stderr, which every MCP client shows in its MCP log. */
|
|
4
|
+
export type Log = (line: string) => void;
|
|
5
|
+
/** The source as the log names it: `Workspace <root>` or `Bundle <location>`. */
|
|
6
|
+
export declare const describeSource: (source: Source) => string;
|
|
7
|
+
export interface StartupOptions {
|
|
8
|
+
version: string;
|
|
9
|
+
transport: "stdio" | "http" | "check";
|
|
10
|
+
source: Source;
|
|
11
|
+
writesAllowed: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The line the server prints once it has loaded its source: what it serves,
|
|
15
|
+
* how big the Model is and what check finds, or why it can't load it. It
|
|
16
|
+
* never rejects: a source that fails to load is reported, not fatal, and the
|
|
17
|
+
* tools return `source_unavailable` until it loads.
|
|
18
|
+
*/
|
|
19
|
+
export declare function startupLine({ version, transport, source, writesAllowed }: StartupOptions): Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* One log line for a tool call: the tool, what it was called on, and how it
|
|
22
|
+
* ended. A write names what it did and the files it changed; a refusal or a
|
|
23
|
+
* failed read names its error code.
|
|
24
|
+
*/
|
|
25
|
+
export declare function callLine(name: string, args: unknown, result: CallToolResult): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** The source as the log names it: `Workspace <root>` or `Bundle <location>`. */
|
|
2
|
+
export const describeSource = (source) => (source.kind === "checkout" ? `Workspace ${source.root}` : `Bundle ${source.location}`);
|
|
3
|
+
/**
|
|
4
|
+
* The line the server prints once it has loaded its source: what it serves,
|
|
5
|
+
* how big the Model is and what check finds, or why it can't load it. It
|
|
6
|
+
* never rejects: a source that fails to load is reported, not fatal, and the
|
|
7
|
+
* tools return `source_unavailable` until it loads.
|
|
8
|
+
*/
|
|
9
|
+
export async function startupLine({ version, transport, source, writesAllowed }) {
|
|
10
|
+
const head = `archidocs ${version} MCP server (${transport}): ${describeSource(source)}`;
|
|
11
|
+
try {
|
|
12
|
+
const { bundle, issues } = await source.snapshot();
|
|
13
|
+
const errors = issues.filter((i) => i.severity === "error").length;
|
|
14
|
+
return `${head} — ${bundle.projects.length} Projects, ${bundle.elements.length} Elements; check: ${errors} errors, ${issues.length - errors} warnings; writes ${writesAllowed ? "on" : "off"}`;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return `${head} — can't load it: ${error instanceof Error ? error.message : String(error)}; tools return source_unavailable until it loads`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One log line for a tool call: the tool, what it was called on, and how it
|
|
22
|
+
* ended. A write names what it did and the files it changed; a refusal or a
|
|
23
|
+
* failed read names its error code.
|
|
24
|
+
*/
|
|
25
|
+
export function callLine(name, args, result) {
|
|
26
|
+
const target = label(args);
|
|
27
|
+
const data = (result.structuredContent ?? {});
|
|
28
|
+
let outcome;
|
|
29
|
+
if (result.isError)
|
|
30
|
+
outcome = `refused (${data.code ?? "error"})`;
|
|
31
|
+
else if (data.action !== undefined)
|
|
32
|
+
outcome = [data.action, ...(data.files ?? [])].join(" ") + (data.dryRun ? " (dry run)" : "");
|
|
33
|
+
else
|
|
34
|
+
outcome = "ok";
|
|
35
|
+
return `${name}${target ? ` ${target}` : ""}: ${outcome}`;
|
|
36
|
+
}
|
|
37
|
+
/** What a call is about, from its arguments: an Element or other id (qualified by `project`), a Relationship's ends, or a Deployment. */
|
|
38
|
+
function label(args) {
|
|
39
|
+
if (typeof args !== "object" || args === null)
|
|
40
|
+
return "";
|
|
41
|
+
const a = args;
|
|
42
|
+
const str = (k) => (typeof a[k] === "string" ? a[k] : undefined);
|
|
43
|
+
const qualify = (id) => (id.includes(":") || str("project") === undefined ? id : `${str("project")}:${id}`);
|
|
44
|
+
const id = str("id");
|
|
45
|
+
if (id !== undefined)
|
|
46
|
+
return qualify(id);
|
|
47
|
+
const [from, to] = [str("from"), str("to")];
|
|
48
|
+
if (from !== undefined && to !== undefined)
|
|
49
|
+
return `${qualify(from)} -> ${to}`;
|
|
50
|
+
const [service, environment] = [str("service"), str("environment")];
|
|
51
|
+
if (service !== undefined && environment !== undefined)
|
|
52
|
+
return `${qualify(service)} in ${environment}`;
|
|
53
|
+
return str("project") ?? str("topic") ?? "";
|
|
54
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ServerOptions } from "./server.ts";
|
|
2
|
+
export interface CheckResult {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
/** What the check found, to print on stdout. */
|
|
5
|
+
lines: string[];
|
|
6
|
+
/** Why it failed, when it did. */
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `archidocs mcp --check`: runs the server these options would start behind
|
|
11
|
+
* an in-process client, as an agent would, and reports what it serves. It
|
|
12
|
+
* does `initialize`, `tools/list` and one read (`list_teams`), so it fails
|
|
13
|
+
* when the server can't start or can't read its source.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkServer(options: ServerOptions & {
|
|
16
|
+
version: string;
|
|
17
|
+
}): Promise<CheckResult>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { InMemoryTransport, LATEST_PROTOCOL_VERSION } from "@modelcontextprotocol/server";
|
|
2
|
+
import { startupLine } from "./announce.js";
|
|
3
|
+
import { createServer } from "./server.js";
|
|
4
|
+
const TIMEOUT_MS = 30_000;
|
|
5
|
+
/**
|
|
6
|
+
* `archidocs mcp --check`: runs the server these options would start behind
|
|
7
|
+
* an in-process client, as an agent would, and reports what it serves. It
|
|
8
|
+
* does `initialize`, `tools/list` and one read (`list_teams`), so it fails
|
|
9
|
+
* when the server can't start or can't read its source.
|
|
10
|
+
*/
|
|
11
|
+
export async function checkServer(options) {
|
|
12
|
+
const lines = [await startupLine({ version: options.version, transport: "check", source: options.source, writesAllowed: options.source.writesAllowed })];
|
|
13
|
+
const server = createServer(options);
|
|
14
|
+
const [client, end] = InMemoryTransport.createLinkedPair();
|
|
15
|
+
const pending = new Map();
|
|
16
|
+
client.onmessage = (message) => {
|
|
17
|
+
const id = message.id;
|
|
18
|
+
if (id !== undefined)
|
|
19
|
+
pending.get(id)?.(message);
|
|
20
|
+
};
|
|
21
|
+
let next = 0;
|
|
22
|
+
const request = async (method, params) => {
|
|
23
|
+
const id = ++next;
|
|
24
|
+
const reply = new Promise((resolve, reject) => {
|
|
25
|
+
pending.set(id, resolve);
|
|
26
|
+
setTimeout(() => reject(new Error(`${method} got no answer in ${TIMEOUT_MS / 1000} s`)), TIMEOUT_MS).unref();
|
|
27
|
+
});
|
|
28
|
+
await client.send({ jsonrpc: "2.0", id, method, params });
|
|
29
|
+
const message = (await reply);
|
|
30
|
+
if (message.error)
|
|
31
|
+
throw new Error(`${method} failed: ${message.error.message}`);
|
|
32
|
+
return message.result;
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
await server.connect(end);
|
|
36
|
+
await client.start();
|
|
37
|
+
await request("initialize", { protocolVersion: LATEST_PROTOCOL_VERSION, capabilities: {}, clientInfo: { name: "archidocs-check", version: options.version } });
|
|
38
|
+
await client.send({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
39
|
+
const { tools } = (await request("tools/list", {}));
|
|
40
|
+
const teams = (await request("tools/call", { name: "list_teams", arguments: {} }));
|
|
41
|
+
if (teams.isError)
|
|
42
|
+
throw new Error(`list_teams failed: ${teams.structuredContent?.code}: ${teams.structuredContent?.message}`);
|
|
43
|
+
lines.push(`ok: ${tools.length} tools; list_teams answered`);
|
|
44
|
+
return { ok: true, lines };
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return { ok: false, lines, error: error instanceof Error ? error.message : String(error) };
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
await server.close();
|
|
51
|
+
}
|
|
52
|
+
}
|
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;
|