Elffuss BraidHub

utopia-ia/elffuss-code public

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