Elffuss BraidHub

utopia-ia/elffuss-claw public

coordinated: Agent.handle takes an optional tool allowlist

handle(text, onEvent, { signal, permitir }): a tool that permitir() rejects
is not run; the model gets an ERROR result that says it can only read here
and should propose the change as text. The autonomous brain passes a
read-only list through ceo.js (allowTool). Callers that do not pass it are
unchanged.

Coordinated: agent.js has large uncommitted edits in the live tree (live
context as a message, <function> tags, prefill events). This touches only the
signature of handle() and _turno() and the runTool call; a merge should keep
the live prompt and prefill changes and add the permitir check around
runTool.

Integration (onto stop-fix 7147228 / main 10073b7): main 66c2865 holds the
live-tree edits named above. The only conflict was the runTool call, which
stop-fix 5f91e5a races against the turn signal (hastaQueParen): a tool that
permitir() lets through still runs inside that race, so a stop during a tool
or a permission dialog ends the turn as before.
Changesetbadd8fcabf9c8091fe6213396e2e69221d71ead817fdd23b716ae054e9647d9c
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-10 16:32 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 17:46 +02:00
Parentsa677a77c12ff

Browse the files at this changeset

1 file changed

modified web/js/agent.js +17 −9
@@ -354,16 +354,20 @@
354354 // CEO…—: abortarlo para este agente igual que stop(). Si ya llega abortado,
355355 // ni se apunta el mensaje en el histórico ni se llama al modelo (igual que en
356356 // Elffuss Code).
357- async handle(userText, onEvent, { signal: deFuera = null } = {}) {
357+ //
358+ // `permitir` (opcional): (nombre de herramienta) => bool. Lo que no pasa no se
359+ // ejecuta: el modelo recibe un ERROR que se lo explica. Lo usa el cerebro
360+ // autónomo, que solo puede leer (ver ceo.js `allowTool`).
361+ async handle(userText, onEvent, { signal: deFuera = null, permitir = null } = {}) {
358362 const aborter = (this._aborter = new AbortController());
359363 if (deFuera?.aborted) { onEvent({ type: 'aborted', text: t('stopped') }); return; }
360364 const alAbortar = () => aborter.abort();
361365 deFuera?.addEventListener?.('abort', alAbortar, { once: true });
362- try { return await this._turno(userText, onEvent, aborter.signal); }
366+ try { return await this._turno(userText, onEvent, aborter.signal, permitir); }
363367 finally { deFuera?.removeEventListener?.('abort', alAbortar); }
364368 }
365369
366- async _turno(userText, onEvent, signal) {
370+ async _turno(userText, onEvent, signal, permitir = null) {
367371 const parado = () => onEvent({ type: 'aborted', text: t('stopped') });
368372 // La marca temporal se pone AL AÑADIR, que es el único momento en que se
369373 // sabe: el gestor de contexto resuelve «ayer» con la fecha del turno en que
@@ -440,12 +444,16 @@
440444
441445 onEvent({ type: 'tool', call });
442446 let result;
443- try { result = await hastaQueParen(runTool(call.tool, call.args), signal); }
444- catch (e) {
445- // Parado con la herramienta en marcha: el turno acaba aquí y no apunta
446- // nada de este paso (la herramienta puede acabar por detrás).
447- if (signal.aborted) return parado();
448- result = 'ERROR: ' + e.message;
447+ if (permitir && !permitir(call.tool)) {
448+ result = `ERROR: aquí solo puedes leer; «${call.tool}» cambiaría cosas y no está permitida. Propón ese cambio en texto.`;
449+ } else {
450+ try { result = await hastaQueParen(runTool(call.tool, call.args), signal); }
451+ catch (e) {
452+ // Parado con la herramienta en marcha: el turno acaba aquí y no apunta
453+ // nada de este paso (la herramienta puede acabar por detrás).
454+ if (signal.aborted) return parado();
455+ result = 'ERROR: ' + e.message;
456+ }
449457 }
450458 const resultStr = typeof result === 'string' ? result : JSON.stringify(result);
451459 lastResult = resultStr;