@rig-c/review 2.4.6 → 2.6.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/PARTS_VIEW.md +82 -3
- package/docs/REVIEW_PACKAGE.md +16 -1
- package/docs/STABILITY.md +2 -0
- package/docs/WORKFLOWS.md +37 -1
- package/package.json +1 -1
- package/src/cli.ts +52 -7
- package/src/comment-crops.ts +48 -3
- package/src/entry.ts +1 -0
- package/src/job-act.ts +59 -4
- package/src/job-api.ts +21 -6
- package/src/job-cli.ts +391 -28
- package/src/job-contract.ts +57 -1
- package/src/job-host.ts +4 -0
- package/src/job-session.ts +31 -4
- package/src/job-store.ts +28 -0
- package/src/parts-server.ts +46 -7
- package/src/parts-view.ts +76 -14
- package/web/catalog-en.ts +15 -0
- package/web/catalog-ko.ts +15 -0
- package/web/job-rig-capture.ts +211 -0
- package/web/job-session.ts +357 -23
- package/web/parts.ts +6 -1
- package/web/styles.css +14 -0
- package/web/viewport-capture.ts +119 -17
package/src/job-store.ts
CHANGED
|
@@ -42,6 +42,16 @@ export interface JobSnapshotTombstone {
|
|
|
42
42
|
readonly reason: 'closed' | 'superseded';
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
export interface JobStoredStill {
|
|
46
|
+
readonly actId: string;
|
|
47
|
+
readonly pageId: string;
|
|
48
|
+
readonly submissionId: string;
|
|
49
|
+
readonly sha256: string;
|
|
50
|
+
readonly binding: string;
|
|
51
|
+
readonly png: Uint8Array;
|
|
52
|
+
readonly actBytes: Uint8Array;
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
interface JobRow {
|
|
46
56
|
job_id: string;
|
|
47
57
|
root_key: string;
|
|
@@ -143,6 +153,11 @@ export class JobStore<Data> {
|
|
|
143
153
|
job_id TEXT NOT NULL, publication_id TEXT NOT NULL, snapshot_hash TEXT NOT NULL,
|
|
144
154
|
reclaimed_at TEXT NOT NULL, reason TEXT NOT NULL CHECK(reason IN ('closed','superseded')),
|
|
145
155
|
PRIMARY KEY(job_id, publication_id)
|
|
156
|
+
);
|
|
157
|
+
CREATE TABLE IF NOT EXISTS job_act_stills (
|
|
158
|
+
job_id TEXT NOT NULL, act_id TEXT NOT NULL, page_id TEXT NOT NULL, submission_id TEXT NOT NULL,
|
|
159
|
+
sha256 TEXT NOT NULL, binding TEXT NOT NULL, png BLOB NOT NULL, act_bytes BLOB NOT NULL,
|
|
160
|
+
PRIMARY KEY(job_id, act_id), UNIQUE(job_id, page_id, submission_id)
|
|
146
161
|
);`);
|
|
147
162
|
} catch {
|
|
148
163
|
throw new JobError('JOB_STORAGE_FAILED', 'Private job storage could not be opened');
|
|
@@ -207,6 +222,7 @@ export class JobStore<Data> {
|
|
|
207
222
|
readonly data: Data;
|
|
208
223
|
readonly active?: boolean;
|
|
209
224
|
readonly snapshot?: JobSnapshotOwner;
|
|
225
|
+
readonly still?: JobStoredStill;
|
|
210
226
|
}, replay?: (current: StoredJob<Data>) => boolean): StoredJob<Data> {
|
|
211
227
|
return this.transaction(() => {
|
|
212
228
|
const current = this.get(jobId);
|
|
@@ -221,12 +237,24 @@ export class JobStore<Data> {
|
|
|
221
237
|
(job_id,publication_id,snapshot_hash,snapshot_root,dev,ino) VALUES(?,?,?,?,?,?)`)
|
|
222
238
|
.run(jobId, snapshot.publicationId, snapshot.snapshotHash, snapshot.snapshotRoot, snapshot.dev, snapshot.ino);
|
|
223
239
|
}
|
|
240
|
+
if (next.still) {
|
|
241
|
+
const still = next.still;
|
|
242
|
+
this.db.query(`INSERT INTO job_act_stills
|
|
243
|
+
(job_id,act_id,page_id,submission_id,sha256,binding,png,act_bytes) VALUES(?,?,?,?,?,?,?,?)`)
|
|
244
|
+
.run(jobId, still.actId, still.pageId, still.submissionId, still.sha256, still.binding, still.png, still.actBytes);
|
|
245
|
+
}
|
|
224
246
|
this.db.query('UPDATE jobs SET revision=?,active=?,document=? WHERE job_id=?')
|
|
225
247
|
.run(current.revision + 1, active ? 1 : 0, document, jobId);
|
|
226
248
|
return this.get(jobId);
|
|
227
249
|
});
|
|
228
250
|
}
|
|
229
251
|
|
|
252
|
+
readStill(jobId: string, actId: string): Pick<JobStoredStill, 'sha256' | 'png' | 'actBytes'> | null {
|
|
253
|
+
return this.db.query<{sha256: string; png: Uint8Array; actBytes: Uint8Array}, [string, string]>(
|
|
254
|
+
'SELECT sha256,png,act_bytes AS actBytes FROM job_act_stills WHERE job_id=? AND act_id=?',
|
|
255
|
+
).get(jobId, actId);
|
|
256
|
+
}
|
|
257
|
+
|
|
230
258
|
/** Close never grows or rewrites the bounded historical document. */
|
|
231
259
|
sealClose(jobId: string, expectedRevision: number,
|
|
232
260
|
replay: (current: StoredJob<Data>) => Pick<JobClosure, 'replay'> | null,
|
package/src/parts-server.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { accessGate } from './open-protocol.ts';
|
|
|
6
6
|
import { createLiveLifecycle, LIVE_PATH, type LiveExitInfo, type UpgradableServer } from './live-lifecycle.ts';
|
|
7
7
|
import {preparePartsComment} from './parts-comment-crops.ts';
|
|
8
8
|
import {serveReference} from './reference.ts';
|
|
9
|
-
import { partsDifference, partsViewJson, exportPartsVerdict, assertPartsUnchanged, readVerdict,
|
|
9
|
+
import { partsDifference, partsViewJson, exportPartsVerdict, assertPartsUnchanged, readVerdict, saveVerdictWithReceipt, servedImage, type PartsViewPackage, type PartsSaveReceipt } from './parts-view.ts';
|
|
10
10
|
|
|
11
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'" };
|
|
12
12
|
const json = (value: unknown, status = 200) => Response.json(value, { status, headers });
|
|
@@ -36,13 +36,47 @@ async function bodyJson(req: Request): Promise<unknown> {
|
|
|
36
36
|
return JSON.parse(new TextDecoder().decode(body));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export interface
|
|
39
|
+
export interface PartsSavedEvent extends PartsSaveReceipt { saveCount: number }
|
|
40
|
+
export interface PartsServerOptions {
|
|
41
|
+
port?: number; capability?: string; exitOnClose?: boolean; graceMs?: number; unopenedTimeoutMs?: number;
|
|
42
|
+
onClose?: (info: LiveExitInfo) => void | Promise<void>; log?: (line: string) => void;
|
|
43
|
+
by?: string;
|
|
44
|
+
onSaved?: (event: PartsSavedEvent) => Promise<void>;
|
|
45
|
+
onNotifyFailure?: (error: Error) => void;
|
|
46
|
+
onWriteFailure?: (error: Error) => void;
|
|
47
|
+
}
|
|
40
48
|
|
|
41
49
|
export async function startPartsServer(pkg: PartsViewPackage, options: PartsServerOptions = {}) {
|
|
50
|
+
const by = options.by;
|
|
51
|
+
if (by !== undefined && (typeof by !== 'string' || !by.trim())) throw new Error('PARTS_VERDICT_INVALID: reviewer name must be nonblank');
|
|
42
52
|
const bundle = await buildWeb('parts');
|
|
43
53
|
let rawStop: ((closeActiveConnections?: boolean) => void) | null = null;
|
|
44
|
-
let
|
|
45
|
-
|
|
54
|
+
let pendingSaves = 0, saveCount = 0;
|
|
55
|
+
let saveQueue: Promise<void> = Promise.resolve();
|
|
56
|
+
let closing = false;
|
|
57
|
+
let notifyFailure: Error | null = null;
|
|
58
|
+
const live = createLiveLifecycle({ label: 'review parts', graceMs: options.graceMs, unopenedTimeoutMs: options.unopenedTimeoutMs, exitOnClose: options.exitOnClose, onClose: options.onClose, log: options.log, busy: () => pendingSaves > 0, stopServer: () => { rawStop?.(true); } });
|
|
59
|
+
const save = (req: Request) => {
|
|
60
|
+
if (closing) throw new Error('PARTS_VERDICT_WRITE_FAILED: server is closing');
|
|
61
|
+
pendingSaves++;
|
|
62
|
+
const result = saveQueue.then(async () => {
|
|
63
|
+
if (notifyFailure) throw notifyFailure;
|
|
64
|
+
if (saveCount === Number.MAX_SAFE_INTEGER) throw new Error('PARTS_VERDICT_WRITE_FAILED: save count exhausted');
|
|
65
|
+
const {verdict, receipt} = await saveVerdictWithReceipt(pkg, await bodyJson(req), undefined, by);
|
|
66
|
+
const event = {...receipt, saveCount: ++saveCount};
|
|
67
|
+
try { await options.onSaved?.(event); }
|
|
68
|
+
catch (error) {
|
|
69
|
+
notifyFailure = new Error('PARTS_VERDICT_NOTIFY_FAILED: durable save notification failed', {cause: error});
|
|
70
|
+
options.onNotifyFailure?.(notifyFailure);
|
|
71
|
+
throw notifyFailure;
|
|
72
|
+
}
|
|
73
|
+
return verdict;
|
|
74
|
+
});
|
|
75
|
+
saveQueue = result.then(() => {}, error => {
|
|
76
|
+
if (error instanceof Error && error.message.startsWith('PARTS_VERDICT_WRITE_FAILED:')) options.onWriteFailure?.(error);
|
|
77
|
+
}).finally(() => { pendingSaves--; });
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
46
80
|
const handle = async (req: Request, port: number | undefined, srv: UpgradableServer): Promise<Response | undefined> => {
|
|
47
81
|
try {
|
|
48
82
|
const url = new URL(req.url), origin = `http://127.0.0.1:${port}`;
|
|
@@ -60,8 +94,7 @@ export async function startPartsServer(pkg: PartsViewPackage, options: PartsServ
|
|
|
60
94
|
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'}});}
|
|
61
95
|
if (url.pathname === '/api/parts/verdict' && req.method === 'POST') {
|
|
62
96
|
if (req.headers.get('origin') !== origin) return json({ error: 'Same-origin Origin required' }, 403);
|
|
63
|
-
|
|
64
|
-
try { return json({ verdict: await saveVerdict(pkg, await bodyJson(req)) }); } finally { saving = false; }
|
|
97
|
+
return json({ verdict: await save(req) });
|
|
65
98
|
}
|
|
66
99
|
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
100
|
const difference=/^\/api\/parts\/difference\/(\d+)$/.exec(url.pathname);
|
|
@@ -92,5 +125,11 @@ export async function startPartsServer(pkg: PartsViewPackage, options: PartsServ
|
|
|
92
125
|
const server = Bun.serve({ hostname: '127.0.0.1', port: options.port ?? 4317, websocket: live.websocket, async fetch(req, srv) { const res = await handle(req, srv.port, srv); return res as Response; } });
|
|
93
126
|
rawStop = server.stop.bind(server);
|
|
94
127
|
server.stop = ((closeActiveConnections?: boolean) => { live.stop(); return rawStop!(closeActiveConnections); }) as typeof server.stop;
|
|
95
|
-
|
|
128
|
+
const shutdown = async () => {
|
|
129
|
+
closing = true;
|
|
130
|
+
await saveQueue;
|
|
131
|
+
live.stop();
|
|
132
|
+
await server.stop(false);
|
|
133
|
+
};
|
|
134
|
+
return Object.assign(server, { live, shutdown });
|
|
96
135
|
}
|
package/src/parts-view.ts
CHANGED
|
@@ -21,13 +21,14 @@ import {preparePartsComment,validateStoredPartsComment} from './parts-comment-cr
|
|
|
21
21
|
import {resolvedCropPath} from './comment-crops.ts';
|
|
22
22
|
import { createHash } from 'node:crypto';
|
|
23
23
|
import { existsSync } from 'node:fs';
|
|
24
|
-
import { mkdir, readFile, realpath, rename, rm, stat
|
|
24
|
+
import { mkdir, open, readFile, realpath, rename, rm, stat } from 'node:fs/promises';
|
|
25
25
|
import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
26
26
|
import { PNG } from 'pngjs';
|
|
27
27
|
import { loadReview, safeFile, packagePath, type ReviewPackage } from './manifest.ts';
|
|
28
28
|
import { destinationDirectory } from './destination-directory.ts';
|
|
29
29
|
|
|
30
30
|
export const PARTS_VERDICT_SCHEMA = 'rig-review-parts-verdict/2';
|
|
31
|
+
const NAMED_VERDICT_SCHEMA = 'rig-review-parts-verdict/3';
|
|
31
32
|
export const PARTS_VERDICT_FILE = 'parts-review.json';
|
|
32
33
|
export const PARTS_NOTE_LIMIT = 10000;
|
|
33
34
|
export type PartsViewMode = 'parts' | 'atlas';
|
|
@@ -553,8 +554,20 @@ async function packageVersion(): Promise<string> {
|
|
|
553
554
|
return (JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8')) as { version: string }).version;
|
|
554
555
|
}
|
|
555
556
|
|
|
556
|
-
|
|
557
|
-
|
|
557
|
+
async function verdictWrite<T>(operation: string, action: () => Promise<T>): Promise<T> {
|
|
558
|
+
try { return await action(); }
|
|
559
|
+
catch (error) {
|
|
560
|
+
const code = (error as NodeJS.ErrnoException).code ?? 'IO';
|
|
561
|
+
throw new Error(`PARTS_VERDICT_WRITE_FAILED: ${operation} (${code})`, {cause: error});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export interface PartsSaveReceipt { verdictPath: string; sha256: string; status: VerdictStatus }
|
|
566
|
+
|
|
567
|
+
/** One durable buffer, shared by standalone and joined saves. Attribution is launch configuration only. */
|
|
568
|
+
export async function saveVerdictWithReceipt(pkg: PartsViewPackage, input: unknown,
|
|
569
|
+
assertCurrent?: () => Promise<void>, by?: string): Promise<{verdict: PartsVerdict; receipt: PartsSaveReceipt}> {
|
|
570
|
+
if (by !== undefined && (typeof by !== 'string' || !by.trim())) refuse('PARTS_VERDICT_INVALID', 'reviewer name must be nonblank');
|
|
558
571
|
await assertCurrent?.();
|
|
559
572
|
await assertVerdictDestination(pkg);
|
|
560
573
|
await assertPartsUnchanged(pkg);
|
|
@@ -562,14 +575,37 @@ export async function saveVerdict(pkg: PartsViewPackage, input: unknown, assertC
|
|
|
562
575
|
const verdict = buildVerdict(pkg, input, await packageVersion());
|
|
563
576
|
for(const comment of verdict.comments)await preparePartsComment(pkg,comment,true);
|
|
564
577
|
await assertPartsUnchanged(pkg);
|
|
565
|
-
|
|
578
|
+
const stored = by === undefined ? verdict : {...verdict, schema: NAMED_VERDICT_SCHEMA, by};
|
|
579
|
+
const bytes = Buffer.from(JSON.stringify(stored, null, 2) + '\n');
|
|
580
|
+
const parent = dirname(pkg.verdictPath);
|
|
581
|
+
const firstCreated = await verdictWrite('mkdir', () => mkdir(parent, { recursive: true }));
|
|
566
582
|
const tmp = `${pkg.verdictPath}.${crypto.randomUUID()}.tmp`;
|
|
567
583
|
try {
|
|
568
|
-
await
|
|
584
|
+
await verdictWrite('write/fsync', async () => {
|
|
585
|
+
const file = await open(tmp, 'wx');
|
|
586
|
+
try { await file.writeFile(bytes); await file.sync(); }
|
|
587
|
+
finally { await file.close(); }
|
|
588
|
+
});
|
|
569
589
|
await assertVerdictDestination(pkg);
|
|
570
590
|
await assertCurrent?.();
|
|
571
|
-
await
|
|
572
|
-
|
|
591
|
+
await assertPartsUnchanged(pkg);
|
|
592
|
+
await verdictWrite('rename', () => rename(tmp, pkg.verdictPath));
|
|
593
|
+
// Flush the file's entry and every newly created directory's entry in its parent.
|
|
594
|
+
const last = firstCreated ? dirname(firstCreated) : parent;
|
|
595
|
+
for (let directory = parent; ; directory = dirname(directory)) {
|
|
596
|
+
await verdictWrite('directory fsync', async () => {
|
|
597
|
+
const handle = await open(directory, 'r');
|
|
598
|
+
try { await handle.sync(); } finally { await handle.close(); }
|
|
599
|
+
});
|
|
600
|
+
if (directory === last) break;
|
|
601
|
+
}
|
|
602
|
+
} finally { await verdictWrite('temporary cleanup', () => rm(tmp, { force: true })); }
|
|
603
|
+
return {verdict, receipt: {verdictPath: pkg.verdictPath, sha256: createHash('sha256').update(bytes).digest('hex'), status: verdict.status}};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/** Shared callers retain the ordinary normalized verdict and produce no save notification. */
|
|
607
|
+
export async function saveVerdict(pkg: PartsViewPackage, input: unknown, assertCurrent?: () => Promise<void>): Promise<PartsVerdict> {
|
|
608
|
+
const {verdict} = await saveVerdictWithReceipt(pkg, input, assertCurrent);
|
|
573
609
|
return verdict;
|
|
574
610
|
}
|
|
575
611
|
|
|
@@ -581,16 +617,42 @@ export type VerdictStale = 'files' | 'flags' | null;
|
|
|
581
617
|
* `source.sha256` alone; the page also requires `source.flags`, so a reviewer never sees a sign-off over flags they
|
|
582
618
|
* were not shown.
|
|
583
619
|
*/
|
|
584
|
-
|
|
620
|
+
async function readVerdictSnapshot(pkg: PartsViewPackage): Promise<{
|
|
621
|
+
verdict: PartsVerdict | null; stale: VerdictStale; by: string | null; savedFileSha256: string | null;
|
|
622
|
+
}> {
|
|
585
623
|
let raw: unknown;
|
|
586
|
-
|
|
587
|
-
|
|
624
|
+
const unavailable = {verdict: null, by: null, savedFileSha256: null};
|
|
625
|
+
let bytes: Buffer;
|
|
626
|
+
try { bytes = await readFile(pkg.verdictPath); }
|
|
627
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code === 'ENOENT') return {...unavailable, stale: null}; throw new Error('PARTS_VERDICT_READ: saved verdict cannot be read'); }
|
|
628
|
+
try{raw=JSON.parse(bytes.toString('utf8'));}catch{throw new Error('PARTS_VERDICT_INVALID: saved verdict is not valid JSON');}
|
|
588
629
|
const v = record(raw), source = record(v?.source), now = verdictSource(pkg);
|
|
589
|
-
if(!v||![PARTS_VERDICT_SCHEMA,'rig-review-parts-verdict/1'].includes(String(v.schema))||typeof source?.sha256!=='string')throw new Error('PARTS_VERDICT_INVALID: saved verdict schema or binding is invalid');
|
|
590
|
-
|
|
591
|
-
if (
|
|
630
|
+
if(!v||![PARTS_VERDICT_SCHEMA,'rig-review-parts-verdict/1',NAMED_VERDICT_SCHEMA].includes(String(v.schema))||typeof source?.sha256!=='string')throw new Error('PARTS_VERDICT_INVALID: saved verdict schema or binding is invalid');
|
|
631
|
+
let by: string | null = null;
|
|
632
|
+
if (v.schema === NAMED_VERDICT_SCHEMA) {
|
|
633
|
+
if (typeof v.by !== 'string' || !v.by.trim()) refuse('PARTS_VERDICT_INVALID', 'saved reviewer name must be nonblank');
|
|
634
|
+
by = v.by as string;
|
|
635
|
+
}
|
|
636
|
+
if(v.mode!==pkg.mode||source.sha256!==now.sha256)return {...unavailable,stale:'files'};
|
|
637
|
+
if (JSON.stringify(source.flags) !== JSON.stringify(now.flags)) return { ...unavailable, stale: 'flags' };
|
|
592
638
|
const date=new Date(String(v.updatedAt));if(!Number.isFinite(date.getTime()))throw new Error('PARTS_VERDICT_INVALID: saved verdict date is invalid');
|
|
593
|
-
const normalized=buildVerdict(pkg,{...v,comments:v.schema==='rig-review-parts-verdict/1'?[]:v.comments},String(record(v.tool)?.version??''),date);
|
|
639
|
+
const normalized=buildVerdict(pkg,{...v,comments:v.schema==='rig-review-parts-verdict/1'?[]:v.comments},String(record(v.tool)?.version??''),date);
|
|
640
|
+
for(const c of normalized.comments)await validateStoredPartsComment(pkg,c);
|
|
641
|
+
return {verdict:normalized,stale:null,by,savedFileSha256:createHash('sha256').update(bytes).digest('hex')};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/** Explicitly project the shared response so retrieval metadata cannot escape through joined wrappers. */
|
|
645
|
+
export async function readVerdict(pkg: PartsViewPackage): Promise<{verdict: PartsVerdict | null; stale: VerdictStale}> {
|
|
646
|
+
const {verdict, stale} = await readVerdictSnapshot(pkg);
|
|
647
|
+
return {verdict, stale};
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/** Standalone CLI retrieval metadata and content come from one validated saved-file buffer. */
|
|
651
|
+
export async function readPartsVerdictJson(pkg: PartsViewPackage): Promise<string> {
|
|
652
|
+
const saved = await readVerdictSnapshot(pkg);
|
|
653
|
+
if (!saved.verdict) refuse('PARTS_VERDICT_UNAVAILABLE', 'save a verdict first');
|
|
654
|
+
await assertPartsUnchanged(pkg);
|
|
655
|
+
return JSON.stringify({...JSON.parse(exportPartsVerdict(saved.verdict!, 'json')), by: saved.by, savedFileSha256: saved.savedFileSha256}, null, 2) + '\n';
|
|
594
656
|
}
|
|
595
657
|
|
|
596
658
|
/** What the page reads: no absolute path leaves the server but the verdict file's name. */
|
package/web/catalog-en.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export const enCatalog: Readonly<Record<string, string>> = {
|
|
2
|
+
"JOB_STILL_CAPTURE_FAILED": "JOB_STILL_CAPTURE_FAILED · The displayed Rig frame could not be captured. Wait for a successful draw and try again.",
|
|
3
|
+
"JOB_STILL_CAMERA_NOT_FIXED": "JOB_STILL_CAMERA_NOT_FIXED · Restore the default Rig framing before submitting this verdict.",
|
|
4
|
+
"JOB_STILL_VIEW_UNSUPPORTED": "JOB_STILL_VIEW_UNSUPPORTED · Show the whole Rig without solo, highlight or comparison layers before submitting.",
|
|
5
|
+
"JOB_STILL_BINDING_MISMATCH": "JOB_STILL_BINDING_MISMATCH · The displayed source, page or drawn frame changed. Start a new verdict attempt.",
|
|
6
|
+
"JOB_STILL_UNAVAILABLE": "JOB_STILL_UNAVAILABLE · This historical or non-rig act has no retained Rig PNG.",
|
|
7
|
+
"JOB_STILL_OUTPUT_FAILED": "JOB_STILL_OUTPUT_FAILED · The consumer could not finish writing the Rig PNG or act output.",
|
|
2
8
|
"WORKSPACE_BODY_TIMEOUT": "WORKSPACE_BODY_TIMEOUT",
|
|
3
9
|
"rig-review-target/1": "rig-review-target/1",
|
|
4
10
|
"Review workspace": "Review workspace",
|
|
@@ -3280,6 +3286,15 @@ export const enCatalog: Readonly<Record<string, string>> = {
|
|
|
3280
3286
|
"PARTS_VERDICT_INVALID: saved verdict is not valid JSON": "PARTS_VERDICT_INVALID: saved verdict is not valid JSON",
|
|
3281
3287
|
"PARTS_VERDICT_INVALID: saved verdict schema or binding is invalid": "PARTS_VERDICT_INVALID: saved verdict schema or binding is invalid",
|
|
3282
3288
|
"PARTS_VERDICT_INVALID: saved verdict date is invalid": "PARTS_VERDICT_INVALID: saved verdict date is invalid",
|
|
3289
|
+
"PARTS_VERDICT_INVALID: reviewer name must be nonblank": "PARTS_VERDICT_INVALID: reviewer name must be nonblank",
|
|
3290
|
+
"PARTS_VERDICT_INVALID: saved reviewer name must be nonblank": "PARTS_VERDICT_INVALID: saved reviewer name must be nonblank",
|
|
3291
|
+
"PARTS_VERDICT_WRITE_FAILED: {0} ({1})": "PARTS_VERDICT_WRITE_FAILED: {0} ({1})",
|
|
3292
|
+
"PARTS_VERDICT_WRITE_FAILED: server is closing": "PARTS_VERDICT_WRITE_FAILED: server is closing",
|
|
3293
|
+
"PARTS_VERDICT_WRITE_FAILED: save count exhausted": "PARTS_VERDICT_WRITE_FAILED: save count exhausted",
|
|
3294
|
+
"PARTS_VERDICT_NOTIFY_FAILED: durable save notification failed": "PARTS_VERDICT_NOTIFY_FAILED: durable save notification failed",
|
|
3295
|
+
"PARTS_VERDICT_NOTIFY_FAILED: stdout failed": "PARTS_VERDICT_NOTIFY_FAILED: stdout failed",
|
|
3296
|
+
"--by: expected a nonblank reviewer name": "--by: expected a nonblank reviewer name",
|
|
3297
|
+
"--by: launch only; incompatible with export or correction options": "--by: launch only; incompatible with export or correction options",
|
|
3283
3298
|
"Painting comparison": "Painting comparison",
|
|
3284
3299
|
"Overlay": "Overlay",
|
|
3285
3300
|
"Part opacity": "Part opacity",
|
package/web/catalog-ko.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export const koCatalog: Readonly<Record<string, string>> = {
|
|
2
|
+
"JOB_STILL_CAPTURE_FAILED": "JOB_STILL_CAPTURE_FAILED · 표시된 리그 프레임을 캡처하지 못했습니다. 정상적으로 그려진 뒤 다시 시도하세요.",
|
|
3
|
+
"JOB_STILL_CAMERA_NOT_FIXED": "JOB_STILL_CAMERA_NOT_FIXED · 판정을 제출하기 전에 리그를 기본 화면 구도로 되돌리세요.",
|
|
4
|
+
"JOB_STILL_VIEW_UNSUPPORTED": "JOB_STILL_VIEW_UNSUPPORTED · 단독 표시·강조·비교 레이어를 해제하고 전체 리그를 표시한 뒤 제출하세요.",
|
|
5
|
+
"JOB_STILL_BINDING_MISMATCH": "JOB_STILL_BINDING_MISMATCH · 표시된 소스·페이지·그려진 프레임이 바뀌었습니다. 새 판정 시도를 시작하세요.",
|
|
6
|
+
"JOB_STILL_UNAVAILABLE": "JOB_STILL_UNAVAILABLE · 이 과거 기록 또는 리그 외 판정에는 보관된 리그 PNG가 없습니다.",
|
|
7
|
+
"JOB_STILL_OUTPUT_FAILED": "JOB_STILL_OUTPUT_FAILED · 소비자가 리그 PNG 또는 판정 출력을 끝까지 기록하지 못했습니다.",
|
|
2
8
|
"WORKSPACE_BODY_TIMEOUT": "WORKSPACE_BODY_TIMEOUT",
|
|
3
9
|
"rig-review-target/1": "rig-review-target/1",
|
|
4
10
|
"Review workspace": "검토 작업 공간",
|
|
@@ -3280,6 +3286,15 @@ export const koCatalog: Readonly<Record<string, string>> = {
|
|
|
3280
3286
|
"PARTS_VERDICT_INVALID: saved verdict is not valid JSON": "PARTS_VERDICT_INVALID: 저장된 판정이 올바른 JSON이 아니에요",
|
|
3281
3287
|
"PARTS_VERDICT_INVALID: saved verdict schema or binding is invalid": "PARTS_VERDICT_INVALID: 저장된 판정의 스키마나 원본 연결이 잘못됐어요",
|
|
3282
3288
|
"PARTS_VERDICT_INVALID: saved verdict date is invalid": "PARTS_VERDICT_INVALID: 저장된 판정의 날짜가 잘못됐어요",
|
|
3289
|
+
"PARTS_VERDICT_INVALID: reviewer name must be nonblank": "PARTS_VERDICT_INVALID: 검토자 이름은 공백이 아닌 문자열이어야 해요",
|
|
3290
|
+
"PARTS_VERDICT_INVALID: saved reviewer name must be nonblank": "PARTS_VERDICT_INVALID: 저장된 판정의 검토자 이름이 비어 있거나 잘못됐어요",
|
|
3291
|
+
"PARTS_VERDICT_WRITE_FAILED: {0} ({1})": "PARTS_VERDICT_WRITE_FAILED: 판정을 저장하지 못했어요 — {0} ({1})",
|
|
3292
|
+
"PARTS_VERDICT_WRITE_FAILED: server is closing": "PARTS_VERDICT_WRITE_FAILED: 서버가 종료 중이라 판정을 저장할 수 없어요",
|
|
3293
|
+
"PARTS_VERDICT_WRITE_FAILED: save count exhausted": "PARTS_VERDICT_WRITE_FAILED: 저장 횟수 한도에 도달해 판정을 저장할 수 없어요",
|
|
3294
|
+
"PARTS_VERDICT_NOTIFY_FAILED: durable save notification failed": "PARTS_VERDICT_NOTIFY_FAILED: 판정은 저장됐지만 저장 완료 알림을 전달하지 못했어요",
|
|
3295
|
+
"PARTS_VERDICT_NOTIFY_FAILED: stdout failed": "PARTS_VERDICT_NOTIFY_FAILED: 표준 출력(stdout)으로 저장 알림을 기록하지 못했어요",
|
|
3296
|
+
"--by: expected a nonblank reviewer name": "--by: 공백이 아닌 검토자 이름이 필요해요",
|
|
3297
|
+
"--by: launch only; incompatible with export or correction options": "--by: 실행 전용 옵션이라 내보내기 또는 수정 인계 옵션과 함께 쓸 수 없어요",
|
|
3283
3298
|
"Painting comparison": "원화 비교",
|
|
3284
3299
|
"Overlay": "오버레이",
|
|
3285
3300
|
"Part opacity": "파츠 불투명도",
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type {RigPlayer} from '@rig-c/play';
|
|
2
|
+
import {jobStillByteLimit, type JobRigCapture, type JobUISubmission} from '../src/job-contract.ts';
|
|
3
|
+
import type {JobRigPresentation} from './viewport-capture.ts';
|
|
4
|
+
|
|
5
|
+
type DrawSource = Pick<JobRigCapture['binding'], 'publicationId' | 'instanceKey' | 'sourceHash' | 'pageId'>;
|
|
6
|
+
export interface JobRigDrawState {
|
|
7
|
+
player: Pick<RigPlayer, 'generation' | 'current' | 'time' | 'slots' | 'entry'> & {readonly renderer: object};
|
|
8
|
+
frameGeneration: number | undefined;
|
|
9
|
+
presentation: JobRigPresentation | undefined;
|
|
10
|
+
source: DrawSource;
|
|
11
|
+
layout: string;
|
|
12
|
+
defaultCamera: boolean;
|
|
13
|
+
wholeRig: boolean;
|
|
14
|
+
playing: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface JobRigDraw {
|
|
17
|
+
readonly player: JobRigDrawState['player'];
|
|
18
|
+
readonly renderer: object;
|
|
19
|
+
readonly presentation: JobRigPresentation;
|
|
20
|
+
readonly playerGeneration: number;
|
|
21
|
+
readonly drawGeneration: number;
|
|
22
|
+
readonly animation: string | null;
|
|
23
|
+
readonly time: number;
|
|
24
|
+
readonly trackTime: number;
|
|
25
|
+
readonly loop: boolean;
|
|
26
|
+
readonly playing: boolean;
|
|
27
|
+
readonly source: DrawSource;
|
|
28
|
+
readonly layout: string;
|
|
29
|
+
}
|
|
30
|
+
export interface JobRigPixels {
|
|
31
|
+
readonly width: number;
|
|
32
|
+
readonly height: number;
|
|
33
|
+
encode(): Promise<string>;
|
|
34
|
+
}
|
|
35
|
+
export interface FrozenJobRigCapture {
|
|
36
|
+
encode(): Promise<JobRigCapture>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const sourceKey = (source: DrawSource) => JSON.stringify([
|
|
40
|
+
source.publicationId, source.instanceKey, source.sourceHash, source.pageId,
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
/** Bind local placement and physical-pixel phase while allowing whole-pixel page movement. */
|
|
44
|
+
export function jobRigPixelPlacement(pane: Pick<DOMRect, 'left' | 'top'>,
|
|
45
|
+
canvas: Pick<DOMRect, 'left' | 'top'>, ratio: number) {
|
|
46
|
+
function phase(coordinate: number): number {
|
|
47
|
+
const deviceCoordinate = coordinate * ratio;
|
|
48
|
+
return deviceCoordinate - Math.floor(deviceCoordinate);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
offsetX: canvas.left - pane.left,
|
|
52
|
+
offsetY: canvas.top - pane.top,
|
|
53
|
+
panePhaseX: phase(pane.left),
|
|
54
|
+
panePhaseY: phase(pane.top),
|
|
55
|
+
canvasPhaseX: phase(canvas.left),
|
|
56
|
+
canvasPhaseY: phase(canvas.top),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function readPlayerTiming(state: JobRigDrawState): {animation: string | null; time: number; trackTime: number; loop: boolean} {
|
|
61
|
+
if (!Number.isFinite(state.player.time) || state.player.time < 0 || typeof state.playing !== 'boolean' ||
|
|
62
|
+
typeof state.player.entry !== 'function') {
|
|
63
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
64
|
+
}
|
|
65
|
+
const entry = state.player.entry(0);
|
|
66
|
+
if (state.player.current === null) {
|
|
67
|
+
if (state.playing || state.player.time !== 0 ||
|
|
68
|
+
(entry !== null && (entry.animation !== null || entry.trackTime !== 0 || entry.animationTime !== 0))) {
|
|
69
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
70
|
+
}
|
|
71
|
+
return {animation: null, time: 0, trackTime: 0, loop: false};
|
|
72
|
+
}
|
|
73
|
+
if (typeof state.player.current !== 'string' || !state.player.current || !entry ||
|
|
74
|
+
typeof entry.animation !== 'string' || entry.animation !== state.player.current ||
|
|
75
|
+
typeof entry.loop !== 'boolean' || !Number.isFinite(entry.trackTime) || entry.trackTime < 0 ||
|
|
76
|
+
entry.trackTime !== state.player.time || !Number.isFinite(entry.duration) || entry.duration < 0 ||
|
|
77
|
+
!Number.isFinite(entry.animationTime) || entry.animationTime < 0 || entry.animationTime > entry.duration) {
|
|
78
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
79
|
+
}
|
|
80
|
+
return {animation: entry.animation, time: entry.animationTime, trackTime: entry.trackTime, loop: entry.loop};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function matchesDrawState(draw: JobRigDraw, state: JobRigDrawState): boolean {
|
|
84
|
+
if (draw.presentation !== state.presentation || draw.player !== state.player || draw.renderer !== state.player.renderer ||
|
|
85
|
+
draw.playerGeneration !== state.player.generation || state.frameGeneration !== draw.playerGeneration ||
|
|
86
|
+
draw.animation !== state.player.current || draw.trackTime !== state.player.time ||
|
|
87
|
+
draw.playing !== state.playing || draw.layout !== state.layout || sourceKey(draw.source) !== sourceKey(state.source)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const entry = state.player.entry(0);
|
|
91
|
+
if (draw.animation === null) {
|
|
92
|
+
return !draw.playing && !state.playing && draw.time === 0 && draw.trackTime === 0 && draw.loop === false && state.player.time === 0 &&
|
|
93
|
+
(entry === null || (entry.animation === null && entry.trackTime === 0 && entry.animationTime === 0));
|
|
94
|
+
}
|
|
95
|
+
return entry !== null && entry.animation === draw.animation && entry.loop === draw.loop &&
|
|
96
|
+
entry.trackTime === draw.trackTime && entry.animationTime === draw.time &&
|
|
97
|
+
Number.isFinite(entry.duration) && entry.duration >= 0 && draw.time >= 0 && draw.time <= entry.duration;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Called after the public draw/present and viewport-render boundaries succeed. */
|
|
101
|
+
export function recordJobRigDraw(state: JobRigDrawState, drawGeneration: number): JobRigDraw {
|
|
102
|
+
if (!state.presentation || state.frameGeneration !== state.player.generation || !Number.isSafeInteger(drawGeneration) || drawGeneration < 1 ||
|
|
103
|
+
!Number.isSafeInteger(state.player.generation) || state.player.generation < 0) {
|
|
104
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
105
|
+
}
|
|
106
|
+
const timing = readPlayerTiming(state);
|
|
107
|
+
return Object.freeze({
|
|
108
|
+
player: state.player,
|
|
109
|
+
renderer: state.player.renderer,
|
|
110
|
+
presentation: state.presentation,
|
|
111
|
+
playerGeneration: state.player.generation,
|
|
112
|
+
drawGeneration,
|
|
113
|
+
animation: timing.animation,
|
|
114
|
+
time: timing.time,
|
|
115
|
+
trackTime: timing.trackTime,
|
|
116
|
+
loop: timing.loop,
|
|
117
|
+
playing: state.playing,
|
|
118
|
+
source: Object.freeze({...state.source}),
|
|
119
|
+
layout: state.layout,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** copy() runs synchronously. The returned encoder owns an already copied bitmap. */
|
|
124
|
+
export function freezeJobRigCapture(draw: JobRigDraw | undefined, state: JobRigDrawState, askId: string,
|
|
125
|
+
copy: () => JobRigPixels): FrozenJobRigCapture {
|
|
126
|
+
if (!state.defaultCamera) throw new Error('JOB_STILL_CAMERA_NOT_FIXED');
|
|
127
|
+
if (!state.wholeRig || state.player.slots !== null) throw new Error('JOB_STILL_VIEW_UNSUPPORTED');
|
|
128
|
+
if (!draw || typeof state.player.entry !== 'function') throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
129
|
+
if (draw.animation !== null && !draw.animation) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
130
|
+
if (!matchesDrawState(draw, state)) {
|
|
131
|
+
throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
132
|
+
}
|
|
133
|
+
const pixels = copy();
|
|
134
|
+
if (!matchesDrawState(draw, state)) {
|
|
135
|
+
throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
136
|
+
}
|
|
137
|
+
if (!Number.isSafeInteger(pixels.width) || !Number.isSafeInteger(pixels.height) || pixels.width < 1 || pixels.height < 1 ||
|
|
138
|
+
pixels.width > 16384 || pixels.height > 16384 || pixels.width * pixels.height > 16777216) {
|
|
139
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
140
|
+
}
|
|
141
|
+
const metadata: Omit<JobRigCapture, 'png'> = {
|
|
142
|
+
width: pixels.width, height: pixels.height, camera: 'fixed', framing: 'default', view: 'whole-rig',
|
|
143
|
+
frame: draw.animation === null ? 'setup' : draw.time,
|
|
144
|
+
...(draw.animation === null ? {} : {animation: draw.animation}), playing: draw.playing,
|
|
145
|
+
binding: {...draw.source, askId, drawGeneration: draw.drawGeneration, playerGeneration: draw.playerGeneration},
|
|
146
|
+
};
|
|
147
|
+
return {async encode() {
|
|
148
|
+
const png = await pixels.encode();
|
|
149
|
+
if (!png.startsWith('data:image/png;base64,') || png.length > 22 + Math.ceil(jobStillByteLimit / 3) * 4) {
|
|
150
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
151
|
+
}
|
|
152
|
+
return {...metadata, png};
|
|
153
|
+
}};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Copy the committed display bitmap synchronously, before asynchronous PNG encoding. */
|
|
157
|
+
export function copyJobRigViewport(presentation: JobRigPresentation): JobRigPixels {
|
|
158
|
+
const {canvas: displayed, width, height, ratio} = presentation;
|
|
159
|
+
if (!displayed.isConnected || displayed.width !== width || displayed.height !== height ||
|
|
160
|
+
ratio !== (globalThis.devicePixelRatio || 1) || width < 1 || height < 1 ||
|
|
161
|
+
width > 16384 || height > 16384 || width * height > 16777216) {
|
|
162
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
163
|
+
}
|
|
164
|
+
const canvas = document.createElement('canvas');
|
|
165
|
+
canvas.width = width;
|
|
166
|
+
canvas.height = height;
|
|
167
|
+
try {
|
|
168
|
+
const source = displayed.getContext('2d');
|
|
169
|
+
const context = canvas.getContext('2d');
|
|
170
|
+
if (!source || !context) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
171
|
+
context.putImageData(source.getImageData(0, 0, width, height), 0, 0);
|
|
172
|
+
} catch { throw new Error('JOB_STILL_CAPTURE_FAILED'); }
|
|
173
|
+
return {width, height, encode: () => new Promise<string>((resolve, reject) => {
|
|
174
|
+
canvas.toBlob(blob => {
|
|
175
|
+
if (!blob || blob.size > jobStillByteLimit) {reject(new Error('JOB_STILL_CAPTURE_FAILED')); return;}
|
|
176
|
+
const reader = new FileReader();
|
|
177
|
+
reader.onload = () => typeof reader.result === 'string' ? resolve(reader.result) : reject(new Error('JOB_STILL_CAPTURE_FAILED'));
|
|
178
|
+
reader.onerror = () => reject(new Error('JOB_STILL_CAPTURE_FAILED'));
|
|
179
|
+
reader.readAsDataURL(blob);
|
|
180
|
+
}, 'image/png');
|
|
181
|
+
}).catch(() => {throw new Error('JOB_STILL_CAPTURE_FAILED');})};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Per-form first attempt, including human words and observed generation, survives a lost reply. */
|
|
185
|
+
export function createJobRigSubmission() {
|
|
186
|
+
let frozen: {identity: string; base: Extract<JobUISubmission, {kind: 'review-verdict'}>; copy?: FrozenJobRigCapture;
|
|
187
|
+
pending?: Promise<JobUISubmission>; request?: JobUISubmission} | undefined;
|
|
188
|
+
return {
|
|
189
|
+
reset() {frozen = undefined;},
|
|
190
|
+
prepare(input: JobUISubmission, copy: () => FrozenJobRigCapture): Promise<JobUISubmission> {
|
|
191
|
+
if (input.kind !== 'review-verdict' || input.value.stage !== 'rig-review') throw new Error('JOB_ACT_INVALID');
|
|
192
|
+
const identity = JSON.stringify([input.publicationId, input.pageId, input.displayedNonce, input.askId, input.submissionId, input.kind]);
|
|
193
|
+
if (frozen && frozen.identity !== identity) throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
194
|
+
if (!frozen) {
|
|
195
|
+
const base = structuredClone(input);
|
|
196
|
+
frozen = {identity, base, copy: copy()};
|
|
197
|
+
}
|
|
198
|
+
const saved = frozen;
|
|
199
|
+
if (saved.request) return Promise.resolve(saved.request);
|
|
200
|
+
if (!saved.pending) saved.pending = saved.copy!.encode().then(capture => {
|
|
201
|
+
Object.freeze(capture.binding);
|
|
202
|
+
Object.freeze(capture);
|
|
203
|
+
Object.freeze(saved.base.value);
|
|
204
|
+
saved.request = Object.freeze({...saved.base, capture});
|
|
205
|
+
saved.copy = undefined;
|
|
206
|
+
return saved.request;
|
|
207
|
+
}).finally(() => {saved.pending = undefined;});
|
|
208
|
+
return saved.pending;
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|