Elffuss BraidHub

utopia-ia/elffuss-code public

9255fd1f0dc0 · 2.1 KiBRawPermalink
1// ¿El agente REINTENTA tras un error en vez de rendirse?
2// Proveedor de guion: 1ª vez pide code.read de un fichero que no existe (falla);
3// 2ª vez, viendo el ERROR + la pista en el historial, corrige y lee el bueno.
4import { chromium } from 'playwright';
5const b = await chromium.launch({ channel: 'chrome', headless: true });
6const p = await (await b.newContext()).newPage();
7await p.goto('https://code.elffuss.com/', { waitUntil: 'domcontentloaded' });
8await p.waitForTimeout(1200);
9const r = await p.evaluate(async () => {
10 const { Agent } = await import('/js/agent.js?v=' + Date.now());
11 const code = await import('/js/tools/code.js');
12 const raiz = await navigator.storage.getDirectory();
13 for await (const [n] of raiz.entries()) await raiz.removeEntry(n, { recursive: true }).catch(()=>{});
14 const w = await (await raiz.getFileHandle('bueno.js', { create: true })).createWritable();
15 await w.write('export const x = 42;'); await w.close();
16 await code.openProject(raiz);
17 // proveedor: falla la 1ª, y si ve ERROR en el historial reintenta con el bueno
18 let llamadas = 0; const vistos = [];
19 const guion = { chat: async (history) => {
20 llamadas++;
21 const huboError = history.some(m => /ERROR|Reanaliza/.test(m.content || ''));
22 vistos.push(huboError ? 'vio-error' : 'primera');
23 if (!huboError) return '```tool\n{"tool":"code.read","args":{"path":"noexiste.js"}}\n```';
24 if (llamadas <= 3) return '```tool\n{"tool":"code.read","args":{"path":"bueno.js"}}\n```';
25 return 'Ya está, leído bueno.js.';
26 }};
27 const ev = [];
28 await new Agent(guion).handle('lee el fichero', e => ev.push(e.type + (e.tool ? ':' + e.tool : '')));
29 return { llamadas, vistos, tipos: [...new Set(ev)], reintentó: vistos.includes('vio-error') };
30});
31console.log(' llamadas al modelo:', r.llamadas, '·', r.vistos.join(' → '));
32console.log(' eventos:', r.tipos.join(', '));
33console.log(r.reintentó ? '\n✅ reintenta: tras el ERROR, el modelo recibe la pista y corrige (no se rinde)'
34 : '\n❌ no reintentó');
35await b.close();
36process.exit(r.reintentó ? 0 : 1);