@rig-c/review 4.10.0 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/DESIGN.md +16 -12
- package/docs/PANELS.md +3 -1
- package/docs/REVIEW_PACKAGE.md +91 -16
- package/docs/STABILITY.md +38 -0
- package/package.json +2 -2
- package/src/cloth-recipe.ts +27 -7
- package/src/job-act.ts +4 -2
- package/src/job-api.ts +21 -9
- package/src/job-checkpoint-evidence.ts +17 -0
- package/src/job-contract.ts +18 -2
- package/src/job-front.ts +34 -5
- package/src/job-source.ts +34 -9
- package/src/open-workspace-state.ts +6 -1
- package/src/open.ts +3 -3
- package/src/rebuild.ts +42 -10
- package/src/stage-comment.ts +32 -4
- package/web/catalog-en.ts +13 -2
- package/web/catalog-ko.ts +38 -27
- package/web/cloth-panel.ts +1 -1
- package/web/compare.css +1 -1
- package/web/environment-world.ts +9 -0
- package/web/inspector-blocks.ts +9 -7
- package/web/interview-panel.ts +2 -2
- package/web/job-rig-screen.ts +15 -8
- package/web/job-session.ts +39 -27
- package/web/label-placement.ts +2 -1
- package/web/main.ts +150 -90
- package/web/parts-viewport-provider.ts +2 -2
- package/web/rebuild-client.ts +1 -1
- package/web/rig-host.ts +1 -1
- package/web/rig-viewport-provider.ts +4 -5
- package/web/stage-comments.ts +7 -1
- package/web/styles.css +24 -3
- package/web/viewport-controller.ts +4 -0
- package/web/workspace-layout.ts +8 -6
- package/web/workspace-preferences.ts +10 -8
- package/web/workspace-ui.ts +53 -27
package/src/job-api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {checkpointEvidenceFields} from './job-checkpoint-evidence.ts';
|
|
1
|
+
import {checkpointEvidenceFields, planPictureFields} from './job-checkpoint-evidence.ts';
|
|
2
2
|
import {previousDraftFields} from './job-previous-draft.ts';
|
|
3
3
|
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
4
4
|
import {
|
|
@@ -744,6 +744,7 @@ type ParsedRecordPayload =
|
|
|
744
744
|
| {
|
|
745
745
|
readonly kind: 'plan';
|
|
746
746
|
readonly checkpointEvidence?: readonly JobCheckpointEvidence[];
|
|
747
|
+
readonly planPicture?: JobFileIdentity;
|
|
747
748
|
readonly inputs: readonly JobFileIdentity[];
|
|
748
749
|
readonly files: readonly JobFileIdentity[];
|
|
749
750
|
readonly plan: JobPlanIdentity;
|
|
@@ -761,14 +762,15 @@ function parseRecordClosureAndSubjects(
|
|
|
761
762
|
): ParsedRecordPayload {
|
|
762
763
|
const { inputs, files } = parseFileClosure(rawInputs, rawFiles, checkedRecord, 'JOB_SOURCE_MISMATCH');
|
|
763
764
|
if (selection.kind === 'option-set') {
|
|
764
|
-
if (rawPlan !== null || 'checkpointEvidence' in evidenceHolder) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
765
|
+
if (rawPlan !== null || 'checkpointEvidence' in evidenceHolder || 'planPicture' in evidenceHolder) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
765
766
|
const subjects = parseOptionSubjects(rawSubjects, selection, 'JOB_SOURCE_MISMATCH');
|
|
766
767
|
return { kind: 'option-set', inputs, files, plan: null, subjects };
|
|
767
768
|
}
|
|
768
769
|
if (rawPlan === null) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
769
770
|
const { plan, stepIds } = parsePlanIdentity(rawPlan, 'JOB_SOURCE_MISMATCH');
|
|
770
771
|
const subjects = parsePlanSubjects(rawSubjects, stepIds, 'JOB_SOURCE_MISMATCH');
|
|
771
|
-
return { kind: 'plan', inputs, files, plan, subjects, ...checkpointEvidenceFields(evidenceHolder, plan, subjects, files)
|
|
772
|
+
return { kind: 'plan', inputs, files, plan, subjects, ...checkpointEvidenceFields(evidenceHolder, plan, subjects, files),
|
|
773
|
+
...planPictureFields(evidenceHolder, plan, files) };
|
|
772
774
|
}
|
|
773
775
|
|
|
774
776
|
export function parseRecordPublishedContext(
|
|
@@ -794,7 +796,7 @@ export function parseRecordPublishedContext(
|
|
|
794
796
|
const selection = parseRecordResult(result);
|
|
795
797
|
const checkedRecord = record === undefined ? undefined : parseProjectRecord(record, 'JOB_SOURCE_MISMATCH');
|
|
796
798
|
if (value && typeof value === 'object') previousDraftFields(value, null);
|
|
797
|
-
const item = exactObject(value, ['label', 'parts', 'inputs', 'files', 'plan', 'subjects'], 'JOB_SOURCE_MISMATCH', ['checkpointEvidence']);
|
|
799
|
+
const item = exactObject(value, ['label', 'parts', 'inputs', 'files', 'plan', 'subjects'], 'JOB_SOURCE_MISMATCH', ['checkpointEvidence', 'planPicture']);
|
|
798
800
|
const label = asCode(() => jobText(item.label), 'JOB_SOURCE_MISMATCH');
|
|
799
801
|
const parts = parseRecordPartsIdentity(item.parts, 'JOB_SOURCE_MISMATCH');
|
|
800
802
|
const body = parseRecordClosureAndSubjects(
|
|
@@ -810,7 +812,8 @@ export function parseRecordPublishedContext(
|
|
|
810
812
|
return { label, parts, inputs: body.inputs, files: body.files, plan: null, subjects: body.subjects };
|
|
811
813
|
}
|
|
812
814
|
return { label, parts, inputs: body.inputs, files: body.files, plan: body.plan, subjects: body.subjects,
|
|
813
|
-
...(body.checkpointEvidence ? {checkpointEvidence: body.checkpointEvidence} : {})
|
|
815
|
+
...(body.checkpointEvidence ? {checkpointEvidence: body.checkpointEvidence} : {}),
|
|
816
|
+
...(body.planPicture ? {planPicture: body.planPicture} : {}) };
|
|
814
817
|
}
|
|
815
818
|
|
|
816
819
|
export function assertEqualRecordContexts(
|
|
@@ -838,6 +841,7 @@ export function assertEqualRecordContexts(
|
|
|
838
841
|
|
|
839
842
|
export interface RecordSourceDigestInput {
|
|
840
843
|
readonly checkpointEvidence?: readonly JobCheckpointEvidence[];
|
|
844
|
+
readonly planPicture?: JobFileIdentity;
|
|
841
845
|
readonly schema?: typeof JOB_RECORD_SOURCE_SCHEMA;
|
|
842
846
|
readonly sourceHash?: JobSha256;
|
|
843
847
|
readonly projectHash?: JobSha256;
|
|
@@ -871,6 +875,7 @@ export function serializeRecordSourceDigestPayload(input: RecordSourceDigestInpu
|
|
|
871
875
|
'files',
|
|
872
876
|
'checkpointEvidence',
|
|
873
877
|
'optionSets',
|
|
878
|
+
'planPicture',
|
|
874
879
|
]),
|
|
875
880
|
'JOB_SOURCE_MISMATCH',
|
|
876
881
|
);
|
|
@@ -894,7 +899,7 @@ export function serializeRecordSourceDigestPayload(input: RecordSourceDigestInpu
|
|
|
894
899
|
const { inputs, files, byPath } = parseFileClosure(item.inputs, item.files, record, 'JOB_SOURCE_MISMATCH');
|
|
895
900
|
|
|
896
901
|
if (selection.kind === 'option-set') {
|
|
897
|
-
if ('checkpointEvidence' in item || item.plan !== null || item.optionSet === null || item.optionSetFile === null) {
|
|
902
|
+
if ('checkpointEvidence' in item || 'planPicture' in item || item.plan !== null || item.optionSet === null || item.optionSetFile === null) {
|
|
898
903
|
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
899
904
|
}
|
|
900
905
|
const rawOptionSet = exactObject(item.optionSet, ['id', 'sha256'], 'JOB_SOURCE_MISMATCH');
|
|
@@ -944,6 +949,8 @@ export function serializeRecordSourceDigestPayload(input: RecordSourceDigestInpu
|
|
|
944
949
|
subjects,
|
|
945
950
|
files,
|
|
946
951
|
...checkpointEvidenceFields(item, plan, subjects, files),
|
|
952
|
+
// #983: last, and only when present, so a record without it keeps its source hash.
|
|
953
|
+
...planPictureFields(item, plan, files),
|
|
947
954
|
});
|
|
948
955
|
}
|
|
949
956
|
|
|
@@ -1047,6 +1054,7 @@ function assembleRecordSource(
|
|
|
1047
1054
|
subjects: body.subjects,
|
|
1048
1055
|
files: body.files,
|
|
1049
1056
|
...(body.checkpointEvidence ? {checkpointEvidence: body.checkpointEvidence} : {}),
|
|
1057
|
+
...(body.planPicture ? {planPicture: body.planPicture} : {}),
|
|
1050
1058
|
});
|
|
1051
1059
|
return {
|
|
1052
1060
|
sourceHash,
|
|
@@ -1055,6 +1063,7 @@ function assembleRecordSource(
|
|
|
1055
1063
|
inputs: body.inputs,
|
|
1056
1064
|
files: body.files,
|
|
1057
1065
|
...(body.checkpointEvidence ? {checkpointEvidence: body.checkpointEvidence} : {}),
|
|
1066
|
+
...(body.planPicture ? {planPicture: body.planPicture} : {}),
|
|
1058
1067
|
subject: 'plan',
|
|
1059
1068
|
selection: { kind: 'plan' },
|
|
1060
1069
|
optionSet: null,
|
|
@@ -1104,6 +1113,7 @@ export function buildRecordSource(input: {
|
|
|
1104
1113
|
plan: context.plan,
|
|
1105
1114
|
subjects: context.subjects,
|
|
1106
1115
|
...(context.checkpointEvidence ? {checkpointEvidence: context.checkpointEvidence} : {}),
|
|
1116
|
+
...(context.planPicture ? {planPicture: context.planPicture} : {}),
|
|
1107
1117
|
};
|
|
1108
1118
|
const sets = selection.kind === 'option-set' ? selection.sets : undefined;
|
|
1109
1119
|
if ((sets === undefined) !== (input.optionSetFiles === undefined)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
@@ -1131,7 +1141,7 @@ export function parseRecordSource(value: unknown): RecordSource {
|
|
|
1131
1141
|
'subjects',
|
|
1132
1142
|
],
|
|
1133
1143
|
'JOB_SOURCE_MISMATCH',
|
|
1134
|
-
['checkpointEvidence', 'optionSets'],
|
|
1144
|
+
['checkpointEvidence', 'optionSets', 'planPicture'],
|
|
1135
1145
|
);
|
|
1136
1146
|
const record = parseProjectRecord(item.record, 'JOB_SOURCE_MISMATCH');
|
|
1137
1147
|
const projectHash = asCode(() => jobSha(item.projectHash), 'JOB_SOURCE_MISMATCH');
|
|
@@ -1283,7 +1293,8 @@ export function parseRecordAct(value: unknown): RecordAct {
|
|
|
1283
1293
|
switch (item.kind) {
|
|
1284
1294
|
case 'interview-picks': {
|
|
1285
1295
|
if (source.subject !== 'option-set') throw new JobError('JOB_ACT_INVALID');
|
|
1286
|
-
|
|
1296
|
+
// #1048: `words` is optional and additive; it carries the comments with the same checker as checkpoint and signoff.
|
|
1297
|
+
const rawValue = exactObject(item.value, ['questionId', 'selections', 'note'], 'JOB_ACT_INVALID', ['words']);
|
|
1287
1298
|
const questionId = asCode(() => jobId(rawValue.questionId), 'JOB_ACT_INVALID');
|
|
1288
1299
|
if (received.set && questionId !== received.set.questionId) {
|
|
1289
1300
|
throw new JobError('JOB_ACT_INVALID', `value.questionId ${questionId} is not the act set ${received.set.questionId}/${received.set.setId}`);
|
|
@@ -1300,6 +1311,7 @@ export function parseRecordAct(value: unknown): RecordAct {
|
|
|
1300
1311
|
return { itemId, optionId, otherText };
|
|
1301
1312
|
});
|
|
1302
1313
|
const note = parseActWords(rawValue.note, 'JOB_ACT_INVALID');
|
|
1314
|
+
const words = Object.hasOwn(rawValue, 'words') ? parseActWords(rawValue.words, 'JOB_ACT_INVALID') : undefined;
|
|
1303
1315
|
return {
|
|
1304
1316
|
schema: JOB_RECORD_ACT_SCHEMA,
|
|
1305
1317
|
actId,
|
|
@@ -1310,7 +1322,7 @@ export function parseRecordAct(value: unknown): RecordAct {
|
|
|
1310
1322
|
authority,
|
|
1311
1323
|
at,
|
|
1312
1324
|
source,
|
|
1313
|
-
value: { questionId, selections, note },
|
|
1325
|
+
value: words === undefined ? { questionId, selections, note } : { questionId, selections, note, words },
|
|
1314
1326
|
};
|
|
1315
1327
|
}
|
|
1316
1328
|
case 'checkpoint': {
|
|
@@ -55,6 +55,23 @@ export function checkpointEvidenceFields(holder: object, plan: JobPlanIdentity |
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** #983: the plan-level picture the owner signs against. Plan records only; one sealed raster, by the
|
|
59
|
+
* package page-image rule (png, jpg, webp). Absence must not materialize the field. */
|
|
60
|
+
export function planPictureFields(holder: object, plan: JobPlanIdentity | null,
|
|
61
|
+
files: readonly JobFileIdentity[]): {planPicture?: JobFileIdentity} {
|
|
62
|
+
if (!('planPicture' in holder)) return {};
|
|
63
|
+
try {
|
|
64
|
+
if (!plan) throw new Error('plan only');
|
|
65
|
+
const raw = exactObject(holder.planPicture, ['path', 'sha256'], 'JOB_SOURCE_MISMATCH');
|
|
66
|
+
const planPicture = {path: jobPath(raw.path), sha256: jobSha(raw.sha256)};
|
|
67
|
+
if (!/\.(png|jpe?g|webp)$/i.test(planPicture.path) ||
|
|
68
|
+
!files.some(seal => seal.path === planPicture.path && seal.sha256 === planPicture.sha256)) throw new Error('closure');
|
|
69
|
+
return {planPicture};
|
|
70
|
+
} catch {
|
|
71
|
+
throw new JobError('JOB_SOURCE_MISMATCH', 'PLAN_PICTURE_INVALID');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
58
75
|
/** The sealed document is the sole table body. Preserve columns, rows and scalars. */
|
|
59
76
|
export function parseCheckpointTable(bytes: Buffer): JobCheckpointTable {
|
|
60
77
|
try {
|
package/src/job-contract.ts
CHANGED
|
@@ -353,6 +353,7 @@ export type JobPlanTextProjection = {
|
|
|
353
353
|
readonly record: {readonly path: 'project.json'; readonly sha256: string};
|
|
354
354
|
readonly status: 'projected';
|
|
355
355
|
readonly steps: readonly JobPlanTextStep[];
|
|
356
|
+
readonly questions?: Readonly<Record<string, string>>;
|
|
356
357
|
} | {
|
|
357
358
|
readonly schema: typeof JOB_PLAN_TEXT_SCHEMA;
|
|
358
359
|
readonly record: {readonly path: 'project.json'; readonly sha256: string} | null;
|
|
@@ -368,7 +369,7 @@ export function parseJobPlanTextProjection(value: unknown): JobPlanTextProjectio
|
|
|
368
369
|
Object.keys(input).some(key => !keys.includes(key))) return fail();
|
|
369
370
|
return input as Record<string, unknown>;
|
|
370
371
|
};
|
|
371
|
-
const envelope = object(value, ['schema', 'record', 'status', 'steps', 'reason']);
|
|
372
|
+
const envelope = object(value, ['schema', 'record', 'status', 'steps', 'questions', 'reason']);
|
|
372
373
|
if (envelope.schema !== JOB_PLAN_TEXT_SCHEMA || !Object.hasOwn(envelope, 'record') ||
|
|
373
374
|
new TextEncoder().encode(JSON.stringify(value)).length > 512 * 1024) return fail();
|
|
374
375
|
if (envelope.record !== null) {
|
|
@@ -376,11 +377,17 @@ export function parseJobPlanTextProjection(value: unknown): JobPlanTextProjectio
|
|
|
376
377
|
if (record.path !== 'project.json' || typeof record.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(record.sha256)) return fail();
|
|
377
378
|
}
|
|
378
379
|
if (envelope.status === 'unavailable') {
|
|
379
|
-
if (Object.hasOwn(envelope, 'steps') ||
|
|
380
|
+
if (Object.hasOwn(envelope, 'steps') || Object.hasOwn(envelope, 'questions') ||
|
|
381
|
+
!(JOB_PLAN_TEXT_UNAVAILABLE as readonly unknown[]).includes(envelope.reason)) return fail();
|
|
380
382
|
return value as JobPlanTextProjection;
|
|
381
383
|
}
|
|
382
384
|
if (envelope.status !== 'projected' || envelope.record === null || Object.hasOwn(envelope, 'reason') ||
|
|
383
385
|
!Array.isArray(envelope.steps) || envelope.steps.length > 4096) return fail();
|
|
386
|
+
if (Object.hasOwn(envelope, 'questions')) {
|
|
387
|
+
const questions = envelope.questions;
|
|
388
|
+
if (!questions || typeof questions !== 'object' || Array.isArray(questions) ||
|
|
389
|
+
Object.entries(questions).some(([id, text]) => !id || id.length > 128 || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(id) || typeof text !== 'string')) return fail();
|
|
390
|
+
}
|
|
384
391
|
const ids = new Set<string>();
|
|
385
392
|
for (const raw of envelope.steps) {
|
|
386
393
|
const row = object(raw, ['id', 'hash', ...JOB_PLAN_TEXT_FIELDS, 'issues']);
|
|
@@ -538,6 +545,9 @@ export interface JobActValues {
|
|
|
538
545
|
readonly otherText: string | null;
|
|
539
546
|
}[];
|
|
540
547
|
readonly note: string;
|
|
548
|
+
/** #1048: optional and additive. Present only when the reviewer left comments; exactly the `projectComments`
|
|
549
|
+
* output that checkpoint and signoff carry. An act without comments has no `words` key. */
|
|
550
|
+
readonly words?: string;
|
|
541
551
|
};
|
|
542
552
|
readonly checkpoint: {
|
|
543
553
|
readonly checkpointId: string;
|
|
@@ -1164,6 +1174,7 @@ export interface RecordContextBase {
|
|
|
1164
1174
|
|
|
1165
1175
|
export type OptionContext = RecordContextBase & {
|
|
1166
1176
|
readonly checkpointEvidence?: never;
|
|
1177
|
+
readonly planPicture?: never;
|
|
1167
1178
|
readonly plan: null;
|
|
1168
1179
|
/** One `interview-picks` subject per published set, in set order. */
|
|
1169
1180
|
readonly subjects: readonly RecordPicksSubject[];
|
|
@@ -1171,6 +1182,8 @@ export type OptionContext = RecordContextBase & {
|
|
|
1171
1182
|
|
|
1172
1183
|
export type PlanContext = RecordContextBase & {
|
|
1173
1184
|
readonly checkpointEvidence?: readonly JobCheckpointEvidence[];
|
|
1185
|
+
/** #983: the sealed raster (an entry of `files`) the owner signs the plan against; drawn first. */
|
|
1186
|
+
readonly planPicture?: JobFileIdentity;
|
|
1174
1187
|
readonly plan: JobPlanIdentity;
|
|
1175
1188
|
readonly subjects: readonly RecordPlanSubject[];
|
|
1176
1189
|
};
|
|
@@ -1215,6 +1228,7 @@ export interface RecordSourceBase {
|
|
|
1215
1228
|
|
|
1216
1229
|
export type OptionSource = RecordSourceBase & {
|
|
1217
1230
|
readonly checkpointEvidence?: never;
|
|
1231
|
+
readonly planPicture?: never;
|
|
1218
1232
|
readonly subject: 'option-set';
|
|
1219
1233
|
readonly selection: RecordOptionResult;
|
|
1220
1234
|
readonly optionSet: { readonly id: string; readonly sha256: JobSha256 };
|
|
@@ -1236,6 +1250,8 @@ export interface RecordOptionSetBinding {
|
|
|
1236
1250
|
|
|
1237
1251
|
export type PlanSource = RecordSourceBase & {
|
|
1238
1252
|
readonly checkpointEvidence?: readonly JobCheckpointEvidence[];
|
|
1253
|
+
/** #983: equal to an entry of `files`; bound into `sourceHash` only when present. */
|
|
1254
|
+
readonly planPicture?: JobFileIdentity;
|
|
1239
1255
|
readonly subject: 'plan';
|
|
1240
1256
|
readonly selection: RecordPlanResult;
|
|
1241
1257
|
readonly optionSet: null;
|
package/src/job-front.ts
CHANGED
|
@@ -28,6 +28,26 @@ const headers = {
|
|
|
28
28
|
'Referrer-Policy': 'no-referrer',
|
|
29
29
|
'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'",
|
|
30
30
|
};
|
|
31
|
+
/** #1050 cache policy. Every capability-bearing or computed response keeps `no-store` (`headers`).
|
|
32
|
+
* A sealed snapshot file is served only under its publication's instance route, whose publication id is new on every
|
|
33
|
+
* publish and whose instance key binds the source hash, and the seal refuses any other bytes: one URL, one content.
|
|
34
|
+
* `private` because the loopback server holds one user's work and no shared cache may keep it. */
|
|
35
|
+
const sealedHeaders = (sha256: string) => ({...headers, 'Cache-Control': 'private, max-age=31536000, immutable', ETag: `"${sha256}"`});
|
|
36
|
+
/** The shipped page files keep one URL across review upgrades: revalidate each load (the job liveness gate still runs). */
|
|
37
|
+
const resourceHashes = new WeakMap<object, string>();
|
|
38
|
+
async function shippedResource(request: Request, body: BodyInit, type: string): Promise<Response> {
|
|
39
|
+
// Bun's bundle is a BuildArtifact: Blob-like, not a Blob instance. Its hash is kept for the artifact's life.
|
|
40
|
+
const blob = typeof body === 'object' && 'arrayBuffer' in body && typeof body.arrayBuffer === 'function' ? body as {arrayBuffer(): Promise<ArrayBuffer>} : null;
|
|
41
|
+
let hash = blob ? resourceHashes.get(blob) : undefined;
|
|
42
|
+
if (!hash && (typeof body === 'string' || body instanceof Uint8Array || blob)) {
|
|
43
|
+
hash = jobHash(blob ? new Uint8Array(await blob.arrayBuffer()) : body as string | Uint8Array);
|
|
44
|
+
if (blob) resourceHashes.set(blob, hash);
|
|
45
|
+
}
|
|
46
|
+
const etag = hash ? `"${hash}"` : null;
|
|
47
|
+
const responseHeaders = {...headers, 'Content-Type': type, ...(etag ? {'Cache-Control': 'no-cache', ETag: etag} : {})};
|
|
48
|
+
if (etag && request.headers.get('if-none-match') === etag) return new Response(null, {status: 304, headers: responseHeaders});
|
|
49
|
+
return new Response(request.method === 'HEAD' ? null : body, {headers: responseHeaders});
|
|
50
|
+
}
|
|
31
51
|
interface CropFailureDiagnostic {
|
|
32
52
|
field: string;
|
|
33
53
|
expected: string | number[];
|
|
@@ -206,9 +226,7 @@ export function createJobFront(options: {
|
|
|
206
226
|
if (!name)
|
|
207
227
|
return failure('JOB_REQUEST_INVALID', 404);
|
|
208
228
|
const type = name === 'index.html' ? 'text/html; charset=utf-8' : name === 'main.js' ? 'text/javascript' : 'text/css';
|
|
209
|
-
return
|
|
210
|
-
headers: { ...headers, 'Content-Type': type },
|
|
211
|
-
});
|
|
229
|
+
return shippedResource(request, await options.resource(name), type);
|
|
212
230
|
}
|
|
213
231
|
return {
|
|
214
232
|
fetch: fetchJob,
|
|
@@ -269,7 +287,9 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
269
287
|
const file = await safeFile(retained.snapshotRoot, relativePath);
|
|
270
288
|
if (literal !== undefined && literal !== file)
|
|
271
289
|
return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
272
|
-
|
|
290
|
+
const cached = sealedHeaders(seal.sha256);
|
|
291
|
+
if (request.headers.get('if-none-match') === cached.ETag) return new Response(null, {status: 304, headers: cached});
|
|
292
|
+
return serveReference(request, file, seal.sha256, cached);
|
|
273
293
|
};
|
|
274
294
|
const reviewMetadata = (review: ReviewPackage | null) => json({
|
|
275
295
|
...checkpointEvidenceMetadata(retained.snapshotRoot, retained.source.checkpointEvidence),
|
|
@@ -295,11 +315,15 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
295
315
|
const interviewMetadata = (rigPicture = false, painting?: NonNullable<ReturnType<typeof retainedRecordPainting>>) => {
|
|
296
316
|
const interview = isRetainedRecordSource(retained) ? undefined :
|
|
297
317
|
retained.interview !== undefined ? retained.interview : display.publication.interview;
|
|
318
|
+
// #1048: a record question image names its sealed `files` entry, so a pin binds to those bytes.
|
|
319
|
+
const sealed = isRetainedRecordSource(retained) ? retained.source.files : [];
|
|
298
320
|
return json({
|
|
299
321
|
questions: questions.map(question => ({...question,
|
|
300
322
|
...(rigPicture && question.missingPicture === 'rig' ? {missingPicture: undefined} : {}),
|
|
301
323
|
images: (painting && question.missingPicture ? [painting] : question.images).map((image, index) => ({name: image.name,
|
|
302
|
-
url: `/api/interview/image/${question.ref.sha256}/${index}
|
|
324
|
+
url: `/api/interview/image/${question.ref.sha256}/${index}`,
|
|
325
|
+
...(sealed.some(file => file.path === image.ref.path && file.sha256 === image.ref.sha256)
|
|
326
|
+
? {path: image.ref.path, sha256: image.ref.sha256} : {})})),
|
|
303
327
|
})),
|
|
304
328
|
...(interview === undefined ? {} : {interview}),
|
|
305
329
|
});
|
|
@@ -325,6 +349,11 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
325
349
|
return await sealedFile(member.path);
|
|
326
350
|
}
|
|
327
351
|
if (isRetainedRecordSource(retained)) {
|
|
352
|
+
// #983: the declared plan picture is an exact sealed member; no other file is reachable here.
|
|
353
|
+
if (path === 'api/plan-picture') {
|
|
354
|
+
const picture = retained.source.subject === 'plan' ? retained.source.planPicture : undefined;
|
|
355
|
+
return picture ? await sealedFile(picture.path) : failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
356
|
+
}
|
|
328
357
|
// hasParts is projected only after validating the option's sealed draft closure.
|
|
329
358
|
const question = retained.questions.find(question => question.hasParts);
|
|
330
359
|
if (question && (path === 'api/stage-parts' || /^api\/stage-parts\/(image|page)\/(0|[1-9]\d*)$/.test(path))) {
|
package/src/job-source.ts
CHANGED
|
@@ -956,15 +956,29 @@ export async function loadRetainedRecordRig(retained: JobRetainedRecordSource) {
|
|
|
956
956
|
}
|
|
957
957
|
}
|
|
958
958
|
|
|
959
|
-
/** Create declares the original painting as the first project input. */
|
|
959
|
+
/** Create declares the original painting as `project.painting`, or as the first project input on older records. */
|
|
960
960
|
export function retainedRecordPainting(retained: JobRetainedRecordSource): Pick<InterviewQuestion['images'][number], 'ref' | 'name'> | null {
|
|
961
961
|
const {project} = readProjectRecordBytes(retained.snapshotRoot, retained.record);
|
|
962
|
-
const
|
|
962
|
+
const inputs = Array.isArray(project.inputs) ? project.inputs : [];
|
|
963
|
+
let rawInput: unknown = null;
|
|
964
|
+
if (Object.hasOwn(project, 'painting')) {
|
|
965
|
+
if (typeof project.painting !== 'string') return null;
|
|
966
|
+
rawInput = inputs.find(item => asPlainObject(item)?.path === project.painting) ?? null;
|
|
967
|
+
} else {
|
|
968
|
+
rawInput = inputs[0] ?? null;
|
|
969
|
+
}
|
|
970
|
+
const input = asPlainObject(rawInput);
|
|
963
971
|
const seal = retained.seals.find(file => file.path === input?.path && file.sha256 === input?.sha256);
|
|
964
972
|
if (!seal || !/\.(png|jpe?g|webp|svg)$/i.test(seal.path)) return null;
|
|
965
973
|
return {ref: seal, name: posix.basename(seal.path)};
|
|
966
974
|
}
|
|
967
975
|
|
|
976
|
+
const recordInterviewCollections = (interview: Record<string, unknown>) => [
|
|
977
|
+
[interview.framing, ['interview']],
|
|
978
|
+
[interview.waypoints, ['interview', 'rigging-interview']],
|
|
979
|
+
[asPlainObject(interview.post)?.items, ['post-interview']],
|
|
980
|
+
] as const;
|
|
981
|
+
|
|
968
982
|
/** Delivery-only projection through the existing retained record reader. */
|
|
969
983
|
export function projectRetainedPlanText(retained: JobRetainedSourceV3): JobPlanTextProjection | undefined {
|
|
970
984
|
const {source, record} = retained;
|
|
@@ -1024,7 +1038,20 @@ export function projectRetainedPlanText(retained: JobRetainedSourceV3): JobPlanT
|
|
|
1024
1038
|
}
|
|
1025
1039
|
return {id:step.id, hash:step.hash, ...fields, issues};
|
|
1026
1040
|
});
|
|
1027
|
-
const
|
|
1041
|
+
const questions: Record<string, string> = {};
|
|
1042
|
+
const interview = asPlainObject(project.interview);
|
|
1043
|
+
if (interview) {
|
|
1044
|
+
for (const [items] of recordInterviewCollections(interview)) {
|
|
1045
|
+
for (const rawItem of Array.isArray(items) ? items : []) {
|
|
1046
|
+
const item = asPlainObject(rawItem);
|
|
1047
|
+
if (typeof item?.id === 'string' && item.id.length <= 128 && /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(item.id) &&
|
|
1048
|
+
typeof item.text === 'string' && !Object.hasOwn(questions, item.id))
|
|
1049
|
+
questions[item.id] = item.text;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
const projection: JobPlanTextProjection = {schema:JOB_PLAN_TEXT_SCHEMA, record:identity, status:'projected', steps,
|
|
1054
|
+
...(Object.keys(questions).length ? {questions} : {})};
|
|
1028
1055
|
return Buffer.byteLength(JSON.stringify(projection)) > 512 * 1024 ? unavailable('PLAN_TEXT_LIMIT') : projection;
|
|
1029
1056
|
}
|
|
1030
1057
|
|
|
@@ -1068,11 +1095,7 @@ function decodeRetainedRecordProject(
|
|
|
1068
1095
|
if (!interview) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1069
1096
|
// #1004: one question per published set, in set order; one set keeps the original single-question result.
|
|
1070
1097
|
const decodedSets = optionSetRefs(result).map(({ questionId, setId }) => {
|
|
1071
|
-
const collections =
|
|
1072
|
-
[interview.framing, ['interview']],
|
|
1073
|
-
[interview.waypoints, ['interview', 'rigging-interview']],
|
|
1074
|
-
[asPlainObject(interview.post)?.items, ['post-interview']],
|
|
1075
|
-
] as const;
|
|
1098
|
+
const collections = recordInterviewCollections(interview);
|
|
1076
1099
|
const matches: { readonly pending: unknown; readonly allowedStages: readonly string[] }[] = [];
|
|
1077
1100
|
for (const [items, allowedStages] of collections) {
|
|
1078
1101
|
if (items !== undefined && !Array.isArray(items)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
@@ -1725,9 +1748,11 @@ export function assertStoredCheckpointEvidence(retained: JobRetainedSourceV3): v
|
|
|
1725
1748
|
if (isRetainedRecordSource(retained)) {
|
|
1726
1749
|
if ('chestLandmarks' in retained) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1727
1750
|
const parsed = parseRecordSource(retained.source);
|
|
1728
|
-
if (!hasEvidence && !('
|
|
1751
|
+
if (!hasEvidence && !('planPicture' in retained.source) && !('checkpointEvidence' in retained.context) &&
|
|
1752
|
+
!('planPicture' in retained.context) && !('previousDraft' in retained.context)) return;
|
|
1729
1753
|
const context = parseRecordPublishedContext(retained.context, retained.result, retained.record);
|
|
1730
1754
|
if (requestDigest(parsed.checkpointEvidence ?? null) !== requestDigest(context.checkpointEvidence ?? null) ||
|
|
1755
|
+
requestDigest(parsed.planPicture ?? null) !== requestDigest(context.planPicture ?? null) ||
|
|
1731
1756
|
requestDigest(parsed.subjects) !== requestDigest(retained.subjects) ||
|
|
1732
1757
|
requestDigest(parsed.files) !== requestDigest(retained.seals)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1733
1758
|
return;
|
|
@@ -32,7 +32,12 @@ export async function readPrivate(path: string): Promise<unknown | null> {
|
|
|
32
32
|
const info = await lstat(path);
|
|
33
33
|
// lstat can finish with nlink=0 during unlink. Establish that the path still
|
|
34
34
|
// opens before validating that snapshot; a vanished path remains ENOENT.
|
|
35
|
-
|
|
35
|
+
// On Linux the open can still reach that same detached inode (fstat nlink=0, #894):
|
|
36
|
+
// no path names it any more, so it is absent too. A reappeared file still refuses.
|
|
37
|
+
return await smallJson(path, opened => {
|
|
38
|
+
if (info.nlink === 0 && opened.nlink === 0) throw Object.assign(new Error('detached'), {code: 'ENOENT'});
|
|
39
|
+
assertPrivateInfo(info, false);
|
|
40
|
+
});
|
|
36
41
|
}
|
|
37
42
|
catch (error) {if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null; throw workspaceError('WORKSPACE_STATE_INVALID');}
|
|
38
43
|
}
|
package/src/open.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {createHash,randomBytes,randomUUID} from 'node:crypto';
|
|
|
5
5
|
import {spawn} from 'node:child_process';
|
|
6
6
|
import {homedir} from 'node:os';
|
|
7
7
|
import {mkdir,readFile,readdir,writeFile,rename,unlink,rm,rmdir,realpath,lstat,stat,open as openFile} from 'node:fs/promises';
|
|
8
|
-
import {constants} from 'node:fs';
|
|
8
|
+
import {constants,type Stats} from 'node:fs';
|
|
9
9
|
import {basename,dirname,join,resolve,isAbsolute} from 'node:path';
|
|
10
10
|
import {fileURLToPath} from 'node:url';
|
|
11
11
|
import {loadReferencedReview,selectedReference,assertReviewUnchanged} from './reference.ts';
|
|
@@ -73,8 +73,8 @@ export function openKey(p:OpenPackage,fingerprint:string):string {return digest(
|
|
|
73
73
|
/** Handoff URL: the managed front's `/instances/<key>/` path (or the worker's own origin when direct). The
|
|
74
74
|
* capability rides in the fragment, which browsers never send to a server; the page stores and strips it. */
|
|
75
75
|
export function openUrl(record:Pick<RecordFile,'origin'|'key'|'contentHash'|'capability'>,front?:string):string {const url=new URL(front?`${front}/instances/${record.key}/`:record.origin);url.searchParams.set('input',record.contentHash);url.searchParams.set('handoff',record.key);url.hash='cap='+record.capability;return url.href;}
|
|
76
|
-
/** Optional caller validation runs after open, before any content read, inside the close guard. */
|
|
77
|
-
export async function smallJson(file:string,validate?:()=>void):Promise<unknown>{const handle=await openFile(file,constants.O_RDONLY|constants.O_NOFOLLOW|constants.O_NONBLOCK);try{
|
|
76
|
+
/** Optional caller validation runs after open with the opened descriptor's fstat, before any content read, inside the close guard. */
|
|
77
|
+
export async function smallJson(file:string,validate?:(opened:Stats)=>void):Promise<unknown>{const handle=await openFile(file,constants.O_RDONLY|constants.O_NOFOLLOW|constants.O_NONBLOCK);try{const before=await handle.stat();validate?.(before);if(!before.isFile()||before.size>65536)throw new Error('open state: bounded regular file required');const buffer=Buffer.alloc(before.size+1);let size=0;while(size<buffer.length){const next=await handle.read(buffer,size,buffer.length-size,size);if(!next.bytesRead)break;size+=next.bytesRead;}const after=await handle.stat();if(size!==before.size||before.size!==after.size||before.mtimeMs!==after.mtimeMs)throw new Error('open state: changed while reading');return JSON.parse(buffer.subarray(0,size).toString('utf8'));}finally{await handle.close();}}
|
|
78
78
|
function recordValue(value:unknown,key:string):RecordFile|null {if(!value||typeof value!=='object')return null;const v=value as Partial<RecordFile>;return v.schema==='rig-review-open-instance/1'&&v.key===key&&/^[a-f0-9]{64}$/.test(v.contentHash??'')&&/^[a-f0-9]{64}$/.test(v.fingerprint??'')&&typeof v.nonce==='string'&&/^[a-f0-9-]{36}$/.test(v.nonce)&&typeof v.origin==='string'&&/^http:\/\/127\.0\.0\.1:[1-9]\d{0,4}$/.test(v.origin)&&Number(v.origin.slice(v.origin.lastIndexOf(':')+1))<=65535&&Number.isSafeInteger(v.pid)&&v.pid!>0&&(v.mode==='single'||v.mode==='compare')&&capabilityPattern.test(v.capability??'')?v as RecordFile:null;}
|
|
79
79
|
export async function readRecord(file:string,key:string):Promise<RecordFile|null>{try{return recordValue(await smallJson(file),key);}catch(e){if(['ENOENT','ELOOP'].includes((e as NodeJS.ErrnoException).code??'')||e instanceof SyntaxError)return null;throw e;}}
|
|
80
80
|
/** Hard byte ceiling and body deadline, including stalled or chunked responses. */
|
package/src/rebuild.ts
CHANGED
|
@@ -34,7 +34,7 @@ import { producerHint } from './baseline-reach.ts';
|
|
|
34
34
|
import { carriedCheck, carriedCheckSummary, type CarryingOp, provenanceFile, REMESH_CHECK_SINCE, RETUNE_CHECK_SINCE, revisionBinding } from './retune-check.ts';
|
|
35
35
|
import { absolutizeBuildFiles, buildLines, buildNamedFiles, buildReadout, MAX_BUILD_READOUT, needsBuild, newBuildFile, recompositeFigures, type RecompositeFigures } from './build-route.ts';
|
|
36
36
|
import { jsonDiff } from './config-patch.ts';
|
|
37
|
-
import { CLOTH_KEYPOINTS_UNDECLARED, CLOTH_PATCH_MIXED, CLOTH_SOURCE_UNAVAILABLE, CLOTH_WRITE_SINCE, clothLinks, clothPatchKind,
|
|
37
|
+
import { CLOTH_KEYPOINTS_UNDECLARED, CLOTH_PATCH_MIXED, CLOTH_SOURCE_UNAVAILABLE, CLOTH_TARGETS_EXPORT, CLOTH_TARGETS_INVALID, CLOTH_TARGETS_UNAVAILABLE, CLOTH_WRITE_SINCE, clothLinks, clothPatchKind, clothTargetsUnavailable, ClothTargetsError, configClothTags, parseClothTargets, writtenDiff, type ClothTagView, type WrittenDiff } from './cloth-recipe.ts';
|
|
38
38
|
import { CHECK_ENVIRONMENT_SINCE, parseSchedule, ScheduleError, scheduleText } from './environment-schedule.ts';
|
|
39
39
|
import { availableParallelism } from 'node:os';
|
|
40
40
|
import { candidateRow, DENSITY_STRIP_SCHEMA, DensityStripError, stripLabels, stripPatches, stripShape, type DensityField, type StripRow } from './density-strip.ts';
|
|
@@ -552,13 +552,36 @@ export interface ClothJob {
|
|
|
552
552
|
/** #111: what a cloth Apply runs with — the handoff's painting and keypoints (absolute), parts.json and the reader's tags; never from the client. */
|
|
553
553
|
export interface ClothPlan { source: string; keypoints: string; partsJson: unknown; targets: string[]; namedAssembly?: BuildPlan | RebuildError }
|
|
554
554
|
/**
|
|
555
|
-
* The tags the installed reader accepts,
|
|
556
|
-
*
|
|
555
|
+
* The tags the installed reader accepts, resolved from its `package.json` `exports["./cloth-targets.json"]`
|
|
556
|
+
* (`rig-parts/cloth-targets@1`) inside the package directory; when that export key is absent on an older producer,
|
|
557
|
+
* the tags the config's `cloth` block already declares (`read: false` and `CLOTH_TARGETS_UNAVAILABLE` naming the version).
|
|
557
558
|
*/
|
|
558
|
-
export async function clothTargets(producerRoot: string | null, configText: string): Promise<{ tags: string[]; read: boolean }> {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
559
|
+
export async function clothTargets(producerRoot: string | null, configText: string): Promise<{ tags: string[]; read: boolean; reason: string | null }> {
|
|
560
|
+
const fallback = () => configClothTags(object(JSON.parse(configText), 'config'));
|
|
561
|
+
if (!producerRoot) return { tags: fallback(), read: false, reason: null };
|
|
562
|
+
let pkgReal: string, pkgText: string;
|
|
563
|
+
try { pkgReal = await realpath(producerRoot); pkgText = await readFile(join(pkgReal, 'package.json'), 'utf8'); }
|
|
564
|
+
catch { return { tags: fallback(), read: false, reason: clothTargetsUnavailable('unknown') }; }
|
|
565
|
+
let pkg: Record<string, unknown>;
|
|
566
|
+
try { pkg = object(JSON.parse(pkgText), 'package.json'); }
|
|
567
|
+
catch { throw new RebuildError(CLOTH_TARGETS_INVALID, 'package.json is not a JSON object'); }
|
|
568
|
+
const version = typeof pkg.version === 'string' && pkg.version.trim() ? pkg.version.trim() : 'unknown';
|
|
569
|
+
const exportsMap = pkg.exports && typeof pkg.exports === 'object' && !Array.isArray(pkg.exports) ? pkg.exports as Record<string, unknown> : null;
|
|
570
|
+
if (!exportsMap || exportsMap[CLOTH_TARGETS_EXPORT] === undefined) {
|
|
571
|
+
return { tags: fallback(), read: false, reason: clothTargetsUnavailable(version) };
|
|
572
|
+
}
|
|
573
|
+
const entry = exportsMap[CLOTH_TARGETS_EXPORT];
|
|
574
|
+
if (typeof entry !== 'string' || !entry.startsWith('./')) {
|
|
575
|
+
throw new RebuildError(CLOTH_TARGETS_INVALID, `exports[${JSON.stringify(CLOTH_TARGETS_EXPORT)}] must be a string path starting with "./"`);
|
|
576
|
+
}
|
|
577
|
+
let text: string;
|
|
578
|
+
try { text = await readFile(await safeFile(pkgReal, entry.slice(2)), 'utf8'); }
|
|
579
|
+
catch (e) { throw new RebuildError(CLOTH_TARGETS_INVALID, e instanceof Error ? e.message : String(e)); }
|
|
580
|
+
let parsed: unknown;
|
|
581
|
+
try { parsed = JSON.parse(text); }
|
|
582
|
+
catch { throw new RebuildError(CLOTH_TARGETS_INVALID, `exports[${JSON.stringify(CLOTH_TARGETS_EXPORT)}] is not valid JSON`); }
|
|
583
|
+
try { return { tags: parseClothTargets(parsed), read: true, reason: null }; }
|
|
584
|
+
catch (e) { if (e instanceof ClothTargetsError) throw new RebuildError(CLOTH_TARGETS_INVALID, e.message.slice(CLOTH_TARGETS_INVALID.length + 2)); throw e; }
|
|
562
585
|
}
|
|
563
586
|
/** A written config that differs from its input outside the drafted sections is not built (bar 1, #111). */
|
|
564
587
|
export const CLOTH_WRITTEN_OUTSIDE_DRAFTED = 'CLOTH_WRITTEN_OUTSIDE_DRAFTED';
|
|
@@ -1260,13 +1283,17 @@ export function createRebuilds(p: ReviewPackage, options: RebuildOptions) {
|
|
|
1260
1283
|
const config = object(JSON.parse(inputs.configText), 'config');
|
|
1261
1284
|
let partsJson: unknown = null;
|
|
1262
1285
|
try { partsJson = JSON.parse(await readFile(join(inputs.parts, 'parts.json'), 'utf8')); } catch { /* none: no tag lists its parts */ }
|
|
1263
|
-
|
|
1286
|
+
let targets: { tags: string[]; read: boolean; reason: string | null };
|
|
1287
|
+
let targetsInvalid: string | null = null;
|
|
1288
|
+
try { targets = await clothTargets(resolved.ok ? resolved.producer.root : null, inputs.configText); }
|
|
1289
|
+
catch (e) { if (!(e instanceof RebuildError)) throw e; targets = { tags: configClothTags(config), read: false, reason: e.message }; targetsInvalid = e.message; }
|
|
1264
1290
|
const reason = !handoff.keypoints || !handoff.record.keypoints ? CLOTH_KEYPOINTS_UNDECLARED
|
|
1265
1291
|
: !resolved.ok ? resolved.error
|
|
1266
1292
|
: !versionAtLeast(resolved.producer.version, CLOTH_WRITE_SINCE) ? modelingProducerTooOld(resolved.producer.version || 'unknown', CLOTH_WRITE_SINCE, 'rig-parts propose --cloth --write-config (entry by entry)')
|
|
1293
|
+
: targetsInvalid ? targetsInvalid
|
|
1267
1294
|
: !handoff.source ? CLOTH_SOURCE_UNAVAILABLE
|
|
1268
1295
|
: config.limbs !== undefined && !handoff.full ? BUILD_SOURCE_UNAVAILABLE : null;
|
|
1269
|
-
return { targets: targets.tags, targetsRead: targets.read, recipes: config.cloth ?? null, tags: clothLinks(config, partsJson, targets.tags), keypoints: handoff.record.keypoints ?? null, route: config.limbs !== undefined ? 'build' : 'rig', reason };
|
|
1296
|
+
return { targets: targets.tags, targetsRead: targets.read, targetsReason: targets.reason, recipes: config.cloth ?? null, tags: clothLinks(config, partsJson, targets.tags), keypoints: handoff.record.keypoints ?? null, route: config.limbs !== undefined ? 'build' : 'rig', reason };
|
|
1270
1297
|
}
|
|
1271
1298
|
/** The inspected build's check once it settles (tests); null when the baseline did not reproduce. */
|
|
1272
1299
|
async function settledInspectedCheck(): Promise<InspectedCheck | null> { await settledBaseline(); return inspectedCheckRun ? await inspectedCheckRun : inspectedCheck; }
|
|
@@ -1864,9 +1891,14 @@ export function createRebuilds(p: ReviewPackage, options: RebuildOptions) {
|
|
|
1864
1891
|
if (clothing) {
|
|
1865
1892
|
if (!versionAtLeast(resolved.producer.version, CLOTH_WRITE_SINCE)) { const error = modelingProducerTooOld(resolved.producer.version || 'unknown', CLOTH_WRITE_SINCE, 'rig-parts propose --cloth --write-config (entry by entry)'); return { status: 200, body: { status: 'refused', error, producerLine: error } }; }
|
|
1866
1893
|
if (!p.handoff!.source) throw new RebuildError('MODELING_INPUT_UNAVAILABLE', CLOTH_SOURCE_UNAVAILABLE.slice('MODELING_INPUT_UNAVAILABLE: '.length));
|
|
1894
|
+
const targets = await clothTargets(resolved.producer.root, inputs.configText);
|
|
1895
|
+
if (!targets.read && configClothTags(patched).some(t => !targets.tags.includes(t))) {
|
|
1896
|
+
const error = targets.reason ?? clothTargetsUnavailable(resolved.producer.version);
|
|
1897
|
+
throw new RebuildError(CLOTH_TARGETS_UNAVAILABLE, error.slice(CLOTH_TARGETS_UNAVAILABLE.length + 2));
|
|
1898
|
+
}
|
|
1867
1899
|
let partsJson: unknown = null;
|
|
1868
1900
|
try { partsJson = JSON.parse(await readFile(join(inputs.parts, 'parts.json'), 'utf8')); } catch { /* propose reads parts.json itself and refuses by name */ }
|
|
1869
|
-
clothPlan = { source: p.handoff!.source, keypoints: p.handoff!.keypoints!, partsJson, targets:
|
|
1901
|
+
clothPlan = { source: p.handoff!.source, keypoints: p.handoff!.keypoints!, partsJson, targets: targets.tags };
|
|
1870
1902
|
}
|
|
1871
1903
|
// Decision 2 (#111): the written config is built as #115 builds when it declares limbs, else by `rig --config`.
|
|
1872
1904
|
const building = patch.op.cmd === 'rig' && (needsBuild(patch.ops, original) || (clothing && !!original && typeof original === 'object' && !Array.isArray(original) && (original as Record<string, unknown>).limbs !== undefined));
|
package/src/stage-comment.ts
CHANGED
|
@@ -8,14 +8,41 @@ import type {CompareFeedback} from './compare-session.ts';
|
|
|
8
8
|
export interface MarkPoint {x:number;y:number}
|
|
9
9
|
export interface MarkRegion {x:number;y:number;width:number;height:number}
|
|
10
10
|
|
|
11
|
+
/** A sealed record file a pin can name: the path and sha256 of an entry of the publication's `files` (#1048). */
|
|
12
|
+
export interface PictureIdentity {readonly path: string; readonly sha256: string}
|
|
13
|
+
const pictureLabelInvalid = (why: string): never => { throw new Error('COMMENT_PICTURE_LABEL_INVALID: ' + why); };
|
|
14
|
+
/** #1048 A1: `[schema, mode, 'reference', referenceId, referenceHash, x, y, w, h]`, integers in the picture's natural pixels, Y down. */
|
|
15
|
+
function pictureCommentLabel(mark: StageComment, picture: PictureIdentity): string {
|
|
16
|
+
if (mark.referenceHash !== picture.sha256) pictureLabelInvalid(`referenceHash is not the sealed sha256 of ${picture.path}`);
|
|
17
|
+
const {x, y, width, height} = mark.world;
|
|
18
|
+
const label = JSON.stringify([mark.schema, mark.mode, 'reference', picture.path, picture.sha256,
|
|
19
|
+
Math.round(x), Math.round(y), Math.round(width), Math.round(height)]);
|
|
20
|
+
parsePictureCommentLabel(label);
|
|
21
|
+
return label;
|
|
22
|
+
}
|
|
23
|
+
/** The restore path's inverse of the A1 label; anything else refuses by name. */
|
|
24
|
+
export function parsePictureCommentLabel(label: string): {mode: CommentMode; referenceId: string; referenceHash: string; region: MarkRegion} {
|
|
25
|
+
let value: unknown;
|
|
26
|
+
try { value = JSON.parse(label); } catch { return pictureLabelInvalid('not JSON'); }
|
|
27
|
+
if (!Array.isArray(value) || value.length !== 9) return pictureLabelInvalid('expected nine fields');
|
|
28
|
+
const [schema, mode, viewport, referenceId, referenceHash, x, y, width, height] = value as unknown[];
|
|
29
|
+
if (schema !== 'rig-review-comment/1' || !commentModes.includes(mode as CommentMode) || viewport !== 'reference') pictureLabelInvalid('schema, mode or viewport');
|
|
30
|
+
if (typeof referenceId !== 'string' || !referenceId || referenceId.length > 512 || typeof referenceHash !== 'string' || !/^[a-f0-9]{64}$/.test(referenceHash)) pictureLabelInvalid('picture identity');
|
|
31
|
+
if (![x, y, width, height].every(n => Number.isSafeInteger(n)) || (width as number) < 0 || (height as number) < 0) pictureLabelInvalid('region is not natural-pixel integers');
|
|
32
|
+
return {mode: mode as CommentMode, referenceId: referenceId as string, referenceHash: referenceHash as string,
|
|
33
|
+
region: {x: x as number, y: y as number, width: width as number, height: height as number}};
|
|
34
|
+
}
|
|
35
|
+
|
|
11
36
|
/** Stable logical labels survive a new Apply capture; raw anchors retain its full evidence. */
|
|
12
|
-
function commentLabel(anchor: JobCommentAnchor): string {
|
|
37
|
+
function commentLabel(anchor: JobCommentAnchor, pictures?: readonly PictureIdentity[]): string {
|
|
13
38
|
if ('checkpointId' in anchor) return JSON.stringify(['checkpoint', anchor.checkpointId]);
|
|
14
39
|
if ('schema' in anchor) return JSON.stringify([anchor.schema, anchor.parts.map(part => part.name), anchor.view.mode]);
|
|
15
40
|
if ('name' in anchor) return JSON.stringify([anchor.name]);
|
|
16
41
|
const context = anchor.context as Record<string, unknown> | undefined;
|
|
17
42
|
if (hasStageComment(context?.comment)) {
|
|
18
43
|
const mark = parseStageComment(context!.comment);
|
|
44
|
+
const picture = mark.viewport === 'reference' ? pictures?.find(item => item.path === mark.referenceId) : undefined;
|
|
45
|
+
if (picture) return pictureCommentLabel(mark, picture);
|
|
19
46
|
return JSON.stringify([mark.schema, mark.mode, mark.viewport, anchor.target.kind, anchor.target.name,
|
|
20
47
|
anchor.frameStart, anchor.frameEnd]);
|
|
21
48
|
}
|
|
@@ -23,13 +50,14 @@ function commentLabel(anchor: JobCommentAnchor): string {
|
|
|
23
50
|
'side' in anchor ? anchor.side : null]);
|
|
24
51
|
}
|
|
25
52
|
|
|
26
|
-
/** The signed scalar projection. Entry text and array order are never normalized.
|
|
27
|
-
|
|
53
|
+
/** The signed scalar projection. Entry text and array order are never normalized.
|
|
54
|
+
* `pictures` is a record host's sealed shown pictures (#1048); without it every label keeps its existing branch. */
|
|
55
|
+
export function projectComments(comments: readonly JobComment[], pictures?: readonly PictureIdentity[]): string {
|
|
28
56
|
if (!Array.isArray(comments) || comments.length > 1000) throw new Error('JOB_ACT_INVALID');
|
|
29
57
|
const blocks = comments.map(comment => {
|
|
30
58
|
if (!comment || typeof comment.text !== 'string' || !comment.text.trim() || comment.text.length > 10000 ||
|
|
31
59
|
Object.keys(comment).some(key => key !== 'text' && key !== 'anchor')) throw new Error('JOB_ACT_INVALID');
|
|
32
|
-
return `[${comment.anchor === undefined ? 'general' : commentLabel(comment.anchor)}]\n${comment.text}`;
|
|
60
|
+
return `[${comment.anchor === undefined ? 'general' : commentLabel(comment.anchor, pictures)}]\n${comment.text}`;
|
|
33
61
|
});
|
|
34
62
|
const text = blocks.join('\n\n');
|
|
35
63
|
if (text.length > 10000) throw new Error('JOB_ACT_INVALID');
|