@dotrino/terminal-agent 0.12.0 → 0.14.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/bin/terminal.js CHANGED
@@ -55,8 +55,8 @@ if (args.includes('-h') || args.includes('--help')) {
55
55
  dotrino-terminal rename <perfil> [nuevo] renombra un perfil (para su agente: cierra sus consolas)
56
56
 
57
57
  Dentro de una consola: Ctrl+] y luego d la suelta sin cerrarla; Ctrl+] n abre otra
58
- (y suelta la actual); Ctrl+] a <id> Enter pasa a esa consola; Ctrl+] r ajusta la consola al
59
- tamaño de esta ventana.
58
+ (y suelta la actual); Ctrl+] a <id> Enter pasa a esa consola; Ctrl+] p fija el tamaño de la
59
+ consola a esta ventana y Ctrl+] u lo suelta.
60
60
  Cerrar la ventana cierra la consola que abrió.`, `usage:
61
61
  dotrino-terminal [--name <n>] [--cwd <dir>] open a new console in this window, in the current folder
62
62
  dotrino-terminal attach <id> [--name <n>] attach to an open console
@@ -67,8 +67,8 @@ Cerrar la ventana cierra la consola que abrió.`, `usage:
67
67
  dotrino-terminal rename <profile> [new] rename a profile (stops its agent: closes its consoles)
68
68
 
69
69
  Inside a console: Ctrl+] then d detaches without closing it; Ctrl+] n opens another
70
- (detaching the current one); Ctrl+] a <id> Enter switches to that console; Ctrl+] r fits the
71
- console to this window's size.
70
+ (detaching the current one); Ctrl+] a <id> Enter switches to that console; Ctrl+] p pins the
71
+ console's size to this window and Ctrl+] u unpins it.
72
72
  Closing the window closes the console it opened.`))
73
73
  process.exit(0)
74
74
  }
@@ -380,6 +380,8 @@ function interactive (conn, first, dir) {
380
380
  // «r»: esta ventana manda en el tamaño de la consola (la app la usa al ganar el foco: con
381
381
  // varias ventanas de tamaños distintos en la misma consola, se ajusta a la que miras).
382
382
  if (ch === 'r') { conn.send({ type: 'resize', ...size() }); continue }
383
+ // «p» / «u»: esta ventana fija (📌) o suelta el tamaño de la consola.
384
+ if (ch === 'p' || ch === 'u') { conn.send({ type: 'pin', on: ch === 'p' }); if (ch === 'p') conn.send({ type: 'resize', ...size() }); continue }
383
385
  if (ch === 'n') {
384
386
  if (send) { input(send); send = '' }
385
387
  switchTo({ type: 'open', cwd: first.cwd || path.resolve(process.cwd()) })
package/consoles.js CHANGED
@@ -37,7 +37,12 @@ class Console {
37
37
  this.rows = rows
38
38
  this.createdAt = Date.now()
39
39
  this.lastActive = Date.now()
40
- this.viewers = new Set() // sesiones mirando: { onOut(data), onExit(code), onMeta?(info), origin, device? }
40
+ this.viewers = new Set() // sesiones mirando: { onOut(data), onExit(code), onMeta?(info), origin, device?, tag?, size? }
41
+ // QUIÉN MANDA EN EL TAMAÑO. `pinned`: quien lo fijó a propósito (📌 en la app o el teléfono);
42
+ // si nadie, `holder`: el último que se enganchó. Solo ese lo cambia, y se sigue su pantalla
43
+ // (redimensionar la ventana, girar el teléfono). Escribir o dar foco no cambia nada.
44
+ this.pinned = null
45
+ this.holder = null
41
46
  this.exited = false
42
47
  this.screen = new Terminal({ cols, rows, scrollback: SCROLLBACK, allowProposedApi: true })
43
48
  this.serializer = new SerializeAddon()
@@ -62,9 +67,13 @@ class Console {
62
67
 
63
68
  resize (cols, rows) {
64
69
  if (!cols || !rows) return
70
+ const changed = cols !== this.cols || rows !== this.rows
65
71
  this.cols = cols; this.rows = rows
66
72
  try { this.pty.resize(cols, rows) } catch (_) {}
67
73
  try { this.screen.resize(cols, rows) } catch (_) {}
74
+ // Quien mira desde otro aparato se entera del tamaño nuevo y adapta su vista (la PWA no
75
+ // encoge la consola: la muestra a su tamaño, con desplazamiento).
76
+ if (changed) this._meta()
68
77
  }
69
78
 
70
79
  /**
@@ -90,7 +99,39 @@ class Console {
90
99
  })
91
100
  }
92
101
 
93
- detach (viewer) { if (this.viewers.delete(viewer)) this._meta() }
102
+ detach (viewer) {
103
+ if (!this.viewers.delete(viewer)) return
104
+ const before = this.decider()
105
+ if (this.pinned === viewer) this.pinned = null
106
+ // Si se fue el último que llegó, lo es el último de los que quedan.
107
+ if (this.holder === viewer) this.holder = [...this.viewers].filter((v) => v.size).pop() || null
108
+ // Si cambió quién decide (se fue el que lo tenía, fijado o no), manda su tamaño.
109
+ const d = this.decider()
110
+ if (d !== before && d?.size) this.resize(d.size.cols, d.size.rows)
111
+ this._meta()
112
+ }
113
+
114
+ /** Quién decide el tamaño ahora. */
115
+ decider () { return this.pinned || this.holder }
116
+
117
+ /**
118
+ * `viewer` dice su tamaño (al engancharse, `attaching`, o porque cambió su pantalla). Se aplica
119
+ * solo si es quien decide; engancharse lo hace decidir si nadie lo tiene fijado.
120
+ */
121
+ sizeFrom (viewer, { attaching = false } = {}) {
122
+ if (attaching) this.holder = viewer
123
+ if (this.decider() === viewer && viewer.size) this.resize(viewer.size.cols, viewer.size.rows)
124
+ else this._meta()
125
+ }
126
+
127
+ /** 📌: `viewer` fija (o suelta) el tamaño a su pantalla. */
128
+ pin (viewer, on) {
129
+ if (on) this.pinned = viewer
130
+ else if (this.pinned === viewer) this.pinned = null
131
+ const d = this.decider()
132
+ if (d?.size) this.resize(d.size.cols, d.size.rows)
133
+ this._meta()
134
+ }
94
135
 
95
136
  /**
96
137
  * `watchers` dice QUIÉN mira: una ventana de esta máquina o un aparato de la cuenta (con
@@ -99,7 +140,9 @@ class Console {
99
140
  */
100
141
  info () {
101
142
  const watchers = [...this.viewers].filter((v) => v.origin).map((v) => ({ origin: v.origin, device: v.device || null, tag: v.tag || null }))
102
- return { id: this.id, n: this.n, origin: this.origin, title: this.title, cols: this.cols, rows: this.rows, createdAt: this.createdAt, lastActive: this.lastActive, viewers: this.viewers.size, watchers }
143
+ const d = this.decider()
144
+ const sizeBy = d ? { origin: d.origin || null, device: d.device || null, tag: d.tag || null, pinned: d === this.pinned } : null
145
+ return { id: this.id, n: this.n, sizeBy, origin: this.origin, title: this.title, cols: this.cols, rows: this.rows, createdAt: this.createdAt, lastActive: this.lastActive, viewers: this.viewers.size, watchers }
103
146
  }
104
147
  }
105
148
 
package/index.js CHANGED
@@ -12,7 +12,7 @@
12
12
  * Payloads de dominio (van cifrados dentro de la sesión, el proxio no los ve):
13
13
  * cliente → agente: { type:'list' } · { type:'open', cols, rows, cwd?, tag? } ·
14
14
  * { type:'attach', id, cols, rows } · { type:'detach' } ·
15
- * { type:'input', data } · { type:'resize', cols, rows } ·
15
+ * { type:'input', data } · { type:'resize', cols, rows } · { type:'pin', on } ·
16
16
  * { type:'close' } (mata la consola enganchada) · { type:'kill', id }
17
17
  * agente → cliente: { type:'consoles', list } · { type:'attached', id, fresh } ·
18
18
  * { type:'replay', id, data, last } · { type:'out', data } ·
@@ -70,7 +70,9 @@ export function makeHub (pty, opts = {}) {
70
70
  * ella: cerrar la ventana mata su shell, como en cualquier terminal. Una ventana que solo
71
71
  * se enganchó a una consola ajena, o que la soltó a propósito (`detach`), no mata nada.
72
72
  *
73
- * Tamaño con varios mirando: manda el último que se enganchó o escribió (como tmux).
73
+ * Tamaño con varios mirando: lo decide quien lo FIJÓ (`pin`, el 📌 de la app o el teléfono) y, si
74
+ * nadie, el último que se enganchó. Solo esa pantalla lo cambia (sus `resize` se siguen: girar el
75
+ * teléfono, redimensionar la ventana). Escribir o dar foco no cambia nada.
74
76
  * Exportada para las pruebas.
75
77
  *
76
78
  * @param {object} session
@@ -90,7 +92,7 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
90
92
  }
91
93
  const release = () => { if (current) { current.detach(viewer); current = null } }
92
94
  const fail = (code, message) => session.send({ type: 'fail', code, message })
93
- const takeSize = (msg) => { if (msg.cols && msg.rows) size = { cols: msg.cols, rows: msg.rows } }
95
+ const takeSize = (msg) => { if (msg.cols && msg.rows) { size = { cols: msg.cols, rows: msg.rows }; viewer.size = size } }
94
96
  // La etiqueta con la que se presenta quien mira (una ventana de la app de escritorio).
95
97
  const takeTag = (msg) => { if (typeof msg.tag === 'string') viewer.tag = msg.tag.slice(0, 64) }
96
98
 
@@ -98,6 +100,7 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
98
100
  release()
99
101
  current = c
100
102
  const snapshot = await c.attach(viewer)
103
+ c.sizeFrom(viewer, { attaching: true })
101
104
  // La pantalla va en trozos: el proxio corta los mensajes a 1 MB.
102
105
  for (let i = 0; i < snapshot.length || i === 0; i += REPLAY_CHUNK) {
103
106
  await session.send({ type: 'replay', id: c.id, data: snapshot.slice(i, i + REPLAY_CHUNK), last: i + REPLAY_CHUNK >= snapshot.length })
@@ -124,18 +127,18 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
124
127
  if (!c) return fail('no-console', 'that console no longer exists')
125
128
  takeSize(msg)
126
129
  takeTag(msg)
127
- c.resize(size.cols, size.rows)
128
130
  attachTo(c, { fresh: false })
129
131
  return
130
132
  }
131
133
  if (msg.type === 'detach') { owned = null; release(); return }
132
134
  if (msg.type === 'input') {
133
135
  if (!current) return
134
- if (current.cols !== size.cols || current.rows !== size.rows) current.resize(size.cols, size.rows)
135
136
  current.write(String(msg.data ?? ''))
136
137
  return
137
138
  }
138
- if (msg.type === 'resize') { takeSize(msg); current?.resize(size.cols, size.rows); return }
139
+ if (msg.type === 'resize') { takeSize(msg); current?.sizeFrom(viewer); return }
140
+ // 📌 «Esta pantalla manda en el tamaño» (on) o soltarlo (off).
141
+ if (msg.type === 'pin') { current?.pin(viewer, !!msg.on); return }
139
142
  if (msg.type === 'close') { if (current) hub.kill(current.id); return }
140
143
  if (msg.type === 'kill') { if (!hub.kill(msg.id)) fail('no-console', 'that console no longer exists') }
141
144
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/terminal-agent",
3
- "version": "0.12.0",
3
+ "version": "0.14.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": {