@rig-c/review 1.9.0 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/DESIGN.md +38 -14
- package/docs/PANELS.md +37 -13
- package/docs/PARTS_VIEW.md +79 -0
- package/docs/REVIEW_PACKAGE.md +66 -0
- package/package.json +3 -2
- package/src/applied-context.ts +17 -4
- package/src/front.ts +5 -1
- package/src/parts-comment-crops.ts +3 -1
- package/src/parts-comparison.ts +25 -2
- package/src/parts-server.ts +11 -2
- package/src/parts-view.ts +37 -5
- package/src/rebuild.ts +84 -1
- package/src/retune-check.ts +1 -1
- package/src/server.ts +4 -2
- package/src/stage-parts.ts +81 -4
- package/web/catalog-en.ts +38 -1
- package/web/catalog-ko.ts +38 -1
- package/web/chest-editor.ts +3 -0
- package/web/main.ts +59 -13
- package/web/parts.css +7 -0
- package/web/parts.html +2 -1
- package/web/parts.ts +87 -16
- package/web/rebuild-client.ts +15 -7
- package/web/stage-nav.ts +21 -6
package/docs/DESIGN.md
CHANGED
|
@@ -155,17 +155,40 @@ not create pipeline stages or sign-offs. Opening or switching never submits a
|
|
|
155
155
|
verdict, applies an edit or starts a producer job. Interview and Direction name
|
|
156
156
|
their missing consumer contracts; no tools are fabricated for them.
|
|
157
157
|
|
|
158
|
-
Stage 1
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
158
|
+
Stage 1 in a single compiled inspection with a producer handoff shows the
|
|
159
|
+
handoff's **separated parts and draft meshes**, labelled **Draft rig · structure
|
|
160
|
+
evidence only**. It proves each part's original raster crop against the rig image
|
|
161
|
+
and binds its exact skin/slot/attachment, dimensions, UVs and triangle indices to
|
|
162
|
+
the compiled mesh. UV values compare as exact float32 values, including the
|
|
163
|
+
compiler's shortest round-trip decimal representation; no numeric tolerance is
|
|
164
|
+
used. A name alone is insufficient. This is structure inspection, never final
|
|
165
|
+
rigging approval or evidence of unmeasured compiler gates.
|
|
166
|
+
|
|
167
|
+
Choose **Chest regions**, **Mesh parameters** or **Edit Mesh** on the selected
|
|
168
|
+
part to open the existing Setup precision instrument. The part and exact
|
|
169
|
+
`rig-parts remesh --mesh` or `rig-parts remesh --delta` operation remain visible.
|
|
170
|
+
Apply/Rebuild and Reset are the existing producer-backed actions. Return with
|
|
171
|
+
**1 Parts + mesh** to inspect the revision actually drawn by the parent, including
|
|
172
|
+
a checked scratch revision. Each entry reloads against that explicit build ID;
|
|
173
|
+
a pending candidate or the server's unrelated latest build is never substituted.
|
|
174
|
+
Reset returns to the inspected revision. New scratch reads and made-mesh feedback
|
|
175
|
+
submissions recheck pinned producer inputs, revision files and compiled files.
|
|
176
|
+
A changed scratch input cannot inherit clean checked evidence.
|
|
177
|
+
|
|
178
|
+
The embedding is read-only: original verdicts and comments are never copied onto
|
|
179
|
+
scratch geometry or saved by navigating. Use the standalone `parts` command for
|
|
180
|
+
its separate explicit original-parts sign-off. Parts-only inputs remain
|
|
181
|
+
inspectable and name `STAGE_DRAFT_UNAVAILABLE` for direct correction. A missing
|
|
182
|
+
handoff keeps the inspected atlas available where supplied. Compare retains its
|
|
183
|
+
read-only, side-specific inspected atlas. Neither flow guesses a sibling draft.
|
|
184
|
+
|
|
185
|
+
Named draft boundaries are `STAGE_DRAFT_UNAVAILABLE`, `STAGE_DRAFT_MISMATCH`,
|
|
186
|
+
`STAGE_DRAFT_STALE`, `STAGE_DRAFT_CHANGED`, `STAGE_DRAFT_UNCHECKED` and
|
|
187
|
+
`STAGE_DRAFT_OPERATION`. Producer discovery and its named missing/old-producer
|
|
188
|
+
refusals are unchanged; Review never installs a producer. Correction-record
|
|
189
|
+
export remains unavailable pending review#369 and create#91. Existing reviewer
|
|
190
|
+
requests remain verbatim in their existing feedback/comment contracts; there
|
|
191
|
+
is no fake Apply for art repair.
|
|
169
192
|
|
|
170
193
|
Only Stage 3 shows the legacy Setup, Animate and Compare switch; its existing
|
|
171
194
|
instruments, DOM and mode IDs are retained. In Stage 1 a compare session keeps
|
|
@@ -173,8 +196,9 @@ the A/B source picker usable and shows the selected side's cached atlas frame.
|
|
|
173
196
|
**Open setup mesh instruments** returns from the atlas to Setup; it does not
|
|
174
197
|
rebuild. Existing bookmarks, Apply/Reset provenance, selected slot, compare side,
|
|
175
198
|
time, pending edits and applied build stay owned by those original tools. Stage
|
|
176
|
-
changes retain
|
|
177
|
-
|
|
199
|
+
changes retain the original workspace and each compare side's atlas controller.
|
|
200
|
+
Single draft frames are rebound on revision changes. Language changes update retained
|
|
201
|
+
frames without applying or submitting.
|
|
178
202
|
The parts-only entry retains its part selection, geometry and pending verdict
|
|
179
203
|
while visiting unavailable stages; it needs no compiled model.
|
|
180
204
|
|
|
@@ -190,7 +214,7 @@ mesh painting. The optional protected `--painting` input supplies the real refer
|
|
|
190
214
|
A/B and adjustable-opacity Overlay share the original painting
|
|
191
215
|
transform from declared rig/source canvas geometry, with exact fractional placement. This is a visual
|
|
192
216
|
comparison using browser interpolation, not native pixel parity with the producer's resampled raster.
|
|
193
|
-
Difference
|
|
217
|
+
Difference uses the producer-declared rig-space painting artifact; see [Declared-grid Difference](PARTS_VIEW.md#declared-grid-difference).
|
|
194
218
|
`tests/parts-comparison.test.ts` guards the geometry/settings; `tests/parts-overlay-browser.ts` verifies
|
|
195
219
|
displayed overlay pixels and comment restoration in both languages.
|
|
196
220
|
|
package/docs/PANELS.md
CHANGED
|
@@ -455,17 +455,40 @@ not create pipeline stages or sign-offs. Opening or switching never submits a
|
|
|
455
455
|
verdict, applies an edit or starts a producer job. Interview and Direction name
|
|
456
456
|
their missing consumer contracts; no tools are fabricated for them.
|
|
457
457
|
|
|
458
|
-
Stage 1
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
458
|
+
Stage 1 in a single compiled inspection with a producer handoff shows the
|
|
459
|
+
handoff's **separated parts and draft meshes**, labelled **Draft rig · structure
|
|
460
|
+
evidence only**. It proves each part's original raster crop against the rig image
|
|
461
|
+
and binds its exact skin/slot/attachment, dimensions, UVs and triangle indices to
|
|
462
|
+
the compiled mesh. UV values compare as exact float32 values, including the
|
|
463
|
+
compiler's shortest round-trip decimal representation; no numeric tolerance is
|
|
464
|
+
used. A name alone is insufficient. This is structure inspection, never final
|
|
465
|
+
rigging approval or evidence of unmeasured compiler gates.
|
|
466
|
+
|
|
467
|
+
Choose **Chest regions**, **Mesh parameters** or **Edit Mesh** on the selected
|
|
468
|
+
part to open the existing Setup precision instrument. The part and exact
|
|
469
|
+
`rig-parts remesh --mesh` or `rig-parts remesh --delta` operation remain visible.
|
|
470
|
+
Apply/Rebuild and Reset are the existing producer-backed actions. Return with
|
|
471
|
+
**1 Parts + mesh** to inspect the revision actually drawn by the parent, including
|
|
472
|
+
a checked scratch revision. Each entry reloads against that explicit build ID;
|
|
473
|
+
a pending candidate or the server's unrelated latest build is never substituted.
|
|
474
|
+
Reset returns to the inspected revision. New scratch reads and made-mesh feedback
|
|
475
|
+
submissions recheck pinned producer inputs, revision files and compiled files.
|
|
476
|
+
A changed scratch input cannot inherit clean checked evidence.
|
|
477
|
+
|
|
478
|
+
The embedding is read-only: original verdicts and comments are never copied onto
|
|
479
|
+
scratch geometry or saved by navigating. Use the standalone `parts` command for
|
|
480
|
+
its separate explicit original-parts sign-off. Parts-only inputs remain
|
|
481
|
+
inspectable and name `STAGE_DRAFT_UNAVAILABLE` for direct correction. A missing
|
|
482
|
+
handoff keeps the inspected atlas available where supplied. Compare retains its
|
|
483
|
+
read-only, side-specific inspected atlas. Neither flow guesses a sibling draft.
|
|
484
|
+
|
|
485
|
+
Named draft boundaries are `STAGE_DRAFT_UNAVAILABLE`, `STAGE_DRAFT_MISMATCH`,
|
|
486
|
+
`STAGE_DRAFT_STALE`, `STAGE_DRAFT_CHANGED`, `STAGE_DRAFT_UNCHECKED` and
|
|
487
|
+
`STAGE_DRAFT_OPERATION`. Producer discovery and its named missing/old-producer
|
|
488
|
+
refusals are unchanged; Review never installs a producer. Correction-record
|
|
489
|
+
export remains unavailable pending review#369 and create#91. Existing reviewer
|
|
490
|
+
requests remain verbatim in their existing feedback/comment contracts; there
|
|
491
|
+
is no fake Apply for art repair.
|
|
469
492
|
|
|
470
493
|
Only Stage 3 shows the legacy Setup, Animate and Compare switch; its existing
|
|
471
494
|
instruments, DOM and mode IDs are retained. In Stage 1 a compare session keeps
|
|
@@ -473,7 +496,8 @@ the A/B source picker usable and shows the selected side's cached atlas frame.
|
|
|
473
496
|
**Open setup mesh instruments** returns from the atlas to Setup; it does not
|
|
474
497
|
rebuild. Existing bookmarks, Apply/Reset provenance, selected slot, compare side,
|
|
475
498
|
time, pending edits and applied build stay owned by those original tools. Stage
|
|
476
|
-
changes retain
|
|
477
|
-
|
|
499
|
+
changes retain the original workspace and each compare side's atlas controller.
|
|
500
|
+
Single draft frames are rebound on revision changes. Language changes update retained
|
|
501
|
+
frames without applying or submitting.
|
|
478
502
|
The parts-only entry retains its part selection, geometry and pending verdict
|
|
479
503
|
while visiting unavailable stages; it needs no compiled model.
|
package/docs/PARTS_VIEW.md
CHANGED
|
@@ -330,3 +330,82 @@ checks real EN/KO assembly/reference pixels against an independent browser draw
|
|
|
330
330
|
base-vs-base control, tap/hole/hide selection, pan, camera preservation, background, alpha,
|
|
331
331
|
verdict save and missing-input refusals. Existing `tests/parts-comparison.test.ts` and
|
|
332
332
|
`tests/parts-comments.test.ts` retain the painting-size and protected-input guards.
|
|
333
|
+
|
|
334
|
+
## Draft mesh correction connection
|
|
335
|
+
|
|
336
|
+
In a single compiled inspection with a live producer handoff, Stage 1 reads the
|
|
337
|
+
same original `parts.json`/PNGs through the existing reader and uses the exact
|
|
338
|
+
inspected or checked applied scratch `rig.json` for its mesh overlay. The
|
|
339
|
+
skin/slot/attachment, float32 UVs, dimensions and triangle arrays must match the
|
|
340
|
+
compiled model; raster equality is still proved by `locateMeshRasters`. Neither
|
|
341
|
+
matching names nor a shared folder is enough. Mismatch refuses by name.
|
|
342
|
+
|
|
343
|
+
The selected part opens the actual Chest regions, Mesh parameters or Edit Mesh
|
|
344
|
+
instrument, naming `remesh --mesh` or `remesh --delta`. The existing installed
|
|
345
|
+
producer writes only scratch. Return to Stage 1 after Apply to inspect the
|
|
346
|
+
recorded revision; Reset restores the original revision. New applied chest and
|
|
347
|
+
delta records carry the producer check, counts, file diff and a scratch input
|
|
348
|
+
pin. Changed scratch input, pending builds and missing/failed checks cannot be
|
|
349
|
+
submitted as new checked made evidence. Historical records with no check remain
|
|
350
|
+
readable as historical evidence; no PASS is synthesized for them.
|
|
351
|
+
|
|
352
|
+
Stage 1 does not rewrite `rig-review-parts-verdict/2`: `source.files`,
|
|
353
|
+
`source.flags`, their digest, per-part outcomes and comment/crop/comparison
|
|
354
|
+
bindings remain the standalone original-parts contract. Scratch inspection
|
|
355
|
+
returns no inherited verdict. Its own parts digest and build evidence accompany
|
|
356
|
+
the original package `sourceHash`; original Review sessions/drafts remain scoped
|
|
357
|
+
to their original `sourceHash`/`reviewedSource`. A standalone parts-only package
|
|
358
|
+
names the absent draft instead of offering an Apply that cannot run.
|
|
359
|
+
|
|
360
|
+
Correction-record export is unfinished, blocked on review#369/create#91. Existing
|
|
361
|
+
comments and feedback preserve reviewer wording, but are not a substitute for
|
|
362
|
+
that shared export or for create-owned structure decisions.
|
|
363
|
+
|
|
364
|
+
### Declared-grid Difference
|
|
365
|
+
|
|
366
|
+
**Difference** in an individual part view reads the optional producer declaration
|
|
367
|
+
`painting_in_rig: {path, sha256, resample:"lanczos3-rgb-opaque"}` in `parts.json`.
|
|
368
|
+
The literal portable path resolves inside the package. Its PNG must be RGBA8,
|
|
369
|
+
alpha 255 and exactly `rig_size`; its bytes must match the declared SHA-256.
|
|
370
|
+
The artifact joins `source.files` and protected inputs. Original `--painting`
|
|
371
|
+
A/B and Overlay remain independent. Legacy manifests without the declaration
|
|
372
|
+
still open normally; Difference requests refuse `PARTS_DIFFERENCE_UNAVAILABLE`.
|
|
373
|
+
|
|
374
|
+
The consumer is pinned to the published contract in
|
|
375
|
+
[@rig-c/parts 2.19.0](https://github.com/rig-c/parts/tree/193380b36b61a44daa3a4fcc5824a58efd6750a4).
|
|
376
|
+
This is assemble's operand: source RGB forced opaque, then producer Lanczos3.
|
|
377
|
+
Check instead flattens source alpha over its backdrop before resizing. The
|
|
378
|
+
[producer's per-example report](https://github.com/rig-c/parts/pull/1101)
|
|
379
|
+
reports equality for its five opaque example sources. That report is provenance,
|
|
380
|
+
not a consumer verdict or proof of `SETUP_MATCHES_PAINTING`.
|
|
381
|
+
|
|
382
|
+
For each original part cell with alpha > 0, the server compares stored RGB to
|
|
383
|
+
`painting_in_rig[x+cellX,y+cellY]`. No premultiplication, resampling or browser
|
|
384
|
+
pixel readback enters the metric. Difference is
|
|
385
|
+
`max(abs(dR),abs(dG),abs(dB))`, counted only when **strictly greater** than the
|
|
386
|
+
integer Threshold (0–255). Above-threshold cells are red with intensity equal
|
|
387
|
+
to the difference; others are black. Alpha-zero cells show the sentinel.
|
|
388
|
+
Invalid threshold input is refused and visibly restored to the last valid value.
|
|
389
|
+
There is no automatic approval or pass/fail verdict.
|
|
390
|
+
|
|
391
|
+
With Footprints enabled, a cell held at alpha > 0 by any overlapping later
|
|
392
|
+
part at the same integer rig coordinate is grey (128,128,128) and excluded
|
|
393
|
+
from the count. Off compares the selected part without decoding or sampling front
|
|
394
|
+
rasters. The selected part and any front parts sampled with Footprints on need
|
|
395
|
+
integer x/y, PNG dimensions equal to w/h, and native RGBA8 operands.
|
|
396
|
+
A nontransparent selected cell outside the rig grid or fractional placement
|
|
397
|
+
refuses `PARTS_DIFFERENCE_ALIGNMENT`; review never rounds placement or invents
|
|
398
|
+
edge coverage. Assembly remains a separate visual view.
|
|
399
|
+
|
|
400
|
+
Difference comments retain `view.comparison:{mode:"difference",opacity,threshold}`
|
|
401
|
+
and the existing footprints, background and cameras. Older part/overlay states
|
|
402
|
+
keep their two-field shape. The common viewport crop captures the displayed
|
|
403
|
+
comparison; the native crop keeps original RGBA. Save, reopen, restore, JSON
|
|
404
|
+
and issue Markdown retain this state, with source checks before use.
|
|
405
|
+
|
|
406
|
+
Named input refusals: `PARTS_DIFFERENCE_PROVENANCE`, `PARTS_DIFFERENCE_PATH`,
|
|
407
|
+
`PARTS_DIFFERENCE_HASH`, `PARTS_DIFFERENCE_PNG`, `PARTS_DIFFERENCE_SIZE`,
|
|
408
|
+
`PARTS_DIFFERENCE_ALPHA`. A changed loaded input uses
|
|
409
|
+
`PARTS_VIEW_SOURCE_CHANGED`. No producer command executes for Difference.
|
|
410
|
+
`tests/parts-difference.test.ts` supplies literal independent numeric controls;
|
|
411
|
+
`tests/parts-difference-browser.ts` exercises bilingual display and saved evidence.
|
package/docs/REVIEW_PACKAGE.md
CHANGED
|
@@ -826,3 +826,69 @@ existing verdict/1 records read with no comments. This identity comes from the e
|
|
|
826
826
|
parts verdict source digest and actual original PNG SHA-256, without a fabricated review
|
|
827
827
|
manifest id, revision or compiled model. The rig's `rig-review-comment/1` schema stays closed.
|
|
828
828
|
See [the parts contract and validation instruments](PARTS_VIEW.md#pointed-parts-comments).
|
|
829
|
+
|
|
830
|
+
## Stage-1 draft mesh inspection
|
|
831
|
+
|
|
832
|
+
`GET /api/stage-parts` in single inspections uses the live handoff's original
|
|
833
|
+
separated parts when a compatible draft is supplied. Its fixed indexed image
|
|
834
|
+
routes use the same binding. The closed `X-Review-Stage-Build` read header is
|
|
835
|
+
`inspected` or a 64-hex applied build ID; it is not a path or an execution request.
|
|
836
|
+
The managed front forwards it only for these single-inspection read routes.
|
|
837
|
+
Without a separated draft, the existing inspected atlas remains read-only and
|
|
838
|
+
names direct-correction absence. Compare stays read-only and side-closed.
|
|
839
|
+
Region-only handoff drafts retain the separated-parts view and image inspection;
|
|
840
|
+
`STAGE_DRAFT_NO_MESH` names unavailable direct correction on a part without a
|
|
841
|
+
mesh attachment, in English and Korean. It does not turn inspection into an error.
|
|
842
|
+
Opening another chest-capable part rebinds both region rows and landmarks to
|
|
843
|
+
that part's config and kept-region seed. Reopening the same part keeps its edits.
|
|
844
|
+
|
|
845
|
+
The draft response adds `draft:{label,buildId,inspectionSourceHash,mappings,evidence}`
|
|
846
|
+
to the existing parts-view response; `mappings` names the exact part,
|
|
847
|
+
skin/slot/attachment and mesh counts. It includes no inherited verdict or
|
|
848
|
+
submission authority. Raster/crop, float32 UV, triangle and source-hash checks
|
|
849
|
+
bind the displayed geometry. `evidence` is the actual applied producer job, not
|
|
850
|
+
a guessed correction-export object. A changed original refuses; scratch is never
|
|
851
|
+
quietly repinned. Every scratch read revalidates the recorded revision and build.
|
|
852
|
+
|
|
853
|
+
New `rig-review-applied/1` (Chest regions) and `/3` (Edit Mesh) records add optional
|
|
854
|
+
`check` and `stageInputHash`. Chest records also support `files` and `mesh`, as
|
|
855
|
+
existing patch/delta records do; `/2` can carry `stageInputHash` too. The input
|
|
856
|
+
pin hashes the whole revision plus the present scratch mesh/config/delta/world
|
|
857
|
+
inputs; compiled file hashes stay in their existing build record. Producer
|
|
858
|
+
remesh checks are reused only when their revision hash rows validate; older
|
|
859
|
+
producers run the existing check operation on scratch. A new null, failed or
|
|
860
|
+
nonzero-exit mesh check refuses `EDIT_SUBMIT_UNCHECKED`. Historical `/1` and `/3`
|
|
861
|
+
without those optional fields stay readable and never gain synthesized checks.
|
|
862
|
+
A newly requested Apply does not reuse a historical result lacking check data.
|
|
863
|
+
Each settled Apply writes a server-owned, SHA-256-verified evidence seal under
|
|
864
|
+
`<state>/applied-evidence/<package hash>/<build id>.json`, bounded to 1 MiB per
|
|
865
|
+
build. It holds the exact applied record, package binding, operation, input and
|
|
866
|
+
output digests, model hash and check summary. Seals remain for the state directory's
|
|
867
|
+
lifetime, independently of the eight-build Undo cache; pending strip candidates
|
|
868
|
+
are not applied and receive no seal. Add feedback remains local until Submit.
|
|
869
|
+
New made-mesh submissions with an input pin must exactly equal their sealed
|
|
870
|
+
record, including after Undo, eviction or a server restart. Missing, damaged or
|
|
871
|
+
different evidence refuses `STAGE_DRAFT_STALE`; client fields or `result.json`
|
|
872
|
+
alone are never evidence. Historical feedback describes the recorded Apply,
|
|
873
|
+
not the currently displayed revision. Stage reads separately re-hash the live
|
|
874
|
+
revision and compiled files, require the settled current Apply and successful
|
|
875
|
+
check, and retain `STAGE_DRAFT_CHANGED`/pending refusals. A seal never authorizes
|
|
876
|
+
drawing an evicted, changed or pending build as current.
|
|
877
|
+
|
|
878
|
+
Original `sourceHash`, `reviewedSource`, session/draft scope and parts verdict/2
|
|
879
|
+
remain unchanged. The scratch parts digest changes with its geometry; original
|
|
880
|
+
approvals never become scratch mesh approvals. Reset returns inspection to the
|
|
881
|
+
original. Draft geometry is structure evidence only. Correction-record export
|
|
882
|
+
remains blocked on review#369/create#91; no universal export, artwork Apply,
|
|
883
|
+
source-key write or automatic message is introduced.
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
Draft correspondence supports producer-authored named `weights` (compiled
|
|
887
|
+
weighted bindings) and authored unweighted `vertices` (compiled `xy`), comparing
|
|
888
|
+
the bone names and each represented float32 component exactly. Raw bone-indexed
|
|
889
|
+
vertex runs refuse `STAGE_DRAFT_GEOMETRY_UNSUPPORTED`; Review does not infer their
|
|
890
|
+
index mapping. This does not restrict standalone parts-mode UV inspection.
|
|
891
|
+
Equal UV/index arrays alone are insufficient when compiled vertex data differs.
|
|
892
|
+
Single Stage-1 controllers retain selection/camera on same-build navigation;
|
|
893
|
+
cross-revision restoration requires the same original package/image/placement
|
|
894
|
+
and exact draft skin/slot/attachment address, with named refusal if absent.
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rig-c/review",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local human rig inspection and structured feedback export",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"review": "bun src/cli.ts",
|
|
9
9
|
"check": "bun src/cli.ts check",
|
|
10
|
+
"check:demo": "bun run check -- examples/demo/review.json",
|
|
10
11
|
"demo": "bun src/cli.ts examples/demo/review.json --view-only",
|
|
11
12
|
"check:readme": "bun scripts/check-readme.ts",
|
|
12
13
|
"typecheck": "tsc --noEmit",
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
"feedback": "bun src/cli.ts feedback",
|
|
16
17
|
"open": "bun src/cli.ts open",
|
|
17
18
|
"smoke": "bun scripts/install-smoke.ts",
|
|
18
|
-
"prepublishOnly": "
|
|
19
|
+
"prepublishOnly": "node scripts/prepublish.cjs"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"@napi-rs/canvas": "1.0.11",
|
package/src/applied-context.ts
CHANGED
|
@@ -55,6 +55,7 @@ export interface CheckSummary {
|
|
|
55
55
|
}
|
|
56
56
|
export interface Tool { package: string; version: string }
|
|
57
57
|
export interface AppliedPatch {
|
|
58
|
+
stageInputHash?: string;
|
|
58
59
|
schema: typeof APPLIED_PATCH_SCHEMA;
|
|
59
60
|
buildId: string;
|
|
60
61
|
patch: ConfigPatch;
|
|
@@ -104,6 +105,8 @@ function parseAssembled(v: unknown, field: string): void {
|
|
|
104
105
|
}
|
|
105
106
|
/** #135: Edit Mesh's delta as applied by `rig-parts remesh --delta`. */
|
|
106
107
|
export interface AppliedDelta {
|
|
108
|
+
stageInputHash?: string;
|
|
109
|
+
check?: CheckSummary | null;
|
|
107
110
|
schema: typeof APPLIED_DELTA_SCHEMA;
|
|
108
111
|
buildId: string;
|
|
109
112
|
part: string;
|
|
@@ -191,7 +194,7 @@ const meshCounts = (v: unknown, field: string) => {
|
|
|
191
194
|
const isObject = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
192
195
|
const hex = (v: unknown) => typeof v === 'string' && /^[a-f0-9]{64}$/.test(v);
|
|
193
196
|
const exact = (v: unknown, keys: string, field: string): Record<string, unknown> => {
|
|
194
|
-
if (!isObject(v) || Object.keys(v).sort().join(',') !== keys) throw new Error(`${field}: expected exactly {${keys.split(',').join(', ')}}`);
|
|
197
|
+
if (!isObject(v) || Object.keys(v).sort().join(',') !== keys.split(',').sort().join(',')) throw new Error(`${field}: expected exactly {${keys.split(',').join(', ')}}`);
|
|
195
198
|
return v;
|
|
196
199
|
};
|
|
197
200
|
const tool = (v: unknown, field: string) => { const t = exact(v, 'package,version', field); if (typeof t.package !== 'string' || typeof t.version !== 'string') throw new Error(`${field}: package and version are strings`); };
|
|
@@ -223,9 +226,15 @@ export function parseAppliedContext(value: unknown): void {
|
|
|
223
226
|
if (value === null) return;
|
|
224
227
|
if (!isObject(value)) throw new Error('feedback.context.applied: expected an applied record or null');
|
|
225
228
|
const field = 'feedback.context.applied';
|
|
229
|
+
if(Object.hasOwn(value,'stageInputHash')&&!hex(value.stageInputHash))throw new Error(`${field}.stageInputHash: SHA-256 required`);
|
|
226
230
|
if (value.schema === APPLIED_REGIONS_SCHEMA) {
|
|
227
231
|
// #105: a landmarks Apply adds `bust` (the contour.bust entry as sent); its `regions` are review's derived circles.
|
|
228
|
-
const
|
|
232
|
+
const keys = Object.hasOwn(value, 'bust') ? 'buildId,bust,compiler,configHash,entrySha256,line,modelHash,part,producer,regions,schema' : 'buildId,compiler,configHash,entrySha256,line,modelHash,part,producer,regions,schema';
|
|
233
|
+
const v = exact(value, keys + ['check','stageInputHash','files','mesh'].filter(k=>Object.hasOwn(value,k)).map(k=>','+k).join(''), field);
|
|
234
|
+
if (Object.hasOwn(v, 'check')) parseCheck(v.check, `${field}.check`);
|
|
235
|
+
if (Object.hasOwn(v, 'stageInputHash')&&!hex(v.stageInputHash))throw new Error(`${field}.stageInputHash: SHA-256 required`);
|
|
236
|
+
if(Object.hasOwn(v,'files'))parseFilesDiff(v.files,`${field}.files`);
|
|
237
|
+
if(Object.hasOwn(v,'mesh')){const m=exact(v.mesh,'after,before,part',`${field}.mesh`);if(m.part!==v.part)throw new Error(`${field}.mesh.part: expected the designated part`);meshCounts(m.before,`${field}.mesh.before`);meshCounts(m.after,`${field}.mesh.after`);}
|
|
229
238
|
if (Object.hasOwn(v, 'bust')) { try { parseBustSpec(v.bust, `${field}.bust`); } catch (e) { throw new Error(e instanceof Error ? e.message : String(e)); } }
|
|
230
239
|
if (![v.buildId, v.configHash, v.entrySha256, v.modelHash].every(hex)) throw new Error(`${field}: buildId, configHash, entrySha256 and modelHash are SHA-256 hex`);
|
|
231
240
|
if (typeof v.part !== 'string' || !Array.isArray(v.regions)) throw new Error(`${field}: part and regions`);
|
|
@@ -233,7 +242,7 @@ export function parseAppliedContext(value: unknown): void {
|
|
|
233
242
|
return;
|
|
234
243
|
}
|
|
235
244
|
if (value.schema === APPLIED_PATCH_SCHEMA) {
|
|
236
|
-
const v = exact(value, `${Object.hasOwn(value, 'assembled') ? 'assembled,' : ''}buildId,check,${Object.hasOwn(value, 'cloth') ? 'cloth,' : ''}compiler,configHash,diff,${Object.hasOwn(value, 'environment') ? 'environment,' : ''}${Object.hasOwn(value, 'files') ? 'files,' : ''}line,${Object.hasOwn(value, 'mesh') ? 'mesh,' : ''}modelHash,${Object.hasOwn(value, 'op') ? 'op,' : ''}patch,patchSha256,producer,schema`, field);
|
|
245
|
+
const v = exact(value, `${Object.hasOwn(value, 'stageInputHash')?'stageInputHash,':''}${Object.hasOwn(value, 'assembled') ? 'assembled,' : ''}buildId,check,${Object.hasOwn(value, 'cloth') ? 'cloth,' : ''}compiler,configHash,diff,${Object.hasOwn(value, 'environment') ? 'environment,' : ''}${Object.hasOwn(value, 'files') ? 'files,' : ''}line,${Object.hasOwn(value, 'mesh') ? 'mesh,' : ''}modelHash,${Object.hasOwn(value, 'op') ? 'op,' : ''}patch,patchSha256,producer,schema`, field);
|
|
237
246
|
if (![v.buildId, v.configHash, v.patchSha256, v.modelHash].every(hex)) throw new Error(`${field}: buildId, configHash, patchSha256 and modelHash are SHA-256 hex`);
|
|
238
247
|
let patch: ConfigPatch;
|
|
239
248
|
try { patch = parseConfigPatch(v.patch); } catch (e) { throw new Error(`${field}.patch: ${e instanceof Error ? e.message : String(e)}`); }
|
|
@@ -263,13 +272,14 @@ export function parseAppliedContext(value: unknown): void {
|
|
|
263
272
|
return;
|
|
264
273
|
}
|
|
265
274
|
if (value.schema === APPLIED_DELTA_SCHEMA) {
|
|
266
|
-
const v = exact(value,
|
|
275
|
+
const v = exact(value, `${Object.hasOwn(value,'stageInputHash')?'stageInputHash,':''}buildId,${Object.hasOwn(value, 'check') ? 'check,' : ''}compiler,configHash,delta,deltaSha256,files,line,${Object.hasOwn(value, 'mesh') ? 'mesh,' : ''}modelHash,op,part,producer,schema`, field);
|
|
267
276
|
if (![v.buildId, v.configHash, v.deltaSha256, v.modelHash].every(hex)) throw new Error(`${field}: buildId, configHash, deltaSha256 and modelHash are SHA-256 hex`);
|
|
268
277
|
if (typeof v.part !== 'string' || !/^[A-Za-z0-9_-]{1,64}$/.test(v.part)) throw new Error(`${field}.part: the part remesh --delta ran on`);
|
|
269
278
|
const d = v.delta;
|
|
270
279
|
if (!isObject(d) || d.schema !== MESH_EDIT_SCHEMA || d.basis !== MESH_EDIT_BASIS || d.slot !== v.part || !isObject(d.source) || !hex(d.source.hash) || !Array.isArray(d.ops) || d.ops.length > MESH_EDIT_MAX_OPS) throw new Error(`${field}.delta: a ${MESH_EDIT_SCHEMA} document (basis "${MESH_EDIT_BASIS}", slot the part, source.hash, at most ${MESH_EDIT_MAX_OPS} ops)`);
|
|
271
280
|
if (v.op !== 'remesh') throw new Error(`${field}.op: "remesh" for a mesh-edit delta`);
|
|
272
281
|
tool(v.producer, `${field}.producer`); tool(v.compiler, `${field}.compiler`); lineOrNull(v.line, `${field}.line`);
|
|
282
|
+
if (Object.hasOwn(v, 'check')) parseCheck(v.check, `${field}.check`);
|
|
273
283
|
parseFilesDiff(v.files, `${field}.files`);
|
|
274
284
|
if (Object.hasOwn(v, 'mesh')) {
|
|
275
285
|
const m = exact(v.mesh, 'after,before,part', `${field}.mesh`);
|
|
@@ -350,6 +360,9 @@ export function appliedSummary(value: unknown): string | null {
|
|
|
350
360
|
* else the first bar check.json marks FAIL — verbatim. Null when the record is not a patch or its check did not FAIL.
|
|
351
361
|
*/
|
|
352
362
|
export function appliedCheckRefusal(value: unknown): string | null {
|
|
363
|
+
if (isObject(value) && [APPLIED_REGIONS_SCHEMA, APPLIED_DELTA_SCHEMA].includes(String(value.schema)) && Object.hasOwn(value, 'check')) {
|
|
364
|
+
if (!isObject(value.check) || value.check.pass !== true || value.check.exitCode !== 0) return 'EDIT_SUBMIT_UNCHECKED: applied mesh has no successful producer check';
|
|
365
|
+
}
|
|
353
366
|
if (!isObject(value) || (value.schema !== APPLIED_PATCH_SCHEMA && value.schema !== APPLIED_ANIMATION_SCHEMA) || !isObject(value.check) || value.check.pass !== false) return null;
|
|
354
367
|
const check = value.check as unknown as CheckSummary;
|
|
355
368
|
const bar = Object.entries(check.bars ?? {}).find(([, status]) => status === 'FAIL')?.[0];
|
package/src/front.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {stageDraftRefusals} from './stage-parts.ts';
|
|
1
2
|
/** Managed loopback front: one stable origin (127.0.0.1:4318 by default) routing `/instances/<key>/…` to the
|
|
2
3
|
* worker named by that key's private open record. It is a router, not an authority: it never reads packages,
|
|
3
4
|
* never serves or logs a capability, and forwards a mutation (rewriting Origin) only with the page capability. */
|
|
@@ -108,7 +109,9 @@ async function stagePartsRefusal(mode:'single'|'compare',method:string,path:stri
|
|
|
108
109
|
for(;;){const {value,done}=await reader.read();if(done)break;bytes+=value.byteLength;if(bytes>limit){void reader.cancel().catch(()=>{});return null;}chunks.push(value);}
|
|
109
110
|
const body=new Uint8Array(bytes);let offset=0;for(const chunk of chunks){body.set(chunk,offset);offset+=chunk.byteLength;}
|
|
110
111
|
const data:unknown=JSON.parse(new TextDecoder().decode(body)),named='PARTS_ATLAS_UNAVAILABLE: the inspected package has no usable atlas or its source changed.';
|
|
111
|
-
|
|
112
|
+
if(data===null||typeof data!=='object'||Array.isArray(data)||Object.keys(data).length!==1)return null;
|
|
113
|
+
const error=(data as {error?:unknown}).error;
|
|
114
|
+
return typeof error==='string'&&[named,...Object.values(stageDraftRefusals)].includes(error)?error:null;
|
|
112
115
|
}catch{return null;}finally{reader.releaseLock();}
|
|
113
116
|
}
|
|
114
117
|
export const maximumUpstreamStreams=32;
|
|
@@ -168,6 +171,7 @@ export function startFront(options:{control:string;port:number;nonce:string;fing
|
|
|
168
171
|
}
|
|
169
172
|
if(active>=maximumUpstreamStreams)return refuse('FRONT_BUSY: too many concurrent upstream streams',503);
|
|
170
173
|
const headers=new Headers({[openNonceHeader]:record.nonce});for(const name of ['accept','range','if-range',...(route.mutation?['content-type']:[]),...(route.control?['authorization']:[])]){const value=req.headers.get(name);if(value!==null)headers.set(name,value);}
|
|
174
|
+
if(/^\/api\/stage-parts(?:\/(?:image|page)\/\d+)?$/.test(path)){const build=req.headers.get('X-Review-Stage-Build');if(build!==null){if(build!=='inspected'&&!/^[a-f0-9]{64}$/.test(build))return refuse('FRONT_QUERY_REFUSED',400);headers.set('X-Review-Stage-Build',build);}}
|
|
171
175
|
if(route.mutation){headers.set('origin',record.origin);headers.set(capabilityHeader,record.capability);}
|
|
172
176
|
active++;let released=false;const abort=new AbortController(),timer=setTimeout(()=>abort.abort(),route.timeoutMs);const release=()=>{if(released)return;released=true;active--;clearTimeout(timer);};
|
|
173
177
|
req.signal.addEventListener('abort',()=>abort.abort(),{once:true});
|
|
@@ -4,7 +4,7 @@ import {readFile} from 'node:fs/promises';
|
|
|
4
4
|
import {PNG} from 'pngjs';
|
|
5
5
|
import {parsePartsComment,assertPartsCommentBinding,type PartsComment} from './parts-comment.ts';
|
|
6
6
|
import {validatePngCrop,storePngCrop,readPngCrop} from './comment-crops.ts';
|
|
7
|
-
import {verdictSource,type PartsViewPackage} from './parts-view.ts';
|
|
7
|
+
import {assertPartsUnchanged,partsDifference,verdictSource,type PartsViewPackage} from './parts-view.ts';
|
|
8
8
|
export async function preparePartsComment(pkg:PartsViewPackage,raw:unknown,requireNative=false):Promise<PartsComment>{return resolvePartsComment(pkg,raw,requireNative,true);}
|
|
9
9
|
export async function validateStoredPartsComment(pkg:PartsViewPackage,raw:unknown):Promise<PartsComment>{return resolvePartsComment(pkg,raw,true,false);}
|
|
10
10
|
async function resolvePartsComment(pkg:PartsViewPackage,raw:unknown,requireNative:boolean,persist:boolean):Promise<PartsComment>{
|
|
@@ -13,7 +13,9 @@ async function resolvePartsComment(pkg:PartsViewPackage,raw:unknown,requireNativ
|
|
|
13
13
|
const path=pkg.imagePaths[item.index],file=pkg.files.find(f=>f.abs===path);if(!path||!file)throw new Error('PARTS_COMMENT_UNAVAILABLE: bound original PNG required');
|
|
14
14
|
assertPartsCommentBinding(c,item,file.sha256,verdictSource(pkg).sha256);
|
|
15
15
|
if(c.view.comparison?.mode==='overlay'&&!pkg.painting)throw new Error('PARTS_COMPARISON_UNAVAILABLE: original painting required');
|
|
16
|
+
if(c.view.comparison?.mode==='difference')await partsDifference(pkg,item.index,c.view.comparison.threshold,c.view.footprints);
|
|
16
17
|
const bytes=await readFile(path);if(createHash('sha256').update(bytes).digest('hex')!==file.sha256)throw new Error('PARTS_COMMENT_STALE_SOURCE: original PNG changed');
|
|
18
|
+
await assertPartsUnchanged(pkg);
|
|
17
19
|
validatePngCrop(c.crop);
|
|
18
20
|
const original=PNG.sync.read(bytes),r=c.imageRegion;
|
|
19
21
|
if(original.width!==item.w||original.height!==item.h)throw new Error('PARTS_COMMENT_IMAGE_SIZE: original dimensions differ from placement');
|
package/src/parts-comparison.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/** Visual comparison settings are evidence, never a producer verdict. Older comments omit them. */
|
|
2
|
-
export
|
|
2
|
+
export type PartsComparison = {mode:'part'|'overlay';opacity:number} | {mode:'difference';opacity:number;threshold:number};
|
|
3
3
|
export const defaultPartsComparison = ():PartsComparison => ({mode:'part',opacity:.5});
|
|
4
4
|
export function parsePartsComparison(raw:unknown):PartsComparison {
|
|
5
5
|
const v=raw as PartsComparison;
|
|
6
|
-
|
|
6
|
+
const keys=v?.mode==='difference'?['mode','opacity','threshold']:['mode','opacity'];
|
|
7
|
+
if(!v||typeof v!=='object'||Array.isArray(v)||Object.keys(v).length!==keys.length||!keys.every(k=>Object.hasOwn(v,k))||!['part','overlay','difference'].includes(v.mode)||typeof v.opacity!=='number'||!Number.isFinite(v.opacity)||v.opacity<0||v.opacity>1||v.mode==='difference'&&(!Number.isInteger(v.threshold)||v.threshold<0||v.threshold>255))throw new Error('PARTS_COMPARISON_INVALID: part/overlay with opacity 0..1, or difference with integer threshold 0..255 required');
|
|
7
8
|
return v;
|
|
8
9
|
}
|
|
9
10
|
export interface PaintingRectangle {x:number;y:number;width:number;height:number}
|
|
@@ -18,3 +19,25 @@ export function paintingRectangle(item:{x:number;y:number;w:number;h:number},rig
|
|
|
18
19
|
const x=painting.width/rigSize[0]!,y=painting.height/rigSize[1]!;
|
|
19
20
|
return {x:item.x*x,y:item.y*y,width:item.w*x,height:item.h*y};
|
|
20
21
|
}
|
|
22
|
+
|
|
23
|
+
export interface DifferenceRaster {width:number;height:number;data:Uint8Array}
|
|
24
|
+
export interface DifferenceBox {x:number;y:number;w:number;h:number}
|
|
25
|
+
/** Exact native-cell pairing only. No placement rounding, filtering or alpha premultiplication. */
|
|
26
|
+
export function differencePixels(part:DifferenceRaster,box:DifferenceBox,painting:DifferenceRaster,fronts:readonly {box:DifferenceBox;raster:DifferenceRaster}[],threshold:number,excludeCovered:boolean) {
|
|
27
|
+
if(!Number.isInteger(threshold)||threshold<0||threshold>255)throw new Error('PARTS_COMPARISON_INVALID: integer threshold 0..255 required');
|
|
28
|
+
const valid=(b:DifferenceBox,r:DifferenceRaster)=>[b.x,b.y,b.w,b.h].every(Number.isSafeInteger)&&b.w===r.width&&b.h===r.height&&r.data.length===r.width*r.height*4;
|
|
29
|
+
if(!valid(box,part)||(excludeCovered&&fronts.some(f=>!valid(f.box,f.raster))))throw new Error('PARTS_DIFFERENCE_ALIGNMENT: integer native placement and exact PNG dimensions required');
|
|
30
|
+
const rgba=new Uint8Array(part.width*part.height*4);let count=0,covered=0,compared=0;
|
|
31
|
+
for(let y=0;y<part.height;y++)for(let x=0;x<part.width;x++){
|
|
32
|
+
const i=(y*part.width+x)*4;if(!part.data[i+3])continue;
|
|
33
|
+
const gx=box.x+x,gy=box.y+y;
|
|
34
|
+
if(gx<0||gy<0||gx>=painting.width||gy>=painting.height)throw new Error('PARTS_DIFFERENCE_ALIGNMENT: nontransparent part pixel lies outside declared rig grid');
|
|
35
|
+
if(excludeCovered&&fronts.some(f=>{const fx=gx-f.box.x,fy=gy-f.box.y;return fx>=0&&fy>=0&&fx<f.raster.width&&fy<f.raster.height&&f.raster.data[(fy*f.raster.width+fx)*4+3]!>0;})){
|
|
36
|
+
rgba.set([128,128,128,255],i);covered++;continue;
|
|
37
|
+
}
|
|
38
|
+
const j=(gy*painting.width+gx)*4,d=Math.max(...[0,1,2].map(c=>Math.abs(part.data[i+c]!-painting.data[j+c]!)));
|
|
39
|
+
compared++;if(d>threshold)count++;
|
|
40
|
+
rgba.set([d>threshold?d:0,0,0,255],i);
|
|
41
|
+
}
|
|
42
|
+
return {width:part.width,height:part.height,data:rgba,count,covered,compared};
|
|
43
|
+
}
|
package/src/parts-server.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/** Serves the parts and atlas view (#348): the page, its bundle, the part and page images by index, and the sign-off. */
|
|
2
|
+
import { PNG } from 'pngjs';
|
|
2
3
|
import { readFile } from 'node:fs/promises';
|
|
3
4
|
import { appRoot, buildWeb } from './build.ts';
|
|
4
5
|
import { accessGate } from './open-protocol.ts';
|
|
5
6
|
import { createLiveLifecycle, LIVE_PATH, type LiveExitInfo, type UpgradableServer } from './live-lifecycle.ts';
|
|
6
7
|
import {preparePartsComment} from './parts-comment-crops.ts';
|
|
7
8
|
import {serveReference} from './reference.ts';
|
|
8
|
-
import { partsViewJson, exportPartsVerdict, assertPartsUnchanged, readVerdict, saveVerdict, servedImage, type PartsViewPackage } from './parts-view.ts';
|
|
9
|
+
import { partsDifference, partsViewJson, exportPartsVerdict, assertPartsUnchanged, readVerdict, saveVerdict, servedImage, type PartsViewPackage } from './parts-view.ts';
|
|
9
10
|
|
|
10
11
|
const headers = { 'X-Content-Type-Options': 'nosniff', 'Cache-Control': 'no-store', 'Content-Security-Policy': "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' blob: data:; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'" };
|
|
11
12
|
const json = (value: unknown, status = 200) => Response.json(value, { status, headers });
|
|
@@ -56,13 +57,21 @@ export async function startPartsServer(pkg: PartsViewPackage, options: PartsServ
|
|
|
56
57
|
try {
|
|
57
58
|
if (url.pathname === '/api/parts' && req.method === 'GET'){await assertPartsUnchanged(pkg);return json(partsViewJson(pkg,await readVerdict(pkg)));}
|
|
58
59
|
if(url.pathname==='/api/parts/comment'&&req.method==='POST'){if(req.headers.get('origin')!==origin)return json({error:'Same-origin Origin required'},403);await assertPartsUnchanged(pkg);return json({comment:await preparePartsComment(pkg,await bodyJson(req))});}
|
|
59
|
-
if(url.pathname==='/api/parts/export'&&req.method==='GET'){const saved=await readVerdict(pkg);if(!saved.verdict)return json({error:'PARTS_VERDICT_UNAVAILABLE: save a verdict first'},409);return new Response(exportPartsVerdict(saved.verdict,url.searchParams.get('format')==='issue'?'issue':'json'),{headers:{...headers,'Content-Type':url.searchParams.get('format')==='issue'?'text/markdown':'application/json'}});}
|
|
60
|
+
if(url.pathname==='/api/parts/export'&&req.method==='GET'){await assertPartsUnchanged(pkg);const saved=await readVerdict(pkg);if(!saved.verdict)return json({error:'PARTS_VERDICT_UNAVAILABLE: save a verdict first'},409);return new Response(exportPartsVerdict(saved.verdict,url.searchParams.get('format')==='issue'?'issue':'json'),{headers:{...headers,'Content-Type':url.searchParams.get('format')==='issue'?'text/markdown':'application/json'}});}
|
|
60
61
|
if (url.pathname === '/api/parts/verdict' && req.method === 'POST') {
|
|
61
62
|
if (req.headers.get('origin') !== origin) return json({ error: 'Same-origin Origin required' }, 403);
|
|
62
63
|
saving = true;
|
|
63
64
|
try { return json({ verdict: await saveVerdict(pkg, await bodyJson(req)) }); } finally { saving = false; }
|
|
64
65
|
}
|
|
65
66
|
if(url.pathname==='/api/parts/painting'&&req.method==='GET'){if(!pkg.painting)return json({error:'PARTS_REFERENCE_UNAVAILABLE: supply --painting to compare the original painting'},404);return serveReference(req,pkg.painting.abs,pkg.painting.sha256,headers);}
|
|
67
|
+
const difference=/^\/api\/parts\/difference\/(\d+)$/.exec(url.pathname);
|
|
68
|
+
if(difference&&req.method==='GET'){
|
|
69
|
+
const t=url.searchParams.get('threshold'),f=url.searchParams.get('footprints');
|
|
70
|
+
if(!t||!/^\d{1,3}$/.test(t)||!['true','false'].includes(f??''))throw new Error('PARTS_COMPARISON_INVALID: threshold and footprints required');
|
|
71
|
+
const r=await partsDifference(pkg,Number(difference[1]),Number(t),f==='true');
|
|
72
|
+
const png=new PNG({width:r.width,height:r.height});png.data=Buffer.from(r.data);
|
|
73
|
+
return new Response(new Uint8Array(PNG.sync.write(png)),{headers:{...headers,'Content-Type':'image/png','X-Difference-Count':String(r.count),'X-Difference-Covered':String(r.covered),'X-Difference-Compared':String(r.compared)}});
|
|
74
|
+
}
|
|
66
75
|
const image = /^\/api\/parts\/(image|page)\/(\d+)$/.exec(url.pathname);
|
|
67
76
|
if (image && (req.method === 'GET' || req.method === 'HEAD')) {
|
|
68
77
|
const path = servedImage(pkg, image[1] as 'image' | 'page', Number(image[2]));
|