utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | b68cefab2bf21b3377058974468bf805a65ef0d78d43b06a837d6acba6fe7e4f |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-11 15:10 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 15:10 +02:00 |
| Parents | 48f115f65832 |
5 files changed
added tests/english-ui.mjs +89 −0
| @@ -0,0 +1,89 @@ | ||
| 1 | +// Con la interfaz en inglés, nada en español colado: | |
| 2 | +// 1. La ayuda del modo Básico (era siempre en español y mandaba a «Ajustes → | |
| 3 | +// Cerebro» mientras la interfaz decía «Settings → Brain»), y las órdenes | |
| 4 | +// en inglés que esa ayuda promete («tree», «read <file>»…) funcionan. | |
| 5 | +// 2. Lo que se para dice «(Stopped.)», no «(Parado.)». | |
| 6 | +// 3. La carpeta del almacenamiento del navegador es «OPFS (browser)». | |
| 7 | +// Y en español sigue todo igual. | |
| 8 | +// | |
| 9 | +// BASE=http://localhost:8799 node tests/english-ui.mjs | |
| 10 | +import { chromium } from 'playwright'; | |
| 11 | +const BASE = process.env.BASE || 'http://localhost:8799'; | |
| 12 | +let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; | |
| 13 | +const b = await chromium.launch(); | |
| 14 | +const errs = []; | |
| 15 | + | |
| 16 | +async function abre(locale) { | |
| 17 | + const ctx = await b.newContext({ locale }); | |
| 18 | + await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 19 | + const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } }); | |
| 20 | + p.on('pageerror', e => errs.push(e.message.slice(0, 160))); | |
| 21 | + await p.goto(BASE + '/manifest.json'); | |
| 22 | + await p.evaluate(async () => { | |
| 23 | + const root = await navigator.storage.getDirectory(); | |
| 24 | + const w = await (await root.getFileHandle('notes.md', { create: true })).createWritable(); await w.write('# notes\nhello\n'); await w.close(); | |
| 25 | + }); | |
| 26 | + await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 27 | + await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 }); | |
| 28 | + return { ctx, p }; | |
| 29 | +} | |
| 30 | +const di = async (p, texto) => { | |
| 31 | + const antes = await p.locator('#chat-log .msg.assistant').count(); | |
| 32 | + await p.fill('#prompt', texto); | |
| 33 | + await p.press('#prompt', 'Enter'); | |
| 34 | + await p.waitForFunction(n => document.querySelectorAll('#chat-log .msg.assistant').length > n && !window.elffussClaw.conv.isBusy(), antes, { timeout: 10000 }).catch(() => {}); | |
| 35 | + return p.evaluate(() => ({ ultima: [...document.querySelectorAll('#chat-log .msg.assistant')].at(-1)?.textContent || '', | |
| 36 | + herramientas: [...document.querySelectorAll('#chat-log .msg.tool b')].map(b => b.textContent) })); | |
| 37 | +}; | |
| 38 | + | |
| 39 | +// 1 · inglés | |
| 40 | +{ | |
| 41 | + const { ctx, p } = await abre('en-US'); | |
| 42 | + const hola = await di(p, 'hello'); | |
| 43 | + ok('1 · en inglés, la ayuda del modo Básico sale en inglés', /basic mode/.test(hola.ultima) && /Settings → Brain/.test(hola.ultima) && !/Ajustes|Cerebro|Entiendo/.test(hola.ultima), hola.ultima.slice(0, 160)); | |
| 44 | + const arbol = await di(p, 'tree'); | |
| 45 | + ok('1 · …y entiende las órdenes en inglés que promete («tree»)', arbol.herramientas.includes('code.tree'), JSON.stringify(arbol.herramientas)); | |
| 46 | + const lee = await di(p, 'read notes.md'); | |
| 47 | + ok('1 · …(«read <file>»)', lee.herramientas.includes('code.read'), JSON.stringify(lee.herramientas)); | |
| 48 | + | |
| 49 | + // 2 · parar | |
| 50 | + await p.evaluate(() => { | |
| 51 | + window.elffussClaw.conv.setProvider({ chat: async (h, s, cb, signal) => { | |
| 52 | + for (let i = 0; i < 200; i++) { if (signal?.aborted) throw new DOMException('Stopped', 'AbortError'); cb('·'); await new Promise(r => setTimeout(r, 25)); } | |
| 53 | + return 'done'; | |
| 54 | + } }); | |
| 55 | + }); | |
| 56 | + await p.fill('#prompt', 'a long job'); | |
| 57 | + await p.press('#prompt', 'Enter'); | |
| 58 | + await p.waitForFunction(() => document.getElementById('btn-send').classList.contains('is-stop'), null, { timeout: 5000 }).catch(() => {}); | |
| 59 | + await p.click('#btn-send'); | |
| 60 | + await p.waitForFunction(() => !window.elffussClaw.conv.isBusy(), null, { timeout: 8000 }).catch(() => {}); | |
| 61 | + const nota = await p.evaluate(() => [...document.querySelectorAll('#chat-log .msg.muted')].map(n => n.textContent).at(-1) || ''); | |
| 62 | + ok('2 · lo que se para dice «(Stopped.)»', nota === '(Stopped.)', JSON.stringify(nota)); | |
| 63 | + | |
| 64 | + // 3 · carpeta OPFS: el proyecto de prueba vive en la OPFS, y su carpeta es la | |
| 65 | + // que se adopta como espacio de trabajo («Use the project's») | |
| 66 | + await p.click('#btn-settings'); | |
| 67 | + await p.waitForTimeout(400); | |
| 68 | + await p.locator('#settings-panel button', { hasText: "Use the project's" }).click(); | |
| 69 | + await p.waitForTimeout(400); | |
| 70 | + const ajustes = await p.evaluate(() => document.getElementById('settings-panel').textContent); | |
| 71 | + ok('3 · la carpeta del navegador se llama «OPFS (browser)»', /OPFS \(browser\)/.test(ajustes) && !/navegador/.test(ajustes), (ajustes.match(/[^.]{0,40}OPFS[^.]{0,30}/) || [''])[0]); | |
| 72 | + await ctx.close(); | |
| 73 | +} | |
| 74 | + | |
| 75 | +// 4 · español: igual que antes | |
| 76 | +{ | |
| 77 | + const { ctx, p } = await abre('es-ES'); | |
| 78 | + const hola = await di(p, 'hola'); | |
| 79 | + ok('4 · en español, la ayuda sigue en español', /modo básico/.test(hola.ultima) && /Ajustes → Cerebro/.test(hola.ultima), hola.ultima.slice(0, 120)); | |
| 80 | + const arbol = await di(p, 'árbol'); | |
| 81 | + ok('4 · …y «árbol» sigue funcionando', arbol.herramientas.includes('code.tree'), JSON.stringify(arbol.herramientas)); | |
| 82 | + await ctx.close(); | |
| 83 | +} | |
| 84 | + | |
| 85 | +console.log('\n errores JS:', errs[0] || 'ninguno'); | |
| 86 | +ok('sin errores de página', errs.length === 0, errs.join(' | ')); | |
| 87 | +console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ INTERFAZ EN INGLÉS SIN ESPAÑOL COLADO'); | |
| 88 | +await b.close(); | |
| 89 | +process.exit(fails ? 1 : 0); |
modified web/js/i18n.js +8 −0
| @@ -112,6 +112,10 @@ | ||
| 112 | 112 | planStopped: "parado", |
| 113 | 113 | stopping: "Parando…", |
| 114 | 114 | stopped: "Parado.", |
| 115 | + stoppedNote: "(Parado.)", | |
| 116 | + rulesHello: "¡Hola!", | |
| 117 | + rulesHelp: "Estoy en modo básico (sin modelo). Entiendo:\n• «árbol» / «qué hay en el proyecto»\n• «lee <archivo>» · «abre <archivo>»\n• «busca <texto>»\n• «escribe <archivo>: <contenido>»\nPara programar de verdad, elige un modelo en ⚙️ Ajustes → Cerebro (o pulsa el punto de estado del modelo, arriba a la derecha).", | |
| 118 | + wsOpfsName: "OPFS (navegador)", | |
| 115 | 119 | send: "Enviar", |
| 116 | 120 | stop: "Parar", |
| 117 | 121 | stModelLoadingAI: "Cargando el modelo IA…", |
| @@ -337,6 +341,10 @@ | ||
| 337 | 341 | planStopped: "stopped", |
| 338 | 342 | stopping: "Stopping…", |
| 339 | 343 | stopped: "Stopped.", |
| 344 | + stoppedNote: "(Stopped.)", | |
| 345 | + rulesHello: "Hello!", | |
| 346 | + rulesHelp: "I'm in basic mode (no model). I understand:\n• “tree” / “what's in the project”\n• “read <file>” · “open <file>”\n• “search <text>”\n• “write <file>: <content>”\nTo really code, pick a model in ⚙️ Settings → Brain (or press the model status dot, top right).", | |
| 347 | + wsOpfsName: "OPFS (browser)", | |
| 340 | 348 | send: "Send", |
| 341 | 349 | stop: "Stop", |
| 342 | 350 | stModelLoadingAI: "Loading the AI model…", |
modified web/js/main.js +4 −2
| @@ -25,7 +25,7 @@ | ||
| 25 | 25 | |
| 26 | 26 | // Espacio de trabajo (core): qué de Code puede guardarse en tu disco. |
| 27 | 27 | workspace.init({ |
| 28 | - app: 'code', ns: 'elffusscode', db, | |
| 28 | + app: 'code', ns: 'elffusscode', db, opfsName: t('wsOpfsName'), | |
| 29 | 29 | stores: [ |
| 30 | 30 | { id: 'conversations', label: 'Conversaciones', icon: '💬', kind: 'idb-key', store: 'kv', key: 'conversations', |
| 31 | 31 | files: { ext: '.json', name: c => c.title || c.id } }, |
| @@ -372,7 +372,9 @@ | ||
| 372 | 372 | if (ev.type === 'tool_result') addToolResult(ev.result); |
| 373 | 373 | if (ev.type === 'progress') activeThinking?.tool(ev.text); |
| 374 | 374 | if (ev.type === 'error') addMsg('assistant err', ev.text); |
| 375 | - if (ev.type === 'aborted') addMsg('assistant muted', ev.text); | |
| 375 | + // «(Parado.)» lo emiten módulos que no saben de idiomas (agent, goal, la | |
| 376 | + // cola…): se pinta en el de la interfaz. | |
| 377 | + if (ev.type === 'aborted') addMsg('assistant muted', t('stoppedNote')); | |
| 376 | 378 | // 🎯 Modo Objetivo: la tarjeta de plan se crea con 'plan' y se repinta |
| 377 | 379 | // in-place en cada 'plan_update'/'plan_complete' (mismo nodo, por id). |
| 378 | 380 | if (ev.type === 'plan' || ev.type === 'plan_update' || ev.type === 'plan_complete') renderPlanCard(ev.plan); |
modified web/js/providers/rules.js +12 −14
| @@ -1,16 +1,14 @@ | ||
| 1 | 1 | // Modo básico de Elffuss Code: órdenes deterministas sin modelo. |
| 2 | +// La ayuda sale en el idioma de la interfaz (antes siempre en español, también | |
| 3 | +// con la interfaz en inglés, que decía «Settings → Brain» donde la ayuda decía | |
| 4 | +// «Ajustes → Cerebro»), y las órdenes se entienden en los dos idiomas: una | |
| 5 | +// ayuda en inglés que solo entendiera «árbol» mentiría. | |
| 6 | +import { t } from '../i18n.js'; | |
| 2 | 7 | export const name = 'Básico (sin modelo)'; |
| 3 | 8 | export async function load() {} |
| 4 | 9 | |
| 5 | 10 | const call = obj => '```tool\n' + JSON.stringify(obj) + '\n```'; |
| 6 | 11 | |
| 7 | -const HELP = `Estoy en modo básico (sin modelo). Entiendo: | |
| 8 | -• «árbol» / «qué hay en el proyecto» | |
| 9 | -• «lee <archivo>» · «abre <archivo>» | |
| 10 | -• «busca <texto>» | |
| 11 | -• «escribe <archivo>: <contenido>» | |
| 12 | -Para programar de verdad, elige un modelo en ⚙️ Ajustes → Cerebro (o pulsa el punto de estado del modelo, arriba a la derecha).`; | |
| 13 | - | |
| 14 | 12 | export async function chat(history, systemPrompt) { |
| 15 | 13 | const last = history[history.length - 1]; |
| 16 | 14 | const text = (last?.content || '').trim(); |
| @@ -33,16 +31,16 @@ | ||
| 33 | 31 | return body.startsWith('ERROR:') ? 'No pude: ' + body.slice(6).trim() : body; |
| 34 | 32 | } |
| 35 | 33 | |
| 36 | - const t = text.toLowerCase(); | |
| 37 | - if (/(árbol|arbol|estructura|qué hay|que hay)/.test(t)) | |
| 34 | + const low = text.toLowerCase(); | |
| 35 | + if (/(árbol|arbol|estructura|qué hay|que hay|\btree\b|\bstructure\b|what'?s in)/.test(low)) | |
| 38 | 36 | return call({ tool: 'code.tree', args: {} }); |
| 39 | - const mRead = text.match(/(?:lee|abre|muestra|cat)\s+([\w./-]+\.\w+)/i); | |
| 37 | + const mRead = text.match(/(?:lee|abre|muestra|cat|read|open|show)\s+([\w./-]+\.\w+)/i); | |
| 40 | 38 | if (mRead) return call({ tool: 'code.read', args: { path: mRead[1] } }); |
| 41 | - const mSearch = text.match(/busca(?:r)?\s+(?:d[oó]nde\s+)?(?:se\s+\w+\s+)?["«']?([^"»']{2,60})["»']?$/i); | |
| 39 | + const mSearch = text.match(/(?:busca(?:r)?\s+(?:d[oó]nde\s+)?(?:se\s+\w+\s+)?|(?:search|find)\s+(?:for\s+)?)["«“']?([^"»”']{2,60})["»”']?$/i); | |
| 42 | 40 | if (mSearch) return call({ tool: 'code.search', args: { query: mSearch[1].trim() } }); |
| 43 | - const mWrite = text.match(/escribe\s+([\w./-]+\.\w+)\s*[:=]\s*([\s\S]+)/i); | |
| 41 | + const mWrite = text.match(/(?:escribe|write)\s+([\w./-]+\.\w+)\s*[:=]\s*([\s\S]+)/i); | |
| 44 | 42 | if (mWrite) return call({ tool: 'code.write', args: { path: mWrite[1], content: mWrite[2] } }); |
| 45 | 43 | |
| 46 | - if (/^(hola|buenas|hey|hi)\b/.test(t)) return '¡Hola! ' + HELP; | |
| 47 | - return HELP; | |
| 44 | + if (/^(hola|buenas|hey|hi|hello)\b/.test(low)) return t('rulesHello') + ' ' + t('rulesHelp'); | |
| 45 | + return t('rulesHelp'); | |
| 48 | 46 | } |
modified web/js/workspace.js +6 −2
| @@ -24,8 +24,12 @@ | ||
| 24 | 24 | let autosaveCfg = { enabled: false, debounceMs: 3000 }; |
| 25 | 25 | let autosaveTimer = null; |
| 26 | 26 | |
| 27 | -export function init({ app, ns, db, stores }) { | |
| 27 | +// `nombreOPFS`: cómo se llama, en el idioma de la interfaz, la carpeta del | |
| 28 | +// almacenamiento privado del navegador (no tiene nombre propio). Lo da la app. | |
| 29 | +let nombreOPFS = 'OPFS'; | |
| 30 | +export function init({ app, ns, db, stores, opfsName }) { | |
| 28 | 31 | cfg = { app, ns, db, stores: stores || [] }; |
| 32 | + if (opfsName) nombreOPFS = opfsName; | |
| 29 | 33 | } |
| 30 | 34 | |
| 31 | 35 | export function supported() { |
| @@ -40,7 +44,7 @@ | ||
| 40 | 44 | |
| 41 | 45 | // La raíz del almacenamiento privado del navegador (OPFS) no tiene nombre: '' |
| 42 | 46 | // se leía como «sin carpeta» y la carpeta elegida no se podía usar. |
| 43 | -const nombreDe = h => h ? (h.name || 'OPFS (navegador)') : null; | |
| 47 | +const nombreDe = h => h ? (h.name || nombreOPFS) : null; | |
| 44 | 48 | |
| 45 | 49 | function statusSync() { |
| 46 | 50 | return { |