| 1 | // Modo básico de Elffuss Code: órdenes deterministas sin modelo. |
| 2 | export const name = 'Básico (sin modelo)'; |
| 3 | export async function load() {} |
| 4 | |
| 5 | const call = obj => '```tool\n' + JSON.stringify(obj) + '\n```'; |
| 6 | |
| 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 | export async function chat(history, systemPrompt) { |
| 15 | const last = history[history.length - 1]; |
| 16 | const text = (last?.content || '').trim(); |
| 17 | |
| 18 | // 🎯 Modo Objetivo (goal.js) también funciona en modo básico: un plan fijo |
| 19 | // de 2 tareas (explorar + escribir), para poder probar/usar el planificador |
| 20 | // sin depender de un modelo real cargado. |
| 21 | if (/^ROL: PLANIFICADOR/.test(systemPrompt || '')) { |
| 22 | return JSON.stringify({ |
| 23 | plan: 'Plan básico (sin modelo) para: ' + text.slice(0, 60), |
| 24 | tasks: [ |
| 25 | { title: 'Explorar el proyecto', description: 'Mira el árbol del proyecto para entender qué hay.' }, |
| 26 | { title: 'Escribir el resultado', description: 'escribe objetivo.txt: ' + text }, |
| 27 | ], |
| 28 | }); |
| 29 | } |
| 30 | |
| 31 | if (text.startsWith('[resultado')) { |
| 32 | const body = text.slice(text.indexOf('\n') + 1).trim(); |
| 33 | return body.startsWith('ERROR:') ? 'No pude: ' + body.slice(6).trim() : body; |
| 34 | } |
| 35 | |
| 36 | const t = text.toLowerCase(); |
| 37 | if (/(árbol|arbol|estructura|qué hay|que hay)/.test(t)) |
| 38 | return call({ tool: 'code.tree', args: {} }); |
| 39 | const mRead = text.match(/(?:lee|abre|muestra|cat)\s+([\w./-]+\.\w+)/i); |
| 40 | 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); |
| 42 | 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); |
| 44 | if (mWrite) return call({ tool: 'code.write', args: { path: mWrite[1], content: mWrite[2] } }); |
| 45 | |
| 46 | if (/^(hola|buenas|hey|hi)\b/.test(t)) return '¡Hola! ' + HELP; |
| 47 | return HELP; |
| 48 | } |