@orkestrel/capture 0.0.0-stage → 0.0.1

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.
@@ -0,0 +1,1043 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _orkestrel_contract = require("@orkestrel/contract");
3
+ // src/core/constants.ts
4
+ /**
5
+ * Lists the condition axes a capture failure carries, in the order the executable reports them.
6
+ *
7
+ * @remarks
8
+ * `USAGE` is a refused command line and exits 64; every other condition exits 1. `SELECTION`
9
+ * names a selector, variant, case, state, or portfolio the host does not declare. `HOST` names a
10
+ * wrapper, configuration, or declaration fault. `STAGE` names a runner stage that did not
11
+ * complete. `EVIDENCE` names a record, report, registry, or manifest that fails its protocol.
12
+ * `CONTAINMENT` names a path that leaves the authorized roots.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * CAPTURE_ERROR_CODES.includes('USAGE') // true
17
+ * ```
18
+ */
19
+ var CAPTURE_ERROR_CODES = Object.freeze([
20
+ "USAGE",
21
+ "SELECTION",
22
+ "HOST",
23
+ "STAGE",
24
+ "EVIDENCE",
25
+ "CONTAINMENT"
26
+ ]);
27
+ /**
28
+ * Keys the global brand a capture error carries, so a duplicate installation recognizes it.
29
+ *
30
+ * @remarks
31
+ * The key follows the package-and-class form, `Symbol.for('<package>.<ClassName>')`. The brand is
32
+ * a recognition marker and never proof that the class's constructor ran.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * CAPTURE_ERROR_BRAND === Symbol.for('@orkestrel/capture.CaptureError') // true
37
+ * ```
38
+ */
39
+ var CAPTURE_ERROR_BRAND = Symbol.for("@orkestrel/capture.CaptureError");
40
+ /**
41
+ * Lists the non-current freshness classifications from highest precedence to lowest.
42
+ *
43
+ * @remarks
44
+ * `resolveCaptureStatus` reads this order to choose a frame's primary classification while the
45
+ * reading keeps every finding separately. A frame with none of these is current.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * CAPTURE_STATUS_PRECEDENCE[0] // 'duplicate'
50
+ * ```
51
+ */
52
+ var CAPTURE_STATUS_PRECEDENCE = Object.freeze([
53
+ "duplicate",
54
+ "orphan",
55
+ "missing",
56
+ "unstamped",
57
+ "stale-shared",
58
+ "stale-own"
59
+ ]);
60
+ /**
61
+ * Names the file prefix of a runner request, completed by the runner's process id and `.json`.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * `${CAPTURE_REQUEST_PREFIX}-${process.pid}.json` // 'journey-selection-4242.json'
66
+ * ```
67
+ */
68
+ var CAPTURE_REQUEST_PREFIX = "journey-selection";
69
+ /**
70
+ * Holds the protocol version every request, record, receipt, registry, and manifest declares.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * CAPTURE_VERSION // 1
75
+ * ```
76
+ */
77
+ var CAPTURE_VERSION = 1;
78
+ /**
79
+ * Holds the eight bytes every PNG file opens with.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * CAPTURE_PNG_SIGNATURE.map((byte) => byte.toString(16)).join('') // '89504e470d0a1a0a'
84
+ * ```
85
+ */
86
+ var CAPTURE_PNG_SIGNATURE = Object.freeze([
87
+ 137,
88
+ 80,
89
+ 78,
90
+ 71,
91
+ 13,
92
+ 10,
93
+ 26,
94
+ 10
95
+ ]);
96
+ /**
97
+ * Names the default accepted complete-run registry file inside a portfolio directory.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * `tmp/captures/states/${CAPTURE_REGISTRY_FILE}` // 'tmp/captures/states/registry.json'
102
+ * ```
103
+ */
104
+ var CAPTURE_REGISTRY_FILE = "registry.json";
105
+ /**
106
+ * Names the default image-stamp manifest file inside a portfolio directory.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * `tmp/captures/states/${CAPTURE_MANIFEST_FILE}` // 'tmp/captures/states/manifest.json'
111
+ * ```
112
+ */
113
+ var CAPTURE_MANIFEST_FILE = "manifest.json";
114
+ /**
115
+ * Names the default lookup journal file inside a portfolio directory.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * `tmp/captures/states/${CAPTURE_LOOKUPS_FILE}` // 'tmp/captures/states/lookups.json'
120
+ * ```
121
+ */
122
+ var CAPTURE_LOOKUPS_FILE = "lookups.json";
123
+ // src/core/errors.ts
124
+ /**
125
+ * Reports one capture failure under a stable condition axis.
126
+ *
127
+ * @remarks
128
+ * Every refusal the engine, the runner, and the readers raise arrives as one of these, so the
129
+ * executable branches on `code` rather than on message text: `USAGE` exits 64 and every other
130
+ * condition exits 1. Narrow a caught value with `isCaptureError` before reading `code`.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * const error = new CaptureError('Unknown variant: phone', {
135
+ * code: 'SELECTION',
136
+ * context: { variant: 'phone' },
137
+ * })
138
+ * error.code // 'SELECTION'
139
+ * error.context?.variant // 'phone'
140
+ * ```
141
+ */
142
+ var CaptureError = class extends Error {
143
+ name = "CaptureError";
144
+ code;
145
+ context;
146
+ /**
147
+ * Creates one classified capture failure.
148
+ *
149
+ * @param message - Human-readable description of what failed
150
+ * @param options - The condition, optional structured context, and optional cause
151
+ */
152
+ constructor(message, options) {
153
+ super(message, "cause" in options ? { cause: options.cause } : void 0);
154
+ Object.defineProperty(this, CAPTURE_ERROR_BRAND, { value: this });
155
+ this.code = options.code;
156
+ this.context = options.context;
157
+ }
158
+ };
159
+ /**
160
+ * Checks whether an unknown value is a capture error.
161
+ *
162
+ * @remarks
163
+ * Recognition requires a native `Error` whose prototype is not `Error.prototype`, an own brand
164
+ * property holding the tested value itself, a declared condition code, and a record or absent
165
+ * context. It recognizes an error from another installed copy of this package, and refuses a
166
+ * look-alike with the same code and no brand, a proxy over a branded error, and a plain object
167
+ * that only carries the brand.
168
+ *
169
+ * @param value - The value to inspect
170
+ * @returns True if the value is a `CaptureError`; false otherwise
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * isCaptureError(new CaptureError('Empty selection', { code: 'USAGE' })) // true
175
+ * isCaptureError(new Error('Empty selection')) // false
176
+ * ```
177
+ */
178
+ function isCaptureError(value) {
179
+ return (0, _orkestrel_contract.holds)(() => {
180
+ if (!(0, _orkestrel_contract.isError)(value) || _orkestrel_contract.INTRINSICS.prototype(value) === _orkestrel_contract.INTRINSICS.error.prototype) return false;
181
+ if (_orkestrel_contract.INTRINSICS.describe(value, CAPTURE_ERROR_BRAND)?.value !== value) return false;
182
+ const code = _orkestrel_contract.INTRINSICS.reflect.read(value, "code");
183
+ const context = _orkestrel_contract.INTRINSICS.reflect.read(value, "context");
184
+ return CAPTURE_ERROR_CODES.some((declared) => declared === code) && (context === void 0 || (0, _orkestrel_contract.isRecord)(context));
185
+ });
186
+ }
187
+ // src/core/validators.ts
188
+ /**
189
+ * Checks whether a serialized path stays within the portable relative-path vocabulary.
190
+ *
191
+ * @param value - The serialized file or directory path
192
+ * @returns True if every segment is portable and relative; false otherwise
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * isCapturePath('tmp/captures/states/pages/mail--inbox.png') // true
197
+ * isCapturePath('../escape.png') // false
198
+ * ```
199
+ */
200
+ function isCapturePath(value) {
201
+ return typeof value === "string" && value.length > 0 && [...value].every((character) => character.charCodeAt(0) > 31) && value.split("/").every((segment) => segment !== "" && segment !== "." && segment !== ".." && !/[<>:"\\|?*]/u.test(segment) && !/[. ]$/u.test(segment) && !/^(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/iu.test(segment));
202
+ }
203
+ /**
204
+ * Checks whether a native glob declaration uses relative portable path segments.
205
+ *
206
+ * @param value - A source attribution pattern
207
+ * @returns True if the pattern has no path traversal or host-specific spelling; false otherwise
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * isCapturePattern('src/**') // true
212
+ * isCapturePattern('src\\**') // false
213
+ * ```
214
+ */
215
+ function isCapturePattern(value) {
216
+ return typeof value === "string" && value.length > 0 && [...value].every((character) => character.charCodeAt(0) > 31) && value.split("/").every((segment) => segment !== "" && segment !== "." && segment !== ".." && !/[<>:"\\|]/u.test(segment) && !/[. ]$/u.test(segment) && !/^(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/iu.test(segment));
217
+ }
218
+ /**
219
+ * Checks whether a protocol identity can occupy one portable path segment.
220
+ *
221
+ * @param value - The identity segment
222
+ * @returns True if the segment is safe and nonempty; false otherwise
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * isCaptureSegment('light-390') // true
227
+ * isCaptureSegment('light 390') // false
228
+ * ```
229
+ */
230
+ function isCaptureSegment(value) {
231
+ return isCapturePath(value) && /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/u.test(value);
232
+ }
233
+ /**
234
+ * Checks whether an owner selector uses canonical colon-separated segments.
235
+ *
236
+ * @param value - The owner selector
237
+ * @returns True if every owner segment is canonical; false otherwise
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * isCaptureSelector('pages:mail') // true
242
+ * isCaptureSelector('pages::mail') // false
243
+ * ```
244
+ */
245
+ function isCaptureSelector(value) {
246
+ return typeof value === "string" && value.split(":").every(isCaptureSegment);
247
+ }
248
+ /**
249
+ * Checks whether a value is a SHA-256 hexadecimal digest.
250
+ *
251
+ * @param value - The digest
252
+ * @returns True if the digest has the expected hexadecimal width; false otherwise
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * isCaptureHash('a'.repeat(64)) // true
257
+ * isCaptureHash('abc') // false
258
+ * ```
259
+ */
260
+ function isCaptureHash(value) {
261
+ return typeof value === "string" && /^[a-f0-9]{64}$/u.test(value);
262
+ }
263
+ /**
264
+ * Checks whether a file-hash map has portable keys and valid digests.
265
+ *
266
+ * @param value - The hash map
267
+ * @returns True if every key and digest is valid and no two keys differ only by case; false otherwise
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * isCaptureHashes({ 'src/index.ts': 'a'.repeat(64) }) // true
272
+ * isCaptureHashes({ 'src/index.ts': 'x' }) // false
273
+ * ```
274
+ */
275
+ function isCaptureHashes(value) {
276
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && Object.entries(value).every(([file, digest]) => isCapturePath(file) && isCaptureHash(digest)) && new Set(Object.keys(value).map((file) => file.toLowerCase())).size === Object.keys(value).length);
277
+ }
278
+ /**
279
+ * Checks whether source attribution separates own, shared, and behavioral patterns.
280
+ *
281
+ * @param value - The attribution
282
+ * @returns True if every declared pattern is valid; false otherwise
283
+ *
284
+ * @example
285
+ * ```ts
286
+ * isCaptureSources({ own: ['src/mail/**'], shared: [], tests: [] }) // true
287
+ * isCaptureSources({ own: ['../x'], shared: [], tests: [] }) // false
288
+ * ```
289
+ */
290
+ function isCaptureSources(value) {
291
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && (0, _orkestrel_contract.arrayOf)(isCapturePattern)(value.own) && (0, _orkestrel_contract.arrayOf)(isCapturePattern)(value.shared) && (0, _orkestrel_contract.arrayOf)(isCapturePattern)(value.tests));
292
+ }
293
+ /**
294
+ * Checks whether an execution identity carries its required authorization fields.
295
+ *
296
+ * @param value - The identity
297
+ * @returns True if the identity is valid; false otherwise
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * isCaptureIdentity({ id: 'run-1', stage: 'selected', pid: 4242, config: 'configs/journey.ts' }) // true
302
+ * isCaptureIdentity({ id: 'run-1', stage: 'selected', pid: 0, config: 'configs/journey.ts' }) // false
303
+ * ```
304
+ */
305
+ function isCaptureIdentity(value) {
306
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && isCaptureSegment(value.id) && isCaptureSegment(value.stage) && typeof value.pid === "number" && Number.isSafeInteger(value.pid) && value.pid > 0 && isCapturePath(value.config));
307
+ }
308
+ /**
309
+ * Checks whether a request has the supported version and complete execution identity.
310
+ *
311
+ * @param value - The transported request
312
+ * @returns True if every request field has its protocol shape; false otherwise
313
+ *
314
+ * @example
315
+ * ```ts
316
+ * isCaptureRequest(JSON.parse(text)) // true for a well-formed runner request
317
+ * isCaptureRequest({ version: 2 }) // false
318
+ * ```
319
+ */
320
+ function isCaptureRequest(value) {
321
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && isCaptureIdentity(value) && value.version === 1 && (value.command === "journey" || value.command === "capture") && isCaptureSelector(value.selector) && (0, _orkestrel_contract.arrayOf)(isCaptureSegment)(value.variants) && value.variants.length > 0 && (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString)(value.args) && (value.case === void 0 || typeof value.case === "string" && value.case.trim() !== "") && (value.state === void 0 || value.command === "capture" && isCaptureSegment(value.state)));
322
+ }
323
+ /**
324
+ * Checks whether a collected declaration preserves its full owner and state population.
325
+ *
326
+ * @param value - The declaration
327
+ * @returns True if the declaration has its supported shape; false otherwise
328
+ *
329
+ * @example
330
+ * ```ts
331
+ * isCaptureDeclaration({
332
+ * case: 'mail shows the inbox',
333
+ * owner: 'pages:mail',
334
+ * variant: 'light-390',
335
+ * eligible: true,
336
+ * states: ['inbox'],
337
+ * }) // true
338
+ * ```
339
+ */
340
+ function isCaptureDeclaration(value) {
341
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && typeof value.case === "string" && value.case.trim() !== "" && isCaptureSelector(value.owner) && isCaptureSegment(value.variant) && typeof value.eligible === "boolean" && (0, _orkestrel_contract.arrayOf)(isCaptureSegment)(value.states));
342
+ }
343
+ /**
344
+ * Checks whether a destination supplies canonical identity and source attribution fields.
345
+ *
346
+ * @param value - The destination
347
+ * @returns True if the destination has its supported shape; false otherwise
348
+ *
349
+ * @example
350
+ * ```ts
351
+ * isCaptureDestination(JSON.parse(text)) // true for a registry destination row
352
+ * isCaptureDestination({}) // false
353
+ * ```
354
+ */
355
+ function isCaptureDestination(value) {
356
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && isCaptureSegment(value.portfolio) && isCaptureSegment(value.state) && isCaptureSegment(value.scope) && isCaptureSegment(value.part) && (value.section === void 0 || isCaptureSegment(value.section)) && isCaptureSegment(value.variant) && typeof value.project === "string" && value.project !== "" && isCapturePath(value.file) && typeof value.case === "string" && value.case.trim() !== "" && isCaptureSources(value.sources));
357
+ }
358
+ /**
359
+ * Checks whether an emitted entry includes a finite nonnegative case duration.
360
+ *
361
+ * @param value - The emitted entry
362
+ * @returns True if the entry is valid; false otherwise
363
+ *
364
+ * @example
365
+ * ```ts
366
+ * isCaptureEntry({ ...destination, duration: 812 }) // true
367
+ * isCaptureEntry({ ...destination, duration: -1 }) // false
368
+ * ```
369
+ */
370
+ function isCaptureEntry(value) {
371
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && isCaptureDestination(value) && (0, _orkestrel_contract.isFiniteNumber)(value.duration) && value.duration >= 0);
372
+ }
373
+ /**
374
+ * Checks whether a record names its journey artifact by portable path and SHA-256 digest.
375
+ *
376
+ * @param value - The decoded artifact reference
377
+ * @returns True if the reference has its supported shape; false otherwise
378
+ *
379
+ * @example
380
+ * ```ts
381
+ * isCaptureArtifact({ file: 'tmp/runs/a/light-390.txt', digest: 'a'.repeat(64) }) // true
382
+ * isCaptureArtifact({ file: '/abs.txt', digest: 'a'.repeat(64) }) // false
383
+ * ```
384
+ */
385
+ function isCaptureArtifact(value) {
386
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && isCapturePath(value.file) && isCaptureHash(value.digest));
387
+ }
388
+ /**
389
+ * Checks whether a final record preserves declarations, observations, and output separately.
390
+ *
391
+ * @param value - The decoded run record
392
+ * @returns True if the record has the supported protocol shape; false otherwise
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * isCaptureRun(JSON.parse(text)) // true for a final run record
397
+ * isCaptureRun(null) // false
398
+ * ```
399
+ */
400
+ function isCaptureRun(value) {
401
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && value.version === 1 && isCaptureSegment(value.variant) && typeof value.time === "string" && Number.isFinite(Date.parse(value.time)) && typeof value.complete === "boolean" && typeof value.reference === "boolean" && (0, _orkestrel_contract.arrayOf)(isCaptureDeclaration)(value.declarations) && (0, _orkestrel_contract.arrayOf)(isCaptureDestination)(value.registry) && (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString)(value.passed) && (0, _orkestrel_contract.arrayOf)(isCaptureSegment)(value.observed) && (0, _orkestrel_contract.arrayOf)(isCaptureEntry)(value.entries) && (value.artifact === void 0 || isCaptureArtifact(value.artifact)) && (value.identity === void 0 && value.request === void 0 || isCaptureIdentity(value.identity) && isCaptureRequest(value.request)));
402
+ }
403
+ /**
404
+ * Checks whether a shared-source digest retains both patterns and expanded file hashes.
405
+ *
406
+ * @param value - The digest reading
407
+ * @returns True if the digest reading has its supported shape; false otherwise
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * isCaptureDigest({ patterns: ['src/**'], files: {}, digest: 'a'.repeat(64) }) // true
412
+ * isCaptureDigest({ patterns: [], files: {} }) // false
413
+ * ```
414
+ */
415
+ function isCaptureDigest(value) {
416
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && (0, _orkestrel_contract.arrayOf)(isCapturePattern)(value.patterns) && isCaptureHashes(value.files) && isCaptureHash(value.digest));
417
+ }
418
+ /**
419
+ * Checks whether a complete-run receipt binds the report, inputs, and declaration registry.
420
+ *
421
+ * @param value - The receipt
422
+ * @returns True if the receipt has its supported shape; false otherwise
423
+ *
424
+ * @example
425
+ * ```ts
426
+ * isCaptureReceipt(JSON.parse(text)) // true for a complete-run receipt
427
+ * isCaptureReceipt({}) // false
428
+ * ```
429
+ */
430
+ function isCaptureReceipt(value) {
431
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && value.version === 1 && isCaptureSegment(value.variant) && typeof value.time === "string" && Number.isFinite(Date.parse(value.time)) && (0, _orkestrel_contract.isRecord)(value.report) && isCapturePath(value.report.file) && isCaptureHash(value.report.digest) && isCaptureHashes(value.inputs) && (0, _orkestrel_contract.arrayOf)(isCaptureDeclaration)(value.declarations) && (0, _orkestrel_contract.arrayOf)(isCaptureDestination)(value.registry) && typeof value.complete === "boolean");
432
+ }
433
+ /**
434
+ * Checks whether a registry document retains its receipts and required output pairs.
435
+ *
436
+ * @param value - The registry document
437
+ * @returns True if the registry has the supported shape; false otherwise
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * isCaptureRegistry(JSON.parse(text)) // true for a published registry.json
442
+ * isCaptureRegistry([]) // false
443
+ * ```
444
+ */
445
+ function isCaptureRegistry(value) {
446
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && value.version === 1 && (0, _orkestrel_contract.arrayOf)(isCaptureReceipt)(value.receipts) && (0, _orkestrel_contract.arrayOf)(isCaptureDestination)(value.entries) && isCaptureHash(value.digest));
447
+ }
448
+ /**
449
+ * Checks whether a lookup binds a passing case to its full run record and input hashes.
450
+ *
451
+ * @param value - The lookup receipt
452
+ * @returns True if the receipt has its supported shape; false otherwise
453
+ *
454
+ * @example
455
+ * ```ts
456
+ * isCaptureLookup(JSON.parse(text)) // true for a lookup row
457
+ * isCaptureLookup(undefined) // false
458
+ * ```
459
+ */
460
+ function isCaptureLookup(value) {
461
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && isCaptureHash(value.registry) && isCaptureSegment(value.variant) && typeof value.case === "string" && value.case.trim() !== "" && isCaptureSelector(value.owner) && (0, _orkestrel_contract.arrayOf)(isCaptureSegment)(value.states) && isCaptureHashes(value.inputs) && (0, _orkestrel_contract.isRecord)(value.run) && isCapturePath(value.run.file) && isCaptureHash(value.run.digest));
462
+ }
463
+ /**
464
+ * Checks the separate lookup journal and its optional predecessor manifest digest.
465
+ *
466
+ * @param value - The decoded journal
467
+ * @returns True if the journal has its supported shape; false otherwise
468
+ * @remarks Input-map digests and reference existence are verified when the journal is read.
469
+ *
470
+ * @example
471
+ * ```ts
472
+ * isCaptureLookupJournal({ version: 1, inputs: {}, lookups: [] }) // true
473
+ * isCaptureLookupJournal({ version: 2, inputs: {}, lookups: [] }) // false
474
+ * ```
475
+ */
476
+ function isCaptureLookupJournal(value) {
477
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && (value.collections === void 0 || (0, _orkestrel_contract.arrayOf)(isCaptureCollection)(value.collections)) && value.version === 1 && (value.manifest === void 0 || isCaptureHash(value.manifest)) && (0, _orkestrel_contract.isRecord)(value.inputs) && Object.entries(value.inputs).every(([digest, inputs]) => isCaptureHash(digest) && isCaptureHashes(inputs)) && (0, _orkestrel_contract.arrayOf)((entry) => (0, _orkestrel_contract.isRecord)(entry) && isCaptureHash(entry.inputs) && isCaptureLookup({
478
+ ...entry,
479
+ inputs: {}
480
+ }))(value.lookups));
481
+ }
482
+ /**
483
+ * Checks whether a stamp binds an emitted image to source and execution provenance.
484
+ *
485
+ * @param value - The stamp
486
+ * @returns True if the stamp has its supported shape; false otherwise
487
+ *
488
+ * @example
489
+ * ```ts
490
+ * isCaptureStamp(manifest.entries['pages/mail--inbox.png']) // true for a stamped frame
491
+ * isCaptureStamp({}) // false
492
+ * ```
493
+ */
494
+ function isCaptureStamp(value) {
495
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && isCaptureEntry(value) && isCaptureIdentity(value.identity) && typeof value.time === "string" && Number.isFinite(Date.parse(value.time)) && typeof value.commit === "string" && /^[a-f0-9]{40,64}$/u.test(value.commit) && (0, _orkestrel_contract.arrayOf)(isCapturePath)(value.dirty) && isCaptureHashes(value.own) && isCaptureDigest(value.shared) && isCaptureHashes(value.tests) && isCaptureHash(value.registry) && (0, _orkestrel_contract.isRecord)(value.image) && isCaptureHash(value.image.digest) && (0, _orkestrel_contract.isFiniteNumber)(value.image.size) && Number.isSafeInteger(value.image.size) && value.image.size > 0 && (0, _orkestrel_contract.isFiniteNumber)(value.image.modified) && value.image.modified >= 0);
496
+ }
497
+ /**
498
+ * Checks whether an inherited manifest has the supported schema without discarding malformed rows.
499
+ *
500
+ * @param value - The manifest
501
+ * @returns True if every inherited member validates; false otherwise
502
+ *
503
+ * @example
504
+ * ```ts
505
+ * isCaptureManifest(JSON.parse(text)) // true for a published manifest.json
506
+ * isCaptureManifest('manifest') // false
507
+ * ```
508
+ */
509
+ function isCaptureManifest(value) {
510
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && value.version === 1 && isCaptureRegistry(value.registry) && (0, _orkestrel_contract.isRecord)(value.entries) && Object.entries(value.entries).every(([key, stamp]) => isCapturePath(key) && isCaptureStamp(stamp)) && (0, _orkestrel_contract.arrayOf)(isCaptureLookup)(value.lookups));
511
+ }
512
+ /**
513
+ * Checks whether collection evidence pins complete input membership and both external artifacts.
514
+ *
515
+ * @param value - The collection receipt
516
+ * @returns True if every field has the supported shape; false otherwise
517
+ *
518
+ * @example
519
+ * ```ts
520
+ * isCaptureCollection(manifest.collections?.[0]) // true for a collection receipt
521
+ * isCaptureCollection({}) // false
522
+ * ```
523
+ */
524
+ function isCaptureCollection(value) {
525
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && isCaptureHash(value.registry) && isCaptureSegment(value.variant) && typeof value.project === "string" && value.project.trim() !== "" && isCaptureDigest(value.inputs) && (0, _orkestrel_contract.isRecord)(value.run) && isCapturePath(value.run.file) && isCaptureHash(value.run.digest) && (0, _orkestrel_contract.isRecord)(value.report) && isCapturePath(value.report.file) && isCaptureHash(value.report.digest));
526
+ }
527
+ /**
528
+ * Checks optional collection metadata without upgrading historical image evidence.
529
+ *
530
+ * @param value - The inherited image transaction
531
+ * @returns True if its existing manifest and any collection receipts are valid; false otherwise
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * isCaptureStoredManifest(JSON.parse(text)) // true for a manifest with or without collections
536
+ * isCaptureStoredManifest(null) // false
537
+ * ```
538
+ */
539
+ function isCaptureStoredManifest(value) {
540
+ return (0, _orkestrel_contract.holds)(() => isCaptureManifest(value) && (0, _orkestrel_contract.isRecord)(value) && (value.collections === void 0 || (0, _orkestrel_contract.arrayOf)(isCaptureCollection)(value.collections)));
541
+ }
542
+ /**
543
+ * Checks the host's declared viewport without deriving geometry from an output name.
544
+ *
545
+ * @param value - The published viewport data
546
+ * @returns True if the named viewport has usable dimensions; false otherwise
547
+ *
548
+ * @example
549
+ * ```ts
550
+ * isCaptureGeometry({ name: 'light-390', width: 390, height: 844 }) // true
551
+ * isCaptureGeometry({ name: 'light-390', width: 0, height: 844 }) // false
552
+ * ```
553
+ */
554
+ function isCaptureGeometry(value) {
555
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isObject)(value) && "name" in value && isCaptureSegment(value.name) && "width" in value && (0, _orkestrel_contract.isFiniteNumber)(value.width) && value.width > 0 && "height" in value && (0, _orkestrel_contract.isFiniteNumber)(value.height) && value.height > 0);
556
+ }
557
+ /**
558
+ * Checks a journey artifact's recorded sampling box.
559
+ *
560
+ * @param value - The recorded viewport box
561
+ * @returns True if its coordinates and dimensions are finite; false otherwise
562
+ *
563
+ * @example
564
+ * ```ts
565
+ * isCaptureBox({ x: 0, y: 64, width: 390, height: 780 }) // true
566
+ * isCaptureBox({ x: 0, y: 64, width: 0, height: 780 }) // false
567
+ * ```
568
+ */
569
+ function isCaptureBox(value) {
570
+ return (0, _orkestrel_contract.holds)(() => (0, _orkestrel_contract.isRecord)(value) && (0, _orkestrel_contract.isFiniteNumber)(value.x) && (0, _orkestrel_contract.isFiniteNumber)(value.y) && (0, _orkestrel_contract.isFiniteNumber)(value.width) && value.width > 0 && (0, _orkestrel_contract.isFiniteNumber)(value.height) && value.height > 0);
571
+ }
572
+ // src/core/helpers.ts
573
+ /**
574
+ * Describes a caught failure as one reportable line.
575
+ *
576
+ * @param error - The caught value, which need not be an `Error`
577
+ * @returns The error's message, or the value's string form
578
+ *
579
+ * @example
580
+ * ```ts
581
+ * describeCaptureError(new Error('Unknown variant: phone')) // 'Unknown variant: phone'
582
+ * describeCaptureError('refused') // 'refused'
583
+ * ```
584
+ */
585
+ function describeCaptureError(error) {
586
+ return (0, _orkestrel_contract.isError)(error) ? error.message : String(error);
587
+ }
588
+ /**
589
+ * Finds repeated identities before a keyed collection could discard them.
590
+ *
591
+ * @param values - The identity population
592
+ * @param folded - If `true`, compares case-folded keys; if `false`, compares exact identities. Default: `false`
593
+ * @returns Every member whose comparison key appears more than once
594
+ *
595
+ * @example
596
+ * ```ts
597
+ * collectCaptureDuplicates(['a', 'b', 'a']) // ['a', 'a']
598
+ * collectCaptureDuplicates(['Pages', 'pages'], true) // ['Pages', 'pages']
599
+ * ```
600
+ */
601
+ function collectCaptureDuplicates(values, folded = false) {
602
+ const keys = values.map((value) => folded ? value.toLowerCase() : value);
603
+ return values.filter((_value, index) => keys.indexOf(keys[index] ?? "") !== keys.lastIndexOf(keys[index] ?? ""));
604
+ }
605
+ /**
606
+ * Refuses duplicate declarations or portable storage-key collisions before indexing.
607
+ *
608
+ * @param values - The complete identity population
609
+ * @param label - The diagnostic subject
610
+ * @param folded - If `true`, refuses case-colliding keys; if `false`, requires exact uniqueness. Default: `false`
611
+ * @throws Thrown as an `EVIDENCE` capture error when an identity repeats.
612
+ *
613
+ * @example
614
+ * ```ts
615
+ * requireCaptureUnique(['mail', 'files'], 'owners') // returns
616
+ * requireCaptureUnique(['mail', 'mail'], 'owners') // throws 'Duplicate owners: mail, mail'
617
+ * ```
618
+ */
619
+ function requireCaptureUnique(values, label, folded = false) {
620
+ const duplicates = collectCaptureDuplicates(values, folded);
621
+ if (duplicates.length > 0) throw new CaptureError(`Duplicate ${label}: ${duplicates.join(", ")}`, {
622
+ code: "EVIDENCE",
623
+ context: {
624
+ label,
625
+ duplicates
626
+ }
627
+ });
628
+ }
629
+ /**
630
+ * Compares complete populations without erasing duplicates.
631
+ *
632
+ * @param left - The first population
633
+ * @param right - The second population
634
+ * @returns True if the sorted populations are equal; false otherwise
635
+ *
636
+ * @example
637
+ * ```ts
638
+ * matchesCaptureMembers(['b', 'a'], ['a', 'b']) // true
639
+ * matchesCaptureMembers(['a', 'a'], ['a']) // false
640
+ * ```
641
+ */
642
+ function matchesCaptureMembers(left, right) {
643
+ const ordered = right.toSorted();
644
+ return left.length === right.length && left.toSorted().every((entry, index) => entry === ordered[index]);
645
+ }
646
+ /**
647
+ * Compares an owner with an explicit selector at colon boundaries.
648
+ *
649
+ * @param owner - The canonical owner
650
+ * @param selector - The requested owner or the `all` selector
651
+ * @returns True if the owner belongs to the selection; false otherwise
652
+ *
653
+ * @example
654
+ * ```ts
655
+ * matchesCaptureSelector('pages:mail', 'pages') // true
656
+ * matchesCaptureSelector('pages:mailbox', 'pages:mail') // false
657
+ * ```
658
+ */
659
+ function matchesCaptureSelector(owner, selector) {
660
+ return selector === "all" || owner === selector || owner.startsWith(`${selector}:`);
661
+ }
662
+ /**
663
+ * Builds the canonical owner from a destination's registry identity.
664
+ *
665
+ * @param entry - The destination
666
+ * @returns The scope, part, and optional section selector
667
+ *
668
+ * @example
669
+ * ```ts
670
+ * resolveCaptureOwner({ ...destination, scope: 'pages', part: 'mail' }) // 'pages:mail'
671
+ * ```
672
+ */
673
+ function resolveCaptureOwner(entry) {
674
+ return [
675
+ entry.scope,
676
+ entry.part,
677
+ ...entry.section === void 0 ? [] : [entry.section]
678
+ ].join(":");
679
+ }
680
+ /**
681
+ * Builds a manifest identity independently of the physical image path.
682
+ *
683
+ * @param entry - The registry destination
684
+ * @returns The scope-qualified state and output-variant key
685
+ *
686
+ * @example
687
+ * ```ts
688
+ * resolveCaptureKey({ ...destination, scope: 'pages', state: 'inbox', variant: 'light-390' })
689
+ * // 'pages/inbox--light-390.png'
690
+ * ```
691
+ */
692
+ function resolveCaptureKey(entry) {
693
+ return `${entry.scope}/${entry.state}--${entry.variant}.png`;
694
+ }
695
+ /**
696
+ * Serializes a destination's identity and attribution in a deterministic field order.
697
+ *
698
+ * @param entry - The destination
699
+ * @returns The comparison representation, excluding image and duration readings
700
+ *
701
+ * @example
702
+ * ```ts
703
+ * describeCaptureDestination(destination) === describeCaptureDestination({ ...destination })
704
+ * // true
705
+ * ```
706
+ */
707
+ function describeCaptureDestination(entry) {
708
+ return JSON.stringify([
709
+ entry.portfolio,
710
+ entry.state,
711
+ entry.scope,
712
+ entry.part,
713
+ entry.section,
714
+ entry.variant,
715
+ entry.project,
716
+ entry.file,
717
+ entry.case,
718
+ entry.sources.own.toSorted(),
719
+ entry.sources.shared.toSorted(),
720
+ entry.sources.tests.toSorted()
721
+ ]);
722
+ }
723
+ /**
724
+ * Serializes only the registry's execution and output identity, independent of input revisions.
725
+ *
726
+ * @param entry - The destination or inherited stamp
727
+ * @returns The identity used for relevant manifest agreement during state resolution
728
+ *
729
+ * @example
730
+ * ```ts
731
+ * describeCaptureIdentity(destination) === describeCaptureIdentity({
732
+ * ...destination,
733
+ * sources: { own: [], shared: [], tests: [] },
734
+ * })
735
+ * // true
736
+ * ```
737
+ */
738
+ function describeCaptureIdentity(entry) {
739
+ return JSON.stringify([
740
+ entry.portfolio,
741
+ entry.state,
742
+ entry.scope,
743
+ entry.part,
744
+ entry.section,
745
+ entry.variant,
746
+ entry.project,
747
+ entry.file,
748
+ entry.case
749
+ ]);
750
+ }
751
+ /**
752
+ * Serializes a complete behavioral declaration without dropping eligibility or states.
753
+ *
754
+ * @param entry - The collected declaration
755
+ * @returns The deterministic comparison representation
756
+ *
757
+ * @example
758
+ * ```ts
759
+ * describeCaptureDeclaration({ ...declaration, states: ['b', 'a'] }) ===
760
+ * describeCaptureDeclaration({ ...declaration, states: ['a', 'b'] })
761
+ * // true
762
+ * ```
763
+ */
764
+ function describeCaptureDeclaration(entry) {
765
+ return JSON.stringify([
766
+ entry.case,
767
+ entry.owner,
768
+ entry.variant,
769
+ entry.eligible,
770
+ entry.states.toSorted()
771
+ ]);
772
+ }
773
+ /**
774
+ * Serializes every request field, retaining the exact argv order.
775
+ *
776
+ * @param request - The transported request
777
+ * @returns The exact request comparison representation
778
+ *
779
+ * @example
780
+ * ```ts
781
+ * describeCaptureRequest(request) === describeCaptureRequest({ ...request, args: [] })
782
+ * // false when the request carried argv
783
+ * ```
784
+ */
785
+ function describeCaptureRequest(request) {
786
+ return JSON.stringify([
787
+ request.version,
788
+ request.id,
789
+ request.stage,
790
+ request.pid,
791
+ request.config,
792
+ request.command,
793
+ request.selector,
794
+ request.case,
795
+ request.state,
796
+ request.variants,
797
+ request.args
798
+ ]);
799
+ }
800
+ /**
801
+ * Names every changed, added, or removed file in hash populations.
802
+ *
803
+ * @param previous - The retained file hashes
804
+ * @param current - The observed file hashes
805
+ * @returns The sorted changed membership
806
+ *
807
+ * @example
808
+ * ```ts
809
+ * collectCaptureChanges({ 'a.ts': 'x', 'b.ts': 'y' }, { 'a.ts': 'x', 'b.ts': 'z', 'c.ts': 'w' })
810
+ * // ['b.ts', 'c.ts']
811
+ * ```
812
+ */
813
+ function collectCaptureChanges(previous, current) {
814
+ return [.../* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(current)])].filter((file) => previous[file] !== current[file]).toSorted();
815
+ }
816
+ /**
817
+ * Builds the stable case identity used to merge separate lookup receipts.
818
+ *
819
+ * @param lookup - The lookup identity
820
+ * @returns The producing variant and full case key
821
+ *
822
+ * @example
823
+ * ```ts
824
+ * resolveLookupKey({ variant: 'light-390', case: 'mail shows the inbox' })
825
+ * // '["light-390","mail shows the inbox"]'
826
+ * ```
827
+ */
828
+ function resolveLookupKey(lookup) {
829
+ return JSON.stringify([lookup.variant, lookup.case]);
830
+ }
831
+ /**
832
+ * Reads successful Vitest JSON output and validates every owner-bearing assertion.
833
+ *
834
+ * @param value - The parsed external reporter document
835
+ * @returns A validated projection of the fields used by integrity
836
+ * @throws Thrown as an `EVIDENCE` capture error for failed reporters, malformed assertions, or duplicate case identities.
837
+ *
838
+ * @example
839
+ * ```ts
840
+ * const report = readCaptureReport(parseJSON(text))
841
+ * report.assertions.map((assertion) => assertion.case)
842
+ * ```
843
+ */
844
+ function readCaptureReport(value) {
845
+ if (!(0, _orkestrel_contract.isRecord)(value) || value.success !== true || value.numFailedTests !== 0 || value.numFailedTestSuites !== 0 || !(0, _orkestrel_contract.isFiniteNumber)(value.startTime) || !(0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isRecord)(value.testResults) || value.testResults.length === 0) throw new CaptureError("Invalid or unsuccessful Vitest JSON report", { code: "EVIDENCE" });
846
+ const files = value.testResults.map((file) => {
847
+ if (file.status !== "passed" || !(0, _orkestrel_contract.isFiniteNumber)(file.startTime) || !(0, _orkestrel_contract.isFiniteNumber)(file.endTime) || file.endTime < file.startTime || !(0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isRecord)(file.assertionResults)) throw new CaptureError("Invalid Vitest file report", { code: "EVIDENCE" });
848
+ return {
849
+ start: file.startTime,
850
+ end: file.endTime,
851
+ assertions: file.assertionResults
852
+ };
853
+ });
854
+ const assertions = files.flatMap((file) => file.assertions.flatMap((assertion) => {
855
+ if (!(0, _orkestrel_contract.isRecord)(assertion.meta)) throw new CaptureError("Invalid Vitest assertion metadata", { code: "EVIDENCE" });
856
+ if (assertion.meta.owner === void 0) return [];
857
+ const declaration = {
858
+ case: assertion.fullName,
859
+ owner: assertion.meta.owner,
860
+ variant: assertion.meta.variant,
861
+ eligible: assertion.meta.eligible === void 0 ? true : assertion.meta.eligible,
862
+ states: assertion.meta.states === void 0 ? [] : assertion.meta.states
863
+ };
864
+ if (!isCaptureDeclaration(declaration) || !(0, _orkestrel_contract.isString)(assertion.status) || assertion.duration !== void 0 && assertion.duration !== null && (!(0, _orkestrel_contract.isFiniteNumber)(assertion.duration) || assertion.duration < 0)) throw new CaptureError("Invalid owner-bearing Vitest assertion", { code: "EVIDENCE" });
865
+ return [{
866
+ ...declaration,
867
+ status: assertion.status,
868
+ ...typeof assertion.duration === "number" ? { duration: assertion.duration } : {}
869
+ }];
870
+ }));
871
+ requireCaptureUnique(assertions.map(resolveLookupKey), "reporter case identities");
872
+ return {
873
+ start: Math.min(value.startTime, ...files.map((file) => file.start)),
874
+ end: Math.max(...files.map((file) => file.end)),
875
+ assertions
876
+ };
877
+ }
878
+ /**
879
+ * Validates declaration, reporter, observation, completeness, and output-projection agreement.
880
+ *
881
+ * @param run - The final record
882
+ * @param report - The validated external reporter
883
+ * @param project - The actual producing project name
884
+ * @throws Thrown as an `EVIDENCE` capture error when a record differs from the actual selected results or declarations.
885
+ *
886
+ * @example
887
+ * ```ts
888
+ * validateCaptureRun(run, readCaptureReport(parseJSON(text)), 'journey:light-390')
889
+ * ```
890
+ */
891
+ function validateCaptureRun(run, report, project) {
892
+ const assertions = report.assertions.filter((entry) => entry.variant === run.variant);
893
+ requireCaptureUnique(run.declarations.map((entry) => entry.case), "declaring cases");
894
+ requireCaptureUnique(run.declarations.flatMap((entry) => entry.states), "declared states", true);
895
+ requireCaptureUnique(run.registry.map(resolveCaptureKey), "registry identities", true);
896
+ requireCaptureUnique(run.registry.map((entry) => entry.file), "registry paths", true);
897
+ requireCaptureUnique(run.entries.map(resolveCaptureKey), "emitted identities", true);
898
+ requireCaptureUnique(run.passed, "passed cases");
899
+ requireCaptureUnique(run.observed, "observed states", true);
900
+ if (!matchesCaptureMembers(run.declarations.map(describeCaptureDeclaration), assertions.map(describeCaptureDeclaration))) throw new CaptureError("Run declarations differ from full reporter declarations", { code: "EVIDENCE" });
901
+ const eligible = run.declarations.filter((entry) => entry.eligible);
902
+ const passed = assertions.filter((entry) => entry.eligible && entry.status === "passed");
903
+ if (!matchesCaptureMembers(run.passed, passed.map((entry) => entry.case))) throw new CaptureError("Run passed cases differ from reporter results", { code: "EVIDENCE" });
904
+ if (!matchesCaptureMembers(run.observed, passed.flatMap((entry) => entry.states))) throw new CaptureError("Run observations differ from full passed declarations", { code: "EVIDENCE" });
905
+ if (run.complete !== (eligible.length > 0 && eligible.length === passed.length)) throw new CaptureError("Run completeness differs from eligible results", { code: "EVIDENCE" });
906
+ for (const declaration of eligible) {
907
+ const destinations = run.registry.filter((entry) => entry.case === declaration.case);
908
+ if (!matchesCaptureMembers(destinations.map((entry) => entry.state), declaration.states) || destinations.some((entry) => entry.project !== project || !matchesCaptureSelector(resolveCaptureOwner(entry), declaration.owner))) throw new CaptureError(`Registry differs from eligible declaration: ${declaration.case}`, { code: "EVIDENCE" });
909
+ }
910
+ if (run.registry.some((entry) => !eligible.some((declaration) => declaration.case === entry.case))) throw new CaptureError("Registry contains an ineligible or undeclared case", { code: "EVIDENCE" });
911
+ const reference = run.registry.filter((entry) => entry.section === entry.state);
912
+ if (run.reference !== (reference.length > 0 && reference.every((entry) => run.passed.includes(entry.case)))) throw new CaptureError("Reference completeness differs from declaring section results", { code: "EVIDENCE" });
913
+ const request = run.request;
914
+ if (request !== void 0) {
915
+ if (run.identity === void 0 || run.identity.id !== request.id || run.identity.stage !== request.stage || run.identity.pid !== request.pid || run.identity.config !== request.config || !request.variants.includes(run.variant)) throw new CaptureError("Run identity differs from its request", { code: "EVIDENCE" });
916
+ const selected = eligible.filter((entry) => matchesCaptureSelector(entry.owner, request.selector) && (request.case === void 0 || entry.case === request.case) && (request.command === "journey" || entry.states.length > 0));
917
+ if (!matchesCaptureMembers(selected.map((entry) => entry.case), run.passed)) throw new CaptureError("Selected full case names differ from passed results", { code: "EVIDENCE" });
918
+ if (request.state !== void 0 && selected.some((entry) => !entry.states.includes(request.state ?? ""))) throw new CaptureError("Requested state differs from its selected declaring case", { code: "EVIDENCE" });
919
+ }
920
+ const expected = request?.command === "journey" || request === void 0 && run.entries.length === 0 ? [] : run.registry.filter((entry) => run.passed.includes(entry.case) && (request?.state === void 0 || entry.state === request.state));
921
+ if (!matchesCaptureMembers(run.entries.map(describeCaptureDestination), expected.map(describeCaptureDestination))) throw new CaptureError("Emitted entries differ from exact requested projection", { code: "EVIDENCE" });
922
+ for (const entry of run.entries) if (passed.find((assertion) => assertion.case === entry.case)?.duration !== entry.duration) throw new CaptureError(`Emitted duration differs from its producing case: ${entry.case}`, { code: "EVIDENCE" });
923
+ }
924
+ /**
925
+ * Chooses the primary classification while retaining all findings separately.
926
+ *
927
+ * @param statuses - Every classification justified by the reading
928
+ * @returns The highest-precedence classification, or `current` when none applies
929
+ *
930
+ * @example
931
+ * ```ts
932
+ * resolveCaptureStatus(['stale-own', 'missing']) // 'missing'
933
+ * resolveCaptureStatus([]) // 'current'
934
+ * ```
935
+ */
936
+ function resolveCaptureStatus(statuses) {
937
+ return CAPTURE_STATUS_PRECEDENCE.find((status) => statuses.includes(status)) ?? "current";
938
+ }
939
+ /**
940
+ * Reads Git's NUL-delimited porcelain paths without treating spaces or quoted names as separators.
941
+ *
942
+ * @param output - The exact `status --porcelain=v1 -z` output
943
+ * @returns Dirty repository-relative paths, including both sides of renames, sorted without repeats
944
+ * @throws Thrown as an `EVIDENCE` capture error when a rename or copy record has no original path.
945
+ *
946
+ * @example
947
+ * ```ts
948
+ * readCaptureDirty(' M src/a.ts\0R src/b.ts\0src/c.ts\0') // ['src/a.ts', 'src/b.ts', 'src/c.ts']
949
+ * ```
950
+ */
951
+ function readCaptureDirty(output) {
952
+ const result = output.split("\0").filter((record) => record !== "").reduce((state, record) => state.pending ? {
953
+ paths: [...state.paths, record],
954
+ pending: false
955
+ } : {
956
+ paths: [...state.paths, record.slice(3)],
957
+ pending: /[RC]/u.test(record.slice(0, 2))
958
+ }, {
959
+ paths: [],
960
+ pending: false
961
+ });
962
+ if (result.pending) throw new CaptureError("Incomplete Git rename provenance", { code: "EVIDENCE" });
963
+ return [...new Set(result.paths)].toSorted();
964
+ }
965
+ /**
966
+ * Validates a complete receipt against full reporter declarations and eligible output coverage.
967
+ *
968
+ * @param receipt - The retained complete-run receipt
969
+ * @param report - The authenticated reporter projection
970
+ * @throws Thrown as an `EVIDENCE` capture error when the receipt omits, invents, or changes a collected declaration or output.
971
+ *
972
+ * @example
973
+ * ```ts
974
+ * validateCaptureReceipt(receipt, readCaptureReport(parseJSON(text)))
975
+ * ```
976
+ */
977
+ function validateCaptureReceipt(receipt, report) {
978
+ const assertions = report.assertions.filter((entry) => entry.variant === receipt.variant);
979
+ if (!receipt.complete || !matchesCaptureMembers(assertions.map(describeCaptureDeclaration), receipt.declarations.map(describeCaptureDeclaration)) || !assertions.some((entry) => entry.eligible) || assertions.some((entry) => entry.eligible && entry.status !== "passed")) throw new CaptureError("Registry receipt does not prove complete eligible behavior", { code: "EVIDENCE" });
980
+ const eligible = receipt.declarations.filter((entry) => entry.eligible);
981
+ for (const declaration of eligible) {
982
+ requireCaptureUnique(declaration.states, "states within a declaration", true);
983
+ const entries = receipt.registry.filter((entry) => entry.case === declaration.case);
984
+ if (!matchesCaptureMembers(entries.map((entry) => entry.state), declaration.states) || entries.some((entry) => !matchesCaptureSelector(resolveCaptureOwner(entry), declaration.owner))) throw new CaptureError("Registry receipt destination coverage differs from declarations", { code: "EVIDENCE" });
985
+ }
986
+ if (receipt.registry.some((entry) => !eligible.some((declaration) => declaration.case === entry.case)) || new Set(receipt.registry.map((entry) => entry.project)).size > 1) throw new CaptureError("Registry receipt contains an undeclared output or mixes producing projects", { code: "EVIDENCE" });
987
+ }
988
+ exports.CAPTURE_ERROR_BRAND = CAPTURE_ERROR_BRAND;
989
+ exports.CAPTURE_ERROR_CODES = CAPTURE_ERROR_CODES;
990
+ exports.CAPTURE_LOOKUPS_FILE = CAPTURE_LOOKUPS_FILE;
991
+ exports.CAPTURE_MANIFEST_FILE = CAPTURE_MANIFEST_FILE;
992
+ exports.CAPTURE_PNG_SIGNATURE = CAPTURE_PNG_SIGNATURE;
993
+ exports.CAPTURE_REGISTRY_FILE = CAPTURE_REGISTRY_FILE;
994
+ exports.CAPTURE_REQUEST_PREFIX = CAPTURE_REQUEST_PREFIX;
995
+ exports.CAPTURE_STATUS_PRECEDENCE = CAPTURE_STATUS_PRECEDENCE;
996
+ exports.CAPTURE_VERSION = CAPTURE_VERSION;
997
+ exports.CaptureError = CaptureError;
998
+ exports.collectCaptureChanges = collectCaptureChanges;
999
+ exports.collectCaptureDuplicates = collectCaptureDuplicates;
1000
+ exports.describeCaptureDeclaration = describeCaptureDeclaration;
1001
+ exports.describeCaptureDestination = describeCaptureDestination;
1002
+ exports.describeCaptureError = describeCaptureError;
1003
+ exports.describeCaptureIdentity = describeCaptureIdentity;
1004
+ exports.describeCaptureRequest = describeCaptureRequest;
1005
+ exports.isCaptureArtifact = isCaptureArtifact;
1006
+ exports.isCaptureBox = isCaptureBox;
1007
+ exports.isCaptureCollection = isCaptureCollection;
1008
+ exports.isCaptureDeclaration = isCaptureDeclaration;
1009
+ exports.isCaptureDestination = isCaptureDestination;
1010
+ exports.isCaptureDigest = isCaptureDigest;
1011
+ exports.isCaptureEntry = isCaptureEntry;
1012
+ exports.isCaptureError = isCaptureError;
1013
+ exports.isCaptureGeometry = isCaptureGeometry;
1014
+ exports.isCaptureHash = isCaptureHash;
1015
+ exports.isCaptureHashes = isCaptureHashes;
1016
+ exports.isCaptureIdentity = isCaptureIdentity;
1017
+ exports.isCaptureLookup = isCaptureLookup;
1018
+ exports.isCaptureLookupJournal = isCaptureLookupJournal;
1019
+ exports.isCaptureManifest = isCaptureManifest;
1020
+ exports.isCapturePath = isCapturePath;
1021
+ exports.isCapturePattern = isCapturePattern;
1022
+ exports.isCaptureReceipt = isCaptureReceipt;
1023
+ exports.isCaptureRegistry = isCaptureRegistry;
1024
+ exports.isCaptureRequest = isCaptureRequest;
1025
+ exports.isCaptureRun = isCaptureRun;
1026
+ exports.isCaptureSegment = isCaptureSegment;
1027
+ exports.isCaptureSelector = isCaptureSelector;
1028
+ exports.isCaptureSources = isCaptureSources;
1029
+ exports.isCaptureStamp = isCaptureStamp;
1030
+ exports.isCaptureStoredManifest = isCaptureStoredManifest;
1031
+ exports.matchesCaptureMembers = matchesCaptureMembers;
1032
+ exports.matchesCaptureSelector = matchesCaptureSelector;
1033
+ exports.readCaptureDirty = readCaptureDirty;
1034
+ exports.readCaptureReport = readCaptureReport;
1035
+ exports.requireCaptureUnique = requireCaptureUnique;
1036
+ exports.resolveCaptureKey = resolveCaptureKey;
1037
+ exports.resolveCaptureOwner = resolveCaptureOwner;
1038
+ exports.resolveCaptureStatus = resolveCaptureStatus;
1039
+ exports.resolveLookupKey = resolveLookupKey;
1040
+ exports.validateCaptureReceipt = validateCaptureReceipt;
1041
+ exports.validateCaptureRun = validateCaptureRun;
1042
+
1043
+ //# sourceMappingURL=index.cjs.map