@phnx-labs/artifacts-cli 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +79 -3
- package/dist/cli.js +33 -18
- package/dist/cli.js.map +1 -1
- package/dist/commands/history.d.ts +4 -0
- package/dist/commands/history.js +29 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/new.js +2 -0
- package/dist/commands/new.js.map +1 -1
- package/dist/lib/agent-assets.d.ts +1 -0
- package/dist/lib/agent-assets.js +15 -0
- package/dist/lib/agent-assets.js.map +1 -0
- package/dist/lib/creator-cover.d.ts +7 -0
- package/dist/lib/creator-cover.js +68 -0
- package/dist/lib/creator-cover.js.map +1 -0
- package/dist/lib/freshness.d.ts +6 -0
- package/dist/lib/freshness.js +52 -0
- package/dist/lib/freshness.js.map +1 -0
- package/dist/lib/icons.js +2 -1
- package/dist/lib/icons.js.map +1 -1
- package/dist/lib/metadata-menu.d.ts +22 -0
- package/dist/lib/metadata-menu.js +52 -0
- package/dist/lib/metadata-menu.js.map +1 -0
- package/dist/lib/render.js +216 -34
- package/dist/lib/render.js.map +1 -1
- package/dist/lib/revisions.d.ts +85 -0
- package/dist/lib/revisions.js +440 -0
- package/dist/lib/revisions.js.map +1 -0
- package/dist/lib/templates.d.ts +10 -3
- package/dist/lib/templates.js +34 -6
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/validate.js +46 -2
- package/dist/lib/validate.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,440 @@
|
|
|
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
|
+
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
|
+
function idDirFor(id) {
|
|
59
|
+
return join(historyRoot(), id);
|
|
60
|
+
}
|
|
61
|
+
function pad(n) {
|
|
62
|
+
return String(n).padStart(4, '0');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Content fingerprint of a rendered document, insensitive to the two surfaces
|
|
66
|
+
* that change on every write regardless of content: the source-mtime freshness
|
|
67
|
+
* stamp and the whole-document content-hash marker (which itself folds in that
|
|
68
|
+
* mtime). Everything else — prose, embedded assets, design tokens — contributes,
|
|
69
|
+
* so a re-render with unchanged inputs fingerprints identically and reuses the
|
|
70
|
+
* latest revision rather than minting a hollow new one.
|
|
71
|
+
*/
|
|
72
|
+
export function fingerprint(baseHtml) {
|
|
73
|
+
const normalized = baseHtml
|
|
74
|
+
.replace(/<meta name="artifacts-content-hash" content="[^"]*">/g, '')
|
|
75
|
+
.replace(/<time\b[^>]*\bdata-label="Source updated"[^>]*>[^<]*<\/time>/g, '');
|
|
76
|
+
return sha256Hex(normalized);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Freeze a decorated document into an immutable snapshot: strip the content-hash
|
|
80
|
+
* marker so the live-reload poll — whose own guard returns early when the marker
|
|
81
|
+
* is absent — never fires against a page that has no server to re-render it.
|
|
82
|
+
* Every other render surface (creator line, timestamps, revision menu) is kept.
|
|
83
|
+
*/
|
|
84
|
+
function freezeSnapshot(decoratedHtml) {
|
|
85
|
+
return decoratedHtml.replace(/<meta name="artifacts-content-hash" content="[^"]*">\n?/g, '');
|
|
86
|
+
}
|
|
87
|
+
function isStoredRevision(value) {
|
|
88
|
+
if (typeof value !== 'object' || value === null)
|
|
89
|
+
return false;
|
|
90
|
+
const v = value;
|
|
91
|
+
return (typeof v.number === 'number' &&
|
|
92
|
+
Number.isInteger(v.number) &&
|
|
93
|
+
typeof v.createdAt === 'string' &&
|
|
94
|
+
typeof v.fingerprint === 'string' &&
|
|
95
|
+
typeof v.sourceFile === 'string' &&
|
|
96
|
+
typeof v.htmlFile === 'string' &&
|
|
97
|
+
typeof v.sourceSha256 === 'string' &&
|
|
98
|
+
typeof v.htmlSha256 === 'string');
|
|
99
|
+
}
|
|
100
|
+
function isManifest(value) {
|
|
101
|
+
if (typeof value !== 'object' || value === null)
|
|
102
|
+
return false;
|
|
103
|
+
const v = value;
|
|
104
|
+
return (v.schema === MANIFEST_SCHEMA &&
|
|
105
|
+
typeof v.id === 'string' &&
|
|
106
|
+
typeof v.sourcePath === 'string' &&
|
|
107
|
+
Array.isArray(v.revisions) &&
|
|
108
|
+
v.revisions.every(isStoredRevision));
|
|
109
|
+
}
|
|
110
|
+
const HEX_256 = /^[0-9a-f]{64}$/;
|
|
111
|
+
const ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;
|
|
112
|
+
/**
|
|
113
|
+
* Beyond shape, enforce the invariants a swapped or hand-edited manifest could
|
|
114
|
+
* otherwise satisfy while still handing back the wrong artifact or version: the
|
|
115
|
+
* id must be this source's hash and match the request, revision numbers must be
|
|
116
|
+
* exactly 1..n in order, timestamps must be real ISO instants, every hash must
|
|
117
|
+
* be a 64-hex digest, and the file names must be the fixed store names (so a
|
|
118
|
+
* crafted path can never redirect a snapshot read).
|
|
119
|
+
*/
|
|
120
|
+
function assertManifestIntegrity(manifest, requestedId, file) {
|
|
121
|
+
const fail = (why) => {
|
|
122
|
+
throw new Error(`Corrupt revision manifest at ${file}: ${why}`);
|
|
123
|
+
};
|
|
124
|
+
if (!HEX_256.test(manifest.id))
|
|
125
|
+
fail('id is not a sha-256 digest');
|
|
126
|
+
if (manifest.id !== requestedId)
|
|
127
|
+
fail('id does not match the requested source');
|
|
128
|
+
if (sha256Hex(manifest.sourcePath) !== manifest.id)
|
|
129
|
+
fail('id does not match its source path');
|
|
130
|
+
manifest.revisions.forEach((r, i) => {
|
|
131
|
+
if (r.number !== i + 1)
|
|
132
|
+
fail(`revision numbers are not the sequence 1..n (index ${i} is ${r.number})`);
|
|
133
|
+
if (r.sourceFile !== SOURCE_FILE || r.htmlFile !== HTML_FILE)
|
|
134
|
+
fail(`revision ${r.number} names an unexpected file`);
|
|
135
|
+
if (!HEX_256.test(r.fingerprint))
|
|
136
|
+
fail(`revision ${r.number} has a malformed fingerprint`);
|
|
137
|
+
if (!HEX_256.test(r.sourceSha256) || !HEX_256.test(r.htmlSha256))
|
|
138
|
+
fail(`revision ${r.number} has a malformed content hash`);
|
|
139
|
+
if (!ISO_INSTANT.test(r.createdAt) || Number.isNaN(Date.parse(r.createdAt)))
|
|
140
|
+
fail(`revision ${r.number} has a malformed timestamp`);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Read a source's manifest. A missing manifest is a fresh, empty history. A
|
|
145
|
+
* present-but-unparseable, wrong-shaped, or integrity-violating manifest is
|
|
146
|
+
* fatal: it is never silently reset, because that would erase a real history
|
|
147
|
+
* behind a transient read glitch. Fail loudly so the corruption is investigated,
|
|
148
|
+
* not overwritten.
|
|
149
|
+
*/
|
|
150
|
+
function readManifest(idDir, id, sourcePath) {
|
|
151
|
+
const file = join(idDir, MANIFEST_FILE);
|
|
152
|
+
if (!existsSync(file))
|
|
153
|
+
return { schema: MANIFEST_SCHEMA, id, sourcePath, revisions: [] };
|
|
154
|
+
const raw = readFileSync(file, 'utf8');
|
|
155
|
+
let parsed;
|
|
156
|
+
try {
|
|
157
|
+
parsed = JSON.parse(raw);
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
throw new Error(`Corrupt revision manifest at ${file}: ${err.message}`);
|
|
161
|
+
}
|
|
162
|
+
if (!isManifest(parsed)) {
|
|
163
|
+
throw new Error(`Corrupt revision manifest at ${file}: unexpected shape`);
|
|
164
|
+
}
|
|
165
|
+
assertManifestIntegrity(parsed, id, file);
|
|
166
|
+
return parsed;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Atomic single-file write: create a unique temp file in the destination
|
|
170
|
+
* directory, fsync it, then rename over the target. A rename within one
|
|
171
|
+
* directory is atomic, so a reader never sees a half-written file and a crash
|
|
172
|
+
* never truncates an existing one. An explicit `mode` is forced past any umask
|
|
173
|
+
* (used for the private history store); when omitted the platform default
|
|
174
|
+
* (`0o666 & ~umask`) applies, so a reader-facing output keeps normal
|
|
175
|
+
* permissions.
|
|
176
|
+
*/
|
|
177
|
+
function atomicWrite(target, data, mode) {
|
|
178
|
+
const tmp = join(dirname(target), `.${basename(target)}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`);
|
|
179
|
+
const fd = mode === undefined ? openSync(tmp, 'wx') : openSync(tmp, 'wx', mode);
|
|
180
|
+
try {
|
|
181
|
+
writeFileSync(fd, data);
|
|
182
|
+
fsyncSync(fd);
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
closeSync(fd);
|
|
186
|
+
}
|
|
187
|
+
if (mode !== undefined)
|
|
188
|
+
chmodSync(tmp, mode);
|
|
189
|
+
renameSync(tmp, target);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The real path a reader-facing output write should land on. An existing symlink
|
|
193
|
+
* resolves to its target (so a link is written through, not clobbered by a
|
|
194
|
+
* regular file); a plain or not-yet-existing path resolves to its absolute form.
|
|
195
|
+
*/
|
|
196
|
+
function resolveOutputTarget(out) {
|
|
197
|
+
try {
|
|
198
|
+
return realpathSync(out);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
const absolute = resolve(out);
|
|
202
|
+
const parent = dirname(absolute);
|
|
203
|
+
if (parent === absolute)
|
|
204
|
+
return absolute;
|
|
205
|
+
// Resolve existing ancestors even before the file exists. Otherwise the
|
|
206
|
+
// first write through an aliased directory and subsequent realpath writes
|
|
207
|
+
// would acquire different destination locks.
|
|
208
|
+
return join(resolveOutputTarget(parent), basename(absolute));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function hasError(diagnostics) {
|
|
212
|
+
return diagnostics.some((d) => d.level === 'error');
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Render `source` to `out`, recording a revision when the rendered content has
|
|
216
|
+
* changed. The whole transaction runs under a per-source lock:
|
|
217
|
+
*
|
|
218
|
+
* 1. The source bytes are captured, `render()` runs, and the source is re-read;
|
|
219
|
+
* an error diagnostic, or a source edited mid-render, aborts before anything
|
|
220
|
+
* is written — output and history are left untouched.
|
|
221
|
+
* 2. The base is fingerprinted. An unchanged fingerprint reuses the latest
|
|
222
|
+
* revision (number and timestamp); a change (or first render) mints the next.
|
|
223
|
+
* 3. `decorate()` renders the reader-facing document from the base and history.
|
|
224
|
+
* 4. The decorated document is written to `out` (its parent directory created as
|
|
225
|
+
* needed) *before* the history is committed, so a bad destination never
|
|
226
|
+
* consumes a revision number. Any prior output is captured first.
|
|
227
|
+
* 5. Only then is a new revision committed: its source bytes and frozen snapshot
|
|
228
|
+
* are staged, moved into place (clearing any orphan from an interrupted prior
|
|
229
|
+
* commit), and the manifest is rewritten last, so a failure can never leave a
|
|
230
|
+
* dangling authoritative index entry. A commit that fails after the output was
|
|
231
|
+
* written rolls that output back to its prior bytes.
|
|
232
|
+
*
|
|
233
|
+
* The returned `html` is the decorated document (what was written to `out`).
|
|
234
|
+
*/
|
|
235
|
+
export async function saveRevision(source, out, render, decorate) {
|
|
236
|
+
const realSource = canonicalSource(source);
|
|
237
|
+
const id = sourceId(realSource);
|
|
238
|
+
const idDir = idDirFor(id);
|
|
239
|
+
mkdirSync(idDir, { recursive: true, mode: DIR_MODE });
|
|
240
|
+
const release = await lock(idDir, LOCK_OPTIONS);
|
|
241
|
+
try {
|
|
242
|
+
// Read the source before rendering, so the archived bytes are exactly those
|
|
243
|
+
// the renderer consumed rather than whatever the file holds after it returns.
|
|
244
|
+
const sourceBefore = readFileSync(realSource);
|
|
245
|
+
const result = await render();
|
|
246
|
+
// A render error leaves output and history untouched — nothing is written.
|
|
247
|
+
if (hasError(result.diagnostics))
|
|
248
|
+
return result;
|
|
249
|
+
// If the source was edited while the renderer ran, the rendered HTML and the
|
|
250
|
+
// bytes on disk may no longer correspond. Never archive a mismatched pair:
|
|
251
|
+
// abort untouched and let the caller re-render once the edit settles.
|
|
252
|
+
const sourceAfter = readFileSync(realSource);
|
|
253
|
+
if (!sourceBefore.equals(sourceAfter)) {
|
|
254
|
+
return {
|
|
255
|
+
...result,
|
|
256
|
+
diagnostics: [
|
|
257
|
+
...result.diagnostics,
|
|
258
|
+
{ level: 'error', message: `Source ${realSource} changed during render; nothing was archived` },
|
|
259
|
+
],
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const base = result.html;
|
|
263
|
+
const fp = fingerprint(base);
|
|
264
|
+
const manifest = readManifest(idDir, id, realSource);
|
|
265
|
+
const latest = manifest.revisions.at(-1);
|
|
266
|
+
const isNew = !latest || latest.fingerprint !== fp;
|
|
267
|
+
const number = isNew ? (latest?.number ?? 0) + 1 : latest.number;
|
|
268
|
+
const createdAt = isNew ? new Date().toISOString() : latest.createdAt;
|
|
269
|
+
const summaries = manifest.revisions.map((r) => ({ number: r.number, createdAt: r.createdAt }));
|
|
270
|
+
if (isNew)
|
|
271
|
+
summaries.push({ number, createdAt });
|
|
272
|
+
const history = { id, sourcePath: realSource, revisions: summaries };
|
|
273
|
+
const decorated = decorate(base, history);
|
|
274
|
+
// Follow an existing output symlink to its real target (matching plain
|
|
275
|
+
// writeFileSync, which writes through a link rather than replacing it), and
|
|
276
|
+
// refuse to overwrite the source itself with its own rendering.
|
|
277
|
+
const outTarget = resolveOutputTarget(out);
|
|
278
|
+
if (outTarget === realSource) {
|
|
279
|
+
return {
|
|
280
|
+
...result,
|
|
281
|
+
diagnostics: [...result.diagnostics, { level: 'error', message: `Refusing to write output over the source ${realSource}` }],
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
// Stage the new revision's bytes before touching the destination. The source
|
|
285
|
+
// snapshot is the verified-stable bytes read above, so the archived Markdown
|
|
286
|
+
// always matches the archived HTML.
|
|
287
|
+
let stagingDir;
|
|
288
|
+
let snapshotSha = '';
|
|
289
|
+
let sourceSha = '';
|
|
290
|
+
if (isNew) {
|
|
291
|
+
const snapshot = freezeSnapshot(decorated);
|
|
292
|
+
sourceSha = sha256Hex(sourceBefore);
|
|
293
|
+
snapshotSha = sha256Hex(snapshot);
|
|
294
|
+
stagingDir = join(idDir, `.staging-${process.pid}-${randomBytes(6).toString('hex')}`);
|
|
295
|
+
mkdirSync(stagingDir, { mode: DIR_MODE });
|
|
296
|
+
atomicWrite(join(stagingDir, SOURCE_FILE), sourceBefore, FILE_MODE);
|
|
297
|
+
atomicWrite(join(stagingDir, HTML_FILE), snapshot, FILE_MODE);
|
|
298
|
+
}
|
|
299
|
+
// Write the reader-facing output first, creating its parent directory like
|
|
300
|
+
// compileArtifact does and preserving an existing file's permissions (a fresh
|
|
301
|
+
// file gets the platform default, never the private archive mode). A bad
|
|
302
|
+
// destination must not consume a revision number, so on failure clean up the
|
|
303
|
+
// staged snapshot and surface an error diagnostic — the history is left
|
|
304
|
+
// exactly as it was. Capture any prior output and its mode so a later commit
|
|
305
|
+
// failure can restore it.
|
|
306
|
+
// Every source takes its own lock first, then this shared destination lock.
|
|
307
|
+
// Separate source histories writing one output cannot race a failed commit's
|
|
308
|
+
// rollback. A private hash-keyed lock also works before the output exists.
|
|
309
|
+
const outputLockDir = join(historyRoot(), '.output-locks', sha256Hex(outTarget));
|
|
310
|
+
mkdirSync(outputLockDir, { recursive: true, mode: DIR_MODE });
|
|
311
|
+
const releaseOutput = await lock(outputLockDir, LOCK_OPTIONS);
|
|
312
|
+
try {
|
|
313
|
+
const outExisted = existsSync(outTarget);
|
|
314
|
+
const prevOutput = outExisted ? readFileSync(outTarget) : undefined;
|
|
315
|
+
const outMode = outExisted ? statSync(outTarget).mode & 0o777 : undefined;
|
|
316
|
+
try {
|
|
317
|
+
mkdirSync(dirname(outTarget), { recursive: true });
|
|
318
|
+
atomicWrite(outTarget, decorated, outMode);
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
if (stagingDir)
|
|
322
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
323
|
+
return {
|
|
324
|
+
...result,
|
|
325
|
+
diagnostics: [...result.diagnostics, { level: 'error', message: `Could not write ${out}: ${err.message}` }],
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
// Commit the revision. The snapshot directory is moved into place — first
|
|
329
|
+
// clearing any orphan a previously interrupted commit may have left (the
|
|
330
|
+
// manifest is authoritative, so an unreferenced revision directory is safe to
|
|
331
|
+
// drop) — then the manifest is rewritten last and atomically. If the commit
|
|
332
|
+
// fails after the output was written, roll the output back so it stays
|
|
333
|
+
// consistent with the still-authoritative, unchanged manifest.
|
|
334
|
+
if (isNew && stagingDir) {
|
|
335
|
+
try {
|
|
336
|
+
const revDir = join(idDir, REVISIONS_DIR, pad(number));
|
|
337
|
+
mkdirSync(join(idDir, REVISIONS_DIR), { recursive: true, mode: DIR_MODE });
|
|
338
|
+
if (existsSync(revDir)) {
|
|
339
|
+
// Preserve interrupted snapshots: the output may have briefly exposed
|
|
340
|
+
// them before its manifest committed. Never discard recoverable work.
|
|
341
|
+
renameSync(revDir, join(idDir, `.orphan-${pad(number)}-${randomBytes(6).toString('hex')}`));
|
|
342
|
+
}
|
|
343
|
+
renameSync(stagingDir, revDir);
|
|
344
|
+
const stored = {
|
|
345
|
+
number,
|
|
346
|
+
createdAt,
|
|
347
|
+
fingerprint: fp,
|
|
348
|
+
sourceFile: SOURCE_FILE,
|
|
349
|
+
htmlFile: HTML_FILE,
|
|
350
|
+
sourceSha256: sourceSha,
|
|
351
|
+
htmlSha256: snapshotSha,
|
|
352
|
+
};
|
|
353
|
+
const nextManifest = {
|
|
354
|
+
schema: MANIFEST_SCHEMA,
|
|
355
|
+
id,
|
|
356
|
+
sourcePath: realSource,
|
|
357
|
+
revisions: [...manifest.revisions, stored],
|
|
358
|
+
};
|
|
359
|
+
atomicWrite(join(idDir, MANIFEST_FILE), JSON.stringify(nextManifest, null, 2) + '\n', FILE_MODE);
|
|
360
|
+
}
|
|
361
|
+
catch (err) {
|
|
362
|
+
if (existsSync(stagingDir))
|
|
363
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
364
|
+
// Guarded restore: only roll our output back if it still holds the exact
|
|
365
|
+
// bytes we wrote, so a different source that wrote this shared destination
|
|
366
|
+
// after us (under its own lock, not ours) is never clobbered.
|
|
367
|
+
try {
|
|
368
|
+
if (readFileSync(outTarget).equals(Buffer.from(decorated))) {
|
|
369
|
+
if (prevOutput !== undefined)
|
|
370
|
+
atomicWrite(outTarget, prevOutput, outMode);
|
|
371
|
+
else
|
|
372
|
+
rmSync(outTarget, { force: true });
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
// Output already removed or unreadable — nothing safe to roll back.
|
|
377
|
+
}
|
|
378
|
+
throw err;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return { ...result, html: decorated, revision: history };
|
|
382
|
+
}
|
|
383
|
+
finally {
|
|
384
|
+
await releaseOutput();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
finally {
|
|
388
|
+
await release();
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* The public revision history for a source path or id. A missing history returns
|
|
393
|
+
* an empty one (no revisions) rather than throwing, so callers can render "no
|
|
394
|
+
* history yet" uniformly; a *corrupt* manifest still throws (see readManifest).
|
|
395
|
+
* When called with a bare id whose manifest is missing, `sourcePath` is unknown
|
|
396
|
+
* and returned empty.
|
|
397
|
+
*/
|
|
398
|
+
export function readHistory(sourceOrId) {
|
|
399
|
+
const { id, sourcePath } = resolveTarget(sourceOrId);
|
|
400
|
+
const idDir = idDirFor(id);
|
|
401
|
+
if (!existsSync(join(idDir, MANIFEST_FILE))) {
|
|
402
|
+
return { id, sourcePath: sourcePath ?? '', revisions: [] };
|
|
403
|
+
}
|
|
404
|
+
const manifest = readManifest(idDir, id, sourcePath ?? '');
|
|
405
|
+
return {
|
|
406
|
+
id,
|
|
407
|
+
sourcePath: manifest.sourcePath,
|
|
408
|
+
revisions: manifest.revisions.map((r) => ({ number: r.number, createdAt: r.createdAt })),
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Absolute path to a revision's saved snapshot HTML, for a viewer to open. The
|
|
413
|
+
* number must name a real revision; the resolved path is confined to the
|
|
414
|
+
* source's own history directory (no traversal via a crafted manifest), and the
|
|
415
|
+
* stored bytes are verified against their recorded hash before the path is
|
|
416
|
+
* handed back.
|
|
417
|
+
*/
|
|
418
|
+
export function revisionSnapshot(sourceOrId, number) {
|
|
419
|
+
if (!Number.isInteger(number) || number < 1) {
|
|
420
|
+
throw new Error(`Invalid revision number: ${String(number)}`);
|
|
421
|
+
}
|
|
422
|
+
const { id } = resolveTarget(sourceOrId);
|
|
423
|
+
const idDir = idDirFor(id);
|
|
424
|
+
const manifest = readManifest(idDir, id, '');
|
|
425
|
+
const entry = manifest.revisions.find((r) => r.number === number);
|
|
426
|
+
if (!entry)
|
|
427
|
+
throw new Error(`No revision ${number} for ${sourceOrId}`);
|
|
428
|
+
const base = resolve(idDir);
|
|
429
|
+
const expected = resolve(join(base, REVISIONS_DIR, pad(entry.number), HTML_FILE));
|
|
430
|
+
const path = resolve(join(base, REVISIONS_DIR, pad(entry.number), entry.htmlFile));
|
|
431
|
+
if (path !== expected || !path.startsWith(base + sep)) {
|
|
432
|
+
throw new Error(`Refusing to resolve revision path outside history: ${path}`);
|
|
433
|
+
}
|
|
434
|
+
const bytes = readFileSync(path);
|
|
435
|
+
if (sha256Hex(bytes) !== entry.htmlSha256) {
|
|
436
|
+
throw new Error(`Revision ${number} snapshot failed hash verification`);
|
|
437
|
+
}
|
|
438
|
+
return path;
|
|
439
|
+
}
|
|
440
|
+
//# sourceMappingURL=revisions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revisions.js","sourceRoot":"","sources":["../../src/lib/revisions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAoDvC,MAAM,eAAe,GAAG,wBAAwB,CAAC;AACjD,MAAM,aAAa,GAAG,eAAe,CAAC;AACtC,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,WAAW,GAAG,QAAQ,CAAC;AAC7B,MAAM,SAAS,GAAG,aAAa,CAAC;AAEhC,2EAA2E;AAC3E,2DAA2D;AAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC;AACvB,MAAM,SAAS,GAAG,KAAK,CAAC;AAExB,gFAAgF;AAChF,gFAAgF;AAChF,2EAA2E;AAC3E,kDAAkD;AAClD,MAAM,YAAY,GAAG;IACnB,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U,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,sDAAsD,IAAI,EAAE,CAAC,CAAC;IAChF,CAAC;IACD,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,UAAU,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,YAAY,MAAM,oCAAoC,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/lib/templates.d.ts
CHANGED
|
@@ -19,7 +19,13 @@ export interface ArtifactContext {
|
|
|
19
19
|
/** Full, untruncated session id — used for the session deep link's href. */
|
|
20
20
|
sessionId: string;
|
|
21
21
|
date: string;
|
|
22
|
+
created?: string;
|
|
23
|
+
harnessVersion?: string;
|
|
24
|
+
hostPlatform?: string;
|
|
25
|
+
hostArch?: string;
|
|
22
26
|
}
|
|
27
|
+
/** Match the Agents CLI's machine-id convention without retaining DNS suffixes. */
|
|
28
|
+
export declare function shortHost(raw: string): string;
|
|
23
29
|
export declare const STARTER_DESIGN = "---\nname: default\nfonts:\n body: Inter\n mono: JetBrains Mono\n display: Inter\ntheme:\n default: system\nthemes:\n light:\n background: \"#faf9f6\"\n surface: \"#ffffff\"\n surfaceAlt: \"#f2f4f0\"\n line: \"#e2e6df\"\n text: \"#1a1c1a\"\n muted: \"#5c655c\"\n accent: \"#4d7c0f\"\n accentAlt: \"#0e7490\"\n warn: \"#b45309\"\n danger: \"#dc2626\"\n dark:\n background: \"#0a0a0a\"\n surface: \"#111312\"\n surfaceAlt: \"#161a18\"\n line: \"#26302a\"\n text: \"#e7ece8\"\n muted: \"#8b938c\"\n accent: \"#a3e635\"\n accentAlt: \"#5ad6c0\"\n warn: \"#f5c451\"\n danger: \"#ff6b6b\"\nlayout:\n contentWidth: 980\n pagePadding: 24\n mobilePagePadding: 16\n heroTop: 40\n heroBottom: 28\n sectionSpacing: 36\n figureSpacing: 22\n panelPadding: 16\n footerSpacing: 64\n printMargin: 24\nartifact:\n density: compact\n radius: 10\n printTheme: light\n---\n\n# Design\n\nProject-wide artifact rendering defaults. Keep artifact-specific metadata in the Markdown artifact frontmatter.\n";
|
|
24
30
|
export declare function repositoryName(remote: string): string;
|
|
25
31
|
/**
|
|
@@ -33,11 +39,12 @@ export interface KnownProject {
|
|
|
33
39
|
name: string;
|
|
34
40
|
repo: string;
|
|
35
41
|
paths: string[];
|
|
42
|
+
displayName?: string;
|
|
43
|
+
url?: string;
|
|
36
44
|
}
|
|
37
45
|
/**
|
|
38
|
-
* Read the known project list
|
|
39
|
-
*
|
|
40
|
-
* not take a yaml dependency for one directory of simple manifests. An absent
|
|
46
|
+
* Read the known project list: top-level subject fields and the linked
|
|
47
|
+
* tracker's optional display name and URL. An absent
|
|
41
48
|
* or unreadable directory (a non-fleet machine) yields an empty list, never an
|
|
42
49
|
* error: detection then falls back to the git remote alone.
|
|
43
50
|
*/
|
package/dist/lib/templates.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { readdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
-
import { homedir, hostname, userInfo } from 'node:os';
|
|
3
|
+
import { arch, homedir, hostname, platform, userInfo } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import matter from 'gray-matter';
|
|
6
6
|
import { randomWorksheetId } from './worksheet.js';
|
|
@@ -29,6 +29,10 @@ export function normalizeKind(raw) {
|
|
|
29
29
|
export function isTemplateKind(kind) {
|
|
30
30
|
return TEMPLATE_KINDS.includes(kind);
|
|
31
31
|
}
|
|
32
|
+
/** Match the Agents CLI's machine-id convention without retaining DNS suffixes. */
|
|
33
|
+
export function shortHost(raw) {
|
|
34
|
+
return raw.split('.')[0].trim().toLowerCase().replace(/[^a-z0-9_-]/g, '-') || '';
|
|
35
|
+
}
|
|
32
36
|
export const STARTER_DESIGN = `---
|
|
33
37
|
name: default
|
|
34
38
|
fonts:
|
|
@@ -257,13 +261,12 @@ function expandHome(path) {
|
|
|
257
261
|
return path;
|
|
258
262
|
}
|
|
259
263
|
/**
|
|
260
|
-
* Read the known project list
|
|
261
|
-
*
|
|
262
|
-
* not take a yaml dependency for one directory of simple manifests. An absent
|
|
264
|
+
* Read the known project list: top-level subject fields and the linked
|
|
265
|
+
* tracker's optional display name and URL. An absent
|
|
263
266
|
* or unreadable directory (a non-fleet machine) yields an empty list, never an
|
|
264
267
|
* error: detection then falls back to the git remote alone.
|
|
265
268
|
*/
|
|
266
|
-
export function knownProjects(dir = join(homedir(), '.agents', 'projects')) {
|
|
269
|
+
export function knownProjects(dir = process.env.AGENTS_PROJECTS_DIR || join(homedir(), '.agents', 'projects')) {
|
|
267
270
|
let files;
|
|
268
271
|
try {
|
|
269
272
|
files = readdirSync(dir).filter((file) => file.endsWith('.yaml') || file.endsWith('.yml'));
|
|
@@ -284,10 +287,23 @@ export function knownProjects(dir = join(homedir(), '.agents', 'projects')) {
|
|
|
284
287
|
const name = field('name');
|
|
285
288
|
if (!name)
|
|
286
289
|
continue;
|
|
290
|
+
// ProjectDef.name is the stable ID; its linked tracker's name is the human
|
|
291
|
+
// label. Read only presentation fields here; cwd/project resolution below
|
|
292
|
+
// continues to use the stable name and declared directories.
|
|
293
|
+
let presentation = {};
|
|
294
|
+
try {
|
|
295
|
+
const linear = matter(`---\n${text}\n---`).data.linear;
|
|
296
|
+
if (typeof linear?.name === 'string' && linear.name.trim())
|
|
297
|
+
presentation.displayName = linear.name.trim();
|
|
298
|
+
if (typeof linear?.url === 'string' && /^https?:\/\//i.test(linear.url.trim()))
|
|
299
|
+
presentation.url = linear.url.trim();
|
|
300
|
+
}
|
|
301
|
+
catch { /* Malformed optional tracker metadata cannot invent a label. */ }
|
|
287
302
|
projects.push({
|
|
288
303
|
name,
|
|
289
304
|
repo: field('repo'),
|
|
290
305
|
paths: [field('root'), field('defaultPath')].filter(Boolean).map(expandHome),
|
|
306
|
+
...presentation,
|
|
291
307
|
});
|
|
292
308
|
}
|
|
293
309
|
return projects;
|
|
@@ -396,6 +412,8 @@ export function anonymizedArtifactContext(cwd = process.cwd()) {
|
|
|
396
412
|
host: 'fleet-worker',
|
|
397
413
|
session: '',
|
|
398
414
|
sessionId: '',
|
|
415
|
+
hostPlatform: '',
|
|
416
|
+
hostArch: '',
|
|
399
417
|
};
|
|
400
418
|
}
|
|
401
419
|
export function detectArtifactContext(cwd = process.cwd(), options = {}) {
|
|
@@ -430,10 +448,13 @@ export function detectArtifactContext(cwd = process.cwd(), options = {}) {
|
|
|
430
448
|
human: gitValue(cwd, ['config', 'user.name'])
|
|
431
449
|
|| firstEnvironmentValue(['GIT_AUTHOR_NAME', 'USER', 'LOGNAME'])
|
|
432
450
|
|| osUsername(),
|
|
433
|
-
host: hostname(),
|
|
451
|
+
host: shortHost(process.env.AGENTS_SYNC_MACHINE_ID || hostname()),
|
|
434
452
|
session: session.length > 8 ? session.slice(0, 8) : session,
|
|
435
453
|
sessionId: session,
|
|
436
454
|
date: localDate(),
|
|
455
|
+
harnessVersion: firstEnvironmentValue(['AGENTS_RUN_VERSION']),
|
|
456
|
+
hostPlatform: platform() === 'darwin' ? 'macos' : platform() === 'win32' ? 'windows' : platform(),
|
|
457
|
+
hostArch: arch(),
|
|
437
458
|
};
|
|
438
459
|
}
|
|
439
460
|
function frontmatter(kind, context) {
|
|
@@ -445,17 +466,24 @@ function frontmatter(kind, context) {
|
|
|
445
466
|
header: '',
|
|
446
467
|
footer: '',
|
|
447
468
|
project: context.project || '',
|
|
469
|
+
projectUrl: '',
|
|
448
470
|
context: '',
|
|
449
471
|
repository: context.repository || '',
|
|
450
472
|
branch: context.branch || '',
|
|
451
473
|
tracking: '',
|
|
452
474
|
status: 'draft',
|
|
453
475
|
harness: context.harness || '',
|
|
476
|
+
harnessVersion: context.harnessVersion || '',
|
|
454
477
|
agent: context.agent || '',
|
|
455
478
|
human: context.human || '',
|
|
456
479
|
host: context.host || '',
|
|
480
|
+
hostPlatform: context.hostPlatform || '',
|
|
481
|
+
hostArch: context.hostArch || '',
|
|
457
482
|
session: context.session || '',
|
|
483
|
+
sessionId: context.sessionId || '',
|
|
458
484
|
date: context.date || '',
|
|
485
|
+
created: context.created || '',
|
|
486
|
+
updated: '',
|
|
459
487
|
facts: [],
|
|
460
488
|
links: [],
|
|
461
489
|
assets: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/lib/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/lib/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAU,CAAC;AAGjF,MAAM,YAAY,GAAiC;IACjD,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,MAAM;IAChB,qBAAqB,EAAE,MAAM;IAC7B,mBAAmB,EAAE,MA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