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.
Files changed (119) hide show
  1. package/README.md +62 -13
  2. package/dist/cli/commands.d.ts +231 -10
  3. package/dist/cli/commands.js +134 -9
  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 +1 -1
  8. package/dist/cli/init.js +2 -2
  9. package/dist/cli/main.js +2 -329
  10. package/dist/cli/run.d.ts +18 -0
  11. package/dist/cli/run.js +283 -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/compare.d.ts +2 -13
  25. package/dist/core/compare.js +2 -35
  26. package/dist/core/index.d.ts +3 -6
  27. package/dist/core/index.js +3 -6
  28. package/dist/core/load.d.ts +0 -2
  29. package/dist/core/load.js +5 -6
  30. package/dist/core/rules.d.ts +10 -0
  31. package/dist/core/rules.js +186 -7
  32. package/dist/core/views/compare.d.ts +12 -0
  33. package/dist/core/views/compare.js +37 -0
  34. package/dist/core/{deployment-views.d.ts → views/deployment.d.ts} +4 -5
  35. package/dist/core/{deployment-views.js → views/deployment.js} +5 -7
  36. package/dist/core/{dynamic-views.d.ts → views/dynamic.d.ts} +1 -3
  37. package/dist/core/{dynamic-views.js → views/dynamic.js} +4 -8
  38. package/dist/core/views/generated.d.ts +18 -0
  39. package/dist/core/views/generated.js +92 -0
  40. package/dist/core/views/ids.d.ts +36 -0
  41. package/dist/core/views/ids.js +51 -0
  42. package/dist/core/views/index.d.ts +13 -0
  43. package/dist/core/views/index.js +12 -0
  44. package/dist/core/views/lens.d.ts +27 -0
  45. package/dist/core/views/lens.js +112 -0
  46. package/dist/core/views/model.d.ts +21 -0
  47. package/dist/core/views/model.js +69 -0
  48. package/dist/core/views/resolve.d.ts +42 -0
  49. package/dist/core/views/resolve.js +81 -0
  50. package/dist/core/{save-as-view.d.ts → views/save-as-view.d.ts} +2 -2
  51. package/dist/core/{save-as-view.js → views/save-as-view.js} +13 -10
  52. package/dist/core/{saved-views.d.ts → views/saved.d.ts} +4 -18
  53. package/dist/core/{saved-views.js → views/saved.js} +8 -103
  54. package/dist/core/views/types.d.ts +91 -0
  55. package/dist/core/views/types.js +2 -0
  56. package/dist/core/workspace-files.d.ts +13 -0
  57. package/dist/core/workspace-files.js +20 -0
  58. package/dist/git.d.ts +2 -0
  59. package/dist/git.js +14 -4
  60. package/dist/history/git.d.ts +0 -10
  61. package/dist/history/git.js +1 -30
  62. package/dist/history/index.d.ts +15 -31
  63. package/dist/history/index.js +47 -43
  64. package/dist/history/points.d.ts +23 -0
  65. package/dist/history/points.js +28 -0
  66. package/dist/history/site.d.ts +30 -0
  67. package/dist/history/site.js +37 -0
  68. package/dist/mcp/errors.d.ts +37 -0
  69. package/dist/mcp/errors.js +35 -0
  70. package/dist/mcp/history.d.ts +4 -4
  71. package/dist/mcp/history.js +56 -116
  72. package/dist/mcp/index.d.ts +2 -1
  73. package/dist/mcp/index.js +1 -0
  74. package/dist/mcp/server.d.ts +1 -2
  75. package/dist/mcp/server.js +30 -29
  76. package/dist/mcp/site.d.ts +12 -0
  77. package/dist/mcp/site.js +46 -0
  78. package/dist/mcp/source.d.ts +14 -7
  79. package/dist/mcp/source.js +25 -99
  80. package/dist/render/layout.d.ts +20 -3
  81. package/dist/render/layout.js +49 -12
  82. package/dist/render/sequence-svg.d.ts +1 -1
  83. package/dist/render/sequence.d.ts +1 -1
  84. package/dist/render/svg.d.ts +1 -1
  85. package/dist/render/svg.js +4 -4
  86. package/dist/revisions/find.d.ts +64 -0
  87. package/dist/revisions/find.js +85 -0
  88. package/dist/revisions/index.d.ts +57 -0
  89. package/dist/revisions/index.js +24 -0
  90. package/dist/revisions/site.d.ts +82 -0
  91. package/dist/revisions/site.js +157 -0
  92. package/dist/revisions/text.d.ts +8 -0
  93. package/dist/revisions/text.js +17 -0
  94. package/dist/revisions/touching.d.ts +7 -0
  95. package/dist/revisions/touching.js +7 -0
  96. package/dist/schema/adr.js +18 -13
  97. package/dist/schema/workspace.js +226 -130
  98. package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
  99. package/dist/viewer/assets/index-YFA-pYjQ.css +1 -0
  100. package/dist/viewer/assets/{layout.worker-Bg-OaLVN.js → layout.worker-BRHAGJrD.js} +1 -1
  101. package/dist/viewer/assets/{png-BDKIXtm5.js → png-DMwnpRCt.js} +1 -1
  102. package/dist/viewer/assets/{svg-Bulv5YWn.js → svg-DN6lMeZo.js} +2 -2
  103. package/dist/viewer/index.html +2 -2
  104. package/dist/workspace/index.d.ts +37 -0
  105. package/dist/workspace/index.js +52 -0
  106. package/guide/SKILL.md +1 -1
  107. package/guide/topics/bootstrap.md +1 -1
  108. package/guide/topics/relationships.md +1 -1
  109. package/package.json +4 -3
  110. package/schemas/adr.schema.json +18 -15
  111. package/schemas/model.schema.json +637 -1144
  112. package/schemas/project.schema.json +8 -4
  113. package/schemas/workspace.schema.json +39 -20
  114. package/dist/core/views.d.ts +0 -126
  115. package/dist/core/views.js +0 -217
  116. package/dist/viewer/assets/index-DvKgCpBr.css +0 -1
  117. package/dist/viewer/assets/index-gucix3xm.js +0 -113
  118. /package/dist/{history → revisions}/migrate.d.ts +0 -0
  119. /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,3 +1,4 @@
1
- export { createServer, type ServerOptions, type ErrorCode } from "./server.ts";
1
+ export { createServer, type ServerOptions } from "./server.ts";
2
+ export { ERROR_CODES, type ErrorCode } from "./errors.ts";
2
3
  export { bundleSource, checkoutSource, type BundleSource, type CheckoutSource, type Source, type Snapshot } from "./source.ts";
3
4
  export { serveHttp, DEFAULT_PORT, type HttpServer, type ServeHttpOptions } from "./http.ts";
package/dist/mcp/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { createServer } from "./server.js";
2
+ export { ERROR_CODES } from "./errors.js";
2
3
  export { bundleSource, checkoutSource } from "./source.js";
3
4
  export { serveHttp, DEFAULT_PORT } from "./http.js";
@@ -2,6 +2,7 @@ import { McpServer, type CallToolResult, type StandardSchemaWithJSON } from "@mo
2
2
  import { z } from "zod";
3
3
  import type { Snapshot, Source } from "./source.ts";
4
4
  import { type Past } from "./history.ts";
5
+ import type { ErrorCode } from "./errors.ts";
5
6
  export interface ServerOptions {
6
7
  source: Source;
7
8
  /** Base URL of a published viewer; when set, results carry `viewerUrl` links. */
@@ -13,8 +14,6 @@ export interface ServerOptions {
13
14
  */
14
15
  allowWrites?: boolean;
15
16
  }
16
- /** The typed error codes a tool result can carry in `structuredContent.code`. */
17
- export type ErrorCode = "not_found" | "ambiguous" | "invalid_input" | "validation_failed" | "read_only" | "source_unavailable" | "history_unavailable";
18
17
  export type ToolOutcome = {
19
18
  ok: true;
20
19
  data: Record<string, unknown>;
@@ -5,12 +5,11 @@ import { withDocs } from "../core/rules.js";
5
5
  import { search } from "../core/search.js";
6
6
  import { changeKinds, countChanges, deriveEdges, diff, filterChanges, findPaths, getImpact, levelOf, listOwned, resolveScope, scopeMatcher, } from "../core/index.js";
7
7
  import { suggest } from "../core/suggest.js";
8
- import { listViews, resolveView } from "../core/views.js";
9
- import { resolveDynamic, resolveDynamicView, takesPart } from "../core/dynamic-views.js";
10
- import { describeLens } from "../core/saved-views.js";
8
+ import { describeLens, listViews, resolveView } from "../core/views/index.js";
11
9
  import { listAdrs } from "../core/adrs.js";
12
10
  import { AdrStatus } from "../schema/adr.js";
13
11
  import { BundleAdr, BundleDeployment, BundleElement, BundleLens, BundleRelationship } from "../schema/bundle.js";
12
+ import { POINT_GRAMMAR, touching } from "../revisions/index.js";
14
13
  import { pastOf } from "./history.js";
15
14
  import { registerWriteTools } from "./writes.js";
16
15
  import { authoringGuide, topics } from "../guide/index.js";
@@ -131,7 +130,7 @@ export function createServer(options) {
131
130
  // Edges at the Element's level that carry at least one Relationship declared beneath either end.
132
131
  const derived = deriveEdges(bundle, levelOf(element)).filter((e) => e.relationships.some((r) => r.from !== e.from || r.to !== e.to));
133
132
  const derivedEdges = { in: derived.filter((e) => e.to === id), out: derived.filter((e) => e.from === id) };
134
- const dynamicViews = bundle.views.flatMap((v) => (v.kind === "dynamic" && takesPart(resolveDynamic(bundle, v).view, id) ? [{ id: v.id, title: v.title }] : []));
133
+ const dynamicViews = listViews(bundle, { kind: "dynamic", element: id }).map((v) => ({ id: v.id, title: v.title }));
135
134
  const data = {
136
135
  element,
137
136
  owner: team ? { id: team.id, name: team.name } : null,
@@ -290,10 +289,11 @@ export function createServer(options) {
290
289
  });
291
290
  tool("get_view", {
292
291
  title: "Get View",
293
- description: "One View by id (c1, c2, c2/<system>, c3/<service>, deployment/<environment>, or a Saved View's project:view-id) as nodes and edges. Neighbours outside the focus are collapsed to the highest level that still separates them; each edge carries the declared Relationships beneath it. A Deployment View nests Deployment Targets (kind `target`), a System box per System inside each Target (id `<system>@<target>`) and the Deployments (kind `deployment`, id `<service>@<target>`, `element` the Service); a consumer Deployment connects to the provider's Deployments under their deepest shared Target, else to all of them, and a related Service with no Deployment there is a node outside every Target. A Saved View with a Lens also returns the Lens, a `mark` ({hit, distance?, side?}, `side` being origin, upstream or downstream for an impact Lens) per node and `lit` per edge; the Lens never changes which nodes the View holds. A Dynamic View instead returns `participants` in drawing order and `steps` [{n, kind: call|return|event, from, to, relationship, interaction, via?, channel?, description, note?}]: an event is drawn publisher → subscriber while `relationship` is the stored subscriber → publisher subscription; a return replies over the sync `relationship` the other way. Steps that don't resolve are left out (`check` reports them).",
292
+ description: "One View by id (c1, c2, c2/<system>, c3/<service>, deployment/<environment>, or a Saved View's project:view-id) as nodes and edges. Neighbors outside the focus are collapsed to the highest level that still separates them; each edge carries the declared Relationships beneath it, and `direction` is the way the View draws (a Saved View's own, else TB for a Deployment View, else LR). A Deployment View nests Deployment Targets (kind `target`), a System box per System inside each Target (id `<system>@<target>`) and the Deployments (kind `deployment`, id `<service>@<target>`, `element` the Service, `target` the Deployment Target), and returns its `environment`; a consumer Deployment connects to the provider's Deployments under their deepest shared Target, else to all of them, and a related Service with no Deployment there is a node outside every Target. A Saved View with a Lens also returns the Lens, a `mark` ({hit, distance?, side?}, `side` being origin, upstream or downstream for an impact Lens) per node and `lit` per edge; the Lens never changes which nodes the View holds. A Dynamic View instead returns `participants` in drawing order and `steps` [{n, kind: call|return|event, from, to, relationship, interaction, via?, channel?, description, note?}]: an event is drawn publisher → subscriber while `relationship` is the stored subscriber → publisher subscription; a return replies over the sync `relationship` the other way. Steps that don't resolve are left out (`check` reports them).",
294
293
  input: z.object({ id: z.string().min(1).describe("A View id, such as c1, c2/shop:checkout, c3/shop:cart or architecture:purchase") }),
295
294
  output: ViewSummary.extend({
296
295
  direction: z.enum(["TB", "BT", "LR", "RL"]).optional(),
296
+ environment: z.string().optional(),
297
297
  lens: BundleLens.optional(),
298
298
  nodes: z
299
299
  .array(z.object({
@@ -301,6 +301,7 @@ export function createServer(options) {
301
301
  kind: z.enum([...ElementKind.options, "target", "deployment"]),
302
302
  name: z.string(),
303
303
  element: z.string().optional(),
304
+ target: z.string().optional(),
304
305
  parent: z.string().nullable(),
305
306
  collapsed: z.boolean(),
306
307
  external: z.boolean(),
@@ -325,21 +326,21 @@ export function createServer(options) {
325
326
  .optional(),
326
327
  }),
327
328
  }, ({ id }, { bundle }) => {
328
- const dynamic = resolveDynamicView(bundle, id);
329
- if (dynamic) {
329
+ const view = resolveView(bundle, id);
330
+ if (!view)
331
+ return notFound("View", id, listViews(bundle).map((v) => v.id));
332
+ if (view.kind === "dynamic") {
333
+ const dynamic = view;
330
334
  return ok({ ...dynamic }, [
331
335
  `${dynamic.title} (${dynamic.id}): ${count(dynamic.participants.length, "participant")}, ${count(dynamic.steps.length, "Step")}.`,
332
336
  `Participants: ${dynamic.participants.join(", ")}`,
333
337
  ...(dynamic.steps.length ? ["Steps:", ...dynamic.steps.map(stepLine)] : []),
334
338
  ].join("\n"));
335
339
  }
336
- const view = resolveView(bundle, id);
337
- if (!view)
338
- return notFound("View", id, listViews(bundle).map((v) => v.id));
339
340
  const edgeCount = `${view.edges.length} edge${view.edges.length === 1 ? "" : "s"}`;
340
341
  return ok({ ...view }, [
341
342
  `${view.title} (${view.id}): ${view.nodes.length} node${view.nodes.length === 1 ? "" : "s"}, ${edgeCount}.`,
342
- ...(view.lens ? [`Lens: ${describeLens(view.lens)}.`] : []),
343
+ ...(view.lens ? [`Lens: ${describeLens(bundle, view.lens)}.`] : []),
343
344
  "Nodes:",
344
345
  ...view.nodes.map(nodeLine),
345
346
  ...(view.edges.length ? ["Edges:", ...view.edges.map((e) => `- ${e.from} → ${e.to}: ${e.relationships.map(relationshipLabel).join("; ")}${e.lit ? " (lit)" : ""}`)] : []),
@@ -506,10 +507,10 @@ export function createServer(options) {
506
507
  });
507
508
  tool("get_changes", {
508
509
  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.",
510
+ 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
511
  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"),
512
+ from: Point.describe(`The point to compare from: ${POINT_GRAMMAR}`),
513
+ to: Point.optional().describe(`The point to compare to: ${POINT_GRAMMAR}. Defaults to \`at\`, else the current Workspace`),
513
514
  scope: z.string().min(1).optional().describe("An Element (project:id), a Team id or a Project id"),
514
515
  scope_kind: ScopeKind.optional(),
515
516
  kinds: z.array(ChangeKindSchema).min(1).optional().describe(`Only these item kinds: ${changeKinds.join(", ")}`),
@@ -562,12 +563,12 @@ export function createServer(options) {
562
563
  });
563
564
  tool("list_history", {
564
565
  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.",
566
+ 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
567
  input: z.object({
567
568
  scope: z.string().min(1).optional().describe("An Element (project:id), a Team id or a Project id"),
568
569
  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"),
570
+ since: Point.optional().describe(`The earliest point: ${POINT_GRAMMAR}`),
571
+ until: Point.optional().describe(`The latest point: ${POINT_GRAMMAR}`),
571
572
  limit: Limit,
572
573
  }),
573
574
  output: z.object({
@@ -581,17 +582,18 @@ export function createServer(options) {
581
582
  if (!listed.ok)
582
583
  return listed;
583
584
  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],
585
+ // A Revision is kept from the start of `since`'s span up to, not including, the end of `until`'s or `at`'s.
586
+ for (const [point, keep] of [
587
+ [since, (s, d) => d >= s.start],
588
+ [until, (s, d) => d < s.end],
589
+ [at, (s, d) => d < s.end],
588
590
  ]) {
589
591
  if (point === undefined)
590
592
  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)));
593
+ const spanned = await past.span(point);
594
+ if (!spanned.ok)
595
+ return spanned;
596
+ revisions = revisions.filter((r) => keep(spanned.span, Date.parse(r.date)));
595
597
  }
596
598
  let resolved;
597
599
  if (scope !== undefined) {
@@ -599,8 +601,7 @@ export function createServer(options) {
599
601
  if (!found.ok)
600
602
  return scopeFailure(scope, found);
601
603
  resolved = found.scope;
602
- const touched = scopeMatcher(resolved, [bundle]);
603
- revisions = revisions.filter((r) => touched(r.changedIds));
604
+ revisions = touching(revisions, scopeMatcher(resolved, [bundle]));
604
605
  }
605
606
  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
607
  const tally = ({ added, removed, changed }) => [added && `+${added}`, removed && `-${removed}`, changed && `~${changed}`].filter(Boolean).join(" ") || "no Changes";
@@ -631,7 +632,7 @@ export function createServer(options) {
631
632
  });
632
633
  server.registerTool("get_authoring_guide", {
633
634
  title: "Authoring guide",
634
- description: "How to edit the Model with the write tools. With no topic: the archidocs-authoring skill (the Model, the edit loop) and its list of topics. With a topic: that flow's reference file; `rules` is the catalogue of every check rule. Load it before writing.",
635
+ description: "How to edit the Model with the write tools. With no topic: the archidocs-authoring skill (the Model, the edit loop) and its list of topics. With a topic: that flow's reference file; `rules` is the catalog of every check rule. Load it before writing.",
635
636
  inputSchema: advertise(GuideInput),
636
637
  outputSchema: z.object({ topic: z.string().nullable(), topics: z.array(z.object({ id: z.string(), summary: z.string() })), text: z.string() }),
637
638
  annotations: { readOnlyHint: true, openWorldHint: false },
@@ -684,7 +685,7 @@ function scopeFailure(scope, found) {
684
685
  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
686
  return notFound("Element, Team or Project", scope, found.known);
686
687
  }
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.");
688
+ 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
689
  /** Whether a call's raw arguments carry `at`, which write tools never take. */
689
690
  export const takesAt = (raw) => raw !== null && typeof raw === "object" && "at" in raw;
690
691
  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;