#!/usr/bin/env node // Rebuild bench/runs/index.json from the run files. Parallel agents must not // read-modify-write a shared index; they write their own run file and the // index is regenerated here (the batch runner calls this periodically). import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'; import { resolve } from 'node:path'; export function rebuildIndex(dir = resolve('bench/runs')) { if (!existsSync(dir)) return []; const index = []; for (const f of readdirSync(dir)) { if (!f.endsWith('.json') || f === 'index.json') continue; try { const r = JSON.parse(readFileSync(resolve(dir, f), 'utf8')); index.push({ run: r.run, level: r.level.id, persona: r.persona, model: r.model, peek: r.peek, status: r.status, steps: r.steps.length, updatedAt: r.updatedAt }); } catch { /* a file being written right now; next rebuild picks it up */ } } index.sort((a, b) => (b.updatedAt || '').localeCompare(a.updatedAt || '')); writeFileSync(resolve(dir, 'index.json'), JSON.stringify(index, null, 1)); return index; } if (process.argv[1] && process.argv[1].endsWith('bench-index.mjs')) { const index = rebuildIndex(); console.log(`index.json · ${index.length} 局`); }