@dotrino/terminal-agent 0.8.1 → 0.10.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/README.md +2 -1
- package/bin/terminal.js +36 -6
- package/consoles.js +3 -2
- package/index.js +10 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -33,7 +33,8 @@ dotrino-terminal rename <perfil> [nuevo] # renombrarlo (mueve su carpeta y para
|
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
Cerrar la ventana cierra su consola, como cualquier terminal; **Ctrl+] y luego d** la suelta
|
|
36
|
-
viva
|
|
36
|
+
viva, **Ctrl+] n** abre otra (soltando la actual) y **Ctrl+] a<id> Enter** pasa a otra consola,
|
|
37
|
+
por la misma conexión. `--tag <t>` presenta la ventana en la lista de quién mira. Si un aparato remoto entra en una ventana local, esa ventana suena y lo dice en el
|
|
37
38
|
título. Sin enlace el agente atiende solo a las ventanas locales; al enlazarlo
|
|
38
39
|
(`dotrino-terminal link`) enciende la parte remota sin reiniciarse. La app de escritorio
|
|
39
40
|
(`desktop/` del repo) es una ventana nativa que corre este mismo cliente.
|
package/bin/terminal.js
CHANGED
|
@@ -54,7 +54,8 @@ if (args.includes('-h') || args.includes('--help')) {
|
|
|
54
54
|
dotrino-terminal link [--name <n>] enlaza un perfil con tu bóveda
|
|
55
55
|
dotrino-terminal rename <perfil> [nuevo] renombra un perfil (para su agente: cierra sus consolas)
|
|
56
56
|
|
|
57
|
-
Dentro de una consola: Ctrl+] y luego d la suelta sin cerrarla
|
|
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.
|
|
58
59
|
Cerrar la ventana cierra la consola que abrió.`, `usage:
|
|
59
60
|
dotrino-terminal [--name <n>] [--cwd <dir>] open a new console in this window, in the current folder
|
|
60
61
|
dotrino-terminal attach <id> [--name <n>] attach to an open console
|
|
@@ -64,7 +65,8 @@ Cerrar la ventana cierra la consola que abrió.`, `usage:
|
|
|
64
65
|
dotrino-terminal link [--name <n>] link a profile with your vault
|
|
65
66
|
dotrino-terminal rename <profile> [new] rename a profile (stops its agent: closes its consoles)
|
|
66
67
|
|
|
67
|
-
Inside a console: Ctrl+] then d detaches without closing it
|
|
68
|
+
Inside a console: Ctrl+] then d detaches without closing it; Ctrl+] n opens another
|
|
69
|
+
(detaching the current one); Ctrl+] a <id> Enter switches to that console.
|
|
68
70
|
Closing the window closes the console it opened.`))
|
|
69
71
|
process.exit(0)
|
|
70
72
|
}
|
|
@@ -131,6 +133,9 @@ async function agent (dir) {
|
|
|
131
133
|
throw new Error(t(`el agente no arrancó; mira ${log}`, `the agent did not start; see ${log}`))
|
|
132
134
|
}
|
|
133
135
|
|
|
136
|
+
/** `--tag <t>`: cómo se presenta esta ventana en la lista de quién mira (la app de escritorio). */
|
|
137
|
+
const tag = () => (opt('--tag') ? { tag: opt('--tag') } : {})
|
|
138
|
+
|
|
134
139
|
function alive (pid) {
|
|
135
140
|
try { process.kill(pid, 0); return true } catch (e) { return e.code === 'EPERM' }
|
|
136
141
|
}
|
|
@@ -332,11 +337,30 @@ function interactive (conn, first, dir) {
|
|
|
332
337
|
process.stdin.off('data', earlyTap)
|
|
333
338
|
const decoder = new StringDecoder('utf8')
|
|
334
339
|
let prefixed = false
|
|
340
|
+
let collecting = null // tras Ctrl+] a: el id de la consola, hasta Enter
|
|
341
|
+
// Cambiar de consola SIN salir: por la misma conexión, y con la pantalla en limpio para que la
|
|
342
|
+
// repetición de la otra consola no se pinte encima. Lo tecleado mientras tanto se guarda.
|
|
343
|
+
const switchTo = (msg) => {
|
|
344
|
+
ready = false
|
|
345
|
+
out.write('\x1bc') // RIS: pantalla, historial y modos, de cero
|
|
346
|
+
conn.send({ ...msg, ...size(), ...tag() })
|
|
347
|
+
}
|
|
335
348
|
const onKeys = (buf) => {
|
|
336
|
-
// Ctrl+] abre el atajo: «d» suelta la consola,
|
|
337
|
-
//
|
|
349
|
+
// Ctrl+] abre el atajo: «d» suelta la consola, «n» abre otra nueva, «a<id>⏎» pasa a esa
|
|
350
|
+
// consola (lo usa el panel de la app de escritorio), otro Ctrl+] manda uno literal, y
|
|
351
|
+
// cualquier otra tecla pasa tal cual, con su Ctrl+] delante. Pueden llegar todas juntas.
|
|
338
352
|
let send = ''
|
|
339
353
|
for (const ch of decoder.write(buf)) {
|
|
354
|
+
if (collecting !== null) {
|
|
355
|
+
if (ch === '\r' || ch === '\n') {
|
|
356
|
+
const id = collecting
|
|
357
|
+
collecting = null
|
|
358
|
+
if (send) { input(send); send = '' }
|
|
359
|
+
if (id) switchTo({ type: 'attach', id })
|
|
360
|
+
} else if (/[0-9a-f]/i.test(ch) && collecting.length < 64) collecting += ch
|
|
361
|
+
else collecting = null // no era un id: se descarta el atajo
|
|
362
|
+
continue
|
|
363
|
+
}
|
|
340
364
|
if (prefixed) {
|
|
341
365
|
prefixed = false
|
|
342
366
|
if (ch === 'd') {
|
|
@@ -344,6 +368,12 @@ function interactive (conn, first, dir) {
|
|
|
344
368
|
conn.send({ type: 'detach' })
|
|
345
369
|
return finish(0, t(`Consola soltada. Para volver: dotrino-terminal attach ${consoleId}`, `Console detached. To return: dotrino-terminal attach ${consoleId}`))
|
|
346
370
|
}
|
|
371
|
+
if (ch === 'a') { collecting = ''; continue }
|
|
372
|
+
if (ch === 'n') {
|
|
373
|
+
if (send) { input(send); send = '' }
|
|
374
|
+
switchTo({ type: 'open', cwd: first.cwd || path.resolve(process.cwd()) })
|
|
375
|
+
continue
|
|
376
|
+
}
|
|
347
377
|
send += ch === DETACH_PREFIX ? ch : DETACH_PREFIX + ch
|
|
348
378
|
} else if (ch === DETACH_PREFIX) prefixed = true
|
|
349
379
|
else send += ch
|
|
@@ -375,10 +405,10 @@ try {
|
|
|
375
405
|
conn.close()
|
|
376
406
|
} else if (cmd === 'attach') {
|
|
377
407
|
if (!args[1]) die(t('falta el id: dotrino-terminal attach <id> (mira «dotrino-terminal ls»)', 'missing id: dotrino-terminal attach <id> (see "dotrino-terminal ls")'))
|
|
378
|
-
interactive(conn, { type: 'attach', id: args[1] }, dir)
|
|
408
|
+
interactive(conn, { type: 'attach', id: args[1], ...tag() }, dir)
|
|
379
409
|
} else if (cmd === 'open') {
|
|
380
410
|
// Como cualquier terminal: la consola abre en la carpeta donde estás (o en `--cwd`).
|
|
381
|
-
interactive(conn, { type: 'open', cwd: path.resolve(opt('--cwd') || process.cwd()) }, dir)
|
|
411
|
+
interactive(conn, { type: 'open', cwd: path.resolve(opt('--cwd') || process.cwd()), ...tag() }, dir)
|
|
382
412
|
} else die(t(`orden desconocida: ${cmd} (mira --help)`, `unknown command: ${cmd} (see --help)`))
|
|
383
413
|
} catch (e) {
|
|
384
414
|
if (e !== HOLD) { try { die(`dotrino-terminal: ${e.message}`) } catch (_) {} }
|
package/consoles.js
CHANGED
|
@@ -93,10 +93,11 @@ class Console {
|
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* `watchers` dice QUIÉN mira: una ventana de esta máquina o un aparato de la cuenta (con
|
|
96
|
-
* su pubkey)
|
|
96
|
+
* su pubkey), y la etiqueta con la que se presentó (`tag`): así una ventana de la app de
|
|
97
|
+
* escritorio reconoce, en la lista, cuál es la consola que está mostrando ella. Es lo que deja a la ventana local avisar de que alguien entró desde fuera.
|
|
97
98
|
*/
|
|
98
99
|
info () {
|
|
99
|
-
const watchers = [...this.viewers].filter((v) => v.origin).map((v) => ({ origin: v.origin, device: v.device || null }))
|
|
100
|
+
const watchers = [...this.viewers].filter((v) => v.origin).map((v) => ({ origin: v.origin, device: v.device || null, tag: v.tag || null }))
|
|
100
101
|
return { id: this.id, origin: this.origin, title: this.title, cols: this.cols, rows: this.rows, createdAt: this.createdAt, lastActive: this.lastActive, viewers: this.viewers.size, watchers }
|
|
101
102
|
}
|
|
102
103
|
}
|
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* el navegador solo las suelta, y cualquier aparato de la cuenta puede volver a ellas.
|
|
11
11
|
*
|
|
12
12
|
* Payloads de dominio (van cifrados dentro de la sesión, el proxio no los ve):
|
|
13
|
-
* cliente → agente: { type:'list' } · { type:'open', cols, rows, cwd? } ·
|
|
13
|
+
* cliente → agente: { type:'list' } · { type:'open', cols, rows, cwd?, tag? } ·
|
|
14
14
|
* { type:'attach', id, cols, rows } · { type:'detach' } ·
|
|
15
15
|
* { type:'input', data } · { type:'resize', cols, rows } ·
|
|
16
16
|
* { type:'close' } (mata la consola enganchada) · { type:'kill', id }
|
|
@@ -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
|
}
|
|
@@ -88,6 +91,8 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
88
91
|
const release = () => { if (current) { current.detach(viewer); current = null } }
|
|
89
92
|
const fail = (code, message) => session.send({ type: 'fail', code, message })
|
|
90
93
|
const takeSize = (msg) => { if (msg.cols && msg.rows) size = { cols: msg.cols, rows: msg.rows } }
|
|
94
|
+
// La etiqueta con la que se presenta quien mira (una ventana de la app de escritorio).
|
|
95
|
+
const takeTag = (msg) => { if (typeof msg.tag === 'string') viewer.tag = msg.tag.slice(0, 64) }
|
|
91
96
|
|
|
92
97
|
async function attachTo (c, { fresh }) {
|
|
93
98
|
release()
|
|
@@ -105,6 +110,7 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
105
110
|
if (msg.type === 'list') { session.send({ type: 'consoles', list: hub.list() }); return }
|
|
106
111
|
if (msg.type === 'open') {
|
|
107
112
|
takeSize(msg)
|
|
113
|
+
takeTag(msg)
|
|
108
114
|
// `cwd`: dónde abre la shell (la carpeta de la ventana que la pide). Si no existe, se
|
|
109
115
|
// dice: abrir en otra carpeta sin avisar haría que un comando corra donde no toca.
|
|
110
116
|
if (msg.cwd != null && !isDir(msg.cwd)) return fail('bad-cwd', `not a directory: ${msg.cwd}`)
|
|
@@ -117,6 +123,7 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
117
123
|
const c = hub.get(msg.id)
|
|
118
124
|
if (!c) return fail('no-console', 'that console no longer exists')
|
|
119
125
|
takeSize(msg)
|
|
126
|
+
takeTag(msg)
|
|
120
127
|
c.resize(size.cols, size.rows)
|
|
121
128
|
attachTo(c, { fresh: false })
|
|
122
129
|
return
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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"
|