@adea-ai/plugins 4.0.0 → 4.0.6

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 (147) hide show
  1. package/dist/agent-plugins-catalog.d.ts +2 -4
  2. package/dist/agent-plugins-catalog.js +42 -50
  3. package/dist/agent-plugins-catalog.js.map +1 -1
  4. package/dist/agent-plugins-schema.d.ts +8 -0
  5. package/dist/agent-plugins-schema.js +10 -1
  6. package/dist/agent-plugins-schema.js.map +1 -1
  7. package/dist/artifacts.d.ts +57 -0
  8. package/dist/artifacts.js +159 -0
  9. package/dist/artifacts.js.map +1 -0
  10. package/dist/build.d.ts +20 -0
  11. package/dist/build.js +103 -0
  12. package/dist/build.js.map +1 -0
  13. package/dist/capabilities.d.ts +7 -0
  14. package/dist/capabilities.js +116 -0
  15. package/dist/capabilities.js.map +1 -0
  16. package/dist/catalog-store.d.ts +76 -0
  17. package/dist/catalog-store.js +463 -0
  18. package/dist/catalog-store.js.map +1 -0
  19. package/dist/concurrency.d.ts +1 -0
  20. package/dist/concurrency.js +15 -0
  21. package/dist/concurrency.js.map +1 -0
  22. package/dist/consumer-index.d.ts +7 -29
  23. package/dist/consumer-index.js +24 -15
  24. package/dist/consumer-index.js.map +1 -1
  25. package/dist/digest.d.ts +13 -0
  26. package/dist/digest.js +47 -0
  27. package/dist/digest.js.map +1 -0
  28. package/dist/fs-atomic.d.ts +7 -0
  29. package/dist/fs-atomic.js +30 -0
  30. package/dist/fs-atomic.js.map +1 -0
  31. package/dist/harness.js +2 -1
  32. package/dist/harness.js.map +1 -1
  33. package/dist/icon-mirror.d.ts +5 -4
  34. package/dist/icon-mirror.js +73 -72
  35. package/dist/icon-mirror.js.map +1 -1
  36. package/dist/icons.d.ts +2 -2
  37. package/dist/icons.js +4 -12
  38. package/dist/icons.js.map +1 -1
  39. package/dist/index.d.ts +16 -309
  40. package/dist/index.js +12 -1900
  41. package/dist/index.js.map +1 -1
  42. package/dist/integrity-manifest.d.ts +43 -13
  43. package/dist/integrity-manifest.js +28 -17
  44. package/dist/integrity-manifest.js.map +1 -1
  45. package/dist/json-values.d.ts +3 -0
  46. package/dist/json-values.js +10 -0
  47. package/dist/json-values.js.map +1 -0
  48. package/dist/plugin-release.d.ts +38 -0
  49. package/dist/plugin-release.js +321 -0
  50. package/dist/plugin-release.js.map +1 -0
  51. package/dist/plugin-skips.d.ts +19 -0
  52. package/dist/plugin-skips.js +65 -0
  53. package/dist/plugin-skips.js.map +1 -0
  54. package/dist/policy.d.ts +13 -0
  55. package/dist/policy.js +26 -0
  56. package/dist/policy.js.map +1 -0
  57. package/dist/portable-catalog.d.ts +4 -4
  58. package/dist/portable-catalog.js +14 -126
  59. package/dist/portable-catalog.js.map +1 -1
  60. package/dist/portable-verify.d.ts +2 -0
  61. package/dist/portable-verify.js +68 -0
  62. package/dist/portable-verify.js.map +1 -0
  63. package/dist/publication.d.ts +12 -12
  64. package/dist/publication.js +31 -21
  65. package/dist/publication.js.map +1 -1
  66. package/dist/published-output.d.ts +17 -0
  67. package/dist/published-output.js +49 -0
  68. package/dist/published-output.js.map +1 -0
  69. package/dist/site-icons.d.ts +4 -3
  70. package/dist/site-icons.js +38 -11
  71. package/dist/site-icons.js.map +1 -1
  72. package/dist/snapshots.d.ts +39 -0
  73. package/dist/snapshots.js +238 -0
  74. package/dist/snapshots.js.map +1 -0
  75. package/dist/source-resolution.d.ts +28 -0
  76. package/dist/source-resolution.js +158 -0
  77. package/dist/source-resolution.js.map +1 -0
  78. package/dist/sources.d.ts +5 -1
  79. package/dist/sources.js +21 -27
  80. package/dist/sources.js.map +1 -1
  81. package/dist/synchronize.d.ts +44 -0
  82. package/dist/synchronize.js +118 -0
  83. package/dist/synchronize.js.map +1 -0
  84. package/dist/taxonomy.d.ts +23 -0
  85. package/dist/taxonomy.js +62 -0
  86. package/dist/taxonomy.js.map +1 -0
  87. package/dist/upstream.d.ts +42 -0
  88. package/dist/upstream.js +179 -0
  89. package/dist/upstream.js.map +1 -0
  90. package/dist/verify-artifacts.d.ts +36 -0
  91. package/dist/verify-artifacts.js +286 -0
  92. package/dist/verify-artifacts.js.map +1 -0
  93. package/native/build-provenance.txt +5 -5
  94. package/native/staged-reader-win32-arm64.node +0 -0
  95. package/native/staged-reader-win32-x64.node +0 -0
  96. package/package.json +3 -3
  97. package/src/agent-plugins-catalog.test.ts +2 -2
  98. package/src/agent-plugins-catalog.ts +46 -49
  99. package/src/agent-plugins-schema.ts +11 -1
  100. package/src/artifacts.test.ts +80 -0
  101. package/src/artifacts.ts +234 -0
  102. package/src/build.ts +131 -0
  103. package/src/capabilities.ts +153 -0
  104. package/src/catalog-store.ts +519 -0
  105. package/src/concurrency.ts +19 -0
  106. package/src/consumer-index.test.ts +147 -16
  107. package/src/consumer-index.ts +35 -43
  108. package/src/default-head.test.ts +143 -0
  109. package/src/digest.ts +55 -0
  110. package/src/fs-atomic.ts +32 -0
  111. package/src/harness.test.ts +4 -32
  112. package/src/harness.ts +2 -1
  113. package/src/icon-mirror.ts +78 -72
  114. package/src/icons.test.ts +0 -4
  115. package/src/icons.ts +4 -4
  116. package/src/index.test.ts +172 -46
  117. package/src/index.ts +58 -2562
  118. package/src/integrity-manifest.ts +41 -21
  119. package/src/json-values.ts +11 -0
  120. package/src/manifest-retry.test.ts +49 -0
  121. package/src/plugin-release.ts +457 -0
  122. package/src/plugin-skips.ts +110 -0
  123. package/src/policy.ts +39 -0
  124. package/src/portable-catalog.test.ts +0 -5
  125. package/src/portable-catalog.ts +16 -143
  126. package/src/portable-verify.ts +71 -0
  127. package/src/publication.test.ts +29 -1
  128. package/src/publication.ts +38 -22
  129. package/src/published-output.ts +60 -0
  130. package/src/site-icons.test.ts +73 -1
  131. package/src/site-icons.ts +31 -14
  132. package/src/snapshots.ts +287 -0
  133. package/src/source-config-sync.test.ts +84 -0
  134. package/src/source-digest.test.ts +61 -8
  135. package/src/source-resolution.ts +233 -0
  136. package/src/sources-json.test.ts +18 -2
  137. package/src/sources.ts +27 -33
  138. package/src/synchronize.ts +213 -0
  139. package/src/taxonomy.ts +87 -0
  140. package/src/upstream.ts +194 -0
  141. package/src/verify-artifacts.ts +365 -0
  142. package/src/write-artifacts.test.ts +374 -0
  143. package/dist/source-digest.d.ts +0 -2
  144. package/dist/source-digest.js +0 -12
  145. package/dist/source-digest.js.map +0 -1
  146. package/native/README.md +0 -24
  147. package/src/source-digest.ts +0 -14
@@ -0,0 +1,463 @@
1
+ /**
2
+ * Catalog output coordination and publication.
3
+ *
4
+ * Contract (see docs/architecture.md, "Catalog publication"):
5
+ *
6
+ * - Every writer and every coordinated reader of one output directory uses a
7
+ * lock directory that sits beside the output, in the output's real parent.
8
+ * The lock is keyed by the output, never by `TMPDIR`, so processes with
9
+ * different temporary directories, users or working directories still meet.
10
+ * - Supported filesystems are local filesystems where `mkdir` and same-directory
11
+ * `rename` are atomic: Linux (ext4, xfs, btrfs, tmpfs, overlayfs), macOS
12
+ * (APFS, HFS+) and Windows (NTFS, ReFS). Network filesystems are not
13
+ * supported: their lock leases depend on clocks and caches this module does
14
+ * not control.
15
+ * - A sync reads a base snapshot under the lock, builds without it, and then
16
+ * publishes only if the output still has the same fingerprint (compare and
17
+ * swap). A writer that replaced the catalog in between makes the later
18
+ * publication fail with `CATALOG_BASE_CHANGED` instead of being overwritten.
19
+ * - Publication stages a complete directory, records a journal, moves the
20
+ * current output to `<output>.previous`, then renames the staged directory
21
+ * into place. Coordinated readers never observe the window between the two
22
+ * renames. A process killed at any point leaves a journal that the next lock
23
+ * holder (writer or reader) rolls back or forward before doing anything else.
24
+ * - A lock whose holder process is gone (same host) or whose heartbeat is older
25
+ * than the lease is broken automatically and safely: the stale directory is
26
+ * renamed aside first, so only one contender can break it, and a holder that
27
+ * lost its lock refuses to swap with `CATALOG_LOCK_LOST`.
28
+ */
29
+ import { createHash, randomUUID } from 'node:crypto';
30
+ import { promises as fs } from 'node:fs';
31
+ import { hostname } from 'node:os';
32
+ import { basename, dirname, join, sep } from 'node:path';
33
+ import { setTimeout as sleep } from 'node:timers/promises';
34
+ import { writeDurably } from './fs-atomic.js';
35
+ const LOCK_PREFIX = '.catalog-';
36
+ const ABSENT = 'absent';
37
+ const READ_ONLY_CODES = new Set(['EACCES', 'EPERM', 'EROFS']);
38
+ /** Names the coordination files of one output, beside it in its real parent. */
39
+ export function catalogPathsIn(parent, name) {
40
+ const normalized = name.normalize('NFC').toLowerCase();
41
+ // Case-insensitive and Unicode-normalized so that `Generated` and
42
+ // `generated` on macOS or Windows share one lock. On a case-sensitive
43
+ // filesystem such outputs are merely serialized together, which is harmless.
44
+ const hash = createHash('sha256').update(normalized).digest('hex').slice(0, 16);
45
+ const label = normalized.replace(/[^a-z0-9_-]/g, '_').slice(0, 32);
46
+ const stem = `${LOCK_PREFIX}${label}-${hash}`;
47
+ const output = join(parent, name);
48
+ const lock = `${stem}.lock`;
49
+ return {
50
+ output,
51
+ parent,
52
+ backup: `${output}.previous`,
53
+ lock: join(parent, lock),
54
+ owner: join(parent, lock, 'owner.json'),
55
+ journal: join(parent, `${stem}.journal.json`),
56
+ stagePrefix: join(parent, `${stem}.stage-`),
57
+ };
58
+ }
59
+ function isReservedName(name) {
60
+ return name.startsWith(LOCK_PREFIX);
61
+ }
62
+ function reserved(component) {
63
+ return isReservedName(component) || component.endsWith('.previous');
64
+ }
65
+ /** Resolves the output's real parent, optionally creating it. */
66
+ async function resolvePaths(output, create) {
67
+ // Not `resolve()`: it would collapse `link/..` lexically, while the
68
+ // filesystem resolves the symbolic link first. `realpath` below does that.
69
+ const name = basename(output);
70
+ const parent = dirname(output);
71
+ // Reading a backup or a coordination directory, for example while
72
+ // inspecting one by hand, is allowed but not coordinated; writing is not.
73
+ if (create && (name === '' || name === '.' || name === '..'))
74
+ throw new Error(`CATALOG_OUTPUT_INVALID: ${output}`);
75
+ if (reserved(name) || parent.split(/[\\/]/).some(reserved)) {
76
+ if (!create)
77
+ return undefined;
78
+ throw new Error(`CATALOG_WRITE_LOCK_RESERVED: ${output}`);
79
+ }
80
+ if (create)
81
+ await fs.mkdir(parent, { recursive: true });
82
+ let actualParent;
83
+ try {
84
+ actualParent = await fs.realpath(parent);
85
+ }
86
+ catch (error) {
87
+ if (!create && error.code === 'ENOENT')
88
+ return undefined;
89
+ throw error;
90
+ }
91
+ // An output reached through a coordination directory, for example a
92
+ // symbolic link into another output's lock, would be destroyed when that
93
+ // lock is released or broken.
94
+ if (actualParent.split(sep).some(reserved)) {
95
+ if (!create)
96
+ return undefined;
97
+ throw new Error(`CATALOG_WRITE_LOCK_RESERVED: ${output}`);
98
+ }
99
+ return catalogPathsIn(actualParent, name);
100
+ }
101
+ async function inspectHolder(lock) {
102
+ const owner = join(lock, 'owner.json');
103
+ try {
104
+ const [text, stat] = await Promise.all([fs.readFile(owner, 'utf8'), fs.stat(owner)]);
105
+ const parsed = JSON.parse(text);
106
+ return {
107
+ ...(typeof parsed.token === 'string' ? { token: parsed.token } : {}),
108
+ ...(typeof parsed.pid === 'number' ? { pid: parsed.pid } : {}),
109
+ ...(typeof parsed.host === 'string' ? { host: parsed.host } : {}),
110
+ heartbeatAt: stat.mtimeMs,
111
+ };
112
+ }
113
+ catch (error) {
114
+ const code = error.code;
115
+ if (code !== 'ENOENT' && !(error instanceof SyntaxError))
116
+ throw error;
117
+ }
118
+ // The holder created the directory but has not written its owner record yet
119
+ // (or was killed in between): the directory's own age is the heartbeat.
120
+ try {
121
+ return { heartbeatAt: (await fs.stat(lock)).mtimeMs };
122
+ }
123
+ catch (error) {
124
+ if (error.code === 'ENOENT')
125
+ return undefined;
126
+ throw error;
127
+ }
128
+ }
129
+ function processIsAlive(pid) {
130
+ try {
131
+ process.kill(pid, 0);
132
+ return true;
133
+ }
134
+ catch (error) {
135
+ return error.code === 'EPERM';
136
+ }
137
+ }
138
+ function holderIsStale(holder, staleAfterMs) {
139
+ if (holder.pid !== undefined && holder.host === hostname() && !processIsAlive(holder.pid))
140
+ return true;
141
+ return Date.now() - holder.heartbeatAt > staleAfterMs;
142
+ }
143
+ /**
144
+ * Breaks a stale lock. Renaming first means two contenders cannot both remove
145
+ * it; re-inspecting the renamed directory catches the case where the stale
146
+ * lock was replaced by a live one between inspection and rename.
147
+ */
148
+ async function breakLock(paths, staleAfterMs) {
149
+ const grave = `${paths.lock}.stale-${randomUUID()}`;
150
+ try {
151
+ await fs.rename(paths.lock, grave);
152
+ }
153
+ catch (error) {
154
+ if (error.code === 'ENOENT')
155
+ return;
156
+ throw error;
157
+ }
158
+ const taken = await inspectHolder(grave);
159
+ if (taken && !holderIsStale(taken, staleAfterMs)) {
160
+ // A live holder: give the lock back. If someone already took the name,
161
+ // the live holder will see CATALOG_LOCK_LOST before it swaps anything.
162
+ await fs.rename(grave, paths.lock).catch(() => undefined);
163
+ return;
164
+ }
165
+ await fs.rm(grave, { recursive: true, force: true });
166
+ }
167
+ export class CatalogLock {
168
+ paths;
169
+ token;
170
+ #timer;
171
+ #released = false;
172
+ constructor(paths, token, heartbeatMs) {
173
+ this.paths = paths;
174
+ this.token = token;
175
+ this.#timer = setInterval(() => {
176
+ const now = new Date();
177
+ fs.utimes(paths.owner, now, now).catch(() => undefined);
178
+ }, heartbeatMs);
179
+ this.#timer.unref?.();
180
+ }
181
+ /** Fails with `CATALOG_LOCK_LOST` if another process broke this lock. */
182
+ async assertHeld() {
183
+ const holder = await inspectHolder(this.paths.lock);
184
+ if (holder?.token !== this.token)
185
+ throw new Error(`CATALOG_LOCK_LOST: ${this.paths.output}`);
186
+ }
187
+ async release() {
188
+ if (this.#released)
189
+ return;
190
+ this.#released = true;
191
+ clearInterval(this.#timer);
192
+ const holder = await inspectHolder(this.paths.lock);
193
+ if (holder?.token !== this.token)
194
+ return;
195
+ await fs.rm(this.paths.lock, { recursive: true, force: true });
196
+ }
197
+ }
198
+ async function acquire(paths, mode, options) {
199
+ const waitMs = options.waitMs ?? 30_000;
200
+ const staleAfterMs = options.staleAfterMs ?? 120_000;
201
+ const pollMs = options.pollMs ?? 50;
202
+ const deadline = Date.now() + waitMs;
203
+ for (;;) {
204
+ try {
205
+ await fs.mkdir(paths.lock);
206
+ }
207
+ catch (error) {
208
+ const code = error.code;
209
+ // A read-only output cannot be published by anyone using this mount, so
210
+ // a reader proceeds without coordination there.
211
+ if (mode === 'read' && code !== undefined && READ_ONLY_CODES.has(code))
212
+ return undefined;
213
+ if (code !== 'EEXIST')
214
+ throw error;
215
+ const holder = await inspectHolder(paths.lock);
216
+ if (holder === undefined)
217
+ continue;
218
+ if (holderIsStale(holder, staleAfterMs)) {
219
+ await breakLock(paths, staleAfterMs);
220
+ continue;
221
+ }
222
+ if (Date.now() >= deadline) {
223
+ const who = holder.pid === undefined ? '' : ` (held by pid ${holder.pid} on ${holder.host})`;
224
+ throw new Error(`CATALOG_WRITE_IN_PROGRESS: ${paths.output}${who}`, { cause: error });
225
+ }
226
+ await sleep(pollMs);
227
+ continue;
228
+ }
229
+ const token = randomUUID();
230
+ try {
231
+ await fs.writeFile(paths.owner, `${JSON.stringify({ token, pid: process.pid, host: hostname(), mode, acquiredAt: new Date().toISOString() })}\n`, { flag: 'wx' });
232
+ }
233
+ catch (error) {
234
+ // A contender that misjudged a live lock as stale restored it over the
235
+ // directory just created here (see breakLock): the lock is not ours.
236
+ if (error.code === 'EEXIST')
237
+ continue;
238
+ throw error;
239
+ }
240
+ const lock = new CatalogLock(paths, token, options.heartbeatMs ?? 5_000);
241
+ try {
242
+ await options.onLocked?.(mode);
243
+ }
244
+ catch (error) {
245
+ await lock.release();
246
+ throw error;
247
+ }
248
+ return lock;
249
+ }
250
+ }
251
+ async function exists(path) {
252
+ try {
253
+ await fs.lstat(path);
254
+ return true;
255
+ }
256
+ catch (error) {
257
+ if (error.code === 'ENOENT')
258
+ return false;
259
+ throw error;
260
+ }
261
+ }
262
+ async function readJournal(paths) {
263
+ let text;
264
+ try {
265
+ text = await fs.readFile(paths.journal, 'utf8');
266
+ }
267
+ catch (error) {
268
+ if (error.code === 'ENOENT')
269
+ return undefined;
270
+ throw error;
271
+ }
272
+ try {
273
+ const parsed = JSON.parse(text);
274
+ if (parsed.version === 1 &&
275
+ typeof parsed.stage === 'string' &&
276
+ join(paths.parent, parsed.stage).startsWith(paths.stagePrefix) &&
277
+ !parsed.stage.includes(sep) &&
278
+ !parsed.stage.includes('/'))
279
+ return parsed;
280
+ }
281
+ catch {
282
+ // An empty or torn journal: the writer died while writing it, before it
283
+ // moved anything, so the output and backup have not been touched.
284
+ return { version: 1, stage: '' };
285
+ }
286
+ throw new Error(`CATALOG_RECOVERY_REQUIRED: unrecognized journal ${paths.journal}`);
287
+ }
288
+ /** Best effort: directory fsync is unavailable on Windows and some filesystems. */
289
+ async function syncDirectory(path) {
290
+ let handle;
291
+ try {
292
+ handle = await fs.open(path, 'r');
293
+ await handle.sync();
294
+ }
295
+ catch {
296
+ // Process-crash safety does not depend on it; power-loss durability does.
297
+ }
298
+ finally {
299
+ await handle?.close().catch(() => undefined);
300
+ }
301
+ }
302
+ async function removeOrphanStages(paths, keep) {
303
+ const prefix = basename(paths.stagePrefix);
304
+ for (const name of await fs.readdir(paths.parent))
305
+ if (name.startsWith(prefix) && name !== keep)
306
+ await fs.rm(join(paths.parent, name), { recursive: true, force: true });
307
+ }
308
+ /**
309
+ * Completes or undoes an interrupted publication. Must run under the lock.
310
+ *
311
+ * | output | backup | staged dir | meaning | action |
312
+ * | ------ | ------ | ---------- | -------------------------------- | -------------- |
313
+ * | yes | no | any | not swapped, or already cleaned | drop staging |
314
+ * | no | yes | any | died between the two renames | roll back |
315
+ * | yes | yes | no | swapped, backup not yet removed | roll forward |
316
+ * | no | no | any | first publication never swapped | drop staging |
317
+ * | yes | yes | yes | inconsistent | stop, preserve |
318
+ */
319
+ export async function recoverCatalogOutput(paths) {
320
+ const journal = await readJournal(paths);
321
+ if (journal === undefined) {
322
+ // Staging directories without a journal belong to a writer that died
323
+ // before it recorded anything; nothing else references them.
324
+ await removeOrphanStages(paths);
325
+ return;
326
+ }
327
+ const stage = journal.stage === '' ? undefined : join(paths.parent, journal.stage);
328
+ const [hasOutput, hasBackup, hasStage] = await Promise.all([
329
+ exists(paths.output),
330
+ exists(paths.backup),
331
+ stage ? exists(stage) : Promise.resolve(false),
332
+ ]);
333
+ if (stage === undefined && hasBackup)
334
+ // A torn journal is written before anything moves, so a backup next to it
335
+ // was not made by that writer.
336
+ throw new Error(`CATALOG_RECOVERY_REQUIRED: preserve and inspect ${paths.backup}`);
337
+ if (!hasOutput && hasBackup)
338
+ await fs.rename(paths.backup, paths.output);
339
+ else if (hasOutput && hasBackup && !hasStage)
340
+ await fs.rm(paths.backup, { recursive: true, force: true });
341
+ else if (hasOutput && hasBackup)
342
+ throw new Error(`CATALOG_RECOVERY_REQUIRED: preserve and inspect ${paths.backup}`);
343
+ await removeOrphanStages(paths);
344
+ await syncDirectory(paths.parent);
345
+ await fs.rm(paths.journal, { force: true });
346
+ }
347
+ /**
348
+ * A digest of the output's entries and bytes, or `absent`. Run it under the
349
+ * lock (inside {@link withCatalogRead}) so it describes a published state.
350
+ */
351
+ export async function catalogFingerprint(output) {
352
+ let names;
353
+ try {
354
+ names = (await fs.readdir(output)).toSorted();
355
+ }
356
+ catch (error) {
357
+ if (error.code === 'ENOENT')
358
+ return ABSENT;
359
+ throw error;
360
+ }
361
+ const hash = createHash('sha256');
362
+ for (const name of names) {
363
+ const path = join(output, name);
364
+ const stat = await fs.lstat(path);
365
+ hash.update(`${name}\0`);
366
+ if (stat.isFile())
367
+ hash.update('f\0').update(await fs.readFile(path));
368
+ else if (stat.isSymbolicLink())
369
+ hash.update('l\0').update(await fs.readlink(path));
370
+ else
371
+ hash.update(`o\0${stat.mode}\0${stat.size}`);
372
+ hash.update('\0');
373
+ }
374
+ return `sha256:${hash.digest('hex')}`;
375
+ }
376
+ /**
377
+ * Runs `read` while no writer can publish to `output`, after finishing any
378
+ * interrupted publication. Readers are serialized with writers and with each
379
+ * other; the lock is held only for the read itself.
380
+ */
381
+ export async function withCatalogRead(output, read, options = {}) {
382
+ const paths = await resolvePaths(output, false);
383
+ if (paths === undefined)
384
+ return read();
385
+ const lock = await acquire(paths, 'read', options);
386
+ try {
387
+ if (lock)
388
+ await recoverCatalogOutput(paths);
389
+ return await read();
390
+ }
391
+ finally {
392
+ await lock?.release();
393
+ }
394
+ }
395
+ /**
396
+ * Replaces `output` with exactly `files`. The previous output stays in place
397
+ * until the new one is complete, and a coordinated reader sees either one or
398
+ * the other.
399
+ */
400
+ export async function publishCatalog(output, files, options = {}) {
401
+ const paths = await resolvePaths(output, true);
402
+ if (paths === undefined)
403
+ throw new Error(`CATALOG_OUTPUT_UNRESOLVED: ${output}`);
404
+ await options.onStep?.('acquiring');
405
+ const lock = await acquire(paths, 'write', options);
406
+ if (lock === undefined)
407
+ throw new Error(`CATALOG_OUTPUT_UNRESOLVED: ${output}`);
408
+ try {
409
+ await recoverCatalogOutput(paths);
410
+ // A backup without a journal predates coordinated publication or was made
411
+ // by hand. Its provenance is unknown, so it is never deleted or restored.
412
+ if (await exists(paths.backup))
413
+ throw new Error(`CATALOG_RECOVERY_REQUIRED: preserve and inspect ${paths.backup}`);
414
+ if (options.expectedBase !== undefined) {
415
+ const current = await catalogFingerprint(paths.output);
416
+ if (current !== options.expectedBase)
417
+ throw new Error(`CATALOG_BASE_CHANGED: ${paths.output} was replaced after this sync read it; run the sync again`);
418
+ }
419
+ const stage = await fs.mkdtemp(paths.stagePrefix);
420
+ try {
421
+ await writeDurably(paths.journal, `${JSON.stringify({ version: 1, stage: basename(stage) })}\n`);
422
+ for (const [name, content] of Object.entries(files)) {
423
+ if (name === '' ||
424
+ name.includes('/') ||
425
+ name.includes('\\') ||
426
+ name === '.' ||
427
+ name === '..')
428
+ throw new Error(`CATALOG_ARTIFACT_NAME_INVALID: ${name}`);
429
+ await writeDurably(join(stage, name), content);
430
+ }
431
+ await syncDirectory(stage);
432
+ await options.onStep?.('staged');
433
+ await lock.assertHeld();
434
+ try {
435
+ await fs.rename(paths.output, paths.backup);
436
+ }
437
+ catch (error) {
438
+ if (error.code !== 'ENOENT')
439
+ throw error;
440
+ }
441
+ await options.onStep?.('backed-up');
442
+ await fs.rename(stage, paths.output);
443
+ await syncDirectory(paths.parent);
444
+ await options.onStep?.('swapped');
445
+ await fs.rm(paths.backup, { recursive: true, force: true });
446
+ await fs.rm(paths.journal, { force: true });
447
+ await options.onStep?.('cleaned');
448
+ }
449
+ catch (error) {
450
+ // Same state machine a later process would run after a crash, unless
451
+ // another process now holds the lock: then it owns the recovery.
452
+ const held = await lock.assertHeld().then(() => true, () => false);
453
+ if (held)
454
+ await recoverCatalogOutput(paths);
455
+ throw error;
456
+ }
457
+ await options.afterPublish?.();
458
+ }
459
+ finally {
460
+ await lock.release();
461
+ }
462
+ }
463
+ //# sourceMappingURL=catalog-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog-store.js","sourceRoot":"","sources":["../src/catalog-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAgC7C,MAAM,WAAW,GAAG,WAAW,CAAA;AAC/B,MAAM,MAAM,GAAG,QAAQ,CAAA;AACvB,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;AAY7D,gFAAgF;AAChF,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,IAAY;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,S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BACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;oBAAE,MAAM,KAAK,CAAA;YACrE,CAAC;YACD,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,CAAA;YACnC,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;YACpC,MAAM,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YACjC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAA;YACjC,MAAM,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;YAC3D,MAAM,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;YAC3C,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAA;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qEAAqE;YACrE,iEAAiE;YACjE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CACvC,GAAG,EAAE,CAAC,IAAI,EACV,GAAG,EAAE,CAAC,KAAK,CACZ,CAAA;YACD,IAAI,IAAI;gBAAE,MAAM,oBAAoB,CAAC,KAAK,CAAC,CAAA;YAC3C,MAAM,KAAK,CAAA;QACb,CAAC;QACD,MAAM,OAAO,CAAC,YAAY,EAAE,EAAE,CAAA;IAChC,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,CAAC,OAAO,EAAE,CAAA;IACtB,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function mapWithConcurrency<T, U>(values: readonly T[], concurrency: number, mapper: (value: T, index: number) => Promise<U>): Promise<U[]>;
@@ -0,0 +1,15 @@
1
+ export async function mapWithConcurrency(values, concurrency, mapper) {
2
+ const results = Array.from({ length: values.length });
3
+ let nextIndex = 0;
4
+ const worker = async () => {
5
+ while (true) {
6
+ const index = nextIndex++;
7
+ if (index >= values.length)
8
+ return;
9
+ results[index] = await mapper(values[index], index);
10
+ }
11
+ };
12
+ await Promise.all(Array.from({ length: Math.min(Math.max(concurrency, 1), values.length) }, () => worker()));
13
+ return results;
14
+ }
15
+ //# sourceMappingURL=concurrency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency.js","sourceRoot":"","sources":["../src/concurrency.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAoB,EACpB,WAAmB,EACnB,MAA+C;IAE/C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;IACxD,IAAI,SAAS,GAAG,CAAC,CAAA;IACjB,MAAM,MAAM,GAAG,KAAK,IAAmB,EAAE;QACvC,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,KAAK,GAAG,SAAS,EAAE,CAAA;YACzB,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM;gBAAE,OAAM;YAClC,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,CAAA;QACtD,CAAC;IACH,CAAC,CAAA;IACD,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,CAC1F,CAAA;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -24,7 +24,7 @@ export declare function parseProductPreference(input: unknown): ProductPreferenc
24
24
  export interface ProductIcon {
25
25
  /** `content` is the vendor's own plugin file; `favicon` is the product site's. */
26
26
  readonly kind: 'content' | 'favicon';
27
- /** Release asset name; fetch it from the release for this `catalogId`. */
27
+ /** Content-addressed asset name, published beside the catalog's artifacts. */
28
28
  readonly asset: string;
29
29
  /**
30
30
  * Absolute, immutable URL for the asset, present when the build knows where
@@ -75,31 +75,6 @@ export interface ConsumerRelease {
75
75
  readonly packageStatus?: string;
76
76
  readonly packageDigest?: string;
77
77
  }
78
- /** One installable product, resolved from every source variant that publishes it. */ /**
79
- * The install-relevant facts of the release a product installs.
80
- *
81
- * A browsing client shows a plugin, then plans an install from it: the digest it
82
- * must pin, the connectors and credentials setup will ask for, and the
83
- * capabilities the harness has to negotiate. Carrying them here means the grid
84
- * needs no second artifact.
85
- */
86
- export interface ConsumerRelease {
87
- readonly releaseId: string;
88
- readonly canonicalContentDigest: string;
89
- readonly contentResolution: string;
90
- readonly capabilities: readonly {
91
- readonly type: string;
92
- readonly name: string;
93
- }[];
94
- readonly requiredConnectors: readonly string[];
95
- readonly requiredCredentials: readonly string[];
96
- /** Commit the release was resolved from, for audit and update state. */
97
- readonly sourceRevision: string;
98
- readonly upstreamVersion?: string;
99
- /** Canonical package status, when the release carries one. */
100
- readonly packageStatus?: string;
101
- readonly packageDigest?: string;
102
- }
103
78
  /** One installable product, resolved from every source variant that publishes it. */
104
79
  export interface ConsumerProduct {
105
80
  readonly productKey: string;
@@ -158,7 +133,7 @@ export interface ConsumerCategory {
158
133
  export interface LeadingDiagnostic {
159
134
  readonly category: string;
160
135
  readonly name: string;
161
- readonly reason: 'UNKNOWN_CATEGORY' | 'PRODUCT_NOT_FOUND' | 'PRODUCT_NOT_IN_CATEGORY';
136
+ readonly reason: 'UNKNOWN_CATEGORY' | 'PRODUCT_NOT_FOUND' | 'PRODUCT_NOT_IN_CATEGORY' | 'PRODUCT_AMBIGUOUS';
162
137
  }
163
138
  /** Brand-mark coverage, so an incomplete set is visible rather than implied. */
164
139
  export interface IconCoverage {
@@ -206,10 +181,13 @@ export declare function monogramFor(displayName: string, productKey: string): Pr
206
181
  * stable identifiers.
207
182
  */
208
183
  export declare function buildConsumerIndex(input: {
209
- readonly catalog: Pick<Catalog, 'plugins' | 'sources'>;
184
+ /** A catalog without its ID yields records with no published asset URLs. */
185
+ readonly catalog: Pick<Catalog, 'plugins' | 'sources'> & {
186
+ readonly catalogId?: string;
187
+ };
210
188
  readonly leading?: Readonly<Record<string, readonly string[]>>;
211
189
  readonly topCount?: number;
212
- readonly preference?: ProductPreference;
190
+ readonly productPreference?: ProductPreference;
213
191
  /** Where the catalog will be published, so records can carry absolute URLs. */
214
192
  readonly publicationRepositoryUrl?: string;
215
193
  /** Committed asset base a browser can fetch directly; preferred when set. */