archidocs 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +9 -15
  2. package/dist/cli/commands.d.ts +19 -11
  3. package/dist/cli/commands.js +12 -10
  4. package/dist/cli/dev.d.ts +5 -6
  5. package/dist/cli/dev.js +12 -14
  6. package/dist/cli/diff-format.d.ts +1 -5
  7. package/dist/cli/init.d.ts +11 -1
  8. package/dist/cli/init.js +121 -10
  9. package/dist/cli/main.js +2 -324
  10. package/dist/cli/run.d.ts +18 -0
  11. package/dist/cli/run.js +312 -0
  12. package/dist/commands/build.d.ts +51 -0
  13. package/dist/commands/build.js +39 -0
  14. package/dist/commands/check.d.ts +8 -0
  15. package/dist/commands/check.js +5 -0
  16. package/dist/commands/diff.d.ts +29 -0
  17. package/dist/commands/diff.js +25 -0
  18. package/dist/commands/export.d.ts +41 -0
  19. package/dist/commands/export.js +47 -0
  20. package/dist/commands/history.d.ts +18 -0
  21. package/dist/commands/history.js +9 -0
  22. package/dist/commands/index.d.ts +11 -0
  23. package/dist/commands/index.js +11 -0
  24. package/dist/core/index.d.ts +1 -1
  25. package/dist/core/index.js +1 -1
  26. package/dist/core/load.d.ts +0 -2
  27. package/dist/core/load.js +5 -6
  28. package/dist/core/workspace-files.d.ts +13 -0
  29. package/dist/core/workspace-files.js +20 -0
  30. package/dist/git.d.ts +2 -0
  31. package/dist/git.js +14 -4
  32. package/dist/guide/index.d.ts +5 -4
  33. package/dist/guide/index.js +6 -5
  34. package/dist/history/git.d.ts +0 -10
  35. package/dist/history/git.js +1 -30
  36. package/dist/history/index.d.ts +15 -31
  37. package/dist/history/index.js +47 -43
  38. package/dist/history/points.d.ts +23 -0
  39. package/dist/history/points.js +28 -0
  40. package/dist/history/site.d.ts +30 -0
  41. package/dist/history/site.js +37 -0
  42. package/dist/mcp/announce.d.ts +25 -0
  43. package/dist/mcp/announce.js +54 -0
  44. package/dist/mcp/check.d.ts +17 -0
  45. package/dist/mcp/check.js +52 -0
  46. package/dist/mcp/history.d.ts +4 -4
  47. package/dist/mcp/history.js +56 -116
  48. package/dist/mcp/index.d.ts +2 -0
  49. package/dist/mcp/index.js +2 -0
  50. package/dist/mcp/server.d.ts +6 -0
  51. package/dist/mcp/server.js +30 -21
  52. package/dist/mcp/site.d.ts +12 -0
  53. package/dist/mcp/site.js +46 -0
  54. package/dist/mcp/source.d.ts +14 -7
  55. package/dist/mcp/source.js +25 -99
  56. package/dist/mcp/writes.d.ts +2 -2
  57. package/dist/mcp/writes.js +3 -3
  58. package/dist/revisions/find.d.ts +64 -0
  59. package/dist/revisions/find.js +85 -0
  60. package/dist/revisions/index.d.ts +57 -0
  61. package/dist/revisions/index.js +24 -0
  62. package/dist/revisions/site.d.ts +82 -0
  63. package/dist/revisions/site.js +157 -0
  64. package/dist/revisions/text.d.ts +8 -0
  65. package/dist/revisions/text.js +17 -0
  66. package/dist/revisions/touching.d.ts +7 -0
  67. package/dist/revisions/touching.js +7 -0
  68. package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
  69. package/dist/viewer/assets/{png-CAaXWR-k.js → png-DMwnpRCt.js} +1 -1
  70. package/dist/viewer/assets/{svg-BPVHfD36.js → svg-DN6lMeZo.js} +1 -1
  71. package/dist/viewer/index.html +1 -1
  72. package/dist/workspace/index.d.ts +37 -0
  73. package/dist/workspace/index.js +52 -0
  74. package/guide/SKILL.md +2 -0
  75. package/package.json +1 -1
  76. package/dist/viewer/assets/index-BXa5R96a.js +0 -138
  77. /package/dist/{history → revisions}/migrate.d.ts +0 -0
  78. /package/dist/{history → revisions}/migrate.js +0 -0
@@ -0,0 +1,51 @@
1
+ import type { Issue } from "../core/index.ts";
2
+ import type { Checkout } from "../workspace/index.ts";
3
+ export interface BuildOptions {
4
+ /** The folder to write, absolute. */
5
+ out: string;
6
+ /** The prebuilt viewer, copied as is into a site. */
7
+ viewerDir: string;
8
+ /** How many past Bundles a site keeps: a count or all. */
9
+ keep: number | "all";
10
+ /** Write only the Bundle, not the site. */
11
+ bundleOnly: boolean;
12
+ /** Write a preview site of HEAD against `origin/<base>`; `base` defaults to origin's HEAD branch, else main. */
13
+ preview?: {
14
+ base?: string;
15
+ };
16
+ }
17
+ export type BuildResult =
18
+ /** The Workspace has errors; nothing was written. */
19
+ {
20
+ kind: "errors";
21
+ issues: Issue[];
22
+ }
23
+ /** A preview needs git and the Workspace isn't in a repo; nothing was written. */
24
+ | {
25
+ kind: "not-in-git";
26
+ }
27
+ /** A site needs the viewer, and `viewerDir` has none; nothing was written. */
28
+ | {
29
+ kind: "viewer-missing";
30
+ viewerDir: string;
31
+ }
32
+ /** Wrote the Bundle alone, to `file`. */
33
+ | {
34
+ kind: "bundle";
35
+ file: string;
36
+ }
37
+ /** Wrote the site to `out`. */
38
+ | {
39
+ kind: "site";
40
+ out: string;
41
+ }
42
+ /** Wrote the preview site: the PR head against `origin/<base>`. */
43
+ | {
44
+ kind: "preview";
45
+ out: string;
46
+ base: string;
47
+ baseSha: string;
48
+ headSha: string;
49
+ };
50
+ /** The Workspace's Bundle, alone or as a site with the viewer and past Bundles, or as a PR preview site. */
51
+ export declare function build(checkout: Checkout, options: BuildOptions): Promise<BuildResult>;
@@ -0,0 +1,39 @@
1
+ import { existsSync } from "node:fs";
2
+ import { cp } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { defaultBaseBranch, previewSides, publishHistory, publishPreview, writeSite } from "../history/index.js";
5
+ import { INDEX_VERSION, LATEST_BUNDLE_PATH } from "../revisions/index.js";
6
+ /** The Workspace's Bundle, alone or as a site with the viewer and past Bundles, or as a PR preview site. */
7
+ export async function build(checkout, options) {
8
+ const { out, viewerDir, keep, bundleOnly } = options;
9
+ const { bundle, issues } = await checkout.load();
10
+ if (issues.some((i) => i.severity === "error"))
11
+ return { kind: "errors", issues };
12
+ // A preview finds both sides before writing anything, so a missing base writes no site.
13
+ let preview;
14
+ if (options.preview) {
15
+ const repo = await checkout.repo();
16
+ if (!repo)
17
+ return { kind: "not-in-git" };
18
+ const h = repo.history;
19
+ preview = { h, sides: await previewSides(h, options.preview.base ?? (await defaultBaseBranch(h.repoRoot))) };
20
+ }
21
+ if (bundleOnly) {
22
+ await writeSite(out, { bundle });
23
+ return { kind: "bundle", file: join(out, LATEST_BUNDLE_PATH) };
24
+ }
25
+ if (!existsSync(join(viewerDir, "index.html")))
26
+ return { kind: "viewer-missing", viewerDir };
27
+ await cp(viewerDir, out, { recursive: true });
28
+ // The viewer's exports name the Workspace as `archidocs export` does: by its repo's folder.
29
+ const latest = { bundle, workspace: await checkout.name() };
30
+ if (preview)
31
+ return { kind: "preview", out, ...(await publishPreview(preview.h, out, preview.sides, bundle, latest.workspace)) };
32
+ const repo = await checkout.repo();
33
+ if (repo)
34
+ await publishHistory(repo.history, out, latest, { keep });
35
+ // Outside git, an empty index, so the viewer knows there is no history.
36
+ else
37
+ await writeSite(out, { ...latest, index: { schemaVersion: INDEX_VERSION, revisions: [] } });
38
+ return { kind: "site", out };
39
+ }
@@ -0,0 +1,8 @@
1
+ import type { Issue } from "../core/index.ts";
2
+ import type { Checkout } from "../workspace/index.ts";
3
+ export type CheckResult = {
4
+ kind: "checked";
5
+ issues: Issue[];
6
+ };
7
+ /** The Workspace's issues. */
8
+ export declare function check(checkout: Checkout): Promise<CheckResult>;
@@ -0,0 +1,5 @@
1
+ /** The Workspace's issues. */
2
+ export async function check(checkout) {
3
+ const { issues } = await checkout.load();
4
+ return { kind: "checked", issues };
5
+ }
@@ -0,0 +1,29 @@
1
+ import { type Change } from "../core/index.ts";
2
+ import { type PointFailure } from "../history/index.ts";
3
+ import type { Checkout } from "../workspace/index.ts";
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 type DiffResult =
10
+ /** History needs the Workspace in a git repo. */
11
+ {
12
+ kind: "not-in-git";
13
+ }
14
+ /** A point names no commit: an unknown ref, a date before the first Revision, or a prefix of several Revisions' shas. */
15
+ | {
16
+ kind: "unknown-point";
17
+ point: string;
18
+ failure: PointFailure;
19
+ } | {
20
+ kind: "ok";
21
+ from: DiffSide;
22
+ to: DiffSide;
23
+ changes: Change[];
24
+ };
25
+ /** The Changes between two points in history (refs or dates); a missing `to` is the working tree. */
26
+ export declare function diff(checkout: Checkout, points: {
27
+ from: string;
28
+ to?: string;
29
+ }): Promise<DiffResult>;
@@ -0,0 +1,25 @@
1
+ import { diff as diffBundles } from "../core/index.js";
2
+ import { bundleAt, resolvePoint } from "../history/index.js";
3
+ /** The Changes between two points in history (refs or dates); a missing `to` is the working tree. */
4
+ export async function diff(checkout, points) {
5
+ const repo = await checkout.repo();
6
+ if (!repo)
7
+ return { kind: "not-in-git" };
8
+ const h = repo.history;
9
+ /** A point's Bundle; with no point, the working tree's. */
10
+ const side = async (point) => {
11
+ if (point === undefined)
12
+ return { ok: true, side: { point: "working tree", commit: null }, bundle: (await checkout.load()).bundle };
13
+ const resolved = await resolvePoint(h, point);
14
+ if (!resolved.ok)
15
+ return { ok: false, result: { kind: "unknown-point", point, failure: resolved } };
16
+ return { ok: true, side: { point, commit: resolved.sha }, bundle: (await bundleAt(h, resolved.sha)).bundle };
17
+ };
18
+ const from = await side(points.from);
19
+ if (!from.ok)
20
+ return from.result;
21
+ const to = await side(points.to);
22
+ if (!to.ok)
23
+ return to.result;
24
+ return { kind: "ok", from: from.side, to: to.side, changes: diffBundles(from.bundle, to.bundle) };
25
+ }
@@ -0,0 +1,41 @@
1
+ import { type Issue } from "../core/index.ts";
2
+ import { type Direction } from "../render/layout.ts";
3
+ import type { Theme } from "../render/tokens.ts";
4
+ import type { Checkout } from "../workspace/index.ts";
5
+ export interface ExportOptions {
6
+ /** The View ids to draw (c1, c2/<system>, project:view-id, …), or every Saved View. */
7
+ views: string[] | "all-saved";
8
+ format: "svg" | "png";
9
+ /** Wins over each View's own direction. */
10
+ direction?: Direction;
11
+ theme: Theme;
12
+ /** Replaces the source line under the title. */
13
+ label?: string;
14
+ /** The folder the pictures go in, absolute; each is named by its View id. */
15
+ out: string;
16
+ /** With one View id: the picture's path, absolute, instead of one named by the id in `out`. */
17
+ file?: string;
18
+ }
19
+ export interface ExportedFile {
20
+ view: string;
21
+ /** Absolute. */
22
+ path: string;
23
+ }
24
+ export type ExportResult =
25
+ /** The Workspace has errors; nothing was written. */
26
+ {
27
+ kind: "errors";
28
+ issues: Issue[];
29
+ }
30
+ /** No View has this id; nothing was written. */
31
+ | {
32
+ kind: "unknown-view";
33
+ id: string;
34
+ }
35
+ /** The pictures written, in order. */
36
+ | {
37
+ kind: "written";
38
+ files: ExportedFile[];
39
+ };
40
+ /** Lays out and draws Views to SVG or PNG files. */
41
+ export declare function exportViews(checkout: Checkout, options: ExportOptions): Promise<ExportResult>;
@@ -0,0 +1,47 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { resolveView } from "../core/index.js";
4
+ // The render files themselves, not render/index.ts, which re-exports png.ts and so would load resvg for every caller.
5
+ import { layoutView } from "../render/layout.js";
6
+ import { renderSequenceSvg } from "../render/sequence-svg.js";
7
+ import { renderSvg } from "../render/svg.js";
8
+ /** Lays out and draws Views to SVG or PNG files. */
9
+ export async function exportViews(checkout, options) {
10
+ const { format, direction, theme, label } = options;
11
+ if (options.file !== undefined && (options.views === "all-saved" || options.views.length !== 1))
12
+ throw new Error("`file` names the picture of one View.");
13
+ const { bundle, issues } = await checkout.load();
14
+ if (issues.some((i) => i.severity === "error"))
15
+ return { kind: "errors", issues };
16
+ const views = [];
17
+ if (options.views === "all-saved") {
18
+ for (const saved of bundle.views) {
19
+ const view = resolveView(bundle, saved.id);
20
+ if (view)
21
+ views.push([saved.id, view]);
22
+ }
23
+ }
24
+ else {
25
+ for (const id of options.views) {
26
+ const view = resolveView(bundle, id);
27
+ if (!view)
28
+ return { kind: "unknown-view", id };
29
+ views.push([id, view]);
30
+ }
31
+ }
32
+ const source = { workspace: await checkout.name(), commit: bundle.commit, date: bundle.builtAt };
33
+ const toPng = format === "png" ? (await import("../render/node.js")).renderPngInNode : undefined;
34
+ if (options.file === undefined)
35
+ await mkdir(options.out, { recursive: true });
36
+ const files = [];
37
+ for (const [id, view] of views) {
38
+ const path = options.file ?? join(options.out, `${id.replace(/[/:]/g, "-")}.${format}`);
39
+ // A Dynamic View draws as a sequence chart, any other as a diagram.
40
+ const svg = view.kind === "dynamic"
41
+ ? renderSequenceSvg({ bundle, view, source, theme, label })
42
+ : renderSvg({ bundle, view, layout: await layoutView(view, direction === undefined ? {} : { direction }), source, theme, label });
43
+ await writeFile(path, toPng ? await toPng(svg) : svg);
44
+ files.push({ view: id, path });
45
+ }
46
+ return { kind: "written", files };
47
+ }
@@ -0,0 +1,18 @@
1
+ import type { Checkout } from "../workspace/index.ts";
2
+ export interface BuildHistoryOptions {
3
+ /** Only Revisions at or after this ref or date. */
4
+ since?: string;
5
+ }
6
+ export type BuildHistoryResult =
7
+ /** History needs the Workspace in a git repo. */
8
+ {
9
+ kind: "not-in-git";
10
+ }
11
+ /** How many Revisions are in scope, and how many of those this run built. */
12
+ | {
13
+ kind: "ok";
14
+ revisions: number;
15
+ built: number;
16
+ };
17
+ /** Builds and caches the Bundle of every Revision not yet built. */
18
+ export declare function buildHistory(checkout: Checkout, options?: BuildHistoryOptions): Promise<BuildHistoryResult>;
@@ -0,0 +1,9 @@
1
+ import { buildHistory as buildRevisions } from "../history/index.js";
2
+ /** Builds and caches the Bundle of every Revision not yet built. */
3
+ export async function buildHistory(checkout, options = {}) {
4
+ const repo = await checkout.repo();
5
+ if (!repo)
6
+ return { kind: "not-in-git" };
7
+ const { revisions, built } = await buildRevisions(repo.history, options.since === undefined ? {} : { since: options.since });
8
+ return { kind: "ok", revisions, built };
9
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The CLI's commands as functions over a Checkout: each takes options and
3
+ * returns a tagged result, for `run` to format or for the docs site to use.
4
+ * Node-only. None writes to a stream or reads `process`; an expected outcome
5
+ * is a result, and only unexpected failures (git, the disk) throw.
6
+ */
7
+ export { check, type CheckResult } from "./check.ts";
8
+ export { build, type BuildOptions, type BuildResult } from "./build.ts";
9
+ export { exportViews, type ExportOptions, type ExportResult, type ExportedFile } from "./export.ts";
10
+ export { diff, type DiffResult, type DiffSide } from "./diff.ts";
11
+ export { buildHistory, type BuildHistoryOptions, type BuildHistoryResult } from "./history.ts";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The CLI's commands as functions over a Checkout: each takes options and
3
+ * returns a tagged result, for `run` to format or for the docs site to use.
4
+ * Node-only. None writes to a stream or reads `process`; an expected outcome
5
+ * is a result, and only unexpected failures (git, the disk) throw.
6
+ */
7
+ export { check } from "./check.js";
8
+ export { build } from "./build.js";
9
+ export { exportViews } from "./export.js";
10
+ export { diff } from "./diff.js";
11
+ export { buildHistory } from "./history.js";
@@ -1,4 +1,4 @@
1
- export { load, findWorkspaceRoot, serializeBundle, type LoadOptions, type LoadResult } from "./load.ts";
1
+ export { load, findWorkspaceRoot, type LoadOptions, type LoadResult } from "./load.ts";
2
2
  export { nodeFileSystem, type FileSystem, type WritableFileSystem, type DirEntry } from "./fs.ts";
3
3
  export { rules, removed, ruleDocsUrl, withDocs, RULE_DOCS_BASE_URL, type RuleDefinition, type RemovedRule } from "./rules.ts";
4
4
  export type { Issue, Severity } from "./model.ts";
@@ -1,4 +1,4 @@
1
- export { load, findWorkspaceRoot, serializeBundle } from "./load.js";
1
+ export { load, findWorkspaceRoot } from "./load.js";
2
2
  export { nodeFileSystem } from "./fs.js";
3
3
  export { rules, removed, ruleDocsUrl, withDocs, RULE_DOCS_BASE_URL } from "./rules.js";
4
4
  export { ruleCatalogue } from "./catalogue.js";
@@ -28,5 +28,3 @@ export declare function loadDetailed(options: LoadOptions): Promise<LoadResult &
28
28
  }>;
29
29
  /** Walks up from `start` to the folder holding `workspace.yaml`, also looking in each folder's `archidocs/`. */
30
30
  export declare function findWorkspaceRoot(fs: FileSystem, start: string): Promise<string | undefined>;
31
- /** The Bundle as written to `workspace.bundle.json`: stable key order, two-space indent. */
32
- export declare function serializeBundle(bundle: Bundle): string;
package/dist/core/load.js CHANGED
@@ -7,6 +7,7 @@ import { checkSchema } from "./schema-check.js";
7
7
  import { bundleAdrs } from "./adrs.js";
8
8
  import { PROJECT_TEMPLATE, readAdr } from "./adr.js";
9
9
  import { parseYaml } from "./yaml.js";
10
+ import { isSkippedName, isWorkspaceFile } from "./workspace-files.js";
10
11
  const WORKSPACE_FILE = "workspace.yaml";
11
12
  const PROJECT_FILE = "project.yaml";
12
13
  const ADR_DIR = "adr";
@@ -117,14 +118,16 @@ async function walk(fs, root) {
117
118
  const dirs = [root];
118
119
  for (let i = 0; i < dirs.length; i++) {
119
120
  for (const entry of await fs.readDir(dirs[i])) {
120
- if (entry.name.startsWith(".") || entry.name === "node_modules")
121
+ if (isSkippedName(entry.name))
121
122
  continue;
122
123
  const path = join(dirs[i], entry.name);
123
124
  if (entry.isDirectory)
124
125
  dirs.push(path);
126
+ else if (!isWorkspaceFile(entry.name))
127
+ continue;
125
128
  else if (entry.name.endsWith(".yaml"))
126
129
  files.push(path);
127
- else if (entry.name.endsWith(".md"))
130
+ else
128
131
  markdown.push(path);
129
132
  }
130
133
  }
@@ -457,9 +460,5 @@ function toBundle(ws, options) {
457
460
  // Parsing fixes key order to the schema's.
458
461
  return Bundle.parse(bundle);
459
462
  }
460
- /** The Bundle as written to `workspace.bundle.json`: stable key order, two-space indent. */
461
- export function serializeBundle(bundle) {
462
- return JSON.stringify(Bundle.parse(bundle), null, 2) + "\n";
463
- }
464
463
  const asRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
465
464
  const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The one rule for which files make up a Workspace: `load`'s walk, the
3
+ * Checkout's fingerprint and (later) dev's watcher all use it. Pure and
4
+ * browser-safe, so core can use it.
5
+ */
6
+ /** Whether `load` skips a folder or file by its name: hidden ones (`.git`, editor swap files) and `node_modules`. */
7
+ export declare function isSkippedName(name: string): boolean;
8
+ /**
9
+ * Whether a path, relative to the Workspace root and `/` or `\` separated,
10
+ * is a Workspace file: no part of it is skipped, and it is a `.yaml` model
11
+ * file or an `.md` ADR.
12
+ */
13
+ export declare function isWorkspaceFile(path: string): boolean;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The one rule for which files make up a Workspace: `load`'s walk, the
3
+ * Checkout's fingerprint and (later) dev's watcher all use it. Pure and
4
+ * browser-safe, so core can use it.
5
+ */
6
+ /** Whether `load` skips a folder or file by its name: hidden ones (`.git`, editor swap files) and `node_modules`. */
7
+ export function isSkippedName(name) {
8
+ return name.startsWith(".") || name === "node_modules";
9
+ }
10
+ /**
11
+ * Whether a path, relative to the Workspace root and `/` or `\` separated,
12
+ * is a Workspace file: no part of it is skipped, and it is a `.yaml` model
13
+ * file or an `.md` ADR.
14
+ */
15
+ export function isWorkspaceFile(path) {
16
+ const parts = path.split(/[\\/]/).filter((part) => part !== "");
17
+ if (parts.length === 0 || parts.some(isSkippedName))
18
+ return false;
19
+ return path.endsWith(".yaml") || path.endsWith(".md");
20
+ }
package/dist/git.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
2
+ export declare function git(cwd: string, ...args: string[]): Promise<string>;
1
3
  /** HEAD's sha and commit time, so a Bundle built twice at one commit is byte-identical. Both null outside git or before the first commit. */
2
4
  export declare function gitHead(cwd: string): Promise<{
3
5
  commit: string | null;
package/dist/git.js CHANGED
@@ -1,10 +1,21 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { promisify } from "node:util";
3
+ const exec = promisify(execFile);
4
+ /** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
5
+ export async function git(cwd, ...args) {
6
+ try {
7
+ const { stdout } = await exec("git", ["-c", "core.quotePath=false", ...args], { cwd, maxBuffer: 1024 * 1024 * 1024, encoding: "utf8" });
8
+ return stdout;
9
+ }
10
+ catch (e) {
11
+ const err = e;
12
+ throw new Error(err.stderr?.trim() || err.message, { cause: e });
13
+ }
14
+ }
3
15
  /** HEAD's sha and commit time, so a Bundle built twice at one commit is byte-identical. Both null outside git or before the first commit. */
4
16
  export async function gitHead(cwd) {
5
17
  try {
6
- const { stdout } = await promisify(execFile)("git", ["log", "-1", "--format=%H %cI"], { cwd });
7
- const [commit, builtAt] = stdout.trim().split(" ");
18
+ const [commit, builtAt] = (await git(cwd, "log", "-1", "--format=%H %cI")).trim().split(" ");
8
19
  return { commit: commit || null, builtAt: builtAt || null };
9
20
  }
10
21
  catch {
@@ -14,8 +25,7 @@ export async function gitHead(cwd) {
14
25
  /** The top folder of the git checkout holding `cwd`, or null outside git. */
15
26
  export async function gitTopLevel(cwd) {
16
27
  try {
17
- const { stdout } = await promisify(execFile)("git", ["rev-parse", "--show-toplevel"], { cwd });
18
- return stdout.trim() || null;
28
+ return (await git(cwd, "rev-parse", "--show-toplevel")).trim() || null;
19
29
  }
20
30
  catch {
21
31
  return null;
@@ -46,8 +46,9 @@ export type GuideResult = {
46
46
  */
47
47
  export declare function authoringGuide(topic?: string): Promise<GuideResult>;
48
48
  /**
49
- * The thin SKILL.md that `archidocs init` installs in a repo. It only points
50
- * at the served guide, so it never goes stale, and uses only the portable
51
- * frontmatter fields.
49
+ * The thin SKILL.md that `archidocs init` installs in a repo, naming the
50
+ * command that runs archidocs there (`runner`, such as `npx archidocs`). It
51
+ * only points at the served guide, so it never goes stale, and uses only the
52
+ * portable frontmatter fields.
52
53
  */
53
- export declare const skillStub = "---\nname: archidocs-authoring\ndescription: Edit the Archidocs architecture Model. Use when bootstrapping a Project from code, adding or changing Services, Relationships, Deployments or Views, or proposing an ADR.\n---\n\n# Archidocs authoring\n\nBefore editing the Model, load the full guide: call the `get_authoring_guide` tool of the Archidocs MCP server, or run `archidocs guide` when no Archidocs MCP server is connected. It lists the topics; load the one for the task with `get_authoring_guide(topic)` or `archidocs guide <topic>`, and follow it.\n";
54
+ export declare const skillStub: (runner: string) => string;
@@ -42,16 +42,17 @@ export async function authoringGuide(topic) {
42
42
  return { ok: true, topic: found.id, text: await readFile(new URL(`topics/${found.id}.md`, GUIDE_DIR), "utf8") };
43
43
  }
44
44
  /**
45
- * The thin SKILL.md that `archidocs init` installs in a repo. It only points
46
- * at the served guide, so it never goes stale, and uses only the portable
47
- * frontmatter fields.
45
+ * The thin SKILL.md that `archidocs init` installs in a repo, naming the
46
+ * command that runs archidocs there (`runner`, such as `npx archidocs`). It
47
+ * only points at the served guide, so it never goes stale, and uses only the
48
+ * portable frontmatter fields.
48
49
  */
49
- export const skillStub = `---
50
+ export const skillStub = (runner) => `---
50
51
  name: ${SKILL_NAME}
51
52
  description: Edit the Archidocs architecture Model. Use when bootstrapping a Project from code, adding or changing Services, Relationships, Deployments or Views, or proposing an ADR.
52
53
  ---
53
54
 
54
55
  # Archidocs authoring
55
56
 
56
- Before editing the Model, load the full guide: call the \`get_authoring_guide\` tool of the Archidocs MCP server, or run \`archidocs guide\` when no Archidocs MCP server is connected. It lists the topics; load the one for the task with \`get_authoring_guide(topic)\` or \`archidocs guide <topic>\`, and follow it.
57
+ Before editing the Model, load the full guide: call the \`get_authoring_guide\` tool of the Archidocs MCP server, or run \`${runner} guide\` when no Archidocs MCP server is connected. It lists the topics; load the one for the task with \`get_authoring_guide(topic)\` or \`${runner} guide <topic>\`, and follow it.${runner === "archidocs" ? "" : ` In this repo, run every \`archidocs\` command as \`${runner}\`.`}
57
58
  `;
@@ -1,6 +1,4 @@
1
1
  import type { FileSystem } from "../core/fs.ts";
2
- /** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
3
- export declare function git(cwd: string, ...args: string[]): Promise<string>;
4
2
  /**
5
3
  * A read-only FileSystem over the tree of one commit. Paths are absolute
6
4
  * under `repoRoot`, as on disk; files are read with `git show`, so no
@@ -28,12 +26,4 @@ export declare function defaultBranch(repoRoot: string): Promise<string>;
28
26
  export declare function firstParentCommitsTouching(repoRoot: string, branch: string, path: string): Promise<CommitInfo[]>;
29
27
  /** Tag names by the commit they point at. */
30
28
  export declare function tagsByCommit(repoRoot: string): Promise<Map<string, string[]>>;
31
- /** Whether `point` is a date (`YYYY-MM-DD` or a full ISO 8601 time) rather than a ref. */
32
- export declare const isDate: (point: string) => boolean;
33
- /**
34
- * Resolves a point in time to a commit sha: a date to the last first-parent
35
- * default-branch commit at or before it, anything else as a git ref.
36
- * Undefined when there is no such commit.
37
- */
38
- export declare function resolvePoint(repoRoot: string, point: string): Promise<string | undefined>;
39
29
  export declare const joinRepo: (repoRoot: string, rel: string) => string;
@@ -1,18 +1,5 @@
1
- import { execFile } from "node:child_process";
2
1
  import { join, relative, sep } from "node:path";
3
- import { promisify } from "node:util";
4
- const exec = promisify(execFile);
5
- /** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
6
- export async function git(cwd, ...args) {
7
- try {
8
- const { stdout } = await exec("git", ["-c", "core.quotePath=false", ...args], { cwd, maxBuffer: 1024 * 1024 * 1024, encoding: "utf8" });
9
- return stdout;
10
- }
11
- catch (e) {
12
- const err = e;
13
- throw new Error(err.stderr?.trim() || err.message, { cause: e });
14
- }
15
- }
2
+ import { git } from "../git.js";
16
3
  /**
17
4
  * A read-only FileSystem over the tree of one commit. Paths are absolute
18
5
  * under `repoRoot`, as on disk; files are read with `git show`, so no
@@ -107,20 +94,4 @@ export async function tagsByCommit(repoRoot) {
107
94
  }
108
95
  return map;
109
96
  }
110
- /** Whether `point` is a date (`YYYY-MM-DD` or a full ISO 8601 time) rather than a ref. */
111
- export const isDate = (point) => /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:?\d{2})?)?$/.test(point);
112
- /** A bare date means the end of that day (UTC); a time is taken as given. */
113
- const endOf = (date) => (/^\d{4}-\d{2}-\d{2}$/.test(date) ? `${date}T23:59:59Z` : date);
114
- /**
115
- * Resolves a point in time to a commit sha: a date to the last first-parent
116
- * default-branch commit at or before it, anything else as a git ref.
117
- * Undefined when there is no such commit.
118
- */
119
- export async function resolvePoint(repoRoot, point) {
120
- if (isDate(point)) {
121
- const sha = (await git(repoRoot, "rev-list", "-1", "--first-parent", `--before=${endOf(point)}`, await defaultBranch(repoRoot)).catch(() => "")).trim();
122
- return sha || undefined;
123
- }
124
- return (await git(repoRoot, "rev-parse", "--verify", "--quiet", "--end-of-options", `${point}^{commit}`).catch(() => "")).trim() || undefined;
125
- }
126
97
  export const joinRepo = (repoRoot, rel) => (rel === "" ? repoRoot : join(repoRoot, rel));
@@ -1,8 +1,11 @@
1
- import { type ChangeCounts } from "../core/index.ts";
2
1
  import { Bundle } from "../schema/bundle.ts";
2
+ import { type PreviewMark, type RevisionIndex } from "../revisions/index.ts";
3
3
  import { type CommitInfo } from "./git.ts";
4
- export { migrateBundle, migrations, type Migration } from "./migrate.ts";
5
- export { resolvePoint, isDate, type CommitInfo } from "./git.ts";
4
+ import { type SiteContent } from "./site.ts";
5
+ export { migrateBundle, migrations, type Migration } from "../revisions/index.ts";
6
+ export { type CommitInfo } from "./git.ts";
7
+ export { writeSite, type PastBundle, type SiteContent } from "./site.ts";
8
+ export { resolvePoint, pointMessage, type PointFailure, type ResolvedPoint } from "./points.ts";
6
9
  /** The cache a checkout keeps past Bundles and their index entries in, under the repo root. */
7
10
  export declare const CACHE_DIR: string;
8
11
  /** Where a Workspace's history lives: its git repo and the Workspace root within it. */
@@ -11,23 +14,6 @@ export interface History {
11
14
  /** The Workspace root relative to the repo root, with `/` separators; "" when they are the same folder. */
12
15
  workspacePath: string;
13
16
  }
14
- /** One Revision as the index records it; `bundle: false` marks a Revision whose Bundle was dropped. */
15
- export interface RevisionEntry {
16
- sha: string;
17
- date: string;
18
- subject: string;
19
- author: string;
20
- tags: string[];
21
- /** Changes against the previous Revision (or an empty Model for the first). */
22
- counts: ChangeCounts;
23
- changedIds: string[];
24
- bundle: boolean;
25
- }
26
- export interface RevisionIndex {
27
- schemaVersion: number;
28
- /** Newest first. */
29
- revisions: RevisionEntry[];
30
- }
31
17
  export declare const history: (repoRoot: string, workspaceRoot: string) => History;
32
18
  /**
33
19
  * The Revisions: first-parent default-branch commits that changed something
@@ -66,19 +52,22 @@ export declare function buildHistory(h: History, options?: {
66
52
  }): Promise<BuildResult>;
67
53
  /** Past Bundles a published site keeps by default: the latest 200 Revisions, plus every tagged one. */
68
54
  export declare const DEFAULT_KEEP = 200;
55
+ /** The latest Bundle and the Workspace's name, which a site holds beside its history. */
56
+ export type Latest = Pick<SiteContent, "bundle" | "workspace">;
69
57
  export interface PublishResult {
70
58
  revisions: number;
71
59
  kept: number;
72
60
  }
73
61
  /**
74
- * Writes the site's `bundles/` folder: `bundles/<sha>.json` for each kept
75
- * Revision and `bundles/index.json` listing every Revision. Kept are the
62
+ * Writes a site through {@link writeSite}: the latest Bundle and its name,
63
+ * `bundles/<sha>.json` for each kept Revision and `bundles/index.json`
64
+ * listing every Revision. Kept are the
76
65
  * latest `keep` Revisions plus every tagged one; the others stay in the
77
66
  * index with `bundle: false`. Bundles come from the checkout's cache,
78
67
  * backfilled from git first, so nothing is fetched. A Bundle file left in
79
68
  * the folder by an earlier build is removed once its Revision is dropped.
80
69
  */
81
- export declare function publishHistory(h: History, out: string, { keep }?: {
70
+ export declare function publishHistory(h: History, out: string, latest: Latest, { keep }?: {
82
71
  keep?: number | "all";
83
72
  }): Promise<PublishResult>;
84
73
  /** The two sides a preview site Compares: the base branch's latest Revision and the PR head. */
@@ -97,18 +86,13 @@ export interface PreviewSides {
97
86
  * yet) and HEAD. It never fetches; a missing `origin/<base>` is an error.
98
87
  */
99
88
  export declare function previewSides(h: History, base: string): Promise<PreviewSides>;
100
- /** What a preview site's `bundles/index.json` adds: the base branch and both sides' shas, so the viewer opens with Compare "base → PR". */
101
- export interface PreviewMark {
102
- base: string;
103
- baseSha: string;
104
- headSha: string;
105
- }
106
89
  /**
107
- * Writes a preview site's `bundles/`: the base's Bundle, the head's (the
90
+ * Writes a preview site through {@link writeSite}: the head as the latest
91
+ * Bundle, and in a cleared `bundles/` the base's Bundle, the head's (the
108
92
  * checkout as built) and an index of the two, newest first, marked with
109
93
  * `preview`. The head's counts are against the base.
110
94
  */
111
- export declare function publishPreview(h: History, out: string, sides: PreviewSides, head: Bundle): Promise<PreviewMark>;
95
+ export declare function publishPreview(h: History, out: string, sides: PreviewSides, head: Bundle, workspace?: string): Promise<PreviewMark>;
112
96
  /** The base branch origin/HEAD names, else `main`. */
113
97
  export declare function defaultBaseBranch(repoRoot: string): Promise<string>;
114
98
  /** A point in time that names no commit, or history that can't be read. */