rig-review 2.7.1 → 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 +32 -17
- package/docs/STABILITY.md +85 -4
- package/docs/WORKFLOWS.md +1 -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/interview-project.ts +173 -10
- package/src/job-act.ts +101 -33
- package/src/job-api.ts +194 -13
- package/src/job-cli.ts +6 -2
- package/src/job-contract.ts +203 -19
- package/src/job-front.ts +270 -34
- package/src/job-host.ts +123 -1
- package/src/job-session.ts +227 -47
- package/src/job-source.ts +88 -16
- 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 +37 -1
- package/web/catalog-ko.ts +37 -1
- package/web/job-session.ts +830 -161
- 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_RECORD_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, jobStillByteLimit, JOB_ENABLED_ACT_KINDS, JOB_PLAN_BOUND_SIGNOFF_STAGES, JOB_RESERVED_ACT_KINDS,
|
|
4
|
-
type ActV3, type JobAct, type JobActValues, type JobPendingAsk, type JobReviewerBinding,
|
|
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
|
+
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
|
-
type PendingAskV3, type RecordAct, type RecordSource, type RecordSubject, type SourceV3,
|
|
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,
|
|
@@ -75,6 +76,12 @@ export function bindJobRecordAsk(subject: unknown, retained: JobRetainedRecordSo
|
|
|
75
76
|
}
|
|
76
77
|
return source;
|
|
77
78
|
}
|
|
79
|
+
case 'reopen': {
|
|
80
|
+
if (source.subject !== 'plan') {
|
|
81
|
+
throw new JobError('JOB_ASK_INVALID');
|
|
82
|
+
}
|
|
83
|
+
return source;
|
|
84
|
+
}
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
87
|
|
|
@@ -121,24 +128,45 @@ export function bindJobAsk(subject: JobSubject | RecordSubject, retained: JobRet
|
|
|
121
128
|
if (!declared) throw new JobError('JOB_ASK_INVALID');
|
|
122
129
|
if ((JOB_PLAN_BOUND_SIGNOFF_STAGES as readonly string[]).includes(subject.stage)) requirePlan(source);
|
|
123
130
|
return source;
|
|
131
|
+
case 'reopen':
|
|
132
|
+
throw new JobError('JOB_ASK_INVALID');
|
|
124
133
|
}
|
|
125
134
|
}
|
|
126
135
|
|
|
127
|
-
export function parseUISubmission(
|
|
136
|
+
export function parseUISubmission(
|
|
137
|
+
value: unknown,
|
|
138
|
+
mode?: typeof JOB_API_SCHEMA | 'package-only',
|
|
139
|
+
): JobUISubmission;
|
|
140
|
+
export function parseUISubmission(
|
|
141
|
+
value: unknown,
|
|
142
|
+
mode: typeof JOB_API_V3_SCHEMA | 'record-and-package',
|
|
143
|
+
): UISubmissionV3;
|
|
144
|
+
export function parseUISubmission(
|
|
145
|
+
value: unknown,
|
|
146
|
+
mode?: JobApiSchema | JobPublicationMode,
|
|
147
|
+
): UISubmissionV3;
|
|
148
|
+
export function parseUISubmission(
|
|
149
|
+
value: unknown,
|
|
150
|
+
mode: JobApiSchema | JobPublicationMode = JOB_API_SCHEMA,
|
|
151
|
+
): JobUISubmission | UISubmissionV3 {
|
|
128
152
|
const item = jobObject(value, ['publicationId', 'askId', 'pageId', 'displayedNonce', 'expectedGeneration', 'submissionId', 'kind', 'value', 'capture']);
|
|
129
153
|
if ((JOB_RESERVED_ACT_KINDS as readonly unknown[]).includes(item.kind)) throw new JobError('JOB_ACT_KIND_DISABLED');
|
|
130
154
|
jobId(item.publicationId); jobId(item.askId); jobId(item.pageId); jobId(item.displayedNonce); jobId(item.submissionId);
|
|
131
155
|
jobInteger(item.expectedGeneration);
|
|
132
|
-
|
|
156
|
+
const recordEnabled = mode === JOB_API_V3_SCHEMA || mode === 'record-and-package';
|
|
157
|
+
const kind = String(item.kind);
|
|
158
|
+
const allowed = (JOB_ENABLED_ACT_KINDS as readonly string[]).includes(kind) ||
|
|
159
|
+
(recordEnabled && (JOB_RECORD_ACT_KINDS as readonly string[]).includes(kind));
|
|
160
|
+
if (!allowed) {
|
|
133
161
|
throw new JobError('JOB_ACT_INVALID');
|
|
134
162
|
}
|
|
135
163
|
if (item.capture !== undefined && (item.kind !== 'review-verdict' ||
|
|
136
164
|
(item.value as {stage?: unknown} | null)?.stage !== 'rig-review')) throw new JobError('JOB_REQUEST_INVALID');
|
|
137
|
-
return item as unknown as
|
|
165
|
+
return item as unknown as UISubmissionV3;
|
|
138
166
|
}
|
|
139
167
|
|
|
140
168
|
/** The browser supplies pixels and draw provenance, never a trusted hash or path. */
|
|
141
|
-
export function prepareJobStill(input:
|
|
169
|
+
export function prepareJobStill(input: UISubmissionV3, ask: JobPendingAsk, retained: JobRetainedSource): {
|
|
142
170
|
readonly still: JobRigStill;
|
|
143
171
|
readonly bytes: Buffer;
|
|
144
172
|
readonly binding: JobRigCapture['binding'];
|
|
@@ -201,7 +229,7 @@ function actIdField(value: unknown): string {
|
|
|
201
229
|
|
|
202
230
|
export function prepareJobRecordAct(options: {
|
|
203
231
|
readonly jobId: string;
|
|
204
|
-
readonly submission:
|
|
232
|
+
readonly submission: UISubmissionV3;
|
|
205
233
|
readonly ask: PendingAskV3;
|
|
206
234
|
readonly retained: JobRetainedRecordSource;
|
|
207
235
|
readonly reviewer: JobReviewerBinding;
|
|
@@ -379,6 +407,26 @@ export function prepareJobRecordAct(options: {
|
|
|
379
407
|
},
|
|
380
408
|
});
|
|
381
409
|
}
|
|
410
|
+
case 'reopen': {
|
|
411
|
+
if (boundSource.subject !== 'plan') throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
412
|
+
const value = actObject(submission.value, ['stage', 'words']);
|
|
413
|
+
if (
|
|
414
|
+
!('stage' in value) ||
|
|
415
|
+
!('words' in value) ||
|
|
416
|
+
value.stage !== askSubject.stage
|
|
417
|
+
) {
|
|
418
|
+
throw new JobError('JOB_ACT_INVALID');
|
|
419
|
+
}
|
|
420
|
+
return parseRecordAct({
|
|
421
|
+
...envelope,
|
|
422
|
+
kind: 'reopen',
|
|
423
|
+
source: boundSource,
|
|
424
|
+
value: {
|
|
425
|
+
stage: askSubject.stage,
|
|
426
|
+
words: words(value.words),
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
}
|
|
382
430
|
}
|
|
383
431
|
}
|
|
384
432
|
|
|
@@ -395,7 +443,7 @@ export function finalizeJobAct(options: {
|
|
|
395
443
|
}): JobAct;
|
|
396
444
|
export function finalizeJobAct(options: {
|
|
397
445
|
readonly jobId: string;
|
|
398
|
-
readonly submission:
|
|
446
|
+
readonly submission: UISubmissionV3;
|
|
399
447
|
readonly ask: PendingAskV3;
|
|
400
448
|
readonly retained: JobRetainedRecordSource;
|
|
401
449
|
readonly reviewer: JobReviewerBinding;
|
|
@@ -405,7 +453,7 @@ export function finalizeJobAct(options: {
|
|
|
405
453
|
}): RecordAct;
|
|
406
454
|
export function finalizeJobAct(options: {
|
|
407
455
|
readonly jobId: string;
|
|
408
|
-
readonly submission:
|
|
456
|
+
readonly submission: UISubmissionV3;
|
|
409
457
|
readonly ask: JobPendingAsk | PendingAskV3;
|
|
410
458
|
readonly retained: JobRetainedSourceV3;
|
|
411
459
|
readonly reviewer: JobReviewerBinding;
|
|
@@ -415,7 +463,7 @@ export function finalizeJobAct(options: {
|
|
|
415
463
|
}): ActV3;
|
|
416
464
|
export function finalizeJobAct(options: {
|
|
417
465
|
readonly jobId: string;
|
|
418
|
-
readonly submission:
|
|
466
|
+
readonly submission: UISubmissionV3;
|
|
419
467
|
readonly ask: JobPendingAsk | PendingAskV3;
|
|
420
468
|
readonly retained: JobRetainedSourceV3;
|
|
421
469
|
readonly reviewer: JobReviewerBinding;
|
|
@@ -435,6 +483,7 @@ export function finalizeJobAct(options: {
|
|
|
435
483
|
at: options.at,
|
|
436
484
|
});
|
|
437
485
|
}
|
|
486
|
+
if ((options.submission.kind as string) === 'reopen') throw new JobError('JOB_ACT_INVALID');
|
|
438
487
|
const { submission, ask, retained, reviewer } = options as {
|
|
439
488
|
readonly jobId: string;
|
|
440
489
|
readonly submission: JobUISubmission;
|
|
@@ -510,30 +559,49 @@ export function finalizeJobAct(options: {
|
|
|
510
559
|
} };
|
|
511
560
|
}
|
|
512
561
|
case 'parts-verdict': {
|
|
513
|
-
const value = jobObject(submission.value, ['verdict', '
|
|
514
|
-
|
|
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
|
+
}
|
|
515
571
|
const ids = new Set<string>();
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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);
|
|
529
592
|
});
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
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
|
+
};
|
|
537
605
|
}
|
|
538
606
|
case 'review-verdict': {
|
|
539
607
|
const value = jobObject(submission.value, ['stage', 'verdict', 'words']);
|
package/src/job-api.ts
CHANGED
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
JOB_RESERVED_ACT_KINDS,
|
|
6
6
|
type AgentRequestV3, type FetchActRequestV3, type JobAgentRequest, type JobApiSchema,
|
|
7
7
|
type JobDisplayAcknowledgment, type JobErrorCode, type JobFetchActRequest, type JobFileIdentity,
|
|
8
|
-
type JobHostPorts, type JobHumanAuthority, type
|
|
8
|
+
type JobHostPorts, type JobHumanAuthority, type JobInterviewDiagnostic, type JobInterviewDiagnostics,
|
|
9
|
+
type JobInterviewJson, type JobInterviewRecord, type JobPlanIdentity, type JobPublicationMode,
|
|
9
10
|
type JobPublishRequest, type JobResult, type JobSelector, type JobSha256, type JobSubject,
|
|
10
11
|
type OptionContext, type OptionSource, type PlanContext, type PlanSource, type ProjectRecord,
|
|
11
12
|
type PublishRequestV3, type PublishResultV3, type RecordAct, type RecordFreeze,
|
|
@@ -16,6 +17,13 @@ import {
|
|
|
16
17
|
import { JobError } from './job-store.ts';
|
|
17
18
|
import type { JobSession } from './job-session.ts';
|
|
18
19
|
|
|
20
|
+
export type {
|
|
21
|
+
JobInterviewJson,
|
|
22
|
+
JobInterviewRecord,
|
|
23
|
+
JobInterviewDiagnostic,
|
|
24
|
+
JobInterviewDiagnostics,
|
|
25
|
+
} from './job-contract.ts';
|
|
26
|
+
|
|
19
27
|
export const jobBodyLimit = 256 * 1024;
|
|
20
28
|
export const jobWaitLimitMs = 30_000;
|
|
21
29
|
const requestDeadlineMs = 10_000;
|
|
@@ -219,7 +227,12 @@ export function parseRecordSubject(value: unknown): RecordSubject {
|
|
|
219
227
|
if ((JOB_RESERVED_ACT_KINDS as readonly unknown[]).includes(item.kind)) {
|
|
220
228
|
throw new JobError('JOB_ACT_KIND_DISABLED');
|
|
221
229
|
}
|
|
222
|
-
if (
|
|
230
|
+
if (
|
|
231
|
+
item.kind !== 'interview-picks' &&
|
|
232
|
+
item.kind !== 'checkpoint' &&
|
|
233
|
+
item.kind !== 'signoff' &&
|
|
234
|
+
item.kind !== 'reopen'
|
|
235
|
+
) {
|
|
223
236
|
throw new JobError('JOB_ASK_INVALID');
|
|
224
237
|
}
|
|
225
238
|
switch (item.kind) {
|
|
@@ -237,6 +250,9 @@ export function parseRecordSubject(value: unknown): RecordSubject {
|
|
|
237
250
|
}
|
|
238
251
|
return { kind: 'signoff', stage: stage as RecordSignoffStage };
|
|
239
252
|
}
|
|
253
|
+
case 'reopen':
|
|
254
|
+
jobObject(item, ['kind', 'stage']);
|
|
255
|
+
return { kind: 'reopen', stage: jobId(item.stage) };
|
|
240
256
|
}
|
|
241
257
|
}
|
|
242
258
|
|
|
@@ -248,6 +264,10 @@ export function parseJobRequest(
|
|
|
248
264
|
value: unknown,
|
|
249
265
|
mode: typeof JOB_API_V3_SCHEMA | 'record-and-package',
|
|
250
266
|
): AgentRequestV3 | FetchActRequestV3;
|
|
267
|
+
export function parseJobRequest(
|
|
268
|
+
value: unknown,
|
|
269
|
+
mode: JobApiSchema | JobPublicationMode,
|
|
270
|
+
): JobAgentRequest | JobFetchActRequest | AgentRequestV3 | FetchActRequestV3;
|
|
251
271
|
export function parseJobRequest(
|
|
252
272
|
value: unknown,
|
|
253
273
|
mode: JobApiSchema | JobPublicationMode = JOB_API_SCHEMA,
|
|
@@ -299,9 +319,20 @@ export function parseJobRequest(
|
|
|
299
319
|
};
|
|
300
320
|
return parsedRecordPublish;
|
|
301
321
|
}
|
|
302
|
-
case 'ask':
|
|
322
|
+
case 'ask': {
|
|
303
323
|
jobObject(item, ['schema', 'jobId', 'requestId', 'verb', 'expectedGeneration', 'idempotencyKey', 'publicationId', 'subject']);
|
|
304
|
-
|
|
324
|
+
const isReopenSubject =
|
|
325
|
+
item.subject !== null &&
|
|
326
|
+
typeof item.subject === 'object' &&
|
|
327
|
+
!Array.isArray(item.subject) &&
|
|
328
|
+
(item.subject as { kind?: unknown }).kind === 'reopen';
|
|
329
|
+
return {
|
|
330
|
+
...mutation,
|
|
331
|
+
verb: 'ask',
|
|
332
|
+
publicationId: jobId(item.publicationId),
|
|
333
|
+
subject: isReopenSubject ? parseRecordSubject(item.subject) : parseJobSubject(item.subject),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
305
336
|
case 'close':
|
|
306
337
|
jobObject(item, ['schema', 'jobId', 'requestId', 'verb', 'expectedGeneration', 'idempotencyKey', 'reason']);
|
|
307
338
|
return { ...mutation, verb: 'close', reason: jobText(item.reason, 1024) };
|
|
@@ -377,6 +408,119 @@ function parseFileRow(value: unknown, code: JobErrorCode): JobFileIdentity {
|
|
|
377
408
|
return asCode(() => ({ path: jobPath(item.path), sha256: jobSha(item.sha256) }), code);
|
|
378
409
|
}
|
|
379
410
|
|
|
411
|
+
function parseInterviewJson(value: unknown, code: JobErrorCode, depth = 0): JobInterviewJson {
|
|
412
|
+
if (depth > 32) throw new JobError(code);
|
|
413
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string') return value;
|
|
414
|
+
if (typeof value === 'number') {
|
|
415
|
+
if (!Number.isFinite(value)) throw new JobError(code);
|
|
416
|
+
return value;
|
|
417
|
+
}
|
|
418
|
+
if (Array.isArray(value)) {
|
|
419
|
+
return value.map(entry => parseInterviewJson(entry, code, depth + 1));
|
|
420
|
+
}
|
|
421
|
+
if (typeof value === 'object') {
|
|
422
|
+
return Object.fromEntries(
|
|
423
|
+
Object.entries(value as Record<string, unknown>).map(([key, child]) => [
|
|
424
|
+
key,
|
|
425
|
+
parseInterviewJson(child, code, depth + 1),
|
|
426
|
+
]),
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
throw new JobError(code);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function parseInterviewJsonObject(
|
|
433
|
+
value: unknown,
|
|
434
|
+
code: JobErrorCode,
|
|
435
|
+
): { readonly [key: string]: JobInterviewJson } {
|
|
436
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
437
|
+
throw new JobError(code);
|
|
438
|
+
}
|
|
439
|
+
return parseInterviewJson(value, code) as { readonly [key: string]: JobInterviewJson };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function parseJobInterviewDiagnostics(
|
|
443
|
+
value: unknown,
|
|
444
|
+
code: JobErrorCode = 'JOB_REQUEST_INVALID',
|
|
445
|
+
): JobInterviewDiagnostics | null | undefined {
|
|
446
|
+
if (value === undefined) return undefined;
|
|
447
|
+
if (value === null) return null;
|
|
448
|
+
const item = exactObject(
|
|
449
|
+
value,
|
|
450
|
+
['schema', 'project', 'evaluatedAt', 'records', 'diagnostics'],
|
|
451
|
+
code,
|
|
452
|
+
);
|
|
453
|
+
if (item.schema !== 'rig-review/job-interview@1') throw new JobError(code);
|
|
454
|
+
const project = asCode(() => parseProjectRecord(item.project, code), code);
|
|
455
|
+
const evaluatedAt = asCode(() => jobText(item.evaluatedAt), code);
|
|
456
|
+
if (!Number.isFinite(Date.parse(evaluatedAt))) throw new JobError(code);
|
|
457
|
+
if (!Array.isArray(item.records) || item.records.length > maxRecordFiles ||
|
|
458
|
+
!Array.isArray(item.diagnostics) || item.diagnostics.length > maxRecordFiles) {
|
|
459
|
+
throw new JobError(code);
|
|
460
|
+
}
|
|
461
|
+
const recordsByLocator = new Map<string, JobInterviewRecord>();
|
|
462
|
+
const records: JobInterviewRecord[] = item.records.map(rawRow => {
|
|
463
|
+
const row = exactObject(
|
|
464
|
+
rawRow,
|
|
465
|
+
['questionId', 'record', 'setId', 'ref', 'observedSet', 'timeKind', 'at', 'original'],
|
|
466
|
+
code,
|
|
467
|
+
);
|
|
468
|
+
const questionId = asCode(() => jobId(row.questionId), code);
|
|
469
|
+
const record = asCode(() => jobText(row.record, 256), code);
|
|
470
|
+
if (recordsByLocator.has(record)) throw new JobError(code);
|
|
471
|
+
const setId = row.setId === null ? null : asCode(() => jobId(row.setId), code);
|
|
472
|
+
const ref = parseFileRow(row.ref, code);
|
|
473
|
+
const observedSet = row.observedSet === null ? null : parseFileRow(row.observedSet, code);
|
|
474
|
+
if (row.timeKind !== 'inspection' && row.timeKind !== 'answer' && row.timeKind !== 'decision') {
|
|
475
|
+
throw new JobError(code);
|
|
476
|
+
}
|
|
477
|
+
const timeKind = row.timeKind;
|
|
478
|
+
const at = row.at === null ? null : asCode(() => jobText(row.at), code);
|
|
479
|
+
if (timeKind === 'inspection') {
|
|
480
|
+
if (at !== evaluatedAt || row.original !== null) throw new JobError(code);
|
|
481
|
+
const parsed: JobInterviewRecord = { questionId, record, setId, ref, observedSet, timeKind, at, original: null };
|
|
482
|
+
recordsByLocator.set(record, parsed);
|
|
483
|
+
return parsed;
|
|
484
|
+
}
|
|
485
|
+
const original = parseInterviewJsonObject(row.original, code);
|
|
486
|
+
if (timeKind === 'decision') {
|
|
487
|
+
const completed = ['at', 'value', 'fragments'].some(key => Object.hasOwn(original, key));
|
|
488
|
+
if (!completed && at !== null) throw new JobError(code);
|
|
489
|
+
}
|
|
490
|
+
const parsed: JobInterviewRecord = { questionId, record, setId, ref, observedSet, timeKind, at, original };
|
|
491
|
+
recordsByLocator.set(record, parsed);
|
|
492
|
+
return parsed;
|
|
493
|
+
});
|
|
494
|
+
const seenDiagnosticRecords = new Set<string>();
|
|
495
|
+
const diagnostics: JobInterviewDiagnostic[] = item.diagnostics.map(rawDiag => {
|
|
496
|
+
const diag = exactObject(rawDiag, ['record', 'at', 'code', 'severity'], code);
|
|
497
|
+
const record = asCode(() => jobText(diag.record, 256), code);
|
|
498
|
+
const at = diag.at === null ? null : asCode(() => jobText(diag.at), code);
|
|
499
|
+
if (seenDiagnosticRecords.has(record)) throw new JobError(code);
|
|
500
|
+
const matching = recordsByLocator.get(record);
|
|
501
|
+
if (!matching || matching.at !== at) throw new JobError(code);
|
|
502
|
+
if (matching.timeKind === 'decision' && matching.original &&
|
|
503
|
+
!['at', 'value', 'fragments'].some(key => Object.hasOwn(matching.original!, key))) {
|
|
504
|
+
throw new JobError(code);
|
|
505
|
+
}
|
|
506
|
+
seenDiagnosticRecords.add(record);
|
|
507
|
+
if (diag.code === 'INTERVIEW_OPTIONS_STALE' && diag.severity === 'error') {
|
|
508
|
+
return { record, at, code: 'INTERVIEW_OPTIONS_STALE', severity: 'error' };
|
|
509
|
+
}
|
|
510
|
+
if (diag.code === 'INTERVIEW_OPTIONS_SCENE_LEGACY' && diag.severity === 'warning') {
|
|
511
|
+
return { record, at, code: 'INTERVIEW_OPTIONS_SCENE_LEGACY', severity: 'warning' };
|
|
512
|
+
}
|
|
513
|
+
throw new JobError(code);
|
|
514
|
+
});
|
|
515
|
+
return {
|
|
516
|
+
schema: 'rig-review/job-interview@1',
|
|
517
|
+
project,
|
|
518
|
+
evaluatedAt,
|
|
519
|
+
records,
|
|
520
|
+
diagnostics,
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
|
|
380
524
|
function parseFileClosure(
|
|
381
525
|
rawInputs: unknown,
|
|
382
526
|
rawFiles: unknown,
|
|
@@ -440,9 +584,6 @@ function parsePlanSubjects(
|
|
|
440
584
|
if (!Array.isArray(rawSubjects) || rawSubjects.length > maxRecordFiles) {
|
|
441
585
|
throw new JobError(code);
|
|
442
586
|
}
|
|
443
|
-
if (rawSubjects.length > 0 && stepIds.size === 0) {
|
|
444
|
-
throw new JobError(code);
|
|
445
|
-
}
|
|
446
587
|
const seen = new Set<string>();
|
|
447
588
|
return rawSubjects.map(raw => {
|
|
448
589
|
const parsed = asCode(() => parseRecordSubject(raw), code);
|
|
@@ -454,6 +595,13 @@ function parsePlanSubjects(
|
|
|
454
595
|
seen.add(key);
|
|
455
596
|
return { kind: 'checkpoint', checkpointId: parsed.checkpointId };
|
|
456
597
|
}
|
|
598
|
+
if (parsed.kind === 'reopen') {
|
|
599
|
+
const key = `reopen:${parsed.stage}`;
|
|
600
|
+
if (seen.has(key)) throw new JobError(code);
|
|
601
|
+
seen.add(key);
|
|
602
|
+
return { kind: 'reopen', stage: parsed.stage };
|
|
603
|
+
}
|
|
604
|
+
if (stepIds.size === 0) throw new JobError(code);
|
|
457
605
|
const key = `signoff:${parsed.stage}`;
|
|
458
606
|
if (seen.has(key)) throw new JobError(code);
|
|
459
607
|
seen.add(key);
|
|
@@ -872,14 +1020,17 @@ export function validateRecordAskSubject(subject: unknown, source: RecordSource)
|
|
|
872
1020
|
}
|
|
873
1021
|
return parsed;
|
|
874
1022
|
}
|
|
875
|
-
if (
|
|
1023
|
+
if (
|
|
1024
|
+
parsed.kind === 'interview-picks' ||
|
|
1025
|
+
((parsed.kind === 'checkpoint' || parsed.kind === 'signoff') && checkedSource.plan.steps.length === 0)
|
|
1026
|
+
) {
|
|
876
1027
|
throw new JobError('JOB_ASK_INVALID');
|
|
877
1028
|
}
|
|
878
1029
|
const declared = checkedSource.subjects.some(candidate =>
|
|
879
1030
|
candidate.kind === parsed.kind &&
|
|
880
1031
|
(candidate.kind === 'checkpoint'
|
|
881
1032
|
? candidate.checkpointId === (parsed as Extract<RecordPlanSubject, { kind: 'checkpoint' }>).checkpointId
|
|
882
|
-
: candidate.stage === (parsed as Extract<RecordPlanSubject, { kind: 'signoff' }>).stage),
|
|
1033
|
+
: candidate.stage === (parsed as Extract<RecordPlanSubject, { kind: 'signoff' | 'reopen' }>).stage),
|
|
883
1034
|
);
|
|
884
1035
|
if (!declared) throw new JobError('JOB_ASK_INVALID');
|
|
885
1036
|
return parsed;
|
|
@@ -993,6 +1144,25 @@ export function parseRecordAct(value: unknown): RecordAct {
|
|
|
993
1144
|
value: { stage: stage as RecordSignoffStage, decision: 'approved', words },
|
|
994
1145
|
};
|
|
995
1146
|
}
|
|
1147
|
+
case 'reopen': {
|
|
1148
|
+
if (source.subject !== 'plan') throw new JobError('JOB_ACT_INVALID');
|
|
1149
|
+
const rawValue = exactObject(item.value, ['stage', 'words'], 'JOB_ACT_INVALID');
|
|
1150
|
+
const stage = asCode(() => jobId(rawValue.stage), 'JOB_ACT_INVALID');
|
|
1151
|
+
asCode(() => validateRecordAskSubject({ kind: 'reopen', stage }, source), 'JOB_ACT_INVALID');
|
|
1152
|
+
const words = parseActWords(rawValue.words, 'JOB_ACT_INVALID');
|
|
1153
|
+
return {
|
|
1154
|
+
schema: JOB_RECORD_ACT_SCHEMA,
|
|
1155
|
+
actId,
|
|
1156
|
+
jobId: jobIdValue,
|
|
1157
|
+
askId,
|
|
1158
|
+
publicationId,
|
|
1159
|
+
kind: 'reopen',
|
|
1160
|
+
authority,
|
|
1161
|
+
at,
|
|
1162
|
+
source,
|
|
1163
|
+
value: { stage, words },
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
996
1166
|
}
|
|
997
1167
|
throw new JobError('JOB_ACT_INVALID');
|
|
998
1168
|
}
|
|
@@ -1069,10 +1239,21 @@ export function createJobHostPorts(session: JobSession, origin: string): JobHost
|
|
|
1069
1239
|
}
|
|
1070
1240
|
return {
|
|
1071
1241
|
async handleJobApi(request) {
|
|
1072
|
-
let input: JobAgentRequest | JobFetchActRequest | null = null;
|
|
1242
|
+
let input: JobAgentRequest | AgentRequestV3 | JobFetchActRequest | FetchActRequestV3 | null = null;
|
|
1243
|
+
let responseSchema: typeof JOB_API_SCHEMA | typeof JOB_API_V3_SCHEMA = session.apiSchema;
|
|
1073
1244
|
try {
|
|
1074
1245
|
gate(request, base + '/api', false);
|
|
1075
|
-
|
|
1246
|
+
const body = await jobBody(request);
|
|
1247
|
+
const mode: JobPublicationMode =
|
|
1248
|
+
session.publicationMode === 'record-and-package' &&
|
|
1249
|
+
body !== null &&
|
|
1250
|
+
typeof body === 'object' &&
|
|
1251
|
+
!Array.isArray(body) &&
|
|
1252
|
+
(body as { schema?: unknown }).schema === JOB_API_SCHEMA
|
|
1253
|
+
? 'package-only'
|
|
1254
|
+
: session.publicationMode;
|
|
1255
|
+
responseSchema = jobApiSchemaForMode(mode);
|
|
1256
|
+
input = parseJobRequest(body, mode);
|
|
1076
1257
|
if (input.jobId !== session.jobId) throw new JobError('JOB_UNKNOWN');
|
|
1077
1258
|
session.authorize(input.verb === 'fetch-act' ? 'consumer' : 'agent', request.headers.get('authorization'));
|
|
1078
1259
|
if (input.verb === 'fetch-act') {
|
|
@@ -1086,13 +1267,13 @@ export function createJobHostPorts(session: JobSession, origin: string): JobHost
|
|
|
1086
1267
|
if (accept && accept !== '*/*' && accept !== 'application/json') throw new JobError('JOB_REQUEST_INVALID');
|
|
1087
1268
|
}
|
|
1088
1269
|
const value = await session.execute(input, request.signal);
|
|
1089
|
-
return Response.json({ schema:
|
|
1270
|
+
return Response.json({ schema: responseSchema, verb: input.verb, jobId: input.jobId, requestId: input.requestId,
|
|
1090
1271
|
generation: session.status().generation, ok: true, value }, { headers: responseHeaders });
|
|
1091
1272
|
} catch (error) {
|
|
1092
1273
|
const failure = jobFailure(error);
|
|
1093
1274
|
const status = failure.error.code.includes('CAPABILITY') || failure.error.code === 'JOB_AUTHORITY_REFUSED' ? 403 :
|
|
1094
1275
|
failure.error.code === 'JOB_BODY_LIMIT' ? 413 : failure.error.code === 'JOB_REQUEST_INVALID' ? 400 : 409;
|
|
1095
|
-
return Response.json({ schema:
|
|
1276
|
+
return Response.json({ schema: responseSchema, verb: input?.verb ?? null, jobId: session.jobId,
|
|
1096
1277
|
requestId: input?.requestId ?? null, generation: session.lastObservedGeneration, ...failure }, { status, headers: responseHeaders });
|
|
1097
1278
|
}
|
|
1098
1279
|
},
|
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) {
|