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/docs/WORKFLOWS.md
CHANGED
|
@@ -681,7 +681,7 @@ the source-bound result and deduplicate by `actId`.
|
|
|
681
681
|
- **One standing window and visual gate.** Every owner visual, question, choice, correction and verdict goes through one standing Review window/link plus one what-to-look-at line. Internal agent and HQ media stay internal and are never substituted for the owner handoff. When a required visual is missing (`visual.status` set to `'unavailable'` with a named `code`), the agent stops immediately and files a Create on-path Review card rather than falling back to chat text or images.
|
|
682
682
|
- **Human UI vs agent verbs.** People submit through the Review browser UI (`actor` set to `'human'`, `channel` set to `'review-ui'`). Trusted host bootstrap declares `reviewer` (`id` and `role` as `'owner'` or `'delegate'`), which the browser UI cannot type or override. This binding records bootstrap-declared provenance rather than keyboard-user authentication, and Create maps `role` to its existing `by` authority. Agents use only `publish`, `ask`, `next` and `close` (`JobAgentRequest`), with `expectedGeneration` compare-and-swap (CAS) and `idempotencyKey` on mutations.
|
|
683
683
|
- **Explicit producer-held freeze and explicit close.** Every `publish` request designates a root-relative `result` (`path` and `selector`, never a command) and carries an explicit producer-held freeze (`freeze.kind` set to `'producer-held'`, `holdId`, `record` as `JobFileIdentity` or `null` for a declared non-Create root) held until acknowledgment. Review validates retained bytes, detects a moved record (`JOB_RECORD_MOVED`, `JOB_RECORD_INCOMPLETE`, `JOB_FREEZE_REQUIRED`, `JOB_SOURCE_MISMATCH`, `JOB_SOURCE_UNRETAINABLE`, `JOB_ROOT_REPLACED`) and commits local generation CAS (`JOB_GENERATION_STALE`, `JOB_IDEMPOTENCY_CONFLICT`). The freeze assertion is a caller obligation rather than a lock Review can impose on independent writers. Review offers no watched-root or automatic-close guarantee, and only explicit `close` ends an active job.
|
|
684
|
-
- **Exact displayed source and retained drafts.** The daemon derives `JobSourceBinding` from validated retained bytes and the actual displayed publication (`ackDisplayed` returning a page-scoped `displayedNonce` receipt, pinned same-origin `routes` with no mutable current alias). All metadata, images, runtime assets, routes and pending form dependencies prepare before the visible swap; paint and the single `displayedNonce` acknowledgment precede retirement of the previous view, and failed preparation or acknowledgment restores the prior view and draft. Clients never supply trusted source hashes or transfer prior approval onto a new binding. When a new publication updates the displayed source, old local drafts
|
|
684
|
+
- **Exact displayed source and retained drafts.** The daemon derives `JobSourceBinding` from validated retained bytes and the actual displayed publication (`ackDisplayed` returning a page-scoped `displayedNonce` receipt, pinned same-origin `routes` with no mutable current alias). All metadata, images, runtime assets, routes and pending form dependencies prepare before the visible swap; paint and the single `displayedNonce` acknowledgment precede retirement of the previous view, and failed preparation or acknowledgment restores the prior view and draft. Clients never supply trusted source hashes or transfer prior approval onto a new binding. When a new publication updates the displayed source or a browser tab reconnects to the same job, the window shows an explicit changed-version notice, preserves compatible camera, animation, time, repeat, part/solo, reference and panel state (flagging incompatible selections explicitly), and retains old local drafts in storage for their original source binding without rebinding onto the new publication.
|
|
685
685
|
- **Finalized acts, five enabled kinds and cursor replay.** `next` (`after` cursor and bounded abortable `waitMs` that never consumes an act) and `subscribeJob` replay complete durable `JobEvent` records (`published`, `pending`, `act`, `closed`). Only five act kinds are enabled (`interview-picks`, `checkpoint`, `parts-verdict`, `review-verdict`, `signoff`). `described-correction` (awaiting the joint [Create #182](https://github.com/rig-c/create/issues/182) context allowlist) and `mesh-edit` (awaiting the joint [Parts #1159](https://github.com/rig-c/parts/issues/1159) freeze) stay reserved and disabled (`JOB_ACT_KIND_DISABLED`).
|
|
686
686
|
- **Checkpoints, signoffs, plan steps and parts PNGs.** In `checkpoint` acts, `outcome` is `'pass'` or `'fail'` only (`'pending'` stays in the UI draft and never produces a finalized act), and required `words` is preserved verbatim as a string including empty or whitespace-only text. The browser sends `checkpointId`, `outcome` and `words` only while the daemon copies resolved `planStepId` from the validated ask, and Create derives execution stage from its authoritative step phase and order without Review stamping a stage. Only `'pass'` is eligible for Create's checkpoint sign-off writer, while `'fail'` is feedback or a named consumer refusal. In `signoff` acts, `decision` is `'approved'` only (changes requested are a verdict) with required `words` preserved verbatim including empty or whitespace-only text. A verdict, a signoff and a Create stage transition are three separate writes, and plan-bound signoff stages (`plan-approved`, `rigging-interview`, `post-interview`) require `source.plan` with exact displayed step IDs and hashes published by [Create #184](https://github.com/rig-c/create/issues/184) without Review recomputing `stepHash`. C4 binds the exact public `partsFileReferences(dir)` array from `@rig-c/parts/src/parts.ts`, whose contract is frozen at Parts 2.25.0. The trusted host resolves an installed version in `JOB_PARTS_ENUMERATOR_RANGE` (`>=2.25.0 <3.0.0`), supplies its actual version and official callback through `partsEnumerator`, and declares `partsEnumeratorId`. `JobPartsIdentity.enumeratorVersion` carries that actual version. Manifest paths are work-root-relative and image paths are relative to the manifest directory. Each image carries `path`, bounded-string `role` and raw-byte `sha256`. Review compares the claimed array positionally with the official array, preserving its role/order/duplicate semantics. Upstream roles include `part`, `alternate`, `depth`, `painting` and `figure_mask`. Review bounds shape and paths, refuses traversal/symlinks, decodes PNGs and hashes retained bytes. Missing references refuse with row, role and path, including a missing sibling figure mask when a render copy exists. Unreferenced extras stay outside this parts identity. Composite source hashes use `rig-review-job-source/2`. Create #184 production reader/projection and official-hook wiring remain pending.
|
|
687
687
|
- **No agent file carriage, writer-owned sibling fetch and public host seam.** Agents never build, parse, reshape or carry Review session, picks, verdict or applied-record storage files. [Create #182](https://github.com/rig-c/create/issues/182) and [Create #184](https://github.com/rig-c/create/issues/184) own direct writer publication and act fetch through a private writer-owned sibling binding outside `project.json` (`writer-owned-sibling-fetch-capability`, pending Create #184 production reader/writer integration). That binding is never tracked in version control or unstaged project output, dies at explicit `close` with a new grant per job incarnation, and grants read-only `fetch-act` over loopback with `Authorization`. In the public managed-host startup seam (`startJobHost` from `@rig-c/review/job-host`, frozen in [Public API stability](STABILITY.md#managed-owner-host)), hook-bearing host callers declare `readerId` for `readPublished` and `bindingId` for `installWriterBinding` and `partsEnumeratorId` for `partsEnumerator`; missing or invalid IDs refuse with `JOB_HOST_OPTION_ID_INVALID`, and listener reuse requires equal `readerId`, `bindingId` and `partsEnumeratorId` or refuses with `JOB_HOST_REUSE_MISMATCH` (with no function hashes). Future mesh-edit consumption is owned by [Parts #1159](https://github.com/rig-c/parts/issues/1159), where Create fetches a finalized mesh act and passes its typed value in process to Parts' public exported API without Parts reading Review or Create storage.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rig-review",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local human rig inspection and structured feedback export",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@napi-rs/canvas": "1.0.11",
|
|
23
|
-
"@rig-c/play": "1.
|
|
23
|
+
"@rig-c/play": "1.24.0",
|
|
24
24
|
"@types/pngjs": "6.0.5",
|
|
25
25
|
"pngjs": "7.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@rig-c/parts": "2.
|
|
28
|
+
"@rig-c/parts": "2.37.0",
|
|
29
29
|
"@types/bun": "^1.3.0",
|
|
30
30
|
"typescript": "^5.9.3"
|
|
31
31
|
},
|
package/src/build.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
1
2
|
import { fileURLToPath } from 'node:url';
|
|
2
3
|
export const appRoot=fileURLToPath(new URL('..',import.meta.url));
|
|
3
|
-
export
|
|
4
|
-
|
|
4
|
+
export const PLAY_SOURCE_CONDITION='@rig-c/source';
|
|
5
|
+
export function playBuildConditions(root:string=appRoot):string[] {
|
|
6
|
+
try{return /[\\/]src[\\/]index\.ts$/.test(Bun.resolveSync('@rig-c/play',root))?[PLAY_SOURCE_CONDITION]:[];}
|
|
7
|
+
catch{return [];}
|
|
8
|
+
}
|
|
9
|
+
export async function buildWeb(mode:'single'|'compare'|'parts'|'interview'|'workspace'|'job-hub'='single',root:string=appRoot):Promise<Blob> {
|
|
10
|
+
const conditions=playBuildConditions(root);
|
|
11
|
+
const entry=join(root,mode==='job-hub'?'web/job-hub.ts':mode==='workspace'?'web/owner-workspace.ts':mode==='compare'?'web/compare.ts':mode==='parts'?'web/parts-page.ts':mode==='interview'?'web/interview.ts':'web/main.ts');
|
|
12
|
+
const result=await Bun.build({entrypoints:[entry],target:'browser',format:'esm',minify:false,...(conditions.length?{conditions}:{})});
|
|
5
13
|
if(!result.success)throw new Error(result.logs.map(v=>v.message).join('\n'));
|
|
6
14
|
const output=result.outputs.find(v=>v.path.endsWith('.js'));if(!output)throw new Error('frontend bundle: JavaScript output missing');return output;
|
|
7
15
|
}
|
package/src/cli.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { readFeedbackSession, readFeedbackCompareSession } from './session-histo
|
|
|
18
18
|
import { startServer } from './server.ts';
|
|
19
19
|
import { loadCompare } from './compare.ts';
|
|
20
20
|
import { startCompareServer } from './compare-server.ts';
|
|
21
|
-
import { loadPartsView, readVerdict, readPartsVerdictJson, exportPartsVerdict, exportPartsCorrection, assertPartsUnchanged, type PartsViewOptions } from './parts-view.ts';
|
|
21
|
+
import { loadPartsView, readVerdict, readPartsVerdictForCli, readPartsVerdictJson, exportPartsVerdict, exportPartsCorrection, assertPartsUnchanged, type PartsViewOptions } from './parts-view.ts';
|
|
22
22
|
import { startPartsServer } from './parts-server.ts';
|
|
23
23
|
import { readSession, parseSession, sessionFile, type Feedback } from './session.ts';
|
|
24
24
|
import { readCompareSession } from './compare-session.ts';
|
|
@@ -217,16 +217,15 @@ async function partsCommand(args:string[]){
|
|
|
217
217
|
if((itemId||partNote||inventory)&&(!format||!itemId||!inventory))throw new Error('CORRECTION_SELECTOR_INVALID: parts correction requires --format, --correction and --parts-file');
|
|
218
218
|
const pkg=await loadPartsView(input,options);
|
|
219
219
|
if(format&&itemId&&inventory){
|
|
220
|
-
const
|
|
221
|
-
if(!
|
|
220
|
+
const verdict=await readPartsVerdictForCli(pkg);
|
|
221
|
+
if(!verdict)throw new Error('PARTS_VERDICT_UNAVAILABLE: save a current verdict first');
|
|
222
222
|
await assertPartsUnchanged(pkg);
|
|
223
|
-
const verdict=saved.verdict;
|
|
224
223
|
const projected=projectPartsDescription({verdict,source:verdict.source,selector:{stage:'parts-review',kind:'parts',inventory},selection:partNote?{kind:'note',itemId,part:partNote}:{kind:'comment',itemId}});
|
|
225
224
|
process.stdout.write(format==='json'?exportPartsCorrection(verdict,projected):formatCorrectionIssue(projected)+'\n');
|
|
226
225
|
return;
|
|
227
226
|
}
|
|
228
227
|
if(format==='json'){process.stdout.write(await readPartsVerdictJson(pkg));return;}
|
|
229
|
-
if(format){const
|
|
228
|
+
if(format){const verdict=await readPartsVerdictForCli(pkg);if(!verdict)throw new Error('PARTS_VERDICT_UNAVAILABLE: save a verdict first');process.stdout.write(exportPartsVerdict(verdict,format));return;}
|
|
230
229
|
const capability=randomBytes(32).toString('hex');
|
|
231
230
|
let outputFailure: Error | null = null;
|
|
232
231
|
let rejectWrite: ((error: Error) => void) | undefined;
|
|
@@ -196,9 +196,21 @@ export function projectSessionCorrection(input: SessionInput) {
|
|
|
196
196
|
return { ...common, kind: 'checked-patch' as const, applied, sessionBytes, patchBytes: patchText(patch), outcome: null };
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
type PartsCorrectionVerdict = PartsVerdict | {
|
|
200
|
+
schema?: string;
|
|
201
|
+
mode: PartsVerdict['mode'];
|
|
202
|
+
tool?: { name: string; version: string };
|
|
203
|
+
source: PartsVerdict['source'];
|
|
204
|
+
status?: string;
|
|
205
|
+
parts?: Record<string, { outcome: string; note: string; flags: string[] }>;
|
|
206
|
+
comments?: import('./parts-comment.ts').PartsComment[];
|
|
207
|
+
issues?: import('./parts-comment.ts').PartsIssue[];
|
|
208
|
+
updatedAt?: string;
|
|
209
|
+
};
|
|
210
|
+
|
|
199
211
|
/** Standalone parts notes and pointed comments keep their original parts identity. */
|
|
200
212
|
export function projectPartsDescription(input: {
|
|
201
|
-
verdict:
|
|
213
|
+
verdict: PartsCorrectionVerdict;
|
|
202
214
|
source: PartsVerdict['source'];
|
|
203
215
|
selector: Extract<Selector, { kind: 'parts' }>;
|
|
204
216
|
selection: { kind: 'comment'; itemId: string } | { kind: 'note'; itemId: string; part: string };
|
|
@@ -210,13 +222,24 @@ export function projectPartsDescription(input: {
|
|
|
210
222
|
}
|
|
211
223
|
const { itemId } = selection;
|
|
212
224
|
if (selection.kind === 'comment') {
|
|
213
|
-
|
|
225
|
+
if ('issues' in verdict && Array.isArray(verdict.issues)) {
|
|
226
|
+
const matches = verdict.issues.filter(issue => issue.id === itemId);
|
|
227
|
+
const item = matches[0];
|
|
228
|
+
if (matches.length !== 1 || !item || item.sourceHash !== source.sha256) {
|
|
229
|
+
return refuse('CORRECTION_ITEM_INVALID', 'expected one source-bound parts comment');
|
|
230
|
+
}
|
|
231
|
+
const primary = item.parts[0]!;
|
|
232
|
+
return { kind: 'described' as const, itemId, verbatim: itemWords(itemId, item.summary), stage: selector.stage, on, source, part: primary.name, imageHash: primary.imageHash, parts: item.parts, comment: item, outcome: null };
|
|
233
|
+
}
|
|
234
|
+
const comments = ('comments' in verdict && Array.isArray(verdict.comments)) ? verdict.comments : [];
|
|
235
|
+
const matches = comments.filter(comment => comment.id === itemId);
|
|
214
236
|
const item = matches[0];
|
|
215
237
|
if (matches.length !== 1 || !item || item.sourceHash !== source.sha256) {
|
|
216
238
|
return refuse('CORRECTION_ITEM_INVALID', 'expected one source-bound parts comment');
|
|
217
239
|
}
|
|
218
240
|
return { kind: 'described' as const, itemId, verbatim: itemWords(itemId, item.summary), stage: selector.stage, on, source, part: item.part, imageHash: item.imageHash, comment: item, outcome: null };
|
|
219
241
|
}
|
|
220
|
-
|
|
221
|
-
|
|
242
|
+
const parts = ('parts' in verdict && verdict.parts) ? verdict.parts : null;
|
|
243
|
+
if (!parts || !Object.hasOwn(parts, selection.part)) return refuse('CORRECTION_ITEM_INVALID', 'expected a saved part note');
|
|
244
|
+
return { kind: 'described' as const, itemId, verbatim: itemWords(itemId, parts[selection.part]!.note), stage: selector.stage, on, source, part: selection.part, outcome: null };
|
|
222
245
|
}
|
package/src/feedback-export.ts
CHANGED
|
@@ -247,7 +247,7 @@ export function formatFeedbackIssues(input: ParsedFeedbackSession): string {
|
|
|
247
247
|
|
|
248
248
|
/** Selected handoff uses the existing issue export surface with exact JSON-escaped words and evidence. */
|
|
249
249
|
export function formatCorrectionIssue(
|
|
250
|
-
correction: {kind:string;itemId:string;stage:string;on:readonly string[];verbatim:string;source:unknown;createSource?:string;operation?:string;patchBytes?:string;target?:unknown;part?:string;imageHash?:string;comment?:import('./parts-comment.ts').PartsComment},
|
|
250
|
+
correction: {kind:string;itemId:string;stage:string;on:readonly string[];verbatim:string;source:unknown;createSource?:string;operation?:string;patchBytes?:string;target?:unknown;part?:string;imageHash?:string;comment?:import('./parts-comment.ts').PartsComment|import('./parts-comment.ts').PartsIssue},
|
|
251
251
|
context?:Json,
|
|
252
252
|
): string {
|
|
253
253
|
const state=correction.kind==='described'?'Unresolved request':
|
package/src/front.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {lstat,readFile,readdir,realpath,rename,unlink,writeFile,open as openFile
|
|
|
12
12
|
import {dirname,join} from 'node:path';
|
|
13
13
|
import {fileURLToPath} from 'node:url';
|
|
14
14
|
import {acquireClaim,alive,openFingerprint,readRecord,releaseClaim,running,smallJson,type RecordFile} from './open.ts';
|
|
15
|
+
import {playBuildConditions} from './build.ts';
|
|
15
16
|
import {capabilityHeader,openKeyHeader,openNonceHeader,sameSecret} from './open-protocol.ts';
|
|
16
17
|
import {DEFAULT_CLOSE_GRACE_MS,LIVE_PATH} from './live-lifecycle.ts';
|
|
17
18
|
export const defaultFrontPort=4318; // Foreground `review <dir>` keeps 4317.
|
|
@@ -40,7 +41,7 @@ export async function ensureFront(options:{control:string;port:number;fingerprin
|
|
|
40
41
|
const row=await reuse();if(row)return row.origin;
|
|
41
42
|
request=join(control,`${name}.${nonce}.request.json`);const log=join(control,`${name}.${nonce}.log`);
|
|
42
43
|
const spec:FrontRequest={schema:'rig-review-front-request/1',control,request,record:recordPath,port,nonce,fingerprint,idleMs};await writeFile(request,JSON.stringify(spec),{mode:0o600,flag:'wx'});
|
|
43
|
-
const logHandle=await openFile(log,'a',0o600);try{child=spawn(process.execPath,[join(appRoot,'src/front-worker.ts'),request],{cwd:control,detached:true,stdio:['ignore',logHandle.fd,logHandle.fd],env:process.env});child.unref();}finally{await logHandle.close();}
|
|
44
|
+
const logHandle=await openFile(log,'a',0o600);try{child=spawn(process.execPath,[...playBuildConditions().map(c=>`--conditions=${c}`),join(appRoot,'src/front-worker.ts'),request],{cwd:control,detached:true,stdio:['ignore',logHandle.fd,logHandle.fd],env:process.env});child.unref();}finally{await logHandle.close();}
|
|
44
45
|
let exited:string|undefined;child.on('error',error=>{exited=error.message;});child.on('exit',(code,signal)=>{exited=`exit ${code} ${signal??''}`;});
|
|
45
46
|
while(performance.now()<deadline){const live=await reuse();if(live){handedOff=true;return live.origin;}
|
|
46
47
|
if(exited){if(/FRONT_PORT_BUSY/.test(await readFile(log,'utf8').catch(()=>'')))throw new Error(`FRONT_PORT_BUSY: 127.0.0.1:${port} is held by another listener; use --direct (or set RIG_REVIEW_FRONT_PORT)`);throw new Error(`FRONT_START: ${exited}; front log ${log}`);}
|
package/src/handoff.ts
CHANGED
|
@@ -430,7 +430,7 @@ export async function resolveHandoff(root: string, declared: HandoffDeclaration
|
|
|
430
430
|
const full = declared.full !== undefined ? await blockPath(root, declared.full, 'producer.full', 'dir') : undefined;
|
|
431
431
|
const head = declared.head !== undefined ? await blockPath(root, declared.head, 'producer.head', 'dir') : undefined;
|
|
432
432
|
const keypoints = declared.keypoints !== undefined ? await blockPath(root, declared.keypoints, 'producer.keypoints', 'file') : undefined;
|
|
433
|
-
if ((
|
|
433
|
+
if ((full !== undefined && source === undefined) || (head !== undefined && full === undefined)) throw new HandoffError('HANDOFF_FLAGS_INVALID', 'producer', 'full requires source, and head requires full');
|
|
434
434
|
return { handoff: await record(root, root, 'declared', 'review.json producer', config, parts, { source, full, head, keypoints }, declared.parts !== undefined, options), reason: null };
|
|
435
435
|
}
|
|
436
436
|
for (const name of ['config.json', 'rig/config.json']) {
|
package/src/interview-project.ts
CHANGED
|
@@ -3,6 +3,12 @@ import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, realpat
|
|
|
3
3
|
import { extname, join, resolve } from 'node:path';
|
|
4
4
|
import { isDeepStrictEqual as equal } from 'node:util';
|
|
5
5
|
import {coveringChange, sceneAt} from './interview-scene.ts';
|
|
6
|
+
import type {
|
|
7
|
+
JobInterviewDiagnostic,
|
|
8
|
+
JobInterviewDiagnostics,
|
|
9
|
+
JobInterviewJson,
|
|
10
|
+
JobInterviewRecord,
|
|
11
|
+
} from './job-contract.ts';
|
|
6
12
|
|
|
7
13
|
type RecordData = Record<string, unknown>;
|
|
8
14
|
export interface SetRef {path: string; sha256: string}
|
|
@@ -234,7 +240,37 @@ function inspectContext(root: string, project: RecordData, raw: RecordData, set:
|
|
|
234
240
|
return {images, hasParts: ctx.kind !== 'inputs'};
|
|
235
241
|
}
|
|
236
242
|
|
|
243
|
+
function cloneJson(value: unknown): JobInterviewJson {
|
|
244
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string') return value;
|
|
245
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : null;
|
|
246
|
+
if (Array.isArray(value)) return value.map(cloneJson);
|
|
247
|
+
if (typeof value === 'object') {
|
|
248
|
+
return Object.fromEntries(
|
|
249
|
+
Object.entries(value as RecordData)
|
|
250
|
+
.filter(([, entry]) => entry !== undefined)
|
|
251
|
+
.map(([key, entry]) => [key, cloneJson(entry)]),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function cloneJsonObject(value: RecordData): { readonly [key: string]: JobInterviewJson } {
|
|
258
|
+
return cloneJson(value) as { readonly [key: string]: JobInterviewJson };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function observeRetainedSet(root: string, ref: SetRef): SetRef | null {
|
|
262
|
+
try {
|
|
263
|
+
if (['derived', 'outputs', 'scratch', 'node_modules', '.git'].includes(ref.path.split('/')[0]!)) return null;
|
|
264
|
+
const bytes = readRegular(checkedPath(root, ref.path), 64 * 1024 * 1024);
|
|
265
|
+
return { path: ref.path, sha256: digest(bytes) };
|
|
266
|
+
} catch {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
237
271
|
export function readProject(root: string, now = Date.now()) {
|
|
272
|
+
if (!Number.isFinite(now)) return invalid('Evaluation instant must be finite');
|
|
273
|
+
const evaluatedAt = new Date(now).toISOString();
|
|
238
274
|
try {
|
|
239
275
|
root = realpathSync(resolve(root));
|
|
240
276
|
if (!lstatSync(root).isDirectory()) return invalid('Project root must be a directory');
|
|
@@ -246,10 +282,13 @@ export function readProject(root: string, now = Date.now()) {
|
|
|
246
282
|
project = jsonObject(bytes);
|
|
247
283
|
} catch {return invalid('project.json must be a readable regular JSON file');}
|
|
248
284
|
if (project.schema !== 'rig-create/project@0') return invalid('Unsupported create project');
|
|
285
|
+
const hash = digest(bytes);
|
|
249
286
|
const interview = object(project.interview);
|
|
250
287
|
const questions: InterviewQuestion[] = [];
|
|
251
288
|
const historical: HistoricalInterview[] = [];
|
|
252
289
|
const diagnostics: InterviewDiagnostic[] = [];
|
|
290
|
+
const interviewRecords: JobInterviewRecord[] = [];
|
|
291
|
+
const interviewDiagnostics: JobInterviewDiagnostic[] = [];
|
|
253
292
|
let sceneAnswers = 0;
|
|
254
293
|
const seen = new Map<string, string>();
|
|
255
294
|
for (const [items, answerKey, allowed, collection] of [
|
|
@@ -290,11 +329,66 @@ export function readProject(root: string, now = Date.now()) {
|
|
|
290
329
|
} catch (error) {
|
|
291
330
|
if (editable) throw error;
|
|
292
331
|
const answer = entry.answer!;
|
|
332
|
+
const observedSet = observeRetainedSet(root, ref);
|
|
333
|
+
const answerAt = typeof answer.at === 'string' ? answer.at : null;
|
|
293
334
|
historical.push({question: String(item.id), verbatim: typeof answer.verbatim === 'string' ? answer.verbatim : '',
|
|
294
|
-
by: typeof answer.by === 'string' ? answer.by : undefined, at:
|
|
335
|
+
by: typeof answer.by === 'string' ? answer.by : undefined, at: answerAt ?? undefined,
|
|
295
336
|
ref, record: entry.record, answer});
|
|
296
337
|
diagnostics.push({code: 'INTERVIEW_OPTIONS_STALE', question: String(item.id), record: entry.record, ref,
|
|
297
|
-
...(
|
|
338
|
+
...(answerAt !== null ? {at: answerAt} : {})});
|
|
339
|
+
interviewRecords.push({
|
|
340
|
+
questionId: String(item.id),
|
|
341
|
+
record: entry.record,
|
|
342
|
+
setId: null,
|
|
343
|
+
ref,
|
|
344
|
+
observedSet,
|
|
345
|
+
timeKind: 'answer',
|
|
346
|
+
at: answerAt,
|
|
347
|
+
original: cloneJsonObject(answer),
|
|
348
|
+
});
|
|
349
|
+
interviewDiagnostics.push({
|
|
350
|
+
record: entry.record,
|
|
351
|
+
at: answerAt,
|
|
352
|
+
code: 'INTERVIEW_OPTIONS_STALE',
|
|
353
|
+
severity: 'error',
|
|
354
|
+
});
|
|
355
|
+
const rawDecision = answer.agent_decision;
|
|
356
|
+
if (rawDecision !== null && typeof rawDecision === 'object' && !Array.isArray(rawDecision)) {
|
|
357
|
+
const decision = rawDecision as RecordData;
|
|
358
|
+
const decisionRecord = entry.record + '.agent_decision';
|
|
359
|
+
if (['at', 'value', 'fragments'].some(key => Object.hasOwn(decision, key))) {
|
|
360
|
+
const decisionAt = typeof decision.at === 'string' ? decision.at : null;
|
|
361
|
+
interviewRecords.push({
|
|
362
|
+
questionId: String(item.id),
|
|
363
|
+
record: decisionRecord,
|
|
364
|
+
setId: null,
|
|
365
|
+
ref,
|
|
366
|
+
observedSet,
|
|
367
|
+
timeKind: 'decision',
|
|
368
|
+
at: decisionAt,
|
|
369
|
+
original: cloneJsonObject(decision),
|
|
370
|
+
});
|
|
371
|
+
diagnostics.push({code: 'INTERVIEW_OPTIONS_STALE', question: String(item.id), record: decisionRecord, ref,
|
|
372
|
+
...(decisionAt !== null ? {at: decisionAt} : {})});
|
|
373
|
+
interviewDiagnostics.push({
|
|
374
|
+
record: decisionRecord,
|
|
375
|
+
at: decisionAt,
|
|
376
|
+
code: 'INTERVIEW_OPTIONS_STALE',
|
|
377
|
+
severity: 'error',
|
|
378
|
+
});
|
|
379
|
+
} else {
|
|
380
|
+
interviewRecords.push({
|
|
381
|
+
questionId: String(item.id),
|
|
382
|
+
record: decisionRecord,
|
|
383
|
+
setId: null,
|
|
384
|
+
ref,
|
|
385
|
+
observedSet,
|
|
386
|
+
timeKind: 'decision',
|
|
387
|
+
at: null,
|
|
388
|
+
original: cloneJsonObject(decision),
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
298
392
|
continue;
|
|
299
393
|
}
|
|
300
394
|
if (editable && (set.stage === 'interview' || set.stage === 'rigging-interview') &&
|
|
@@ -304,27 +398,96 @@ export function readProject(root: string, now = Date.now()) {
|
|
|
304
398
|
if (editable && approval(project, set.stage === 'interview' ? 'plan-approved' : set.stage, now)) return invalid('Question approval is still live');
|
|
305
399
|
const sceneKind = object(raw.context).kind === 'scene';
|
|
306
400
|
if (!editable && sceneKind) sceneAnswers++;
|
|
307
|
-
const
|
|
401
|
+
const observedSet: SetRef = { path: ref.path, sha256: ref.sha256 };
|
|
402
|
+
const evaluate = (at: number, record: string, recordAt: string | null) => {
|
|
308
403
|
try {
|
|
309
404
|
const {legacy, ...context} = inspectContext(root, project, raw, set, at, editable);
|
|
310
|
-
if (legacy)
|
|
405
|
+
if (legacy) {
|
|
406
|
+
diagnostics.push({code: 'INTERVIEW_OPTIONS_SCENE_LEGACY', question: set.question, record, ref,
|
|
407
|
+
...(recordAt !== null ? {at: recordAt} : {})});
|
|
408
|
+
interviewDiagnostics.push({
|
|
409
|
+
record,
|
|
410
|
+
at: recordAt,
|
|
411
|
+
code: 'INTERVIEW_OPTIONS_SCENE_LEGACY',
|
|
412
|
+
severity: 'warning',
|
|
413
|
+
});
|
|
414
|
+
}
|
|
311
415
|
return context;
|
|
312
416
|
} catch (error) {
|
|
313
417
|
if (editable || !(error instanceof Error) || !error.message.startsWith('INTERVIEW_OPTIONS_STALE:')) throw error;
|
|
314
418
|
diagnostics.push({code: 'INTERVIEW_OPTIONS_STALE', question: set.question, record, ref,
|
|
315
|
-
...(
|
|
419
|
+
...(recordAt !== null ? {at: recordAt} : {})});
|
|
420
|
+
interviewDiagnostics.push({
|
|
421
|
+
record,
|
|
422
|
+
at: recordAt,
|
|
423
|
+
code: 'INTERVIEW_OPTIONS_STALE',
|
|
424
|
+
severity: 'error',
|
|
425
|
+
});
|
|
316
426
|
return {images: [], hasParts: false};
|
|
317
427
|
}
|
|
318
428
|
};
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
429
|
+
const recordAt = editable ? evaluatedAt : typeof entry.answer?.at === 'string' ? entry.answer.at : null;
|
|
430
|
+
interviewRecords.push({
|
|
431
|
+
questionId: String(item.id),
|
|
432
|
+
record: entry.record,
|
|
433
|
+
setId: set.id,
|
|
434
|
+
ref,
|
|
435
|
+
observedSet,
|
|
436
|
+
timeKind: editable ? 'inspection' : 'answer',
|
|
437
|
+
at: recordAt,
|
|
438
|
+
original: editable ? null : cloneJsonObject(entry.answer!),
|
|
439
|
+
});
|
|
440
|
+
const context = evaluate(editable ? now : date(entry.answer?.at), entry.record, recordAt);
|
|
441
|
+
const rawDecision = entry.answer?.agent_decision;
|
|
442
|
+
if (!editable && rawDecision !== null && typeof rawDecision === 'object' && !Array.isArray(rawDecision)) {
|
|
443
|
+
const decision = rawDecision as RecordData;
|
|
444
|
+
const decisionRecord = entry.record + '.agent_decision';
|
|
445
|
+
if (['at', 'value', 'fragments'].some(key => Object.hasOwn(decision, key))) {
|
|
446
|
+
const decisionAt = typeof decision.at === 'string' ? decision.at : null;
|
|
447
|
+
interviewRecords.push({
|
|
448
|
+
questionId: String(item.id),
|
|
449
|
+
record: decisionRecord,
|
|
450
|
+
setId: set.id,
|
|
451
|
+
ref,
|
|
452
|
+
observedSet,
|
|
453
|
+
timeKind: 'decision',
|
|
454
|
+
at: decisionAt,
|
|
455
|
+
original: cloneJsonObject(decision),
|
|
456
|
+
});
|
|
457
|
+
evaluate(date(decision.at), decisionRecord, decisionAt);
|
|
458
|
+
} else {
|
|
459
|
+
interviewRecords.push({
|
|
460
|
+
questionId: String(item.id),
|
|
461
|
+
record: decisionRecord,
|
|
462
|
+
setId: set.id,
|
|
463
|
+
ref,
|
|
464
|
+
observedSet,
|
|
465
|
+
timeKind: 'decision',
|
|
466
|
+
at: null,
|
|
467
|
+
original: cloneJsonObject(decision),
|
|
468
|
+
});
|
|
469
|
+
}
|
|
323
470
|
}
|
|
324
471
|
questions.push({ref, set, editable, answer: entry.answer, ...context});
|
|
325
472
|
seen.set(ref.sha256, ref.path);
|
|
326
473
|
}
|
|
327
474
|
}
|
|
328
475
|
}
|
|
329
|
-
|
|
476
|
+
const interviewDiagnosticsEnvelope: JobInterviewDiagnostics = {
|
|
477
|
+
schema: 'rig-review/job-interview@1',
|
|
478
|
+
project: { path: 'project.json', sha256: hash },
|
|
479
|
+
evaluatedAt,
|
|
480
|
+
records: interviewRecords,
|
|
481
|
+
diagnostics: interviewDiagnostics,
|
|
482
|
+
};
|
|
483
|
+
return {
|
|
484
|
+
root,
|
|
485
|
+
hash,
|
|
486
|
+
project,
|
|
487
|
+
questions,
|
|
488
|
+
historical,
|
|
489
|
+
diagnostics,
|
|
490
|
+
sceneAnswers,
|
|
491
|
+
interview: interviewDiagnosticsEnvelope,
|
|
492
|
+
};
|
|
330
493
|
}
|