@rig-c/review 2.8.0 → 2.9.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 +103 -66
- package/docs/REVIEW_PACKAGE.md +5 -6
- package/docs/STABILITY.md +6 -1
- package/package.json +3 -3
- package/src/build.ts +10 -2
- package/src/cli.ts +4 -5
- package/src/correction-handoff.ts +27 -4
- package/src/feedback-export.ts +1 -1
- package/src/front.ts +2 -1
- package/src/handoff.ts +1 -1
- package/src/job-act.ts +43 -23
- package/src/job-cli.ts +6 -2
- package/src/job-contract.ts +86 -12
- package/src/job-front.ts +106 -9
- package/src/job-host.ts +5 -0
- package/src/job-session.ts +37 -4
- package/src/manifest.ts +9 -0
- package/src/open-workspace-launch.ts +2 -2
- package/src/open.ts +2 -1
- package/src/parts-comment-crops.ts +126 -31
- package/src/parts-comment.ts +321 -28
- package/src/parts-view.ts +485 -89
- package/src/stage-comment.ts +9 -1
- package/src/stage-parts.ts +5 -1
- package/src/versions.ts +7 -7
- package/web/catalog-en.ts +36 -1
- package/web/catalog-ko.ts +36 -1
- package/web/job-session.ts +353 -83
- package/web/parts-page.ts +217 -0
- package/web/parts-render.ts +26 -19
- package/web/parts-viewport-provider.ts +13 -1
- package/web/parts.css +13 -1
- package/web/parts.html +4 -38
- package/web/parts.ts +644 -267
- package/web/stage-comments.ts +77 -23
- package/web/styles.css +10 -2
- package/web/viewport-controller.ts +13 -4
package/src/job-act.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import {
|
|
3
|
-
JOB_ACT_SCHEMA, JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_RECORD_ACT_KINDS, JOB_RECORD_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, jobStillByteLimit, JOB_ENABLED_ACT_KINDS, JOB_PLAN_BOUND_SIGNOFF_STAGES, JOB_RESERVED_ACT_KINDS,
|
|
3
|
+
JOB_ACT_SCHEMA, JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, JOB_RECORD_ACT_KINDS, JOB_RECORD_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, jobStillByteLimit, JOB_ENABLED_ACT_KINDS, JOB_PLAN_BOUND_SIGNOFF_STAGES, JOB_RESERVED_ACT_KINDS,
|
|
4
4
|
type ActV3, type JobAct, type JobActValues, type JobApiSchema, type JobPendingAsk, type JobPublicationMode, type JobReviewerBinding,
|
|
5
5
|
type JobSourceBinding, type JobSubject, type JobUISubmission, type JobRigCapture, type JobRigStill,
|
|
6
6
|
type PendingAskV3, type RecordAct, type RecordSource, type RecordSubject, type SourceV3, type UISubmissionV3,
|
|
7
7
|
} from './job-contract.ts';
|
|
8
|
+
import { parsePartsIssue, type PartsIssue } from './parts-comment.ts';
|
|
8
9
|
import {
|
|
9
10
|
isRecordSource, jobHash, jobId, jobInteger, jobObject,
|
|
10
11
|
parseRecordAct, parseRecordSource, requestDigest, validateRecordAskSubject,
|
|
@@ -558,30 +559,49 @@ export function finalizeJobAct(options: {
|
|
|
558
559
|
} };
|
|
559
560
|
}
|
|
560
561
|
case 'parts-verdict': {
|
|
561
|
-
const value = jobObject(submission.value, ['verdict', '
|
|
562
|
-
|
|
562
|
+
const value = jobObject(submission.value, ['verdict', 'issues', 'words']);
|
|
563
|
+
const verdict = choice(value.verdict, ['approved', 'changes-requested'] as const);
|
|
564
|
+
if (
|
|
565
|
+
!Array.isArray(value.issues) ||
|
|
566
|
+
value.issues.length > 1000 ||
|
|
567
|
+
(verdict === 'approved') !== (value.issues.length === 0)
|
|
568
|
+
) {
|
|
569
|
+
throw new JobError('JOB_ACT_INVALID');
|
|
570
|
+
}
|
|
563
571
|
const ids = new Set<string>();
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
572
|
+
const issues: PartsIssue[] = value.issues.map(raw => {
|
|
573
|
+
let issue: PartsIssue;
|
|
574
|
+
try {
|
|
575
|
+
issue = parsePartsIssue(raw, true, false, false);
|
|
576
|
+
} catch {
|
|
577
|
+
throw new JobError('JOB_ACT_INVALID');
|
|
578
|
+
}
|
|
579
|
+
if (issue.sourceHash !== source.sourceHash || ids.has(issue.id)) {
|
|
580
|
+
throw new JobError('JOB_ACT_INVALID');
|
|
581
|
+
}
|
|
582
|
+
ids.add(issue.id);
|
|
583
|
+
for (const part of issue.parts) {
|
|
584
|
+
const matchesSource = source.parts!.images.some(
|
|
585
|
+
img => img.role === 'part' && img.path === `parts/${part.name}.png` && img.sha256 === part.imageHash,
|
|
586
|
+
);
|
|
587
|
+
if (!retained.partIds.includes(part.name) || !matchesSource) {
|
|
588
|
+
throw new JobError('JOB_ACT_INVALID');
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return structuredClone(issue);
|
|
577
592
|
});
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
593
|
+
return {
|
|
594
|
+
...envelope,
|
|
595
|
+
schema: JOB_PARTS_VERDICT_ACT_SCHEMA,
|
|
596
|
+
kind: 'parts-verdict',
|
|
597
|
+
source: {
|
|
598
|
+
...source,
|
|
599
|
+
projectHash: source.projectHash!,
|
|
600
|
+
selector: source.selector as Extract<NonNullable<JobSourceBinding['selector']>, { kind: 'draft' }>,
|
|
601
|
+
parts: source.parts!,
|
|
602
|
+
},
|
|
603
|
+
value: { verdict, issues, words: words(value.words) },
|
|
604
|
+
};
|
|
585
605
|
}
|
|
586
606
|
case 'review-verdict': {
|
|
587
607
|
const value = jobObject(submission.value, ['stage', 'verdict', 'words']);
|
package/src/job-cli.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import {closeSync, constants, fstatSync, fsyncSync, lstatSync, openSync, readFileSync, renameSync, unlinkSync, writeSync} from 'node:fs';
|
|
3
3
|
import {join} from 'node:path';
|
|
4
|
-
import { JOB_API_SCHEMA, JOB_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, JOB_ENABLED_ACT_KINDS, jobRawActMediaType, jobStillByteLimit,
|
|
4
|
+
import { JOB_API_SCHEMA, JOB_ACT_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, JOB_ENABLED_ACT_KINDS, jobRawActMediaType, jobStillByteLimit,
|
|
5
5
|
type JobAct, type JobAgentRequest, type JobNextRequest, type JobNextValue } from './job-contract.ts';
|
|
6
6
|
import { assertJobApiSchema, jobFailure, jobHash, jobId, jobInteger, jobObject, jobWaitLimitMs, parseJobRequest } from './job-api.ts';
|
|
7
7
|
import { JobError } from './job-store.ts';
|
|
@@ -150,7 +150,11 @@ function parseConsumerAct(bytes: Buffer, job: string, actId: string): JobAct {
|
|
|
150
150
|
try { value = JSON.parse(new TextDecoder('utf-8', {fatal: true}).decode(bytes)); }
|
|
151
151
|
catch { throw new JobError('JOB_REQUEST_INVALID'); }
|
|
152
152
|
const act = jobObject(value, ['schema', 'actId', 'jobId', 'askId', 'publicationId', 'kind', 'authority', 'at', 'source', 'value', 'still']);
|
|
153
|
-
if (act.jobId !== job || act.actId !== actId ||
|
|
153
|
+
if (act.jobId !== job || act.actId !== actId ||
|
|
154
|
+
(act.schema !== JOB_ACT_SCHEMA && act.schema !== JOB_RIG_REVIEW_ACT_SCHEMA && act.schema !== JOB_PARTS_VERDICT_ACT_SCHEMA)) {
|
|
155
|
+
throw new JobError('JOB_ACT_INVALID');
|
|
156
|
+
}
|
|
157
|
+
if (act.schema === JOB_PARTS_VERDICT_ACT_SCHEMA && (act.kind !== 'parts-verdict' || act.still !== undefined)) {
|
|
154
158
|
throw new JobError('JOB_ACT_INVALID');
|
|
155
159
|
}
|
|
156
160
|
if (act.schema === JOB_RIG_REVIEW_ACT_SCHEMA) {
|
package/src/job-contract.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import type { JobPublicationReader } from './job-source.ts';
|
|
15
|
+
import type { PartsIssue } from './parts-comment.ts';
|
|
15
16
|
|
|
16
17
|
export const JOB_API_SCHEMA = 'rig-review/job-api@2' as const;
|
|
17
18
|
export const JOB_API_V3_SCHEMA = 'rig-review/job-api@3' as const;
|
|
@@ -20,6 +21,65 @@ export const JOB_ACT_SCHEMA = 'rig-review/act@2' as const;
|
|
|
20
21
|
export const JOB_RIG_REVIEW_ACT_SCHEMA = 'rig-review/act@3' as const;
|
|
21
22
|
/** Record-source acts only under opt-in API@3. Package/image acts retain @2/@3. */
|
|
22
23
|
export const JOB_RECORD_ACT_SCHEMA = 'rig-review/act@4' as const;
|
|
24
|
+
/** New parts verdicts only. Historical @2 parts-verdict acts remain readable. */
|
|
25
|
+
export const JOB_PARTS_VERDICT_ACT_SCHEMA = 'rig-review/act@5' as const;
|
|
26
|
+
export const JOB_PANEL_COMPOSITION_SCHEMA = 'rig-review/panels@1' as const;
|
|
27
|
+
|
|
28
|
+
export type PanelSlot = 'left' | 'stage' | 'toolbar' | 'side';
|
|
29
|
+
export const PANEL_COMPONENTS = [
|
|
30
|
+
'parts.canvas', 'parts.list', 'parts.issues', 'parts.layers', 'act.submit',
|
|
31
|
+
'interview.picks', 'plan.body', 'rig.playback', 'scene.composite', 'images.set',
|
|
32
|
+
] as const;
|
|
33
|
+
export type PanelComponent = typeof PANEL_COMPONENTS[number];
|
|
34
|
+
export interface JobPanelComposition {
|
|
35
|
+
readonly schema: typeof JOB_PANEL_COMPOSITION_SCHEMA;
|
|
36
|
+
readonly left?: readonly PanelComponent[];
|
|
37
|
+
readonly stage?: readonly PanelComponent[];
|
|
38
|
+
readonly toolbar?: readonly PanelComponent[];
|
|
39
|
+
readonly side?: readonly PanelComponent[];
|
|
40
|
+
}
|
|
41
|
+
export function isPanelComponent(value: string): value is PanelComponent {
|
|
42
|
+
return (PANEL_COMPONENTS as readonly string[]).includes(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function parsePanelComposition(input: unknown): JobPanelComposition {
|
|
46
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input) || Object.getPrototypeOf(input) !== Object.prototype) {
|
|
47
|
+
throw new Error('JOB_PANELS_INVALID: panels must be a plain object');
|
|
48
|
+
}
|
|
49
|
+
const p = input as Record<string, unknown>;
|
|
50
|
+
if (p.schema !== JOB_PANEL_COMPOSITION_SCHEMA) {
|
|
51
|
+
throw new Error(`JOB_PANELS_INVALID: panels.schema must be ${JOB_PANEL_COMPOSITION_SCHEMA}`);
|
|
52
|
+
}
|
|
53
|
+
for (const key of Object.keys(p)) {
|
|
54
|
+
if (!['schema', 'left', 'stage', 'toolbar', 'side'].includes(key)) {
|
|
55
|
+
throw new Error(`JOB_PANELS_INVALID: unknown panel slot ${key}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const slot = (value: unknown, field: string): PanelComponent[] => {
|
|
59
|
+
if (!Array.isArray(value) || value.length > 32) {
|
|
60
|
+
throw new Error(`JOB_PANELS_INVALID: ${field} must be an array of at most 32 components`);
|
|
61
|
+
}
|
|
62
|
+
return value.map((item, index) => {
|
|
63
|
+
if (typeof item !== 'string' || !item.trim() || item.length > 128 || /[\r\n\0]/.test(item)) {
|
|
64
|
+
throw new Error(`JOB_PANELS_INVALID: ${field}[${index}] must be a nonblank component id`);
|
|
65
|
+
}
|
|
66
|
+
// Unknown component IDs are preserved in their declared slot so the host renders JOB_PANEL_UNKNOWN: <id>.
|
|
67
|
+
return item as PanelComponent;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const stage = slot(p.stage, 'panels.stage');
|
|
71
|
+
const side = slot(p.side, 'panels.side');
|
|
72
|
+
if (stage.length !== 1 || side.length < 1 || side[side.length - 1] !== 'act.submit') {
|
|
73
|
+
throw new Error('JOB_PANELS_INVALID: stage must have exactly one component and side must end with act.submit');
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
schema: JOB_PANEL_COMPOSITION_SCHEMA,
|
|
77
|
+
...(p.left === undefined ? {} : { left: slot(p.left, 'panels.left') }),
|
|
78
|
+
stage,
|
|
79
|
+
...(p.toolbar === undefined ? {} : { toolbar: slot(p.toolbar, 'panels.toolbar') }),
|
|
80
|
+
side,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
23
83
|
export const JOB_RECORD_READER_ID = 'rig-create/publication-reader/2' as const;
|
|
24
84
|
export const JOB_RECORD_SOURCE_SCHEMA = 'rig-review-job-record-source/1' as const;
|
|
25
85
|
export const JOB_RECORD_INSTANCE_SCHEMA = 'rig-review-job-record-instance/1' as const;
|
|
@@ -228,6 +288,22 @@ export type JobVerdict = 'pending' | 'approved' | 'changes-requested';
|
|
|
228
288
|
export type JobPartOutcome = 'pending' | 'clean' | 'flagged';
|
|
229
289
|
export type JobReviewStage = 'rig-review' | 'direction-review' | 'image-review';
|
|
230
290
|
|
|
291
|
+
export type PartsVerdictValue = {
|
|
292
|
+
readonly verdict: 'approved' | 'changes-requested';
|
|
293
|
+
readonly issues: readonly PartsIssue[];
|
|
294
|
+
readonly words: string;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export interface JobLegacyPartsVerdictValue {
|
|
298
|
+
readonly verdict: JobVerdict;
|
|
299
|
+
readonly parts: readonly {
|
|
300
|
+
readonly partId: string;
|
|
301
|
+
readonly part: { readonly outcome: JobPartOutcome; readonly note: string };
|
|
302
|
+
readonly mesh: { readonly outcome: JobPartOutcome; readonly note: string };
|
|
303
|
+
}[];
|
|
304
|
+
readonly words: string;
|
|
305
|
+
}
|
|
306
|
+
|
|
231
307
|
export interface JobActValues {
|
|
232
308
|
readonly 'interview-picks': {
|
|
233
309
|
readonly questionId: string;
|
|
@@ -251,15 +327,7 @@ export interface JobActValues {
|
|
|
251
327
|
*/
|
|
252
328
|
readonly words: string;
|
|
253
329
|
};
|
|
254
|
-
readonly 'parts-verdict':
|
|
255
|
-
readonly verdict: JobVerdict;
|
|
256
|
-
readonly parts: readonly {
|
|
257
|
-
readonly partId: string;
|
|
258
|
-
readonly part: { readonly outcome: JobPartOutcome; readonly note: string };
|
|
259
|
-
readonly mesh: { readonly outcome: JobPartOutcome; readonly note: string };
|
|
260
|
-
}[];
|
|
261
|
-
readonly words: string;
|
|
262
|
-
};
|
|
330
|
+
readonly 'parts-verdict': PartsVerdictValue;
|
|
263
331
|
readonly 'review-verdict': JobModelReviewValue | JobImageReviewValue;
|
|
264
332
|
readonly signoff: {
|
|
265
333
|
/** An explicitly declared Create stage. Validation belongs to its writer. */
|
|
@@ -321,7 +389,8 @@ export type JobLegacyAct = {
|
|
|
321
389
|
} & (Kind extends 'review-verdict' ? (
|
|
322
390
|
| {readonly source: Exclude<JobActSources['review-verdict'], JobImageSourceBinding>; readonly value: JobModelReviewValue}
|
|
323
391
|
| {readonly source: JobImageSourceBinding; readonly value: JobImageReviewValue}
|
|
324
|
-
) : {readonly source: JobActSources[
|
|
392
|
+
) : Kind extends 'parts-verdict' ? {readonly source: JobActSources['parts-verdict']; readonly value: JobLegacyPartsVerdictValue}
|
|
393
|
+
: {readonly source: JobActSources[Kind]; readonly value: JobActValues[Kind]});
|
|
325
394
|
}[JobEnabledActKind];
|
|
326
395
|
|
|
327
396
|
export type JobRigStill = {
|
|
@@ -343,8 +412,13 @@ export type JobRigReviewAct = Omit<Extract<JobLegacyAct, {kind: 'review-verdict'
|
|
|
343
412
|
readonly still: JobRigStill;
|
|
344
413
|
};
|
|
345
414
|
|
|
346
|
-
|
|
347
|
-
|
|
415
|
+
export type JobPartsVerdictAct = Omit<Extract<JobLegacyAct, {kind: 'parts-verdict'}>, 'schema' | 'value'> & {
|
|
416
|
+
readonly schema: typeof JOB_PARTS_VERDICT_ACT_SCHEMA;
|
|
417
|
+
readonly value: PartsVerdictValue;
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
/** Historical @2 acts remain readable without being backfilled or relabelled. */
|
|
421
|
+
export type JobAct = JobLegacyAct | JobRigReviewAct | JobPartsVerdictAct;
|
|
348
422
|
|
|
349
423
|
/** Authenticated browser provenance. The daemon validates identity and hashes PNG bytes. */
|
|
350
424
|
export interface JobRigCapture {
|
package/src/job-front.ts
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
import { JOB_API_SCHEMA, JOB_ACT_SCHEMA, type JobErrorCode, type JobHostPorts, type JobId, type JobPublicationMode, type JobResult, type JobReviewerBinding } from './job-contract.ts';
|
|
3
3
|
import { createJobHostPorts, jobBody, jobHash, jobId, jobObject, jobPartsEnumeratorVersion } from './job-api.ts';
|
|
4
4
|
import { JobSession } from './job-session.ts';
|
|
5
|
-
import { assertJobRoot, captureJobRoot, isRetainedRecordSource, type JobRootIdentity } from './job-source.ts';
|
|
5
|
+
import { assertJobRoot, assertRetainedSnapshotIntact, captureJobRoot, isRetainedRecordSource, type JobRootIdentity } from './job-source.ts';
|
|
6
6
|
import type { JobWorkerOptions } from './job-worker.ts';
|
|
7
7
|
import { JobError, JobStore } from './job-store.ts';
|
|
8
8
|
import { loadReview, safeFile, packagePath, type ReviewPackage } from './manifest.ts';
|
|
9
9
|
import { serveReference, assertReviewUnchanged } from './reference.ts';
|
|
10
|
+
import {preparePartsComment} from './parts-comment-crops.ts';
|
|
10
11
|
import { loadPartsView, partsViewJson, servedImage, type PartsViewPackage } from './parts-view.ts';
|
|
11
12
|
import { destinationDirectory, DestinationDirectoryError } from './destination-directory.ts';
|
|
12
13
|
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
@@ -22,8 +23,60 @@ const headers = {
|
|
|
22
23
|
'Referrer-Policy': 'no-referrer',
|
|
23
24
|
'Content-Security-Policy': "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' blob: data:; media-src 'self' blob:; connect-src 'self'; base-uri 'none'; frame-ancestors 'none'; form-action 'none'",
|
|
24
25
|
};
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
interface CropFailureDiagnostic {
|
|
27
|
+
field: string;
|
|
28
|
+
expected: string | number[];
|
|
29
|
+
received: string | number[];
|
|
30
|
+
}
|
|
31
|
+
function failure(code: string, status: number, diagnostic?: CropFailureDiagnostic): Response {
|
|
32
|
+
return Response.json({ ok: false, error: { code, message: code, ...(diagnostic ? {diagnostic} : {}) } }, { status, headers });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Explain an existing rejection without returning body text, filesystem paths or PNG bytes. */
|
|
36
|
+
function cropFailureDiagnostic(error: unknown, raw: unknown): CropFailureDiagnostic {
|
|
37
|
+
const message = error instanceof Error ? error.message : '';
|
|
38
|
+
const invariants: Record<string, [string, string]> = {
|
|
39
|
+
'PARTS_COMMENT_RIG_REGION: rig region must be exact placement plus image region': ['rigRegion', 'exact placement plus imageRegion'],
|
|
40
|
+
'PARTS_COMMENT_OUT_OF_BOUNDS: region exceeds original image': ['imageRegion', 'inside original image bounds'],
|
|
41
|
+
'PARTS_COMMENT_OUT_OF_BOUNDS: region exceeds union of issue parts': ['rigRegion', 'inside union of bound parts'],
|
|
42
|
+
'PARTS_CAMERA_RANGE: native zoom below fit/1 minimum': ['view.camera.zoom', 'at least min(fit, 1)'],
|
|
43
|
+
'PARTS_CAMERA_RANGE: native scale or camera extent': ['view.camera', 'bounded positive zoom and viewport'],
|
|
44
|
+
'PARTS_COMMENT_IMAGE_SIZE: original dimensions differ from placement': ['part.image.dimensions', 'equal retained placement dimensions'],
|
|
45
|
+
'PARTS_COMMENT_CROP_INVALID: bounded content-addressed crop': ['crop', 'bounded content-addressed PNG metadata'],
|
|
46
|
+
'COMMENT_CROP_INVALID: bounded content-addressed PNG required': ['crop', 'bounded content-addressed PNG'],
|
|
47
|
+
'COMMENT_CROP_INVALID: expected noninterlaced 8-bit RGB/RGBA': ['crop.png.format', 'noninterlaced 8-bit RGB/RGBA'],
|
|
48
|
+
'COMMENT_CROP_INVALID: truncated PNG chunk': ['crop.png.chunks', 'complete chunks'],
|
|
49
|
+
'COMMENT_CROP_INVALID: PNG chunk length': ['crop.png.chunk.length', 'inside PNG byte bounds'],
|
|
50
|
+
'COMMENT_CROP_INVALID: PNG chunk CRC': ['crop.png.chunk.crc', 'matching CRC'],
|
|
51
|
+
'COMMENT_CROP_INVALID: static PNG required': ['crop.png.animation', 'static PNG'],
|
|
52
|
+
'COMMENT_CROP_INVALID: PNG end': ['crop.png.end', 'final empty IEND'],
|
|
53
|
+
'COMMENT_CROP_INVALID: PNG data/end missing': ['crop.png.data', 'IDAT and IEND present'],
|
|
54
|
+
'COMMENT_CROP_INVALID: bounded PNG data decode': ['crop.png.data', 'bounded decodable scanlines'],
|
|
55
|
+
'COMMENT_CROP_INVALID: PNG scanlines': ['crop.png.scanlines', 'exact dimensions and valid filters'],
|
|
56
|
+
'COMMENT_CROP_PATH: existing crop is not the bound regular PNG': ['crop.storage', 'regular file with matching SHA-256'],
|
|
57
|
+
'COMMENT_CROP_PATH: regular state directory required': ['crop.storage', 'regular state directory'],
|
|
58
|
+
};
|
|
59
|
+
// Inspect metadata only after the existing validator reports this exact invariant.
|
|
60
|
+
if (message === 'COMMENT_CROP_INVALID: PNG signature, dimensions or SHA-256 differ' &&
|
|
61
|
+
raw && typeof raw === 'object' && 'crop' in raw) {
|
|
62
|
+
const crop = raw.crop as {png?: unknown; sha256?: unknown; width?: unknown; height?: unknown} | null;
|
|
63
|
+
if (crop && typeof crop.png === 'string' && crop.png.length <= 200000 &&
|
|
64
|
+
typeof crop.sha256 === 'string' && /^[a-f0-9]{64}$/.test(crop.sha256)) {
|
|
65
|
+
const bytes = Buffer.from(crop.png.slice('data:image/png;base64,'.length), 'base64');
|
|
66
|
+
const hash = jobHash(bytes);
|
|
67
|
+
if (hash !== crop.sha256) return {field: 'crop.sha256', expected: crop.sha256, received: hash};
|
|
68
|
+
if (bytes.length >= 24 && bytes.subarray(0, 8).toString('hex') === '89504e470d0a1a0a' &&
|
|
69
|
+
typeof crop.width === 'number' && typeof crop.height === 'number' &&
|
|
70
|
+
(crop.width !== bytes.readUInt32BE(16) || crop.height !== bytes.readUInt32BE(20))) {
|
|
71
|
+
return {field: 'crop.dimensions', expected: [crop.width, crop.height],
|
|
72
|
+
received: [bytes.readUInt32BE(16), bytes.readUInt32BE(20)]};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {field: 'crop.png.signature', expected: 'PNG signature and IHDR', received: 'invalid'};
|
|
76
|
+
}
|
|
77
|
+
const invariant = Object.hasOwn(invariants, message) ? invariants[message] : undefined;
|
|
78
|
+
return invariant ? {field: invariant[0], expected: invariant[1], received: 'rejected by existing validator'} :
|
|
79
|
+
{field: 'partsComment.prepare', expected: 'valid source-bound crop and writable evidence state', received: 'unclassified rejection'};
|
|
27
80
|
}
|
|
28
81
|
const errorStatus: Partial<Record<JobErrorCode, number>> = {
|
|
29
82
|
JOB_REQUEST_INVALID: 400,
|
|
@@ -83,8 +136,11 @@ export function createJobFront(options: {
|
|
|
83
136
|
return result(await options.ports.ackDisplayed(jobId, request));
|
|
84
137
|
return result(await options.ports.commitUIAct(jobId, request));
|
|
85
138
|
}
|
|
86
|
-
|
|
139
|
+
const partsCrop = request.method === 'POST' &&
|
|
140
|
+
/^publications\/[A-Za-z0-9][A-Za-z0-9._-]{0,127}\/instances\/[a-f0-9]{64}\/api\/stage-parts\/comment$/.test(route);
|
|
141
|
+
if (!read && !partsCrop)
|
|
87
142
|
return failure('JOB_REQUEST_INVALID', 405);
|
|
143
|
+
if (partsCrop && sentOrigin !== origin.origin) return failure('JOB_SAME_ORIGIN_REQUIRED', 403);
|
|
88
144
|
const liveness = await options.ports.jobLiveness(jobId);
|
|
89
145
|
if (!liveness.ok)
|
|
90
146
|
return result(liveness);
|
|
@@ -172,7 +228,9 @@ export function jobWindowResources() {
|
|
|
172
228
|
'<body data-job-window><script type="module" src="job.js"></script></body></html>';
|
|
173
229
|
}
|
|
174
230
|
if (name === 'styles.css')
|
|
175
|
-
return Bun.file(new URL('../web/styles.css', import.meta.url))
|
|
231
|
+
return (await Bun.file(new URL('../web/styles.css', import.meta.url)).text()) +
|
|
232
|
+
'\n@scope (.job-inspection[data-job-parts-workspace]) {\n' +
|
|
233
|
+
(await Bun.file(new URL('../web/parts.css', import.meta.url)).text()) + '\n}';
|
|
176
234
|
bundle ??= buildJobWindow();
|
|
177
235
|
return bundle;
|
|
178
236
|
};
|
|
@@ -199,9 +257,13 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
199
257
|
return async (jobId: string, publicationId: string, key: string, path: string, request: Request): Promise<Response> => {
|
|
200
258
|
if (jobId !== session.jobId) return failure('JOB_UNKNOWN', 404);
|
|
201
259
|
try {
|
|
260
|
+
const crop = path === 'api/stage-parts/comment' && request.method === 'POST';
|
|
261
|
+
if (crop) session.authorize('ui', request.headers.get('X-Review-Capability'));
|
|
202
262
|
return await session.readPublicationResponse(publicationId, async retained => {
|
|
203
263
|
const display = session.displayPublication(publicationId);
|
|
204
264
|
if (key !== display.publication.instanceKey) return failure('JOB_DISPLAY_MISMATCH', 409);
|
|
265
|
+
if (crop && session.status().publication?.publicationId !== publicationId)
|
|
266
|
+
return failure('JOB_ACT_SOURCE_STALE', 409);
|
|
205
267
|
const json = (value: unknown) => new Response(request.method === 'HEAD' ? null : JSON.stringify(value), {
|
|
206
268
|
headers: {...headers, 'Content-Type': 'application/json'},
|
|
207
269
|
});
|
|
@@ -247,9 +309,18 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
247
309
|
if (!pending) {
|
|
248
310
|
pending = (async () => {
|
|
249
311
|
const review = await loadReview(retained.manifestPath);
|
|
250
|
-
const
|
|
251
|
-
?
|
|
252
|
-
|
|
312
|
+
const partsRoot = retained.source.parts
|
|
313
|
+
? dirname(join(retained.snapshotRoot, retained.source.parts.manifest.path)) : null;
|
|
314
|
+
// Forward only retained producer files. Discovery never reads the live draft.
|
|
315
|
+
const retainedFile = (path: string) => retained.seals.some(file =>
|
|
316
|
+
file.path === relative(retained.snapshotRoot, path).split('\\').join('/')) ? path : undefined;
|
|
317
|
+
const rigRoot = review.handoff?.rig ?? partsRoot;
|
|
318
|
+
const parts = partsRoot ? await loadPartsView(partsRoot, {
|
|
319
|
+
rig: rigRoot ? retainedFile(join(rigRoot, 'rig.json')) : undefined,
|
|
320
|
+
meshReport: rigRoot ? retainedFile(join(rigRoot, 'mesh_report.json')) : undefined,
|
|
321
|
+
painting: review.handoff?.source ? retainedFile(review.handoff.source) : undefined,
|
|
322
|
+
paintingRoot: retained.snapshotRoot,
|
|
323
|
+
}) : null;
|
|
253
324
|
if (parts) {
|
|
254
325
|
if (parts.items.length !== retained.partIds.length || parts.items.some(item => !retained.partIds.includes(item.name))) {
|
|
255
326
|
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
@@ -308,6 +379,29 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
308
379
|
if (!image) return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
309
380
|
return await sealedFile(image.path);
|
|
310
381
|
}
|
|
382
|
+
if (crop) {
|
|
383
|
+
if (!parts) return failure('JOB_SOURCE_UNRETAINABLE', 409);
|
|
384
|
+
if (request.headers.get('origin') !== new URL(request.url).origin)
|
|
385
|
+
return failure('JOB_SAME_ORIGIN_REQUIRED', 403);
|
|
386
|
+
const raw = await jobBody(request);
|
|
387
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw) ||
|
|
388
|
+
(raw as {sourceHash?: unknown}).sourceHash !== retained.source.sourceHash)
|
|
389
|
+
return failure('JOB_ACT_SOURCE_STALE', 409);
|
|
390
|
+
// Preserve the exact displayed job identity through native evidence validation.
|
|
391
|
+
assertRetainedSnapshotIntact(retained.snapshotRoot, retained.seals);
|
|
392
|
+
let comment;
|
|
393
|
+
try {
|
|
394
|
+
comment = await preparePartsComment(parts, raw, false, {sourceHash: retained.source.sourceHash});
|
|
395
|
+
} catch (error) {
|
|
396
|
+
if (error instanceof JobError ||
|
|
397
|
+
error instanceof Error && error.message.startsWith('PARTS_COMMENT_STALE_SOURCE:')) throw error;
|
|
398
|
+
return failure('JOB_SOURCE_MISMATCH', 409, cropFailureDiagnostic(error, raw));
|
|
399
|
+
}
|
|
400
|
+
assertRetainedSnapshotIntact(retained.snapshotRoot, retained.seals);
|
|
401
|
+
if (session.status().publication?.publicationId !== publicationId)
|
|
402
|
+
return failure('JOB_ACT_SOURCE_STALE', 409);
|
|
403
|
+
return json({comment});
|
|
404
|
+
}
|
|
311
405
|
if (path === 'api/stage-parts') {
|
|
312
406
|
if (!parts) return failure('JOB_SOURCE_UNRETAINABLE', 409);
|
|
313
407
|
return json({...partsViewJson(parts, {verdict: null, stale: null}), sourceHash: retained.source.sourceHash,
|
|
@@ -330,7 +424,10 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
330
424
|
return failure('JOB_REQUEST_INVALID', 404);
|
|
331
425
|
});
|
|
332
426
|
} catch (error) {
|
|
333
|
-
|
|
427
|
+
const code = error instanceof JobError ? error.code :
|
|
428
|
+
error instanceof Error && error.message.startsWith('PARTS_COMMENT_STALE_SOURCE:')
|
|
429
|
+
? 'PARTS_COMMENT_STALE_SOURCE' : 'JOB_SOURCE_MISMATCH';
|
|
430
|
+
return failure(code, errorStatus[code as JobErrorCode] ?? 409);
|
|
334
431
|
}
|
|
335
432
|
};
|
|
336
433
|
}
|
package/src/job-host.ts
CHANGED
package/src/job-session.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
-
import { isAbsolute, relative, sep } from 'node:path';
|
|
2
|
+
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
3
3
|
import {
|
|
4
|
-
JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, JOB_RECORD_READER_ID, jobStillByteLimit, JOB_CAPABILITIES, JOB_CAPABILITIES_V3, JOB_ENABLED_ACT_KINDS,
|
|
4
|
+
JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_ACT_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, JOB_RECORD_READER_ID, jobStillByteLimit, JOB_CAPABILITIES, JOB_CAPABILITIES_V3, JOB_ENABLED_ACT_KINDS,
|
|
5
5
|
type ActV3, type AgentRequestV3, type EventV3, type JobPartsEnumerator, type JobAct, type JobAgentRequest, type JobDisplayAcknowledgment,
|
|
6
6
|
type JobDisplayPublication, type JobDisplayPublicationV3, type JobDisplayReceipt, type JobEvent, type JobFetchActRequest, type JobFetchActRequestV3,
|
|
7
7
|
type JobNextValue, type JobPendingAsk, type JobPublication, type JobPublicationMode, type JobReviewerBinding,
|
|
@@ -15,6 +15,9 @@ import {
|
|
|
15
15
|
} from './job-source.ts';
|
|
16
16
|
import { JobError, JobStore, type JobSnapshotOwner, type StoredJob } from './job-store.ts';
|
|
17
17
|
import { canonicalStatePath } from './state-dir.ts';
|
|
18
|
+
import { loadReview } from './manifest.ts';
|
|
19
|
+
import { loadPartsView } from './parts-view.ts';
|
|
20
|
+
import { validateStoredPartsComment } from './parts-comment-crops.ts';
|
|
18
21
|
|
|
19
22
|
export type { JobDisplayPublicationV3 } from './job-contract.ts';
|
|
20
23
|
|
|
@@ -600,7 +603,9 @@ export class JobSession {
|
|
|
600
603
|
}
|
|
601
604
|
|
|
602
605
|
async commitUIAct(raw: unknown): Promise<ActV3> {
|
|
603
|
-
const
|
|
606
|
+
const parsed = parseUISubmission(raw, this.publicationMode);
|
|
607
|
+
const input = parsed.kind === 'parts-verdict' ? {...parsed, value: structuredClone(parsed.value)} : parsed;
|
|
608
|
+
const digest = requestDigest(input), key = `ui:${input.pageId}:${input.submissionId}`;
|
|
604
609
|
const current = this.current();
|
|
605
610
|
const previous = this.replay(current.data, key, digest);
|
|
606
611
|
if (previous) return previous.value as ActV3;
|
|
@@ -627,6 +632,34 @@ export class JobSession {
|
|
|
627
632
|
phase: 'finalize',
|
|
628
633
|
subject: ask.subject as RecordSubject,
|
|
629
634
|
});
|
|
635
|
+
} else if (ask && stored && input.kind === 'parts-verdict') {
|
|
636
|
+
assertJobSourceCurrent(stored.retained);
|
|
637
|
+
const candidate = finalizeJobAct({jobId: this.jobId, submission: input, ask,
|
|
638
|
+
retained: stored.retained, reviewer: current.data.reviewer});
|
|
639
|
+
if (candidate.schema === JOB_PARTS_VERDICT_ACT_SCHEMA && candidate.value.issues.length) {
|
|
640
|
+
await this.readPublicationResponse(input.publicationId, async retained => {
|
|
641
|
+
if (isRetainedRecordSource(retained) || !retained.source.parts) throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
642
|
+
assertRetainedSnapshotIntact(retained.snapshotRoot, retained.seals,
|
|
643
|
+
retained.snapshotIdentity, 'JOB_ACT_SOURCE_STALE');
|
|
644
|
+
try {
|
|
645
|
+
const review = await loadReview(retained.manifestPath);
|
|
646
|
+
const painting = review.handoff?.source;
|
|
647
|
+
const sealedPainting = painting && retained.seals.some(file =>
|
|
648
|
+
file.path === relative(retained.snapshotRoot, painting).split(sep).join('/')) ? painting : undefined;
|
|
649
|
+
const pkg = await loadPartsView(dirname(join(retained.snapshotRoot, retained.source.parts.manifest.path)),
|
|
650
|
+
{painting: sealedPainting, paintingRoot: retained.snapshotRoot});
|
|
651
|
+
for (const issue of candidate.value.issues) {
|
|
652
|
+
await validateStoredPartsComment(pkg, issue, false, {sourceHash: retained.source.sourceHash});
|
|
653
|
+
}
|
|
654
|
+
} catch (error) {
|
|
655
|
+
if (error instanceof JobError) throw error;
|
|
656
|
+
throw new JobError('JOB_ACT_INVALID');
|
|
657
|
+
}
|
|
658
|
+
assertRetainedSnapshotIntact(retained.snapshotRoot, retained.seals,
|
|
659
|
+
retained.snapshotIdentity, 'JOB_ACT_SOURCE_STALE');
|
|
660
|
+
return new Response(null, {status: 204});
|
|
661
|
+
});
|
|
662
|
+
}
|
|
630
663
|
}
|
|
631
664
|
}
|
|
632
665
|
}
|
|
@@ -646,7 +679,7 @@ export class JobSession {
|
|
|
646
679
|
if (!ask) throw new JobError('JOB_ASK_INVALID');
|
|
647
680
|
const retained = fresh.data.publications[input.publicationId].retained;
|
|
648
681
|
assertJobSourceCurrent(retained);
|
|
649
|
-
if (isRetainedRecordSource(retained)) {
|
|
682
|
+
if (isRetainedRecordSource(retained) || input.kind === 'parts-verdict') {
|
|
650
683
|
assertRetainedSnapshotIntact(
|
|
651
684
|
retained.snapshotRoot,
|
|
652
685
|
retained.seals,
|
package/src/manifest.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { readFile, realpath, stat, lstat, readdir } from 'node:fs/promises';
|
|
|
9
9
|
import { createReadStream } from 'node:fs';
|
|
10
10
|
import { basename, dirname, isAbsolute, relative, resolve, posix } from 'node:path';
|
|
11
11
|
import { isBuildRoot, parseHandoffDeclaration, resolveHandoff, type Handoff, type HandoffDeclaration, type HandoffFlags, type HandoffRecord } from './handoff.ts';
|
|
12
|
+
import { parsePanelComposition, type JobPanelComposition } from './job-contract.ts';
|
|
13
|
+
export { isPanelComponent, parsePanelComposition } from './job-contract.ts';
|
|
12
14
|
|
|
13
15
|
export type Json = null | boolean | number | string | Json[] | { [key: string]: Json };
|
|
14
16
|
export interface Reference { id: string; label: string; type: 'image' | 'video' | 'pose'; path: string; width?: number; height?: number }
|
|
@@ -22,6 +24,7 @@ export interface ReviewManifest {
|
|
|
22
24
|
audio: { clips: { id: string; label?: string; path: string }[]; cues: { id: string; clip: string; time: number; animation?: string }[] };
|
|
23
25
|
/** Optional producer handoff (#101): package-relative literal paths; checked when the package loads. */
|
|
24
26
|
producer?: HandoffDeclaration;
|
|
27
|
+
panels?: JobPanelComposition;
|
|
25
28
|
}
|
|
26
29
|
export interface ReviewedSource { readonly packageRevision:string; readonly viewerVersion:string; readonly runtimeVersion:string; readonly rig:{readonly path:string;readonly sha256:string}|null; readonly motion:{readonly path:string;readonly sha256:string}|null; readonly handoff?:HandoffRecord }
|
|
27
30
|
export interface ReviewPackage { direction?:DirectionInspection; setsHash?:string; referenceHashes?:Record<string,string>; root: string; manifestPath: string; manifest: ReviewManifest; sourceHash: string; reviewedSource:ReviewedSource; files: Set<string>; report:ReportSeeds|null; feedbackCatalog:FeedbackCatalog;
|
|
@@ -64,6 +67,11 @@ export async function safeFile(root: string, path: string): Promise<string> {
|
|
|
64
67
|
export function parseManifest(input: unknown): ReviewManifest {
|
|
65
68
|
const m = object(input, 'review'); if (m.schema !== 'rig-review/1') fail('schema', 'rig-review/1');
|
|
66
69
|
const audio = m.audio === undefined ? {} : object(m.audio, 'audio');
|
|
70
|
+
let panels: JobPanelComposition | undefined;
|
|
71
|
+
if (m.panels !== undefined) {
|
|
72
|
+
try { panels = parsePanelComposition(m.panels); }
|
|
73
|
+
catch { panels = undefined; }
|
|
74
|
+
}
|
|
67
75
|
const manifest: ReviewManifest = {
|
|
68
76
|
schema: 'rig-review/1', id: id(m.id, 'id'), title: string(m.title, 'title'), revision: string(m.revision, 'revision'),
|
|
69
77
|
model: m.model === undefined ? undefined : packagePath(m.model, 'model'),
|
|
@@ -76,6 +84,7 @@ export function parseManifest(input: unknown): ReviewManifest {
|
|
|
76
84
|
authoring:list(m.authoring,'authoring',(v,f)=>({label:string(v.label,f+'.label'),path:packagePath(v.path,f+'.path')})),
|
|
77
85
|
axes:list(m.axes,'axes',(v,f)=>({id:id(v.id,f+'.id'),label:string(v.label,f+'.label'),animation:string(v.animation,f+'.animation'),min:number(v.min,f+'.min',-Number.MAX_VALUE),max:number(v.max,f+'.max',-Number.MAX_VALUE)})),
|
|
78
86
|
...(m.producer===undefined?{}:{producer:parseHandoffDeclaration(m.producer)}),
|
|
87
|
+
...(panels===undefined?{}:{panels}),
|
|
79
88
|
audio:{clips:list(audio.clips,'audio.clips',(v,f)=>({id:id(v.id,f+'.id'),label:optionalString(v.label,f+'.label'),path:packagePath(v.path,f+'.path')})),cues:list(audio.cues,'audio.cues',(v,f)=>({id:id(v.id,f+'.id'),clip:string(v.clip,f+'.clip'),time:number(v.time,f+'.time'),animation:optionalString(v.animation,f+'.animation')}))}
|
|
80
89
|
};
|
|
81
90
|
if(manifest.model&&!manifest.model.endsWith('.model.json'))fail('model','compiled model path ending .model.json (the play runtime input)');
|
|
@@ -2,7 +2,7 @@ import {spawn} from 'node:child_process';
|
|
|
2
2
|
import {randomUUID} from 'node:crypto';
|
|
3
3
|
import {open, readFile, unlink} from 'node:fs/promises';
|
|
4
4
|
import {join} from 'node:path';
|
|
5
|
-
import {appRoot} from './build.ts';
|
|
5
|
+
import {appRoot, playBuildConditions} from './build.ts';
|
|
6
6
|
import {frontPort} from './front.ts';
|
|
7
7
|
import {acquireClaim, defaultStateDir, openFingerprint, prepareOpenTarget, readOpenStatus, releaseClaim,
|
|
8
8
|
type OpenInputs, type OpenOptions} from './open.ts';
|
|
@@ -61,7 +61,7 @@ export async function openWorkspace(inputs: readonly OpenInputs[], options: Open
|
|
|
61
61
|
const logPath = join(directory, nonce + '.log');
|
|
62
62
|
const log = await open(logPath, 'a', 0o600);
|
|
63
63
|
try {
|
|
64
|
-
child = spawn(process.execPath, [join(appRoot, 'src/open-workspace-worker.ts'), request],
|
|
64
|
+
child = spawn(process.execPath, [...playBuildConditions().map(c => `--conditions=${c}`), join(appRoot, 'src/open-workspace-worker.ts'), request],
|
|
65
65
|
{cwd: directory, detached: true, stdio: ['ignore', log.fd, log.fd], env: process.env});
|
|
66
66
|
child.unref();
|
|
67
67
|
} finally {await log.close();}
|
package/src/open.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {startCompareServer} from './compare-server.ts';
|
|
|
16
16
|
import {selectAnimation,AnimationSelectionError,type AnimationSelection} from './animation-selection.ts';
|
|
17
17
|
import {capabilityHeader,capabilityPattern,type OpenIdentity} from './open-protocol.ts';
|
|
18
18
|
import {ensureFront,frontPort} from './front.ts';
|
|
19
|
+
import {playBuildConditions} from './build.ts';
|
|
19
20
|
import {playPackagePath} from './versions.ts';
|
|
20
21
|
import {HandoffError,HANDOFF_FLAGS,isBuildRoot,type HandoffFlags,type HandoffRecord} from './handoff.ts';
|
|
21
22
|
import {stateDirInside,stateRoots} from './state-dir.ts';
|
|
@@ -160,7 +161,7 @@ async function ensureWorker(p:OpenPackage,key:string,fingerprint:string,stateDir
|
|
|
160
161
|
const row=await reuse();if(row)return {row,reused:true};
|
|
161
162
|
const identity:OpenIdentity={key,contentHash:p.contentHash,nonce,fingerprint};request=join(canonicalControl,`${key}.${nonce}.request.json`);const log=join(canonicalControl,`${key}.${nonce}.log`);
|
|
162
163
|
const spec:WorkerRequest={schema:'rig-review-open-request/1',inputs:p.inputs,identity,stateDir,registry,request,idleMs,...(graceMs!==undefined?{graceMs}:{}),cwd,...(viewOnly?{viewOnly:true}:{}),...(p.inputs.control?{controlToken:randomUUID()}:{} )};await writeFile(request,JSON.stringify(spec),{mode:0o600,flag:'wx'});
|
|
163
|
-
const logHandle=await openFile(log,'a',0o600);let child;try{child=spawn(process.execPath,[join(appRoot,'src/open-worker.ts'),request],{cwd:canonicalControl,detached:true,stdio:['ignore',logHandle.fd,logHandle.fd],env:process.env});spawned=child;child.unref();}finally{await logHandle.close();}
|
|
164
|
+
const logHandle=await openFile(log,'a',0o600);let child;try{child=spawn(process.execPath,[...playBuildConditions().map(c=>`--conditions=${c}`),join(appRoot,'src/open-worker.ts'),request],{cwd:canonicalControl,detached:true,stdio:['ignore',logHandle.fd,logHandle.fd],env:process.env});spawned=child;child.unref();}finally{await logHandle.close();}
|
|
164
165
|
let exited:string|undefined;child.on('error',error=>{exited=error.message;});child.on('exit',(code,signal)=>{exited=`exit ${code} ${signal??''}`;});
|
|
165
166
|
while(performance.now()<deadline){const record=await reuse();if(record){handedOff=true;return {row:record,reused:false};}if(exited)throw new Error(`OPEN_START: ${exited}; worker log ${log}`);await sleep(30);}throw new Error(`OPEN_TIMEOUT: worker did not become ready; log ${log}`);
|
|
166
167
|
}finally{if(spawned&&!handedOff&&spawned.exitCode===null&&spawned.signalCode===null)spawned.kill('SIGTERM');await releaseClaim(claim,nonce);if(request)await unlink(request).catch(e=>{if(e.code!=='ENOENT')throw e;});}
|