@orkestrel/capture 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,260 @@
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
+ For changed selection, `HEAD` includes uncommitted work. The plan prints changed paths and commands
79
+ after discovery and starts no execution child. Shared inputs refuse narrowing and print an explicit
80
+ complete journey command. Without `--plan`, owners run in stable order until an owner fails.
81
+
82
+ The CLI uses this exit contract:
83
+
84
+ | Exit | Meaning |
85
+ | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
86
+ | `0` | Successful work, current sound evidence, or a valid changed-selection plan, including an empty plan. |
87
+ | `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. |
88
+ | `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. |
89
+
90
+ A held ownership marker refuses before argument values are judged. A supplied `--config`,
91
+ `--journeys`, `--checks`, or `--output` path that resolves outside the repository is usage (64).
92
+ Containment caught on a resolved target at write time remains a failure (1).
93
+
94
+ Selectors are checked against the wrapper before registry authentication. A runner reports a release
95
+ failure without replacing its already decided exit.
96
+
97
+ ## Host integration
98
+
99
+ Before output initialization or collection, your wrapper calls `answerCaptureDiscovery` with its
100
+ parent PID, process arguments, wrapper path, and project declarations. When the hook answers,
101
+ return `buildCaptureDiscoveryConfig()` so discovery starts no browser or test. For an execution
102
+ child, read `readCaptureRequest` with the same parent, arguments, and wrapper identity plus the
103
+ declared owners and variants. The runner passes the request directory through `CAPTURE_REQUESTS`.
104
+
105
+ Each project's `test.provide` object supplies the following host declarations:
106
+
107
+ | Declaration | Meaning |
108
+ | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
109
+ | `variant`, `variants` | The producing variant and the ordered variant declarations. Readers require each variant's `name`, `width`, and `height`. |
110
+ | `first` | The producing variant to run alone before the other selected frame variants. |
111
+ | `final` | The exact final case name that persists the run record, including under exact-case selection. |
112
+ | `directory`, `record` | The primary evidence directory and the project's declared record path. Stage records bind the request's invocation, stage, and variant. |
113
+ | `inputs` | Bounded native glob patterns for the input snapshot. |
114
+ | `portfolios` | Authorized portfolio roots with their `portfolio`, `directory`, and `scoped` declarations. |
115
+ | `uniform` | Optional owner selectors for mixed-framing checks. Omission checks every scope; an empty list checks none. |
116
+ | `standalone` | Optional portfolio roots with no stamping route through this wrapper. |
117
+
118
+ Declare `owner:` tags for owners and their ancestors, and capture tags for the scopes and parts
119
+ that produce frames. Projects must agree on shared host declarations. The final case must retain
120
+ collected declarations, passing cases, observed states, emitted destinations, and the authenticated
121
+ journey artifact. For the protocol shapes and wrapper examples, see the
122
+ [Capture guide](https://github.com/orkestrel/capture/blob/main/guides/capture.md).
123
+
124
+ ## Evidence
125
+
126
+ The host's evidence directory separates these documents:
127
+
128
+ - `registry.json` pins complete capture-free runs, authenticated reporter bytes, input hashes,
129
+ declarations, and required output pairs.
130
+ - `lookups.json` stores passing state-to-case lookups and collection receipts without upgrading
131
+ historical image stamps. Its optional predecessor manifest digest determines whether it applies.
132
+ - `manifest.json` binds image stamps to their execution identity, registry, source hashes, and
133
+ image bytes. Failed or interrupted stages publish no evidence from that stage.
134
+
135
+ Freshness readings retain every reason and select a primary class in this precedence order:
136
+ `duplicate`, `orphan`, `missing`, `unstamped`, `stale-shared`, `stale-own`, then `current` when no
137
+ finding applies. A passing capture-free journey does not make an older image current.
138
+
139
+ Serialize capture commands and the host's Vitest work per workspace. Preparation creates the
140
+ request directory and checks that it is a directory. An invocation writes `{pid,id}` once to
141
+ a unique `.capture-owner.<pid>.<id>.tmp` file with flag `wx`, then claims `.capture-owner`
142
+ with `linkSync`. The marker stays byte-identical from that link until its own invocation
143
+ unlinks it after confirmed child termination. It stays held between stages. The temporary
144
+ is always removed after the claim attempt. A dead pid's leftover claim temporary is swept
145
+ best effort; sweep errors are ignored, and a live pid's temporary is never touched.
146
+ The marker does not coordinate another request directory or unrelated Vitest processes.
147
+
148
+ A held marker is parsed as `{pid,id}`, ignoring extra members. EPERM from the pid probe
149
+ counts as alive. After the liveness probe the claim re-reads the marker; a vanished or
150
+ changed marker retries. Deletion advice for a dead holder requires identical content on
151
+ that re-read. A live-holder refusal makes any deletion conditional on confirming that no
152
+ capture process or surviving child is running. Empty or malformed markers require
153
+ identical reads separated by backoff and ask for inspection. A permanent read error
154
+ refuses as unreadable without deletion advice.
155
+
156
+ Marker reads, links, and removals retry only `EBUSY` and `EMFILE` on POSIX, and those
157
+ codes plus `EPERM` and `EACCES` on Windows, with synchronous 10 ms backoff within
158
+ 1,000 ms. On POSIX, a link failure with `EPERM`, `ENOTSUP`, `EOPNOTSUPP`, `ENOSYS`,
159
+ or `EXDEV` refuses immediately with the hard-link requirement. Exhaustion names the
160
+ error code and gives no deletion advice. Other temporary-write or link errors refuse
161
+ permanently and name the operation and code.
162
+
163
+ Release awaits signal-driven termination, retracts its request, and stops every child.
164
+ It reads its marker and checks its invocation id before acting; an absent or foreign
165
+ marker is left alone. Unconfirmed termination keeps the marker byte-identical and the
166
+ lease held. Release writes `runs/<id>/survivors.json` with flag `wx`, treats `EEXIST`
167
+ as already recorded, and on `ENOENT` creates the run directory and retries once.
168
+ Other write errors join the shutdown failure. The record contains the owner pid, run id,
169
+ command, every unconfirmed child pid, and the ISO timestamp of the attempt:
170
+
171
+ ```text
172
+ {"pid":1234,"id":"RUN_ID","command":"journey","children":[5678],"at":"2026-10-28T00:00:00.000Z"}
173
+ ```
174
+
175
+ Release throws STAGE, naming the unconfirmed pids, marker, and record. A later release
176
+ in the same process retries the stop. After termination is confirmed, release removes
177
+ only its own marker, re-reading and checking its id on every removal retry. A successful
178
+ release leaves no claim temporary or marker from that invocation. An exhausted or
179
+ permanent removal failure retains the marker and joins the shutdown failure.
180
+
181
+ A dead-holder refusal reads `runs/<holder id>/survivors.json` once, without retry.
182
+ A well-formed record names its pids and path. ENOENT reports absence; other errors report
183
+ the code, and malformed content reports EINVAL. The record is advisory; the marker
184
+ provides ownership exclusion. A recorded pid is unconfirmed, not a claim that it is alive.
185
+ Stop any recorded children and confirm the marker's content before deleting it.
186
+
187
+ The following messages use `PID`, `RUN_ID`, `PIDS`, `MARKER`, `RECORD`,
188
+ `TEMPORARY`, `DIRECTORY`, `CONTENT`, and `CODE` as placeholders for the actual values. `RECORD_STATUS`
189
+ is one of the record messages that follows the dead-owner refusal.
190
+
191
+ ```text
192
+ 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
193
+ Unconfirmed child processes: PIDS; stop them before deleting. Child record: RECORD.
194
+ No child record exists at RECORD.
195
+ Child record could not be read (CODE): RECORD.
196
+ 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
197
+ Capture shutdown failed; child termination was not confirmed for process PIDS; ownership marker retained: MARKER; child record: RECORD
198
+ Cannot write capture child record (CODE): RECORD
199
+ Cannot write capture ownership temporary (CODE): TEMPORARY
200
+ Cannot link capture ownership (CODE): MARKER; the store directory must support hard links
201
+ Cannot link capture ownership (CODE): MARKER; inspect the filesystem error and rerun
202
+ Capture ownership marker is temporarily unavailable (CODE): MARKER; rerun after serializing capture commands
203
+ Capture ownership marker is unreadable: MARKER; rerun after inspecting the filesystem error
204
+ Capture request directory is unavailable: DIRECTORY
205
+ Capture ownership marker is empty; confirm no capture process or surviving child is running and inspect this file: MARKER; its holder cannot be established
206
+ 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
207
+ Capture shutdown failed
208
+ ```
209
+
210
+ Every USAGE refusal (exit 64) removes its invocation's run directory and leaves no marker.
211
+ An exit-1 failure after discovery keeps its run directory and logs.
212
+
213
+ PNG decoding is capped at 20,971,520 pixels, about 19.5% over the largest measured fleet frame,
214
+ 1170 × 15000; 2880 × 6000 also fits. Each side is capped at 131,072 pixels. The file allowance is
215
+ 100,820,583 bytes: the maximum RGBA scanlines plus a 20% encoding margin, checked before reading
216
+ or joining compressed chunks. Preflight judges full frames one at a time and retains dimensions
217
+ and sheet thumbnails. Isolated Node runs on Windows on 2026-10-28 peaked at 276–333 MiB process
218
+ RSS for those fleet frames, 438 MiB for stored-deflate RGBA at the pixel boundary, and 456 MiB for
219
+ 131072 × 160. Thumbnails use an exact box area average over typed arrays. Every pixel in each
220
+ displayed block contributes once; partial edge blocks divide by their actual pixel count. The
221
+ accumulators hold one output row, and thumbnails clip at 400 pixels tall.
222
+
223
+ ## Package
224
+
225
+ The typed ESM and CommonJS entry points expose the following APIs:
226
+
227
+ - `@orkestrel/capture` supplies protocol types, constants, guards, pure comparison helpers, and
228
+ `CaptureError` with its `isCaptureError` guard.
229
+ - `@orkestrel/capture/server` supplies `CaptureIntegrity`, `CaptureRunner`, `CaptureInvocation`,
230
+ `CaptureDiscovery`, `CapturePreflight`, `CaptureSheets`, and `CaptureRegistrar`, their factories
231
+ where provided, the `CaptureCLI` dispatcher and `createCaptureCLI` factory, and host integration
232
+ helpers such as `answerCaptureDiscovery` and `readCaptureRequest`.
233
+
234
+ For every export, method, and behavioral limit, see the
235
+ [Capture guide](https://github.com/orkestrel/capture/blob/main/guides/capture.md).
236
+
237
+ ## Development
238
+
239
+ Install the development dependencies, build the executable, and run the package and consumer proofs:
240
+
241
+ ```sh
242
+ npm install
243
+ npm run build
244
+ npm test
245
+ ```
246
+
247
+ The integration proof at `tests/integration.test.ts` runs the built executable through real Vitest
248
+ and Chromium as part of `npm test` or with `npm run test:integration`. It requires `npm run build`,
249
+ the installed `@vitest/browser-playwright` browser provider, and the Chromium runtime.
250
+
251
+ For read-only documentation and formatting checks, run the following commands:
252
+
253
+ ```sh
254
+ npm run test:guides
255
+ npm run format:check
256
+ ```
257
+
258
+ ## License
259
+
260
+ 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"}