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.
Files changed (78) hide show
  1. package/README.md +9 -15
  2. package/dist/cli/commands.d.ts +19 -11
  3. package/dist/cli/commands.js +12 -10
  4. package/dist/cli/dev.d.ts +5 -6
  5. package/dist/cli/dev.js +12 -14
  6. package/dist/cli/diff-format.d.ts +1 -5
  7. package/dist/cli/init.d.ts +11 -1
  8. package/dist/cli/init.js +121 -10
  9. package/dist/cli/main.js +2 -324
  10. package/dist/cli/run.d.ts +18 -0
  11. package/dist/cli/run.js +312 -0
  12. package/dist/commands/build.d.ts +51 -0
  13. package/dist/commands/build.js +39 -0
  14. package/dist/commands/check.d.ts +8 -0
  15. package/dist/commands/check.js +5 -0
  16. package/dist/commands/diff.d.ts +29 -0
  17. package/dist/commands/diff.js +25 -0
  18. package/dist/commands/export.d.ts +41 -0
  19. package/dist/commands/export.js +47 -0
  20. package/dist/commands/history.d.ts +18 -0
  21. package/dist/commands/history.js +9 -0
  22. package/dist/commands/index.d.ts +11 -0
  23. package/dist/commands/index.js +11 -0
  24. package/dist/core/index.d.ts +1 -1
  25. package/dist/core/index.js +1 -1
  26. package/dist/core/load.d.ts +0 -2
  27. package/dist/core/load.js +5 -6
  28. package/dist/core/workspace-files.d.ts +13 -0
  29. package/dist/core/workspace-files.js +20 -0
  30. package/dist/git.d.ts +2 -0
  31. package/dist/git.js +14 -4
  32. package/dist/guide/index.d.ts +5 -4
  33. package/dist/guide/index.js +6 -5
  34. package/dist/history/git.d.ts +0 -10
  35. package/dist/history/git.js +1 -30
  36. package/dist/history/index.d.ts +15 -31
  37. package/dist/history/index.js +47 -43
  38. package/dist/history/points.d.ts +23 -0
  39. package/dist/history/points.js +28 -0
  40. package/dist/history/site.d.ts +30 -0
  41. package/dist/history/site.js +37 -0
  42. package/dist/mcp/announce.d.ts +25 -0
  43. package/dist/mcp/announce.js +54 -0
  44. package/dist/mcp/check.d.ts +17 -0
  45. package/dist/mcp/check.js +52 -0
  46. package/dist/mcp/history.d.ts +4 -4
  47. package/dist/mcp/history.js +56 -116
  48. package/dist/mcp/index.d.ts +2 -0
  49. package/dist/mcp/index.js +2 -0
  50. package/dist/mcp/server.d.ts +6 -0
  51. package/dist/mcp/server.js +30 -21
  52. package/dist/mcp/site.d.ts +12 -0
  53. package/dist/mcp/site.js +46 -0
  54. package/dist/mcp/source.d.ts +14 -7
  55. package/dist/mcp/source.js +25 -99
  56. package/dist/mcp/writes.d.ts +2 -2
  57. package/dist/mcp/writes.js +3 -3
  58. package/dist/revisions/find.d.ts +64 -0
  59. package/dist/revisions/find.js +85 -0
  60. package/dist/revisions/index.d.ts +57 -0
  61. package/dist/revisions/index.js +24 -0
  62. package/dist/revisions/site.d.ts +82 -0
  63. package/dist/revisions/site.js +157 -0
  64. package/dist/revisions/text.d.ts +8 -0
  65. package/dist/revisions/text.js +17 -0
  66. package/dist/revisions/touching.d.ts +7 -0
  67. package/dist/revisions/touching.js +7 -0
  68. package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
  69. package/dist/viewer/assets/{png-CAaXWR-k.js → png-DMwnpRCt.js} +1 -1
  70. package/dist/viewer/assets/{svg-BPVHfD36.js → svg-DN6lMeZo.js} +1 -1
  71. package/dist/viewer/index.html +1 -1
  72. package/dist/workspace/index.d.ts +37 -0
  73. package/dist/workspace/index.js +52 -0
  74. package/guide/SKILL.md +2 -0
  75. package/package.json +1 -1
  76. package/dist/viewer/assets/index-BXa5R96a.js +0 -138
  77. /package/dist/{history → revisions}/migrate.d.ts +0 -0
  78. /package/dist/{history → revisions}/migrate.js +0 -0
@@ -1,7 +1,5 @@
1
- import { readFile, realpath } from "node:fs/promises";
2
- import { dirname, join } from "node:path";
3
- import { gitTopLevel } from "../git.js";
4
- import { bundleAt, buildHistory, history, isDate, migrateBundle, readIndex, resolvePoint } from "../history/index.js";
1
+ import { bundleAt, buildHistory, readIndex, resolvePoint } from "../history/index.js";
2
+ import { find, INDEX_PATH, span, timeSpan } from "../revisions/index.js";
5
3
  import { commitInfo } from "../history/git.js";
6
4
  export function pastOf(source) {
7
5
  return source.kind === "checkout" ? checkoutPast(source) : bundlePast(source);
@@ -14,28 +12,26 @@ const noCommit = (point, suggestions) => ({
14
12
  ...(suggestions?.length ? { suggestions } : {}),
15
13
  });
16
14
  const reason = (error) => (error instanceof Error ? error.message : String(error));
17
- /** A bare date's start or end (UTC); a full time as given. */
18
- function dateTime(point, edge) {
19
- if (/^\d{4}-\d{2}-\d{2}$/.test(point))
20
- return Date.parse(`${point}T${edge === "start" ? "00:00:00" : "23:59:59"}Z`);
21
- return Date.parse(point);
15
+ /** `find`'s failure in MCP's words: no Revision (naming the first one for a date before it), or a prefix of several. */
16
+ function findFailure(point, failure) {
17
+ if (failure.kind === "ambiguous") {
18
+ return { ok: false, code: "not_found", message: `"${point}" is the start of ${failure.count} Revisions' shas; give more of it.`, suggestions: failure.candidates.map((r) => r.sha) };
19
+ }
20
+ const missing = noCommit(point, failure.tags);
21
+ return failure.first ? { ...missing, message: `${missing.message} The first Revision is ${failure.first.sha.slice(0, 7)}, ${failure.first.date}.` } : missing;
22
22
  }
23
23
  function checkoutPast(source) {
24
- let found;
25
- const repo = () => (found ??= (async () => {
26
- const root = await realpath(source.root);
27
- const repoRoot = await gitTopLevel(root);
28
- return repoRoot ? history(repoRoot, root) : undefined;
29
- })());
24
+ const repo = async () => (await source.checkout.repo())?.history;
30
25
  const noGit = unavailable(`The Workspace at ${source.root} is not in a git repository, so it has no history.`);
31
26
  return {
32
27
  async at(point) {
33
28
  const h = await repo();
34
29
  if (!h)
35
30
  return noGit;
36
- const sha = await resolvePoint(h.repoRoot, point);
37
- if (!sha)
38
- return noCommit(point);
31
+ const resolved = await resolvePoint(h, point);
32
+ if (!resolved.ok)
33
+ return findFailure(point, resolved);
34
+ const { sha } = resolved;
39
35
  try {
40
36
  return { ok: true, commit: sha, snapshot: { bundle: (await bundleAt(h, sha)).bundle, issues: [] } };
41
37
  }
@@ -56,120 +52,64 @@ function checkoutPast(source) {
56
52
  return unavailable(`Could not read the history of ${h.repoRoot}: ${reason(error)}`);
57
53
  }
58
54
  },
59
- async time(point, edge) {
60
- if (isDate(point))
61
- return { ok: true, time: dateTime(point, edge) };
55
+ async span(point) {
56
+ // A ref spans its commit's instant, a tag that looks like a date included;
57
+ // otherwise a day or a time spans itself, as on a site.
58
+ const own = timeSpan(point);
62
59
  const h = await repo();
63
60
  if (!h)
64
- return noGit;
65
- const sha = await resolvePoint(h.repoRoot, point);
66
- if (!sha)
67
- return noCommit(point);
68
- return { ok: true, time: Date.parse((await commitInfo(h.repoRoot, sha)).date) };
61
+ return own ? { ok: true, span: own } : noGit;
62
+ const resolved = await resolvePoint(h, point);
63
+ if (own && !(resolved.ok && resolved.ref))
64
+ return { ok: true, span: own };
65
+ if (!resolved.ok)
66
+ return findFailure(point, resolved);
67
+ const at = Date.parse((await commitInfo(h.repoRoot, resolved.sha)).date);
68
+ return { ok: true, span: { start: at, end: at + 1 } };
69
69
  },
70
70
  };
71
71
  }
72
- /** How long a fetched index is trusted before the site is asked again, as for the Bundle. */
73
- const RECHECK_MS = 60_000;
74
72
  function bundlePast(source) {
75
- // Past Bundles are immutable, so each is fetched once.
76
- const bundles = new Map();
77
- let cached;
78
- const sibling = (path) => {
79
- const location = source.location;
80
- return /^https?:\/\//i.test(location) ? new URL(path, location).href : join(dirname(location), path);
81
- };
82
- const read = async (path) => {
83
- const where = sibling(path);
84
- if (!/^https?:\/\//i.test(where))
85
- return readFile(where, "utf8");
86
- const response = await fetch(where, { headers: { accept: "application/json" }, cache: "no-store" });
87
- if (!response.ok)
88
- throw new Error(`${where} answered ${response.status} ${response.statusText}`.trim());
89
- return response.text();
90
- };
73
+ const { site } = source;
91
74
  const index = async () => {
92
- const now = Date.now();
93
- if (cached && now - cached.checkedAt < RECHECK_MS)
94
- return { ok: true, revisions: cached.revisions };
95
- let raw;
96
- try {
97
- raw = JSON.parse(await read("bundles/index.json"));
98
- }
99
- catch (error) {
100
- return unavailable(`The site has no readable Revision index (bundles/index.json): ${reason(error)}`);
101
- }
102
- const revisions = raw?.revisions;
103
- if (!Array.isArray(revisions))
104
- return unavailable("The site's bundles/index.json holds no Revisions.");
105
- cached = { revisions: revisions, checkedAt: now };
106
- return { ok: true, revisions: cached.revisions };
107
- };
108
- /** A point as a Revision of the index: the last at or before a date, a tag, or a sha (or its prefix). */
109
- const entryAt = async (point) => {
110
- const listed = await index();
111
- if (!listed.ok)
112
- return listed;
113
- const { revisions } = listed;
114
- if (isDate(point)) {
115
- const time = dateTime(point, "end");
116
- return revisions.find((r) => Date.parse(r.date) <= time) ?? noCommit(point);
117
- }
118
- const tagged = revisions.find((r) => r.tags.includes(point));
119
- if (tagged)
120
- return tagged;
121
- if (/^[0-9a-f]{4,40}$/i.test(point)) {
122
- const matches = revisions.filter((r) => r.sha.startsWith(point.toLowerCase()));
123
- if (matches.length === 1)
124
- return matches[0];
125
- if (matches.length > 1)
126
- return { ok: false, code: "not_found", message: `"${point}" is the start of ${matches.length} Revisions' shas; give more of it.`, suggestions: matches.map((m) => m.sha).slice(0, 5) };
127
- }
128
- return noCommit(point, revisions.flatMap((r) => r.tags).slice(0, 5));
129
- };
130
- const fetchBundle = (sha) => {
131
- let pending = bundles.get(sha);
132
- if (!pending) {
133
- pending = (async () => {
134
- let raw;
135
- try {
136
- raw = JSON.parse(await read(`bundles/${sha}.json`));
137
- }
138
- catch (error) {
139
- return unavailable(`The Bundle at ${sha.slice(0, 7)} can't be read from the site: ${reason(error)}`);
140
- }
141
- return migrateBundle(raw) ?? unavailable(`The Bundle at ${sha.slice(0, 7)} has a schema this Archidocs can't read or migrate.`);
142
- })();
143
- bundles.set(sha, pending);
144
- // A failure may be a host's hiccup; ask again next time.
145
- void pending.then((b) => "ok" in b && bundles.delete(sha));
146
- }
147
- return pending;
75
+ const read = await site.index();
76
+ if (!read.ok)
77
+ return unavailable(read.message);
78
+ if (!read.index)
79
+ return unavailable(`The site has no Revision index (${INDEX_PATH}), so it has no history.`);
80
+ return { ok: true, revisions: read.index.revisions };
148
81
  };
149
82
  return {
150
83
  index,
151
84
  async at(point, current) {
152
85
  const commit = current.bundle.commit;
153
- if (commit && (point === commit || (/^[0-9a-f]{4,40}$/i.test(point) && commit.startsWith(point.toLowerCase())))) {
86
+ // The current commit answers without the index; a prefix of it does unless the index says it starts other shas too.
87
+ if (commit && point === commit)
154
88
  return { ok: true, commit, snapshot: current };
155
- }
156
- const entry = await entryAt(point);
157
- if ("ok" in entry)
158
- return entry;
89
+ const startsCommit = !!commit && /^[0-9a-f]{4,64}$/i.test(point) && commit.startsWith(point.toLowerCase());
90
+ const listed = await index();
91
+ if (!listed.ok)
92
+ return startsCommit ? { ok: true, commit: commit, snapshot: current } : listed;
93
+ const found = find(listed.revisions, point);
94
+ if (!found.ok)
95
+ return found.kind === "not_found" && startsCommit ? { ok: true, commit: commit, snapshot: current } : findFailure(point, found);
96
+ const entry = found.revision;
159
97
  if (entry.sha === commit)
160
98
  return { ok: true, commit, snapshot: current };
161
- if (entry.bundle === false)
162
- return unavailable(`The Bundle at ${entry.sha.slice(0, 7)} (${entry.date}) was not kept on this site.`);
163
- const bundle = await fetchBundle(entry.sha);
164
- if ("ok" in bundle)
165
- return bundle;
166
- return { ok: true, commit: entry.sha, snapshot: { bundle, issues: [] } };
99
+ const past = await site.bundle(entry);
100
+ if (!past.ok)
101
+ return unavailable(past.message);
102
+ return { ok: true, commit: entry.sha, snapshot: { bundle: past.bundle, issues: [] } };
167
103
  },
168
- async time(point, edge) {
169
- if (isDate(point))
170
- return { ok: true, time: dateTime(point, edge) };
171
- const entry = await entryAt(point);
172
- return "ok" in entry ? entry : { ok: true, time: Date.parse(entry.date) };
104
+ async span(point) {
105
+ // Tags come first, so read the index; a day or a time still spans itself without one.
106
+ const listed = await index();
107
+ if (!listed.ok) {
108
+ const own = timeSpan(point);
109
+ return own ? { ok: true, span: own } : listed;
110
+ }
111
+ const spanned = span(listed.revisions, point);
112
+ return spanned.ok ? spanned : findFailure(point, spanned);
173
113
  },
174
114
  };
175
115
  }
@@ -1,4 +1,6 @@
1
1
  export { createServer, type ServerOptions } from "./server.ts";
2
2
  export { ERROR_CODES, type ErrorCode } from "./errors.ts";
3
3
  export { bundleSource, checkoutSource, type BundleSource, type CheckoutSource, type Source, type Snapshot } from "./source.ts";
4
+ export { checkServer, type CheckResult } from "./check.ts";
5
+ export { startupLine, callLine, describeSource, type Log } from "./announce.ts";
4
6
  export { serveHttp, DEFAULT_PORT, type HttpServer, type ServeHttpOptions } from "./http.ts";
package/dist/mcp/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export { createServer } from "./server.js";
2
2
  export { ERROR_CODES } from "./errors.js";
3
3
  export { bundleSource, checkoutSource } from "./source.js";
4
+ export { checkServer } from "./check.js";
5
+ export { startupLine, callLine, describeSource } from "./announce.js";
4
6
  export { serveHttp, DEFAULT_PORT } from "./http.js";
@@ -3,6 +3,7 @@ import { z } from "zod";
3
3
  import type { Snapshot, Source } from "./source.ts";
4
4
  import { type Past } from "./history.ts";
5
5
  import type { ErrorCode } from "./errors.ts";
6
+ import { type Log } from "./announce.ts";
6
7
  export interface ServerOptions {
7
8
  source: Source;
8
9
  /** Base URL of a published viewer; when set, results carry `viewerUrl` links. */
@@ -13,6 +14,11 @@ export interface ServerOptions {
13
14
  * source that takes them: a Bundle never does.
14
15
  */
15
16
  allowWrites?: boolean;
17
+ /** The archidocs version, reported to clients. */
18
+ version?: string;
19
+ /** Where to log tool calls: every write call, and read calls too with `logReads`. */
20
+ log?: Log;
21
+ logReads?: boolean;
16
22
  }
17
23
  export type ToolOutcome = {
18
24
  ok: true;
@@ -9,8 +9,10 @@ import { describeLens, listViews, resolveView } from "../core/views/index.js";
9
9
  import { listAdrs } from "../core/adrs.js";
10
10
  import { AdrStatus } from "../schema/adr.js";
11
11
  import { BundleAdr, BundleDeployment, BundleElement, BundleLens, BundleRelationship } from "../schema/bundle.js";
12
+ import { POINT_GRAMMAR, touching } from "../revisions/index.js";
12
13
  import { pastOf } from "./history.js";
13
14
  import { registerWriteTools } from "./writes.js";
15
+ import { callLine } from "./announce.js";
14
16
  import { authoringGuide, topics } from "../guide/index.js";
15
17
  const ok = (data, text) => ({ ok: true, data, text });
16
18
  const fail = (code, message, suggestions) => ({ ok: false, code, message, ...(suggestions ? { suggestions } : {}) });
@@ -24,12 +26,19 @@ const fail = (code, message, suggestions) => ({ ok: false, code, message, ...(su
24
26
  */
25
27
  export function createServer(options) {
26
28
  const { source } = options;
27
- const server = new McpServer({ name: "archidocs", version: "0.0.0" }, { capabilities: { tools: {} } });
29
+ const server = new McpServer({ name: "archidocs", version: options.version ?? "0.0.0" }, { capabilities: { tools: {} } });
28
30
  const writesAllowed = source.writesAllowed && options.allowWrites !== false;
29
31
  const readOnlyReason = source.kind === "bundle"
30
32
  ? `This server reads a published Bundle (${source.location}); write tools need a checkout.`
31
33
  : "Write tools are off over HTTP; restart the server with --allow-writes to allow them.";
32
34
  const past = pastOf(source);
35
+ /** Wraps a tool handler so its call is logged: always for a write, for a read only with `logReads`. */
36
+ const logged = (name, write, handle) => async (raw) => {
37
+ const result = await handle(raw);
38
+ if (options.log && (write || options.logReads))
39
+ options.log(callLine(name, raw, result));
40
+ return result;
41
+ };
33
42
  /**
34
43
  * Registers a tool. A read tool also takes `at` (a ref or a date) and runs
35
44
  * over the Bundle there; a write tool refuses `at`.
@@ -42,7 +51,7 @@ export function createServer(options) {
42
51
  inputSchema: advertise(input),
43
52
  outputSchema: config.output,
44
53
  annotations: { readOnlyHint: !config.write, openWorldHint: false },
45
- }, async (raw) => {
54
+ }, logged(name, config.write === true, async (raw) => {
46
55
  if (config.write && !writesAllowed)
47
56
  return toResult(fail("read_only", readOnlyReason));
48
57
  if (config.write && takesAt(raw))
@@ -66,7 +75,7 @@ export function createServer(options) {
66
75
  snapshot = then.snapshot;
67
76
  }
68
77
  return toResult(await run(rest, snapshot, { past, at, current }));
69
- });
78
+ }));
70
79
  };
71
80
  tool("get_workspace_info", {
72
81
  title: "Workspace info",
@@ -506,10 +515,10 @@ export function createServer(options) {
506
515
  });
507
516
  tool("get_changes", {
508
517
  title: "Get Changes",
509
- description: "What changed in the Model between two points in time, each a ref (sha, tag or branch) or a date: a flat list of Changes (added, removed or changed), each with the fields that differ and the whole item before and after. `to` defaults to `at`, else the Workspace the server is reading. `scope` narrows to an Element (with its descendants and the Relationships, Deployments and ADRs touching them), a Team (what it owns at either side) or a Project; pass `scope_kind` when a Team and a Project share the id. `kinds` keeps only some item kinds.",
518
+ description: `What changed in the Model between two points in time, each ${POINT_GRAMMAR} (on a checkout, any git ref too): a flat list of Changes (added, removed or changed), each with the fields that differ and the whole item before and after. \`to\` defaults to \`at\`, else the Workspace the server is reading. \`scope\` narrows to an Element (with its descendants and the Relationships, Deployments and ADRs touching them), a Team (what it owns at either side) or a Project; pass \`scope_kind\` when a Team and a Project share the id. \`kinds\` keeps only some item kinds.`,
510
519
  input: z.object({
511
- from: Point.describe("The point to compare from: a ref or a date"),
512
- to: Point.optional().describe("The point to compare to; defaults to `at`, else the current Workspace"),
520
+ from: Point.describe(`The point to compare from: ${POINT_GRAMMAR}`),
521
+ to: Point.optional().describe(`The point to compare to: ${POINT_GRAMMAR}. Defaults to \`at\`, else the current Workspace`),
513
522
  scope: z.string().min(1).optional().describe("An Element (project:id), a Team id or a Project id"),
514
523
  scope_kind: ScopeKind.optional(),
515
524
  kinds: z.array(ChangeKindSchema).min(1).optional().describe(`Only these item kinds: ${changeKinds.join(", ")}`),
@@ -562,12 +571,12 @@ export function createServer(options) {
562
571
  });
563
572
  tool("list_history", {
564
573
  title: "List history",
565
- description: "The Revisions (default-branch commits that changed the Workspace), newest first, each with sha, date, subject, author, tags, change counts against the Revision before, and whether its Bundle can be read with `at`. `scope` keeps the Revisions that touched an Element or its descendants, a Team or what it owns, or a Project (as they are at `at`, else now). `since` and `until` are refs or dates, inclusive; with `at`, Revisions after it are left out. Read from the Revision index, so it is cheap.",
574
+ description: "The Revisions (default-branch commits that changed the Workspace), newest first, each with sha, date, subject, author, tags, change counts against the Revision before, and whether its Bundle can be read with `at`. `scope` keeps the Revisions that touched an Element or its descendants, a Team or what it owns, or a Project (as they are at `at`, else now). `since` and `until` are points, inclusive: a day covers the whole UTC day. With `at`, Revisions after it are left out. Read from the Revision index, so it is cheap.",
566
575
  input: z.object({
567
576
  scope: z.string().min(1).optional().describe("An Element (project:id), a Team id or a Project id"),
568
577
  scope_kind: ScopeKind.optional(),
569
- since: Point.optional().describe("The earliest point: a ref or a date"),
570
- until: Point.optional().describe("The latest point: a ref or a date"),
578
+ since: Point.optional().describe(`The earliest point: ${POINT_GRAMMAR}`),
579
+ until: Point.optional().describe(`The latest point: ${POINT_GRAMMAR}`),
571
580
  limit: Limit,
572
581
  }),
573
582
  output: z.object({
@@ -581,17 +590,18 @@ export function createServer(options) {
581
590
  if (!listed.ok)
582
591
  return listed;
583
592
  let revisions = listed.revisions;
584
- for (const [point, edge, keep] of [
585
- [since, "start", (t, d) => d >= t],
586
- [until, "end", (t, d) => d <= t],
587
- [at, "end", (t, d) => d <= t],
593
+ // A Revision is kept from the start of `since`'s span up to, not including, the end of `until`'s or `at`'s.
594
+ for (const [point, keep] of [
595
+ [since, (s, d) => d >= s.start],
596
+ [until, (s, d) => d < s.end],
597
+ [at, (s, d) => d < s.end],
588
598
  ]) {
589
599
  if (point === undefined)
590
600
  continue;
591
- const time = await past.time(point, edge);
592
- if (!time.ok)
593
- return time;
594
- revisions = revisions.filter((r) => keep(time.time, Date.parse(r.date)));
601
+ const spanned = await past.span(point);
602
+ if (!spanned.ok)
603
+ return spanned;
604
+ revisions = revisions.filter((r) => keep(spanned.span, Date.parse(r.date)));
595
605
  }
596
606
  let resolved;
597
607
  if (scope !== undefined) {
@@ -599,8 +609,7 @@ export function createServer(options) {
599
609
  if (!found.ok)
600
610
  return scopeFailure(scope, found);
601
611
  resolved = found.scope;
602
- const touched = scopeMatcher(resolved, [bundle]);
603
- revisions = revisions.filter((r) => touched(r.changedIds));
612
+ revisions = touching(revisions, scopeMatcher(resolved, [bundle]));
604
613
  }
605
614
  const { items, total, truncated } = page(revisions.map(({ sha, date, subject, author, tags, counts, bundle: kept }) => ({ sha, date, subject, author, tags, counts, bundle: kept })), limit);
606
615
  const tally = ({ added, removed, changed }) => [added && `+${added}`, removed && `-${removed}`, changed && `~${changed}`].filter(Boolean).join(" ") || "no Changes";
@@ -646,7 +655,7 @@ export function createServer(options) {
646
655
  return toResult(fail("not_found", guide.message, guide.suggestion ? [guide.suggestion] : undefined));
647
656
  return toResult(ok({ topic: guide.topic, topics: topics.map((t) => ({ ...t })), text: guide.text }, guide.text));
648
657
  });
649
- registerWriteTools(server, source, writesAllowed ? undefined : readOnlyReason);
658
+ registerWriteTools(server, source, writesAllowed ? undefined : readOnlyReason, logged);
650
659
  return server;
651
660
  }
652
661
  const Point = z.string().min(1);
@@ -684,7 +693,7 @@ function scopeFailure(scope, found) {
684
693
  return fail("ambiguous", `"${scope}" is both a ${found.candidates.map((c) => c.kind).join(" and a ")}; pass scope_kind to pick one.`, found.candidates.map((c) => c.kind));
685
694
  return notFound("Element, Team or Project", scope, found.known);
686
695
  }
687
- const At = z.string().min(1).describe("A point in time to answer at: a ref (sha, tag or branch) or a date (YYYY-MM-DD, the last Revision on or before it). Leave out for the current Workspace.");
696
+ const At = z.string().min(1).describe(`A point in time to answer at: ${POINT_GRAMMAR}. On a checkout, any git ref works too. Leave out for the current Workspace.`);
688
697
  /** Whether a call's raw arguments carry `at`, which write tools never take. */
689
698
  export const takesAt = (raw) => raw !== null && typeof raw === "object" && "at" in raw;
690
699
  export const atRefused = "Write tools never take `at`: they edit the Workspace as it is now.";
@@ -0,0 +1,12 @@
1
+ import { type SiteReader } from "../revisions/index.ts";
2
+ /**
3
+ * A {@link SiteReader} for `archidocs mcp --bundle <location>`: a URL or a
4
+ * path, naming the site (its root) or a `.json` Bundle file in it. A
5
+ * Bundle file's folder is the root, and its name is the latest Bundle's
6
+ * path. Over HTTP it reads with `fetch`; on disk, a file's mtime and size
7
+ * stand in for an ETag, so an unchanged file is not read again.
8
+ */
9
+ export declare function siteAt(location: string): {
10
+ reader: SiteReader;
11
+ bundle: string;
12
+ };
@@ -0,0 +1,46 @@
1
+ import { readFile, stat } from "node:fs/promises";
2
+ import { basename, dirname, join, resolve } from "node:path";
3
+ import { fetchReader, LATEST_BUNDLE_PATH } from "../revisions/index.js";
4
+ /**
5
+ * A {@link SiteReader} for `archidocs mcp --bundle <location>`: a URL or a
6
+ * path, naming the site (its root) or a `.json` Bundle file in it. A
7
+ * Bundle file's folder is the root, and its name is the latest Bundle's
8
+ * path. Over HTTP it reads with `fetch`; on disk, a file's mtime and size
9
+ * stand in for an ETag, so an unchanged file is not read again.
10
+ */
11
+ export function siteAt(location) {
12
+ if (/^https?:\/\//i.test(location)) {
13
+ const url = new URL(location);
14
+ if (url.pathname.endsWith(".json")) {
15
+ const name = url.pathname.slice(url.pathname.lastIndexOf("/") + 1);
16
+ return { reader: fetchReader(new URL("./", url).href), bundle: name };
17
+ }
18
+ if (!url.pathname.endsWith("/"))
19
+ url.pathname += "/";
20
+ return { reader: fetchReader(url.href), bundle: LATEST_BUNDLE_PATH };
21
+ }
22
+ const path = resolve(location);
23
+ return path.endsWith(".json") ? { reader: fileReader(dirname(path)), bundle: basename(path) } : { reader: fileReader(path), bundle: LATEST_BUNDLE_PATH };
24
+ }
25
+ function fileReader(root) {
26
+ const location = (path) => join(root, ...path.split("/"));
27
+ return {
28
+ location,
29
+ async read(path, validators) {
30
+ const where = location(path);
31
+ try {
32
+ const s = await stat(where);
33
+ const etag = `${s.mtimeMs}-${s.size}`;
34
+ if (validators?.etag === etag)
35
+ return { kind: "not_modified" };
36
+ return { kind: "text", text: await readFile(where, "utf8"), validators: { etag } };
37
+ }
38
+ catch (error) {
39
+ // A missing file, or a folder missing on the way to it.
40
+ if (error.code === "ENOENT" || error.code === "ENOTDIR")
41
+ return { kind: "missing" };
42
+ throw error;
43
+ }
44
+ },
45
+ };
46
+ }
@@ -1,5 +1,7 @@
1
- import { type Issue } from "../core/index.ts";
2
- import { Bundle } from "../schema/bundle.ts";
1
+ import type { Issue } from "../core/index.ts";
2
+ import { type Checkout } from "../workspace/index.ts";
3
+ import type { Bundle } from "../schema/bundle.ts";
4
+ import { type Site } from "../revisions/index.ts";
3
5
  /** The Bundle the server answers from, with the issues Load found building it. */
4
6
  export interface Snapshot {
5
7
  bundle: Bundle;
@@ -20,11 +22,15 @@ export interface CheckoutSource extends SourceBase {
20
22
  readonly kind: "checkout";
21
23
  /** The Workspace root: the folder holding `workspace.yaml`. */
22
24
  readonly root: string;
25
+ /** The Checkout at `root` the Bundle is built from. */
26
+ readonly checkout: Checkout;
23
27
  }
24
28
  export interface BundleSource extends SourceBase {
25
29
  readonly kind: "bundle";
26
30
  /** The Bundle file's URL or absolute path. */
27
31
  readonly location: string;
32
+ /** The site the Bundle is read from, which also holds its Revision index and past Bundles. */
33
+ readonly site: Site;
28
34
  }
29
35
  /**
30
36
  * A local checkout: the Bundle is built in memory and rebuilt when a file
@@ -38,11 +44,12 @@ export declare function checkoutSource({ root }: {
38
44
  /**
39
45
  * A published Workspace Bundle, read-only. `location` is a URL or a path,
40
46
  * naming either the Bundle file or the site (folder) that holds
41
- * `workspace.bundle.json`. The source is re-checked at most every 60 s; over
42
- * HTTP the re-check is a conditional request when the host gave an ETag or
43
- * Last-Modified, so an unchanged Bundle costs a 304. A source that can't be
44
- * read, or doesn't hold a valid Bundle, rejects and the tool returns
45
- * `source_unavailable`; the next call tries again.
47
+ * `workspace.bundle.json`. The Bundle and the site's Revision index are
48
+ * re-checked at most every 60 s; over HTTP the re-check is a conditional
49
+ * request when the host gave an ETag or Last-Modified, so an unchanged file
50
+ * costs a 304. A Bundle from an older Archidocs is migrated. A source that
51
+ * can't be read, or doesn't hold a Bundle this version can read, rejects and
52
+ * the tool returns `source_unavailable`; the next call tries again.
46
53
  */
47
54
  export declare function bundleSource({ location }: {
48
55
  location: string;