@dotrino/terminal-agent 0.15.1 → 0.16.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 +30 -2
- package/consoles.js +8 -2
- package/index.js +6 -5
- package/package.json +2 -2
package/bin/terminal.js
CHANGED
|
@@ -319,10 +319,13 @@ function interactive (conn, first, dir) {
|
|
|
319
319
|
// primeros milisegundos (antes de pasar a crudo), y entonces todo se pintaba corrido: el cursor
|
|
320
320
|
// acababa en la columna 0 o encima del prompt. Por eso, antes de la primera, en limpio.
|
|
321
321
|
let clean = false
|
|
322
|
+
let switching = false // se pidió pasar a otra consola y aún no contestó
|
|
323
|
+
let recovering = false // falló el cambio: se está repintando la que había
|
|
322
324
|
conn.on('message', (m) => {
|
|
323
325
|
if (m.type === 'replay' && !clean) { clean = true; out.write('\x1b[H\x1b[2J') }
|
|
324
326
|
if (m.type === 'out' || m.type === 'replay') { out.write(filter(m.data)); return }
|
|
325
327
|
if (m.type === 'attached') {
|
|
328
|
+
switching = false; recovering = false
|
|
326
329
|
consoleId = m.id
|
|
327
330
|
onInfo(m.console)
|
|
328
331
|
// Ya hay consola: va lo que se tecleó mientras tanto, en orden y de una vez.
|
|
@@ -331,8 +334,32 @@ function interactive (conn, first, dir) {
|
|
|
331
334
|
return
|
|
332
335
|
}
|
|
333
336
|
if (m.type === 'meta') { onInfo(m.console); return }
|
|
334
|
-
if (m.type === 'exit') {
|
|
335
|
-
|
|
337
|
+
if (m.type === 'exit') {
|
|
338
|
+
// LA CERRÓ OTRA PANTALLA (el teléfono, la web, el panel de otra ventana): esta ventana no
|
|
339
|
+
// se va — nadie aquí pidió cerrarla, y cerrarla dejaba al usuario sin ventana y sin forma
|
|
340
|
+
// de abrir otra consola. Se abre una nueva y se dice. Si la shell terminó sola (`exit`) o
|
|
341
|
+
// la cerró esta misma ventana, la ventana se cierra, como cualquier terminal.
|
|
342
|
+
if (m.closedBy === 'other') {
|
|
343
|
+
consoleId = null
|
|
344
|
+
switchTo({ type: 'open', cwd: first.cwd || path.resolve(process.cwd()) })
|
|
345
|
+
out.write(`\x1b[2m${t('Otra pantalla cerró esta consola. Esta es una nueva.', 'Another screen closed this console. This is a new one.')}\x1b[0m\r\n`)
|
|
346
|
+
return
|
|
347
|
+
}
|
|
348
|
+
finish(m.code || 0)
|
|
349
|
+
return
|
|
350
|
+
}
|
|
351
|
+
if (m.type === 'fail') {
|
|
352
|
+
// FALLÓ UN CAMBIO DE CONSOLA (la que se pidió ya no existe: el panel de la app iba un
|
|
353
|
+
// instante por detrás). El agente rechaza ANTES de soltar la actual, así que esta ventana
|
|
354
|
+
// sigue en la suya: se vuelve a pintar y se sigue. Terminar aquí cerraba la ventana entera
|
|
355
|
+
// por elegir una entrada caducada. Solo es fatal si falla al arrancar, o al repintar.
|
|
356
|
+
if (switching && consoleId && !recovering) {
|
|
357
|
+
switching = false; recovering = true
|
|
358
|
+
conn.send({ type: 'attach', id: consoleId, ...size(), ...tag() })
|
|
359
|
+
return
|
|
360
|
+
}
|
|
361
|
+
finish(1, `dotrino-terminal: ${m.message} (${m.code})`)
|
|
362
|
+
}
|
|
336
363
|
})
|
|
337
364
|
conn.on('close', () => {
|
|
338
365
|
// Si se fue porque el perfil cambió de nombre (`rename`), no es un error: se dice y se sale.
|
|
@@ -350,6 +377,7 @@ function interactive (conn, first, dir) {
|
|
|
350
377
|
// repetición de la otra consola no se pinte encima. Lo tecleado mientras tanto se guarda.
|
|
351
378
|
const switchTo = (msg) => {
|
|
352
379
|
ready = false
|
|
380
|
+
switching = true
|
|
353
381
|
out.write('\x1bc') // RIS: pantalla, historial y modos, de cero
|
|
354
382
|
conn.send({ ...msg, ...size(), ...tag() })
|
|
355
383
|
}
|
package/consoles.js
CHANGED
|
@@ -183,7 +183,10 @@ export class ConsoleHub {
|
|
|
183
183
|
pty.onExit(({ exitCode }) => {
|
|
184
184
|
c.exited = true
|
|
185
185
|
this.consoles.delete(id)
|
|
186
|
-
|
|
186
|
+
// A cada pantalla se le dice si la consola la cerró OTRA (`byOther`): la shell que termina
|
|
187
|
+
// sola, o la que cierra la propia pantalla, no lo es. Quien mira decide con eso si se va
|
|
188
|
+
// (una ventana cuya shell hizo `exit`) o si sigue (se la cerraron desde otro aparato).
|
|
189
|
+
for (const v of c.viewers) v.onExit(exitCode, { byOther: c.killed === true && c.killedBy !== v })
|
|
187
190
|
c.viewers.clear()
|
|
188
191
|
try { c.screen.dispose() } catch (_) {}
|
|
189
192
|
})
|
|
@@ -195,9 +198,12 @@ export class ConsoleHub {
|
|
|
195
198
|
|
|
196
199
|
list () { return [...this.consoles.values()].map((c) => c.info()).sort((a, b) => a.n - b.n) }
|
|
197
200
|
|
|
198
|
-
|
|
201
|
+
/** Cierra una consola. `by`: la pantalla (viewer) que lo pide, para decirle a las DEMÁS que no fueron ellas. */
|
|
202
|
+
kill (id, by = null) {
|
|
199
203
|
const c = this.consoles.get(id)
|
|
200
204
|
if (!c) return false
|
|
205
|
+
c.killed = true
|
|
206
|
+
c.killedBy = by
|
|
201
207
|
try { c.pty.kill() } catch (_) {}
|
|
202
208
|
return true
|
|
203
209
|
}
|
package/index.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
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 } ·
|
|
19
|
-
* { type:'exit', code } · { type:'fail', code, message }
|
|
19
|
+
* { type:'exit', code, closedBy? } · { type:'fail', code, message }
|
|
20
20
|
*/
|
|
21
21
|
import fs from 'node:fs'
|
|
22
22
|
import os from 'node:os'
|
|
@@ -87,7 +87,8 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
87
87
|
origin,
|
|
88
88
|
device: session.device || null,
|
|
89
89
|
onOut: (data) => { session.send({ type: 'out', data }) },
|
|
90
|
-
|
|
90
|
+
// `closedBy: 'other'`: la cerró otra pantalla (no esta, ni la shell por su cuenta).
|
|
91
|
+
onExit: (code, why) => { current = null; owned = null; session.send({ type: 'exit', code, ...(why?.byOther ? { closedBy: 'other' } : {}) }) },
|
|
91
92
|
onMeta: (info) => { session.send({ type: 'meta', console: info }) }
|
|
92
93
|
}
|
|
93
94
|
const release = () => { if (current) { current.detach(viewer); current = null } }
|
|
@@ -139,13 +140,13 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
139
140
|
if (msg.type === 'resize') { takeSize(msg); current?.sizeFrom(viewer); return }
|
|
140
141
|
// ⤢ «Esta pantalla manda en el tamaño» (on) o soltarlo (off).
|
|
141
142
|
if (msg.type === 'pin') { current?.pin(viewer, !!msg.on); return }
|
|
142
|
-
if (msg.type === 'close') { if (current) hub.kill(current.id); return }
|
|
143
|
-
if (msg.type === 'kill') { if (!hub.kill(msg.id)) fail('no-console', 'that console no longer exists') }
|
|
143
|
+
if (msg.type === 'close') { if (current) hub.kill(current.id, viewer); return }
|
|
144
|
+
if (msg.type === 'kill') { if (!hub.kill(msg.id, viewer)) fail('no-console', 'that console no longer exists') }
|
|
144
145
|
})
|
|
145
146
|
session.on('close', () => {
|
|
146
147
|
const mine = owned && owned === current ? owned : null
|
|
147
148
|
release()
|
|
148
|
-
if (mine) hub.kill(mine.id)
|
|
149
|
+
if (mine) hub.kill(mine.id, viewer)
|
|
149
150
|
})
|
|
150
151
|
}
|
|
151
152
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@dotrino/identity": "0.107.2",
|
|
28
28
|
"@dotrino/proxy-client": "0.27.1",
|
|
29
|
-
"@dotrino/remote-agent": "0.
|
|
29
|
+
"@dotrino/remote-agent": "0.14.0",
|
|
30
30
|
"@dotrino/update": "0.2.2",
|
|
31
31
|
"@dotrino/vault": "0.79.0",
|
|
32
32
|
"@xterm/addon-serialize": "0.13.0",
|