@dotrino/terminal-agent 0.34.0 → 0.35.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 +2 -2
- package/consoles.js +16 -50
- package/index.js +10 -9
- package/package.json +2 -2
package/bin/terminal.js
CHANGED
|
@@ -521,8 +521,8 @@ function interactive (conn, first, dir) {
|
|
|
521
521
|
// «r»: esta ventana manda en el tamaño de la consola (la app la usa al ganar el foco: con
|
|
522
522
|
// varias ventanas de tamaños distintos en la misma consola, se ajusta a la que miras).
|
|
523
523
|
if (ch === 'r') { conn.send({ type: 'resize', ...size() }); continue }
|
|
524
|
-
// «p
|
|
525
|
-
if (ch === 'p'
|
|
524
|
+
// «p»: ⤢, la consola toma ahora el tamaño de esta ventana.
|
|
525
|
+
if (ch === 'p') { conn.send({ type: 'resize', ...size() }); conn.send({ type: 'take' }); continue }
|
|
526
526
|
if (ch === 'n') {
|
|
527
527
|
if (send) { input(send); send = '' }
|
|
528
528
|
switchTo({ type: 'open', cwd: first.cwd || path.resolve(process.cwd()) })
|
package/consoles.js
CHANGED
|
@@ -83,12 +83,11 @@ class Console {
|
|
|
83
83
|
this.createdAt = Date.now()
|
|
84
84
|
this.lastActive = Date.now()
|
|
85
85
|
this.viewers = new Set() // sesiones mirando: { onOut(data), onExit(code), onMeta?(info), origin, device?, tag?, size? }
|
|
86
|
-
// QUIÉN
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
this.pinKey = null
|
|
86
|
+
// QUIÉN PUSO EL TAMAÑO. Lo gana una pantalla en cuatro momentos y solo en esos: al abrir la
|
|
87
|
+
// consola, al cambiarse a ella, al pulsar ⤢ y al teclear. Se ajusta en ese instante y nada
|
|
88
|
+
// queda fijado: la siguiente pantalla que haga una de las cuatro cosas lo cambia. `holder` es la última que lo
|
|
89
|
+
// hizo; solo a ella se le sigue la pantalla (redimensionar la ventana, girar el teléfono).
|
|
90
|
+
// Volver a conectarse o que otra pantalla se vaya no cambia el tamaño.
|
|
92
91
|
this.holder = null
|
|
93
92
|
this.exited = false
|
|
94
93
|
this.screen = new Terminal({ cols, rows, scrollback: SCROLLBACK, allowProposedApi: true })
|
|
@@ -222,56 +221,24 @@ class Console {
|
|
|
222
221
|
|
|
223
222
|
detach (viewer) {
|
|
224
223
|
if (!this.viewers.has(viewer)) return
|
|
225
|
-
// Quién decidía, ANTES de quitarlo: si era él, hay que pasar el tamaño a otro.
|
|
226
|
-
const before = this.decider()
|
|
227
224
|
this.viewers.delete(viewer)
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const d = this.decider()
|
|
232
|
-
if (d !== before && d?.size) this.resize(d.size.cols, d.size.rows)
|
|
225
|
+
// Irse no cambia el tamaño ni se lo pasa a otra pantalla: se queda como está hasta que
|
|
226
|
+
// alguien abra la consola, se cambie a ella, pulse ⤢ o teclee.
|
|
227
|
+
if (this.holder === viewer) this.holder = null
|
|
233
228
|
this._meta()
|
|
234
229
|
}
|
|
235
230
|
|
|
236
|
-
/**
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
/** La pantalla que eligió el tamaño, si está mirando ahora. */
|
|
240
|
-
pinnedViewer () {
|
|
241
|
-
if (!this.pinKey) return null
|
|
242
|
-
return [...this.viewers].filter((v) => viewerKey(v) === this.pinKey).pop() || null
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* `viewer` dice su tamaño (al engancharse, `attaching`, o porque cambió su pantalla). Se aplica
|
|
247
|
-
* solo si es quien decide; engancharse lo hace decidir si nadie lo tiene fijado.
|
|
248
|
-
*/
|
|
249
|
-
sizeFrom (viewer, { attaching = false } = {}) {
|
|
250
|
-
if (attaching) this.holder = viewer
|
|
251
|
-
if (this.decider() === viewer && viewer.size) this.resize(viewer.size.cols, viewer.size.rows)
|
|
252
|
-
else this._meta()
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* `viewer` tecleó: pasa a decidir el tamaño, también sobre una pantalla que lo tenía fijado
|
|
257
|
-
* (deja de estarlo). Es la única forma de ganarlo que tiene quien no puede fijarlo, como la
|
|
258
|
-
* terminal embebida de un editor.
|
|
259
|
-
*/
|
|
260
|
-
typed (viewer) {
|
|
261
|
-
if (!this.viewers.has(viewer) || this.decider() === viewer) return
|
|
231
|
+
/** `viewer` toma el tamaño AHORA: abrió la consola, se cambió a ella, pulsó ⤢ o tecleó. */
|
|
232
|
+
take (viewer) {
|
|
233
|
+
if (!this.viewers.has(viewer)) return
|
|
262
234
|
this.holder = viewer
|
|
263
|
-
if (this.pinKey !== viewerKey(viewer)) this.pinKey = null
|
|
264
235
|
if (viewer.size) this.resize(viewer.size.cols, viewer.size.rows)
|
|
265
236
|
else this._meta()
|
|
266
237
|
}
|
|
267
238
|
|
|
268
|
-
/**
|
|
269
|
-
|
|
270
|
-
if (
|
|
271
|
-
else if (this.pinKey === viewerKey(viewer)) this.pinKey = null
|
|
272
|
-
const d = this.decider()
|
|
273
|
-
if (d?.size) this.resize(d.size.cols, d.size.rows)
|
|
274
|
-
this._meta()
|
|
239
|
+
/** Cambió la pantalla de `viewer` (ventana, giro). Solo se sigue a quien puso el tamaño. */
|
|
240
|
+
sizeFrom (viewer) {
|
|
241
|
+
if (this.holder === viewer && viewer.size) this.resize(viewer.size.cols, viewer.size.rows)
|
|
275
242
|
}
|
|
276
243
|
|
|
277
244
|
/**
|
|
@@ -281,8 +248,8 @@ class Console {
|
|
|
281
248
|
*/
|
|
282
249
|
info () {
|
|
283
250
|
const watchers = [...this.viewers].filter((v) => v.origin).map((v) => ({ origin: v.origin, device: v.device || null, tag: v.tag || null }))
|
|
284
|
-
const d = this.
|
|
285
|
-
const sizeBy = d ? { origin: d.origin || null, device: d.device || null, tag: d.tag || null
|
|
251
|
+
const d = this.holder
|
|
252
|
+
const sizeBy = d ? { origin: d.origin || null, device: d.device || null, tag: d.tag || null } : null
|
|
286
253
|
return { id: this.id, n: this.n, activity: this.busy ? 'busy' : 'idle', doneAt: this.doneAt, sizeBy, origin: this.origin, title: this.title, host: HOST, cwd: cwdOf(this.pty?.pid), cols: this.cols, rows: this.rows, createdAt: this.createdAt, lastActive: this.lastActive, viewers: this.viewers.size, watchers }
|
|
287
254
|
}
|
|
288
255
|
}
|
|
@@ -305,7 +272,6 @@ const REPORTS = new RegExp([
|
|
|
305
272
|
/** ¿Hay algo TECLEADO en `data`, o es solo lo que la terminal contesta por su cuenta? */
|
|
306
273
|
export function isTyped (data) { return String(data).replace(REPORTS, '') !== '' }
|
|
307
274
|
|
|
308
|
-
function viewerKey (v) { return `${v.origin || ''}|${v.device || ''}|${v.tag || ''}` }
|
|
309
275
|
|
|
310
276
|
/** Las consolas de este agente. */
|
|
311
277
|
export class ConsoleHub {
|
package/index.js
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
*
|
|
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
|
-
* { type:'attach', id, cols, rows } · { type:'detach' } ·
|
|
15
|
-
* { type:'input', data } · { type:'resize', cols, rows } · { type:'
|
|
14
|
+
* { type:'attach', id, cols, rows, keep? } · { type:'detach' } ·
|
|
15
|
+
* { type:'input', data } · { type:'resize', cols, rows } · { type:'take' } ·
|
|
16
16
|
* { type:'close' } (mata la consola enganchada) · { type:'kill', id } ·
|
|
17
17
|
* { type:'move', id, before? } (el orden del panel; contesta con `consoles`) ·
|
|
18
18
|
* { type:'unlock', code } (la clave de la máquina, si tiene: access.js)
|
|
@@ -120,7 +120,7 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
|
|
|
120
120
|
// La etiqueta con la que se presenta quien mira (una ventana de la app de escritorio).
|
|
121
121
|
const takeTag = (msg) => { if (typeof msg.tag === 'string') viewer.tag = msg.tag.slice(0, 64) }
|
|
122
122
|
|
|
123
|
-
async function attachTo (c, { fresh }) {
|
|
123
|
+
async function attachTo (c, { fresh, keep = false }) {
|
|
124
124
|
release()
|
|
125
125
|
current = c
|
|
126
126
|
// SI EL CANAL DIRECTO AÚN NO ABRIÓ, PRIMERO SOLO LA PANTALLA. La foto con su historial
|
|
@@ -133,7 +133,8 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
|
|
|
133
133
|
// suya. Quedarse enganchado dejaba un mirón FANTASMA (la consola salía «abierta en otro
|
|
134
134
|
// aparato» sin nadie mirando, y nadie la elegía como libre).
|
|
135
135
|
if (current !== c) { c.detach(viewer); return }
|
|
136
|
-
|
|
136
|
+
// Volver a engancharse tras una reconexión (`keep`) no es abrir ni cambiarse: no toca el tamaño.
|
|
137
|
+
if (!keep) c.take(viewer)
|
|
137
138
|
// La pantalla va en trozos: el proxio corta los mensajes a 1 MB.
|
|
138
139
|
for (let i = 0; i < snapshot.length || i === 0; i += REPLAY_CHUNK) {
|
|
139
140
|
await session.send({ type: 'replay', id: c.id, data: snapshot.slice(i, i + REPLAY_CHUNK), last: i + REPLAY_CHUNK >= snapshot.length })
|
|
@@ -185,21 +186,21 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
|
|
|
185
186
|
if (!c) return fail('no-console', 'that console no longer exists')
|
|
186
187
|
takeSize(msg)
|
|
187
188
|
takeTag(msg)
|
|
188
|
-
attachTo(c, { fresh: false })
|
|
189
|
+
attachTo(c, { fresh: false, keep: msg.keep === true })
|
|
189
190
|
return
|
|
190
191
|
}
|
|
191
192
|
if (msg.type === 'detach') { release(); return }
|
|
192
193
|
if (msg.type === 'input') {
|
|
193
194
|
if (!current) return
|
|
194
195
|
const data = String(msg.data ?? '')
|
|
195
|
-
// Quien teclea
|
|
196
|
-
if (isTyped(data)) current.
|
|
196
|
+
// Quien teclea toma el tamaño. Lo que la terminal contesta sola no cuenta.
|
|
197
|
+
if (isTyped(data) && current.holder !== viewer) current.take(viewer)
|
|
197
198
|
current.write(data)
|
|
198
199
|
return
|
|
199
200
|
}
|
|
200
201
|
if (msg.type === 'resize') { takeSize(msg); current?.sizeFrom(viewer); return }
|
|
201
|
-
// ⤢ «
|
|
202
|
-
if (msg.type === '
|
|
202
|
+
// ⤢ «Usar el tamaño de esta pantalla»: se ajusta ahora, sin dejar nada fijado.
|
|
203
|
+
if (msg.type === 'take') { current?.take(viewer); return }
|
|
203
204
|
if (msg.type === 'close') { if (current) hub.kill(current.id, viewer); return }
|
|
204
205
|
if (msg.type === 'kill') { if (!hub.kill(msg.id, viewer)) fail('no-console', 'that console no longer exists'); return }
|
|
205
206
|
// El orden del panel: es de la máquina, así que lo ve igual cualquier pantalla.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.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": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@dotrino/identity": "0.107.2",
|
|
31
31
|
"@dotrino/proxy-client": "0.30.3",
|
|
32
|
-
"@dotrino/remote-agent": "0.18.
|
|
32
|
+
"@dotrino/remote-agent": "0.18.1",
|
|
33
33
|
"@dotrino/update": "0.5.1",
|
|
34
34
|
"@dotrino/vault": "0.82.1",
|
|
35
35
|
"@xterm/addon-serialize": "0.13.0",
|