archidocs 0.0.0-stage → 1.0.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 (162) hide show
  1. package/dist/cli/dev.d.ts +31 -0
  2. package/dist/cli/dev.js +156 -0
  3. package/dist/cli/diff-format.d.ts +9 -0
  4. package/dist/cli/diff-format.js +50 -0
  5. package/dist/cli/format.d.ts +15 -0
  6. package/dist/cli/format.js +60 -0
  7. package/dist/cli/init.d.ts +17 -0
  8. package/dist/cli/init.js +82 -0
  9. package/dist/cli/main.d.ts +2 -0
  10. package/dist/cli/main.js +371 -0
  11. package/dist/core/adr.d.ts +28 -0
  12. package/dist/core/adr.js +88 -0
  13. package/dist/core/adrs.d.ts +20 -0
  14. package/dist/core/adrs.js +86 -0
  15. package/dist/core/catalogue.d.ts +7 -0
  16. package/dist/core/catalogue.js +35 -0
  17. package/dist/core/compare.d.ts +21 -0
  18. package/dist/core/compare.js +62 -0
  19. package/dist/core/deployment-views.d.ts +28 -0
  20. package/dist/core/deployment-views.js +108 -0
  21. package/dist/core/deployments.d.ts +18 -0
  22. package/dist/core/deployments.js +21 -0
  23. package/dist/core/diff.d.ts +44 -0
  24. package/dist/core/diff.js +138 -0
  25. package/dist/core/dynamic-views.d.ts +73 -0
  26. package/dist/core/dynamic-views.js +162 -0
  27. package/dist/core/files.d.ts +2 -0
  28. package/dist/core/files.js +1 -0
  29. package/dist/core/fs.d.ts +19 -0
  30. package/dist/core/fs.js +21 -0
  31. package/dist/core/history-scope.d.ts +40 -0
  32. package/dist/core/history-scope.js +63 -0
  33. package/dist/core/impact.d.ts +34 -0
  34. package/dist/core/impact.js +62 -0
  35. package/dist/core/index.d.ts +20 -0
  36. package/dist/core/index.js +18 -0
  37. package/dist/core/load.d.ts +32 -0
  38. package/dist/core/load.js +465 -0
  39. package/dist/core/model.d.ts +150 -0
  40. package/dist/core/model.js +1 -0
  41. package/dist/core/ownership.d.ts +34 -0
  42. package/dist/core/ownership.js +65 -0
  43. package/dist/core/paths.d.ts +47 -0
  44. package/dist/core/paths.js +115 -0
  45. package/dist/core/query.d.ts +51 -0
  46. package/dist/core/query.js +77 -0
  47. package/dist/core/refs.d.ts +31 -0
  48. package/dist/core/refs.js +50 -0
  49. package/dist/core/rules.d.ts +21 -0
  50. package/dist/core/rules.js +1025 -0
  51. package/dist/core/save-as-view.d.ts +45 -0
  52. package/dist/core/save-as-view.js +114 -0
  53. package/dist/core/saved-views.d.ts +48 -0
  54. package/dist/core/saved-views.js +243 -0
  55. package/dist/core/schema-check.d.ts +13 -0
  56. package/dist/core/schema-check.js +79 -0
  57. package/dist/core/search.d.ts +27 -0
  58. package/dist/core/search.js +63 -0
  59. package/dist/core/suggest.d.ts +3 -0
  60. package/dist/core/suggest.js +30 -0
  61. package/dist/core/views.d.ts +126 -0
  62. package/dist/core/views.js +217 -0
  63. package/dist/core/yaml.d.ts +16 -0
  64. package/dist/core/yaml.js +52 -0
  65. package/dist/git.d.ts +7 -0
  66. package/dist/git.js +23 -0
  67. package/dist/guide/index.d.ts +53 -0
  68. package/dist/guide/index.js +57 -0
  69. package/dist/history/git.d.ts +39 -0
  70. package/dist/history/git.js +126 -0
  71. package/dist/history/index.d.ts +118 -0
  72. package/dist/history/index.js +223 -0
  73. package/dist/history/migrate.d.ts +16 -0
  74. package/dist/history/migrate.js +30 -0
  75. package/dist/mcp/history.d.ts +36 -0
  76. package/dist/mcp/history.js +175 -0
  77. package/dist/mcp/http.d.ts +23 -0
  78. package/dist/mcp/http.js +85 -0
  79. package/dist/mcp/index.d.ts +3 -0
  80. package/dist/mcp/index.js +3 -0
  81. package/dist/mcp/server.d.ts +54 -0
  82. package/dist/mcp/server.js +822 -0
  83. package/dist/mcp/source.d.ts +50 -0
  84. package/dist/mcp/source.js +132 -0
  85. package/dist/mcp/writes.d.ts +10 -0
  86. package/dist/mcp/writes.js +266 -0
  87. package/dist/render/font.d.ts +8 -0
  88. package/dist/render/font.js +10 -0
  89. package/dist/render/index.d.ts +7 -0
  90. package/dist/render/index.js +7 -0
  91. package/dist/render/layout.d.ts +53 -0
  92. package/dist/render/layout.js +199 -0
  93. package/dist/render/node.d.ts +3 -0
  94. package/dist/render/node.js +8 -0
  95. package/dist/render/png.d.ts +11 -0
  96. package/dist/render/png.js +29 -0
  97. package/dist/render/sequence-svg.d.ts +28 -0
  98. package/dist/render/sequence-svg.js +98 -0
  99. package/dist/render/sequence.d.ts +103 -0
  100. package/dist/render/sequence.js +142 -0
  101. package/dist/render/svg.d.ts +23 -0
  102. package/dist/render/svg.js +159 -0
  103. package/dist/render/teams.d.ts +12 -0
  104. package/dist/render/teams.js +31 -0
  105. package/dist/render/text.d.ts +13 -0
  106. package/dist/render/text.js +27 -0
  107. package/dist/schema/adr.d.ts +36 -0
  108. package/dist/schema/adr.js +27 -0
  109. package/dist/schema/bundle.d.ts +726 -0
  110. package/dist/schema/bundle.js +171 -0
  111. package/dist/schema/index.d.ts +4 -0
  112. package/dist/schema/index.js +4 -0
  113. package/dist/schema/json-schema.d.ts +8 -0
  114. package/dist/schema/json-schema.js +19 -0
  115. package/dist/schema/workspace.d.ts +1066 -0
  116. package/dist/schema/workspace.js +271 -0
  117. package/dist/viewer/assets/index-BwUCSYuf.js +113 -0
  118. package/dist/viewer/assets/index-DvKgCpBr.css +1 -0
  119. package/dist/viewer/assets/index_bg-Blvrv-U2.wasm +0 -0
  120. package/dist/viewer/assets/index_bg-D3t31u3-.js +1 -0
  121. package/dist/viewer/assets/layout.worker-Bg-OaLVN.js +26 -0
  122. package/dist/viewer/assets/overpass-latin-QyaMbcmi.woff2 +0 -0
  123. package/dist/viewer/assets/overpass-latin-ext-DSRhPfzW.woff2 +0 -0
  124. package/dist/viewer/assets/overpass-mono-latin-BTquVRaO.woff2 +0 -0
  125. package/dist/viewer/assets/overpass-mono-latin-ext-D47EiU4_.woff2 +0 -0
  126. package/dist/viewer/assets/png-D1zzLB1s.js +1 -0
  127. package/dist/viewer/assets/svg-Cw4FMsm3.js +2 -0
  128. package/dist/viewer/favicon.svg +1 -0
  129. package/dist/viewer/index.html +53 -0
  130. package/dist/writer/adrs.d.ts +21 -0
  131. package/dist/writer/adrs.js +72 -0
  132. package/dist/writer/deployments.d.ts +51 -0
  133. package/dist/writer/deployments.js +145 -0
  134. package/dist/writer/diff.d.ts +6 -0
  135. package/dist/writer/diff.js +77 -0
  136. package/dist/writer/document.d.ts +25 -0
  137. package/dist/writer/document.js +79 -0
  138. package/dist/writer/edit.d.ts +78 -0
  139. package/dist/writer/edit.js +63 -0
  140. package/dist/writer/index.d.ts +67 -0
  141. package/dist/writer/index.js +310 -0
  142. package/dist/writer/overlay.d.ts +7 -0
  143. package/dist/writer/overlay.js +26 -0
  144. package/dist/writer/views.d.ts +29 -0
  145. package/dist/writer/views.js +78 -0
  146. package/dist/writer/workspace.d.ts +25 -0
  147. package/dist/writer/workspace.js +56 -0
  148. package/guide/SKILL.md +36 -0
  149. package/guide/topics/add-service.md +30 -0
  150. package/guide/topics/bootstrap.md +28 -0
  151. package/guide/topics/change.md +32 -0
  152. package/guide/topics/deployments.md +36 -0
  153. package/guide/topics/dynamic-view.md +39 -0
  154. package/guide/topics/propose-adr.md +12 -0
  155. package/guide/topics/relationships.md +39 -0
  156. package/guide/topics/saved-view.md +36 -0
  157. package/package.json +60 -4
  158. package/schemas/adr.schema.json +82 -0
  159. package/schemas/model.schema.json +1381 -0
  160. package/schemas/project.schema.json +24 -0
  161. package/schemas/workspace.schema.json +72 -0
  162. package/README.md +0 -3
@@ -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>;
@@ -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. */
15
+ export declare function formatText(issues: Issue[], { color }?: FormatOptions): string;
@@ -0,0 +1,60 @@
1
+ export const formats = ["text", "json", "github"];
2
+ /** Writes issues in the chosen `--format`. */
3
+ export function formatIssues(issues, format, options = {}) {
4
+ if (format === "json")
5
+ return formatJson(issues);
6
+ if (format === "github")
7
+ return formatGithub(issues);
8
+ return formatText(issues, options);
9
+ }
10
+ /** Exit code for a finished check: 1 on any error, or on any warning with `--strict`; else 0. */
11
+ export function exitCodeFor(issues, { strict = false } = {}) {
12
+ return issues.some((i) => strict || i.severity === "error") ? 1 : 0;
13
+ }
14
+ const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
15
+ function summarize(issues) {
16
+ const errors = issues.filter((i) => i.severity === "error").length;
17
+ return { errors, warnings: issues.length - errors };
18
+ }
19
+ const ansi = (code) => (s) => `\x1b[${code}m${s}\x1b[0m`;
20
+ const plain = (s) => s;
21
+ /** `--format text`: issues grouped by file, one per line, then a summary count. */
22
+ export function formatText(issues, { color = false } = {}) {
23
+ const red = color ? ansi(31) : plain;
24
+ const yellow = color ? ansi(33) : plain;
25
+ const dim = color ? ansi(2) : plain;
26
+ const lines = [];
27
+ let lastFile;
28
+ for (const i of issues) {
29
+ if (lastFile !== undefined && i.file !== lastFile)
30
+ lines.push("");
31
+ lastFile = i.file;
32
+ const where = `${i.file}:${i.line}${i.column === undefined ? "" : `:${i.column}`}`;
33
+ const severity = i.severity === "error" ? red(i.severity) : yellow(i.severity);
34
+ lines.push(`${where} ${severity} ${dim(i.rule)} ${i.message}`);
35
+ }
36
+ const { errors, warnings } = summarize(issues);
37
+ if (lines.length > 0)
38
+ lines.push("");
39
+ lines.push(`${plural(errors, "error")}, ${plural(warnings, "warning")}`);
40
+ return lines.join("\n") + "\n";
41
+ }
42
+ /** `--format json`: the issue records, as MCP returns them, and a summary. */
43
+ function formatJson(issues) {
44
+ return JSON.stringify({ issues, summary: summarize(issues) }, null, 2) + "\n";
45
+ }
46
+ // GitHub workflow command escaping: https://github.com/actions/toolkit/blob/main/packages/core/src/command.ts
47
+ const escapeData = (s) => s.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
48
+ 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. */
50
+ function formatGithub(issues) {
51
+ return issues
52
+ .map((i) => {
53
+ const props = [`file=${escapeProperty(i.file)}`, `line=${i.line}`];
54
+ if (i.column !== undefined)
55
+ props.push(`col=${i.column}`);
56
+ props.push(`title=${escapeProperty(i.rule)}`);
57
+ return `::${i.severity} ${props.join(",")}::${escapeData(i.message)}\n`;
58
+ })
59
+ .join("");
60
+ }
@@ -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[]>;
@@ -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("/");
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};