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
package/README.md CHANGED
@@ -34,21 +34,15 @@ The questions it's built to answer:
34
34
 
35
35
  From an empty repo to your first System in the viewer, in about five minutes. Archidocs needs Node.js 22.18 or later.
36
36
 
37
- **1. Install the CLI.** With pnpm, use `pnpm add --global archidocs`. To install nothing, put `npx` before each command, as in `npx archidocs check`.
37
+ **1. Create a Workspace.** There is nothing to install: `npx` runs the CLI. In the repo that will hold the Workspace (a new, empty one is fine):
38
38
 
39
39
  ```bash
40
- npm install --global archidocs
40
+ npx archidocs init
41
41
  ```
42
42
 
43
- **2. Create a Workspace.** In the repo that will hold it (a new, empty one is fine):
43
+ This writes a starter `archidocs/workspace.yaml`, adds the `.archidocs/` cache to `.gitignore`, and installs an authoring skill for coding agents. The skill and the MCP command it prints use the same `npx` form, so agents never need a global install. To keep a version in the repo, run `npm install --save-dev archidocs` first; to use a bare `archidocs` anywhere, run `npm install --global archidocs`. Run `init` again after either, and it updates the commands it wrote.
44
44
 
45
- ```bash
46
- archidocs init
47
- ```
48
-
49
- This writes a starter `archidocs/workspace.yaml`, adds the `.archidocs/` cache to `.gitignore`, and installs an authoring skill for coding agents.
50
-
51
- **3. Add three files.** Replace `archidocs/workspace.yaml`, which defines Teams and Environments, with:
45
+ **2. Add three files.** Replace `archidocs/workspace.yaml`, which defines Teams and Environments, with:
52
46
 
53
47
  ```yaml
54
48
  teams:
@@ -92,20 +86,20 @@ systems:
92
86
  technology: Node.js
93
87
  ```
94
88
 
95
- **4. Check it.**
89
+ **3. Check it.**
96
90
 
97
91
  ```bash
98
- archidocs check
92
+ npx archidocs check
99
93
  ```
100
94
 
101
95
  ```text
102
96
  0 errors, 0 warnings
103
97
  ```
104
98
 
105
- **5. Open the viewer.**
99
+ **4. Open the viewer.**
106
100
 
107
101
  ```bash
108
- archidocs dev
102
+ npx archidocs dev
109
103
  ```
110
104
 
111
105
  Open <http://localhost:4321>. The viewer starts on the C2 Landscape, which shows the Shopper and the Online Shop; select the arrow button on the Online Shop box to see the two Services inside it. The viewer reloads as you edit the files.
@@ -212,7 +206,7 @@ A failed check deploys nothing, so the last good site stays up. GitLab Pages, PR
212
206
  archidocs mcp --workspace ./archidocs
213
207
  ```
214
208
 
215
- `archidocs init` installs the authoring skill into `.agents/skills`, `.claude/skills` and `.github/skills`. The full guide is in [guide/SKILL.md](guide/SKILL.md) with task topics in [guide/topics](guide/topics).
209
+ `archidocs init` registers that server in the repo's `.mcp.json`, which Claude Code, VS Code and Copilot read, and prints a `--check` command that runs the server once and reports what it serves. Once running, the server prints one line to stderr saying what it loaded, and logs each write. `init` also installs the authoring skill into `.agents/skills`, `.claude/skills` and `.github/skills`. The full guide is in [guide/SKILL.md](guide/SKILL.md) with task topics in [guide/topics](guide/topics).
216
210
 
217
211
  ## Examples
218
212
 
@@ -249,7 +249,7 @@ export declare const commands: {
249
249
  readonly dev: {
250
250
  readonly name: "dev";
251
251
  readonly synopsis: readonly ["dev [--workspace <dir>] [--port <n>] [--host <host>]"];
252
- readonly description: "Serve the viewer locally and reload it as you edit the Workspace.";
252
+ readonly description: "Serve the viewer locally and reload it when a `.yaml` or `.md` file in the Workspace changes.";
253
253
  readonly arguments: readonly [];
254
254
  readonly flags: {
255
255
  readonly workspace: {
@@ -368,10 +368,10 @@ export declare const commands: {
368
368
  readonly description: "Show what changed in the Model between two points in the Workspace's history.";
369
369
  readonly arguments: readonly [{
370
370
  readonly name: "<from>";
371
- readonly description: "A git ref, or a date, which means the last default-branch commit at or before it.";
371
+ readonly description: "A git ref, or a date or time, which names the last Revision at or before it.";
372
372
  }, {
373
373
  readonly name: "[<to>]";
374
- readonly description: "A ref or date like `<from>`; with none, the working tree.";
374
+ readonly description: "A ref, date or time like `<from>`; with none, the working tree.";
375
375
  }];
376
376
  readonly flags: {
377
377
  readonly format: {
@@ -389,7 +389,7 @@ export declare const commands: {
389
389
  readonly description: "Show what a branch changes against the default branch, as a reviewer of its pull request will see it.";
390
390
  }, {
391
391
  readonly command: "archidocs diff 2026-01-01 2026-06-30";
392
- readonly description: "Show the Changes between two dates; each date means the last default-branch commit at or before it.";
392
+ readonly description: "Show the Changes between two dates; each date names the last Revision at or before it.";
393
393
  }, {
394
394
  readonly command: "archidocs diff origin/main HEAD --format markdown";
395
395
  readonly description: "Write the Changes as Markdown, to post as a pull request comment.";
@@ -399,20 +399,20 @@ export declare const commands: {
399
399
  readonly meaning: "The Changes were printed. It exits 0 whether or not anything changed, so a script that asks whether the Model changed must read the output, not the exit code.";
400
400
  }, {
401
401
  readonly code: 2;
402
- readonly meaning: "It could not run: an unknown flag, a flag missing its value, an unknown format, no point or more than two, an unknown ref or date, no Workspace found, or a Workspace outside git.";
402
+ readonly meaning: "It could not run: an unknown flag, a flag missing its value, an unknown format, no point or more than two, an unknown ref or date, a date before the first Revision, a sha prefix of several Revisions, no Workspace found, or a Workspace outside git.";
403
403
  }];
404
404
  };
405
405
  readonly "history build": {
406
406
  readonly name: "history build";
407
- readonly synopsis: readonly ["history build [--since <ref|date>]"];
407
+ readonly synopsis: readonly ["history build [--since <ref|date|time>]"];
408
408
  readonly description: "Build and cache the Bundle of every past Revision, so later builds and diffs don't have to. Safe to re-run.";
409
409
  readonly arguments: readonly [];
410
410
  readonly flags: {
411
411
  readonly since: {
412
412
  readonly type: "string";
413
- readonly value: "<ref|date>";
413
+ readonly value: "<ref|date|time>";
414
414
  readonly defaultText: "every Revision";
415
- readonly description: "Only build Revisions at or after this ref's commit time or the start of this date.";
415
+ readonly description: "Only build Revisions at or after this ref's commit time, the start of this date, or this time (UTC unless it gives a zone).";
416
416
  };
417
417
  };
418
418
  readonly examples: readonly [{
@@ -435,7 +435,7 @@ export declare const commands: {
435
435
  };
436
436
  readonly mcp: {
437
437
  readonly name: "mcp";
438
- readonly synopsis: readonly ["mcp [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>]", "mcp --http [--host <loopback>] [--port <n>] [--allow-writes] [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>]"];
438
+ readonly synopsis: readonly ["mcp [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>] [--check]", "mcp --http [--host <loopback>] [--port <n>] [--allow-writes] [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>]"];
439
439
  readonly description: "Serve the Model to AI agents over MCP, from a Workspace checkout or a published Bundle, on stdio or local HTTP.";
440
440
  readonly arguments: readonly [];
441
441
  readonly flags: {
@@ -477,10 +477,18 @@ export declare const commands: {
477
477
  readonly default: false;
478
478
  readonly description: "With `--http`: allow the write tools, which are off over HTTP by default.";
479
479
  };
480
+ readonly check: {
481
+ readonly type: "boolean";
482
+ readonly default: false;
483
+ readonly description: "Check the server instead of serving: run it behind an in-process client, print what it serves, and exit 0, or 2 with the reason.";
484
+ };
480
485
  };
481
486
  readonly examples: readonly [{
482
487
  readonly command: "archidocs mcp --workspace archidocs";
483
488
  readonly description: "Serve a Workspace checkout over stdio, with the read and write tools. This is the command to register with a coding agent, which starts it from the repo root.";
489
+ }, {
490
+ readonly command: "archidocs mcp --workspace archidocs --check";
491
+ readonly description: "Check the server that command starts: print what it serves and how many tools it has, then exit.";
484
492
  }, {
485
493
  readonly command: "archidocs mcp --bundle https://big-bank.archidocs.dev/workspace.bundle.json";
486
494
  readonly description: "Serve a published Bundle, here the Big Bank demo's, with the read tools only.";
@@ -496,10 +504,10 @@ export declare const commands: {
496
504
  }];
497
505
  readonly exitCodes: readonly [{
498
506
  readonly code: 0;
499
- readonly meaning: "Over stdio, the client closed the connection.";
507
+ readonly meaning: "Over stdio, the client closed the connection. With `--check`, the server started and answered.";
500
508
  }, {
501
509
  readonly code: 2;
502
- readonly meaning: "It could not start: an unknown flag, a flag missing its value, flags that don't go together, a `--viewer-url` that is not a URL, a `--port` that is not a port or is in use, a `--host` that is not a loopback address, or no Workspace found when `--bundle` is not given.";
510
+ readonly meaning: "It could not start: an unknown flag, a flag missing its value, flags that don't go together, a `--viewer-url` that is not a URL, a `--port` that is not a port or is in use, a `--host` that is not a loopback address, no Workspace found when `--bundle` is not given, or, with `--check`, a server that could not read its source.";
503
511
  }];
504
512
  readonly exitNote: "With `--http`, `mcp` runs until you stop it with Ctrl+C. The interrupt ends the process, so the exit status is the shell's for an interrupted command (130 in most shells), not a code of its own. A Bundle that can't be read does not stop the server: each tool call answers `source_unavailable`, and the next call tries again.";
505
513
  };
@@ -118,7 +118,7 @@ export const commands = {
118
118
  dev: {
119
119
  name: "dev",
120
120
  synopsis: ["dev [--workspace <dir>] [--port <n>] [--host <host>]"],
121
- description: "Serve the viewer locally and reload it as you edit the Workspace.",
121
+ description: "Serve the viewer locally and reload it when a `.yaml` or `.md` file in the Workspace changes.",
122
122
  arguments: [],
123
123
  flags: {
124
124
  workspace: { type: "string", value: "<dir>", defaultText: "the Workspace found from the current folder", description: "Where to look for the Workspace." },
@@ -174,8 +174,8 @@ export const commands = {
174
174
  synopsis: ["diff <from> [<to>] [--format text|json|markdown]"],
175
175
  description: "Show what changed in the Model between two points in the Workspace's history.",
176
176
  arguments: [
177
- { name: "<from>", description: "A git ref, or a date, which means the last default-branch commit at or before it." },
178
- { name: "[<to>]", description: "A ref or date like `<from>`; with none, the working tree." },
177
+ { name: "<from>", description: "A git ref, or a date or time, which names the last Revision at or before it." },
178
+ { name: "[<to>]", description: "A ref, date or time like `<from>`; with none, the working tree." },
179
179
  ],
180
180
  flags: {
181
181
  format: { type: "string", value: "text|json|markdown", default: "text", description: "Print the changes as text, JSON, or Markdown for a PR comment." },
@@ -183,21 +183,21 @@ export const commands = {
183
183
  examples: [
184
184
  { command: "archidocs diff HEAD", description: "Show what your uncommitted edits change, against the last commit." },
185
185
  { command: "archidocs diff origin/main HEAD", description: "Show what a branch changes against the default branch, as a reviewer of its pull request will see it." },
186
- { command: "archidocs diff 2026-01-01 2026-06-30", description: "Show the Changes between two dates; each date means the last default-branch commit at or before it." },
186
+ { command: "archidocs diff 2026-01-01 2026-06-30", description: "Show the Changes between two dates; each date names the last Revision at or before it." },
187
187
  { command: "archidocs diff origin/main HEAD --format markdown", description: "Write the Changes as Markdown, to post as a pull request comment." },
188
188
  ],
189
189
  exitCodes: [
190
190
  { code: EXIT.ok, meaning: "The Changes were printed. It exits 0 whether or not anything changed, so a script that asks whether the Model changed must read the output, not the exit code." },
191
- { code: EXIT.couldNotRun, meaning: `It could not run: ${USAGE_ERROR}, an unknown format, no point or more than two, an unknown ref or date, no Workspace found, or a Workspace outside git.` },
191
+ { code: EXIT.couldNotRun, meaning: `It could not run: ${USAGE_ERROR}, an unknown format, no point or more than two, an unknown ref or date, a date before the first Revision, a sha prefix of several Revisions, no Workspace found, or a Workspace outside git.` },
192
192
  ],
193
193
  },
194
194
  "history build": {
195
195
  name: "history build",
196
- synopsis: ["history build [--since <ref|date>]"],
196
+ synopsis: ["history build [--since <ref|date|time>]"],
197
197
  description: "Build and cache the Bundle of every past Revision, so later builds and diffs don't have to. Safe to re-run.",
198
198
  arguments: [],
199
199
  flags: {
200
- since: { type: "string", value: "<ref|date>", defaultText: "every Revision", description: "Only build Revisions at or after this ref's commit time or the start of this date." },
200
+ since: { type: "string", value: "<ref|date|time>", defaultText: "every Revision", description: "Only build Revisions at or after this ref's commit time, the start of this date, or this time (UTC unless it gives a zone)." },
201
201
  },
202
202
  examples: [
203
203
  { command: "archidocs history build", description: "Build and cache the Bundle of every past Revision, so the next `build` or `diff` reads them from the cache." },
@@ -211,7 +211,7 @@ export const commands = {
211
211
  },
212
212
  mcp: {
213
213
  name: "mcp",
214
- synopsis: ["mcp [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>]", "mcp --http [--host <loopback>] [--port <n>] [--allow-writes] [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>]"],
214
+ synopsis: ["mcp [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>] [--check]", "mcp --http [--host <loopback>] [--port <n>] [--allow-writes] [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>]"],
215
215
  description: "Serve the Model to AI agents over MCP, from a Workspace checkout or a published Bundle, on stdio or local HTTP.",
216
216
  arguments: [],
217
217
  flags: {
@@ -222,12 +222,14 @@ export const commands = {
222
222
  host: { type: "string", value: "<loopback>", defaultText: "127.0.0.1", description: "With `--http`: the loopback address to listen on, `127.0.0.1`, `localhost` or `::1`." },
223
223
  port: { type: "string", value: "<n>", defaultText: "3737", description: "With `--http`: the port to serve on." },
224
224
  "allow-writes": { type: "boolean", default: false, description: "With `--http`: allow the write tools, which are off over HTTP by default." },
225
+ check: { type: "boolean", default: false, description: "Check the server instead of serving: run it behind an in-process client, print what it serves, and exit 0, or 2 with the reason." },
225
226
  },
226
227
  examples: [
227
228
  {
228
229
  command: "archidocs mcp --workspace archidocs",
229
230
  description: "Serve a Workspace checkout over stdio, with the read and write tools. This is the command to register with a coding agent, which starts it from the repo root.",
230
231
  },
232
+ { command: "archidocs mcp --workspace archidocs --check", description: "Check the server that command starts: print what it serves and how many tools it has, then exit." },
231
233
  { command: "archidocs mcp --bundle https://big-bank.archidocs.dev/workspace.bundle.json", description: "Serve a published Bundle, here the Big Bank demo's, with the read tools only." },
232
234
  {
233
235
  command: "archidocs mcp --bundle https://architecture.example.com/workspace.bundle.json --viewer-url https://architecture.example.com/",
@@ -237,10 +239,10 @@ export const commands = {
237
239
  { command: "archidocs mcp --http --allow-writes --workspace archidocs", description: "Serve over HTTP with the write tools on." },
238
240
  ],
239
241
  exitCodes: [
240
- { code: EXIT.ok, meaning: "Over stdio, the client closed the connection." },
242
+ { code: EXIT.ok, meaning: "Over stdio, the client closed the connection. With `--check`, the server started and answered." },
241
243
  {
242
244
  code: EXIT.couldNotRun,
243
- meaning: `It could not start: ${USAGE_ERROR}, flags that don't go together, a \`--viewer-url\` that is not a URL, a \`--port\` that is not a port or is in use, a \`--host\` that is not a loopback address, or no Workspace found when \`--bundle\` is not given.`,
245
+ meaning: `It could not start: ${USAGE_ERROR}, flags that don't go together, a \`--viewer-url\` that is not a URL, a \`--port\` that is not a port or is in use, a \`--host\` that is not a loopback address, no Workspace found when \`--bundle\` is not given, or, with \`--check\`, a server that could not read its source.`,
244
246
  },
245
247
  ],
246
248
  exitNote: "With `--http`, `mcp` runs until you stop it with Ctrl+C. The interrupt ends the process, so the exit status is the shell's for an interrupted command (130 in most shells), not a code of its own. A Bundle that can't be read does not stop the server: each tool call answers `source_unavailable`, and the next call tries again.",
package/dist/cli/dev.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { type Issue } from "../core/index.ts";
1
+ import type { Issue } from "../core/index.ts";
2
+ import { type Checkout } from "../workspace/index.ts";
2
3
  export declare const DEFAULT_DEV_PORT = 4321;
3
4
  export interface DevOptions {
4
- /** The Workspace root, watched for changes. */
5
- root: string;
5
+ /** The Workspace to serve. Its root is watched for changes, and its name is how the viewer's exports name the Workspace, as `site.json` does in a built site. */
6
+ checkout: Checkout;
6
7
  /** The prebuilt viewer to serve. */
7
8
  viewerDir: string;
8
- /** How the viewer's exports name the Workspace, as `site.json` does in a built site. */
9
- workspace: string;
10
9
  host?: string;
11
10
  /** 0 picks a free port. */
12
11
  port?: number;
@@ -28,4 +27,4 @@ export interface DevServer {
28
27
  * the Workspace on every file change. A Workspace with errors keeps serving
29
28
  * its last good Bundle and shows the errors in the page instead.
30
29
  */
31
- export declare function serveDev({ root, viewerDir, workspace, host, port, onLoad }: DevOptions): Promise<DevServer>;
30
+ export declare function serveDev({ checkout, viewerDir, host, port, onLoad }: DevOptions): Promise<DevServer>;
package/dist/cli/dev.js CHANGED
@@ -2,10 +2,9 @@ import { watch } from "node:fs";
2
2
  import { readFile, stat } from "node:fs/promises";
3
3
  import { createServer } from "node:http";
4
4
  import { extname, join, normalize, sep } from "node:path";
5
- import { load, nodeFileSystem, serializeBundle } from "../core/index.js";
6
5
  import { formatText } from "./format.js";
7
- import { gitHead } from "../git.js";
8
- import { SCHEMA_VERSION } from "../schema/bundle.js";
6
+ import { isWorkspaceFile } from "../workspace/index.js";
7
+ import { INDEX_PATH, INDEX_VERSION, LATEST_BUNDLE_PATH, serializeBundle, serializeIndex, serializeSiteFile, SITE_FILE_PATH } from "../revisions/index.js";
9
8
  export const DEFAULT_DEV_PORT = 4321;
10
9
  /** The path the page listens on for reloads; under `__archidocs/` so it can't clash with a site file. */
11
10
  const EVENTS = "/__archidocs/events";
@@ -42,7 +41,7 @@ const CLIENT = `<script>
42
41
  * the Workspace on every file change. A Workspace with errors keeps serving
43
42
  * its last good Bundle and shows the errors in the page instead.
44
43
  */
45
- export async function serveDev({ root, viewerDir, workspace, host = "127.0.0.1", port = DEFAULT_DEV_PORT, onLoad }) {
44
+ export async function serveDev({ checkout, viewerDir, host = "127.0.0.1", port = DEFAULT_DEV_PORT, onLoad }) {
46
45
  let bundleJson;
47
46
  let errors;
48
47
  const clients = new Set();
@@ -52,8 +51,7 @@ export async function serveDev({ root, viewerDir, workspace, host = "127.0.0.1",
52
51
  };
53
52
  let first = true;
54
53
  const rebuild = async () => {
55
- const { commit, builtAt } = await gitHead(root);
56
- const { bundle, issues } = await load({ fs: nodeFileSystem(), root, commit, builtAt });
54
+ const { bundle, issues } = await checkout.load();
57
55
  const failed = issues.filter((i) => i.severity === "error");
58
56
  const kept = failed.length > 0 && bundleJson !== undefined;
59
57
  onLoad?.({ issues, kept, first });
@@ -89,8 +87,8 @@ export async function serveDev({ root, viewerDir, workspace, host = "127.0.0.1",
89
87
  };
90
88
  await rebuild();
91
89
  const index = (await readFile(join(viewerDir, "index.html"), "utf8")).replace("</body>", `${CLIENT}</body>`);
92
- const site = JSON.stringify({ workspace }) + "\n";
93
- const noHistory = JSON.stringify({ schemaVersion: SCHEMA_VERSION, revisions: [] }) + "\n";
90
+ const site = serializeSiteFile(await checkout.name());
91
+ const noHistory = serializeIndex({ schemaVersion: INDEX_VERSION, revisions: [] });
94
92
  const server = createServer((req, res) => {
95
93
  void (async () => {
96
94
  const path = decodeURIComponent(new URL(req.url ?? "/", "http://dev").pathname);
@@ -109,12 +107,12 @@ export async function serveDev({ root, viewerDir, workspace, host = "127.0.0.1",
109
107
  }
110
108
  if (path === "/" || path === "/index.html")
111
109
  return send(index, TYPES[".html"]);
112
- if (path === "/workspace.bundle.json")
110
+ if (path === `/${LATEST_BUNDLE_PATH}`)
113
111
  return send(bundleJson, TYPES[".json"]);
114
- if (path === "/site.json")
112
+ if (path === `/${SITE_FILE_PATH}`)
115
113
  return send(site, TYPES[".json"]);
116
114
  // Dev mode shows the working tree only; the viewer reads an empty index as no history.
117
- if (path === "/bundles/index.json")
115
+ if (path === `/${INDEX_PATH}`)
118
116
  return send(noHistory, TYPES[".json"]);
119
117
  const file = normalize(join(viewerDir, path));
120
118
  if (!file.startsWith(normalize(viewerDir + sep)) || !(await stat(file).catch(() => undefined))?.isFile()) {
@@ -132,9 +130,9 @@ export async function serveDev({ root, viewerDir, workspace, host = "127.0.0.1",
132
130
  server.once("error", fail);
133
131
  server.listen(port, host, () => done());
134
132
  });
135
- const watcher = watch(root, { recursive: true }, (_event, name) => {
136
- // Hidden folders (.git, editor swap files) and node_modules aren't Workspace files.
137
- if (name && name.split(/[\\/]/).some((part) => part.startsWith(".") || part === "node_modules"))
133
+ const watcher = watch(checkout.root, { recursive: true }, (_event, name) => {
134
+ // Only a Workspace file feeds the Bundle. Some platforms give no name, so reload then.
135
+ if (name && !isWorkspaceFile(name))
138
136
  return;
139
137
  schedule();
140
138
  });
@@ -1,9 +1,5 @@
1
1
  import { type Change } from "../core/index.ts";
2
+ import type { DiffSide } from "../commands/index.ts";
2
3
  export declare const diffFormats: readonly ["text", "json", "markdown"];
3
4
  export type DiffFormat = (typeof diffFormats)[number];
4
- /** One side of a diff: the point as given and the commit it resolved to (null for the working tree). */
5
- export interface DiffSide {
6
- point: string;
7
- commit: string | null;
8
- }
9
5
  export declare function formatDiff(changes: Change[], from: DiffSide, to: DiffSide, format: DiffFormat): string;
@@ -8,10 +8,20 @@ export interface InitOptions {
8
8
  skillOnly: boolean;
9
9
  /** For `--skill`: the Workspace checkout to print in the MCP command. */
10
10
  workspace?: string;
11
+ /** The environment init ran in, to tell a package runner from a global bin. */
12
+ env: Record<string, string | undefined>;
13
+ /** The archidocs version running init, pinned in the on-demand command. */
14
+ version: string;
11
15
  }
16
+ /**
17
+ * The command that runs archidocs in this repo, as ADR 0001 decides it: the
18
+ * local copy when `package.json` lists archidocs, a pinned on-demand npx when
19
+ * init itself ran through a package runner, else the global bin.
20
+ */
21
+ export declare function archidocsCommand(repoRoot: string, env: Record<string, string | undefined>, version: string): Promise<string>;
12
22
  /**
13
23
  * `archidocs init` and `init --skill`. Safe to re-run: an existing Workspace
14
24
  * and existing pointers are left alone, and the stub is rewritten as is.
15
25
  * Returns the lines to print.
16
26
  */
17
- export declare function init({ repoRoot, cwd, skillOnly, workspace }: InitOptions): Promise<string[]>;
27
+ export declare function init({ repoRoot, cwd, skillOnly, workspace, env, version }: InitOptions): Promise<string[]>;
package/dist/cli/init.js CHANGED
@@ -12,13 +12,41 @@ environments: {}
12
12
  `;
13
13
  /** The local history cache, kept out of git. */
14
14
  const CACHE_IGNORE = ".archidocs/";
15
+ /**
16
+ * The command that runs archidocs in this repo, as ADR 0001 decides it: the
17
+ * local copy when `package.json` lists archidocs, a pinned on-demand npx when
18
+ * init itself ran through a package runner, else the global bin.
19
+ */
20
+ export async function archidocsCommand(repoRoot, env, version) {
21
+ if (await listsArchidocs(join(repoRoot, "package.json")))
22
+ return "npx archidocs";
23
+ if (env.npm_config_user_agent)
24
+ return `npx -y archidocs@${version}`;
25
+ return "archidocs";
26
+ }
27
+ async function listsArchidocs(path) {
28
+ if (!existsSync(path))
29
+ return false;
30
+ try {
31
+ const manifest = JSON.parse(await readFile(path, "utf8"));
32
+ return ["dependencies", "devDependencies", "optionalDependencies"].some((field) => {
33
+ const deps = manifest[field];
34
+ return typeof deps === "object" && deps !== null && "archidocs" in deps;
35
+ });
36
+ }
37
+ catch {
38
+ return false;
39
+ }
40
+ }
15
41
  /**
16
42
  * `archidocs init` and `init --skill`. Safe to re-run: an existing Workspace
17
43
  * and existing pointers are left alone, and the stub is rewritten as is.
18
44
  * Returns the lines to print.
19
45
  */
20
- export async function init({ repoRoot, cwd, skillOnly, workspace }) {
46
+ export async function init({ repoRoot, cwd, skillOnly, workspace, env, version }) {
21
47
  const out = [];
48
+ const runner = await archidocsCommand(repoRoot, env, version);
49
+ const stub = skillStub(runner);
22
50
  const wrote = (path, what) => out.push(`${what} ${posix(relative(repoRoot, path))}`);
23
51
  let workspaceDir;
24
52
  if (!skillOnly) {
@@ -36,31 +64,114 @@ export async function init({ repoRoot, cwd, skillOnly, workspace }) {
36
64
  for (const dir of SKILL_DIRS) {
37
65
  const path = join(repoRoot, dir, SKILL_NAME, "SKILL.md");
38
66
  const before = existsSync(path) ? await readFile(path, "utf8") : undefined;
39
- if (before === skillStub)
67
+ if (before === stub)
40
68
  continue;
41
69
  await mkdir(dirname(path), { recursive: true });
42
- await writeFile(path, skillStub);
70
+ await writeFile(path, stub);
43
71
  wrote(path, before === undefined ? "Wrote" : "Updated");
44
72
  }
45
73
  const where = workspaceDir === undefined ? undefined : posix(relative(repoRoot, workspaceDir)) || ".";
46
74
  const pointer = [
47
- "## Architecture model",
75
+ POINTER_HEADING,
48
76
  "",
49
77
  where === undefined
50
78
  ? "This code's architecture is declared in an Archidocs Workspace kept in another repo."
51
79
  : `This repo's architecture is declared in the Archidocs Workspace in \`${where}/\`.`,
52
- `To edit it, use the \`${SKILL_NAME}\` skill: call the \`get_authoring_guide\` MCP tool, or run \`archidocs guide\` without MCP.`,
80
+ `To edit it, use the \`${SKILL_NAME}\` skill: call the \`get_authoring_guide\` MCP tool, or run \`${runner} guide\` without MCP.`,
53
81
  "",
54
82
  ].join("\n");
55
- const hasPointer = (text) => text.includes(SKILL_NAME);
56
- if (await appendOnce(join(repoRoot, "AGENTS.md"), pointer, hasPointer, { create: true }))
83
+ if (await writePointer(join(repoRoot, "AGENTS.md"), pointer, { create: true }))
57
84
  wrote(join(repoRoot, "AGENTS.md"), "Updated");
58
- if (await appendOnce(join(repoRoot, "CLAUDE.md"), pointer, hasPointer, { create: false }))
85
+ if (await writePointer(join(repoRoot, "CLAUDE.md"), pointer, { create: false }))
59
86
  wrote(join(repoRoot, "CLAUDE.md"), "Updated");
60
- const mcpPath = workspace ?? where ?? "<path-to-workspace-checkout>";
61
- out.push("", "Register the Archidocs MCP server with your coding agent, started from the repo root:", "", ` archidocs mcp --workspace ${mcpPath}`, "", ...(workspaceDir === undefined ? ["Point --workspace at a local checkout of the Workspace repo, relative to where the coding agent starts the server."] : []));
87
+ const checkoutNote = workspaceDir === undefined ? ["Point --workspace at a local checkout of the Workspace repo, relative to where the coding agent starts the server."] : [];
88
+ const mcpPath = workspace ?? where;
89
+ if (mcpPath === undefined) {
90
+ out.push("", "Register the Archidocs MCP server with your coding agent, started from the repo root:", "", ` ${runner} mcp --workspace <path-to-workspace-checkout>`, "", ...checkoutNote);
91
+ return out;
92
+ }
93
+ const [command, ...runnerArgs] = runner.split(" ");
94
+ const entry = { type: "stdio", command: command, args: [...runnerArgs, "mcp", "--workspace", mcpPath] };
95
+ const manual = [];
96
+ for (const config of MCP_CONFIGS) {
97
+ const path = join(repoRoot, config.path);
98
+ const result = await registerServer(path, config.key, entry, { create: config.create });
99
+ if (result === "wrote" || result === "updated")
100
+ wrote(path, result === "wrote" ? "Wrote" : "Updated");
101
+ if (result === "unreadable") {
102
+ const snippet = JSON.stringify({ [SERVER_NAME]: entry }, null, 2).split("\n").slice(1, -1);
103
+ manual.push("", `Could not read ${config.path} as JSON; add this to its "${config.key}" by hand:`, "", ...snippet);
104
+ }
105
+ }
106
+ out.push(...manual, "", "Check the server your coding agent will start:", "", ` ${runner} mcp --workspace ${mcpPath} --check`, "", ...checkoutNote);
62
107
  return out;
63
108
  }
109
+ /** The name the server is registered under in every config. */
110
+ const SERVER_NAME = "archidocs";
111
+ /**
112
+ * The project MCP configs init writes the server into, as ADR 0002 decides:
113
+ * the repo-root `.mcp.json` (Claude Code, VS Code, Copilot) always, and
114
+ * Cursor's and VS Code's own files only when the repo already has them.
115
+ */
116
+ const MCP_CONFIGS = [
117
+ { path: ".mcp.json", key: "mcpServers", create: true },
118
+ { path: ".cursor/mcp.json", key: "mcpServers", create: false },
119
+ { path: ".vscode/mcp.json", key: "servers", create: false },
120
+ ];
121
+ /**
122
+ * Adds or replaces the archidocs entry under `key` in an MCP config, keeping
123
+ * every other server and field, and rewrites the file as 2-space JSON. A file
124
+ * that isn't plain JSON (comments, say) is left alone.
125
+ */
126
+ async function registerServer(path, key, entry, { create }) {
127
+ if (!existsSync(path)) {
128
+ if (!create)
129
+ return "skipped";
130
+ await writeFile(path, `${JSON.stringify({ [key]: { [SERVER_NAME]: entry } }, null, 2)}\n`);
131
+ return "wrote";
132
+ }
133
+ let config;
134
+ try {
135
+ config = JSON.parse(await readFile(path, "utf8"));
136
+ }
137
+ catch {
138
+ return "unreadable";
139
+ }
140
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
141
+ if (!isObject(config))
142
+ return "unreadable";
143
+ const servers = config[key] ?? {};
144
+ if (!isObject(servers))
145
+ return "unreadable";
146
+ if (JSON.stringify(servers[SERVER_NAME]) === JSON.stringify(entry))
147
+ return "unchanged";
148
+ config[key] = { ...servers, [SERVER_NAME]: entry };
149
+ await writeFile(path, `${JSON.stringify(config, null, 2)}\n`);
150
+ return "updated";
151
+ }
152
+ const POINTER_HEADING = "## Architecture model";
153
+ /**
154
+ * Writes the pointer into AGENTS.md or CLAUDE.md: replaces init's own
155
+ * section (its heading up to the next `## ` heading) in place, so a re-run
156
+ * follows a change of setup, or appends it when the file has none. A file
157
+ * that names the skill outside that section is left alone. Returns whether
158
+ * the file changed.
159
+ */
160
+ async function writePointer(path, pointer, { create }) {
161
+ const text = existsSync(path) ? await readFile(path, "utf8") : undefined;
162
+ const lines = text?.split("\n") ?? [];
163
+ const start = lines.indexOf(POINTER_HEADING);
164
+ if (text === undefined || start === -1)
165
+ return appendOnce(path, pointer, (t) => t.includes(SKILL_NAME), { create });
166
+ const next = lines.findIndex((line, i) => i > start && line.startsWith("## "));
167
+ const before = lines.slice(0, start).join("\n");
168
+ const after = next === -1 ? "" : "\n" + lines.slice(next).join("\n");
169
+ const updated = (start === 0 ? "" : before + "\n") + pointer + after;
170
+ if (updated === text)
171
+ return false;
172
+ await writeFile(path, updated);
173
+ return true;
174
+ }
64
175
  /**
65
176
  * Appends `block` to the file unless `present` already finds it there,
66
177
  * separating it from what is there by a blank line (one newline for a line