#!/usr/bin/env node /** * 重建猫咪对话的 cat-cafe/index.html: * 子智能体 write_file 全文 + 主对话两次 edit_file(太阳修复、按钮修复) * 输出到 cache/website-mock-review/assets/cat-cafe/index.html */ const fs = require('fs'); const path = require('path'); const SUB = '/Users/jojo/.astrion/astrion/host/data/sub_agent_tasks/sub_4_1788364765_5d6208/conversation.json'; const MAIN = '/Users/jojo/.astrion/astrion/host/mutiagents/conversations/workspace/conv_20260902_235153_495.json'; const OUT = '/Users/jojo/Desktop/agents/正在修复中/agents/cache/website-mock-review/assets/cat-cafe/index.html'; // 1. 取子智能体的 write_file 全文 const sub = JSON.parse(fs.readFileSync(SUB, 'utf8')); const msgs = sub.messages || sub; let html = null; for (const m of msgs) { for (const tc of m.tool_calls || []) { if (tc.function.name === 'write_file') { const args = JSON.parse(tc.function.arguments); if (args.file_path && args.file_path.includes('cat-cafe')) html = args.content; } } } if (!html) throw new Error('未找到 cat-cafe 的 write_file'); console.log('write_file 全文:', html.length, '字符'); // 2. 按主对话顺序应用 edit_file const main = JSON.parse(fs.readFileSync(MAIN, 'utf8')); let edits = []; for (const m of main.messages) { for (const tc of m.tool_calls || []) { if (tc.function.name === 'edit_file') { const args = JSON.parse(tc.function.arguments); if ((args.file_path || '').includes('cat-cafe')) edits.push(args); } } } console.log('待应用 edit_file:', edits.length, '个'); for (const [i, e] of edits.entries()) { for (const [j, r] of (e.replacements || []).entries()) { const cnt = html.split(r.old_string).length - 1; console.log(` edit ${i + 1}.${j + 1}: 匹配 ${cnt} 处`); if (cnt !== 1) throw new Error('匹配数异常,重建不保真'); html = html.split(r.old_string).join(r.new_string); } } fs.mkdirSync(path.dirname(OUT), { recursive: true }); fs.writeFileSync(OUT, html); console.log('已写出:', OUT, fs.statSync(OUT).size, '字节');