rig-review 2.0.0 → 2.1.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/README.md +3 -3
- package/docs/WORKFLOWS.md +159 -35
- package/package.json +1 -1
- package/skills/rig-review/SKILL.md +58 -1
- package/src/build.ts +2 -2
- package/src/cli.ts +57 -2
- package/src/compare-server.ts +48 -10
- package/src/front.ts +1 -1
- package/src/open-workspace-contract.ts +60 -0
- package/src/open-workspace-launch.ts +103 -0
- package/src/open-workspace-state.ts +125 -0
- package/src/open-workspace-worker.ts +33 -0
- package/src/open-workspace.ts +292 -0
- package/src/open.ts +20 -7
- package/src/server.ts +51 -10
- package/web/catalog-en.ts +37 -0
- package/web/catalog-ko.ts +37 -0
- package/web/compare.ts +2 -0
- package/web/main.ts +2 -0
- package/web/owner-workspace.css +14 -0
- package/web/owner-workspace.html +5 -0
- package/web/owner-workspace.ts +124 -0
- package/web/workspace-visibility.ts +21 -0
package/src/open.ts
CHANGED
|
@@ -125,22 +125,29 @@ async function verifyOpenLoad(p:OpenPackage,viewOnly:boolean,cwd=process.cwd()):
|
|
|
125
125
|
}
|
|
126
126
|
/** Managed is the default: the printed URL goes through the one loopback front (127.0.0.1:4318, or
|
|
127
127
|
* RIG_REVIEW_FRONT_PORT) so browser storage keeps one origin across reopens. `direct` keeps the worker's own port. */
|
|
128
|
-
export
|
|
129
|
-
|
|
128
|
+
export interface OpenOptions {stateDir?:string;idleMs?:number;graceMs?:number;direct?:boolean;viewOnly?:boolean;cwd?:string;frontPort?:number;frontIdleMs?:number}
|
|
129
|
+
export async function prepareOpenTarget(inputs: OpenInputs, options: OpenOptions = {}, fingerprint?: string) {
|
|
130
|
+
const viewOnly=options.viewOnly??inputs.viewOnly??false;
|
|
130
131
|
for(const path of [inputs.input,...(inputs.compare!==undefined?[inputs.compare]:[])])await assertOpenInput(path);
|
|
131
132
|
if(inputs.compare!==undefined&&!inputs.reference)throw new Error('OPEN_REFERENCE_REQUIRED: compare: explicit --reference required');
|
|
132
133
|
let p:OpenPackage;try{p=await loadOpenPackage(inputs);}catch(error){throw await openRefusal(error,inputs);}
|
|
133
|
-
|
|
134
|
+
fingerprint??=await openFingerprint();const key=openKey(p,fingerprint);
|
|
134
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.
|
|
135
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)];
|
|
136
137
|
if(p.mode==='single'&&p.joined&&stateDirInside(stateDir,[{kind:'package',path:p.joined.opened.root}]))throw new Error('OPEN_STATE_INSIDE_PACKAGE: review state must be outside the joined project');
|
|
137
138
|
const inside=stateDirInside(stateDir,roots);if(inside)throw new Error(`OPEN_STATE_INSIDE_PACKAGE ${inside.kind}: the review state directory must be outside input packages; it is inside the ${inside.kind}; set RIG_REVIEW_STATE_DIR outside it`);
|
|
138
139
|
await verifyOpenLoad(p,viewOnly,options.cwd);
|
|
140
|
+
const build=p.mode==='single'&&basename(p.p.root)==='check'&&await isBuildRoot(dirname(p.p.root))?{package:p.p.root,handoff:p.p.reviewedSource.handoff??null,reason:p.p.handoffReason}:null;
|
|
141
|
+
return {package:p,key,fingerprint,stateDir,viewOnly,cwd:resolve(options.cwd??process.cwd()),build};
|
|
142
|
+
}
|
|
143
|
+
export async function openReview(inputs:OpenInputs,options:OpenOptions={}):Promise<{url:string;reused:boolean;nonce:string;inputs:OpenInputs;selection:AnimationSelection|null;direct:boolean;build:BuildOpen|null}>{
|
|
144
|
+
const direct=options.direct??inputs.direct??false,port=direct?0:frontPort(options.frontPort);
|
|
145
|
+
const prepared=await prepareOpenTarget(inputs,options);
|
|
146
|
+
const {package:p,key,fingerprint,stateDir,viewOnly,build}=prepared;
|
|
139
147
|
const control=join(stateDir,'open');await mkdir(control,{recursive:true,mode:0o700});const canonicalControl=await realpath(control);if((await lstat(control)).isSymbolicLink())throw new Error('open.state: control directory cannot be a symlink');
|
|
140
148
|
const worker=await ensureWorker(p,key,fingerprint,stateDir,canonicalControl,options.idleMs??DEFAULT_UNOPENED_TIMEOUT_MS,options.graceMs,viewOnly,options.cwd);
|
|
141
149
|
const url=direct?openUrl(worker.row):openUrl(worker.row,await ensureFront({control:canonicalControl,port,fingerprint,idleMs:options.frontIdleMs}));
|
|
142
150
|
// #149: the check package of a rig-parts build root says which package it opened and which config the handoff took.
|
|
143
|
-
const build=p.mode==='single'&&basename(p.p.root)==='check'&&await isBuildRoot(dirname(p.p.root))?{package:p.p.root,handoff:p.p.reviewedSource.handoff??null,reason:p.p.handoffReason}:null;
|
|
144
151
|
return {url,reused:worker.reused,nonce:worker.row.nonce,inputs:p.inputs,selection:p.selection,direct,build};
|
|
145
152
|
}
|
|
146
153
|
async function ensureWorker(p:OpenPackage,key:string,fingerprint:string,stateDir:string,canonicalControl:string,idleMs:number,graceMs?:number,viewOnly=false,cwd=process.cwd()):Promise<{row:RecordFile;reused:boolean}>{
|
|
@@ -179,13 +186,19 @@ export async function controlReview(inputs:OpenInputs,commandOptions:{pageId?:st
|
|
|
179
186
|
const wait=commandOptions.waitMs??10000;if(!Number.isSafeInteger(wait)||wait<0||wait>30000)throw new Error('CONTROL_WAIT: expected integer 0..30000');
|
|
180
187
|
const p=await loadOpenPackage({...inputs,control:true}),fingerprint=await openFingerprint(),key=openKey(p,fingerprint);
|
|
181
188
|
const stateDir=destinationDirectory(commandOptions.stateDir??defaultStateDir(),'CONTROL_STATE: the state directory path has a non-directory component or a symlink loop');
|
|
189
|
+
const workspace=await (await import('./open-workspace-launch.ts')).workspaceControlLocator(stateDir,key);
|
|
190
|
+
let record:{origin:string;controlToken:string;capability:string},prefix='';
|
|
191
|
+
if(workspace){record=workspace;prefix=workspace.prefix;}
|
|
192
|
+
else {
|
|
182
193
|
const controlDir=join(stateDir,'open');
|
|
183
194
|
try{if((await lstat(controlDir)).isSymbolicLink())throw new Error('CONTROL_STATE: control directory cannot be a symlink');}catch(error){if((error as NodeJS.ErrnoException).code==='ENOENT')throw new Error('CONTROL_INSTANCE_UNAVAILABLE: open the exact inputs once with --control');throw error;}
|
|
184
195
|
const file=join(controlDir,key+'.json');try{const info=await lstat(file);if(!info.isFile()||(info.mode&0o077)!==0)throw new Error('CONTROL_STATE: owner-only regular capability record required');}catch(error){if((error as NodeJS.ErrnoException).code==='ENOENT')throw new Error('CONTROL_INSTANCE_UNAVAILABLE: open the exact inputs once with --control');throw error;}
|
|
185
|
-
const
|
|
186
|
-
if(!
|
|
196
|
+
const legacy=await readRecord(file,key);
|
|
197
|
+
if(!legacy||!legacy.controlToken||!await alive(legacy))throw new Error('CONTROL_INSTANCE_UNAVAILABLE: open the exact inputs once with --control');
|
|
198
|
+
record={origin:legacy.origin,controlToken:legacy.controlToken,capability:legacy.capability};
|
|
199
|
+
}
|
|
187
200
|
const headers={Authorization:'Bearer '+record.controlToken,Origin:record.origin,'Content-Type':'application/json',[capabilityHeader]:record.capability};
|
|
188
|
-
const get=async(path:string,body?:unknown)=>{const response=await fetch(record.origin+path,{method:body===undefined?'GET':'POST',headers,...(body===undefined?{}:{body:JSON.stringify(body)}),redirect:'error',signal:AbortSignal.timeout(5000)});const value=await readOpenStatus(response,5000);if(!response.ok)throw new Error((value as {error?:string}).error??'CONTROL_REQUEST_FAILED');return value;};
|
|
201
|
+
const get=async(path:string,body?:unknown)=>{const response=await fetch(record.origin+prefix+path,{method:body===undefined?'GET':'POST',headers,...(body===undefined?{}:{body:JSON.stringify(body)}),redirect:'error',signal:AbortSignal.timeout(5000)});const value=await readOpenStatus(response,5000);if(!response.ok)throw new Error((value as {error?:string}).error??'CONTROL_REQUEST_FAILED');return value;};
|
|
189
202
|
const state=await get('/api/control') as {sourceHash:string;instanceKey:string;pages:{pageId:string;revision:number}[]};
|
|
190
203
|
if(state.sourceHash!==p.contentHash||state.instanceKey!==key)throw new Error('CONTROL_STALE_BINDING');
|
|
191
204
|
if(!commandOptions.command)return state;
|
package/src/server.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { BONES_CHECK_LIMIT, createBonesCheck } from './bones-check.ts';
|
|
|
19
19
|
import { createRequirementsCheck } from './requirements-run.ts';
|
|
20
20
|
import { REQUIREMENTS_LIMIT, RequirementsError } from './requirements.ts';
|
|
21
21
|
import { createEnvironmentCheck, ENVIRONMENT_CHECK_LIMIT, EnvironmentCheckError } from './environment-check.ts';
|
|
22
|
-
import { createLiveLifecycle, LIVE_PATH, type LiveExitInfo, type UpgradableServer } from './live-lifecycle.ts';
|
|
22
|
+
import { createLiveLifecycle, LIVE_PATH, type LiveExitInfo, type LiveLifecycle, type UpgradableServer } from './live-lifecycle.ts';
|
|
23
23
|
import { homedir } from 'node:os';
|
|
24
24
|
import { join } from 'node:path';
|
|
25
25
|
const headers={ 'X-Content-Type-Options':'nosniff','Cache-Control':'no-store','Content-Security-Policy':"default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' blob: data:; media-src 'self'; frame-src 'self'; connect-src 'self'; font-src 'self'; base-uri 'none'; frame-ancestors 'none'; form-action 'none'",'Referrer-Policy':'no-referrer'};
|
|
@@ -35,13 +35,39 @@ async function bodyJson(req:Request,limit=1024*1024,what='Session payload exceed
|
|
|
35
35
|
}
|
|
36
36
|
/** `capability` (open workers and foreground CLI serving) gates every non-GET request; tests may omit it.
|
|
37
37
|
* `cwd` is where the producer is looked for after the package's own directories (review's working directory by default). */
|
|
38
|
-
export
|
|
38
|
+
export interface ReviewServerOptions {
|
|
39
|
+
port?: number;
|
|
40
|
+
stateDir?: string;
|
|
41
|
+
joined?: JoinedProject;
|
|
42
|
+
open?: OpenIdentity;
|
|
43
|
+
initialAnimation?: string;
|
|
44
|
+
activity?: () => void;
|
|
45
|
+
control?: ControlIdentity;
|
|
46
|
+
capability?: string;
|
|
47
|
+
cwd?: string;
|
|
48
|
+
stripConcurrency?: number;
|
|
49
|
+
graceMs?: number;
|
|
50
|
+
unopenedTimeoutMs?: number;
|
|
51
|
+
exitOnClose?: boolean;
|
|
52
|
+
onClose?: (info: LiveExitInfo) => void | Promise<void>;
|
|
53
|
+
log?: (line: string) => void;
|
|
54
|
+
viewOnly?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ReviewRequestContextOptions extends ReviewServerOptions {
|
|
58
|
+
lifecycle?: LiveLifecycle;
|
|
59
|
+
bundle?: Blob;
|
|
60
|
+
stopServer?: () => void | Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Package-scoped routes without a listener. An injected lifecycle belongs to its caller. */
|
|
64
|
+
export async function createReviewRequestContext(p: ReviewPackage, options: ReviewRequestContextOptions = {}) {
|
|
39
65
|
const joined = options.joined;
|
|
40
66
|
if (joined && !options.capability) throw new Error('Joined interview requires an instance capability');
|
|
41
67
|
const interview = joined && interviewRoutes(joined.opened.root, joined.designation.picksDir, options.capability!,
|
|
42
68
|
{...joined, sourceHash:p.sourceHash, version:joined.designation.version,draftId:joined.designation.draftId});
|
|
43
69
|
let interviewBundle: Promise<Blob> | undefined;
|
|
44
|
-
const bundle=await buildWeb();
|
|
70
|
+
const bundle=options.bundle??await buildWeb();
|
|
45
71
|
const unchanged=()=>assertReviewUnchanged(p);
|
|
46
72
|
const stateDir=options.stateDir??process.env.RIG_REVIEW_STATE_DIR??join(homedir(),'.local','state','rig-c-review'),starts=[p.root,options.cwd??process.cwd()];
|
|
47
73
|
const rebuilds=createRebuilds(p,{stateDir,starts,unchanged,bones:p.feedbackCatalog.bones,...(options.stripConcurrency?{stripConcurrency:options.stripConcurrency}:{}),...(options.viewOnly??p.viewOnly?{viewOnly:true}:{})});
|
|
@@ -60,16 +86,17 @@ export async function startServer(p:ReviewPackage,options:{port?:number;stateDir
|
|
|
60
86
|
// Check under this world (#112): the exported schedule written into scratch; the installed producer's check --environment reads it.
|
|
61
87
|
const environmentCheck=createEnvironmentCheck(p,{stateDir,starts,unchanged,latest:rebuilds.latest});
|
|
62
88
|
const control=options.control?createControlServer({identity:options.control,sourceHash:p.sourceHash,mode:'single',unchanged,activity:options.activity}):null;
|
|
63
|
-
|
|
64
|
-
const
|
|
89
|
+
const busy=()=>Boolean(rebuilds.busy()||readings.running()||requirements.running()||environmentCheck.running()||bonesCheck.running());
|
|
90
|
+
const ownsLifecycle=options.lifecycle===undefined;
|
|
91
|
+
const live=options.lifecycle??createLiveLifecycle({
|
|
65
92
|
label:'review',
|
|
66
93
|
graceMs:options.graceMs,
|
|
67
94
|
unopenedTimeoutMs:options.unopenedTimeoutMs,
|
|
68
95
|
exitOnClose:options.exitOnClose,
|
|
69
96
|
onClose:options.onClose,
|
|
70
97
|
log:options.log,
|
|
71
|
-
busy
|
|
72
|
-
stopServer:
|
|
98
|
+
busy,
|
|
99
|
+
stopServer:options.stopServer,
|
|
73
100
|
});
|
|
74
101
|
const handle=async(req:Request,port:number|undefined,srv:UpgradableServer):Promise<Response|undefined>=>{try {
|
|
75
102
|
const url=new URL(req.url);const origin=`http://127.0.0.1:${port}`;
|
|
@@ -225,8 +252,22 @@ export async function startServer(p:ReviewPackage,options:{port?:number;stateDir
|
|
|
225
252
|
return json({error:'Not found'},404);
|
|
226
253
|
} finally { live.onRequestEnd(url.pathname); }
|
|
227
254
|
}catch(e){const message=e instanceof Error?e.message:'Request failed';return json({error:message},message===directionStale || message.startsWith(interviewStale) || message.includes('inputs changed')?409:400);}};
|
|
228
|
-
|
|
255
|
+
return {
|
|
256
|
+
live,
|
|
257
|
+
busy,
|
|
258
|
+
async handle(req: Request, port: number | undefined, srv: UpgradableServer): Promise<Response | undefined> {
|
|
259
|
+
const response=await handle(req,port,srv);
|
|
260
|
+
return response?stampOpen(req,response,options.open):undefined;
|
|
261
|
+
},
|
|
262
|
+
stop() { if(ownsLifecycle)live.stop(); },
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export async function startServer(p: ReviewPackage, options: ReviewServerOptions = {}) {
|
|
267
|
+
let rawStop:((closeActiveConnections?:boolean)=>void)|null=null;
|
|
268
|
+
const context=await createReviewRequestContext(p,{...options,stopServer:()=>{rawStop?.(true);}});
|
|
269
|
+
const server=Bun.serve({hostname:'127.0.0.1',port:options.port??4317,websocket:context.live.websocket,async fetch(req,srv){return await context.handle(req,srv.port,srv) as Response;}});
|
|
229
270
|
rawStop=server.stop.bind(server);
|
|
230
|
-
server.stop=((closeActiveConnections?:boolean)=>{
|
|
231
|
-
return Object.assign(server,{live});
|
|
271
|
+
server.stop=((closeActiveConnections?:boolean)=>{context.stop();return rawStop!(closeActiveConnections);}) as typeof server.stop;
|
|
272
|
+
return Object.assign(server,{live:context.live});
|
|
232
273
|
}
|
package/web/catalog-en.ts
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
1
|
export const enCatalog: Readonly<Record<string, string>> = {
|
|
2
|
+
"WORKSPACE_BODY_TIMEOUT": "WORKSPACE_BODY_TIMEOUT",
|
|
3
|
+
"rig-review-target/1": "rig-review-target/1",
|
|
4
|
+
"Review workspace": "Review workspace",
|
|
5
|
+
"Review targets": "Review targets",
|
|
6
|
+
"Inspection only": "Inspection only",
|
|
7
|
+
"Review target": "Review target",
|
|
8
|
+
"Select a target. Drafts stay with their original source.": "Select a target. Drafts stay with their original source.",
|
|
9
|
+
"FRONT_QUERY_REFUSED": "FRONT_QUERY_REFUSED",
|
|
10
|
+
"Korean": "Korean",
|
|
11
|
+
"WORKSPACE_BODY_LIMIT": "WORKSPACE_BODY_LIMIT",
|
|
12
|
+
"WORKSPACE_BUSY": "WORKSPACE_BUSY",
|
|
13
|
+
"WORKSPACE_CAPABILITY_REQUIRED": "WORKSPACE_CAPABILITY_REQUIRED",
|
|
14
|
+
"WORKSPACE_CLOSING": "WORKSPACE_CLOSING",
|
|
15
|
+
"WORKSPACE_HOST_MISMATCH": "WORKSPACE_HOST_MISMATCH",
|
|
16
|
+
"WORKSPACE_HOST_UNRESPONSIVE": "WORKSPACE_HOST_UNRESPONSIVE",
|
|
17
|
+
"WORKSPACE_LOOPBACK_REQUIRED": "WORKSPACE_LOOPBACK_REQUIRED",
|
|
18
|
+
"WORKSPACE_OWNER_MISMATCH": "WORKSPACE_OWNER_MISMATCH",
|
|
19
|
+
"WORKSPACE_PORT_BUSY": "WORKSPACE_PORT_BUSY",
|
|
20
|
+
"WORKSPACE_REGISTRATION_REFUSED": "WORKSPACE_REGISTRATION_REFUSED",
|
|
21
|
+
"WORKSPACE_REQUEST_INVALID": "WORKSPACE_REQUEST_INVALID",
|
|
22
|
+
"WORKSPACE_REQUEST_REFUSED": "WORKSPACE_REQUEST_REFUSED",
|
|
23
|
+
"WORKSPACE_ROUTE_REFUSED": "WORKSPACE_ROUTE_REFUSED",
|
|
24
|
+
"WORKSPACE_SAME_ORIGIN_REQUIRED": "WORKSPACE_SAME_ORIGIN_REQUIRED",
|
|
25
|
+
"WORKSPACE_SOURCE_CHANGED": "WORKSPACE_SOURCE_CHANGED",
|
|
26
|
+
"WORKSPACE_START_BUSY": "WORKSPACE_START_BUSY",
|
|
27
|
+
"WORKSPACE_START_REFUSED": "WORKSPACE_START_REFUSED",
|
|
28
|
+
"WORKSPACE_START_TIMEOUT": "WORKSPACE_START_TIMEOUT",
|
|
29
|
+
"WORKSPACE_STATE_INVALID": "WORKSPACE_STATE_INVALID",
|
|
30
|
+
"WORKSPACE_TARGET_LIMIT": "WORKSPACE_TARGET_LIMIT",
|
|
31
|
+
"WORKSPACE_TARGET_OPTIONS_MISMATCH": "WORKSPACE_TARGET_OPTIONS_MISMATCH",
|
|
32
|
+
"WORKSPACE_TARGET_UNAVAILABLE": "WORKSPACE_TARGET_UNAVAILABLE",
|
|
33
|
+
"WORKSPACE_TARGET_UNKNOWN": "WORKSPACE_TARGET_UNKNOWN",
|
|
34
|
+
"rig-review-open-workspace/1": "rig-review-open-workspace/1",
|
|
35
|
+
"rig-review-open-targets/1": "rig-review-open-targets/1",
|
|
36
|
+
"rig-review-workspace-visibility/1": "rig-review-workspace-visibility/1",
|
|
37
|
+
"rig-review-workspace-ready/1": "rig-review-workspace-ready/1",
|
|
38
|
+
"rig-review-owner-workspace/1:": "rig-review-owner-workspace/1:",
|
|
2
39
|
"Producer check passed": "Producer check passed",
|
|
3
40
|
"Producer check failed": "Producer check failed",
|
|
4
41
|
"Producer check unavailable": "Producer check unavailable",
|
package/web/catalog-ko.ts
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
1
|
export const koCatalog: Readonly<Record<string, string>> = {
|
|
2
|
+
"WORKSPACE_BODY_TIMEOUT": "WORKSPACE_BODY_TIMEOUT",
|
|
3
|
+
"rig-review-target/1": "rig-review-target/1",
|
|
4
|
+
"Review workspace": "검토 작업 공간",
|
|
5
|
+
"Review targets": "검토 대상",
|
|
6
|
+
"Inspection only": "살펴보기 전용",
|
|
7
|
+
"Review target": "검토 대상",
|
|
8
|
+
"Select a target. Drafts stay with their original source.": "대상을 선택해. 초안은 원래 소스에 보관돼.",
|
|
9
|
+
"FRONT_QUERY_REFUSED": "FRONT_QUERY_REFUSED",
|
|
10
|
+
"Korean": "한국어",
|
|
11
|
+
"WORKSPACE_BODY_LIMIT": "WORKSPACE_BODY_LIMIT",
|
|
12
|
+
"WORKSPACE_BUSY": "WORKSPACE_BUSY",
|
|
13
|
+
"WORKSPACE_CAPABILITY_REQUIRED": "WORKSPACE_CAPABILITY_REQUIRED",
|
|
14
|
+
"WORKSPACE_CLOSING": "WORKSPACE_CLOSING",
|
|
15
|
+
"WORKSPACE_HOST_MISMATCH": "WORKSPACE_HOST_MISMATCH",
|
|
16
|
+
"WORKSPACE_HOST_UNRESPONSIVE": "WORKSPACE_HOST_UNRESPONSIVE",
|
|
17
|
+
"WORKSPACE_LOOPBACK_REQUIRED": "WORKSPACE_LOOPBACK_REQUIRED",
|
|
18
|
+
"WORKSPACE_OWNER_MISMATCH": "WORKSPACE_OWNER_MISMATCH",
|
|
19
|
+
"WORKSPACE_PORT_BUSY": "WORKSPACE_PORT_BUSY",
|
|
20
|
+
"WORKSPACE_REGISTRATION_REFUSED": "WORKSPACE_REGISTRATION_REFUSED",
|
|
21
|
+
"WORKSPACE_REQUEST_INVALID": "WORKSPACE_REQUEST_INVALID",
|
|
22
|
+
"WORKSPACE_REQUEST_REFUSED": "WORKSPACE_REQUEST_REFUSED",
|
|
23
|
+
"WORKSPACE_ROUTE_REFUSED": "WORKSPACE_ROUTE_REFUSED",
|
|
24
|
+
"WORKSPACE_SAME_ORIGIN_REQUIRED": "WORKSPACE_SAME_ORIGIN_REQUIRED",
|
|
25
|
+
"WORKSPACE_SOURCE_CHANGED": "WORKSPACE_SOURCE_CHANGED",
|
|
26
|
+
"WORKSPACE_START_BUSY": "WORKSPACE_START_BUSY",
|
|
27
|
+
"WORKSPACE_START_REFUSED": "WORKSPACE_START_REFUSED",
|
|
28
|
+
"WORKSPACE_START_TIMEOUT": "WORKSPACE_START_TIMEOUT",
|
|
29
|
+
"WORKSPACE_STATE_INVALID": "WORKSPACE_STATE_INVALID",
|
|
30
|
+
"WORKSPACE_TARGET_LIMIT": "WORKSPACE_TARGET_LIMIT",
|
|
31
|
+
"WORKSPACE_TARGET_OPTIONS_MISMATCH": "WORKSPACE_TARGET_OPTIONS_MISMATCH",
|
|
32
|
+
"WORKSPACE_TARGET_UNAVAILABLE": "WORKSPACE_TARGET_UNAVAILABLE",
|
|
33
|
+
"WORKSPACE_TARGET_UNKNOWN": "WORKSPACE_TARGET_UNKNOWN",
|
|
34
|
+
"rig-review-open-workspace/1": "rig-review-open-workspace/1",
|
|
35
|
+
"rig-review-open-targets/1": "rig-review-open-targets/1",
|
|
36
|
+
"rig-review-workspace-visibility/1": "rig-review-workspace-visibility/1",
|
|
37
|
+
"rig-review-workspace-ready/1": "rig-review-workspace-ready/1",
|
|
38
|
+
"rig-review-owner-workspace/1:": "rig-review-owner-workspace/1:",
|
|
2
39
|
"Producer check passed": "프로듀서 검사 통과",
|
|
3
40
|
"Producer check failed": "프로듀서 검사 실패",
|
|
4
41
|
"Producer check unavailable": "프로듀서 검사 결과 없음",
|
package/web/compare.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {bindStageNav} from './stage-nav.ts';
|
|
2
|
+
import {bindWorkspaceVisibility} from './workspace-visibility.ts';
|
|
2
3
|
import {requireFeedbackFrames} from '../src/stage-comment.ts';
|
|
3
4
|
import {bindStageComments,type CommentPose} from './stage-comments.ts';
|
|
4
5
|
import {sharedTurnDials,type TurnDial} from '../src/turn-pad.ts';
|
|
@@ -463,6 +464,7 @@ async function start(): Promise<void> {
|
|
|
463
464
|
input('scrub').disabled = false; input('time-input').disabled = false; button('seek').disabled = false; button('play').disabled = domain.end === 0;
|
|
464
465
|
await seekTo(0);configureTurnPad();workspace?.refresh();activeCamera='a';if(cameraSync)alignCameras();fit();for(const id of ['layer-images','layer-mesh','layer-bones'])input(id).disabled=false;renderIdle();const restored=await setupPersistence();setupComments();await pickedTools?.loadInitialSideStatuses();if(!restored&&canRepeatIdle())void playComparison().catch(error=>message(describe(error),true));
|
|
465
466
|
if(!readOnly&&controlServed)controlDispose=connectControl({sourceHash:data.sourceHash,mode:'compare',route:access.route,headers:()=>access.headers(),observe:controlState,apply:applyControl,onStatus:value=>text('control-state',value)});
|
|
467
|
+
bindWorkspaceVisibility({key:access.key,sourceHash:data.sourceHash,pause:()=>{idleHeld=true;stop();}});
|
|
466
468
|
} catch (error) { failPair(error); for (const side of ['a', 'b'] as const) if (!players[side]) text(`${side}-empty`, `${side.toUpperCase()} Could not open comparison rig.`); text('reference-empty', 'Check the reference video and comparison inputs.'); }
|
|
467
469
|
}
|
|
468
470
|
function sharedBox():PoseBounds|null {const a=assets.a?.stage??players.a?.bounds(),b=assets.b?.stage??players.b?.bounds();return a&&b?unionBounds(a,b):a??b??null;}
|
package/web/main.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {bindDirectionPanel} from './direction-panel.ts';
|
|
2
|
+
import {bindWorkspaceVisibility} from './workspace-visibility.ts';
|
|
2
3
|
import type {DirectionInspection} from '../src/direction-inspection.ts';
|
|
3
4
|
import {bindStageNav} from './stage-nav.ts';
|
|
4
5
|
import {timeOnlyBasis,feedbackTimingLabel,requireFeedbackFrames,isTimeOnlyFeedback} from '../src/stage-comment.ts';
|
|
@@ -1078,6 +1079,7 @@ async function start(): Promise<void> {
|
|
|
1078
1079
|
const restored=await setupPersistence();setupComments();await loadRebuildStatus();void loadRequirements();renderChest();restoreEnvironment();physicsPanel?.restore();bonesPanel?.restore();cutsPanel?.restore();clothPanel?.restore();idlePanel?.restore();rigFieldsPanel?.restore();meshPanel?.restore();void refreshDensityStrip();renderIdle();if(!restored&&canRepeatIdle()&&automaticIdlePreview(assets?.animations.map(item=>item.name)??[],animation,first,!!requestedId))void playPreview();
|
|
1079
1080
|
// Only an instance that serves agent control is asked for its config: a plain open has no control endpoint (#164).
|
|
1080
1081
|
if(!readOnly&&writes.control!==false)controlDispose=connectControl({sourceHash:data.sourceHash,mode:'single',route:access.route,headers:()=>access.headers(),observe:controlState,apply:applyControl,onStatus:value=>text('control-state',value)});
|
|
1082
|
+
bindWorkspaceVisibility({key:access.key,sourceHash:data.sourceHash,pause});
|
|
1081
1083
|
} catch (error) { message(`Could not open review package: ${errorText(error)}`, true); text('dirty', 'Load failed'); }
|
|
1082
1084
|
}
|
|
1083
1085
|
/** `feedback` is the review dialog, not an Inspector section: a user action opens it; a restored older bookmark that saved it selects nothing. */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
html, body, #owner-workspace { height: 100%; margin: 0; }
|
|
2
|
+
#owner-workspace { display: grid; grid-template: auto 1fr / minmax(12rem, 18rem) 1fr; color: var(--fg); background: var(--bg); }
|
|
3
|
+
.owner-header { grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
|
|
4
|
+
.owner-header h1 { margin: 0; font-size: 1rem; }
|
|
5
|
+
.owner-header select { width: auto; min-width: 6rem; max-width: 12rem; flex: 0 0 auto; }
|
|
6
|
+
.owner-status { flex: 1; color: var(--fg-muted); }
|
|
7
|
+
.owner-list { overflow: auto; border-right: 1px solid var(--border); padding: .5rem; }
|
|
8
|
+
.owner-list button { width: 100%; display: grid; gap: .25rem; margin-bottom: .5rem; padding: .75rem; text-align: left; }
|
|
9
|
+
.owner-list button[aria-pressed="true"] { border-color: var(--pass); }
|
|
10
|
+
.owner-target-title { overflow-wrap: anywhere; }
|
|
11
|
+
.owner-target-status, .owner-target-animation { color: var(--fg-muted); font-size: .8rem; }
|
|
12
|
+
.owner-stage { min-width: 0; min-height: 0; position: relative; }
|
|
13
|
+
.owner-stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
|
|
14
|
+
.owner-stage iframe[hidden] { display: block !important; visibility: hidden; pointer-events: none; }
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title></title><link rel="stylesheet" href="/styles.css"><link rel="stylesheet" href="/workspace.css"></head>
|
|
4
|
+
<body><div id="owner-workspace"></div><script type="module" src="/workspace.js"></script></body>
|
|
5
|
+
</html>
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {WORKSPACE_TARGET_LIMIT, WORKSPACE_READY_SCHEMA, WORKSPACE_SCHEMA, WORKSPACE_TARGET_DOMAIN, WORKSPACE_VISIBILITY_SCHEMA,
|
|
2
|
+
type WorkspaceList, type WorkspaceTargetView} from '../src/open-workspace-contract.ts';
|
|
3
|
+
import {getLanguage, onLanguageChange, setLanguagePreference, setLinkLanguage, tr} from './i18n.ts';
|
|
4
|
+
import {connectLiveWindow} from './live-connection.ts';
|
|
5
|
+
|
|
6
|
+
const root = document.getElementById('owner-workspace')!;
|
|
7
|
+
const header = document.createElement('header'); header.className = 'owner-header';
|
|
8
|
+
const heading = document.createElement('h1');
|
|
9
|
+
const status = document.createElement('p'); status.className = 'owner-status'; status.setAttribute('role', 'status');
|
|
10
|
+
const language = document.createElement('select');
|
|
11
|
+
for (const value of ['en', 'ko'] as const) {
|
|
12
|
+
const option = document.createElement('option'); option.value = value; language.append(option);
|
|
13
|
+
}
|
|
14
|
+
header.append(heading, status, language);
|
|
15
|
+
const list = document.createElement('nav'); list.className = 'owner-list';
|
|
16
|
+
const stage = document.createElement('main'); stage.className = 'owner-stage';
|
|
17
|
+
root.append(header, list, stage);
|
|
18
|
+
let current: WorkspaceList | null = null, selected: string | null = null, disposed = false;
|
|
19
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
20
|
+
const cancellation = new AbortController();
|
|
21
|
+
const frames = new Map<string, {frame: HTMLIFrameElement; target: WorkspaceTargetView}>();
|
|
22
|
+
const locationURL = new URL(location.href);
|
|
23
|
+
let capability = locationURL.hash.startsWith('#cap=') ? locationURL.hash.slice(5) : '';
|
|
24
|
+
const storageKey = 'rig-review-owner-workspace/1:' + location.origin;
|
|
25
|
+
if (!/^[a-f0-9]{64}$/.test(capability)) capability = '';
|
|
26
|
+
try {
|
|
27
|
+
if (capability) sessionStorage.setItem(storageKey, capability);
|
|
28
|
+
else capability = sessionStorage.getItem(storageKey) ?? '';
|
|
29
|
+
} catch {}
|
|
30
|
+
locationURL.hash = '';
|
|
31
|
+
history.replaceState(history.state, '', locationURL);
|
|
32
|
+
|
|
33
|
+
function text() {
|
|
34
|
+
document.documentElement.lang = getLanguage();
|
|
35
|
+
heading.textContent = tr('Review workspace'); document.title = tr('Review workspace');
|
|
36
|
+
list.setAttribute('aria-label', tr('Review targets'));
|
|
37
|
+
language.setAttribute('aria-label', tr('Language'));
|
|
38
|
+
language.options[0]!.textContent = tr('English'); language.options[1]!.textContent = tr('Korean');
|
|
39
|
+
language.value = getLanguage();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function visibility(entry: {frame: HTMLIFrameElement; target: WorkspaceTargetView}) {
|
|
43
|
+
entry.frame.contentWindow?.postMessage({schema: WORKSPACE_VISIBILITY_SCHEMA,
|
|
44
|
+
incarnation: current?.incarnation, key: entry.target.key, sourceHash: entry.target.contentHash,
|
|
45
|
+
visible: selected === entry.target.key, language: getLanguage()}, location.origin);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function grant(key: string) {
|
|
49
|
+
const encoder = new TextEncoder();
|
|
50
|
+
const secret = await crypto.subtle.importKey('raw', encoder.encode(capability), {name: 'HMAC', hash: 'SHA-256'}, false, ['sign']);
|
|
51
|
+
const bytes = await crypto.subtle.sign('HMAC', secret, encoder.encode(WORKSPACE_TARGET_DOMAIN + '\0' + current!.incarnation + '\0' + key));
|
|
52
|
+
return [...new Uint8Array(bytes)].map(value => value.toString(16).padStart(2, '0')).join('');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let selecting = 0;
|
|
56
|
+
async function select(target: WorkspaceTargetView) {
|
|
57
|
+
const intent = ++selecting;
|
|
58
|
+
if (target.unavailable) {status.textContent = tr(target.unavailable); return;}
|
|
59
|
+
let entry = frames.get(target.key);
|
|
60
|
+
if (!entry) {
|
|
61
|
+
if (frames.size >= WORKSPACE_TARGET_LIMIT) {status.textContent = tr('WORKSPACE_TARGET_LIMIT'); return;}
|
|
62
|
+
const token = await grant(target.key);
|
|
63
|
+
if (disposed || intent !== selecting) return;
|
|
64
|
+
const frame = document.createElement('iframe');
|
|
65
|
+
frame.title = target.title; frame.hidden = true;
|
|
66
|
+
frame.src = target.entry + '&lang=' + getLanguage() + '#cap=' + token;
|
|
67
|
+
entry = {frame, target}; frames.set(target.key, entry); stage.append(frame);
|
|
68
|
+
}
|
|
69
|
+
selected = target.key;
|
|
70
|
+
for (const mounted of frames.values()) {
|
|
71
|
+
visibility(mounted);
|
|
72
|
+
mounted.frame.hidden = mounted.target.key !== selected;
|
|
73
|
+
mounted.frame.inert = mounted.frame.hidden;
|
|
74
|
+
mounted.frame.setAttribute('aria-hidden', String(mounted.frame.hidden));
|
|
75
|
+
}
|
|
76
|
+
render();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function render() {
|
|
80
|
+
text(); list.replaceChildren();
|
|
81
|
+
for (const target of current?.targets ?? []) {
|
|
82
|
+
const button = document.createElement('button'); button.type = 'button';
|
|
83
|
+
button.dataset.targetKey = target.key; button.setAttribute('aria-pressed', String(target.key === selected));
|
|
84
|
+
const title = document.createElement('span'); title.className = 'owner-target-title'; title.textContent = target.title;
|
|
85
|
+
const state = document.createElement('span'); state.className = 'owner-target-status';
|
|
86
|
+
state.textContent = tr(target.unavailable ?? (target.viewOnly ? 'Inspection only' : 'Review target'));
|
|
87
|
+
const animation = document.createElement('span'); animation.className = 'owner-target-animation'; animation.textContent = target.animation;
|
|
88
|
+
button.append(title, state, animation); button.onclick = () => {void select(target).catch(() => {status.textContent = tr('WORKSPACE_REQUEST_REFUSED');});};
|
|
89
|
+
list.append(button);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function refresh() {
|
|
94
|
+
try {
|
|
95
|
+
if (!capability) {status.textContent = tr('WORKSPACE_CAPABILITY_REQUIRED'); return;}
|
|
96
|
+
const response = await fetch('/workspace/api/targets', {
|
|
97
|
+
headers: {'X-Review-Capability': capability}, signal: AbortSignal.any([cancellation.signal, AbortSignal.timeout(5000)]),
|
|
98
|
+
});
|
|
99
|
+
const value = await response.json() as WorkspaceList & {error?: string};
|
|
100
|
+
if (!response.ok) {status.textContent = tr(value.error ?? 'WORKSPACE_REQUEST_REFUSED'); return;}
|
|
101
|
+
if (value.schema !== WORKSPACE_SCHEMA || !Array.isArray(value.targets) || value.targets.length > WORKSPACE_TARGET_LIMIT ||
|
|
102
|
+
current && current.incarnation !== value.incarnation) {status.textContent = tr('WORKSPACE_HOST_MISMATCH'); return;}
|
|
103
|
+
const changed = JSON.stringify(value) !== JSON.stringify(current);
|
|
104
|
+
if (!current) status.textContent = tr('Select a target. Drafts stay with their original source.');
|
|
105
|
+
current = value;
|
|
106
|
+
if (changed) render();
|
|
107
|
+
if (!selected && value.targets[0]) await select(value.targets[0]);
|
|
108
|
+
} catch {if (!disposed) status.textContent = tr('WORKSPACE_REQUEST_REFUSED');}
|
|
109
|
+
finally {if (!disposed) timer = setTimeout(() => {void refresh();}, 1000);}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
window.addEventListener('message', event => {
|
|
113
|
+
if (event.origin !== location.origin || !current || !event.data || typeof event.data !== 'object') return;
|
|
114
|
+
const value = event.data;
|
|
115
|
+
if (value.schema !== WORKSPACE_READY_SCHEMA || value.incarnation !== current.incarnation) return;
|
|
116
|
+
const entry = frames.get(value.key);
|
|
117
|
+
if (entry && entry.frame.contentWindow === event.source && entry.target.contentHash === value.sourceHash) visibility(entry);
|
|
118
|
+
});
|
|
119
|
+
language.onchange = () => {setLinkLanguage(null); setLanguagePreference(language.value === 'ko' ? 'ko' : 'en');};
|
|
120
|
+
onLanguageChange(() => {render(); for (const entry of frames.values()) visibility(entry);});
|
|
121
|
+
const disconnect = connectLiveWindow({route: () => '/workspace/live'});
|
|
122
|
+
window.addEventListener('pagehide', () => {disposed = true; clearTimeout(timer); cancellation.abort(); disconnect();}, {once: true});
|
|
123
|
+
text();
|
|
124
|
+
void refresh();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {WORKSPACE_READY_SCHEMA, WORKSPACE_VISIBILITY_SCHEMA} from '../src/open-workspace-contract.ts';
|
|
2
|
+
import {setLanguagePreference, setLinkLanguage} from './i18n.ts';
|
|
3
|
+
|
|
4
|
+
/** Same-origin shipped frames still validate the exact parent and displayed source. */
|
|
5
|
+
export function bindWorkspaceVisibility(binding: {key: string; sourceHash: string; pause(): void}) {
|
|
6
|
+
const incarnation = new URL(location.href).searchParams.get('workspace');
|
|
7
|
+
if (parent === window || !incarnation) return;
|
|
8
|
+
const receive = (event: MessageEvent) => {
|
|
9
|
+
if (event.origin !== location.origin || event.source !== parent || !event.data || typeof event.data !== 'object') return;
|
|
10
|
+
const value = event.data;
|
|
11
|
+
if (value.schema !== WORKSPACE_VISIBILITY_SCHEMA || value.incarnation !== incarnation ||
|
|
12
|
+
value.key !== binding.key || value.sourceHash !== binding.sourceHash || typeof value.visible !== 'boolean') return;
|
|
13
|
+
if (!value.visible) binding.pause();
|
|
14
|
+
if (value.language === 'en' || value.language === 'ko') {
|
|
15
|
+
setLinkLanguage(null); setLanguagePreference(value.language);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
window.addEventListener('message', receive);
|
|
19
|
+
window.addEventListener('pagehide', () => window.removeEventListener('message', receive), {once: true});
|
|
20
|
+
parent.postMessage({schema: WORKSPACE_READY_SCHEMA, incarnation, key: binding.key, sourceHash: binding.sourceHash}, location.origin);
|
|
21
|
+
}
|