@dotrino/terminal-agent 0.45.0 → 0.46.1

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 CHANGED
@@ -53,6 +53,7 @@ dotrino-terminal vscode [--name <n>] # la terminal embebida de VS Code abre
53
53
  dotrino-terminal claude # Claude Code mantiene la tarjeta de su consola: skill + hooks en ~/.claude (--off lo deshace, --status lo dice)
54
54
  dotrino-terminal desktop update [--check] # actualiza la app de escritorio: baja, verifica la firma e instala
55
55
  dotrino-terminal agents [--json] # con qué versión corre el agente de cada perfil
56
+ dotrino-terminal network [--name <n>] # el uso de red del agente: por dónde va cada conexión (directo, TURN o el proxio) y cuánto pasó
56
57
  dotrino-terminal restart [--name <n>] # para el agente para que arranque con la versión instalada (cierra sus consolas; --stale: solo los atrasados)
57
58
  dotrino-terminal service install|uninstall|status [--name <n>] # el agente como servicio del usuario
58
59
  ```
package/bin/terminal.js CHANGED
@@ -20,6 +20,7 @@
20
20
  * dotrino-terminal updates [--json] [--desktop <versión>]
21
21
  * qué versiones nuevas hay (del cliente y de la app)
22
22
  * dotrino-terminal agents [--json] qué agente corre en cada perfil y con qué versión
23
+ * dotrino-terminal network [--name <n>] [--json] el uso de red del agente: por dónde va cada conexión
23
24
  * dotrino-terminal restart [--name <n>] [--stale] [--yes]
24
25
  * para el agente (cierra sus consolas) para que arranque
25
26
  * con la versión instalada
@@ -97,6 +98,8 @@ if (args.includes('-h') || args.includes('--help')) {
97
98
  (--desktop <versión> es la app que tienes; no instala nada)
98
99
  dotrino-terminal agents [--json] qué agente corre en cada perfil, con qué versión y si va
99
100
  por detrás de la instalada
101
+ dotrino-terminal network [--name <n>] el uso de red del agente: por dónde va cada conexión con
102
+ tus otros aparatos (directo, TURN o el proxy) y cuánto pasó
100
103
  dotrino-terminal restart [--name <n>] para el agente para que arranque con la versión instalada
101
104
  (cierra TODAS sus consolas; --stale: solo los que van por
102
105
  detrás, en todos los perfiles; --yes no pregunta)
@@ -145,6 +148,8 @@ Cerrar la ventana no cierra la consola: sigue abierta y se retoma después.`, `u
145
148
  the app (--desktop <version> is the app you have; installs nothing)
146
149
  dotrino-terminal agents [--json] which agent runs in each profile, its version and whether
147
150
  it is behind the installed one
151
+ dotrino-terminal network [--name <n>] the agent's network use: which path each connection with
152
+ your other devices takes (direct, TURN or the proxy) and how much
148
153
  dotrino-terminal restart [--name <n>] stop the agent so it starts with the installed version
149
154
  (closes ALL its consoles; --stale: only the ones behind,
150
155
  in every profile; --yes does not ask)
@@ -464,6 +469,31 @@ async function restart () {
464
469
  }
465
470
  }
466
471
 
472
+ /**
473
+ * `dotrino-terminal network`: el uso de red del agente de este perfil. Por dónde va cada conexión
474
+ * con tus otros aparatos (directo, TURN o el proxio) y cuánto pasó por cada camino.
475
+ */
476
+ async function network () {
477
+ const asked = opt('--name')
478
+ if (asked !== undefined && !isValidName(asked)) die(t(`nombre de perfil no válido: ${asked}`, `invalid profile name: ${asked}`))
479
+ const { dir } = resolveInstance(LABEL, asked)
480
+ let conn
481
+ try { conn = await connectLocal(dir) } catch (e) {
482
+ if (e.code !== 'ENOAGENT') throw e
483
+ console.log(t('Este perfil no tiene un agente corriendo: no hay conexiones.', 'This profile has no agent running: there are no connections.'))
484
+ return
485
+ }
486
+ const r = await Promise.race([request(conn, { type: 'net' }, 'net'), new Promise((resolve) => setTimeout(() => resolve(null), 5000))])
487
+ conn.close()
488
+ if (!r) die(t('el agente que corre es anterior a la 0.46.0 y no da su uso de red. Reinícialo con la versión nueva: dotrino-terminal restart', 'the running agent predates 0.46.0 and does not report its network use. Restart it with the new version: dotrino-terminal restart'))
489
+ if (r.type === 'fail') die(`${r.message} (${r.code})`)
490
+ if (args.includes('--json')) { console.log(JSON.stringify(r.transports)); return }
491
+ console.log(t('Esta ventana ↔ el agente de esta máquina: socket local (no toca la red).', 'This window ↔ this machine\'s agent: local socket (never touches the network).'))
492
+ console.log(t('El agente ↔ tus otros aparatos (route: direct = WebRTC directo, turn = WebRTC por TURN, proxy = por el proxy):\n', 'The agent ↔ your other devices (route: direct = direct WebRTC, turn = WebRTC via TURN, proxy = through the proxy):\n'))
493
+ process.stdout.write(r.report)
494
+ console.log(t('\nBytes del contenido, sin las cabeceras de la red. Acumulados desde que arrancó el agente.', '\nContent bytes, without network headers. Accumulated since the agent started.'))
495
+ }
496
+
467
497
  /** El agente como servicio del usuario (systemd en Linux, launchd en macOS). */
468
498
  async function service () {
469
499
  const action = args[1]
@@ -887,6 +917,35 @@ function interactive (conn, first, dir) {
887
917
  let clean = false
888
918
  let switching = false // se pidió pasar a otra consola y aún no contestó
889
919
  let recovering = false // falló el cambio: se está repintando la que había
920
+ let wasEmpty = false // el cambio en curso se pidió desde una ventana sin consola
921
+ const showEmpty = () => {
922
+ empty = true
923
+ ready = false
924
+ shellTitle = ''; subject = ''; remote = new Set(); showTitle()
925
+ out.write(`\x1bc\x1b[2m${t('No hay consolas abiertas. Ctrl+] y luego n abre una.', 'No open consoles. Ctrl+] then n opens one.')}\x1b[0m\r\n`)
926
+ }
927
+ // LA CONSOLA DE ESTA VENTANA YA NO EXISTE. Pasa a una que YA existe: primero una que no mire
928
+ // nadie; si todas se miran, la primera igual. NUNCA crea una nueva (para no llenarse de
929
+ // consolas que nadie mira): si la máquina se quedó sin ninguna, la ventana se queda SIN
930
+ // consola (`empty`) y lo dice.
931
+ const lost = () => {
932
+ const closed = consoleId
933
+ consoleId = null
934
+ ready = false // lo que se teclee mientras tanto espera a la consola que venga
935
+ switching = false; recovering = false
936
+ request(conn, { type: 'list' }, 'consoles').then((r) => {
937
+ if (r.type !== 'consoles') return // un `fail`: ya lo atendió el manejador
938
+ const rest = r.list.filter((c) => c.id !== closed)
939
+ // Desatendida EN ESTA MÁQUINA: que la mire otro aparato no la hace atendida aquí.
940
+ const other = rest.find((c) => !c.watchers.length) || rest.find((c) => !c.watchers.some((w) => w.origin === 'local')) || rest[0]
941
+ if (other) return switchTo({ type: 'attach', id: other.id })
942
+ // Mirando OTRA máquina que se quedó sin consolas: decir «no hay consolas» sería falso si
943
+ // en esta sí las hay (dueño, 2026-10-13). El cliente termina sin error y quien lo lanzó
944
+ // (la app) devuelve la ventana a las consolas de esta máquina.
945
+ if (opt('--machine')) return finish(0, t('Esa máquina ya no tiene consolas abiertas.', 'That machine has no open consoles left.'))
946
+ showEmpty()
947
+ })
948
+ }
890
949
  conn.on('message', (m) => {
891
950
  if (m.type === 'replay' && !clean) { clean = true; out.write('\x1b[H\x1b[2J') }
892
951
  if (m.type === 'out' || m.type === 'replay') { out.write(filter(m.data)); return }
@@ -902,37 +961,29 @@ function interactive (conn, first, dir) {
902
961
  if (m.type === 'meta') { onInfo(m.console); return }
903
962
  if (m.type === 'exit') {
904
963
  // LA CONSOLA SE CERRÓ, la cierre quien la cierre (otra pantalla, el panel, o `exit` tecleado
905
- // aquí): cerrar una consola nunca cierra la ventana (dueño, 2026-10-08). Pasa a una consola
906
- // que YA existe: primero una que no mire nadie; si todas se miran, la primera igual.
907
- // NUNCA crea una nueva (para no llenarse de consolas que nadie mira): si la máquina se quedó
908
- // sin ninguna, la ventana se queda SIN consola (`empty`) y lo dice.
909
- {
910
- const closed = consoleId
911
- consoleId = null
912
- ready = false // lo que se teclee mientras tanto espera a la consola que venga
913
- request(conn, { type: 'list' }, 'consoles').then((r) => {
914
- if (r.type !== 'consoles') return // un `fail`: ya lo atendió el manejador de abajo
915
- const rest = r.list.filter((c) => c.id !== closed)
916
- // Desatendida EN ESTA MÁQUINA: que la mire otro aparato no la hace atendida aquí.
917
- const other = rest.find((c) => !c.watchers.length) || rest.find((c) => !c.watchers.some((w) => w.origin === 'local')) || rest[0]
918
- if (other) return switchTo({ type: 'attach', id: other.id })
919
- empty = true
920
- shellTitle = ''; subject = ''; remote = new Set(); showTitle()
921
- out.write(`\x1bc\x1b[2m${t('No hay consolas abiertas. Ctrl+] y luego n abre una.', 'No open consoles. Ctrl+] then n opens one.')}\x1b[0m\r\n`)
922
- })
923
- return
924
- }
964
+ // aquí): cerrar una consola nunca cierra la ventana (dueño, 2026-10-08).
965
+ lost()
966
+ return
925
967
  }
926
968
  if (m.type === 'fail') {
969
+ // LA OTRA MÁQUINA SE REINICIÓ (alguien cerró todas sus terminales para estrenar versión):
970
+ // sus consolas ya no existen. Es lo mismo que cerrarlas una a una, así que la ventana
971
+ // sigue: pasa a una que haya, o se queda sin consola. Terminar aquí cerraba la ventana
972
+ // (y la app, si era la última) en la máquina que solo estaba mirando.
973
+ if (m.code === 'machine-restarted') { lost(); return }
927
974
  // FALLÓ UN CAMBIO DE CONSOLA (la que se pidió ya no existe: el panel de la app iba un
928
975
  // instante por detrás). El agente rechaza ANTES de soltar la actual, así que esta ventana
929
976
  // sigue en la suya: se vuelve a pintar y se sigue. Terminar aquí cerraba la ventana entera
930
- // por elegir una entrada caducada. Solo es fatal si falla al arrancar, o al repintar.
977
+ // por elegir una entrada caducada. Solo es fatal si falla al arrancar.
931
978
  if (switching && consoleId && !recovering) {
932
979
  switching = false; recovering = true
933
980
  conn.send({ type: 'attach', id: consoleId, ...size(), ...tag() })
934
981
  return
935
982
  }
983
+ // Lo mismo desde una ventana SIN consola: no había ninguna que soltar, sigue sin ella.
984
+ if (switching && wasEmpty) { switching = false; showEmpty(); return }
985
+ // Y si la que había tampoco se pudo repintar (se cerró entre medias): a otra, o sin consola.
986
+ if (recovering && m.code === 'no-console') { recovering = false; lost(); return }
936
987
  finish(1, `dotrino-terminal: ${m.message} (${m.code})`)
937
988
  }
938
989
  })
@@ -951,6 +1002,7 @@ function interactive (conn, first, dir) {
951
1002
  // Cambiar de consola SIN salir: por la misma conexión, y con la pantalla en limpio para que la
952
1003
  // repetición de la otra consola no se pinte encima. Lo tecleado mientras tanto se guarda.
953
1004
  const switchTo = (msg) => {
1005
+ wasEmpty = empty
954
1006
  empty = false
955
1007
  ready = false
956
1008
  switching = true
@@ -1034,6 +1086,7 @@ try {
1034
1086
  if (cmd === 'desktop') { await desktop(); process.exit(0) }
1035
1087
  if (cmd === 'updates') { await updates(); process.exit(0) }
1036
1088
  if (cmd === 'agents') { await agents(); process.exit(0) }
1089
+ if (cmd === 'network') { await network(); process.exit(0) }
1037
1090
  if (cmd === 'restart') { await restart(); process.exit(0) }
1038
1091
  if (cmd === 'service') { await service(); process.exit(0) }
1039
1092
  if (cmd === 'note') { await note(); process.exit(0) }
package/far.js CHANGED
@@ -262,8 +262,11 @@ export function makeFar ({ dir, loadLink, kind, discover = discoverReal, connect
262
262
  refreshedAt = 1
263
263
  }
264
264
 
265
+ /** Las máquinas que ya se conocen, sin preguntar a la red (para nombrarlas en un informe). */
266
+ const known = () => [...machines.values()].map((m) => ({ sub: m.sub, id: m.id, name: m.name }))
267
+
265
268
  return {
266
- list, via, send,
269
+ list, via, send, known,
267
270
  close: () => { closed = true; clearTimeout(idle); release() }
268
271
  }
269
272
  }
package/index.js CHANGED
@@ -38,6 +38,8 @@ import path from 'node:path'
38
38
  import { createRequire } from 'node:module'
39
39
  import { startRemoteAgent } from '@dotrino/remote-agent/agent'
40
40
  import { dataDir, loadLink, LABEL } from './link.js'
41
+ import { listTransports, netReport } from '@dotrino/proxy-client'
42
+ import { shortId } from './far.js'
41
43
  import { ConsoleHub, REPLAY_CHUNK, isTyped } from './consoles.js'
42
44
  import { listenLocal } from './local.js'
43
45
  import { makeGate } from './access.js'
@@ -257,6 +259,20 @@ export function serveSession (session, hub, { origin = 'remote', gate = null, up
257
259
  * otras máquinas hay, y una orden suelta para una de ellas.
258
260
  * Exportada para las pruebas.
259
261
  */
262
+ /**
263
+ * El uso de red de este agente: cada conexión con otro aparato, por qué camino va (directo,
264
+ * TURN o el proxio) y cuánto pasó por cada uno. El mismo informe que el modal de red del topbar.
265
+ * Una máquina de la cuenta sale con su nombre; cualquier otro aparato, con su id.
266
+ */
267
+ export async function netOf (far) {
268
+ const transports = await Promise.all(listTransports().map(async (c) => {
269
+ try { return await c.stats() } catch (e) { return { url: c.url, error: e?.message || String(e) } }
270
+ }))
271
+ const names = new Map(far.known().map((m) => [m.id, m.name ? `${m.name} ${m.id}` : m.id]))
272
+ const label = async (pubkey) => { const id = await shortId(pubkey); return names.get(id) || id }
273
+ return { transports, report: await netReport(transports, { label }) }
274
+ }
275
+
260
276
  export function serveLocal (session, hub, far, { uploadsDir = null } = {}) {
261
277
  const h = { message: [], close: [] }
262
278
  const inner = { device: null, send: (p) => session.send(p), on (ev, cb) { h[ev]?.push(cb); return this } }
@@ -265,6 +281,7 @@ export function serveLocal (session, hub, far, { uploadsDir = null } = {}) {
265
281
  session.on('message', (msg) => {
266
282
  if (!msg || typeof msg !== 'object') return
267
283
  if (mode !== 'far' && msg.type === 'machines') { far.list().then((list) => session.send({ type: 'machines', list })).catch(failed); return }
284
+ if (mode !== 'far' && msg.type === 'net') { netOf(far).then((r) => session.send({ type: 'net', ...r })).catch(failed); return }
268
285
  if (mode !== 'far' && msg.type === 'far') { far.send(msg.machine, msg.msg).catch(failed); return }
269
286
  if (!mode) {
270
287
  if (msg.type === 'via') { mode = 'far'; far.via(inner, msg.machine).catch(failed); return }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/terminal-agent",
3
- "version": "0.45.0",
3
+ "version": "0.46.1",
4
4
  "description": "Dotrino Terminal: las ventanas de esta máquina (dotrino-terminal) y su agente, que deja abrir esas mismas consolas desde los otros aparatos de tu cuenta, cifrado punto a punto.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,8 +34,8 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@dotrino/identity": "0.107.2",
37
- "@dotrino/proxy-client": "0.30.3",
38
- "@dotrino/remote-agent": "0.18.2",
37
+ "@dotrino/proxy-client": "0.31.0",
38
+ "@dotrino/remote-agent": "0.18.3",
39
39
  "@dotrino/update": "0.9.0",
40
40
  "@dotrino/vault": "0.82.1",
41
41
  "@xterm/addon-serialize": "0.13.0",