archidocs 1.0.0 → 1.3.0

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 (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +231 -0
  3. package/dist/cli/commands.d.ts +543 -0
  4. package/dist/cli/commands.js +299 -0
  5. package/dist/cli/format.d.ts +2 -2
  6. package/dist/cli/format.js +9 -5
  7. package/dist/cli/init.d.ts +1 -1
  8. package/dist/cli/init.js +2 -2
  9. package/dist/cli/main.js +27 -73
  10. package/dist/core/compare.d.ts +2 -13
  11. package/dist/core/compare.js +2 -35
  12. package/dist/core/index.d.ts +3 -6
  13. package/dist/core/index.js +3 -6
  14. package/dist/core/query.d.ts +1 -1
  15. package/dist/core/rules.d.ts +30 -0
  16. package/dist/core/rules.js +194 -7
  17. package/dist/core/views/compare.d.ts +12 -0
  18. package/dist/core/views/compare.js +37 -0
  19. package/dist/core/{deployment-views.d.ts → views/deployment.d.ts} +4 -5
  20. package/dist/core/{deployment-views.js → views/deployment.js} +5 -7
  21. package/dist/core/{dynamic-views.d.ts → views/dynamic.d.ts} +1 -3
  22. package/dist/core/{dynamic-views.js → views/dynamic.js} +4 -8
  23. package/dist/core/views/generated.d.ts +18 -0
  24. package/dist/core/views/generated.js +92 -0
  25. package/dist/core/views/ids.d.ts +36 -0
  26. package/dist/core/views/ids.js +51 -0
  27. package/dist/core/views/index.d.ts +13 -0
  28. package/dist/core/views/index.js +12 -0
  29. package/dist/core/views/lens.d.ts +27 -0
  30. package/dist/core/views/lens.js +112 -0
  31. package/dist/core/views/model.d.ts +21 -0
  32. package/dist/core/views/model.js +69 -0
  33. package/dist/core/views/resolve.d.ts +42 -0
  34. package/dist/core/views/resolve.js +81 -0
  35. package/dist/core/{save-as-view.d.ts → views/save-as-view.d.ts} +2 -2
  36. package/dist/core/{save-as-view.js → views/save-as-view.js} +13 -10
  37. package/dist/core/{saved-views.d.ts → views/saved.d.ts} +4 -18
  38. package/dist/core/{saved-views.js → views/saved.js} +8 -103
  39. package/dist/core/views/types.d.ts +91 -0
  40. package/dist/core/views/types.js +2 -0
  41. package/dist/mcp/errors.d.ts +37 -0
  42. package/dist/mcp/errors.js +35 -0
  43. package/dist/mcp/index.d.ts +2 -1
  44. package/dist/mcp/index.js +1 -0
  45. package/dist/mcp/server.d.ts +1 -2
  46. package/dist/mcp/server.js +15 -13
  47. package/dist/mcp/writes.js +2 -1
  48. package/dist/render/font.d.ts +14 -8
  49. package/dist/render/font.js +11 -10
  50. package/dist/render/index.d.ts +1 -0
  51. package/dist/render/index.js +1 -0
  52. package/dist/render/layout.d.ts +20 -3
  53. package/dist/render/layout.js +49 -12
  54. package/dist/render/png.d.ts +1 -1
  55. package/dist/render/png.js +5 -5
  56. package/dist/render/sequence-svg.d.ts +8 -3
  57. package/dist/render/sequence-svg.js +32 -32
  58. package/dist/render/sequence.d.ts +1 -1
  59. package/dist/render/sequence.js +1 -1
  60. package/dist/render/svg.d.ts +19 -6
  61. package/dist/render/svg.js +148 -85
  62. package/dist/render/text.d.ts +6 -4
  63. package/dist/render/text.js +11 -9
  64. package/dist/render/tokens.d.ts +53 -0
  65. package/dist/render/tokens.js +71 -0
  66. package/dist/schema/adr.js +18 -13
  67. package/dist/schema/workspace.js +226 -130
  68. package/dist/viewer/assets/index-BXa5R96a.js +138 -0
  69. package/dist/viewer/assets/index-YFA-pYjQ.css +1 -0
  70. package/dist/viewer/assets/{layout.worker-Bg-OaLVN.js → layout.worker-BRHAGJrD.js} +1 -1
  71. package/dist/viewer/assets/{png-D1zzLB1s.js → png-CAaXWR-k.js} +1 -1
  72. package/dist/viewer/assets/svg-BPVHfD36.js +2 -0
  73. package/dist/viewer/index.html +2 -2
  74. package/guide/SKILL.md +1 -1
  75. package/guide/topics/bootstrap.md +1 -1
  76. package/guide/topics/relationships.md +1 -1
  77. package/package.json +20 -4
  78. package/schemas/adr.schema.json +18 -15
  79. package/schemas/model.schema.json +637 -1144
  80. package/schemas/project.schema.json +8 -4
  81. package/schemas/workspace.schema.json +39 -20
  82. package/dist/core/views.d.ts +0 -126
  83. package/dist/core/views.js +0 -217
  84. package/dist/viewer/assets/index-BwUCSYuf.js +0 -113
  85. package/dist/viewer/assets/index-DvKgCpBr.css +0 -1
  86. package/dist/viewer/assets/svg-Cw4FMsm3.js +0 -2
@@ -0,0 +1,299 @@
1
+ /**
2
+ * The CLI's commands and flags, described once. The CLI parses each
3
+ * command's arguments with these flags and prints its usage text from them;
4
+ * the docs site generates its CLI reference from them, examples and exit
5
+ * codes included, and checks every `archidocs …` line in a page with
6
+ * `parseCommandLine`. Importing this module has no side effects and pulls in
7
+ * nothing but `node:util`.
8
+ */
9
+ import { parseArgs } from "node:util";
10
+ /** The CLI's exit codes: 0 no errors, 1 errors found (or any warning with `check --strict`), 2 could not run. */
11
+ export const EXIT = { ok: 0, foundErrors: 1, couldNotRun: 2 };
12
+ /** What a command that needs a Workspace says, exiting 2, when the search for one finds none. */
13
+ export const NO_WORKSPACE = "No workspace.yaml found in this folder, its archidocs/ folder, or any folder above.";
14
+ /** How every command's exit 2 starts: the command line itself was refused. */
15
+ const USAGE_ERROR = "an unknown flag, a flag missing its value";
16
+ export const commands = {
17
+ version: {
18
+ name: "version",
19
+ synopsis: ["version [--format text|json]"],
20
+ description: "Print the CLI's version and the Bundle schemaVersion it writes.",
21
+ arguments: [],
22
+ flags: {
23
+ format: { type: "string", value: "text|json", default: "text", description: "Print a line of text, or a JSON object with `version` and `schemaVersion`." },
24
+ },
25
+ examples: [
26
+ { command: "archidocs version", description: "Print both versions as one line of text." },
27
+ { command: "archidocs version --format json", description: "Print them as JSON, for a CI cache key that changes when the Bundle schemaVersion does." },
28
+ ],
29
+ exitCodes: [
30
+ { code: EXIT.ok, meaning: "The version was printed." },
31
+ { code: EXIT.couldNotRun, meaning: `It could not run: ${USAGE_ERROR}, or an unknown format.` },
32
+ ],
33
+ },
34
+ init: {
35
+ name: "init",
36
+ synopsis: ["init [--skill [--workspace <dir>]]"],
37
+ description: "Set up a Workspace in this repo and install the agent skill, or with `--skill` install only the skill in a code repo. Safe to re-run.",
38
+ arguments: [],
39
+ flags: {
40
+ skill: { type: "boolean", default: false, description: "Install only the agent skill and its pointers, for a code repo that has no Workspace of its own." },
41
+ workspace: { type: "string", value: "<dir>", description: "With `--skill`: the Workspace checkout that the printed MCP command points at." },
42
+ },
43
+ examples: [
44
+ { command: "archidocs init", description: "Write `archidocs/workspace.yaml` if the repo has no Workspace yet, and install the agent skill." },
45
+ {
46
+ command: "archidocs init --skill --workspace ../architecture/archidocs",
47
+ description: "In a code repo, install only the agent skill, and print the MCP command for the Workspace checked out beside it.",
48
+ },
49
+ ],
50
+ exitCodes: [
51
+ { code: EXIT.ok, meaning: "The Workspace and the agent skill are set up, or already were. Each file written or updated is printed." },
52
+ { code: EXIT.couldNotRun, meaning: `It could not run: ${USAGE_ERROR}, \`--workspace\` without \`--skill\`, or a file it could not write.` },
53
+ ],
54
+ },
55
+ guide: {
56
+ name: "guide",
57
+ synopsis: ["guide [topic]"],
58
+ description: "Print the authoring guide for agents, or one of its task topics.",
59
+ arguments: [{ name: "[topic]", description: "A task topic; with none, the guide and the list of topics." }],
60
+ flags: {},
61
+ examples: [
62
+ { command: "archidocs guide", description: "Print the guide: the Model in brief, the edit loop and the list of task topics." },
63
+ { command: "archidocs guide add-service", description: "Print one task topic, here how to add a Service." },
64
+ ],
65
+ exitCodes: [
66
+ { code: EXIT.ok, meaning: "The guide or the topic was printed." },
67
+ { code: EXIT.couldNotRun, meaning: "It could not run: an unknown topic (the message lists the topics there are), more than one topic, or any flag, since it takes none." },
68
+ ],
69
+ },
70
+ check: {
71
+ name: "check",
72
+ synopsis: ["check [--format text|json|github] [--strict]"],
73
+ description: "Validate the Workspace found from the current folder and print each issue with its file, line and rule.",
74
+ arguments: [],
75
+ flags: {
76
+ format: { type: "string", value: "text|json|github", default: "text", description: "Print issues as text, as JSON, or as GitHub Actions annotations." },
77
+ strict: { type: "boolean", default: false, description: "Exit 1 on warnings too, not only on errors." },
78
+ },
79
+ examples: [
80
+ { command: "archidocs check", description: "Validate the Workspace and print its issues grouped by file, then a count and a link to each rule's page." },
81
+ { command: "archidocs check --strict", description: "Fail on warnings as well as errors, for a CI job that keeps the Workspace clean." },
82
+ { command: "archidocs check --format github", description: "Print each issue as a GitHub Actions annotation, which a pull request shows on the line the issue is about." },
83
+ { command: "archidocs check --format json", description: "Print the issues and a count of errors and warnings as JSON, for a script." },
84
+ ],
85
+ exitCodes: [
86
+ { code: EXIT.ok, meaning: "No errors. Warnings are printed and still exit 0, unless `--strict` is given." },
87
+ { code: EXIT.foundErrors, meaning: "The Workspace has at least one error; with `--strict`, at least one error or warning." },
88
+ { code: EXIT.couldNotRun, meaning: `It could not run: ${USAGE_ERROR}, an unknown format, or no Workspace found.` },
89
+ ],
90
+ },
91
+ build: {
92
+ name: "build",
93
+ synopsis: ["build [--out <dir>] [--bundle-only] [--keep <n|all>]", "build --preview [--base <branch>] [--out <dir>]"],
94
+ description: "Write the static viewer site with the Workspace's Bundle and past Revisions, or a PR preview site.",
95
+ arguments: [],
96
+ flags: {
97
+ out: { type: "string", value: "<dir>", default: "dist", description: "The folder to write the site, or the Bundle, into." },
98
+ "bundle-only": { type: "boolean", default: false, description: "Write only `workspace.bundle.json`, without the viewer or past Revisions." },
99
+ keep: { type: "string", value: "<n|all>", defaultText: "200", description: "How many of the latest past Revisions the site keeps Bundles for, or `all`; tagged Revisions are always kept." },
100
+ preview: { type: "boolean", default: false, description: "Build a PR preview site holding just the PR head and the base branch's latest Revision, for Compare." },
101
+ base: { type: "string", value: "<branch>", defaultText: "the branch origin/HEAD points at", description: "With `--preview`: the base branch, read from `origin/<branch>` without fetching." },
102
+ },
103
+ examples: [
104
+ { command: "archidocs build --out site", description: "Write the viewer, the latest Bundle and the past Revisions' Bundles into `site/`, ready for any static host." },
105
+ { command: "archidocs build --out site --keep 50", description: "Keep Bundles for the latest 50 past Revisions only, and for every tagged one." },
106
+ { command: "archidocs build --bundle-only --out public", description: "Write only `public/workspace.bundle.json`, for `mcp --bundle` or a script to read." },
107
+ { command: "archidocs build --preview --base main --out preview", description: "Write a PR preview site that opens on Compare, from `origin/main` to the pull request checked out." },
108
+ ],
109
+ exitCodes: [
110
+ { code: EXIT.ok, meaning: "The site, the Bundle or the preview site was written." },
111
+ { code: EXIT.foundErrors, meaning: "The Workspace has errors. They are printed as `check` prints them, and nothing is written." },
112
+ {
113
+ code: EXIT.couldNotRun,
114
+ meaning: `It could not run: ${USAGE_ERROR}, flags that don't go together, a \`--keep\` that is not a count or \`all\`, no Workspace found, or with \`--preview\` a Workspace outside git or a base branch that is not in the checkout.`,
115
+ },
116
+ ],
117
+ },
118
+ dev: {
119
+ name: "dev",
120
+ synopsis: ["dev [--workspace <dir>] [--port <n>] [--host <host>]"],
121
+ description: "Serve the viewer locally and reload it as you edit the Workspace.",
122
+ arguments: [],
123
+ flags: {
124
+ workspace: { type: "string", value: "<dir>", defaultText: "the Workspace found from the current folder", description: "Where to look for the Workspace." },
125
+ port: { type: "string", value: "<n>", default: "4321", description: "The port to serve on." },
126
+ host: { type: "string", value: "<host>", default: "127.0.0.1", description: "The address to listen on." },
127
+ },
128
+ examples: [
129
+ { command: "archidocs dev", description: "Serve the viewer for the Workspace found from the current folder, and print its address." },
130
+ { command: "archidocs dev --port 4000", description: "Serve on another port, for when the default one is in use." },
131
+ { command: "archidocs dev --workspace ../architecture", description: "Serve the Workspace found from another folder, such as a checkout of the Workspace repo beside a code repo." },
132
+ { command: "archidocs dev --host 0.0.0.0", description: "Listen on every network interface, so that other machines can open the viewer." },
133
+ ],
134
+ exitCodes: [{ code: EXIT.couldNotRun, meaning: `It could not start: ${USAGE_ERROR}, a \`--port\` that is not a port or is in use, or no Workspace found.` }],
135
+ exitNote: "Once it is serving, `dev` runs until you stop it with Ctrl+C. A Workspace with errors does not stop it: it prints them and keeps serving. 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.",
136
+ },
137
+ export: {
138
+ name: "export",
139
+ synopsis: [
140
+ "export <view-id> [--format svg|png] [--out <file>] [--direction TB|BT|LR|RL] [--theme light|dark] [--label <text>]",
141
+ "export --all-saved --out <dir> [--format svg|png] [--direction TB|BT|LR|RL] [--theme light|dark] [--label <text>]",
142
+ ],
143
+ description: "Render a View, or every Saved View, to an SVG or PNG picture.",
144
+ arguments: [{ name: "<view-id>", description: "The View: c1, c2, c2/<system>, c3/<service>, deployment/<environment>, or a Saved View as project:view-id." }],
145
+ flags: {
146
+ format: { type: "string", value: "svg|png", default: "svg", description: "The picture format." },
147
+ out: { type: "string", value: "<file>", defaultText: "<view-id>.<format> in the current folder", description: "The file to write; with `--all-saved`, the folder to write each picture into." },
148
+ direction: { type: "string", value: "TB|BT|LR|RL", defaultText: "a Saved View's own direction, else LR", description: "The layout direction: top to bottom, bottom to top, left to right or right to left. Dynamic Views ignore it." },
149
+ "all-saved": { type: "boolean", default: false, description: "Render every Saved View into the `--out` folder, one picture each." },
150
+ theme: { type: "string", value: "light|dark", default: "light", description: "The palette: the viewer's light tokens, or its Night shift dark ones." },
151
+ label: { type: "string", value: "<text>", defaultText: "the Workspace, short commit and date", description: "The line under the title, such as `Big Bank · v1.2.0`, in place of the source line." },
152
+ },
153
+ examples: [
154
+ { command: "archidocs export c2", description: "Write the C2 Generated View, every System and Service, to `c2.svg` in the current folder." },
155
+ {
156
+ command: "archidocs export c2/digital:internet-banking --direction TB --theme dark",
157
+ description: "Write one System's Services, the System named by its Qualified id, laid out top to bottom in the dark palette.",
158
+ },
159
+ { command: "archidocs export payments:make-a-payment --format png --out make-a-payment.png", description: "Write a Saved View, here a Dynamic View, as a PNG." },
160
+ { command: "archidocs export --all-saved --out views", description: "Write every Saved View into `views/`, one picture each, named by its id." },
161
+ { command: 'archidocs export deployment/prod --label "Big Bank · v1.2.0"', description: "Write an Environment's Deployment View with a line of your own under the title, in place of the commit and date." },
162
+ ],
163
+ exitCodes: [
164
+ { code: EXIT.ok, meaning: "Each picture was written, and its path printed." },
165
+ { code: EXIT.foundErrors, meaning: "The Workspace has errors. They are printed as `check` prints them, and nothing is exported." },
166
+ {
167
+ code: EXIT.couldNotRun,
168
+ meaning: `It could not run: ${USAGE_ERROR}, an unknown format, direction or theme, an unknown View, a View together with \`--all-saved\` or neither of them, \`--all-saved\` without \`--out\`, or no Workspace found.`,
169
+ },
170
+ ],
171
+ },
172
+ diff: {
173
+ name: "diff",
174
+ synopsis: ["diff <from> [<to>] [--format text|json|markdown]"],
175
+ description: "Show what changed in the Model between two points in the Workspace's history.",
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." },
179
+ ],
180
+ flags: {
181
+ format: { type: "string", value: "text|json|markdown", default: "text", description: "Print the changes as text, JSON, or Markdown for a PR comment." },
182
+ },
183
+ examples: [
184
+ { command: "archidocs diff HEAD", description: "Show what your uncommitted edits change, against the last commit." },
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." },
187
+ { command: "archidocs diff origin/main HEAD --format markdown", description: "Write the Changes as Markdown, to post as a pull request comment." },
188
+ ],
189
+ exitCodes: [
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.` },
192
+ ],
193
+ },
194
+ "history build": {
195
+ name: "history build",
196
+ synopsis: ["history build [--since <ref|date>]"],
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
+ arguments: [],
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." },
201
+ },
202
+ examples: [
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." },
204
+ { command: "archidocs history build --since 2026-01-01", description: "Only build the Revisions from the start of that date on." },
205
+ { command: "archidocs history build --since v1.0.0", description: "Only build the Revisions at or after a tag's commit." },
206
+ ],
207
+ exitCodes: [
208
+ { code: EXIT.ok, meaning: "Every Revision asked for is in the cache. It prints how many it built and how many were already built." },
209
+ { code: EXIT.couldNotRun, meaning: `It could not run: ${USAGE_ERROR}, an unknown \`--since\` ref or date, no Workspace found, or a Workspace outside git.` },
210
+ ],
211
+ },
212
+ mcp: {
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>]"],
215
+ description: "Serve the Model to AI agents over MCP, from a Workspace checkout or a published Bundle, on stdio or local HTTP.",
216
+ arguments: [],
217
+ flags: {
218
+ workspace: { type: "string", value: "<dir>", defaultText: "the Workspace found from the current folder", description: "Serve this Workspace checkout; its write tools edit the YAML in place." },
219
+ bundle: { type: "string", value: "<url|path>", description: "Serve a published Bundle, read-only, instead of a checkout." },
220
+ "viewer-url": { type: "string", value: "<url>", description: "The published viewer's base URL; tool results then link to it." },
221
+ http: { type: "boolean", default: false, description: "Serve Streamable HTTP at `/mcp` instead of stdio." },
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
+ port: { type: "string", value: "<n>", defaultText: "3737", description: "With `--http`: the port to serve on." },
224
+ "allow-writes": { type: "boolean", default: false, description: "With `--http`: allow the write tools, which are off over HTTP by default." },
225
+ },
226
+ examples: [
227
+ {
228
+ command: "archidocs mcp --workspace archidocs",
229
+ 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
+ { 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
+ {
233
+ command: "archidocs mcp --bundle https://architecture.example.com/workspace.bundle.json --viewer-url https://architecture.example.com/",
234
+ description: "Serve your own published Bundle, with links to its viewer in the tool results.",
235
+ },
236
+ { command: "archidocs mcp --http --port 3737 --workspace archidocs", description: "Serve Streamable HTTP at `/mcp` on a loopback address, with the write tools off." },
237
+ { command: "archidocs mcp --http --allow-writes --workspace archidocs", description: "Serve over HTTP with the write tools on." },
238
+ ],
239
+ exitCodes: [
240
+ { code: EXIT.ok, meaning: "Over stdio, the client closed the connection." },
241
+ {
242
+ 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.`,
244
+ },
245
+ ],
246
+ 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.",
247
+ },
248
+ };
249
+ /** Every command, in the order the usage lists them. */
250
+ export const commandList = Object.values(commands);
251
+ /** The usage text the CLI prints after a usage error. */
252
+ export function usageText() {
253
+ const lines = commandList.flatMap((c) => c.synopsis.map((s) => ` archidocs ${s}`));
254
+ return `Usage:\n${lines.join("\n")}\n`;
255
+ }
256
+ /**
257
+ * Parses a command's arguments (the words after its name) with its flags,
258
+ * strictly: an unknown flag or a missing value throws `ERR_PARSE_ARGS_*`.
259
+ */
260
+ export function parseCommand(name, args) {
261
+ const command = commands[name];
262
+ return parseArgs({ args, options: command.flags, allowPositionals: command.arguments.length > 0, strict: true });
263
+ }
264
+ /** The command a command line names, and the arguments after its name. */
265
+ export function findCommand(argv) {
266
+ // The longest name wins, so `history build` is found before any `history`.
267
+ const byLength = [...commandList].sort((a, b) => b.name.split(" ").length - a.name.split(" ").length);
268
+ for (const command of byLength) {
269
+ const words = command.name.split(" ");
270
+ if (words.every((w, i) => argv[i] === w))
271
+ return { command, args: argv.slice(words.length) };
272
+ }
273
+ return undefined;
274
+ }
275
+ /**
276
+ * Checks a command line (the words after `archidocs`) against the
277
+ * definitions without running anything: an unknown command, an unknown
278
+ * flag, a flag missing its value or a stray argument is reported. What
279
+ * a value means, and which flags go together, are left to the command.
280
+ */
281
+ export function parseCommandLine(argv) {
282
+ const found = findCommand(argv);
283
+ if (!found) {
284
+ const [first, second] = argv;
285
+ if (first === undefined)
286
+ return { ok: false, message: "No command given." };
287
+ const sub = commandList.find((c) => c.name.startsWith(`${first} `));
288
+ if (sub)
289
+ return { ok: false, message: second === undefined ? `Give a ${first} command.` : `Unknown ${first} command "${second}".` };
290
+ return { ok: false, message: `Unknown command "${first}".` };
291
+ }
292
+ try {
293
+ parseArgs({ args: found.args, options: found.command.flags, allowPositionals: found.command.arguments.length > 0, strict: true });
294
+ return { ok: true, command: found.command.name };
295
+ }
296
+ catch (e) {
297
+ return { ok: false, message: e instanceof Error ? e.message : String(e) };
298
+ }
299
+ }
@@ -1,4 +1,4 @@
1
- import type { Issue } from "../core/index.ts";
1
+ import { type Issue } from "../core/index.ts";
2
2
  export declare const formats: readonly ["text", "json", "github"];
3
3
  export type Format = (typeof formats)[number];
4
4
  export interface FormatOptions {
@@ -11,5 +11,5 @@ export declare function formatIssues(issues: Issue[], format: Format, options?:
11
11
  export declare function exitCodeFor(issues: Issue[], { strict }?: {
12
12
  strict?: boolean;
13
13
  }): 0 | 1;
14
- /** `--format text`: issues grouped by file, one per line, then a summary count. */
14
+ /** `--format text`: issues grouped by file, one per line, then a summary count and each distinct rule's docs link. */
15
15
  export declare function formatText(issues: Issue[], { color }?: FormatOptions): string;
@@ -1,3 +1,4 @@
1
+ import { ruleDocsUrl, withDocs } from "../core/index.js";
1
2
  export const formats = ["text", "json", "github"];
2
3
  /** Writes issues in the chosen `--format`. */
3
4
  export function formatIssues(issues, format, options = {}) {
@@ -18,7 +19,7 @@ function summarize(issues) {
18
19
  }
19
20
  const ansi = (code) => (s) => `\x1b[${code}m${s}\x1b[0m`;
20
21
  const plain = (s) => s;
21
- /** `--format text`: issues grouped by file, one per line, then a summary count. */
22
+ /** `--format text`: issues grouped by file, one per line, then a summary count and each distinct rule's docs link. */
22
23
  export function formatText(issues, { color = false } = {}) {
23
24
  const red = color ? ansi(31) : plain;
24
25
  const yellow = color ? ansi(33) : plain;
@@ -37,16 +38,19 @@ export function formatText(issues, { color = false } = {}) {
37
38
  if (lines.length > 0)
38
39
  lines.push("");
39
40
  lines.push(`${plural(errors, "error")}, ${plural(warnings, "warning")}`);
41
+ const ruleIds = [...new Set(issues.map((i) => i.rule))];
42
+ if (ruleIds.length > 0)
43
+ lines.push("", "Rule docs:", ...ruleIds.map((id) => ` ${dim(id)} ${ruleDocsUrl(id)}`));
40
44
  return lines.join("\n") + "\n";
41
45
  }
42
- /** `--format json`: the issue records, as MCP returns them, and a summary. */
46
+ /** `--format json`: the issue records with their rule's `docs` link, as MCP returns them, and a summary. */
43
47
  function formatJson(issues) {
44
- return JSON.stringify({ issues, summary: summarize(issues) }, null, 2) + "\n";
48
+ return JSON.stringify({ issues: issues.map(withDocs), summary: summarize(issues) }, null, 2) + "\n";
45
49
  }
46
50
  // GitHub workflow command escaping: https://github.com/actions/toolkit/blob/main/packages/core/src/command.ts
47
51
  const escapeData = (s) => s.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
48
52
  const escapeProperty = (s) => escapeData(s).replace(/:/g, "%3A").replace(/,/g, "%2C");
49
- /** `--format github`: one `::error`/`::warning` workflow command per issue, for inline PR annotations. */
53
+ /** `--format github`: one `::error`/`::warning` workflow command per issue, for inline PR annotations, ending with its rule's docs link. */
50
54
  function formatGithub(issues) {
51
55
  return issues
52
56
  .map((i) => {
@@ -54,7 +58,7 @@ function formatGithub(issues) {
54
58
  if (i.column !== undefined)
55
59
  props.push(`col=${i.column}`);
56
60
  props.push(`title=${escapeProperty(i.rule)}`);
57
- return `::${i.severity} ${props.join(",")}::${escapeData(i.message)}\n`;
61
+ return `::${i.severity} ${props.join(",")}::${escapeData(`${i.message} See ${ruleDocsUrl(i.rule)}`)}\n`;
58
62
  })
59
63
  .join("");
60
64
  }
@@ -1,4 +1,4 @@
1
- /** Where harnesses look for skills; the stub goes into each. */
1
+ /** Where coding agents look for skills; the stub goes into each. */
2
2
  export declare const SKILL_DIRS: readonly [".agents/skills", ".claude/skills", ".github/skills"];
3
3
  export interface InitOptions {
4
4
  /** The repo being set up: its git top level, or the current folder outside git. */
package/dist/cli/init.js CHANGED
@@ -3,7 +3,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
3
  import { dirname, join, relative, sep } from "node:path";
4
4
  import { findWorkspaceRoot, nodeFileSystem } from "../core/index.js";
5
5
  import { SKILL_NAME, skillStub } from "../guide/index.js";
6
- /** Where harnesses look for skills; the stub goes into each. */
6
+ /** Where coding agents look for skills; the stub goes into each. */
7
7
  export const SKILL_DIRS = [".agents/skills", ".claude/skills", ".github/skills"];
8
8
  const STARTER_WORKSPACE = `# The Archidocs Workspace root: Teams and Environments are defined here only.
9
9
  # Each Project is a folder below this one holding a project.yaml.
@@ -58,7 +58,7 @@ export async function init({ repoRoot, cwd, skillOnly, workspace }) {
58
58
  if (await appendOnce(join(repoRoot, "CLAUDE.md"), pointer, hasPointer, { create: false }))
59
59
  wrote(join(repoRoot, "CLAUDE.md"), "Updated");
60
60
  const mcpPath = workspace ?? where ?? "<path-to-workspace-checkout>";
61
- out.push("", "Register the Archidocs MCP server with your agent harness, 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 harness starts the server."] : []));
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."] : []));
62
62
  return out;
63
63
  }
64
64
  /**
package/dist/cli/main.js CHANGED
@@ -3,14 +3,14 @@ import { existsSync } from "node:fs";
3
3
  import { cp, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
4
4
  import { basename, join, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
- import { parseArgs } from "node:util";
7
- import { findWorkspaceRoot, load, nodeFileSystem, resolveDynamicView, resolveView, serializeBundle } from "../core/index.js";
8
- import { directions, layoutView, renderSequenceSvg, renderSvg } from "../render/index.js";
6
+ import { findWorkspaceRoot, load, nodeFileSystem, resolveView, serializeBundle } from "../core/index.js";
7
+ import { directions, layoutView, renderSequenceSvg, renderSvg, themes } from "../render/index.js";
9
8
  import { renderPngInNode } from "../render/node.js";
10
9
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
11
10
  import { gitHead, gitTopLevel } from "../git.js";
12
11
  import { bundleSource, checkoutSource, createServer, DEFAULT_PORT, serveHttp } from "../mcp/index.js";
13
12
  import { authoringGuide } from "../guide/index.js";
13
+ import { EXIT, NO_WORKSPACE, parseCommand, usageText } from "./commands.js";
14
14
  import { init } from "./init.js";
15
15
  import { DEFAULT_DEV_PORT, serveDev } from "./dev.js";
16
16
  import { exitCodeFor, formatIssues, formats, formatText } from "./format.js";
@@ -18,10 +18,8 @@ import { diff } from "../core/index.js";
18
18
  import { bundleAt, buildHistory, DEFAULT_KEEP, defaultBaseBranch, history, previewSides, publishHistory, publishPreview, resolvePoint } from "../history/index.js";
19
19
  import { SCHEMA_VERSION } from "../schema/bundle.js";
20
20
  import { diffFormats, formatDiff } from "./diff-format.js";
21
- /** Exit codes: 0 no errors, 1 errors found (or any warning with `--strict`), 2 could not run. */
22
- const OK = 0;
23
- const FOUND_ERRORS = 1;
24
- const COULD_NOT_RUN = 2;
21
+ /** Exit codes, shared with the command definitions that document them: 0 no errors, 1 errors found (or any warning with `--strict`), 2 could not run. */
22
+ const { ok: OK, foundErrors: FOUND_ERRORS, couldNotRun: COULD_NOT_RUN } = EXIT;
25
23
  class UsageError extends Error {
26
24
  }
27
25
  /**
@@ -32,25 +30,11 @@ class UsageError extends Error {
32
30
  const VIEWER_DIR = fileURLToPath(new URL("../../dist/viewer/", import.meta.url));
33
31
  /** The package's own package.json, two levels up from dist/cli/ or src/cli/ like the viewer. */
34
32
  const PACKAGE_JSON = fileURLToPath(new URL("../../package.json", import.meta.url));
35
- const usage = `Usage:
36
- archidocs version [--format text|json]
37
- archidocs init [--skill [--workspace <dir>]]
38
- archidocs guide [topic]
39
- archidocs check [--format text|json|github] [--strict]
40
- archidocs build [--out <dir>] [--bundle-only] [--keep <n|all>]
41
- archidocs build --preview [--base <branch>] [--out <dir>]
42
- archidocs dev [--workspace <dir>] [--port <n>] [--host <host>]
43
- archidocs export <view-id> [--format svg|png] [--out <file>] [--direction TB|BT|LR|RL]
44
- archidocs export --all-saved --out <dir> [--format svg|png] [--direction TB|BT|LR|RL]
45
- archidocs diff <from> [<to>] [--format text|json|markdown]
46
- archidocs history build [--since <ref|date>]
47
- archidocs mcp [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>]
48
- [--http [--host <loopback>] [--port <n>] [--allow-writes]]
49
- `;
33
+ const usage = usageText();
50
34
  async function main(argv) {
51
35
  const [command, ...rest] = argv;
52
36
  if (command === "init") {
53
- const { values } = parseArgs({ args: rest, options: { skill: { type: "boolean", default: false }, workspace: { type: "string" } }, strict: true });
37
+ const { values } = parseCommand("init", rest);
54
38
  if (values.workspace !== undefined && !values.skill)
55
39
  throw new UsageError("--workspace only applies with --skill; without it, init uses or creates this repo's Workspace.");
56
40
  const cwd = await realpath(process.cwd());
@@ -60,7 +44,7 @@ async function main(argv) {
60
44
  return OK;
61
45
  }
62
46
  if (command === "version") {
63
- const { values } = parseArgs({ args: rest, options: { format: { type: "string", default: "text" } }, strict: true });
47
+ const { values } = parseCommand("version", rest);
64
48
  if (values.format !== "text" && values.format !== "json")
65
49
  throw new UsageError(`Unknown format "${values.format}"; use text or json.`);
66
50
  const { version } = JSON.parse(await readFile(PACKAGE_JSON, "utf8"));
@@ -68,7 +52,7 @@ async function main(argv) {
68
52
  return OK;
69
53
  }
70
54
  if (command === "guide") {
71
- const { positionals } = parseArgs({ args: rest, options: {}, allowPositionals: true, strict: true });
55
+ const { positionals } = parseCommand("guide", rest);
72
56
  if (positionals.length > 1)
73
57
  throw new UsageError(`Give one topic at a time; got ${positionals.join(", ")}.`);
74
58
  const guide = await authoringGuide(positionals[0]);
@@ -78,11 +62,7 @@ async function main(argv) {
78
62
  return OK;
79
63
  }
80
64
  if (command === "check") {
81
- const { values } = parseArgs({
82
- args: rest,
83
- options: { format: { type: "string", default: "text" }, strict: { type: "boolean", default: false } },
84
- strict: true,
85
- });
65
+ const { values } = parseCommand("check", rest);
86
66
  const format = values.format;
87
67
  if (!formats.includes(format))
88
68
  throw new UsageError(`Unknown format "${values.format}"; use ${formats.join(", ")}.`);
@@ -91,17 +71,7 @@ async function main(argv) {
91
71
  return exitCodeFor(issues, { strict: values.strict });
92
72
  }
93
73
  if (command === "build") {
94
- const { values } = parseArgs({
95
- args: rest,
96
- options: {
97
- "bundle-only": { type: "boolean" },
98
- out: { type: "string", default: "dist" },
99
- keep: { type: "string" },
100
- preview: { type: "boolean", default: false },
101
- base: { type: "string" },
102
- },
103
- strict: true,
104
- });
74
+ const { values } = parseCommand("build", rest);
105
75
  if (values.preview && values.keep !== undefined)
106
76
  throw new UsageError("--keep doesn't apply to --preview, whose site holds just the base and the PR head.");
107
77
  if (values.preview && values["bundle-only"])
@@ -147,7 +117,7 @@ async function main(argv) {
147
117
  return OK;
148
118
  }
149
119
  if (command === "dev") {
150
- const { values } = parseArgs({ args: rest, options: { port: { type: "string" }, host: { type: "string" }, workspace: { type: "string" } }, strict: true });
120
+ const { values } = parseCommand("dev", rest);
151
121
  const port = values.port === undefined ? DEFAULT_DEV_PORT : Number(values.port);
152
122
  if (!Number.isInteger(port) || port < 0 || port > 65535)
153
123
  throw new UsageError(`--port "${values.port}" is not a port.`);
@@ -179,12 +149,7 @@ async function main(argv) {
179
149
  return OK;
180
150
  }
181
151
  if (command === "export") {
182
- const { values, positionals } = parseArgs({
183
- args: rest,
184
- options: { format: { type: "string", default: "svg" }, out: { type: "string" }, direction: { type: "string" }, "all-saved": { type: "boolean", default: false } },
185
- allowPositionals: true,
186
- strict: true,
187
- });
152
+ const { values, positionals } = parseCommand("export", rest);
188
153
  const allSaved = values["all-saved"];
189
154
  const [viewId, ...extra] = positionals;
190
155
  if (allSaved && viewId !== undefined)
@@ -201,6 +166,10 @@ async function main(argv) {
201
166
  const direction = values.direction;
202
167
  if (direction !== undefined && !directions.includes(direction))
203
168
  throw new UsageError(`Unknown direction "${direction}"; use ${directions.join(", ")}.`);
169
+ const theme = values.theme;
170
+ if (!themes.includes(theme))
171
+ throw new UsageError(`Unknown theme "${values.theme}"; use ${themes.join(" or ")}.`);
172
+ const { label } = values;
204
173
  const root = await workspaceRoot(process.cwd());
205
174
  const { bundle, issues } = await loadFromCwd();
206
175
  if (issues.some((i) => i.severity === "error")) {
@@ -210,38 +179,35 @@ async function main(argv) {
210
179
  }
211
180
  const workspace = await workspaceName(root);
212
181
  const fileName = (id) => `${id.replace(/[/:]/g, "-")}.${format}`;
213
- /** Lays out and draws one View; `--direction` wins over a Saved View's own. */
214
182
  const source = { workspace, commit: bundle.commit, date: bundle.builtAt };
215
183
  const write = async (svg, out) => {
216
184
  await writeFile(resolve(out), format === "svg" ? svg : await renderPngInNode(svg));
217
185
  process.stdout.write(`Wrote ${out}\n`);
218
186
  };
219
- /** Lays out and draws one View: a Dynamic View as a sequence chart, any other as a diagram. */
187
+ /** Lays out and draws one View: a Dynamic View as a sequence chart, any other as a diagram; `--direction` wins over the View's own. */
220
188
  const draw = async (view, out) => {
221
189
  if (view.kind === "dynamic")
222
- return write(renderSequenceSvg({ bundle, view, source }), out);
223
- const chosen = direction ?? view.direction;
224
- const layout = await layoutView(view, chosen === undefined ? {} : { direction: chosen });
225
- await write(renderSvg({ bundle, view, layout, source }), out);
190
+ return write(renderSequenceSvg({ bundle, view, source, theme, label }), out);
191
+ const layout = await layoutView(view, direction === undefined ? {} : { direction });
192
+ await write(renderSvg({ bundle, view, layout, source, theme, label }), out);
226
193
  };
227
- const resolveAny = (id) => resolveDynamicView(bundle, id) ?? resolveView(bundle, id);
228
194
  if (allSaved) {
229
195
  await mkdir(resolve(values.out), { recursive: true });
230
196
  for (const saved of bundle.views) {
231
- const view = resolveAny(saved.id);
197
+ const view = resolveView(bundle, saved.id);
232
198
  if (view)
233
199
  await draw(view, join(values.out, fileName(saved.id)));
234
200
  }
235
201
  return OK;
236
202
  }
237
- const view = resolveAny(viewId);
203
+ const view = resolveView(bundle, viewId);
238
204
  if (!view)
239
205
  throw new UsageError(`Unknown View "${viewId}"; Views are c1, c2, c2/<system>, c3/<service with Components>, deployment/<environment> and Saved Views (project:view-id).`);
240
206
  await draw(view, values.out ?? fileName(viewId));
241
207
  return OK;
242
208
  }
243
209
  if (command === "diff") {
244
- const { values, positionals } = parseArgs({ args: rest, options: { format: { type: "string", default: "text" } }, allowPositionals: true, strict: true });
210
+ const { values, positionals } = parseCommand("diff", rest);
245
211
  const format = values.format;
246
212
  if (!diffFormats.includes(format))
247
213
  throw new UsageError(`Unknown format "${values.format}"; use ${diffFormats.join(", ")}.`);
@@ -269,7 +235,7 @@ async function main(argv) {
269
235
  const [sub, ...args] = rest;
270
236
  if (sub !== "build")
271
237
  throw new UsageError(sub ? `Unknown history command "${sub}".` : "Give a history command: build.");
272
- const { values } = parseArgs({ args, options: { since: { type: "string" } }, strict: true });
238
+ const { values } = parseCommand("history build", args);
273
239
  const h = await historyFromCwd();
274
240
  const { revisions, built } = await buildHistory(h, values.since === undefined ? {} : { since: values.since });
275
241
  const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
@@ -277,19 +243,7 @@ async function main(argv) {
277
243
  return OK;
278
244
  }
279
245
  if (command === "mcp") {
280
- const { values } = parseArgs({
281
- args: rest,
282
- options: {
283
- workspace: { type: "string" },
284
- bundle: { type: "string" },
285
- "viewer-url": { type: "string" },
286
- http: { type: "boolean", default: false },
287
- host: { type: "string" },
288
- port: { type: "string" },
289
- "allow-writes": { type: "boolean", default: false },
290
- },
291
- strict: true,
292
- });
246
+ const { values } = parseCommand("mcp", rest);
293
247
  const viewerUrl = values["viewer-url"];
294
248
  if (viewerUrl !== undefined && !URL.canParse(viewerUrl))
295
249
  throw new UsageError(`--viewer-url "${viewerUrl}" is not a URL.`);
@@ -333,7 +287,7 @@ async function workspaceName(root) {
333
287
  async function workspaceRoot(start) {
334
288
  const root = await findWorkspaceRoot(nodeFileSystem(), start);
335
289
  if (!root)
336
- throw new UsageError("No workspace.yaml found in this folder, its archidocs/ folder, or any folder above.");
290
+ throw new UsageError(NO_WORKSPACE);
337
291
  return root;
338
292
  }
339
293
  /** The history of the Workspace found from the current folder; it must be in a git repo. */
@@ -1,7 +1,6 @@
1
1
  import type { Bundle } from "../schema/bundle.ts";
2
- import { type ResolveOptions, type ResolvedView } from "./views.ts";
3
- /** How Compare marks a node or edge of a View between two Bundles. */
4
- export type CompareMark = "added" | "removed" | "changed" | "unchanged";
2
+ /** An item as text, leaving out where it was written. */
3
+ export declare const withoutSource: (item: object) => string;
5
4
  /**
6
5
  * One Bundle holding everything either side holds, the later side's version
7
6
  * where both do, so a View drawn from it keeps removed things in place.
@@ -9,13 +8,3 @@ export type CompareMark = "added" | "removed" | "changed" | "unchanged";
9
8
  * at both sides; each lands on the same edge.
10
9
  */
11
10
  export declare function unionBundle(before: Bundle, after: Bundle): Bundle;
12
- /**
13
- * A View for Compare: laid out over the union of both sides, with every node
14
- * and edge marked. A node or edge only the later side's View shows is
15
- * added, one only the earlier side's shows is removed. One both show is
16
- * changed when its Element changed, or for a collapsed box when anything
17
- * inside it was added, removed or changed; an edge when its Relationships
18
- * did. A View that exists at one side only is drawn from that side.
19
- * Undefined when neither side has the View.
20
- */
21
- export declare function compareView(before: Bundle, after: Bundle, id: string, options?: Pick<ResolveOptions, "expand">): ResolvedView | undefined;