File size: 99,939 Bytes
9cef56d
 
 
 
 
 
4adcba2
d6619c7
 
 
 
79d68ff
6c1f8bc
b844444
 
 
 
 
 
 
 
 
 
 
 
 
 
54e4235
 
b844444
 
 
 
 
 
 
 
 
 
 
335bd62
b844444
 
 
 
335bd62
 
 
 
c642262
335bd62
54e4235
335bd62
 
 
 
 
54e4235
 
 
 
 
335bd62
 
b844444
 
 
 
 
 
 
 
 
335bd62
b844444
 
 
 
 
 
 
 
 
 
 
9cef56d
b844444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335bd62
b844444
 
 
335bd62
b844444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54e4235
b844444
aff3034
 
 
 
335bd62
aff3034
 
335bd62
aff3034
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b844444
335bd62
b844444
 
 
 
 
 
 
aff3034
 
b844444
 
aff3034
b844444
 
 
 
 
 
42ad6ab
b844444
 
42ad6ab
d846d5c
ccaf22c
b844444
 
 
 
 
 
 
 
 
335bd62
b844444
 
 
 
 
 
 
 
 
 
 
 
9cef56d
b844444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9fec14a
b844444
 
 
 
 
 
 
6c1f8bc
b844444
 
 
 
 
 
9fec14a
b844444
 
 
 
 
 
 
 
 
 
 
 
 
667cd2a
b844444
 
4adcba2
b844444
 
 
 
 
 
 
 
 
 
42ad6ab
b844444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555be04
b844444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aff3034
 
 
 
 
 
 
 
 
 
 
 
b844444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42ad6ab
 
 
b844444
 
 
 
 
 
 
 
 
 
 
 
9cef56d
 
b844444
9fec14a
b844444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
let agentVersions = {sources: {}};
function recordedAgentVersion(ep) {
  const source = Object.entries(agentVersions.sources).find(([path]) => ep.links?.provenance?.endsWith('/' + path));
  return source?.[1]?.[ep.variant] || (ep.harness === 'kinex' ? source?.[1]?.kinex : null);
}
function agentVersion(ep) {
  return recordedAgentVersion(ep)?.label || (ep.kinex_version ? 'Kinex v' + ep.kinex_version : ep.codex_version ? 'Codex ' + ep.codex_version : ep.claude_code_version ? 'Claude Code ' + ep.claude_code_version : 'Version not recorded');
}
function plusSeedNote(task,variant,ep) {
 const selection=variant==='kinex'?(ep?.measured_protocol?.seed_selection||task.planned_protocol_by_variant?.kinex?.seed_selection):null;
 if(!selection)return '';
 return `<aside class="native-note" data-plus-seed-note><span class="note-symbol">i</span><div><strong>Plus-only initialization seed: ${number(selection.selected_seed)}</strong><p>Authored seed 0 could not initialize this Plus task/configuration. Examined seeds: ${selection.examined_seeds.map(number).join(', ')}. The first initializable seed was selected before model use, without expert-success filtering. One formal episode ${ep?'was evaluated':'is scheduled'}. Easy and Hard keep their established seeds, including previously validated seed 0.</p><div class="inline-links">${external(selection.evidence,'Seed selection and preflight evidence')}</div></div></aside>`;
}
'use strict';
const plannedProtocol = (task, variant) => task.planned_protocol_by_variant?.[variant] || task.planned_protocol;
// RoboEnv LIBERO raw counters include five initialization frames; RoboBridge counters do not.
const actionSteps = (value, task, variant=task?.variant || current.variant || filters.variant) => Number.isFinite(value) ? Math.max(0, value - (task?.initialization_control_steps ?? task?.planned_protocol_by_variant?.[variant]?.initialization_control_steps ?? 0)) : null;
const currentBudget = task => data.budget_defaults?.tasks?.[task.native_id]?.action_step_limit ?? null;
const budgetNote = task => `<p class="subtle" data-budget-note>${currentBudget(task)==null?'':`Current benchmark default: ${number(currentBudget(task))} action steps. `}${task.family==='task02'?'RoboEnv and rosbridge displays exclude five initialization steps; RoboBridge directly counts agent actions. ':''}Recorded episodes and campaign plans retain their original budgets.</p>`;
const $ = s => document.querySelector(s);
const $$ = s => [...document.querySelectorAll(s)];
const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const number = v => v == null ? '—' : Number(v).toLocaleString('en-US');
const compact = v => v == null ? '—' : Math.abs(v) >= 1e9 ? (v/1e9).toFixed(2)+'B' : Math.abs(v) >= 1e6 ? (v/1e6).toFixed(2)+'M' : Math.abs(v) >= 1e3 ? (v/1e3).toFixed(1)+'K' : Math.round(v).toString();
const pct = v => v == null ? '—' : (v*100).toFixed(1)+'%';
const elapsed = v => v == null ? '—' : v >= 3600 ? (v/3600).toFixed(1)+' h' : v >= 60 ? (v/60).toFixed(1)+' min' : v.toFixed(1)+' s';
const arrow = '<span aria-hidden="true">↗</span>';
// Text-target Clean 50k presentation.
const colors = {'kinex-vlact50k-input-required-text':'#7a6940','kinex-vlact50k-autonomous':'#4674a3','kinex-vlact50k-input-required':'#a96682','kinex-vla-input-required':'#b35349','kinex-vla-autonomous':'#367d96','kinex-vla-input-guided':'#96703b','standalone-oft-all140k':'#547a36','standalone-vlact-clean':'#a75f7f','standalone-vlact-all':'#bd733b','standalone-official':'#39819c','standalone':'#39819c','kinex_policy':'#756ee4','kinex':'#27847a','codex-astra-spectator':'#a76a34','codex-astra':'#39819c','kinex-astra':'#756ee4','cc-opus':'#b48566','kinex-opus':'#958bc8','cc-opus-vertex-high':'#c9875a','cc-opus-vertex-xhigh':'#8c5a3a','kinex-opus-vertex-high':'#5b8bd8','kinex-opus-vertex-xhigh':'#3a5ba6','cc-opus-vertex-high-run2':'#e0a37a','cc-opus-vertex-xhigh-run2':'#a8704a','kinex-opus-vertex-high-run2':'#86aae6','kinex-opus-vertex-xhigh-run2':'#5876c0'};
let data, epoch = 0, current = {}, matrixMetric = 'success';
let filters = {query:'',family:'',status:'',variant:'standalone-vlact-clean',sort:'catalog'};
let sessionState = {filter:'all',query:'',count:40,view:'timeline'};
let imageItems = [], imageIndex = 0;
const sessionCache = new Map(), fileCache = new Map();
const episodes = (variant, family) => data.episodes.filter(e => (!variant || e.variant===variant) && (!family || e.family===family));
const reviewFor = (key, variant) => (data.runtime_reviews||[]).find(r => r.task_key===key && r.variant===variant);
const epFor = (key, variant) => data.episodes.find(e => e.task_key===key && e.variant===variant);
const plannedTasks = variant => data.tasks.filter(t => !variant || t.planned_variants.includes(variant));
const variantFor = id => data.variants.find(v => v.id===id);
const familyName = id => data.families.find(f => f.id===id)?.name || id;
const variantName = id => {const v=variantFor(id);return v ? `${methodLabel(v)} + ${v.model}` : id;};
const taskRoute = (key, variant='kinex', section='overview') => `#task/${key}/${variant}${section==='overview' ? '' : '/'+section}`;
const outcome = e => !e ? 'pending' : e.valid===false ? 'invalid' : typeof e.success!=='boolean' ? 'unreported' : e.success ? 'pass' : 'fail';
const badge = (e, link) => {if(!e&&link){const p=link.split('/'),t=data.tasks.find(t=>t.key===p.slice(1,3).join('/'));if(t&&!t.planned_variants.includes(p[3]))return '<span class="muted">Not scheduled</span>';}if(!e&&link){const p=link.split('/');if(reviewFor(p.slice(1,3).join('/'),p[3]))return `<a class="badge invalid" href="${esc(link)}">Under review</a>`;}const s=outcome(e),tag=link?'a':'span';return `<${tag} class="badge ${s}" ${link ? `href="${esc(link)}"` : ''}><span class="status-dot"></span>${s==='pending'?((data.active_campaign?.initialization_blocked||[]).includes((link||'').split('/').slice(1,4).join('/'))?'Blocked':'Pending'):s==='invalid'?'Invalid':s==='unreported'?'Unreported':s==='pass'?'Pass':'Fail'}</${tag}>`;};
const external = (url,label,cls='') => typeof url==='string' && /^(https?:|[a-zA-Z0-9_.-]+\/|[a-zA-Z0-9_.-]+\.json)/.test(url) ? `<a class="${cls}" href="${esc(evidenceURL(url))}" target="_blank" rel="noopener">${esc(label)} ${arrow}</a>` : '';
// Explicit checkpoint and protocol labels.
const methodLabel = v => ({
  'kinex-vla-autonomous':'Kinex + Qwen3-VL-OFT · All 140k (autonomous)',
  'kinex-vla-input-guided':'Kinex + Qwen3-VL-OFT · All 140k (input-guided)',
  'kinex-vla-input-required':'Kinex + Qwen3-VL-OFT · All 140k (input-required · text targets)'
}[v.id] || v.label || v.agent);
const protocolLabel = v => v.id==='kinex-vlact50k-input-required-text' ? 'Protocol: input-required · text-targets-v1' : v.id==='kinex-vlact50k-input-required' ? 'Protocol: input-required · numeric-target-text-v1' : v.id==='kinex-vlact50k-autonomous' ? 'Protocol: autonomous · verbatim-text-v1' : v.id==='kinex-vla-input-required' ? 'Protocol: five JSON fields · nullable targets' : '';
function checkpointDetails(v) {
  if(!v.checkpoint_repo)return '';
  return `<aside class="native-note" data-checkpoint-card><span class="note-symbol">i</span><div><strong>VLAct Clean 50k · ${esc(v.agent_protocol)}</strong><p>${esc(v.checkpoint_repo)} · step ${number(v.checkpoint_step)} · ${esc(v.training_distribution)}. Agent: GPT-6 Astra / high.</p><p>${esc(protocolLabel(v))}. VLA invocation remains optional.</p><div class="inline-links">${external(v.model_card,'Model card & protocol')}${external(v.checkpoint,'Pinned checkpoint & hashes')}</div></div></aside>`;
}
function vlactCampaignProgress() {
  const c=data.active_campaign;if(!c)return '';
  const textTargets=c.input_contract==='text-targets-v1';
  const report=textTargets?'text-target-hard50-20261106':'numeric-target-hard50-20261106';
  const scope=textTargets?'input-required · text targets':'autonomous and input-required · numeric targets';
  return `<aside class="native-note" data-vlact-progress><span class="note-symbol">i</span><div><strong>Kinex + VLAct Qwen3-VL-OFT · Clean 50k · ${c.closed?'Complete':'Partial results'}</strong><p>${c.published_episodes} / ${c.planned_episodes} audited episodes published: ${scope}. Pending tasks are excluded from success-rate denominators.</p><div class="inline-links">${external('research/'+report+'/MODEL_CARD.md','Model card & checkpoint')}${external('research/'+report+'/REPORT.md','Results & protocols')}</div></div></aside>`;
}

const modelLabel = v => `${v.model} <span class="separator">/</span> ${v.effort} <span class="separator">/</span> ${esc(v.provider)}`;
const icon = v => `<img class="agent-logo" src="assets/${v.agent==='Kinex'?'kinex':'vla'}-logo.svg" alt="" width="23" height="23">`;
function stats(es) {
  return UsageMetrics.stats(es);
}
window.benchmarkStats = stats;
const tokens = e => e && Number.isFinite(e.usage?.input_tokens) && Number.isFinite(e.usage?.output_tokens) ? e.usage.input_tokens+e.usage.output_tokens : null;
function metric(value,label,detail='',attrs='') {return `<div class="metric" ${attrs}><span class="metric-label">${label}</span><strong>${value}</strong>${detail?`<small>${detail}</small>`:''}</div>`;}
function variantTabs(selected,taskKey,section) {
  return `<div class="variant-tabs" aria-label="Choose agent and model">${data.variants.filter(v=>!taskKey||data.tasks.find(t=>t.key===taskKey)?.planned_variants.includes(v.id)).map(v=>`<a class="variant-tab ${v.id===selected?'active':''}" style="--variant:${colors[v.id]}" href="${taskKey?taskRoute(taskKey,v.id,epFor(taskKey,v.id)?section:'overview'):'#runs/'+v.id}" ${v.id===selected?'aria-current="page"':''}><span class="tab-agent">${icon(v)}<strong>${esc(methodLabel(v))}</strong>${taskKey?badge(epFor(taskKey,v.id)):''}</span><span class="tab-model">${modelLabel(v)}</span></a>`).join('')}</div>`;
}

const rangeNumber = (lo,hi,formatter=compact) => UsageMetrics.bounds(lo,hi,formatter);
const costValue = s => UsageMetrics.bounds(s.costLow,s.costHigh,UsageMetrics.money);
const exactMoney = v => v == null ? '—' : '$'+v.toLocaleString('en-US',{minimumFractionDigits:6,maximumFractionDigits:6});
const costNote = s => !s.n ? 'Not evaluated' : s.costCount!==s.n ? `Pricing available for ${s.costCount} / ${s.n} episodes` : s.conditional ? 'Estimated · 5m cache-write basis' : 'Estimated · recorded session rates';
function taskResult(ep, link) {
  const s=stats(ep?[ep]:[]), cost=costValue(s);
  return `<span class="task-result">${badge(ep,link)}<span class="task-cost" title="${esc(costNote(s))} · USD" aria-label="Estimated cost: ${esc(cost)} USD">${cost}</span></span>`;
}
function usageTiles(s,includeCost=true) {
  return `<div class="usage-metrics">${metric(compact(s.fresh),'Fresh input','',`title="${number(s.fresh)}"`)}${metric(rangeNumber(s.cacheLow,s.cacheHigh),'Cache read','',`title="${rangeNumber(s.cacheLow,s.cacheHigh,number)}"`)}${metric(compact(s.cacheWrite),'Cache write','',`title="${number(s.cacheWrite)}"`)}${metric(compact(s.output),'Output')}${metric(rangeNumber(s.cacheRateLow,s.cacheRateHigh,pct),'Cache hit rate')}${includeCost?metric(costValue(s),'Estimated cost'):''}</div>`;
}
function modelGroups() {
  const groups=new Map();
  for (const v of data.variants) {
    const key=v.model+' / '+v.effort;
    if(!groups.has(key))groups.set(key,{key,model:v.model,effort:v.effort,variants:[]});
    groups.get(key).variants.push(v);
  }
  return [{key:'baselines',model:'RoboTwin 2.0 Hard',effort:'Selected seeds',variants:data.variants}];
}
let expandedModels=null;
function perTaskStats(s) {
  const average = value => s.n > 0 && Number.isFinite(value) ? value / s.n : null;
  const result = {...s, perTask: true};
  for (const key of ['inclusive','fresh','cacheWrite','input','cached','output','inputLow','inputHigh','cacheLow','cacheHigh','reasoning','costLow','costHigh','knownCost']) result[key] = average(s[key]);
  result.buckets = s.buckets.map(b => ({...b, tokens: average(b.tokens), lower: average(b.lower), upper: average(b.upper)}));
  return result;
}
function comparisonCell(v,f) {
  if(!plannedTasks(v.id).some(t=>t.family===f.id))return '<td><span class="muted">Not scheduled</span></td>';
  const s=stats(episodes(v.id,f.id)),mean=perTaskStats(s),link=`#runs/${v.id}?family=${f.id}`;
  let value;
  if(matrixMetric==='success')value=`<div class="comparison-value"><strong>${pct(s.rate)}</strong><span>${s.n?s.passes+' / '+s.n+' passed':'Not evaluated'}</span></div><div class="mini-track"><span style="width:${(s.rate||0)*100}%;background:${colors[v.id]}"></span></div>`;
  else if(matrixMetric==='tokens')value=`<dl class="comparison-usage"><div><dt>Fresh input / task</dt><dd title="${number(mean.fresh)} tokens / task">${compact(mean.fresh)}</dd></div><div><dt>Cache write / task</dt><dd title="${number(mean.cacheWrite)} tokens / task">${compact(mean.cacheWrite)}</dd></div><div><dt>Cache read / task</dt><dd title="${rangeNumber(mean.cacheLow,mean.cacheHigh,number)} tokens / task">${rangeNumber(mean.cacheLow,mean.cacheHigh)}</dd></div><div><dt>Cache hit</dt><dd>${rangeNumber(s.cacheRateLow,s.cacheRateHigh,pct)}</dd></div><div><dt>Output / task</dt><dd title="${number(mean.output)} tokens / task">${compact(mean.output)}</dd></div></dl>`;
  else value=`<div class="comparison-value"><strong>${costValue(mean)}</strong><span>USD / task · ${costNote(s)}</span></div>`;
  return `<td data-harness="${esc(methodLabel(v))}" style="--variant:${colors[v.id]}">${value}<a class="comparison-explore" href="${link}">${s.n} evaluated · ${plannedTasks(v.id).filter(t=>t.family===f.id).length-s.n} pending ${arrow}</a></td>`;
}

function comparisonTable() {
  return `<section class="comparison-panel" aria-labelledby="comparison-title"><div class="section-heading bare"><div><h2 id="comparison-title">Compare methods</h2></div><div class="segmented" aria-label="Comparison metric">${[['success','Success rate'],['tokens','Tokens / task'],['cost','Cost / task']].map(([k,l])=>`<button data-matrix="${k}" aria-pressed="${matrixMetric===k}">${l}</button>`).join('')}</div></div><div class="model-comparisons">${modelGroups().map((g,i)=>`<details class="model-comparison panel" data-model-group="${esc(g.key)}" ${expandedModels?expandedModels.has(g.key)?'open':'':i===0?'open':''}><summary><span><strong>${esc(g.model)}</strong><span class="model-group-meta">${g.key==='baselines'?'One episode per task':esc(g.effort)+' effort'}</span></span><span class="model-group-count">${g.variants.length} variants <span class="disclosure-arrow">⌄</span></span></summary><div class="table-scroll"><table class="comparison-table grouped-comparison ${matrixMetric}"><thead><tr><th>Environment</th>${g.variants.map(v=>`<th><a href="#runs/${v.id}" class="agent-inline">${icon(v)}${esc(methodLabel(v))} ${arrow}</a><small>${modelLabel(v)}</small></th>`).join('')}</tr></thead><tbody>${data.families.map(f=>`<tr><th scope="row"><span class="family-code">${f.id.slice(-2)}</span>${esc(f.name)}<small>${f.tasks} tasks</small></th>${g.variants.map(v=>comparisonCell(v,f)).join('')}</tr>`).join('')}</tbody></table></div></details>`).join('')}</div></section>`;
}
function recordingPilotProgress(){
 const p=data.recording_pilot;if(!p)return '';
 return `<section class="panel" style="padding:18px 24px;margin-bottom:24px" data-recording-pilot><strong>Codex + RoboBridge · GPT-6 Astra / high · GPU recording pilot</strong><p>${number(p.completed)} / ${number(p.planned)} independent attempts published: LIBERO, RoboTwin, and two RoboDojo recording conditions. This pilot does not cover the full benchmark.</p><p>LIBERO and RoboTwin use independent 720-high spectator cameras. RoboDojo compares native camera recording with online HD recording. Both keep native agent camera resolution, but the RTX control test found that extra HD cameras change subsequent native image pixels. The HD control is shown separately.</p><p>Videos play at 4× simulation speed. Session galleries contain images actually submitted to the agent. One model episode per condition cannot establish a success-rate effect.</p><div class="inline-links"><a href="#runs/codex-astra">Three simulator results ↗</a><a href="#task/task04/01/codex-astra-spectator">RoboDojo HD control ↗</a>${external(p.details_url||p.report_url,'GPU recording validation')}</div></section>`;
}
function recordingComparisonNote(ep){
 if(!ep.recording_comparison)return '';
 const hd=ep.recording_mode==='spectator';
 return `<aside class="native-note" data-recording-comparison><span class="note-symbol">i</span><div><strong>Recording comparison · ${hd?'Online HD cameras':'Native camera frames'}</strong><p>${hd?'The agent receives native-resolution images. GPU controls show that extra HD cameras affect subsequent native RGB pixels through the shared renderer. Spectator images are for the human video only.':'The video uses cached native camera frames. No extra camera or rendering pass is added for recording.'}</p><p>Same task, seed 0, model, effort, prompt, budget and owner image; one fresh model attempt per condition. Model sampling also varies, so trajectory differences alone do not establish causality.</p>${ep.collector_review?`<p>Original Harbor collection failed because of a nested Docker log-path mismatch. The unchanged session, usage, sealed evidence and native failure were recovered; the original collection exception is retained. ${external(ep.links.collector_review,'Collection recovery receipt')}</p>`:''}${ep.encoding_review?`<p>The original 300-second encoding deadline expired after four of six videos. This presentation uses all sealed source frames re-encoded offline with a 600-second deadline; there was no model or simulator retry. ${external(ep.links.encoding_recovery,'Encoding recovery receipt')}</p>`:''}<a href="${taskRoute(ep.task_key,hd?'codex-astra':'codex-astra-spectator')}">View the other recording condition ↗</a>${external(data.recording_pilot.details_url||data.recording_pilot.report_url,'Measured image differences and behavior review')}</div></aside>`;
}

function opusPilotProgress(){
 const c=data.pilot_campaigns?.['cc-opus'];if(!c)return '';const n=c.counts||{};
 return `<section class="panel" style="padding:18px 24px;margin-bottom:24px" aria-label="Claude Code campaign"><strong>Claude Code · Opus 5.5 / high</strong><p>${number(n.finished||0)} / ${number(c.planned_episodes)} episodes completed · ${number(n.running||0)} running · ${number(n.queued||0)} pending${n.needs_review?' · '+number(n.needs_review)+' under review':''}${n.interrupted?' · '+number(n.interrupted)+' interrupted':''}.</p><p class="source-note">${c.quota_waiting?'Waiting for model-service quota recovery · ':''}${number(c.published_episodes)} episode records published · <a href="${esc(c.status_url)}" target="_blank" rel="noopener">Results and protocol ↗</a></p></section>`;
}
function methodology() {
 return `<details class="panel methodology" id="methodology"><summary><span><span class="eyebrow">Reading the Hard benchmark</span><strong>Protocol, metrics & provenance</strong></span><span class="summary-plus">+</span></summary><div class="method-grid"><div><h3>Full-suite comparison and input-guided pilot</h3><p>RoboTwin 2.0 Hard, ALOHA AgileX, demo_randomized. The five original conditions cover 50 tasks each. Earlier All 140k autonomous and input-required results cover 50 RLE tasks, retaining their first ten results. The VLAct Clean 50k comparison adds 100 fresh episodes: 50 tasks in each of its two protocols. Input-guided retains its first 10 RLE tasks. Completion and denominators are shown separately. Successes and valid failures are both retained; no completed, protocol-valid agent outcome was retried. This is RoboTwin 2.0 Hard, not RoboTwin 2.0-Plus.</p></div><div><h3>Instruction protocols</h3><p>Pure Kinex and all Kinex + VLA conditions use the revised RLE Hard templates and public scene bindings. VLA checkpoints and archived Kinex results retain original upstream unseen instructions. Each episode records the exact measured instruction and its authorship policy.</p></div><div><h3>Checkpoint identity</h3><p>Base 40k: StarVLA/Qwen3-VL-OFT-Robotwin2. VLAct Clean 50k: StarVLA/VLAct_Qwen3OFT_Robotwin_Finetune. VLAct All 100k: StarVLA/VLAct_Qwen3OFT_Robotwin_all_Finetune. Non-VLAct All 140k: StarVLA/Qwen3-VL-OFT-RoboTwin2-All, trained on 27,500 clean and randomized demonstrations. Full revisions and weight checksums are linked below. Pure Kinex uses GPT-6 Astra / high. The three earlier Kinex + VLA protocols use All 140k. The new autonomous and input-required conditions use VLAct Clean 50k, with 50 fresh Hard episodes per condition, 32-action chunks and the released wrap decoder. In the retained All 140k study, autonomous left input selection unguided, input-guided added optional context suggestions, and input-required used five JSON fields with nullable targets. The new VLAct Clean 50k autonomous condition leaves caller text unconstrained. Its input-required condition uses numeric-target-text-v1: instruction and one or two numerical TCP/joint targets, with optional feedback. Targets include an observation timestamp, source and uncertainty; desired joint targets may be derived by IK. Null or qualitative targets are rejected. Validation checks syntax, not grounding, reachability or learned compliance. The full JSON enters the frozen model as language text without a trained numerical encoder. Both modes leave VLA invocation and action execution to Kinex; zero VLA calls are valid. These are distinct protocols, and historical records retain their original descriptions.</p></div><div><h3>Execution and seeds</h3><p>Standalone VLA uses official expert admission from scene seed 100000 and official take_action with full predicted chunks. Current pure Kinex uses rosbridge at 25 Hz and the authored RLE manifest seeds and overrides, frozen before model use. No seed substitution or expert-success filtering is performed during this campaign. Seeds, admission rules and physical durations are not matched across the interfaces; this is not a paired causal comparison. Per-episode seeds and budgets are retained. In the superseded protocol study, two preliminary guided attempts were native successes but are excluded because a profile serialization defect corrupted their interface; their diagnostics are retained in the protocol report. Two further attempts were interrupted by provider quota exhaustion (HTTP 429) and restarted with unchanged seeds and budgets after quota recovery; both interruption records are preserved. The Kinex + VLA protocols share RLE instructions, authored seeds, budgets and the nominal 60 ms data clock resampled to 40 ms controls; prefixes and other control choices belong to the agent. Historical standalone results use native TOPP and are not an execution-matched baseline for this comparison.</p></div><div><h3>Initialization provenance</h3><p>Five infrastructure startup attempts produced no completed model response and are excluded from the original 200 valid outcomes. For hanging_mug, a minimal runtime repair retains native language bindings if the expert path fails before finishing. Selected seed 0, task physics and the native verifier are preserved.</p></div><div><h3>Usage and costs</h3><p>Estimated API-equivalent costs use recorded Pi session values. Actual account charges and GPU costs are not measured. Standalone VLA has zero language-agent API calls, not zero compute cost.</p></div></div><div class="method-links"><a href="${esc(evidenceURL('research/text-target-hard50-20261106/REPORT.md'))}">VLAct Clean 50k text-target report ↗</a><a href="${esc(evidenceURL('research/numeric-target-hard50-20261106/REPORT.md'))}">VLAct 50k paired Hard report ↗</a><a href="${esc(evidenceURL('research/hard50-expansion-20261105/REPORT.md'))}">Earlier All 140k expansion & protocol ↗</a><a href="${esc(evidenceURL('research/spatial-inputs-20261105/REPORT.md'))}">Retained spatial-input pilot ↗</a><a href="${esc(evidenceURL('research/input-required-20261105/REPORT.md'))}">Previous input-required study ↗</a><a href="${esc(evidenceURL('research/agent-protocols-20261105/REPORT.md'))}">Original autonomous/guided study ↗</a><a href="${esc(evidenceURL('research/oft-all140k-20261103/REPORT.md'))}">All 140k results & validation ↗</a><a href="${esc(evidenceURL('research/oft-all140k-20261103/protocol.json'))}">All 140k protocol & checkpoint ↗</a><a href="${esc(resultURL('sources.json'))}" target="_blank">Data sources ↗</a><a href="${esc(evidenceURL('research/robotwin-hard-20261101/REPORT.md'))}">Report ↗</a><a href="${esc(evidenceURL('research/robotwin-hard-20261101/protocol.json'))}">Protocol & checkpoints ↗</a><a href="${esc(evidenceURL('research/robotwin-hard-20261101/execution-audit.json'))}">200-episode audit ↗</a><a href="../index.html#overview">Retained Easy results ↗</a><button class="text-button" data-export="all">Download comparison CSV ↓</button></div></details>`;
}

const expandedTaskVariants = new Set();
const visibleTaskVariants = () => data.variants.filter(v => expandedTaskVariants.has(v.id));
function taskColumnPicker() {
  return `<div class="task-column-picker" role="group" aria-label="Methods to compare"><div class="column-picker-heading"><div><strong>Choose methods to compare</strong><p id="task-column-status" role="status">All method columns are collapsed. Select one or more to compare.</p></div><div class="column-picker-actions"><button class="text-button" data-task-columns="all">Expand all</button><button class="text-button" data-task-columns="none">Collapse all</button></div></div><div class="task-column-options">${data.variants.map(v=>`<button class="task-column-toggle" data-task-column="${esc(v.id)}" aria-expanded="${expandedTaskVariants.has(v.id)}" aria-controls="task-comparison" style="--variant:${colors[v.id]}"><span class="column-toggle-icon" aria-hidden="true">${expandedTaskVariants.has(v.id)?'−':'+'}</span><span>${esc(methodLabel(v))}</span></button>`).join('')}</div></div>`;
}
function taskColumnHeaders() {
  return '<th scope="col">Task</th>' + visibleTaskVariants().map(v=>`<th scope="col" data-task-variant="${esc(v.id)}" class="${v.id===filters.variant?'focus-column':''}"><div class="task-column-label"><span>${esc(methodLabel(v))}</span><button class="column-close" data-task-column="${esc(v.id)}" aria-label="Collapse ${esc(methodLabel(v))} column" aria-expanded="true" aria-controls="task-comparison">×</button></div><small>${esc(v.model)} · ${esc(v.effort)}</small><small>Native result · Estimated USD</small></th>`).join('');
}
function syncTaskColumns() {
  if(current.type==='runs')return;
  const variants=visibleTaskVariants(), table=$('#task-comparison');
  table.querySelector('thead tr').innerHTML=taskColumnHeaders();
  table.classList.toggle('has-methods',variants.length>0);
  table.style.setProperty('--method-count',variants.length);
  $$('[data-task-column].task-column-toggle').forEach(button=>{
    const expanded=expandedTaskVariants.has(button.dataset.taskColumn);
    button.setAttribute('aria-expanded',expanded);
    button.querySelector('.column-toggle-icon').textContent=expanded?'−':'+';
  });
  $('#task-column-status').textContent=variants.length?`${variants.length} of ${data.variants.length} method columns expanded. Select another method to compare.`:'All method columns are collapsed. Select one or more to compare.';
  $('[data-task-columns="none"]').disabled=variants.length===0;
  $('[data-task-columns="all"]').disabled=variants.length===data.variants.length;
}

function taskBrowser(variant=null) {
  return `<section class="task-browser" id="tasks"><div class="section-heading bare"><div><div class="eyebrow">${variant?'Episode index':'Browse the benchmark'}</div><h2>Explore tasks <span class="heading-count">${plannedTasks(variant).length}</span></h2></div><button class="button secondary" data-export="${variant||'all'}">Export CSV ↓</button></div><div class="panel">${variant?'':taskColumnPicker()}<div class="filters"><label class="search-field"><span aria-hidden="true">⌕</span><input id="task-search" type="search" aria-label="Search tasks" placeholder="Search task name, instruction or ID" value="${esc(filters.query)}"></label><select id="task-family" aria-label="Environment"><option value="">All environments</option>${data.families.map(f=>`<option value="${f.id}" ${filters.family===f.id?'selected':''}>${f.name}</option>`).join('')}</select>${variant?'':`<select id="task-variant" aria-label="Agent for outcome filter">${data.variants.map(v=>`<option value="${v.id}" ${filters.variant===v.id?'selected':''}>${methodLabel(v)} · ${v.model}</option>`).join('')}</select>`}<select id="task-status" aria-label="Outcome"><option value="">All outcomes</option>${['pass','fail','pending'].map(s=>`<option value="${s}" ${filters.status===s?'selected':''}>${s[0].toUpperCase()+s.slice(1)}</option>`).join('')}</select><select id="task-sort" aria-label="Sort tasks"><option value="catalog" ${filters.sort==='catalog'?'selected':''}>Catalog order</option><option value="tokens" ${filters.sort==='tokens'?'selected':''}>Most fresh input tokens</option><option value="cost" ${filters.sort==='cost'?'selected':''}>Highest cost</option><option value="name" ${filters.sort==='name'?'selected':''}>Task name</option></select></div><div class="table-scroll"><table id="task-comparison" class="task-table ${variant?'single-variant':'selectable-task-table'}"><thead><tr>${variant?'<th scope="col">Task</th><th>Native result</th><th>Fresh input<small>Excludes read and write</small></th><th>Cache read</th><th>Cache write</th><th>Cache hit</th><th>Output</th><th>Total cost<small>Estimated USD</small></th><th>Action steps</th>':taskColumnHeaders()}</tr></thead><tbody id="task-rows"></tbody></table></div><div class="table-footer"><span id="task-count" aria-live="polite"></span><span id="filter-context"></span><button class="text-button" id="reset-filters">Reset filters</button></div></div></section>`;
}
function renderRows() {
  const variant=current.type==='runs'?current.variant:null, selected=variant||filters.variant, q=filters.query.trim().toLowerCase();
  let tasks=plannedTasks(variant).filter(t=>(!filters.family||t.family===filters.family)&&(!filters.status||outcome(epFor(t.key,selected))===filters.status)&&(!q||[t.key,t.title,t.catalog_instruction,t.native_id,familyName(t.family)].some(s=>s?.toLowerCase().includes(q))));
  if(filters.sort==='name') tasks.sort((a,b)=>a.title.localeCompare(b.title));
  if(filters.sort==='tokens') tasks.sort((a,b)=>(UsageMetrics.usage(epFor(b.key,selected)).fresh??-1)-(UsageMetrics.usage(epFor(a.key,selected)).fresh??-1));
  if(filters.sort==='cost') tasks.sort((a,b)=>(UsageMetrics.price(epFor(b.key,selected))?.upper??-1)-(UsageMetrics.price(epFor(a.key,selected))?.upper??-1));
  syncTaskColumns();
  $('#task-rows').innerHTML=tasks.length?tasks.map(t=>{const ep=epFor(t.key,selected),us=UsageMetrics.usage(ep),cs=stats(ep?[ep]:[]);return `<tr data-task="${t.key}"><th scope="row"><a class="task-title" href="${taskRoute(t.key,selected)}">${esc(t.title)} <span class="row-arrow">↗</span></a><span class="task-meta">${familyName(t.family)} <span>·</span> <code>${t.key}</code>${data.task_notes[t.key]?'<span class="native-marker" title="Simulator source issue">◆ Native note</span>':''}</span></th>${variant?`<td>${badge(ep,taskRoute(t.key,selected))}</td><td class="numeric" title="${number(us.fresh)}">${compact(us.fresh)}</td><td class="numeric" title="${rangeNumber(us.cacheLow,us.cacheHigh,number)}">${rangeNumber(us.cacheLow,us.cacheHigh)}</td><td class="numeric" title="${number(us.cacheWrite)}">${compact(us.cacheWrite)}</td><td class="numeric">${rangeNumber(us.cacheRateLow,us.cacheRateHigh,pct)}</td><td class="numeric">${compact(us.output)}</td><td class="numeric" title="${esc(costNote(cs))}">${costValue(cs)}</td><td class="numeric">${number(actionSteps(ep?.steps,t))}<small>${ep?'of '+number(actionSteps(ep.measured_protocol?.max_steps,ep)):number(actionSteps(plannedProtocol(t,selected).max_control_steps,t))+' campaign plan'}</small></td>`:visibleTaskVariants().map(v=>`<td class="${v.id===filters.variant?'focus-column':''}">${taskResult(epFor(t.key,v.id),taskRoute(t.key,v.id))}</td>`).join('')}</tr>`;}).join(''):`<tr><td colspan="${variant?9:visibleTaskVariants().length+1}" class="empty-state">No tasks match these filters. <button class="text-button" data-reset>Clear filters</button></td></tr>`;
  $('#task-count').textContent=`${tasks.length} of ${data.tasks.length} tasks`;
  $('#filter-context').textContent=variant?variantName(variant):'Outcome filter & usage/cost sort: '+variantName(filters.variant);

}
function researchRerunNote() {
  const r=data.research_update;if(!r)return '';
  return `<aside class="native-note" data-research-rerun><span class="note-symbol">i</span><div><strong>Kinex + VLAct 50k · October 30</strong><p>${number(r.successes)} / ${number(r.valid)} native successes · ${number(r.vla_calls)} VLA calls · ${number(r.structured_condition_calls)} calls with caller-defined structured conditions. Astra/high chooses tool use, conditions, text organization and execution horizon. Three single-seed episodes do not establish a causal benefit or superiority over pure agent control.</p><div class="inline-links"><a href="#runs/kinex_policy">Explore the new runs ↗</a><a href="${esc(evidenceURL(r.report))}">Calling behavior & evidence ↗</a><a href="history.html#overview">Previous pilot ↗</a></div></div></aside>`;
}


function overview() {
  current={type:'overview'};
  $('#main').innerHTML=`<section class="hero"><div><div class="eyebrow"><span class="tiny-logo">✦</span> RLE-Bench · Embodied agent evaluation</div><h1>RoboTwin 2.0.<br><span>Hard evaluation.</span></h1><p>demo_randomized · one episode per selected task.<br>Kinex and the paired Kinex + VLA study use RLE revised instructions; four standalone VLA checkpoints retain native instructions.</p></div><div class="hero-facts"><div><strong>${data.families.length}</strong><span>environment</span></div><div><strong>${data.tasks.length}</strong><span>distinct tasks</span></div><div><strong>${data.variants.length}</strong><span>agent–model variants</span></div><span class="progress-label"><i></i>${data.benchmark_complete?'Evaluation complete':'Evaluation in progress'} · selected seeds</span></div></section>
  ${vlactCampaignProgress()}${researchRerunNote()}${recordingPilotProgress()}${opusPilotProgress()}<div class="agent-cards">${data.variants.map(v=>{const s=stats(episodes(v.id));return `<a class="agent-card ${s.n?'':'planned'}" href="#runs/${v.id}" style="--variant:${colors[v.id]}"><div class="card-header"><span class="agent-name">${icon(v)}${esc(methodLabel(v))}</span><span class="state-label">${s.n===plannedTasks(v.id).length?'Complete':s.n?'Partial':'Planned'}</span></div><p class="card-model">${modelLabel(v)}</p><div class="card-rate"><strong>${pct(s.rate)}</strong><span>native success</span></div><div class="card-stats"><span><b>${s.n?s.passes+' / '+s.n:'—'}</b> passed</span><span class="card-cost" title="${esc(costNote(s))}"><b>${costValue(s)}</b> total cost<small>Estimated USD</small></span></div><div class="completion-track"><span style="width:${s.n/plannedTasks(v.id).length*100}%"></span></div><div class="card-bottom"><span>${s.n} / ${plannedTasks(v.id).length} evaluated</span><span>${s.n?'Explore runs':'View planned'} ${arrow}</span></div></a>`;}).join('')}</div><div id="comparison-mount">${comparisonTable()}</div><a class="audit-launcher" href="#instructions"><div><strong>Instructions audit</strong><p>Compare current RLE goals with native descriptions, runtime language pools and recorded episode instructions.</p></div><span aria-hidden="true">↗</span></a>${taskBrowser()}${methodology()}`;
  ModelCards.mount($('.agent-cards'), 'hard');
  renderRows();
}
function runsPage(variant,params,restoredFilters=null) {
  if(!variantFor(variant)){overview();return;}
  if(current.type!=='runs'||current.variant!==variant)filters={query:'',family:'',status:'',variant,sort:'catalog'};
  current={type:'runs',variant};filters.variant=variant;
  if(params.has('family')){filters.family=params.get('family');filters.status='';filters.query='';}
  if(restoredFilters)filters={...restoredFilters};
  const v=variantFor(variant),s=stats(episodes(variant));
  $('#main').innerHTML=`<div class="breadcrumbs"><a href="#overview">Benchmark</a><span>/</span><span>Agent report</span></div>${variantTabs(variant)}<section class="report-hero" style="--variant:${colors[variant]}"><div><div class="eyebrow">${s.n?'Selected results':'Planned evaluation'}</div><h1>${esc(methodLabel(v))} <span class="muted-times">×</span> ${v.model}</h1><p>${esc(v.effort)} effort · One seed per task · ${s.n} evaluated · ${plannedTasks(variant).length-s.n} pending</p></div><button class="button secondary" data-export="${variant}">Download results ↓</button></section>${checkpointDetails(v)}<div class="report-metrics">${metric(pct(s.rate),'Native success',s.n?`${s.passes} passed / ${s.n} evaluated`:'No recorded episodes')}${metric(costValue(s),'Total cost',costNote(s))}${metric(number(s.responses??s.usageMessages),s.responses==null&&s.usageMessages!=null?'Session usage messages':'Model responses',s.n?(s.responses==null&&s.usageMessages!=null?'Provider response identity unavailable':'Recorded response count'):'Not yet measured')}${metric(elapsed(s.wall==null?null:s.wall/s.n),'Mean wall time',s.n?'Per evaluated episode':'Not yet measured')}</div>${usageTiles(s,false)}<div class="family-cards">${data.families.map(f=>{const fs=stats(episodes(variant,f.id));if(!plannedTasks(variant).some(t=>t.family===f.id))return '';return `<button class="family-card ${filters.family===f.id?'active':''}" data-report-family="${f.id}"><div><strong>${f.name}</strong><span>${pct(fs.rate)}</span></div><div class="mini-track"><span style="width:${(fs.rate||0)*100}%;background:${colors[variant]}"></span></div><small>${fs.n?`${fs.passes} / ${fs.n} passed`:'Pending'} · ${plannedTasks(variant).filter(t=>t.family===f.id).length-fs.n} untested</small></button>`;}).join('')}</div>${taskBrowser(variant)}${methodology()}`;
  renderRows();
}
function nativeNote(task,ep) {
  const note=data.task_notes[task.key];if(!note)return '';
  return `<aside class="native-note" data-native-note><span class="note-symbol">!</span><div><strong>Native source · ${esc(note.kind)}</strong><p>${esc(note.text)}</p><div class="inline-links">${external(note.source,'Pinned source')}${external(note.evidence,'Diagnostic evidence')}${external(ep?.links?.analysis,'Episode record')}${external(ep?.links?.terminal_frame,'Terminal frame')}</div></div></aside>`;
}
function videoPanel(ep,mini=false) {
  const m=ep.media||{},speed=m.speed||1,links=ep.links;
  return `<div class="video-panel ${mini?'mini-video':''}"><div class="video-caption"><span><i class="status-dot"></i> Native recording</span><span>${m.width||'—'} × ${m.height||'—'} · ${m.duration_s==null?'':m.duration_s.toFixed(2)+' s'}</span></div><video id="episode-video" controls playsinline preload="metadata" style="aspect-ratio:${m.width||2}/${m.height||1}" poster="${esc(links.poster||'')}" src="${esc(links.video)}"></video><div class="video-toolbar"><label>Speed <select id="playback-speed" aria-label="Video playback speed">${[.25,.5,1,2].map(x=>`<option value="${x}" ${x===1?'selected':''}>${x*speed}× ${m.playback_kind==='official_action_index'?'recording':'simulation'}</option>`).join('')}</select></label><div><button class="button small" id="final-frame">${m.playback_kind==='official_action_index'?'Last recorded frame':'Final frame'}</button>${external(links.video,'Video','button small')}${external(links.terminal_frame,'Still','button small')}</div></div><div id="video-error" class="inline-error" hidden>Video unavailable. Open the pinned video directly using the Video link.</div></div>`;
}
function episodeMetrics(ep) {
  const u=ep.usage||{},s=stats([ep]);
  return `<section class="episode-usage" aria-label="Token usage and cost">${usageTiles(s)}<div class="usage-activity"><span><strong>${u.response_count==null&&Number.isFinite(u.known_response_count)?number(u.known_response_count)+'+':number(u.response_count??u.usage_message_count)}</strong> ${u.response_count==null&&u.usage_message_count!=null?'session usage messages':'model responses'}</span><span><strong>${number(ep.call_activity?.model_tool_calls)}</strong> tool calls</span>${external(ep.links.usage,'Usage accounting record')}</div></section>`;
}
// Align words and punctuation while preserving the exact original whitespace.
function instructionDiff(original, revised) {
  const split = text => text.match(/\s+|[\p{L}\p{N}_]+|[^\s]/gu) || [];
  const a=split(original), b=split(revised);
  const lcs=Array.from({length:a.length+1},()=>new Uint16Array(b.length+1));
  for(let i=a.length-1;i>=0;i--)for(let j=b.length-1;j>=0;j--)
    lcs[i][j]=a[i]===b[j]?lcs[i+1][j+1]+1:Math.max(lcs[i+1][j],lcs[i][j+1]);
  const before=[],after=[];
  const append=(list,text,changed)=>{const last=list.at(-1);if(last&&last.changed===changed)last.text+=text;else list.push({text,changed});};
  let i=0,j=0;
  while(i<a.length||j<b.length){
    if(i<a.length&&j<b.length&&a[i]===b[j]){append(before,a[i++],false);append(after,b[j++],false);}
    else if(j<b.length&&(i===a.length||lcs[i][j+1]>=lcs[i+1][j]))append(after,b[j++],true);
    else append(before,a[i++],true);
  }
  const html=(parts,kind)=>parts.map(p=>p.changed&&p.text.trim()?`<${kind==='removed'?'del':'mark'} class="instruction-${kind}">${esc(p.text)}</${kind==='removed'?'del':'mark'}>`:esc(p.text)).join('');
  return {original:html(before,'removed'),revised:html(after,'added')};
}
function instructionPair(task, ep) {
  const candidate = ep ? measuredInstructions.episodes[ep.id] : null;
  const record = candidate && candidate.initial_goal === ep.instruction && candidate.task_key === task.key ? candidate : null;
  const recordedNative = record?.observed_native || (ep ? ep.native_instruction : task.native_instruction);
  const measured = record?.text || (ep ? (ep.instruction || (ep.instruction_policy === 'original_native' ? recordedNative : null)) : null);
  const reference = catalogInstructionAudit.tasks.find(item => item.published_task_key === task.key && item.id === task.native_id);
  const nativeReference = !recordedNative && reference?.native ? reference : null;
  const native = recordedNative || nativeReference?.native;
  return {record, native, measured, nativeReference};
}

function instructionPanel(task,ep) {
  const {record,native,measured:recorded,nativeReference}=instructionPair(task,ep);
  const measured=ep?recorded:(task.catalog_instruction_by_variant?.[current.variant]||task.catalog_instruction);
  const initial=record&&record.initial_goal!==measured?record.initial_goal:null;
  const changed=Boolean(native&&measured&&native!==measured);
  const diff=changed?instructionDiff(native,measured):null;
  const choices=[['measured',ep?'Measured':'Planned',measured],['native','Original native',native],['current','Current catalog',null]].filter(([key,,text])=>text&&(key!=='current'||(ep&&text!==measured&&text!==initial)));
  const currentChanged=native&&task.catalog_instruction&&native!==task.catalog_instruction;
  const description=!ep?'The current catalog instruction for the planned evaluation.':record?.kind==='scene_bound_goal'?"The measured goal with this episode's objects and targets filled in from the agent's session.":record?.kind==='native_received'?'The native instruction received by the agent during this episode.':'The task instruction supplied for this episode.';
  return `<section class="panel instruction-panel"><div class="section-heading"><div><h2>Task instruction</h2><p>${description}</p></div><div class="segmented" aria-label="Instruction version">${choices.map(([k,label],i)=>`<button data-instruction="${k}" aria-pressed="${i===0}">${label}</button>`).join('')}</div></div>${nativeReference?`<p class="instruction-diff-note" data-native-reference><span>Native comparison uses the pinned upstream full_description reference${ep?'; native text was not recorded in this episode':''}. ${external(nativeReference.source_url,'Native source')}</span></p>`:''}${choices.map(([k,,text],i)=>{
    const comparison=k==='current'?(currentChanged?instructionDiff(native,text):null):diff;
    const html=comparison?(k==='native'?comparison.original:comparison.revised):esc(text);
    const note=comparison?(k==='native'?'Struck-through text was removed or replaced in the '+(ep?'measured':'planned')+' instruction.':'Highlighted text was added or replaced relative to the original native instruction.'):(native?'No changes from the original native instruction.':'Original native text is unavailable for comparison.');
    return `<div class="instruction-version" id="instruction-${k}" ${i?'hidden':''}><p class="instruction-diff-note">${comparison?`<span class="diff-swatch ${k==='native'?'removed':'added'}" aria-hidden="true"></span>`:''}${note}${k==='current'?' This catalog text is not the measured episode instruction.':''}</p><div class="instruction-text">${html}</div></div>`;
  }).join('')}<div class="instruction-footer"><span>${ep?`Policy: ${esc(ep.instruction_policy)}`:'Planned seed: '+(task.planned_seed_by_variant?.[current.variant]??plannedProtocol(task,current.variant).seed)}</span><span>${ep?'Recorded':'Campaign planned'} budget: ${number(actionSteps(ep?ep.measured_protocol?.max_steps:plannedProtocol(task,current.variant).max_control_steps,task))} action steps</span></div>${record&&initial?`<p class="instruction-diff-note">${record.kind==='scene_bound_goal'?'Object names are resolved for display; the measured completion requirements are preserved.':'The initial input contained a generic placeholder; this native instruction was received in the recorded session.'} <a href="${esc(record.source.instructions_url)}" target="_blank" rel="noopener">Original instruction record ↗</a> · <a href="${esc(record.source.transcript_url)}" target="_blank" rel="noopener">Session evidence ↗</a></p>`:''}</section>`;
}

function overviewDetail(task,ep) {
  const seedLimit=data.active_campaign?.native_seed_selection?.[task.key];
  const initializationNote=task.initialization_note_by_variant?.[ep?.variant]||task.initialization_note;
  const initializationBlocked=(data.active_campaign?.initialization_blocked||[]).includes(task.key+'/'+current.variant);
  const review=reviewFor(task.key,current.variant);
  if(!ep&&review)return `<section class="panel pending-panel" data-runtime-review><span class="badge invalid">Under review</span><h2>Native success recorded; runtime finalization failed</h2><p>${esc(review.reason)}</p><p>Original harness verdict: invalid. Recording manifest: incomplete. This attempt is excluded from formal success metrics; its usage is retained separately.</p><dl class="facts"><dt>Native terminal steps</dt><dd>${number(actionSteps(review.native_terminal_steps,task,current.variant))}</dd><dt>Fresh input</dt><dd>${number(review.usage.fresh_input_tokens)}</dd><dt>Cache read</dt><dd>${number(review.usage.cached_input_tokens)}</dd><dt>Output</dt><dd>${number(review.usage.output_tokens)}</dd><dt>Model responses</dt><dd>${number(review.usage.response_count)}</dd><dt>Estimated API-equivalent cost</dt><dd>${exactMoney(review.estimated_api_equivalent_usd)}</dd></dl><p>Both original camera streams decode successfully. Their completion manifest was not sealed, so they are retained as review evidence.</p><div class="inline-links">${Object.entries(review.links).map(([key,url])=>external(url,key.replaceAll('_',' '))).join('')}</div></section>${instructionPanel(task,null)}`;
  if(!ep)return `<div class="pending-layout"><section class="pending-panel"><span class="pending-orbit">○</span><span class="eyebrow">${initializationBlocked?'Initialization blocked':'Awaiting evaluation'}</span><h2>${seedLimit?.exhausted?'No native-valid seed at or below '+number(seedLimit.max_seed):initializationBlocked?'Native seed 0 could not initialize':'No recorded episode yet'}</h2><p>${variantName(current.variant)} / ${esc(variantFor(current.variant).effort)}</p><div class="pending-facts">${metric(number(actionSteps(plannedProtocol(task,current.variant).max_control_steps,task)),'Campaign planned action steps')}${metric(String(task.planned_seed_by_variant?.[current.variant]??plannedProtocol(task,current.variant).seed),'Seed')}${metric(plannedProtocol(task,current.variant).control_frequency_hz+' Hz','Control frequency')}</div><p class="subtle">${seedLimit?.exhausted?'Native checks exhausted seeds 1–'+number(seedLimit.max_seed)+'. No Codex model attempt was launched. The original Kinex result is retained; this unavailable Codex task is excluded from success rates.':initializationBlocked?'No model was called. The authored seed could not initialize; a seed-selection decision is pending. This case is excluded from native success rates.':'This task is included in the planned catalog. Results and usage will appear after evaluation.'}</p></section>${instructionPanel(task,null)}</div>${seedLimit?.evidence_url?external(seedLimit.evidence_url,'Native seed selection evidence'):''}${nativeNote(task,null)}`;
  const m=ep.media||{},u=ep.usage||{},a=ep.analysis||{};
  const reason=a.evidence_note||a.failure_reason||a.cause||a.observed||a.visible_completion;
  return `<div class="episode-layout"><div>${videoPanel(ep)}<p class="media-note">${m.playback_kind==='official_action_index'?'Head + left wrist + right wrist · 4× official recording, not simulation time. Wrist views update only at inference boundaries. Native 320 × 240 views are upscaled for display; action-limit recordings omit the post-final-action frame.':ep.recording_mode==='native'?'Native camera recording · cached agent-resolution frames · '+(m.speed||1)+'× simulation speed.':ep.provider==='robobridge'&&m.playback_kind==='live_spectator'?'Independent spectator cameras · 720 px high per view · overview + wrist views · '+(m.speed||1)+'× simulation speed. Agent images retain native resolution and orientation.':m.playback_kind==='native_observation_snapshots'?'Native observation snapshots · 10 FPS playback; this is not simulation time.':`${m.source_fps?m.source_fps+' FPS source capture · ':''}${m.speed||1}× simulation speed.`} Session timestamps use wall time and are not synchronized to video frames.</p></div><aside class="result-panel panel"><div class="result-head"><span class="eyebrow">Native verdict</span>${badge(ep)}</div><div class="result-number">${number(actionSteps(ep.steps,ep))}<span> / ${number(actionSteps(ep.measured_protocol?.max_steps,ep))} action steps</span></div><div class="completion-track"><span style="width:${Math.min(100,(actionSteps(ep.steps,ep)||0)/(actionSteps(ep.measured_protocol?.max_steps,ep)||1)*100)}%"></span></div><dl class="facts"><dt>Termination</dt><dd>${esc(ep.verdict?.termination||ep.verdict?.reason||'—')}</dd><dt>Execution</dt><dd>${esc(ep.execution?.status||'—')}</dd><dt>Evidence</dt><dd>${ep.valid?'Valid':'Invalid'}</dd><dt>Simulation time</dt><dd title="${esc(ep.timing?.simulation_time_note||'')}">${ep.timing&&ep.simulation_time_s==null?'Not recorded':elapsed(ep.simulation_time_s)}</dd><dt>Wall time</dt><dd title="${esc(ep.timing?.wall_time_scope||'')}">${elapsed(ep.wall_time_s)}</dd><dt>Estimated cost</dt><dd>${costValue(stats([ep]))}</dd><dt>Seed</dt><dd>${ep.seed}</dd><dt>Agent version</dt><dd data-agent-version>${esc(agentVersion(ep))}</dd></dl><div class="result-links">${external(ep.links.verdict,'Native verdict')}${external(ep.links.provenance,'Source identity')}</div></aside></div>${nativeNote(task,ep)}${ep.post_terminal_review?`<aside class="native-note" data-post-terminal-note><span class="note-symbol">!</span><div><strong>Native episode completed; later provider error</strong><p>${esc(ep.post_terminal_review.reason)}</p>${external(ep.links.completion_review,"Terminal completion review")}</div></aside>`:""}${initializationNote?`<aside class="native-note" data-initialization-note><span class="note-symbol">!</span><div><strong>Measured initial-state variation</strong><p>${esc(initializationNote)}</p><a href="${esc(resultURL('initialization-comparison.json'))}" target="_blank">Paired initialization evidence ↗</a></div></aside>`:''}${ep.usage_review?`<aside class="native-note" data-usage-review-note><span class="note-symbol">i</span><div><strong>${esc(ep.usage_review.title||'Usage accounting review')}</strong><p>${esc(ep.usage_review.reason)}</p>${external(ep.links.usage_review,"Usage reconciliation evidence")}</div></aside>`:""}${ep.native_clock_review?`<aside class="native-note" data-native-clock-note><span class="note-symbol">i</span><div><strong>Native physics clock differs from control-frame time</strong><p>${esc(ep.native_clock_review.reason)}</p>${external(ep.links.native_clock_review,"Native clock review")}</div></aside>`:""}${ep.collector_review&&ep.collector_review.schema!=="rlebench/collector-recovery/1"?`<aside class="native-note" data-collector-review-note><span class="note-symbol">i</span><div><strong>Host collector recovered; original model continued</strong><p>${esc(ep.collector_review.reason)}</p><p>Wall time uses the original session timestamps. Lost host setup timing is left unknown.</p><p>Host waiting protection was extended prospectively from 8 to 16 hours for this original execution; the native control budget is unchanged.</p>${external(ep.links.collector_review,"Collector recovery evidence")}</div></aside>`:""}${ep.provenance?.protocol_exception?.same_seed_comparison===false?`<aside class="native-note" data-seed-scope-note><span class="note-symbol">i</span><div><strong>Different evaluation seeds</strong><p>Codex uses seed ${number(ep.seed)} after native expert and initialization checks with no model calls during selection. ${ep.provenance.protocol_exception.max_seed!=null?'Seed selection was capped at '+number(ep.provenance.protocol_exception.max_seed)+'. ':''} Kinex retains its original seed ${number(ep.provenance.protocol_exception.preserved_kinex_seed)} result. Codex ran once; this is not a same-seed comparison.</p>${external(ep.links.seed_selection,'Native seed selection evidence')}</div></aside>`:''}${recordingComparisonNote(ep)}${episodeMetrics(ep)}<div class="detail-two-column">${instructionPanel(task,ep)}<section class="panel episode-analysis"><div class="section-heading"><div><h2>Episode notes</h2><p>Recorded observations and task-specific interpretation.</p></div></div><div class="analysis-body">${reason?`<p>${esc(reason)}</p>`:`<p>${esc(a.outcome||'The native result and original evidence are retained for this episode.')}</p>`}<details><summary>Read recorded analysis</summary>${Object.entries(a).filter(([k])=>k!=='preflight').map(([k,v])=>`<div class="analysis-entry"><span>${esc(k.replaceAll('_',' '))}</span><p>${esc(typeof v==='string'?v:JSON.stringify(v))}</p></div>`).join('')}</details><div class="inline-links">${external(ep.links.analysis,'Analysis JSON')}${external(ep.links.terminal_frame,'Terminal evidence')}</div></div></section></div><div class="detail-launchers"><a href="${taskRoute(task.key,ep.variant,'session')}"><span class="launcher-icon">≡</span><div><strong>Read the full session</strong><span>${number(ep.session_counts?.visible_events)} events · ${number(ep.session_counts?.observed_images)} observations</span></div>${arrow}</a><a href="${taskRoute(task.key,ep.variant,'artifacts')}"><span class="launcher-icon">⌘</span><div><strong>Inspect agent artifacts</strong><span>${ep.resources?.length||0} saved files · workspace & evidence</span></div>${arrow}</a></div>`;
}
function taskPage(key,variant,section='overview') {
  const task=data.tasks.find(t=>t.key===key);if(!task||!variantFor(variant)){notFound();return;}
  if(!task.planned_variants.includes(variant)){current={type:'not-scheduled'};$('#main').innerHTML=`<section class="panel pending-panel"><h1>Not scheduled</h1><p>${esc(variantFor(variant).agent)} is not included for ${esc(familyName(task.family))} in this campaign.</p><a class="button secondary" href="${taskRoute(key,task.planned_variants[0])}">View the scheduled evaluation ${arrow}</a></section>`;return;}
  const ep=epFor(key,variant), validSections=['overview','session','tools','policy','artifacts','evidence','attempts'];
  if(!validSections.includes(section)||(!ep&&!['overview','attempts'].includes(section)))section='overview';
  current={type:'task',key,variant,section,ep,task};
  sessionState={filter:'all',query:'',count:40,view:'timeline'};
  const taskList=plannedTasks(variant),index=taskList.indexOf(task),history=data.attempt_history.filter(h=>h.task_key===key&&h.variant===variant);
  document.title=`${task.title} · ${variantFor(variant).agent} — Programmable VLA`;
  $('#main').innerHTML=`<div class="breadcrumbs"><a data-task-return href="${esc(taskListReturn?.hash || '#tasks?task='+encodeURIComponent(key))}">← Back to tasks</a><span>/</span><a href="#runs/${variant}?family=${task.family}">${familyName(task.family)}</a><span>/</span><code>${key}</code></div><div class="task-heading"><div><div class="eyebrow">${familyName(task.family)} · ${key}</div><h1>${esc(task.title)}</h1><p><code>${esc(task.native_id)}</code></p></div><div class="task-arrows">${index?`<a class="button" href="${taskRoute(taskList[index-1].key,variant)}" aria-label="Previous task">←</a>`:''}${index<taskList.length-1?`<a class="button" href="${taskRoute(taskList[index+1].key,variant)}" aria-label="Next task">→</a>`:''}</div></div>${budgetNote(task)}${plusSeedNote(task,variant,ep)}${variantTabs(variant,key,section)}<nav class="detail-nav" aria-label="Episode sections">${[['overview','Overview',null],['session','Session',ep?.session_counts?.visible_events],['tools','Tool calls',ep?.call_activity?.model_tool_calls],['policy','VLA input/output',ep?.vla_calls],['artifacts','Artifacts',ep?.resources?.length],['evidence','Evidence',null],['attempts','Previous attempts',history.length]].filter(([k])=>(k!=='attempts'||history.length)&&(k!=='policy'||variantFor(variant).agent_protocol||variantFor(variant).agent!=='Kinex')).map(([k,l,n])=>!ep&&!['overview','attempts'].includes(k)?`<span class="disabled-tab" aria-disabled="true">${l}</span>`:`<a href="${taskRoute(key,variant,k)}" class="${k===section?'active':''}" ${k===section?'aria-current="page"':''}>${l}${n!=null?`<span>${number(n)}</span>`:''}</a>`).join('')}<span class="detail-model">${variantFor(variant).model} / ${variantFor(variant).effort}</span></nav><div id="detail-content">${section==='overview'?overviewDetail(task,ep):section==='session'?sessionShell(ep):section==='tools'?toolsShell(ep):section==='policy'?policyShell(ep):section==='artifacts'?artifactsPanel(ep):section==='evidence'?evidencePanel(task,ep):historyPanel(history,task)}</div>`;
  setupVideo();
  if(section==='session')loadSession(ep,epoch);
  if(section==='tools')loadTools(ep,epoch);
  if(section==='policy')loadPolicy(ep,epoch);
  if(section==='artifacts'&&ep.resources?.length)loadResource(0,epoch);
}
function setupVideo() {
  const v=$('#episode-video');if(!v)return;
  v.onerror=()=>{if($('#video-error'))$('#video-error').hidden=false;};
}
function sessionShell(ep) {
  return `<section class="panel session-panel"><div class="section-heading"><div><h2>Session & observations</h2><p id="session-summary">Loading the original transcript…</p></div><div class="inline-links">${external(ep.links.transcript,'Transcript JSON')}${external(ep.links.native_session,'Native session')}</div></div><div class="session-toolbar"><div class="segmented"><button data-session-view="timeline" aria-pressed="true">Timeline</button><button data-session-view="gallery" aria-pressed="false">Observations</button></div><select id="event-filter" aria-label="Filter session events"><option value="all">All events</option><option value="assistant">Assistant</option><option value="tools">Tool results</option><option value="errors">Tool errors</option><option value="images">With images</option><option value="context">User & context</option></select><input id="event-search" type="search" placeholder="Search text, tool name or event ID" aria-label="Search session"><span id="event-count" aria-live="polite"></span></div><div id="session-events"><div class="loading"><span class="spinner"></span>Loading session…</div></div><div class="session-more"><button id="more-events" class="button secondary" hidden>Load more events</button></div></section>`;
}
async function loadSession(ep,token) {
  try {
    if(!sessionCache.has(ep.id)) {
      const response=await fetch(ep.links.transcript);if(!response.ok)throw Error('HTTP '+response.status);
      const raw=await response.json();const entries=Array.isArray(raw)?raw:raw.messages||raw.entries||raw.events||[];
      if(!Array.isArray(entries))throw Error('Unsupported transcript format');
      sessionCache.set(ep.id,entries);
      if(sessionCache.size>6)sessionCache.delete(sessionCache.keys().next().value);
    }
    if(token!==epoch)return;
    const entries=sessionCache.get(ep.id),images=entries.flatMap((m,i)=>(m.parts||[]).filter(p=>p.type==='image'&&p.src).map(p=>({url:new URL(p.src,new URL(ep.links.transcript,location.href)).href,label:`Event ${i+1} · ${m.id||m.role||'Observation'}`})));
    $('#session-summary').textContent=`${number(entries.length)} events · ${number(images.length)} observation images · ${entries.filter(e=>e.error).length} tool errors. Event timestamps are in UTC.`;
    renderSession();
  } catch(error) {if(token!==epoch)return;$('#session-events').innerHTML=`<div class="empty-state">Transcript preview could not load (${esc(error.message)}).<br><button class="button secondary" data-retry-session>Retry</button> ${external(ep.links.transcript,'Open original transcript')}</div>`;}
}
function sessionText(entry) {return [entry.id,entry.role,entry.tool,...(entry.parts||[]).map(p=>p.text||JSON.stringify(p.input||p))].join('\n');}
function renderSession() {
  const entries=sessionCache.get(current.ep.id);if(!entries)return;
  const {filter,query,count,view}=sessionState, q=query.trim().toLowerCase();
  let matches=entries.map((entry,i)=>({entry,index:i})).filter(({entry:e})=>(filter==='all'||filter==='assistant'&&e.role==='assistant'||filter==='tools'&&e.role==='toolResult'||filter==='errors'&&e.error||filter==='images'&&(e.parts||[]).some(p=>p.type==='image')||filter==='context'&&['user','system','developer'].includes(e.role))&&(!q||sessionText(e).toLowerCase().includes(q)));
  imageItems=[];
  const imagePart=(p,index,entry,cls='observation')=>{
    const url=new URL(p.src,new URL(current.ep.links.transcript,location.href)).href;if(!/^https?:/.test(url))return '';
    const n=imageItems.length;imageItems.push({url,label:`Event ${index+1} · ${entry.id||entry.role||'Observation'}`});
    return `<button class="${cls}" data-image="${n}" aria-label="Open observation from event ${index+1}"><img src="${esc(url)}" alt="Agent observation at event ${index+1}" loading="lazy" decoding="async"><span>Event ${index+1} ${arrow}</span></button>`;
  };
  if(view==='gallery') {
    const images=matches.flatMap(({entry,index})=>(entry.parts||[]).filter(p=>p.type==='image'&&p.src).map(part=>({entry,index,part})));
    $('#session-events').innerHTML=images.length?`<div class="observation-gallery">${images.slice(0,count).map(({entry,index,part})=>imagePart(part,index,entry,'gallery-image')).join('')}</div>`:'<div class="empty-state">No observation images match these filters.</div>';
    $('#event-count').textContent=`${Math.min(count,images.length)} / ${images.length} images`;$('#more-events').hidden=count>=images.length;
  } else {
    $('#session-events').innerHTML=matches.length?`<div class="timeline">${matches.slice(0,count).map(({entry:e,index})=>{
      const role=e.role==='toolResult'?'Tool result':e.role==='assistant'?'Assistant':({user:'User',system:'System',developer:'Developer'}[e.role]||e.role||e.type||'Event');
      const tool=e.tool||(e.parts||[]).find(p=>p.type==='tool')?.name;
      return `<article class="session-entry ${e.error?'event-error':''}" id="event-${index}"><div class="event-index">${index+1}</div><div class="event-content"><div class="event-header"><strong>${esc(role)}</strong>${tool?`<code>${esc(tool)}</code>`:''}${e.error?'<span class="error-tag">Error</span>':''}<time>${esc(e.timestamp?e.timestamp.replace('T',' ').replace(/\.\d+Z$/,' UTC'):'')}</time></div><div class="event-parts">${(e.parts||[{type:'text',text:typeof e==='string'?e:JSON.stringify(e,null,2)}]).map(p=>{
        if(p.type==='image'&&p.src)return imagePart(p,index,e);
        if(p.type==='tool')return `<details class="tool-block"><summary><span>Tool call · <strong>${esc(p.name)}</strong></span><code>${esc((typeof p.input==='string'?p.input:JSON.stringify(p.input)).slice(0,130))}</code></summary><pre>${esc(typeof p.input==='string'?p.input:JSON.stringify(p.input,null,2))}</pre></details>`;
        const txt=p.text??p.thinking??JSON.stringify(p,null,2);
        if(txt==='')return '<span class="empty-event">No text recorded.</span>';
        if(p.type==='thinking'||p.type==='reasoning')return `<details class="tool-block"><summary>Recorded reasoning</summary><pre>${esc(txt)}</pre></details>`;
        if(e.role==='toolResult'||txt.length>1800)return `<details class="tool-block ${e.error?'error-block':''}"><summary><span>${e.role==='toolResult'?'Tool output':'Message'}</span><span class="output-excerpt">${esc(txt.slice(0,160))}</span></summary><pre>${esc(txt)}</pre></details>`;
        return `<div class="message-text">${esc(txt)}</div>`;
      }).join('')}</div><div class="event-id">${esc(e.id||'')}</div></div></article>`;
    }).join('')}</div>`:'<div class="empty-state">No events match these filters.</div>';
    $('#event-count').textContent=`${Math.min(count,matches.length)} / ${matches.length} events`;$('#more-events').hidden=count>=matches.length;
  }
  $('#more-events').textContent=view==='gallery'?'Load more observations':'Load next 40 events';
}
function artifactsPanel(ep) {
  const resources=ep.resources||[];
  return `<section class="panel artifacts-panel"><div class="section-heading"><div><h2>Agent artifacts</h2><p>Final files created during this episode. Their edit history remains in the session.</p></div><div class="inline-links">${external(ep.links.workspace,'Workspace archive')}${external(ep.links.workspace_changes,'Workspace manifest')}</div></div>${resources.length?`<div class="file-browser"><aside class="file-list" aria-label="Artifact files"><div class="file-list-title">${resources.length} saved files</div>${resources.map((r,i)=>`<button data-resource="${i}" class="file-item ${i===0?'active':''}" aria-pressed="${i===0}"><span class="file-extension">${esc(r.name.split('.').at(-1).toUpperCase().slice(0,4))}</span><span>${esc(r.name)}</span></button>`).join('')}</aside><div class="file-preview"><div class="file-toolbar"><code id="resource-name">${esc(resources[0].name)}</code><div><button class="button small" id="copy-resource">Copy</button><a class="button small" id="resource-open" target="_blank" rel="noopener" href="${esc(resources[0].file)}">Open file ↗</a></div></div><p id="resource-kind" class="file-caption"></p><pre id="resource-preview" tabindex="0">Loading file…</pre></div></div>`:'<div class="empty-state">No standalone tool or memo files were saved in this episode. The original session and workspace evidence remain available.</div>'}</section><div class="artifact-shortcuts">${evidenceCard('Execution evidence','Original verdict, protocol and runtime identity.',[['verdict','Native verdict'],['protocol','Protocol'],['provenance','Source identity']],ep)}${evidenceCard('Session & interactions','Original tool calls, observations and edited workspace.',[['native_session','Native session'],['trace','Trace'],['workspace_changes','Workspace changes']],ep)}</div>`;
}
async function fetchText(url) {
  if(fileCache.has(url))return fileCache.get(url);
  const r=await fetch(url);if(!r.ok)throw Error('HTTP '+r.status);
  if(Number(r.headers.get('content-length'))>3e6)throw Error('File exceeds the 3 MB preview limit; use Open file');
  const text=await r.text();if(text.length>3e6)throw Error('File exceeds the preview limit; use Open file');
  fileCache.set(url,text);if(fileCache.size>20)fileCache.delete(fileCache.keys().next().value);return text;
}
async function loadResource(index,token) {
  const r=current.ep?.resources?.[index];if(!r)return;
  current.resource=index;$('#resource-name').textContent=r.name;$('#resource-open').href=r.file;$('#resource-kind').textContent=r.kind||'Final workspace snapshot';$('#resource-preview').textContent='Loading file…';
  $$('[data-resource]').forEach(b=>{b.classList.toggle('active',+b.dataset.resource===index);b.setAttribute('aria-pressed',+b.dataset.resource===index);});
  try{const text=await fetchText(r.file);if(token===epoch&&current.resource===index){$('#resource-preview').textContent=text;current.resourceText=text;}}
  catch(e){if(token===epoch&&current.resource===index){$('#resource-preview').textContent='Preview unavailable: '+e.message;current.resourceText=null;}}
}
const evidenceGroups=[
  ['Native evaluation','Owner verdicts, measured task and control protocol.',[['verdict','Native verdict'],['timing','Episode timing'],['protocol','Measured protocol'],['native_goal','Task instructions'],['owner_journal','Owner action journal']]],
  ['Session & workspace','The original agent trajectory and final files.',[['native_session','Native session'],['transcript','Readable transcript'],['trace','Agent trace'],['workspace','Workspace archive'],['workspace_changes','Workspace manifest']]],
  ['Recording & review','Published media and checks against the recorded evidence.',[['native_video','Original head recording'],['video','Video'],['poster','Poster'],['terminal_frame','Terminal frame'],['recording_manifest','Recording manifest'],['media_check','Media validation'],['analysis','Episode analysis']]],
  ['Usage & provenance','Provider counters and the actual code used by the episode.',[['usage','Token usage'],['provider_usage','Provider usage ledger'],['provenance','Source identities'],['tool_errors','Tool errors']]]
];
function evidenceCard(title,description,items,ep) {
  return `<section class="panel evidence-card"><h3>${title}</h3><p>${description}</p><div>${items.filter(([k])=>ep.links[k]).flatMap(([k,l])=>(Array.isArray(ep.links[k])?ep.links[k]:[ep.links[k]]).map((url,i)=>external(url,l+(Array.isArray(ep.links[k])?' '+(i+1):'')))).join('')}</div></section>`;
}
function evidencePanel(task,ep) {
  const used=new Set(evidenceGroups.flatMap(g=>g[2].map(x=>x[0]))),extras=Object.keys(ep.links).filter(k=>!used.has(k));
  const source={...data.variant_sources[ep.variant],...(ep.source_dataset_revision?{dataset_revision:ep.source_dataset_revision}:{})};
  return `<div class="evidence-intro"><h2>Evidence & provenance</h2><p>Original files retained with their published checksums. Native verdicts and measured source identities remain unchanged.</p></div><div class="evidence-grid">${evidenceGroups.map(([title,desc,items])=>evidenceCard(title,desc,items,ep)).join('')}${extras.length?evidenceCard('Additional records','Episode-specific checks and retained references.',extras.map(k=>[k,k.replaceAll('_',' ')]),ep):''}</div><section class="panel provenance-panel"><div class="section-heading"><div><h2>Recorded identity</h2><p>Source and protocol belonging to this episode.</p></div></div><dl class="provenance-list"><dt>Episode</dt><dd><code>${esc(ep.source_episode_id)}</code></dd><dt>Model</dt><dd>${esc(ep.model)} / ${ep.effort}</dd><dt>Space</dt><dd>${external('https://huggingface.co/spaces/'+source.space,source.space)}</dd><dt>Original evidence revision</dt><dd><code>${source.evidence_revision}</code></dd>${ep.kinex_revision?`<dt>Kinex revision</dt><dd><code>${esc(ep.kinex_revision)}</code></dd>`:''}${Object.entries(ep.provenance?.sources||{}).map(([k,v])=>`<dt>${esc(k)}</dt><dd><code>${esc(v.revision||'Unrecorded revision')}</code>${v.dirty?' <span class="tag">Local changes recorded</span>':''}</dd>`).join('')}<dt>Recorded action-step budget</dt><dd>${number(actionSteps(ep.measured_protocol?.max_steps,ep))} steps</dd><dt>Campaign planned action-step budget</dt><dd>${number(actionSteps(plannedProtocol(task,current.variant).max_control_steps,task))} steps</dd><dt>Current benchmark default</dt><dd>${number(currentBudget(task))} action steps</dd></dl><details class="protocol-json"><summary>Inspect the measured protocol JSON</summary><pre>${esc(JSON.stringify(ep.measured_protocol,null,2))}</pre></details></section><section class="panel evidence-preview-panel"><div class="section-heading"><div><h2>Preview an evidence file</h2><p>Inspect the recorded JSON without leaving this page.</p></div><select id="evidence-select" aria-label="Choose evidence preview"><option value="">Choose a file…</option>${[['verdict','Native verdict'],['timing','Episode timing'],['protocol','Measured protocol'],['provenance','Source identities'],['usage','Token usage'],['analysis','Episode analysis'],['media_check','Media validation'],['recording_manifest','Recording manifest']].filter(([k])=>ep.links[k]).map(([k,l])=>`<option value="${k}">${l}</option>`).join('')}</select></div><pre id="evidence-preview" hidden tabindex="0"></pre></section>`;
}
function historyPanel(history,task) {
  return `<section class="panel history-panel"><div class="section-heading"><div><h2>Previous attempts</h2><p>Archived attempts are preserved separately and excluded from the current success rate, usage and costs.</p></div><a href="${esc(resultURL('attempt-history.json'))}" target="_blank" class="button secondary">Full archive ↗</a></div>${history.length?history.map(h=>`<article class="history-row"><div class="history-outcome">${badge(h)}<small>${h.valid===false?'Interrupted / invalid':typeof h.success==='boolean'?'Archived result':'Verdict not recorded'}</small></div><div><strong>${esc((h.status||'Archived attempt').replaceAll('_',' '))}</strong><p><code>${esc(h.id||h.job||h.dataset_revision||'Historical record')}</code></p><span class="history-stats">${h.steps!=null?number(actionSteps(h.steps,task))+' action steps · ':''}${h.usage?'Fresh input '+compact(UsageMetrics.usage(h).fresh)+' · cache read '+compact(h.usage.cached_input_tokens)+' · cache write '+compact(UsageMetrics.usage(h).cacheWrite)+' · output '+compact(UsageMetrics.usage(h).output)+' · ':''}${h.dataset_revision?'Revision '+h.dataset_revision.slice(0,8):''}</span>${h.analysis?.execution?`<p>${esc(h.analysis.execution)}</p>`:''}${h.instruction?`<details><summary>Measured instruction</summary><p>${esc(h.instruction)}</p></details>`:''}<div class="inline-links">${Object.entries(h.links||{}).filter(([k])=>['video','verdict','provenance','transcript','terminal_frame','native_session','result_page'].includes(k)).map(([k,u])=>external(u,k.replaceAll('_',' '))).join('')}</div></div></article>`).join(''):'<div class="empty-state">No earlier attempts are listed for this task and agent combination.</div>'}</section>`;
}
function notFound() {$('#main').innerHTML='<div class="empty-state"><h1>Page not found</h1><p><a href="#overview">Return to the benchmark</a></p></div>';}
// Keep each task list's view with its browser history entry.
history.scrollRestoration = 'manual';
let taskListReturn = null;
const navigationHash = () => location.hash || '#overview';
function saveTaskList(row = null) {
  if (!['overview', 'runs'].includes(current.type) || !$('#task-rows')) return;
  row ||= $$('#task-rows tr[data-task]').find(r => r.getBoundingClientRect().bottom > 100);
  const view = {
    hash: navigationHash(), filters: {...filters}, x: window.scrollX, y: window.scrollY,
    task: row?.dataset.task, offset: row?.getBoundingClientRect().top,
    tableX: $('#tasks .table-scroll').scrollLeft,
    matrixMetric, expandedModels: $$('[data-model-group][open]').map(el => el.dataset.modelGroup)
  };
  history.replaceState({...history.state, benchmarkNavigation: {list: view}}, '');
  return view;
}
function restoreTaskList(view) {
  const row = $$('#task-rows tr[data-task]').find(r => r.dataset.task === view.task);
  const y = row && view.offset != null
    ? window.scrollY + row.getBoundingClientRect().top - view.offset : view.y;
  $('#tasks .table-scroll').scrollLeft = view.tableX;
  window.scrollTo({left: view.x, top: y, behavior: 'instant'});
}
document.addEventListener('click', event => {
  const link = event.target.closest('a[href]');
  if (!link || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey ||
      link.target === '_blank' || !link.getAttribute('href').startsWith('#')) return;
  const view = saveTaskList(link.closest('tr[data-task]'));
  if (view && link.getAttribute('href').startsWith('#task/')) taskListReturn = view;
}, true);
window.addEventListener('pagehide', () => saveTaskList());

function route() {
  epoch++;$$('video').forEach(v=>{v.pause();v.removeAttribute('src');v.load();});
  const [hash,query='']=location.hash.slice(1).split('?'),parts=hash.split('/'),params=new URLSearchParams(query);
  const saved = history.state?.benchmarkNavigation;
  const returning = current.type === 'task' && taskListReturn &&
    (taskListReturn.hash === navigationHash() ||
     ['#overview', '#tasks'].includes(taskListReturn.hash) && ['#overview', '#tasks'].includes(navigationHash()));
  const view = saved?.list?.hash === navigationHash() ? saved.list : returning ? taskListReturn : null;
  if (parts[0] === 'task') {
    taskListReturn = saved ? saved.origin || null : (['overview', 'runs', 'task'].includes(current.type) ? taskListReturn : null);
    history.replaceState({...history.state, benchmarkNavigation: {origin: taskListReturn}}, '');
  } else if (view) {
    filters = {...view.filters};
    matrixMetric = view.matrixMetric;
    expandedModels = new Set(view.expandedModels);
  }
  document.title='Programmable VLA — RLE-Bench';
  if(parts[0]==='task')taskPage(parts[1]+'/'+parts[2],parts[3],parts[4]||'overview');
  else if(parts[0]==='instructions'){current={type:'instructions'};const auditEpoch=epoch;InstructionAudit.render({panel:'hard',root:'../',data,measuredInstructions,diff:instructionDiff,isCurrent:()=>epoch===auditEpoch});}
  else if(parts[0]==='runs')runsPage(parts[1],params,view?.filters);
  else overview();
  $$('[data-nav]').forEach(a=>a.setAttribute('aria-current',a.dataset.nav===(hash||'overview')?'page':'false'));
  if(view && $('#task-rows'))restoreTaskList(view);
  else if(hash==='tasks') {
    const row = $$('#task-rows tr[data-task]').find(r => r.dataset.task === params.get('task'));
    (row || $('#tasks')).scrollIntoView({block: row ? 'center' : 'start', behavior: 'instant'});
  }
  else if(hash==='methodology'){$('#methodology').open=true;$('#methodology').scrollIntoView();}
  else window.scrollTo({left:0,top:0,behavior:'instant'});
  if(parts[0]!=='task')taskListReturn=null;
}
function resetFilters() {filters={query:'',family:'',status:'',variant:filters.variant,sort:'catalog'};if(current.type==='runs')runsPage(current.variant,new URLSearchParams());else overview();$('#tasks').scrollIntoView();}
function showToast(text){$('#toast').textContent=text;$('#toast').classList.add('visible');setTimeout(()=>$('#toast').classList.remove('visible'),2200);}
function exportCSV(variant) {
  const ids=variant==='all'?data.variants.map(v=>v.id):[variant];
  const rows=[['task','environment','title','agent','model','effort','status','native_success','fresh_input_tokens','cache_read_tokens','cache_write_tokens','cache_write_counter_source','input_tokens_fresh_plus_cache_write','input_tokens_lower','input_tokens_upper','cached_tokens','cached_tokens_lower','cached_tokens_upper','cache_hit_rate','cache_hit_rate_lower','cache_hit_rate_upper','output_tokens','inclusive_input_tokens_original','cache_write_tokens_original','estimated_cost_usd','estimated_cost_lower_usd','estimated_cost_upper_usd','cost_basis','cache_write_basis','cache_write_assumed','steps','episode_id','reasoning_output_tokens','recorded_budget','planned_budget','source_episode_id','inclusive_total_tokens_original','seed','planned_seed','agent_execution','reported_harness_valid','post_terminal_provider_error','host_collector_recovered','harness_result_origin','agent_wall_time_limit_s','requested_wall_time_limit_s','wall_time_guard_adjusted','raw_steps','raw_recorded_budget','raw_planned_budget','current_action_step_budget']];
  for(const t of data.tasks)for(const id of ids){
    if(!t.planned_variants.includes(id))continue;
    const e=epFor(t.key,id),v=variantFor(id),u=UsageMetrics.usage(e),c=UsageMetrics.price(e);
    rows.push([t.key,familyName(t.family),t.title,v.agent,v.model,v.effort,outcome(e),e?e.success:'',u.fresh,u.cached,u.cacheWrite,e?u.writeBasis:null,u.input,u.inputLow,u.inputHigh,u.cached,u.cacheLow,u.cacheHigh,u.cacheRate,u.cacheRateLow,u.cacheRateHigh,u.output,u.inclusive,e?.usage?.cache_write_input_tokens,c&&c.lower===c.upper?c.lower:null,c?.lower,c?.upper,c?.basis,c?.cache_write_basis,c?.cache_write_assumed,actionSteps(e?.steps,t,id),e?.id,e?.usage?.reasoning_output_tokens,actionSteps(e?.measured_protocol?.max_steps,t,id),actionSteps(plannedProtocol(t,id).max_control_steps,t,id),e?.source_episode_id,tokens(e),e?.seed,t.planned_seed_by_variant[id],e?.execution?.status,e?(Object.prototype.hasOwnProperty.call(e,"harness_valid")?e.harness_valid:e.valid):null,e?Boolean(e.post_terminal_review):null,e?Boolean(e.collector_review):null,e?(e.harness_result_origin||"harbor"):null,e?.measured_protocol?.timeout_s,e?(e.measured_protocol?.requested_timeout_s??e.measured_protocol?.timeout_s):null,e?Boolean(e.collector_review?.operational_wall_time_adjustment):null,e?.steps,e?.measured_protocol?.max_steps,plannedProtocol(t,id).max_control_steps,currentBudget(t)]);
  }
  const csv=rows.map(row=>row.map(v=>'"'+String(v??'').replaceAll('"','""')+'"').join(',')).join('\r\n');
  const url=URL.createObjectURL(new Blob([csv],{type:'text/csv;charset=utf-8'})),a=document.createElement('a');a.href=url;a.download='kinex-benchmark-'+variant+'.csv';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000);
}
function showImage(index) {
  if(!imageItems.length)return;imageIndex=(index+imageItems.length)%imageItems.length;const item=imageItems[imageIndex];$('#large-image').src=item.url;$('#image-original').href=item.url;$('#image-caption').textContent=`${imageIndex+1} / ${imageItems.length} · ${item.label}`;if(!$('#image-viewer').open)$('#image-viewer').showModal();
}
$('#main').addEventListener('click',async event=>{
  const b=event.target.closest('button,a');if(!b)return;
  if(b.dataset.taskColumn || b.dataset.taskColumns){
    const id=b.dataset.taskColumn, wasEmpty=expandedTaskVariants.size===0;
    if(id){
      if(expandedTaskVariants.has(id))expandedTaskVariants.delete(id);else expandedTaskVariants.add(id);
      if(wasEmpty){filters.variant=id;$('#task-variant').value=id;}
    }else{
      expandedTaskVariants.clear();
      if(b.dataset.taskColumns==='all')data.variants.forEach(v=>expandedTaskVariants.add(v.id));
    }
    renderRows();
    if(b.classList.contains('column-close'))$(`[data-task-column="${id}"].task-column-toggle`).focus({preventScroll:true});
  }
  if(b.dataset.matrix){expandedModels=new Set($$('[data-model-group][open]').map(x=>x.dataset.modelGroup));matrixMetric=b.dataset.matrix;$('#comparison-mount').innerHTML=comparisonTable();}
  if(b.dataset.familyLink){filters.family=b.dataset.familyLink;filters.query='';filters.status='';if(location.hash==='#tasks'){overview();$('#tasks').scrollIntoView();}}
  if(b.dataset.reportFamily){filters.family=filters.family===b.dataset.reportFamily?'':b.dataset.reportFamily;$('#task-family').value=filters.family;$$('[data-report-family]').forEach(x=>x.classList.toggle('active',x.dataset.reportFamily===filters.family));renderRows();$('#tasks').scrollIntoView({behavior:'smooth'});}
  if(b.id==='reset-filters'||b.hasAttribute('data-reset'))resetFilters();
  if(b.dataset.export)exportCSV(b.dataset.export);
  if(b.dataset.instruction){$$('[data-instruction]').forEach(x=>x.setAttribute('aria-pressed',x===b));$$('.instruction-version').forEach(x=>x.hidden=x.id!=='instruction-'+b.dataset.instruction);}
  if(b.id==='final-frame'){const v=$('#episode-video');if(v.readyState<1)await new Promise(r=>v.addEventListener('loadedmetadata',r,{once:true}));v.pause();v.currentTime=Math.max(0,v.duration-.001);}
  if(b.dataset.sessionView){sessionState.view=b.dataset.sessionView;sessionState.count=40;$$('[data-session-view]').forEach(x=>x.setAttribute('aria-pressed',x===b));renderSession();}
  if(b.id==='more-events'){sessionState.count+=40;renderSession();}
  if(b.hasAttribute('data-image'))showImage(+b.dataset.image);
  if(b.hasAttribute('data-resource'))loadResource(+b.dataset.resource,epoch);
  if(b.hasAttribute('data-retry-session'))loadSession(current.ep,epoch);
  if(b.id==='copy-resource'){if(current.resourceText!=null){try{await navigator.clipboard.writeText(current.resourceText);showToast('File copied to clipboard');}catch{showToast('Copy unavailable. Use Open file to select the text.');}}}
});
$('#main').addEventListener('input',event=>{
  if(event.target.id==='task-search'){filters.query=event.target.value;renderRows();}
  if(event.target.id==='event-search'){sessionState.query=event.target.value;sessionState.count=40;renderSession();}
});
$('#main').addEventListener('change',async event=>{
  const {id,value}=event.target;
  if(id==='task-family'){filters.family=value;renderRows();$$('[data-report-family]').forEach(x=>x.classList.toggle('active',x.dataset.reportFamily===value));}
  if(id==='task-variant'){filters.variant=value;renderRows();}
  if(id==='task-status'){filters.status=value;renderRows();}
  if(id==='task-sort'){filters.sort=value;renderRows();}
  if(id==='playback-speed')$('#episode-video').playbackRate=Number(value);
  if(id==='event-filter'){sessionState.filter=value;sessionState.count=40;renderSession();}
  if(id==='evidence-select'){
    const preview=$('#evidence-preview'),token=epoch;preview.hidden=!value;if(!value)return;preview.textContent='Loading evidence…';
    try{const text=await fetchText(current.ep.links[value]);if(token!==epoch||$('#evidence-select').value!==value)return;try{preview.textContent=JSON.stringify(JSON.parse(text),null,2);}catch{preview.textContent=text;}}
    catch(e){if(token===epoch)preview.textContent='Preview unavailable: '+e.message;}
  }
});
$('#close-viewer').onclick=()=>$('#image-viewer').close();$('#previous-image').onclick=()=>showImage(imageIndex-1);$('#next-image').onclick=()=>showImage(imageIndex+1);
$('#image-viewer').addEventListener('click',event=>{if(event.target===$('#image-viewer'))$('#image-viewer').close();});
$('#image-viewer').addEventListener('keydown',event=>{if(event.key==='ArrowLeft'){event.preventDefault();showImage(imageIndex-1);}if(event.key==='ArrowRight'){event.preventDefault();showImage(imageIndex+1);}});
let catalogInstructionAudit={tasks:[],families:[]};
let measuredInstructions={episodes:{}};
let evidenceRoot = '';
const evidenceURL = path => {
  if (typeof path !== 'string' || !evidenceRoot || path.endsWith('.html')) return path;
  if (/^(?:experiments|official|policy-contract|research|data|history|probes|hard)\//.test(path) || /^[a-zA-Z0-9_-]+\.json$/.test(path)) return new URL(path, evidenceRoot).href;
  return path;
};
// Resolve published file references for display; downloaded evidence remains byte-identical.
function resolveEvidence(value) {
  if (typeof value === 'string') return evidenceURL(value);
  if (Array.isArray(value)) return value.map(resolveEvidence);
  if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, resolveEvidence(item)]));
  return value;
}
let resultFiles = {};
const resultURL = name => evidenceURL(resultFiles[name]?.url || name);
let policyRecord=null;
function policyShell(ep) {
 return `<section class="panel session-panel"><div class="section-heading"><div><h2>VLA input/output</h2><p>${number(ep.vla_calls)} recorded inferences · model inputs, action outputs and agent tool results.</p></div><div class="inline-links">${external(ep.links.vla_io,'All calls JSON')}${external(ep.links.policy_trace,'Original trace')}</div></div><div class="policy-body" id="policy-body">Loading recorded calls…</div></section>`;
}
async function loadPolicy(ep,token) {
 try {const response=await fetch(ep.links.vla_io);if(!response.ok)throw Error(response.status);const record=resolveEvidence(await response.json());if(token!==epoch)return;policyRecord=record;renderPolicy(0);}catch(e){if(token===epoch)$('#policy-body').textContent='Preview unavailable: '+e.message;}
}
function jsonBlock(title,value,open=false) {return `<details class="tool-block" ${open?'open':''}><summary>${esc(title)}</summary><pre>${esc(JSON.stringify(value,null,2))}</pre></details>`;}
function renderPolicy(index) {
 const record=policyRecord,c=record.calls[index],ep=current.ep;
 if(ep.provider==='robotwin-official')return renderOfficialPolicy(index);
 if(!c){$('#policy-body').innerHTML='<div class="empty-state">No VLA inference was made in this episode.</div>';return;}
 const images=c.images.map(im=>`<figure><a href="${esc(im.model_image)}" target="_blank"><img src="${esc(im.model_image)}" alt="${esc(im.camera)} model input, call ${index+1}"></a><figcaption>${esc(im.camera)} · ${im.model_size.join(' × ')}<br><a href="${esc(im.recorded)}" target="_blank">Recorded RGB · ${im.recorded_size.join(' × ')} ↗</a></figcaption></figure>`).join('');
 const caller=c.caller;
 const textParts=p=>(p||[]).filter(x=>x.type!=='image');
 const toolImages=caller?caller.tool_result.parts.filter(p=>p.type==='image').map(p=>{const url=new URL(p.src,new URL(ep.links.transcript,location.href)).href;return `<a href="${esc(url)}" target="_blank"><img src="${esc(url)}" alt="Observation returned to the language agent" style="width:240px;max-width:100%"></a>`;}).join(''):'';
 const cols=record.contract.output_layout;
 const response=c.service_response, actions=response?.waypoints||response?.actions||[];
 const timing=response?`${response.inference_s.toFixed(3)} s · ${actions.length} × ${actions[0]?.length||0} actions`:'No output recorded';
 $('#policy-body').innerHTML=`<label>Inference <select class="policy-select" id="policy-call" aria-label="VLA inference">${record.calls.map((x,i)=>`<option value="${i}" ${i===index?'selected':''}>${i+1} / ${record.calls.length} · ${x.call_id.slice(0,12)} · ${String(x.request.task||'').trim().toLowerCase().replace(/\s+/g,' ').replace(/[.!?]+$/,'')===String(ep.instruction||'').trim().toLowerCase().replace(/\s+/g,' ').replace(/[.!?]+$/,'')?'full task':'caller task'}</option>`).join('')}</select></label><div class="inline-links"><code>${esc(c.call_id)}</code><span>${timing}</span></div><h3>Caller-supplied condition text</h3><div class="instruction-text">${esc(c.request.task)}</div><div class="policy-images">${images}</div><p class="subtle">${esc(record.contract.image_preprocessing||"Model images follow the recorded checkpoint preprocessing.")} Additional information reaches the model only when present in the request and rendered language below.</p>${jsonBlock('Complete model-service request',c.request)}${c.model_input_text!==undefined?jsonBlock('Language passed to predict_action · recorded',c.model_input_text,true):''}${c.backbone_messages?jsonBlock('Backbone message · reconstructed from executed code',c.backbone_messages):''}<h3>Model-service output</h3><p class="subtle">${response?.waypoints?'Untimed joint waypoints consumed by the recorded caller. Kinex or agent-authored code determines their physical timing.':'The recorded action response consumed by the caller.'} Joint values are absolute radians; grippers use −1 open, +1 closed.</p><div class="policy-table"><table><thead><tr><th>Action</th>${cols.map(x=>`<th>${esc(x.replace('left_','L ').replace('right_','R '))}</th>`).join('')}</tr></thead><tbody>${actions.map((row,i)=>`<tr><th>${i+1}</th>${row.map(x=>`<td title="${x}">${x.toFixed(5)}</td>`).join('')}</tr>`).join('')}</tbody></table></div>${jsonBlock('Recorded model output · full precision',c.service_response)}${c.execution?jsonBlock('Actual execution · target count and world time',{executor:c.planner,...c.execution},true):''}${jsonBlock('Internal diagnostic · denormalized training-order actions',c.internal_diagnostics.denormalized_actions)}${caller?`<h3>Kinex tool call & result</h3><p class="subtle">This inference is joined to the recorded tool call and result below. Agent-authored code may consume the model output directly; the language agent receives the displayed tool response.</p>${jsonBlock('Agent tool call',caller.tool_call,true)}${jsonBlock('Tool result received by the language agent',{...caller.tool_result,parts:textParts(caller.tool_result.parts)},true)}<div class="inline-links">${toolImages}<a href="${taskRoute(ep.task_key,ep.variant,'session')}">Read the full session ↗</a><a href="${taskRoute(ep.task_key,ep.variant,'artifacts')}">Inspect agent artifacts ↗</a></div>${c.executed_tool_source?jsonBlock('Agent-authored code at this call',c.executed_tool_source):''}`:'<p class="subtle">An exact caller-to-inference join is unavailable. Inspect the recorded Kinex session and authored code.</p>'}<details class="tool-block"><summary>Recording coverage & model contract</summary><p>See the per-run contract below for recorded and reconstructed fields. Original requests and rendered language are retained in the current rich-input run; older runs have different recording coverage.</p><pre>${esc(JSON.stringify(record.contract,null,2))}</pre><div class="inline-links">${external(record.contract.model_metadata,'Model configuration')}${external(record.contract.executed_sources,'Executed source checksums')}${external(record.contract.model_service_source||'policy-contract/model_node.py','Model service')}${external(record.contract.adapter_source||'policy-contract/starvla.py','Policy adapter')}${external(record.contract.helper_source||'policy-contract/kinex_policy.py','Recorded sampling helper')}</div></details>`;
 $('#policy-call').onchange=e=>renderPolicy(Number(e.target.value));
}
function toolsShell(ep) {return `<section class="panel session-panel"><div class="section-heading"><div><h2>Tool calls</h2><p>Original tool inputs and outputs from the agent trace.</p></div>${external(ep.links.tool_calls,'Tool calls JSON')}</div><div class="policy-body" id="tools-body">Loading tool calls…</div></section>`;}
async function loadTools(ep,token) {
 try{const r=await fetch(ep.links.tool_calls);if(!r.ok)throw Error(r.status);const calls=await r.json();if(token!==epoch)return;$('#tools-body').innerHTML=calls.length?calls.map((c,i)=>`<details class="tool-block"><summary>${i+1} · ${esc(c.name)}${c.is_error?' · Error':''}</summary><p><code>${esc(c.call_id)}</code></p><h3>Input</h3><pre>${esc(JSON.stringify(c.input,null,2))}</pre><h3>Output</h3><pre>${esc(typeof c.output==='string'?c.output:JSON.stringify(c.output,null,2))}</pre></details>`).join(''):'<div class="empty-state">No language-agent tool calls in this episode.</div>';}catch(e){if(token===epoch)$('#tools-body').textContent='Preview unavailable: '+e.message;}
}

async function boot(){try{
const source=await fetch('data-source.json');if(!source.ok)throw Error('Result source unavailable');
const sourceConfig=await source.json();evidenceRoot=sourceConfig.evidence_root;resultFiles=sourceConfig.files;
document.querySelectorAll('[data-result-file]').forEach(link=>{link.href=resultURL(link.dataset.resultFile);});
const r=await fetch(resultURL('data.json'));if(!r.ok)throw Error('HTTP '+r.status);data=resolveEvidence(await r.json());
for(const variant of data.variants)if(variant.id==='kinex')variant.label='Kinex';
const vr=await fetch('../agent-versions.json');if(!vr.ok)throw Error('Agent versions unavailable');agentVersions=await vr.json();
const ir=await fetch(resultURL('measured-instructions.json'));if(!ir.ok)throw Error('Instruction evidence unavailable');measuredInstructions=resolveEvidence(await ir.json());
const nr=await fetch('../instruction-audit/hard.json');if(!nr.ok)throw Error('Instruction audit unavailable');catalogInstructionAudit=await nr.json();
try{const c=await fetch(resultURL('cost-data.json'));if(c.ok)UsageMetrics.init(resolveEvidence(await c.json()));}catch{UsageMetrics.init({episodes:{},sources:[]});}
for(const task of data.tasks){
  if(task.family==='task02'){
    const {suite_name,task_id}=task.native_identity;
    task.title=`LIBERO-${suite_name.replace(/^libero_/, '')}-${String(task_id+1).padStart(2,'0')}`;
  }
}
window.benchmarkData=data;$('#updated').textContent='Results updated '+data.updated_at.slice(0,10);window.addEventListener('hashchange',route);route();}catch(e){$('#main').innerHTML=`<div class="empty-state"><h2>Results could not load</h2><p>${esc(e.message)}</p><a href="${esc(resultURL('data.json'))}">Download the results index</a></div>`;}}
boot();

function renderOfficialPolicy(index) {
 const r=policyRecord,c=r.calls[index],ep=current.ep;
 const ims=c.images.map(im=>`<figure><a href="${esc(im.model_image)}" target="_blank"><img src="${esc(im.model_image)}" alt="${esc(im.camera)} model input"></a><figcaption>${esc(im.camera)} · ${im.model_size.join(' × ')}<br><a href="${esc(im.recorded)}" target="_blank">Recorded RGB · ${im.recorded_size.join(' × ')} ↗</a></figcaption></figure>`).join('');
 $('#policy-body').innerHTML=`<label>Inference <select class="policy-select" id="policy-call" aria-label="VLA inference">${r.calls.map((x,i)=>`<option value="${i}" ${i===index?'selected':''}>${i+1} / ${r.calls.length} · action ${x.native_step}</option>`).join('')}</select></label><div class="inline-links"><code>${esc(c.call_id)}</code><span>${c.service_response.inference_s.toFixed(3)} s · ${(c.service_response.waypoints||c.service_response.actions).length} × ${(c.service_response.waypoints||c.service_response.actions)[0].length} actions</span></div><h3>Task instruction</h3><div class="instruction-text">${esc(c.request.task)}</div><div class="policy-images">${ims}</div><p class="subtle">Exact transmitted RGB pixels. No joint state or agent conversation is passed to the VLA.</p>${jsonBlock('Complete model request · image arrays linked as PNGs',c.request.wire_payload)}<h3>Native action chunk</h3><p class="subtle">Reordered model output consumed by the official evaluator. Absolute joint radians; gripper opening: 0 closed, 1 open.</p><div class="policy-table"><table><thead><tr><th>Action</th>${r.contract.output_layout.map(x=>`<th>${esc(x.replace('left_','L ').replace('right_','R '))}</th>`).join('')}</tr></thead><tbody>${(c.service_response.waypoints||c.service_response.actions).map((row,i)=>`<tr><th>${i+1}</th>${row.map(x=>`<td title="${x}">${x.toFixed(5)}</td>`).join('')}</tr>`).join('')}</tbody></table></div>${jsonBlock('Complete recorded StarVLA response · full precision',c.raw_response)}${jsonBlock('Reordered native actions · full precision',c.service_response.actions)}<p class="subtle">Standalone execution; no language-agent session or tool call. Token and API costs cover the language agent only; local GPU cost is not reported.</p>${jsonBlock('Recording coverage & model contract',r.contract)}<div class="inline-links">${external(r.contract.model_metadata,'Model configuration')}${external(r.contract.executed_sources,'Source identities')}${external(r.contract.adapter_source||'official/adapters.py','Policy adapter')}${external(r.contract.integration_source||'official/integrations.py','Official evaluator integration')}</div>`;
 $('#policy-call').onchange=e=>renderPolicy(Number(e.target.value));
}