@dotrino/terminal-agent 0.17.0 → 0.19.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 +25 -0
- package/bin/terminal.js +66 -1
- package/consoles.js +32 -49
- package/index.js +36 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,3 +58,28 @@ Cada agente guarda su enlace en `~/.dotrino/agent/terminal-agent/<nombre>/`, el
|
|
|
58
58
|
carpeta concreta. El `link.json` guarda la llave privada: trátalo como una llave SSH.
|
|
59
59
|
|
|
60
60
|
MIT.
|
|
61
|
+
|
|
62
|
+
## Clave de la máquina (opcional)
|
|
63
|
+
|
|
64
|
+
Por defecto, cualquier aparato de tu cuenta con permiso abre consolas en esta máquina. Si
|
|
65
|
+
quieres pedir además una clave (un PIN o una contraseña):
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
dotrino-terminal lock [--name <perfil>] # la pone o la cambia (se teclea dos veces, no se ve)
|
|
69
|
+
dotrino-terminal lock --off [--name <perfil>] # la quita
|
|
70
|
+
dotrino-terminal lock --status [--name <perfil>] # dice si hay
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
En la app de escritorio: menú **Perfil → Poner o cambiar la clave… / Quitar la clave**.
|
|
74
|
+
|
|
75
|
+
- Es **del perfil**: todas sus consolas comparten la misma clave.
|
|
76
|
+
- La piden **solo los otros aparatos** (web, teléfono). Las ventanas de esta máquina no.
|
|
77
|
+
- Vale **al momento**, sin reiniciar el agente: quien ya estaba dentro tiene que escribirla
|
|
78
|
+
en lo siguiente que haga.
|
|
79
|
+
- Cada conexión la escribe una vez. La web y las apps la recuerdan solo en memoria.
|
|
80
|
+
- Cinco fallos seguidos y hay que esperar (30 s, y el doble cada vez, hasta una hora). El freno
|
|
81
|
+
es de la máquina, no de la conexión.
|
|
82
|
+
- En el disco (`access.json`, en la carpeta del perfil) quedan la sal y el resumen scrypt,
|
|
83
|
+
nunca la clave. Viaja dentro de la sesión cifrada: el proxio no la ve.
|
|
84
|
+
- Hace falta agente ≥ 0.19.0, y web ≥ 0.8.9 o las apps ≥ 0.8.9 para poder escribirla. Un
|
|
85
|
+
cliente más viejo ve el error `locked` y no entra.
|
package/bin/terminal.js
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* dotrino-terminal kill <id> [--name <n>] cierra una consola
|
|
9
9
|
* dotrino-terminal profiles [--json] los perfiles de esta máquina (enlazados o no)
|
|
10
10
|
* dotrino-terminal link [--name <n>] enlaza un perfil con tu bóveda
|
|
11
|
-
dotrino-terminal rename <perfil> [nuevo] renombra un perfil (para su agente: cierra sus consolas)
|
|
12
11
|
* dotrino-terminal rename <perfil> [nuevo] renombra un perfil (para su agente si corre)
|
|
12
|
+
* dotrino-terminal lock [--name <n>] pone o cambia la clave que piden los otros aparatos
|
|
13
|
+
* dotrino-terminal lock --off [--name <n>] la quita
|
|
13
14
|
*
|
|
14
15
|
* Un PERFIL es un agente con nombre (`~/.dotrino/agent/terminal-agent/<nombre>/`), enlazado a
|
|
15
16
|
* una bóveda o solo local. Cada consola vive en el agente de un perfil.
|
|
@@ -33,6 +34,7 @@ import { resolveInstance, isValidName } from '@dotrino/remote-agent/instances'
|
|
|
33
34
|
import readline from 'node:readline'
|
|
34
35
|
import { connectLocal } from '../local.js'
|
|
35
36
|
import { titleFilter } from '../title.js'
|
|
37
|
+
import { hasAccessCode, setAccessCode, clearAccessCode, MIN_LENGTH } from '../access.js'
|
|
36
38
|
|
|
37
39
|
const { version: VERSION } = createRequire(import.meta.url)('../package.json')
|
|
38
40
|
const args = process.argv.slice(2)
|
|
@@ -53,6 +55,10 @@ if (args.includes('-h') || args.includes('--help')) {
|
|
|
53
55
|
dotrino-terminal profiles [--json] los perfiles de esta máquina
|
|
54
56
|
dotrino-terminal link [--name <n>] enlaza un perfil con tu bóveda
|
|
55
57
|
dotrino-terminal rename <perfil> [nuevo] renombra un perfil (para su agente: cierra sus consolas)
|
|
58
|
+
dotrino-terminal lock [--name <n>] pone o cambia la clave (PIN o contraseña) que tus otros
|
|
59
|
+
aparatos tienen que escribir para abrir consolas aquí
|
|
60
|
+
dotrino-terminal lock --off [--name <n>] quita la clave
|
|
61
|
+
dotrino-terminal lock --status [--name <n>] dice si hay clave
|
|
56
62
|
|
|
57
63
|
Dentro de una consola: Ctrl+] y luego d la suelta sin cerrarla; Ctrl+] n abre otra
|
|
58
64
|
(y suelta la actual); Ctrl+] a <id> Enter pasa a esa consola; Ctrl+] p fija el tamaño de la
|
|
@@ -65,6 +71,10 @@ Cerrar la ventana cierra la consola que abrió.`, `usage:
|
|
|
65
71
|
dotrino-terminal profiles [--json] this machine's profiles
|
|
66
72
|
dotrino-terminal link [--name <n>] link a profile with your vault
|
|
67
73
|
dotrino-terminal rename <profile> [new] rename a profile (stops its agent: closes its consoles)
|
|
74
|
+
dotrino-terminal lock [--name <n>] set or change the code (PIN or password) your other
|
|
75
|
+
devices must type to open consoles here
|
|
76
|
+
dotrino-terminal lock --off [--name <n>] remove the code
|
|
77
|
+
dotrino-terminal lock --status [--name <n>] say whether there is a code
|
|
68
78
|
|
|
69
79
|
Inside a console: Ctrl+] then d detaches without closing it; Ctrl+] n opens another
|
|
70
80
|
(detaching the current one); Ctrl+] a <id> Enter switches to that console; Ctrl+] p pins the
|
|
@@ -173,6 +183,60 @@ function ask (q) {
|
|
|
173
183
|
return new Promise((resolve) => rl.question(q, (a) => { rl.close(); resolve(a.trim()) }))
|
|
174
184
|
}
|
|
175
185
|
|
|
186
|
+
/** Pregunta algo que no debe verse al teclearlo. Solo en una TTY: una clave no se pasa por una tubería. */
|
|
187
|
+
function askHidden (q) {
|
|
188
|
+
if (!process.stdin.isTTY) die(t('la clave se teclea: hace falta una terminal', 'the code is typed: a terminal is needed'))
|
|
189
|
+
process.stdout.write(q)
|
|
190
|
+
process.stdin.setRawMode(true)
|
|
191
|
+
process.stdin.resume()
|
|
192
|
+
return new Promise((resolve) => {
|
|
193
|
+
let typed = ''
|
|
194
|
+
const onData = (b) => {
|
|
195
|
+
for (const ch of b.toString('utf8')) {
|
|
196
|
+
if (ch === '\r' || ch === '\n') {
|
|
197
|
+
process.stdin.off('data', onData); process.stdin.setRawMode(false); process.stdin.pause()
|
|
198
|
+
process.stdout.write('\n'); resolve(typed); return
|
|
199
|
+
}
|
|
200
|
+
if (ch === '\x03') { process.stdin.setRawMode(false); process.stdout.write('\n'); process.exit(130) }
|
|
201
|
+
if (ch === '\x7f' || ch === '\b') typed = typed.slice(0, -1)
|
|
202
|
+
else if (ch >= ' ') typed += ch
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
process.stdin.on('data', onData)
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* La clave de esta máquina (access.js). Se pone AQUÍ, en la máquina, y la piden solo los otros
|
|
211
|
+
* aparatos: quien está sentado delante ya es el usuario que puede leer y borrar el archivo, así
|
|
212
|
+
* que ni cambiarla ni quitarla piden la anterior. Vale al momento, sin reiniciar el agente.
|
|
213
|
+
*/
|
|
214
|
+
async function lock () {
|
|
215
|
+
const dir = opt('--dir') || dataDir(opt('--name'))
|
|
216
|
+
if (args.includes('--status')) {
|
|
217
|
+
console.log(hasAccessCode(dir)
|
|
218
|
+
? t('Hay clave: tus otros aparatos la escriben para abrir consolas en esta máquina.', 'There is a code: your other devices type it to open consoles on this machine.')
|
|
219
|
+
: t('Sin clave: cualquier aparato de tu cuenta abre consolas en esta máquina.', 'No code: any device of your account opens consoles on this machine.'))
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
if (args.includes('--off')) {
|
|
223
|
+
if (!hasAccessCode(dir)) { console.log(t('Esta máquina no tenía clave.', 'This machine had no code.')); return }
|
|
224
|
+
clearAccessCode(dir)
|
|
225
|
+
console.log(t('Clave quitada. Cualquier aparato de tu cuenta vuelve a abrir consolas aquí.', 'Code removed. Any device of your account opens consoles here again.'))
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 })
|
|
229
|
+
const changing = hasAccessCode(dir)
|
|
230
|
+
const first = await askHidden(t(`Clave nueva (PIN o contraseña, mínimo ${MIN_LENGTH}): `, `New code (PIN or password, at least ${MIN_LENGTH}): `))
|
|
231
|
+
if (first.length < MIN_LENGTH) die(t(`demasiado corta: mínimo ${MIN_LENGTH} caracteres`, `too short: at least ${MIN_LENGTH} characters`))
|
|
232
|
+
const again = await askHidden(t('Otra vez: ', 'Again: '))
|
|
233
|
+
if (again !== first) die(t('no coinciden. No se cambió nada.', 'they do not match. Nothing was changed.'))
|
|
234
|
+
setAccessCode(dir, first)
|
|
235
|
+
console.log(changing
|
|
236
|
+
? t('Clave cambiada. Los aparatos que ya estaban dentro siguen hasta que se desconecten.', 'Code changed. Devices already in stay until they disconnect.')
|
|
237
|
+
: t('Clave puesta. Tus otros aparatos la escriben para abrir consolas en esta máquina; las ventanas de esta máquina no la piden.', 'Code set. Your other devices type it to open consoles on this machine; this machine\'s own windows do not ask for it.'))
|
|
238
|
+
}
|
|
239
|
+
|
|
176
240
|
/**
|
|
177
241
|
* Renombra un perfil: su carpeta, nada más. Es el mismo aparato con la misma llave, así que el
|
|
178
242
|
* acta no se entera ni hace falta volver a enrolar. El nombre es solo tuyo, de esta máquina.
|
|
@@ -435,6 +499,7 @@ try {
|
|
|
435
499
|
if (cmd === 'profiles') { await profiles(); process.exit(0) }
|
|
436
500
|
if (cmd === 'link') { await link(); process.exit(0) }
|
|
437
501
|
if (cmd === 'rename') { await rename(); process.exit(0) }
|
|
502
|
+
if (cmd === 'lock') { await lock(); process.exit(0) }
|
|
438
503
|
const dir = opt('--dir') || dataDir(opt('--name'))
|
|
439
504
|
if (cmd === 'open' || cmd === 'attach') captureEarly()
|
|
440
505
|
const conn = await agent(dir)
|
package/consoles.js
CHANGED
|
@@ -24,30 +24,19 @@ export const SCROLLBACK = 1000
|
|
|
24
24
|
/** Tamaño máximo de cada trozo de la repetición: el proxio corta los mensajes a 1 MB. */
|
|
25
25
|
export const REPLAY_CHUNK = 64 * 1024
|
|
26
26
|
|
|
27
|
-
// ¿ESTÁ TRABAJANDO? Lo que el panel enseña con un color por consola.
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
27
|
+
// ¿ESTÁ TRABAJANDO? Lo que el panel enseña con un color por consola. UNA regla, sin leer lo que
|
|
28
|
+
// dice la pantalla ni el título (dueño, 2026-10-06): si el TÍTULO o el CONTENIDO cambian de
|
|
29
|
+
// seguido, trabaja; si llevan un rato sin cambiar, está quieta. Sirve igual para cualquier
|
|
30
|
+
// agente — medidos Claude Code y Codex (giran el título), y OpenCode (anima la pantalla): los
|
|
31
|
+
// tres cambian algo al menos una vez por segundo mientras trabajan y se callan al terminar.
|
|
32
32
|
// «Terminó» (`doneAt`) queda marcado hasta que alguien entra a la consola o teclea en ella: es
|
|
33
33
|
// lo que avisa de que un agente acabó mientras mirabas otra cosa. Una campana (BEL) lo marca igual.
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (IDLE_GLYPHS.test(t)) return false
|
|
41
|
-
return null
|
|
42
|
-
}
|
|
43
|
-
const ECHO_MS = 400 // salida tan pegada a una tecla es su eco, no trabajo
|
|
44
|
-
const SUSTAIN_MS = 1500 // salida propia durante este rato = está trabajando
|
|
45
|
-
const GAP_MS = 1000 // un hueco mayor que este corta la racha: no era salida seguida
|
|
46
|
-
// EL RESPALDO, para quien no lo dice en el título (OpenCode, un comando cualquiera): si la
|
|
47
|
-
// pantalla no cambia en este rato, la consola está quieta. Un minuto por defecto (dueño,
|
|
48
|
-
// 2026-10-06): un programa que piensa en silencio unos segundos no debe darse por terminado.
|
|
49
|
-
// `DOTRINO_TERMINAL_IDLE_SECONDS` lo cambia; quien lo dice en el título no espera a esto.
|
|
50
|
-
export const QUIET_MS = Math.max(1, Number(process.env.DOTRINO_TERMINAL_IDLE_SECONDS) || 60) * 1000
|
|
34
|
+
const ECHO_MS = 400 // un cambio tan pegado a una tecla es su eco, no trabajo
|
|
35
|
+
const SUSTAIN_MS = 1500 // cambios seguidos durante este rato = está trabajando
|
|
36
|
+
const GAP_MS = 2000 // un hueco mayor que este corta la racha: eran cambios sueltos
|
|
37
|
+
// Sin cambios en este rato, la consola está quieta. `DOTRINO_TERMINAL_IDLE_SECONDS` lo cambia.
|
|
38
|
+
// Diez segundos: de sobra para un agente, y un comando que calle más se da por terminado pronto.
|
|
39
|
+
export const QUIET_MS = Math.max(1, Number(process.env.DOTRINO_TERMINAL_IDLE_SECONDS) || 10) * 1000
|
|
51
40
|
const MIN_TASK_MS = 3000 // menos que esto no fue «una tarea»: no se marca como terminada
|
|
52
41
|
|
|
53
42
|
const randomId = () => [...crypto.getRandomValues(new Uint8Array(8))].map((x) => x.toString(16).padStart(2, '0')).join('')
|
|
@@ -80,31 +69,37 @@ class Console {
|
|
|
80
69
|
this.busySince = 0
|
|
81
70
|
this.doneAt = null // terminó (o pidió atención) y nadie lo ha atendido
|
|
82
71
|
this.lastInput = 0
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
85
|
-
this._lastOwnOut = 0
|
|
72
|
+
this._changing = 0 // desde cuándo hay cambios seguidos
|
|
73
|
+
this._lastChange = 0
|
|
86
74
|
this._quiet = null
|
|
87
75
|
this.screen.onTitleChange((t) => {
|
|
88
76
|
this.title = String(t).slice(0, 200)
|
|
89
|
-
|
|
90
|
-
const before = this._titleSays
|
|
91
|
-
this._titleSays = says
|
|
92
|
-
// Cuando el programa lo dice, manda él; si DEJA de decirlo (salió), ya no está trabajando.
|
|
93
|
-
// Un título que nunca dijo nada (el de la shell) no toca lo que se dedujo de la salida.
|
|
94
|
-
let changed = false
|
|
95
|
-
if (says !== null) changed = this._setBusy(says)
|
|
96
|
-
else if (before !== null) changed = this._setBusy(false)
|
|
97
|
-
if (!changed) this._meta()
|
|
77
|
+
if (!this._changed(Date.now())) this._meta()
|
|
98
78
|
})
|
|
99
79
|
this.screen.onBell(() => { this.doneAt = Date.now(); this._meta() })
|
|
100
80
|
}
|
|
101
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Algo cambió (el título o el contenido). Cambios seguidos encienden «trabajando»; un rato sin
|
|
84
|
+
* ninguno lo apaga. Dos cambios sueltos (el prompt que se redibuja, un comando instantáneo) no
|
|
85
|
+
* son un programa trabajando. Devuelve si avisó a quien mira.
|
|
86
|
+
*/
|
|
87
|
+
_changed (now) {
|
|
88
|
+
if (now - this.lastInput <= ECHO_MS) return false
|
|
89
|
+
if (!this._changing || now - this._lastChange > GAP_MS) this._changing = now
|
|
90
|
+
this._lastChange = now
|
|
91
|
+
clearTimeout(this._quiet)
|
|
92
|
+
this._quiet = setTimeout(() => { this._changing = 0; this._setBusy(false) }, this.quietMs)
|
|
93
|
+
this._quiet.unref?.()
|
|
94
|
+
return now - this._changing >= SUSTAIN_MS ? this._setBusy(true) : false
|
|
95
|
+
}
|
|
96
|
+
|
|
102
97
|
/** Cambia «trabajando». Al dejar de trabajar tras una tarea de verdad, queda como terminada. */
|
|
103
98
|
_setBusy (v) {
|
|
104
99
|
if (v === this.busy) return false
|
|
105
|
-
const now = Date.now()
|
|
106
100
|
this.busy = v
|
|
107
|
-
|
|
101
|
+
// La tarea duró hasta el ÚLTIMO cambio, no hasta que se notó el silencio.
|
|
102
|
+
if (v) { this.busySince = this._changing; this.doneAt = null } else if (this._lastChange - this.busySince >= MIN_TASK_MS) this.doneAt = Date.now()
|
|
108
103
|
this._meta()
|
|
109
104
|
return true
|
|
110
105
|
}
|
|
@@ -126,19 +121,7 @@ class Console {
|
|
|
126
121
|
_out (data) {
|
|
127
122
|
const now = Date.now()
|
|
128
123
|
this.lastActive = now
|
|
129
|
-
|
|
130
|
-
if (this._titleSays === null) {
|
|
131
|
-
if (now - this.lastInput > ECHO_MS) {
|
|
132
|
-
// SOSTENIDA = seguida: dos ráfagas sueltas (el prompt que se redibuja al cambiar el
|
|
133
|
-
// tamaño, y otra cosa segundos después) no son un programa trabajando.
|
|
134
|
-
if (!this._outSince || now - this._lastOwnOut > GAP_MS) this._outSince = now
|
|
135
|
-
this._lastOwnOut = now
|
|
136
|
-
if (now - this._outSince >= SUSTAIN_MS) this._setBusy(true)
|
|
137
|
-
}
|
|
138
|
-
clearTimeout(this._quiet)
|
|
139
|
-
this._quiet = setTimeout(() => { this._outSince = 0; if (this._titleSays === null) this._setBusy(false) }, this.quietMs)
|
|
140
|
-
this._quiet.unref?.()
|
|
141
|
-
}
|
|
124
|
+
this._changed(now)
|
|
142
125
|
this.screen.write(data)
|
|
143
126
|
for (const v of this.viewers) v.onOut(data)
|
|
144
127
|
}
|
package/index.js
CHANGED
|
@@ -13,10 +13,16 @@
|
|
|
13
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 } · { type:'pin', on } ·
|
|
16
|
-
* { type:'close' } (mata la consola enganchada) · { type:'kill', id }
|
|
16
|
+
* { type:'close' } (mata la consola enganchada) · { type:'kill', id } ·
|
|
17
|
+
* { type:'unlock', code } (la clave de la máquina, si tiene: access.js)
|
|
17
18
|
* agente → cliente: { type:'consoles', list } · { type:'attached', id, fresh } ·
|
|
18
19
|
* { type:'replay', id, data, last } · { type:'out', data } ·
|
|
19
|
-
* { type:'exit', code, closedBy? } · { type:'fail', code, message }
|
|
20
|
+
* { type:'exit', code, closedBy? } · { type:'fail', code, message, retryMs? } ·
|
|
21
|
+
* { type:'unlocked' }
|
|
22
|
+
*
|
|
23
|
+
* Con clave puesta, una sesión remota que no la ha escrito recibe `fail` con `code:'locked'`
|
|
24
|
+
* a todo lo que pida; tras `unlock` vale para esa conexión. `bad-code` y `wait` traen
|
|
25
|
+
* `retryMs` cuando toca esperar.
|
|
20
26
|
*/
|
|
21
27
|
import fs from 'node:fs'
|
|
22
28
|
import os from 'node:os'
|
|
@@ -26,6 +32,7 @@ import { startRemoteAgent } from '@dotrino/remote-agent/agent'
|
|
|
26
32
|
import { dataDir, loadLink, LABEL } from './link.js'
|
|
27
33
|
import { ConsoleHub, REPLAY_CHUNK } from './consoles.js'
|
|
28
34
|
import { listenLocal } from './local.js'
|
|
35
|
+
import { makeGate } from './access.js'
|
|
29
36
|
|
|
30
37
|
const require = createRequire(import.meta.url)
|
|
31
38
|
|
|
@@ -78,9 +85,10 @@ export function makeHub (pty, opts = {}) {
|
|
|
78
85
|
*
|
|
79
86
|
* @param {object} session
|
|
80
87
|
* @param {ConsoleHub} hub
|
|
81
|
-
* @param {{ origin?: 'local'|'remote' }} [opts]
|
|
88
|
+
* @param {{ origin?: 'local'|'remote', gate?: ReturnType<typeof makeGate> }} [opts] `gate`: la
|
|
89
|
+
* clave de la máquina (access.js). Solo se le pide a las sesiones remotas.
|
|
82
90
|
*/
|
|
83
|
-
export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
91
|
+
export function serveSession (session, hub, { origin = 'remote', gate = null } = {}) {
|
|
84
92
|
let current = null
|
|
85
93
|
let owned = null // la consola que esta ventana local abrió
|
|
86
94
|
let size = { cols: 80, rows: 24 }
|
|
@@ -93,7 +101,18 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
93
101
|
onMeta: (info) => { session.send({ type: 'meta', console: info }) }
|
|
94
102
|
}
|
|
95
103
|
const release = () => { if (current) { current.detach(viewer); current = null } }
|
|
96
|
-
const fail = (code, message) => session.send({ type: 'fail', code, message })
|
|
104
|
+
const fail = (code, message, extra = {}) => session.send({ type: 'fail', code, message, ...extra })
|
|
105
|
+
// La clave de la máquina: una vez escrita vale para ESTA conexión.
|
|
106
|
+
let unlocked = false
|
|
107
|
+
/** True si esta sesión puede seguir; si no, ya contestó por qué. No saber si hay clave = no pasa. */
|
|
108
|
+
const mayPass = () => {
|
|
109
|
+
if (origin !== 'remote' || !gate || unlocked) return true
|
|
110
|
+
try {
|
|
111
|
+
if (!gate.required()) return true
|
|
112
|
+
} catch (e) { fail(e.code || 'access-unreadable', e.message); return false }
|
|
113
|
+
fail('locked', 'this machine asks for its code')
|
|
114
|
+
return false
|
|
115
|
+
}
|
|
97
116
|
const takeSize = (msg) => { if (msg.cols && msg.rows) { size = { cols: msg.cols, rows: msg.rows }; viewer.size = size } }
|
|
98
117
|
// La etiqueta con la que se presenta quien mira (una ventana de la app de escritorio).
|
|
99
118
|
const takeTag = (msg) => { if (typeof msg.tag === 'string') viewer.tag = msg.tag.slice(0, 64) }
|
|
@@ -112,6 +131,16 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
112
131
|
|
|
113
132
|
session.on('message', (msg) => {
|
|
114
133
|
if (!msg || typeof msg !== 'object') return
|
|
134
|
+
if (msg.type === 'unlock') {
|
|
135
|
+
if (origin !== 'remote' || !gate) { session.send({ type: 'unlocked' }); return }
|
|
136
|
+
try {
|
|
137
|
+
if (gate.required()) gate.check(msg.code)
|
|
138
|
+
unlocked = true
|
|
139
|
+
session.send({ type: 'unlocked' })
|
|
140
|
+
} catch (e) { fail(e.code || 'access-unreadable', e.message, e.retryMs ? { retryMs: e.retryMs } : {}) }
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
if (!mayPass()) return
|
|
115
144
|
if (msg.type === 'list') { session.send({ type: 'consoles', list: hub.list() }); return }
|
|
116
145
|
if (msg.type === 'open') {
|
|
117
146
|
takeSize(msg)
|
|
@@ -172,6 +201,7 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
172
201
|
export async function startAgent (opts = {}) {
|
|
173
202
|
const dir = opts.dir || dataDir()
|
|
174
203
|
const hub = makeHub(loadPty(), { ...opts, dir })
|
|
204
|
+
const gate = makeGate(dir)
|
|
175
205
|
const local = await listenLocal({ dir, serve: (session) => serveSession(session, hub, { origin: 'local' }) })
|
|
176
206
|
let remote = null
|
|
177
207
|
let stopped = false
|
|
@@ -181,7 +211,7 @@ export async function startAgent (opts = {}) {
|
|
|
181
211
|
proxyUrl: opts.proxyUrl,
|
|
182
212
|
quiet: opts.quiet,
|
|
183
213
|
onRevoked: () => { hub.killAll(); opts.onRevoked?.() },
|
|
184
|
-
onSession: (session) => serveSession(session, hub, { origin: 'remote' })
|
|
214
|
+
onSession: (session) => serveSession(session, hub, { origin: 'remote', gate })
|
|
185
215
|
})
|
|
186
216
|
let watcher = null
|
|
187
217
|
if (loadLink(dir)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.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": {
|