@dotrino/terminal-agent 0.23.0 → 0.24.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/bin/terminal.js CHANGED
@@ -435,13 +435,23 @@ function interactive (conn, first, dir) {
435
435
  if (m.type === 'meta') { onInfo(m.console); return }
436
436
  if (m.type === 'exit') {
437
437
  // LA CERRÓ OTRA PANTALLA (el teléfono, la web, el panel de otra ventana): esta ventana no
438
- // se va — nadie aquí pidió cerrarla, y cerrarla dejaba al usuario sin ventana y sin forma
439
- // de abrir otra consola. Se abre una nueva y se dice. Si la shell terminó sola (`exit`) o
440
- // la cerró esta misma ventana, la ventana se cierra, como cualquier terminal.
438
+ // se va — nadie aquí pidió cerrarla, y cerrarla dejaba al usuario sin ventana. Pasa a una
439
+ // consola que YA existe: primero una que no mire nadie; si todas se miran, la primera igual.
440
+ // Una NUEVA solo si la máquina se quedó sin ninguna (dueño, 2026-10-07: la misma regla que
441
+ // el panel de la web y de los teléfonos), y entonces se dice. Si la shell terminó sola
442
+ // (`exit`) o la cerró esta misma ventana, la ventana se cierra, como cualquier terminal.
441
443
  if (m.closedBy === 'other') {
444
+ const closed = consoleId
442
445
  consoleId = null
443
- switchTo({ type: 'open', cwd: first.cwd || path.resolve(process.cwd()) })
444
- out.write(`\x1b[2m${t('Otra pantalla cerró esta consola. Esta es una nueva.', 'Another screen closed this console. This is a new one.')}\x1b[0m\r\n`)
446
+ ready = false // lo que se teclee mientras tanto espera a la consola que venga
447
+ request(conn, { type: 'list' }, 'consoles').then((r) => {
448
+ if (r.type !== 'consoles') return // un `fail`: ya lo atendió el manejador de abajo
449
+ const rest = r.list.filter((c) => c.id !== closed)
450
+ const other = rest.find((c) => !c.watchers.length) || rest[0]
451
+ if (other) return switchTo({ type: 'attach', id: other.id })
452
+ switchTo({ type: 'open', cwd: first.cwd || path.resolve(process.cwd()) })
453
+ out.write(`\x1b[2m${t('Otra pantalla cerró esta consola. Esta es una nueva.', 'Another screen closed this console. This is a new one.')}\x1b[0m\r\n`)
454
+ })
445
455
  return
446
456
  }
447
457
  finish(m.code || 0)
package/consoles.js CHANGED
@@ -55,6 +55,16 @@ export function cwdOf (pid) {
55
55
  return dir === home ? '~' : dir.startsWith(home + '/') ? '~' + dir.slice(home.length) : dir
56
56
  }
57
57
 
58
+ /**
59
+ * `usuario@máquina` de ESTA máquina, tal como lo pone el prompt de una shell (`\u@\h`: el nombre
60
+ * hasta el primer punto). Va con cada consola para que el panel sepa si su título habla de OTRA
61
+ * (tras un `ssh`) y solo entonces la enseñe. Si el sistema no lo dice, `null`: no se inventa.
62
+ */
63
+ export function userAtHost () {
64
+ try { return `${os.userInfo().username}@${os.hostname().split('.')[0]}` } catch (_) { return null }
65
+ }
66
+ const HOST = userAtHost()
67
+
58
68
  const randomId = () => [...crypto.getRandomValues(new Uint8Array(8))].map((x) => x.toString(16).padStart(2, '0')).join('')
59
69
 
60
70
  class Console {
@@ -242,7 +252,7 @@ class Console {
242
252
  const watchers = [...this.viewers].filter((v) => v.origin).map((v) => ({ origin: v.origin, device: v.device || null, tag: v.tag || null }))
243
253
  const d = this.decider()
244
254
  const sizeBy = d ? { origin: d.origin || null, device: d.device || null, tag: d.tag || null, pinned: !!d && d === this.pinnedViewer() } : null
245
- return { id: this.id, n: this.n, activity: this.busy ? 'busy' : 'idle', doneAt: this.doneAt, sizeBy, origin: this.origin, title: this.title, cwd: cwdOf(this.pty?.pid), cols: this.cols, rows: this.rows, createdAt: this.createdAt, lastActive: this.lastActive, viewers: this.viewers.size, watchers }
255
+ return { id: this.id, n: this.n, activity: this.busy ? 'busy' : 'idle', doneAt: this.doneAt, sizeBy, origin: this.origin, title: this.title, host: HOST, cwd: cwdOf(this.pty?.pid), cols: this.cols, rows: this.rows, createdAt: this.createdAt, lastActive: this.lastActive, viewers: this.viewers.size, watchers }
246
256
  }
247
257
  }
248
258
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/terminal-agent",
3
- "version": "0.23.0",
3
+ "version": "0.24.1",
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": {