@dotrino/terminal-agent 0.47.1 → 0.47.3

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 CHANGED
@@ -202,4 +202,4 @@ manda la llave en su primera línea (`{ type:'local-auth', key }`) y sin ella el
202
202
  contestar: la lista de tuberías la ve cualquier usuario de la máquina, la carpeta del perfil no.
203
203
  En PowerShell, con la política de ejecución por defecto, npm deja `dotrino-terminal.ps1` y Windows
204
204
  no lo deja correr: se llama `dotrino-terminal.cmd` (o se permite con
205
- `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`). La app de escritorio (`desktop/`) todavía no tiene versión para Windows.
205
+ `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`). La app de escritorio también corre en Windows (≥ 0.2.73): lanza el cliente como `node terminal.js` (no por el `.cmd`, que metería un `cmd.exe` en medio) y habla con el agente por la misma tubería.
package/bin/terminal.js CHANGED
@@ -202,7 +202,10 @@ function captureEarly () {
202
202
 
203
203
  /** El agente de esta máquina; si no hay ninguno escuchando, lo levanta y espera a que conteste. */
204
204
  async function agent (dir) {
205
- try { return await connectLocal(dir) } catch (e) { if (e.code !== 'ENOAGENT') throw e }
205
+ try { return await connectLocal(dir) } catch (e) {
206
+ if (e.code === 'EAGENTACCESS') throw new Error(t(`el agente de este perfil corre con otros permisos y no deja entrar a esta ventana (${e.cause?.code}). Reinícialo: dotrino-terminal restart`, `this profile's agent runs with other permissions and does not let this window in (${e.cause?.code}). Restart it: dotrino-terminal restart`))
207
+ if (e.code !== 'ENOAGENT') throw e
208
+ }
206
209
  // Un agente vivo sin socket es uno anterior a las ventanas (< 0.6.0): no se levanta otro
207
210
  // encima (tendrían la misma llave), se dice.
208
211
  const pid = Number((() => { try { return fs.readFileSync(path.join(dir, 'agent.pid'), 'utf8') } catch (_) { return '' } })())
@@ -353,7 +356,7 @@ async function desktop () {
353
356
  if (args[1] !== 'update') die(t('uso: dotrino-terminal desktop update [--check]', 'usage: dotrino-terminal desktop update [--check]'))
354
357
  const { updateDesktop, BINARY } = await import('../desktop.js')
355
358
  const current = opt('--current')
356
- const exe = opt('--exe') || findDesktop(BINARY)
359
+ const exe = opt('--exe') || findDesktop(process.platform === 'win32' ? `${BINARY}.exe` : BINARY)
357
360
  const check = args.includes('--check')
358
361
  if (!exe && !check) die(t(`no encontré ${BINARY} en esta máquina. Bájala de https://terminal.dotrino.com/`, `could not find ${BINARY} on this machine. Get it from https://terminal.dotrino.com/`))
359
362
  const say = (step, d) => {
package/desktop.js CHANGED
@@ -13,6 +13,8 @@
13
13
  * contraseña en esa misma ventana.
14
14
  * · tarball — el binario es del usuario: se cambia por el nuevo, de forma atómica.
15
15
  * · macOS — se cambia el `.app` entero.
16
+ * · Windows — el `.exe` es del usuario (sale de un `.zip`). Un `.exe` que está corriendo no se
17
+ * puede sobrescribir, pero sí renombrar: el viejo pasa a `.exe.old` y el nuevo ocupa su sitio.
16
18
  *
17
19
  * La ventana que ya corre sigue con la versión anterior hasta que se cierre y se vuelva a abrir.
18
20
  */
@@ -42,7 +44,7 @@ export const latestDesktop = (opts = {}) =>
42
44
  * gestor hay se equivoca con un tarball en una máquina con `dpkg`.
43
45
  *
44
46
  * @param {any} [o]
45
- * @returns {any} `{ ok:true, kind:'deb'|'rpm'|'tar'|'mac', app? }` o `{ ok:false, code, reason }`
47
+ * @returns {any} `{ ok:true, kind:'deb'|'rpm'|'tar'|'mac'|'win', app? }` o `{ ok:false, code, reason }`
46
48
  */
47
49
  export function installKind ({ exe, platform = process.platform, arch = process.arch, run = execFileSync, writable = canWrite } = {}) {
48
50
  if (!exe) return fail('no-exe', 'the desktop app was not found')
@@ -52,6 +54,11 @@ export function installKind ({ exe, platform = process.platform, arch = process.
52
54
  if (!writable(path.dirname(m[1]))) return fail('not-writable', `cannot write in ${path.dirname(m[1])}`)
53
55
  return { ok: true, kind: 'mac', app: m[1] }
54
56
  }
57
+ if (platform === 'win32') {
58
+ if (arch !== 'x64') return fail('unsupported-arch', `there is no desktop app for ${arch}`)
59
+ if (!writable(path.dirname(exe))) return fail('not-writable', `cannot write in ${path.dirname(exe)}`)
60
+ return { ok: true, kind: 'win' }
61
+ }
55
62
  if (platform !== 'linux') return fail('unsupported-platform', `there is no desktop app for ${platform}`)
56
63
  if (arch !== 'x64') return fail('unsupported-arch', `there is no desktop app for ${arch}`)
57
64
  const owns = (cmd, args) => { try { run(cmd, args, { stdio: 'ignore' }); return true } catch (_) { return false } }
@@ -69,7 +76,8 @@ const MATCH = {
69
76
  deb: { kind: 'deb', re: /_amd64\.deb$/ },
70
77
  rpm: { kind: 'rpm', re: /\.x86_64\.rpm$/ },
71
78
  tar: { kind: 'tar', re: /-linux-x64\.tar\.gz$/ },
72
- mac: { kind: 'mac', re: /-macos-universal\.zip$/ }
79
+ mac: { kind: 'mac', re: /-macos-universal\.zip$/ },
80
+ win: { kind: 'win', re: /-windows-x64\.zip$/ }
73
81
  }
74
82
 
75
83
  /** El archivo de la release que le toca a esa forma de instalación. */
@@ -146,6 +154,27 @@ export function install (file, how, { exe, run = execFileSync, uid = process.get
146
154
  fs.rmSync(work, { recursive: true, force: true })
147
155
  }
148
156
  }
157
+ if (how.kind === 'win') {
158
+ const work = path.dirname(file)
159
+ // `tar` de Windows (bsdtar, desde Windows 10) desempaqueta un .zip.
160
+ try { run('tar', ['-xf', file, '-C', work], { stdio: ['ignore', 'ignore', 'pipe'] }) } catch (e) {
161
+ return fail('unpack-failed', `could not unpack the release: ${String(e.stderr || e.message).trim()}`, { file })
162
+ }
163
+ const name = `${BINARY}.exe`
164
+ const src = [path.join(work, name), ...fs.readdirSync(work).map((d) => path.join(work, d, name))].find((f) => fs.existsSync(f))
165
+ if (!src) return fail('bad-zip', `the zip has no ${name} inside`, { file })
166
+ // El .exe que corre no se puede pisar, pero sí apartar: la ventana abierta sigue con él. El
167
+ // `.old` de la vez anterior se borra si ya nadie lo usa.
168
+ const old = `${exe}.old`
169
+ try { fs.rmSync(old, { force: true }) } catch (_) { /* aún lo usa una ventana: se queda */ }
170
+ try {
171
+ fs.renameSync(exe, old)
172
+ try { fs.copyFileSync(src, exe) } catch (e) { fs.renameSync(old, exe); throw e }
173
+ } catch (e) {
174
+ return fail('install-failed', `could not replace the app: ${e.message}`, { file })
175
+ }
176
+ return { ok: true }
177
+ }
149
178
  return fail('unknown-kind', `unknown install kind: ${how.kind}`)
150
179
  }
151
180
 
package/local.js CHANGED
@@ -19,6 +19,10 @@
19
19
  * hacerse pasar por él, porque no sabe cómo se va a llamar;
20
20
  * · una LLAVE que la ventana manda en su primera línea. La lista de tuberías la ve cualquiera,
21
21
  * y sin la llave el agente corta la conexión sin atender nada.
22
+ *
23
+ * Por eso la tubería se abre para todos (`readableAll`/`writableAll`): lo que protege es la llave.
24
+ * Con el permiso por defecto, un agente lanzado con el token de administrador entero (desde SSH)
25
+ * dejaba fuera a las ventanas del mismo usuario, que corren sin elevar.
22
26
  */
23
27
  import fs from 'node:fs'
24
28
  import net from 'node:net'
@@ -137,7 +141,7 @@ export async function listenLocal ({ dir, serve, platform = process.platform })
137
141
  })
138
142
  await new Promise((resolve, reject) => {
139
143
  server.once('error', reject)
140
- server.listen(file, () => { server.off('error', reject); resolve() })
144
+ server.listen({ path: file, ...(key ? { readableAll: true, writableAll: true } : {}) }, () => { server.off('error', reject); resolve() })
141
145
  })
142
146
  if (key) {
143
147
  // Se apunta DESPUÉS de escuchar: quien lo lea encuentra la tubería ya abierta.
@@ -190,7 +194,10 @@ export function connectLocal (dir, { platform = process.platform } = {}) {
190
194
  })
191
195
  // Tras conectar, un error acaba en 'close', que ya se avisa arriba.
192
196
  sock.on('error', (e) => {
193
- if (!connected) reject(Object.assign(new Error(`no terminal agent is listening on ${file}`), { code: 'ENOAGENT', cause: e }))
197
+ if (connected) return
198
+ // Hay agente pero no deja entrar: no es lo mismo que no haber ninguno.
199
+ if (e.code === 'EPERM' || e.code === 'EACCES') reject(Object.assign(new Error(`the terminal agent on ${file} refused this window (${e.code})`), { code: 'EAGENTACCESS', cause: e }))
200
+ else reject(Object.assign(new Error(`no terminal agent is listening on ${file}`), { code: 'ENOAGENT', cause: e }))
194
201
  })
195
202
  })
196
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/terminal-agent",
3
- "version": "0.47.1",
3
+ "version": "0.47.3",
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": {
@@ -33,11 +33,11 @@
33
33
  "type-check": "tsc --noEmit"
34
34
  },
35
35
  "dependencies": {
36
- "@dotrino/identity": "0.107.2",
36
+ "@dotrino/identity": "0.116.0",
37
37
  "@dotrino/proxy-client": "0.32.0",
38
38
  "@dotrino/remote-agent": "0.18.3",
39
39
  "@dotrino/update": "0.9.0",
40
- "@dotrino/vault": "0.82.1",
40
+ "@dotrino/vault": "0.86.0",
41
41
  "@xterm/addon-serialize": "0.13.0",
42
42
  "@xterm/headless": "5.5.0",
43
43
  "jsonc-parser": "3.3.1",