Files
Agent-Workbench/docs/project-cache-f-release-evidence/0171-inspect-cache-ui-failure.mjs
T
2026-11-01 09:31:00 +08:00

22 lines
2.2 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { DatabaseSync } from 'node:sqlite';
const hosts = fs.readdirSync('.qa', { withFileTypes: true }).filter(row => row.isDirectory() && row.name.startsWith('ui-host-verify-ui-')).map(row => ({ root: path.resolve('.qa', row.name), at: fs.statSync(path.join('.qa', row.name)).birthtimeMs })).sort((a, b) => b.at - a.at);
const owned = hosts[0]; assert.ok(owned && fs.existsSync(path.join(owned.root, 'workbench.sqlite')));
const db = new DatabaseSync(path.join(owned.root, 'workbench.sqlite'), { readOnly: true });
try {
const rowKeys = {};
for (const table of ['sessions', 'events', 'records']) {
const rows = db.prepare('SELECT * FROM ' + table + ' ORDER BY rowid').all();
rowKeys[table] = rows.length ? Object.keys(rows[0]) : [];
}
const sessions = db.prepare('SELECT payload FROM sessions').all().map(row => { const value = JSON.parse(row.payload); return { id: value.id, title: value.title, status: value.status, updatedAt: value.updatedAt }; });
const events = db.prepare('SELECT created_at,payload FROM events ORDER BY seq').all().map(row => { const value = JSON.parse(row.payload); return { at: row.created_at, type: value.type, kind: value.kind, phase: value.phase, label: value.label, keys: Object.keys(value), status: value.status }; });
const tools = db.prepare("SELECT kind,status,payload FROM records WHERE kind LIKE '%tool%'").all().map(row => { const value = JSON.parse(row.payload); return { kind: row.kind, status: row.status, id: value.id, tool: value.tool, command: value.command, arguments: value.arguments }; });
const resumed = events.findLastIndex(row => row.status === 'awaiting_approval'), running = events.slice(resumed + 1).find(row => row.status === 'running'), review = events.find(row => row.status === 'needs_review');
const result = { ownedRoot: owned.root, rowKeys, sessions, events, tools, afterApprovalToReviewMs: Date.parse(review.at) - Date.parse(running.at) };
fs.writeFileSync('.qa/cache-ui-failure-runtime-observation.json', JSON.stringify(result, null, 2) + '\n', { flag: 'wx' });
console.log(JSON.stringify(result));
} finally { db.close(); }