@dotrino/terminal-agent 0.50.1 → 0.52.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 +61 -3
- package/clipboard.js +115 -0
- package/far.js +2 -1
- package/index.js +8 -0
- package/package.json +6 -5
package/bin/terminal.js
CHANGED
|
@@ -50,6 +50,7 @@ import { resolveInstance, isValidName } from '@dotrino/remote-agent/instances'
|
|
|
50
50
|
import readline from 'node:readline'
|
|
51
51
|
import { connectLocal } from '../local.js'
|
|
52
52
|
import { titleFilter } from '../title.js'
|
|
53
|
+
import { clipboardImage, uploadImage, typedPath } from '../clipboard.js'
|
|
53
54
|
import { farMessage as farMessageFor } from '../far-messages.js'
|
|
54
55
|
import { hasAccessCode, setAccessCode, clearAccessCode, MIN_LENGTH } from '../access.js'
|
|
55
56
|
import { configureEditors, terminalProfile } from '../editors.js'
|
|
@@ -859,6 +860,11 @@ async function note () {
|
|
|
859
860
|
}
|
|
860
861
|
}
|
|
861
862
|
|
|
863
|
+
/** Ctrl+V: con una imagen copiada y la consola en otra máquina, se sube la imagen. */
|
|
864
|
+
const PASTE_KEY = '\x16'
|
|
865
|
+
/** Los fallos que contesta la máquina a una subida: son de la subida, no cierran la ventana. */
|
|
866
|
+
const UPLOAD_FAILS = new Set(['not-image', 'too-big', 'bad-file', 'no-uploads', 'file-failed'])
|
|
867
|
+
|
|
862
868
|
/** La ventana: la TTY enganchada a una consola del agente. */
|
|
863
869
|
function interactive (conn, first, dir) {
|
|
864
870
|
// Hasta que el agente diga `attached` no hay consola a la que escribir: se guarda.
|
|
@@ -877,10 +883,19 @@ function interactive (conn, first, dir) {
|
|
|
877
883
|
let remote = new Set()
|
|
878
884
|
let ending = false
|
|
879
885
|
|
|
886
|
+
// Lo que se dice un momento en el título (mandar una imagen): la pantalla es del programa.
|
|
887
|
+
let status = ''
|
|
888
|
+
let statusTimer = null
|
|
880
889
|
const showTitle = () => {
|
|
881
890
|
const base = subject || shellTitle || 'Dotrino Terminal'
|
|
882
891
|
const mark = remote.size ? ` ● ${t('abierta desde otro aparato', 'open on another device')}${remote.size > 1 ? ` ×${remote.size}` : ''}` : ''
|
|
883
|
-
out.write(`\x1b]2;${base}${mark}\x07`)
|
|
892
|
+
out.write(`\x1b]2;${base}${mark}${status ? ` · ${status}` : ''}\x07`)
|
|
893
|
+
}
|
|
894
|
+
const say = (text, ms = 0) => {
|
|
895
|
+
clearTimeout(statusTimer)
|
|
896
|
+
status = text
|
|
897
|
+
showTitle()
|
|
898
|
+
if (ms) statusTimer = setTimeout(() => { status = ''; showTitle() }, ms)
|
|
884
899
|
}
|
|
885
900
|
const onInfo = (info) => {
|
|
886
901
|
if (!info) return
|
|
@@ -950,9 +965,19 @@ function interactive (conn, first, dir) {
|
|
|
950
965
|
showEmpty()
|
|
951
966
|
})
|
|
952
967
|
}
|
|
968
|
+
// ¿El programa pidió pegado entre corchetes? Así recibe la ruta de una imagen como algo
|
|
969
|
+
// pegado, que es como Claude Code reconoce un archivo.
|
|
970
|
+
let bracketed = false
|
|
971
|
+
const watchModes = (data) => {
|
|
972
|
+
const all = [...String(data).matchAll(/\x1b\[\?2004([hl])/g)]
|
|
973
|
+
if (all.length) bracketed = all[all.length - 1][1] === 'h'
|
|
974
|
+
}
|
|
975
|
+
// La subida en curso: sus respuestas (`filed`, o un `fail` suyo) son de ella y de nadie más.
|
|
976
|
+
let uploadReply = null
|
|
953
977
|
conn.on('message', (m) => {
|
|
954
978
|
if (m.type === 'replay' && !clean) { clean = true; out.write('\x1b[H\x1b[2J') }
|
|
955
|
-
if (m.type === 'out' || m.type === 'replay') { out.write(filter(m.data)); return }
|
|
979
|
+
if (m.type === 'out' || m.type === 'replay') { watchModes(m.data); out.write(filter(m.data)); return }
|
|
980
|
+
if (uploadReply && (m.type === 'filed' || (m.type === 'fail' && UPLOAD_FAILS.has(m.code)))) { const r = uploadReply; uploadReply = null; r(m); return }
|
|
956
981
|
if (m.type === 'attached') {
|
|
957
982
|
switching = false; recovering = false
|
|
958
983
|
consoleId = m.id
|
|
@@ -1064,10 +1089,43 @@ function interactive (conn, first, dir) {
|
|
|
1064
1089
|
}
|
|
1065
1090
|
send += ch === DETACH_PREFIX ? ch : DETACH_PREFIX + ch
|
|
1066
1091
|
} else if (ch === DETACH_PREFIX) prefixed = true
|
|
1067
|
-
else
|
|
1092
|
+
else if (ch === PASTE_KEY && opt('--machine')) {
|
|
1093
|
+
if (send) { input(send); send = '' }
|
|
1094
|
+
pasteImage()
|
|
1095
|
+
} else send += ch
|
|
1068
1096
|
}
|
|
1069
1097
|
if (send) input(send)
|
|
1070
1098
|
}
|
|
1099
|
+
// CTRL+V EN UNA CONSOLA DE OTRA MÁQUINA. Con una imagen copiada, el programa de la consola
|
|
1100
|
+
// (Claude Code) la busca en el portapapeles de AQUELLA máquina, y la imagen está en esta: no
|
|
1101
|
+
// salía nada. Si aquí hay una imagen, se sube (la misma subida que usa el teléfono) y se pega
|
|
1102
|
+
// la ruta donde quedó. Sin imagen, Ctrl+V sigue su camino, como siempre.
|
|
1103
|
+
let pasting = false
|
|
1104
|
+
const ask = (msg) => new Promise((resolve) => {
|
|
1105
|
+
const timer = setTimeout(() => { uploadReply = null; resolve({ type: 'fail', code: 'timeout', message: 'the machine did not answer (its agent may predate 0.43)' }) }, 20000)
|
|
1106
|
+
uploadReply = (m) => { clearTimeout(timer); resolve(m) }
|
|
1107
|
+
conn.send(msg)
|
|
1108
|
+
})
|
|
1109
|
+
const pasteImage = async () => {
|
|
1110
|
+
if (pasting) return
|
|
1111
|
+
pasting = true
|
|
1112
|
+
try {
|
|
1113
|
+
let bytes
|
|
1114
|
+
try { bytes = await clipboardImage() } catch (e) {
|
|
1115
|
+
say(t(`no pude leer el portapapeles (${e.code})`, `could not read the clipboard (${e.code})`), 8000)
|
|
1116
|
+
input(PASTE_KEY)
|
|
1117
|
+
return
|
|
1118
|
+
}
|
|
1119
|
+
if (!bytes) { input(PASTE_KEY); return }
|
|
1120
|
+
say(t('mandando la imagen…', 'sending the image…'))
|
|
1121
|
+
const where = await uploadImage(ask, bytes)
|
|
1122
|
+
const text = typedPath(where) + ' '
|
|
1123
|
+
input(bracketed ? `\x1b[200~${text}\x1b[201~` : text)
|
|
1124
|
+
say(t('imagen enviada', 'image sent'), 3000)
|
|
1125
|
+
} catch (e) {
|
|
1126
|
+
say(t(`no se pudo mandar la imagen: ${e.message} (${e.code || '?'})`, `could not send the image: ${e.message} (${e.code || '?'})`), 10000)
|
|
1127
|
+
} finally { pasting = false }
|
|
1128
|
+
}
|
|
1071
1129
|
process.stdin.on('data', onKeys)
|
|
1072
1130
|
// Lo tecleado antes de llegar aquí pasa por el mismo camino (el atajo de soltar incluido).
|
|
1073
1131
|
for (const b of early.splice(0)) onKeys(b)
|
package/clipboard.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* clipboard.js — la imagen del portapapeles de ESTA máquina, para mandarla a otra.
|
|
3
|
+
*
|
|
4
|
+
* Para qué: Ctrl+V con una imagen copiada hace que el programa de la consola (Claude Code) la
|
|
5
|
+
* busque en el portapapeles de la máquina donde corre. Si la consola es de OTRA máquina
|
|
6
|
+
* (`--machine`), allí no hay nada: la imagen está aquí. El cliente la lee con esto, la sube
|
|
7
|
+
* (uploads.js, la misma subida que usa el teléfono) y pega la ruta donde quedó.
|
|
8
|
+
*
|
|
9
|
+
* Cada sistema la da con su herramienta: `wl-paste` (Wayland), `xclip` (X11), `osascript`
|
|
10
|
+
* (macOS) y PowerShell (Windows). Devuelve `null` si en el portapapeles no hay imagen, que es
|
|
11
|
+
* lo normal (entonces Ctrl+V sigue su camino), y lanza con `code` si no se pudo mirar.
|
|
12
|
+
*/
|
|
13
|
+
import { execFile } from 'node:child_process'
|
|
14
|
+
|
|
15
|
+
/** Los tipos que admite la subida (uploads.js), en orden de preferencia. */
|
|
16
|
+
export const IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp']
|
|
17
|
+
|
|
18
|
+
const fail = (code, message) => Object.assign(new Error(message), { code })
|
|
19
|
+
|
|
20
|
+
/** Corre una herramienta y devuelve su salida en bytes. */
|
|
21
|
+
function runTool (cmd, args) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
execFile(cmd, args, { encoding: 'buffer', maxBuffer: 64 * 1024 * 1024, timeout: 5000, windowsHide: true }, (err, stdout) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
if (err.code === 'ENOENT') return reject(fail('no-clipboard-tool', `${cmd} is not installed`))
|
|
26
|
+
// Sin imagen, varias herramientas salen con error (xclip: «target … not available»).
|
|
27
|
+
return reject(Object.assign(err, { code: 'clipboard-empty' }))
|
|
28
|
+
}
|
|
29
|
+
resolve(stdout)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** De la lista de tipos que ofrece el portapapeles, el de imagen que se manda, o null. */
|
|
35
|
+
export function pickImageType (targets) {
|
|
36
|
+
const offered = new Set(String(targets).split(/\r?\n/).map((s) => s.trim()).filter(Boolean))
|
|
37
|
+
return IMAGE_TYPES.find((t) => offered.has(t)) || null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Lo que contesta `osascript` (`«data PNGf89504E…»`), en bytes; null si no es eso. */
|
|
41
|
+
export function parseAppleData (text) {
|
|
42
|
+
const m = /«data PNGf([0-9A-Fa-f]+)»/.exec(String(text))
|
|
43
|
+
return m ? Buffer.from(m[1], 'hex') : null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const WINDOWS_SCRIPT = [
|
|
47
|
+
'Add-Type -AssemblyName System.Windows.Forms',
|
|
48
|
+
'Add-Type -AssemblyName System.Drawing',
|
|
49
|
+
'$i = [Windows.Forms.Clipboard]::GetImage()',
|
|
50
|
+
'if ($i) { $m = New-Object IO.MemoryStream; $i.Save($m, [Drawing.Imaging.ImageFormat]::Png); [Convert]::ToBase64String($m.ToArray()) }',
|
|
51
|
+
].join('; ')
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* La imagen del portapapeles, o null si no hay.
|
|
55
|
+
* @param {{ platform?: string, env?: object, run?: (cmd:string, args:string[]) => Promise<Buffer> }} [opts]
|
|
56
|
+
* @returns {Promise<Buffer|null>}
|
|
57
|
+
*/
|
|
58
|
+
export async function clipboardImage ({ platform = process.platform, env = process.env, run = runTool } = {}) {
|
|
59
|
+
const quiet = async (cmd, args) => {
|
|
60
|
+
try { return await run(cmd, args) } catch (e) { if (e.code === 'clipboard-empty') return null; throw e }
|
|
61
|
+
}
|
|
62
|
+
if (platform === 'darwin') {
|
|
63
|
+
const out = await quiet('osascript', ['-e', 'the clipboard as «class PNGf»'])
|
|
64
|
+
return out ? parseAppleData(out.toString('utf8')) : null
|
|
65
|
+
}
|
|
66
|
+
if (platform === 'win32') {
|
|
67
|
+
const out = await quiet('powershell.exe', ['-NoProfile', '-STA', '-Command', WINDOWS_SCRIPT])
|
|
68
|
+
const b64 = out ? out.toString('utf8').trim() : ''
|
|
69
|
+
return b64 ? Buffer.from(b64, 'base64') : null
|
|
70
|
+
}
|
|
71
|
+
if (env.WAYLAND_DISPLAY) {
|
|
72
|
+
const type = pickImageType((await quiet('wl-paste', ['--list-types'])) || '')
|
|
73
|
+
if (!type) return null
|
|
74
|
+
return (await quiet('wl-paste', ['--no-newline', '--type', type])) || null
|
|
75
|
+
}
|
|
76
|
+
if (env.DISPLAY) {
|
|
77
|
+
const type = pickImageType((await quiet('xclip', ['-selection', 'clipboard', '-t', 'TARGETS', '-o'])) || '')
|
|
78
|
+
if (!type) return null
|
|
79
|
+
return (await quiet('xclip', ['-selection', 'clipboard', '-t', type, '-o'])) || null
|
|
80
|
+
}
|
|
81
|
+
throw fail('no-display', 'no graphical session here (neither WAYLAND_DISPLAY nor DISPLAY)')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Una ruta como se teclea en una shell: entre comillas solo si hace falta. */
|
|
85
|
+
export function typedPath (file) {
|
|
86
|
+
return /^[\w@%+=:,./-]+$/.test(file) ? file : `'${file.replace(/'/g, `'\\''`)}'`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Lo que va en cada trozo, antes de pasarlo a base64 (≤ 256 KB ya en base64: uploads.js). */
|
|
90
|
+
export const UPLOAD_PIECE = 96 * 1024
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sube una imagen a la máquina de la consola y devuelve la ruta donde quedó. Va en trozos y
|
|
94
|
+
* cada uno espera su acuse (`filed`). `ask(msg)` manda un mensaje y resuelve con la respuesta
|
|
95
|
+
* (`filed` o `fail`); un `fail` se lanza con su `code`.
|
|
96
|
+
* @param {(msg: object) => Promise<object>} ask
|
|
97
|
+
* @param {Buffer} bytes
|
|
98
|
+
* @param {{ id?: string }} [opts]
|
|
99
|
+
* @returns {Promise<string>}
|
|
100
|
+
*/
|
|
101
|
+
export async function uploadImage (ask, bytes, { id = Math.random().toString(16).slice(2, 18) } = {}) {
|
|
102
|
+
if (!bytes?.length) throw fail('not-image', 'the image is empty')
|
|
103
|
+
for (let at = 0, seq = 0; ; seq++) {
|
|
104
|
+
const end = Math.min(bytes.length, at + UPLOAD_PIECE)
|
|
105
|
+
const last = end >= bytes.length
|
|
106
|
+
const r = await ask({ type: 'file', up: id, seq, data: bytes.subarray(at, end).toString('base64'), ...(last ? { last: true } : {}) })
|
|
107
|
+
if (r.type === 'fail') throw fail(r.code || 'file-failed', r.message || 'the machine did not keep the image')
|
|
108
|
+
if (r.up !== id || r.seq !== seq) throw fail('bad-file', 'the machine answered about another image')
|
|
109
|
+
at = end
|
|
110
|
+
if (last) {
|
|
111
|
+
if (typeof r.path !== 'string' || !r.path) throw fail('bad-file', 'the machine did not say where it kept the image')
|
|
112
|
+
return r.path
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
package/far.js
CHANGED
|
@@ -287,7 +287,8 @@ export function makeFar ({ dir, loadLink, kind, discover = discoverReal, connect
|
|
|
287
287
|
})
|
|
288
288
|
rc.on('error', (e) => session.send({ type: 'fail', code: e.code || 'far-error', message: e.message }))
|
|
289
289
|
// LA SESIÓN CON LA OTRA MÁQUINA SE PERDIÓ y se abrió otra: o la máquina se reinició, o la
|
|
290
|
-
// sesión venció (
|
|
290
|
+
// sesión venció (una hora sin mensajes, SESSION_IDLE_MS: una consola quieta; la otra máquina
|
|
291
|
+
// lo avisa en el momento, remote-agent ≥ 0.27). Se pregunta a la sesión nueva:
|
|
291
292
|
// - pide la clave: DESCONECTADA. La clave guardada se olvida y el panel suelta su conexión,
|
|
292
293
|
// así deja de enseñar sus consolas y vuelve a salir «Escribir la clave» (dueño,
|
|
293
294
|
// 2026-10-27). Antes el panel la reenviaba solo y las consolas seguían a la vista.
|
package/index.js
CHANGED
|
@@ -59,6 +59,13 @@ export const HISTORY_WAIT_MS = 8000
|
|
|
59
59
|
|
|
60
60
|
export { LABEL }
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Cuánto dura sin mensajes una sesión de otro aparato (una ventana en otra máquina, el
|
|
64
|
+
* teléfono). Una consola quieta no manda nada, y con los 30 min del pilar la ventana se
|
|
65
|
+
* perdía a media tarea (dueño, 2026-11-04: «al menos debería intentar estar abierta una hora»).
|
|
66
|
+
*/
|
|
67
|
+
export const SESSION_IDLE_MS = 60 * 60_000
|
|
68
|
+
|
|
62
69
|
/** Cada cuánto mira un agente sin enlazar si ya lo enlazaron. */
|
|
63
70
|
export const LINK_POLL_MS = 2000
|
|
64
71
|
/** Cada cuánto se reintenta la parte remota cuando no pudo arrancar (sin red, proxio caído). */
|
|
@@ -360,6 +367,7 @@ export async function startAgent (opts = {}) {
|
|
|
360
367
|
dir,
|
|
361
368
|
proxyUrl: opts.proxyUrl,
|
|
362
369
|
quiet: opts.quiet,
|
|
370
|
+
sessionTtlMs: SESSION_IDLE_MS,
|
|
363
371
|
onRevoked: () => { hub.killAll(); opts.onRevoked?.() },
|
|
364
372
|
onSession: (session) => serveSession(session, hub, { origin: 'remote', gate, uploadsDir })
|
|
365
373
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.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": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"far-messages.js",
|
|
18
18
|
"editors.js",
|
|
19
19
|
"claude.js",
|
|
20
|
+
"clipboard.js",
|
|
20
21
|
"consoles.js",
|
|
21
22
|
"desktop.js",
|
|
22
23
|
"downloads.js",
|
|
@@ -35,11 +36,11 @@
|
|
|
35
36
|
"type-check": "tsc --noEmit"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@dotrino/identity": "0.
|
|
39
|
-
"@dotrino/proxy-client": "0.45.
|
|
40
|
-
"@dotrino/remote-agent": "0.
|
|
39
|
+
"@dotrino/identity": "0.135.0",
|
|
40
|
+
"@dotrino/proxy-client": "0.45.3",
|
|
41
|
+
"@dotrino/remote-agent": "0.30.0",
|
|
41
42
|
"@dotrino/update": "0.9.2",
|
|
42
|
-
"@dotrino/vault": "0.
|
|
43
|
+
"@dotrino/vault": "0.115.0",
|
|
43
44
|
"@xterm/addon-serialize": "0.13.0",
|
|
44
45
|
"@xterm/headless": "5.5.0",
|
|
45
46
|
"jsonc-parser": "3.3.1",
|