@phnx-labs/artifacts-cli 0.9.13 → 0.11.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 (140) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +7 -9
  3. package/dist/cli.d.ts +1 -2
  4. package/dist/cli.js +34 -190
  5. package/dist/cli.js.map +1 -1
  6. package/dist/commands/auth.d.ts +3 -1
  7. package/dist/commands/auth.js +17 -18
  8. package/dist/commands/auth.js.map +1 -1
  9. package/dist/commands/comments.js +2 -2
  10. package/dist/commands/comments.js.map +1 -1
  11. package/dist/commands/new.js +3 -3
  12. package/dist/commands/new.js.map +1 -1
  13. package/dist/commands/share.d.ts +58 -111
  14. package/dist/commands/share.js +314 -638
  15. package/dist/commands/share.js.map +1 -1
  16. package/dist/lib/collab.d.ts +3 -3
  17. package/dist/lib/collab.js +183 -13
  18. package/dist/lib/collab.js.map +1 -1
  19. package/dist/lib/components.js +0 -1
  20. package/dist/lib/components.js.map +1 -1
  21. package/dist/lib/config.d.ts +0 -17
  22. package/dist/lib/config.js.map +1 -1
  23. package/dist/lib/embedded-html.d.ts +1 -1
  24. package/dist/lib/embedded-html.js +0 -15
  25. package/dist/lib/embedded-html.js.map +1 -1
  26. package/dist/lib/freshness.d.ts +2 -6
  27. package/dist/lib/freshness.js +4 -33
  28. package/dist/lib/freshness.js.map +1 -1
  29. package/dist/lib/header-actions.d.ts +10 -37
  30. package/dist/lib/header-actions.js +19 -94
  31. package/dist/lib/header-actions.js.map +1 -1
  32. package/dist/lib/metadata-menu.d.ts +10 -33
  33. package/dist/lib/metadata-menu.js +12 -51
  34. package/dist/lib/metadata-menu.js.map +1 -1
  35. package/dist/lib/reader-anchors.d.ts +3 -3
  36. package/dist/lib/reader-anchors.js +7 -4
  37. package/dist/lib/reader-anchors.js.map +1 -1
  38. package/dist/lib/render.d.ts +2 -19
  39. package/dist/lib/render.js +37 -321
  40. package/dist/lib/render.js.map +1 -1
  41. package/dist/lib/section-collapse.d.ts +1 -2
  42. package/dist/lib/section-collapse.js +1 -2
  43. package/dist/lib/section-collapse.js.map +1 -1
  44. package/dist/lib/selection-toolbar.d.ts +9 -0
  45. package/dist/lib/selection-toolbar.js +49 -0
  46. package/dist/lib/selection-toolbar.js.map +1 -0
  47. package/dist/lib/share/backend.d.ts +8 -75
  48. package/dist/lib/share/backend.js +11 -123
  49. package/dist/lib/share/backend.js.map +1 -1
  50. package/dist/lib/share/config.d.ts +0 -79
  51. package/dist/lib/share/config.js +3 -175
  52. package/dist/lib/share/config.js.map +1 -1
  53. package/dist/lib/share/delete.d.ts +3 -14
  54. package/dist/lib/share/delete.js +8 -12
  55. package/dist/lib/share/delete.js.map +1 -1
  56. package/dist/lib/share/http-error.d.ts +12 -0
  57. package/dist/lib/share/http-error.js +32 -0
  58. package/dist/lib/share/http-error.js.map +1 -1
  59. package/dist/lib/share/media.d.ts +1 -6
  60. package/dist/lib/share/media.js +9 -17
  61. package/dist/lib/share/media.js.map +1 -1
  62. package/dist/lib/share/og.d.ts +0 -3
  63. package/dist/lib/share/og.js +2 -4
  64. package/dist/lib/share/og.js.map +1 -1
  65. package/dist/lib/share/people.d.ts +56 -0
  66. package/dist/lib/share/people.js +139 -0
  67. package/dist/lib/share/people.js.map +1 -0
  68. package/dist/lib/share/provision.d.ts +7 -120
  69. package/dist/lib/share/provision.js +30 -290
  70. package/dist/lib/share/provision.js.map +1 -1
  71. package/dist/lib/share/publish.d.ts +21 -63
  72. package/dist/lib/share/publish.js +44 -131
  73. package/dist/lib/share/publish.js.map +1 -1
  74. package/dist/lib/share/visibility.d.ts +13 -36
  75. package/dist/lib/share/visibility.js +8 -35
  76. package/dist/lib/share/visibility.js.map +1 -1
  77. package/dist/lib/share/worker-media-template.js +1 -1
  78. package/dist/lib/share/worker-people-template.d.ts +1 -0
  79. package/dist/lib/share/worker-people-template.js +491 -0
  80. package/dist/lib/share/worker-people-template.js.map +1 -0
  81. package/dist/lib/share/worker-publish-template.d.ts +1 -1
  82. package/dist/lib/share/worker-publish-template.js +5 -0
  83. package/dist/lib/share/worker-publish-template.js.map +1 -1
  84. package/dist/lib/share/worker-template.d.ts +2 -14
  85. package/dist/lib/share/worker-template.js +303 -52
  86. package/dist/lib/share/worker-template.js.map +1 -1
  87. package/dist/lib/templates.d.ts +1 -2
  88. package/dist/lib/templates.js +1 -19
  89. package/dist/lib/templates.js.map +1 -1
  90. package/dist/lib/validate.js +1 -29
  91. package/dist/lib/validate.js.map +1 -1
  92. package/package.json +1 -4
  93. package/dist/commands/answers.d.ts +0 -6
  94. package/dist/commands/answers.js +0 -91
  95. package/dist/commands/answers.js.map +0 -1
  96. package/dist/commands/favorite.d.ts +0 -9
  97. package/dist/commands/favorite.js +0 -59
  98. package/dist/commands/favorite.js.map +0 -1
  99. package/dist/commands/history.d.ts +0 -4
  100. package/dist/commands/history.js +0 -29
  101. package/dist/commands/history.js.map +0 -1
  102. package/dist/commands/notes.d.ts +0 -5
  103. package/dist/commands/notes.js +0 -28
  104. package/dist/commands/notes.js.map +0 -1
  105. package/dist/lib/browser-detect.d.ts +0 -28
  106. package/dist/lib/browser-detect.js +0 -126
  107. package/dist/lib/browser-detect.js.map +0 -1
  108. package/dist/lib/favorites.d.ts +0 -73
  109. package/dist/lib/favorites.js +0 -180
  110. package/dist/lib/favorites.js.map +0 -1
  111. package/dist/lib/github.d.ts +0 -14
  112. package/dist/lib/github.js +0 -36
  113. package/dist/lib/github.js.map +0 -1
  114. package/dist/lib/highlights.d.ts +0 -11
  115. package/dist/lib/highlights.js +0 -116
  116. package/dist/lib/highlights.js.map +0 -1
  117. package/dist/lib/link-previews.d.ts +0 -67
  118. package/dist/lib/link-previews.js +0 -427
  119. package/dist/lib/link-previews.js.map +0 -1
  120. package/dist/lib/notes.d.ts +0 -22
  121. package/dist/lib/notes.js +0 -22
  122. package/dist/lib/notes.js.map +0 -1
  123. package/dist/lib/pdf.d.ts +0 -13
  124. package/dist/lib/pdf.js +0 -66
  125. package/dist/lib/pdf.js.map +0 -1
  126. package/dist/lib/revisions.d.ts +0 -102
  127. package/dist/lib/revisions.js +0 -445
  128. package/dist/lib/revisions.js.map +0 -1
  129. package/dist/lib/share/analytics.d.ts +0 -13
  130. package/dist/lib/share/analytics.js +0 -46
  131. package/dist/lib/share/analytics.js.map +0 -1
  132. package/dist/lib/share/capture.d.ts +0 -31
  133. package/dist/lib/share/capture.js +0 -175
  134. package/dist/lib/share/capture.js.map +0 -1
  135. package/dist/lib/tokens.d.ts +0 -12
  136. package/dist/lib/tokens.js +0 -28
  137. package/dist/lib/tokens.js.map +0 -1
  138. package/dist/lib/worksheet.d.ts +0 -94
  139. package/dist/lib/worksheet.js +0 -394
  140. package/dist/lib/worksheet.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"pdf.js","sourceRoot":"","sources":["../../src/lib/pdf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAU,CAAC;AAc3D,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,IAAK,WAAiC,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAkB,CAAC;IAClF,MAAM,IAAI,KAAK,CAAC,8BAA8B,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,QAAgB,EAAE,OAAe,EAAE,UAA4B,EAAE;IAC/F,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,KAAK,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C7B,MAAM,EAAE,GAAG,MAAM,IAAI;gBACrB,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE;gBACxD,eAAe,EAAE,IAAI;gBACrB,MAAM,EAAE,IAAI;gBACZ,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;YACH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QACzF,CAAC;QACD,MAAM,IAAI,CAAC,GAAG,CAAC;YACb,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,QAAQ;YAChB,eAAe,EAAE,IAAI;YACrB,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QACH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC7C,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;AACH,CAAC"}
@@ -1,102 +0,0 @@
1
- /**
2
- * Revision storage: an artifact's rendered history, keyed by the identity of its
3
- * *source* file (not its output path), so re-rendering the same document to two
4
- * destinations records one shared lineage. Every distinct rendered state is kept
5
- * forever — nothing here ever deletes a revision. The module owns the whole
6
- * serialize → render → write transaction under a per-source filesystem lock, so
7
- * concurrent renders of the same source never interleave or corrupt the index.
8
- *
9
- * The authoritative index is `manifest.json`; a snapshot's bytes are only
10
- * *referenced* by it. The manifest is always written last and atomically, so a
11
- * crash mid-commit can leave an orphaned snapshot directory (harmless) but never
12
- * a dangling index entry that points at bytes which were never written.
13
- */
14
- /** One entry as shown to a reader: which revision, and when it was first seen. */
15
- export interface RevisionSummary {
16
- number: number;
17
- createdAt: string;
18
- }
19
- /**
20
- * The public shape handed to a decorator and returned from {@link saveRevision}.
21
- * `sourcePath` is the artifact's real on-disk source path — a local path the
22
- * caller is expected to keep OUT of any reader-facing HTML it renders.
23
- */
24
- export interface RevisionHistory {
25
- id: string;
26
- sourcePath: string;
27
- revisions: RevisionSummary[];
28
- }
29
- export declare const LOCK_OPTIONS: {
30
- stale: number;
31
- update: number;
32
- retries: {
33
- retries: number;
34
- factor: number;
35
- minTimeout: number;
36
- maxTimeout: number;
37
- };
38
- realpath: true;
39
- };
40
- /** The root under which every source's history directory lives. */
41
- export declare function historyRoot(): string;
42
- /** Public form of {@link resolveTarget} for sibling stores (favorites) that key
43
- * records by the same artifact identity. */
44
- export declare function artifactTarget(sourceOrId: string): {
45
- id: string;
46
- sourcePath?: string;
47
- };
48
- /**
49
- * Content fingerprint of a rendered document, insensitive to the two surfaces
50
- * that change on every write regardless of content: the source-mtime freshness
51
- * stamp and the whole-document content-hash marker (which itself folds in that
52
- * mtime). Everything else — prose, embedded assets, design tokens — contributes,
53
- * so a re-render with unchanged inputs fingerprints identically and reuses the
54
- * latest revision rather than minting a hollow new one.
55
- */
56
- export declare function fingerprint(baseHtml: string): string;
57
- /**
58
- * Render `source` to `out`, recording a revision when the rendered content has
59
- * changed. The whole transaction runs under a per-source lock:
60
- *
61
- * 1. The source bytes are captured, `render()` runs, and the source is re-read;
62
- * an error diagnostic, or a source edited mid-render, aborts before anything
63
- * is written — output and history are left untouched.
64
- * 2. The base is fingerprinted. An unchanged fingerprint reuses the latest
65
- * revision (number and timestamp); a change (or first render) mints the next.
66
- * 3. `decorate()` renders the reader-facing document from the base and history.
67
- * 4. The decorated document is written to `out` (its parent directory created as
68
- * needed) *before* the history is committed, so a bad destination never
69
- * consumes a revision number. Any prior output is captured first.
70
- * 5. Only then is a new revision committed: its source bytes and frozen snapshot
71
- * are staged, moved into place (clearing any orphan from an interrupted prior
72
- * commit), and the manifest is rewritten last, so a failure can never leave a
73
- * dangling authoritative index entry. A commit that fails after the output was
74
- * written rolls that output back to its prior bytes.
75
- *
76
- * The returned `html` is the decorated document (what was written to `out`).
77
- */
78
- export declare function saveRevision<T extends {
79
- html: string;
80
- diagnostics: Array<{
81
- level: string;
82
- message: string;
83
- }>;
84
- }>(source: string, out: string, render: () => Promise<T>, decorate: (html: string, history: RevisionHistory) => string): Promise<T & {
85
- revision?: RevisionHistory;
86
- }>;
87
- /**
88
- * The public revision history for a source path or id. A missing history returns
89
- * an empty one (no revisions) rather than throwing, so callers can render "no
90
- * history yet" uniformly; a *corrupt* manifest still throws (see readManifest).
91
- * When called with a bare id whose manifest is missing, `sourcePath` is unknown
92
- * and returned empty.
93
- */
94
- export declare function readHistory(sourceOrId: string): RevisionHistory;
95
- /**
96
- * Absolute path to a revision's saved snapshot HTML, for a viewer to open. The
97
- * number must name a real revision; the resolved path is confined to the
98
- * source's own history directory (no traversal via a crafted manifest), and the
99
- * stored bytes are verified against their recorded hash before the path is
100
- * handed back.
101
- */
102
- export declare function revisionSnapshot(sourceOrId: string, number: number): string;
@@ -1,445 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { randomBytes } from 'node:crypto';
3
- import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
4
- import { homedir } from 'node:os';
5
- import { basename, dirname, join, resolve, sep } from 'node:path';
6
- import { lock } from 'proper-lockfile';
7
- const MANIFEST_SCHEMA = 'artifacts.revisions.v1';
8
- const MANIFEST_FILE = 'manifest.json';
9
- const REVISIONS_DIR = 'revisions';
10
- const SOURCE_FILE = 'source';
11
- const HTML_FILE = 'render.html';
12
- // Private permissions: an artifact's source and rendered history can carry
13
- // unpublished content, so the on-disk store is owner-only.
14
- const DIR_MODE = 0o700;
15
- const FILE_MODE = 0o600;
16
- // Lock tuning. `stale` bounds how long a crashed writer can block others before
17
- // its lock is treated as abandoned; `update` is the heartbeat that keeps a live
18
- // writer's lock fresh well inside that window; `retries` bounds how long a
19
- // waiter blocks for a busy lock before giving up.
20
- export const LOCK_OPTIONS = {
21
- stale: 20000,
22
- update: 5000,
23
- retries: { retries: 40, factor: 1.4, minTimeout: 50, maxTimeout: 1000 },
24
- realpath: true,
25
- };
26
- /** The root under which every source's history directory lives. */
27
- export function historyRoot() {
28
- return process.env.ARTIFACTS_HISTORY_DIR || join(homedir(), '.agents', 'artifact-history');
29
- }
30
- /**
31
- * Canonical, symlink-resolved absolute path for a source. A symlink and its
32
- * target therefore share one identity (and one lineage). When the path does not
33
- * exist yet (e.g. a read against a since-deleted source), fall back to a plain
34
- * absolute resolution so a stable id can still be derived.
35
- */
36
- function canonicalSource(source) {
37
- try {
38
- return realpathSync(resolve(source));
39
- }
40
- catch {
41
- return resolve(source);
42
- }
43
- }
44
- function sha256Hex(input) {
45
- return createHash('sha256').update(input).digest('hex');
46
- }
47
- /** Identity of a source: SHA-256 over its canonical real path. */
48
- function sourceId(realSource) {
49
- return sha256Hex(realSource);
50
- }
51
- /** Resolve a caller-supplied "source path OR id" into an id and (when known) a path. */
52
- function resolveTarget(sourceOrId) {
53
- if (/^[0-9a-f]{64}$/.test(sourceOrId))
54
- return { id: sourceOrId };
55
- const real = canonicalSource(sourceOrId);
56
- return { id: sourceId(real), sourcePath: real };
57
- }
58
- /** Public form of {@link resolveTarget} for sibling stores (favorites) that key
59
- * records by the same artifact identity. */
60
- export function artifactTarget(sourceOrId) {
61
- return resolveTarget(sourceOrId);
62
- }
63
- function idDirFor(id) {
64
- return join(historyRoot(), id);
65
- }
66
- function pad(n) {
67
- return String(n).padStart(4, '0');
68
- }
69
- /**
70
- * Content fingerprint of a rendered document, insensitive to the two surfaces
71
- * that change on every write regardless of content: the source-mtime freshness
72
- * stamp and the whole-document content-hash marker (which itself folds in that
73
- * mtime). Everything else — prose, embedded assets, design tokens — contributes,
74
- * so a re-render with unchanged inputs fingerprints identically and reuses the
75
- * latest revision rather than minting a hollow new one.
76
- */
77
- export function fingerprint(baseHtml) {
78
- const normalized = baseHtml
79
- .replace(/<meta name="artifacts-content-hash" content="[^"]*">/g, '')
80
- .replace(/<time\b[^>]*\bdata-label="Source updated"[^>]*>[^<]*<\/time>/g, '');
81
- return sha256Hex(normalized);
82
- }
83
- /**
84
- * Freeze a decorated document into an immutable snapshot: strip the content-hash
85
- * marker so the live-reload poll — whose own guard returns early when the marker
86
- * is absent — never fires against a page that has no server to re-render it.
87
- * Every other render surface (creator line, timestamps, revision menu) is kept.
88
- */
89
- function freezeSnapshot(decoratedHtml) {
90
- return decoratedHtml.replace(/<meta name="artifacts-content-hash" content="[^"]*">\n?/g, '');
91
- }
92
- function isStoredRevision(value) {
93
- if (typeof value !== 'object' || value === null)
94
- return false;
95
- const v = value;
96
- return (typeof v.number === 'number' &&
97
- Number.isInteger(v.number) &&
98
- typeof v.createdAt === 'string' &&
99
- typeof v.fingerprint === 'string' &&
100
- typeof v.sourceFile === 'string' &&
101
- typeof v.htmlFile === 'string' &&
102
- typeof v.sourceSha256 === 'string' &&
103
- typeof v.htmlSha256 === 'string');
104
- }
105
- function isManifest(value) {
106
- if (typeof value !== 'object' || value === null)
107
- return false;
108
- const v = value;
109
- return (v.schema === MANIFEST_SCHEMA &&
110
- typeof v.id === 'string' &&
111
- typeof v.sourcePath === 'string' &&
112
- Array.isArray(v.revisions) &&
113
- v.revisions.every(isStoredRevision));
114
- }
115
- const HEX_256 = /^[0-9a-f]{64}$/;
116
- const ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;
117
- /**
118
- * Beyond shape, enforce the invariants a swapped or hand-edited manifest could
119
- * otherwise satisfy while still handing back the wrong artifact or version: the
120
- * id must be this source's hash and match the request, revision numbers must be
121
- * exactly 1..n in order, timestamps must be real ISO instants, every hash must
122
- * be a 64-hex digest, and the file names must be the fixed store names (so a
123
- * crafted path can never redirect a snapshot read).
124
- */
125
- function assertManifestIntegrity(manifest, requestedId, file) {
126
- const fail = (why) => {
127
- throw new Error(`Corrupt revision manifest at ${file}: ${why}`);
128
- };
129
- if (!HEX_256.test(manifest.id))
130
- fail('id is not a sha-256 digest');
131
- if (manifest.id !== requestedId)
132
- fail('id does not match the requested source');
133
- if (sha256Hex(manifest.sourcePath) !== manifest.id)
134
- fail('id does not match its source path');
135
- manifest.revisions.forEach((r, i) => {
136
- if (r.number !== i + 1)
137
- fail(`revision numbers are not the sequence 1..n (index ${i} is ${r.number})`);
138
- if (r.sourceFile !== SOURCE_FILE || r.htmlFile !== HTML_FILE)
139
- fail(`revision ${r.number} names an unexpected file`);
140
- if (!HEX_256.test(r.fingerprint))
141
- fail(`revision ${r.number} has a malformed fingerprint`);
142
- if (!HEX_256.test(r.sourceSha256) || !HEX_256.test(r.htmlSha256))
143
- fail(`revision ${r.number} has a malformed content hash`);
144
- if (!ISO_INSTANT.test(r.createdAt) || Number.isNaN(Date.parse(r.createdAt)))
145
- fail(`revision ${r.number} has a malformed timestamp`);
146
- });
147
- }
148
- /**
149
- * Read a source's manifest. A missing manifest is a fresh, empty history. A
150
- * present-but-unparseable, wrong-shaped, or integrity-violating manifest is
151
- * fatal: it is never silently reset, because that would erase a real history
152
- * behind a transient read glitch. Fail loudly so the corruption is investigated,
153
- * not overwritten.
154
- */
155
- function readManifest(idDir, id, sourcePath) {
156
- const file = join(idDir, MANIFEST_FILE);
157
- if (!existsSync(file))
158
- return { schema: MANIFEST_SCHEMA, id, sourcePath, revisions: [] };
159
- const raw = readFileSync(file, 'utf8');
160
- let parsed;
161
- try {
162
- parsed = JSON.parse(raw);
163
- }
164
- catch (err) {
165
- throw new Error(`Corrupt revision manifest at ${file}: ${err.message}`);
166
- }
167
- if (!isManifest(parsed)) {
168
- throw new Error(`Corrupt revision manifest at ${file}: unexpected shape`);
169
- }
170
- assertManifestIntegrity(parsed, id, file);
171
- return parsed;
172
- }
173
- /**
174
- * Atomic single-file write: create a unique temp file in the destination
175
- * directory, fsync it, then rename over the target. A rename within one
176
- * directory is atomic, so a reader never sees a half-written file and a crash
177
- * never truncates an existing one. An explicit `mode` is forced past any umask
178
- * (used for the private history store); when omitted the platform default
179
- * (`0o666 & ~umask`) applies, so a reader-facing output keeps normal
180
- * permissions.
181
- */
182
- function atomicWrite(target, data, mode) {
183
- const tmp = join(dirname(target), `.${basename(target)}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`);
184
- const fd = mode === undefined ? openSync(tmp, 'wx') : openSync(tmp, 'wx', mode);
185
- try {
186
- writeFileSync(fd, data);
187
- fsyncSync(fd);
188
- }
189
- finally {
190
- closeSync(fd);
191
- }
192
- if (mode !== undefined)
193
- chmodSync(tmp, mode);
194
- renameSync(tmp, target);
195
- }
196
- /**
197
- * The real path a reader-facing output write should land on. An existing symlink
198
- * resolves to its target (so a link is written through, not clobbered by a
199
- * regular file); a plain or not-yet-existing path resolves to its absolute form.
200
- */
201
- function resolveOutputTarget(out) {
202
- try {
203
- return realpathSync(out);
204
- }
205
- catch {
206
- const absolute = resolve(out);
207
- const parent = dirname(absolute);
208
- if (parent === absolute)
209
- return absolute;
210
- // Resolve existing ancestors even before the file exists. Otherwise the
211
- // first write through an aliased directory and subsequent realpath writes
212
- // would acquire different destination locks.
213
- return join(resolveOutputTarget(parent), basename(absolute));
214
- }
215
- }
216
- function hasError(diagnostics) {
217
- return diagnostics.some((d) => d.level === 'error');
218
- }
219
- /**
220
- * Render `source` to `out`, recording a revision when the rendered content has
221
- * changed. The whole transaction runs under a per-source lock:
222
- *
223
- * 1. The source bytes are captured, `render()` runs, and the source is re-read;
224
- * an error diagnostic, or a source edited mid-render, aborts before anything
225
- * is written — output and history are left untouched.
226
- * 2. The base is fingerprinted. An unchanged fingerprint reuses the latest
227
- * revision (number and timestamp); a change (or first render) mints the next.
228
- * 3. `decorate()` renders the reader-facing document from the base and history.
229
- * 4. The decorated document is written to `out` (its parent directory created as
230
- * needed) *before* the history is committed, so a bad destination never
231
- * consumes a revision number. Any prior output is captured first.
232
- * 5. Only then is a new revision committed: its source bytes and frozen snapshot
233
- * are staged, moved into place (clearing any orphan from an interrupted prior
234
- * commit), and the manifest is rewritten last, so a failure can never leave a
235
- * dangling authoritative index entry. A commit that fails after the output was
236
- * written rolls that output back to its prior bytes.
237
- *
238
- * The returned `html` is the decorated document (what was written to `out`).
239
- */
240
- export async function saveRevision(source, out, render, decorate) {
241
- const realSource = canonicalSource(source);
242
- const id = sourceId(realSource);
243
- const idDir = idDirFor(id);
244
- mkdirSync(idDir, { recursive: true, mode: DIR_MODE });
245
- const release = await lock(idDir, LOCK_OPTIONS);
246
- try {
247
- // Read the source before rendering, so the archived bytes are exactly those
248
- // the renderer consumed rather than whatever the file holds after it returns.
249
- const sourceBefore = readFileSync(realSource);
250
- const result = await render();
251
- // A render error leaves output and history untouched — nothing is written.
252
- if (hasError(result.diagnostics))
253
- return result;
254
- // If the source was edited while the renderer ran, the rendered HTML and the
255
- // bytes on disk may no longer correspond. Never archive a mismatched pair:
256
- // abort untouched and let the caller re-render once the edit settles.
257
- const sourceAfter = readFileSync(realSource);
258
- if (!sourceBefore.equals(sourceAfter)) {
259
- return {
260
- ...result,
261
- diagnostics: [
262
- ...result.diagnostics,
263
- { level: 'error', message: `Source ${realSource} changed during render; nothing was archived` },
264
- ],
265
- };
266
- }
267
- const base = result.html;
268
- const fp = fingerprint(base);
269
- const manifest = readManifest(idDir, id, realSource);
270
- const latest = manifest.revisions.at(-1);
271
- const isNew = !latest || latest.fingerprint !== fp;
272
- const number = isNew ? (latest?.number ?? 0) + 1 : latest.number;
273
- const createdAt = isNew ? new Date().toISOString() : latest.createdAt;
274
- const summaries = manifest.revisions.map((r) => ({ number: r.number, createdAt: r.createdAt }));
275
- if (isNew)
276
- summaries.push({ number, createdAt });
277
- const history = { id, sourcePath: realSource, revisions: summaries };
278
- const decorated = decorate(base, history);
279
- // Follow an existing output symlink to its real target (matching plain
280
- // writeFileSync, which writes through a link rather than replacing it), and
281
- // refuse to overwrite the source itself with its own rendering.
282
- const outTarget = resolveOutputTarget(out);
283
- if (outTarget === realSource) {
284
- return {
285
- ...result,
286
- diagnostics: [...result.diagnostics, { level: 'error', message: `Refusing to write output over the source ${realSource}` }],
287
- };
288
- }
289
- // Stage the new revision's bytes before touching the destination. The source
290
- // snapshot is the verified-stable bytes read above, so the archived Markdown
291
- // always matches the archived HTML.
292
- let stagingDir;
293
- let snapshotSha = '';
294
- let sourceSha = '';
295
- if (isNew) {
296
- const snapshot = freezeSnapshot(decorated);
297
- sourceSha = sha256Hex(sourceBefore);
298
- snapshotSha = sha256Hex(snapshot);
299
- stagingDir = join(idDir, `.staging-${process.pid}-${randomBytes(6).toString('hex')}`);
300
- mkdirSync(stagingDir, { mode: DIR_MODE });
301
- atomicWrite(join(stagingDir, SOURCE_FILE), sourceBefore, FILE_MODE);
302
- atomicWrite(join(stagingDir, HTML_FILE), snapshot, FILE_MODE);
303
- }
304
- // Write the reader-facing output first, creating its parent directory like
305
- // compileArtifact does and preserving an existing file's permissions (a fresh
306
- // file gets the platform default, never the private archive mode). A bad
307
- // destination must not consume a revision number, so on failure clean up the
308
- // staged snapshot and surface an error diagnostic — the history is left
309
- // exactly as it was. Capture any prior output and its mode so a later commit
310
- // failure can restore it.
311
- // Every source takes its own lock first, then this shared destination lock.
312
- // Separate source histories writing one output cannot race a failed commit's
313
- // rollback. A private hash-keyed lock also works before the output exists.
314
- const outputLockDir = join(historyRoot(), '.output-locks', sha256Hex(outTarget));
315
- mkdirSync(outputLockDir, { recursive: true, mode: DIR_MODE });
316
- const releaseOutput = await lock(outputLockDir, LOCK_OPTIONS);
317
- try {
318
- const outExisted = existsSync(outTarget);
319
- const prevOutput = outExisted ? readFileSync(outTarget) : undefined;
320
- const outMode = outExisted ? statSync(outTarget).mode & 0o777 : undefined;
321
- try {
322
- mkdirSync(dirname(outTarget), { recursive: true });
323
- atomicWrite(outTarget, decorated, outMode);
324
- }
325
- catch (err) {
326
- if (stagingDir)
327
- rmSync(stagingDir, { recursive: true, force: true });
328
- return {
329
- ...result,
330
- diagnostics: [...result.diagnostics, { level: 'error', message: `Could not write ${out}: ${err.message}` }],
331
- };
332
- }
333
- // Commit the revision. The snapshot directory is moved into place — first
334
- // clearing any orphan a previously interrupted commit may have left (the
335
- // manifest is authoritative, so an unreferenced revision directory is safe to
336
- // drop) — then the manifest is rewritten last and atomically. If the commit
337
- // fails after the output was written, roll the output back so it stays
338
- // consistent with the still-authoritative, unchanged manifest.
339
- if (isNew && stagingDir) {
340
- try {
341
- const revDir = join(idDir, REVISIONS_DIR, pad(number));
342
- mkdirSync(join(idDir, REVISIONS_DIR), { recursive: true, mode: DIR_MODE });
343
- if (existsSync(revDir)) {
344
- // Preserve interrupted snapshots: the output may have briefly exposed
345
- // them before its manifest committed. Never discard recoverable work.
346
- renameSync(revDir, join(idDir, `.orphan-${pad(number)}-${randomBytes(6).toString('hex')}`));
347
- }
348
- renameSync(stagingDir, revDir);
349
- const stored = {
350
- number,
351
- createdAt,
352
- fingerprint: fp,
353
- sourceFile: SOURCE_FILE,
354
- htmlFile: HTML_FILE,
355
- sourceSha256: sourceSha,
356
- htmlSha256: snapshotSha,
357
- };
358
- const nextManifest = {
359
- schema: MANIFEST_SCHEMA,
360
- id,
361
- sourcePath: realSource,
362
- revisions: [...manifest.revisions, stored],
363
- };
364
- atomicWrite(join(idDir, MANIFEST_FILE), JSON.stringify(nextManifest, null, 2) + '\n', FILE_MODE);
365
- }
366
- catch (err) {
367
- if (existsSync(stagingDir))
368
- rmSync(stagingDir, { recursive: true, force: true });
369
- // Guarded restore: only roll our output back if it still holds the exact
370
- // bytes we wrote, so a different source that wrote this shared destination
371
- // after us (under its own lock, not ours) is never clobbered.
372
- try {
373
- if (readFileSync(outTarget).equals(Buffer.from(decorated))) {
374
- if (prevOutput !== undefined)
375
- atomicWrite(outTarget, prevOutput, outMode);
376
- else
377
- rmSync(outTarget, { force: true });
378
- }
379
- }
380
- catch {
381
- // Output already removed or unreadable — nothing safe to roll back.
382
- }
383
- throw err;
384
- }
385
- }
386
- return { ...result, html: decorated, revision: history };
387
- }
388
- finally {
389
- await releaseOutput();
390
- }
391
- }
392
- finally {
393
- await release();
394
- }
395
- }
396
- /**
397
- * The public revision history for a source path or id. A missing history returns
398
- * an empty one (no revisions) rather than throwing, so callers can render "no
399
- * history yet" uniformly; a *corrupt* manifest still throws (see readManifest).
400
- * When called with a bare id whose manifest is missing, `sourcePath` is unknown
401
- * and returned empty.
402
- */
403
- export function readHistory(sourceOrId) {
404
- const { id, sourcePath } = resolveTarget(sourceOrId);
405
- const idDir = idDirFor(id);
406
- if (!existsSync(join(idDir, MANIFEST_FILE))) {
407
- return { id, sourcePath: sourcePath ?? '', revisions: [] };
408
- }
409
- const manifest = readManifest(idDir, id, sourcePath ?? '');
410
- return {
411
- id,
412
- sourcePath: manifest.sourcePath,
413
- revisions: manifest.revisions.map((r) => ({ number: r.number, createdAt: r.createdAt })),
414
- };
415
- }
416
- /**
417
- * Absolute path to a revision's saved snapshot HTML, for a viewer to open. The
418
- * number must name a real revision; the resolved path is confined to the
419
- * source's own history directory (no traversal via a crafted manifest), and the
420
- * stored bytes are verified against their recorded hash before the path is
421
- * handed back.
422
- */
423
- export function revisionSnapshot(sourceOrId, number) {
424
- if (!Number.isInteger(number) || number < 1) {
425
- throw new Error(`Invalid revision number: ${String(number)}`);
426
- }
427
- const { id } = resolveTarget(sourceOrId);
428
- const idDir = idDirFor(id);
429
- const manifest = readManifest(idDir, id, '');
430
- const entry = manifest.revisions.find((r) => r.number === number);
431
- if (!entry)
432
- throw new Error(`No revision ${number} for ${sourceOrId}`);
433
- const base = resolve(idDir);
434
- const expected = resolve(join(base, REVISIONS_DIR, pad(entry.number), HTML_FILE));
435
- const path = resolve(join(base, REVISIONS_DIR, pad(entry.number), entry.htmlFile));
436
- if (path !== expected || !path.startsWith(base + sep)) {
437
- throw new Error(`Refusing to resolve revision path outside history: ${path}`);
438
- }
439
- const bytes = readFileSync(path);
440
- if (sha256Hex(bytes) !== entry.htmlSha256) {
441
- throw new Error(`Revision ${number} snapshot failed hash verification`);
442
- }
443
- return path;
444
- }
445
- //# sourceMappingURL=revisions.js.map
@@ -1 +0,0 @@
1
- {"version":3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C,KAAK,KAAK,CAAC,UAAU,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,YAAY,MAAM,oCAAoC,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,13 +0,0 @@
1
- /** Cloudflare Web Analytics snippet for a given zone token. */
2
- export declare function renderBeacon(token: string): string;
3
- /**
4
- * Inject the CF Web Analytics beacon into an HTML page. Idempotent: any existing
5
- * agents-share analytics block is removed first. The snippet is appended before
6
- * `</body>` when present, otherwise before `</head>`, otherwise prepended to the
7
- * document so it still loads.
8
- */
9
- export declare function injectAnalyticsBeacon(html: string, token: string): string;
10
- /** True if the share config has a non-empty analytics token. */
11
- export declare function analyticsEnabled(cfg: {
12
- analyticsToken?: string;
13
- } | undefined | null): boolean;
@@ -1,46 +0,0 @@
1
- // Cloudflare Web Analytics injection for `artifacts share`.
2
- //
3
- // The beacon is cookieless and privacy-first, which matters because a lot of shared
4
- // content (games, kid-facing pages) should avoid GA4-style tracking. The token is
5
- // stored in the synced share config and injected into every published HTML page at
6
- // publish time, so analytics work with zero user effort once setup is complete.
7
- const BEACON_OPEN = '<!-- agents-share:analytics -->';
8
- const BEACON_CLOSE = '<!-- /agents-share:analytics -->';
9
- /** Cloudflare Web Analytics snippet for a given zone token. */
10
- export function renderBeacon(token) {
11
- const payload = JSON.stringify({ token });
12
- return (`${BEACON_OPEN}\n` +
13
- '<script defer ' +
14
- 'src="https://static.cloudflareinsights.com/beacon.min.js" ' +
15
- `data-cf-beacon='${payload}'></script>\n` +
16
- `${BEACON_CLOSE}\n`);
17
- }
18
- /** Strip a previously-injected analytics block so re-publishing doesn't duplicate it. */
19
- function stripPrevious(html) {
20
- const re = new RegExp(`${BEACON_OPEN}[\\s\\S]*?${BEACON_CLOSE}\\n?`, 'g');
21
- return html.replace(re, '');
22
- }
23
- /**
24
- * Inject the CF Web Analytics beacon into an HTML page. Idempotent: any existing
25
- * agents-share analytics block is removed first. The snippet is appended before
26
- * `</body>` when present, otherwise before `</head>`, otherwise prepended to the
27
- * document so it still loads.
28
- */
29
- export function injectAnalyticsBeacon(html, token) {
30
- if (!token)
31
- return html;
32
- const cleaned = stripPrevious(html);
33
- const block = renderBeacon(token);
34
- const bodyClose = cleaned.search(/<\/body>/i);
35
- if (bodyClose !== -1)
36
- return cleaned.slice(0, bodyClose) + block + cleaned.slice(bodyClose);
37
- const headClose = cleaned.search(/<\/head>/i);
38
- if (headClose !== -1)
39
- return cleaned.slice(0, headClose) + block + cleaned.slice(headClose);
40
- return block + cleaned;
41
- }
42
- /** True if the share config has a non-empty analytics token. */
43
- export function analyticsEnabled(cfg) {
44
- return Boolean(cfg?.analyticsToken && cfg.analyticsToken.trim().length > 0);
45
- }
46
- //# sourceMappingURL=analytics.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../../src/lib/share/analytics.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,EAAE;AACF,oFAAoF;AACpF,kFAAkF;AAClF,mFAAmF;AACnF,gFAAgF;AAEhF,MAAM,WAAW,GAAG,iCAAiC,CAAC;AACtD,MAAM,YAAY,GAAG,kCAAkC,CAAC;AAExD,+DAA+D;AAC/D,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1C,OAAO,CACL,GAAG,WAAW,IAAI;QAClB,gBAAgB;QAChB,4DAA4D;QAC5D,mBAAmB,OAAO,eAAe;QACzC,GAAG,YAAY,IAAI,CACpB,CAAC;AACJ,CAAC;AAED,yFAAyF;AACzF,SAAS,aAAa,CAAC,IAAY;IACjC,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,GAAG,WAAW,aAAa,YAAY,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC;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