Elffuss BraidHub

utopia-ia/elffuss-code public

main · 2.3 KiBRawPermalink
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.
6import { t } from '../i18n.js';
7export const name = 'Básico (sin modelo)';
8export async function load() {}
9
10const call = obj => '```tool\n' + JSON.stringify(obj) + '\n```';
11
12export async function chat(history, systemPrompt) {
13 const last = history[history.length - 1];
14 const text = (last?.content || '').trim();
15
16 // 🎯 Modo Objetivo (goal.js) también funciona en modo básico: un plan fijo
17 // de 2 tareas (explorar + escribir), para poder probar/usar el planificador
18 // sin depender de un modelo real cargado.
19 if (/^ROL: PLANIFICADOR/.test(systemPrompt || '')) {
20 return JSON.stringify({
21 plan: 'Plan básico (sin modelo) para: ' + text.slice(0, 60),
22 tasks: [
23 { title: 'Explorar el proyecto', description: 'Mira el árbol del proyecto para entender qué hay.' },
24 { title: 'Escribir el resultado', description: 'escribe objetivo.txt: ' + text },
25 ],
26 });
27 }
28
29 if (text.startsWith('[resultado')) {
30 const body = text.slice(text.indexOf('\n') + 1).trim();
31 return body.startsWith('ERROR:') ? 'No pude: ' + body.slice(6).trim() : body;
32 }
33
34 const low = text.toLowerCase();
35 if (/(árbol|arbol|estructura|qué hay|que hay|\btree\b|\bstructure\b|what'?s in)/.test(low))
36 return call({ tool: 'code.tree', args: {} });
37 const mRead = text.match(/(?:lee|abre|muestra|cat|read|open|show)\s+([\w./-]+\.\w+)/i);
38 if (mRead) return call({ tool: 'code.read', args: { path: mRead[1] } });
39 const mSearch = text.match(/(?:busca(?:r)?\s+(?:d[oó]nde\s+)?(?:se\s+\w+\s+)?|(?:search|find)\s+(?:for\s+)?)["«“']?([^"»”']{2,60})["»”']?$/i);
40 if (mSearch) return call({ tool: 'code.search', args: { query: mSearch[1].trim() } });
41 const mWrite = text.match(/(?:escribe|write)\s+([\w./-]+\.\w+)\s*[:=]\s*([\s\S]+)/i);
42 if (mWrite) return call({ tool: 'code.write', args: { path: mWrite[1], content: mWrite[2] } });
43
44 if (/^(hola|buenas|hey|hi|hello)\b/.test(low)) return t('rulesHello') + ' ' + t('rulesHelp');
45 return t('rulesHelp');
46}