Elffuss BraidHub

utopia-ia/elffuss-claw public

Hash routes module, safe links in chat markdown, no fragment in error reports

- rutas.js: #/<section>[/<detail>] for the tabs (vista, apps, tareas, vault,
  skills, permisos, ajustes), #/apps/<name>, #/tareas/<id>,
  #/tareas/automatizaciones, #/skills/<name>, #/ajustes/acerca, #/mente,
  #/mente/<proposal path> and the #/modelo action (focus the model picker).
  reflejar() writes the current place with pushState (a user click) or
  replaceState (something that happened on its own), so Back walks what the
  user did; alCambiar() listens to hashchange, and an empty hash is the View.
  Secret names and memory facts never go in a URL.
- md.js: [text](target) and bare URLs become links, only for http(s) (new tab,
  rel="noopener noreferrer") and internal #/ routes (same tab). Any other
  scheme (javascript:, data:, file:) stays text, code spans and blocks are
  left alone, and the href is escaped. linkify() does the same for plain
  text such as tool results. Before, no URL in the chat could be opened.
- telemetry.js: reports carry origin, path and query, not the fragment, which
  now holds app names, task ids and paths inside the authorized folder.

md.js and telemetry.js are identical in Elffuss Code; Code's copies do not
have these changes yet.
Changesete3eaa60b500a54ad57e2f4772b01e1c5dc9cd3ba8446da56241c8017ca38eaae
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-10 16:03 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 17:45 +02:00
Parents122281d349f8

Browse the files at this changeset

3 files changed

modified web/js/md.js +0 −0

Binary content is not shown. View the file.

added web/js/rutas.js +59 −0
@@ -0,0 +1,59 @@
1+// Rutas con el hash: #/<sección>[/<detalle>]. Sin dependencias.
2+// ─────────────────────────────────────────────────────────────────────────────
3+// Claw no tenía estado en la URL: ni un panel ni una app se podían enlazar,
4+// guardar en marcadores o recuperar con «Atrás», y los avisos del chat («Tarea
5+// t… programada», «Guardado en .elffuss/soul/…») no llevaban a ningún sitio.
6+//
7+// #/vista · #/apps · #/apps/<nombre> · #/tareas · #/tareas/<id>
8+// #/tareas/automatizaciones · #/vault · #/skills · #/skills/<nombre>
9+// #/permisos · #/ajustes · #/ajustes/acerca · #/mente · #/mente/<ruta>
10+// #/modelo → no es un sitio, es una acción: enfoca el selector de modelo.
11+//
12+// Lo que NUNCA va en una URL: nombres de secretos ni hechos de la memoria. Un
13+// fragmento acaba en el historial del navegador y, si alguien activa los
14+// informes de errores, cerca del campo url (telemetry.js quita el hash).
15+//
16+// El detalle es relativo y corto (un nombre de app, un id de tarea, una ruta
17+// DENTRO de la carpeta autorizada): ninguna ruta de disco completa llega aquí,
18+// porque el navegador solo nos da el nombre de la carpeta, no dónde está.
19+export const SECCIONES = ['vista', 'apps', 'tareas', 'vault', 'skills', 'permisos', 'ajustes', 'mente', 'modelo'];
20+
21+export function leer(hash = location.hash) {
22+ const m = /^#\/([a-z]+)(?:\/(.*))?$/.exec(hash || '');
23+ if (!m || !SECCIONES.includes(m[1])) return null;
24+ let detalle = null;
25+ if (m[2]) { try { detalle = decodeURIComponent(m[2]); } catch { detalle = m[2]; } }
26+ return { seccion: m[1], detalle };
27+}
28+
29+export function href(seccion, detalle = null) {
30+ return '#/' + seccion + (detalle != null && detalle !== '' ? '/' + encodeURIComponent(detalle) : '');
31+}
32+
33+// Refleja en la URL dónde está el usuario. `push` crea una entrada de historial
34+// (un clic suyo: «Atrás» lo deshace); sin `push` se reemplaza la actual (algo que
35+// pasa solo, como abrir la Vista al crear una app, no debe llenar el historial).
36+// Ni pushState ni replaceState disparan hashchange: reflejar no re-navega.
37+export function reflejar(seccion, detalle = null, { push = false } = {}) {
38+ const h = href(seccion, detalle);
39+ if (location.hash === h) return;
40+ try { history[push ? 'pushState' : 'replaceState'](history.state, '', h); } catch { /* sandbox o file: */ }
41+}
42+
43+// Navegar: igual que pulsar un enlace. Dispara hashchange, y quien escuche
44+// abre lo que toque.
45+export function ir(seccion, detalle = null) {
46+ const h = href(seccion, detalle);
47+ if (location.hash === h) { dispatchEvent(new HashChangeEvent('hashchange')); return; }
48+ location.hash = h;
49+}
50+
51+// hashchange llega con «Atrás»/«Adelante», con un enlace pulsado y con la URL
52+// editada a mano. Sin fragmento (volver al principio con «Atrás») es la Vista,
53+// que es donde arranca la app.
54+export function alCambiar(fn) {
55+ addEventListener('hashchange', () => {
56+ const r = leer() || (!location.hash || location.hash === '#' ? { seccion: 'vista', detalle: null } : null);
57+ if (r) fn(r);
58+ });
59+}
modified web/js/telemetry.js +4 −1
@@ -32,7 +32,10 @@
3232 body: JSON.stringify({
3333 app: appName, kind, message: String(message ?? '').slice(0, 2000),
3434 stack: String(opts.stack || '').slice(0, 4000),
35- url: location.href, userAgent: navigator.userAgent,
35+ // Sin el fragmento (#/…): la app guarda ahí dónde estás (rutas.js) —
36+ // un nombre de app, un id de tarea, una ruta dentro de tu carpeta— y
37+ // eso no tiene por qué viajar en un informe de error.
38+ url: location.origin + location.pathname + location.search, userAgent: navigator.userAgent,
3639 extra: String(opts.extra || '').slice(0, 2000),
3740 }),
3841 });