utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 4b0609511c80e9d6bc7f18b7903849fe3de7a8f92f69c23fb9670a8bccd228cc |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-11 15:11 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 15:11 +02:00 |
| Parents | 4b3dbf7a3704 |
5 files changed
added tests/attach-chips.mjs +65 −0
| @@ -0,0 +1,65 @@ | ||
| 1 | +// Lo adjuntado con @ se ve como fichas encima de la caja, cada una con su ×. | |
| 2 | +// Antes el adjunto era solo texto dentro del mensaje: para saber qué iba | |
| 3 | +// adjunto había que leerlo, y para quitarlo, encontrarlo y borrarlo a mano. | |
| 4 | +// | |
| 5 | +// BASE=http://localhost:8799 node tests/attach-chips.mjs | |
| 6 | +import { chromium } from 'playwright'; | |
| 7 | +const BASE = process.env.BASE || 'http://localhost:8799'; | |
| 8 | +let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; | |
| 9 | + | |
| 10 | +const b = await chromium.launch(); | |
| 11 | +const ctx = await b.newContext({ locale: 'es-ES' }); | |
| 12 | +await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 13 | +const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } }); | |
| 14 | +const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160))); | |
| 15 | +await p.goto(BASE + '/manifest.json'); | |
| 16 | +await p.evaluate(async () => { | |
| 17 | + const o = await navigator.storage.getDirectory(); | |
| 18 | + const w = async (path, txt) => { const parts = path.split('/'); const name = parts.pop(); let d = o; for (const x of parts) d = await d.getDirectoryHandle(x, { create: true }); const f = await d.getFileHandle(name, { create: true }); const s = await f.createWritable(); await s.write(txt); await s.close(); }; | |
| 19 | + await w('README.md', '# demo'); | |
| 20 | + await w('src/app.js', 'export const app = 1;'); | |
| 21 | +}); | |
| 22 | +await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 23 | +await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 }); | |
| 24 | +const fichas = () => p.evaluate(() => ({ | |
| 25 | + oculto: document.getElementById('attach-chips').hidden, | |
| 26 | + fichas: [...document.querySelectorAll('#attach-chips .attach-chip')].map(c => c.firstChild.textContent), | |
| 27 | + quitar: [...document.querySelectorAll('#attach-chips .attach-chip button')].map(b => b.getAttribute('aria-label')), | |
| 28 | + texto: document.getElementById('prompt').value, | |
| 29 | +})); | |
| 30 | +const elige = async (frag, ruta) => { | |
| 31 | + await p.focus('#prompt'); | |
| 32 | + await p.keyboard.type(frag); | |
| 33 | + await p.locator('#menu .menu-item', { hasText: '@' + ruta }).first().click(); | |
| 34 | +}; | |
| 35 | + | |
| 36 | +ok('sin adjuntos no hay fichas', (await fichas()).oculto); | |
| 37 | +await p.focus('#prompt'); await p.keyboard.type('mira '); | |
| 38 | +await elige('@app', 'src/app.js'); | |
| 39 | +let f = await fichas(); | |
| 40 | +ok('adjuntar con @ pone una ficha con la ruta', !f.oculto && JSON.stringify(f.fichas) === '["@src/app.js"]' && /@src\/app\.js/.test(f.texto), JSON.stringify(f)); | |
| 41 | +ok(' …y su × dice qué quita', f.quitar[0] === 'Quitar @src/app.js del mensaje', JSON.stringify(f.quitar)); | |
| 42 | +await p.keyboard.type('y '); | |
| 43 | +await elige('@READ', 'README.md'); | |
| 44 | +f = await fichas(); | |
| 45 | +ok('dos adjuntos, dos fichas', JSON.stringify(f.fichas) === '["@src/app.js","@README.md"]', JSON.stringify(f)); | |
| 46 | +await p.locator('#attach-chips .attach-chip button').first().click(); | |
| 47 | +f = await fichas(); | |
| 48 | +ok('× quita la ficha Y la @ruta del mensaje', JSON.stringify(f.fichas) === '["@README.md"]' && !/@src\/app\.js/.test(f.texto) && /@README\.md/.test(f.texto), JSON.stringify(f)); | |
| 49 | +ok(' …y el foco vuelve a la caja', await p.evaluate(() => document.activeElement?.id) === 'prompt'); | |
| 50 | +// borrar la @ruta a mano también se lleva su ficha | |
| 51 | +await p.evaluate(() => { const t = document.getElementById('prompt'); t.value = t.value.replace('@README.md', ''); t.dispatchEvent(new Event('input')); }); | |
| 52 | +f = await fichas(); | |
| 53 | +ok('borrar la @ruta a mano también quita su ficha', f.oculto && f.fichas.length === 0, JSON.stringify(f)); | |
| 54 | +// al enviar, las fichas se van con el mensaje | |
| 55 | +await elige('@app', 'src/app.js'); | |
| 56 | +await p.keyboard.press('Enter'); | |
| 57 | +await p.waitForTimeout(400); | |
| 58 | +f = await fichas(); | |
| 59 | +ok('al enviar, las fichas se van con el mensaje', f.oculto && f.texto === '', JSON.stringify(f)); | |
| 60 | + | |
| 61 | +console.log('\n errores JS:', errs[0] || 'ninguno'); | |
| 62 | +ok('sin errores de página', errs.length === 0, errs.join(' | ')); | |
| 63 | +console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ ADJUNTOS COMO FICHAS QUE SE QUITAN'); | |
| 64 | +await b.close(); | |
| 65 | +process.exit(fails ? 1 : 0); |
modified web/css/code.css +6 −0
| @@ -467,6 +467,12 @@ | ||
| 467 | 467 | .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } |
| 468 | 468 | |
| 469 | 469 | #composer #prompt { flex: 1; min-width: 0; } |
| 470 | +/* fichas de lo adjuntado con @, encima de la caja */ | |
| 471 | +#attach-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 10px 0; } | |
| 472 | +#attach-chips[hidden] { display: none; } | |
| 473 | +.attach-chip { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; font-size: .72rem; color: var(--fg); background: var(--bg3); border: 1px solid var(--line); border-radius: 12px; padding: 1px 2px 1px 8px; overflow-wrap: anywhere; } | |
| 474 | +.attach-chip button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .85rem; line-height: 1; padding: 2px 6px; border-radius: 10px; } | |
| 475 | +.attach-chip button:hover, .attach-chip button:focus-visible { color: var(--fg); background: var(--line); } | |
| 470 | 476 | |
| 471 | 477 | /* menú flotante de +/ */ |
| 472 | 478 | #menu { |
modified web/index.html +1 −0
| @@ -134,6 +134,7 @@ | ||
| 134 | 134 | <span id="ctx-text">ctx 0 / 6k</span> |
| 135 | 135 | <div class="ctx-track"><div id="ctx-bar"></div></div> |
| 136 | 136 | </div> |
| 137 | + <div id="attach-chips" role="list" hidden></div> | |
| 137 | 138 | <form id="composer"> |
| 138 | 139 | <button type="button" id="btn-plus" class="cbtn" title="Adjuntar archivo del proyecto (@)"></button> |
| 139 | 140 | <button type="button" id="btn-slash" class="cbtn" title="Comandos"></button> |
modified web/js/i18n.js +2 −0
| @@ -35,6 +35,7 @@ | ||
| 35 | 35 | pTree: 'árbol', pSearch: 'busca ', pCommit: 'resume los cambios y prepárame el mensaje de commit', |
| 36 | 36 | pProposal: 'Implementa esta propuesta de mejora con cambios reales en el código:\n\n', |
| 37 | 37 | attachSep: 'Adjuntar al mensaje (@)', attachOpen: 'archivo abierto', openProjFirst: 'Abre un proyecto primero', |
| 38 | + attachChips: 'Ficheros adjuntos al mensaje', attachRemove: 'Quitar @{path} del mensaje', | |
| 38 | 39 | autoTxt: 'Auto', reviewTxt: 'Revisar', |
| 39 | 40 | autoOn: 'Editar archivos automáticamente (clic para revisar antes)', |
| 40 | 41 | autoOff: 'Pedir confirmación antes de escribir (clic para automático)', |
| @@ -269,6 +270,7 @@ | ||
| 269 | 270 | pTree: 'tree', pSearch: 'search ', pCommit: 'summarize the changes and prepare my commit message', |
| 270 | 271 | pProposal: 'Implement this improvement proposal with real changes to the code:\n\n', |
| 271 | 272 | attachSep: 'Attach to message (@)', attachOpen: 'open file', openProjFirst: 'Open a project first', |
| 273 | + attachChips: 'Files attached to the message', attachRemove: 'Remove @{path} from the message', | |
| 272 | 274 | autoTxt: 'Auto', reviewTxt: 'Review', |
| 273 | 275 | autoOn: 'Edit files automatically (click to review first)', |
| 274 | 276 | autoOff: 'Ask before writing (click for automatic)', |
modified web/js/main.js +41 −0
| @@ -1633,6 +1633,7 @@ | ||
| 1633 | 1633 | const text = $('prompt').value.trim(); |
| 1634 | 1634 | if (!text) return; |
| 1635 | 1635 | $('prompt').value = ''; |
| 1636 | + pintaAdjuntos(); // lo adjuntado se fue con el mensaje | |
| 1636 | 1637 | pushPromptHistory(text); |
| 1637 | 1638 | send(text); |
| 1638 | 1639 | }); |
| @@ -2368,12 +2369,50 @@ | ||
| 2368 | 2369 | } |
| 2369 | 2370 | |
| 2370 | 2371 | $('prompt').addEventListener('input', () => { |
| 2372 | + pintaAdjuntos(); | |
| 2371 | 2373 | const tk = tokenArroba($('prompt')); |
| 2372 | 2374 | if (!tk) { if (arrobaDesde >= 0) cierraMenu(); return; } |
| 2373 | 2375 | arrobaDesde = tk.desde; |
| 2374 | 2376 | abreMenuFicheros(tk.frag); |
| 2375 | 2377 | }); |
| 2376 | 2378 | |
| 2379 | +// Lo adjuntado con @ se ve como fichas encima de la caja, cada una con su × | |
| 2380 | +// para quitarla. Antes solo era texto dentro del mensaje: para saber qué iba | |
| 2381 | +// adjunto había que leerlo entero, y para quitarlo, encontrarlo y borrarlo a | |
| 2382 | +// mano. La ficha vive mientras su @ruta siga en el texto (si la borras a mano, | |
| 2383 | +// se va también). | |
| 2384 | +const adjuntos = new Set(); | |
| 2385 | +const tokenDe = ruta => new RegExp('(^|\\s)@' + ruta.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '(?=\\s|$)'); | |
| 2386 | +function pintaAdjuntos() { | |
| 2387 | + const box = $('attach-chips'); | |
| 2388 | + if (!box) return; | |
| 2389 | + const v = $('prompt').value; | |
| 2390 | + for (const ruta of [...adjuntos]) if (!tokenDe(ruta).test(v)) adjuntos.delete(ruta); | |
| 2391 | + box.replaceChildren(); | |
| 2392 | + box.hidden = !adjuntos.size; | |
| 2393 | + box.setAttribute('aria-label', t('attachChips')); | |
| 2394 | + for (const ruta of adjuntos) { | |
| 2395 | + const ficha = document.createElement('span'); | |
| 2396 | + ficha.className = 'attach-chip'; | |
| 2397 | + ficha.setAttribute('role', 'listitem'); | |
| 2398 | + ficha.append('@' + ruta); | |
| 2399 | + const x = document.createElement('button'); | |
| 2400 | + x.type = 'button'; | |
| 2401 | + x.textContent = '×'; | |
| 2402 | + x.setAttribute('aria-label', t('attachRemove', { path: ruta })); | |
| 2403 | + x.title = x.getAttribute('aria-label'); | |
| 2404 | + x.onclick = () => { quitaAdjunto(ruta); $('prompt').focus(); }; | |
| 2405 | + ficha.appendChild(x); | |
| 2406 | + box.appendChild(ficha); | |
| 2407 | + } | |
| 2408 | +} | |
| 2409 | +function quitaAdjunto(ruta) { | |
| 2410 | + const p = $('prompt'); | |
| 2411 | + p.value = p.value.replace(tokenDe(ruta), '$1').replace(/[ \t]{2,}/g, ' ').replace(/^ +/, ''); | |
| 2412 | + adjuntos.delete(ruta); | |
| 2413 | + pintaAdjuntos(); | |
| 2414 | +} | |
| 2415 | + | |
| 2377 | 2416 | function attach(path) { |
| 2378 | 2417 | const p = $('prompt'); |
| 2379 | 2418 | if (arrobaDesde >= 0) { |
| @@ -2391,6 +2430,8 @@ | ||
| 2391 | 2430 | } |
| 2392 | 2431 | arrobaDesde = -1; |
| 2393 | 2432 | cacheFicheros = null; |
| 2433 | + adjuntos.add(path); | |
| 2434 | + pintaAdjuntos(); | |
| 2394 | 2435 | } |
| 2395 | 2436 | |
| 2396 | 2437 | // </> Auto (Edit automatically): si off, pide confirmación antes de escribir |