Elffuss BraidHub

utopia-ia/elffuss-code public

fe092393385c · 4.9 KiBRawPermalink
1// Elffuss Code demo video: the file tree stays visible the whole time, real
2// tool-calling runs in sequence (read → search/locate → edit), then a brief
3// (~4s) look at the Mind, and an outro with logo+claim.
4// Doubles as an e2e smoke test: loads the real Gemma-4 model on WebGPU and
5// exercises code.read / code.search / code.edit end to end.
6import { chromium } from 'playwright';
7import { mkdirSync } from 'node:fs';
8const REC = process.env.REC || new URL('../../elffuss-assets/_recording', import.meta.url).pathname;
9const OUT = process.env.OUT || REC + '/videos';
10mkdirSync(OUT, { recursive: true });
11const BASE = process.env.BASE || 'https://code.elffuss.com';
12
13async function waitIdle(p, maxMs = 180000) {
14 const t0 = Date.now();
15 while (Date.now() - t0 < maxMs) {
16 const sending = await p.locator('#btn-send.sending').count().catch(() => 0);
17 if (!sending) return true;
18 await p.waitForTimeout(500);
19 }
20 return false;
21}
22
23const PROFILE = process.env.PROFILE || REC + '/profile-code-gemma';
24mkdirSync(PROFILE, { recursive: true });
25const ctx = await chromium.launchPersistentContext(PROFILE, {
26 args: ['--autoplay-policy=no-user-gesture-required', '--enable-unsafe-webgpu', '--use-angle=metal',
27 // WebGPU LLM inference issues long GPU dispatches; Chromium's GPU watchdog
28 // otherwise kills the GPU process mid-inference/-load → "Target page…closed".
29 '--disable-gpu-watchdog', '--disable-gpu-process-crash-limit'],
30 viewport: { width: 1440, height: 900 },
31 locale: 'en-US', // fuerza navigator.language=en → chrome i18n + modelo en inglés
32 recordVideo: { dir: OUT, size: { width: 1440, height: 900 } },
33});
34await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'litert:gemma-e2b'); } catch {} });
35const p = ctx.pages()[0] || await ctx.newPage();
36
37await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
38await p.waitForTimeout(2000);
39await p.evaluate(async () => {
40 const root = await navigator.storage.getDirectory();
41 for await (const name of root.keys()) await root.removeEntry(name, { recursive: true }).catch(() => {});
42 const w = async (name, txt) => { const fh = await root.getFileHandle(name, { create: true }); const s = await fh.createWritable(); await s.write(txt); await s.close(); };
43 await w('README.md', '# calculator\nSimple numeric utilities.');
44 await w('calc.py',
45 'def average(numbers):\n' +
46 ' return sum(numbers) / len(numbers) - 1 # why -1?\n\n' +
47 'def is_prime(n):\n' +
48 ' if n < 2:\n' +
49 ' return False\n' +
50 ' for i in range(2, n):\n' +
51 ' if n % i == 0:\n' +
52 ' return False\n' +
53 ' return True\n');
54 const ide = await import('/js/ide.js');
55 await ide.refreshTree(root);
56});
57await p.waitForTimeout(500);
58console.log('1) project seeded (README.md + calc.py with a real bug) — tree visible');
59
60console.log('2) loading real Gemma-4 E2B (~2GB if not cached)…');
61let loaded = false;
62{
63 const t0 = Date.now();
64 while (Date.now() - t0 < 300000) {
65 const cls = await p.locator('#model-dot').getAttribute('class').catch(() => '');
66 if (cls && /\bon\b/.test(cls)) { loaded = true; break; }
67 await p.waitForTimeout(1000);
68 }
69}
70if (!loaded) throw new Error('Gemma did NOT load in time');
71console.log('3) Gemma-4 actually loaded, running in your browser');
72
73await p.click('#prompt');
74await p.type('#prompt', 'What does calc.py do?', { delay: 25 });
75await p.press('#prompt', 'Enter');
76console.log('4) turn 1 — should read the file (code.read) before answering');
77await waitIdle(p, 120000);
78await p.waitForTimeout(1200);
79
80await p.click('#prompt');
81await p.type('#prompt', 'There is a real bug in average(): it subtracts 1 too many from the result. Find it in the project and fix it with a minimal edit.', { delay: 22 });
82await p.press('#prompt', 'Enter');
83console.log('5) turn 2 — should search/locate and edit (code.search + code.edit)');
84await waitIdle(p, 150000);
85await p.waitForTimeout(1500);
86console.log('6) Gemma answered — tree still visible');
87
88const fileRow = p.locator('#tree .file', { hasText: 'calc.py' });
89if (await fileRow.count()) {
90 await fileRow.first().click({ force: true });
91 await p.waitForTimeout(1800);
92 console.log('7) calc.py open in the editor — the real fix is visible');
93}
94await p.waitForTimeout(1500);
95
96await p.click('#activity img');
97await p.waitForTimeout(4000);
98console.log('8) brief look at the Mind (4s)');
99await p.click('#mind-close').catch(() => {});
100await p.waitForTimeout(500);
101
102await p.evaluate(async () => (await import('/js/db.js')).del('kv', 'project'));
103await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
104await p.waitForTimeout(4000);
105console.log('9) outro with logo + claim');
106
107const _vid = p.video();
108await ctx.close();
109// guarda el webm directamente como el keeper que consume finalize-demos.sh
110if (_vid) { await _vid.saveAs(REC + '/code-keeper.webm'); console.log('keeper →', REC + '/code-keeper.webm'); }
111console.log('OK — video saved in', OUT);