@orkestrel/capture 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,9 +15,9 @@ import type { CaptureStamp } from '@orkestrel/capture';
15
15
  import type { CaptureStoredManifest } from '@orkestrel/capture';
16
16
  import type { CaptureViewport } from '@orkestrel/capture';
17
17
  import type { CaptureWarning } from '@orkestrel/capture';
18
+ import type { DuplexInterface } from '@orkestrel/process';
18
19
  import type { parseArgs } from 'node:util';
19
20
  import type { ParseArgsOptionsConfig } from 'node:util';
20
- import type { SessionInterface } from '@orkestrel/process';
21
21
 
22
22
  /**
23
23
  * Answers the runner's discovery request from the wrapper, before the wrapper does any other work.
@@ -227,9 +227,9 @@ export declare function buildCaptureRequestRefusal(file: string, cause?: unknown
227
227
  * ```
228
228
  */
229
229
  export declare const CAPTURE_COMMAND_NAMES: Readonly<{
230
- readonly journey: "journey";
231
- readonly capture: "frames";
232
- readonly stale: "stale";
230
+ readonly journey: 'journey';
231
+ readonly capture: 'frames';
232
+ readonly stale: 'stale';
233
233
  }>;
234
234
 
235
235
  /**
@@ -380,9 +380,9 @@ export declare const CAPTURE_COMMAND_OPTIONS: Readonly<{
380
380
  * ```
381
381
  */
382
382
  export declare const CAPTURE_DEFAULTS: Readonly<{
383
- readonly config: "configs/app/vite.journey.config.ts";
384
- readonly requests: "tmp/capture";
385
- readonly journeys: "tmp/journey";
383
+ readonly config: 'configs/app/vite.journey.config.ts';
384
+ readonly requests: 'tmp/capture';
385
+ readonly journeys: 'tmp/journey';
386
386
  }>;
387
387
 
388
388
  /**
@@ -400,8 +400,8 @@ export declare const CAPTURE_DEFAULTS: Readonly<{
400
400
  * ```
401
401
  */
402
402
  export declare const CAPTURE_DISCOVERY: Readonly<{
403
- readonly phase: "discover";
404
- readonly description: "description.json";
403
+ readonly phase: 'discover';
404
+ readonly description: 'description.json';
405
405
  readonly arguments: readonly string[];
406
406
  readonly deadline: 60000;
407
407
  }>;
@@ -555,8 +555,8 @@ export declare const CAPTURE_REGISTRY_STAGE = "registry";
555
555
  * ```
556
556
  */
557
557
  export declare const CAPTURE_REPORT_LINES: Readonly<{
558
- readonly preflight: "READER";
559
- readonly sheets: "SHEETS";
558
+ readonly preflight: 'READER';
559
+ readonly sheets: 'SHEETS';
560
560
  }>;
561
561
 
562
562
  /**
@@ -616,10 +616,10 @@ export declare const CAPTURE_SHEET: Readonly<{
616
616
  * ```
617
617
  */
618
618
  export declare const CAPTURE_SHEET_FILES: Readonly<{
619
- readonly prefix: "sheet-";
619
+ readonly prefix: 'sheet-';
620
620
  readonly digits: 3;
621
- readonly index: "index.json";
622
- readonly notes: "index.md";
621
+ readonly index: 'index.json';
622
+ readonly notes: 'index.md';
623
623
  }>;
624
624
 
625
625
  /**
@@ -631,9 +631,9 @@ export declare const CAPTURE_SHEET_FILES: Readonly<{
631
631
  * ```
632
632
  */
633
633
  export declare const CAPTURE_STAGES: Readonly<{
634
- readonly selected: "selected";
635
- readonly first: "narrow";
636
- readonly rest: "rest";
634
+ readonly selected: 'selected';
635
+ readonly first: 'narrow';
636
+ readonly rest: 'rest';
637
637
  }>;
638
638
 
639
639
  /**
@@ -847,7 +847,7 @@ export declare interface CaptureCheckResult {
847
847
  * const terminate: CaptureChildTerminationHandler = (child) => child.stop()
848
848
  * ```
849
849
  */
850
- export declare type CaptureChildTerminationHandler = (child: SessionInterface) => Promise<boolean>;
850
+ export declare type CaptureChildTerminationHandler = (child: DuplexInterface) => Promise<boolean>;
851
851
 
852
852
  /**
853
853
  * Dispatches capture commands and maps usage and evidence refusals to their exit codes.
@@ -1840,15 +1840,15 @@ export declare interface CaptureOwnershipHost {
1840
1840
  */
1841
1841
  export declare type CaptureParsedArguments<Options extends ParseArgsOptionsConfig> = {
1842
1842
  readonly [Key in keyof ReturnType<typeof parseArgs<{
1843
- options: Options;
1844
- tokens: true;
1845
- strict: true;
1846
- allowPositionals: true;
1843
+ readonly options: Options;
1844
+ readonly tokens: true;
1845
+ readonly strict: true;
1846
+ readonly allowPositionals: true;
1847
1847
  }>>]: Readonly<ReturnType<typeof parseArgs<{
1848
- options: Options;
1849
- tokens: true;
1850
- strict: true;
1851
- allowPositionals: true;
1848
+ readonly options: Options;
1849
+ readonly tokens: true;
1850
+ readonly strict: true;
1851
+ readonly allowPositionals: true;
1852
1852
  }>>[Key]>;
1853
1853
  };
1854
1854
 
@@ -2286,6 +2286,8 @@ export declare interface CaptureReceiptInput {
2286
2286
  * place, so a registry the engine would refuse never replaces a good one. With `--variant`, the
2287
2287
  * existing registry's receipts for the other declared variants are kept. It never widens a scoped
2288
2288
  * run into a refresh and refuses while another runner holds a request file in the request directory.
2289
+ * Before any stage, it reads the inherited manifest and lookup journal and refuses an unsupported
2290
+ * schema with the file to inspect and repair.
2289
2291
  *
2290
2292
  * @example
2291
2293
  * ```ts
@@ -15,9 +15,9 @@ import type { CaptureStamp } from '@orkestrel/capture';
15
15
  import type { CaptureStoredManifest } from '@orkestrel/capture';
16
16
  import type { CaptureViewport } from '@orkestrel/capture';
17
17
  import type { CaptureWarning } from '@orkestrel/capture';
18
+ import type { DuplexInterface } from '@orkestrel/process';
18
19
  import type { parseArgs } from 'node:util';
19
20
  import type { ParseArgsOptionsConfig } from 'node:util';
20
- import type { SessionInterface } from '@orkestrel/process';
21
21
 
22
22
  /**
23
23
  * Answers the runner's discovery request from the wrapper, before the wrapper does any other work.
@@ -227,9 +227,9 @@ export declare function buildCaptureRequestRefusal(file: string, cause?: unknown
227
227
  * ```
228
228
  */
229
229
  export declare const CAPTURE_COMMAND_NAMES: Readonly<{
230
- readonly journey: "journey";
231
- readonly capture: "frames";
232
- readonly stale: "stale";
230
+ readonly journey: 'journey';
231
+ readonly capture: 'frames';
232
+ readonly stale: 'stale';
233
233
  }>;
234
234
 
235
235
  /**
@@ -380,9 +380,9 @@ export declare const CAPTURE_COMMAND_OPTIONS: Readonly<{
380
380
  * ```
381
381
  */
382
382
  export declare const CAPTURE_DEFAULTS: Readonly<{
383
- readonly config: "configs/app/vite.journey.config.ts";
384
- readonly requests: "tmp/capture";
385
- readonly journeys: "tmp/journey";
383
+ readonly config: 'configs/app/vite.journey.config.ts';
384
+ readonly requests: 'tmp/capture';
385
+ readonly journeys: 'tmp/journey';
386
386
  }>;
387
387
 
388
388
  /**
@@ -400,8 +400,8 @@ export declare const CAPTURE_DEFAULTS: Readonly<{
400
400
  * ```
401
401
  */
402
402
  export declare const CAPTURE_DISCOVERY: Readonly<{
403
- readonly phase: "discover";
404
- readonly description: "description.json";
403
+ readonly phase: 'discover';
404
+ readonly description: 'description.json';
405
405
  readonly arguments: readonly string[];
406
406
  readonly deadline: 60000;
407
407
  }>;
@@ -555,8 +555,8 @@ export declare const CAPTURE_REGISTRY_STAGE = "registry";
555
555
  * ```
556
556
  */
557
557
  export declare const CAPTURE_REPORT_LINES: Readonly<{
558
- readonly preflight: "READER";
559
- readonly sheets: "SHEETS";
558
+ readonly preflight: 'READER';
559
+ readonly sheets: 'SHEETS';
560
560
  }>;
561
561
 
562
562
  /**
@@ -616,10 +616,10 @@ export declare const CAPTURE_SHEET: Readonly<{
616
616
  * ```
617
617
  */
618
618
  export declare const CAPTURE_SHEET_FILES: Readonly<{
619
- readonly prefix: "sheet-";
619
+ readonly prefix: 'sheet-';
620
620
  readonly digits: 3;
621
- readonly index: "index.json";
622
- readonly notes: "index.md";
621
+ readonly index: 'index.json';
622
+ readonly notes: 'index.md';
623
623
  }>;
624
624
 
625
625
  /**
@@ -631,9 +631,9 @@ export declare const CAPTURE_SHEET_FILES: Readonly<{
631
631
  * ```
632
632
  */
633
633
  export declare const CAPTURE_STAGES: Readonly<{
634
- readonly selected: "selected";
635
- readonly first: "narrow";
636
- readonly rest: "rest";
634
+ readonly selected: 'selected';
635
+ readonly first: 'narrow';
636
+ readonly rest: 'rest';
637
637
  }>;
638
638
 
639
639
  /**
@@ -847,7 +847,7 @@ export declare interface CaptureCheckResult {
847
847
  * const terminate: CaptureChildTerminationHandler = (child) => child.stop()
848
848
  * ```
849
849
  */
850
- export declare type CaptureChildTerminationHandler = (child: SessionInterface) => Promise<boolean>;
850
+ export declare type CaptureChildTerminationHandler = (child: DuplexInterface) => Promise<boolean>;
851
851
 
852
852
  /**
853
853
  * Dispatches capture commands and maps usage and evidence refusals to their exit codes.
@@ -1840,15 +1840,15 @@ export declare interface CaptureOwnershipHost {
1840
1840
  */
1841
1841
  export declare type CaptureParsedArguments<Options extends ParseArgsOptionsConfig> = {
1842
1842
  readonly [Key in keyof ReturnType<typeof parseArgs<{
1843
- options: Options;
1844
- tokens: true;
1845
- strict: true;
1846
- allowPositionals: true;
1843
+ readonly options: Options;
1844
+ readonly tokens: true;
1845
+ readonly strict: true;
1846
+ readonly allowPositionals: true;
1847
1847
  }>>]: Readonly<ReturnType<typeof parseArgs<{
1848
- options: Options;
1849
- tokens: true;
1850
- strict: true;
1851
- allowPositionals: true;
1848
+ readonly options: Options;
1849
+ readonly tokens: true;
1850
+ readonly strict: true;
1851
+ readonly allowPositionals: true;
1852
1852
  }>>[Key]>;
1853
1853
  };
1854
1854
 
@@ -2286,6 +2286,8 @@ export declare interface CaptureReceiptInput {
2286
2286
  * place, so a registry the engine would refuse never replaces a good one. With `--variant`, the
2287
2287
  * existing registry's receipts for the other declared variants are kept. It never widens a scoped
2288
2288
  * run into a refresh and refuses while another runner holds a request file in the request directory.
2289
+ * Before any stage, it reads the inherited manifest and lookup journal and refuses an unsupported
2290
+ * schema with the file to inspect and repair.
2289
2291
  *
2290
2292
  * @example
2291
2293
  * ```ts
@@ -6,7 +6,7 @@ import { crc32, deflateSync, inflateSync } from "node:zlib";
6
6
  import { arrayOf, attempt, isArray, isError, isFunction, isRecord, isString, parseJSON, preview } from "@orkestrel/contract";
7
7
  import { CAPTURE_LOOKUPS_FILE, CAPTURE_MANIFEST_FILE, CAPTURE_PNG_SIGNATURE, CAPTURE_REGISTRY_FILE, CAPTURE_REQUEST_PREFIX, CAPTURE_VERSION, CaptureError, collectCaptureChanges, collectCaptureDuplicates, describeCaptureDeclaration, describeCaptureDestination, describeCaptureError, describeCaptureIdentity, describeCaptureRequest, isCaptureError, isCaptureGeometry, isCaptureLookupJournal, isCapturePath, isCapturePattern, isCaptureReceipt, isCaptureRegistry, isCaptureRequest, isCaptureRun, isCaptureSegment, isCaptureSelector, isCaptureStoredManifest, matchesCaptureMembers, matchesCaptureSelector, readCaptureDirty, readCaptureReport, requireCaptureUnique, resolveCaptureKey, resolveCaptureOwner, resolveCaptureStatus, resolveLookupKey, validateCaptureReceipt, validateCaptureRun } from "../core/index.js";
8
8
  import { pathToFileURL } from "node:url";
9
- import { createSession, executeSync } from "@orkestrel/process/server";
9
+ import { createDuplex, executeSync } from "@orkestrel/process/server";
10
10
  import { StringDecoder } from "node:string_decoder";
11
11
  import { createTimeout } from "@orkestrel/timeout";
12
12
  // src/server/constants.ts
@@ -1130,39 +1130,23 @@ function encodeCapturePicture(picture, compressed = true) {
1130
1130
  function shrinkCapturePicture(picture, factor, limit) {
1131
1131
  const width = Math.max(1, Math.ceil(picture.width / factor));
1132
1132
  const height = Math.min(Math.max(1, Math.ceil(picture.height / factor)), limit);
1133
- const pixels = new Uint8Array(width * height * 3);
1134
- const sums = new Float64Array(width * 3);
1135
- for (let y = 0; y < height; y += 1) {
1136
- sums.fill(0);
1137
- const rows = Math.min(factor, picture.height - y * factor);
1138
- for (let row = 0; row < rows; row += 1) {
1139
- let source = (y * factor + row) * picture.width * 3;
1140
- for (let x = 0; x < width; x += 1) {
1141
- const columns = Math.min(factor, picture.width - x * factor);
1142
- let red = 0;
1143
- let green = 0;
1144
- let blue = 0;
1145
- for (let column = 0; column < columns; column += 1) {
1146
- red += picture.pixels[source] ?? 0;
1147
- green += picture.pixels[source + 1] ?? 0;
1148
- blue += picture.pixels[source + 2] ?? 0;
1149
- source += 3;
1150
- }
1151
- const target = x * 3;
1152
- sums[target] = (sums[target] ?? 0) + red;
1153
- sums[target + 1] = (sums[target + 1] ?? 0) + green;
1154
- sums[target + 2] = (sums[target + 2] ?? 0) + blue;
1155
- }
1156
- }
1157
- for (let x = 0; x < width; x += 1) {
1158
- const count = rows * Math.min(factor, picture.width - x * factor);
1159
- for (let channel = 0; channel < 3; channel += 1) pixels[(y * width + x) * 3 + channel] = Math.round((sums[x * 3 + channel] ?? 0) / count);
1160
- }
1161
- }
1133
+ const span = Array.from({ length: Math.ceil(Math.min(factor, Math.max(picture.width, picture.height))) }, (_, index) => index);
1162
1134
  return {
1163
1135
  width,
1164
1136
  height,
1165
- pixels
1137
+ pixels: Uint8Array.from({ length: width * height * 3 }, (_, index) => {
1138
+ const channel = index % 3;
1139
+ const x = Math.floor(index / 3) % width;
1140
+ const y = Math.floor(index / 3 / width);
1141
+ const rows = Math.min(factor, picture.height - y * factor);
1142
+ const columns = Math.min(factor, picture.width - x * factor);
1143
+ const sum = span.reduce((total, row) => {
1144
+ if (row >= rows) return total;
1145
+ const start = (y * factor + row) * picture.width * 3 + x * Math.ceil(factor) * 3 + channel;
1146
+ return span.reduce((block, column) => column >= columns ? block : block + (picture.pixels[start + column * 3] ?? 0), total);
1147
+ }, 0);
1148
+ return Math.round(sum / (rows * columns));
1149
+ })
1166
1150
  };
1167
1151
  }
1168
1152
  /**
@@ -3478,7 +3462,7 @@ var CaptureInvocation = class {
3478
3462
  mkdirSync(this.#directory, { recursive: true });
3479
3463
  writeFileSync(log, "");
3480
3464
  const environment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toLowerCase() !== "CAPTURE".toLowerCase() && name.toLowerCase() !== "CAPTURE_REQUESTS".toLowerCase()));
3481
- const session = createSession({
3465
+ const session = createDuplex({
3482
3466
  command: {
3483
3467
  file: process.execPath,
3484
3468
  arguments: args,
@@ -4084,6 +4068,8 @@ var CapturePreflight = class {
4084
4068
  * place, so a registry the engine would refuse never replaces a good one. With `--variant`, the
4085
4069
  * existing registry's receipts for the other declared variants are kept. It never widens a scoped
4086
4070
  * run into a refresh and refuses while another runner holds a request file in the request directory.
4071
+ * Before any stage, it reads the inherited manifest and lookup journal and refuses an unsupported
4072
+ * schema with the file to inspect and repair.
4087
4073
  *
4088
4074
  * @example
4089
4075
  * ```ts
@@ -4157,10 +4143,12 @@ var CaptureRegistrar = class {
4157
4143
  });
4158
4144
  const target = `${resolveCaptureRelative(root, primary.directory)}/${CAPTURE_REGISTRY_FILE}`;
4159
4145
  const candidate = `${target}.${invocation.id}.candidate`;
4146
+ const options = buildCaptureIntegrityOptions(root, primary);
4160
4147
  const integrity = new CaptureIntegrity({
4161
- ...buildCaptureIntegrityOptions(root, primary),
4148
+ ...options,
4162
4149
  registry: candidate
4163
4150
  });
4151
+ this.#inherit(options);
4164
4152
  const holders = invocation.holders();
4165
4153
  if (holders.length > 0) throw new CaptureError(`Another runner holds this workspace (process ${holders.join(", ")}); the registry refresh starts only while no runner is mid-stage`, {
4166
4154
  code: "STAGE",
@@ -4196,6 +4184,22 @@ var CaptureRegistrar = class {
4196
4184
  })}\n`);
4197
4185
  return CAPTURE_EXIT.passed;
4198
4186
  }
4187
+ #inherit(options) {
4188
+ for (const [file, guard] of [[options.manifest, isCaptureStoredManifest], [options.lookups, isCaptureLookupJournal]]) {
4189
+ const path = resolve(options.root, file);
4190
+ try {
4191
+ requireCaptureContained(options.root, path);
4192
+ if (!existsSync(path)) continue;
4193
+ if (!guard(parseJSON(readFileSync(path, "utf8")))) throw new CaptureError("Invalid inherited evidence schema", { code: "EVIDENCE" });
4194
+ } catch (error) {
4195
+ throw new CaptureError(`Cannot refresh the registry with inherited evidence at ${JSON.stringify(file)}: ${describeCaptureError(error)}; inspect and repair this file before retrying`, {
4196
+ code: "EVIDENCE",
4197
+ cause: error,
4198
+ context: { file }
4199
+ });
4200
+ }
4201
+ }
4202
+ }
4199
4203
  async #stage(invocation, parsed, projects, primary, variant) {
4200
4204
  const { root } = this.#options;
4201
4205
  const project = projects.find((candidate) => candidate.variant === variant);