agent-Specialization/website-design/tools/rebuild-cat-html.cjs
JOJO 2f0b970060 chore(website-demo): 新增 mock 构建/校验/本地预览工具脚本
- build-mocks.cjs:从真实对话导出演示 mock 数据
- check-mocks.cjs:mock 数据完整性校验
- rebuild-cat-html.cjs / serve.cjs:分类页重建与本地预览服务
2026-09-03 21:54:58 +08:00

53 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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, '字节');