@dotrino/terminal-agent 0.44.0 → 0.46.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 +3 -0
- package/bin/terminal.js +133 -0
- package/far.js +4 -1
- package/index.js +20 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -52,6 +52,9 @@ dotrino-terminal rename <perfil> [nuevo] # renombrarlo (mueve su carpeta y para
|
|
|
52
52
|
dotrino-terminal vscode [--name <n>] # la terminal embebida de VS Code abre consolas de aquí (--off lo deshace)
|
|
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
|
+
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ó
|
|
57
|
+
dotrino-terminal restart [--name <n>] # para el agente para que arranque con la versión instalada (cierra sus consolas; --stale: solo los atrasados)
|
|
55
58
|
dotrino-terminal service install|uninstall|status [--name <n>] # el agente como servicio del usuario
|
|
56
59
|
```
|
|
57
60
|
|
package/bin/terminal.js
CHANGED
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
* dotrino-terminal desktop update [--check] actualiza la app de escritorio (la ventana)
|
|
20
20
|
* dotrino-terminal updates [--json] [--desktop <versión>]
|
|
21
21
|
* qué versiones nuevas hay (del cliente y de la app)
|
|
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
|
|
24
|
+
* dotrino-terminal restart [--name <n>] [--stale] [--yes]
|
|
25
|
+
* para el agente (cierra sus consolas) para que arranque
|
|
26
|
+
* con la versión instalada
|
|
22
27
|
* dotrino-terminal service install|uninstall|status [--name <n>]
|
|
23
28
|
* el agente como servicio: arranca solo con la máquina
|
|
24
29
|
*
|
|
@@ -91,6 +96,13 @@ if (args.includes('-h') || args.includes('--help')) {
|
|
|
91
96
|
(--check solo mira si hay una)
|
|
92
97
|
dotrino-terminal updates [--json] dice si hay versión nueva de dotrino-terminal y de la app
|
|
93
98
|
(--desktop <versión> es la app que tienes; no instala nada)
|
|
99
|
+
dotrino-terminal agents [--json] qué agente corre en cada perfil, con qué versión y si va
|
|
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ó
|
|
103
|
+
dotrino-terminal restart [--name <n>] para el agente para que arranque con la versión instalada
|
|
104
|
+
(cierra TODAS sus consolas; --stale: solo los que van por
|
|
105
|
+
detrás, en todos los perfiles; --yes no pregunta)
|
|
94
106
|
dotrino-terminal service install [--name <n>] deja el agente como servicio de tu usuario: arranca
|
|
95
107
|
solo al encender la máquina, sin abrir ninguna ventana
|
|
96
108
|
dotrino-terminal service uninstall [--name <n>] lo quita (para el agente: cierra sus consolas)
|
|
@@ -134,6 +146,13 @@ Cerrar la ventana no cierra la consola: sigue abierta y se retoma después.`, `u
|
|
|
134
146
|
(--check only looks for one)
|
|
135
147
|
dotrino-terminal updates [--json] say whether there is a new version of dotrino-terminal and of
|
|
136
148
|
the app (--desktop <version> is the app you have; installs nothing)
|
|
149
|
+
dotrino-terminal agents [--json] which agent runs in each profile, its version and whether
|
|
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
|
|
153
|
+
dotrino-terminal restart [--name <n>] stop the agent so it starts with the installed version
|
|
154
|
+
(closes ALL its consoles; --stale: only the ones behind,
|
|
155
|
+
in every profile; --yes does not ask)
|
|
137
156
|
dotrino-terminal service install [--name <n>] run the agent as a service of your user: it starts
|
|
138
157
|
by itself when the machine boots, with no window open
|
|
139
158
|
dotrino-terminal service uninstall [--name <n>] remove it (stops the agent: closes its consoles)
|
|
@@ -187,6 +206,9 @@ async function agent (dir) {
|
|
|
187
206
|
// Un agente vivo sin socket es uno anterior a las ventanas (< 0.6.0): no se levanta otro
|
|
188
207
|
// encima (tendrían la misma llave), se dice.
|
|
189
208
|
const pid = Number((() => { try { return fs.readFileSync(path.join(dir, 'agent.pid'), 'utf8') } catch (_) { return '' } })())
|
|
209
|
+
// Un agente que se está yendo (`dotrino-terminal restart`) cierra su socket un instante antes
|
|
210
|
+
// de terminar: se le da ese instante antes de decir que es uno viejo.
|
|
211
|
+
for (const t0 = Date.now(); pid && alive(pid) && Date.now() - t0 < 3000;) await new Promise((r) => setTimeout(r, 100))
|
|
190
212
|
if (pid && alive(pid)) {
|
|
191
213
|
throw new Error(t(`hay un agente corriendo (pid ${pid}) que no acepta ventanas: es anterior a la 0.6.0. Reinícialo con la versión nueva.`,
|
|
192
214
|
`an agent is running (pid ${pid}) that does not accept windows: it predates 0.6.0. Restart it with the new version.`))
|
|
@@ -364,6 +386,114 @@ async function openConsoles (dir) {
|
|
|
364
386
|
return r.list.length
|
|
365
387
|
}
|
|
366
388
|
|
|
389
|
+
/** Lo que se espera a que un agente diga su versión: uno anterior a la 0.45.0 no contesta. */
|
|
390
|
+
const VERSION_WAIT_MS = 1500
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Los agentes de esta máquina, uno por perfil: si corre, con qué versión y cuántas consolas.
|
|
394
|
+
* `stale`: corre con una versión que no es la instalada (el paquete se actualizó y él sigue con
|
|
395
|
+
* la anterior hasta que se reinicie). `version: null`: no la dijo, así que es anterior a la 0.45.0.
|
|
396
|
+
*/
|
|
397
|
+
async function agentStates () {
|
|
398
|
+
const out = []
|
|
399
|
+
for (const p of await listProfiles()) {
|
|
400
|
+
let conn
|
|
401
|
+
try { conn = await connectLocal(p.dir) } catch (e) {
|
|
402
|
+
if (e.code !== 'ENOAGENT') throw e
|
|
403
|
+
out.push({ name: p.name, running: false, version: null, consoles: 0, stale: false })
|
|
404
|
+
continue
|
|
405
|
+
}
|
|
406
|
+
const v = await Promise.race([request(conn, { type: 'version' }, 'version'), new Promise((resolve) => setTimeout(() => resolve(null), VERSION_WAIT_MS))])
|
|
407
|
+
const l = await request(conn, { type: 'list' }, 'consoles')
|
|
408
|
+
conn.close()
|
|
409
|
+
if (l.type === 'fail') throw new Error(`${l.message} (${l.code})`)
|
|
410
|
+
const version = v && v.type === 'version' ? v.version : null
|
|
411
|
+
out.push({ name: p.name, running: true, version, consoles: l.list.length, stale: version !== VERSION })
|
|
412
|
+
}
|
|
413
|
+
return out
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** `dotrino-terminal agents`: qué agente corre en cada perfil y si va por detrás de lo instalado. */
|
|
417
|
+
async function agents () {
|
|
418
|
+
const list = await agentStates()
|
|
419
|
+
if (args.includes('--json')) { console.log(JSON.stringify({ installed: VERSION, agents: list })); return }
|
|
420
|
+
for (const a of list) {
|
|
421
|
+
const what = !a.running ? t('parado', 'stopped')
|
|
422
|
+
: `${a.version || t('anterior a la 0.45.0', 'older than 0.45.0')} · ${a.consoles} ${t('consola(s)', 'console(s)')}${a.stale ? t(` · instalada la ${VERSION}: reinícialo con «dotrino-terminal restart --name ${a.name}»`, ` · ${VERSION} is installed: restart it with "dotrino-terminal restart --name ${a.name}"`) : ''}`
|
|
423
|
+
console.log(` ${a.name.padEnd(16)} ${what}`)
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* `dotrino-terminal restart`: para el agente para que arranque con la versión instalada. Cierra
|
|
429
|
+
* TODAS sus consolas (las de las ventanas, las de un editor y las que miran otros aparatos), así
|
|
430
|
+
* que pregunta antes. `--stale`: solo los que van por detrás de lo instalado, en todos los perfiles.
|
|
431
|
+
*/
|
|
432
|
+
async function restart () {
|
|
433
|
+
const stale = args.includes('--stale')
|
|
434
|
+
const asked = opt('--name')
|
|
435
|
+
if (asked !== undefined && !isValidName(asked)) die(t(`nombre de perfil no válido: ${asked}`, `invalid profile name: ${asked}`))
|
|
436
|
+
const only = stale && asked === undefined ? null : path.basename(resolveInstance(LABEL, asked).dir)
|
|
437
|
+
const targets = (await agentStates()).filter((a) => a.running && (only === null || a.name === only) && (!stale || a.stale))
|
|
438
|
+
if (!targets.length) { console.log(stale ? t('Ningún agente va por detrás de lo instalado.', 'No agent is behind what is installed.') : t('Ese perfil no tiene un agente corriendo.', 'That profile has no agent running.')); return }
|
|
439
|
+
const dirOf = (name) => resolveInstance(LABEL, name).dir
|
|
440
|
+
// ¿Corre esta orden DENTRO de una consola de uno de esos agentes? Pararlo la cerraría a mitad
|
|
441
|
+
// de camino: el trabajo lo hace un proceso aparte.
|
|
442
|
+
const inside = targets.some((a) => !!process.env.DOTRINO_TERMINAL_PROFILE_DIR && samePath(process.env.DOTRINO_TERMINAL_PROFILE_DIR, dirOf(a.name)))
|
|
443
|
+
const open = targets.reduce((n, a) => n + a.consoles, 0)
|
|
444
|
+
if (open && !args.includes('--yes')) {
|
|
445
|
+
const ok = await ask(t(`Se van a cerrar ${open} consola(s)${inside ? ', esta incluida' : ''}. ¿Seguir? [s/N] `, `${open} console(s) will be closed${inside ? ', this one included' : ''}. Continue? [y/N] `))
|
|
446
|
+
if (!/^[sy]/i.test(ok)) die(t('No se reinició nada.', 'Nothing was restarted.'))
|
|
447
|
+
}
|
|
448
|
+
if (inside && !args.includes('--detached-step')) {
|
|
449
|
+
const self = fileURLToPath(import.meta.url)
|
|
450
|
+
spawn(process.execPath, [self, ...args.filter((a) => a !== '--yes'), '--yes', '--detached-step'], { detached: true, stdio: 'ignore', env: process.env }).unref()
|
|
451
|
+
console.log(t('Reiniciando. Esta consola se va a cerrar.', 'Restarting. This console is about to close.'))
|
|
452
|
+
return
|
|
453
|
+
}
|
|
454
|
+
const { serviceStatus } = await import('../service.js')
|
|
455
|
+
for (const a of targets) {
|
|
456
|
+
const dir = dirOf(a.name)
|
|
457
|
+
const pid = Number((() => { try { return fs.readFileSync(path.join(dir, 'agent.pid'), 'utf8') } catch (_) { return '' } })())
|
|
458
|
+
if (!pid || !alive(pid)) die(t(`el agente de «${a.name}» contesta pero no dejó su pid: páralo a mano.`, `the agent of "${a.name}" answers but left no pid: stop it by hand.`))
|
|
459
|
+
process.kill(pid, 'SIGTERM')
|
|
460
|
+
for (const t0 = Date.now(); alive(pid);) {
|
|
461
|
+
if (Date.now() - t0 > 5000) die(t(`el agente de «${a.name}» (pid ${pid}) no se detuvo: páralo a mano.`, `the agent of "${a.name}" (pid ${pid}) did not stop: stop it by hand.`))
|
|
462
|
+
await new Promise((r) => setTimeout(r, 100))
|
|
463
|
+
}
|
|
464
|
+
let service = false
|
|
465
|
+
try { service = serviceStatus({ name: a.name }).installed } catch (e) { if (e.code !== 'no-user-systemd' && e.code !== 'unsupported-platform') throw e }
|
|
466
|
+
console.log(service
|
|
467
|
+
? t(`«${a.name}»: agente detenido (${a.consoles} consola(s) cerradas). Su servicio lo vuelve a levantar con la ${VERSION}.`, `"${a.name}": agent stopped (${a.consoles} console(s) closed). Its service starts it again with ${VERSION}.`)
|
|
468
|
+
: t(`«${a.name}»: agente detenido (${a.consoles} consola(s) cerradas). Arranca con la ${VERSION} al abrir una ventana.`, `"${a.name}": agent stopped (${a.consoles} console(s) closed). It starts with ${VERSION} when you open a window.`))
|
|
469
|
+
}
|
|
470
|
+
}
|
|
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
|
+
|
|
367
497
|
/** El agente como servicio del usuario (systemd en Linux, launchd en macOS). */
|
|
368
498
|
async function service () {
|
|
369
499
|
const action = args[1]
|
|
@@ -933,6 +1063,9 @@ try {
|
|
|
933
1063
|
if (cmd === 'claude') { await claude(); process.exit(0) }
|
|
934
1064
|
if (cmd === 'desktop') { await desktop(); process.exit(0) }
|
|
935
1065
|
if (cmd === 'updates') { await updates(); process.exit(0) }
|
|
1066
|
+
if (cmd === 'agents') { await agents(); process.exit(0) }
|
|
1067
|
+
if (cmd === 'network') { await network(); process.exit(0) }
|
|
1068
|
+
if (cmd === 'restart') { await restart(); process.exit(0) }
|
|
936
1069
|
if (cmd === 'service') { await service(); process.exit(0) }
|
|
937
1070
|
if (cmd === 'note') { await note(); process.exit(0) }
|
|
938
1071
|
const dir = opt('--dir') || dataDir(opt('--name'))
|
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'
|
|
@@ -45,6 +47,7 @@ import { makeFar } from './far.js'
|
|
|
45
47
|
import { makeUploads } from './uploads.js'
|
|
46
48
|
|
|
47
49
|
const require = createRequire(import.meta.url)
|
|
50
|
+
const { version: VERSION } = require('./package.json')
|
|
48
51
|
|
|
49
52
|
/** Cuánto se espera al canal directo antes de mandar el historial por el proxio. */
|
|
50
53
|
export const HISTORY_WAIT_MS = 8000
|
|
@@ -186,6 +189,8 @@ export function serveSession (session, hub, { origin = 'remote', gate = null, up
|
|
|
186
189
|
return
|
|
187
190
|
}
|
|
188
191
|
if (!mayPass()) return
|
|
192
|
+
// Qué versión corre: tras actualizar el paquete, el agente en marcha sigue con la anterior.
|
|
193
|
+
if (msg.type === 'version') { session.send({ type: 'version', version: VERSION }); return }
|
|
189
194
|
if (msg.type === 'list') { session.send({ type: 'consoles', list: hub.list() }); return }
|
|
190
195
|
if (msg.type === 'open') {
|
|
191
196
|
takeSize(msg)
|
|
@@ -254,6 +259,20 @@ export function serveSession (session, hub, { origin = 'remote', gate = null, up
|
|
|
254
259
|
* otras máquinas hay, y una orden suelta para una de ellas.
|
|
255
260
|
* Exportada para las pruebas.
|
|
256
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
|
+
|
|
257
276
|
export function serveLocal (session, hub, far, { uploadsDir = null } = {}) {
|
|
258
277
|
const h = { message: [], close: [] }
|
|
259
278
|
const inner = { device: null, send: (p) => session.send(p), on (ev, cb) { h[ev]?.push(cb); return this } }
|
|
@@ -262,6 +281,7 @@ export function serveLocal (session, hub, far, { uploadsDir = null } = {}) {
|
|
|
262
281
|
session.on('message', (msg) => {
|
|
263
282
|
if (!msg || typeof msg !== 'object') return
|
|
264
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 }
|
|
265
285
|
if (mode !== 'far' && msg.type === 'far') { far.send(msg.machine, msg.msg).catch(failed); return }
|
|
266
286
|
if (!mode) {
|
|
267
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.
|
|
3
|
+
"version": "0.46.0",
|
|
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.
|
|
38
|
-
"@dotrino/remote-agent": "0.18.
|
|
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",
|