utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 9255fd1f0dc0d832a61b0eadea1162f7f0ee4cfe4e1faf5a5cbdebecec606062 |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-10 16:10 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 14:13 +02:00 |
| Parents | 0cc5946ae823 |
11 files changed
added tests/mind-consent.mjs +123 −0
| @@ -0,0 +1,123 @@ | ||
| 1 | +// La Mente: abrirla no enciende nada, y lo que se ve se puede pulsar. | |
| 2 | +// | |
| 3 | +// 1. Clic en la elfa: abre la Mente y NADA más. Antes el primer clic encendía | |
| 4 | +// el cerebro autónomo en silencio y pedía permiso de notificaciones. | |
| 5 | +// 2. Sin modelo (modo Básico) el cerebro no piensa: «Pensar ahora» lo dice en | |
| 6 | +// el panel y no se escribe nada en la carpeta-alma. Antes el motor de | |
| 7 | +// reglas generaba «4 mejoras» con el texto de ayuda dentro del proyecto. | |
| 8 | +// 3. Las etiquetas de propuesta se pueden pulsar (antes pointer-events:none: | |
| 9 | +// el clic se iba al lienzo) y son botones. | |
| 10 | +// 4. «Abrir en el editor» cierra la Mente antes (antes abría DETRÁS) y las | |
| 11 | +// rutas de la propuesta abren su fichero. | |
| 12 | +// 5. La música no se carga sola: hay que pedirla, y se puede quitar. | |
| 13 | +// La red a SoundCloud va bloqueada: el test solo mira si la app la PIDE. | |
| 14 | +// | |
| 15 | +// BASE=http://127.0.0.1:8898 node tests/mind-consent.mjs | |
| 16 | +import { chromium } from 'playwright'; | |
| 17 | +const BASE = process.env.BASE || 'http://localhost:8799'; | |
| 18 | +let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; | |
| 19 | + | |
| 20 | +const b = await chromium.launch(); | |
| 21 | +const ctx = await b.newContext({ locale: 'es-ES' }); | |
| 22 | +await ctx.addInitScript(() => { | |
| 23 | + try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} | |
| 24 | + window.__permiso = 0; | |
| 25 | + if (window.Notification) Notification.requestPermission = () => { window.__permiso++; return Promise.resolve('default'); }; | |
| 26 | +}); | |
| 27 | +const sc = []; | |
| 28 | +await ctx.route(/soundcloud/, r => { sc.push(r.request().url()); r.abort(); }); | |
| 29 | +const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } }); | |
| 30 | +const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160))); | |
| 31 | + | |
| 32 | +await p.goto(BASE + '/manifest.json'); | |
| 33 | +await p.evaluate(async () => { | |
| 34 | + const root = await navigator.storage.getDirectory(); | |
| 35 | + const escribe = async (path, txt) => { | |
| 36 | + const parts = path.split('/'); const name = parts.pop(); let d = root; | |
| 37 | + for (const x of parts) d = await d.getDirectoryHandle(x, { create: true }); | |
| 38 | + const w = await (await d.getFileHandle(name, { create: true })).createWritable(); await w.write(txt); await w.close(); | |
| 39 | + }; | |
| 40 | + await escribe('src/app.js', 'export const a = 1;\n'); | |
| 41 | + await escribe('.elffuss/soul/2026-10-10-1200-prueba.md', '# Propuesta\n\nRevisa `src/app.js`.\n'); | |
| 42 | +}); | |
| 43 | +await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 44 | +await p.waitForFunction(() => window.monaco && document.querySelector('#tree [data-path]'), null, { timeout: 30000 }); | |
| 45 | + | |
| 46 | +// 1 · abrir la Mente | |
| 47 | +const esBoton = await p.evaluate(() => { const b = document.getElementById('act-mind'); return !!b && b.tagName === 'BUTTON' && !!b.getAttribute('aria-label'); }); | |
| 48 | +ok('1 · la elfa es un botón con nombre accesible', esBoton); | |
| 49 | +await p.click('#act-mind'); | |
| 50 | +await p.waitForSelector('#mind-overlay', { timeout: 45000 }); | |
| 51 | +await p.waitForTimeout(800); | |
| 52 | +const r1 = await p.evaluate(async () => ({ on: (await import('/js/ceo.js')).isEnabled(), permiso: window.__permiso, boton: document.getElementById('mind-playstop').textContent })); | |
| 53 | +ok('1 · abrir la Mente NO enciende el cerebro', !r1.on && /activar/.test(r1.boton), JSON.stringify(r1)); | |
| 54 | +ok('1 · …ni pide permiso de notificaciones', r1.permiso === 0, JSON.stringify(r1)); | |
| 55 | +ok('5 · la música no se carga sola (ninguna petición a SoundCloud)', sc.length === 0, sc.join(' ')); | |
| 56 | + | |
| 57 | +// 2 · modo Básico: no piensa | |
| 58 | +await p.click('#mind-playstop'); // encenderlo a propósito | |
| 59 | +await p.click('#mind-config'); | |
| 60 | +await p.click('#cfg-think-now'); | |
| 61 | +await p.waitForTimeout(300); | |
| 62 | +const nota = await p.evaluate(() => document.getElementById('cfg-note')?.textContent || ''); | |
| 63 | +ok('2 · «Pensar ahora» sin modelo lo dice en el panel', /Sin un modelo cargado/.test(nota), nota); | |
| 64 | +const r2 = await p.evaluate(async () => { | |
| 65 | + const ceo = await import('/js/ceo.js'); | |
| 66 | + const forzado = await ceo.forceCycle(); | |
| 67 | + const root = await navigator.storage.getDirectory(); | |
| 68 | + const soul = await (await root.getDirectoryHandle('.elffuss')).getDirectoryHandle('soul'); | |
| 69 | + const nombres = []; for await (const e of soul.values()) nombres.push(e.name); | |
| 70 | + return { forzado, nombres }; | |
| 71 | +}); | |
| 72 | +ok('2 · …y con el motor de reglas no se escribe ninguna propuesta', r2.forzado === false && r2.nombres.length === 1, JSON.stringify(r2)); | |
| 73 | +await p.click('#cfg-x'); | |
| 74 | + | |
| 75 | +// 3 · etiqueta de propuesta pulsable | |
| 76 | +await p.waitForSelector('.mind-node-label', { timeout: 10000 }); | |
| 77 | +const r3 = await p.evaluate(() => { | |
| 78 | + const lab = [...document.querySelectorAll('.mind-node-label')].find(l => l.style.display !== 'none'); | |
| 79 | + const r = lab.getBoundingClientRect(); | |
| 80 | + const enPunto = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); | |
| 81 | + return { boton: lab.tagName === 'BUTTON', recibeClic: enPunto === lab, aria: lab.getAttribute('aria-label') }; | |
| 82 | +}); | |
| 83 | +ok('3 · la etiqueta es un botón y recibe el clic (no el lienzo)', r3.boton && r3.recibeClic && /Abrir la propuesta/.test(r3.aria || ''), JSON.stringify(r3)); | |
| 84 | +await p.evaluate(() => [...document.querySelectorAll('.mind-node-label')].find(l => l.style.display !== 'none').click()); | |
| 85 | +await p.waitForSelector('#mind-panel.show'); | |
| 86 | +const enlace = await p.evaluate(() => [...document.querySelectorAll('#mind-panel .mp-body a')].map(a => a.textContent)); | |
| 87 | +ok('4 · las rutas de la propuesta son enlaces', enlace.includes('src/app.js'), JSON.stringify(enlace)); | |
| 88 | + | |
| 89 | +// 4 · Abrir en el editor: cierra la Mente y abre el fichero | |
| 90 | +await p.click('#mp-open'); | |
| 91 | +await p.waitForTimeout(400); | |
| 92 | +const r4 = await p.evaluate(() => ({ | |
| 93 | + mente: getComputedStyle(document.getElementById('mind-overlay')).display, | |
| 94 | + activa: document.querySelector('#tabs-bar .tab.active')?.dataset.path, | |
| 95 | +})); | |
| 96 | +ok('4 · «Abrir en el editor» cierra la Mente y abre la propuesta', r4.mente === 'none' && /prueba\.md$/.test(r4.activa || ''), JSON.stringify(r4)); | |
| 97 | +await p.click('#act-mind'); | |
| 98 | +await p.waitForTimeout(500); | |
| 99 | +await p.evaluate(() => [...document.querySelectorAll('.mind-node-label')].find(l => l.style.display !== 'none').click()); | |
| 100 | +await p.waitForSelector('#mind-panel.show'); | |
| 101 | +await p.locator('#mind-panel .mp-body a', { hasText: 'src/app.js' }).click(); | |
| 102 | +await p.waitForTimeout(400); | |
| 103 | +const r4b = await p.evaluate(() => ({ mente: getComputedStyle(document.getElementById('mind-overlay')).display, activa: document.querySelector('#tabs-bar .tab.active')?.dataset.path })); | |
| 104 | +ok('4 · una ruta de la propuesta cierra la Mente y abre ese fichero', r4b.mente === 'none' && r4b.activa === 'src/app.js', JSON.stringify(r4b)); | |
| 105 | + | |
| 106 | +// 5 · la música, solo si se pide, y se puede quitar | |
| 107 | +await p.click('#act-mind'); | |
| 108 | +await p.waitForTimeout(400); | |
| 109 | +await p.click('.mind-music-btn'); | |
| 110 | +await p.waitForTimeout(300); | |
| 111 | +const conMusica = await p.evaluate(() => !!document.getElementById('mind-sc')); | |
| 112 | +await p.click('.mind-music-btn'); | |
| 113 | +await p.waitForTimeout(200); | |
| 114 | +const sinMusica = await p.evaluate(() => !document.getElementById('mind-sc')); | |
| 115 | +ok('5 · «Poner música» carga el reproductor y «Quitar música» lo elimina', conMusica && sinMusica && sc.length > 0, `${conMusica} ${sinMusica} ${sc.length}`); | |
| 116 | +const leyenda = await p.evaluate(() => [...document.querySelectorAll('#mind-legend .ml-item')].every(x => x.tagName === 'BUTTON')); | |
| 117 | +ok('3 · la leyenda de perfiles son botones (teclado)', leyenda); | |
| 118 | + | |
| 119 | +console.log('\n errores JS:', errs[0] || 'ninguno'); | |
| 120 | +ok('sin errores de página', errs.length === 0, errs.join(' | ')); | |
| 121 | +console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ LA MENTE PIDE PERMISO Y SE DEJA PULSAR'); | |
| 122 | +await b.close(); | |
| 123 | +process.exit(fails ? 1 : 0); |
modified tests/mind.mjs +3 −2
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 7 | 7 | let fails = 0; const ok = (n,c,e='')=>{console.log((c?'✅':'❌')+' '+n+(e?' — '+e:''));if(!c)fails++}; |
| 8 | 8 | const b = await chromium.launch({ args:['--enable-unsafe-webgpu',...CHROME_ARGS,'--autoplay-policy=no-user-gesture-required'] }); |
| 9 | -const ctx = await b.newContext(); await ctx.addInitScript(()=>{try{localStorage.setItem('elffusscode.model','rules')}catch{}}); | |
| 9 | +const ctx = await b.newContext({ locale: 'es-ES' }); await ctx.addInitScript(()=>{try{localStorage.setItem('elffusscode.model','rules')}catch{}}); | |
| 10 | 10 | const p = await ctx.newPage({ viewport:{width:1500,height:900} }); |
| 11 | 11 | p.on('console', m=>{ if(m.type()==='error' && !/allow-same-origin|soundcloud|widget|encrypted-media|permissions policy/i.test(m.text())) console.log(' err:', m.text().slice(0,140)); }); |
| 12 | 12 | await p.goto(BASE+'/',{waitUntil:'domcontentloaded'}); |
| @@ -16,7 +16,8 @@ | ||
| 16 | 16 | await p.locator('#activity img').click(); await p.waitForTimeout(1000); |
| 17 | 17 | ok('overlay + mundo WebGL', await p.locator('#mind-overlay').count()>0 && await p.evaluate(()=>{const c=document.getElementById('mind-canvas');const gl=c&&(c.getContext('webgl2')||c.getContext('webgl'));return !!gl&&!gl.isContextLost();})); |
| 18 | 18 | ok('sin subtítulo (solo título)', await p.evaluate(()=>{const t=document.getElementById('mind-title');return t && !t.querySelector('span') && /MENTE DE ELFFUSS/.test(t.textContent);})); |
| 19 | -ok('música (SoundCloud)', await p.locator('.mind-music iframe').count()>0); | |
| 19 | +// La música ya no se carga sola: hay que pedirla (era una petición a un tercero sin preguntar). | |
| 20 | +ok('música solo a petición (botón, sin reproductor cargado)', await p.locator('.mind-music iframe').count()===0 && await p.locator('.mind-music-btn').count()===1); | |
| 20 | 21 | ok('botón de config del cerebro', await p.locator('#mind-config').count()>0); |
| 21 | 22 | |
| 22 | 23 | // inyectar pensamientos + una mejora forjada |
modified tests/mind_stars.mjs +1 −1
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 8 | 8 | |
| 9 | 9 | const b = await chromium.launch({ args: ['--enable-unsafe-webgpu', ...CHROME_ARGS, '--autoplay-policy=no-user-gesture-required'] }); |
| 10 | -const ctx = await b.newContext(); | |
| 10 | +const ctx = await b.newContext({ locale: 'es-ES' }); | |
| 11 | 11 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); localStorage.removeItem('elffusscode.ceoProfiles'); } catch {} }); |
| 12 | 12 | const p = await ctx.newPage({ viewport: { width: 1500, height: 900 } }); |
| 13 | 13 | p.on('console', m => { if (m.type() === 'error' && !/allow-same-origin|soundcloud|widget|encrypted-media|permissions policy/i.test(m.text())) console.log(' err:', m.text().slice(0, 160)); }); |
modified tests/notify.mjs +1 −1
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 7 | 7 | |
| 8 | 8 | const b = await chromium.launch(); |
| 9 | -const ctx = await b.newContext(); | |
| 9 | +const ctx = await b.newContext({ locale: 'es-ES' }); | |
| 10 | 10 | await ctx.addInitScript(() => { |
| 11 | 11 | try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} |
| 12 | 12 | window.__notifs = []; window.__askedPermission = 0; |
modified tests/playstop.mjs +9 −4
| @@ -6,15 +6,20 @@ | ||
| 6 | 6 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 7 | 7 | |
| 8 | 8 | const b = await chromium.launch(); |
| 9 | -const ctx = await b.newContext(); await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 9 | +const ctx = await b.newContext({ locale: 'es-ES' }); await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 10 | 10 | const p = await ctx.newPage(); |
| 11 | 11 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500); |
| 12 | 12 | |
| 13 | -// clic en la elfa activa el cerebro (comportamiento ya existente) | |
| 13 | +// Abrir la Mente NO enciende el cerebro (antes el primer clic en la elfa lo | |
| 14 | +// activaba en silencio): el botón ofrece activarlo y hay que pulsarlo. | |
| 14 | 15 | await p.locator('#activity img').click(); await p.waitForTimeout(1000); |
| 15 | -ok('al entrar por primera vez, el botón dice "pausar" (el cerebro quedó activo)', /pausar/.test(await p.locator('#mind-playstop').innerText())); | |
| 16 | +ok('al entrar por primera vez, el cerebro sigue apagado y el botón ofrece activarlo', /activar/.test(await p.locator('#mind-playstop').innerText())); | |
| 17 | +const en0 = await p.evaluate(async () => (await import('/js/ceo.js')).isEnabled()); | |
| 18 | +ok('ceo.isEnabled() es false tras el primer clic en la elfa', !en0); | |
| 19 | +await p.click('#mind-playstop'); await p.waitForTimeout(200); | |
| 20 | +ok('activado a propósito, el botón dice "pausar"', /pausar/.test(await p.locator('#mind-playstop').innerText())); | |
| 16 | 21 | const en1 = await p.evaluate(async () => (await import('/js/ceo.js')).isEnabled()); |
| 17 | -ok('ceo.isEnabled() es true tras el primer clic en la elfa', en1); | |
| 22 | +ok('ceo.isEnabled() es true tras activarlo desde la Mente', en1); | |
| 18 | 23 | |
| 19 | 24 | // pausar desde la Mente |
| 20 | 25 | await p.click('#mind-playstop'); await p.waitForTimeout(200); |
modified web/css/code.css +4 −0
| @@ -100,6 +100,10 @@ | ||
| 100 | 100 | #activity button:hover { color: var(--fg); } |
| 101 | 101 | #activity button.on { color: var(--fg); border-left-color: var(--accent); } |
| 102 | 102 | #activity img { width: 26px; height: 26px; margin-top: auto; margin-bottom: 6px; opacity: .85; } |
| 103 | +/* la elfa es un botón (abre la Mente): el botón va abajo, la imagen dentro */ | |
| 104 | +#activity #act-mind { margin-top: auto; margin-bottom: 6px; } | |
| 105 | +#activity #act-mind img { margin: 0; } | |
| 106 | +#activity button:focus-visible { outline: 2px solid var(--accent2); outline-offset: -2px; } | |
| 103 | 107 | |
| 104 | 108 | /* explorador */ |
| 105 | 109 | #sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--bg2); border-right: 1px solid var(--line); } |
modified web/index.html +1 −1
| @@ -96,7 +96,7 @@ | ||
| 96 | 96 | <button id="act-term" title="Terminal (Ctrl+`)"></button> |
| 97 | 97 | <button id="act-skills" title="Skills"></button> |
| 98 | 98 | <button id="act-settings" title="Ajustes y modelo"></button> |
| 99 | - <img src="img/elffuss-code.svg" alt="Elffuss" title="Elffuss Code"> | |
| 99 | + <button id="act-mind" title="Mente de Elffuss — cerebro autónomo" aria-label="Mente de Elffuss"><img src="img/elffuss-code.svg" alt=""></button> | |
| 100 | 100 | </nav> |
| 101 | 101 | <aside id="sidebar"> |
| 102 | 102 | <div id="explorer-head">EXPLORER<span id="explorer-proj"></span></div> |
modified web/js/ceo.js +13 −0
| @@ -160,6 +160,19 @@ | ||
| 160 | 160 | |
| 161 | 161 | function schedule() { if (timer) clearTimeout(timer); timer = setTimeout(tick, TICK_MS); } |
| 162 | 162 | |
| 163 | +// ¿Puede pensar AHORA? Para que la UI lo diga antes de prometer un ciclo: | |
| 164 | +// devuelve '' si sí, o el motivo ('leader' | 'running' | 'workspace' | | |
| 165 | +// 'provider'). Sin modelo de verdad (el anfitrión devuelve null en modo | |
| 166 | +// básico) no hay ciclo: con el motor de reglas solo salían propuestas basura | |
| 167 | +// escritas dentro del proyecto. | |
| 168 | +export async function whyNotThink() { | |
| 169 | + if (!isLeader) return 'leader'; | |
| 170 | + if (running) return 'running'; | |
| 171 | + if (!(await ws?.isReady())) return 'workspace'; | |
| 172 | + if (!getProvider()) return 'provider'; | |
| 173 | + return ''; | |
| 174 | +} | |
| 175 | + | |
| 163 | 176 | // «Pensar ahora» — salta la espera de ociosidad. Sigue respetando el |
| 164 | 177 | // semáforo: si otra pestaña es la líder, no compite por la GPU. |
| 165 | 178 | export async function forceCycle() { |
modified web/js/i18n.js +48 −0
| @@ -157,6 +157,30 @@ | ||
| 157 | 157 | cloneListing: "Listando el repo…", cloneHalf: "Descarga a medias de {repo} ({n}/{total} ficheros)", |
| 158 | 158 | reopenFolder: "Reabrir «{name}»", |
| 159 | 159 | openFolderBusy: "La elfa está trabajando en este proyecto. ¿Abrir otra carpeta igualmente?", |
| 160 | + // Mente y cerebro autónomo | |
| 161 | + mindThought: "pensamiento", mindEmpty: "(sin contenido)", mindOpenProposal: "Abrir la propuesta {name}", | |
| 162 | + mindOpenPath: "abrir {path} en el editor", mindExec: "▶ Ejecutar esta propuesta", mindOpenEditor: "Abrir en el editor", | |
| 163 | + mindFlyTo: "Llevar la cámara a {name}", mindLegend: "Perfiles del cerebro", | |
| 164 | + mindMusic: "♪ Poner música", mindMusicTitle: "Carga un reproductor de SoundCloud (esto sí sale a internet)", | |
| 165 | + mindMusicPlayer: "música", mindMusicOff: "■ Quitar música", | |
| 166 | + mindActivate: "▶ activar cerebro autónomo", mindResume: "▶ reanudar cerebro", mindPause: "⏸ pausar cerebro", | |
| 167 | + mindActivateTitle: "Cuando estés ocioso, revisa el proyecto con el modelo cargado y deja propuestas en {dir}/ (no toca tu código). Necesita un modelo de verdad.", | |
| 168 | + mindPauseTitle: "Pausar: deja de trabajar por su cuenta", | |
| 169 | + mindConfig: "⚙ cerebro", mindConfigTitle: "reprogramar el cerebro", mindHistory: "≡ historial", mindHistoryTitle: "ver todo lo que ha llegado", | |
| 170 | + mindClose: "✕ salir", mindCloseTitle: "salir (Esc)", mindLogTitle: "Historial completo", | |
| 171 | + cfgTitle: "⚙ Reprogramar el cerebro", cfgNotif: "🔔 Notificaciones del navegador:", cfgNotifAsk: "Activar", | |
| 172 | + cfgNotifUnsupported: "no soportadas por este navegador", cfgNotifGranted: "✓ concedidas — avisaré cuando encuentre algo bueno", | |
| 173 | + cfgNotifDenied: "✕ bloqueadas — actívalas en los ajustes del sitio del navegador", cfgNotifDefault: "aún no pedidas", | |
| 174 | + cfgMission: "Misión (qué quieres que haga por su cuenta)", cfgDir: "Carpeta-alma (dentro del proyecto)", | |
| 175 | + cfgProfiles: "Perfiles — cada uno piensa en paralelo, con el color de su estrella", cfgAddProf: "+ nuevo perfil", | |
| 176 | + cfgColor: "Color", cfgName: "Nombre", cfgFocus: "En qué se centra", cfgRemove: "quitar", | |
| 177 | + cfgThink: "Pensar ahora", cfgSave: "Reprogramar", | |
| 178 | + cfgNote: "La elfa trabajará según esto cuando estés ocioso y volcará todo en esa carpeta.", | |
| 179 | + cfgCant_provider: "Sin un modelo cargado no pienso: en modo Básico solo saldrían propuestas sin sentido. Elige un modelo en ⚙ Ajustes → Cerebro.", | |
| 180 | + cfgCant_workspace: "Abre una carpeta de proyecto primero.", | |
| 181 | + cfgCant_running: "Ya estoy pensando: espera a que termine este ciclo.", | |
| 182 | + cfgCant_leader: "Otra pestaña lleva el cerebro: hazlo desde ahí.", | |
| 183 | + avatarLabel: "Mente de Elffuss", | |
| 160 | 184 | }, |
| 161 | 185 | en: { |
| 162 | 186 | ph: 'Type here… (@ attaches a file)', |
| @@ -309,6 +333,30 @@ | ||
| 309 | 333 | cloneListing: "Listing the repo…", cloneHalf: "Half-finished download of {repo} ({n}/{total} files)", |
| 310 | 334 | reopenFolder: "Reopen “{name}”", |
| 311 | 335 | openFolderBusy: "The elf is working on this project. Open another folder anyway?", |
| 336 | + // Mind and autonomous brain | |
| 337 | + mindThought: "thought", mindEmpty: "(no content)", mindOpenProposal: "Open the proposal {name}", | |
| 338 | + mindOpenPath: "open {path} in the editor", mindExec: "▶ Run this proposal", mindOpenEditor: "Open in the editor", | |
| 339 | + mindFlyTo: "Fly the camera to {name}", mindLegend: "Brain profiles", | |
| 340 | + mindMusic: "♪ Play music", mindMusicTitle: "Loads a SoundCloud player (this does go to the internet)", | |
| 341 | + mindMusicPlayer: "music", mindMusicOff: "■ Remove music", | |
| 342 | + mindActivate: "▶ turn on the autonomous brain", mindResume: "▶ resume brain", mindPause: "⏸ pause brain", | |
| 343 | + mindActivateTitle: "When you are idle, it reviews the project with the loaded model and leaves proposals in {dir}/ (it does not touch your code). Needs a real model.", | |
| 344 | + mindPauseTitle: "Pause: stop working on its own", | |
| 345 | + mindConfig: "⚙ brain", mindConfigTitle: "reprogram the brain", mindHistory: "≡ history", mindHistoryTitle: "see everything that came in", | |
| 346 | + mindClose: "✕ exit", mindCloseTitle: "exit (Esc)", mindLogTitle: "Full history", | |
| 347 | + cfgTitle: "⚙ Reprogram the brain", cfgNotif: "🔔 Browser notifications:", cfgNotifAsk: "Turn on", | |
| 348 | + cfgNotifUnsupported: "not supported by this browser", cfgNotifGranted: "✓ granted — I'll let you know when I find something good", | |
| 349 | + cfgNotifDenied: "✕ blocked — turn them on in the browser's site settings", cfgNotifDefault: "not asked yet", | |
| 350 | + cfgMission: "Mission (what you want it to do on its own)", cfgDir: "Soul folder (inside the project)", | |
| 351 | + cfgProfiles: "Profiles — each one thinks in parallel, with the colour of its star", cfgAddProf: "+ new profile", | |
| 352 | + cfgColor: "Colour", cfgName: "Name", cfgFocus: "What it focuses on", cfgRemove: "remove", | |
| 353 | + cfgThink: "Think now", cfgSave: "Reprogram", | |
| 354 | + cfgNote: "The elf will work on this when you are idle and put everything in that folder.", | |
| 355 | + cfgCant_provider: "I don't think without a loaded model: in Basic mode only nonsense proposals would come out. Pick a model in ⚙ Settings → Brain.", | |
| 356 | + cfgCant_workspace: "Open a project folder first.", | |
| 357 | + cfgCant_running: "I'm already thinking: wait for this cycle to end.", | |
| 358 | + cfgCant_leader: "Another tab runs the brain: do it from there.", | |
| 359 | + avatarLabel: "Elffuss Mind", | |
| 312 | 360 | }, |
| 313 | 361 | }; |
| 314 | 362 |
modified web/js/main.js +12 −10
| @@ -1420,7 +1420,10 @@ | ||
| 1420 | 1420 | workspace: ceoWorkspace, |
| 1421 | 1421 | defaultProfiles: CEO_DEFAULT_PROFILES, |
| 1422 | 1422 | defaultMission: 'Revisar el proyecto y proponer mejoras concretas y accionables (código, procesos, datos o docs).', |
| 1423 | - provider: () => conv.getProvider(), | |
| 1423 | + // Sin modelo de verdad no hay cerebro: con el motor de reglas (modo Básico) | |
| 1424 | + // el CEO «pensaba» con el texto de ayuda, escribía .elffuss/soul/*.md dentro | |
| 1425 | + // del proyecto y anunciaba «4 mejoras» que no eran nada. | |
| 1426 | + provider: () => { const p = conv.getProvider(); return p && p !== rules ? p : null; }, | |
| 1424 | 1427 | // el usuario tiene PRIORIDAD: si CUALQUIER conversación está en cola o procesándose, el cerebro espera |
| 1425 | 1428 | isBusy: () => conv.isBusy(), |
| 1426 | 1429 | onEvent: (ch, ev) => { |
| @@ -1506,17 +1509,16 @@ | ||
| 1506 | 1509 | const noteAct = e => { if (!e.target.closest?.('#mind-overlay')) ceo.noteActivity(); }; |
| 1507 | 1510 | document.addEventListener('pointerdown', noteAct, true); |
| 1508 | 1511 | document.addEventListener('keydown', noteAct, true); |
| 1509 | -const elfAvatar = document.querySelector('#activity img'); | |
| 1512 | +// La elfa de la barra es un BOTÓN que abre la Mente, y nada más. Antes el | |
| 1513 | +// primer clic encendía en silencio el cerebro autónomo (que empezaba a trabajar | |
| 1514 | +// sobre tu proyecto) y pedía permiso de notificaciones sin explicar para qué. | |
| 1515 | +// Ahora el cerebro se enciende DENTRO de la Mente, con un botón que dice lo que | |
| 1516 | +// hace, y las notificaciones se piden solo desde ⚙ cerebro. | |
| 1517 | +const elfAvatar = $('act-mind'); | |
| 1510 | 1518 | if (elfAvatar) { |
| 1511 | - elfAvatar.style.cursor = 'pointer'; | |
| 1512 | 1519 | elfAvatar.title = t('avatarTitle'); |
| 1513 | - elfAvatar.addEventListener('click', () => { | |
| 1514 | - // auto-activa SOLO la primera vez (nunca decidiste play/stop); si lo | |
| 1515 | - // pausaste a propósito, abrir la Mente NO debe reactivarlo por sorpresa. | |
| 1516 | - if (!ceo.isEnabled() && !ceo.hasDecided()) ceo.enable(); | |
| 1517 | - try { if ('Notification' in window && Notification.permission === 'default') Notification.requestPermission(); } catch { /* */ } | |
| 1518 | - mind.openMind(); | |
| 1519 | - }); | |
| 1520 | + elfAvatar.setAttribute('aria-label', t('avatarLabel')); | |
| 1521 | + elfAvatar.addEventListener('click', () => mind.openMind()); | |
| 1520 | 1522 | } |
| 1521 | 1523 | // restaura tu última elección (play o stop) tal cual la dejaste |
| 1522 | 1524 | if (ceo.wasEnabledLastSession()) ceo.enable(); |
modified web/js/mind.js +149 −54
| @@ -47,24 +47,55 @@ | ||
| 47 | 47 | export function setOpenFile(fn) { onOpenFile = fn; } |
| 48 | 48 | export function setExecuteProposal(fn) { onExecute = fn; } |
| 49 | 49 | |
| 50 | -const escHtml = s => String(s).replace(/[<>&]/g, c => ({ '<': '<', '>': '>', '&': '&' }[c])); | |
| 50 | +// También las comillas: estos textos van dentro de atributos (value, title, | |
| 51 | +// aria-label) y un nombre de perfil con «"» rompía el atributo. | |
| 52 | +const escHtml = s => String(s).replace(/[<>&"']/g, c => ({ '<': '<', '>': '>', '&': '&', '"': '"', "'": ''' }[c])); | |
| 51 | 53 | const profileOf = channel => channel === 'ceo' |
| 52 | 54 | ? { id: 'ceo', name: 'CEO', color: CEO_COLOR } |
| 53 | 55 | : ceo.getProfiles().find(p => p.id === channel) || { id: channel, name: channel, color: '#7c5cff' }; |
| 54 | 56 | |
| 55 | -// ── música con Widget API (persistente: pausa al salir, reanuda al volver) ── | |
| 57 | +// ── música: SOLO si la pides ──────────────────────────────────────────────── | |
| 58 | +// Antes se cargaba un reproductor de SoundCloud con autoplay cada vez que | |
| 59 | +// abrías la Mente: una petición a un tercero en una app que promete que nada | |
| 60 | +// sale de tu máquina, y sonido sin haberlo pedido. Ahora hay un botón; el | |
| 61 | +// reproductor (con su propio control) solo existe mientras lo quieras, y «■ | |
| 62 | +// Quitar música» lo elimina del todo. | |
| 63 | +let musicOn = false, musicWrap = null; | |
| 56 | 64 | function mountMusic(root) { |
| 57 | - const wrap = document.createElement('div'); | |
| 58 | - wrap.className = 'mind-music'; | |
| 65 | + musicWrap = document.createElement('div'); | |
| 66 | + musicWrap.className = 'mind-music'; | |
| 67 | + root.appendChild(musicWrap); | |
| 68 | + paintMusic(); | |
| 69 | +} | |
| 70 | +function paintMusic() { | |
| 71 | + if (!musicWrap) return; | |
| 72 | + musicWrap.replaceChildren(); | |
| 73 | + const btn = document.createElement('button'); | |
| 74 | + btn.type = 'button'; | |
| 75 | + btn.className = 'mind-music-btn'; | |
| 76 | + btn.style.cssText = 'display:block;width:100%;background:rgba(10,6,24,.8);border:none;color:#ffd7e6;padding:7px 12px;font:inherit;font-size:.74rem;cursor:pointer;text-align:center'; | |
| 77 | + if (!musicOn) { | |
| 78 | + // Sin reproductor, la caja es solo el botón (sin el marco grande). | |
| 79 | + musicWrap.style.cssText = 'width:auto;border-radius:999px'; | |
| 80 | + btn.textContent = t('mindMusic'); | |
| 81 | + btn.title = t('mindMusicTitle'); | |
| 82 | + btn.onclick = () => { musicOn = true; paintMusic(); }; | |
| 83 | + musicWrap.appendChild(btn); | |
| 84 | + return; | |
| 85 | + } | |
| 86 | + musicWrap.style.cssText = ''; | |
| 59 | 87 | const url = 'https://w.soundcloud.com/player/?url=' + encodeURIComponent(SOUNDCLOUD) + |
| 60 | 88 | '&auto_play=true&hide_related=true&show_comments=false&show_user=false&show_reposts=false&visual=false&color=%23ff4d8d'; |
| 61 | - wrap.innerHTML = '<iframe id="mind-sc" title="música" width="100%" height="120" frameborder="no" allow="autoplay; encrypted-media" src="' + url + '"></iframe>' + | |
| 62 | - '<div class="mind-music-cap">▶ Dekel · Baoba Festival — modo trance</div>'; | |
| 63 | - root.appendChild(wrap); | |
| 64 | - const iframe = wrap.querySelector('#mind-sc'); | |
| 89 | + const iframe = document.createElement('iframe'); | |
| 90 | + iframe.id = 'mind-sc'; iframe.title = t('mindMusicPlayer'); iframe.width = '100%'; iframe.height = '120'; | |
| 91 | + iframe.setAttribute('frameborder', 'no'); iframe.allow = 'autoplay; encrypted-media'; iframe.src = url; | |
| 92 | + const cap = document.createElement('div'); cap.className = 'mind-music-cap'; cap.textContent = '▶ Dekel · Baoba Festival — modo trance'; | |
| 93 | + btn.textContent = t('mindMusicOff'); | |
| 94 | + btn.onclick = () => { musicOn = false; widget = null; paintMusic(); }; | |
| 95 | + musicWrap.append(iframe, cap, btn); | |
| 65 | 96 | const initWidget = () => { try { widget = window.SC.Widget(iframe); } catch { /* aún no */ } }; |
| 66 | 97 | if (window.SC && window.SC.Widget) initWidget(); |
| 67 | - else { const s = document.createElement('script'); s.src = 'https://w.soundcloud.com/player/api.js'; s.onload = initWidget; document.head.appendChild(s); } | |
| 98 | + else { const sc = document.createElement('script'); sc.src = 'https://w.soundcloud.com/player/api.js'; sc.onload = initWidget; document.head.appendChild(sc); } | |
| 68 | 99 | } |
| 69 | 100 | |
| 70 | 101 | // ══ ESTRELLAS de pensamiento: cada línea/tool-call nace, brilla y se apaga ══ |
| @@ -204,11 +235,20 @@ | ||
| 204 | 235 | mesh.userData = { path, md, text }; |
| 205 | 236 | nodesGroup.add(mesh); |
| 206 | 237 | thoughtNodes.push(mesh); |
| 207 | - const lab = document.createElement('div'); | |
| 238 | + // Un BOTÓN, y con pointer-events propios: la hoja de estilos pone | |
| 239 | + // `pointer-events:none` a las etiquetas y a su contenedor (para que el ratón | |
| 240 | + // pase al lienzo y se pueda girar la cámara), así que el clic nunca llegaba a | |
| 241 | + // la etiqueta y solo un raycast con suerte sobre la diminuta malla abría el | |
| 242 | + // panel. El contenedor sigue sin capturar; la etiqueta sí, y con el teclado. | |
| 243 | + const lab = document.createElement('button'); | |
| 244 | + lab.type = 'button'; | |
| 208 | 245 | lab.className = 'mind-node-label'; |
| 209 | - lab.textContent = (path || 'pensamiento').split('/').pop(); | |
| 210 | - // clicable ella misma — antes SOLO el raycast contra la diminuta malla 3D | |
| 211 | - // abría el panel, fácil de fallar; la etiqueta es el blanco visible real. | |
| 246 | + lab.style.pointerEvents = 'auto'; | |
| 247 | + lab.style.cursor = 'pointer'; | |
| 248 | + lab.style.fontFamily = 'inherit'; | |
| 249 | + const nombre = (path || t('mindThought')).split('/').pop(); | |
| 250 | + lab.textContent = nombre; | |
| 251 | + lab.setAttribute('aria-label', t('mindOpenProposal', { name: nombre })); | |
| 212 | 252 | lab.addEventListener('click', () => selectThoughtNode(mesh)); |
| 213 | 253 | document.getElementById('mind-anchors').appendChild(lab); |
| 214 | 254 | anchors.push({ el: lab, pos: mesh.position }); |
| @@ -222,21 +262,49 @@ | ||
| 222 | 262 | // selección de un nodo de propuesta — desde la malla 3D (raycast) o su etiqueta |
| 223 | 263 | function selectThoughtNode(mesh) { showThoughtPanel(mesh); focusOn(mesh.position, 26); } |
| 224 | 264 | |
| 265 | +// Abrir un fichero DESDE la Mente: primero se cierra la Mente. Antes la | |
| 266 | +// pestaña se abría detrás de esta capa, que lo tapa todo, y parecía que el | |
| 267 | +// botón no hacía nada. | |
| 268 | +function openInEditor(path) { | |
| 269 | + document.getElementById('mind-panel')?.classList.remove('show'); | |
| 270 | + closeMind(); | |
| 271 | + onOpenFile(path); | |
| 272 | +} | |
| 273 | +// Las rutas `entre comillas invertidas` de una propuesta se pueden abrir. | |
| 274 | +const PATH_RE = /^[\w.-]+(\/[\w.-]+)*\.[a-z0-9]{1,10}$/i; | |
| 275 | +function linkifyPaths(root) { | |
| 276 | + root.querySelectorAll('code').forEach(el => { | |
| 277 | + const p = el.textContent.trim(); | |
| 278 | + if (!PATH_RE.test(p) || /[{}()<>]/.test(p) || el.closest('pre')) return; | |
| 279 | + const a = document.createElement('a'); | |
| 280 | + a.href = '#'; | |
| 281 | + a.textContent = p; | |
| 282 | + a.title = t('mindOpenPath', { path: p }); | |
| 283 | + a.style.cssText = 'color:inherit;text-decoration:underline dotted'; | |
| 284 | + a.onclick = e => { e.preventDefault(); openInEditor(p); }; | |
| 285 | + el.replaceChildren(a); | |
| 286 | + }); | |
| 287 | +} | |
| 288 | + | |
| 225 | 289 | function showThoughtPanel(node) { |
| 226 | 290 | const root = document.getElementById('mind-panel'); |
| 227 | - const md = node.userData.md || node.userData.text || '(sin contenido)'; | |
| 228 | - const path = node.userData.path || 'pensamiento'; | |
| 229 | - root.innerHTML = `<div class="mp-head">${escHtml(path)}<button id="mp-x">✕</button></div>` + | |
| 291 | + const md = node.userData.md || node.userData.text || t('mindEmpty'); | |
| 292 | + const path = node.userData.path || t('mindThought'); | |
| 293 | + root.setAttribute('role', 'dialog'); | |
| 294 | + root.setAttribute('aria-label', path); | |
| 295 | + root.innerHTML = `<div class="mp-head">${escHtml(path)}<button id="mp-x" aria-label="${escHtml(t('close'))}">✕</button></div>` + | |
| 230 | 296 | `<div class="mp-body">${renderMarkdown(md)}</div>` + |
| 231 | 297 | `<div class="mp-actions">` + |
| 232 | - `<button id="mp-exec" class="mp-exec">▶ Ejecutar esta propuesta</button>` + | |
| 233 | - (node.userData.path ? `<button id="mp-open" class="mp-open">Abrir en el editor</button>` : '') + | |
| 298 | + `<button id="mp-exec" class="mp-exec">${escHtml(t('mindExec'))}</button>` + | |
| 299 | + (node.userData.path ? `<button id="mp-open" class="mp-open">${escHtml(t('mindOpenEditor'))}</button>` : '') + | |
| 234 | 300 | `</div>`; |
| 235 | 301 | root.classList.add('show'); |
| 302 | + linkifyPaths(root.querySelector('.mp-body')); | |
| 236 | 303 | root.querySelector('#mp-x').onclick = () => root.classList.remove('show'); |
| 237 | 304 | root.querySelector('#mp-exec').onclick = () => { onExecute(md); root.classList.remove('show'); }; |
| 238 | 305 | const openBtn = root.querySelector('#mp-open'); |
| 239 | - if (openBtn) openBtn.onclick = () => { onOpenFile(node.userData.path); root.classList.remove('show'); }; | |
| 306 | + if (openBtn) openBtn.onclick = () => openInEditor(node.userData.path); | |
| 307 | + root.querySelector('#mp-exec').focus(); | |
| 240 | 308 | } |
| 241 | 309 | |
| 242 | 310 | // ══ perfiles: anclas 3D + leyenda (recalculadas al abrir o al reprogramar) ══ |
| @@ -251,13 +319,16 @@ | ||
| 251 | 319 | }); |
| 252 | 320 | return map; |
| 253 | 321 | } |
| 322 | +// Botones (antes <div>: solo con ratón). Llevan la cámara a ese perfil. | |
| 254 | 323 | function renderLegend() { |
| 255 | 324 | const el = document.getElementById('mind-legend'); |
| 256 | 325 | if (!el) return; |
| 257 | 326 | const profs = ceo.getProfiles(); |
| 258 | - el.innerHTML = `<div class="ml-item" data-id="ceo"><span class="ml-sw" style="background:${CEO_COLOR}"></span>CEO</div>` + | |
| 259 | - profs.map(p => `<div class="ml-item" data-id="${p.id}"><span class="ml-sw" style="background:${p.color}"></span>${escHtml(p.name)}</div>`).join(''); | |
| 327 | + const reset = 'background:none;border:none;font:inherit;color:inherit;text-align:left;width:100%'; | |
| 328 | + el.innerHTML = `<button type="button" class="ml-item" data-id="ceo" style="${reset}"><span class="ml-sw" style="background:${CEO_COLOR}"></span>CEO</button>` + | |
| 329 | + profs.map(p => `<button type="button" class="ml-item" data-id="${escHtml(p.id)}" style="${reset}"><span class="ml-sw" style="background:${escHtml(p.color)}"></span>${escHtml(p.name)}</button>`).join(''); | |
| 260 | 330 | el.querySelectorAll('.ml-item').forEach(row => { |
| 331 | + row.title = t('mindFlyTo', { name: row.textContent }); | |
| 261 | 332 | row.onclick = () => { const pos = anchorMap.get(row.dataset.id); if (pos) focusOn(pos, 46); }; |
| 262 | 333 | }); |
| 263 | 334 | } |
| @@ -277,38 +348,49 @@ | ||
| 277 | 348 | function wireConfig(root) { |
| 278 | 349 | const btn = root.querySelector('#mind-config'); |
| 279 | 350 | const cfg = root.querySelector('#mind-cfg'); |
| 351 | + cfg.setAttribute('role', 'dialog'); | |
| 352 | + cfg.setAttribute('aria-labelledby', 'cfg-title'); | |
| 280 | 353 | const profRowHtml = p => `<div class="cfg-prof" data-id="${escHtml(p.id || '')}"> |
| 281 | - <input type="color" class="cp-color" value="${p.color || '#7c5cff'}"> | |
| 282 | - <input type="text" class="cp-name" value="${escHtml(p.name || '')}" placeholder="Nombre"> | |
| 283 | - <input type="text" class="cp-focus" value="${escHtml(p.focus || '')}" placeholder="En qué se centra"> | |
| 284 | - <button class="cp-del" title="quitar">✕</button></div>`; | |
| 285 | - const notifState = () => (!('Notification' in window)) ? { txt: 'no soportadas por este navegador', can: false } | |
| 286 | - : Notification.permission === 'granted' ? { txt: '✓ concedidas — avisaré cuando encuentre algo bueno', can: false } | |
| 287 | - : Notification.permission === 'denied' ? { txt: '✕ bloqueadas — actívalas en los ajustes del sitio del navegador', can: false } | |
| 288 | - : { txt: 'aún no pedidas', can: true }; | |
| 354 | + <input type="color" class="cp-color" value="${escHtml(p.color || '#7c5cff')}" aria-label="${escHtml(t('cfgColor'))}"> | |
| 355 | + <input type="text" class="cp-name" value="${escHtml(p.name || '')}" placeholder="${escHtml(t('cfgName'))}" aria-label="${escHtml(t('cfgName'))}"> | |
| 356 | + <input type="text" class="cp-focus" value="${escHtml(p.focus || '')}" placeholder="${escHtml(t('cfgFocus'))}" aria-label="${escHtml(t('cfgFocus'))}"> | |
| 357 | + <button class="cp-del" title="${escHtml(t('cfgRemove'))}" aria-label="${escHtml(t('cfgRemove'))}">✕</button></div>`; | |
| 358 | + const notifState = () => (!('Notification' in window)) ? { txt: t('cfgNotifUnsupported'), can: false } | |
| 359 | + : Notification.permission === 'granted' ? { txt: t('cfgNotifGranted'), can: false } | |
| 360 | + : Notification.permission === 'denied' ? { txt: t('cfgNotifDenied'), can: false } | |
| 361 | + : { txt: t('cfgNotifDefault'), can: true }; | |
| 289 | 362 | const draw = () => { |
| 290 | 363 | const profs = ceo.getProfiles(); |
| 291 | 364 | const ns = notifState(); |
| 365 | + // Etiquetas ASOCIADAS a sus campos (for/id): antes un lector de pantalla | |
| 366 | + // solo oía el placeholder, o nada. | |
| 292 | 367 | cfg.innerHTML = |
| 293 | - '<div class="cfg-head">⚙ Reprogramar el cerebro<button id="cfg-x">✕</button></div>' + | |
| 294 | - '<div class="cfg-notif">🔔 Notificaciones del navegador: ' + escHtml(ns.txt) + (ns.can ? ' <button id="cfg-notif-ask" class="cfg-notif-btn">Activar</button>' : '') + '</div>' + | |
| 295 | - '<label>Misión (qué quieres que haga por su cuenta)</label>' + | |
| 368 | + `<div class="cfg-head"><span id="cfg-title">${escHtml(t('cfgTitle'))}</span><button id="cfg-x" aria-label="${escHtml(t('close'))}">✕</button></div>` + | |
| 369 | + `<div class="cfg-notif">${escHtml(t('cfgNotif'))} ${escHtml(ns.txt)}` + (ns.can ? ` <button id="cfg-notif-ask" class="cfg-notif-btn">${escHtml(t('cfgNotifAsk'))}</button>` : '') + '</div>' + | |
| 370 | + `<label for="cfg-mission">${escHtml(t('cfgMission'))}</label>` + | |
| 296 | 371 | '<textarea id="cfg-mission" rows="3">' + escHtml(ceo.getMission()) + '</textarea>' + |
| 297 | - '<label>Carpeta-alma (dentro del proyecto)</label>' + | |
| 372 | + `<label for="cfg-dir">${escHtml(t('cfgDir'))}</label>` + | |
| 298 | 373 | '<input id="cfg-dir" value="' + escHtml(ceo.getSoulDir()) + '">' + |
| 299 | - '<label>Perfiles — cada uno piensa en paralelo, con el color de su estrella</label>' + | |
| 300 | - '<div id="cfg-profiles">' + profs.map(profRowHtml).join('') + '</div>' + | |
| 301 | - '<button id="cfg-add-prof" class="cfg-add">+ nuevo perfil</button>' + | |
| 302 | - '<div class="cfg-actions"><button id="cfg-think-now" class="cfg-ghost">Pensar ahora</button>' + | |
| 303 | - '<button id="cfg-save" class="cfg-save">Reprogramar</button></div>' + | |
| 304 | - '<div class="cfg-note">La elfa trabajará según esto cuando estés ocioso y volcará todo en esa carpeta.</div>'; | |
| 374 | + `<label id="cfg-prof-lbl">${escHtml(t('cfgProfiles'))}</label>` + | |
| 375 | + '<div id="cfg-profiles" role="group" aria-labelledby="cfg-prof-lbl">' + profs.map(profRowHtml).join('') + '</div>' + | |
| 376 | + `<button id="cfg-add-prof" class="cfg-add">${escHtml(t('cfgAddProf'))}</button>` + | |
| 377 | + `<div class="cfg-actions"><button id="cfg-think-now" class="cfg-ghost">${escHtml(t('cfgThink'))}</button>` + | |
| 378 | + `<button id="cfg-save" class="cfg-save">${escHtml(t('cfgSave'))}</button></div>` + | |
| 379 | + `<div class="cfg-note" id="cfg-note" role="status">${escHtml(t('cfgNote'))}</div>`; | |
| 305 | 380 | cfg.querySelector('#cfg-x').onclick = () => cfg.classList.remove('show'); |
| 306 | 381 | cfg.querySelector('#cfg-notif-ask')?.addEventListener('click', () => { Notification.requestPermission().then(draw); }); |
| 307 | 382 | cfg.querySelector('#cfg-add-prof').onclick = () => { |
| 308 | 383 | cfg.querySelector('#cfg-profiles').insertAdjacentHTML('beforeend', profRowHtml({ color: '#ff9f45', name: '', focus: '' })); |
| 309 | 384 | wireRows(); |
| 310 | 385 | }; |
| 311 | - cfg.querySelector('#cfg-think-now').onclick = () => { ceo.forceCycle(); cfg.classList.remove('show'); }; | |
| 386 | + // «Pensar ahora» sin modelo de verdad (modo básico) o sin proyecto: se dice | |
| 387 | + // aquí mismo en vez de cerrar el panel como si hubiera empezado. | |
| 388 | + cfg.querySelector('#cfg-think-now').onclick = async () => { | |
| 389 | + const motivo = await ceo.whyNotThink(); | |
| 390 | + if (motivo) { cfg.querySelector('#cfg-note').textContent = '⚠️ ' + t('cfgCant_' + motivo); return; } | |
| 391 | + ceo.forceCycle(); | |
| 392 | + cfg.classList.remove('show'); | |
| 393 | + }; | |
| 312 | 394 | cfg.querySelector('#cfg-save').onclick = () => { |
| 313 | 395 | // preserva el id original de cada perfil (si no, cada guardado los |
| 314 | 396 | // regeneraría desde el nombre y los ciclos en curso perderían el hilo) |
| @@ -322,12 +404,17 @@ | ||
| 322 | 404 | ceo.setSoulDir(cfg.querySelector('#cfg-dir').value); |
| 323 | 405 | ceo.setProfiles(rows); |
| 324 | 406 | if (!ceo.isEnabled()) ceo.enable(); |
| 407 | + paintPlay(); | |
| 325 | 408 | cfg.classList.remove('show'); |
| 326 | 409 | }; |
| 327 | 410 | wireRows(); |
| 328 | 411 | function wireRows() { cfg.querySelectorAll('.cp-del').forEach(b => { b.onclick = () => b.closest('.cfg-prof').remove(); }); } |
| 329 | 412 | }; |
| 330 | - btn.onclick = () => { if (cfg.classList.contains('show')) cfg.classList.remove('show'); else { draw(); cfg.classList.add('show'); } }; | |
| 413 | + btn.onclick = () => { | |
| 414 | + if (cfg.classList.contains('show')) { cfg.classList.remove('show'); return; } | |
| 415 | + draw(); cfg.classList.add('show'); | |
| 416 | + cfg.querySelector('#cfg-mission')?.focus(); | |
| 417 | + }; | |
| 331 | 418 | } |
| 332 | 419 | function wireHistory(root) { |
| 333 | 420 | const btn = root.querySelector('#mind-history'), panel = root.querySelector('#mind-log'); |
| @@ -336,16 +423,21 @@ | ||
| 336 | 423 | } |
| 337 | 424 | |
| 338 | 425 | // play/stop del cerebro, visible dentro de la Mente. La elección la persiste |
| 339 | -// ceo.js (misma clave que usa el clic en la elfa) → sobrevive a recargar. | |
| 426 | +// ceo.js → sobrevive a recargar. Abrir la Mente YA NO enciende el cerebro: se | |
| 427 | +// enciende aquí, a propósito, y el botón dice qué hace («activar» la primera | |
| 428 | +// vez, «reanudar» si lo pausaste). | |
| 429 | +let paintPlay = () => {}; | |
| 340 | 430 | function wirePlayStop(root) { |
| 341 | 431 | const btn = root.querySelector('#mind-playstop'); |
| 342 | - const paint = () => { | |
| 432 | + paintPlay = () => { | |
| 343 | 433 | const on = ceo.isEnabled(); |
| 344 | - btn.textContent = on ? '⏸ pausar cerebro' : '▶ reanudar cerebro'; | |
| 434 | + btn.textContent = on ? t('mindPause') : (ceo.hasDecided() ? t('mindResume') : t('mindActivate')); | |
| 435 | + btn.title = on ? t('mindPauseTitle') : t('mindActivateTitle', { dir: ceo.getSoulDir() }); | |
| 436 | + btn.setAttribute('aria-pressed', on ? 'true' : 'false'); | |
| 345 | 437 | btn.classList.toggle('paused', !on); |
| 346 | 438 | }; |
| 347 | - btn.onclick = () => { if (ceo.isEnabled()) ceo.disable(); else ceo.enable(); paint(); }; | |
| 348 | - paint(); | |
| 439 | + btn.onclick = () => { if (ceo.isEnabled()) ceo.disable(); else ceo.enable(); paintPlay(); }; | |
| 440 | + paintPlay(); | |
| 349 | 441 | } |
| 350 | 442 | |
| 351 | 443 | // ══ ciudad de fondo (motor de la app anfitriona, por debajo del mundo) ══════ |
| @@ -445,20 +537,23 @@ | ||
| 445 | 537 | export async function openMind() { |
| 446 | 538 | if (open) return; |
| 447 | 539 | open = true; |
| 448 | - if (built) { overlay.style.display = ''; try { widget?.play(); } catch {} startLoop(); return; } | |
| 540 | + if (built) { overlay.style.display = ''; if (musicOn) { try { widget?.play(); } catch {} } paintPlay(); startLoop(); return; } | |
| 449 | 541 | |
| 450 | 542 | overlay = document.createElement('div'); |
| 451 | 543 | overlay.id = 'mind-overlay'; |
| 544 | + overlay.setAttribute('role', 'dialog'); | |
| 545 | + overlay.setAttribute('aria-modal', 'true'); | |
| 546 | + overlay.setAttribute('aria-label', t('mindTitle')); | |
| 452 | 547 | overlay.innerHTML = |
| 453 | - '<canvas id="mind-canvas"></canvas>' + | |
| 548 | + '<canvas id="mind-canvas" aria-hidden="true"></canvas>' + | |
| 454 | 549 | `<div id="mind-title">${t('mindTitle')}</div>` + |
| 455 | - '<div id="mind-legend"></div>' + | |
| 456 | - '<button id="mind-playstop" title="pausar/reanudar el cerebro"></button>' + | |
| 457 | - '<button id="mind-config" title="reprogramar el cerebro">⚙ cerebro</button>' + | |
| 458 | - '<button id="mind-history" title="ver todo lo que ha llegado">≡ historial</button>' + | |
| 459 | - '<button id="mind-close" title="salir">✕ salir</button>' + | |
| 550 | + `<div id="mind-legend" role="group" aria-label="${escHtml(t('mindLegend'))}"></div>` + | |
| 551 | + '<button id="mind-playstop"></button>' + | |
| 552 | + `<button id="mind-config" title="${escHtml(t('mindConfigTitle'))}">${escHtml(t('mindConfig'))}</button>` + | |
| 553 | + `<button id="mind-history" title="${escHtml(t('mindHistoryTitle'))}">${escHtml(t('mindHistory'))}</button>` + | |
| 554 | + `<button id="mind-close" title="${escHtml(t('mindCloseTitle'))}">${escHtml(t('mindClose'))}</button>` + | |
| 460 | 555 | '<div id="mind-anchors"></div><div id="mind-panel"></div><div id="mind-cfg"></div>' + |
| 461 | - '<div id="mind-log"><div class="ml-head">Historial completo<button id="ml-x">✕</button></div><div id="mind-log-body"></div></div>'; | |
| 556 | + `<div id="mind-log"><div class="ml-head">${escHtml(t('mindLogTitle'))}<button id="ml-x" aria-label="${escHtml(t('close'))}">✕</button></div><div id="mind-log-body" role="log"></div></div>`; | |
| 462 | 557 | document.body.appendChild(overlay); |
| 463 | 558 | wireConfig(overlay); wireHistory(overlay); wirePlayStop(overlay); |
| 464 | 559 | mountMusic(overlay); |