@dotrino/terminal-agent 0.54.0 → 0.54.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/access.js +29 -6
- package/bin/cli.js +7 -5
- package/bin/terminal.js +129 -34
- package/claude.js +28 -2
- package/clipboard.js +23 -7
- package/consoles.js +92 -14
- package/desktop.js +60 -20
- package/downloads.js +15 -3
- package/editors.js +22 -1
- package/far-messages.js +4 -2
- package/far.js +92 -27
- package/index.js +61 -25
- package/link.js +9 -0
- package/local.js +53 -17
- package/package.json +3 -2
- package/service.js +73 -8
- package/types/agent.d.ts +58 -0
- package/types/deps.d.ts +173 -0
- package/types/global.d.ts +4 -0
- package/update.js +9 -5
- package/uploads.js +19 -2
package/access.js
CHANGED
|
@@ -31,20 +31,28 @@ const BASE_WAIT_MS = 30_000
|
|
|
31
31
|
const MAX_WAIT_MS = 60 * 60_000
|
|
32
32
|
const SCRYPT = { N: 1 << 15, r: 8, p: 1, maxmem: 64 * 1024 * 1024 }
|
|
33
33
|
|
|
34
|
+
/** @type {(code: string, message: string, extra?: object) => Error & { code: string }} */
|
|
34
35
|
const fail = (code, message, extra = {}) => Object.assign(new Error(message), { code, ...extra })
|
|
36
|
+
/** @param {string} dir */
|
|
35
37
|
const file = (dir) => path.join(dir, ACCESS_FILE)
|
|
38
|
+
/** @type {(secret: unknown, salt: Buffer, params: import('node:crypto').ScryptOptions) => Buffer} */
|
|
36
39
|
const digest = (secret, salt, params) => crypto.scryptSync(String(secret).normalize('NFKC'), salt, 32, params)
|
|
37
40
|
|
|
38
41
|
/** Si esta máquina tiene clave. Un archivo que existe y no se puede leer NO es «sin clave»: se lanza. */
|
|
42
|
+
/** @param {string} dir */
|
|
39
43
|
export function hasAccessCode (dir) {
|
|
40
44
|
return readRecord(dir) !== null
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @param {string} dir
|
|
49
|
+
* @returns {{ v: 1, salt: string, hash: string, params: import('node:crypto').ScryptOptions } | null}
|
|
50
|
+
*/
|
|
43
51
|
function readRecord (dir) {
|
|
44
52
|
let raw
|
|
45
53
|
try { raw = fs.readFileSync(file(dir), 'utf8') } catch (e) {
|
|
46
|
-
if (e.code === 'ENOENT') return null
|
|
47
|
-
throw fail('access-unreadable', `cannot read ${ACCESS_FILE}: ${e.message}`)
|
|
54
|
+
if (/** @type {Thrown} */ (e).code === 'ENOENT') return null
|
|
55
|
+
throw fail('access-unreadable', `cannot read ${ACCESS_FILE}: ${/** @type {Thrown} */ (e).message}`)
|
|
48
56
|
}
|
|
49
57
|
let r
|
|
50
58
|
try { r = JSON.parse(raw) } catch (_) { throw fail('access-unreadable', `${ACCESS_FILE} is not valid JSON`) }
|
|
@@ -54,7 +62,11 @@ function readRecord (dir) {
|
|
|
54
62
|
return r
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Pone o cambia la clave.
|
|
67
|
+
* @param {string} dir
|
|
68
|
+
* @param {unknown} secret
|
|
69
|
+
*/
|
|
58
70
|
export function setAccessCode (dir, secret) {
|
|
59
71
|
if (typeof secret !== 'string' || secret.length < MIN_LENGTH) throw fail('too-short', `the code needs at least ${MIN_LENGTH} characters`)
|
|
60
72
|
const salt = crypto.randomBytes(16)
|
|
@@ -64,12 +76,19 @@ export function setAccessCode (dir, secret) {
|
|
|
64
76
|
fs.renameSync(tmp, file(dir))
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Quita la clave.
|
|
81
|
+
* @param {string} dir
|
|
82
|
+
*/
|
|
68
83
|
export function clearAccessCode (dir) {
|
|
69
84
|
fs.rmSync(file(dir), { force: true })
|
|
70
85
|
}
|
|
71
86
|
|
|
72
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Si `secret` es la clave de esta máquina. Sin frenos: para la orden local que la cambia.
|
|
89
|
+
* @param {string} dir
|
|
90
|
+
* @param {unknown} secret
|
|
91
|
+
*/
|
|
73
92
|
export function checkAccessCode (dir, secret) {
|
|
74
93
|
const r = readRecord(dir)
|
|
75
94
|
if (!r) throw fail('no-access-code', 'this machine has no code')
|
|
@@ -82,7 +101,7 @@ export function checkAccessCode (dir, secret) {
|
|
|
82
101
|
* La puerta de un agente: comprueba la clave y frena los fallos seguidos. Una por agente,
|
|
83
102
|
* compartida por todas sus sesiones.
|
|
84
103
|
* @param {string} dir
|
|
85
|
-
* @param {{ now?: () => number, onIncident?: (i: { device: string, tries: number }) => void }} [opts]
|
|
104
|
+
* @param {{ now?: () => number, onIncident?: ((i: { device: string, tries: number }) => void) | null }} [opts]
|
|
86
105
|
* `onIncident`: un mismo aparato (`device`, su pubkey) falló `INCIDENT_AFTER` veces seguidas.
|
|
87
106
|
* Se llama UNA vez por racha; la racha se corta al acertar.
|
|
88
107
|
*/
|
|
@@ -98,6 +117,10 @@ export function makeGate (dir, { now = Date.now, onIncident = null } = {}) {
|
|
|
98
117
|
* Lanza `wait` (con `retryMs`) o `bad-code`; si no lanza, la clave era la buena.
|
|
99
118
|
* `device` es quién la escribió (pubkey), para contar sus fallos y avisar.
|
|
100
119
|
*/
|
|
120
|
+
/**
|
|
121
|
+
* @param {unknown} secret
|
|
122
|
+
* @param {string | null} [device]
|
|
123
|
+
*/
|
|
101
124
|
check (secret, device = null) {
|
|
102
125
|
const left = until - now()
|
|
103
126
|
if (left > 0) throw fail('wait', 'too many wrong codes', { retryMs: left })
|
package/bin/cli.js
CHANGED
|
@@ -25,9 +25,11 @@ import { linkInteractive, loadLink, dataDir, LABEL } from '../link.js'
|
|
|
25
25
|
import { listInstances, lockInstance, instancesRoot } from '@dotrino/remote-agent/instances'
|
|
26
26
|
import { deviceInfo, formatDeviceInfo } from '@dotrino/vault/device-info'
|
|
27
27
|
|
|
28
|
+
/** @type {{ version: string }} */
|
|
28
29
|
const { version: VERSION } = createRequire(import.meta.url)('../package.json')
|
|
29
30
|
const args = process.argv.slice(2)
|
|
30
31
|
const cmd = args[0] && !args[0].startsWith('-') ? args[0] : 'run'
|
|
32
|
+
/** @param {string} name */
|
|
31
33
|
const opt = (name) => { const i = args.indexOf(name); return i >= 0 ? args[i + 1] : undefined }
|
|
32
34
|
|
|
33
35
|
if (args.includes('-h') || args.includes('--help')) {
|
|
@@ -64,7 +66,7 @@ if (cmd === 'update') {
|
|
|
64
66
|
// Solo las banderas de este comando: `--name`/`--dir` ya eligieron la carpeta.
|
|
65
67
|
const own = args.slice(1).filter((a, i, all) => !['--name', '--dir'].includes(a) && !['--name', '--dir'].includes(all[i - 1]))
|
|
66
68
|
r = updatePrefsCommand(own, { dir, lang: 'es' })
|
|
67
|
-
} catch (e) { console.error('error:', e.message); process.exit(1) }
|
|
69
|
+
} catch (e) { console.error('error:', /** @type {Thrown} */ (e).message); process.exit(1) }
|
|
68
70
|
if (!r.handled) { console.error('uso: dotrino-terminal-agent update [--name <n>] [--approval on|off] [--notify on|off]'); process.exit(2) }
|
|
69
71
|
;(r.ok ? console.log : console.error)(r.text)
|
|
70
72
|
process.exit(r.ok ? 0 : 2)
|
|
@@ -88,7 +90,7 @@ if (cmd === 'supervise') {
|
|
|
88
90
|
const s = supervise({ name, dir: dataDir(name), cli })
|
|
89
91
|
const bye = () => { s.stop(); process.exit(0) }
|
|
90
92
|
process.on('SIGINT', bye); process.on('SIGTERM', bye)
|
|
91
|
-
} catch (e) { console.error('error:', e.message); process.exit(1) }
|
|
93
|
+
} catch (e) { console.error('error:', /** @type {Thrown} */ (e).message); process.exit(1) }
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
// `info`: la pieza común del ecosistema (`@dotrino/vault/device-info`). Lo que se viene a
|
|
@@ -104,7 +106,7 @@ if (cmd === 'info') {
|
|
|
104
106
|
const pending = updateStatusText({ dir, current: VERSION, lang: 'es' })
|
|
105
107
|
if (args.includes('--json')) console.log(JSON.stringify(pending ? { ...info, update: pending } : info, null, 2))
|
|
106
108
|
else console.log(formatDeviceInfo(info) + (pending ? '\n' + pending : ''))
|
|
107
|
-
} catch (e) { console.error('error:', e.message); process.exit(1) }
|
|
109
|
+
} catch (e) { console.error('error:', /** @type {Thrown} */ (e).message); process.exit(1) }
|
|
108
110
|
process.exit(0)
|
|
109
111
|
}
|
|
110
112
|
|
|
@@ -126,7 +128,7 @@ if (cmd !== 'supervise') try {
|
|
|
126
128
|
const agent = await startAgent({
|
|
127
129
|
dir, proxyUrl: opt('--proxy'), shell: opt('--shell'),
|
|
128
130
|
onRevoked: () => { console.log(' Esta máquina se quitó de tu bóveda. Para volver a usarla, enlázala otra vez.\n'); process.exit(0) },
|
|
129
|
-
onLinked: (r) => console.log(` enlazada: máquina ${r.machineId}. Tus otros aparatos ya pueden abrir estas consolas.\n`),
|
|
131
|
+
onLinked: (/** @type {import('@dotrino/remote-agent/agent').RemoteAgent} */ r) => console.log(` enlazada: máquina ${r.machineId}. Tus otros aparatos ya pueden abrir estas consolas.\n`),
|
|
130
132
|
onLinkError: (e) => console.error('[terminal-agent] linked, but the remote side did not start:', e.message)
|
|
131
133
|
})
|
|
132
134
|
console.log('\n Dotrino Terminal — agente activo')
|
|
@@ -144,6 +146,6 @@ if (cmd !== 'supervise') try {
|
|
|
144
146
|
const bye = () => { clearInterval(keepAlive); stopUpdates(); agent.close(); process.exit(0) }
|
|
145
147
|
process.on('SIGINT', bye); process.on('SIGTERM', bye)
|
|
146
148
|
} catch (e) {
|
|
147
|
-
console.error('error:', e.message)
|
|
149
|
+
console.error('error:', /** @type {Thrown} */ (e).message)
|
|
148
150
|
process.exit(1)
|
|
149
151
|
}
|