@orkestrel/capture 0.0.7 → 0.0.9

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.
@@ -2,12 +2,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let node_crypto = require("node:crypto");
3
3
  let node_fs = require("node:fs");
4
4
  let node_path = require("node:path");
5
+ let node_url = require("node:url");
5
6
  let node_util = require("node:util");
6
7
  let node_zlib = require("node:zlib");
7
8
  let _orkestrel_contract = require("@orkestrel/contract");
8
- let _src_core = require("../core/index.cjs");
9
- let node_url = require("node:url");
10
9
  let _orkestrel_process_server = require("@orkestrel/process/server");
10
+ let _orkestrel_test_server = require("@orkestrel/test/server");
11
+ let _src_core = require("../core/index.cjs");
11
12
  let node_string_decoder = require("node:string_decoder");
12
13
  let _orkestrel_timeout = require("@orkestrel/timeout");
13
14
  // src/server/constants.ts
@@ -53,6 +54,14 @@ var CAPTURE_EXIT = Object.freeze({
53
54
  */
54
55
  var CAPTURE_OWNER_FILE = ".capture-owner";
55
56
  /**
57
+ * Holds the largest process id a POSIX or Windows host can assign, the signed 32-bit maximum.
58
+ * @example
59
+ * ```ts
60
+ * CAPTURE_PID_LIMIT // 2147483647
61
+ * ```
62
+ */
63
+ var CAPTURE_PID_LIMIT = 2147483647;
64
+ /**
56
65
  * Caps each refusal population so hostile records cannot flood a terminal or agent context.
57
66
  * @example
58
67
  * ```ts
@@ -84,6 +93,9 @@ var CAPTURE_STAGES = Object.freeze({
84
93
  /**
85
94
  * Defines each command's frozen options for Node's standard argument parser.
86
95
  *
96
+ * @remarks A boolean option whose default is `true` reads only its `--no-` form, which sets it to
97
+ * `false`; `bail` is the one such option.
98
+ *
87
99
  * @example
88
100
  * ```ts
89
101
  * CAPTURE_COMMAND_OPTIONS.journey.variant.multiple // true
@@ -99,6 +111,10 @@ var CAPTURE_COMMAND_OPTIONS = Object.freeze({
99
111
  case: Object.freeze({ type: "string" }),
100
112
  changed: Object.freeze({ type: "string" }),
101
113
  plan: Object.freeze({ type: "boolean" }),
114
+ bail: Object.freeze({
115
+ type: "boolean",
116
+ default: true
117
+ }),
102
118
  mode: Object.freeze({ type: "string" })
103
119
  }),
104
120
  capture: Object.freeze({
@@ -111,6 +127,10 @@ var CAPTURE_COMMAND_OPTIONS = Object.freeze({
111
127
  state: Object.freeze({ type: "string" }),
112
128
  changed: Object.freeze({ type: "string" }),
113
129
  plan: Object.freeze({ type: "boolean" }),
130
+ bail: Object.freeze({
131
+ type: "boolean",
132
+ default: true
133
+ }),
114
134
  mode: Object.freeze({ type: "string" })
115
135
  }),
116
136
  stale: Object.freeze({
@@ -157,8 +177,13 @@ var CAPTURE_COMMAND_OPTIONS = Object.freeze({
157
177
  multiple: true
158
178
  }),
159
179
  config: Object.freeze({ type: "string" }),
180
+ bail: Object.freeze({
181
+ type: "boolean",
182
+ default: true
183
+ }),
160
184
  mode: Object.freeze({ type: "string" })
161
- })
185
+ }),
186
+ progress: Object.freeze({})
162
187
  });
163
188
  /**
164
189
  * Lists the words a tag name can never be, because a tag filter reads them as operators.
@@ -174,15 +199,6 @@ var CAPTURE_TAG_OPERATORS = Object.freeze([
174
199
  "not"
175
200
  ]);
176
201
  /**
177
- * Names the tag prefix that marks a case's owner path and each ancestor of it.
178
- *
179
- * @example
180
- * ```ts
181
- * `${CAPTURE_OWNER_PREFIX}pages:mail` // 'owner:pages:mail'
182
- * ```
183
- */
184
- var CAPTURE_OWNER_PREFIX = "owner:";
185
- /**
186
202
  * Names the environment variable that turns frame capture on for a Vitest child.
187
203
  *
188
204
  * @example
@@ -218,6 +234,32 @@ var CAPTURE_VITEST_ENTRY = "node_modules/vitest/vitest.mjs";
218
234
  * ```
219
235
  */
220
236
  var CAPTURE_RUNS_DIRECTORY = "runs";
237
+ /**
238
+ * Names the ending of the progress file each stage writes beneath its invocation's run directory.
239
+ *
240
+ * @remarks The stage's name precedes it, so `selected` writes `selected.progress.jsonl`.
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * `tmp/capture/${CAPTURE_RUNS_DIRECTORY}/a/selected${CAPTURE_PROGRESS_SUFFIX}`
245
+ * ```
246
+ */
247
+ var CAPTURE_PROGRESS_SUFFIX = ".progress.jsonl";
248
+ /**
249
+ * Names the prefixes a journey wrapper derives its own paths from.
250
+ *
251
+ * @remarks `scratch` precedes the variant in the sibling of the evidence root a run without frame
252
+ * capture writes to, and `direct` precedes the random identity of a run no runner started.
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * `tmp/captures/${CAPTURE_WRAPPER_PREFIXES.scratch}light-390` // 'tmp/captures/no-capture-light-390'
257
+ * ```
258
+ */
259
+ var CAPTURE_WRAPPER_PREFIXES = Object.freeze({
260
+ scratch: "no-capture-",
261
+ direct: "direct-"
262
+ });
221
263
  /** Names the create-only child record beneath an invocation's run directory.
222
264
  * @example
223
265
  * ```ts
@@ -352,7 +394,8 @@ var CAPTURE_SUBCOMMANDS = Object.freeze([
352
394
  "stale",
353
395
  "preflight",
354
396
  "sheets",
355
- "registry"
397
+ "registry",
398
+ "progress"
356
399
  ]);
357
400
  /**
358
401
  * Holds the repository-relative paths the executable falls back to when the command line names none.
@@ -419,17 +462,20 @@ var CAPTURE_DISCOVERY = Object.freeze({
419
462
  var CAPTURE_USAGE = [
420
463
  "Usage: capture <command> [arguments]",
421
464
  "Commands:",
422
- " journey <selector> [--variant <name>]... [--case <full name>] [--mode <name>] [--config <file>]",
423
- " journey --changed <ref> [--plan] [--variant <name>]... [--case <full name>] [--mode <name>] [--config <file>]",
424
- " frames <selector> [--variant <name>]... [--case <full name>] [--state <name>] [--mode <name>] [--config <file>]",
425
- " frames --changed <ref> [--plan] [--variant <name>]... [--case <full name>] [--state <name>] [--mode <name>] [--config <file>]",
465
+ " journey <selector> [--variant <name>]... [--case <full name>] [--no-bail] [--mode <name>] [--config <file>]",
466
+ " journey --changed <ref> [--plan] [--variant <name>]... [--case <full name>] [--no-bail] [--mode <name>] [--config <file>]",
467
+ " frames <selector> [--variant <name>]... [--case <full name>] [--state <name>] [--no-bail] [--mode <name>] [--config <file>]",
468
+ " frames --changed <ref> [--plan] [--variant <name>]... [--case <full name>] [--state <name>] [--no-bail] [--mode <name>] [--config <file>]",
426
469
  " stale <selector> [--variant <name>]... [--case <full name>] [--state <name>] [--portfolio <name>] [--mode <name>] [--config <file>]",
427
470
  " preflight <selector> [--variant <name>]... [--state <name>] [--case <full name>] [--portfolio <name>] [--mode <name>] [--config <file>] [--journeys <directory>] [--checks <module>]",
428
471
  " sheets <selector> --output <new directory> [--variant <name>]... [--state <name>] [--case <full name>] [--portfolio <name>] [--mode <name>] [--config <file>] [--journeys <directory>] [--checks <module>]",
429
- " registry [--variant <name>]... [--mode <name>] [--config <file>]",
472
+ " registry [--variant <name>]... [--no-bail] [--mode <name>] [--config <file>]",
473
+ " progress",
430
474
  "--changed takes one Git ref; HEAD selects uncommitted work. It cannot accompany a selector.",
431
475
  "--plan requires --changed and prints paths and commands after read-only discovery; no execution child starts.",
432
- "Only --variant repeats. Every flag except --plan takes one nonempty value, as --flag value or --flag=value; use --flag=-x for a value beginning with a dash. The -- terminator is refused.",
476
+ "--no-bail runs every selected case after a failure; by default a stage stops at its first failed case.",
477
+ "progress prints where the stage that is running, or that ran last, stands, from its progress file.",
478
+ "Only --variant repeats. Every flag except --plan and --no-bail takes one nonempty value, as --flag value or --flag=value; use --flag=-x for a value beginning with a dash. The -- terminator is refused.",
433
479
  "Exit: 0 passed, 1 failed or refused by the evidence, 64 refused usage."
434
480
  ].join("\n");
435
481
  // src/server/helpers.ts
@@ -484,7 +530,7 @@ function buildCaptureChangePlan(paths, entries) {
484
530
  * Renders an exact owner command with the selected variants and filters in host shell syntax.
485
531
  *
486
532
  * @param command - The request command, translated to its executable name, or the registry command
487
- * @param parsed - The parsed flags; changed and plan flags are deliberately replaced by the owner
533
+ * @param parsed - The parsed flags, a `false` bail rendered as `--no-bail` on every command but `stale`; changed and plan flags are deliberately replaced by the owner
488
534
  * @param selector - The explicit owner or all selector; omitted for a registry refresh
489
535
  * @param root - The workspace that makes the wrapper path relative
490
536
  * @returns The command ready to copy into the host shell
@@ -504,6 +550,7 @@ function renderCaptureCommand(command, parsed, selector, root) {
504
550
  ...parsed.mode === void 0 ? [] : ["--mode", parsed.mode],
505
551
  ...parsed.case === void 0 ? [] : parsed.case.startsWith("-") ? [`--case=${parsed.case}`] : ["--case", parsed.case],
506
552
  ...parsed.state === void 0 ? [] : ["--state", parsed.state],
553
+ ...parsed.bail === false && command !== "stale" ? ["--no-bail"] : [],
507
554
  ...config.startsWith("-") ? [`--config=${config}`] : ["--config", config]
508
555
  ].map((argument) => /^[\w./:-]+$/u.test(argument) ? argument : process.platform === "win32" ? `'${argument.replaceAll("'", "''")}'` : `'${argument.replaceAll("'", "'\\''")}'`).join(" ");
509
556
  }
@@ -735,6 +782,45 @@ function buildCaptureDigest(patterns, files) {
735
782
  };
736
783
  }
737
784
  /**
785
+ * Computes the key under which a pattern list's matched subset of one input population is memoized.
786
+ *
787
+ * @remarks
788
+ * The key joins the population's digest with the sorted patterns, so a list in any order over one
789
+ * population shares a key, and one population never answers for another.
790
+ *
791
+ * @param inputs - The digested input population the patterns match against
792
+ * @param patterns - The native glob patterns, in any order
793
+ * @returns The memo key of the population and the pattern list
794
+ *
795
+ * @example
796
+ * ```ts
797
+ * const inputs = buildCaptureDigest(['src/**'], { 'src/a.ts': 'f'.repeat(64) })
798
+ * computeCaptureMatchKey(inputs, ['src/*.ts', 'src/*.md']) === computeCaptureMatchKey(inputs, ['src/*.md', 'src/*.ts']) // true
799
+ * ```
800
+ */
801
+ function computeCaptureMatchKey(inputs, patterns) {
802
+ return JSON.stringify([inputs.digest, patterns.toSorted()]);
803
+ }
804
+ /**
805
+ * Filters an input population's paths that match any listed pattern.
806
+ *
807
+ * @remarks
808
+ * Each path is matched with the `matchesGlob` function from `node:path`.
809
+ *
810
+ * @param inputs - The digested input population whose paths are matched
811
+ * @param patterns - The native glob patterns
812
+ * @returns The population's paths that match at least one pattern, in population order
813
+ *
814
+ * @example
815
+ * ```ts
816
+ * const inputs = buildCaptureDigest(['src/**'], { 'src/a.ts': 'f'.repeat(64), 'src/b.md': 'e'.repeat(64) })
817
+ * filterCaptureInputs(inputs, ['src/*.ts']) // Set { 'src/a.ts' }
818
+ * ```
819
+ */
820
+ function filterCaptureInputs(inputs, patterns) {
821
+ return new Set(Object.keys(inputs.files).filter((path) => patterns.some((pattern) => (0, node_path.matchesGlob)(path, pattern))));
822
+ }
823
+ /**
738
824
  * Stores each distinct lookup input population once in a manifest-bound journal.
739
825
  *
740
826
  * @param lookups - The expanded passing case evidence to publish
@@ -969,15 +1055,14 @@ function requireCaptureImageSize(size) {
969
1055
  * ```
970
1056
  */
971
1057
  function unfilterCaptureRow(filter, line, above, channels) {
972
- const bytes = [];
1058
+ const bytes = new Uint8Array(line.length);
973
1059
  for (const [index, value] of line.entries()) {
974
1060
  const left = index >= channels ? bytes[index - channels] ?? 0 : 0;
975
1061
  const up = above?.[index] ?? 0;
976
1062
  const corner = index >= channels ? above?.[index - channels] ?? 0 : 0;
977
- const predicted = filter === 1 ? left : filter === 2 ? up : filter === 3 ? left + up >> 1 : filter === 4 ? predictCaptureByte(left, up, corner) : 0;
978
- bytes.push(value + predicted & 255);
1063
+ bytes[index] = value + (filter === 1 ? left : filter === 2 ? up : filter === 3 ? left + up >> 1 : filter === 4 ? predictCaptureByte(left, up, corner) : 0) & 255;
979
1064
  }
980
- return Uint8Array.from(bytes);
1065
+ return bytes;
981
1066
  }
982
1067
  /**
983
1068
  * Inflates a PNG's compressed stream, refusing one that is corrupt or longer than declared.
@@ -1035,16 +1120,31 @@ function decodeCapturePicture(bytes) {
1035
1120
  const chunks = readCaptureChunks(bytes);
1036
1121
  const raw = inflateCaptureStream(chunks.length === 1 && chunks[0] !== void 0 ? chunks[0] : Buffer.concat(chunks), length);
1037
1122
  if (raw.length !== length) throw new _src_core.CaptureError("Capture PNG scanline length differs", { code: "EVIDENCE" });
1038
- const rows = [];
1123
+ const rows = new Uint8Array(stride * height);
1039
1124
  for (const row of new Array(height).keys()) {
1040
1125
  const filter = raw[row * (stride + 1)];
1041
1126
  if (filter === void 0 || filter > 4) throw new _src_core.CaptureError("Unsupported capture PNG filter", { code: "EVIDENCE" });
1042
- rows.push(unfilterCaptureRow(filter, raw.subarray(row * (stride + 1) + 1, (row + 1) * (stride + 1)), rows[row - 1], channels));
1127
+ const line = raw.subarray(row * (stride + 1) + 1, (row + 1) * (stride + 1));
1128
+ rows.set(filter === 0 ? line : unfilterCaptureRow(filter, line, row === 0 ? void 0 : rows.subarray((row - 1) * stride, row * stride), channels), row * stride);
1129
+ }
1130
+ if (channels === 3) return {
1131
+ width,
1132
+ height,
1133
+ pixels: rows
1134
+ };
1135
+ const pixels = new Uint8Array(width * height * 3);
1136
+ const columns = Array.from({ length: width }, (_, column) => column);
1137
+ for (const row of new Array(height).keys()) for (const column of columns) {
1138
+ const source = (row * width + column) * channels;
1139
+ const target = (row * width + column) * 3;
1140
+ pixels[target] = rows[source] ?? 0;
1141
+ pixels[target + 1] = rows[source + (gray ? 0 : 1)] ?? 0;
1142
+ pixels[target + 2] = rows[source + (gray ? 0 : 2)] ?? 0;
1043
1143
  }
1044
1144
  return {
1045
1145
  width,
1046
1146
  height,
1047
- pixels: Uint8Array.from({ length: width * height * 3 }, (_, index) => rows[Math.floor(index / (width * 3))]?.[Math.floor(index % (width * 3) / 3) * channels + (gray ? 0 : index % 3)] ?? 0)
1147
+ pixels
1048
1148
  };
1049
1149
  }
1050
1150
  /**
@@ -1138,22 +1238,29 @@ function shrinkCapturePicture(picture, factor, limit) {
1138
1238
  const width = Math.max(1, Math.ceil(picture.width / factor));
1139
1239
  const height = Math.min(Math.max(1, Math.ceil(picture.height / factor)), limit);
1140
1240
  const span = Array.from({ length: Math.ceil(Math.min(factor, Math.max(picture.width, picture.height))) }, (_, index) => index);
1141
- return {
1142
- width,
1143
- height,
1144
- pixels: Uint8Array.from({ length: width * height * 3 }, (_, index) => {
1145
- const channel = index % 3;
1146
- const x = Math.floor(index / 3) % width;
1147
- const y = Math.floor(index / 3 / width);
1148
- const rows = Math.min(factor, picture.height - y * factor);
1241
+ const pixels = new Uint8Array(Math.min(Math.max(Math.trunc(width * height * 3) || 0, 0), Number.MAX_SAFE_INTEGER));
1242
+ const offsets = Array.from({ length: Math.min(width * 3, pixels.length) }, (_, offset) => offset);
1243
+ const lines = pixels.length === 0 ? 0 : Math.ceil(pixels.length / (width * 3));
1244
+ for (const y of new Array(lines).keys()) {
1245
+ const rows = Math.min(factor, picture.height - y * factor);
1246
+ for (const offset of offsets) {
1247
+ const index = y * width * 3 + offset;
1248
+ if (index >= pixels.length) break;
1249
+ const channel = offset % 3;
1250
+ const x = Math.floor(offset / 3);
1149
1251
  const columns = Math.min(factor, picture.width - x * factor);
1150
1252
  const sum = span.reduce((total, row) => {
1151
1253
  if (row >= rows) return total;
1152
1254
  const start = (y * factor + row) * picture.width * 3 + x * Math.ceil(factor) * 3 + channel;
1153
1255
  return span.reduce((block, column) => column >= columns ? block : block + (picture.pixels[start + column * 3] ?? 0), total);
1154
1256
  }, 0);
1155
- return Math.round(sum / (rows * columns));
1156
- })
1257
+ pixels[index] = Math.round(sum / (rows * columns));
1258
+ }
1259
+ }
1260
+ return {
1261
+ width,
1262
+ height,
1263
+ pixels
1157
1264
  };
1158
1265
  }
1159
1266
  /**
@@ -1163,7 +1270,10 @@ function shrinkCapturePicture(picture, factor, limit) {
1163
1270
  * @param vertical - If `true`, stacks rows; if `false`, places cells side by side
1164
1271
  * @param gap - The space between source pictures. Default: 6.
1165
1272
  * @returns A separately owned composite
1166
- * @throws Thrown for an empty picture selection.
1273
+ * @throws Thrown for an empty picture selection, with the `USAGE` condition.
1274
+ * @throws Thrown with the `EVIDENCE` condition when a width, a height, or the gap is not a whole
1275
+ * number from 0 to `CAPTURE_PNG_LIMITS.side`, or when the composite exceeds that side or the
1276
+ * `CAPTURE_PNG_LIMITS.pixels` budget.
1167
1277
  *
1168
1278
  * @example
1169
1279
  * ```ts
@@ -1172,42 +1282,80 @@ function shrinkCapturePicture(picture, factor, limit) {
1172
1282
  */
1173
1283
  function composeCapturePictures(pictures, vertical, gap = 6) {
1174
1284
  if (pictures.length === 0) throw new _src_core.CaptureError("Empty contact-sheet picture selection", { code: "USAGE" });
1175
- const width = vertical ? Math.max(...pictures.map((entry) => entry.width)) : pictures.reduce((sum, entry) => sum + entry.width, 0) + gap * (pictures.length - 1);
1176
- const height = vertical ? pictures.reduce((sum, entry) => sum + entry.height, 0) + gap * (pictures.length - 1) : Math.max(...pictures.map((entry) => entry.height));
1285
+ const { side, pixels: budget } = CAPTURE_PNG_LIMITS;
1286
+ const faults = [...pictures.flatMap((picture, position) => ["width", "height"].flatMap((axis) => Number.isSafeInteger(picture[axis]) && picture[axis] >= 0 && picture[axis] <= side ? [] : [`pictures[${String(position)}].${axis} is ${(0, _orkestrel_contract.preview)(picture[axis])}`])), ...Number.isSafeInteger(gap) && gap >= 0 && gap <= side ? [] : [`gap is ${(0, _orkestrel_contract.preview)(gap)}`]];
1287
+ const width = vertical ? pictures.reduce((widest, entry) => Math.max(widest, entry.width), -Infinity) : pictures.reduce((sum, entry) => sum + entry.width, 0) + gap * (pictures.length - 1);
1288
+ const height = vertical ? pictures.reduce((sum, entry) => sum + entry.height, 0) + gap * (pictures.length - 1) : pictures.reduce((tallest, entry) => Math.max(tallest, entry.height), -Infinity);
1289
+ if (faults.length > 0 || width > side || height > side || width * height > budget) throw new _src_core.CaptureError(`Contact-sheet geometry is out of range: ${faults.length === 0 ? `composite is ${String(width)} × ${String(height)}` : [...faults.slice(0, 16), ...faults.length > 16 ? [`… ${String(faults.length - 16)} more`] : []].join("; ")}; expected whole numbers from 0 to ${String(side)} for every width, height, and gap, and a composite of at most ${String(side)} per side and ${String(budget)} pixels`, { code: "EVIDENCE" });
1177
1290
  const offsets = pictures.map((_picture, position) => pictures.slice(0, position).reduce((sum, entry) => sum + (vertical ? entry.height : entry.width) + gap, 0));
1291
+ const pixels = new Uint8Array(width * height * 3);
1292
+ const spans = pictures.map((picture, position) => ({
1293
+ picture,
1294
+ start: offsets[position] ?? 0,
1295
+ end: Math.min(offsets[position + 1] ?? Infinity, vertical ? height : width)
1296
+ }));
1297
+ if (vertical) {
1298
+ for (const { picture, start, end } of spans) for (const row of new Array(Math.max(0, end - start)).keys()) {
1299
+ const copied = row < picture.height ? picture.width : 0;
1300
+ const target = (start + row) * width * 3;
1301
+ pixels.set(picture.pixels.subarray(row * picture.width * 3, (row * picture.width + copied) * 3), target);
1302
+ pixels.fill(128, target + copied * 3, target + width * 3);
1303
+ }
1304
+ return {
1305
+ width,
1306
+ height,
1307
+ pixels
1308
+ };
1309
+ }
1310
+ for (const row of new Array(height).keys()) for (const { picture, start, end } of spans) {
1311
+ const copied = row < picture.height ? Math.min(picture.width, end - start) : 0;
1312
+ const target = (row * width + start) * 3;
1313
+ pixels.set(picture.pixels.subarray(row * picture.width * 3, (row * picture.width + copied) * 3), target);
1314
+ pixels.fill(128, target + copied * 3, (row * width + end) * 3);
1315
+ }
1178
1316
  return {
1179
1317
  width,
1180
1318
  height,
1181
- pixels: Uint8Array.from({ length: width * height * 3 }, (_value, index) => {
1182
- const x = Math.floor(index % (width * 3) / 3);
1183
- const y = Math.floor(index / (width * 3));
1184
- const position = offsets.findLastIndex((offset) => offset <= (vertical ? y : x));
1185
- const picture = pictures[position];
1186
- const offset = offsets[position];
1187
- if (picture === void 0 || offset === void 0) return 128;
1188
- const column = vertical ? x : x - offset;
1189
- const row = vertical ? y - offset : y;
1190
- return column < picture.width && row < picture.height ? picture.pixels[(row * picture.width + column) * 3 + index % 3] ?? 0 : 128;
1191
- })
1319
+ pixels
1192
1320
  };
1193
1321
  }
1194
1322
  /**
1195
1323
  * Reads the process id that a request file, or its temporary sibling, names.
1196
1324
  *
1197
1325
  * @param name - A file name from the request directory
1198
- * @returns The positive process id the name carries, or `undefined` for any other name
1326
+ * @returns The process id the name carries, from 1 to `CAPTURE_PID_LIMIT`, or `undefined` for any
1327
+ * other name
1199
1328
  *
1200
1329
  * @example
1201
1330
  * ```ts
1202
1331
  * readCaptureRequestOwner('journey-selection-4242.json') // 4242
1203
1332
  * readCaptureRequestOwner('journey-selection-4242.json.tmp') // 4242
1204
1333
  * readCaptureRequestOwner('journey-selection.json') // undefined
1334
+ * readCaptureRequestOwner('journey-selection-4294967296.json') // undefined
1205
1335
  * ```
1206
1336
  */
1207
1337
  function readCaptureRequestOwner(name) {
1208
1338
  const match = new RegExp(`^${_src_core.CAPTURE_REQUEST_PREFIX}-(\\d+)\\.json(?:\\.tmp)?$`, "u").exec(name);
1209
1339
  const pid = Number(match?.[1]);
1210
- return Number.isSafeInteger(pid) && pid > 0 ? pid : void 0;
1340
+ return Number.isSafeInteger(pid) && pid > 0 && pid <= 2147483647 ? pid : void 0;
1341
+ }
1342
+ /**
1343
+ * Describes the request holders that keep a workspace busy, naming apart those the host could not inspect.
1344
+ *
1345
+ * @param holders - The holders `CaptureInvocationInterface.holders` lists
1346
+ * @param directory - The workspace-relative request directory that holds their request files
1347
+ * @returns The running holders' sentence, then the uninspected holders' sentence with its correction
1348
+ *
1349
+ * @example
1350
+ * ```ts
1351
+ * describeCaptureHolders([{ pid: 4242, inspected: true }], 'tmp/capture')
1352
+ * // 'Another runner holds this workspace (process 4242)'
1353
+ * ```
1354
+ */
1355
+ function describeCaptureHolders(holders, directory) {
1356
+ const running = holders.filter((holder) => holder.inspected).map((holder) => holder.pid);
1357
+ const unknown = holders.filter((holder) => !holder.inspected).map((holder) => holder.pid);
1358
+ return [...running.length === 0 ? [] : [`Another runner holds this workspace (process ${running.join(", ")})`], ...unknown.length === 0 ? [] : [`Request holder process ${unknown.join(", ")} could not be inspected; confirm no capture process or surviving child is running before deleting its request file in ${directory}`]].join(". ");
1211
1359
  }
1212
1360
  /**
1213
1361
  * Resolves a path to the slash-separated form the evidence documents store, relative to a root.
@@ -1259,7 +1407,7 @@ function escapeCapturePattern(text) {
1259
1407
  */
1260
1408
  function buildCaptureFilter(command, selector, selectors) {
1261
1409
  const scopes = selectors.filter((entry) => !entry.includes(":"));
1262
- const owner = selector === "all" ? `(${scopes.map((scope) => `${CAPTURE_OWNER_PREFIX}${scope}`).join(" || ")})` : `${CAPTURE_OWNER_PREFIX}${selector}`;
1410
+ const owner = selector === "all" ? `(${scopes.map((scope) => `${_src_core.CAPTURE_OWNER_PREFIX}${scope}`).join(" || ")})` : `${_src_core.CAPTURE_OWNER_PREFIX}${selector}`;
1263
1411
  const capture = selector === "all" ? `(${scopes.join(" || ")})` : selector.split(":").slice(0, 2).join(":");
1264
1412
  return command === "journey" ? owner : `${owner} && ${capture}`;
1265
1413
  }
@@ -1329,7 +1477,7 @@ function resolveCaptureVariants(selected, projects) {
1329
1477
  * ```
1330
1478
  */
1331
1479
  function requireCaptureSelection(selector, variants, projects, outputs = [], portfolio) {
1332
- const fault = describeCaptureSelectorFault(selector, [...new Set(projects.flatMap((project) => [...project.tags.filter((tag) => tag.startsWith(CAPTURE_OWNER_PREFIX)).map((tag) => tag.slice(CAPTURE_OWNER_PREFIX.length)), ...project.standalone.map((entry) => entry.portfolio)]))]);
1480
+ const fault = describeCaptureSelectorFault(selector, [...new Set(projects.flatMap((project) => [...project.tags.filter((tag) => tag.startsWith(_src_core.CAPTURE_OWNER_PREFIX)).map((tag) => tag.slice(_src_core.CAPTURE_OWNER_PREFIX.length)), ...project.standalone.map((entry) => entry.portfolio)]))]);
1333
1481
  if (fault !== void 0) throw new _src_core.CaptureError(fault, { code: "USAGE" });
1334
1482
  const portfolios = [...new Set(projects.flatMap((project) => [...project.portfolios, ...project.standalone].map((entry) => entry.portfolio)))];
1335
1483
  if (portfolio !== void 0 && !portfolios.includes(portfolio)) throw new _src_core.CaptureError(describeCaptureFault("--portfolio", portfolio, "a portfolio declared by the wrapper", portfolios), { code: "USAGE" });
@@ -1356,7 +1504,7 @@ function readCaptureVariants(root, file) {
1356
1504
  * spaces and quotes. An exact case adds `-t` with the anchored pattern for that case and the
1357
1505
  * final case, so the final case still writes the run record.
1358
1506
  *
1359
- * @param options - The entry, wrapper, report, projects, tag filter, and optional exact case and mode
1507
+ * @param options - The entry, wrapper, report and progress files, projects, tag filter, bail switch, and optional exact case and mode
1360
1508
  * @returns The arguments after the Node executable
1361
1509
  *
1362
1510
  * @example
@@ -1365,6 +1513,7 @@ function readCaptureVariants(root, file) {
1365
1513
  * entry: '/repo/node_modules/vitest/vitest.mjs',
1366
1514
  * config: '/repo/vite.journey.config.ts',
1367
1515
  * report: '/repo/tmp/units/runs/a/journey-selected.json',
1516
+ * progress: '/repo/tmp/units/runs/a/selected.progress.jsonl',
1368
1517
  * projects: ['journey:light-390'],
1369
1518
  * filter: 'owner:pages:mail',
1370
1519
  * final: 'closes the run',
@@ -1383,13 +1532,13 @@ function buildCaptureArguments(options) {
1383
1532
  "--configLoader",
1384
1533
  "runner",
1385
1534
  "--no-cache",
1386
- "--bail=1",
1535
+ ...options.bail === false ? [] : ["--bail=1"],
1387
1536
  "--reporter=dot",
1388
1537
  "--reporter=json",
1389
1538
  `--outputFile.json=${options.report}`,
1539
+ `--outputFile.progress=${options.progress}`,
1390
1540
  ...options.projects.flatMap((project) => ["--project", project]),
1391
- "--tags-filter",
1392
- options.filter,
1541
+ ...options.filter === void 0 ? [] : ["--tags-filter", options.filter],
1393
1542
  ...options.case === void 0 ? [] : ["-t", `^(?:${[options.case, options.final].map((name) => escapeCapturePattern((options.titles?.[name] ?? [name]).join(separator))).join("|")})$`]
1394
1543
  ];
1395
1544
  }
@@ -1397,7 +1546,7 @@ function buildCaptureArguments(options) {
1397
1546
  * Reads the installed workspace Vitest's exact title separator, refusing unsupported majors.
1398
1547
  * @example
1399
1548
  * ```ts
1400
- * readCaptureSeparator('/workspace/node_modules/vitest/vitest.mjs') // ' ' on Vitest 4
1549
+ * readCaptureSeparator('/workspace/node_modules/vitest/vitest.mjs') // ' > ' on Vitest 5
1401
1550
  * ```
1402
1551
  */
1403
1552
  function readCaptureSeparator(entry) {
@@ -1409,9 +1558,8 @@ function readCaptureSeparator(entry) {
1409
1558
  });
1410
1559
  const manifest = loaded.value;
1411
1560
  const version = (0, _orkestrel_contract.isRecord)(manifest) ? manifest.version : void 0;
1412
- if (typeof version === "string" && version.split(".")[0] === "4") return " ";
1413
1561
  if (typeof version === "string" && version.split(".")[0] === "5") return " > ";
1414
- throw new _src_core.CaptureError(describeCaptureFault("vitest.version", version, "a supported installed Vitest major", ["4", "5"]), { code: "HOST" });
1562
+ throw new _src_core.CaptureError(describeCaptureFault("vitest.version", version, "a supported installed Vitest major", ["5"]), { code: "HOST" });
1415
1563
  }
1416
1564
  /**
1417
1565
  * Reads original title segments from the accepted registry's authenticated JSON reporter files.
@@ -1450,6 +1598,10 @@ function readCaptureTitles(root, file, selector) {
1450
1598
  /**
1451
1599
  * Parses standard option tokens and refuses empty values, terminators, and repeated single options.
1452
1600
  *
1601
+ * @remarks A boolean option whose default is `true` reads its `--no-` form as `false` and refuses
1602
+ * its positive form, so `--no-bail` is the one spelling of `bail`; the `--no-` form of any other
1603
+ * option is refused as unknown. An option and its `--no-` form repeat each other.
1604
+ *
1453
1605
  * @param argv - The arguments after the subcommand
1454
1606
  * @param options - The command's frozen Node option definitions
1455
1607
  * @param usage - The command syntax appended to every parser refusal
@@ -1457,6 +1609,7 @@ function readCaptureTitles(root, file, selector) {
1457
1609
  * @example
1458
1610
  * ```ts
1459
1611
  * readCaptureOptions(['--case=-draft'], CAPTURE_COMMAND_OPTIONS.journey, 'Usage: capture journey <selector>').values.case // '-draft'
1612
+ * readCaptureOptions(['--no-bail'], CAPTURE_COMMAND_OPTIONS.journey, 'Usage: capture journey <selector>').values.bail // false
1460
1613
  * ```
1461
1614
  */
1462
1615
  function readCaptureOptions(argv, options, usage) {
@@ -1466,11 +1619,14 @@ function readCaptureOptions(argv, options, usage) {
1466
1619
  options,
1467
1620
  tokens: true,
1468
1621
  strict: true,
1469
- allowPositionals: true
1622
+ allowPositionals: true,
1623
+ allowNegative: true
1470
1624
  });
1471
1625
  for (const token of parsed.tokens) {
1472
1626
  if (token.kind === "option-terminator") throw new _src_core.CaptureError("The -- option terminator is refused", { code: "USAGE" });
1473
1627
  if (token.kind !== "option") continue;
1628
+ if (token.rawName === `--no-${token.name}` && options[token.name]?.default !== true) throw new _src_core.CaptureError(`Unknown option '${token.rawName}'`, { code: "USAGE" });
1629
+ if (token.rawName === `--${token.name}` && options[token.name]?.default === true) throw new _src_core.CaptureError(`Unknown option '${token.rawName}'; ${token.name} is on by default, and --no-${token.name} turns it off`, { code: "USAGE" });
1474
1630
  if (token.value === "") throw new _src_core.CaptureError(`Missing value: --${token.name}`, { code: "USAGE" });
1475
1631
  if (options[token.name]?.multiple !== true && parsed.tokens.some((earlier) => earlier.kind === "option" && earlier.name === token.name && earlier.index < token.index)) throw new _src_core.CaptureError(`Repeated option: --${token.name}`, { code: "USAGE" });
1476
1632
  }
@@ -1487,7 +1643,8 @@ function readCaptureOptions(argv, options, usage) {
1487
1643
  *
1488
1644
  * @remarks
1489
1645
  * `--state` belongs to `capture` and `stale`, and `--portfolio` to `stale`. Journey and capture
1490
- * accept `--changed <ref>` instead of a selector, with optional valueless `--plan`. Every other
1646
+ * accept `--changed <ref>` instead of a selector, with optional valueless `--plan`, and valueless
1647
+ * `--no-bail`, which sets `bail` to `false`. Every other
1491
1648
  * flag takes one nonempty value, either separated or in equals form, and only `--variant` repeats.
1492
1649
  * A value beginning with a dash requires equals form. A bare invocation leaves its selector absent
1493
1650
  * so the caller can print usage with the declared selectors.
@@ -1523,12 +1680,14 @@ function readCaptureArguments(argv, command, root, fallback) {
1523
1680
  const selector = positional.at(0);
1524
1681
  const changed = "changed" in values && typeof values.changed === "string" ? values.changed : void 0;
1525
1682
  const plan = "plan" in values && values.plan === true;
1683
+ const bail = !("bail" in values) || values.bail !== false;
1526
1684
  if (changed !== void 0 && selector !== void 0) throw new _src_core.CaptureError("A selector cannot be combined with --changed; use --changed <ref> alone", { code: "USAGE" });
1527
1685
  if (plan && changed === void 0) throw new _src_core.CaptureError("--plan requires --changed <ref>", { code: "USAGE" });
1528
1686
  return {
1529
1687
  ...selector === void 0 ? {} : { selector },
1530
1688
  ...changed === void 0 ? {} : { changed },
1531
1689
  ...plan ? { plan: true } : {},
1690
+ ...bail ? {} : { bail: false },
1532
1691
  config: (0, node_path.resolve)(root, values.config ?? fallback),
1533
1692
  ...mode === void 0 ? {} : { mode },
1534
1693
  variants,
@@ -1989,29 +2148,6 @@ function collectCaptureErrors(file, text) {
1989
2148
  return text.split(/\r\n|\n/u).filter((line) => /\b(uncaught|unhandled|error:)/iu.test(line)).map((line) => `${file}: ${line}`);
1990
2149
  }
1991
2150
  /**
1992
- * Checks whether a process with this id is running, counting one the caller may not signal.
1993
- *
1994
- * @remarks
1995
- * A zero signal tests existence without sending one. A refusal for permission still proves the
1996
- * process exists, so only a missing process reads as not running.
1997
- *
1998
- * @param pid - The process id
1999
- * @returns True if the process exists; false otherwise
2000
- *
2001
- * @example
2002
- * ```ts
2003
- * readCaptureRunning(process.pid) // true
2004
- * ```
2005
- */
2006
- function readCaptureRunning(pid) {
2007
- try {
2008
- process.kill(pid, 0);
2009
- return true;
2010
- } catch (error) {
2011
- return (0, _orkestrel_contract.isError)(error) && "code" in error && error.code === "EPERM";
2012
- }
2013
- }
2014
- /**
2015
2151
  * Resolves one entry of a wrapper's project list to the project it declares.
2016
2152
  *
2017
2153
  * @remarks
@@ -2214,12 +2350,294 @@ async function answerCaptureDiscovery(options) {
2214
2350
  return true;
2215
2351
  }
2216
2352
  /**
2353
+ * Lists a directory through a reader, answering an empty list for a missing directory.
2354
+ *
2355
+ * @param directory - The absolute directory to list
2356
+ * @param list - Reads the directory's entries, such as `readdirSync` with its options
2357
+ * @returns The entries the reader returned, or none when the directory is missing
2358
+ * @throws Thrown as an `EVIDENCE` capture error naming the directory for any other failure to read it.
2359
+ *
2360
+ * @example
2361
+ * ```ts
2362
+ * readCaptureListing('/repo/tmp/captures/states/pages', (path) => readdirSync(path)) // ['inbox--light-390.png']
2363
+ * ```
2364
+ */
2365
+ function readCaptureListing(directory, list) {
2366
+ const listed = (0, _orkestrel_contract.attempt)(() => list(directory));
2367
+ if (listed.success) return listed.value;
2368
+ if ((0, _orkestrel_contract.isError)(listed.error) && "code" in listed.error && listed.error.code === "ENOENT") return [];
2369
+ throw new _src_core.CaptureError(`Cannot list capture frames under ${directory}`, {
2370
+ code: "EVIDENCE",
2371
+ cause: listed.error,
2372
+ context: { directory }
2373
+ });
2374
+ }
2375
+ /**
2376
+ * Lists the frames a portfolio directory holds, as paths relative to it, in sorted order.
2377
+ *
2378
+ * @remarks
2379
+ * A frame is a `.png` file at the directory's top level or directly inside one of the scope
2380
+ * directories. The run records directory holds no frame, and every other directory is unknown. A
2381
+ * missing directory, or one removed between the listing and its read, holds no frame.
2382
+ *
2383
+ * @param directory - The absolute portfolio directory
2384
+ * @param scopes - The scope directories the owners declare, each an owner path's first segment
2385
+ * @returns Each frame's slash-separated path relative to the directory
2386
+ * @throws Thrown as an `EVIDENCE` capture error for a frame beneath the run records, an unknown
2387
+ * directory, a directory inside a scope, or a directory the host refuses to read.
2388
+ *
2389
+ * @example
2390
+ * ```ts
2391
+ * readCaptureFrames('/repo/tmp/captures/states', ['pages']) // ['pages/inbox--light-390.png']
2392
+ * ```
2393
+ */
2394
+ function readCaptureFrames(directory, scopes) {
2395
+ return readCaptureListing(directory, (path) => (0, node_fs.readdirSync)(path, { withFileTypes: true })).flatMap((entry) => {
2396
+ if (!entry.isDirectory()) return entry.name.endsWith(".png") ? [entry.name] : [];
2397
+ if (entry.name === "runs") {
2398
+ const frames = readCaptureListing((0, node_path.resolve)(directory, entry.name), (path) => (0, node_fs.readdirSync)(path, {
2399
+ recursive: true,
2400
+ encoding: "utf8"
2401
+ })).filter((name) => name.endsWith(".png"));
2402
+ if (frames.length > 0) throw new _src_core.CaptureError(`Frames sit beneath the run records: ${describeCaptureMembers(frames.map(normalizeSlashes))}`, {
2403
+ code: "EVIDENCE",
2404
+ context: { directory }
2405
+ });
2406
+ return [];
2407
+ }
2408
+ if (!scopes.includes(entry.name)) throw new _src_core.CaptureError(`Unknown capture directory: ${describeCaptureFault("directory", entry.name, "a scope the owners declare, or the run records", [...scopes, CAPTURE_RUNS_DIRECTORY])}`, {
2409
+ code: "EVIDENCE",
2410
+ context: { directory }
2411
+ });
2412
+ return readCaptureListing((0, node_path.resolve)(directory, entry.name), (path) => (0, node_fs.readdirSync)(path, { withFileTypes: true })).flatMap((file) => {
2413
+ if (file.isDirectory()) throw new _src_core.CaptureError(`Unknown capture directory: ${(0, _orkestrel_contract.preview)(`${entry.name}/${file.name}`)}; a scope holds frames only`, {
2414
+ code: "EVIDENCE",
2415
+ context: { directory }
2416
+ });
2417
+ return file.name.endsWith(".png") ? [`${entry.name}/${file.name}`] : [];
2418
+ });
2419
+ }).toSorted();
2420
+ }
2421
+ /**
2422
+ * Reads the progress file of the stage that is running, or that ran last, in a workspace.
2423
+ *
2424
+ * @remarks
2425
+ * The file is the most recently modified `<stage>.progress.jsonl` beneath the request directory's
2426
+ * run directories. The progress file is an observation of the run and never evidence. A partial
2427
+ * last line, which the reporter can still be appending, is not read, so a file with no complete
2428
+ * line holds no run. For each run with no `end` line, `alive` reads the process id its `init` line
2429
+ * records: a writer that has ended turns the run `interrupted`, measured to the time of its last
2430
+ * line, and a writer the host cannot inspect, or an id that is not a positive safe integer, lists
2431
+ * the run's id in `uninspected`.
2432
+ *
2433
+ * @param root - The absolute workspace path
2434
+ * @param requests - The workspace-relative request directory
2435
+ * @param now - The wall-clock time of the reading, in milliseconds since the Unix epoch. Default: `Date.now()`
2436
+ * @param alive - Reads whether a writer process exists, or `undefined` when the host cannot tell. Default: `inspectProcess` from `@orkestrel/process/server`
2437
+ * @returns The workspace-relative file, one reading per process that wrote it, and the writers the host could not inspect
2438
+ * @throws Thrown as a `STAGE` capture error when no stage has written a progress file, or when the
2439
+ * file cannot be read or holds a complete line that is not a progress event.
2440
+ *
2441
+ * @example
2442
+ * ```ts
2443
+ * readCaptureProgress('/repo', 'tmp/capture').runs[0]?.state // 'live' while the stage runs
2444
+ * ```
2445
+ */
2446
+ function readCaptureProgress(root, requests, now = Date.now(), alive = _orkestrel_process_server.inspectProcess) {
2447
+ const runs = (0, node_path.resolve)(root, requests, CAPTURE_RUNS_DIRECTORY);
2448
+ const [newest] = (0, node_fs.globSync)(`*/*${CAPTURE_PROGRESS_SUFFIX}`, { cwd: runs }).flatMap((name) => {
2449
+ const stat = (0, _orkestrel_contract.attempt)(() => (0, node_fs.statSync)((0, node_path.resolve)(runs, name)));
2450
+ return stat.success && stat.value.isFile() ? [{
2451
+ file: resolveCaptureRelative(root, (0, node_path.resolve)(runs, name)),
2452
+ time: stat.value.mtimeMs
2453
+ }] : [];
2454
+ }).toSorted((left, right) => right.time - left.time || right.file.localeCompare(left.file));
2455
+ if (newest === void 0) throw new _src_core.CaptureError(`No stage has written a progress file under ${resolveCaptureRelative(root, runs)}; run a journey, frames, or registry command first`, {
2456
+ code: "STAGE",
2457
+ context: { directory: resolveCaptureRelative(root, runs) }
2458
+ });
2459
+ const read = (0, _orkestrel_contract.attempt)(() => (0, _orkestrel_test_server.extractProgressEvents)((0, _orkestrel_test_server.readFileSnapshot)((0, node_path.resolve)(root, newest.file)).toString("utf8")));
2460
+ if (!read.success) throw new _src_core.CaptureError(`Cannot read the progress file ${newest.file}: ${describeCaptureOutput((0, _src_core.describeCaptureError)(read.error))}`, {
2461
+ code: "STAGE",
2462
+ cause: read.error,
2463
+ context: { file: newest.file }
2464
+ });
2465
+ const events = read.value;
2466
+ const computed = (0, _orkestrel_test_server.computeProgress)(events, now);
2467
+ const writers = new Map(computed.filter((run) => run.state === "live").map((run) => [run.pid, Number.isSafeInteger(run.pid) && run.pid > 0 ? alive(run.pid) : void 0]));
2468
+ return {
2469
+ file: newest.file,
2470
+ runs: computed.map((run) => {
2471
+ if (writers.get(run.pid) !== false) return run;
2472
+ const own = events.filter((event) => event.pid === run.pid);
2473
+ const init = own.findLast((event) => event.event === "init");
2474
+ const last = own.at(-1);
2475
+ return {
2476
+ ...init === void 0 || last === void 0 ? run : (0, _orkestrel_test_server.computeProgressRun)(own, init.wall + last.time - init.time) ?? run,
2477
+ state: "interrupted",
2478
+ running: [],
2479
+ remaining: void 0
2480
+ };
2481
+ }),
2482
+ uninspected: [...writers].flatMap(([pid, answer]) => answer === void 0 ? [pid] : [])
2483
+ };
2484
+ }
2485
+ /**
2486
+ * Renders a progress reading as the text `capture progress` prints.
2487
+ *
2488
+ * @param progress - The reading `readCaptureProgress` returns
2489
+ * @returns The file line, then each run as `renderProgress` from `@orkestrel/test/server` renders it,
2490
+ * followed by an unknown-state line for each run whose writer the host could not inspect
2491
+ *
2492
+ * @example
2493
+ * ```ts
2494
+ * renderCaptureProgress({ file: 'tmp/capture/runs/a/selected.progress.jsonl', runs: [], uninspected: [] })
2495
+ * // 'progress tmp/capture/runs/a/selected.progress.jsonl\nNo run has written a complete progress line yet'
2496
+ * ```
2497
+ */
2498
+ function renderCaptureProgress(progress) {
2499
+ return [`progress ${progress.file}`, ...progress.runs.length === 0 ? ["No run has written a complete progress line yet"] : progress.runs.flatMap((run) => [(0, _orkestrel_test_server.renderProgress)([run]), ...progress.uninspected.includes(run.pid) ? [` state unknown: the host could not inspect writer ${String(run.pid)}, so the run might have ended without its end line`] : []])].join("\n");
2500
+ }
2501
+ /**
2502
+ * Builds the values capture merges into one variant's Vitest project.
2503
+ *
2504
+ * @param options - The wrapper's declarations
2505
+ * @param variant - The variant the project produces
2506
+ * @param provided - The variant's frame directory, run record path, capture switch, and runner request
2507
+ * @returns The owner tags, the provided values, and the `readCaptureFrames` browser command over the directory
2508
+ *
2509
+ * @example
2510
+ * ```ts
2511
+ * buildCaptureOverride(options, variant, { directory, record, capture: true }).test.provide.record
2512
+ * // 'tmp/captures/states/runs/run-1/selected/light-390.json'
2513
+ * ```
2514
+ */
2515
+ function buildCaptureOverride(options, variant, provided) {
2516
+ const scopes = [...new Set(options.owners.flatMap((owner) => (0, _src_core.collectCaptureAncestors)(owner).slice(0, 1)))];
2517
+ return { test: {
2518
+ tags: (0, _src_core.buildCaptureTags)(options.owners).map((name) => ({ name })),
2519
+ provide: {
2520
+ variant: variant.name,
2521
+ variants: options.variants,
2522
+ directory: provided.directory,
2523
+ record: provided.record,
2524
+ inputs: options.inputs,
2525
+ sources: options.sources,
2526
+ final: options.final,
2527
+ first: options.first,
2528
+ ...options.uniform === void 0 ? {} : { uniform: options.uniform },
2529
+ portfolios: options.portfolios,
2530
+ capture: provided.capture,
2531
+ ...provided.request === void 0 ? {} : { request: provided.request }
2532
+ },
2533
+ browser: { commands: { readCaptureFrames: () => readCaptureFrames(provided.directory, scopes) } }
2534
+ } };
2535
+ }
2536
+ /**
2537
+ * Builds a journey wrapper's Vitest configuration as plain data, answering discovery first.
2538
+ *
2539
+ * @remarks
2540
+ * Call it inside the wrapper's own `defineConfig` callback, before any other work: capture imports
2541
+ * neither Vite nor Vitest, so the result is data the wrapper returns. The wrapper path is `url`
2542
+ * relative to the working directory, which is the workspace root for every child the runner
2543
+ * spawns. During a discovery request it describes each variant's project as `{ name, tags,
2544
+ * provide }`, with the name the host's `project` chose, and returns `buildCaptureDiscoveryConfig()`.
2545
+ * Otherwise it reads the runner's request, provides each project the values `CaptureProvided`
2546
+ * declares except `standalone`, and registers the browser command `readCaptureFrames`, which lists the frames under
2547
+ * the provided directory. With the capture variable unset, each variant writes to its own scratch
2548
+ * sibling of the evidence root, emptied first. The result's root `plugins` holds one
2549
+ * `createProgressPlugin()`, so a stage the runner passes `--outputFile.progress` writes its
2550
+ * progress file.
2551
+ *
2552
+ * @param options - The wrapper path, variants, owners, stage and final names, evidence root, inputs, sources, portfolios, and project builder
2553
+ * @returns The discovery configuration while discovery runs, and otherwise the progress plugin and one project per variant
2554
+ * @throws Thrown as a `HOST` capture error, before any directory work, for a `url` that is no
2555
+ * `file:` URL, an evidence root that is not a portable relative path, or a variant name that is no
2556
+ * capture segment, and later for an invalid owner or a runner request that fails its checks; and as
2557
+ * a `CONTAINMENT` capture error for a wrapper or scratch path outside the workspace.
2558
+ *
2559
+ * @example
2560
+ * ```ts
2561
+ * export default defineConfig(({ mode }) =>
2562
+ * buildCaptureWrapper({ ...declarations, url: import.meta.url, project: (variant, override) => appJourney(variant, mode, override) }),
2563
+ * )
2564
+ * ```
2565
+ */
2566
+ async function buildCaptureWrapper(options) {
2567
+ const root = process.cwd();
2568
+ const path = (0, _orkestrel_contract.attempt)(() => (0, node_url.fileURLToPath)(options.url));
2569
+ if (!path.success) throw new _src_core.CaptureError(`Invalid wrapper url; ${describeCaptureFault("url", options.url, "the wrapper module's import.meta.url, a file: URL")}`, {
2570
+ code: "HOST",
2571
+ cause: path.error
2572
+ });
2573
+ requireCaptureContained(root, path.value);
2574
+ if (!(0, _src_core.isCapturePath)(options.directory)) throw new _src_core.CaptureError(`Invalid evidence root; ${describeCaptureFault("directory", options.directory, "a portable workspace-relative path")}`, { code: "HOST" });
2575
+ const invalid = options.variants.findIndex((variant) => !(0, _src_core.isCaptureSegment)(variant.name));
2576
+ if (invalid !== -1) throw new _src_core.CaptureError(`Invalid variant name; ${describeCaptureFault(`variants[${String(invalid)}].name`, options.variants[invalid]?.name, "a portable nonempty identity segment")}`, { code: "HOST" });
2577
+ const roots = [options.directory, ...options.portfolios.map((entry) => entry.directory)];
2578
+ for (const variant of options.variants) {
2579
+ const scratch = (0, node_path.resolve)(root, (0, node_path.dirname)(options.directory), `${CAPTURE_WRAPPER_PREFIXES.scratch}${variant.name}`);
2580
+ const overlap = roots.find((entry) => [(0, node_path.relative)((0, node_path.resolve)(root, entry), scratch), (0, node_path.relative)(scratch, (0, node_path.resolve)(root, entry))].some((step) => step === "" || !step.startsWith("..") && !(0, node_path.isAbsolute)(step)));
2581
+ if (overlap !== void 0) throw new _src_core.CaptureError(`Invalid evidence root; the no-capture scratch directory ${resolveCaptureRelative(root, scratch)} of variant ${variant.name} overlaps ${overlap}, which it would empty`, { code: "HOST" });
2582
+ }
2583
+ const config = resolveCaptureRelative(root, path.value);
2584
+ const argv = process.argv.slice(1);
2585
+ const capture = process.env[CAPTURE_FLAG] === "1";
2586
+ const evidence = (0, node_path.resolve)(root, options.directory);
2587
+ if (await answerCaptureDiscovery({
2588
+ ppid: process.ppid,
2589
+ argv,
2590
+ config,
2591
+ projects: options.variants.map((variant) => () => {
2592
+ const override = buildCaptureOverride(options, variant, {
2593
+ directory: evidence,
2594
+ record: `${options.directory}/runs/${CAPTURE_DISCOVERY.phase}/${variant.name}.json`,
2595
+ capture
2596
+ });
2597
+ const project = options.project(variant, override);
2598
+ return { test: {
2599
+ name: (0, _orkestrel_contract.isRecord)(project) && (0, _orkestrel_contract.isRecord)(project.test) ? project.test.name : void 0,
2600
+ tags: override.test.tags,
2601
+ provide: override.test.provide
2602
+ } };
2603
+ })
2604
+ })) return buildCaptureDiscoveryConfig();
2605
+ const request = readCaptureRequest({
2606
+ ppid: process.ppid,
2607
+ argv,
2608
+ config,
2609
+ owners: options.owners,
2610
+ variants: options.variants.map((variant) => variant.name)
2611
+ });
2612
+ const invocation = request === void 0 ? `${CAPTURE_WRAPPER_PREFIXES.direct}${(0, node_crypto.randomUUID)()}` : `${request.id}/${request.stage}`;
2613
+ return {
2614
+ plugins: [(0, _orkestrel_test_server.createProgressPlugin)()],
2615
+ test: { projects: options.variants.map((variant) => {
2616
+ const directory = capture ? evidence : requireCaptureContained(root, (0, node_path.resolve)(root, (0, node_path.dirname)(options.directory), `${CAPTURE_WRAPPER_PREFIXES.scratch}${variant.name}`));
2617
+ if (!capture) {
2618
+ (0, node_fs.rmSync)(directory, {
2619
+ recursive: true,
2620
+ force: true
2621
+ });
2622
+ (0, node_fs.mkdirSync)(directory, { recursive: true });
2623
+ }
2624
+ return options.project(variant, buildCaptureOverride(options, variant, {
2625
+ directory,
2626
+ record: `${options.directory}/${CAPTURE_RUNS_DIRECTORY}/${invocation}/${variant.name}.json`,
2627
+ capture,
2628
+ ...request === void 0 ? {} : { request }
2629
+ }));
2630
+ }) }
2631
+ };
2632
+ }
2633
+ /**
2217
2634
  * Reads the registry command line into the wrapper path, the variants to refresh, and the mode.
2218
2635
  *
2219
2636
  * @remarks
2220
2637
  * The command takes no selector: it refreshes every producing variant the wrapper declares, or the
2221
- * variants named by repeated `--variant` flags. Every flag takes one value, and only `--variant`
2222
- * repeats. `--mode` is forwarded to the wrapper's Vitest process unread.
2638
+ * variants named by repeated `--variant` flags. Every flag but valueless `--no-bail` takes one
2639
+ * value, and only `--variant` repeats. `--mode` is forwarded to the wrapper's Vitest process
2640
+ * unread, and `--no-bail` sets `bail` to `false`.
2223
2641
  *
2224
2642
  * @param argv - The arguments after the subcommand
2225
2643
  * @param root - The absolute workspace path the wrapper path resolves against
@@ -2235,7 +2653,7 @@ async function answerCaptureDiscovery(options) {
2235
2653
  * ```
2236
2654
  */
2237
2655
  function readCaptureRegistryArguments(argv, root, fallback) {
2238
- const usage = "Usage: capture registry [--variant <name>]... [--mode <name>] [--config <file>]";
2656
+ const usage = "Usage: capture registry [--variant <name>]... [--no-bail] [--mode <name>] [--config <file>]";
2239
2657
  const { values, positionals } = readCaptureOptions(argv, CAPTURE_COMMAND_OPTIONS.registry, usage);
2240
2658
  if (positionals.length > 0) throw new _src_core.CaptureError(`Unexpected argument ${JSON.stringify(positionals[0]?.slice(0, 80))}: the registry command takes no selector and refreshes every producing variant, or those named by --variant. ${usage}`, { code: "USAGE" });
2241
2659
  const variants = values.variant ?? [];
@@ -2246,7 +2664,8 @@ function readCaptureRegistryArguments(argv, root, fallback) {
2246
2664
  return {
2247
2665
  config: (0, node_path.resolve)(root, values.config ?? fallback),
2248
2666
  variants,
2249
- ...mode === void 0 ? {} : { mode }
2667
+ ...mode === void 0 ? {} : { mode },
2668
+ ...values.bail === false ? { bail: false } : {}
2250
2669
  };
2251
2670
  }
2252
2671
  /**
@@ -2447,6 +2866,7 @@ var CaptureIntegrity = class {
2447
2866
  #root;
2448
2867
  #roots;
2449
2868
  #hash;
2869
+ #matches = /* @__PURE__ */ new Map();
2450
2870
  /**
2451
2871
  * Binds the engine to an explicit workspace and host portfolio mapping.
2452
2872
  *
@@ -3090,12 +3510,24 @@ var CaptureIntegrity = class {
3090
3510
  ]) {
3091
3511
  const current = this.#digest(patterns, snapshots, digests);
3092
3512
  if (Object.keys(current.files).some((file) => before.files[file] === void 0)) throw new _src_core.CaptureError(`Attribution outside the predeclared host population: ${entry.file}`, { code: "STAGE" });
3093
- const previous = Object.fromEntries(Object.entries(before.files).filter(([file]) => patterns.some((pattern) => (0, node_path.matchesGlob)(file, pattern))));
3513
+ const matched = this.#match(before, patterns);
3514
+ const previous = Object.fromEntries(Object.entries(before.files).filter(([file]) => matched.has(file)));
3094
3515
  if ((0, _src_core.collectCaptureChanges)(previous, current.files).length > 0) throw new _src_core.CaptureError(`Attributed inputs or membership changed during execution: ${entry.file}`, { code: "STAGE" });
3095
- if (patterns.some((pattern) => !Object.keys(current.files).some((file) => (0, node_path.matchesGlob)(file, pattern)))) throw new _src_core.CaptureError(`Declared source pattern has no files: ${entry.file}`, { code: "HOST" });
3516
+ if (patterns.some((pattern) => {
3517
+ const files = this.#match(before, [pattern]);
3518
+ return !Object.keys(current.files).some((file) => files.has(file));
3519
+ })) throw new _src_core.CaptureError(`Declared source pattern has no files: ${entry.file}`, { code: "HOST" });
3096
3520
  }
3097
3521
  stable.set(key, true);
3098
3522
  }
3523
+ #match(inputs, patterns) {
3524
+ const key = computeCaptureMatchKey(inputs, patterns);
3525
+ const known = this.#matches.get(key);
3526
+ if (known !== void 0) return known;
3527
+ const matched = filterCaptureInputs(inputs, patterns);
3528
+ this.#matches.set(key, matched);
3529
+ return matched;
3530
+ }
3099
3531
  #destination(entry, paths) {
3100
3532
  const portfolio = this.#options.portfolios.find((candidate) => candidate.portfolio === entry.portfolio);
3101
3533
  if (portfolio === void 0) throw new _src_core.CaptureError(`Unknown portfolio: ${entry.portfolio}`, { code: "SELECTION" });
@@ -3395,6 +3827,7 @@ var CaptureInvocation = class {
3395
3827
  }
3396
3828
  async release() {
3397
3829
  const failures = [];
3830
+ const kept = [];
3398
3831
  try {
3399
3832
  if (this.#termination !== void 0) await this.#termination;
3400
3833
  failures.push(...await settleCaptureShutdown(() => this.retract(), [...this.#children].map((child) => () => this.#stop(child))));
@@ -3413,7 +3846,10 @@ var CaptureInvocation = class {
3413
3846
  }
3414
3847
  if (this.#owner(marker.value).id !== this.id) return;
3415
3848
  if (this.#unconfirmed.size > 0) {
3416
- this.#record();
3849
+ kept.push(`ownership marker retained: ${this.#lock}`);
3850
+ const record = (0, _orkestrel_contract.attempt)(() => this.#record());
3851
+ if (record.success) kept.push(`child record: ${record.value}`);
3852
+ else failures.push(record.error);
3417
3853
  return;
3418
3854
  }
3419
3855
  this.#remove(deadline);
@@ -3422,7 +3858,7 @@ var CaptureInvocation = class {
3422
3858
  else if (!removal.success) failures.push(removal.error);
3423
3859
  }
3424
3860
  }
3425
- if (failures.length > 0 || this.#unconfirmed.size > 0) throw new _src_core.CaptureError(`Capture shutdown failed${this.#unconfirmed.size === 0 ? "" : `; child termination was not confirmed for process ${[...this.#unconfirmed].join(", ")}; ownership marker retained: ${this.#lock}; child record: ${(0, node_path.resolve)(this.#directory, CAPTURE_SURVIVORS_FILE)}`}`, {
3861
+ if (failures.length > 0 || this.#unconfirmed.size > 0) throw new _src_core.CaptureError(`Capture shutdown failed${this.#unconfirmed.size === 0 ? "" : `; child termination was not confirmed for process ${[...this.#unconfirmed].join(", ")}`}${kept.map((entry) => `; ${entry}`).join("")}`, {
3426
3862
  code: "STAGE",
3427
3863
  cause: new AggregateError(failures)
3428
3864
  });
@@ -3434,15 +3870,21 @@ var CaptureInvocation = class {
3434
3870
  for (const name of (0, node_fs.readdirSync)(requests)) {
3435
3871
  const pid = readCaptureRequestOwner(name);
3436
3872
  if (pid === void 0 || pid === process.pid) continue;
3437
- if (!readCaptureRunning(pid)) (0, node_fs.rmSync)((0, node_path.resolve)(requests, name), { force: true });
3873
+ if (this.#alive(pid) === false) (0, _orkestrel_contract.attempt)(() => (0, node_fs.rmSync)((0, node_path.resolve)(requests, name), { force: true }));
3438
3874
  }
3439
3875
  }
3440
3876
  holders() {
3441
3877
  const requests = (0, node_path.resolve)(this.#options.root, this.#options.requests);
3442
3878
  return [...new Set((0, node_fs.readdirSync)(requests).flatMap((name) => {
3443
3879
  const pid = readCaptureRequestOwner(name);
3444
- return pid === void 0 || pid === process.pid && this.#lease !== void 0 || !readCaptureRunning(pid) ? [] : [pid];
3445
- }))];
3880
+ return pid === void 0 || pid === process.pid && this.#lease !== void 0 ? [] : [pid];
3881
+ }))].flatMap((pid) => {
3882
+ const alive = this.#alive(pid);
3883
+ return alive === false ? [] : [{
3884
+ pid,
3885
+ inspected: alive === true
3886
+ }];
3887
+ });
3446
3888
  }
3447
3889
  publish(request) {
3448
3890
  this.#claim();
@@ -3477,16 +3919,13 @@ var CaptureInvocation = class {
3477
3919
  try {
3478
3920
  (0, node_fs.mkdirSync)(this.#directory, { recursive: true });
3479
3921
  (0, node_fs.writeFileSync)(log, "");
3480
- const environment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toLowerCase() !== "CAPTURE".toLowerCase() && name.toLowerCase() !== "CAPTURE_REQUESTS".toLowerCase()));
3481
3922
  const session = (0, _orkestrel_process_server.createDuplex)({
3482
3923
  command: {
3483
3924
  file: process.execPath,
3484
3925
  arguments: args,
3485
- isolated: true,
3486
3926
  environment: {
3487
- ...environment,
3488
3927
  [CAPTURE_REQUESTS_FLAG]: (0, node_path.resolve)(this.#options.root, this.#options.requests),
3489
- ...capture ? { [CAPTURE_FLAG]: "1" } : {}
3928
+ [CAPTURE_FLAG]: capture ? "1" : void 0
3490
3929
  }
3491
3930
  },
3492
3931
  workspace: this.#options.root,
@@ -3598,9 +4037,10 @@ var CaptureInvocation = class {
3598
4037
  try {
3599
4038
  if (this.#options.ownership?.write === void 0) (0, node_fs.writeFileSync)(file, text, { flag: "wx" });
3600
4039
  else this.#options.ownership.write(file, text);
4040
+ return file;
3601
4041
  } catch (error) {
3602
4042
  const code = error instanceof Error && "code" in error ? String(error.code) : (0, _src_core.describeCaptureError)(error);
3603
- if (code === "EEXIST") return;
4043
+ if (code === "EEXIST") return file;
3604
4044
  if (code === "ENOENT" && retry) {
3605
4045
  (0, node_fs.mkdirSync)(this.#directory, { recursive: true });
3606
4046
  return this.#record(false);
@@ -3624,9 +4064,9 @@ var CaptureInvocation = class {
3624
4064
  }
3625
4065
  #backoff(deadline, error) {
3626
4066
  const left = deadline - performance.now();
3627
- if (left <= 0) throw new _src_core.CaptureError(`Capture ownership marker is temporarily unavailable (${error instanceof Error && "code" in error ? String(error.code) : "contention"}): ${this.#lock}; rerun after serializing capture commands`, {
4067
+ if (left <= 0) throw new _src_core.CaptureError(error === void 0 ? `Capture ownership marker kept changing until the deadline: ${this.#lock}; rerun after serializing capture commands` : `Capture ownership marker is temporarily unavailable (${error instanceof Error && "code" in error ? String(error.code) : (0, _src_core.describeCaptureError)(error)}): ${this.#lock}; rerun after serializing capture commands`, {
3628
4068
  code: "STAGE",
3629
- cause: error
4069
+ ...error === void 0 ? {} : { cause: error }
3630
4070
  });
3631
4071
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Math.min(10, left));
3632
4072
  }
@@ -3641,7 +4081,7 @@ var CaptureInvocation = class {
3641
4081
  for (const name of (0, node_fs.readdirSync)(requests)) {
3642
4082
  if (!name.startsWith(`.capture-owner.`) || !name.endsWith(".tmp")) continue;
3643
4083
  const [pid] = name.slice(CAPTURE_OWNER_FILE.length + 1).split(".");
3644
- if (pid !== void 0 && /^\d+$/u.test(pid) && Number.isSafeInteger(Number(pid)) && Number(pid) > 0 && !readCaptureRunning(Number(pid))) (0, _orkestrel_contract.attempt)(() => (0, node_fs.rmSync)((0, node_path.resolve)(requests, name), { force: true }));
4084
+ if (pid !== void 0 && /^\d+$/u.test(pid) && Number.isSafeInteger(Number(pid)) && Number(pid) > 0 && this.#alive(Number(pid)) === false) (0, _orkestrel_contract.attempt)(() => (0, node_fs.rmSync)((0, node_path.resolve)(requests, name), { force: true }));
3645
4085
  }
3646
4086
  const temporary = `${this.#lock}.${String(process.pid)}.${this.id}.tmp`;
3647
4087
  try {
@@ -3666,7 +4106,7 @@ var CaptureInvocation = class {
3666
4106
  cause: error
3667
4107
  });
3668
4108
  } finally {
3669
- (0, node_fs.rmSync)(temporary, { force: true });
4109
+ (0, _orkestrel_contract.attempt)(() => (0, node_fs.rmSync)(temporary, { force: true }));
3670
4110
  }
3671
4111
  }
3672
4112
  #acquire(temporary, deadline) {
@@ -3693,7 +4133,7 @@ var CaptureInvocation = class {
3693
4133
  });
3694
4134
  }
3695
4135
  const owner = (0, _orkestrel_contract.attempt)(() => this.#owner(marker.value));
3696
- const alive = owner.success ? (this.#options.ownership?.alive ?? readCaptureRunning)(owner.value.pid) : void 0;
4136
+ const alive = owner.success ? this.#alive(owner.value.pid) : void 0;
3697
4137
  if (!owner.success) this.#backoff(deadline);
3698
4138
  const confirmed = (0, _orkestrel_contract.attempt)(() => this.#read(deadline));
3699
4139
  if (!confirmed.success) {
@@ -3712,7 +4152,10 @@ var CaptureInvocation = class {
3712
4152
  return this.#acquire(temporary, deadline);
3713
4153
  }
3714
4154
  if (!owner.success) throw owner.error;
3715
- this.#refuse(owner.value, alive === true);
4155
+ this.#refuse(owner.value, alive);
4156
+ }
4157
+ #alive(pid) {
4158
+ return (this.#options.ownership?.alive ?? _orkestrel_process_server.inspectProcess)(pid);
3716
4159
  }
3717
4160
  #owner(marker) {
3718
4161
  if (marker === "") throw new _src_core.CaptureError(`Capture ownership marker is empty; confirm no capture process or surviving child is running and inspect this file: ${this.#lock}; its holder cannot be established`, { code: "STAGE" });
@@ -3724,15 +4167,18 @@ var CaptureInvocation = class {
3724
4167
  };
3725
4168
  }
3726
4169
  #refuse(holder, alive) {
3727
- if (!alive) throw new _src_core.CaptureError(`Capture ownership process ${String(holder.pid)} is not running; invocation ${(0, _orkestrel_contract.preview)(holder.id)}. ${this.#survivors(holder)} Confirm no capture process or surviving child is running and re-read ${this.#lock} to confirm it still names pid ${String(holder.pid)} before you delete this file and rerun`, { code: "STAGE" });
4170
+ if (alive === false) throw new _src_core.CaptureError(`Capture ownership process ${String(holder.pid)} is not running; invocation ${(0, _orkestrel_contract.preview)(holder.id)}. ${this.#survivors(holder)} Confirm no capture process or surviving child is running and re-read ${this.#lock} to confirm it still names pid ${String(holder.pid)} before you delete this file and rerun`, { code: "STAGE" });
4171
+ if (alive === void 0) throw new _src_core.CaptureError(`Capture ownership process ${String(holder.pid)} could not be inspected; invocation ${(0, _orkestrel_contract.preview)(holder.id)}; serialize capture commands. Confirm no capture process or surviving child is running and re-read ${this.#lock} to confirm it still names pid ${String(holder.pid)} before deleting`, { code: "STAGE" });
3728
4172
  throw new _src_core.CaptureError(`Another runner holds this workspace (process ${(0, _orkestrel_contract.preview)(holder.pid)}); invocation ${(0, _orkestrel_contract.preview)(holder.id)}; serialize capture commands. If this pid is not a capture run, confirm no capture process or surviving child is running and re-read ${this.#lock} to confirm it still names pid ${String(holder.pid)} before deleting`, { code: "STAGE" });
3729
4173
  }
3730
4174
  #survivors(holder) {
4175
+ if (!/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/u.test(holder.id)) return `Invocation ${(0, _orkestrel_contract.preview)(holder.id)} is not an invocation id; no child record is read.`;
3731
4176
  const file = (0, node_path.resolve)(this.#options.root, this.#options.requests, CAPTURE_RUNS_DIRECTORY, holder.id, CAPTURE_SURVIVORS_FILE);
3732
4177
  try {
3733
4178
  const record = (0, _orkestrel_contract.parseJSON)(this.#options.ownership?.read === void 0 ? (0, node_fs.readFileSync)(file, "utf8") : this.#options.ownership.read(file));
3734
4179
  if (!(0, _orkestrel_contract.isRecord)(record) || record.pid !== holder.pid || record.id !== holder.id || typeof record.command !== "string" || record.command === "" || typeof record.at !== "string" || !Number.isFinite(Date.parse(record.at)) || !Array.isArray(record.children) || !record.children.every((pid) => typeof pid === "number" && Number.isSafeInteger(pid) && pid > 0)) return `Child record could not be read (EINVAL): ${file}.`;
3735
- return `Unconfirmed child processes: ${record.children.join(", ")}; stop them before deleting. Child record: ${file}.`;
4180
+ const omitted = record.children.length - 16;
4181
+ return `Unconfirmed child processes: ${[...record.children.slice(0, 16), ...omitted > 0 ? [`… ${String(omitted)} more`] : []].join(", ")}; stop them before deleting. Child record: ${file}.`;
3736
4182
  } catch (error) {
3737
4183
  const code = error instanceof SyntaxError ? "EINVAL" : error instanceof Error && "code" in error ? String(error.code) : (0, _src_core.describeCaptureError)(error);
3738
4184
  return code === "ENOENT" ? `No child record exists at ${file}.` : `Child record could not be read (${code}): ${file}.`;
@@ -4005,14 +4451,14 @@ var CapturePreflight = class {
4005
4451
  issues: [(0, _src_core.describeCaptureError)(outcome.error)]
4006
4452
  };
4007
4453
  const artifact = outcome.value;
4008
- const lines = artifact.text.split(/\r\n|\n/u);
4454
+ const lines = (0, _src_core.readCaptureArtifact)(artifact.text);
4009
4455
  return {
4010
4456
  entry,
4011
4457
  artifact,
4012
4458
  issues: [
4013
4459
  ...artifact.run.passed.includes(location.value.case) && artifact.run.entries.some((emitted) => (0, _src_core.resolveCaptureKey)(emitted) === (0, _src_core.resolveCaptureKey)(entry)) ? [] : [`Judged record does not cover ${entry.file}: ${artifact.record}`],
4014
- ...lines.includes(`record=${artifact.record}`) ? [] : [`Judged journey artifact does not cover its record: ${artifact.file}`],
4015
- ...lines.includes(`case-ran=${location.value.case}`) ? [] : [`Judged journey artifact does not cover ${location.value.case}: ${artifact.file}`]
4460
+ ...lines.records.includes(artifact.record) ? [] : [`Judged journey artifact does not cover its record: ${artifact.file}`],
4461
+ ...lines.cases.includes(location.value.case) ? [] : [`Judged journey artifact does not cover ${location.value.case}: ${artifact.file}`]
4016
4462
  ]
4017
4463
  };
4018
4464
  });
@@ -4079,7 +4525,8 @@ var CapturePreflight = class {
4079
4525
  * requires, so it cannot stamp through the integrity engine. It reads the wrapper through the same
4080
4526
  * discovery the runner uses, takes the same invocation entity, request file, and Vitest child, and runs
4081
4527
  * every selected producing variant in one stage, one child that receives each variant's project, with
4082
- * the `all` selector and no capture variable. It reads the stage's reporter once and each variant's
4528
+ * the `all` selector and no capture variable. The stage passes no tag filter, so it runs the whole
4529
+ * suite, which stands in for the consumer's complete test run. It reads the stage's reporter once and each variant's
4083
4530
  * final record, takes each project's input population before and after, and builds one receipt per
4084
4531
  * variant, all naming the one reporter, through `buildCaptureRegistry`. The registry is written to a
4085
4532
  * candidate beside its target, read back through the integrity engine, and only then renamed into
@@ -4172,14 +4619,14 @@ var CaptureRegistrar = class {
4172
4619
  });
4173
4620
  this.#inherit(options);
4174
4621
  const holders = invocation.holders();
4175
- if (holders.length > 0) throw new _src_core.CaptureError(`Another runner holds this workspace (process ${holders.join(", ")}); the registry refresh starts only while no runner is mid-stage`, {
4622
+ if (holders.length > 0) throw new _src_core.CaptureError(`${describeCaptureHolders(holders, this.#options.requests)}; the registry refresh starts only while no runner is mid-stage`, {
4176
4623
  code: "STAGE",
4177
- context: { holders }
4624
+ context: { holders: holders.map((holder) => holder.pid) }
4178
4625
  });
4179
4626
  const retained = parsed.variants.length === 0 ? [] : this.#retain(target, variants, declared);
4180
4627
  if (retained.length > 0) buildCaptureRegistry(retained);
4181
4628
  if (invocation.interrupted) return CAPTURE_EXIT.failed;
4182
- const imports = await this.#stage(invocation, parsed, projects, primary, selected);
4629
+ const imports = await this.#stage(invocation, parsed, primary, selected);
4183
4630
  if (invocation.interrupted) return CAPTURE_EXIT.failed;
4184
4631
  const registry = buildCaptureRegistry([...retained, ...imports]);
4185
4632
  const path = (0, node_path.resolve)(root, candidate);
@@ -4219,9 +4666,8 @@ var CaptureRegistrar = class {
4219
4666
  }
4220
4667
  }
4221
4668
  }
4222
- async #stage(invocation, parsed, projects, primary, selected) {
4669
+ async #stage(invocation, parsed, primary, selected) {
4223
4670
  const { root } = this.#options;
4224
- const selectors = [...new Set(projects.flatMap((candidate) => candidate.tags))].filter((tag) => tag.startsWith(CAPTURE_OWNER_PREFIX)).map((tag) => tag.slice(CAPTURE_OWNER_PREFIX.length));
4225
4671
  const stage = CAPTURE_REGISTRY_STAGE;
4226
4672
  const variants = selected.map((project) => project.variant);
4227
4673
  const reportFile = (0, node_path.resolve)(invocation.directory, `${stage}.json`);
@@ -4231,8 +4677,9 @@ var CaptureRegistrar = class {
4231
4677
  entry: (0, node_path.resolve)(root, CAPTURE_VITEST_ENTRY),
4232
4678
  config: parsed.config,
4233
4679
  report: reportFile,
4680
+ progress: (0, node_path.resolve)(invocation.directory, `${stage}${CAPTURE_PROGRESS_SUFFIX}`),
4681
+ ...parsed.bail === void 0 ? {} : { bail: parsed.bail },
4234
4682
  projects: selected.map((project) => project.name),
4235
- filter: buildCaptureFilter("journey", "all", selectors),
4236
4683
  final: primary.final,
4237
4684
  ...parsed.mode === void 0 ? {} : { mode: parsed.mode }
4238
4685
  });
@@ -4482,7 +4929,7 @@ var CaptureRunner = class {
4482
4929
  })}\nNEXT ${complete}\n`);
4483
4930
  return parsed.plan ? CAPTURE_EXIT.passed : CAPTURE_EXIT.failed;
4484
4931
  }
4485
- const selectors = [...new Set(projects.flatMap((project) => project.tags))].filter((tag) => tag.startsWith(CAPTURE_OWNER_PREFIX)).map((tag) => tag.slice(CAPTURE_OWNER_PREFIX.length));
4932
+ const selectors = [...new Set(projects.flatMap((project) => project.tags))].filter((tag) => tag.startsWith(_src_core.CAPTURE_OWNER_PREFIX)).map((tag) => tag.slice(_src_core.CAPTURE_OWNER_PREFIX.length));
4486
4933
  for (const owner of plan.owners) {
4487
4934
  const fault = describeCaptureSelectorFault(owner, selectors);
4488
4935
  if (fault !== void 0) throw new _src_core.CaptureError(fault, { code: "HOST" });
@@ -4570,7 +5017,7 @@ var CaptureRunner = class {
4570
5017
  async #run(invocation, command, parsed, projects) {
4571
5018
  const { root } = this.#options;
4572
5019
  const primary = requireCaptureProjects(projects);
4573
- const selectors = [...new Set(projects.flatMap((project) => project.tags))].filter((tag) => tag.startsWith(CAPTURE_OWNER_PREFIX)).map((tag) => tag.slice(CAPTURE_OWNER_PREFIX.length));
5020
+ const selectors = [...new Set(projects.flatMap((project) => project.tags))].filter((tag) => tag.startsWith(_src_core.CAPTURE_OWNER_PREFIX)).map((tag) => tag.slice(_src_core.CAPTURE_OWNER_PREFIX.length));
4574
5021
  const selector = parsed.selector;
4575
5022
  if (selector === void 0) throw new _src_core.CaptureError(this.#usage(selectors), { code: "USAGE" });
4576
5023
  const fault = describeCaptureSelectorFault(selector, selectors);
@@ -4591,7 +5038,8 @@ var CaptureRunner = class {
4591
5038
  final: primary.final,
4592
5039
  directory: resolveCaptureRelative(root, primary.directory),
4593
5040
  config: resolveCaptureRelative(root, parsed.config),
4594
- ...parsed.mode === void 0 ? {} : { mode: parsed.mode }
5041
+ ...parsed.mode === void 0 ? {} : { mode: parsed.mode },
5042
+ ...parsed.bail === void 0 ? {} : { bail: parsed.bail }
4595
5043
  };
4596
5044
  const outcomes = [];
4597
5045
  const stages = resolveCaptureStages(variants, primary.first, command);
@@ -4633,6 +5081,8 @@ var CaptureRunner = class {
4633
5081
  entry: (0, node_path.resolve)(root, CAPTURE_VITEST_ENTRY),
4634
5082
  config: (0, node_path.resolve)(root, plan.config),
4635
5083
  report,
5084
+ progress: (0, node_path.resolve)(invocation.directory, `${stage.name}${CAPTURE_PROGRESS_SUFFIX}`),
5085
+ ...plan.bail === void 0 ? {} : { bail: plan.bail },
4636
5086
  projects: selected.map((project) => project.name),
4637
5087
  filter: plan.filter,
4638
5088
  ...plan.mode === void 0 ? {} : { mode: plan.mode },
@@ -4916,9 +5366,10 @@ var CaptureSheets = class {
4916
5366
  *
4917
5367
  * @remarks
4918
5368
  * The executable's whole behaviour: it reads the subcommand, hands the rest of the command line to
4919
- * the runner, the registry refresh, the preflight, or the contact sheets, and turns a refused
4920
- * usage into exit 64 and any other capture refusal into exit 1, writing the refusal to its error
4921
- * writer. An error that is not a capture refusal propagates.
5369
+ * the runner, the registry refresh, the preflight, or the contact sheets, or prints the progress of
5370
+ * the stage that ran last, and turns a refused usage into exit 64 and any other capture refusal
5371
+ * into exit 1, writing the refusal to its error writer. An error that is not a capture refusal
5372
+ * propagates.
4922
5373
  *
4923
5374
  * @example
4924
5375
  * ```ts
@@ -4970,6 +5421,13 @@ var CaptureCLI = class {
4970
5421
  stdout: this.#stdout,
4971
5422
  stderr: this.#stderr
4972
5423
  }).execute();
5424
+ case "progress": {
5425
+ const usage = "Usage: capture progress";
5426
+ const { positionals } = readCaptureOptions(argv, CAPTURE_COMMAND_OPTIONS.progress, usage);
5427
+ if (positionals.length > 0) throw new _src_core.CaptureError(`Unexpected argument ${JSON.stringify(positionals[0]?.slice(0, 80))}: the progress command takes no argument. ${usage}`, { code: "USAGE" });
5428
+ this.#stdout(`${renderCaptureProgress(readCaptureProgress(root, CAPTURE_DEFAULTS.requests))}\n`);
5429
+ return CAPTURE_EXIT.passed;
5430
+ }
4973
5431
  case "preflight": {
4974
5432
  const { reader } = readCaptureReaderArguments(argv, root, CAPTURE_DEFAULTS, "preflight");
4975
5433
  return await new CapturePreflight({
@@ -5138,9 +5596,10 @@ exports.CAPTURE_MESSAGE_LIMIT = CAPTURE_MESSAGE_LIMIT;
5138
5596
  exports.CAPTURE_MINIMUM_IMAGE = CAPTURE_MINIMUM_IMAGE;
5139
5597
  exports.CAPTURE_OWNER_BACKOFF = CAPTURE_OWNER_BACKOFF;
5140
5598
  exports.CAPTURE_OWNER_FILE = CAPTURE_OWNER_FILE;
5141
- exports.CAPTURE_OWNER_PREFIX = CAPTURE_OWNER_PREFIX;
5142
5599
  exports.CAPTURE_OWNER_TIMEOUT = CAPTURE_OWNER_TIMEOUT;
5600
+ exports.CAPTURE_PID_LIMIT = CAPTURE_PID_LIMIT;
5143
5601
  exports.CAPTURE_PNG_LIMITS = CAPTURE_PNG_LIMITS;
5602
+ exports.CAPTURE_PROGRESS_SUFFIX = CAPTURE_PROGRESS_SUFFIX;
5144
5603
  exports.CAPTURE_REFUSAL_LIMIT = CAPTURE_REFUSAL_LIMIT;
5145
5604
  exports.CAPTURE_REGISTRY_LINE = CAPTURE_REGISTRY_LINE;
5146
5605
  exports.CAPTURE_REGISTRY_STAGE = CAPTURE_REGISTRY_STAGE;
@@ -5155,6 +5614,7 @@ exports.CAPTURE_SURVIVORS_FILE = CAPTURE_SURVIVORS_FILE;
5155
5614
  exports.CAPTURE_TAG_OPERATORS = CAPTURE_TAG_OPERATORS;
5156
5615
  exports.CAPTURE_USAGE = CAPTURE_USAGE;
5157
5616
  exports.CAPTURE_VITEST_ENTRY = CAPTURE_VITEST_ENTRY;
5617
+ exports.CAPTURE_WRAPPER_PREFIXES = CAPTURE_WRAPPER_PREFIXES;
5158
5618
  exports.CaptureCLI = CaptureCLI;
5159
5619
  exports.CaptureDiscovery = CaptureDiscovery;
5160
5620
  exports.CaptureIntegrity = CaptureIntegrity;
@@ -5171,12 +5631,15 @@ exports.buildCaptureDiscoveryConfig = buildCaptureDiscoveryConfig;
5171
5631
  exports.buildCaptureFilter = buildCaptureFilter;
5172
5632
  exports.buildCaptureIntegrityOptions = buildCaptureIntegrityOptions;
5173
5633
  exports.buildCaptureLookupJournal = buildCaptureLookupJournal;
5634
+ exports.buildCaptureOverride = buildCaptureOverride;
5174
5635
  exports.buildCaptureRegistry = buildCaptureRegistry;
5175
5636
  exports.buildCaptureRequestRefusal = buildCaptureRequestRefusal;
5637
+ exports.buildCaptureWrapper = buildCaptureWrapper;
5176
5638
  exports.collectCaptureErrors = collectCaptureErrors;
5177
5639
  exports.collectCaptureIdentical = collectCaptureIdentical;
5178
5640
  exports.composeCapturePictures = composeCapturePictures;
5179
5641
  exports.computeCaptureHash = computeCaptureHash;
5642
+ exports.computeCaptureMatchKey = computeCaptureMatchKey;
5180
5643
  exports.computeRegistryDigest = computeRegistryDigest;
5181
5644
  exports.createCaptureCLI = createCaptureCLI;
5182
5645
  exports.createCaptureDiscovery = createCaptureDiscovery;
@@ -5187,6 +5650,7 @@ exports.createCaptureRunner = createCaptureRunner;
5187
5650
  exports.createCaptureSheets = createCaptureSheets;
5188
5651
  exports.decodeCapturePicture = decodeCapturePicture;
5189
5652
  exports.describeCaptureFault = describeCaptureFault;
5653
+ exports.describeCaptureHolders = describeCaptureHolders;
5190
5654
  exports.describeCaptureMembers = describeCaptureMembers;
5191
5655
  exports.describeCaptureOutput = describeCaptureOutput;
5192
5656
  exports.describeCapturePortfolios = describeCapturePortfolios;
@@ -5195,6 +5659,7 @@ exports.encodeCaptureChunk = encodeCaptureChunk;
5195
5659
  exports.encodeCapturePicture = encodeCapturePicture;
5196
5660
  exports.encodeCaptureWord = encodeCaptureWord;
5197
5661
  exports.escapeCapturePattern = escapeCapturePattern;
5662
+ exports.filterCaptureInputs = filterCaptureInputs;
5198
5663
  exports.inflateCaptureStream = inflateCaptureStream;
5199
5664
  exports.matchesCaptureFile = matchesCaptureFile;
5200
5665
  exports.matchesCaptureSignature = matchesCaptureSignature;
@@ -5207,22 +5672,25 @@ exports.readCaptureArguments = readCaptureArguments;
5207
5672
  exports.readCaptureChunks = readCaptureChunks;
5208
5673
  exports.readCaptureDescription = readCaptureDescription;
5209
5674
  exports.readCaptureEntry = readCaptureEntry;
5675
+ exports.readCaptureFrames = readCaptureFrames;
5210
5676
  exports.readCaptureImage = readCaptureImage;
5211
5677
  exports.readCaptureInputs = readCaptureInputs;
5678
+ exports.readCaptureListing = readCaptureListing;
5212
5679
  exports.readCaptureLookups = readCaptureLookups;
5213
5680
  exports.readCaptureOptions = readCaptureOptions;
5214
5681
  exports.readCapturePortfolios = readCapturePortfolios;
5682
+ exports.readCaptureProgress = readCaptureProgress;
5215
5683
  exports.readCaptureProject = readCaptureProject;
5216
5684
  exports.readCaptureReaderArguments = readCaptureReaderArguments;
5217
5685
  exports.readCaptureRegistryArguments = readCaptureRegistryArguments;
5218
5686
  exports.readCaptureRequest = readCaptureRequest;
5219
5687
  exports.readCaptureRequestOwner = readCaptureRequestOwner;
5220
- exports.readCaptureRunning = readCaptureRunning;
5221
5688
  exports.readCaptureSeparator = readCaptureSeparator;
5222
5689
  exports.readCaptureTitles = readCaptureTitles;
5223
5690
  exports.readCaptureVariants = readCaptureVariants;
5224
5691
  exports.readCaptureViewport = readCaptureViewport;
5225
5692
  exports.renderCaptureCommand = renderCaptureCommand;
5693
+ exports.renderCaptureProgress = renderCaptureProgress;
5226
5694
  exports.requireCaptureArgument = requireCaptureArgument;
5227
5695
  exports.requireCaptureContained = requireCaptureContained;
5228
5696
  exports.requireCaptureImageSize = requireCaptureImageSize;