@dotrino/terminal-agent 0.17.0 → 0.18.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.
Files changed (2) hide show
  1. package/consoles.js +32 -49
  2. package/package.json +1 -1
package/consoles.js CHANGED
@@ -24,30 +24,19 @@ export const SCROLLBACK = 1000
24
24
  /** Tamaño máximo de cada trozo de la repetición: el proxio corta los mensajes a 1 MB. */
25
25
  export const REPLAY_CHUNK = 64 * 1024
26
26
 
27
- // ¿ESTÁ TRABAJANDO? Lo que el panel enseña con un color por consola.
28
- // · Si el programa lo dice en el TÍTULO, manda eso. Claude Code lo hace (medido el 2026-10-06
29
- // con la 2.1.291): «✳ tema» esperando, «◐ tema» / «◑ tema» alternando mientras trabaja.
30
- // · Si no lo dice (otro agente, un comando): salida SOSTENIDA que no es eco de lo tecleado es
31
- // trabajo, y el silencio es que terminó.
27
+ // ¿ESTÁ TRABAJANDO? Lo que el panel enseña con un color por consola. UNA regla, sin leer lo que
28
+ // dice la pantalla ni el título (dueño, 2026-10-06): si el TÍTULO o el CONTENIDO cambian de
29
+ // seguido, trabaja; si llevan un rato sin cambiar, está quieta. Sirve igual para cualquier
30
+ // agente — medidos Claude Code y Codex (giran el título), y OpenCode (anima la pantalla): los
31
+ // tres cambian algo al menos una vez por segundo mientras trabajan y se callan al terminar.
32
32
  // «Terminó» (`doneAt`) queda marcado hasta que alguien entra a la consola o teclea en ella: es
33
33
  // lo que avisa de que un agente acabó mientras mirabas otra cosa. Una campana (BEL) lo marca igual.
34
- const BUSY_GLYPHS = /^[\u25d0-\u25d3\u25f4-\u25f7\u2800-\u28ff]/ // ◐◑◒◓ ◴◵◶◷ y los girasoles braille
35
- const IDLE_GLYPHS = /^\u2733/ // ✳
36
- /** Lo que dice el título: true (trabajando), false (esperando) o null (el programa no lo dice). */
37
- export function titleSignal (title) {
38
- const t = String(title || '')
39
- if (BUSY_GLYPHS.test(t)) return true
40
- if (IDLE_GLYPHS.test(t)) return false
41
- return null
42
- }
43
- const ECHO_MS = 400 // salida tan pegada a una tecla es su eco, no trabajo
44
- const SUSTAIN_MS = 1500 // salida propia durante este rato = está trabajando
45
- const GAP_MS = 1000 // un hueco mayor que este corta la racha: no era salida seguida
46
- // EL RESPALDO, para quien no lo dice en el título (OpenCode, un comando cualquiera): si la
47
- // pantalla no cambia en este rato, la consola está quieta. Un minuto por defecto (dueño,
48
- // 2026-10-06): un programa que piensa en silencio unos segundos no debe darse por terminado.
49
- // `DOTRINO_TERMINAL_IDLE_SECONDS` lo cambia; quien lo dice en el título no espera a esto.
50
- export const QUIET_MS = Math.max(1, Number(process.env.DOTRINO_TERMINAL_IDLE_SECONDS) || 60) * 1000
34
+ const ECHO_MS = 400 // un cambio tan pegado a una tecla es su eco, no trabajo
35
+ const SUSTAIN_MS = 1500 // cambios seguidos durante este rato = está trabajando
36
+ const GAP_MS = 2000 // un hueco mayor que este corta la racha: eran cambios sueltos
37
+ // Sin cambios en este rato, la consola está quieta. `DOTRINO_TERMINAL_IDLE_SECONDS` lo cambia.
38
+ // Diez segundos: de sobra para un agente, y un comando que calle más se da por terminado pronto.
39
+ export const QUIET_MS = Math.max(1, Number(process.env.DOTRINO_TERMINAL_IDLE_SECONDS) || 10) * 1000
51
40
  const MIN_TASK_MS = 3000 // menos que esto no fue «una tarea»: no se marca como terminada
52
41
 
53
42
  const randomId = () => [...crypto.getRandomValues(new Uint8Array(8))].map((x) => x.toString(16).padStart(2, '0')).join('')
@@ -80,31 +69,37 @@ class Console {
80
69
  this.busySince = 0
81
70
  this.doneAt = null // terminó (o pidió atención) y nadie lo ha atendido
82
71
  this.lastInput = 0
83
- this._titleSays = null // lo último que dijo el título (true/false), o null si no lo dice
84
- this._outSince = 0 // desde cuándo hay salida propia seguida
85
- this._lastOwnOut = 0
72
+ this._changing = 0 // desde cuándo hay cambios seguidos
73
+ this._lastChange = 0
86
74
  this._quiet = null
87
75
  this.screen.onTitleChange((t) => {
88
76
  this.title = String(t).slice(0, 200)
89
- const says = titleSignal(this.title)
90
- const before = this._titleSays
91
- this._titleSays = says
92
- // Cuando el programa lo dice, manda él; si DEJA de decirlo (salió), ya no está trabajando.
93
- // Un título que nunca dijo nada (el de la shell) no toca lo que se dedujo de la salida.
94
- let changed = false
95
- if (says !== null) changed = this._setBusy(says)
96
- else if (before !== null) changed = this._setBusy(false)
97
- if (!changed) this._meta()
77
+ if (!this._changed(Date.now())) this._meta()
98
78
  })
99
79
  this.screen.onBell(() => { this.doneAt = Date.now(); this._meta() })
100
80
  }
101
81
 
82
+ /**
83
+ * Algo cambió (el título o el contenido). Cambios seguidos encienden «trabajando»; un rato sin
84
+ * ninguno lo apaga. Dos cambios sueltos (el prompt que se redibuja, un comando instantáneo) no
85
+ * son un programa trabajando. Devuelve si avisó a quien mira.
86
+ */
87
+ _changed (now) {
88
+ if (now - this.lastInput <= ECHO_MS) return false
89
+ if (!this._changing || now - this._lastChange > GAP_MS) this._changing = now
90
+ this._lastChange = now
91
+ clearTimeout(this._quiet)
92
+ this._quiet = setTimeout(() => { this._changing = 0; this._setBusy(false) }, this.quietMs)
93
+ this._quiet.unref?.()
94
+ return now - this._changing >= SUSTAIN_MS ? this._setBusy(true) : false
95
+ }
96
+
102
97
  /** Cambia «trabajando». Al dejar de trabajar tras una tarea de verdad, queda como terminada. */
103
98
  _setBusy (v) {
104
99
  if (v === this.busy) return false
105
- const now = Date.now()
106
100
  this.busy = v
107
- if (v) { this.busySince = now; this.doneAt = null } else if (now - this.busySince >= MIN_TASK_MS) this.doneAt = now
101
+ // La tarea duró hasta el ÚLTIMO cambio, no hasta que se notó el silencio.
102
+ if (v) { this.busySince = this._changing; this.doneAt = null } else if (this._lastChange - this.busySince >= MIN_TASK_MS) this.doneAt = Date.now()
108
103
  this._meta()
109
104
  return true
110
105
  }
@@ -126,19 +121,7 @@ class Console {
126
121
  _out (data) {
127
122
  const now = Date.now()
128
123
  this.lastActive = now
129
- // Sin señal en el título: salida propia y sostenida = trabajando; el silencio lo apaga.
130
- if (this._titleSays === null) {
131
- if (now - this.lastInput > ECHO_MS) {
132
- // SOSTENIDA = seguida: dos ráfagas sueltas (el prompt que se redibuja al cambiar el
133
- // tamaño, y otra cosa segundos después) no son un programa trabajando.
134
- if (!this._outSince || now - this._lastOwnOut > GAP_MS) this._outSince = now
135
- this._lastOwnOut = now
136
- if (now - this._outSince >= SUSTAIN_MS) this._setBusy(true)
137
- }
138
- clearTimeout(this._quiet)
139
- this._quiet = setTimeout(() => { this._outSince = 0; if (this._titleSays === null) this._setBusy(false) }, this.quietMs)
140
- this._quiet.unref?.()
141
- }
124
+ this._changed(now)
142
125
  this.screen.write(data)
143
126
  for (const v of this.viewers) v.onOut(data)
144
127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/terminal-agent",
3
- "version": "0.17.0",
3
+ "version": "0.18.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": {