Elffuss BraidHub

utopia-ia/elffuss-code public

Attached files show as removable chips above the message box

A file attached with @ (the menu or the + button) was only text inside the
message. To see what was attached you had to read the message, and to
remove it, find it and delete it by hand.

Each attachment is now a chip above the box, with a × whose accessible name
says what it removes. The × takes the @path out of the message and returns
focus to the box; deleting the @path by hand removes its chip too; sending the
message clears them.

tests/attach-chips.mjs: attaching through the @ menu adds a chip, two
attachments make two, × removes the chip and the @path and keeps the focus in
the box, deleting the text by hand removes the chip, and sending clears them.
Changeset4b0609511c80e9d6bc7f18b7903849fe3de7a8f92f69c23fb9670a8bccd228cc
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-11 15:11 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 15:11 +02:00
Parents4b3dbf7a3704

Browse the files at this changeset

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 @@
467467 .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; }
468468
469469 #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); }
470476
471477 /* menú flotante de +/ */
472478 #menu {
modified web/index.html +1 −0
@@ -134,6 +134,7 @@
134134 <span id="ctx-text">ctx 0 / 6k</span>
135135 <div class="ctx-track"><div id="ctx-bar"></div></div>
136136 </div>
137+ <div id="attach-chips" role="list" hidden></div>
137138 <form id="composer">
138139 <button type="button" id="btn-plus" class="cbtn" title="Adjuntar archivo del proyecto (@)"></button>
139140 <button type="button" id="btn-slash" class="cbtn" title="Comandos"></button>
modified web/js/i18n.js +2 −0
@@ -35,6 +35,7 @@
3535 pTree: 'árbol', pSearch: 'busca ', pCommit: 'resume los cambios y prepárame el mensaje de commit',
3636 pProposal: 'Implementa esta propuesta de mejora con cambios reales en el código:\n\n',
3737 attachSep: 'Adjuntar al mensaje (@)', attachOpen: 'archivo abierto', openProjFirst: 'Abre un proyecto primero',
38+ attachChips: 'Ficheros adjuntos al mensaje', attachRemove: 'Quitar @{path} del mensaje',
3839 autoTxt: 'Auto', reviewTxt: 'Revisar',
3940 autoOn: 'Editar archivos automáticamente (clic para revisar antes)',
4041 autoOff: 'Pedir confirmación antes de escribir (clic para automático)',
@@ -269,6 +270,7 @@
269270 pTree: 'tree', pSearch: 'search ', pCommit: 'summarize the changes and prepare my commit message',
270271 pProposal: 'Implement this improvement proposal with real changes to the code:\n\n',
271272 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',
272274 autoTxt: 'Auto', reviewTxt: 'Review',
273275 autoOn: 'Edit files automatically (click to review first)',
274276 autoOff: 'Ask before writing (click for automatic)',
modified web/js/main.js +41 −0
@@ -1633,6 +1633,7 @@
16331633 const text = $('prompt').value.trim();
16341634 if (!text) return;
16351635 $('prompt').value = '';
1636+ pintaAdjuntos(); // lo adjuntado se fue con el mensaje
16361637 pushPromptHistory(text);
16371638 send(text);
16381639 });
@@ -2368,12 +2369,50 @@
23682369 }
23692370
23702371 $('prompt').addEventListener('input', () => {
2372+ pintaAdjuntos();
23712373 const tk = tokenArroba($('prompt'));
23722374 if (!tk) { if (arrobaDesde >= 0) cierraMenu(); return; }
23732375 arrobaDesde = tk.desde;
23742376 abreMenuFicheros(tk.frag);
23752377 });
23762378
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+
23772416 function attach(path) {
23782417 const p = $('prompt');
23792418 if (arrobaDesde >= 0) {
@@ -2391,6 +2430,8 @@
23912430 }
23922431 arrobaDesde = -1;
23932432 cacheFicheros = null;
2433+ adjuntos.add(path);
2434+ pintaAdjuntos();
23942435 }
23952436
23962437 // </> Auto (Edit automatically): si off, pide confirmación antes de escribir