@thebattlearena/battle-arena-hooks 0.5.3-beta.55 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -11
- package/cli.mjs +48 -2
- package/lib/ghostty-theme.mjs +162 -0
- package/lib/icon-font.mjs +36 -18
- package/lib/radio-install.mjs +2 -2
- package/package.json +2 -1
- package/plugin/.claude-plugin/plugin.json +3 -1
- package/plugin/hooks/pane.tsx +3 -1
- package/plugin/hooks/ring-pane.tsx +95 -5
- package/plugin/hooks/ring.ts +100 -10
- package/plugin/tests/ring-pane.test.tsx +51 -0
- package/plugin/tests/ring.test.ts +193 -1
- package/plugin/types/index.d.ts +7 -0
- package/ring/scripts/live-hook.mjs +28 -13
- package/ring/scripts/live.mjs +27 -1
- package/ring/scripts/monitors.mjs +67 -9
- package/ring/skills/weigh-in/SKILL.md +8 -2
- package/themes/ghostty/Battle Arena +25 -0
package/README.md
CHANGED
|
@@ -80,6 +80,24 @@ y `npm install` baja su dependencia SOLO en esa carpeta; los hooks `.mjs` siguen
|
|
|
80
80
|
canciones siguen en la web). La API no da la duración ni el artista: el panel muestra lo que lleva
|
|
81
81
|
sonando y el título que arma la API.
|
|
82
82
|
|
|
83
|
+
### El tema de Ghostty — opcional
|
|
84
|
+
|
|
85
|
+
Los colores de la marca en la terminal: fondo navy `#061224`, cursor coral `#F26464`, azul `#2684FF`
|
|
86
|
+
y la paleta ANSI de los tokens dark de `apps/web`. El tema vive en `themes/ghostty/Battle Arena`:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npx @thebattlearena/battle-arena-hooks@latest install --with theme
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Lo copia a `~/.config/ghostty/themes/` y lo elige en la config de Ghostty que ya exista
|
|
93
|
+
(`config.ghostty` o `config`, en `~/.config/ghostty/` o en `~/Library/Application Support/com.mitchellh.ghostty/`):
|
|
94
|
+
Ghostty las carga en orden y gana el último `theme =`, así que sólo toca la config que decide: la
|
|
95
|
+
última con tema (cambia su último `theme =` y anota el anterior, tal cual, en un comentario) o, si
|
|
96
|
+
ninguna tiene, la última que exista. Si ya tenías un tema «Battle Arena» propio, no lo pisa. Nunca crea la config: sin ella imprime `theme = Battle Arena` para que
|
|
97
|
+
la pegues. También imprime, sin escribirlas, las líneas del look completo (JetBrains Mono, márgenes de
|
|
98
|
+
la ventana e ícono coral en macOS). Como la radio, queda en `"with"` de config.json. `uninstall`
|
|
99
|
+
regresa el tema que tenías y quita el archivo sólo si es el nuestro y ninguna config lo sigue eligiendo. Se ve al recargar la config de Ghostty (⌘⇧,).
|
|
100
|
+
|
|
83
101
|
Los comandos del Scorecard no llevan el prefijo del plugin (así registra Claude Code los comandos de
|
|
84
102
|
un módulo), por eso su nombre ya es único.
|
|
85
103
|
|
|
@@ -114,6 +132,7 @@ apps/claude-hooks/
|
|
|
114
132
|
skills/ las skills (las genera `npm run bundle:skill`)
|
|
115
133
|
tests/ pruebas del Scorecard (`claude plugin test plugin`)
|
|
116
134
|
radio/player.mjs radio/package.json reproductor de la radio (solo con `install --with radio`)
|
|
135
|
+
themes/ghostty/Battle Arena tema de Ghostty (solo con `install --with theme`)
|
|
117
136
|
```
|
|
118
137
|
|
|
119
138
|
### Plan de batalla (skill `/battlearena:conquer` + `plan.mjs`, ADR-0042)
|
|
@@ -274,9 +293,9 @@ celda de una mono típica es 0.6 em), centrados en vertical en y = 340. 31 viene
|
|
|
274
293
|
`LICENSE-lucide.txt`) y 5 son propios. `install` la copia a `~/Library/Fonts` (macOS) o a
|
|
275
294
|
`~/.local/share/fonts` (Linux, con `fc-cache -f` si está) y deja `iconFont: true` en
|
|
276
295
|
`~/.claude/battle-arena/config.json`: un mod no puede saber qué fuentes tiene la terminal, así que el
|
|
277
|
-
Scorecard sólo dibuja glifos con esa bandera. Si Ghostty ya tiene config (`~/.config/ghostty
|
|
278
|
-
o
|
|
279
|
-
`font-codepoint-map = U+FBA00-U+
|
|
296
|
+
Scorecard sólo dibuja glifos con esa bandera. Si Ghostty ya tiene config (`config.ghostty` o `config`, en `~/.config/ghostty/`
|
|
297
|
+
o en `~/Library/Application Support/com.mitchellh.ghostty/`), le agrega
|
|
298
|
+
`font-codepoint-map = U+FBA00-U+FBAFF=Battle Arena Icons` (el bloque entero de la fuente); si no, imprime la línea para que la
|
|
280
299
|
agregues tú (nunca crea ni reescribe tu config). `uninstall` quita la fuente, esa línea y apaga
|
|
281
300
|
`iconFont`. Para regenerarla tras cambiar un SVG: `python3 -m venv /tmp/ba-icons &&
|
|
282
301
|
/tmp/ba-icons/bin/pip install -r fonts/battle-arena-icons/requirements.txt &&
|
|
@@ -334,9 +353,16 @@ ejemplo, el de agents-studio-be (su batería de campañas, que además abre la v
|
|
|
334
353
|
- `color` (opcional): uno de la paleta (`slate`, `blue`, `teal`, `amber`, `purple`, `orange`,
|
|
335
354
|
`green`, `red`, `pink`); sin él, verde. Va en el borde de la ficha; el ícono de un monitor se
|
|
336
355
|
dibuja en gris neutro (sólo los actores del ring tienen PNG en su color).
|
|
337
|
-
- `match.command` (opcional): regex sobre el comando de Bash
|
|
338
|
-
|
|
339
|
-
|
|
356
|
+
- `match.command` (opcional): regex sobre lo que el comando de Bash **ejecuta**. Antes de probarla
|
|
357
|
+
se quitan los cuerpos de heredoc (`<<'EOF' … EOF`, `<<EOF … EOF`) y los textos entre comillas con
|
|
358
|
+
espacios (una comilla con una sola palabra, como una ruta, se queda sin las comillas), y se prueba
|
|
359
|
+
tramo por tramo (`;`, `&&`, `||`, `|`): escribir un script que menciona `scripts/run.mjs` no activa
|
|
360
|
+
la batería, correrlo sí. Mientras corre uno que la cumple, el monitor está activo (`PreToolUse` →
|
|
361
|
+
`PostToolUse`/`PostToolUseFailure`), con la descripción del Bash como etiqueta o, sin ella, el
|
|
362
|
+
programa que corrió (`node run.mjs`): **nunca el comando ni una ruta entera** (toda ruta absoluta se
|
|
363
|
+
corta a su último tramo). Ese evento lleva `source: "hook"` y su id, y sólo cierra lo suyo: nunca
|
|
364
|
+
termina una corrida que un script abrió con `emit`. Un comando en segundo plano no cuenta, para eso
|
|
365
|
+
está `emit`. `one-at-a-time` también lo marca mientras tiene el candado,
|
|
340
366
|
pero sólo fuera de Claude Code (dentro, ya lo hace el hook de Bash).
|
|
341
367
|
- `open` (opcional): `{ "command": "<comando sin />" }` pone un botón «abrir ↗» en el detalle del
|
|
342
368
|
chip que corre ese comando (por ejemplo el de otro mod que abre su propio panel); si el comando no
|
|
@@ -349,8 +375,31 @@ ejemplo, el de agents-studio-be (su batería de campañas, que además abre la v
|
|
|
349
375
|
(`{"at":"<ISO>","monitor":"bateria","state":"active","label":"probando","progress":{"done":1,"total":6}}`)
|
|
350
376
|
sin depender de `ring`. Esquema: `actor` (uno del ring) o `monitor` (declarado), `state`
|
|
351
377
|
(`active`, `waiting`, `done`, `failed`), `label` (≤3 palabras) y, opcionales, `note`, `detail`,
|
|
352
|
-
`progress`, `id` (para cerrar justo ese trabajo), `count`, `severity`, `pr`, `url
|
|
353
|
-
declarado se rechaza (`emit` sale con 1) y el
|
|
378
|
+
`progress`, `id` (para cerrar justo ese trabajo), `count`, `severity`, `pr`, `url`, `fields`,
|
|
379
|
+
`health`, `reason` y `source`. Un monitor no declarado se rechaza (`emit` sale con 1) y el
|
|
380
|
+
Scorecard lo ignora. En la ficha, un valor de `fields` que es una ruta se ve como link a su último
|
|
381
|
+
tramo (`file://`; en Terminal.app, un botón que lo abre), nunca la ruta entera, y un valor largo se
|
|
382
|
+
recorta a un renglón con «…».
|
|
383
|
+
- **Salud** (cualquier monitor o actor, cualquier repo): cada evento puede decir cómo fue ese paso
|
|
384
|
+
con `health` (`ok`, `warn` o `fail`) y por qué con `reason` (corto, ≤80). Desde un script:
|
|
385
|
+
`emit … --health warn --reason "t1 sin medir"`; `--failed` es siempre `fail` y `--done` es `ok`
|
|
386
|
+
salvo que `--health` diga otra cosa. La salud de una ficha es **la peor de su corrida en curso**
|
|
387
|
+
(desde el evento que sigue al último `done`/`failed` de un script; ese cierre cuenta en ella):
|
|
388
|
+
`fail` gana a `warn` y `warn` a `ok`, así que un paso que falló o no se midió sigue avisando
|
|
389
|
+
mientras corren los siguientes, y la corrida nueva empieza limpia. Se ve en la barrita de la ficha
|
|
390
|
+
(verde, ámbar o rojo, con ✓ ⚠ ✗), en una línea bajo el verbo del detalle («⚠ va con avisos: t1 sin
|
|
391
|
+
medir», «✓ va bien», «✗ falla: t3 dobles 2»), en cada renglón de ÚLTIMOS, y —sólo `warn` y
|
|
392
|
+
`fail`— junto al tiempo del punto y en la banda «Revisión #N». Sin `health` en ningún paso, nada
|
|
393
|
+
cambia. Una batería de pruebas, por ejemplo:
|
|
394
|
+
|
|
395
|
+
```sh
|
|
396
|
+
emit() { node "$RING/scripts/live.mjs" emit --monitor bateria "$@" || true; }
|
|
397
|
+
emit --state preparando
|
|
398
|
+
emit --state probando --label "t1 de 6" --progress 1/6 --health warn --reason "t1 sin medir"
|
|
399
|
+
emit --state probando --label "t2 de 6" --progress 2/6 --health ok
|
|
400
|
+
emit --state probando --label "t3 de 6" --progress 3/6 --health fail --reason "t3 dobles 2"
|
|
401
|
+
emit --state terminó --done # la corrida queda en fail (la peor); la siguiente empieza limpia
|
|
402
|
+
```
|
|
354
403
|
|
|
355
404
|
**`mask-guard`** (hook `PreToolUse` sobre Bash) bloquea **siempre** `git add -A/./--all`,
|
|
356
405
|
`git stash pop`, `git reset --hard` con el árbol sucio y, si `forbidAiTrailers` está activo, los
|
|
@@ -423,11 +472,11 @@ Requiere Claude Code CLI (`claude` en el PATH) y node ≥ 18. El instalador:
|
|
|
423
472
|
(`claude plugin marketplace add` + `claude plugin install --scope user`). Se lee directo de esa
|
|
424
473
|
carpeta: para actualizar basta volver a correr el instalador y `/reload-plugins`.
|
|
425
474
|
|
|
426
|
-
5. Con `--with radio` (o si ya
|
|
427
|
-
(Arena FM) en el Scorecard»). Correr `install` sin `--url`/`--api-key` reusa los de config.json.
|
|
475
|
+
5. Con `--with radio` y/o `--with theme` (o si ya los habías pedido), instala además la radio del
|
|
476
|
+
Scorecard y el tema de Ghostty (ver «La radio (Arena FM) en el Scorecard» y «El tema de Ghostty»). Correr `install` sin `--url`/`--api-key` reusa los de config.json.
|
|
428
477
|
|
|
429
478
|
Desde el clone (contribuidores): `HOOK_STREAM_URL=… HOOK_STREAM_API_KEY=… bash apps/claude-hooks/install.sh`
|
|
430
|
-
(acepta `--with radio` al final).
|
|
479
|
+
(acepta `--with radio` o `--with theme` al final).
|
|
431
480
|
Para probar el plugin sin instalarlo: `npm run bundle:skill` y `claude --plugin-dir apps/claude-hooks/plugin`.
|
|
432
481
|
|
|
433
482
|
## Configuración
|
package/cli.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// npx @thebattlearena/battle-arena-hooks install \
|
|
7
7
|
// --url https://api.battlearena.dev --api-key sk_xxx
|
|
8
8
|
// npx @thebattlearena/battle-arena-hooks install --with radio (agrega la radio; reusa url y llave)
|
|
9
|
+
// npx @thebattlearena/battle-arena-hooks install --with theme (el tema Battle Arena de Ghostty)
|
|
9
10
|
// npx @thebattlearena/battle-arena-hooks uninstall
|
|
10
11
|
//
|
|
11
12
|
// (también lee HOOK_STREAM_URL / HOOK_STREAM_API_KEY del entorno)
|
|
@@ -37,6 +38,12 @@ import {
|
|
|
37
38
|
installIconFont,
|
|
38
39
|
uninstallIconFont,
|
|
39
40
|
} from './lib/icon-font.mjs';
|
|
41
|
+
import {
|
|
42
|
+
installTheme,
|
|
43
|
+
LOOK_HINT,
|
|
44
|
+
THEME_NAME,
|
|
45
|
+
uninstallTheme,
|
|
46
|
+
} from './lib/ghostty-theme.mjs';
|
|
40
47
|
import {
|
|
41
48
|
installRadio,
|
|
42
49
|
mergeConfig,
|
|
@@ -128,6 +135,38 @@ function reportFont({ font, ghostty, hint, error }) {
|
|
|
128
135
|
);
|
|
129
136
|
}
|
|
130
137
|
|
|
138
|
+
/** El tema de Ghostty: lo copia y lo elige en la config que ya exista. Si falla, lo demás sigue. */
|
|
139
|
+
function addTheme() {
|
|
140
|
+
try {
|
|
141
|
+
const { theme, file, ghostty, hint } = installTheme({
|
|
142
|
+
pkgDir: PKG_DIR,
|
|
143
|
+
home: HOME,
|
|
144
|
+
});
|
|
145
|
+
console.log(
|
|
146
|
+
file === 'copied'
|
|
147
|
+
? `✅ tema ${THEME_NAME} de Ghostty en ${theme}`
|
|
148
|
+
: ` Ghostty: ya tenías un tema «${THEME_NAME}» propio en ${theme}; no lo toqué`,
|
|
149
|
+
);
|
|
150
|
+
for (const { path, status } of ghostty)
|
|
151
|
+
console.log(
|
|
152
|
+
status === 'set'
|
|
153
|
+
? `✅ Ghostty: elegí el tema en ${path} (el anterior quedó anotado)`
|
|
154
|
+
: ` Ghostty: ${path} ya usaba el tema`,
|
|
155
|
+
);
|
|
156
|
+
if (hint)
|
|
157
|
+
console.log(
|
|
158
|
+
` Si usas Ghostty, agrega a su config (y recárgala):\n ${hint}`,
|
|
159
|
+
);
|
|
160
|
+
console.log(
|
|
161
|
+
` Para el look completo, agrega si quieres:\n ${LOOK_HINT.join('\n ')}`,
|
|
162
|
+
);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error(
|
|
165
|
+
`⚠️ No pude instalar el tema (lo demás quedó bien): ${error.message}`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
131
170
|
/** La config que ya había (url, llave y extras pedidos), o null en una instalación nueva. */
|
|
132
171
|
function previousConfig() {
|
|
133
172
|
try {
|
|
@@ -229,8 +268,10 @@ function install() {
|
|
|
229
268
|
console.log(` colector: ${url}${key ? '' : ' (sin api-key)'}`);
|
|
230
269
|
reportFont(font);
|
|
231
270
|
|
|
232
|
-
// 7) Lo opcional que se pidió (ahora o antes): la radio baja su propia dependencia
|
|
271
|
+
// 7) Lo opcional que se pidió (ahora o antes): la radio baja su propia dependencia; el tema elige
|
|
272
|
+
// los colores de Ghostty.
|
|
233
273
|
if (config.with?.includes('radio')) addRadio();
|
|
274
|
+
if (config.with?.includes('theme')) addTheme();
|
|
234
275
|
console.log(
|
|
235
276
|
'\nListo. Abre Claude Code: /battlearena:conquer arma tu plan y /scorecard abre tu día.' +
|
|
236
277
|
'\nSi ya tenías una sesión abierta, corre /reload-plugins.',
|
|
@@ -254,6 +295,11 @@ function uninstall() {
|
|
|
254
295
|
console.log(`✅ fuente ${FONT_FAMILY} quitada de ${font.font}`);
|
|
255
296
|
for (const path of font.ghostty)
|
|
256
297
|
console.log(`✅ Ghostty: quité el mapa de íconos de ${path}`);
|
|
298
|
+
const theme = uninstallTheme({ home: HOME });
|
|
299
|
+
if (theme.theme)
|
|
300
|
+
console.log(`✅ tema ${THEME_NAME} quitado de ${theme.theme}`);
|
|
301
|
+
for (const path of theme.ghostty)
|
|
302
|
+
console.log(`✅ Ghostty: regresé el tema anterior en ${path}`);
|
|
257
303
|
console.log(
|
|
258
304
|
result.plugin
|
|
259
305
|
? `✅ plugin ${PLUGIN_ID} desinstalado`
|
|
@@ -274,7 +320,7 @@ const command = process.argv[2];
|
|
|
274
320
|
const run = COMMANDS[command];
|
|
275
321
|
if (!run) {
|
|
276
322
|
console.log(
|
|
277
|
-
'Uso: npx @thebattlearena/battle-arena-hooks install [--url <colector>] [--api-key <key>] [--with radio]\n' +
|
|
323
|
+
'Uso: npx @thebattlearena/battle-arena-hooks install [--url <colector>] [--api-key <key>] [--with radio,theme]\n' +
|
|
278
324
|
' npx @thebattlearena/battle-arena-hooks uninstall',
|
|
279
325
|
);
|
|
280
326
|
process.exit(command ? 1 : 0);
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// El tema «Battle Arena» de Ghostty (themes/ghostty/Battle Arena): navy, coral y azul del logo.
|
|
2
|
+
// `install --with theme` lo copia a la carpeta de temas del usuario y lo elige en la config de Ghostty
|
|
3
|
+
// que ya exista, guardando en un comentario el tema que había para que `uninstall` lo regrese. Nunca
|
|
4
|
+
// crea la config ni pisa un tema «Battle Arena» que no sea el nuestro. Zero-dependency.
|
|
5
|
+
import {
|
|
6
|
+
copyFileSync,
|
|
7
|
+
existsSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
rmSync,
|
|
11
|
+
writeFileSync,
|
|
12
|
+
} from 'node:fs';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
|
|
15
|
+
import { ghosttyConfigs } from './icon-font.mjs';
|
|
16
|
+
|
|
17
|
+
export const THEME_NAME = 'Battle Arena';
|
|
18
|
+
export const THEME_LINE = `theme = ${THEME_NAME}`;
|
|
19
|
+
/** La primera línea del archivo del tema: dice que es el nuestro y que se puede reemplazar o quitar. */
|
|
20
|
+
export const THEME_HEADER = '# battle-arena-hooks: tema Battle Arena';
|
|
21
|
+
const MARKER =
|
|
22
|
+
'# Battle Arena: tema de battle-arena-hooks install --with theme';
|
|
23
|
+
const BEFORE = '; antes: ';
|
|
24
|
+
/** Cualquier línea `theme = …` (Ghostty usa la última). */
|
|
25
|
+
const THEME_PATTERN = /^\s*theme\s*=.*$/;
|
|
26
|
+
const isOurs = (line) => /^\s*theme\s*=\s*Battle Arena\s*$/.test(line);
|
|
27
|
+
const hasTheme = (text) =>
|
|
28
|
+
text.split('\n').some((line) => THEME_PATTERN.test(line));
|
|
29
|
+
/** El tema que vale en una config: su último `theme =`, o `null`. */
|
|
30
|
+
const lastTheme = (text) =>
|
|
31
|
+
text.split('\n').findLast((line) => THEME_PATTERN.test(line)) ?? null;
|
|
32
|
+
|
|
33
|
+
/** Lo de la ventana que completa el look; se sugiere, no se escribe. */
|
|
34
|
+
export const LOOK_HINT = [
|
|
35
|
+
'font-family = JetBrains Mono',
|
|
36
|
+
'window-padding-x = 10',
|
|
37
|
+
'window-padding-y = 8',
|
|
38
|
+
'window-padding-color = extend',
|
|
39
|
+
'macos-icon = custom-style',
|
|
40
|
+
'macos-icon-frame = chrome',
|
|
41
|
+
'macos-icon-ghost-color = #F26464',
|
|
42
|
+
'macos-icon-screen-color = #061224,#0B1B33',
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/** La carpeta de temas del usuario (Ghostty la lee en macOS y Linux). PURA. */
|
|
46
|
+
export function themesDir(home, env = {}) {
|
|
47
|
+
return join(
|
|
48
|
+
env.XDG_CONFIG_HOME || join(home, '.config'),
|
|
49
|
+
'ghostty',
|
|
50
|
+
'themes',
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* La config con nuestro tema: igual si ya es el que vale (el último `theme =`); si hay otro, el
|
|
56
|
+
* último se cambia por el nuestro y se anota tal cual en el comentario; si no hay ninguno, se agrega
|
|
57
|
+
* al final sólo con `append`. PURA.
|
|
58
|
+
*/
|
|
59
|
+
export function withTheme(text, append = false) {
|
|
60
|
+
const lines = text.split('\n');
|
|
61
|
+
const last = lines.findLastIndex((line) => THEME_PATTERN.test(line));
|
|
62
|
+
if (last !== -1 && isOurs(lines[last])) return text;
|
|
63
|
+
if (last !== -1) {
|
|
64
|
+
lines.splice(last, 1, `${MARKER}${BEFORE}${lines[last]}`, THEME_LINE);
|
|
65
|
+
return lines.join('\n');
|
|
66
|
+
}
|
|
67
|
+
if (!append) return text;
|
|
68
|
+
const base = text === '' || text.endsWith('\n') ? text : `${text}\n`;
|
|
69
|
+
return `${base}\n${MARKER}\n${THEME_LINE}\n`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** La config sin nuestro tema, con el que había antes de vuelta: deshace `withTheme`. PURA. */
|
|
73
|
+
export function withoutTheme(text) {
|
|
74
|
+
const lines = text.split('\n');
|
|
75
|
+
const at = lines.findIndex((line) => line.startsWith(MARKER));
|
|
76
|
+
if (at === -1 || !isOurs(lines[at + 1] ?? '')) return text;
|
|
77
|
+
const note = lines[at];
|
|
78
|
+
const before = note.indexOf(BEFORE);
|
|
79
|
+
if (before !== -1) {
|
|
80
|
+
lines.splice(at, 2, note.slice(before + BEFORE.length));
|
|
81
|
+
return lines.join('\n');
|
|
82
|
+
}
|
|
83
|
+
const blank = at > 0 && lines[at - 1] === '' ? 1 : 0;
|
|
84
|
+
lines.splice(at - blank, 2 + blank);
|
|
85
|
+
return lines.join('\n');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* La config que decide el tema: Ghostty las carga todas en orden y gana el último `theme =`, así que
|
|
90
|
+
* es la última que lo tiene; si ninguna lo tiene, la última que existe. PURA.
|
|
91
|
+
*/
|
|
92
|
+
export function effectiveConfig(configs) {
|
|
93
|
+
return (
|
|
94
|
+
configs.findLast(({ text }) => hasTheme(text)) ?? configs.at(-1) ?? null
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const isOurFile = (path) =>
|
|
99
|
+
readFileSync(path, 'utf8').startsWith(`${THEME_HEADER}\n`);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Copia el tema (salvo que ya haya otro «Battle Arena» que no es el nuestro) y lo elige sólo en la
|
|
103
|
+
* config que decide. Devuelve { theme: ruta, file: 'copied' | 'foreign', ghostty: [{ path, status:
|
|
104
|
+
* 'set' | 'present' }], hint: línea | null } (`hint` cuando no hay config de Ghostty).
|
|
105
|
+
*/
|
|
106
|
+
export function installTheme({
|
|
107
|
+
pkgDir,
|
|
108
|
+
platform = process.platform,
|
|
109
|
+
home,
|
|
110
|
+
env = process.env,
|
|
111
|
+
}) {
|
|
112
|
+
const dir = themesDir(home, env);
|
|
113
|
+
mkdirSync(dir, { recursive: true });
|
|
114
|
+
const theme = join(dir, THEME_NAME);
|
|
115
|
+
const foreign = existsSync(theme) && !isOurFile(theme);
|
|
116
|
+
if (!foreign)
|
|
117
|
+
copyFileSync(join(pkgDir, 'themes', 'ghostty', THEME_NAME), theme);
|
|
118
|
+
const configs = ghosttyConfigs(platform, home, env)
|
|
119
|
+
.filter((path) => existsSync(path))
|
|
120
|
+
.map((path) => ({ path, text: readFileSync(path, 'utf8') }));
|
|
121
|
+
const target = effectiveConfig(configs);
|
|
122
|
+
const ghostty = [target].filter(Boolean).map(({ path, text }) => {
|
|
123
|
+
const next = withTheme(text, true);
|
|
124
|
+
if (next === text) return { path, status: 'present' };
|
|
125
|
+
writeFileSync(path, next);
|
|
126
|
+
return { path, status: 'set' };
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
theme,
|
|
130
|
+
file: foreign ? 'foreign' : 'copied',
|
|
131
|
+
ghostty,
|
|
132
|
+
hint: configs.length ? null : THEME_LINE,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Regresa el tema que había en cada config y quita el archivo sólo si es el nuestro y ninguna config
|
|
138
|
+
* lo sigue eligiendo (p. ej. un `theme = Battle Arena` escrito a mano). Devuelve lo que tocó.
|
|
139
|
+
*/
|
|
140
|
+
export function uninstallTheme({
|
|
141
|
+
platform = process.platform,
|
|
142
|
+
home,
|
|
143
|
+
env = process.env,
|
|
144
|
+
}) {
|
|
145
|
+
const configs = ghosttyConfigs(platform, home, env).filter((path) =>
|
|
146
|
+
existsSync(path),
|
|
147
|
+
);
|
|
148
|
+
const ghostty = configs.filter((path) => {
|
|
149
|
+
const text = readFileSync(path, 'utf8');
|
|
150
|
+
const next = withoutTheme(text);
|
|
151
|
+
if (next === text) return false;
|
|
152
|
+
writeFileSync(path, next);
|
|
153
|
+
return true;
|
|
154
|
+
});
|
|
155
|
+
const theme = join(themesDir(home, env), THEME_NAME);
|
|
156
|
+
const stillUsed = configs.some((path) =>
|
|
157
|
+
isOurs(lastTheme(readFileSync(path, 'utf8')) ?? ''),
|
|
158
|
+
);
|
|
159
|
+
const removed = existsSync(theme) && isOurFile(theme) && !stillUsed;
|
|
160
|
+
if (removed) rmSync(theme);
|
|
161
|
+
return { theme: removed ? theme : null, ghostty };
|
|
162
|
+
}
|
package/lib/icon-font.mjs
CHANGED
|
@@ -15,11 +15,19 @@ import { join } from 'node:path';
|
|
|
15
15
|
|
|
16
16
|
export const FONT_FILE = 'BattleArenaIcons.ttf';
|
|
17
17
|
export const FONT_FAMILY = 'Battle Arena Icons';
|
|
18
|
-
|
|
18
|
+
// El bloque entero U+FBA00–U+FBAFF es de la fuente: crece por grupos de 0x10 dentro de él, así que
|
|
19
|
+
// el mapa de Ghostty cubre el bloque y no el último codepoint de hoy (el viejo U+FBA5F dejó fuera
|
|
20
|
+
// los íconos del Scorecard en cuanto la fuente pasó de U+FBA5F).
|
|
21
|
+
export const ICON_RANGE = 'U+FBA00-U+FBAFF';
|
|
22
|
+
export const GHOSTTY_LINE = `font-codepoint-map = ${ICON_RANGE}=${FONT_FAMILY}`;
|
|
19
23
|
const GHOSTTY_COMMENT =
|
|
20
24
|
'# Battle Arena: íconos del Scorecard (battle-arena-hooks install)';
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
/** Una línea nuestra, con el rango de hoy o con uno viejo más corto que hay que ampliar. */
|
|
26
|
+
const OWN_LINE_PATTERN =
|
|
27
|
+
/^\s*font-codepoint-map\s*=\s*U\+FBA00-U\+FBA[0-9A-F]{2}\s*=\s*Battle Arena Icons\s*$/im;
|
|
28
|
+
/** Una línea que la persona escribió para el mismo bloque con otra fuente: se respeta. */
|
|
29
|
+
const FOREIGN_LINE_PATTERN =
|
|
30
|
+
/^\s*font-codepoint-map\s*=\s*U\+FBA00-U\+FBA[0-9A-F]{2}\s*=.*$/im;
|
|
23
31
|
|
|
24
32
|
/** Dónde van las fuentes del usuario; `null` donde el instalador no sabe instalarlas. PURA. */
|
|
25
33
|
export function fontDir(platform, home) {
|
|
@@ -28,37 +36,47 @@ export function fontDir(platform, home) {
|
|
|
28
36
|
return null;
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Los archivos de config de Ghostty posibles, en el orden en que Ghostty los carga: en cada carpeta,
|
|
41
|
+
* `config.ghostty` (el nombre desde Ghostty 1.2) y luego `config`. PURA.
|
|
42
|
+
*/
|
|
32
43
|
export function ghosttyConfigs(platform, home, env = {}) {
|
|
33
44
|
const xdg = env.XDG_CONFIG_HOME || join(home, '.config');
|
|
34
|
-
const
|
|
45
|
+
const dirs = [join(xdg, 'ghostty')];
|
|
35
46
|
if (platform === 'darwin')
|
|
36
|
-
|
|
37
|
-
join(
|
|
38
|
-
home,
|
|
39
|
-
'Library',
|
|
40
|
-
'Application Support',
|
|
41
|
-
'com.mitchellh.ghostty',
|
|
42
|
-
'config',
|
|
43
|
-
),
|
|
47
|
+
dirs.push(
|
|
48
|
+
join(home, 'Library', 'Application Support', 'com.mitchellh.ghostty'),
|
|
44
49
|
);
|
|
45
|
-
return
|
|
50
|
+
return dirs.flatMap((dir) => [
|
|
51
|
+
join(dir, 'config.ghostty'),
|
|
52
|
+
join(dir, 'config'),
|
|
53
|
+
]);
|
|
46
54
|
}
|
|
47
55
|
|
|
48
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* La config con la línea de los íconos: igual si ya la tiene; con el rango ampliado si tiene la
|
|
58
|
+
* nuestra con un rango viejo; igual si la persona mapeó ese bloque a otra fuente; al final si no.
|
|
59
|
+
* PURA.
|
|
60
|
+
*/
|
|
49
61
|
export function withGhosttyLine(text) {
|
|
50
|
-
if (
|
|
62
|
+
if (text.split('\n').some((line) => line.trim() === GHOSTTY_LINE))
|
|
63
|
+
return text;
|
|
64
|
+
if (OWN_LINE_PATTERN.test(text))
|
|
65
|
+
return text.replace(OWN_LINE_PATTERN, GHOSTTY_LINE);
|
|
66
|
+
if (FOREIGN_LINE_PATTERN.test(text)) return text;
|
|
51
67
|
const base = text === '' || text.endsWith('\n') ? text : `${text}\n`;
|
|
52
68
|
return `${base}\n${GHOSTTY_COMMENT}\n${GHOSTTY_LINE}\n`;
|
|
53
69
|
}
|
|
54
70
|
|
|
55
|
-
/** La config sin
|
|
71
|
+
/** La config sin nuestra línea (de cualquier rango) ni su comentario: deshace `withGhosttyLine`. PURA. */
|
|
56
72
|
export function withoutGhosttyLine(text) {
|
|
57
73
|
const block = `\n${GHOSTTY_COMMENT}\n${GHOSTTY_LINE}\n`;
|
|
74
|
+
const ownLine = new RegExp(OWN_LINE_PATTERN.source, 'i');
|
|
58
75
|
return text
|
|
76
|
+
.replace(OWN_LINE_PATTERN, GHOSTTY_LINE)
|
|
59
77
|
.replace(block, '')
|
|
60
78
|
.split('\n')
|
|
61
|
-
.filter((line) => line !== GHOSTTY_COMMENT && !
|
|
79
|
+
.filter((line) => line !== GHOSTTY_COMMENT && !ownLine.test(line))
|
|
62
80
|
.join('\n');
|
|
63
81
|
}
|
|
64
82
|
|
package/lib/radio-install.mjs
CHANGED
|
@@ -7,8 +7,8 @@ import { join } from 'node:path';
|
|
|
7
7
|
|
|
8
8
|
export const DEFAULT_URL = 'https://api.battlearena.dev';
|
|
9
9
|
|
|
10
|
-
/** Lo que se puede agregar con `--with
|
|
11
|
-
export const EXTRAS = ['radio'];
|
|
10
|
+
/** Lo que se puede agregar con `--with`: la radio y el tema de Ghostty (lib/ghostty-theme.mjs). */
|
|
11
|
+
export const EXTRAS = ['radio', 'theme'];
|
|
12
12
|
|
|
13
13
|
/** Los archivos del reproductor (sin node_modules: esa la baja npm en la máquina de cada quien). */
|
|
14
14
|
const RADIO_FILES = ['player.mjs', 'package.json'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thebattlearena/battle-arena-hooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Battle Arena en Claude Code como el plugin `battlearena`: hooks de tracking, objetivo del turno, plan de batalla /battlearena:conquer y el Scorecard de tu día (zero-dependency).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"fonts/battle-arena-icons/LICENSE-lucide.txt",
|
|
25
25
|
"radio/player.mjs",
|
|
26
26
|
"radio/package.json",
|
|
27
|
+
"themes/ghostty/Battle Arena",
|
|
27
28
|
"README.md"
|
|
28
29
|
],
|
|
29
30
|
"publishConfig": {
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
"name": "battlearena",
|
|
3
3
|
"version": "0.7.0",
|
|
4
4
|
"description": "Battle Arena en Claude Code: tus sesiones al colector, el objetivo del turno, el plan de batalla /battlearena:conquer y el Scorecard de tu día junto al chat.",
|
|
5
|
-
"author": {
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Battle Arena"
|
|
7
|
+
},
|
|
6
8
|
"types": "./types/index.d.ts"
|
|
7
9
|
}
|
package/plugin/hooks/pane.tsx
CHANGED
|
@@ -592,7 +592,9 @@ const Point = (
|
|
|
592
592
|
const isOpen = m.focused === key || m.opened.includes(key);
|
|
593
593
|
// El punto que aloja el ring dice si ahí se está trabajando; la fila del ring sale al abrirlo.
|
|
594
594
|
const badge =
|
|
595
|
-
hostsRing && m.ring
|
|
595
|
+
hostsRing && m.ring
|
|
596
|
+
? pointBadge(m.ring.view, m.ring.tick, m.ring.iconFont)
|
|
597
|
+
: null;
|
|
596
598
|
return (
|
|
597
599
|
<Box key={`row-${key}`} flexDirection="column">
|
|
598
600
|
<Box width={width}>
|