@dotrino/terminal-agent 0.8.0 → 0.9.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 +40 -5
- package/index.js +5 -2
- package/package.json +3 -3
package/bin/terminal.js
CHANGED
|
@@ -76,6 +76,9 @@ Closing the window closes the console it opened.`))
|
|
|
76
76
|
*/
|
|
77
77
|
const HOLD = Symbol('hold')
|
|
78
78
|
function die (msg) {
|
|
79
|
+
// Si la TTY ya estaba en crudo (ver `captureEarly`), se devuelve a normal para que el
|
|
80
|
+
// mensaje salga con sus saltos de línea.
|
|
81
|
+
try { if (process.stdin.isTTY) process.stdin.setRawMode(false) } catch (_) {}
|
|
79
82
|
process.stderr.write(msg + '\n')
|
|
80
83
|
if (process.env.DOTRINO_TERMINAL_HOLD !== '1' || !process.stdin.isTTY) process.exit(1)
|
|
81
84
|
process.stderr.write(t('\nPulsa una tecla para cerrar.', '\nPress any key to close.'))
|
|
@@ -85,6 +88,22 @@ function die (msg) {
|
|
|
85
88
|
throw HOLD // corta lo que venía detrás; el proceso sale con la tecla
|
|
86
89
|
}
|
|
87
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Lo que se teclea MIENTRAS el cliente arranca (Node, y a veces levantar el agente). Con la TTY
|
|
93
|
+
* en modo normal, eso se repetía en pantalla a destiempo y luego la pantalla de la consola lo
|
|
94
|
+
* pisaba (un retorno de carro y a sobrescribir), y el agente lo descartaba porque aún no había
|
|
95
|
+
* consola. Ahora la TTY pasa a crudo nada más empezar, y lo tecleado se guarda y se manda
|
|
96
|
+
* entero cuando la consola está lista.
|
|
97
|
+
*/
|
|
98
|
+
const early = []
|
|
99
|
+
const earlyTap = (b) => early.push(b)
|
|
100
|
+
function captureEarly () {
|
|
101
|
+
if (!process.stdin.isTTY) return
|
|
102
|
+
process.stdin.setRawMode(true)
|
|
103
|
+
process.stdin.resume()
|
|
104
|
+
process.stdin.on('data', earlyTap)
|
|
105
|
+
}
|
|
106
|
+
|
|
88
107
|
/** El agente de esta máquina; si no hay ninguno escuchando, lo levanta y espera a que conteste. */
|
|
89
108
|
async function agent (dir) {
|
|
90
109
|
try { return await connectLocal(dir) } catch (e) { if (e.code !== 'ENOAGENT') throw e }
|
|
@@ -249,6 +268,10 @@ async function list (conn) {
|
|
|
249
268
|
|
|
250
269
|
/** La ventana: la TTY enganchada a una consola del agente. */
|
|
251
270
|
function interactive (conn, first, dir) {
|
|
271
|
+
// Hasta que el agente diga `attached` no hay consola a la que escribir: se guarda.
|
|
272
|
+
let ready = false
|
|
273
|
+
let queued = ''
|
|
274
|
+
const input = (data) => { if (ready) conn.send({ type: 'input', data }); else queued += data }
|
|
252
275
|
if (!process.stdin.isTTY || !process.stdout.isTTY) die(t('dotrino-terminal necesita una terminal (TTY).', 'dotrino-terminal needs a terminal (TTY).'))
|
|
253
276
|
const out = process.stdout
|
|
254
277
|
let consoleId = null
|
|
@@ -286,7 +309,14 @@ function interactive (conn, first, dir) {
|
|
|
286
309
|
|
|
287
310
|
conn.on('message', (m) => {
|
|
288
311
|
if (m.type === 'out' || m.type === 'replay') { out.write(filter(m.data)); return }
|
|
289
|
-
if (m.type === 'attached') {
|
|
312
|
+
if (m.type === 'attached') {
|
|
313
|
+
consoleId = m.id
|
|
314
|
+
onInfo(m.console)
|
|
315
|
+
// Ya hay consola: va lo que se tecleó mientras tanto, en orden y de una vez.
|
|
316
|
+
ready = true
|
|
317
|
+
if (queued) { conn.send({ type: 'input', data: queued }); queued = '' }
|
|
318
|
+
return
|
|
319
|
+
}
|
|
290
320
|
if (m.type === 'meta') { onInfo(m.console); return }
|
|
291
321
|
if (m.type === 'exit') { finish(m.code || 0); return }
|
|
292
322
|
if (m.type === 'fail') { finish(1, `dotrino-terminal: ${m.message} (${m.code})`) }
|
|
@@ -299,9 +329,10 @@ function interactive (conn, first, dir) {
|
|
|
299
329
|
|
|
300
330
|
process.stdin.setRawMode(true)
|
|
301
331
|
process.stdin.resume()
|
|
332
|
+
process.stdin.off('data', earlyTap)
|
|
302
333
|
const decoder = new StringDecoder('utf8')
|
|
303
334
|
let prefixed = false
|
|
304
|
-
|
|
335
|
+
const onKeys = (buf) => {
|
|
305
336
|
// Ctrl+] abre el atajo: «d» suelta la consola, otro Ctrl+] manda uno literal, y cualquier
|
|
306
337
|
// otra tecla pasa tal cual, con su Ctrl+] delante. Las dos teclas pueden llegar juntas.
|
|
307
338
|
let send = ''
|
|
@@ -309,7 +340,7 @@ function interactive (conn, first, dir) {
|
|
|
309
340
|
if (prefixed) {
|
|
310
341
|
prefixed = false
|
|
311
342
|
if (ch === 'd') {
|
|
312
|
-
if (send)
|
|
343
|
+
if (send) input(send)
|
|
313
344
|
conn.send({ type: 'detach' })
|
|
314
345
|
return finish(0, t(`Consola soltada. Para volver: dotrino-terminal attach ${consoleId}`, `Console detached. To return: dotrino-terminal attach ${consoleId}`))
|
|
315
346
|
}
|
|
@@ -317,8 +348,11 @@ function interactive (conn, first, dir) {
|
|
|
317
348
|
} else if (ch === DETACH_PREFIX) prefixed = true
|
|
318
349
|
else send += ch
|
|
319
350
|
}
|
|
320
|
-
if (send)
|
|
321
|
-
}
|
|
351
|
+
if (send) input(send)
|
|
352
|
+
}
|
|
353
|
+
process.stdin.on('data', onKeys)
|
|
354
|
+
// Lo tecleado antes de llegar aquí pasa por el mismo camino (el atajo de soltar incluido).
|
|
355
|
+
for (const b of early.splice(0)) onKeys(b)
|
|
322
356
|
out.on('resize', () => conn.send({ type: 'resize', ...size() }))
|
|
323
357
|
// La ventana se cerró: el agente ve caer la conexión y mata la consola que abrimos.
|
|
324
358
|
for (const sig of ['SIGHUP', 'SIGTERM']) process.on(sig, () => { conn.close(); process.exit(0) })
|
|
@@ -331,6 +365,7 @@ try {
|
|
|
331
365
|
if (cmd === 'link') { await link(); process.exit(0) }
|
|
332
366
|
if (cmd === 'rename') { await rename(); process.exit(0) }
|
|
333
367
|
const dir = opt('--dir') || dataDir(opt('--name'))
|
|
368
|
+
if (cmd === 'open' || cmd === 'attach') captureEarly()
|
|
334
369
|
const conn = await agent(dir)
|
|
335
370
|
if (cmd === 'ls' || cmd === 'list') { await list(conn); conn.close() } else if (cmd === 'kill') {
|
|
336
371
|
if (!args[1]) die(t('falta el id: dotrino-terminal kill <id>', 'missing id: dotrino-terminal kill <id>'))
|
package/index.js
CHANGED
|
@@ -35,8 +35,11 @@ export { LABEL }
|
|
|
35
35
|
export const LINK_POLL_MS = 2000
|
|
36
36
|
|
|
37
37
|
export function loadPty () {
|
|
38
|
-
//
|
|
39
|
-
|
|
38
|
+
// node-pty (Microsoft, el de VS Code) ≥ 1.2 trae los binarios DENTRO del paquete para Linux,
|
|
39
|
+
// macOS y Windows: no compila ni descarga nada al instalarse (funciona con ignore-scripts).
|
|
40
|
+
// Antes: @homebridge/node-pty-prebuilt-multiarch, que los bajaba al instalar con
|
|
41
|
+
// prebuild-install, abandonado (npm avisaba «deprecated»).
|
|
42
|
+
try { return require('node-pty') } catch (e) {
|
|
40
43
|
throw new Error('PTY module missing. Reinstall the agent: `npx @dotrino/terminal-agent` (' + e.message + ')')
|
|
41
44
|
}
|
|
42
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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,9 +29,9 @@
|
|
|
29
29
|
"@dotrino/remote-agent": "0.12.1",
|
|
30
30
|
"@dotrino/update": "0.2.2",
|
|
31
31
|
"@dotrino/vault": "0.79.0",
|
|
32
|
-
"@homebridge/node-pty-prebuilt-multiarch": "0.14.1-beta.2",
|
|
33
32
|
"@xterm/addon-serialize": "0.13.0",
|
|
34
|
-
"@xterm/headless": "5.5.0"
|
|
33
|
+
"@xterm/headless": "5.5.0",
|
|
34
|
+
"node-pty": "1.2.0-beta.15"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=20"
|