hopdeck 1.4.0 → 1.4.2
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/CHANGELOG.md +16 -0
- package/README.en.md +7 -1
- package/README.md +8 -1
- package/bin/hopdeck.js +190 -38
- package/lib/i18n.js +8 -2
- package/lib/mascot.js +149 -0
- package/lib/stats.js +79 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Cambios
|
|
2
2
|
|
|
3
|
+
## 1.4.2
|
|
4
|
+
|
|
5
|
+
### Nuevo
|
|
6
|
+
- **Estadísticas de cada conversación en la fila del título**, a la derecha: `MSGS 2324 │ TOK 206.9M │ TOOLS 1249 │ opus`. Mensajes, tokens (entrada, salida y caché de cada mensaje de Claude), herramientas usadas y modelo; la rama de git sigue a la izquierda, junto al título. Salen en la vista previa al pasar el cursor y con el chat abierto. Si el panel es estrecho se quitan primero los campos menos importantes (TOOLS, luego el modelo). Se calculan en segundo plano (una conversación de 79 MB tarda unos 250 ms) y después solo se lee lo que Claude añade, como mucho cada 3 s.
|
|
7
|
+
- **Barra inferior con las teclas entre corchetes**, como `[/] buscar [n] nueva [Ctrl+P] saltar`. Cambia con el foco: con la lista activa muestra las teclas de letra, y con un chat abierto solo las F (`[F1] lista [F3] copiar texto [F4] ocultar lista [F5] saltar [F8] git [F9] tema`), porque las letras son de Claude. A la derecha, los chats abiertos y cuántos proyectos y chats hay; ese resumen se omite si no caben las teclas enteras.
|
|
8
|
+
- **La mascota de Hopdeck, un sapo naranja con auriculares.** Sale en la pantalla de inicio (el panel derecho cuando no hay ningún chat abierto), encima del texto y del mayor tamaño que quepa; si el terminal es pequeño o usas `NO_COLOR`, se queda el texto de siempre. También en la pantalla de carga y en el panel de tmux. Y con el comando `hopdeck mascot` (`--size small|normal|large`, `--plain` para dibujarla sin colores). Va dentro del programa, sin archivos de imagen ni Python; en el README hay una imagen (`docs/mascot.png`).
|
|
9
|
+
|
|
10
|
+
## 1.4.1
|
|
11
|
+
|
|
12
|
+
### Cambiado
|
|
13
|
+
- **Seleccionar texto del chat ya no lo copia solo.** Al soltar, la selección se queda marcada y se copia con `Ctrl+C` o con el clic derecho; `Esc` o un clic en otro sitio la quitan (`Esc` no llega a Claude mientras hay algo seleccionado, porque lo interrumpiría). Quien prefiera el comportamiento anterior puede poner `"copyOnSelect": true` en `~/.hopdeck.json`.
|
|
14
|
+
|
|
15
|
+
### Arreglado
|
|
16
|
+
- **No se podía seleccionar más de lo que cabía en pantalla.** Al arrastrar contra el borde de arriba o de abajo del chat, este se desplaza solo (aunque el ratón se quede quieto) y la selección sigue. La selección ahora se ancla a las líneas del historial, no a las filas de la pantalla, así que también sigue en su sitio si usas la rueda mientras seleccionas.
|
|
17
|
+
- **El spinner de «trabajando» salía sin que Claude estuviera haciendo nada**, a veces en chats donde ni estabas. Hopdeck marcaba un chat como trabajando si escribía cualquier cosa en el último segundo, y eso también ocurre al mover o redimensionar los paneles (todos los chats se repintan), al cambiar de ventana o al actualizarse la barra de estado. Ahora solo cuenta como trabajando cuando la pantalla de Claude muestra «esc to interrupt», y el repintado justo después de redimensionar se ignora. Si una versión de Claude cambiara ese texto, `HOPDECK_BUSY=output` devuelve el criterio anterior.
|
|
18
|
+
|
|
3
19
|
## 1.4.0
|
|
4
20
|
|
|
5
21
|
### Nuevo
|
package/README.en.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
</picture>
|
|
6
6
|
</p>
|
|
7
7
|
|
|
8
|
+
<p align="center"><img alt="The Hopdeck mascot: an orange toad with headphones" src="docs/mascot.png" width="130"></p>
|
|
9
|
+
|
|
8
10
|
<p align="center"><b>Hop between your Claude Code projects and conversations without leaving the terminal.</b></p>
|
|
9
11
|
|
|
10
12
|
[Español](README.md) · **English**
|
|
@@ -110,6 +112,8 @@ Every text box supports a cursor: `←` `→`, `Home`/`End`, `Delete`, and `Ctrl
|
|
|
110
112
|
|
|
111
113
|
With no chat open, the right pane shows the last messages of the selected conversation. With the mouse you only need to **hover** the list, no click needed.
|
|
112
114
|
|
|
115
|
+
On the title row, at the right, you get the conversation statistics: `MSGS` (messages), `TOK` (tokens: input, output and cache), `TOOLS` (tools used) and the model. They show in the preview and with the chat open, and on a narrow pane the least important ones are dropped first. They are computed in the background the first time, and afterwards only what Claude appends is read.
|
|
116
|
+
|
|
113
117
|
### Pick a folder
|
|
114
118
|
|
|
115
119
|
<picture>
|
|
@@ -178,7 +182,7 @@ It refreshes itself every few seconds and never modifies the repository. It need
|
|
|
178
182
|
### Scroll and copy
|
|
179
183
|
|
|
180
184
|
- **Scroll** the chat with the mouse wheel or `PgUp` / `PgDn`; `End` or typing returns you to the bottom.
|
|
181
|
-
- **
|
|
185
|
+
- **Select and copy:** drag with the mouse over the chat to mark text; it is not copied by itself. Copy it with `Ctrl+C` or right click, and clear the selection with `Esc` or by clicking elsewhere. If you drag to the top or bottom edge the chat scrolls on its own and the selection follows, so you can mark far more than fits on screen. For the old behaviour (copy on release) set `"copyOnSelect": true` in `~/.hopdeck.json`. `F3` turns the mouse off if you prefer terminal selection (or use `Shift`+drag).
|
|
182
186
|
|
|
183
187
|
### More
|
|
184
188
|
|
|
@@ -192,6 +196,7 @@ It refreshes itself every few seconds and never modifies the repository. It need
|
|
|
192
196
|
| `hopdeck` | Opens Hopdeck |
|
|
193
197
|
| `hopdeck shortcut on` / `hopdeck shortcut off` | Installs or removes the shortcut so that `claude` opens Hopdeck |
|
|
194
198
|
| `hopdeck theme light` / `dark` / `auto` | Changes the color theme and remembers it (`hopdeck theme` shows the current one) |
|
|
199
|
+
| `hopdeck mascot` | Draws the mascot in the terminal (`--size small\|normal\|large`; `--plain` draws it without colors). It also shows on Hopdeck's start screen |
|
|
195
200
|
| `hopdeck uninstall` | **Uninstalls Hopdeck completely**: the shortcut, your preferences and cache, and the program. Asks first (without a terminal, use `--yes`). Does not touch your Claude Code history |
|
|
196
201
|
| `hopdeck doctor` | Checks your setup and tells you how to fix whatever is missing |
|
|
197
202
|
| `hopdeck --list` | Lists the projects as plain text |
|
|
@@ -232,6 +237,7 @@ Keys in `~/.hopdeck.json` you can edit by hand:
|
|
|
232
237
|
|---|---|---|
|
|
233
238
|
| `notify` | Desktop notification when a chat finishes | `true` |
|
|
234
239
|
| `mouse` | Mouse enabled (`F3` toggles) | `true` |
|
|
240
|
+
| `copyOnSelect` | Copy to the clipboard as soon as you release a chat selection | `false` |
|
|
235
241
|
| `sidebar` | List width (`[` and `]` adjust it) | automatic |
|
|
236
242
|
| `maxImages` | Max images per conversation in the gallery | `200` |
|
|
237
243
|
| `previewMsgs` | Messages shown in the preview | `12` |
|
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
</picture>
|
|
6
6
|
</p>
|
|
7
7
|
|
|
8
|
+
<p align="center"><img alt="La mascota de Hopdeck: un sapo naranja con auriculares" src="docs/mascot.png" width="130"></p>
|
|
9
|
+
|
|
8
10
|
<p align="center"><b>Salta entre tus proyectos y conversaciones de Claude Code, sin salir de la terminal.</b></p>
|
|
9
11
|
|
|
10
12
|
**Español** · [English](README.en.md)
|
|
@@ -110,6 +112,8 @@ En todas las cajas de texto puedes mover el cursor con `←` `→`, ir al princi
|
|
|
110
112
|
|
|
111
113
|
Sin ningún chat abierto, el panel derecho muestra los últimos mensajes de la conversación seleccionada. Con el ratón basta **pasar el cursor** por la lista, sin hacer clic.
|
|
112
114
|
|
|
115
|
+
En la fila del título, a la derecha, salen las estadísticas de la conversación: `MSGS` (mensajes), `TOK` (tokens: entrada, salida y caché), `TOOLS` (herramientas usadas) y el modelo. Aparecen tanto en la vista previa como con el chat abierto, y si el panel es estrecho se quitan primero los menos importantes. Se calculan en segundo plano la primera vez, y después solo se lee lo que Claude va añadiendo.
|
|
116
|
+
|
|
113
117
|
### Elegir una carpeta
|
|
114
118
|
|
|
115
119
|
<picture>
|
|
@@ -178,7 +182,7 @@ Se refresca solo cada pocos segundos y no modifica nada en el repositorio. Neces
|
|
|
178
182
|
### Scroll y copiar
|
|
179
183
|
|
|
180
184
|
- **Scroll** en el chat: rueda del ratón o `PgUp` / `PgDn`; `End` o escribir algo te devuelve al final.
|
|
181
|
-
- **
|
|
185
|
+
- **Seleccionar y copiar:** arrastra con el ratón sobre el chat para marcar texto; no se copia solo. Cópialo con `Ctrl+C` o con el clic derecho, y quita la selección con `Esc` o haciendo clic en otro sitio. Si arrastras hasta el borde de arriba o de abajo, el chat se desplaza solo y la selección sigue, así que puedes marcar mucho más de lo que cabe en pantalla. Si prefieres el comportamiento anterior (copiar al soltar), pon `"copyOnSelect": true` en `~/.hopdeck.json`. `F3` apaga el ratón si prefieres seleccionar con el terminal (o usa `Shift`+arrastrar).
|
|
182
186
|
|
|
183
187
|
### Otros detalles
|
|
184
188
|
|
|
@@ -192,6 +196,7 @@ Se refresca solo cada pocos segundos y no modifica nada en el repositorio. Neces
|
|
|
192
196
|
| `hopdeck` | Abre Hopdeck |
|
|
193
197
|
| `hopdeck shortcut on` / `hopdeck shortcut off` | Instala o quita el atajo para que `claude` abra Hopdeck |
|
|
194
198
|
| `hopdeck theme light` / `dark` / `auto` | Cambia el tema de colores y lo guarda (`hopdeck theme` muestra el actual) |
|
|
199
|
+
| `hopdeck mascot` | Dibuja la mascota en el terminal (`--size small\|normal\|large`; `--plain` la dibuja sin colores). También sale en la pantalla de inicio de Hopdeck |
|
|
195
200
|
| `hopdeck uninstall` | **Desinstala Hopdeck por completo**: el atajo, tus preferencias y la caché, y el programa. Pregunta antes (sin terminal, usa `--yes`). No toca tu historial de Claude Code |
|
|
196
201
|
| `hopdeck doctor` | Revisa tu instalación y dice cómo arreglar lo que falte |
|
|
197
202
|
| `hopdeck --list` | Lista los proyectos en texto plano |
|
|
@@ -217,6 +222,7 @@ Casi nunca hace falta tocar nada. Lo más útil:
|
|
|
217
222
|
| `HOPDECK_LANG` | `es` o `en` (por defecto, el idioma del sistema) |
|
|
218
223
|
| `HOPDECK_THEME` | `light` o `dark`: manda sobre lo guardado con `hopdeck theme` |
|
|
219
224
|
| `HOPDECK_SIXEL` | `1` fuerza la imagen real al pasar el cursor por `[Image #N]`, `0` usa siempre bloques (por defecto se detecta) |
|
|
225
|
+
| `HOPDECK_BUSY` | `output` marca un chat como «trabajando» con cualquier salida reciente. Por defecto solo cuando Claude muestra «esc to interrupt» |
|
|
220
226
|
| `NO_COLOR` | Quita los colores |
|
|
221
227
|
| `CLAUDE_CONFIG_DIR` | Carpeta de Claude Code, si no es `~/.claude` |
|
|
222
228
|
| `HOPDECK_SKIP=1` | Salta Hopdeck una vez: `HOPDECK_SKIP=1 claude` |
|
|
@@ -232,6 +238,7 @@ Claves de `~/.hopdeck.json` que puedes editar a mano:
|
|
|
232
238
|
|---|---|---|
|
|
233
239
|
| `notify` | Aviso de escritorio al terminar un chat | `true` |
|
|
234
240
|
| `mouse` | Ratón activado (`F3` lo alterna) | `true` |
|
|
241
|
+
| `copyOnSelect` | Copiar al portapapeles en cuanto sueltas la selección del chat | `false` |
|
|
235
242
|
| `sidebar` | Ancho de la lista (`[` y `]` lo ajustan) | automático |
|
|
236
243
|
| `maxImages` | Imágenes máximas por conversación en la galería | `200` |
|
|
237
244
|
| `previewMsgs` | Mensajes mostrados en la vista previa | `12` |
|
package/bin/hopdeck.js
CHANGED
|
@@ -13,6 +13,8 @@ const readline = require('readline');
|
|
|
13
13
|
|
|
14
14
|
const { LANG, T } = require('../lib/i18n');
|
|
15
15
|
const { TRUE, NOCOL, LIGHT, setTheme, isLight, fg, bg, R, C, cw, strW, fit, clean } = require('../lib/style');
|
|
16
|
+
const mascot = require('../lib/mascot');
|
|
17
|
+
const stats = require('../lib/stats');
|
|
16
18
|
const { baseName, tidy, home, shortPath, fold, queryWords, matchWords, fuzzy, wrapText } = require('../lib/text');
|
|
17
19
|
const hist = require('../lib/history');
|
|
18
20
|
const { CONFIG_DIR, CACHE_FILE, textOf, isType, cacheLoad, cacheSave, readSession, decodeDir, projectDirs, buildProject, beginScan, endScan } = hist;
|
|
@@ -842,7 +844,10 @@ function idle() {
|
|
|
842
844
|
const c = process.stdout.columns || 80, r = process.stdout.rows || 24;
|
|
843
845
|
const rows = [[C.brand + C.bold, '» Hop\u0001deck'], [C.text, T.idle1], [C.dim, T.idle2], ['', ''], [C.dim, T.idle3]];
|
|
844
846
|
let out = '\x1b[2J\x1b[?25l';
|
|
845
|
-
|
|
847
|
+
const art = mascotArt(c, r - rows.length - 2), gap = art.length ? 1 : 0; // el panel de tmux también lleva la mascota, si cabe
|
|
848
|
+
const top = art.length ? Math.max(1, Math.floor((r - art.length - gap - rows.length) / 2) + 1) : Math.max(1, Math.floor(r / 2) - 2);
|
|
849
|
+
art.forEach((_, j) => { out += `\x1b[${top + j};1H${mascotRow(art, j, c)}`; });
|
|
850
|
+
rows.forEach(([st, t], i) => { out += `\x1b[${top + art.length + gap + i};${Math.max(1, Math.floor((c - strW(t.replace('\u0001', ''))) / 2) + 1)}H${st}${paintMark(t)}${R}`; });
|
|
846
851
|
process.stdout.write(out);
|
|
847
852
|
};
|
|
848
853
|
draw(); process.stdout.on('resize', draw);
|
|
@@ -1035,10 +1040,28 @@ function termRow(term, y, width, sel, from = 0) {
|
|
|
1035
1040
|
/** Texto con la marca en dos colores: \u0001 separa "Hop" (color de marca) de "deck" (color del texto). */
|
|
1036
1041
|
const paintMark = (t) => t.replace('\u0001', R + C.text + C.bold);
|
|
1037
1042
|
|
|
1043
|
+
/** La mascota, del mayor tamaño que quepa (en `width` columnas y `rows` filas); nada si no cabe ni la más pequeña o si no hay colores. */
|
|
1044
|
+
function mascotArt(width, rows) {
|
|
1045
|
+
if (NOCOL) return [];
|
|
1046
|
+
const n = mascot.sizeFor(width - 2, rows);
|
|
1047
|
+
return n ? mascot.render(n) : [];
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
/** Una fila de la mascota centrada en `width` columnas. */
|
|
1051
|
+
function mascotRow(art, j, width) {
|
|
1052
|
+
const n = art.length * 2, pad = Math.max(0, Math.floor((width - n) / 2));
|
|
1053
|
+
return ' '.repeat(pad) + art[j] + ' '.repeat(Math.max(0, width - pad - n));
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1038
1056
|
function idleRow(y, width, height) {
|
|
1039
1057
|
const k = T.k;
|
|
1040
1058
|
const rows = [[C.brand + C.bold, '» Hop\u0001deck'], [C.text, T.idle1], [C.dim, T.idle2], ['', ''], [C.accent, `⏎ ${k.resume} n ${k.neu} / ${k.find} ? ${T.kHelp}`], [C.dim, T.idle3]];
|
|
1041
|
-
const
|
|
1059
|
+
const art = mascotArt(width, height - rows.length - 2); // la mascota va encima del texto, si cabe
|
|
1060
|
+
const gap = art.length ? 1 : 0;
|
|
1061
|
+
const start = art.length ? Math.floor((height - art.length - gap - rows.length) / 2) : Math.floor(height / 2) - 2;
|
|
1062
|
+
const j = y - start;
|
|
1063
|
+
if (j >= 0 && j < art.length) return mascotRow(art, j, width);
|
|
1064
|
+
const i = j - art.length - gap;
|
|
1042
1065
|
if (i < 0 || i >= rows.length) return ' '.repeat(width);
|
|
1043
1066
|
const [st, t] = rows[i];
|
|
1044
1067
|
const vis = t.replace('\u0001', ''), pad = Math.max(0, Math.floor((width - strW(vis)) / 2));
|
|
@@ -1358,9 +1381,62 @@ function previewRows(msgs, width, height, info = '') {
|
|
|
1358
1381
|
}
|
|
1359
1382
|
|
|
1360
1383
|
/** Título del panel del chat: proyecto › conversación ⎇ rama */
|
|
1361
|
-
|
|
1384
|
+
// ── Estadísticas de la conversación (mensajes, tokens, herramientas, modelo), en la fila del título del chat ──
|
|
1385
|
+
const STATS = new Map(); // archivo → { st, sum, at, busy, m, z }; solo se guardan las últimas conversaciones vistas
|
|
1386
|
+
let sidIdx = { src: null, map: new Map() };
|
|
1387
|
+
/** Archivo de una conversación por su id (la lista se recorre una vez por escaneo). */
|
|
1388
|
+
function fileOfSid(sid) {
|
|
1389
|
+
if (sidIdx.src !== S.projects) sidIdx = { src: S.projects, map: new Map(S.projects.flatMap((p) => p.sessions.map((q) => [q.id, q.file]))) };
|
|
1390
|
+
return sidIdx.map.get(sid) || null;
|
|
1391
|
+
}
|
|
1392
|
+
const chatFile = (x) => x.file || (x.sid ? fileOfSid(x.sid) : null);
|
|
1393
|
+
/**
|
|
1394
|
+
* Resumen de la conversación de ese archivo, o null mientras se lee la primera vez (undefined si no hay archivo). Se calcula en segundo
|
|
1395
|
+
* plano y, si el archivo crece (el chat abierto), se actualiza leyendo solo lo nuevo, como mucho cada 3 s.
|
|
1396
|
+
*/
|
|
1397
|
+
function chatStats(file) {
|
|
1398
|
+
if (!file) return undefined;
|
|
1399
|
+
let e = STATS.get(file);
|
|
1400
|
+
if (e) { STATS.delete(file); STATS.set(file, e); } // los más recientes al final
|
|
1401
|
+
else { e = { st: stats.newState(), sum: null, at: 0, busy: false, m: -1, z: -1 }; STATS.set(file, e); if (STATS.size > 12) STATS.delete(STATS.keys().next().value); }
|
|
1402
|
+
const now = Date.now();
|
|
1403
|
+
if (!e.busy && now - e.at > (e.sum ? 3000 : 0)) {
|
|
1404
|
+
e.at = now;
|
|
1405
|
+
let s; try { s = fs.statSync(file); } catch { return e.sum; }
|
|
1406
|
+
if (!e.sum || s.size !== e.z || s.mtimeMs !== e.m) {
|
|
1407
|
+
e.busy = true; e.z = s.size; e.m = s.mtimeMs;
|
|
1408
|
+
stats.update(e.st, file).then(() => { e.sum = stats.summary(e.st); }, () => { e.sum = e.sum || stats.summary(e.st); }).finally(() => { e.busy = false; if (active) scheduleRender(); });
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return e.sum;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
/** Campos de las estadísticas, de más a menos importante: se muestran los que quepan, siempre en este orden: MSGS │ TOK │ TOOLS │ modelo. */
|
|
1415
|
+
function statFields(sum) {
|
|
1416
|
+
if (sum === undefined) return [];
|
|
1417
|
+
if (sum === null) return [{ t: '…', c: C.dim, o: 0 }];
|
|
1418
|
+
return [
|
|
1419
|
+
{ t: 'MSGS ' + sum.msgs, c: C.accent, o: 0 },
|
|
1420
|
+
sum.tok ? { t: 'TOK ' + stats.fmtNum(sum.tok), c: C.ok, o: 1 } : null,
|
|
1421
|
+
sum.model ? { t: stats.modelShort(sum.model), c: C.brand + C.bold, o: 3 } : null,
|
|
1422
|
+
sum.tools ? { t: 'TOOLS ' + sum.tools, c: C.warn, o: 2 } : null,
|
|
1423
|
+
].filter(Boolean);
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
/** Título del panel del chat: proyecto › conversación ⎇ rama, y a la derecha MSGS │ TOK │ TOOLS │ modelo (los que quepan). */
|
|
1427
|
+
function headerRow(sh, width, sum) {
|
|
1362
1428
|
if (!sh) return ' '.repeat(width);
|
|
1363
|
-
|
|
1429
|
+
const left = [[' ' + sh.project, C.accent + C.bold], [' › ' + sh.title, C.text], [sh.branch ? ' ⎇ ' + sh.branch : '', C.dim]];
|
|
1430
|
+
const leftW = left.reduce((a, [t]) => a + strW(t), 0), budget = width - Math.min(leftW, Math.floor(width * 0.5)) - 1; // el título puede acortarse, pero no desaparecer
|
|
1431
|
+
const chosen = []; let used = 0;
|
|
1432
|
+
for (const f of statFields(sum)) { const w = strW(f.t) + (chosen.length ? 3 : 0); if (used + w > budget) break; chosen.push(f); used += w; } // en orden de importancia
|
|
1433
|
+
if (!chosen.length) return fit(left, width);
|
|
1434
|
+
chosen.sort((a, b) => a.o - b.o);
|
|
1435
|
+
const right = [];
|
|
1436
|
+
chosen.forEach((f, i) => { if (i) right.push([' │ ', C.faint]); right.push([f.t, f.c]); });
|
|
1437
|
+
right.push([' ', '']);
|
|
1438
|
+
const rw = right.reduce((a, [t]) => a + strW(t), 0);
|
|
1439
|
+
return fit(left, width - rw) + fit(right, rw);
|
|
1364
1440
|
}
|
|
1365
1441
|
|
|
1366
1442
|
function renderEmbed() {
|
|
@@ -1373,7 +1449,7 @@ function renderEmbed() {
|
|
|
1373
1449
|
const selEnt = !sh && !S.help && !S.qs ? flatList()[S.c] : null;
|
|
1374
1450
|
const pvMsgs = selEnt && selEnt.t === 's' ? previewFor(selEnt.s) : null;
|
|
1375
1451
|
const pvRows = pvMsgs && pvMsgs.length ? previewRows(pvMsgs, rw, th, T.prevInfo(ago(selEnt.s.mtime), pvMsgs.length)) : null;
|
|
1376
|
-
const hdr = sh || (selEnt && selEnt.t === 's' ? { project: selEnt.p.name, title: selEnt.s.title, branch: gitBranch(selEnt.p.cwd) } : null);
|
|
1452
|
+
const hdr = sh || (selEnt && selEnt.t === 's' ? { project: selEnt.p.name, title: selEnt.s.title, branch: gitBranch(selEnt.p.cwd), file: selEnt.s.file } : null);
|
|
1377
1453
|
const gRows = E.gallery ? galleryRows(rw, th) : null;
|
|
1378
1454
|
const hv = !E.gallery && sh && sh.ready && E.hover && !E.hover.g.loading && E.hover.g.images.length ? E.hover : null;
|
|
1379
1455
|
const pop = hv ? hoverPopup(hv, rw, th) : null;
|
|
@@ -1389,17 +1465,24 @@ function renderEmbed() {
|
|
|
1389
1465
|
const right = gRows ? (y === 0 ? fit([[' ' + E.gallery.project, C.accent + C.bold], [' › ' + E.gallery.title, C.text],
|
|
1390
1466
|
[E.gallery.images.length ? ` ▣ ${E.gallery.i + 1}/${E.gallery.images.length}` + (gd ? ` · ${gd.w}×${gd.h}` : '') : '', C.dim]], rw)
|
|
1391
1467
|
: y === 1 ? C.faint + '─'.repeat(rw) + R : gRows[ty])
|
|
1392
|
-
: y === 0 ? headerRow(hdr, rw) : y === 1 ? C.faint + '─'.repeat(rw) + R
|
|
1468
|
+
: y === 0 ? headerRow(hdr, rw, hdr ? chatStats(chatFile(hdr)) : undefined) : y === 1 ? C.faint + '─'.repeat(rw) + R
|
|
1393
1469
|
: sh && sh.ready ? (popRow(ty) || termRow(sh.term, ty, rw, selRange(ty, rw))) : sh ? loaderRow(ty, rw, th, sh.title) : pvRows ? pvRows[ty] : idleRow(ty, rw, th);
|
|
1394
1470
|
rowsOut.push((left ? (left[y] || ' '.repeat(SW)) + div : '') + right + (gitR ? gdiv + gitR[y] : ''));
|
|
1395
1471
|
}
|
|
1396
1472
|
const live = E.sessions.size;
|
|
1397
|
-
const k = (key, d) => [[key, C.accent], [' ' + d + '
|
|
1473
|
+
const k = (key, d) => [['[' + key + ']', C.accent + C.bold], [' ' + d + ' ', C.text]]; // [tecla] descripción
|
|
1398
1474
|
const sb = sh && sh.ready ? sh.term.buffer.active : null;
|
|
1399
1475
|
const back = sb ? sb.baseY - sb.viewportY : 0;
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
[
|
|
1476
|
+
// las teclas cambian con el foco: en el chat, las letras son de Claude y solo valen las F; en la lista valen las letras
|
|
1477
|
+
const keys = E.focus === 'right' && sh
|
|
1478
|
+
? [...k('F1', T.barList), ...k('F3', E.mouse ? T.bar4 : T.bar5), ...k('F4', E.hideSide ? T.bar7 : T.bar6), ...k('F5', T.barJump), ...k('F8', T.bar8), ...k('F9', T.barTheme)]
|
|
1479
|
+
: [...k('/', T.k.find), ...k('n', T.k.neu), ...k('Ctrl+P', T.barJump), ...k('b', T.bar8), ...k('t', T.barTheme), ...k('?', T.kHelp), ...k('q', T.k.quit)];
|
|
1480
|
+
// a la derecha: los chats abiertos y cuántos proyectos y chats hay (se omiten si no caben)
|
|
1481
|
+
const stat = [[live ? '● ' + live + ' ' : '', C.ok], [T.barCount(S.projects.length, S.projects.reduce((a, p) => a + p.sessions.length, 0)), C.dim], [' ', '']];
|
|
1482
|
+
const statW = stat.reduce((a, [t]) => a + strW(t), 0), keysW = keys.reduce((a, [t]) => a + strW(t), 0) + strW(E.note ? E.note.t : '') + 8;
|
|
1483
|
+
const full = W - statW >= keysW; // el resumen solo sale si las teclas caben enteras
|
|
1484
|
+
const barL = fit([[' ', ''], [E.note ? E.note.t + ' ' : '', C.ok], [back > 0 ? T.up(back, sb && sb.baseY ? Math.round((100 * sb.viewportY) / sb.baseY) : -1) + ' ' : '', C.warn], ...keys], full ? W - statW : W);
|
|
1485
|
+
rowsOut.push(full ? barL + fit(stat, statW) : barL);
|
|
1403
1486
|
const changes = diffRows(rowsOut);
|
|
1404
1487
|
// imagen real (Sixel) sobre el hueco del cuadro: se dibuja al aparecer y se repite si algo reescribe esas filas (con un mínimo de 150 ms entre dibujos)
|
|
1405
1488
|
let sx = '';
|
|
@@ -1443,13 +1526,13 @@ function embedLaunch(project, session) {
|
|
|
1443
1526
|
{ name: 'xterm-256color', cols: rw, rows: th, cwd: project.cwd, env });
|
|
1444
1527
|
} catch (e) { flash(String(e.message).split('\n')[0]); return; }
|
|
1445
1528
|
const term = new Terminal({ cols: rw, rows: th, allowProposedApi: true, scrollback: 2000 });
|
|
1446
|
-
const sess = { p, term, cursorHidden: false, ready: false, lastData: Date.now(), working: false, busy: false, unseen: false, title: session ? session.title : T.newChat, t0: Date.now(), project: project.name, cwd: project.cwd, sid: session ? session.id : null, closing: false, branch: gitBranch(project.cwd) };
|
|
1529
|
+
const sess = { p, term, cursorHidden: false, ready: false, lastData: Date.now(), quietUntil: 0, working: false, busy: false, unseen: false, title: session ? session.title : T.newChat, t0: Date.now(), project: project.name, cwd: project.cwd, sid: session ? session.id : null, closing: false, branch: gitBranch(project.cwd) };
|
|
1447
1530
|
const vis = (hidden) => (params) => { if (params.some((x) => x === 25 || (Array.isArray(x) && x.includes(25)))) sess.cursorHidden = hidden; return false; };
|
|
1448
1531
|
term.parser.registerCsiHandler({ prefix: '?', final: 'h' }, vis(false));
|
|
1449
1532
|
term.parser.registerCsiHandler({ prefix: '?', final: 'l' }, vis(true));
|
|
1450
1533
|
term.onData((d) => { try { p.write(d); } catch { /* cerrado */ } }); // respuestas a consultas del terminal
|
|
1451
1534
|
p.onData((d) => {
|
|
1452
|
-
sess.lastData = Date.now();
|
|
1535
|
+
if (Date.now() >= sess.quietUntil) sess.lastData = Date.now(); // lo que Claude repinta justo tras redimensionar no es trabajo
|
|
1453
1536
|
// "listo" = ya hay texto visible. En Windows ConPTY manda secuencias de control al arrancar, antes de que Claude dibuje nada.
|
|
1454
1537
|
term.write(d, () => { if (!sess.ready && hasContent(term)) sess.ready = true; if (E.shown === key) scheduleRender(); });
|
|
1455
1538
|
});
|
|
@@ -1474,22 +1557,51 @@ function selNorm(sl) {
|
|
|
1474
1557
|
if (b.y < a.y || (b.y === a.y && b.x < a.x)) [a, b] = [b, a];
|
|
1475
1558
|
return [a, b];
|
|
1476
1559
|
}
|
|
1560
|
+
// La selección del chat guarda en `y` la línea del historial del terminal (absoluta), no la fila de la pantalla: así sigue sobre
|
|
1561
|
+
// el mismo texto aunque el chat se desplace mientras se arrastra, y puede abarcar más de lo que cabe en pantalla.
|
|
1477
1562
|
function selRange(ty, rw) {
|
|
1478
|
-
if (!E.sel
|
|
1479
|
-
const
|
|
1480
|
-
|
|
1481
|
-
|
|
1563
|
+
if (!E.sel) return null;
|
|
1564
|
+
const sh = E.sessions.get(E.shown); if (!sh) return null;
|
|
1565
|
+
const y = sh.term.buffer.active.viewportY + ty, [a, b] = selNorm(E.sel);
|
|
1566
|
+
if (y < a.y || y > b.y) return null;
|
|
1567
|
+
return [y === a.y ? a.x : 0, y === b.y ? b.x : rw - 1];
|
|
1482
1568
|
}
|
|
1483
1569
|
function selText(sh, sl) {
|
|
1484
1570
|
const [a, b] = selNorm(sl); const buf = sh.term.buffer.active; const out = [];
|
|
1485
1571
|
for (let y = a.y; y <= b.y; y++) {
|
|
1486
|
-
const l = buf.getLine(
|
|
1572
|
+
const l = buf.getLine(y);
|
|
1487
1573
|
out.push(l ? l.translateToString(true, y === a.y ? a.x : 0, y === b.y ? b.x + 1 : sh.term.cols) : '');
|
|
1488
1574
|
}
|
|
1489
1575
|
return out.join('\n').replace(/\s+$/, '');
|
|
1490
1576
|
}
|
|
1577
|
+
/** Copia la selección marcada y la quita. Solo se llama cuando el usuario lo pide (Ctrl+C, clic derecho), o con "copyOnSelect". */
|
|
1578
|
+
function copySelection(sh) {
|
|
1579
|
+
const sl = E.sel; E.sel = null; stopSelScroll();
|
|
1580
|
+
const t = sl && sh ? selText(sh, sl) : '';
|
|
1581
|
+
if (t) { copyText(t); E.note = { t: T.copied(t.length), until: Date.now() + 3000 }; }
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
// Al arrastrar contra el borde de arriba o de abajo, el chat se desplaza solo (aunque el ratón se quede quieto) y la selección sigue.
|
|
1585
|
+
let selTimer = null;
|
|
1586
|
+
function stopSelScroll() { if (selTimer) { clearInterval(selTimer); selTimer = null; } if (E.sel) E.sel.dir = 0; }
|
|
1587
|
+
function selScrollTick() {
|
|
1588
|
+
const sel = E.sel, sh = E.sessions.get(E.shown);
|
|
1589
|
+
if (!sel || !sel.down || !sel.dir || !sh || sh.term.buffer.active.type === 'alternate') return stopSelScroll();
|
|
1590
|
+
sh.term.scrollLines(-sel.dir * 2); // dir > 0: hacia arriba
|
|
1591
|
+
const row = sel.dir > 0 ? 0 : embedLayout().th - 1;
|
|
1592
|
+
sel.b = { x: sel.b.x, y: sh.term.buffer.active.viewportY + row };
|
|
1593
|
+
render();
|
|
1594
|
+
}
|
|
1595
|
+
/** `row`: fila del ratón respecto a la zona del chat (negativa = encima, ≥ th = debajo). Pone en marcha o para el desplazamiento. */
|
|
1596
|
+
function selEdge(sh, row) {
|
|
1597
|
+
const th = embedLayout().th, dir = row < 0 ? 1 : row >= th ? -1 : 0;
|
|
1598
|
+
E.sel.dir = dir;
|
|
1599
|
+
if (dir && sh.term.buffer.active.type !== 'alternate') { if (!selTimer) { selTimer = setInterval(selScrollTick, 60); selScrollTick(); } }
|
|
1600
|
+
else if (selTimer) { clearInterval(selTimer); selTimer = null; }
|
|
1601
|
+
}
|
|
1491
1602
|
/** Copia al portapapeles: OSC 52 (la mayoría de terminales) + comando del sistema como respaldo. */
|
|
1492
1603
|
function copyText(t) {
|
|
1604
|
+
if (process.env.HOPDECK_COPY_LOG) { try { fs.appendFileSync(process.env.HOPDECK_COPY_LOG, JSON.stringify(t) + '\n'); } catch { /* */ } return; } // pruebas: se anota en un archivo y no se toca el portapapeles
|
|
1493
1605
|
try { process.stdout.write(`\x1b]52;c;${Buffer.from(t).toString('base64')}\x07`); } catch { /* */ }
|
|
1494
1606
|
const run = (cmd, args) => { try { const c = cp.spawn(cmd, args, { stdio: ['pipe', 'ignore', 'ignore'] }); c.on('error', () => {}); c.stdin.on('error', () => {}); c.stdin.end(t); } catch { /* */ } };
|
|
1495
1607
|
if (process.platform === 'darwin') run('pbcopy', []);
|
|
@@ -1570,7 +1682,7 @@ function onMouse(b, x, y, type) {
|
|
|
1570
1682
|
return render();
|
|
1571
1683
|
}
|
|
1572
1684
|
if ((b & 32) && (b & 3) === 3) { // movimiento sin botón (hover): previsualiza la conversación bajo el cursor
|
|
1573
|
-
if (S.help || S.qs || E.sel) return;
|
|
1685
|
+
if (S.help || S.qs || (E.sel && E.sel.down)) return;
|
|
1574
1686
|
if (S.fb) { const i = S.fb.off + (y - 3); if (x <= SW && y >= 3 && y <= rh - 2 && fbRows()[i] && i !== S.fb.i) { S.fb.i = i; scheduleRender(); } return; }
|
|
1575
1687
|
if (sh) { if (x > SW) hoverChat(sh, x, y); else if (E.hover) { E.hover = null; scheduleRender(); } return; }
|
|
1576
1688
|
if (x > SW || y < 3 || y > rh - 2) return;
|
|
@@ -1579,24 +1691,30 @@ function onMouse(b, x, y, type) {
|
|
|
1579
1691
|
return;
|
|
1580
1692
|
}
|
|
1581
1693
|
const x0 = SW ? SW + 2 : 1, inPane = (SW ? x > SW + 1 : true) && y >= 3 && sh && sh.ready;
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
if (
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1694
|
+
// celda del chat bajo el ratón; `y` es la línea del historial (ver selRange), así que sirve aunque el chat esté desplazado
|
|
1695
|
+
const cell = () => { const L = embedLayout(); return { x: clamp(x - x0, 0, L.rw - 1), y: sh.term.buffer.active.viewportY + clamp(y - 3, 0, L.th - 1) }; };
|
|
1696
|
+
if ((b & 32) && (b & 3) === 0) { // arrastre
|
|
1697
|
+
if (E.sel && E.sel.down && sh) { E.sel.b = cell(); selEdge(sh, y - 3); render(); }
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
if (type === 'm') { // soltar
|
|
1701
|
+
stopSelScroll();
|
|
1702
|
+
const sl = E.sel;
|
|
1703
|
+
if (!sl || !sl.down) return render();
|
|
1704
|
+
if (sl.a.x === sl.b.x && sl.a.y === sl.b.y) { // un clic sin arrastrar: si es sobre un [Image #N], se abre la imagen
|
|
1705
|
+
E.sel = null;
|
|
1706
|
+
if (sh && sh.ready) { const hit = imageMarkerAt(sh.term, sl.a.y - sh.term.buffer.active.viewportY, sl.a.x); if (hit) openMarkerImage(sh, hit.n); }
|
|
1707
|
+
return render();
|
|
1593
1708
|
}
|
|
1709
|
+
sl.down = false; // la selección se queda marcada: no se copia sola (se copia con Ctrl+C o clic derecho), salvo con "copyOnSelect": true
|
|
1710
|
+
if (CFG.copyOnSelect) copySelection(sh); else E.note = { t: T.selHint, until: Date.now() + 8000 };
|
|
1594
1711
|
return render();
|
|
1595
1712
|
}
|
|
1713
|
+
if (type === 'M' && (b & 3) === 2 && E.sel && !E.sel.down && sh) { copySelection(sh); return render(); } // clic derecho: copiar lo marcado
|
|
1596
1714
|
if (type !== 'M' || (b & 3) !== 0) return; // solo clic izquierdo
|
|
1597
1715
|
if (x <= SW && y === 1 && !S.fb && !S.qs && S.prompt === null && !S.help) { E.focus = 'left'; E.sel = null; S.searching = true; S.qpos = [...S.query].length; return render(); } // clic en la fila de arriba de la lista: buscar
|
|
1598
|
-
if (inPane) { E.focus = 'right'; const c = cell(); E.sel = { a: c, b: c, down: true }; return render(); }
|
|
1599
|
-
E.sel = null;
|
|
1716
|
+
if (inPane) { E.focus = 'right'; const c = cell(); stopSelScroll(); E.sel = { a: c, b: c, down: true, dir: 0 }; return render(); }
|
|
1717
|
+
stopSelScroll(); E.sel = null;
|
|
1600
1718
|
if (S.fb && x <= SW) {
|
|
1601
1719
|
E.focus = 'left'; const i = S.fb.off + (y - 3);
|
|
1602
1720
|
if (S.prompt === null && y >= 3 && y <= rh - 2 && fbRows()[i]) { S.fb.i = i; return fbActivate(); }
|
|
@@ -1620,7 +1738,11 @@ function hasContent(term) {
|
|
|
1620
1738
|
}
|
|
1621
1739
|
|
|
1622
1740
|
function embedInput(s) {
|
|
1623
|
-
E.sel
|
|
1741
|
+
if (E.sel && !E.sel.down) { // hay texto seleccionado: Ctrl+C lo copia y Esc lo quita, sin llegar a Claude (Esc le interrumpiría)
|
|
1742
|
+
if (s === '\x03') { copySelection(E.sessions.get(E.shown)); return render(); }
|
|
1743
|
+
if (s === '\x1b') { E.sel = null; E.note = null; return render(); }
|
|
1744
|
+
}
|
|
1745
|
+
stopSelScroll(); E.sel = null; E.hover = null;
|
|
1624
1746
|
if (s === '\x1bOP' || s === '\x1b[11~' || s === '\x1b[1;1P') { E.focus = 'left'; if (E.hideSide) { E.hideSide = false; embedResize(); } else render(); return; }
|
|
1625
1747
|
const sh = E.sessions.get(E.shown);
|
|
1626
1748
|
const b = sh.term.buffer.active, scrolled = b.baseY > b.viewportY;
|
|
@@ -1677,10 +1799,26 @@ function closeChat(key) {
|
|
|
1677
1799
|
flash(T.closed(x.title));
|
|
1678
1800
|
}
|
|
1679
1801
|
|
|
1802
|
+
/**
|
|
1803
|
+
* ¿Claude Code está trabajando de verdad? Mientras genera, su pantalla muestra «esc to interrupt» (o «ctrl+c to interrupt»).
|
|
1804
|
+
* Antes bastaba con que el chat escribiera algo en el último segundo, y eso también pasa sin trabajo: al redimensionar los
|
|
1805
|
+
* paneles, al cambiar de ventana, o al actualizar su barra de estado. Se mira solo la pantalla viva (no lo que se ve al subir).
|
|
1806
|
+
*/
|
|
1807
|
+
const BUSY_HINT = /(esc|ctrl\+c) to interrupt/i;
|
|
1808
|
+
function showsBusy(term) {
|
|
1809
|
+
const b = term.buffer.active;
|
|
1810
|
+
for (let y = Math.max(0, term.rows - 14); y < term.rows; y++) {
|
|
1811
|
+
const l = b.getLine(b.baseY + y);
|
|
1812
|
+
if (l && BUSY_HINT.test(l.translateToString(true))) return true;
|
|
1813
|
+
}
|
|
1814
|
+
return false;
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1680
1817
|
function pollChats() {
|
|
1681
1818
|
const now = Date.now(); let changed = false;
|
|
1682
1819
|
for (const [key, x] of E.sessions) {
|
|
1683
|
-
|
|
1820
|
+
// HOPDECK_BUSY=output devuelve el criterio antiguo (cualquier salida reciente) por si una versión de Claude cambia ese texto
|
|
1821
|
+
const working = x.ready && now - x.lastData < 1200 && (process.env.HOPDECK_BUSY === 'output' || showsBusy(x.term));
|
|
1684
1822
|
if (x.working && !working && x.busy) {
|
|
1685
1823
|
x.busy = false;
|
|
1686
1824
|
if (E.shown !== key || E.focus !== 'right') { x.unseen = true; E.note = { t: '✔ ' + x.project + ' › ' + x.title, until: now + 6000 }; process.stdout.write('\x07'); notifyDesktop(x.project + ' › ' + x.title); }
|
|
@@ -1694,9 +1832,9 @@ function pollChats() {
|
|
|
1694
1832
|
const x_any = (e) => [...e.sessions.values()].some((x) => x.working);
|
|
1695
1833
|
|
|
1696
1834
|
function embedResize() {
|
|
1697
|
-
invalidate(); E.sel = null;
|
|
1835
|
+
invalidate(); stopSelScroll(); E.sel = null; // al cambiar el ancho las líneas se reajustan: la selección ya no marcaría lo mismo
|
|
1698
1836
|
const { rw, th } = embedLayout();
|
|
1699
|
-
for (const sess of E.sessions.values()) { try { sess.p.resize(rw, th); sess.term.resize(rw, th); } catch { /* */ } }
|
|
1837
|
+
for (const sess of E.sessions.values()) { sess.quietUntil = Date.now() + 1500; try { sess.p.resize(rw, th); sess.term.resize(rw, th); } catch { /* */ } } // todos los chats se repintan al cambiar el tamaño
|
|
1700
1838
|
render();
|
|
1701
1839
|
}
|
|
1702
1840
|
|
|
@@ -1873,7 +2011,10 @@ function splash(done, total) {
|
|
|
1873
2011
|
const lines = [[C.brand + C.bold, '» Hopdeck'], ['', ''],
|
|
1874
2012
|
[C.dim, `${spin()} ${T.loading}${total ? ` ${done}/${total}` : '…'}`]];
|
|
1875
2013
|
let out = '\x1b[2J';
|
|
1876
|
-
|
|
2014
|
+
const art = mascotArt(c, r - lines.length - 2), gap = art.length ? 1 : 0; // la mascota va encima, si cabe
|
|
2015
|
+
const top = art.length ? Math.max(1, Math.floor((r - art.length - gap - lines.length) / 2) + 1) : Math.max(1, Math.floor(r / 2) - 1);
|
|
2016
|
+
art.forEach((_, j) => { out += `\x1b[${top + j};1H${mascotRow(art, j, c)}`; });
|
|
2017
|
+
lines.forEach(([st, t], i) => { out += `\x1b[${top + art.length + gap + i};${Math.max(1, Math.floor((c - strW(t)) / 2) + 1)}H${st}${t}${R}`; });
|
|
1877
2018
|
process.stdout.write(out);
|
|
1878
2019
|
}
|
|
1879
2020
|
|
|
@@ -2198,9 +2339,9 @@ function tutorial(afterInstall) {
|
|
|
2198
2339
|
|
|
2199
2340
|
// ───────────────────────── entrada ─────────────────────────
|
|
2200
2341
|
// ── Comandos: UNA sola forma para cada uno (shortcut on|off, uninstall, doctor, help). Lo demás no hace nada: da un error con una sugerencia ──
|
|
2201
|
-
const COMMANDS = ['shortcut', 'theme', 'uninstall', 'doctor', 'help'];
|
|
2342
|
+
const COMMANDS = ['shortcut', 'theme', 'mascot', 'uninstall', 'doctor', 'help'];
|
|
2202
2343
|
// Palabras que alguien escribiría para lo mismo: no son comandos y no se ejecutan, solo sirven para sugerir el correcto
|
|
2203
|
-
const SYNONYMS = { install: 'shortcut on', instalar: 'shortcut on', atajo: 'shortcut on', desinstalar: 'uninstall', remove: 'uninstall', delete: 'uninstall', ayuda: 'help', diagnostico: 'doctor', version: '--version', list: '--list', tema: 'theme', modo: 'theme', mode: 'theme', dark: 'theme dark', light: 'theme light', oscuro: 'theme dark', claro: 'theme light' };
|
|
2344
|
+
const SYNONYMS = { install: 'shortcut on', instalar: 'shortcut on', atajo: 'shortcut on', desinstalar: 'uninstall', remove: 'uninstall', delete: 'uninstall', ayuda: 'help', diagnostico: 'doctor', version: '--version', list: '--list', tema: 'theme', mascota: 'mascot', sapo: 'mascot', frog: 'mascot', modo: 'theme', mode: 'theme', dark: 'theme dark', light: 'theme light', oscuro: 'theme dark', claro: 'theme light' };
|
|
2204
2345
|
/** Nombre de comando si `arg` es exactamente uno (sin guiones ni variantes); null si no. */
|
|
2205
2346
|
const commandName = (arg) => (COMMANDS.includes(String(arg || '').toLowerCase()) ? String(arg).toLowerCase() : null);
|
|
2206
2347
|
const editDistance = (a, b) => { const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]); for (let j = 1; j <= b.length; j++) d[0][j] = j; for (let i = 1; i <= a.length; i++) for (let j = 1; j <= b.length; j++) d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)); return d[a.length][b.length]; };
|
|
@@ -2235,6 +2376,17 @@ function main() {
|
|
|
2235
2376
|
const eff = env ? (LIGHT ? 'light' : 'dark') : CFG.theme || (/;(7|15)$/.test(process.env.COLORFGBG || '') ? 'light' : 'dark');
|
|
2236
2377
|
console.log(T.themeShow(CFG.theme || 'auto', eff, CFG.theme ? 'config' : 'auto', env));
|
|
2237
2378
|
}
|
|
2379
|
+
else if (commandName(cmd) === 'mascot') { // hopdeck mascot [--size small|normal|large] [--plain]: dibuja la mascota (sin colores con --plain o NO_COLOR)
|
|
2380
|
+
const sizes = { small: 32, normal: 48, large: 64 }; let size = 'normal', plain = false, bad = false;
|
|
2381
|
+
for (let i = 0; i < rest.length; i++) {
|
|
2382
|
+
if (rest[i] === '--plain') plain = true;
|
|
2383
|
+
else if (rest[i] === '--size' && sizes[rest[i + 1]]) size = rest[++i];
|
|
2384
|
+
else bad = true;
|
|
2385
|
+
}
|
|
2386
|
+
if (bad) { console.error(`${C.warn}${T.mascotUsage}${R}`); process.exit(2); }
|
|
2387
|
+
if (plain || NOCOL) console.log(mascot.ASCII);
|
|
2388
|
+
else { const cols = process.stdout.isTTY ? process.stdout.columns || 80 : 999; console.log(mascot.render(Math.max(16, Math.min(sizes[size], cols))).join('\n')); }
|
|
2389
|
+
}
|
|
2238
2390
|
else if (commandName(cmd) === 'uninstall') { // desinstalación completa: atajo, preferencias, caché y programa
|
|
2239
2391
|
if (rest.some((a) => a !== '--yes' && a !== '-y')) { console.error(`${C.warn}${T.unknownCmd(rest.find((a) => a !== '--yes' && a !== '-y'))}${R}\n${C.dim}${T.cmdList}${R}`); process.exit(2); }
|
|
2240
2392
|
uninstallAll({ yes: rest.length > 0 }).then((code) => process.exit(code), (e) => { console.error(e); process.exit(1); });
|
package/lib/i18n.js
CHANGED
|
@@ -21,8 +21,9 @@ const T = {
|
|
|
21
21
|
prevHint: '⏎ reanudar esta conversación', bar8: 'git', gitNone: 'Elige un proyecto', gitNoRepo: 'Esta carpeta no es un repositorio git', gitMissing: 'git no está instalado', gitErr: 'No se pudo leer el repositorio', gitClean: 'sin cambios', gitDirty: (n) => (n === 1 ? '1 cambio sin guardar' : `${n} cambios sin guardar`), gitMore: (n) => `… y ${n} más`, gitBranches: 'Ramas recientes', gitActivity: 'Actividad de ramas', gitNoActivity: 'Sin cambios de rama', gitFrom: 'desde', gitNarrow: (n) => `Terminal estrecha: el panel de git necesita ${n} columnas`, gitOnlyEmbed: 'El panel de git solo está en el terminal integrado', prevInfo: (a, n) => `${a === 'ahora' ? 'ahora mismo' : 'hace ' + a} · últimos ${n} mensajes`, kUnfold: 'desplegar', kRename: 'renombrar', kPin: 'fijar', kHelp: 'ayuda', noPrev: 'Sin mensajes para mostrar',
|
|
22
22
|
bar6: 'ocultar lista', bar7: 'mostrar lista', deep: 'contenido', pathPrompt: 'nombre de la nueva carpeta', mkIn: 'se crea en', fbTitle: 'Elegir carpeta', fbHere: 'Abrir chat aquí', fbNew: 'Nueva carpeta aquí…', fbUp: 'Subir un nivel', fbProj: 'proyecto', fbHint: '⏎ entrar · ␣ abrir · / buscar · . ocultas', fbDrives: 'Este equipo', fbRecent: 'reciente', hoverMiss: (n) => `[Image #${n}]: aún no está en el historial`, fbEmpty: 'Sin subcarpetas', badId: 'Identificador de sesión no válido',
|
|
23
23
|
imgClickHint: 'clic: abrir en grande', imgOpened: (n) => `[Image #${n}] abierta en el visor de imágenes`,
|
|
24
|
-
unknownCmd: (c) => `Comando desconocido: "${c}"`, didYouMean: (s) => `¿Quisiste decir "${s}"?`, cmdList: 'Comandos: hopdeck shortcut on|off · theme light|dark|auto · uninstall · doctor · help (y --list, --version).\nLas opciones de claude (por ejemplo --model opus) se pasan tal cual: hopdeck --model opus',
|
|
24
|
+
unknownCmd: (c) => `Comando desconocido: "${c}"`, didYouMean: (s) => `¿Quisiste decir "${s}"?`, cmdList: 'Comandos: hopdeck shortcut on|off · theme light|dark|auto · mascot · uninstall · doctor · help (y --list, --version).\nLas opciones de claude (por ejemplo --model opus) se pasan tal cual: hopdeck --model opus',
|
|
25
25
|
themeNow: (n) => `Tema ${n === 'light' ? 'claro' : 'oscuro'} (guardado)`,
|
|
26
|
+
mascotUsage: 'Uso: hopdeck mascot · hopdeck mascot --size small|normal|large · hopdeck mascot --plain (sin colores)',
|
|
26
27
|
themeUsage: 'Uso: hopdeck theme light (claro) · hopdeck theme dark (oscuro) · hopdeck theme auto (según el terminal) · hopdeck theme (ver el actual)',
|
|
27
28
|
themeShow: (saved, eff, from, env) => `Tema guardado: ${saved === 'auto' ? 'automático' : saved === 'light' ? 'claro' : 'oscuro'}.\nSe está usando: ${eff === 'light' ? 'claro' : 'oscuro'}` + (env ? ' (la variable HOPDECK_THEME tiene prioridad sobre lo guardado).' : from === 'auto' ? ' (automático: oscuro salvo que el terminal diga que tiene fondo claro).' : '.'),
|
|
28
29
|
shortcutUsage: 'Uso: hopdeck shortcut on (instalar el atajo de claude) · hopdeck shortcut off (quitarlo)',
|
|
@@ -43,7 +44,9 @@ const T = {
|
|
|
43
44
|
'c F6 cerrar el chat abierto', 'i F7 ver imágenes del chat', 'R a renombrar / archivar', 'Ctrl+P F5 saltar a cualquier chat', '[ ] ancho de la lista', 'r recargar',
|
|
44
45
|
'F1 F2 foco lista / chat', 'F3 copiar texto (ratón)', 'F4 ocultar la lista', 'b F8 panel de git', 't F9 tema claro / oscuro', '⠋ ✔ ● trabajando · terminó · abierta', 'q salir'],
|
|
45
46
|
bar4: 'copiar texto', bar5: 'ratón', up: (n, pct) => `↑ ${n} líneas${pct >= 0 ? ` (${pct}%)` : ''} · PgDn/End`, loading: 'Cargando proyectos', opening: 'Abriendo conversación', close: 'cerrar', idle1: 'Elige una conversación', idle2: 'Usa ↑↓ y ⏎ en el panel izquierdo',
|
|
47
|
+
barList: 'lista', barJump: 'saltar', barTheme: 'tema', barCount: (p, c) => `${p} ${p === 1 ? 'proyecto' : 'proyectos'} · ${c} ${c === 1 ? 'chat' : 'chats'}`,
|
|
46
48
|
idle3: 'F1 proyectos · F2 chat', bar1: 'proyectos', bar2: 'chat', bar3: 'minimizar',
|
|
49
|
+
selHint: 'Ctrl+C o clic derecho: copiar · Esc: quitar la selección',
|
|
47
50
|
searchPh: 'buscar conversación o proyecto…', found: (n) => `${n} ${n === 1 ? 'resultado' : 'resultados'}`, noRes: (q) => `Sin resultados para «${q}»`,
|
|
48
51
|
searchingContent: 'Buscando dentro de las conversaciones…', tryContent: 'Pulsa Tab para buscar también dentro del contenido', inContent: 'en el contenido', kClear: 'limpiar', kEdit: 'editar', kEsc: 'salir',
|
|
49
52
|
inside: 'Ya estás dentro de Hopdeck (F1 para ir a la lista de proyectos).',
|
|
@@ -66,8 +69,9 @@ const T = {
|
|
|
66
69
|
prevHint: '⏎ resume this conversation', bar8: 'git', gitNone: 'Pick a project', gitNoRepo: 'This folder is not a git repository', gitMissing: 'git is not installed', gitErr: 'Could not read the repository', gitClean: 'clean', gitDirty: (n) => (n === 1 ? '1 uncommitted change' : `${n} uncommitted changes`), gitMore: (n) => `… and ${n} more`, gitBranches: 'Recent branches', gitActivity: 'Branch activity', gitNoActivity: 'No branch changes', gitFrom: 'from', gitNarrow: (n) => `Terminal too narrow: the git panel needs ${n} columns`, gitOnlyEmbed: 'The git panel is only in the built-in terminal', prevInfo: (a, n) => `${a === 'now' ? 'just now' : a + ' ago'} · last ${n} messages`, kUnfold: 'unfold', kRename: 'rename', kPin: 'pin', kHelp: 'help', noPrev: 'No messages to show',
|
|
67
70
|
bar6: 'hide list', bar7: 'show list', deep: 'content', pathPrompt: 'new folder name', mkIn: 'created in', fbTitle: 'Pick a folder', fbHere: 'Open chat here', fbNew: 'New folder here…', fbUp: 'Go up', fbProj: 'project', fbHint: '⏎ enter · ␣ open · / find · . hidden', fbDrives: 'This PC', fbRecent: 'recent', hoverMiss: (n) => `[Image #${n}]: not in the history yet`, fbEmpty: 'No subfolders', badId: 'Invalid session id',
|
|
68
71
|
imgClickHint: 'click: open full size', imgOpened: (n) => `[Image #${n}] opened in the image viewer`,
|
|
69
|
-
unknownCmd: (c) => `Unknown command: "${c}"`, didYouMean: (s) => `Did you mean "${s}"?`, cmdList: 'Commands: hopdeck shortcut on|off · theme light|dark|auto · uninstall · doctor · help (and --list, --version).\nclaude options (for example --model opus) are passed through as they are: hopdeck --model opus',
|
|
72
|
+
unknownCmd: (c) => `Unknown command: "${c}"`, didYouMean: (s) => `Did you mean "${s}"?`, cmdList: 'Commands: hopdeck shortcut on|off · theme light|dark|auto · mascot · uninstall · doctor · help (and --list, --version).\nclaude options (for example --model opus) are passed through as they are: hopdeck --model opus',
|
|
70
73
|
themeNow: (n) => `${n === 'light' ? 'Light' : 'Dark'} theme (saved)`,
|
|
74
|
+
mascotUsage: 'Usage: hopdeck mascot · hopdeck mascot --size small|normal|large · hopdeck mascot --plain (no colors)',
|
|
71
75
|
themeUsage: 'Usage: hopdeck theme light · hopdeck theme dark · hopdeck theme auto (follow the terminal) · hopdeck theme (show the current one)',
|
|
72
76
|
themeShow: (saved, eff, from, env) => `Saved theme: ${saved}.\nIn use: ${eff}` + (env ? ' (the HOPDECK_THEME variable takes priority over the saved one).' : from === 'auto' ? ' (auto: dark unless the terminal says it has a light background).' : '.'),
|
|
73
77
|
shortcutUsage: 'Usage: hopdeck shortcut on (install the claude shortcut) · hopdeck shortcut off (remove it)',
|
|
@@ -88,7 +92,9 @@ const T = {
|
|
|
88
92
|
'c F6 close the open chat', 'i F7 view the chat images', 'R a rename / archive', 'Ctrl+P F5 jump to any chat', '[ ] list width', 'r reload',
|
|
89
93
|
'F1 F2 focus list / chat', 'F3 copy text (mouse)', 'F4 hide the list', 'b F8 git panel', 't F9 light / dark theme', '⠋ ✔ ● working · done · open', 'q quit'],
|
|
90
94
|
bar4: 'copy text', bar5: 'mouse', up: (n, pct) => `↑ ${n} lines${pct >= 0 ? ` (${pct}%)` : ''} · PgDn/End`, loading: 'Loading projects', opening: 'Opening conversation', close: 'close', idle1: 'Pick a conversation', idle2: 'Use ↑↓ and ⏎ in the left pane',
|
|
95
|
+
barList: 'list', barJump: 'jump', barTheme: 'theme', barCount: (p, c) => `${p} ${p === 1 ? 'project' : 'projects'} · ${c} ${c === 1 ? 'chat' : 'chats'}`,
|
|
91
96
|
idle3: 'F1 projects · F2 chat', bar1: 'projects', bar2: 'chat', bar3: 'minimize',
|
|
97
|
+
selHint: 'Ctrl+C or right click: copy · Esc: clear the selection',
|
|
92
98
|
searchPh: 'search conversation or project…', found: (n) => `${n} ${n === 1 ? 'result' : 'results'}`, noRes: (q) => `No results for “${q}”`,
|
|
93
99
|
searchingContent: 'Searching inside the conversations…', tryContent: 'Press Tab to also search inside the content', inContent: 'in content', kClear: 'clear', kEdit: 'edit', kEsc: 'exit',
|
|
94
100
|
inside: 'You are already inside Hopdeck (F1 jumps to the project list).',
|
package/lib/mascot.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// La mascota de Hopdeck: un sapo naranja con auriculares. Son 64×64 píxeles con transparencia que se dibujan con medios bloques
|
|
3
|
+
// (▀ ▄) al tamaño que quepa. Los píxeles van comprimidos (zlib + base64) para no depender de ningún archivo de imagen.
|
|
4
|
+
const zlib = require('zlib');
|
|
5
|
+
const { TRUE, R } = require('./style');
|
|
6
|
+
|
|
7
|
+
const SIZE = 64;
|
|
8
|
+
const PIXELS = zlib.inflateSync(Buffer.from(
|
|
9
|
+
'eNrtewd8VNW2N+WWh42SOpmZc2ZOL3OmlxSSANI7QighCT10AtJ7syCKFEFEAQXlXgXUawMUBNQrCOpFrCBypVdBIQnJlP/Z3++c' +
|
|
10
|
+
'gPJ83vt9n4r63nP/fiszk7P32uu/9tprr732PrVq/V5+L7+XX7nUvo7+p+Osm5+f/weDatWqVeeH6xTUvfq87v8QndS5iucHC8dx' +
|
|
11
|
+
'f7bZbPUKavD+QCmoW+tfPvtt475ebgOnwithWZRHyYK8WuClHRwvf8Ry4hGGk45xnHxQ4OVdEi89LYvyVJ6XmzMMU/97/Or894Be' +
|
|
12
|
+
'8C1ukRE1SZDmC4JykGZlksEoJJ1RzU+KlYmTkwjDyaTmmUzSnAqxMIr5m+flkyIvrWRZMfuHeP9G57g5Rg6HKEq8tJbh5KjFqRAr' +
|
|
13
|
+
'LZCwqiT6NnZH57XzRv/a3RfbWhKI7+4fiL8zIBDf2TcQ39jDF3ugvTs2MNcVy3LJcSsjkXSnQlheJpIgv8iykv97PvO3Zu9mEThh' +
|
|
14
|
+
'DMfLl9OcMuEdDIbma9HNw26Pnx2TCTI5E2RqVjwxMTNWPi4S/WpMJHp+dDh66c5wNDYhHCOTwwkyOYKzZSG8UuRLDMlzxVhOShj2' +
|
|
15
|
+
'wvNylOOk6T/U528Be0pKyi2SIG1w8CqxUqxe1swV+/ze7iAvTgR5anh835BwdHknD4blu0jHoELy3QqJqDIJqxLJcUmkrV8mg3JV' +
|
|
16
|
+
'srC9pu/p749WjwvFyaQw9gwIoCRbjaXRQoLlDT1If0tJUW75jejA7N9mszUSeXG3lVVISGCj28a0TpBXJiOxdkRsdZ+8eHuvQBhG' +
|
|
17
|
+
'IEk2ljTMYI82snE70u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hfJ/AKLTK1o=', 'base64')); // RGBA, 4 bytes por píxel
|
|
102
|
+
|
|
103
|
+
/** La misma mascota sin colores, para NO_COLOR o --plain. */
|
|
104
|
+
const ASCII = " .-============-.\n .-' _ _ '-.\n / (o) (o) \\\\\n .---|---. .. .---|---.\n | >_ | \\____/ | |\n '---|---' '---|---'\n \\ .------. /\n '._ \\____/ _.-'\n '----------'\n /_||_\\\\";
|
|
105
|
+
|
|
106
|
+
/** Color del píxel (r, g, b) de la celda (x, y) de una versión de n×n: promedio de los píxeles que cubre, o null si es transparente. */
|
|
107
|
+
function sample(x, y, n) {
|
|
108
|
+
const x0 = Math.floor((x * SIZE) / n), x1 = Math.max(x0 + 1, Math.floor(((x + 1) * SIZE) / n));
|
|
109
|
+
const y0 = Math.floor((y * SIZE) / n), y1 = Math.max(y0 + 1, Math.floor(((y + 1) * SIZE) / n));
|
|
110
|
+
let a = 0, r = 0, g = 0, b = 0, cnt = 0;
|
|
111
|
+
for (let yy = y0; yy < y1 && yy < SIZE; yy++) {
|
|
112
|
+
for (let xx = x0; xx < x1 && xx < SIZE; xx++) {
|
|
113
|
+
const i = (yy * SIZE + xx) * 4, al = PIXELS[i + 3];
|
|
114
|
+
cnt++; a += al; r += PIXELS[i] * al; g += PIXELS[i + 1] * al; b += PIXELS[i + 2] * al;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!cnt || !a || a / cnt < 100) return null; // casi transparente
|
|
118
|
+
return [Math.round(r / a), Math.round(g / a), Math.round(b / a)];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const c256 = ([r, g, b]) => { const q = (v) => Math.round((v / 255) * 5); return 16 + 36 * q(r) + 6 * q(g) + q(b); };
|
|
122
|
+
const col = (c, bg) => (TRUE ? `\x1b[${bg ? 48 : 38};2;${c[0]};${c[1]};${c[2]}m` : `\x1b[${bg ? 48 : 38};5;${c256(c)}m`);
|
|
123
|
+
/** Cada celda son dos píxeles: ▀ con el de arriba de color de letra y el de abajo de fondo. Lo transparente deja ver el fondo del terminal. */
|
|
124
|
+
function cell(top, bottom) {
|
|
125
|
+
if (!top && !bottom) return ' ';
|
|
126
|
+
if (top && !bottom) return col(top) + '▀' + R;
|
|
127
|
+
if (!top && bottom) return col(bottom) + '▄' + R;
|
|
128
|
+
return col(top) + col(bottom, true) + '▀' + R;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const CACHE = new Map();
|
|
132
|
+
/** Filas de texto (n celdas de ancho, n/2 de alto) con la mascota a n×n píxeles. */
|
|
133
|
+
function render(n) {
|
|
134
|
+
n = Math.max(2, Math.min(SIZE, n & ~1));
|
|
135
|
+
if (CACHE.has(n)) return CACHE.get(n);
|
|
136
|
+
const rows = [];
|
|
137
|
+
for (let y = 0; y < n; y += 2) {
|
|
138
|
+
let line = '';
|
|
139
|
+
for (let x = 0; x < n; x++) line += cell(sample(x, y, n), sample(x, y + 1, n));
|
|
140
|
+
rows.push(line);
|
|
141
|
+
}
|
|
142
|
+
CACHE.set(n, rows);
|
|
143
|
+
return rows;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** El mayor tamaño que cabe en `maxCols` columnas y `maxRows` filas, o 0 si ni el más pequeño. */
|
|
147
|
+
const sizeFor = (maxCols, maxRows) => [48, 40, 32, 24, 16].find((n) => n <= maxCols && n / 2 <= maxRows) || 0;
|
|
148
|
+
|
|
149
|
+
module.exports = { SIZE, ASCII, render, sizeFor };
|
package/lib/stats.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Estadísticas de una conversación (mensajes, tokens, herramientas, modelo) sacadas de su archivo .jsonl. Claude Code solo añade
|
|
3
|
+
// líneas al final, así que se lee todo una vez y, cuando el archivo crece, únicamente lo que se añadió. Los archivos llegan a pesar
|
|
4
|
+
// decenas de MB: se lee por bloques y se cede el control entre ellos para no congelar la interfaz.
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const newState = () => ({ pos: 0, carry: Buffer.alloc(0), users: 0, asst: new Map(), anon: 0, anonTok: 0, tools: new Set(), anonTools: 0, model: '' });
|
|
8
|
+
|
|
9
|
+
const num = (v) => (Number.isFinite(v) && v > 0 ? v : 0);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Suma una línea del archivo. Las de la conversación empiezan por {"parentUuid" y llevan el rol dentro de "message", al principio:
|
|
13
|
+
* con eso basta para saber si es de usuario o de Claude (el "type" de la línea va al final en las de Claude). Solo se lee entera
|
|
14
|
+
* la línea de Claude; las de usuario con imágenes miden cientos de KB y no hace falta leerlas.
|
|
15
|
+
*/
|
|
16
|
+
function feed(st, head, full) {
|
|
17
|
+
if (!head.startsWith('{"parentUuid"')) return; // otras líneas: títulos, adjuntos, copias de peticiones…
|
|
18
|
+
const m = /"message":\{[^{}]{0,240}?"role":"(user|assistant)"/.exec(head);
|
|
19
|
+
if (!m) return;
|
|
20
|
+
if (m[1] === 'user') { if (!head.includes('"isMeta":true') && !head.includes('"isSidechain":true')) st.users++; return; }
|
|
21
|
+
let j; try { j = JSON.parse(full()); } catch { return; }
|
|
22
|
+
const msg = j && j.message; if (!msg) return;
|
|
23
|
+
if (typeof msg.model === 'string' && msg.model && !msg.model.startsWith('<')) st.model = msg.model; // «<synthetic>» no es un modelo
|
|
24
|
+
const u = msg.usage || {};
|
|
25
|
+
const cur = { i: num(u.input_tokens), o: num(u.output_tokens), cc: num(u.cache_creation_input_tokens), cr: num(u.cache_read_input_tokens) };
|
|
26
|
+
// Claude Code escribe un mensaje en varias líneas (una por bloque) repitiendo el uso: cada mensaje cuenta una vez, con el mayor valor visto
|
|
27
|
+
if (msg.id) {
|
|
28
|
+
const prev = st.asst.get(msg.id);
|
|
29
|
+
st.asst.set(msg.id, prev ? { i: Math.max(prev.i, cur.i), o: Math.max(prev.o, cur.o), cc: Math.max(prev.cc, cur.cc), cr: Math.max(prev.cr, cur.cr) } : cur);
|
|
30
|
+
} else { st.anon++; st.anonTok += cur.i + cur.o + cur.cc + cur.cr; }
|
|
31
|
+
if (Array.isArray(msg.content)) for (const b of msg.content) if (b && b.type === 'tool_use') { if (b.id) st.tools.add(b.id); else st.anonTools++; }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Lee lo que se haya añadido al archivo desde la última vez. */
|
|
35
|
+
async function update(st, file) {
|
|
36
|
+
const fh = await fs.promises.open(file, 'r');
|
|
37
|
+
try {
|
|
38
|
+
const { size } = await fh.stat();
|
|
39
|
+
if (size < st.pos) Object.assign(st, newState()); // el archivo se reescribió más corto: se empieza de nuevo
|
|
40
|
+
const CHUNK = 2 * 1024 * 1024;
|
|
41
|
+
while (st.pos < size) {
|
|
42
|
+
const buf = Buffer.alloc(Math.min(CHUNK, size - st.pos));
|
|
43
|
+
const { bytesRead } = await fh.read(buf, 0, buf.length, st.pos);
|
|
44
|
+
if (!bytesRead) break;
|
|
45
|
+
st.pos += bytesRead;
|
|
46
|
+
const data = st.carry.length ? Buffer.concat([st.carry, buf.subarray(0, bytesRead)]) : buf.subarray(0, bytesRead);
|
|
47
|
+
let start = 0, nl;
|
|
48
|
+
while ((nl = data.indexOf(10, start)) >= 0) {
|
|
49
|
+
const s = start, e = nl;
|
|
50
|
+
feed(st, data.toString('utf8', s, Math.min(e, s + 700)), () => data.toString('utf8', s, e));
|
|
51
|
+
start = nl + 1;
|
|
52
|
+
}
|
|
53
|
+
st.carry = data.subarray(start); // la última línea, si aún no está completa
|
|
54
|
+
await new Promise((r) => setImmediate(r));
|
|
55
|
+
}
|
|
56
|
+
} finally { await fh.close(); }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Resumen: { msgs, tok, tools, model }. tok suma entrada, salida y caché de cada mensaje de Claude. */
|
|
60
|
+
function summary(st) {
|
|
61
|
+
let tok = st.anonTok;
|
|
62
|
+
for (const u of st.asst.values()) tok += u.i + u.o + u.cc + u.cr;
|
|
63
|
+
return { msgs: st.users + st.asst.size + st.anon, tok, tools: st.tools.size + st.anonTools, model: st.model };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 1234 → «1.2K», 206900000 → «206.9M». */
|
|
67
|
+
function fmtNum(n) {
|
|
68
|
+
if (n < 1000) return String(n);
|
|
69
|
+
for (const [div, s] of [[1e9, 'B'], [1e6, 'M'], [1e3, 'K']]) if (n >= div) return (n / div).toFixed(1).replace(/\.0$/, '') + s;
|
|
70
|
+
return String(n);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** «claude-opus-4-5-20251101» → «opus». */
|
|
74
|
+
function modelShort(model) {
|
|
75
|
+
const m = /(opus|sonnet|haiku|fable)/i.exec(model || '');
|
|
76
|
+
return m ? m[1].toLowerCase() : String(model || '').replace(/^claude-/, '').replace(/-\d{8}$/, '').slice(0, 14);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = { newState, update, summary, feed, fmtNum, modelShort };
|
package/package.json
CHANGED