archidocs 0.0.0-stage → 1.2.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.
- package/LICENSE +21 -0
- package/README.md +181 -2
- package/dist/cli/commands.d.ts +322 -0
- package/dist/cli/commands.js +174 -0
- package/dist/cli/dev.d.ts +31 -0
- package/dist/cli/dev.js +156 -0
- package/dist/cli/diff-format.d.ts +9 -0
- package/dist/cli/diff-format.js +50 -0
- package/dist/cli/format.d.ts +15 -0
- package/dist/cli/format.js +64 -0
- package/dist/cli/init.d.ts +17 -0
- package/dist/cli/init.js +82 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +330 -0
- package/dist/core/adr.d.ts +28 -0
- package/dist/core/adr.js +88 -0
- package/dist/core/adrs.d.ts +20 -0
- package/dist/core/adrs.js +86 -0
- package/dist/core/catalogue.d.ts +7 -0
- package/dist/core/catalogue.js +35 -0
- package/dist/core/compare.d.ts +21 -0
- package/dist/core/compare.js +62 -0
- package/dist/core/deployment-views.d.ts +28 -0
- package/dist/core/deployment-views.js +108 -0
- package/dist/core/deployments.d.ts +18 -0
- package/dist/core/deployments.js +21 -0
- package/dist/core/diff.d.ts +44 -0
- package/dist/core/diff.js +138 -0
- package/dist/core/dynamic-views.d.ts +73 -0
- package/dist/core/dynamic-views.js +162 -0
- package/dist/core/files.d.ts +2 -0
- package/dist/core/files.js +1 -0
- package/dist/core/fs.d.ts +19 -0
- package/dist/core/fs.js +21 -0
- package/dist/core/history-scope.d.ts +40 -0
- package/dist/core/history-scope.js +63 -0
- package/dist/core/impact.d.ts +34 -0
- package/dist/core/impact.js +62 -0
- package/dist/core/index.d.ts +20 -0
- package/dist/core/index.js +18 -0
- package/dist/core/load.d.ts +32 -0
- package/dist/core/load.js +465 -0
- package/dist/core/model.d.ts +150 -0
- package/dist/core/model.js +1 -0
- package/dist/core/ownership.d.ts +34 -0
- package/dist/core/ownership.js +65 -0
- package/dist/core/paths.d.ts +47 -0
- package/dist/core/paths.js +115 -0
- package/dist/core/query.d.ts +51 -0
- package/dist/core/query.js +77 -0
- package/dist/core/refs.d.ts +31 -0
- package/dist/core/refs.js +50 -0
- package/dist/core/rules.d.ts +41 -0
- package/dist/core/rules.js +1033 -0
- package/dist/core/save-as-view.d.ts +45 -0
- package/dist/core/save-as-view.js +114 -0
- package/dist/core/saved-views.d.ts +48 -0
- package/dist/core/saved-views.js +243 -0
- package/dist/core/schema-check.d.ts +13 -0
- package/dist/core/schema-check.js +79 -0
- package/dist/core/search.d.ts +27 -0
- package/dist/core/search.js +63 -0
- package/dist/core/suggest.d.ts +3 -0
- package/dist/core/suggest.js +30 -0
- package/dist/core/views.d.ts +126 -0
- package/dist/core/views.js +217 -0
- package/dist/core/yaml.d.ts +16 -0
- package/dist/core/yaml.js +52 -0
- package/dist/git.d.ts +7 -0
- package/dist/git.js +23 -0
- package/dist/guide/index.d.ts +53 -0
- package/dist/guide/index.js +57 -0
- package/dist/history/git.d.ts +39 -0
- package/dist/history/git.js +126 -0
- package/dist/history/index.d.ts +118 -0
- package/dist/history/index.js +223 -0
- package/dist/history/migrate.d.ts +16 -0
- package/dist/history/migrate.js +30 -0
- package/dist/mcp/history.d.ts +36 -0
- package/dist/mcp/history.js +175 -0
- package/dist/mcp/http.d.ts +23 -0
- package/dist/mcp/http.js +85 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/server.d.ts +54 -0
- package/dist/mcp/server.js +824 -0
- package/dist/mcp/source.d.ts +50 -0
- package/dist/mcp/source.js +132 -0
- package/dist/mcp/writes.d.ts +10 -0
- package/dist/mcp/writes.js +267 -0
- package/dist/render/font.d.ts +14 -0
- package/dist/render/font.js +11 -0
- package/dist/render/index.d.ts +8 -0
- package/dist/render/index.js +8 -0
- package/dist/render/layout.d.ts +53 -0
- package/dist/render/layout.js +199 -0
- package/dist/render/node.d.ts +3 -0
- package/dist/render/node.js +8 -0
- package/dist/render/png.d.ts +11 -0
- package/dist/render/png.js +29 -0
- package/dist/render/sequence-svg.d.ts +33 -0
- package/dist/render/sequence-svg.js +98 -0
- package/dist/render/sequence.d.ts +103 -0
- package/dist/render/sequence.js +142 -0
- package/dist/render/svg.d.ts +36 -0
- package/dist/render/svg.js +222 -0
- package/dist/render/teams.d.ts +12 -0
- package/dist/render/teams.js +31 -0
- package/dist/render/text.d.ts +15 -0
- package/dist/render/text.js +29 -0
- package/dist/render/tokens.d.ts +53 -0
- package/dist/render/tokens.js +71 -0
- package/dist/schema/adr.d.ts +36 -0
- package/dist/schema/adr.js +27 -0
- package/dist/schema/bundle.d.ts +726 -0
- package/dist/schema/bundle.js +171 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.js +4 -0
- package/dist/schema/json-schema.d.ts +8 -0
- package/dist/schema/json-schema.js +19 -0
- package/dist/schema/workspace.d.ts +1066 -0
- package/dist/schema/workspace.js +271 -0
- package/dist/viewer/assets/index-DvKgCpBr.css +1 -0
- package/dist/viewer/assets/index-gucix3xm.js +113 -0
- package/dist/viewer/assets/index_bg-Blvrv-U2.wasm +0 -0
- package/dist/viewer/assets/index_bg-D3t31u3-.js +1 -0
- package/dist/viewer/assets/layout.worker-Bg-OaLVN.js +26 -0
- package/dist/viewer/assets/overpass-latin-QyaMbcmi.woff2 +0 -0
- package/dist/viewer/assets/overpass-latin-ext-DSRhPfzW.woff2 +0 -0
- package/dist/viewer/assets/overpass-mono-latin-BTquVRaO.woff2 +0 -0
- package/dist/viewer/assets/overpass-mono-latin-ext-D47EiU4_.woff2 +0 -0
- package/dist/viewer/assets/png-BDKIXtm5.js +1 -0
- package/dist/viewer/assets/svg-Bulv5YWn.js +2 -0
- package/dist/viewer/favicon.svg +1 -0
- package/dist/viewer/index.html +53 -0
- package/dist/writer/adrs.d.ts +21 -0
- package/dist/writer/adrs.js +72 -0
- package/dist/writer/deployments.d.ts +51 -0
- package/dist/writer/deployments.js +145 -0
- package/dist/writer/diff.d.ts +6 -0
- package/dist/writer/diff.js +77 -0
- package/dist/writer/document.d.ts +25 -0
- package/dist/writer/document.js +79 -0
- package/dist/writer/edit.d.ts +78 -0
- package/dist/writer/edit.js +63 -0
- package/dist/writer/index.d.ts +67 -0
- package/dist/writer/index.js +310 -0
- package/dist/writer/overlay.d.ts +7 -0
- package/dist/writer/overlay.js +26 -0
- package/dist/writer/views.d.ts +29 -0
- package/dist/writer/views.js +78 -0
- package/dist/writer/workspace.d.ts +25 -0
- package/dist/writer/workspace.js +56 -0
- package/guide/SKILL.md +36 -0
- package/guide/topics/add-service.md +30 -0
- package/guide/topics/bootstrap.md +28 -0
- package/guide/topics/change.md +32 -0
- package/guide/topics/deployments.md +36 -0
- package/guide/topics/dynamic-view.md +39 -0
- package/guide/topics/propose-adr.md +12 -0
- package/guide/topics/relationships.md +39 -0
- package/guide/topics/saved-view.md +36 -0
- package/package.json +75 -4
- package/schemas/adr.schema.json +82 -0
- package/schemas/model.schema.json +1381 -0
- package/schemas/project.schema.json +24 -0
- package/schemas/workspace.schema.json +72 -0
|
@@ -0,0 +1,174 @@
|
|
|
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 and checks every
|
|
5
|
+
* `archidocs …` line in a page with `parseCommandLine`. Importing this
|
|
6
|
+
* module has no side effects and pulls in nothing but `node:util`.
|
|
7
|
+
*/
|
|
8
|
+
import { parseArgs } from "node:util";
|
|
9
|
+
export const commands = {
|
|
10
|
+
version: {
|
|
11
|
+
name: "version",
|
|
12
|
+
synopsis: ["version [--format text|json]"],
|
|
13
|
+
description: "Print the CLI's version and the Bundle schemaVersion it writes.",
|
|
14
|
+
arguments: [],
|
|
15
|
+
flags: {
|
|
16
|
+
format: { type: "string", value: "text|json", default: "text", description: "Print a line of text, or a JSON object with `version` and `schemaVersion`." },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
init: {
|
|
20
|
+
name: "init",
|
|
21
|
+
synopsis: ["init [--skill [--workspace <dir>]]"],
|
|
22
|
+
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.",
|
|
23
|
+
arguments: [],
|
|
24
|
+
flags: {
|
|
25
|
+
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." },
|
|
26
|
+
workspace: { type: "string", value: "<dir>", description: "With `--skill`: the Workspace checkout that the printed MCP command points at." },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
guide: {
|
|
30
|
+
name: "guide",
|
|
31
|
+
synopsis: ["guide [topic]"],
|
|
32
|
+
description: "Print the authoring guide for agents, or one of its task topics.",
|
|
33
|
+
arguments: [{ name: "[topic]", description: "A task topic; with none, the guide and the list of topics." }],
|
|
34
|
+
flags: {},
|
|
35
|
+
},
|
|
36
|
+
check: {
|
|
37
|
+
name: "check",
|
|
38
|
+
synopsis: ["check [--format text|json|github] [--strict]"],
|
|
39
|
+
description: "Validate the Workspace found from the current folder. Exits 1 on errors, 2 if it could not run.",
|
|
40
|
+
arguments: [],
|
|
41
|
+
flags: {
|
|
42
|
+
format: { type: "string", value: "text|json|github", default: "text", description: "Print issues as text, as JSON, or as GitHub Actions annotations." },
|
|
43
|
+
strict: { type: "boolean", default: false, description: "Exit 1 on warnings too, not only on errors." },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
build: {
|
|
47
|
+
name: "build",
|
|
48
|
+
synopsis: ["build [--out <dir>] [--bundle-only] [--keep <n|all>]", "build --preview [--base <branch>] [--out <dir>]"],
|
|
49
|
+
description: "Write the static viewer site with the Workspace's Bundle and past Revisions, or a PR preview site.",
|
|
50
|
+
arguments: [],
|
|
51
|
+
flags: {
|
|
52
|
+
out: { type: "string", value: "<dir>", default: "dist", description: "The folder to write the site, or the Bundle, into." },
|
|
53
|
+
"bundle-only": { type: "boolean", default: false, description: "Write only `workspace.bundle.json`, without the viewer or past Revisions." },
|
|
54
|
+
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." },
|
|
55
|
+
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." },
|
|
56
|
+
base: { type: "string", value: "<branch>", defaultText: "the branch origin/HEAD points at", description: "With `--preview`: the base branch, read from `origin/<branch>` without fetching." },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
dev: {
|
|
60
|
+
name: "dev",
|
|
61
|
+
synopsis: ["dev [--workspace <dir>] [--port <n>] [--host <host>]"],
|
|
62
|
+
description: "Serve the viewer locally and reload it as you edit the Workspace.",
|
|
63
|
+
arguments: [],
|
|
64
|
+
flags: {
|
|
65
|
+
workspace: { type: "string", value: "<dir>", defaultText: "the Workspace found from the current folder", description: "Where to look for the Workspace." },
|
|
66
|
+
port: { type: "string", value: "<n>", default: "4321", description: "The port to serve on." },
|
|
67
|
+
host: { type: "string", value: "<host>", default: "127.0.0.1", description: "The address to listen on." },
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
export: {
|
|
71
|
+
name: "export",
|
|
72
|
+
synopsis: [
|
|
73
|
+
"export <view-id> [--format svg|png] [--out <file>] [--direction TB|BT|LR|RL] [--theme light|dark] [--label <text>]",
|
|
74
|
+
"export --all-saved --out <dir> [--format svg|png] [--direction TB|BT|LR|RL] [--theme light|dark] [--label <text>]",
|
|
75
|
+
],
|
|
76
|
+
description: "Render a View, or every Saved View, to an SVG or PNG picture.",
|
|
77
|
+
arguments: [{ name: "<view-id>", description: "The View: c1, c2, c2/<system>, c3/<service>, deployment/<environment>, or a Saved View as project:view-id." }],
|
|
78
|
+
flags: {
|
|
79
|
+
format: { type: "string", value: "svg|png", default: "svg", description: "The picture format." },
|
|
80
|
+
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." },
|
|
81
|
+
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." },
|
|
82
|
+
"all-saved": { type: "boolean", default: false, description: "Render every Saved View into the `--out` folder, one picture each." },
|
|
83
|
+
theme: { type: "string", value: "light|dark", default: "light", description: "The palette: the viewer's light tokens, or its Night shift dark ones." },
|
|
84
|
+
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." },
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
diff: {
|
|
88
|
+
name: "diff",
|
|
89
|
+
synopsis: ["diff <from> [<to>] [--format text|json|markdown]"],
|
|
90
|
+
description: "Show what changed in the Model between two points in the Workspace's history.",
|
|
91
|
+
arguments: [
|
|
92
|
+
{ name: "<from>", description: "A git ref, or a date, which means the last default-branch commit at or before it." },
|
|
93
|
+
{ name: "[<to>]", description: "A ref or date like `<from>`; with none, the working tree." },
|
|
94
|
+
],
|
|
95
|
+
flags: {
|
|
96
|
+
format: { type: "string", value: "text|json|markdown", default: "text", description: "Print the changes as text, JSON, or Markdown for a PR comment." },
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
"history build": {
|
|
100
|
+
name: "history build",
|
|
101
|
+
synopsis: ["history build [--since <ref|date>]"],
|
|
102
|
+
description: "Build and cache the Bundle of every past Revision, so later builds and diffs don't have to. Safe to re-run.",
|
|
103
|
+
arguments: [],
|
|
104
|
+
flags: {
|
|
105
|
+
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." },
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
mcp: {
|
|
109
|
+
name: "mcp",
|
|
110
|
+
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>]"],
|
|
111
|
+
description: "Serve the Model to AI agents over MCP, from a Workspace checkout or a published Bundle, on stdio or local HTTP.",
|
|
112
|
+
arguments: [],
|
|
113
|
+
flags: {
|
|
114
|
+
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." },
|
|
115
|
+
bundle: { type: "string", value: "<url|path>", description: "Serve a published Bundle, read-only, instead of a checkout." },
|
|
116
|
+
"viewer-url": { type: "string", value: "<url>", description: "The published viewer's base URL; tool results then link to it." },
|
|
117
|
+
http: { type: "boolean", default: false, description: "Serve Streamable HTTP at `/mcp` instead of stdio." },
|
|
118
|
+
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`." },
|
|
119
|
+
port: { type: "string", value: "<n>", defaultText: "3737", description: "With `--http`: the port to serve on." },
|
|
120
|
+
"allow-writes": { type: "boolean", default: false, description: "With `--http`: allow the write tools, which are off over HTTP by default." },
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
/** Every command, in the order the usage lists them. */
|
|
125
|
+
export const commandList = Object.values(commands);
|
|
126
|
+
/** The usage text the CLI prints after a usage error. */
|
|
127
|
+
export function usageText() {
|
|
128
|
+
const lines = commandList.flatMap((c) => c.synopsis.map((s) => ` archidocs ${s}`));
|
|
129
|
+
return `Usage:\n${lines.join("\n")}\n`;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Parses a command's arguments (the words after its name) with its flags,
|
|
133
|
+
* strictly: an unknown flag or a missing value throws `ERR_PARSE_ARGS_*`.
|
|
134
|
+
*/
|
|
135
|
+
export function parseCommand(name, args) {
|
|
136
|
+
const command = commands[name];
|
|
137
|
+
return parseArgs({ args, options: command.flags, allowPositionals: command.arguments.length > 0, strict: true });
|
|
138
|
+
}
|
|
139
|
+
/** The command a command line names, and the arguments after its name. */
|
|
140
|
+
export function findCommand(argv) {
|
|
141
|
+
// The longest name wins, so `history build` is found before any `history`.
|
|
142
|
+
const byLength = [...commandList].sort((a, b) => b.name.split(" ").length - a.name.split(" ").length);
|
|
143
|
+
for (const command of byLength) {
|
|
144
|
+
const words = command.name.split(" ");
|
|
145
|
+
if (words.every((w, i) => argv[i] === w))
|
|
146
|
+
return { command, args: argv.slice(words.length) };
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Checks a command line (the words after `archidocs`) against the
|
|
152
|
+
* definitions without running anything: an unknown command, an unknown
|
|
153
|
+
* flag, a flag missing its value or a stray argument is reported. What
|
|
154
|
+
* a value means, and which flags go together, are left to the command.
|
|
155
|
+
*/
|
|
156
|
+
export function parseCommandLine(argv) {
|
|
157
|
+
const found = findCommand(argv);
|
|
158
|
+
if (!found) {
|
|
159
|
+
const [first, second] = argv;
|
|
160
|
+
if (first === undefined)
|
|
161
|
+
return { ok: false, message: "No command given." };
|
|
162
|
+
const sub = commandList.find((c) => c.name.startsWith(`${first} `));
|
|
163
|
+
if (sub)
|
|
164
|
+
return { ok: false, message: second === undefined ? `Give a ${first} command.` : `Unknown ${first} command "${second}".` };
|
|
165
|
+
return { ok: false, message: `Unknown command "${first}".` };
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
parseArgs({ args: found.args, options: found.command.flags, allowPositionals: found.command.arguments.length > 0, strict: true });
|
|
169
|
+
return { ok: true, command: found.command.name };
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
return { ok: false, message: e instanceof Error ? e.message : String(e) };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Issue } from "../core/index.ts";
|
|
2
|
+
export declare const DEFAULT_DEV_PORT = 4321;
|
|
3
|
+
export interface DevOptions {
|
|
4
|
+
/** The Workspace root, watched for changes. */
|
|
5
|
+
root: string;
|
|
6
|
+
/** The prebuilt viewer to serve. */
|
|
7
|
+
viewerDir: string;
|
|
8
|
+
/** How the viewer's exports name the Workspace, as `site.json` does in a built site. */
|
|
9
|
+
workspace: string;
|
|
10
|
+
host?: string;
|
|
11
|
+
/** 0 picks a free port. */
|
|
12
|
+
port?: number;
|
|
13
|
+
/** Called after each load with the Workspace's issues; `kept` when errors kept the last good Bundle. */
|
|
14
|
+
onLoad?: (result: {
|
|
15
|
+
issues: Issue[];
|
|
16
|
+
kept: boolean;
|
|
17
|
+
first: boolean;
|
|
18
|
+
}) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface DevServer {
|
|
21
|
+
url: string;
|
|
22
|
+
/** Re-reads the Workspace now, as a file change would. */
|
|
23
|
+
reload(): Promise<void>;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Serves the viewer with the Workspace's Bundle built in memory, and re-reads
|
|
28
|
+
* the Workspace on every file change. A Workspace with errors keeps serving
|
|
29
|
+
* its last good Bundle and shows the errors in the page instead.
|
|
30
|
+
*/
|
|
31
|
+
export declare function serveDev({ root, viewerDir, workspace, host, port, onLoad }: DevOptions): Promise<DevServer>;
|
package/dist/cli/dev.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { watch } from "node:fs";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { extname, join, normalize, sep } from "node:path";
|
|
5
|
+
import { load, nodeFileSystem, serializeBundle } from "../core/index.js";
|
|
6
|
+
import { formatText } from "./format.js";
|
|
7
|
+
import { gitHead } from "../git.js";
|
|
8
|
+
import { SCHEMA_VERSION } from "../schema/bundle.js";
|
|
9
|
+
export const DEFAULT_DEV_PORT = 4321;
|
|
10
|
+
/** The path the page listens on for reloads; under `__archidocs/` so it can't clash with a site file. */
|
|
11
|
+
const EVENTS = "/__archidocs/events";
|
|
12
|
+
const TYPES = {
|
|
13
|
+
".html": "text/html; charset=utf-8",
|
|
14
|
+
".js": "text/javascript; charset=utf-8",
|
|
15
|
+
".css": "text/css; charset=utf-8",
|
|
16
|
+
".json": "application/json; charset=utf-8",
|
|
17
|
+
".svg": "image/svg+xml",
|
|
18
|
+
".wasm": "application/wasm",
|
|
19
|
+
".ttf": "font/ttf",
|
|
20
|
+
".woff2": "font/woff2",
|
|
21
|
+
".png": "image/png",
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The page's side of dev mode: reload on a new Bundle (hash routing keeps the
|
|
25
|
+
* place), and show the Workspace's errors in a banner while they last.
|
|
26
|
+
*/
|
|
27
|
+
const CLIENT = `<script>
|
|
28
|
+
(() => {
|
|
29
|
+
let banner;
|
|
30
|
+
const events = new EventSource(".${EVENTS}");
|
|
31
|
+
events.addEventListener("reload", () => location.reload());
|
|
32
|
+
events.addEventListener("errors", (e) => {
|
|
33
|
+
banner ??= Object.assign(document.body.appendChild(document.createElement("pre")), { id: "archidocs-dev-errors" });
|
|
34
|
+
banner.style.cssText = "position:fixed;left:12px;right:12px;bottom:12px;z-index:99999;margin:0;max-height:40vh;overflow:auto;padding:12px 14px;border-radius:8px;background:#2b0f12;color:#ffd7d9;font:12px/1.5 ui-monospace,monospace;white-space:pre-wrap;box-shadow:0 6px 24px rgba(0,0,0,.35)";
|
|
35
|
+
banner.textContent = "The Workspace has errors; showing the last good Bundle.\\n\\n" + JSON.parse(e.data);
|
|
36
|
+
});
|
|
37
|
+
events.addEventListener("ok", () => { banner?.remove(); banner = undefined; });
|
|
38
|
+
})();
|
|
39
|
+
</script>`;
|
|
40
|
+
/**
|
|
41
|
+
* Serves the viewer with the Workspace's Bundle built in memory, and re-reads
|
|
42
|
+
* the Workspace on every file change. A Workspace with errors keeps serving
|
|
43
|
+
* its last good Bundle and shows the errors in the page instead.
|
|
44
|
+
*/
|
|
45
|
+
export async function serveDev({ root, viewerDir, workspace, host = "127.0.0.1", port = DEFAULT_DEV_PORT, onLoad }) {
|
|
46
|
+
let bundleJson;
|
|
47
|
+
let errors;
|
|
48
|
+
const clients = new Set();
|
|
49
|
+
const broadcast = (event, data = "") => {
|
|
50
|
+
for (const res of clients)
|
|
51
|
+
res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`);
|
|
52
|
+
};
|
|
53
|
+
let first = true;
|
|
54
|
+
const rebuild = async () => {
|
|
55
|
+
const { commit, builtAt } = await gitHead(root);
|
|
56
|
+
const { bundle, issues } = await load({ fs: nodeFileSystem(), root, commit, builtAt });
|
|
57
|
+
const failed = issues.filter((i) => i.severity === "error");
|
|
58
|
+
const kept = failed.length > 0 && bundleJson !== undefined;
|
|
59
|
+
onLoad?.({ issues, kept, first });
|
|
60
|
+
first = false;
|
|
61
|
+
if (failed.length > 0) {
|
|
62
|
+
errors = formatText(failed).trimEnd();
|
|
63
|
+
// With no good Bundle yet, serve this one so the page still opens.
|
|
64
|
+
bundleJson ??= serializeBundle(bundle);
|
|
65
|
+
broadcast("errors", errors);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const next = serializeBundle(bundle);
|
|
69
|
+
const hadErrors = errors !== undefined;
|
|
70
|
+
errors = undefined;
|
|
71
|
+
if (next !== bundleJson) {
|
|
72
|
+
bundleJson = next;
|
|
73
|
+
broadcast("reload");
|
|
74
|
+
}
|
|
75
|
+
else if (hadErrors)
|
|
76
|
+
broadcast("ok");
|
|
77
|
+
};
|
|
78
|
+
// Several saves in a burst (an editor's write-then-rename, a git checkout) make one reload.
|
|
79
|
+
let timer;
|
|
80
|
+
let running = Promise.resolve();
|
|
81
|
+
const schedule = () => {
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
timer = setTimeout(() => {
|
|
84
|
+
running = running.then(rebuild).catch((e) => {
|
|
85
|
+
errors = e instanceof Error ? e.message : String(e);
|
|
86
|
+
broadcast("errors", errors);
|
|
87
|
+
});
|
|
88
|
+
}, 80);
|
|
89
|
+
};
|
|
90
|
+
await rebuild();
|
|
91
|
+
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";
|
|
94
|
+
const server = createServer((req, res) => {
|
|
95
|
+
void (async () => {
|
|
96
|
+
const path = decodeURIComponent(new URL(req.url ?? "/", "http://dev").pathname);
|
|
97
|
+
const send = (body, type) => {
|
|
98
|
+
res.writeHead(200, { "content-type": type, "cache-control": "no-store" });
|
|
99
|
+
res.end(body);
|
|
100
|
+
};
|
|
101
|
+
if (path === EVENTS) {
|
|
102
|
+
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", connection: "keep-alive" });
|
|
103
|
+
res.write(": connected\n\n");
|
|
104
|
+
if (errors !== undefined)
|
|
105
|
+
res.write(`event: errors\ndata: ${JSON.stringify(errors)}\n\n`);
|
|
106
|
+
clients.add(res);
|
|
107
|
+
req.on("close", () => clients.delete(res));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (path === "/" || path === "/index.html")
|
|
111
|
+
return send(index, TYPES[".html"]);
|
|
112
|
+
if (path === "/workspace.bundle.json")
|
|
113
|
+
return send(bundleJson, TYPES[".json"]);
|
|
114
|
+
if (path === "/site.json")
|
|
115
|
+
return send(site, TYPES[".json"]);
|
|
116
|
+
// Dev mode shows the working tree only; the viewer reads an empty index as no history.
|
|
117
|
+
if (path === "/bundles/index.json")
|
|
118
|
+
return send(noHistory, TYPES[".json"]);
|
|
119
|
+
const file = normalize(join(viewerDir, path));
|
|
120
|
+
if (!file.startsWith(normalize(viewerDir + sep)) || !(await stat(file).catch(() => undefined))?.isFile()) {
|
|
121
|
+
res.writeHead(404).end("Not found");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
send(await readFile(file), TYPES[extname(file)] ?? "application/octet-stream");
|
|
125
|
+
})().catch(() => {
|
|
126
|
+
if (!res.headersSent)
|
|
127
|
+
res.writeHead(500);
|
|
128
|
+
res.end();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
await new Promise((done, fail) => {
|
|
132
|
+
server.once("error", fail);
|
|
133
|
+
server.listen(port, host, () => done());
|
|
134
|
+
});
|
|
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"))
|
|
138
|
+
return;
|
|
139
|
+
schedule();
|
|
140
|
+
});
|
|
141
|
+
const { port: bound } = server.address();
|
|
142
|
+
return {
|
|
143
|
+
url: `http://${host.includes(":") ? `[${host}]` : host}:${bound}/`,
|
|
144
|
+
reload: async () => {
|
|
145
|
+
await running;
|
|
146
|
+
await rebuild();
|
|
147
|
+
},
|
|
148
|
+
close: async () => {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
watcher.close();
|
|
151
|
+
for (const res of clients)
|
|
152
|
+
res.end();
|
|
153
|
+
await new Promise((done) => server.close(() => done()));
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Change } from "../core/index.ts";
|
|
2
|
+
export declare const diffFormats: readonly ["text", "json", "markdown"];
|
|
3
|
+
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
|
+
export declare function formatDiff(changes: Change[], from: DiffSide, to: DiffSide, format: DiffFormat): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { countChanges } from "../core/index.js";
|
|
2
|
+
export const diffFormats = ["text", "json", "markdown"];
|
|
3
|
+
export function formatDiff(changes, from, to, format) {
|
|
4
|
+
if (format === "json")
|
|
5
|
+
return JSON.stringify({ from, to, counts: countChanges(changes), changes }, null, 2) + "\n";
|
|
6
|
+
return format === "markdown" ? markdown(changes, from, to) : text(changes, from, to);
|
|
7
|
+
}
|
|
8
|
+
const kindNames = {
|
|
9
|
+
team: "Team",
|
|
10
|
+
environment: "Environment",
|
|
11
|
+
project: "Project",
|
|
12
|
+
element: "Element",
|
|
13
|
+
relationship: "Relationship",
|
|
14
|
+
target: "Deployment Target",
|
|
15
|
+
deployment: "Deployment",
|
|
16
|
+
view: "Saved View",
|
|
17
|
+
adr: "ADR",
|
|
18
|
+
};
|
|
19
|
+
const label = (side) => (side.commit === null ? side.point : side.commit.startsWith(side.point) ? side.commit.slice(0, 7) : `${side.point} (${side.commit.slice(0, 7)})`);
|
|
20
|
+
const summary = (changes) => {
|
|
21
|
+
const { added, removed, changed } = countChanges(changes);
|
|
22
|
+
return `${added} added, ${removed} removed, ${changed} changed`;
|
|
23
|
+
};
|
|
24
|
+
/** A field's before and after, or just that it changed for an ADR's body. */
|
|
25
|
+
const fieldLines = (c, value) => c.fields.map((f) => (c.kind === "adr" && f === "body" ? "body changed" : `${f}: ${value(c.before[f])} → ${value(c.after[f])}`));
|
|
26
|
+
const sign = { added: "+", removed: "-", changed: "~" };
|
|
27
|
+
function text(changes, from, to) {
|
|
28
|
+
const lines = [`Changes from ${label(from)} to ${label(to)}: ${summary(changes)}`];
|
|
29
|
+
if (changes.length > 0)
|
|
30
|
+
lines.push("");
|
|
31
|
+
for (const c of changes) {
|
|
32
|
+
lines.push(`${sign[c.type]} ${kindNames[c.kind]} ${c.id}`);
|
|
33
|
+
for (const line of fieldLines(c, (v) => JSON.stringify(v)))
|
|
34
|
+
lines.push(` ${line}`);
|
|
35
|
+
}
|
|
36
|
+
return lines.join("\n") + "\n";
|
|
37
|
+
}
|
|
38
|
+
function markdown(changes, from, to) {
|
|
39
|
+
const code = (s) => `\`${s.replace(/`/g, "'")}\``;
|
|
40
|
+
const cell = (s) => s.replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
41
|
+
const lines = [`### Model changes ${code(label(from))} → ${code(label(to))}`, ""];
|
|
42
|
+
if (changes.length === 0)
|
|
43
|
+
return [...lines, "No Model changes.", ""].join("\n");
|
|
44
|
+
lines.push(`${summary(changes)}.`, "", "| Change | Kind | Id | Fields |", "| --- | --- | --- | --- |");
|
|
45
|
+
for (const c of changes) {
|
|
46
|
+
const fields = fieldLines(c, (v) => code(JSON.stringify(v))).join("<br>");
|
|
47
|
+
lines.push(`| ${c.type} | ${kindNames[c.kind]} | ${cell(code(c.id))} | ${cell(fields)} |`);
|
|
48
|
+
}
|
|
49
|
+
return lines.join("\n") + "\n";
|
|
50
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Issue } from "../core/index.ts";
|
|
2
|
+
export declare const formats: readonly ["text", "json", "github"];
|
|
3
|
+
export type Format = (typeof formats)[number];
|
|
4
|
+
export interface FormatOptions {
|
|
5
|
+
/** Colour the text format; only when writing to a terminal. */
|
|
6
|
+
color?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Writes issues in the chosen `--format`. */
|
|
9
|
+
export declare function formatIssues(issues: Issue[], format: Format, options?: FormatOptions): string;
|
|
10
|
+
/** Exit code for a finished check: 1 on any error, or on any warning with `--strict`; else 0. */
|
|
11
|
+
export declare function exitCodeFor(issues: Issue[], { strict }?: {
|
|
12
|
+
strict?: boolean;
|
|
13
|
+
}): 0 | 1;
|
|
14
|
+
/** `--format text`: issues grouped by file, one per line, then a summary count and each distinct rule's docs link. */
|
|
15
|
+
export declare function formatText(issues: Issue[], { color }?: FormatOptions): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ruleDocsUrl, withDocs } from "../core/index.js";
|
|
2
|
+
export const formats = ["text", "json", "github"];
|
|
3
|
+
/** Writes issues in the chosen `--format`. */
|
|
4
|
+
export function formatIssues(issues, format, options = {}) {
|
|
5
|
+
if (format === "json")
|
|
6
|
+
return formatJson(issues);
|
|
7
|
+
if (format === "github")
|
|
8
|
+
return formatGithub(issues);
|
|
9
|
+
return formatText(issues, options);
|
|
10
|
+
}
|
|
11
|
+
/** Exit code for a finished check: 1 on any error, or on any warning with `--strict`; else 0. */
|
|
12
|
+
export function exitCodeFor(issues, { strict = false } = {}) {
|
|
13
|
+
return issues.some((i) => strict || i.severity === "error") ? 1 : 0;
|
|
14
|
+
}
|
|
15
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
16
|
+
function summarize(issues) {
|
|
17
|
+
const errors = issues.filter((i) => i.severity === "error").length;
|
|
18
|
+
return { errors, warnings: issues.length - errors };
|
|
19
|
+
}
|
|
20
|
+
const ansi = (code) => (s) => `\x1b[${code}m${s}\x1b[0m`;
|
|
21
|
+
const plain = (s) => s;
|
|
22
|
+
/** `--format text`: issues grouped by file, one per line, then a summary count and each distinct rule's docs link. */
|
|
23
|
+
export function formatText(issues, { color = false } = {}) {
|
|
24
|
+
const red = color ? ansi(31) : plain;
|
|
25
|
+
const yellow = color ? ansi(33) : plain;
|
|
26
|
+
const dim = color ? ansi(2) : plain;
|
|
27
|
+
const lines = [];
|
|
28
|
+
let lastFile;
|
|
29
|
+
for (const i of issues) {
|
|
30
|
+
if (lastFile !== undefined && i.file !== lastFile)
|
|
31
|
+
lines.push("");
|
|
32
|
+
lastFile = i.file;
|
|
33
|
+
const where = `${i.file}:${i.line}${i.column === undefined ? "" : `:${i.column}`}`;
|
|
34
|
+
const severity = i.severity === "error" ? red(i.severity) : yellow(i.severity);
|
|
35
|
+
lines.push(`${where} ${severity} ${dim(i.rule)} ${i.message}`);
|
|
36
|
+
}
|
|
37
|
+
const { errors, warnings } = summarize(issues);
|
|
38
|
+
if (lines.length > 0)
|
|
39
|
+
lines.push("");
|
|
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)}`));
|
|
44
|
+
return lines.join("\n") + "\n";
|
|
45
|
+
}
|
|
46
|
+
/** `--format json`: the issue records with their rule's `docs` link, as MCP returns them, and a summary. */
|
|
47
|
+
function formatJson(issues) {
|
|
48
|
+
return JSON.stringify({ issues: issues.map(withDocs), summary: summarize(issues) }, null, 2) + "\n";
|
|
49
|
+
}
|
|
50
|
+
// GitHub workflow command escaping: https://github.com/actions/toolkit/blob/main/packages/core/src/command.ts
|
|
51
|
+
const escapeData = (s) => s.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
52
|
+
const escapeProperty = (s) => escapeData(s).replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
53
|
+
/** `--format github`: one `::error`/`::warning` workflow command per issue, for inline PR annotations, ending with its rule's docs link. */
|
|
54
|
+
function formatGithub(issues) {
|
|
55
|
+
return issues
|
|
56
|
+
.map((i) => {
|
|
57
|
+
const props = [`file=${escapeProperty(i.file)}`, `line=${i.line}`];
|
|
58
|
+
if (i.column !== undefined)
|
|
59
|
+
props.push(`col=${i.column}`);
|
|
60
|
+
props.push(`title=${escapeProperty(i.rule)}`);
|
|
61
|
+
return `::${i.severity} ${props.join(",")}::${escapeData(`${i.message} See ${ruleDocsUrl(i.rule)}`)}\n`;
|
|
62
|
+
})
|
|
63
|
+
.join("");
|
|
64
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Where harnesses look for skills; the stub goes into each. */
|
|
2
|
+
export declare const SKILL_DIRS: readonly [".agents/skills", ".claude/skills", ".github/skills"];
|
|
3
|
+
export interface InitOptions {
|
|
4
|
+
/** The repo being set up: its git top level, or the current folder outside git. */
|
|
5
|
+
repoRoot: string;
|
|
6
|
+
cwd: string;
|
|
7
|
+
/** `init --skill`: a code repo, so install only the stub and pointer. */
|
|
8
|
+
skillOnly: boolean;
|
|
9
|
+
/** For `--skill`: the Workspace checkout to print in the MCP command. */
|
|
10
|
+
workspace?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* `archidocs init` and `init --skill`. Safe to re-run: an existing Workspace
|
|
14
|
+
* and existing pointers are left alone, and the stub is rewritten as is.
|
|
15
|
+
* Returns the lines to print.
|
|
16
|
+
*/
|
|
17
|
+
export declare function init({ repoRoot, cwd, skillOnly, workspace }: InitOptions): Promise<string[]>;
|
package/dist/cli/init.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
4
|
+
import { findWorkspaceRoot, nodeFileSystem } from "../core/index.js";
|
|
5
|
+
import { SKILL_NAME, skillStub } from "../guide/index.js";
|
|
6
|
+
/** Where harnesses look for skills; the stub goes into each. */
|
|
7
|
+
export const SKILL_DIRS = [".agents/skills", ".claude/skills", ".github/skills"];
|
|
8
|
+
const STARTER_WORKSPACE = `# The Archidocs Workspace root: Teams and Environments are defined here only.
|
|
9
|
+
# Each Project is a folder below this one holding a project.yaml.
|
|
10
|
+
teams: {}
|
|
11
|
+
environments: {}
|
|
12
|
+
`;
|
|
13
|
+
/** The local history cache, kept out of git. */
|
|
14
|
+
const CACHE_IGNORE = ".archidocs/";
|
|
15
|
+
/**
|
|
16
|
+
* `archidocs init` and `init --skill`. Safe to re-run: an existing Workspace
|
|
17
|
+
* and existing pointers are left alone, and the stub is rewritten as is.
|
|
18
|
+
* Returns the lines to print.
|
|
19
|
+
*/
|
|
20
|
+
export async function init({ repoRoot, cwd, skillOnly, workspace }) {
|
|
21
|
+
const out = [];
|
|
22
|
+
const wrote = (path, what) => out.push(`${what} ${posix(relative(repoRoot, path))}`);
|
|
23
|
+
let workspaceDir;
|
|
24
|
+
if (!skillOnly) {
|
|
25
|
+
workspaceDir = (await findWorkspaceRoot(nodeFileSystem(), cwd)) ?? undefined;
|
|
26
|
+
if (!workspaceDir) {
|
|
27
|
+
workspaceDir = join(repoRoot, "archidocs");
|
|
28
|
+
await mkdir(workspaceDir, { recursive: true });
|
|
29
|
+
await writeFile(join(workspaceDir, "workspace.yaml"), STARTER_WORKSPACE);
|
|
30
|
+
wrote(join(workspaceDir, "workspace.yaml"), "Wrote");
|
|
31
|
+
}
|
|
32
|
+
if (await appendOnce(join(repoRoot, ".gitignore"), CACHE_IGNORE, (text) => text.split(/\r?\n/).includes(CACHE_IGNORE), { create: true })) {
|
|
33
|
+
wrote(join(repoRoot, ".gitignore"), "Updated");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
for (const dir of SKILL_DIRS) {
|
|
37
|
+
const path = join(repoRoot, dir, SKILL_NAME, "SKILL.md");
|
|
38
|
+
const before = existsSync(path) ? await readFile(path, "utf8") : undefined;
|
|
39
|
+
if (before === skillStub)
|
|
40
|
+
continue;
|
|
41
|
+
await mkdir(dirname(path), { recursive: true });
|
|
42
|
+
await writeFile(path, skillStub);
|
|
43
|
+
wrote(path, before === undefined ? "Wrote" : "Updated");
|
|
44
|
+
}
|
|
45
|
+
const where = workspaceDir === undefined ? undefined : posix(relative(repoRoot, workspaceDir)) || ".";
|
|
46
|
+
const pointer = [
|
|
47
|
+
"## Architecture model",
|
|
48
|
+
"",
|
|
49
|
+
where === undefined
|
|
50
|
+
? "This code's architecture is declared in an Archidocs Workspace kept in another repo."
|
|
51
|
+
: `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.`,
|
|
53
|
+
"",
|
|
54
|
+
].join("\n");
|
|
55
|
+
const hasPointer = (text) => text.includes(SKILL_NAME);
|
|
56
|
+
if (await appendOnce(join(repoRoot, "AGENTS.md"), pointer, hasPointer, { create: true }))
|
|
57
|
+
wrote(join(repoRoot, "AGENTS.md"), "Updated");
|
|
58
|
+
if (await appendOnce(join(repoRoot, "CLAUDE.md"), pointer, hasPointer, { create: false }))
|
|
59
|
+
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 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."] : []));
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Appends `block` to the file unless `present` already finds it there,
|
|
66
|
+
* separating it from what is there by a blank line (one newline for a line
|
|
67
|
+
* list such as `.gitignore`). Returns whether the file changed.
|
|
68
|
+
*/
|
|
69
|
+
async function appendOnce(path, block, present, { create }) {
|
|
70
|
+
const exists = existsSync(path);
|
|
71
|
+
if (!exists && !create)
|
|
72
|
+
return false;
|
|
73
|
+
const text = exists ? await readFile(path, "utf8") : "";
|
|
74
|
+
if (present(text))
|
|
75
|
+
return false;
|
|
76
|
+
const lineList = !block.includes("\n");
|
|
77
|
+
const body = lineList ? `${block}\n` : block;
|
|
78
|
+
const separator = text === "" ? "" : text.endsWith("\n") ? (lineList ? "" : "\n") : lineList ? "\n" : "\n\n";
|
|
79
|
+
await writeFile(path, text + separator + body);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
const posix = (path) => path.split(sep).join("/");
|