Elffuss BraidHub

utopia-ia/elffuss-claw public

sync-core.sh no longer overwrites what the core does not have

Open item from the Claw stop-fix work: sync-core.sh copied the core's files
over web/js/ blindly, so running it would have brought back the CEO tick
race, the bare-signal api.js and an older mind.js from core main. This is
Elffuss Code's script from its integration branch (97239cd), byte for byte,
with its test.

It compares each file's code with comments stripped (the core's comments
are in English): the same code is copied as before; a file whose code
differs is left alone, listed, and the script exits with an error, because
either the core is ahead (then --force) or this app has something the core
lacks (port it to the core first).

Run on a scratch copy against the core's stop-fix branch (4ce74a2), it copies
telemetry.js and providers/api.js (same code) and refuses context.js,
embed.js, skills.js, md.js, splash-gl.js, ceo.js, mind.js and humanize.js.
What differs on purpose in Claw: ceo.js has the read-only tool list
(allowTool) and the ceoDecision key; md.js has links and linkify(); mind.js
shows "pausing…" until a paused cycle really ends (stop-fix 93d7b78), which
Code's Mind does not, and takes its strings and modal through Claw's own
i18n.js and modal.js. The other four were already different before these
branches.

tests/sync-core.mjs runs the script on a throwaway repo and core: comments
only sync, a code difference is not overwritten and is reported (a // inside
a string counts as code), and --force copies as before.
Changeset7329589f2158cbc77e5f2025afcb1de9ab3b6706fb19930b95c5927200077557
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-11 18:20 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 18:20 +02:00
Parentsbfc062d16e40

Browse the files at this changeset

2 files changed

modified sync-core.sh +78 −3
@@ -2,10 +2,85 @@
22 # Sincroniza el core compartido (repo elffuss) a web/js/. Ejecuta tras clonar
33 # el core al lado, o cuando el core cambie. Los archivos quedan vendorizados
44 # (este repo es autocontenido: clona y abre, sin build).
5+#
6+# Antes copiaba a ciegas, y un cambio hecho aquí que el core no tenía se perdía
7+# en silencio en la siguiente sincronización (pasó con la parada del proveedor
8+# API, y context.js, mind.js y otros llevan tiempo distintos). Ahora compara el
9+# CÓDIGO de cada fichero, sin comentarios (el core los tiene en inglés): si es
10+# el mismo, lo copia; si no, NO lo pisa, lo dice y termina con error. Puede ser
11+# que el core vaya por delante (entonces --force) o que aquí haya algo que el
12+# core no tiene (entonces hay que llevarlo al core antes).
13+#
14+# ./sync-core.sh [ruta/al/core] [--force]
515 set -euo pipefail
616 cd "$(dirname "$0")"
7-CORE=${1:-../elffuss/core}
17+FORCE=0; CORE=../elffuss/core
18+for a in "$@"; do if [ "$a" = "--force" ]; then FORCE=1; else CORE="$a"; fi; done
819 [ -d "$CORE" ] || { echo "No encuentro el core en $CORE (clona github.com/KikoCis/elffuss al lado)"; exit 1; }
9-for f in context.js embed.js skills.js md.js splash-gl.js ceo.js mind.js humanize.js telemetry.js; do cp "$CORE/$f" web/js/$f; done
10-cp "$CORE/providers/api.js" web/js/providers/api.js
20+
21+# ¿Mismo código, sin contar comentarios ni líneas en blanco? (sale 0 si sí)
22+mismo_codigo() {
23+ python3 -I - "$1" "$2" <<'PY'
24+import sys
25+REGEX_PREV = set('(,=:[!&|?{};+-*%<>~^')
26+ANTES_DE_REGEX = ('return', 'typeof', 'case', 'do', 'else', 'in', 'of', 'void', 'yield', 'await')
27+def codigo(src):
28+ out, i, n, ultimo, palabra = [], 0, len(src), '', ''
29+ while i < n:
30+ c, sig = src[i], src[i + 1] if i + 1 < n else ''
31+ if c == '/' and sig == '/':
32+ j = src.find('\n', i); i = n if j < 0 else j; continue
33+ if c == '/' and sig == '*':
34+ j = src.find('*/', i + 2); i = n if j < 0 else j + 2; continue
35+ if c in '"\'':
36+ j = i + 1
37+ while j < n and src[j] != c and src[j] != '\n':
38+ j += 2 if src[j] == '\\' else 1
39+ out.append(src[i:j + 1]); ultimo = c; i = j + 1; continue
40+ if c == '`':
41+ j, prof = i + 1, 0
42+ while j < n:
43+ if src[j] == '\\': j += 2; continue
44+ if src[j] == '$' and j + 1 < n and src[j + 1] == '{': prof += 1; j += 2; continue
45+ if src[j] == '}' and prof: prof -= 1; j += 1; continue
46+ if src[j] == '`' and not prof: break
47+ j += 1
48+ out.append(src[i:j + 1]); ultimo = '`'; i = j + 1; continue
49+ if c == '/' and (ultimo == '' or ultimo in REGEX_PREV or palabra in ANTES_DE_REGEX):
50+ j, clase = i + 1, False
51+ while j < n and src[j] != '\n':
52+ if src[j] == '\\': j += 2; continue
53+ if src[j] == '[': clase = True
54+ elif src[j] == ']': clase = False
55+ elif src[j] == '/' and not clase: break
56+ j += 1
57+ j += 1
58+ while j < n and src[j].isalpha(): j += 1
59+ out.append(src[i:j]); ultimo = '/'; i = j; continue
60+ out.append(c)
61+ if not c.isspace():
62+ ultimo = c
63+ palabra = (palabra + c) if (c.isalnum() or c in '_$') else ''
64+ elif palabra:
65+ pass
66+ i += 1
67+ return [l.rstrip() for l in ''.join(out).split('\n') if l.strip()]
68+a, b = (open(p, encoding='utf-8').read() for p in sys.argv[1:3])
69+sys.exit(0 if codigo(a) == codigo(b) else 1)
70+PY
71+}
72+
73+distintos=()
74+for f in context.js embed.js skills.js md.js splash-gl.js ceo.js mind.js humanize.js telemetry.js providers/api.js; do
75+ if [ "$FORCE" = 0 ] && [ -f "web/js/$f" ] && ! mismo_codigo "$CORE/$f" "web/js/$f"; then
76+ distintos+=("$f"); continue
77+ fi
78+ cp "$CORE/$f" "web/js/$f"
79+done
80+if [ ${#distintos[@]} -gt 0 ]; then
81+ echo "⚠️ No sincronizados: su código aquí no es el del core (comentarios aparte):"
82+ for f in "${distintos[@]}"; do echo " web/js/$f"; done
83+ echo " Si aquí hay algo que el core no tiene, llévalo antes al core; si es el core el que va por delante, ./sync-core.sh --force."
84+ exit 1
85+fi
1186 echo "✳ core sincronizado desde $CORE"
added tests/sync-core.mjs +58 −0
@@ -0,0 +1,58 @@
1+// sync-core.sh ya no pisa en silencio lo que el core no tiene.
2+//
3+// Copiaba los ficheros del core encima de web/js/ a ciegas: un cambio hecho
4+// aquí y no en el core (la parada del proveedor API, la Mente…) se perdía en la
5+// siguiente sincronización. Ahora compara el código sin comentarios:
6+// 1. mismo código (solo cambian los comentarios): copia;
7+// 2. código distinto: no lo toca, lo dice y sale con error;
8+// 3. --force: copia igual, como antes.
9+// Sobre una copia de mentira del repo y del core en una carpeta temporal.
10+//
11+// node tests/sync-core.mjs
12+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, copyFileSync } from 'node:fs';
13+import { tmpdir } from 'node:os';
14+import { join, dirname } from 'node:path';
15+import { fileURLToPath } from 'node:url';
16+import { spawnSync } from 'node:child_process';
17+const SCRIPT = join(dirname(fileURLToPath(import.meta.url)), '..', 'sync-core.sh');
18+let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
19+
20+const FICHEROS = ['context.js', 'embed.js', 'skills.js', 'md.js', 'splash-gl.js', 'ceo.js', 'mind.js', 'humanize.js', 'telemetry.js', 'providers/api.js'];
21+function montar(aqui, core) {
22+ const base = mkdtempSync(join(process.env.TMPDIR || tmpdir(), 'sync-core-'));
23+ const repo = join(base, 'repo'), dirCore = join(base, 'core');
24+ for (const d of [join(repo, 'web/js/providers'), join(dirCore, 'providers')]) mkdirSync(d, { recursive: true });
25+ copyFileSync(SCRIPT, join(repo, 'sync-core.sh'));
26+ for (const f of FICHEROS) {
27+ writeFileSync(join(repo, 'web/js', f), aqui[f] ?? `export const x = 1; // ${f}\n`);
28+ writeFileSync(join(dirCore, f), core[f] ?? `export const x = 1; // ${f}\n`);
29+ }
30+ return { repo, dirCore, corre: (...extra) => spawnSync('bash', [join(repo, 'sync-core.sh'), dirCore, ...extra], { encoding: 'utf8' }) };
31+}
32+
33+// 1 · mismo código, comentarios en otro idioma: copia
34+{
35+ const m = montar(
36+ { 'ceo.js': '// cerebro CEO\nconst url = "https://ejemplo"; // la web\nexport const a = 1;\n' },
37+ { 'ceo.js': '// CEO brain\nconst url = "https://ejemplo"; // the site\nexport const a = 1;\n' });
38+ const r = m.corre();
39+ const copiado = readFileSync(join(m.repo, 'web/js/ceo.js'), 'utf8');
40+ ok('1 · mismo código (solo cambian los comentarios): sincroniza y sale bien', r.status === 0 && /CEO brain/.test(copiado), `${r.status} ${r.stdout}${r.stderr}`);
41+}
42+// 2 · aquí hay código que el core no tiene: no lo pisa
43+{
44+ const aqui = 'export function f() {\n if (parar) return; // lo nuevo\n return 1;\n}\n';
45+ const m = montar({ 'mind.js': aqui, 'md.js': 'const s = "a // no es comentario";\n' }, { 'mind.js': 'export function f() {\n return 1;\n}\n', 'md.js': 'const s = "a // tampoco";\n' });
46+ const r = m.corre();
47+ const quedo = readFileSync(join(m.repo, 'web/js/mind.js'), 'utf8');
48+ ok('2 · código distinto: no lo pisa', quedo === aqui, quedo);
49+ ok(' …lo dice, con el fichero', r.status !== 0 && /web\/js\/mind\.js/.test(r.stdout), `${r.status} ${r.stdout}`);
50+ ok(' …y un // dentro de una cadena es código, no comentario (md.js tampoco se pisa)', /web\/js\/md\.js/.test(r.stdout), r.stdout);
51+ ok(' …y el resto sí se sincroniza', /ceo\.js/.test(readFileSync(join(m.repo, 'web/js/ceo.js'), 'utf8')), '');
52+ // 3 · --force: como antes
53+ const f = m.corre('--force');
54+ ok('3 · --force copia igual (como antes)', f.status === 0 && readFileSync(join(m.repo, 'web/js/mind.js'), 'utf8') === 'export function f() {\n return 1;\n}\n', `${f.status} ${f.stdout}`);
55+}
56+
57+console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ sync-core.sh no pisa en silencio lo que el core no tiene');
58+process.exit(fails ? 1 : 0);