rig-review 2.6.0 → 2.7.1
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/PANELS.md +1 -1
- package/docs/PARTS_VIEW.md +2 -0
- package/docs/REVIEW_PACKAGE.md +53 -13
- package/docs/STABILITY.md +232 -15
- package/docs/WORKFLOWS.md +2 -0
- package/package.json +2 -2
- package/src/handoff.ts +192 -25
- package/src/interview-project.ts +13 -0
- package/src/job-act.ts +316 -8
- package/src/job-api.ts +821 -8
- package/src/job-contract.ts +299 -0
- package/src/job-front.ts +763 -23
- package/src/job-host.ts +9 -1
- package/src/job-hub.ts +11 -6
- package/src/job-session.ts +68 -9
- package/src/job-source.ts +787 -7
- package/src/job-store.ts +114 -8
- package/src/job-worker.ts +5 -1
- package/src/joined-project.ts +83 -12
- package/src/manifest.ts +5 -3
- package/src/open.ts +5 -4
- package/src/rebuild.ts +445 -51
- package/src/reference.ts +3 -3
- package/src/server.ts +2 -2
- package/src/stage-parts.ts +47 -15
- package/web/catalog-en.ts +5 -0
- package/web/catalog-ko.ts +5 -0
- package/web/main.ts +353 -43
- package/web/part-selection.ts +2 -0
- package/web/parts.ts +22 -4
- package/web/rebuild-client.ts +14 -2
- package/web/stage-nav.ts +20 -12
package/src/job-store.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Database } from 'bun:sqlite';
|
|
1
|
+
import { Database, constants as sqliteConstants } from 'bun:sqlite';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { chmodSync, lstatSync, mkdirSync, realpathSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
@@ -106,6 +106,10 @@ function privateEntry(path: string, directory: boolean): void {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
export interface JobStoreOpenOptions {
|
|
110
|
+
readonly readonly?: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
109
113
|
/** One SQLite transaction seals the entire job, including its events, acts and
|
|
110
114
|
* idempotency receipts. IMMEDIATE transactions serialize independent daemons.
|
|
111
115
|
* FULL synchronous durability and the rollback journal survive process death.
|
|
@@ -113,10 +117,56 @@ function privateEntry(path: string, directory: boolean): void {
|
|
|
113
117
|
*/
|
|
114
118
|
export class JobStore<Data> {
|
|
115
119
|
readonly root: string;
|
|
116
|
-
private
|
|
120
|
+
private readOnly: boolean;
|
|
121
|
+
get isReadonly(): boolean { return this.readOnly; }
|
|
122
|
+
private db: Database;
|
|
123
|
+
private identities!: {directory: {dev: number; ino: number}; file: {dev: number; ino: number}};
|
|
124
|
+
private writeAdoption?: () => void;
|
|
117
125
|
|
|
118
|
-
|
|
126
|
+
|
|
127
|
+
constructor(directory: string, options: JobStoreOpenOptions = {}) {
|
|
128
|
+
this.readOnly = options.readonly === true;
|
|
119
129
|
try {
|
|
130
|
+
if (this.isReadonly) {
|
|
131
|
+
privateEntry(directory, true);
|
|
132
|
+
const directInfo = lstatSync(directory);
|
|
133
|
+
this.root = realpathSync(directory);
|
|
134
|
+
const realInfo = lstatSync(this.root);
|
|
135
|
+
if (directInfo.dev !== realInfo.dev || directInfo.ino !== realInfo.ino) {
|
|
136
|
+
throw new JobError('JOB_STORAGE_FAILED', 'State directory must not be a symlink');
|
|
137
|
+
}
|
|
138
|
+
const file = join(this.root, 'jobs.sqlite');
|
|
139
|
+
privateEntry(file, false);
|
|
140
|
+
for (const suffix of ['-journal', '-wal', '-shm']) {
|
|
141
|
+
let exists = false;
|
|
142
|
+
try { lstatSync(file + suffix); exists = true; }
|
|
143
|
+
catch (error) {
|
|
144
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
|
|
145
|
+
}
|
|
146
|
+
if (exists) throw new JobError('JOB_STORAGE_FAILED', 'Unrecovered SQLite sidecar present');
|
|
147
|
+
}
|
|
148
|
+
const fileInfo = lstatSync(file);
|
|
149
|
+
this.identities = {directory: {dev: directInfo.dev, ino: directInfo.ino}, file: {dev: fileInfo.dev, ino: fileInfo.ino}};
|
|
150
|
+
this.db = new Database(file, sqliteConstants.SQLITE_OPEN_READONLY | sqliteConstants.SQLITE_OPEN_NOFOLLOW);
|
|
151
|
+
try {
|
|
152
|
+
this.db.exec('PRAGMA query_only=ON; PRAGMA busy_timeout=1000;');
|
|
153
|
+
this.assertStorage();
|
|
154
|
+
const tables = new Set(
|
|
155
|
+
this.db.query<{ name: string }, []>("SELECT name FROM sqlite_master WHERE type='table'")
|
|
156
|
+
.all().map(row => row.name),
|
|
157
|
+
);
|
|
158
|
+
for (const required of [
|
|
159
|
+
'jobs', 'job_closures', 'job_snapshot_owners',
|
|
160
|
+
'job_snapshot_reads', 'job_snapshot_tombstones', 'job_act_stills',
|
|
161
|
+
]) {
|
|
162
|
+
if (!tables.has(required)) throw new JobError('JOB_STORAGE_FAILED', 'Required job table missing');
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
this.db.close();
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
120
170
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
121
171
|
privateEntry(directory, true);
|
|
122
172
|
this.root = realpathSync(directory);
|
|
@@ -159,13 +209,55 @@ export class JobStore<Data> {
|
|
|
159
209
|
sha256 TEXT NOT NULL, binding TEXT NOT NULL, png BLOB NOT NULL, act_bytes BLOB NOT NULL,
|
|
160
210
|
PRIMARY KEY(job_id, act_id), UNIQUE(job_id, page_id, submission_id)
|
|
161
211
|
);`);
|
|
212
|
+
this.captureStorage();
|
|
162
213
|
} catch {
|
|
163
214
|
throw new JobError('JOB_STORAGE_FAILED', 'Private job storage could not be opened');
|
|
164
215
|
}
|
|
165
216
|
}
|
|
166
217
|
|
|
218
|
+
private captureStorage(): void {
|
|
219
|
+
const directory = lstatSync(this.root), file = lstatSync(join(this.root, 'jobs.sqlite'));
|
|
220
|
+
this.identities = {directory: {dev: directory.dev, ino: directory.ino}, file: {dev: file.dev, ino: file.ino}};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
assertStorage(): void {
|
|
224
|
+
for (const [path, captured, directory] of [
|
|
225
|
+
[this.root, this.identities.directory, true],
|
|
226
|
+
[join(this.root, 'jobs.sqlite'), this.identities.file, false],
|
|
227
|
+
] as const) {
|
|
228
|
+
privateEntry(path, directory);
|
|
229
|
+
const current = lstatSync(path);
|
|
230
|
+
if (current.dev !== captured.dev || current.ino !== captured.ino) throw new JobError('JOB_STORAGE_FAILED');
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Install the exact-job guard without opening a writable connection. */
|
|
235
|
+
allowExistingWrites(verify: () => void): void { this.writeAdoption = verify; }
|
|
236
|
+
|
|
237
|
+
/** Deferred snapshot: acceptance performs SELECTs only, ordered against sealClose. */
|
|
238
|
+
inspect<Value>(operation: () => Value): Value {
|
|
239
|
+
return this.db.transaction(operation).deferred();
|
|
240
|
+
}
|
|
241
|
+
|
|
167
242
|
private transaction<Value>(operation: () => Value): Value {
|
|
168
|
-
try {
|
|
243
|
+
try {
|
|
244
|
+
if (this.readOnly) {
|
|
245
|
+
if (!this.writeAdoption) throw new JobError('JOB_STORAGE_FAILED');
|
|
246
|
+
this.assertStorage();
|
|
247
|
+
const writable = new Database(join(this.root, 'jobs.sqlite'), sqliteConstants.SQLITE_OPEN_READWRITE | sqliteConstants.SQLITE_OPEN_NOFOLLOW);
|
|
248
|
+
try {
|
|
249
|
+
this.assertStorage();
|
|
250
|
+
writable.exec('PRAGMA synchronous=FULL; PRAGMA busy_timeout=1000;');
|
|
251
|
+
} catch (error) { writable.close(); throw error; }
|
|
252
|
+
this.db.close(); this.db = writable; this.readOnly = false;
|
|
253
|
+
}
|
|
254
|
+
return this.db.transaction(() => {
|
|
255
|
+
if (this.writeAdoption) {
|
|
256
|
+
this.assertStorage(); this.writeAdoption(); this.writeAdoption = undefined;
|
|
257
|
+
}
|
|
258
|
+
return operation();
|
|
259
|
+
}).immediate();
|
|
260
|
+
}
|
|
169
261
|
catch (error) {
|
|
170
262
|
if (typeof (error as { code?: unknown }).code === 'string' &&
|
|
171
263
|
String((error as { code: string }).code).startsWith('SQLITE_')) {
|
|
@@ -176,10 +268,24 @@ export class JobStore<Data> {
|
|
|
176
268
|
}
|
|
177
269
|
|
|
178
270
|
get(jobId: string): StoredJob<Data> {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
271
|
+
try {
|
|
272
|
+
const row = this.db.query<JobRow, [string]>(`SELECT jobs.*, job_closures.document AS closure
|
|
273
|
+
FROM jobs LEFT JOIN job_closures USING(job_id) WHERE job_id=?`).get(jobId);
|
|
274
|
+
if (!row) throw new JobError('JOB_UNKNOWN');
|
|
275
|
+
return decode<Data>(row);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (error instanceof JobError) throw error;
|
|
278
|
+
throw new JobError('JOB_STORAGE_FAILED', 'Stored job state is invalid');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
activeByRootKey(rootKey: string): StoredJob<Data> | null {
|
|
283
|
+
try {
|
|
284
|
+
const row = this.db.query<JobRow, [string]>('SELECT * FROM jobs WHERE root_key=? AND active=1').get(rootKey);
|
|
285
|
+
return row ? decode<Data>(row) : null;
|
|
286
|
+
} catch {
|
|
287
|
+
throw new JobError('JOB_STORAGE_FAILED', 'Stored job state is invalid');
|
|
288
|
+
}
|
|
183
289
|
}
|
|
184
290
|
|
|
185
291
|
open(rootKey: string, initialize: (jobId: string) => Data, canonicalRoot?: string): StoredJob<Data> {
|
package/src/job-worker.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {randomUUID} from 'node:crypto';
|
|
1
2
|
import { createJobHostPorts } from './job-api.ts';
|
|
2
3
|
import { JobSession, type JobSessionOptions } from './job-session.ts';
|
|
3
4
|
import type { JobHostPorts } from './job-contract.ts';
|
|
@@ -7,6 +8,7 @@ export interface JobWorkerOptions extends JobSessionOptions {
|
|
|
7
8
|
readonly port?: number;
|
|
8
9
|
/** Trusted Create #184 adapter installs its private writer-owned sibling.
|
|
9
10
|
* No project record key or binding-file format is defined by this callback.
|
|
11
|
+
* Reusable owner-host attachment (`reuseOnly`) belongs to JobHostOptions.
|
|
10
12
|
*/
|
|
11
13
|
readonly installWriterBinding?: (binding: {
|
|
12
14
|
readonly jobId: string;
|
|
@@ -23,9 +25,11 @@ export async function startJobWorker(options: JobWorkerOptions): Promise<{
|
|
|
23
25
|
readonly session: JobSession;
|
|
24
26
|
readonly ports: JobHostPorts;
|
|
25
27
|
readonly origin: string;
|
|
28
|
+
readonly listenerIncarnation: string;
|
|
26
29
|
stop(): void;
|
|
27
30
|
}> {
|
|
28
31
|
const session = new JobSession(options);
|
|
32
|
+
const listenerIncarnation = randomUUID();
|
|
29
33
|
let ports: JobHostPorts;
|
|
30
34
|
let stopped = false;
|
|
31
35
|
const server = Bun.serve({
|
|
@@ -48,7 +52,7 @@ export async function startJobWorker(options: JobWorkerOptions): Promise<{
|
|
|
48
52
|
};
|
|
49
53
|
try {
|
|
50
54
|
await options.installWriterBinding?.({ ...session.writerGrant(), origin });
|
|
51
|
-
return { session, ports, origin, stop };
|
|
55
|
+
return { session, ports, origin, listenerIncarnation, stop };
|
|
52
56
|
} catch {
|
|
53
57
|
stop();
|
|
54
58
|
throw new JobError('JOB_AUTHORITY_REFUSED', 'Writer binding installation failed');
|
package/src/joined-project.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { lstatSync, readdirSync } from 'node:fs';
|
|
2
|
-
import { join, relative, sep } from 'node:path';
|
|
3
|
-
import { boundBytes, checkedPath, digest, jsonObject, literalPath, object, readProject, readRegular } from './interview-project.ts';
|
|
2
|
+
import { join, posix, relative, sep } from 'node:path';
|
|
3
|
+
import { boundBytes, checkedPath, digest, jsonObject, literalPath, object, partsDraftEditable, readProject, readRegular, type SetRef } from './interview-project.ts';
|
|
4
|
+
import { configNamedReferences, DIRECTORY_INPUT_RECEIPT, plateReceiptSpec, receiptSpec } from './handoff.ts';
|
|
4
5
|
import { DIRECTION_MAX_BYTES, readDirectionInspection } from './direction-inspection.ts';
|
|
5
6
|
import { outputDirectory } from './interview-picks.ts';
|
|
6
7
|
import { packagePath, type ReviewPackage } from './manifest.ts';
|
|
@@ -10,12 +11,25 @@ export type ProjectDesignation={root:string;picksDir:string}&(
|
|
|
10
11
|
{version:number;postVersion?:number;draftId?:never;partsVerdictDir?:never} |
|
|
11
12
|
{draftId:string;partsVerdictDir?:string;version?:never;postVersion?:never}
|
|
12
13
|
);
|
|
14
|
+
interface DraftRecord {
|
|
15
|
+
id:string;
|
|
16
|
+
kind:'draft-rig';
|
|
17
|
+
at:string;
|
|
18
|
+
producer:{name:string;version:string};
|
|
19
|
+
config:SetRef;
|
|
20
|
+
config_inputs?:(SetRef&{directory?:string;spec?:string})[];
|
|
21
|
+
parts:{path:string;files:SetRef[]};
|
|
22
|
+
files:SetRef[];
|
|
23
|
+
}
|
|
13
24
|
interface DraftSource {
|
|
25
|
+
record:DraftRecord;
|
|
26
|
+
editable:boolean;
|
|
14
27
|
parts:string;
|
|
15
28
|
rig:string;
|
|
16
29
|
meshReport:string;
|
|
17
30
|
model:string;
|
|
18
31
|
files:ReadonlyMap<string,string>;
|
|
32
|
+
starts?:readonly string[];
|
|
19
33
|
}
|
|
20
34
|
interface JoinedSource {
|
|
21
35
|
review:ReviewPackage;
|
|
@@ -31,8 +45,8 @@ export const interviewMismatch = 'INTERVIEW_SOURCE_MISMATCH';
|
|
|
31
45
|
export const interviewStale = 'INTERVIEW_OPTIONS_STALE';
|
|
32
46
|
export const directionStale = 'DIRECTION_SOURCE_STALE';
|
|
33
47
|
|
|
34
|
-
export function joinProject(p: ReviewPackage, designation: ProjectDesignation):JoinedSource {
|
|
35
|
-
if(designation.draftId!==undefined)return joinDraft(p,designation);
|
|
48
|
+
export function joinProject(p: ReviewPackage, designation: ProjectDesignation, options: { starts?: readonly string[] } = {}):JoinedSource {
|
|
49
|
+
if(designation.draftId!==undefined)return joinDraft(p,designation,options);
|
|
36
50
|
const opened = readProject(designation.root);
|
|
37
51
|
const {root, hash, project} = opened;
|
|
38
52
|
const {version} = designation;
|
|
@@ -148,18 +162,21 @@ export function joinProject(p: ReviewPackage, designation: ProjectDesignation):J
|
|
|
148
162
|
available:opened.questions.length > 0 || opened.historical.length > 0};
|
|
149
163
|
}
|
|
150
164
|
/** Match the draft writer's explicit parts and rig inventories, independently of a production version. */
|
|
151
|
-
function joinDraft(p:ReviewPackage,designation:Extract<ProjectDesignation,{draftId:string}
|
|
165
|
+
function joinDraft(p:ReviewPackage,designation:Extract<ProjectDesignation,{draftId:string}>,options:{starts?:readonly string[]}={}):JoinedSource {
|
|
152
166
|
const opened=readProject(designation.root);
|
|
153
167
|
const {root,hash,project}=opened;
|
|
154
168
|
const {draftId}=designation;
|
|
155
169
|
const path='derived/drafts/'+draftId;
|
|
156
170
|
const fail=():never=>{throw new Error('INTERVIEW_SOURCE_MISMATCH: expected the selected Create pre-rig draft and exact recorded files');};
|
|
157
|
-
if(!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(draftId)||!Array.isArray(project.versions)||
|
|
171
|
+
if(!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(draftId)||!Array.isArray(project.versions)||
|
|
158
172
|
!Array.isArray(project.drafts)||!Array.isArray(project.signoffs)||!p.manifest.model||!p.reviewedSource.rig||
|
|
159
173
|
p.direction||p.handoffInputs)return fail();
|
|
160
174
|
const matches=project.drafts.map(object).filter(draft=>draft.id===draftId);
|
|
161
175
|
const record=matches[0],parts=object(record?.parts);
|
|
162
|
-
|
|
176
|
+
const producer=object(record?.producer);
|
|
177
|
+
if(matches.length!==1||record?.kind!=='draft-rig'||typeof record.at!=='string'||!Number.isFinite(Date.parse(record.at))||
|
|
178
|
+
producer.name!=='@rig-c/parts'||typeof producer.version!=='string'||!producer.version.trim()||
|
|
179
|
+
!literalPath(parts.path)||!parts.path.startsWith(path+'/')||
|
|
163
180
|
!Array.isArray(parts.files)||!Array.isArray(record.files)||
|
|
164
181
|
(record.config_inputs!==undefined&&!Array.isArray(record.config_inputs)))return fail();
|
|
165
182
|
const files=new Map<string,string>();
|
|
@@ -176,10 +193,45 @@ function joinDraft(p:ReviewPackage,designation:Extract<ProjectDesignation,{draft
|
|
|
176
193
|
return paths;
|
|
177
194
|
};
|
|
178
195
|
let draft:DraftSource;
|
|
196
|
+
let assertInventory:()=>void;
|
|
197
|
+
const searchStarts=options.starts??[...(p.cwd?[p.cwd]:[]),process.cwd()];
|
|
179
198
|
try{
|
|
180
199
|
inventory([record.config,...(record.config_inputs??[])],path);
|
|
200
|
+
const config=object(record.config),doc=jsonObject(boundBytes(root,config as unknown as SetRef));
|
|
201
|
+
const configDir=posix.dirname(config.path as string);
|
|
202
|
+
const {partsRoot,references}=configNamedReferences(doc,[join(root,configDir),root,p.root,...searchStarts]);
|
|
203
|
+
const rawInputs=(record.config_inputs??[]).map(object);
|
|
204
|
+
for(const entry of rawInputs){
|
|
205
|
+
if(entry.directory!==undefined){
|
|
206
|
+
if(!literalPath(entry.directory)||!entry.directory.startsWith(path+'/')||entry.path!==`${entry.directory}/${DIRECTORY_INPUT_RECEIPT}`||typeof entry.spec!=='string'||!entry.spec)return fail();
|
|
207
|
+
checkedPath(root,entry.directory,true);
|
|
208
|
+
const bytes=boundBytes(root,{path:entry.path as string,sha256:entry.sha256 as string});
|
|
209
|
+
if(receiptSpec(bytes)!==entry.spec)return fail();
|
|
210
|
+
}else if(entry.spec!==undefined)return fail();
|
|
211
|
+
}
|
|
212
|
+
for(const ref of references){
|
|
213
|
+
if(!literalPath(ref.value))return fail();
|
|
214
|
+
const resolved=posix.join(configDir,ref.value);
|
|
215
|
+
if(ref.kind==='plate'){
|
|
216
|
+
const expectedSpec=plateReceiptSpec(partsRoot,`config ${ref.at}`);
|
|
217
|
+
const receiptPath=`${resolved}/${DIRECTORY_INPUT_RECEIPT}`;
|
|
218
|
+
if(!rawInputs.some(entry=>entry.path===receiptPath&&entry.directory===resolved&&entry.spec===expectedSpec))return fail();
|
|
219
|
+
}else if(!rawInputs.some(entry=>entry.path===resolved&&entry.directory===undefined)){
|
|
220
|
+
return fail();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
181
223
|
const input=inventory(parts.files,parts.path);
|
|
182
224
|
if(!input.includes(parts.path+'/parts.json')||!input.some(file=>file.startsWith(parts.path+'/parts/')))return fail();
|
|
225
|
+
const manifest=jsonObject(boundBytes(root,{path:parts.path+'/parts.json',sha256:files.get(parts.path+'/parts.json')!}));
|
|
226
|
+
if(!Array.isArray(manifest.parts)||manifest.parts.some(part=>{
|
|
227
|
+
const {name}=object(part);
|
|
228
|
+
return !literalPath(name)||name.includes('/')||!input.includes(parts.path+'/parts/'+name+'.png');
|
|
229
|
+
}))return fail();
|
|
230
|
+
if(manifest.painting_in_rig!==undefined){
|
|
231
|
+
const painting=object(manifest.painting_in_rig);
|
|
232
|
+
if(!literalPath(painting.path)||!input.includes(parts.path+'/'+painting.path)||
|
|
233
|
+
files.get(parts.path+'/'+painting.path)!==painting.sha256)return fail();
|
|
234
|
+
}
|
|
183
235
|
const output=inventory(record.files,path);
|
|
184
236
|
const rigs=output.filter(file=>file.endsWith('/rig.json'));
|
|
185
237
|
if(rigs.length!==1)return fail();
|
|
@@ -190,22 +242,41 @@ function joinDraft(p:ReviewPackage,designation:Extract<ProjectDesignation,{draft
|
|
|
190
242
|
if(!output.includes(meshReport)||!output.includes(dir+'/motion.json')||
|
|
191
243
|
!model.startsWith(checkRoot+'/check/')||!output.includes(model)||files.get(model)!==p.reviewedSource.rig.sha256||
|
|
192
244
|
![...p.files].every(file=>output.includes(relative(root,join(p.root,file)).split(sep).join('/'))))return fail();
|
|
193
|
-
|
|
194
|
-
|
|
245
|
+
const directoryInventory=(prefix:string,expected:string[])=>{
|
|
246
|
+
const remaining=new Set(expected);
|
|
247
|
+
const visit=(prefix:string)=>{
|
|
248
|
+
for(const entry of readdirSync(checkedPath(root,prefix,true),{withFileTypes:true})){
|
|
249
|
+
const file=prefix+'/'+entry.name;
|
|
250
|
+
if(!literalPath(file))return fail();
|
|
251
|
+
if(entry.isDirectory())visit(file);
|
|
252
|
+
else if(!entry.isFile()||!remaining.delete(file))return fail();
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
visit(prefix);
|
|
256
|
+
if(remaining.size)return fail();
|
|
257
|
+
};
|
|
258
|
+
assertInventory=()=>{
|
|
259
|
+
directoryInventory(parts.path+'/parts',input.filter(file=>file.startsWith(parts.path+'/parts/')));
|
|
260
|
+
directoryInventory(checkRoot,output);
|
|
261
|
+
};
|
|
262
|
+
assertInventory();
|
|
263
|
+
draft={record:record as unknown as DraftRecord,editable:partsDraftEditable(project),
|
|
264
|
+
parts:checkedPath(root,parts.path,true),rig:checkedPath(root,rig),meshReport:checkedPath(root,meshReport),
|
|
265
|
+
model:checkedPath(root,model),files:new Map([...files].map(([file,sha])=>[checkedPath(root,file),sha])),
|
|
266
|
+
starts:[join(root,configDir),root,p.root,...searchStarts]};
|
|
195
267
|
for(const [path,sha256] of files)boundBytes(root,{path,sha256});
|
|
196
268
|
}catch{return fail();}
|
|
197
269
|
outputDirectory(root,designation.picksDir,project);
|
|
198
270
|
const assertCurrent=async()=>{
|
|
199
271
|
try{
|
|
200
272
|
await assertReviewUnchanged(p);
|
|
273
|
+
assertInventory();
|
|
201
274
|
for(const [path,sha256] of files)boundBytes(root,{path,sha256});
|
|
202
275
|
if(digest(readRegular(checkedPath(root,'project.json'),8*1024*1024))!==hash)throw new Error('Project changed');
|
|
203
276
|
}catch{throw new Error(interviewStale+': project or draft changed; reopen the project');}
|
|
204
277
|
};
|
|
205
278
|
const dir=designation.partsVerdictDir;
|
|
206
279
|
// An explicit output selects the write surface. A recorded parts approval closes it.
|
|
207
|
-
const pending=['parts','parts-review'].includes(String(project.stage))&&
|
|
208
|
-
!project.signoffs.map(object).some(signoff=>signoff.stage==='parts-review');
|
|
209
280
|
let verdictDirectory:JoinedSource['verdictDirectory'];
|
|
210
281
|
if(dir!==undefined){
|
|
211
282
|
const locate=()=>{
|
|
@@ -217,7 +288,7 @@ function joinDraft(p:ReviewPackage,designation:Extract<ProjectDesignation,{draft
|
|
|
217
288
|
catch{throw new Error('PARTS_VERDICT_OUTPUT');}
|
|
218
289
|
};
|
|
219
290
|
const original=lstatSync(locate());
|
|
220
|
-
if(
|
|
291
|
+
if(draft.editable)verdictDirectory=()=>{
|
|
221
292
|
const output=locate(),stat=lstatSync(output);
|
|
222
293
|
if(stat.dev!==original.dev||stat.ino!==original.ino)throw new Error('PARTS_VERDICT_OUTPUT');
|
|
223
294
|
return output;
|
package/src/manifest.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface ReviewPackage { direction?:DirectionInspection; setsHash?:strin
|
|
|
31
31
|
buildRoot?: string;
|
|
32
32
|
/** #305: viewer-only open (`--view-only`). */
|
|
33
33
|
viewOnly?: boolean;
|
|
34
|
+
/** Logical working directory passed at load/open time for resolving an external producer (`options.cwd`). */
|
|
35
|
+
cwd?: string;
|
|
34
36
|
/** #329: the handoff's source painting, served at a fixed route by its pinned hash; absent when the handoff knows none. */
|
|
35
37
|
sourcePainting?: SourcePainting }
|
|
36
38
|
function fail(field: string, expected: string): never { throw new Error(`${field}: expected ${expected}`); }
|
|
@@ -86,7 +88,7 @@ export function parseManifest(input: unknown): ReviewManifest {
|
|
|
86
88
|
return manifest;
|
|
87
89
|
}
|
|
88
90
|
/** `options.handoff` are the explicit `--config …` flags; they win over the manifest block and discovery. */
|
|
89
|
-
export async function loadReview(input: string, options: { handoff?: HandoffFlags } = {}): Promise<ReviewPackage> {
|
|
91
|
+
export async function loadReview(input: string, options: { handoff?: HandoffFlags; cwd?: string } = {}): Promise<ReviewPackage> {
|
|
90
92
|
const inputPath=await realpath(resolve(input));const directory=(await stat(inputPath)).isDirectory();
|
|
91
93
|
if(directory){try{await stat(resolve(inputPath,'review.json'));return loadReview(resolve(inputPath,'review.json'),options);}catch(e){if((e as NodeJS.ErrnoException).code!=='ENOENT')throw e;}
|
|
92
94
|
// #149: a rig-parts build root without a model of its own opens as its check package, exactly as opening check/ does.
|
|
@@ -118,7 +120,7 @@ export async function loadReview(input: string, options: { handoff?: HandoffFlag
|
|
|
118
120
|
}
|
|
119
121
|
const reportPath=files.has('report.json')?'report.json':authoringPath('report.json');let report:ReportSeeds|null=null;let modelMetadata:Record<string,unknown>|null=null;let directionInput:unknown;
|
|
120
122
|
// The handoff files are hashed beside the package: their record joins the reviewed identity (and so the session file).
|
|
121
|
-
const {handoff,reason:handoffReason}=await resolveHandoff(root,manifest.producer,options.handoff);
|
|
123
|
+
const {handoff,reason:handoffReason}=await resolveHandoff(root,manifest.producer,options.handoff,{starts:[options.cwd??process.cwd()]});
|
|
122
124
|
// #329: the source painting the handoff knows is the first reference, outside the package's own files.
|
|
123
125
|
const painting=sourcePainting(manifest,handoff,directory);
|
|
124
126
|
const hash = createHash('sha256');hash.update(JSON.stringify(manifest));hash.update('\0');const fileHashes=new Map<string,string>();
|
|
@@ -135,7 +137,7 @@ export async function loadReview(input: string, options: { handoff?: HandoffFlag
|
|
|
135
137
|
const reviewedSource:ReviewedSource={packageRevision:manifest.revision,...await toolVersions(),rig:rigPath?{path:rigPath,sha256:fileHashes.get(rigPath)!}:null,motion:motionPath?{path:motionPath,sha256:fileHashes.get(motionPath)!}:null,...(handoff?{handoff:handoff.record}:{})};
|
|
136
138
|
const direction=manifest.direction?readDirectionInspection(directionInput,{path:manifest.direction,sha256:fileHashes.get(manifest.direction)!},reviewedSource.rig):undefined;
|
|
137
139
|
const feedbackCatalog:FeedbackCatalog={rig:manifest.id,bones:modelNames(modelMetadata,'bones'),slots:modelNames(modelMetadata,'slots'),animations:modelAnimations(modelMetadata),clock:report?.clock??null,clockAnimation:report?.animation??null,...(discoverTurnDials(modelMetadata).length?{turnDials:discoverTurnDials(modelMetadata)}:{})};
|
|
138
|
-
return {...(direction?{direction}:{}),...(manifest.sets?{setsHash:fileHashes.get(manifest.sets)!}:{}),referenceHashes:Object.fromEntries(manifest.references.map(r=>[r.id,r.id===painting?.id?painting.sha256:fileHashes.get(r.path)!])),root,manifestPath,manifest,sourceHash:hash.digest('hex'),reviewedSource,files,report,feedbackCatalog,handoff,handoffReason,...(handoff?.flags?{handoffInputs:handoff.flags}:{}),...(buildRoot?{buildRoot}:{}),...(painting?{sourcePainting:painting}:{})};
|
|
140
|
+
return {...(direction?{direction}:{}),...(manifest.sets?{setsHash:fileHashes.get(manifest.sets)!}:{}),referenceHashes:Object.fromEntries(manifest.references.map(r=>[r.id,r.id===painting?.id?painting.sha256:fileHashes.get(r.path)!])),root,manifestPath,manifest,sourceHash:hash.digest('hex'),reviewedSource,files,report,feedbackCatalog,handoff,handoffReason,...(handoff?.flags?{handoffInputs:handoff.flags}:{}),...(buildRoot?{buildRoot}:{}),...(painting?{sourcePainting:painting}:{}),...(options.cwd?{cwd:options.cwd}:{})};
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
/** #329: the reference id and served path of the handoff's source painting; the path is a name, never a package file. */
|
package/src/open.ts
CHANGED
|
@@ -43,9 +43,9 @@ const appRoot=fileURLToPath(new URL('..',import.meta.url));
|
|
|
43
43
|
const digest=(value:unknown)=>createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
44
44
|
const sleep=(ms:number)=>new Promise(resolveSleep=>setTimeout(resolveSleep,ms));
|
|
45
45
|
export const defaultStateDir=()=>process.env.RIG_REVIEW_STATE_DIR??join(homedir(),'.local','state','rig-c-review');
|
|
46
|
-
export async function loadOpenPackage(inputs:OpenInputs):Promise<OpenPackage>{
|
|
46
|
+
export async function loadOpenPackage(inputs:OpenInputs,options:{cwd?:string}={}):Promise<OpenPackage>{
|
|
47
47
|
// Handoff flags become canonical absolute paths here, so the worker and every reload read exactly these files.
|
|
48
|
-
if(!inputs.compare){const base=await loadReferencedReview(inputs.input,inputs.reference,handoffFlags(inputs));const joined=inputs.project?joinProject(base,inputs.project):undefined;const p=joined?.review??base,selection=selectAnimation([{label:'single',catalog:p.feedbackCatalog,report:p.report}],inputs.animation,true);if(inputs.viewOnly)p.viewOnly=true;return {mode:'single',p,selection,contentHash:p.sourceHash,...(joined?{joined}:{}),inputs:{input:p.manifestPath,...(joined?{project:joined.designation}:{}),...(selectedReference(p)?{reference:selectedReference(p)!.path}:{}),...(selection?{animation:selection.name}:{}),...(inputs.control?{control:true}:{}),...(p.handoffInputs??{})}};}
|
|
48
|
+
if(!inputs.compare){const base=await loadReferencedReview(inputs.input,inputs.reference,handoffFlags(inputs),options.cwd);const joined=inputs.project?joinProject(base,inputs.project,{starts:[options.cwd??process.cwd()]}):undefined;const p=joined?.review??base,selection=selectAnimation([{label:'single',catalog:p.feedbackCatalog,report:p.report}],inputs.animation,true);if(inputs.viewOnly)p.viewOnly=true;return {mode:'single',p,selection,contentHash:p.sourceHash,...(joined?{joined}:{}),inputs:{input:p.manifestPath,...(joined?{project:joined.designation}:{}),...(selectedReference(p)?{reference:selectedReference(p)!.path}:{}),...(selection?{animation:selection.name}:{}),...(inputs.control?{control:true}:{}),...(p.handoffInputs??{})}};}
|
|
49
49
|
if(inputs.project)throw new Error('INTERVIEW_SOURCE_MISMATCH: compare takes no joined project');
|
|
50
50
|
if(handoffFlags(inputs))throw new HandoffError('HANDOFF_FLAGS_INVALID','--config','compare takes no producer handoff; open one package with --config');
|
|
51
51
|
if(!inputs.reference)throw new Error('open compare: explicit --reference required');
|
|
@@ -130,7 +130,7 @@ export async function prepareOpenTarget(inputs: OpenInputs, options: OpenOptions
|
|
|
130
130
|
const viewOnly=options.viewOnly??inputs.viewOnly??false;
|
|
131
131
|
for(const path of [inputs.input,...(inputs.compare!==undefined?[inputs.compare]:[])])await assertOpenInput(path);
|
|
132
132
|
if(inputs.compare!==undefined&&!inputs.reference)throw new Error('OPEN_REFERENCE_REQUIRED: compare: explicit --reference required');
|
|
133
|
-
let p:OpenPackage;try{p=await loadOpenPackage(inputs);}catch(error){throw await openRefusal(error,inputs);}
|
|
133
|
+
let p:OpenPackage;try{p=await loadOpenPackage(inputs,{cwd:options.cwd});}catch(error){throw await openRefusal(error,inputs);}
|
|
134
134
|
fingerprint??=await openFingerprint();const key=openKey(p,fingerprint);
|
|
135
135
|
// #187: canonical (symlinks and ancestors resolved) and outside every supplied folder: the package, the build root a check package belongs to, the handoff root.
|
|
136
136
|
const stateDir=destinationDirectory(options.stateDir??defaultStateDir(),'OPEN_STATE_INVALID: the state directory path has a non-directory component or a symlink loop'),roots=p.mode==='single'?stateRoots(p.p):[...stateRoots(p.p.a),...stateRoots(p.p.b)];
|
|
@@ -168,7 +168,8 @@ async function ensureWorker(p:OpenPackage,key:string,fingerprint:string,stateDir
|
|
|
168
168
|
export async function runOpenWorker(requestPath:string):Promise<void>{
|
|
169
169
|
const raw=await smallJson(requestPath) as WorkerRequest;if(raw.schema!=='rig-review-open-request/1'||!raw.identity||!recordValue({schema:'rig-review-open-instance/1',...raw.identity,pid:process.pid,origin:'http://127.0.0.1:1',mode:'single',capability:'0'.repeat(64)},raw.identity.key))throw new Error('open worker: invalid request');
|
|
170
170
|
const spec=raw,control=await realpath(join(spec.stateDir,'open'));if(dirname(await realpath(requestPath))!==control||spec.request!==requestPath||spec.registry!==join(control,spec.identity.key+'.json')||!Number.isSafeInteger(spec.idleMs)||spec.idleMs<100)throw new Error('open worker: invalid state locations or idle limit');
|
|
171
|
-
const
|
|
171
|
+
const workerCwd=typeof spec.cwd==='string'&&isAbsolute(spec.cwd)?spec.cwd:undefined;
|
|
172
|
+
const p=await loadOpenPackage(spec.inputs,{cwd:workerCwd}),fingerprint=await openFingerprint();if(fingerprint!==spec.identity.fingerprint||openKey(p,fingerprint)!==spec.identity.key||p.contentHash!==spec.identity.contentHash)throw new Error('open worker: inputs changed before startup');
|
|
172
173
|
if(spec.inputs.control&&(!spec.controlToken||!/^[a-f0-9-]{36}$/.test(spec.controlToken)))throw new Error('open control: invalid private capability');
|
|
173
174
|
// The worker mints its own page capability; it lives only in this process and the private record.
|
|
174
175
|
const removeRecord=async()=>{const current=await readRecord(spec.registry,spec.identity.key);if(current?.nonce===spec.identity.nonce)await unlink(spec.registry).catch(()=>{});};
|