@dotrino/terminal-agent 0.6.0 → 0.7.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 CHANGED
@@ -8,7 +8,7 @@ el acta, canal cifrado, revocación, renovación) es
8
8
  [`@dotrino/remote-agent`](https://www.npmjs.com/package/@dotrino/remote-agent); esto
9
9
  añade el PTY.
10
10
 
11
- **Cómo se instala y se usa:** [wiki.dotrino.com/herramientas/terminal](https://wiki.dotrino.com/herramientas/terminal/).
11
+ **Cómo se instala y se usa:** [las ventanas y la app de escritorio](https://wiki.dotrino.com/herramientas/terminal-escritorio/) · [el acceso desde el navegador](https://wiki.dotrino.com/herramientas/terminal/).
12
12
 
13
13
  ```sh
14
14
  npx @dotrino/terminal-agent # enlaza (si falta) y corre
package/bin/terminal.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * dotrino-terminal — una ventana de Dotrino Terminal en ESTA terminal (TTY).
4
4
  *
5
- * dotrino-terminal [--name <n>] abre una consola nueva aquí
5
+ * dotrino-terminal [--name <n>] [--cwd <dir>] abre una consola nueva aquí (en la carpeta actual)
6
6
  * dotrino-terminal attach <id> [--name <n>] se engancha a una consola que ya existe
7
7
  * dotrino-terminal ls [--name <n>] [--json] las consolas abiertas en el agente
8
8
  * dotrino-terminal kill <id> [--name <n>] cierra una consola
@@ -44,7 +44,7 @@ const DETACH_PREFIX = '\x1d' // Ctrl+]
44
44
 
45
45
  if (args.includes('-h') || args.includes('--help')) {
46
46
  console.log(t(`uso:
47
- dotrino-terminal [--name <n>] abre una consola nueva en esta ventana
47
+ dotrino-terminal [--name <n>] [--cwd <dir>] abre una consola nueva en esta ventana, en la carpeta actual
48
48
  dotrino-terminal attach <id> [--name <n>] se engancha a una consola abierta
49
49
  dotrino-terminal ls [--name <n>] [--json] las consolas abiertas
50
50
  dotrino-terminal kill <id> [--name <n>] cierra una consola
@@ -53,7 +53,7 @@ if (args.includes('-h') || args.includes('--help')) {
53
53
 
54
54
  Dentro de una consola: Ctrl+] y luego d la suelta sin cerrarla.
55
55
  Cerrar la ventana cierra la consola que abrió.`, `usage:
56
- dotrino-terminal [--name <n>] open a new console in this window
56
+ dotrino-terminal [--name <n>] [--cwd <dir>] open a new console in this window, in the current folder
57
57
  dotrino-terminal attach <id> [--name <n>] attach to an open console
58
58
  dotrino-terminal ls [--name <n>] [--json] list open consoles
59
59
  dotrino-terminal kill <id> [--name <n>] close a console
@@ -252,7 +252,8 @@ try {
252
252
  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")'))
253
253
  interactive(conn, { type: 'attach', id: args[1] })
254
254
  } else if (cmd === 'open') {
255
- interactive(conn, { type: 'open' })
255
+ // Como cualquier terminal: la consola abre en la carpeta donde estás (o en `--cwd`).
256
+ interactive(conn, { type: 'open', cwd: path.resolve(opt('--cwd') || process.cwd()) })
256
257
  } else die(t(`orden desconocida: ${cmd} (mira --help)`, `unknown command: ${cmd} (see --help)`))
257
258
  } catch (e) {
258
259
  if (e !== HOLD) { try { die(`dotrino-terminal: ${e.message}`) } catch (_) {} }
package/consoles.js CHANGED
@@ -104,7 +104,7 @@ class Console {
104
104
  /** Las consolas de este agente. */
105
105
  export class ConsoleHub {
106
106
  /**
107
- * @param {{ spawn:(opts:{cols:number,rows:number})=>any }} opts
107
+ * @param {{ spawn:(opts:{cols:number,rows:number,cwd:string|null})=>any }} opts
108
108
  * `spawn` lanza la shell (un PTY con `onData`, `onExit`, `write`, `resize`, `kill`).
109
109
  */
110
110
  constructor ({ spawn }) {
@@ -112,9 +112,9 @@ export class ConsoleHub {
112
112
  this.consoles = new Map()
113
113
  }
114
114
 
115
- create ({ cols = 80, rows = 24, origin = 'remote' } = {}) {
115
+ create ({ cols = 80, rows = 24, origin = 'remote', cwd = null } = {}) {
116
116
  const id = randomId()
117
- const pty = this._spawn({ cols, rows })
117
+ const pty = this._spawn({ cols, rows, cwd })
118
118
  const c = new Console({ id, pty, cols, rows, origin })
119
119
  pty.onData((d) => c._out(d))
120
120
  pty.onExit(({ exitCode }) => {
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 } ·
13
+ * cliente → agente: { type:'list' } · { type:'open', cols, rows, cwd? } ·
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 }
@@ -18,7 +18,9 @@
18
18
  * { type:'replay', id, data, last } · { type:'out', data } ·
19
19
  * { type:'exit', code } · { type:'fail', code, message }
20
20
  */
21
+ import fs from 'node:fs'
21
22
  import os from 'node:os'
23
+ import path from 'node:path'
22
24
  import { createRequire } from 'node:module'
23
25
  import { startRemoteAgent } from '@dotrino/remote-agent/agent'
24
26
  import { dataDir, loadLink, LABEL } from './link.js'
@@ -39,13 +41,17 @@ export function loadPty () {
39
41
  }
40
42
  }
41
43
 
44
+ const isDir = (p) => {
45
+ try { return typeof p === 'string' && path.isAbsolute(p) && fs.statSync(p).isDirectory() } catch (_) { return false }
46
+ }
47
+
42
48
  /** Las consolas de este agente, sobre el PTY. Exportada para las pruebas. */
43
49
  export function makeHub (pty, opts = {}) {
44
50
  const shell = opts.shell || process.env.SHELL || (process.platform === 'win32' ? 'powershell.exe' : 'bash')
45
51
  return new ConsoleHub({
46
- spawn: ({ cols, rows }) => pty.spawn(shell, [], {
52
+ spawn: ({ cols, rows, cwd }) => pty.spawn(shell, [], {
47
53
  name: 'xterm-256color', cols, rows,
48
- cwd: os.homedir(), env: { ...process.env, TERM: 'xterm-256color' }
54
+ cwd: cwd || os.homedir(), env: { ...process.env, TERM: 'xterm-256color' }
49
55
  })
50
56
  })
51
57
  }
@@ -96,7 +102,10 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
96
102
  if (msg.type === 'list') { session.send({ type: 'consoles', list: hub.list() }); return }
97
103
  if (msg.type === 'open') {
98
104
  takeSize(msg)
99
- const c = hub.create({ ...size, origin })
105
+ // `cwd`: dónde abre la shell (la carpeta de la ventana que la pide). Si no existe, se
106
+ // dice: abrir en otra carpeta sin avisar haría que un comando corra donde no toca.
107
+ if (msg.cwd != null && !isDir(msg.cwd)) return fail('bad-cwd', `not a directory: ${msg.cwd}`)
108
+ const c = hub.create({ ...size, origin, cwd: msg.cwd || null })
100
109
  if (origin === 'local') owned = c
101
110
  attachTo(c, { fresh: true })
102
111
  return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/terminal-agent",
3
- "version": "0.6.0",
3
+ "version": "0.7.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": {