@dotrino/terminal-agent 0.44.0 → 0.45.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 +2 -0
- package/bin/terminal.js +102 -0
- package/index.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,8 @@ 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 restart [--name <n>] # para el agente para que arranque con la versión instalada (cierra sus consolas; --stale: solo los atrasados)
|
|
55
57
|
dotrino-terminal service install|uninstall|status [--name <n>] # el agente como servicio del usuario
|
|
56
58
|
```
|
|
57
59
|
|
package/bin/terminal.js
CHANGED
|
@@ -19,6 +19,10 @@
|
|
|
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 restart [--name <n>] [--stale] [--yes]
|
|
24
|
+
* para el agente (cierra sus consolas) para que arranque
|
|
25
|
+
* con la versión instalada
|
|
22
26
|
* dotrino-terminal service install|uninstall|status [--name <n>]
|
|
23
27
|
* el agente como servicio: arranca solo con la máquina
|
|
24
28
|
*
|
|
@@ -91,6 +95,11 @@ if (args.includes('-h') || args.includes('--help')) {
|
|
|
91
95
|
(--check solo mira si hay una)
|
|
92
96
|
dotrino-terminal updates [--json] dice si hay versión nueva de dotrino-terminal y de la app
|
|
93
97
|
(--desktop <versión> es la app que tienes; no instala nada)
|
|
98
|
+
dotrino-terminal agents [--json] qué agente corre en cada perfil, con qué versión y si va
|
|
99
|
+
por detrás de la instalada
|
|
100
|
+
dotrino-terminal restart [--name <n>] para el agente para que arranque con la versión instalada
|
|
101
|
+
(cierra TODAS sus consolas; --stale: solo los que van por
|
|
102
|
+
detrás, en todos los perfiles; --yes no pregunta)
|
|
94
103
|
dotrino-terminal service install [--name <n>] deja el agente como servicio de tu usuario: arranca
|
|
95
104
|
solo al encender la máquina, sin abrir ninguna ventana
|
|
96
105
|
dotrino-terminal service uninstall [--name <n>] lo quita (para el agente: cierra sus consolas)
|
|
@@ -134,6 +143,11 @@ Cerrar la ventana no cierra la consola: sigue abierta y se retoma después.`, `u
|
|
|
134
143
|
(--check only looks for one)
|
|
135
144
|
dotrino-terminal updates [--json] say whether there is a new version of dotrino-terminal and of
|
|
136
145
|
the app (--desktop <version> is the app you have; installs nothing)
|
|
146
|
+
dotrino-terminal agents [--json] which agent runs in each profile, its version and whether
|
|
147
|
+
it is behind the installed one
|
|
148
|
+
dotrino-terminal restart [--name <n>] stop the agent so it starts with the installed version
|
|
149
|
+
(closes ALL its consoles; --stale: only the ones behind,
|
|
150
|
+
in every profile; --yes does not ask)
|
|
137
151
|
dotrino-terminal service install [--name <n>] run the agent as a service of your user: it starts
|
|
138
152
|
by itself when the machine boots, with no window open
|
|
139
153
|
dotrino-terminal service uninstall [--name <n>] remove it (stops the agent: closes its consoles)
|
|
@@ -187,6 +201,9 @@ async function agent (dir) {
|
|
|
187
201
|
// Un agente vivo sin socket es uno anterior a las ventanas (< 0.6.0): no se levanta otro
|
|
188
202
|
// encima (tendrían la misma llave), se dice.
|
|
189
203
|
const pid = Number((() => { try { return fs.readFileSync(path.join(dir, 'agent.pid'), 'utf8') } catch (_) { return '' } })())
|
|
204
|
+
// Un agente que se está yendo (`dotrino-terminal restart`) cierra su socket un instante antes
|
|
205
|
+
// de terminar: se le da ese instante antes de decir que es uno viejo.
|
|
206
|
+
for (const t0 = Date.now(); pid && alive(pid) && Date.now() - t0 < 3000;) await new Promise((r) => setTimeout(r, 100))
|
|
190
207
|
if (pid && alive(pid)) {
|
|
191
208
|
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
209
|
`an agent is running (pid ${pid}) that does not accept windows: it predates 0.6.0. Restart it with the new version.`))
|
|
@@ -364,6 +381,89 @@ async function openConsoles (dir) {
|
|
|
364
381
|
return r.list.length
|
|
365
382
|
}
|
|
366
383
|
|
|
384
|
+
/** Lo que se espera a que un agente diga su versión: uno anterior a la 0.45.0 no contesta. */
|
|
385
|
+
const VERSION_WAIT_MS = 1500
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Los agentes de esta máquina, uno por perfil: si corre, con qué versión y cuántas consolas.
|
|
389
|
+
* `stale`: corre con una versión que no es la instalada (el paquete se actualizó y él sigue con
|
|
390
|
+
* la anterior hasta que se reinicie). `version: null`: no la dijo, así que es anterior a la 0.45.0.
|
|
391
|
+
*/
|
|
392
|
+
async function agentStates () {
|
|
393
|
+
const out = []
|
|
394
|
+
for (const p of await listProfiles()) {
|
|
395
|
+
let conn
|
|
396
|
+
try { conn = await connectLocal(p.dir) } catch (e) {
|
|
397
|
+
if (e.code !== 'ENOAGENT') throw e
|
|
398
|
+
out.push({ name: p.name, running: false, version: null, consoles: 0, stale: false })
|
|
399
|
+
continue
|
|
400
|
+
}
|
|
401
|
+
const v = await Promise.race([request(conn, { type: 'version' }, 'version'), new Promise((resolve) => setTimeout(() => resolve(null), VERSION_WAIT_MS))])
|
|
402
|
+
const l = await request(conn, { type: 'list' }, 'consoles')
|
|
403
|
+
conn.close()
|
|
404
|
+
if (l.type === 'fail') throw new Error(`${l.message} (${l.code})`)
|
|
405
|
+
const version = v && v.type === 'version' ? v.version : null
|
|
406
|
+
out.push({ name: p.name, running: true, version, consoles: l.list.length, stale: version !== VERSION })
|
|
407
|
+
}
|
|
408
|
+
return out
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** `dotrino-terminal agents`: qué agente corre en cada perfil y si va por detrás de lo instalado. */
|
|
412
|
+
async function agents () {
|
|
413
|
+
const list = await agentStates()
|
|
414
|
+
if (args.includes('--json')) { console.log(JSON.stringify({ installed: VERSION, agents: list })); return }
|
|
415
|
+
for (const a of list) {
|
|
416
|
+
const what = !a.running ? t('parado', 'stopped')
|
|
417
|
+
: `${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}"`) : ''}`
|
|
418
|
+
console.log(` ${a.name.padEnd(16)} ${what}`)
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* `dotrino-terminal restart`: para el agente para que arranque con la versión instalada. Cierra
|
|
424
|
+
* TODAS sus consolas (las de las ventanas, las de un editor y las que miran otros aparatos), así
|
|
425
|
+
* que pregunta antes. `--stale`: solo los que van por detrás de lo instalado, en todos los perfiles.
|
|
426
|
+
*/
|
|
427
|
+
async function restart () {
|
|
428
|
+
const stale = args.includes('--stale')
|
|
429
|
+
const asked = opt('--name')
|
|
430
|
+
if (asked !== undefined && !isValidName(asked)) die(t(`nombre de perfil no válido: ${asked}`, `invalid profile name: ${asked}`))
|
|
431
|
+
const only = stale && asked === undefined ? null : path.basename(resolveInstance(LABEL, asked).dir)
|
|
432
|
+
const targets = (await agentStates()).filter((a) => a.running && (only === null || a.name === only) && (!stale || a.stale))
|
|
433
|
+
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 }
|
|
434
|
+
const dirOf = (name) => resolveInstance(LABEL, name).dir
|
|
435
|
+
// ¿Corre esta orden DENTRO de una consola de uno de esos agentes? Pararlo la cerraría a mitad
|
|
436
|
+
// de camino: el trabajo lo hace un proceso aparte.
|
|
437
|
+
const inside = targets.some((a) => !!process.env.DOTRINO_TERMINAL_PROFILE_DIR && samePath(process.env.DOTRINO_TERMINAL_PROFILE_DIR, dirOf(a.name)))
|
|
438
|
+
const open = targets.reduce((n, a) => n + a.consoles, 0)
|
|
439
|
+
if (open && !args.includes('--yes')) {
|
|
440
|
+
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] `))
|
|
441
|
+
if (!/^[sy]/i.test(ok)) die(t('No se reinició nada.', 'Nothing was restarted.'))
|
|
442
|
+
}
|
|
443
|
+
if (inside && !args.includes('--detached-step')) {
|
|
444
|
+
const self = fileURLToPath(import.meta.url)
|
|
445
|
+
spawn(process.execPath, [self, ...args.filter((a) => a !== '--yes'), '--yes', '--detached-step'], { detached: true, stdio: 'ignore', env: process.env }).unref()
|
|
446
|
+
console.log(t('Reiniciando. Esta consola se va a cerrar.', 'Restarting. This console is about to close.'))
|
|
447
|
+
return
|
|
448
|
+
}
|
|
449
|
+
const { serviceStatus } = await import('../service.js')
|
|
450
|
+
for (const a of targets) {
|
|
451
|
+
const dir = dirOf(a.name)
|
|
452
|
+
const pid = Number((() => { try { return fs.readFileSync(path.join(dir, 'agent.pid'), 'utf8') } catch (_) { return '' } })())
|
|
453
|
+
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.`))
|
|
454
|
+
process.kill(pid, 'SIGTERM')
|
|
455
|
+
for (const t0 = Date.now(); alive(pid);) {
|
|
456
|
+
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.`))
|
|
457
|
+
await new Promise((r) => setTimeout(r, 100))
|
|
458
|
+
}
|
|
459
|
+
let service = false
|
|
460
|
+
try { service = serviceStatus({ name: a.name }).installed } catch (e) { if (e.code !== 'no-user-systemd' && e.code !== 'unsupported-platform') throw e }
|
|
461
|
+
console.log(service
|
|
462
|
+
? 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}.`)
|
|
463
|
+
: 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.`))
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
367
467
|
/** El agente como servicio del usuario (systemd en Linux, launchd en macOS). */
|
|
368
468
|
async function service () {
|
|
369
469
|
const action = args[1]
|
|
@@ -933,6 +1033,8 @@ try {
|
|
|
933
1033
|
if (cmd === 'claude') { await claude(); process.exit(0) }
|
|
934
1034
|
if (cmd === 'desktop') { await desktop(); process.exit(0) }
|
|
935
1035
|
if (cmd === 'updates') { await updates(); process.exit(0) }
|
|
1036
|
+
if (cmd === 'agents') { await agents(); process.exit(0) }
|
|
1037
|
+
if (cmd === 'restart') { await restart(); process.exit(0) }
|
|
936
1038
|
if (cmd === 'service') { await service(); process.exit(0) }
|
|
937
1039
|
if (cmd === 'note') { await note(); process.exit(0) }
|
|
938
1040
|
const dir = opt('--dir') || dataDir(opt('--name'))
|
package/index.js
CHANGED
|
@@ -45,6 +45,7 @@ import { makeFar } from './far.js'
|
|
|
45
45
|
import { makeUploads } from './uploads.js'
|
|
46
46
|
|
|
47
47
|
const require = createRequire(import.meta.url)
|
|
48
|
+
const { version: VERSION } = require('./package.json')
|
|
48
49
|
|
|
49
50
|
/** Cuánto se espera al canal directo antes de mandar el historial por el proxio. */
|
|
50
51
|
export const HISTORY_WAIT_MS = 8000
|
|
@@ -186,6 +187,8 @@ export function serveSession (session, hub, { origin = 'remote', gate = null, up
|
|
|
186
187
|
return
|
|
187
188
|
}
|
|
188
189
|
if (!mayPass()) return
|
|
190
|
+
// Qué versión corre: tras actualizar el paquete, el agente en marcha sigue con la anterior.
|
|
191
|
+
if (msg.type === 'version') { session.send({ type: 'version', version: VERSION }); return }
|
|
189
192
|
if (msg.type === 'list') { session.send({ type: 'consoles', list: hub.list() }); return }
|
|
190
193
|
if (msg.type === 'open') {
|
|
191
194
|
takeSize(msg)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.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": {
|