luca 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,725 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Luca Dataset Review UI</title>
7
+ <style>
8
+ :root {
9
+ --bg: #0b1020;
10
+ --panel: #121a30;
11
+ --panel-2: #18223f;
12
+ --text: #e7ecff;
13
+ --muted: #9db0e0;
14
+ --accent: #72a1ff;
15
+ --good: #33c27f;
16
+ --warn: #f0b24a;
17
+ --bad: #ef6b73;
18
+ --border: #2b3967;
19
+ }
20
+ * { box-sizing: border-box; }
21
+ body {
22
+ margin: 0;
23
+ font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
24
+ background: var(--bg);
25
+ color: var(--text);
26
+ }
27
+ .app {
28
+ display: grid;
29
+ grid-template-columns: 340px 1fr;
30
+ min-height: 100vh;
31
+ }
32
+ .sidebar, .main {
33
+ padding: 16px;
34
+ }
35
+ .sidebar {
36
+ border-right: 1px solid var(--border);
37
+ background: linear-gradient(180deg, #0d1428, #0b1020);
38
+ position: sticky;
39
+ top: 0;
40
+ height: 100vh;
41
+ overflow: auto;
42
+ }
43
+ .main {
44
+ display: grid;
45
+ gap: 16px;
46
+ align-content: start;
47
+ }
48
+ h1, h2, h3 {
49
+ margin: 0 0 8px;
50
+ line-height: 1.2;
51
+ }
52
+ p { color: var(--muted); }
53
+ .panel {
54
+ background: var(--panel);
55
+ border: 1px solid var(--border);
56
+ border-radius: 12px;
57
+ padding: 14px;
58
+ box-shadow: 0 8px 24px rgba(0,0,0,.22);
59
+ }
60
+ .row {
61
+ display: grid;
62
+ grid-template-columns: repeat(2, minmax(0, 1fr));
63
+ gap: 12px;
64
+ }
65
+ .row-3 {
66
+ display: grid;
67
+ grid-template-columns: repeat(3, minmax(0, 1fr));
68
+ gap: 12px;
69
+ }
70
+ label {
71
+ display: block;
72
+ font-size: 12px;
73
+ color: var(--muted);
74
+ margin-bottom: 6px;
75
+ }
76
+ input[type="text"], textarea, select {
77
+ width: 100%;
78
+ background: var(--panel-2);
79
+ border: 1px solid var(--border);
80
+ color: var(--text);
81
+ border-radius: 10px;
82
+ padding: 10px 12px;
83
+ font: inherit;
84
+ }
85
+ textarea { min-height: 96px; resize: vertical; }
86
+ button {
87
+ background: var(--accent);
88
+ color: white;
89
+ border: 0;
90
+ border-radius: 10px;
91
+ padding: 10px 14px;
92
+ font-weight: 600;
93
+ cursor: pointer;
94
+ }
95
+ button.secondary {
96
+ background: #243660;
97
+ color: var(--text);
98
+ }
99
+ button.warn { background: var(--warn); color: #111; }
100
+ button.good { background: var(--good); }
101
+ button.bad { background: var(--bad); }
102
+ .button-row {
103
+ display: flex;
104
+ flex-wrap: wrap;
105
+ gap: 8px;
106
+ }
107
+ .meta {
108
+ display: flex;
109
+ flex-wrap: wrap;
110
+ gap: 8px;
111
+ margin: 8px 0 0;
112
+ }
113
+ .chip {
114
+ border: 1px solid var(--border);
115
+ background: #101831;
116
+ color: var(--text);
117
+ border-radius: 999px;
118
+ padding: 4px 10px;
119
+ font-size: 12px;
120
+ white-space: nowrap;
121
+ }
122
+ .chip.good { border-color: rgba(51,194,127,.4); color: #bdf2d8; }
123
+ .chip.warn { border-color: rgba(240,178,74,.4); color: #ffe0aa; }
124
+ .chip.bad { border-color: rgba(239,107,115,.4); color: #ffc0c4; }
125
+ .candidate-list {
126
+ display: grid;
127
+ gap: 8px;
128
+ margin-top: 12px;
129
+ }
130
+ .candidate-item {
131
+ padding: 10px;
132
+ border: 1px solid var(--border);
133
+ border-radius: 10px;
134
+ background: #0f1730;
135
+ cursor: pointer;
136
+ }
137
+ .candidate-item.active {
138
+ border-color: var(--accent);
139
+ outline: 1px solid var(--accent);
140
+ }
141
+ .candidate-item .title {
142
+ font-weight: 700;
143
+ font-size: 13px;
144
+ margin-bottom: 4px;
145
+ }
146
+ .candidate-item .subtitle {
147
+ font-size: 12px;
148
+ color: var(--muted);
149
+ line-height: 1.35;
150
+ }
151
+ .kvs {
152
+ display: grid;
153
+ grid-template-columns: 180px 1fr;
154
+ gap: 8px 12px;
155
+ font-size: 14px;
156
+ }
157
+ .kvs .k {
158
+ color: var(--muted);
159
+ font-weight: 600;
160
+ }
161
+ pre {
162
+ margin: 0;
163
+ white-space: pre-wrap;
164
+ word-break: break-word;
165
+ background: #0c1328;
166
+ border: 1px solid var(--border);
167
+ border-radius: 10px;
168
+ padding: 10px;
169
+ color: #d6e1ff;
170
+ }
171
+ .snippet-list {
172
+ display: grid;
173
+ gap: 8px;
174
+ }
175
+ .hint {
176
+ font-size: 12px;
177
+ color: var(--muted);
178
+ }
179
+ .statline {
180
+ display: flex;
181
+ gap: 10px;
182
+ flex-wrap: wrap;
183
+ font-size: 13px;
184
+ color: var(--muted);
185
+ }
186
+ .statline strong { color: var(--text); }
187
+ @media (max-width: 980px) {
188
+ .app { grid-template-columns: 1fr; }
189
+ .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
190
+ .row, .row-3 { grid-template-columns: 1fr; }
191
+ .kvs { grid-template-columns: 1fr; }
192
+ }
193
+ </style>
194
+ </head>
195
+ <body>
196
+ <div class="app">
197
+ <aside class="sidebar">
198
+ <div class="panel">
199
+ <h1>Luca review UI</h1>
200
+ <p>Load review-batch-1.jsonl or review-queue.jsonl, then label rows and export review records as JSONL.</p>
201
+ <div class="button-row">
202
+ <button id="loadBatchBtn">Load review-batch-1.jsonl</button>
203
+ <button class="secondary" id="loadQueueBtn">Load review-queue.jsonl</button>
204
+ </div>
205
+ <div style="margin-top:10px;">
206
+ <label for="fileInput">Or load a local JSONL file</label>
207
+ <input id="fileInput" type="file" accept=".jsonl,.json" />
208
+ </div>
209
+ <div style="margin-top:10px;">
210
+ <label for="basePathInput">Base directory</label>
211
+ <input id="basePathInput" type="text" value="./" />
212
+ <div class="hint">When serving this file from the repo, ./ should work. If not, enter the folder that contains the review JSONL files.</div>
213
+ </div>
214
+ </div>
215
+
216
+ <div class="panel" style="margin-top:16px;">
217
+ <h2>Progress</h2>
218
+ <div class="statline" id="progressStats"></div>
219
+ <div style="margin-top:10px;">
220
+ <label for="filterSelect">Filter</label>
221
+ <select id="filterSelect">
222
+ <option value="all">All</option>
223
+ <option value="unreviewed">Unreviewed</option>
224
+ <option value="reviewed">Reviewed</option>
225
+ <option value="canonical-policy">Canonical-policy guess</option>
226
+ <option value="planning">Planning guess</option>
227
+ <option value="strong-implementation">Strong-implementation guess</option>
228
+ <option value="rejects">Reject guess</option>
229
+ </select>
230
+ </div>
231
+ <div style="margin-top:10px;">
232
+ <label for="searchInput">Search</label>
233
+ <input id="searchInput" type="text" placeholder="session id, repo, helper, command..." />
234
+ </div>
235
+ </div>
236
+
237
+ <div class="panel" style="margin-top:16px;">
238
+ <div class="button-row">
239
+ <button class="good" id="exportBtn">Export reviews JSONL</button>
240
+ <button class="secondary" id="saveLocalBtn">Save state</button>
241
+ <button class="secondary" id="restoreLocalBtn">Restore state</button>
242
+ <button class="warn" id="clearLocalBtn">Clear saved state</button>
243
+ </div>
244
+ <div class="hint" style="margin-top:10px;">State is stored in localStorage under luca-review-ui-state.</div>
245
+ </div>
246
+
247
+ <div class="candidate-list" id="candidateList"></div>
248
+ </aside>
249
+
250
+ <main class="main">
251
+ <section class="panel">
252
+ <h2 id="detailTitle">No dataset loaded</h2>
253
+ <div class="meta" id="detailChips"></div>
254
+ <div class="kvs" style="margin-top:12px;" id="detailMeta"></div>
255
+ </section>
256
+
257
+ <section class="panel">
258
+ <h3>Summary</h3>
259
+ <pre id="summaryPre">Load a batch to begin.</pre>
260
+ </section>
261
+
262
+ <section class="panel">
263
+ <h3>Signals</h3>
264
+ <div class="row-3">
265
+ <div>
266
+ <label>Positive signals</label>
267
+ <pre id="positivePre"></pre>
268
+ </div>
269
+ <div>
270
+ <label>Negative signals</label>
271
+ <pre id="negativePre"></pre>
272
+ </div>
273
+ <div>
274
+ <label>Policy / verification</label>
275
+ <pre id="policyPre"></pre>
276
+ </div>
277
+ </div>
278
+ </section>
279
+
280
+ <section class="panel">
281
+ <h3>Snippets</h3>
282
+ <div class="snippet-list" id="snippetList"></div>
283
+ </section>
284
+
285
+ <section class="panel">
286
+ <h3>Author review</h3>
287
+ <div class="row-3">
288
+ <div>
289
+ <label for="reviewerInput">Reviewer</label>
290
+ <input id="reviewerInput" type="text" placeholder="jon" />
291
+ </div>
292
+ <div>
293
+ <label for="canonicalityInput">Canonicality</label>
294
+ <select id="canonicalityInput">
295
+ <option value=""></option>
296
+ <option value="canonical">canonical</option>
297
+ <option value="acceptable">acceptable</option>
298
+ <option value="off-policy">off-policy</option>
299
+ </select>
300
+ </div>
301
+ <div>
302
+ <label for="policyValueInput">Policy value</label>
303
+ <select id="policyValueInput">
304
+ <option value=""></option>
305
+ <option value="high">high</option>
306
+ <option value="medium">medium</option>
307
+ <option value="low">low</option>
308
+ </select>
309
+ </div>
310
+ <div>
311
+ <label for="codeTasteInput">Code taste</label>
312
+ <select id="codeTasteInput">
313
+ <option value=""></option>
314
+ <option value="strong">strong</option>
315
+ <option value="mixed">mixed</option>
316
+ <option value="weak">weak</option>
317
+ </select>
318
+ </div>
319
+ <div>
320
+ <label for="verificationQualityInput">Verification quality</label>
321
+ <select id="verificationQualityInput">
322
+ <option value=""></option>
323
+ <option value="strong">strong</option>
324
+ <option value="weak">weak</option>
325
+ <option value="none">none</option>
326
+ </select>
327
+ </div>
328
+ <div>
329
+ <label for="dispositionInput">Disposition</label>
330
+ <select id="dispositionInput">
331
+ <option value=""></option>
332
+ <option value="keep">keep</option>
333
+ <option value="rewrite">rewrite</option>
334
+ <option value="reject">reject</option>
335
+ </select>
336
+ </div>
337
+ <div>
338
+ <label for="bucketInput">Bucket</label>
339
+ <select id="bucketInput">
340
+ <option value=""></option>
341
+ <option value="canonical-policy">canonical-policy</option>
342
+ <option value="strong-implementation">strong-implementation</option>
343
+ <option value="planning">planning</option>
344
+ <option value="rejects">rejects</option>
345
+ </select>
346
+ </div>
347
+ </div>
348
+
349
+ <div class="row" style="margin-top:12px;">
350
+ <div>
351
+ <label for="positiveSignalsInput">Positive signals</label>
352
+ <textarea id="positiveSignalsInput" placeholder="One per line"></textarea>
353
+ </div>
354
+ <div>
355
+ <label for="negativeSignalsInput">Negative signals</label>
356
+ <textarea id="negativeSignalsInput" placeholder="One per line"></textarea>
357
+ </div>
358
+ </div>
359
+
360
+ <div class="row" style="margin-top:12px;">
361
+ <div>
362
+ <label for="whyKeepInput">Why keep</label>
363
+ <textarea id="whyKeepInput"></textarea>
364
+ </div>
365
+ <div>
366
+ <label for="whyRejectInput">Why reject</label>
367
+ <textarea id="whyRejectInput"></textarea>
368
+ </div>
369
+ </div>
370
+
371
+ <div style="margin-top:12px;">
372
+ <label for="rewriteBriefInput">Rewrite brief</label>
373
+ <textarea id="rewriteBriefInput"></textarea>
374
+ </div>
375
+
376
+ <div style="margin-top:12px;">
377
+ <label for="notesInput">Notes</label>
378
+ <textarea id="notesInput"></textarea>
379
+ </div>
380
+
381
+ <div class="button-row" style="margin-top:12px;">
382
+ <button class="good" id="saveReviewBtn">Save review</button>
383
+ <button class="secondary" id="copyReviewBtn">Copy current review JSON</button>
384
+ <button class="secondary" id="nextBtn">Next</button>
385
+ </div>
386
+ </section>
387
+ </main>
388
+ </div>
389
+
390
+ <script>
391
+ const state = {
392
+ candidates: [],
393
+ reviews: {},
394
+ selectedIndex: 0,
395
+ datasetName: '',
396
+ };
397
+
398
+ const els = {
399
+ candidateList: document.getElementById('candidateList'),
400
+ progressStats: document.getElementById('progressStats'),
401
+ filterSelect: document.getElementById('filterSelect'),
402
+ searchInput: document.getElementById('searchInput'),
403
+ detailTitle: document.getElementById('detailTitle'),
404
+ detailChips: document.getElementById('detailChips'),
405
+ detailMeta: document.getElementById('detailMeta'),
406
+ summaryPre: document.getElementById('summaryPre'),
407
+ positivePre: document.getElementById('positivePre'),
408
+ negativePre: document.getElementById('negativePre'),
409
+ policyPre: document.getElementById('policyPre'),
410
+ snippetList: document.getElementById('snippetList'),
411
+ basePathInput: document.getElementById('basePathInput'),
412
+ fileInput: document.getElementById('fileInput'),
413
+ reviewerInput: document.getElementById('reviewerInput'),
414
+ canonicalityInput: document.getElementById('canonicalityInput'),
415
+ policyValueInput: document.getElementById('policyValueInput'),
416
+ codeTasteInput: document.getElementById('codeTasteInput'),
417
+ verificationQualityInput: document.getElementById('verificationQualityInput'),
418
+ dispositionInput: document.getElementById('dispositionInput'),
419
+ bucketInput: document.getElementById('bucketInput'),
420
+ positiveSignalsInput: document.getElementById('positiveSignalsInput'),
421
+ negativeSignalsInput: document.getElementById('negativeSignalsInput'),
422
+ whyKeepInput: document.getElementById('whyKeepInput'),
423
+ whyRejectInput: document.getElementById('whyRejectInput'),
424
+ rewriteBriefInput: document.getElementById('rewriteBriefInput'),
425
+ notesInput: document.getElementById('notesInput'),
426
+ };
427
+
428
+ function splitLines(text) {
429
+ return text.split('\n').map(s => s.trim()).filter(Boolean);
430
+ }
431
+
432
+ function joinLines(arr) {
433
+ return (arr || []).join('\n');
434
+ }
435
+
436
+ function currentCandidate() {
437
+ return state.candidates[state.selectedIndex] || null;
438
+ }
439
+
440
+ function currentReviewKey(candidate) {
441
+ return candidate ? `${candidate.source_repo}:${candidate.session_id}` : null;
442
+ }
443
+
444
+ function getReview(candidate) {
445
+ const key = currentReviewKey(candidate);
446
+ return key ? state.reviews[key] || null : null;
447
+ }
448
+
449
+ function setReview(candidate, review) {
450
+ const key = currentReviewKey(candidate);
451
+ if (key) state.reviews[key] = review;
452
+ }
453
+
454
+ function filteredCandidates() {
455
+ const filter = els.filterSelect.value;
456
+ const query = els.searchInput.value.trim().toLowerCase();
457
+ return state.candidates.filter(candidate => {
458
+ const key = currentReviewKey(candidate);
459
+ const reviewed = Boolean(state.reviews[key]);
460
+ const haystack = JSON.stringify(candidate).toLowerCase();
461
+ if (query && !haystack.includes(query)) return false;
462
+ if (filter === 'all') return true;
463
+ if (filter === 'unreviewed') return !reviewed;
464
+ if (filter === 'reviewed') return reviewed;
465
+ return candidate.bucket_guess === filter;
466
+ });
467
+ }
468
+
469
+ function renderList() {
470
+ const items = filteredCandidates();
471
+ els.candidateList.innerHTML = '';
472
+ items.forEach(candidate => {
473
+ const key = currentReviewKey(candidate);
474
+ const reviewed = Boolean(state.reviews[key]);
475
+ const div = document.createElement('div');
476
+ div.className = 'candidate-item';
477
+ if (candidate === currentCandidate()) div.classList.add('active');
478
+ div.innerHTML = `
479
+ <div class="title">#${candidate.rank} ${candidate.session_id}</div>
480
+ <div class="subtitle">${candidate.source_repo} • ${candidate.task_type} • ${candidate.bucket_guess}</div>
481
+ <div class="subtitle">${candidate.summary}</div>
482
+ <div class="meta" style="margin-top:8px;">
483
+ <span class="chip ${reviewed ? 'good' : ''}">${reviewed ? 'reviewed' : 'unreviewed'}</span>
484
+ <span class="chip">score ${candidate.review_score}</span>
485
+ <span class="chip">${candidate.quality_tier}</span>
486
+ </div>
487
+ `;
488
+ div.onclick = () => {
489
+ const globalIndex = state.candidates.findIndex(c => c.session_id === candidate.session_id && c.source_repo === candidate.source_repo);
490
+ state.selectedIndex = globalIndex;
491
+ renderAll();
492
+ };
493
+ els.candidateList.appendChild(div);
494
+ });
495
+ renderStats(items.length);
496
+ }
497
+
498
+ function renderStats(filteredCount) {
499
+ const reviewed = Object.keys(state.reviews).length;
500
+ els.progressStats.innerHTML = `
501
+ <span><strong>${state.candidates.length}</strong> loaded</span>
502
+ <span><strong>${filteredCount}</strong> shown</span>
503
+ <span><strong>${reviewed}</strong> reviewed</span>
504
+ <span><strong>${Math.max(state.candidates.length - reviewed, 0)}</strong> remaining</span>
505
+ `;
506
+ }
507
+
508
+ function renderDetail() {
509
+ const candidate = currentCandidate();
510
+ if (!candidate) {
511
+ els.detailTitle.textContent = 'No dataset loaded';
512
+ return;
513
+ }
514
+ els.detailTitle.textContent = `${candidate.rank}. ${candidate.session_id}`;
515
+ els.detailChips.innerHTML = [
516
+ candidate.source_repo,
517
+ candidate.task_type,
518
+ candidate.quality_tier,
519
+ candidate.bucket_guess,
520
+ candidate.suggested_disposition,
521
+ candidate.canonicality_guess,
522
+ ].map(v => `<span class="chip">${v}</span>`).join('');
523
+
524
+ const metaRows = [
525
+ ['Branch', candidate.branch || '—'],
526
+ ['Review score', String(candidate.review_score)],
527
+ ['Commands', (candidate.commands_run || []).join(', ') || '—'],
528
+ ['Tests', (candidate.tests_run || []).join('\n') || '—'],
529
+ ['Helpers', (candidate.relevant_helpers || []).join(', ') || '—'],
530
+ ['Changed files', (candidate.changed_files || []).join('\n') || '—'],
531
+ ['Path', candidate.candidate_path],
532
+ ];
533
+ els.detailMeta.innerHTML = metaRows.map(([k, v]) => `<div class="k">${k}</div><div>${String(v).replace(/\n/g, '<br>')}</div>`).join('');
534
+ els.summaryPre.textContent = candidate.summary || '';
535
+ els.positivePre.textContent = joinLines(candidate.positive_signals || []);
536
+ els.negativePre.textContent = joinLines(candidate.negative_signals || []);
537
+ els.policyPre.textContent = joinLines([...(candidate.policy_signals || []), ...(candidate.verification_signals || [])]);
538
+
539
+ els.snippetList.innerHTML = '';
540
+ (candidate.snippets || []).forEach(snippet => {
541
+ const pre = document.createElement('pre');
542
+ pre.textContent = snippet;
543
+ els.snippetList.appendChild(pre);
544
+ });
545
+ }
546
+
547
+ function loadReviewForm() {
548
+ const candidate = currentCandidate();
549
+ const review = getReview(candidate) || {
550
+ session_id: candidate?.session_id,
551
+ source_repo: candidate?.source_repo,
552
+ candidate_path: candidate?.candidate_path,
553
+ reviewer: '',
554
+ canonicality: '',
555
+ policy_value: '',
556
+ code_taste: '',
557
+ verification_quality: '',
558
+ disposition: '',
559
+ bucket: candidate?.bucket_guess || '',
560
+ positive_signals: candidate?.positive_signals || [],
561
+ negative_signals: candidate?.negative_signals || [],
562
+ commands_run: candidate?.commands_run || [],
563
+ relevant_helpers: candidate?.relevant_helpers || [],
564
+ changed_files: candidate?.changed_files || [],
565
+ first_instruction: candidate?.first_instruction || '',
566
+ task_type: candidate?.task_type || '',
567
+ why_keep: '',
568
+ why_reject: '',
569
+ rewrite_brief: '',
570
+ notes: '',
571
+ };
572
+
573
+ els.reviewerInput.value = review.reviewer || '';
574
+ els.canonicalityInput.value = review.canonicality || '';
575
+ els.policyValueInput.value = review.policy_value || '';
576
+ els.codeTasteInput.value = review.code_taste || '';
577
+ els.verificationQualityInput.value = review.verification_quality || '';
578
+ els.dispositionInput.value = review.disposition || '';
579
+ els.bucketInput.value = review.bucket || '';
580
+ els.positiveSignalsInput.value = joinLines(review.positive_signals || []);
581
+ els.negativeSignalsInput.value = joinLines(review.negative_signals || []);
582
+ els.whyKeepInput.value = review.why_keep || '';
583
+ els.whyRejectInput.value = review.why_reject || '';
584
+ els.rewriteBriefInput.value = review.rewrite_brief || '';
585
+ els.notesInput.value = review.notes || '';
586
+ }
587
+
588
+ function saveCurrentReview() {
589
+ const candidate = currentCandidate();
590
+ if (!candidate) return;
591
+ const review = {
592
+ session_id: candidate.session_id,
593
+ source_repo: candidate.source_repo,
594
+ candidate_path: candidate.candidate_path,
595
+ reviewer: els.reviewerInput.value.trim(),
596
+ reviewed_at: new Date().toISOString(),
597
+ first_instruction: candidate.first_instruction || '',
598
+ task_type: candidate.task_type || '',
599
+ canonicality: els.canonicalityInput.value,
600
+ policy_value: els.policyValueInput.value,
601
+ code_taste: els.codeTasteInput.value,
602
+ verification_quality: els.verificationQualityInput.value,
603
+ disposition: els.dispositionInput.value,
604
+ bucket: els.bucketInput.value,
605
+ positive_signals: splitLines(els.positiveSignalsInput.value),
606
+ negative_signals: splitLines(els.negativeSignalsInput.value),
607
+ commands_run: candidate.commands_run || [],
608
+ relevant_helpers: candidate.relevant_helpers || [],
609
+ changed_files: candidate.changed_files || [],
610
+ why_keep: els.whyKeepInput.value.trim(),
611
+ why_reject: els.whyRejectInput.value.trim(),
612
+ rewrite_brief: els.rewriteBriefInput.value.trim(),
613
+ notes: els.notesInput.value.trim(),
614
+ };
615
+ setReview(candidate, review);
616
+ persistState();
617
+ renderAll();
618
+ }
619
+
620
+ function exportReviews() {
621
+ const rows = Object.values(state.reviews);
622
+ const blob = new Blob([rows.map(row => JSON.stringify(row)).join('\n') + '\n'], { type: 'application/jsonl' });
623
+ const a = document.createElement('a');
624
+ a.href = URL.createObjectURL(blob);
625
+ a.download = `${state.datasetName || 'luca-review'}-reviews.jsonl`;
626
+ a.click();
627
+ URL.revokeObjectURL(a.href);
628
+ }
629
+
630
+ function copyCurrentReview() {
631
+ const candidate = currentCandidate();
632
+ if (!candidate) return;
633
+ saveCurrentReview();
634
+ const review = getReview(candidate);
635
+ navigator.clipboard.writeText(JSON.stringify(review, null, 2));
636
+ }
637
+
638
+ function persistState() {
639
+ localStorage.setItem('luca-review-ui-state', JSON.stringify({
640
+ reviews: state.reviews,
641
+ datasetName: state.datasetName,
642
+ }));
643
+ }
644
+
645
+ function restoreState() {
646
+ const raw = localStorage.getItem('luca-review-ui-state');
647
+ if (!raw) return;
648
+ try {
649
+ const parsed = JSON.parse(raw);
650
+ state.reviews = parsed.reviews || {};
651
+ state.datasetName = parsed.datasetName || state.datasetName;
652
+ } catch (err) {
653
+ console.error(err);
654
+ }
655
+ renderAll();
656
+ }
657
+
658
+ function clearState() {
659
+ localStorage.removeItem('luca-review-ui-state');
660
+ state.reviews = {};
661
+ renderAll();
662
+ }
663
+
664
+ function renderAll() {
665
+ renderList();
666
+ renderDetail();
667
+ loadReviewForm();
668
+ }
669
+
670
+ function parseJsonl(text) {
671
+ return text.split('\n').map(line => line.trim()).filter(Boolean).map(line => JSON.parse(line));
672
+ }
673
+
674
+ async function loadDatasetFromPath(path) {
675
+ const res = await fetch(path);
676
+ if (!res.ok) throw new Error(`Failed to load ${path}: ${res.status}`);
677
+ const text = await res.text();
678
+ state.candidates = parseJsonl(text);
679
+ state.selectedIndex = 0;
680
+ state.datasetName = path.split('/').pop().replace(/\.jsonl$/, '');
681
+ renderAll();
682
+ }
683
+
684
+ function loadDatasetFromText(text, name = 'manual-load') {
685
+ state.candidates = parseJsonl(text);
686
+ state.selectedIndex = 0;
687
+ state.datasetName = name;
688
+ renderAll();
689
+ }
690
+
691
+ document.getElementById('loadBatchBtn').onclick = async () => {
692
+ const base = els.basePathInput.value || './';
693
+ await loadDatasetFromPath(base.replace(/\/?$/, '/') + 'review-batch-1.jsonl');
694
+ };
695
+
696
+ document.getElementById('loadQueueBtn').onclick = async () => {
697
+ const base = els.basePathInput.value || './';
698
+ await loadDatasetFromPath(base.replace(/\/?$/, '/') + 'review-queue.jsonl');
699
+ };
700
+
701
+ els.fileInput.onchange = async (event) => {
702
+ const file = event.target.files[0];
703
+ if (!file) return;
704
+ const text = await file.text();
705
+ loadDatasetFromText(text, file.name.replace(/\.jsonl$/, ''));
706
+ };
707
+
708
+ document.getElementById('saveReviewBtn').onclick = saveCurrentReview;
709
+ document.getElementById('exportBtn').onclick = exportReviews;
710
+ document.getElementById('copyReviewBtn').onclick = copyCurrentReview;
711
+ document.getElementById('saveLocalBtn').onclick = () => { saveCurrentReview(); persistState(); };
712
+ document.getElementById('restoreLocalBtn').onclick = restoreState;
713
+ document.getElementById('clearLocalBtn').onclick = clearState;
714
+ document.getElementById('nextBtn').onclick = () => {
715
+ saveCurrentReview();
716
+ if (state.selectedIndex < state.candidates.length - 1) state.selectedIndex += 1;
717
+ renderAll();
718
+ };
719
+ els.filterSelect.onchange = renderAll;
720
+ els.searchInput.oninput = renderAll;
721
+
722
+ restoreState();
723
+ </script>
724
+ </body>
725
+ </html>