| 1 | // ¿Cómo salen los juegos AHORA, con el arreglo del KV-cache y el parada-por-nota? |
| 2 | // |
| 3 | // Dos variantes por juego: |
| 4 | // borrador · lo que sale a la primera, sin tocar |
| 5 | // nota5 · itera hasta que el evaluador objetivo da 5/5 (tope 3 rondas) |
| 6 | // |
| 7 | // Se puntúa DESDE FUERA con jugabilidad.cjs, que es un arnés independiente. Si |
| 8 | // puntuara el mismo evaluador que dirige el bucle, la medición sería circular: |
| 9 | // diría que 5/5 porque el bucle para justo cuando él dice 5/5. |
| 10 | const {chromium}=require(process.env.PW||"playwright"); |
| 11 | const {medir}=require("./jugabilidad.cjs"); |
| 12 | const fs=require("fs"),os=require("os"),{execSync}=require("child_process"); |
| 13 | const OUT=__dirname+"/ahora"; fs.mkdirSync(OUT,{recursive:true}); |
| 14 | |
| 15 | const GAMES=[ |
| 16 | {id:"breakout",brief:"Hazme un juego de romper ladrillos: pala con el ratón, bola que rebota, ladrillos de colores, puntuación y game over."}, |
| 17 | {id:"snake", brief:"Hazme el juego de la serpiente: se mueve con las flechas, come manzanas, crece, y pierde si choca consigo misma."}, |
| 18 | {id:"pong", brief:"Hazme un pong para dos jugadores: una pala con W/S y otra con las flechas, bola que rebota y marcador."}, |
| 19 | ]; |
| 20 | const VARIANTES=[{k:"borrador",rounds:0,nota:null,bestOf:1}, |
| 21 | {k:"refina", rounds:3,nota:6, bestOf:1}, |
| 22 | {k:"best-of-3",rounds:0,nota:6, bestOf:3}, |
| 23 | {k:"b3+refina",rounds:2,nota:6, bestOf:3}]; |
| 24 | |
| 25 | (async()=>{ |
| 26 | try{execSync("pkill -f elffuss-e4b");}catch{} |
| 27 | await new Promise(r=>setTimeout(r,3000)); |
| 28 | try{execSync("rm -f ~/.cache/elffuss-e4b/Singleton*");}catch{} |
| 29 | // la caché HTTP del perfil sirve JS viejo y la medición sale de otra versión |
| 30 | try{execSync("rm -rf ~/.cache/elffuss-e4b/Default/Cache");}catch{} |
| 31 | const ctx=await chromium.launchPersistentContext(os.homedir()+"/.cache/elffuss-e4b", |
| 32 | {channel:"chrome",headless:true,args:["--enable-unsafe-webgpu"]}); |
| 33 | const p=await ctx.newPage(); |
| 34 | await p.goto("https://claw.elffuss.com/",{waitUntil:"domcontentloaded"}); |
| 35 | await p.waitForTimeout(1500); |
| 36 | |
| 37 | // GUARDIA: sin esto se mide una versión del código que no es la que crees |
| 38 | const listo=await p.evaluate(async()=>{ |
| 39 | const l=await import("/js/providers/litert.js"), r=await import("/js/rlm.js"); |
| 40 | return {kv:l.chat.toString().includes("reiniciada"), evalua:typeof r.rateArtifact==="function", |
| 41 | medidos:r.deepCreate.toString().includes("defectosMedidos")}; |
| 42 | }); |
| 43 | const ok=listo.kv&&listo.evalua&&listo.medidos; |
| 44 | console.log(ok ? "✓ el navegador tiene KV-cache arreglado, evaluador y defectos medidos" |
| 45 | : `✗ MEDICIÓN INVÁLIDA — kv=${listo.kv} evaluador=${listo.evalua} medidos=${listo.medidos}`); |
| 46 | if(!ok){await ctx.close();return;} |
| 47 | |
| 48 | console.log("cargando Gemma E4B…"); |
| 49 | await p.evaluate(async()=>{const m=await import("/js/providers/litert.js");m.configure("gemma-e4b");await m.load(()=>{});}); |
| 50 | console.log("listo\n"); |
| 51 | |
| 52 | const todo={}; |
| 53 | for(const g of GAMES){ |
| 54 | todo[g.id]={}; |
| 55 | for(const V of VARIANTES){ |
| 56 | const t0=Date.now(); |
| 57 | const out=await p.evaluate(async a=>{ |
| 58 | const m=await import("/js/providers/litert.js"); m.configure("gemma-e4b"); |
| 59 | const rlm=await import("/js/rlm.js"); |
| 60 | const notas=[]; |
| 61 | const res=await rlm.deepCreate({brief:a.brief, provider:m, rounds:a.rounds, bestOf:a.bestOf, |
| 62 | editMode:"patch", notaMinima:a.nota, |
| 63 | evaluar:a.nota?(html=>rlm.rateArtifact(html).then(r=>{notas.push(r.nota);return r;})):null, |
| 64 | onProgress:()=>{}}); |
| 65 | return {html:res.html, notas, rondas:res.trace?res.trace.length-1:0, |
| 66 | detalles:(res.trace||[]).map(t=>t.detalle?Object.entries(t.detalle).filter(([,v])=>!v).map(([k])=>k).join('/')||'todo ok':'-')}; |
| 67 | },{brief:g.brief,rounds:V.rounds,nota:V.nota,bestOf:V.bestOf}).catch(e=>({html:"",error:e.message.slice(0,90),notas:[]})); |
| 68 | |
| 69 | const file=`${OUT}/${g.id}-${V.k}.html`; |
| 70 | fs.writeFileSync(file,out.html||""); |
| 71 | // puntuación EXTERNA, en pestaña aparte |
| 72 | const pag=await ctx.newPage(); |
| 73 | const nota=(out.html||"").length ? await medir(pag,"file://"+file) : {puntos:0,error:out.error||"sin html"}; |
| 74 | await pag.close(); |
| 75 | todo[g.id][V.k]={...nota, bytes:(out.html||"").length, segs:Math.round((Date.now()-t0)/1000), |
| 76 | rondas:out.rondas||0, notasInternas:out.notas}; |
| 77 | const d=todo[g.id][V.k]; |
| 78 | console.log(` ${g.id.padEnd(9)} ${V.k.padEnd(10)} ${d.puntos}/6 ${String(d.bytes).padStart(6)}B ${String(d.segs).padStart(4)}s ` + |
| 79 | `${d.rondas} rondas` + (d.notasInternas.length?` · notas ${d.notasInternas.join(",")}`:"") + |
| 80 | (out.detalles?` · falla: ${out.detalles.join(" → ")}`:"") + |
| 81 | (d.error?` · ${String(d.error).slice(0,45)}`:"")); |
| 82 | fs.writeFileSync(__dirname+"/ahora.json",JSON.stringify(todo,null,1)); |
| 83 | } |
| 84 | } |
| 85 | console.log("\n══ RESUMEN (puntuado desde fuera) ══"); |
| 86 | for(const g of GAMES) console.log(` ${g.id.padEnd(9)} `+VARIANTES.map(V=>`${V.k} ${todo[g.id][V.k].puntos}/6`).join(" · ")); |
| 87 | console.log(""); |
| 88 | for(const V of VARIANTES) console.log(` TOTAL ${V.k.padEnd(10)} ${GAMES.reduce((s,g)=>s+todo[g.id][V.k].puntos,0)}/18`); |
| 89 | await ctx.close(); |
| 90 | })().catch(e=>console.log("FATAL",e.message)); |