@dotrino/terminal-agent 0.41.3 → 0.42.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/bin/terminal.js CHANGED
@@ -17,6 +17,8 @@
17
17
  * dotrino-terminal vscode [--name <n>] la terminal embebida de VS Code abre consolas de aquí
18
18
  * dotrino-terminal vscode --off lo deshace
19
19
  * dotrino-terminal desktop update [--check] actualiza la app de escritorio (la ventana)
20
+ * dotrino-terminal updates [--json] [--desktop <versión>]
21
+ * qué versiones nuevas hay (del cliente y de la app)
20
22
  * dotrino-terminal service install|uninstall|status [--name <n>]
21
23
  * el agente como servicio: arranca solo con la máquina
22
24
  *
@@ -87,6 +89,8 @@ if (args.includes('-h') || args.includes('--help')) {
87
89
  dotrino-terminal desktop update actualiza la app de escritorio (la ventana): baja la
88
90
  versión nueva, comprueba su firma y la instala
89
91
  (--check solo mira si hay una)
92
+ dotrino-terminal updates [--json] dice si hay versión nueva de dotrino-terminal y de la app
93
+ (--desktop <versión> es la app que tienes; no instala nada)
90
94
  dotrino-terminal service install [--name <n>] deja el agente como servicio de tu usuario: arranca
91
95
  solo al encender la máquina, sin abrir ninguna ventana
92
96
  dotrino-terminal service uninstall [--name <n>] lo quita (para el agente: cierra sus consolas)
@@ -125,6 +129,8 @@ Cerrar la ventana no cierra la consola: sigue abierta y se retoma después.`, `u
125
129
  dotrino-terminal desktop update update the desktop app (the window): downloads the
126
130
  new version, checks its signature and installs it
127
131
  (--check only looks for one)
132
+ dotrino-terminal updates [--json] say whether there is a new version of dotrino-terminal and of
133
+ the app (--desktop <version> is the app you have; installs nothing)
128
134
  dotrino-terminal service install [--name <n>] run the agent as a service of your user: it starts
129
135
  by itself when the machine boots, with no window open
130
136
  dotrino-terminal service uninstall [--name <n>] remove it (stops the agent: closes its consoles)
@@ -242,6 +248,32 @@ function vscode () {
242
248
  if (!off) console.log(t('\nLas terminales nuevas del editor ya abren aquí. Si actualizas o cambias de Node, vuelve a correr esta orden.', '\nNew terminals in the editor now open here. If you update or switch Node, run this command again.'))
243
249
  }
244
250
 
251
+ /**
252
+ * Qué versiones nuevas hay, sin instalar nada: del cliente (npm) y, con `--desktop <versión>`,
253
+ * de la app de escritorio. La app lo pregunta al arrancar (ella no tiene red). Cada una dice
254
+ * `newer` o por qué no se pudo mirar: «no se pudo mirar» no es «al día».
255
+ */
256
+ async function updates () {
257
+ const { latestVersion, isNewer } = await import('@dotrino/update')
258
+ const one = async (current, ask) => {
259
+ const r = await ask()
260
+ return r.ok ? { current, latest: r.version, newer: isNewer(r.version, current) } : { current, error: r.reason }
261
+ }
262
+ const out = { agent: await one(VERSION, () => latestVersion({ source: 'npm', pkg: '@dotrino/terminal-agent', product: 'dotrino-terminal', version: VERSION })) }
263
+ const app = opt('--desktop')
264
+ if (app) {
265
+ const { latestDesktop } = await import('../desktop.js')
266
+ out.desktop = await one(app, () => latestDesktop({ version: app }))
267
+ }
268
+ if (args.includes('--json')) { console.log(JSON.stringify(out)); return }
269
+ const say = (name, x) => console.log(x.error
270
+ ? t(`${name}: no se pudo mirar (${x.error}).`, `${name}: could not check (${x.error}).`)
271
+ : x.newer ? t(`${name}: hay ${x.latest} y tienes ${x.current}.`, `${name}: ${x.latest} is out and you have ${x.current}.`)
272
+ : t(`${name}: al día (${x.current}).`, `${name}: up to date (${x.current}).`))
273
+ say('dotrino-terminal', out.agent)
274
+ if (out.desktop) say(t('La app', 'The app'), out.desktop)
275
+ }
276
+
245
277
  /** Dónde está la app de escritorio, si no lo dijo quien llama: la del PATH. */
246
278
  function findDesktop (name) {
247
279
  for (const d of (process.env.PATH || '').split(path.delimiter)) {
@@ -846,6 +878,7 @@ try {
846
878
  if (cmd === 'lock') { await lock(); process.exit(0) }
847
879
  if (cmd === 'vscode') { vscode(); process.exit(0) }
848
880
  if (cmd === 'desktop') { await desktop(); process.exit(0) }
881
+ if (cmd === 'updates') { await updates(); process.exit(0) }
849
882
  if (cmd === 'service') { await service(); process.exit(0) }
850
883
  if (cmd === 'note') { await note(); process.exit(0) }
851
884
  const dir = opt('--dir') || dataDir(opt('--name'))
package/consoles.js CHANGED
@@ -102,6 +102,9 @@ class Console {
102
102
  // hizo; solo a ella se le sigue la pantalla (redimensionar la ventana, girar el teléfono).
103
103
  // Volver a conectarse o que otra pantalla se vaya no cambia el tamaño.
104
104
  this.holder = null
105
+ // Quién lo tenía cuando se fue (su aparato o su ventana): si ESA pantalla vuelve por una
106
+ // conexión nueva sin que otra lo haya tomado, sigue siendo la suya (`resume`).
107
+ this.lastHolder = null
105
108
  this.exited = false
106
109
  this.screen = new Terminal({ cols, rows, scrollback: SCROLLBACK, allowProposedApi: true })
107
110
  this.serializer = new SerializeAddon()
@@ -262,14 +265,34 @@ class Console {
262
265
  this.viewers.delete(viewer)
263
266
  // Irse no cambia el tamaño ni se lo pasa a otra pantalla: se queda como está hasta que
264
267
  // alguien abra la consola, se cambie a ella, pulse ⤢ o teclee.
265
- if (this.holder === viewer) this.holder = null
268
+ if (this.holder === viewer) { this.holder = null; this.lastHolder = screenOf(viewer) }
266
269
  this._meta()
267
270
  }
268
271
 
272
+ /**
273
+ * `viewer` VUELVE por una conexión nueva (`attach` con `keep`). No toma el tamaño; pero si el
274
+ * tamaño era de ESA MISMA pantalla, lo sigue teniendo y se le sigue. Sin esto, tras un corte
275
+ * de red el teléfono que lo puso dejaba de contar: abría el teclado y la consola se quedaba
276
+ * con las filas de antes, las últimas por detrás del teclado, hasta que tecleaba.
277
+ * Vale tanto si su conexión vieja ya se soltó (`lastHolder`) como si sigue enganchada sin
278
+ * saberse muerta (`holder` es otra sesión de la misma pantalla).
279
+ */
280
+ resume (viewer) {
281
+ if (!this.viewers.has(viewer)) return
282
+ const mine = screenOf(viewer)
283
+ if (!mine) return
284
+ const had = this.holder ? screenOf(this.holder) : this.lastHolder
285
+ if (this.holder === viewer || had !== mine) return
286
+ this.holder = viewer
287
+ if (viewer.size && (viewer.size.cols !== this.cols || viewer.size.rows !== this.rows)) this.resize(viewer.size.cols, viewer.size.rows)
288
+ else this._meta()
289
+ }
290
+
269
291
  /** `viewer` toma el tamaño AHORA: abrió la consola, se cambió a ella, pulsó ⤢ o tecleó. */
270
292
  take (viewer) {
271
293
  if (!this.viewers.has(viewer)) return
272
294
  this.holder = viewer
295
+ this.lastHolder = null
273
296
  if (viewer.size) this.resize(viewer.size.cols, viewer.size.rows)
274
297
  else this._meta()
275
298
  }
@@ -312,6 +335,12 @@ export function isTyped (data) { return String(data).replace(REPORTS, '') !== ''
312
335
 
313
336
 
314
337
  /** Las consolas de este agente. */
338
+ /** Qué PANTALLA es un mirón, más allá de su conexión: el aparato, o la ventana con su etiqueta. Null si no se sabe. */
339
+ function screenOf (v) {
340
+ if (v.origin === 'remote') return v.device ? `remote:${v.device}` : null
341
+ return v.tag ? `local:${v.tag}` : null
342
+ }
343
+
315
344
  export class ConsoleHub {
316
345
  /**
317
346
  * @param {{ spawn:(opts:{cols:number,rows:number,cwd:string|null,id:string})=>any }} opts
package/index.js CHANGED
@@ -48,6 +48,8 @@ export { LABEL }
48
48
 
49
49
  /** Cada cuánto mira un agente sin enlazar si ya lo enlazaron. */
50
50
  export const LINK_POLL_MS = 2000
51
+ /** Cada cuánto se reintenta la parte remota cuando no pudo arrancar (sin red, proxio caído). */
52
+ const REMOTE_RETRY_MS = 15_000
51
53
 
52
54
  export function loadPty () {
53
55
  // node-pty (Microsoft, el de VS Code) ≥ 1.2 trae los binarios DENTRO del paquete para Linux,
@@ -139,7 +141,8 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
139
141
  // aparato» sin nadie mirando, y nadie la elegía como libre).
140
142
  if (current !== c) { c.detach(viewer); return }
141
143
  // Volver a engancharse tras una reconexión (`keep`) no es abrir ni cambiarse: no toca el tamaño.
142
- if (!keep) c.take(viewer)
144
+ // Pero si el tamaño era de esta misma pantalla, lo sigue siendo (y se le sigue el teclado, el giro).
145
+ if (!keep) c.take(viewer); else c.resume(viewer)
143
146
  // La pantalla va en trozos: el proxio corta los mensajes a 1 MB.
144
147
  for (let i = 0; i < snapshot.length || i === 0; i += REPLAY_CHUNK) {
145
148
  await session.send({ type: 'replay', id: c.id, data: snapshot.slice(i, i + REPLAY_CHUNK), last: i + REPLAY_CHUNK >= snapshot.length })
@@ -300,7 +303,26 @@ export async function startAgent (opts = {}) {
300
303
  })
301
304
  let watcher = null
302
305
  if (loadLink(dir)) {
303
- try { remote = await startRemote() } catch (e) { local.close(); throw e }
306
+ try { remote = await startRemote() } catch (e) {
307
+ // SIN RED AL ARRANCAR (o con el proxio caído) LAS VENTANAS DE ESTA MÁQUINA ABREN IGUAL:
308
+ // una terminal no puede depender de internet. Antes el agente moría aquí y, con la
309
+ // máquina enlazada, no se podía abrir ni una consola local. La parte remota se
310
+ // reintenta por detrás hasta que salga; mientras, se dice.
311
+ console.error(`[terminal-agent] the remote side did not start (${e.message}); local windows work, retrying every ${REMOTE_RETRY_MS / 1000} s`)
312
+ opts.onLinkError?.(e)
313
+ let trying = false
314
+ watcher = setInterval(() => {
315
+ if (trying) return
316
+ trying = true
317
+ startRemote().then((r) => {
318
+ if (stopped) { r.close(); return }
319
+ clearInterval(watcher); watcher = null
320
+ remote = r
321
+ opts.onLinked?.(r)
322
+ }).catch(() => {}).finally(() => { trying = false })
323
+ }, REMOTE_RETRY_MS)
324
+ watcher.unref()
325
+ }
304
326
  } else {
305
327
  // Sin enlace: se mira cada poco si aparece (`dotrino-terminal link` desde una ventana).
306
328
  // Al aparecer se enciende la parte remota SIN reiniciar, así las consolas abiertas siguen.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/terminal-agent",
3
- "version": "0.41.3",
3
+ "version": "0.42.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": {