@orkestrel/capture 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Orkestrel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,263 @@
1
- # Temporary Holding Version
1
+ # @orkestrel/capture
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > An evidence protocol, integrity engine, and runner that stamp browser journey frames with their source provenance and classify each frame's freshness.
4
+
5
+ Run owner-selected browser journeys, capture their frames, and check whether the images still match
6
+ the sources and passing records that produced them. The host supplies its owners, variants,
7
+ portfolios, and paths through a Vitest journey wrapper. Part of the `@orkestrel` line.
8
+
9
+ ## Install
10
+
11
+ Add the package to your development dependencies:
12
+
13
+ ```sh
14
+ npm install -D @orkestrel/capture
15
+ ```
16
+
17
+ The manifest declares these peer ranges; install the browser peers when you run browser journeys:
18
+
19
+ | Peer | Range | Required by the manifest |
20
+ | ---------------------------- | --------------------- | ------------------------ |
21
+ | `vitest` | `^4.1.12 \|\| ^5.0.5` | Yes |
22
+ | `vite` | `^8.3.5` | Yes |
23
+ | `@vitest/browser-playwright` | `^4.1.12 \|\| ^5.0.5` | Optional |
24
+ | `playwright` | `^1.61.0` | Optional |
25
+
26
+ ## Requirements
27
+
28
+ The CLI workflow requires the following host setup:
29
+
30
+ - Node.js >= 22.18.0.
31
+ - A Git workspace with a commit and locally installed Vitest.
32
+ - A Vitest browser provider and its browser runtime for execution stages. The integration proof uses
33
+ `@vitest/browser-playwright` and Chromium.
34
+ - An adopted journey wrapper that answers discovery, reads selection requests, and writes the
35
+ declared final records and journey artifacts. Installing capture alone does not add this protocol
36
+ to an existing test suite.
37
+
38
+ ## Quick start
39
+
40
+ From an adopted workspace, run this sequence. The fictional `pages:mail` owner must be replaced
41
+ with an owner your wrapper declares. The default wrapper is `configs/app/vite.journey.config.ts`;
42
+ add `--config <file>` to each command if yours lives elsewhere. The `tmp/sheets` destination must
43
+ not exist, and its parent must exist.
44
+
45
+ ```sh
46
+ npx capture registry
47
+ npx capture journey pages:mail
48
+ npx capture frames pages:mail
49
+ npx capture stale pages:mail
50
+ npx capture preflight pages:mail
51
+ npx capture sheets pages:mail --output tmp/sheets
52
+ ```
53
+
54
+ The registry command bootstraps the accepted complete-run registry without capturing images.
55
+ The scoped journey publishes passing lookup evidence. The frames command captures the selected
56
+ owners, running the host's `first` variant in the `narrow` stage and the remaining selected variants
57
+ in the `rest` stage. Stale checks provenance; preflight also judges images, artifact coverage,
58
+ logged errors, and optional host checks. Sheets applies the same judgment and writes indexed PNG
59
+ contact sheets. Preflight and sheets report `acceptance: false`; they provide iteration evidence.
60
+
61
+ ## Commands
62
+
63
+ Every command accepts `--config <file>`. The principal selection and output flags are as follows:
64
+
65
+ | Command | Flags and behavior |
66
+ | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
67
+ | `capture registry` | `--variant <name>` repeats to refresh selected producing variants; `--mode <name>` selects the wrapper's mode. Takes no selector. |
68
+ | `capture journey <selector>` | `--variant <name>` repeats; `--case <full name>` selects an exact case. Use `--changed <ref>` instead of the selector, with optional `--plan`. |
69
+ | `capture frames <selector>` | Journey flags plus `--state <name>` to resolve a state through fresh passing lookup evidence. |
70
+ | `capture stale <selector>` | `--variant <name>` repeats; `--case <full name>`, `--state <name>`, and `--portfolio <name>` narrow the freshness reading. |
71
+ | `capture preflight <selector>` | Stale flags plus `--journeys <directory>` for artifacts and `--checks <module>` for the host's `CAPTURE_CHECKS` export. |
72
+ | `capture sheets <selector> --output <directory>` | Preflight flags plus required `--output <directory>` for a new contained directory outside the selected capture directories. |
73
+
74
+ A selector is `all` or a declared colon-separated owner path. Only `--variant` repeats. Every
75
+ flag except `--plan` takes a nonempty value as `--flag value` or `--flag=value`; a value beginning
76
+ with a dash needs equals form. The CLI refuses the `--` terminator and repeated single-value flags.
77
+
78
+ Registry refresh checks inherited manifest and lookup journal schemas before starting a stage.
79
+ An unreadable or unsupported document refuses the refresh and names the file to inspect and repair.
80
+
81
+ For changed selection, `HEAD` includes uncommitted work. The plan prints changed paths and commands
82
+ after discovery and starts no execution child. Shared inputs refuse narrowing and print an explicit
83
+ complete journey command. Without `--plan`, owners run in stable order until an owner fails.
84
+
85
+ The CLI uses this exit contract:
86
+
87
+ | Exit | Meaning |
88
+ | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
89
+ | `0` | Successful work, current sound evidence, or a valid changed-selection plan, including an empty plan. |
90
+ | `1` | Every failure other than usage: failed or interrupted stages, empty execution workloads, Git, wrapper, or plan-derived owner failures, ownership refusals, stale or unsound evidence, and containment failures. |
91
+ | `64` | Refused usage, including unknown or empty selectors, unknown variants, states, cases, and portfolios, outside path arguments, invalid flags, and changed selections that require an explicit shared-input journey. |
92
+
93
+ A held ownership marker refuses before argument values are judged. A supplied `--config`,
94
+ `--journeys`, `--checks`, or `--output` path that resolves outside the repository is usage (64).
95
+ Containment caught on a resolved target at write time remains a failure (1).
96
+
97
+ Selectors are checked against the wrapper before registry authentication. A runner reports a release
98
+ failure without replacing its already decided exit.
99
+
100
+ ## Host integration
101
+
102
+ Before output initialization or collection, your wrapper calls `answerCaptureDiscovery` with its
103
+ parent PID, process arguments, wrapper path, and project declarations. When the hook answers,
104
+ return `buildCaptureDiscoveryConfig()` so discovery starts no browser or test. For an execution
105
+ child, read `readCaptureRequest` with the same parent, arguments, and wrapper identity plus the
106
+ declared owners and variants. The runner passes the request directory through `CAPTURE_REQUESTS`.
107
+
108
+ Each project's `test.provide` object supplies the following host declarations:
109
+
110
+ | Declaration | Meaning |
111
+ | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
112
+ | `variant`, `variants` | The producing variant and the ordered variant declarations. Readers require each variant's `name`, `width`, and `height`. |
113
+ | `first` | The producing variant to run alone before the other selected frame variants. |
114
+ | `final` | The exact final case name that persists the run record, including under exact-case selection. |
115
+ | `directory`, `record` | The primary evidence directory and the project's declared record path. Stage records bind the request's invocation, stage, and variant. |
116
+ | `inputs` | Bounded native glob patterns for the input snapshot. |
117
+ | `portfolios` | Authorized portfolio roots with their `portfolio`, `directory`, and `scoped` declarations. |
118
+ | `uniform` | Optional owner selectors for mixed-framing checks. Omission checks every scope; an empty list checks none. |
119
+ | `standalone` | Optional portfolio roots with no stamping route through this wrapper. |
120
+
121
+ Declare `owner:` tags for owners and their ancestors, and capture tags for the scopes and parts
122
+ that produce frames. Projects must agree on shared host declarations. The final case must retain
123
+ collected declarations, passing cases, observed states, emitted destinations, and the authenticated
124
+ journey artifact. For the protocol shapes and wrapper examples, see the
125
+ [Capture guide](https://github.com/orkestrel/capture/blob/main/guides/capture.md).
126
+
127
+ ## Evidence
128
+
129
+ The host's evidence directory separates these documents:
130
+
131
+ - `registry.json` pins complete capture-free runs, authenticated reporter bytes, input hashes,
132
+ declarations, and required output pairs.
133
+ - `lookups.json` stores passing state-to-case lookups and collection receipts without upgrading
134
+ historical image stamps. Its optional predecessor manifest digest determines whether it applies.
135
+ - `manifest.json` binds image stamps to their execution identity, registry, source hashes, and
136
+ image bytes. Failed or interrupted stages publish no evidence from that stage.
137
+
138
+ Freshness readings retain every reason and select a primary class in this precedence order:
139
+ `duplicate`, `orphan`, `missing`, `unstamped`, `stale-shared`, `stale-own`, then `current` when no
140
+ finding applies. A passing capture-free journey does not make an older image current.
141
+
142
+ Serialize capture commands and the host's Vitest work per workspace. Preparation creates the
143
+ request directory and checks that it is a directory. An invocation writes `{pid,id}` once to
144
+ a unique `.capture-owner.<pid>.<id>.tmp` file with flag `wx`, then claims `.capture-owner`
145
+ with `linkSync`. The marker stays byte-identical from that link until its own invocation
146
+ unlinks it after confirmed child termination. It stays held between stages. The temporary
147
+ is always removed after the claim attempt. A dead pid's leftover claim temporary is swept
148
+ best effort; sweep errors are ignored, and a live pid's temporary is never touched.
149
+ The marker does not coordinate another request directory or unrelated Vitest processes.
150
+
151
+ A held marker is parsed as `{pid,id}`, ignoring extra members. EPERM from the pid probe
152
+ counts as alive. After the liveness probe the claim re-reads the marker; a vanished or
153
+ changed marker retries. Deletion advice for a dead holder requires identical content on
154
+ that re-read. A live-holder refusal makes any deletion conditional on confirming that no
155
+ capture process or surviving child is running. Empty or malformed markers require
156
+ identical reads separated by backoff and ask for inspection. A permanent read error
157
+ refuses as unreadable without deletion advice.
158
+
159
+ Marker reads, links, and removals retry only `EBUSY` and `EMFILE` on POSIX, and those
160
+ codes plus `EPERM` and `EACCES` on Windows, with synchronous 10 ms backoff within
161
+ 1,000 ms. On POSIX, a link failure with `EPERM`, `ENOTSUP`, `EOPNOTSUPP`, `ENOSYS`,
162
+ or `EXDEV` refuses immediately with the hard-link requirement. Exhaustion names the
163
+ error code and gives no deletion advice. Other temporary-write or link errors refuse
164
+ permanently and name the operation and code.
165
+
166
+ Release awaits signal-driven termination, retracts its request, and stops every child.
167
+ It reads its marker and checks its invocation id before acting; an absent or foreign
168
+ marker is left alone. Unconfirmed termination keeps the marker byte-identical and the
169
+ lease held. Release writes `runs/<id>/survivors.json` with flag `wx`, treats `EEXIST`
170
+ as already recorded, and on `ENOENT` creates the run directory and retries once.
171
+ Other write errors join the shutdown failure. The record contains the owner pid, run id,
172
+ command, every unconfirmed child pid, and the ISO timestamp of the attempt:
173
+
174
+ ```text
175
+ {"pid":1234,"id":"RUN_ID","command":"journey","children":[5678],"at":"2026-10-28T00:00:00.000Z"}
176
+ ```
177
+
178
+ Release throws STAGE, naming the unconfirmed pids, marker, and record. A later release
179
+ in the same process retries the stop. After termination is confirmed, release removes
180
+ only its own marker, re-reading and checking its id on every removal retry. A successful
181
+ release leaves no claim temporary or marker from that invocation. An exhausted or
182
+ permanent removal failure retains the marker and joins the shutdown failure.
183
+
184
+ A dead-holder refusal reads `runs/<holder id>/survivors.json` once, without retry.
185
+ A well-formed record names its pids and path. ENOENT reports absence; other errors report
186
+ the code, and malformed content reports EINVAL. The record is advisory; the marker
187
+ provides ownership exclusion. A recorded pid is unconfirmed, not a claim that it is alive.
188
+ Stop any recorded children and confirm the marker's content before deleting it.
189
+
190
+ The following messages use `PID`, `RUN_ID`, `PIDS`, `MARKER`, `RECORD`,
191
+ `TEMPORARY`, `DIRECTORY`, `CONTENT`, and `CODE` as placeholders for the actual values. `RECORD_STATUS`
192
+ is one of the record messages that follows the dead-owner refusal.
193
+
194
+ ```text
195
+ Capture ownership process PID is not running; invocation "RUN_ID". RECORD_STATUS Confirm no capture process or surviving child is running and re-read MARKER to confirm it still names pid PID before you delete this file and rerun
196
+ Unconfirmed child processes: PIDS; stop them before deleting. Child record: RECORD.
197
+ No child record exists at RECORD.
198
+ Child record could not be read (CODE): RECORD.
199
+ Another runner holds this workspace (process PID); invocation "RUN_ID"; serialize capture commands. If this pid is not a capture run, confirm no capture process or surviving child is running and re-read MARKER to confirm it still names pid PID before deleting
200
+ Capture shutdown failed; child termination was not confirmed for process PIDS; ownership marker retained: MARKER; child record: RECORD
201
+ Cannot write capture child record (CODE): RECORD
202
+ Cannot write capture ownership temporary (CODE): TEMPORARY
203
+ Cannot link capture ownership (CODE): MARKER; the store directory must support hard links
204
+ Cannot link capture ownership (CODE): MARKER; inspect the filesystem error and rerun
205
+ Capture ownership marker is temporarily unavailable (CODE): MARKER; rerun after serializing capture commands
206
+ Capture ownership marker is unreadable: MARKER; rerun after inspecting the filesystem error
207
+ Capture request directory is unavailable: DIRECTORY
208
+ Capture ownership marker is empty; confirm no capture process or surviving child is running and inspect this file: MARKER; its holder cannot be established
209
+ Capture ownership marker is malformed; expected { pid: positive integer, id: nonempty string }, received CONTENT; confirm no capture process or surviving child is running and inspect this file: MARKER
210
+ Capture shutdown failed
211
+ ```
212
+
213
+ Every USAGE refusal (exit 64) removes its invocation's run directory and leaves no marker.
214
+ An exit-1 failure after discovery keeps its run directory and logs.
215
+
216
+ PNG decoding is capped at 20,971,520 pixels, about 19.5% over the largest measured fleet frame,
217
+ 1170 × 15000; 2880 × 6000 also fits. Each side is capped at 131,072 pixels. The file allowance is
218
+ 100,820,583 bytes: the maximum RGBA scanlines plus a 20% encoding margin, checked before reading
219
+ or joining compressed chunks. Preflight judges full frames one at a time and retains dimensions
220
+ and sheet thumbnails. Isolated Node runs on Windows on 2026-10-28 peaked at 276–333 MiB process
221
+ RSS for those fleet frames, 438 MiB for stored-deflate RGBA at the pixel boundary, and 456 MiB for
222
+ 131072 × 160. Thumbnails use an exact box area average over typed arrays. Every pixel in each
223
+ displayed block contributes once; partial edge blocks divide by their actual pixel count. The
224
+ accumulators hold one output row, and thumbnails clip at 400 pixels tall.
225
+
226
+ ## Package
227
+
228
+ The typed ESM and CommonJS entry points expose the following APIs:
229
+
230
+ - `@orkestrel/capture` supplies protocol types, constants, guards, pure comparison helpers, and
231
+ `CaptureError` with its `isCaptureError` guard.
232
+ - `@orkestrel/capture/server` supplies `CaptureIntegrity`, `CaptureRunner`, `CaptureInvocation`,
233
+ `CaptureDiscovery`, `CapturePreflight`, `CaptureSheets`, and `CaptureRegistrar`, their factories
234
+ where provided, the `CaptureCLI` dispatcher and `createCaptureCLI` factory, and host integration
235
+ helpers such as `answerCaptureDiscovery` and `readCaptureRequest`.
236
+
237
+ For every export, method, and behavioral limit, see the
238
+ [Capture guide](https://github.com/orkestrel/capture/blob/main/guides/capture.md).
239
+
240
+ ## Development
241
+
242
+ Install the development dependencies, build the executable, and run the package and consumer proofs:
243
+
244
+ ```sh
245
+ npm install
246
+ npm run build
247
+ npm test
248
+ ```
249
+
250
+ The integration proof at `tests/integration.test.ts` runs the built executable through real Vitest
251
+ and Chromium as part of `npm test` or with `npm run test:integration`. It requires `npm run build`,
252
+ the installed `@vitest/browser-playwright` browser provider, and the Chromium runtime.
253
+
254
+ For read-only documentation and formatting checks, run the following commands:
255
+
256
+ ```sh
257
+ npm run test:guides
258
+ npm run format:check
259
+ ```
260
+
261
+ ## License
262
+
263
+ MIT © [Orkestrel](https://github.com/orkestrel) — see [LICENSE](./LICENSE).
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { createCaptureCLI } from "../src/server/index.js";
3
+ // src/bin/main.ts
4
+ process.exitCode = await createCaptureCLI().execute(process.argv.slice(2));
5
+
6
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","names":[],"sources":["../../src/bin/main.ts"],"sourcesContent":["import { createCaptureCLI } from '@src/server'\n\nprocess.exitCode = await createCaptureCLI().execute(process.argv.slice(2))\n"],"mappings":";;;AAEA,QAAQ,WAAW,MAAM,iBAAiB,CAAC,CAAC,QAAQ,QAAQ,KAAK,MAAM,CAAC,CAAC"}