rig-review 1.18.0 → 2.0.0

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/docs/DESIGN.md CHANGED
@@ -157,13 +157,13 @@ their missing consumer contracts; no tools are fabricated for them.
157
157
 
158
158
  ### Standing live job boundary
159
159
 
160
- `src/job-contract.ts` freezes the semantic live-job boundary (`JOB_API_SCHEMA` set to `rig-review/job-api@1`, `JOB_ACT_SCHEMA` set to `rig-review/act@1`, [Review #484](https://github.com/rig-c/review/issues/484)), backed by the implemented backend session/store (`src/job-session.ts`, `src/job-source.ts`, `src/job-act.ts`, `src/job-api.ts`), standing loopback job front and browser window runtime (`src/job-front.ts`, `web/job-session.ts`), and `rig-review session open|publish|ask|next|close` CLI (`src/entry.ts`, `src/job-cli.ts`). The public installed managed-host entry is `@rig-c/review/job-host` with frozen exports in [Public API stability](STABILITY.md#managed-owner-host), and Create's production publication reader and writer-owned sibling `fetch-act` readback remain pending [Create #184](https://github.com/rig-c/create/issues/184). See [Live job contract](REVIEW_PACKAGE.md#live-job-contract) and [Standing live job workflow](WORKFLOWS.md#standing-live-job-workflow).
160
+ `src/job-contract.ts` freezes the semantic live-job boundary (`JOB_API_SCHEMA` set to `rig-review/job-api@2`, `JOB_ACT_SCHEMA` set to `rig-review/act@2`, [Review #484](https://github.com/rig-c/review/issues/484)), backed by the implemented backend session/store (`src/job-session.ts`, `src/job-source.ts`, `src/job-act.ts`, `src/job-api.ts`), standing loopback job front and browser window runtime (`src/job-front.ts`, `web/job-session.ts`), and `rig-review session open|publish|ask|next|close` CLI (`src/entry.ts`, `src/job-cli.ts`). The public installed managed-host entry is `@rig-c/review/job-host` with frozen exports in [Public API stability](STABILITY.md#managed-owner-host), and Create's production publication reader and writer-owned sibling `fetch-act` readback remain pending [Create #184](https://github.com/rig-c/create/issues/184). See [Live job contract](REVIEW_PACKAGE.md#live-job-contract) and [Standing live job workflow](WORKFLOWS.md#standing-live-job-workflow).
161
161
 
162
162
  - **One standing window and owner visual gate.** Every owner visual, question, choice, correction and verdict goes through one standing Review window/link plus one what-to-look-at line. Internal agent and HQ media remain internal. A missing required visual (`visual.status` set to `'unavailable'`) is an immediate stop plus a Create-filed on-path Review card, never a chat fallback.
163
163
  - **Human UI authority vs agent verbs.** People submit finalized acts through the browser UI (`actor` set to `'human'`, `channel` set to `'review-ui'`) under a bootstrap-declared `reviewer` (`id` and `role` as `'owner'` or `'delegate'`). That reviewer binding is declared by trusted host bootstrap, cannot be typed or overridden in the browser UI, represents provenance rather than keyboard-user authentication, and maps to Create's existing `by` authority. Agents use `publish`, `ask`, `next` and `close` with `expectedGeneration` CAS and `idempotencyKey`. `publish` requires an explicit producer-held freeze (`freeze.kind` set to `'producer-held'`, `holdId`, `record`) held until acknowledgment as a caller obligation, with no watched-root or automatic-close guarantee. Only explicit `close` ends an active job.
164
164
  - **Exact displayed source, cursor replay and draft retention.** Finalized acts and job events replay through durable cursors (`next` and `subscribeJob`). The daemon derives `JobSourceBinding` from validated retained bytes and the page-scoped `displayedNonce` receipt rather than browser-supplied hashes. When a new publication updates the displayed source, old local drafts remain retained for their original source binding and are flagged without rebinding onto the new publication.
165
- - **Enabled vs reserved act kinds.** Five act kinds are enabled (`interview-picks`, `checkpoint`, `parts-verdict`, `review-verdict`, `signoff`) while `described-correction` (awaiting the joint [Create #182](https://github.com/rig-c/create/issues/182) context allowlist) and `mesh-edit` (awaiting the joint [Parts #1159](https://github.com/rig-c/parts/issues/1159) freeze) stay reserved and disabled (`JOB_ACT_KIND_DISABLED`). Checkpoint acts carry `pass` or `fail` only (`pending` is UI draft only) and require `words` as a string preserved verbatim including empty or whitespace-only text, with `planStepId` copied by the daemon from the validated ask and stage derived by Create. Signoff acts carry `approved` only with required verbatim `words` (empty or whitespace-only allowed) and remain separate from verdicts and Create stage transitions. Plan-bound signoffs (`plan-approved`, `rigging-interview`, `post-interview`) and checkpoints use step IDs and hashes published by [Create #184](https://github.com/rig-c/create/issues/184) without Review recomputing `stepHash`. In the current C3 runtime, parts bindings (`JobPartsIdentity`) are limited to the declared four roles (`part`, `alternate`, `depth`, `painting`) and path restriction — normal `parts/*.png` images plus exact `painting_in_rig.png` beside `parts.json` (root or project prefix only) — so `figure_mask` is missing and C3 is not yet a complete manifest-referenced parts PNG inventory. C4 ([Review #501](https://github.com/rig-c/review/issues/501)) is queued to bind the `@rig-c/parts` `2.25.0` `partsFileReferences` result per Parts `STABILITY` at `62208d6` ([Parts #1163](https://github.com/rig-c/parts/issues/1163)) together with [Create #184](https://github.com/rig-c/create/issues/184), so Review verifies producer-enumerated paths and bytes without a Review field parser. Within the current C3 set, missing or changed referenced bytes (including a referenced `painting_in_rig.png`) invalidate the binding while unreferenced stale extras are excluded.
166
- - **Writer-owned sibling fetch, public host seam and legacy file handoffs.** [Create #182](https://github.com/rig-c/create/issues/182) and [Create #184](https://github.com/rig-c/create/issues/184) own direct writer publication and `fetch-act` reads via a private writer-owned sibling binding outside `project.json` (`writer-owned-sibling-fetch-capability`, pending Create #184 production reader/writer integration), never tracked in version control or unstaged project output, never constructed or carried by agents, dead at explicit `close`, and renewed on each job incarnation. In the public managed-host startup seam (`startJobHost` from `@rig-c/review/job-host`, frozen in [Public API stability](STABILITY.md#managed-owner-host)), hook-bearing host callers declare `readerId` and `bindingId`; equality governs listener reuse and missing or mismatched IDs refuse by name (`JOB_HOST_OPTION_ID_INVALID`, `JOB_HOST_REUSE_MISMATCH`) with no function hashes. Future mesh acts will be fetched by Create and passed in process to Parts' public exported API owned by [Parts #1159](https://github.com/rig-c/parts/issues/1159) without Parts reading Review or Create storage, while standalone `--delta` remains legacy outside the active cycle. Agents never build, parse, reshape or carry Review session, picks, verdict or applied-record storage files, and existing `--picks-file`, saved verdict path, reshaped feedback JSON and `--verbatim-file` handoffs are legacy/history bypass findings for the active cycle.
165
+ - **Enabled vs reserved act kinds.** Five act kinds are enabled (`interview-picks`, `checkpoint`, `parts-verdict`, `review-verdict`, `signoff`) while `described-correction` (awaiting the joint [Create #182](https://github.com/rig-c/create/issues/182) context allowlist) and `mesh-edit` (awaiting the joint [Parts #1159](https://github.com/rig-c/parts/issues/1159) freeze) stay reserved and disabled (`JOB_ACT_KIND_DISABLED`). Checkpoint acts carry `pass` or `fail` only (`pending` is UI draft only) and require `words` as a string preserved verbatim including empty or whitespace-only text, with `planStepId` copied by the daemon from the validated ask and stage derived by Create. Signoff acts carry `approved` only with required verbatim `words` (empty or whitespace-only allowed) and remain separate from verdicts and Create stage transitions. Plan-bound signoffs (`plan-approved`, `rigging-interview`, `post-interview`) and checkpoints use step IDs and hashes published by [Create #184](https://github.com/rig-c/create/issues/184) without Review recomputing `stepHash`. C4 binds the exact public `partsFileReferences(dir)` array from `@rig-c/parts/src/parts.ts`, whose contract is frozen at Parts 2.25.0. The trusted host resolves an installed version in `JOB_PARTS_ENUMERATOR_RANGE` (`>=2.25.0 <3.0.0`), supplies its actual version and official callback through `partsEnumerator`, and declares `partsEnumeratorId`. `JobPartsIdentity.enumeratorVersion` carries that actual version. Manifest paths are work-root-relative and image paths are relative to the manifest directory. Each image carries `path`, bounded-string `role` and raw-byte `sha256`. Review compares the claimed array positionally with the official array, preserving its role/order/duplicate semantics. Upstream roles include `part`, `alternate`, `depth`, `painting` and `figure_mask`. Review bounds shape and paths, refuses traversal/symlinks, decodes PNGs and hashes retained bytes. Missing references refuse with row, role and path, including a missing sibling figure mask when a render copy exists. Unreferenced extras stay outside this parts identity. Composite source hashes use `rig-review-job-source/2`. Create #184 production reader/projection and official-hook wiring remain pending.
166
+ - **Writer-owned sibling fetch, public host seam and legacy file handoffs.** [Create #182](https://github.com/rig-c/create/issues/182) and [Create #184](https://github.com/rig-c/create/issues/184) own direct writer publication and `fetch-act` reads via a private writer-owned sibling binding outside `project.json` (`writer-owned-sibling-fetch-capability`, pending Create #184 production reader/writer integration), never tracked in version control or unstaged project output, never constructed or carried by agents, dead at explicit `close`, and renewed on each job incarnation. In the public managed-host startup seam (`startJobHost` from `@rig-c/review/job-host`, frozen in [Public API stability](STABILITY.md#managed-owner-host)), hook-bearing host callers declare `readerId`, `bindingId` and `partsEnumeratorId`; equality plus API/act schemas and actual enumerator version govern authenticated active-listener reuse and missing or mismatched IDs refuse by name (`JOB_HOST_OPTION_ID_INVALID`, `JOB_HOST_REUSE_MISMATCH`) with no function hashes. Future mesh acts will be fetched by Create and passed in process to Parts' public exported API owned by [Parts #1159](https://github.com/rig-c/parts/issues/1159) without Parts reading Review or Create storage, while standalone `--delta` remains legacy outside the active cycle. Agents never build, parse, reshape or carry Review session, picks, verdict or applied-record storage files, and existing `--picks-file`, saved verdict path, reshaped feedback JSON and `--verbatim-file` handoffs are legacy/history bypass findings for the active cycle.
167
167
  - **Direction scope.** Direction carriage in `#484` is metadata-only and distinct from [Review #482](https://github.com/rig-c/review/issues/482) preview and [Review #483](https://github.com/rig-c/review/issues/483) actual plated take playback, while [Review #373](https://github.com/rig-c/review/issues/373) remains parked.
168
168
 
169
169
  Stage 1 in a single compiled inspection with a producer handoff shows the
@@ -1017,7 +1017,7 @@ In the standing live-job contract ([Review #484](https://github.com/rig-c/review
1017
1017
 
1018
1018
  ## Live job contract
1019
1019
 
1020
- `src/job-contract.ts` defines the frozen semantic contract boundary for [Review #484](https://github.com/rig-c/review/issues/484), [Create #182](https://github.com/rig-c/create/issues/182), [Create #184](https://github.com/rig-c/create/issues/184), [Parts #1159](https://github.com/rig-c/parts/issues/1159) and [Parts #1163](https://github.com/rig-c/parts/issues/1163) under `JOB_API_SCHEMA` (`rig-review/job-api@1`) and `JOB_ACT_SCHEMA` (`rig-review/act@1`), implemented across the backend session/store (`src/job-store.ts`, `src/job-session.ts`, `src/job-source.ts`, `src/job-act.ts`, `src/job-api.ts`, `src/job-worker.ts`), standing loopback job front and browser window runtime (`src/job-front.ts`, `web/job-session.ts`), and `rig-review session` CLI (`src/entry.ts`, `src/job-cli.ts`). The public installed managed-host entry is `@rig-c/review/job-host` with frozen exports in [Public API stability](STABILITY.md#managed-owner-host), and Create's production publication reader and writer-owned sibling `fetch-act` readback remain pending [Create #184](https://github.com/rig-c/create/issues/184) (publishing a Create root containing `project.json` without a host `readPublished` callback refuses `JOB_SOURCE_UNRETAINABLE` with `CREATE_PUBLICATION_CONTRACT_UNAVAILABLE`). One-shot file-handoff workflows documented elsewhere in this reference remain preserved as legacy/history compatibility for existing callers.
1020
+ `src/job-contract.ts` defines the frozen semantic contract boundary for [Review #484](https://github.com/rig-c/review/issues/484), [Create #182](https://github.com/rig-c/create/issues/182), [Create #184](https://github.com/rig-c/create/issues/184), [Parts #1159](https://github.com/rig-c/parts/issues/1159) and [Parts #1163](https://github.com/rig-c/parts/issues/1163) under `JOB_API_SCHEMA` (`rig-review/job-api@2`) and `JOB_ACT_SCHEMA` (`rig-review/act@2`), implemented across the backend session/store (`src/job-store.ts`, `src/job-session.ts`, `src/job-source.ts`, `src/job-act.ts`, `src/job-api.ts`, `src/job-worker.ts`), standing loopback job front and browser window runtime (`src/job-front.ts`, `web/job-session.ts`), and `rig-review session` CLI (`src/entry.ts`, `src/job-cli.ts`). The public installed managed-host entry is `@rig-c/review/job-host` with frozen exports in [Public API stability](STABILITY.md#managed-owner-host), and Create's production publication reader and writer-owned sibling `fetch-act` readback remain pending [Create #184](https://github.com/rig-c/create/issues/184) (publishing a Create root containing `project.json` without a host `readPublished` callback refuses `JOB_SOURCE_UNRETAINABLE` with `CREATE_PUBLICATION_CONTRACT_UNAVAILABLE`). One-shot file-handoff workflows documented elsewhere in this reference remain preserved as legacy/history compatibility for existing callers.
1021
1021
 
1022
1022
  ### Vocabulary, authority, CLI and host ports
1023
1023
 
@@ -1030,12 +1030,12 @@ In the standing live-job contract ([Review #484](https://github.com/rig-c/review
1030
1030
  - `rig-review session close <job-url> --generation <n> --key <id> --reason <words> [--request-id <id>]`
1031
1031
  Agent verbs authenticate with `RIG_REVIEW_JOB_AGENT_CAPABILITY` (`Authorization: Bearer …`) against `http://127.0.0.1:<port>/jobs/<jobId>` and refuse `fetch-act` (`JOB_AUTHORITY_REFUSED`). See [Standing live job workflow](WORKFLOWS.md#standing-live-job-workflow) for an ordinary-package launch, bootstrap and explicit close example.
1032
1032
  - **Bootstrap-declared reviewer.** `JobReviewerBinding` (`id` and `role` as `'owner'` or `'delegate'` inside `JobHumanAuthority`) is declared by trusted host bootstrap when opening the window. The browser UI cannot type, edit or override this binding. It records bootstrap-declared provenance rather than keyboard-user authentication. Create maps `role` to its existing `by` authority and preserves the declared reviewer identity.
1033
- - **Trusted host ports and public managed-host startup seam.** `JobHostPorts` separates `handleJobApi` (which accepts agent verbs and consumer `fetch-act` only) from closed same-origin UI routes (`readPublication`, `commitUIAct`, `ackDisplayed`, `jobLiveness`, `subscribeJob`, mounted by `createJobFront` under `/jobs/<jobId>/…` with sealed retained publication routes; the owner HTML root accepts the default or literal `?lang=en` or `?lang=ko` only) that remain unavailable to agent tokens. Raw `Request` objects preserve real `Origin`, capability, body size and abort context. A TypeScript value is never authentication evidence. In the public managed-host startup seam (`startJobHost(options: JobHostOptions): Promise<JobOwnerHost>` from `@rig-c/review/job-host`, where `JobHostOptions extends JobWorkerOptions` adds `readerId?: string` and `bindingId?: string`, frozen in [Public API stability](STABILITY.md#managed-owner-host)), each present hook (`readPublished`, `installWriterBinding`) requires a nonempty declared ID and a missing hook requires its ID to be absent (`JOB_HOST_OPTION_ID_INVALID`). Equal declared IDs permit listener reuse across processes and newly allocated function objects via `/jobs/<jobId>/host` (`schema: 'rig-review-job-host/1'`); differing IDs, hook-presence differences and unrecorded older listener IDs fail by name (`JOB_HOST_REUSE_MISMATCH`) with the option name and both IDs while preserving the existing listener. No function hashes are used. `installWriterBinding` receives `{jobId, origin, fetchCapability}` after reuse validation and runs on a matching new or reused host.
1033
+ - **Trusted host ports and public managed-host startup seam.** `JobHostPorts` separates `handleJobApi` (which accepts agent verbs and consumer `fetch-act` only) from closed same-origin UI routes (`readPublication`, `commitUIAct`, `ackDisplayed`, `jobLiveness`, `subscribeJob`, mounted by `createJobFront` under `/jobs/<jobId>/…` with sealed retained publication routes; the owner HTML root accepts the default or literal `?lang=en` or `?lang=ko` only) that remain unavailable to agent tokens. Raw `Request` objects preserve real `Origin`, capability, body size and abort context. A TypeScript value is never authentication evidence. In the public managed-host startup seam (`startJobHost(options: JobHostOptions): Promise<JobOwnerHost>` from `@rig-c/review/job-host`, where `JobHostOptions extends JobWorkerOptions` adds `readerId?: string`, `bindingId?: string` and `partsEnumeratorId?: string`, frozen in [Public API stability](STABILITY.md#managed-owner-host)), each present hook (`readPublished`, `installWriterBinding`, `partsEnumerator`) requires a nonempty declared ID and a missing hook requires its ID to be absent (`JOB_HOST_OPTION_ID_INVALID`). Equal declared IDs, API/act schemas and actual enumerator versions permit authenticated active-listener reuse across processes and newly allocated function objects via `/jobs/<jobId>/host` (`schema: 'rig-review-job-host/1'`); differing IDs, hook-presence differences and unrecorded older listener IDs fail by name (`JOB_HOST_REUSE_MISMATCH`) with the option name and both IDs while preserving the existing listener. No function hashes are used. `installWriterBinding` receives `{jobId, origin, fetchCapability}` after reuse validation and runs on a matching new or reused host.
1034
1034
  - **Standing window and visual gate.** Every owner visual, question, choice, correction and verdict goes through one standing Review window/link plus one what-to-look-at line (a job survives zero open owner tabs and reuses the same active job/link on later `session open` until explicit `close`). Internal agent and HQ media stay internal. Each `JobPublication` reports `visual` with `status` set to `'available'` or `'unavailable'` with a named `code`. A missing required visual is an immediate stop plus a Create-filed on-path Review card, never a chat fallback.
1035
1035
 
1036
1036
  ### Publication, producer-held freeze and generation CAS
1037
1037
 
1038
- - **Mutating requests and CAS.** Agent mutations (`publish`, `ask`, `close` in `JobMutation`) require `expectedGeneration` (a nonnegative safe integer) and `idempotencyKey` alongside `schema` (`rig-review/job-api@1`), `jobId` and `requestId`. Stale generations refuse with `JOB_GENERATION_STALE` and conflicting idempotency payloads refuse with `JOB_IDEMPOTENCY_CONFLICT`.
1038
+ - **Mutating requests and CAS.** Agent mutations (`publish`, `ask`, `close` in `JobMutation`) require `expectedGeneration` (a nonnegative safe integer) and `idempotencyKey` alongside `schema` (`rig-review/job-api@2`), `jobId` and `requestId`. Stale generations refuse with `JOB_GENERATION_STALE` and conflicting idempotency payloads refuse with `JOB_IDEMPOTENCY_CONFLICT`.
1039
1039
  - **Explicit producer-held freeze.** `JobPublishRequest` designates a root-relative `result` (`path` and nullable `selector`, never a command) and requires `freeze` with `kind` set to `'producer-held'`, `holdId` and `record` (`JobFileIdentity` for the exact record used for selection, or `null` for a declared non-Create root) held until acknowledgment. Review validates retained bytes, detects a moved or incomplete record (`JOB_FREEZE_REQUIRED`, `JOB_RECORD_INCOMPLETE`, `JOB_RECORD_MOVED`, `JOB_SOURCE_MISMATCH`, `JOB_SOURCE_UNRETAINABLE`, `JOB_ROOT_REPLACED`) and commits local CAS. The freeze assertion is a caller obligation on the publishing producer or agent, not a lock Review can impose on independent writers.
1040
1040
  - **Explicit close lifecycle.** Review offers no watched-root or automatic-close guarantee. Only an explicit `close` request (`JobCloseRequest` with `reason`) ends an active job (`status` transitions from `'active'` to `'closed'`, and subsequent mutations or fetches refuse with `JOB_CLOSED`).
1041
1041
  - **Finalized acts and cursor replay.** `JobNextRequest` (`verb` set to `'next'`, `after` cursor or `null`, and daemon-bounded `waitMs`) and `subscribeJob` replay complete durable `JobEvent` items (`published`, `pending`, `act`, `closed`) in order, returning `JobNextValue` (`events`, `cursor`, and `status` as `'events'`, `'timeout'` or `'closed'`). Waiting is abortable and never consumes an act. Invalid cursors refuse with `JOB_CURSOR_INVALID`.
@@ -1055,7 +1055,13 @@ In the standing live-job contract ([Review #484](https://github.com/rig-c/review
1055
1055
  - **`review-verdict`.** `JobActValues['review-verdict']` carries `stage` (`'rig-review'` or `'direction-review'`), `verdict` and `words`, requiring a `rig` or `post` selector and non-null `source.model` with runtime stage, selector and direction consistency checks.
1056
1056
  - **`signoff`.** `JobActValues['signoff']` carries `stage` (validated by Create's writer), `decision` restricted to `'approved'` only (changes requested are a verdict, never a signoff) and required `words` preserved verbatim including empty or whitespace-only strings. A verdict, a signoff and a Create stage transition are three separate writes, and `JobAct` grants no transition authority. Every stage in `JOB_PLAN_BOUND_SIGNOFF_STAGES` (`'plan-approved'`, `'rigging-interview'`, `'post-interview'`) requires non-null `source.plan` with exact displayed step IDs and hashes before act creation, while other stages keep `source.plan` nullable where appropriate.
1057
1057
  - **Create-published step IDs and hashes.** `JobPlanIdentity` holds `steps` (`id` and `hash`) published by [Create #184](https://github.com/rig-c/create/issues/184) for the displayed plan. Review retains these values without importing or recomputing Create's internal `stepHash`. Create validates them through its existing `steps` and `step_hashes` writer logic, with no separate plan revision hash or additional revision gate in this contract.
1058
- - **Manifest-referenced parts PNG set and C3 limitation.** In the current C3 runtime (`JobPartsIdentity` and `src/job-source.ts`), parts binding is limited to its declared four roles (`part`, `alternate`, `depth`, `painting`) and path restriction — exact `manifest` (`parts.json` or `${string}/parts.json` and `sha256`) plus lexically ordered unique `images` (`JobPartImagePath` and `sha256`) restricted to normal `parts/*.png` (`parts/${string}.png` or `${string}/parts/${string}.png`) and exact `painting_in_rig.png` beside `parts.json` at the root or project prefix only (`'painting_in_rig.png'` or `${string}/painting_in_rig.png`). Because `figure_mask` is missing from C3, current C3 runtime does not cover the complete manifest-referenced parts PNG inventory. C4 ([Review #501](https://github.com/rig-c/review/issues/501)) is queued to bind the `@rig-c/parts` `2.25.0` `partsFileReferences` result per Parts `STABILITY` at `62208d6` ([Parts #1163](https://github.com/rig-c/parts/issues/1163)) together with [Create #184](https://github.com/rig-c/create/issues/184), so Review verifies producer-enumerated paths and bytes without its own `parts.json` field parser or duplicated field rules. Within the current C3 set, missing or changed referenced bytes — including a referenced `painting_in_rig.png` — invalidate the binding, while unreferenced stale extra files are excluded and do not cause refusal. Both the manifest and the bound referenced set enter `sourceHash`, with no new parts filename or migration.
1058
+ - **C4 manifest-referenced parts PNG identity.** C4 binds the exact public `partsFileReferences(dir)` array from `@rig-c/parts/src/parts.ts`, whose contract is frozen at Parts 2.25.0. The trusted host resolves an installed version in `JOB_PARTS_ENUMERATOR_RANGE` (`>=2.25.0 <3.0.0`), supplies its actual version and official callback through `partsEnumerator`, and declares `partsEnumeratorId`. `JobPartsIdentity.enumeratorVersion` carries that actual version. Manifest paths are work-root-relative and image paths are relative to the manifest directory. Each image carries `path`, bounded-string `role` and raw-byte `sha256`. Review compares the claimed array positionally with the official array, preserving its role/order/duplicate semantics. Upstream roles include `part`, `alternate`, `depth`, `painting` and `figure_mask`. Review bounds shape and paths, refuses traversal/symlinks, decodes PNGs and hashes retained bytes. Missing references refuse with row, role and path, including a missing sibling figure mask when a render copy exists. Unreferenced extras stay outside this parts identity. Composite source hashes use `rig-review-job-source/2`. Create #184 production reader/projection and official-hook wiring remain pending.
1059
+
1060
+ ### C4 schema and stored-state compatibility
1061
+
1062
+ API@1 and unsupported requests refuse `JOB_REQUEST_INVALID` with `JOB_API_SCHEMA_MISMATCH`, HTTP 400, the current API@2 response schema and unchanged generation. The CLI checks response schema before consuming its value. Consumer writers must also check act@2. JobData and host descriptors carry explicit `apiSchema` and `actSchema` markers. Missing or old stored markers refuse `JOB_STORED_SCHEMA_MISMATCH` before credentials, status or replay. Authenticated active-listener reuse compares declared hook IDs, API/act schemas and the actual enumerator version. A stopped listener can be explicitly restarted for the same job with new valid hook IDs. Old retained documents and approvals remain under their original schemas and are never migrated or relabelled. Legacy one-shot contracts retain their documented boundaries.
1063
+
1064
+ The manifest and complete retained image rows enter the composite source hash. Limits are 4096 rows, 128 UTF-16 role units, 4096 path units, 64 MiB per raw file or decoded RGBA allocation and 256 MiB unique retained bytes. Source-bound refusals retain the old head and generation. Reference-set, path, missing-file, PNG, hash and limit details are bounded. A missing row names its official zero-based index, role and manifest-relative path. Create #184 owns its production record projection and consumer checks, which remain pending. [Public boundary](STABILITY.md#parts-enumeration-boundary).
1059
1065
 
1060
1066
  ### Writer-owned sibling fetch capability and consumer writes
1061
1067
 
package/docs/STABILITY.md CHANGED
@@ -10,10 +10,9 @@ The named exports and signatures below are the supported import contract.
10
10
  Changes to them require an explicit public-contract review. The facade reexports
11
11
  the existing implementation and semantic types directly. The semantic schemas
12
12
  and behavior are defined in [Live job contract](REVIEW_PACKAGE.md#live-job-contract).
13
- The current C3 parts binding and the separately queued C4 work remain governed
14
- by that reference.
13
+ The C4 parts binding and schema compatibility are defined by that reference.
15
14
 
16
- At C4 ([Review #501](https://github.com/rig-c/review/issues/501)), `JobPartsManifestPath`, `JobPartImagePath` and `JobPartsIdentity` will change, together with their embedding public types `JobHostOptions`, `JobOwnerHost`, `JobSessionOptions`, `JobSession`, `JobWorkerOptions`, `JobPublicationReader`, `JobPublishedContext`, `JobSourceBinding`, `JobActSources`, `JobAct`, `JobPendingAsk`, `JobPublication`, `JobStatus`, `JobEvent`, `JobNextValue`, `JobResponseValues`, `JobApiResponse`, `JobDisplayPublication` and `JobHostPorts`. This is a declared contract revision that must bump `JOB_API_SCHEMA` and receive HQ sign-off. Current-schema consumers must named-refuse a schema mismatch and must never silently interpret an incompatible payload. The installed smoke control `SMOKE_PUBLIC_HOST_SCHEMA_MISMATCH_REFUSED` sends an unsupported schema through the public host, verifies HTTP 400 with `JOB_REQUEST_INVALID` and the current response schema, and checks that generation remains unchanged, exercising the existing `parseJobRequest` schema guard. [Installed control](https://github.com/rig-c/review/blob/main/scripts/install-smoke.ts#L152), [schema guard](https://github.com/rig-c/review/blob/main/src/job-api.ts#L131).
15
+ C4 changes `JobPartsManifestPath`, `JobPartImagePath`, `JobPartsIdentity` and their embedding public host, publication, source and act types under `JOB_API_SCHEMA` (`rig-review/job-api@2`) and `JOB_ACT_SCHEMA` (`rig-review/act@2`). API@1 and unsupported requests receive HTTP 400 with `JOB_REQUEST_INVALID`, detail `JOB_API_SCHEMA_MISMATCH`, the current response schema and unchanged generation. The CLI validates response schema before consuming values. Consumer writers must check API and act schemas. The C4 candidate requires HQ exact-head sign-off and a parent-owned final contract hash. Create #184 production integration remains pending. [C4](https://github.com/rig-c/review/issues/501), [installed control](https://github.com/rig-c/review/blob/main/scripts/install-smoke.ts).
17
16
 
18
17
  ```ts
19
18
  import {startJobHost} from '@rig-c/review/job-host';
@@ -31,6 +30,7 @@ interface JobSessionOptions {
31
30
  readonly fingerprint: string;
32
31
  readonly reviewer: JobReviewerBinding;
33
32
  readonly readPublished?: JobPublicationReader;
33
+ readonly partsEnumerator?: JobPartsEnumerator;
34
34
  readonly afterSnapshot?: () => void | Promise<void>;
35
35
  readonly afterDirectorySync?: (path: string) => void;
36
36
  }
@@ -47,6 +47,7 @@ interface JobWorkerOptions extends JobSessionOptions {
47
47
  interface JobHostOptions extends JobWorkerOptions {
48
48
  readonly readerId?: string;
49
49
  readonly bindingId?: string;
50
+ readonly partsEnumeratorId?: string;
50
51
  }
51
52
 
52
53
  type JobPublicationReader = (input: {
@@ -64,6 +65,26 @@ interface JobPublishedContext {
64
65
  readonly files: readonly JobFileIdentity[];
65
66
  }
66
67
 
68
+ type JobPartsManifestPath = string; // Work-root-relative, runtime validated.
69
+ type JobPartImagePath = string; // Manifest-directory-relative, runtime validated.
70
+ type JobPartsRole = string; // Bounded string. Membership belongs to Parts.
71
+
72
+ interface JobPartsFileReference {
73
+ readonly path: JobPartImagePath;
74
+ readonly role: JobPartsRole;
75
+ }
76
+
77
+ interface JobPartsEnumerator {
78
+ readonly version: string;
79
+ readonly enumerate: (dir: string) => readonly JobPartsFileReference[];
80
+ }
81
+
82
+ interface JobPartsIdentity {
83
+ readonly enumeratorVersion: string;
84
+ readonly manifest: {readonly path: JobPartsManifestPath; readonly sha256: JobSha256};
85
+ readonly images: readonly {readonly path: JobPartImagePath; readonly role: JobPartsRole; readonly sha256: JobSha256}[];
86
+ }
87
+
67
88
  interface JobOwnerHost {
68
89
  readonly session: JobSession;
69
90
  readonly ports: JobHostPorts;
@@ -97,12 +118,25 @@ available port. `ownerUrl` opens the shipped standing owner page with its privat
97
118
  UI capability fragment. `origin` and the returned `ports` belong to that host.
98
119
 
99
120
  A present `readPublished` callback requires a nonempty `readerId`. A present
100
- `installWriterBinding` callback requires a nonempty `bindingId`. Each ID must be
121
+ `installWriterBinding` callback requires a nonempty `bindingId`. A present
122
+ `partsEnumerator` requires a nonempty `partsEnumeratorId`. Each ID must be
101
123
  absent when its callback is absent. Violations reject startup with
102
124
  `JOB_HOST_OPTION_ID_INVALID`. Equal declared IDs permit active-listener reuse
103
- across processes and newly allocated function objects. Changed or unrecorded IDs
125
+ across processes and newly allocated function objects after an authenticated host probe.
126
+ API/act schemas and the actual enumerator version must match too. Changed or unrecorded IDs
104
127
  reject with `JOB_HOST_REUSE_MISMATCH`, including the option name, listener ID and
105
128
  requested ID. The caller owns the semantic meaning of those IDs.
129
+ After `stop()`, an explicit new startup may change valid hook IDs or enumerator
130
+ version while keeping the same active job. Before allocating for any fingerprint,
131
+ startup checks active rows for that canonical root inside the same store transaction.
132
+ An old or missing stored API/act marker refuses `JOB_STORED_SCHEMA_MISMATCH`, naming
133
+ the canonical root, stored/current schemas and the instruction to close the old job
134
+ with its matching older installation. Old documents remain byte-identical. Current
135
+ schemas retain the existing different-fingerprint partition, and closed old-schema
136
+ rows do not block a new job. Subsequent reads also guard stored schemas before replay. Active listener
137
+ descriptors and authenticated responses with old/missing markers refuse reuse.
138
+ Retained identities and acts keep their original bytes and schemas. They are
139
+ never migrated, relabelled or rebound to new approvals.
106
140
 
107
141
  `readPublished` supplies the producer's published semantic context for the exact
108
142
  frozen record. `installWriterBinding` receives the private finalized-act fetch
@@ -130,6 +164,7 @@ values from the frozen semantic contract.
130
164
  - `startJobHost`
131
165
  - `JOB_API_SCHEMA`
132
166
  - `JOB_ACT_SCHEMA`
167
+ - `JOB_PARTS_ENUMERATOR_RANGE`
133
168
  - `JOB_ENABLED_ACT_KINDS`
134
169
  - `JOB_RESERVED_ACT_KINDS`
135
170
  - `JOB_PLAN_BOUND_SIGNOFF_STAGES`
@@ -163,6 +198,9 @@ without aliases or copied wire shapes.
163
198
  - `JobPartsManifestPath`
164
199
  - `JobPartImagePath`
165
200
  - `JobPartsIdentity`
201
+ - `JobPartsRole`
202
+ - `JobPartsFileReference`
203
+ - `JobPartsEnumerator`
166
204
  - `JobSelector`
167
205
  - `JobSourceBinding`
168
206
  - `JobReviewerBinding`
@@ -198,13 +236,23 @@ without aliases or copied wire shapes.
198
236
  - `JobHostPorts`
199
237
  - `JobConsumerGrant`
200
238
 
239
+ ## Parts enumeration boundary
240
+
241
+ C4 binds the exact public `partsFileReferences(dir)` array from `@rig-c/parts/src/parts.ts`, whose contract is frozen at Parts 2.25.0. The trusted host resolves an installed version in `JOB_PARTS_ENUMERATOR_RANGE` (`>=2.25.0 <3.0.0`), supplies its actual version and official callback through `partsEnumerator`, and declares `partsEnumeratorId`. `JobPartsIdentity.enumeratorVersion` carries that actual version. Manifest paths are work-root-relative and image paths are relative to the manifest directory. Each image carries `path`, bounded-string `role` and raw-byte `sha256`. Review compares the claimed array positionally with the official array, preserving its role/order/duplicate semantics. Upstream roles include `part`, `alternate`, `depth`, `painting` and `figure_mask`. Review bounds shape and paths, refuses traversal/symlinks, decodes PNGs and hashes retained bytes. Missing references refuse with row, role and path, including a missing sibling figure mask when a render copy exists. Unreferenced extras stay outside this parts identity. Composite source hashes use `rig-review-job-source/2`. Create #184 production reader/projection and official-hook wiring remain pending.
242
+
243
+ The directory passed to the public callback holds the retained `parts.json` bytes. The original paths resolve from the directory holding the bound manifest. The host owns the official import and same-installation version check. A supplied version string alone does not authenticate a replaced callback. Review has no Parts runtime dependency and never installs the producer. Its dev-only 2.25.1 fixture is synthetic reference evidence. Missing or out-of-range versions name the required range and received value through `PARTS_ENUMERATOR_VERSION_MISMATCH`. A claimed version differing from the host installation also refuses.
244
+
245
+ Rows are capped at 4096, roles at 128 UTF-16 code units and literal paths at 4096. Individual raw files and decoded RGBA allocations are bounded at 64 MiB, and unique retained bytes at 256 MiB. Same-path multi-role references retain all rows and seal the physical bytes once. Parts' named manifest refusals are preserved through `PARTS_ENUMERATION_REFUSED`. Consumer refusals include `PARTS_REFERENCE_SET_MISMATCH`, `PARTS_REFERENCE_PATH_REFUSED`, `PARTS_REFERENCE_MISSING`, `PARTS_REFERENCE_PNG_INVALID`, `PARTS_REFERENCE_HASH_MISMATCH` and `PARTS_REFERENCE_LIMIT`. Details carry bounded row/role/path context where applicable. Failed publication preserves the committed head, source, generation and replay state.
246
+
201
247
  ## Installed acceptance
202
248
 
203
249
  `bun run smoke` packs the package and installs that tarball into an empty project.
204
250
  A consumer imports the runtime and every listed type through
205
251
  `@rig-c/review/job-host`. TypeScript checks the installed consumer and the runtime
206
252
  checks the full owner resources, retained publication, semantic ports, declared
207
- hooks, reuse and explicit-close grant lifetime using synthetic host data.
253
+ hooks, enumerator version/row carriage, reuse and explicit-close grant lifetime using synthetic host data.
254
+ This installed control uses an explicitly synthetic injected enumerator. Production
255
+ Create integration and official-import evidence have their separate acceptance gates.
208
256
 
209
257
  The declared export-removal control deletes only `./job-host` from the disposable
210
258
  installed manifest and requires the public import to fail for that missing
package/docs/WORKFLOWS.md CHANGED
@@ -360,7 +360,7 @@ The managed front forwards only the trusted stage-atlas frame query (`stageEmbed
360
360
 
361
361
  ## Standing live job workflow
362
362
 
363
- The active Create and Parts inspection cycle uses the semantic job contract in `src/job-contract.ts` (`JOB_API_SCHEMA` set to `rig-review/job-api@1`, `JOB_ACT_SCHEMA` set to `rig-review/act@1`, [Review #484](https://github.com/rig-c/review/issues/484)) together with the implemented backend session/store (`src/job-session.ts`, `src/job-source.ts`, `src/job-act.ts`, `src/job-api.ts`), loopback job front and browser window runtime (`src/job-front.ts`, `web/job-session.ts`), and `rig-review session` CLI (`src/entry.ts`, `src/job-cli.ts`). The public installed managed-host entry is `@rig-c/review/job-host` with frozen exports in [Public API stability](STABILITY.md#managed-owner-host), and Create's production publication reader and writer-owned sibling `fetch-act` readback remain pending [Create #184](https://github.com/rig-c/create/issues/184) (publishing a Create root containing `project.json` without a host `readPublished` callback refuses `JOB_SOURCE_UNRETAINABLE` with `CREATE_PUBLICATION_CONTRACT_UNAVAILABLE`). See [Live job contract](REVIEW_PACKAGE.md#live-job-contract) for the full schema and host seam reference.
363
+ The active Create and Parts inspection cycle uses the semantic job contract in `src/job-contract.ts` (`JOB_API_SCHEMA` set to `rig-review/job-api@2`, `JOB_ACT_SCHEMA` set to `rig-review/act@2`, [Review #484](https://github.com/rig-c/review/issues/484)) together with the implemented backend session/store (`src/job-session.ts`, `src/job-source.ts`, `src/job-act.ts`, `src/job-api.ts`), loopback job front and browser window runtime (`src/job-front.ts`, `web/job-session.ts`), and `rig-review session` CLI (`src/entry.ts`, `src/job-cli.ts`). The public installed managed-host entry is `@rig-c/review/job-host` with frozen exports in [Public API stability](STABILITY.md#managed-owner-host), and Create's production publication reader and writer-owned sibling `fetch-act` readback remain pending [Create #184](https://github.com/rig-c/create/issues/184) (publishing a Create root containing `project.json` without a host `readPublished` callback refuses `JOB_SOURCE_UNRETAINABLE` with `CREATE_PUBLICATION_CONTRACT_UNAVAILABLE`). See [Live job contract](REVIEW_PACKAGE.md#live-job-contract) for the full schema and host seam reference.
364
364
 
365
365
  Exact CLI usage from `src/entry.ts` and `src/job-cli.ts` (`publish`, `ask`, `next` and `close` also accept optional `--request-id <id>`):
366
366
 
@@ -400,8 +400,8 @@ rig-review session close http://127.0.0.1:<port>/jobs/<job-id> \
400
400
  - **Explicit producer-held freeze and explicit close.** Every `publish` request designates a root-relative `result` (`path` and `selector`, never a command) and carries an explicit producer-held freeze (`freeze.kind` set to `'producer-held'`, `holdId`, `record` as `JobFileIdentity` or `null` for a declared non-Create root) held until acknowledgment. Review validates retained bytes, detects a moved record (`JOB_RECORD_MOVED`, `JOB_RECORD_INCOMPLETE`, `JOB_FREEZE_REQUIRED`, `JOB_SOURCE_MISMATCH`, `JOB_SOURCE_UNRETAINABLE`, `JOB_ROOT_REPLACED`) and commits local generation CAS (`JOB_GENERATION_STALE`, `JOB_IDEMPOTENCY_CONFLICT`). The freeze assertion is a caller obligation rather than a lock Review can impose on independent writers. Review offers no watched-root or automatic-close guarantee, and only explicit `close` ends an active job.
401
401
  - **Exact displayed source and retained drafts.** The daemon derives `JobSourceBinding` from validated retained bytes and the actual displayed publication (`ackDisplayed` returning a page-scoped `displayedNonce` receipt, pinned same-origin `routes` with no mutable current alias). All metadata, images, runtime assets, routes and pending form dependencies prepare before the visible swap; paint and the single `displayedNonce` acknowledgment precede retirement of the previous view, and failed preparation or acknowledgment restores the prior view and draft. Clients never supply trusted source hashes or transfer prior approval onto a new binding. When a new publication updates the displayed source, old local drafts remain retained in storage for their original source binding and are flagged without rebinding onto the new publication.
402
402
  - **Finalized acts, five enabled kinds and cursor replay.** `next` (`after` cursor and bounded abortable `waitMs` that never consumes an act) and `subscribeJob` replay complete durable `JobEvent` records (`published`, `pending`, `act`, `closed`). Only five act kinds are enabled (`interview-picks`, `checkpoint`, `parts-verdict`, `review-verdict`, `signoff`). `described-correction` (awaiting the joint [Create #182](https://github.com/rig-c/create/issues/182) context allowlist) and `mesh-edit` (awaiting the joint [Parts #1159](https://github.com/rig-c/parts/issues/1159) freeze) stay reserved and disabled (`JOB_ACT_KIND_DISABLED`).
403
- - **Checkpoints, signoffs, plan steps and parts PNGs.** In `checkpoint` acts, `outcome` is `'pass'` or `'fail'` only (`'pending'` stays in the UI draft and never produces a finalized act), and required `words` is preserved verbatim as a string including empty or whitespace-only text. The browser sends `checkpointId`, `outcome` and `words` only while the daemon copies resolved `planStepId` from the validated ask, and Create derives execution stage from its authoritative step phase and order without Review stamping a stage. Only `'pass'` is eligible for Create's checkpoint sign-off writer, while `'fail'` is feedback or a named consumer refusal. In `signoff` acts, `decision` is `'approved'` only (changes requested are a verdict) with required `words` preserved verbatim including empty or whitespace-only text. A verdict, a signoff and a Create stage transition are three separate writes, and plan-bound signoff stages (`plan-approved`, `rigging-interview`, `post-interview`) require `source.plan` with exact displayed step IDs and hashes published by [Create #184](https://github.com/rig-c/create/issues/184) without Review recomputing `stepHash`. In the current C3 runtime, `JobPartsIdentity` is limited to its declared four roles (`part`, `alternate`, `depth`, `painting`) and path restriction — normal images at `parts/*.png` (`parts/${string}.png` or `${string}/parts/${string}.png`) plus exact `painting_in_rig.png` beside `parts.json` at the root or project prefix only (`painting_in_rig.png` or `${string}/painting_in_rig.png`) — so `figure_mask` is missing and C3 does not yet cover a complete manifest-referenced parts PNG inventory. C4 ([Review #501](https://github.com/rig-c/review/issues/501)) is queued to bind the `@rig-c/parts` `2.25.0` `partsFileReferences` result per Parts `STABILITY` at `62208d6` ([Parts #1163](https://github.com/rig-c/parts/issues/1163)) together with [Create #184](https://github.com/rig-c/create/issues/184), so Review verifies producer-enumerated paths and bytes without parsing `parts.json` fields itself. Within the current C3 set, missing or changed referenced bytes (including a referenced `painting_in_rig.png`) invalidate the binding, while unreferenced stale extra files are excluded without refusal.
404
- - **No agent file carriage, writer-owned sibling fetch and public host seam.** Agents never build, parse, reshape or carry Review session, picks, verdict or applied-record storage files. [Create #182](https://github.com/rig-c/create/issues/182) and [Create #184](https://github.com/rig-c/create/issues/184) own direct writer publication and act fetch through a private writer-owned sibling binding outside `project.json` (`writer-owned-sibling-fetch-capability`, pending Create #184 production reader/writer integration). That binding is never tracked in version control or unstaged project output, dies at explicit `close` with a new grant per job incarnation, and grants read-only `fetch-act` over loopback with `Authorization`. In the public managed-host startup seam (`startJobHost` from `@rig-c/review/job-host`, frozen in [Public API stability](STABILITY.md#managed-owner-host)), hook-bearing host callers declare `readerId` for `readPublished` and `bindingId` for `installWriterBinding`; missing or invalid IDs refuse with `JOB_HOST_OPTION_ID_INVALID`, and listener reuse requires equal `readerId` and `bindingId` or refuses with `JOB_HOST_REUSE_MISMATCH` (with no function hashes). Future mesh-edit consumption is owned by [Parts #1159](https://github.com/rig-c/parts/issues/1159), where Create fetches a finalized mesh act and passes its typed value in process to Parts' public exported API without Parts reading Review or Create storage.
403
+ - **Checkpoints, signoffs, plan steps and parts PNGs.** In `checkpoint` acts, `outcome` is `'pass'` or `'fail'` only (`'pending'` stays in the UI draft and never produces a finalized act), and required `words` is preserved verbatim as a string including empty or whitespace-only text. The browser sends `checkpointId`, `outcome` and `words` only while the daemon copies resolved `planStepId` from the validated ask, and Create derives execution stage from its authoritative step phase and order without Review stamping a stage. Only `'pass'` is eligible for Create's checkpoint sign-off writer, while `'fail'` is feedback or a named consumer refusal. In `signoff` acts, `decision` is `'approved'` only (changes requested are a verdict) with required `words` preserved verbatim including empty or whitespace-only text. A verdict, a signoff and a Create stage transition are three separate writes, and plan-bound signoff stages (`plan-approved`, `rigging-interview`, `post-interview`) require `source.plan` with exact displayed step IDs and hashes published by [Create #184](https://github.com/rig-c/create/issues/184) without Review recomputing `stepHash`. C4 binds the exact public `partsFileReferences(dir)` array from `@rig-c/parts/src/parts.ts`, whose contract is frozen at Parts 2.25.0. The trusted host resolves an installed version in `JOB_PARTS_ENUMERATOR_RANGE` (`>=2.25.0 <3.0.0`), supplies its actual version and official callback through `partsEnumerator`, and declares `partsEnumeratorId`. `JobPartsIdentity.enumeratorVersion` carries that actual version. Manifest paths are work-root-relative and image paths are relative to the manifest directory. Each image carries `path`, bounded-string `role` and raw-byte `sha256`. Review compares the claimed array positionally with the official array, preserving its role/order/duplicate semantics. Upstream roles include `part`, `alternate`, `depth`, `painting` and `figure_mask`. Review bounds shape and paths, refuses traversal/symlinks, decodes PNGs and hashes retained bytes. Missing references refuse with row, role and path, including a missing sibling figure mask when a render copy exists. Unreferenced extras stay outside this parts identity. Composite source hashes use `rig-review-job-source/2`. Create #184 production reader/projection and official-hook wiring remain pending.
404
+ - **No agent file carriage, writer-owned sibling fetch and public host seam.** Agents never build, parse, reshape or carry Review session, picks, verdict or applied-record storage files. [Create #182](https://github.com/rig-c/create/issues/182) and [Create #184](https://github.com/rig-c/create/issues/184) own direct writer publication and act fetch through a private writer-owned sibling binding outside `project.json` (`writer-owned-sibling-fetch-capability`, pending Create #184 production reader/writer integration). That binding is never tracked in version control or unstaged project output, dies at explicit `close` with a new grant per job incarnation, and grants read-only `fetch-act` over loopback with `Authorization`. In the public managed-host startup seam (`startJobHost` from `@rig-c/review/job-host`, frozen in [Public API stability](STABILITY.md#managed-owner-host)), hook-bearing host callers declare `readerId` for `readPublished` and `bindingId` for `installWriterBinding` and `partsEnumeratorId` for `partsEnumerator`; missing or invalid IDs refuse with `JOB_HOST_OPTION_ID_INVALID`, and listener reuse requires equal `readerId`, `bindingId` and `partsEnumeratorId` or refuses with `JOB_HOST_REUSE_MISMATCH` (with no function hashes). Future mesh-edit consumption is owned by [Parts #1159](https://github.com/rig-c/parts/issues/1159), where Create fetches a finalized mesh act and passes its typed value in process to Parts' public exported API without Parts reading Review or Create storage.
405
405
  - **Direction metadata vs playback.** Direction carriage in `#484` is metadata-only (`source.direction` and `direction-review`) and is distinct from [Review #482](https://github.com/rig-c/review/issues/482) preview and [Review #483](https://github.com/rig-c/review/issues/483) actual plated take playback, while [Review #373](https://github.com/rig-c/review/issues/373) stays parked.
406
406
 
407
407
  ## Create choice interview
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rig-review",
3
- "version": "1.18.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "description": "Local human rig inspection and structured feedback export",
6
6
  "license": "MIT",
@@ -25,6 +25,7 @@
25
25
  "pngjs": "7.0.0"
26
26
  },
27
27
  "devDependencies": {
28
+ "@rig-c/parts": "2.25.1",
28
29
  "@types/bun": "^1.3.0",
29
30
  "typescript": "^5.9.3"
30
31
  },
@@ -12,7 +12,7 @@ or to read back their submitted review.
12
12
 
13
13
  ## Active cycle standing live-job contract
14
14
 
15
- For the active Create and Parts cycle, the authoritative contract is `src/job-contract.ts` (`JOB_API_SCHEMA` set to `rig-review/job-api@1`, `JOB_ACT_SCHEMA` set to `rig-review/act@1`, [Review #484](https://github.com/rig-c/review/issues/484)), backed by the implemented backend session/store (`src/job-session.ts`, `src/job-source.ts`, `src/job-act.ts`, `src/job-api.ts`), standing loopback job front and browser window runtime (`src/job-front.ts`, `web/job-session.ts`), and `rig-review session` CLI (`src/entry.ts`, `src/job-cli.ts`). The public installed managed-host entry is `@rig-c/review/job-host` with frozen exports in [Public API stability](https://github.com/rig-c/review/blob/main/docs/STABILITY.md#managed-owner-host), and Create's production publication reader and writer-owned sibling `fetch-act` readback remain pending [Create #184](https://github.com/rig-c/create/issues/184) (publishing a Create root containing `project.json` without a host `readPublished` callback refuses `JOB_SOURCE_UNRETAINABLE` with `CREATE_PUBLICATION_CONTRACT_UNAVAILABLE`). Do not invent public export names, producer scene fields or unimplemented flags, and never expose capabilities in reports or logs. See [Live job contract](https://github.com/rig-c/review/blob/main/docs/REVIEW_PACKAGE.md#live-job-contract) and [Standing live job workflow](https://github.com/rig-c/review/blob/main/docs/WORKFLOWS.md#standing-live-job-workflow).
15
+ For the active Create and Parts cycle, the authoritative contract is `src/job-contract.ts` (`JOB_API_SCHEMA` set to `rig-review/job-api@2`, `JOB_ACT_SCHEMA` set to `rig-review/act@2`, [Review #484](https://github.com/rig-c/review/issues/484)), backed by the implemented backend session/store (`src/job-session.ts`, `src/job-source.ts`, `src/job-act.ts`, `src/job-api.ts`), standing loopback job front and browser window runtime (`src/job-front.ts`, `web/job-session.ts`), and `rig-review session` CLI (`src/entry.ts`, `src/job-cli.ts`). The public installed managed-host entry is `@rig-c/review/job-host` with frozen exports in [Public API stability](https://github.com/rig-c/review/blob/main/docs/STABILITY.md#managed-owner-host), and Create's production publication reader and writer-owned sibling `fetch-act` readback remain pending [Create #184](https://github.com/rig-c/create/issues/184) (publishing a Create root containing `project.json` without a host `readPublished` callback refuses `JOB_SOURCE_UNRETAINABLE` with `CREATE_PUBLICATION_CONTRACT_UNAVAILABLE`). Do not invent public export names, producer scene fields or unimplemented flags, and never expose capabilities in reports or logs. See [Live job contract](https://github.com/rig-c/review/blob/main/docs/REVIEW_PACKAGE.md#live-job-contract) and [Standing live job workflow](https://github.com/rig-c/review/blob/main/docs/WORKFLOWS.md#standing-live-job-workflow).
16
16
 
17
17
  Exact CLI namespace (`src/entry.ts`, `src/job-cli.ts`; `publish`, `ask`, `next`, `close` also accept optional `--request-id <id>`):
18
18
 
@@ -52,8 +52,8 @@ rig-review session close http://127.0.0.1:<port>/jobs/<job-id> \
52
52
  - **Explicit producer-held freeze and explicit close.** Every `publish` carries an explicit producer-held freeze (`freeze.kind` set to `'producer-held'`, `holdId`, `record` as `JobFileIdentity` or `null` for a declared non-Create root) held until acknowledgment as a caller obligation. Review validates retained bytes, detects a moved record and commits local generation CAS. No watched-root or automatic-close guarantee exists, and only explicit `close` ends an active job.
53
53
  - **Exact displayed source, cursor replay and draft retention.** `next` (`after` cursor and bounded abortable `waitMs` that never consumes an act) replays complete durable `JobEvent` items (`published`, `pending`, `act`, `closed`). The daemon derives `JobSourceBinding` from validated retained bytes and the page-scoped `displayedNonce` receipt rather than browser-supplied hashes. When a new publication replaces or updates the displayed source, old local drafts remain retained for their original source binding and are flagged without rebinding onto the new publication.
54
54
  - **Five enabled act kinds and two reserved disabled kinds.** Enabled kinds are `interview-picks`, `checkpoint`, `parts-verdict`, `review-verdict` and `signoff`. Reserved kinds `described-correction` (awaiting the joint [Create #182](https://github.com/rig-c/create/issues/182) context allowlist) and `mesh-edit` (awaiting the joint [Parts #1159](https://github.com/rig-c/parts/issues/1159) freeze) stay disabled (`JOB_ACT_KIND_DISABLED`) and cannot be asked or submitted.
55
- - **Checkpoints, signoffs, plan steps and parts PNGs.** Finalized `checkpoint` acts carry `outcome` `'pass'` or `'fail'` only (`'pending'` stays in the UI draft), require `words` as a string preserved verbatim including empty or whitespace-only text, copy `planStepId` from the validated ask on the daemon while the browser sends `checkpointId`, `outcome` and `words` only, and leave stage derivation to Create (only `'pass'` is eligible for Create's checkpoint sign-off writer). Finalized `signoff` acts carry `decision` `'approved'` only with required `words` preserved verbatim including empty or whitespace-only text, remain separate from verdicts and Create stage transitions, and require `source.plan` with exact displayed step IDs and hashes published by [Create #184](https://github.com/rig-c/create/issues/184) (without Review recomputing `stepHash`) on `plan-approved`, `rigging-interview` and `post-interview`. In the current C3 runtime, `JobPartsIdentity` is limited to its declared four roles (`part`, `alternate`, `depth`, `painting`) and path restriction — normal `parts/*.png` images plus exact `painting_in_rig.png` beside `parts.json` (root or project prefix only) — so `figure_mask` is missing and C3 is not yet a complete manifest-referenced parts PNG inventory. C4 ([Review #501](https://github.com/rig-c/review/issues/501)) is queued to bind the `@rig-c/parts` `2.25.0` `partsFileReferences` result per Parts `STABILITY` at `62208d6` ([Parts #1163](https://github.com/rig-c/parts/issues/1163)) together with [Create #184](https://github.com/rig-c/create/issues/184), which owns the roles without a Review field parser. Within the current C3 set, changed or missing referenced bytes (including a referenced `painting_in_rig.png`) invalidate the binding while unreferenced stale extras are excluded.
56
- - **No agent file carriage, writer-owned sibling fetch and public host seam.** Agents never build, parse, reshape or carry Review session, picks, verdict or applied-record storage files. [Create #182](https://github.com/rig-c/create/issues/182) and [Create #184](https://github.com/rig-c/create/issues/184) own direct writer publication and `fetch-act` reads using a private writer-owned sibling binding outside `project.json` (`writer-owned-sibling-fetch-capability`, pending Create #184 production reader/writer integration) that is never tracked in version control or unstaged project output, dies at explicit `close` and receives a new grant on each job incarnation. In the public managed-host startup seam (`startJobHost` from `@rig-c/review/job-host`, frozen in [Public API stability](https://github.com/rig-c/review/blob/main/docs/STABILITY.md#managed-owner-host)), hook-bearing host callers declare `readerId` and `bindingId`; equality governs listener reuse and missing or mismatched IDs refuse by name (`JOB_HOST_OPTION_ID_INVALID`, `JOB_HOST_REUSE_MISMATCH`) with no function hashes. Future mesh acts will be fetched by Create and passed in process to Parts' public exported API owned by [Parts #1159](https://github.com/rig-c/parts/issues/1159) without Parts reading Review or Create storage, while standalone `--delta` remains legacy outside this cycle.
55
+ - **Checkpoints, signoffs, plan steps and parts PNGs.** Finalized `checkpoint` acts carry `outcome` `'pass'` or `'fail'` only (`'pending'` stays in the UI draft), require `words` as a string preserved verbatim including empty or whitespace-only text, copy `planStepId` from the validated ask on the daemon while the browser sends `checkpointId`, `outcome` and `words` only, and leave stage derivation to Create (only `'pass'` is eligible for Create's checkpoint sign-off writer). Finalized `signoff` acts carry `decision` `'approved'` only with required `words` preserved verbatim including empty or whitespace-only text, remain separate from verdicts and Create stage transitions, and require `source.plan` with exact displayed step IDs and hashes published by [Create #184](https://github.com/rig-c/create/issues/184) (without Review recomputing `stepHash`) on `plan-approved`, `rigging-interview` and `post-interview`. C4 binds the exact public `partsFileReferences(dir)` array from `@rig-c/parts/src/parts.ts`, whose contract is frozen at Parts 2.25.0. The trusted host resolves an installed version in `JOB_PARTS_ENUMERATOR_RANGE` (`>=2.25.0 <3.0.0`), supplies its actual version and official callback through `partsEnumerator`, and declares `partsEnumeratorId`. `JobPartsIdentity.enumeratorVersion` carries that actual version. Manifest paths are work-root-relative and image paths are relative to the manifest directory. Each image carries `path`, bounded-string `role` and raw-byte `sha256`. Review compares the claimed array positionally with the official array, preserving its role/order/duplicate semantics. Upstream roles include `part`, `alternate`, `depth`, `painting` and `figure_mask`. Review bounds shape and paths, refuses traversal/symlinks, decodes PNGs and hashes retained bytes. Missing references refuse with row, role and path, including a missing sibling figure mask when a render copy exists. Unreferenced extras stay outside this parts identity. Composite source hashes use `rig-review-job-source/2`. Create #184 production reader/projection and official-hook wiring remain pending.
56
+ - **No agent file carriage, writer-owned sibling fetch and public host seam.** Agents never build, parse, reshape or carry Review session, picks, verdict or applied-record storage files. [Create #182](https://github.com/rig-c/create/issues/182) and [Create #184](https://github.com/rig-c/create/issues/184) own direct writer publication and `fetch-act` reads using a private writer-owned sibling binding outside `project.json` (`writer-owned-sibling-fetch-capability`, pending Create #184 production reader/writer integration) that is never tracked in version control or unstaged project output, dies at explicit `close` and receives a new grant on each job incarnation. In the public managed-host startup seam (`startJobHost` from `@rig-c/review/job-host`, frozen in [Public API stability](https://github.com/rig-c/review/blob/main/docs/STABILITY.md#managed-owner-host)), hook-bearing host callers declare `readerId`, `bindingId` and `partsEnumeratorId`; equality plus API/act schemas and actual enumerator version govern authenticated active-listener reuse and missing or mismatched IDs refuse by name (`JOB_HOST_OPTION_ID_INVALID`, `JOB_HOST_REUSE_MISMATCH`) with no function hashes. Future mesh acts will be fetched by Create and passed in process to Parts' public exported API owned by [Parts #1159](https://github.com/rig-c/parts/issues/1159) without Parts reading Review or Create storage, while standalone `--delta` remains legacy outside this cycle.
57
57
  - **Direction metadata vs playback.** Direction carriage in `#484` is metadata-only (`source.direction` and `direction-review`) and is distinct from [Review #482](https://github.com/rig-c/review/issues/482) preview and [Review #483](https://github.com/rig-c/review/issues/483) actual plated take playback, while [Review #373](https://github.com/rig-c/review/issues/373) stays parked.
58
58
 
59
59
  ## What an agent drives vs. what the person drives
package/src/job-api.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createHash, timingSafeEqual } from 'node:crypto';
2
2
  import {
3
- JOB_API_SCHEMA, JOB_ENABLED_ACT_KINDS, JOB_RESERVED_ACT_KINDS,
3
+ JOB_API_SCHEMA, JOB_PARTS_ENUMERATOR_RANGE, JOB_ENABLED_ACT_KINDS, JOB_RESERVED_ACT_KINDS,
4
4
  type JobAgentRequest, type JobDisplayAcknowledgment, type JobFetchActRequest,
5
5
  type JobHostPorts, type JobResult, type JobSelector, type JobSubject,
6
6
  } from './job-contract.ts';
@@ -123,12 +123,30 @@ export function parseJobSubject(value: unknown): JobSubject {
123
123
  throw new JobError('JOB_ASK_INVALID');
124
124
  }
125
125
 
126
+ /** Preserve the installed version while enforcing the jointly accepted range. */
127
+ export function jobPartsEnumeratorVersion(value: unknown): string {
128
+ const bounded = typeof value === 'string' && value.length > 0 && value.length <= 128 &&
129
+ !/[\x00-\x20\x7f]/.test(value);
130
+ if (!bounded || !Bun.semver.satisfies(value, JOB_PARTS_ENUMERATOR_RANGE)) {
131
+ const received = bounded ? JSON.stringify(value) : '<missing-or-invalid>';
132
+ throw new JobError('JOB_SOURCE_UNRETAINABLE',
133
+ `PARTS_ENUMERATOR_VERSION_MISMATCH range="${JOB_PARTS_ENUMERATOR_RANGE}" received=${received}`);
134
+ }
135
+ return value;
136
+ }
137
+
138
+ export function assertJobApiSchema(value: unknown): void {
139
+ if (value !== JOB_API_SCHEMA) {
140
+ throw new JobError('JOB_REQUEST_INVALID', 'JOB_API_SCHEMA_MISMATCH');
141
+ }
142
+ }
143
+
126
144
  export function parseJobRequest(value: unknown): JobAgentRequest | JobFetchActRequest {
127
145
  const item = jobObject(value, [
128
146
  'schema', 'jobId', 'requestId', 'verb', 'expectedGeneration', 'idempotencyKey',
129
147
  'result', 'freeze', 'publicationId', 'subject', 'after', 'waitMs', 'reason', 'actId',
130
148
  ]);
131
- if (item.schema !== JOB_API_SCHEMA) throw new JobError('JOB_REQUEST_INVALID');
149
+ assertJobApiSchema(item.schema);
132
150
  const base = { schema: JOB_API_SCHEMA, jobId: jobId(item.jobId), requestId: jobId(item.requestId) };
133
151
  if (item.verb === 'next') {
134
152
  jobObject(item, ['schema', 'jobId', 'requestId', 'verb', 'after', 'waitMs']);
package/src/job-cli.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { JOB_API_SCHEMA, type JobAgentRequest } from './job-contract.ts';
3
- import { jobFailure, parseJobRequest } from './job-api.ts';
3
+ import { assertJobApiSchema, jobFailure, parseJobRequest } from './job-api.ts';
4
4
  import { JobError } from './job-store.ts';
5
5
 
6
6
  export interface JobCLIOptions {
@@ -108,6 +108,7 @@ export async function jobCommand(args: readonly string[], options: JobCLIOptions
108
108
  let value: unknown;
109
109
  try { value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)); }
110
110
  catch { throw new JobError('JOB_REQUEST_INVALID'); }
111
+ assertJobApiSchema(value !== null && typeof value === 'object' ? (value as { schema?: unknown }).schema : undefined);
111
112
  write(JSON.stringify(value));
112
113
  if (!response.ok) process.exitCode = 1;
113
114
  }
@@ -11,8 +11,9 @@
11
11
  * Only explicit close ends an active job. Direction carriage is metadata-only.
12
12
  */
13
13
 
14
- export const JOB_API_SCHEMA = 'rig-review/job-api@1' as const;
15
- export const JOB_ACT_SCHEMA = 'rig-review/act@1' as const;
14
+ export const JOB_API_SCHEMA = 'rig-review/job-api@2' as const;
15
+ export const JOB_ACT_SCHEMA = 'rig-review/act@2' as const;
16
+ export const JOB_PARTS_ENUMERATOR_RANGE = '>=2.25.0 <3.0.0' as const;
16
17
 
17
18
  export const JOB_ENABLED_ACT_KINDS = [
18
19
  'interview-picks',
@@ -76,30 +77,41 @@ export interface JobPlanIdentity {
76
77
  readonly steps: readonly JobPlanStepIdentity[];
77
78
  }
78
79
 
79
- export type JobPartsManifestPath = 'parts.json' | `${string}/parts.json`;
80
- export type JobPartImagePath =
81
- | `parts/${string}.png`
82
- | `${string}/parts/${string}.png`
83
- | 'painting_in_rig.png'
84
- | `${string}/painting_in_rig.png`;
85
-
86
- /** Exact parts.json and EVERY manifest-referenced PNG, across part, alternate,
87
- * depth and painting roles. Create #184 publishes the authoritative set using
88
- * Parts' public reference enumerator, pending Parts #1163. Its export name and
89
- * reader resolution rules belong to Parts. Review verifies the published paths
90
- * and bytes without duplicating those field rules. Paths use original project
91
- * provenance. Images are unique and lexically ordered in this public projection.
92
- * Missing or changed referenced bytes invalidate the binding. Unreferenced stale
93
- * extras are excluded and do not cause refusal. The manifest and complete
94
- * referenced set enter sourceHash. No new parts filename or migration is added.
80
+ /** Literal work-root-relative manifest path, validated at runtime. */
81
+ export type JobPartsManifestPath = string;
82
+ /** Literal path relative to the bound manifest directory. */
83
+ export type JobPartImagePath = string;
84
+ /** Bounded string only. Parts owns role membership, order and duplicate rules. */
85
+ export type JobPartsRole = string;
86
+
87
+ export interface JobPartsFileReference {
88
+ readonly path: JobPartImagePath;
89
+ readonly role: JobPartsRole;
90
+ }
91
+
92
+ /** Trusted host wires the official partsFileReferences export from its actual
93
+ * installed @rig-c/parts/src/parts.ts and checks that installation's version.
94
+ * A version claim alone does not authenticate a substituted callback.
95
+ */
96
+ export interface JobPartsEnumerator {
97
+ readonly version: string;
98
+ readonly enumerate: (dir: string) => readonly JobPartsFileReference[];
99
+ }
100
+
101
+ /** Exact official enumeration, preserved positionally with roles and raw-byte
102
+ * hashes. Manifest provenance is work-root-relative. Image paths are relative
103
+ * to its directory. enumeratorVersion is the actual installed Parts version
104
+ * within JOB_PARTS_ENUMERATOR_RANGE. Unreferenced extras are outside identity.
95
105
  */
96
106
  export interface JobPartsIdentity {
107
+ readonly enumeratorVersion: string;
97
108
  readonly manifest: {
98
109
  readonly path: JobPartsManifestPath;
99
110
  readonly sha256: JobSha256;
100
111
  };
101
112
  readonly images: readonly {
102
113
  readonly path: JobPartImagePath;
114
+ readonly role: JobPartsRole;
103
115
  readonly sha256: JobSha256;
104
116
  }[];
105
117
  }
package/src/job-front.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Disjoint live-job routes. The backend receives the original authenticated Request. */
2
- import type { JobErrorCode, JobHostPorts, JobResult } from './job-contract.ts';
2
+ import { JOB_API_SCHEMA, JOB_ACT_SCHEMA, type JobErrorCode, type JobHostPorts, type JobResult } from './job-contract.ts';
3
3
  import { createJobHostPorts } from './job-api.ts';
4
4
  import { JobSession } from './job-session.ts';
5
5
  import type { JobWorkerOptions } from './job-worker.ts';
@@ -276,6 +276,10 @@ function retainedPublicationRoutes(session: JobSession) {
276
276
 
277
277
  interface JobHostRecord {
278
278
  schema: 'rig-review-job-host/1';
279
+ apiSchema: typeof JOB_API_SCHEMA;
280
+ actSchema: typeof JOB_ACT_SCHEMA;
281
+ partsEnumeratorId: string | null;
282
+ partsEnumeratorVersion: string | null;
279
283
  jobId: string;
280
284
  origin: string;
281
285
  fingerprint: string;
@@ -289,9 +293,11 @@ interface JobHostRecord {
289
293
  export interface JobHostOptions extends JobWorkerOptions {
290
294
  readonly readerId?: string;
291
295
  readonly bindingId?: string;
296
+ readonly partsEnumeratorId?: string;
292
297
  }
293
298
 
294
- type JobHostOptionName = 'readPublished' | 'installWriterBinding';
299
+ type JobHostOptionName = 'readPublished' | 'installWriterBinding' | 'partsEnumerator' |
300
+ 'partsEnumeratorVersion' | 'apiSchema' | 'actSchema';
295
301
 
296
302
  class JobHostOptionError extends Error {
297
303
  constructor(
@@ -329,6 +335,8 @@ export async function startJobHost(options: JobHostOptions): Promise<JobOwnerHos
329
335
  const startup = {...options};
330
336
  const readerId = declaredHostId('readPublished', startup.readPublished, startup.readerId);
331
337
  const bindingId = declaredHostId('installWriterBinding', startup.installWriterBinding, startup.bindingId);
338
+ const partsEnumeratorId = declaredHostId('partsEnumerator', startup.partsEnumerator?.enumerate, startup.partsEnumeratorId);
339
+ const partsEnumeratorVersion = startup.partsEnumerator?.version ?? null;
332
340
  const session = new JobSession(startup);
333
341
  async function installBinding(origin: string): Promise<void> {
334
342
  try {await startup.installWriterBinding?.({...session.writerGrant(), origin});}
@@ -339,6 +347,20 @@ export async function startJobHost(options: JobHostOptions): Promise<JobOwnerHos
339
347
  await mkdir(control, {recursive: true, mode: 0o700}).catch(error => {session.dispose(); throw error;});
340
348
  const recordPath = join(control, session.jobId + '.json');
341
349
  let previousPort = 0;
350
+ function compatible(record: JobHostRecord): void {
351
+ for (const [option, actual, requested] of [
352
+ ['readPublished', record.readerId, readerId],
353
+ ['installWriterBinding', record.bindingId, bindingId],
354
+ ['partsEnumerator', record.partsEnumeratorId, partsEnumeratorId],
355
+ ['partsEnumeratorVersion', record.partsEnumeratorVersion, partsEnumeratorVersion],
356
+ ['apiSchema', record.apiSchema, JOB_API_SCHEMA],
357
+ ['actSchema', record.actSchema, JOB_ACT_SCHEMA],
358
+ ] as const) {
359
+ if (actual !== requested) {
360
+ throw new JobHostOptionError('JOB_HOST_REUSE_MISMATCH', option, actual, requested);
361
+ }
362
+ }
363
+ }
342
364
  const reuse = async (): Promise<JobHostRecord | null> => {
343
365
  try {
344
366
  const info = await lstat(recordPath);
@@ -356,14 +378,8 @@ export async function startJobHost(options: JobHostOptions): Promise<JobOwnerHos
356
378
  if (!response?.ok) {void response?.body?.cancel(); return null;}
357
379
  const value = await response.json() as JobHostRecord;
358
380
  if (value.schema !== row.schema || value.jobId !== row.jobId || value.fingerprint !== row.fingerprint) return null;
359
- for (const [option, actual, requested] of [
360
- ['readPublished', value.readerId, readerId],
361
- ['installWriterBinding', value.bindingId, bindingId],
362
- ] as const) {
363
- if (actual !== requested) {
364
- throw new JobHostOptionError('JOB_HOST_REUSE_MISMATCH', option, actual, requested);
365
- }
366
- }
381
+ compatible(row);
382
+ compatible(value);
367
383
  return row;
368
384
  } catch (error) {
369
385
  if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null;
@@ -403,7 +419,8 @@ export async function startJobHost(options: JobHostOptions): Promise<JobOwnerHos
403
419
  },
404
420
  });
405
421
  const origin = `http://127.0.0.1:${server.port}`;
406
- const record: JobHostRecord = {schema: 'rig-review-job-host/1', jobId: session.jobId, origin,
422
+ const record: JobHostRecord = {schema: 'rig-review-job-host/1', apiSchema: JOB_API_SCHEMA, actSchema: JOB_ACT_SCHEMA,
423
+ partsEnumeratorId, partsEnumeratorVersion, jobId: session.jobId, origin,
407
424
  fingerprint: startup.fingerprint, pid: process.pid, readerId, bindingId};
408
425
  ports = createJobHostPorts(session, origin);
409
426
  front = createJobFront({origin, ports, resource: jobWindowResources(),
package/src/job-host.ts CHANGED
@@ -7,6 +7,7 @@ export type {JobPublicationReader, JobPublishedContext} from './job-source.ts';
7
7
  export {
8
8
  JOB_API_SCHEMA,
9
9
  JOB_ACT_SCHEMA,
10
+ JOB_PARTS_ENUMERATOR_RANGE,
10
11
  JOB_ENABLED_ACT_KINDS,
11
12
  JOB_RESERVED_ACT_KINDS,
12
13
  JOB_PLAN_BOUND_SIGNOFF_STAGES,
@@ -29,6 +30,9 @@ export type {
29
30
  JobPartsManifestPath,
30
31
  JobPartImagePath,
31
32
  JobPartsIdentity,
33
+ JobPartsRole,
34
+ JobPartsFileReference,
35
+ JobPartsEnumerator,
32
36
  JobSelector,
33
37
  JobSourceBinding,
34
38
  JobReviewerBinding,
@@ -2,12 +2,12 @@ import { randomBytes, randomUUID } from 'node:crypto';
2
2
  import { rm } from 'node:fs/promises';
3
3
  import { isAbsolute, relative, sep } from 'node:path';
4
4
  import {
5
- JOB_ENABLED_ACT_KINDS, type JobAct, type JobAgentRequest, type JobDisplayAcknowledgment,
5
+ JOB_API_SCHEMA, JOB_ACT_SCHEMA, JOB_ENABLED_ACT_KINDS, type JobPartsEnumerator, type JobAct, type JobAgentRequest, type JobDisplayAcknowledgment,
6
6
  type JobDisplayPublication, type JobDisplayReceipt, type JobEvent, type JobFetchActRequest,
7
7
  type JobNextValue, type JobPendingAsk, type JobPublication, type JobReviewerBinding, type JobStatus,
8
8
  } from './job-contract.ts';
9
9
  import { bindJobAsk, finalizeJobAct, parseUISubmission } from './job-act.ts';
10
- import { jobHash, jobWaitLimitMs, requestDigest, sameCapability } from './job-api.ts';
10
+ import { jobHash, jobPartsEnumeratorVersion, jobWaitLimitMs, requestDigest, sameCapability } from './job-api.ts';
11
11
  import {
12
12
  assertJobRoot, assertJobSourceCurrent, captureJobRoot, prepareJobSource,
13
13
  type JobPublicationReader, type JobRetainedSource, type JobRootIdentity,
@@ -26,6 +26,8 @@ interface Replay {
26
26
  }
27
27
 
28
28
  interface JobData {
29
+ apiSchema: typeof JOB_API_SCHEMA;
30
+ actSchema: typeof JOB_ACT_SCHEMA;
29
31
  root: JobRootIdentity;
30
32
  fingerprint: string;
31
33
  reviewer: JobReviewerBinding;
@@ -50,11 +52,18 @@ export interface JobSessionOptions {
50
52
  readonly fingerprint: string;
51
53
  readonly reviewer: JobReviewerBinding;
52
54
  readonly readPublished?: JobPublicationReader;
55
+ readonly partsEnumerator?: JobPartsEnumerator;
53
56
  /** Deterministic boundary hook for disposable concurrency controls only. */
54
57
  readonly afterSnapshot?: () => void | Promise<void>;
55
58
  readonly afterDirectorySync?: (path: string) => void;
56
59
  }
57
60
 
61
+ function assertStoredSchemas(data: JobData): void {
62
+ if (data.apiSchema !== JOB_API_SCHEMA || data.actSchema !== JOB_ACT_SCHEMA) {
63
+ throw new JobError('JOB_SOURCE_UNRETAINABLE', 'JOB_STORED_SCHEMA_MISMATCH');
64
+ }
65
+ }
66
+
58
67
  function within(root: string, path: string): boolean {
59
68
  const rel = relative(root, path);
60
69
  return !rel || rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel);
@@ -74,24 +83,35 @@ export class JobSession {
74
83
  const root = captureJobRoot(options.root), state = canonicalStatePath(options.stateDir);
75
84
  if (within(root.path, state)) throw new JobError('JOB_SOURCE_UNRETAINABLE', 'Job state must be outside the designated work root');
76
85
  if (!options.reviewer.id || !['owner', 'delegate'].includes(options.reviewer.role)) throw new JobError('JOB_AUTHORITY_REFUSED');
86
+ if (options.partsEnumerator) jobPartsEnumeratorVersion(options.partsEnumerator.version);
77
87
  this.store = new JobStore(state);
78
- const row = this.store.open(jobHash(JSON.stringify([root.path, options.fingerprint])), () => ({
79
- root, fingerprint: options.fingerprint, reviewer: structuredClone(options.reviewer),
80
- agentCapability: randomBytes(32).toString('hex'), uiCapability: randomBytes(32).toString('hex'),
81
- fetchCapability: randomBytes(32).toString('hex'), generation: 0, head: null,
82
- publications: {}, asks: {}, acts: {}, events: [], replays: {}, pages: {},
83
- }));
84
- this.jobId = row.jobId;
85
- assertJobRoot(row.data.root);
86
- if (requestDigest(row.data.reviewer) !== requestDigest(options.reviewer)) {
88
+ try {
89
+ const row = this.store.open(jobHash(JSON.stringify([root.path, options.fingerprint])), () => ({
90
+ apiSchema: JOB_API_SCHEMA, actSchema: JOB_ACT_SCHEMA,
91
+ root, fingerprint: options.fingerprint, reviewer: structuredClone(options.reviewer),
92
+ agentCapability: randomBytes(32).toString('hex'), uiCapability: randomBytes(32).toString('hex'),
93
+ fetchCapability: randomBytes(32).toString('hex'), generation: 0, head: null,
94
+ publications: {}, asks: {}, acts: {}, events: [], replays: {}, pages: {},
95
+ }), root.path);
96
+ this.jobId = row.jobId;
97
+ assertStoredSchemas(row.data);
98
+ assertJobRoot(row.data.root);
99
+ if (requestDigest(row.data.reviewer) !== requestDigest(options.reviewer)) {
100
+ throw new JobError('JOB_AUTHORITY_REFUSED', 'Active window reviewer binding differs');
101
+ }
102
+ } catch (error) {
87
103
  this.store.close();
88
- throw new JobError('JOB_AUTHORITY_REFUSED', 'Active window reviewer binding differs');
104
+ throw error;
89
105
  }
90
106
  }
91
107
 
92
108
  get busy(): boolean { return this.operations > 0; }
93
109
 
94
- private current(): StoredJob<JobData> { return this.store.get(this.jobId); }
110
+ private current(): StoredJob<JobData> {
111
+ const row = this.store.get(this.jobId);
112
+ assertStoredSchemas(row.data);
113
+ return row;
114
+ }
95
115
 
96
116
  /** Bootstrap delivery is private host work. Agent and owner credentials go to
97
117
  * their separate launch channels. The fetch grant is installed by Create's
@@ -188,7 +208,7 @@ export class JobSession {
188
208
  if (input.verb === 'publish') {
189
209
  candidate = await prepareJobSource({ root: current.data.root, stateRoot: this.store.root,
190
210
  fingerprint: current.data.fingerprint, request: input,
191
- readPublished: this.options.readPublished, afterSnapshot: this.options.afterSnapshot,
211
+ readPublished: this.options.readPublished, partsEnumerator: this.options.partsEnumerator, afterSnapshot: this.options.afterSnapshot,
192
212
  afterDirectorySync: this.options.afterDirectorySync });
193
213
  }
194
214
  if (signal.aborted) throw new JobError('JOB_REQUEST_INVALID', 'Request cancelled');
package/src/job-source.ts CHANGED
@@ -1,16 +1,18 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { lstatSync, realpathSync } from 'node:fs';
3
- import { mkdir, open, rm } from 'node:fs/promises';
3
+ import { mkdir, open, rm, writeFile } from 'node:fs/promises';
4
4
  import { dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
5
+ import { PNG } from 'pngjs';
6
+ import { JOB_PARTS_ENUMERATOR_RANGE } from './job-contract.ts';
5
7
  import type {
6
- JobFileIdentity, JobPartsIdentity, JobPlanIdentity, JobPublishRequest,
8
+ JobFileIdentity, JobPartsEnumerator, JobPartsFileReference, JobPartsIdentity, JobPlanIdentity, JobPublishRequest,
7
9
  JobSelector, JobSourceBinding, JobSubject,
8
10
  } from './job-contract.ts';
9
11
  import { checkedPath, readProject, readRegular, type InterviewQuestion } from './interview-project.ts';
10
12
  import { loadReview } from './manifest.ts';
11
13
  import { openKey } from './open.ts';
12
14
  import { assertReviewUnchanged } from './reference.ts';
13
- import { jobHash, jobId, jobPath, jobSha, requestDigest } from './job-api.ts';
15
+ import { jobHash, jobId, jobPartsEnumeratorVersion, jobObject, jobPath, jobSha, jobText, requestDigest } from './job-api.ts';
14
16
  import { JobError } from './job-store.ts';
15
17
 
16
18
  export interface JobRootIdentity {
@@ -119,21 +121,130 @@ function publishedIdentities(context: JobPublishedContext): JobFileIdentity[] {
119
121
  ids.add(step.id);
120
122
  jobSha(step.hash);
121
123
  }
122
- if (context.parts) {
123
- if (!/(^|\/)parts\.json$/.test(context.parts.manifest.path)) throw new JobError('JOB_SOURCE_MISMATCH');
124
- const painting = posix.join(posix.dirname(context.parts.manifest.path), 'painting_in_rig.png');
125
- if (context.parts.images.some(file =>
126
- !/(^|\/)parts\/[^/]+\.png$/.test(file.path) && file.path !== painting)) {
127
- throw new JobError('JOB_SOURCE_MISMATCH');
124
+ for (const file of files) { jobPath(file.path); jobSha(file.sha256); }
125
+ return files;
126
+ }
127
+
128
+ function referenceRow(raw: unknown, row: number, hashed: boolean): JobPartsFileReference & { sha256?: string } {
129
+ let item: Record<string, unknown>;
130
+ let role: string;
131
+ try {
132
+ item = jobObject(raw, hashed ? ['path', 'role', 'sha256'] : ['path', 'role']);
133
+ role = jobText(item.role, 128);
134
+ if (hashed) jobSha(item.sha256);
135
+ } catch { throw new JobError('JOB_SOURCE_MISMATCH', `PARTS_REFERENCE_SET_MISMATCH row=${row}`); }
136
+ let path: string;
137
+ try { path = jobPath(item.path); }
138
+ catch { throw new JobError('JOB_SOURCE_UNRETAINABLE', `PARTS_REFERENCE_PATH_REFUSED row=${row}`); }
139
+ return {path, role, ...(hashed ? {sha256: item.sha256 as string} : {})};
140
+ }
141
+
142
+ /** Membership, order and duplicate semantics belong solely to the trusted public
143
+ * enumerator. Review compares its exact array and validates byte boundaries.
144
+ */
145
+ async function prepareParts(root: string, snapshotRoot: string, claimed: JobPartsIdentity | null,
146
+ enumerator?: JobPartsEnumerator): Promise<{identity: JobPartsIdentity | null; bytes: Map<string, Buffer>}> {
147
+ const bytes = new Map<string, Buffer>();
148
+ if (claimed === null) return {identity: null, bytes};
149
+ if (!enumerator) throw new JobError('JOB_SOURCE_UNRETAINABLE', 'PARTS_ENUMERATOR_UNAVAILABLE');
150
+ jobObject(claimed, ['enumeratorVersion', 'manifest', 'images']);
151
+ const version = jobPartsEnumeratorVersion(claimed.enumeratorVersion);
152
+ if (version !== jobPartsEnumeratorVersion(enumerator.version)) {
153
+ throw new JobError('JOB_SOURCE_UNRETAINABLE',
154
+ `PARTS_ENUMERATOR_VERSION_MISMATCH range="${JOB_PARTS_ENUMERATOR_RANGE}" received="${version}" installed="${enumerator.version}"`);
155
+ }
156
+ let manifestPath: string;
157
+ try {
158
+ jobObject(claimed.manifest, ['path', 'sha256']);
159
+ manifestPath = jobPath(claimed.manifest.path);
160
+ if (posix.basename(manifestPath) !== 'parts.json') throw new Error('Manifest directory API');
161
+ jobSha(claimed.manifest.sha256);
162
+ } catch { throw new JobError('JOB_SOURCE_UNRETAINABLE', 'PARTS_REFERENCE_PATH_REFUSED manifest'); }
163
+ if (!Array.isArray(claimed.images) || claimed.images.length > maxSourceFiles) {
164
+ throw new JobError('JOB_SOURCE_UNRETAINABLE', 'PARTS_REFERENCE_LIMIT');
165
+ }
166
+ let manifestBytes: Buffer;
167
+ try { manifestBytes = sourceBytes(root, manifestPath); }
168
+ catch (error) {
169
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
170
+ throw new JobError('JOB_SOURCE_MISMATCH', 'PARTS_ENUMERATION_REFUSED rule=PARTS_FILE_PRESENT');
128
171
  }
129
- files.push(context.parts.manifest, ...context.parts.images);
130
- const paths = context.parts.images.map(file => file.path);
131
- if (new Set(paths).size !== paths.length || paths.some((path, i) => i > 0 && path < paths[i - 1])) {
132
- throw new JobError('JOB_SOURCE_MISMATCH');
172
+ throw new JobError('JOB_SOURCE_UNRETAINABLE', 'PARTS_REFERENCE_PATH_REFUSED manifest');
173
+ }
174
+ if (jobHash(manifestBytes) !== claimed.manifest.sha256) {
175
+ throw new JobError('JOB_SOURCE_MISMATCH', 'PARTS_REFERENCE_HASH_MISMATCH manifest');
176
+ }
177
+ bytes.set(manifestPath, manifestBytes);
178
+ const enumerationRoot = join(snapshotRoot, 'enumeration-' + randomUUID());
179
+ let references: readonly JobPartsFileReference[];
180
+ try {
181
+ await mkdir(enumerationRoot, {mode: 0o700});
182
+ await writeFile(join(enumerationRoot, 'parts.json'), manifestBytes, {flag: 'wx', mode: 0o600});
183
+ try { references = enumerator.enumerate(enumerationRoot); }
184
+ catch (error) {
185
+ const code = (error as {problems?: {code?: unknown}[]}).problems?.[0]?.code;
186
+ const rule = typeof code === 'string' && /^[A-Z][A-Z0-9_]{1,127}$/.test(code) ? ` rule=${code}` : '';
187
+ throw new JobError('JOB_SOURCE_MISMATCH', 'PARTS_ENUMERATION_REFUSED' + rule);
133
188
  }
189
+ } finally { await rm(enumerationRoot, {recursive: true, force: true}); }
190
+ if (!Array.isArray(references) || references.length > maxSourceFiles) {
191
+ throw new JobError('JOB_SOURCE_UNRETAINABLE', 'PARTS_REFERENCE_LIMIT');
134
192
  }
135
- for (const file of files) { jobPath(file.path); jobSha(file.sha256); }
136
- return files;
193
+ const official = references.map((raw, row) => referenceRow(raw, row, false));
194
+ const supplied = claimed.images.map((raw, row) => referenceRow(raw, row, true));
195
+ const difference = official.findIndex((row, i) => row.path !== supplied[i]?.path || row.role !== supplied[i]?.role);
196
+ if (difference !== -1 || official.length !== supplied.length) {
197
+ throw new JobError('JOB_SOURCE_MISMATCH',
198
+ `PARTS_REFERENCE_SET_MISMATCH row=${difference !== -1 ? difference : official.length}`);
199
+ }
200
+ let total = manifestBytes.length;
201
+ const decoded = new Set<string>();
202
+ const images: JobPartsIdentity['images'][number][] = [];
203
+ for (const [row, reference] of official.entries()) {
204
+ const detail = `row=${row} role=${reference.role} path=${JSON.stringify(reference.path)}`;
205
+ const path = posix.join(posix.dirname(manifestPath), reference.path);
206
+ let data = bytes.get(path);
207
+ if (!data) {
208
+ try {
209
+ if (lstatSync(checkedPath(root, path)).size > maxFileBytes) {
210
+ throw new JobError('JOB_SOURCE_UNRETAINABLE', `PARTS_REFERENCE_LIMIT ${detail}`);
211
+ }
212
+ data = sourceBytes(root, path);
213
+ }
214
+ catch (error) {
215
+ if (error instanceof JobError && error.message.startsWith('PARTS_REFERENCE_LIMIT ')) throw error;
216
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
217
+ throw new JobError('JOB_SOURCE_MISMATCH', `PARTS_REFERENCE_MISSING ${detail}`);
218
+ }
219
+ throw new JobError('JOB_SOURCE_UNRETAINABLE', `PARTS_REFERENCE_PATH_REFUSED ${detail}`);
220
+ }
221
+ total += data.length;
222
+ if (bytes.size >= maxSourceFiles || total > maxSourceBytes) {
223
+ throw new JobError('JOB_SOURCE_UNRETAINABLE', `PARTS_REFERENCE_LIMIT ${detail}`);
224
+ }
225
+ }
226
+ if (!decoded.has(path)) {
227
+ if (data.length < 33 || !data.subarray(0, 8).equals(Buffer.from('89504e470d0a1a0a', 'hex')) ||
228
+ data.readUInt32BE(8) !== 13 || data.toString('ascii', 12, 16) !== 'IHDR') {
229
+ throw new JobError('JOB_SOURCE_MISMATCH', `PARTS_REFERENCE_PNG_INVALID ${detail}`);
230
+ }
231
+ const width = data.readUInt32BE(16), height = data.readUInt32BE(20);
232
+ if (!width || !height) throw new JobError('JOB_SOURCE_MISMATCH', `PARTS_REFERENCE_PNG_INVALID ${detail}`);
233
+ if (width > Math.floor(maxFileBytes / 4 / height)) {
234
+ throw new JobError('JOB_SOURCE_UNRETAINABLE', `PARTS_REFERENCE_LIMIT ${detail}`);
235
+ }
236
+ try { PNG.sync.read(data); }
237
+ catch { throw new JobError('JOB_SOURCE_MISMATCH', `PARTS_REFERENCE_PNG_INVALID ${detail}`); }
238
+ bytes.set(path, data);
239
+ decoded.add(path);
240
+ }
241
+ const sha256 = jobHash(data);
242
+ if (sha256 !== supplied[row].sha256) {
243
+ throw new JobError('JOB_SOURCE_MISMATCH', `PARTS_REFERENCE_HASH_MISMATCH ${detail}`);
244
+ }
245
+ images.push({path: reference.path, role: reference.role, sha256});
246
+ }
247
+ return {identity: {enumeratorVersion: version, manifest: {path: manifestPath, sha256: jobHash(manifestBytes)}, images}, bytes};
137
248
  }
138
249
 
139
250
  function collectQuestionFiles(root: string, questions: readonly InterviewQuestion[]): JobFileIdentity[] {
@@ -160,6 +271,7 @@ export async function prepareJobSource(options: {
160
271
  readonly fingerprint: string;
161
272
  readonly request: JobPublishRequest;
162
273
  readonly readPublished?: JobPublicationReader;
274
+ readonly partsEnumerator?: JobPartsEnumerator;
163
275
  readonly afterSnapshot?: () => void | Promise<void>;
164
276
  readonly afterDirectorySync?: (path: string) => void;
165
277
  }): Promise<JobRetainedSource> {
@@ -218,10 +330,13 @@ export async function prepareJobSource(options: {
218
330
  const seals: JobFileIdentity[] = [];
219
331
  try {
220
332
  await mkdir(snapshotRoot, { recursive: true, mode: 0o700 });
333
+ const parts = await prepareParts(root.path, snapshotRoot, context.parts, options.partsEnumerator);
334
+ for (const [path, bytes] of parts.bytes) add(path, jobHash(bytes));
335
+ if (wanted.size > maxSourceFiles) throw new JobError('JOB_SOURCE_UNRETAINABLE', 'PARTS_REFERENCE_LIMIT');
221
336
  let size = 0;
222
337
  const directories = new Set([snapshotRoot, dirname(snapshotRoot), options.stateRoot]);
223
338
  for (const [path, expected] of [...wanted].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
224
- const bytes = sourceBytes(root.path, path), sha256 = jobHash(bytes);
339
+ const bytes = parts.bytes.get(path) ?? sourceBytes(root.path, path), sha256 = jobHash(bytes);
225
340
  size += bytes.length;
226
341
  if (size > maxSourceBytes) throw new JobError('JOB_SOURCE_UNRETAINABLE');
227
342
  if (expected && sha256 !== expected) throw new JobError(path === record?.path ? 'JOB_RECORD_MOVED' : 'JOB_SOURCE_MISMATCH');
@@ -253,15 +368,15 @@ export async function prepareJobSource(options: {
253
368
  });
254
369
  const source: JobSourceBinding = {
255
370
  sourceHash: project || context.plan || context.parts ? jobHash(JSON.stringify({
256
- schema: 'rig-review-job-source/1', packageSourceHash: review.sourceHash,
257
- record, selector: context.selector, plan: context.plan, parts: context.parts, files: seals,
371
+ schema: 'rig-review-job-source/2', packageSourceHash: review.sourceHash,
372
+ record, selector: context.selector, plan: context.plan, parts: parts.identity, files: seals,
258
373
  })) : review.sourceHash,
259
374
  projectHash: project?.hash ?? null,
260
375
  package: { id: review.manifest.id, revision: review.manifest.revision },
261
376
  selector: context.selector,
262
377
  model: originalIdentity(review.reviewedSource.rig),
263
378
  direction: originalIdentity(review.direction?.file ?? null),
264
- optionSet: null, appliedResult: null, plan: context.plan, parts: context.parts,
379
+ optionSet: null, appliedResult: null, plan: context.plan, parts: parts.identity,
265
380
  };
266
381
  const boundReview = { ...review, sourceHash: source.sourceHash };
267
382
  const prepared: JobRetainedSource = {
package/src/job-store.ts CHANGED
@@ -2,7 +2,7 @@ import { Database } from 'bun:sqlite';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { chmodSync, lstatSync, mkdirSync, realpathSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
- import type { JobErrorCode } from './job-contract.ts';
5
+ import { JOB_API_SCHEMA, JOB_ACT_SCHEMA, type JobErrorCode } from './job-contract.ts';
6
6
 
7
7
  export class JobError extends Error {
8
8
  constructor(readonly code: JobErrorCode, message: string = code) {
@@ -100,7 +100,9 @@ export class JobStore<Data> {
100
100
  active INTEGER NOT NULL CHECK(active IN (0,1)),
101
101
  document TEXT NOT NULL
102
102
  );
103
- CREATE UNIQUE INDEX IF NOT EXISTS jobs_active_root ON jobs(root_key) WHERE active=1;`);
103
+ CREATE UNIQUE INDEX IF NOT EXISTS jobs_active_root ON jobs(root_key) WHERE active=1;
104
+ CREATE INDEX IF NOT EXISTS jobs_active_canonical_root
105
+ ON jobs(json_extract(document, '$.root.path')) WHERE active=1;`);
104
106
  } catch {
105
107
  throw new JobError('JOB_STORAGE_FAILED', 'Private job storage could not be opened');
106
108
  }
@@ -123,8 +125,24 @@ export class JobStore<Data> {
123
125
  return decode<Data>(row);
124
126
  }
125
127
 
126
- open(rootKey: string, initialize: (jobId: string) => Data): StoredJob<Data> {
128
+ open(rootKey: string, initialize: (jobId: string) => Data, canonicalRoot?: string): StoredJob<Data> {
127
129
  return this.transaction(() => {
130
+ if (canonicalRoot !== undefined) {
131
+ // Inspect only bounded scalar details. The guard and allocation share
132
+ // this IMMEDIATE transaction, including across different fingerprints.
133
+ const incompatible = this.db.query<{api_schema: string; act_schema: string}, [string, string, string]>(`
134
+ SELECT substr(json_quote(json_extract(document, '$.apiSchema')), 1, 160) AS api_schema,
135
+ substr(json_quote(json_extract(document, '$.actSchema')), 1, 160) AS act_schema
136
+ FROM jobs
137
+ WHERE active=1 AND json_extract(document, '$.root.path')=?
138
+ AND (json_extract(document, '$.apiSchema') IS NOT ? OR json_extract(document, '$.actSchema') IS NOT ?)
139
+ LIMIT 1
140
+ `).get(canonicalRoot, JOB_API_SCHEMA, JOB_ACT_SCHEMA);
141
+ if (incompatible) {
142
+ throw new JobError('JOB_SOURCE_UNRETAINABLE',
143
+ `JOB_STORED_SCHEMA_MISMATCH root=${JSON.stringify(canonicalRoot)} storedApi=${incompatible.api_schema} storedAct=${incompatible.act_schema} currentApi=${JSON.stringify(JOB_API_SCHEMA)} currentAct=${JSON.stringify(JOB_ACT_SCHEMA)}. Close the old job with the matching older installation.`);
144
+ }
145
+ }
128
146
  const current = this.db.query<JobRow, [string]>(
129
147
  'SELECT * FROM jobs WHERE root_key=? AND active=1',
130
148
  ).get(rootKey);
package/web/catalog-en.ts CHANGED
@@ -3326,6 +3326,31 @@ export const enCatalog: Readonly<Record<string, string>> = {
3326
3326
  "JOB_RECORD_INCOMPLETE": "JOB_RECORD_INCOMPLETE",
3327
3327
  "JOB_RECORD_MOVED": "JOB_RECORD_MOVED",
3328
3328
  "JOB_REQUEST_INVALID": "JOB_REQUEST_INVALID",
3329
+ "JOB_API_SCHEMA_MISMATCH": "JOB_API_SCHEMA_MISMATCH",
3330
+ "JOB_STORED_SCHEMA_MISMATCH": "JOB_STORED_SCHEMA_MISMATCH",
3331
+ "JOB_STORED_SCHEMA_MISMATCH root={0} storedApi={1} storedAct={2} currentApi={3} currentAct={4}. Close the old job with the matching older installation.": "JOB_STORED_SCHEMA_MISMATCH root={0} storedApi={1} storedAct={2} currentApi={3} currentAct={4}. Close the old job with the matching older installation.",
3332
+ "PARTS_ENUMERATOR_UNAVAILABLE": "PARTS_ENUMERATOR_UNAVAILABLE",
3333
+ "PARTS_ENUMERATOR_VERSION_MISMATCH": "PARTS_ENUMERATOR_VERSION_MISMATCH",
3334
+ "PARTS_REFERENCE_SET_MISMATCH": "PARTS_REFERENCE_SET_MISMATCH",
3335
+ "PARTS_REFERENCE_PATH_REFUSED": "PARTS_REFERENCE_PATH_REFUSED",
3336
+ "PARTS_REFERENCE_HASH_MISMATCH": "PARTS_REFERENCE_HASH_MISMATCH",
3337
+ "PARTS_REFERENCE_MISSING": "PARTS_REFERENCE_MISSING",
3338
+ "PARTS_REFERENCE_PNG_INVALID": "PARTS_REFERENCE_PNG_INVALID",
3339
+ "PARTS_REFERENCE_LIMIT": "PARTS_REFERENCE_LIMIT",
3340
+ "PARTS_ENUMERATION_REFUSED": "PARTS_ENUMERATION_REFUSED",
3341
+ "PARTS_REFERENCE_SET_MISMATCH row={0}": "PARTS_REFERENCE_SET_MISMATCH row={0}",
3342
+ "PARTS_REFERENCE_PATH_REFUSED row={0}": "PARTS_REFERENCE_PATH_REFUSED row={0}",
3343
+ "PARTS_REFERENCE_PATH_REFUSED manifest": "PARTS_REFERENCE_PATH_REFUSED manifest",
3344
+ "PARTS_REFERENCE_HASH_MISMATCH manifest": "PARTS_REFERENCE_HASH_MISMATCH manifest",
3345
+ "PARTS_ENUMERATION_REFUSED rule={0}": "PARTS_ENUMERATION_REFUSED rule={0}",
3346
+ "PARTS_REFERENCE_PATH_REFUSED row={0} role={1} path={2}": "PARTS_REFERENCE_PATH_REFUSED row={0} role={1} path={2}",
3347
+ "PARTS_REFERENCE_HASH_MISMATCH row={0} role={1} path={2}": "PARTS_REFERENCE_HASH_MISMATCH row={0} role={1} path={2}",
3348
+ "PARTS_REFERENCE_MISSING row={0} role={1} path={2}": "PARTS_REFERENCE_MISSING row={0} role={1} path={2}",
3349
+ "PARTS_REFERENCE_PNG_INVALID row={0} role={1} path={2}": "PARTS_REFERENCE_PNG_INVALID row={0} role={1} path={2}",
3350
+ "PARTS_REFERENCE_LIMIT row={0} role={1} path={2}": "PARTS_REFERENCE_LIMIT row={0} role={1} path={2}",
3351
+ "PARTS_ENUMERATOR_VERSION_MISMATCH range=\"{0}\" received={1}": "PARTS_ENUMERATOR_VERSION_MISMATCH range=\"{0}\" received={1}",
3352
+ "PARTS_ENUMERATOR_VERSION_MISMATCH range=\"{0}\" received=\"{1}\" installed=\"{2}\"": "PARTS_ENUMERATOR_VERSION_MISMATCH range=\"{0}\" received=\"{1}\" installed=\"{2}\"",
3353
+ ">=2.25.0 <3.0.0": ">=2.25.0 <3.0.0",
3329
3354
  "JOB_ROOT_REPLACED": "JOB_ROOT_REPLACED",
3330
3355
  "JOB_SAME_ORIGIN_REQUIRED": "JOB_SAME_ORIGIN_REQUIRED",
3331
3356
  "JOB_SOURCE_MISMATCH": "JOB_SOURCE_MISMATCH",
package/web/catalog-ko.ts CHANGED
@@ -3326,6 +3326,31 @@ export const koCatalog: Readonly<Record<string, string>> = {
3326
3326
  "JOB_RECORD_INCOMPLETE": "JOB_RECORD_INCOMPLETE",
3327
3327
  "JOB_RECORD_MOVED": "JOB_RECORD_MOVED",
3328
3328
  "JOB_REQUEST_INVALID": "JOB_REQUEST_INVALID",
3329
+ "JOB_API_SCHEMA_MISMATCH": "JOB_API_SCHEMA_MISMATCH",
3330
+ "JOB_STORED_SCHEMA_MISMATCH": "JOB_STORED_SCHEMA_MISMATCH",
3331
+ "JOB_STORED_SCHEMA_MISMATCH root={0} storedApi={1} storedAct={2} currentApi={3} currentAct={4}. Close the old job with the matching older installation.": "JOB_STORED_SCHEMA_MISMATCH root={0} storedApi={1} storedAct={2} currentApi={3} currentAct={4}. Close the old job with the matching older installation.",
3332
+ "PARTS_ENUMERATOR_UNAVAILABLE": "PARTS_ENUMERATOR_UNAVAILABLE",
3333
+ "PARTS_ENUMERATOR_VERSION_MISMATCH": "PARTS_ENUMERATOR_VERSION_MISMATCH",
3334
+ "PARTS_REFERENCE_SET_MISMATCH": "PARTS_REFERENCE_SET_MISMATCH",
3335
+ "PARTS_REFERENCE_PATH_REFUSED": "PARTS_REFERENCE_PATH_REFUSED",
3336
+ "PARTS_REFERENCE_HASH_MISMATCH": "PARTS_REFERENCE_HASH_MISMATCH",
3337
+ "PARTS_REFERENCE_MISSING": "PARTS_REFERENCE_MISSING",
3338
+ "PARTS_REFERENCE_PNG_INVALID": "PARTS_REFERENCE_PNG_INVALID",
3339
+ "PARTS_REFERENCE_LIMIT": "PARTS_REFERENCE_LIMIT",
3340
+ "PARTS_ENUMERATION_REFUSED": "PARTS_ENUMERATION_REFUSED",
3341
+ "PARTS_REFERENCE_SET_MISMATCH row={0}": "PARTS_REFERENCE_SET_MISMATCH row={0}",
3342
+ "PARTS_REFERENCE_PATH_REFUSED row={0}": "PARTS_REFERENCE_PATH_REFUSED row={0}",
3343
+ "PARTS_REFERENCE_PATH_REFUSED manifest": "PARTS_REFERENCE_PATH_REFUSED manifest",
3344
+ "PARTS_REFERENCE_HASH_MISMATCH manifest": "PARTS_REFERENCE_HASH_MISMATCH manifest",
3345
+ "PARTS_ENUMERATION_REFUSED rule={0}": "PARTS_ENUMERATION_REFUSED rule={0}",
3346
+ "PARTS_REFERENCE_PATH_REFUSED row={0} role={1} path={2}": "PARTS_REFERENCE_PATH_REFUSED row={0} role={1} path={2}",
3347
+ "PARTS_REFERENCE_HASH_MISMATCH row={0} role={1} path={2}": "PARTS_REFERENCE_HASH_MISMATCH row={0} role={1} path={2}",
3348
+ "PARTS_REFERENCE_MISSING row={0} role={1} path={2}": "PARTS_REFERENCE_MISSING row={0} role={1} path={2}",
3349
+ "PARTS_REFERENCE_PNG_INVALID row={0} role={1} path={2}": "PARTS_REFERENCE_PNG_INVALID row={0} role={1} path={2}",
3350
+ "PARTS_REFERENCE_LIMIT row={0} role={1} path={2}": "PARTS_REFERENCE_LIMIT row={0} role={1} path={2}",
3351
+ "PARTS_ENUMERATOR_VERSION_MISMATCH range=\"{0}\" received={1}": "PARTS_ENUMERATOR_VERSION_MISMATCH range=\"{0}\" received={1}",
3352
+ "PARTS_ENUMERATOR_VERSION_MISMATCH range=\"{0}\" received=\"{1}\" installed=\"{2}\"": "PARTS_ENUMERATOR_VERSION_MISMATCH range=\"{0}\" received=\"{1}\" installed=\"{2}\"",
3353
+ ">=2.25.0 <3.0.0": ">=2.25.0 <3.0.0",
3329
3354
  "JOB_ROOT_REPLACED": "JOB_ROOT_REPLACED",
3330
3355
  "JOB_SAME_ORIGIN_REQUIRED": "JOB_SAME_ORIGIN_REQUIRED",
3331
3356
  "JOB_SOURCE_MISMATCH": "JOB_SOURCE_MISMATCH",