@legios/quartermaster 0.1.11 → 0.1.13

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
@@ -49,11 +49,30 @@ brew install legiosai/tap/quartermaster # macOS and Linux
49
49
  npm install -g @legios/quartermaster # anywhere
50
50
  ```
51
51
 
52
- **The menu bar item on macOS:** the first time you run `qm` in a terminal, it
53
- asks once whether to put it in the menu bar and start it at every login. The
54
- install itself can't: brew can't start anything from a formula, and a tool that
55
- reads OAuth tokens shouldn't register login agents nobody asked for. Without the
56
- question: `brew services start quartermaster`.
52
+ **The bar item, on macOS and Linux:** the first time you run `qm` in a terminal,
53
+ it asks once whether to put it in the bar and start it at every login. The
54
+ install itself can't: brew can't start anything from a formula, the `.deb` drops
55
+ the files and leaves, and a tool that reads OAuth tokens shouldn't register login
56
+ agents nobody asked for. Without the question: `brew services start
57
+ quartermaster` on macOS, and on Linux
58
+
59
+ ```sh
60
+ qm-indicator --instalar-extension # the item that opens the panel on click
61
+ qm-indicator --instalar-arranque # and start it once: qm-indicator &
62
+ ```
63
+
64
+ Saying yes on Linux **also installs the GNOME extension**, which is what makes a
65
+ click open the panel: without it the item is hosted by AppIndicator and the click
66
+ falls through to the GTK menu — the one that does not hold the grab and closes
67
+ the moment you touch it. GNOME does not load a freshly installed extension on
68
+ Wayland, so when it had to be installed the closing line says so and you have to
69
+ log out once.
70
+
71
+ The question only appears when there is somewhere to show it: a graphical
72
+ session, `python3-gi` with `AyatanaAppIndicator3`, and a host for the item — an
73
+ extension already in place, or a GNOME Shell to install ours into. Without those
74
+ the process would start anyway and nothing would appear up there, which is worse
75
+ than not offering. `qm --diagnostico` says which one is missing.
57
76
 
58
77
  **Windows:** the installer from the [latest
59
78
  release](https://github.com/legiosai/quartermaster/releases/latest). Per-user
@@ -200,18 +219,27 @@ quota response it got in each profile's `.claude.json`, so quartermaster reads
200
219
  it from disk — which means it still works on a profile whose token expired,
201
220
  the exact state the motivating monitor died in.
202
221
 
203
- The only thing that ever leaves is one request, and only when you ask for it
204
- (`--refrescar`, or `--calentar`, which is what the panels run):
222
+ The only thing that ever leaves is one request per vendor, and only when you ask
223
+ for it (`--refrescar`, or `--calentar`, which is what the panels run):
205
224
 
206
225
  ```
207
226
  GET https://api.anthropic.com/api/oauth/usage
227
+ GET https://api.z.ai/api/monitor/usage/quota/limit # only if you use z.ai
208
228
  ```
209
229
 
210
- Same host Claude Code already talks to, same credential it already stored, with
211
- a 60-second floor. No account, no cloud, no telemetry, and zero runtime
212
- dependencies. **It never refreshes a token** — a locked non-goal, with a test.
230
+ Each one is the same host that vendor's own tool already talks to, with the
231
+ credential it already stored, asking about your own account, with a 60-second
232
+ floor. No account, no cloud, no telemetry, and zero runtime dependencies. **It
233
+ never refreshes a token** — a locked non-goal, with a test.
234
+
235
+ The z.ai one is the exception to "no credential", and it is worth knowing which
236
+ direction it runs: opencode stores GLM, MiniMax and Kimi plans as API keys, and
237
+ those plans leave no percentage anywhere on disk. The opencode rows therefore
238
+ show what disk can prove — tokens spent, and the reset time a `429` already told
239
+ you — and the percentage only after you ask for it once. It is cached like every
240
+ other number, so the panels get a bar without ever touching the key themselves.
213
241
 
214
- The full table, and the straight paragraph about that endpoint being
242
+ The full table, and the straight paragraph about both endpoints being
215
243
  undocumented, are in [`SECURITY.md`](SECURITY.md).
216
244
 
217
245
  ## Package managers
@@ -254,7 +282,8 @@ What each channel needs configured is in
254
282
  src/core/ profiles, types. Knows nothing about keychains or HTTP.
255
283
  src/adapters/ credentials (keychain / file), transcripts (JSONL), quota
256
284
  from the cache (.claude.json) and from the endpoint (HTTP),
257
- Codex (JSON-RPC) and opencode (SQLite).
285
+ Codex (JSON-RPC), opencode (SQLite) and z.ai (HTTP — the
286
+ only file that opens opencode's auth.json).
258
287
  src/cli/ qm, and one demo per milestone.
259
288
  src/render/ bars and formatting for the terminal, and the dashboard.
260
289
  bin/ the launchers — qm (POSIX), qm.cmd + buscar-node.cmd
package/bin/qm CHANGED
@@ -7,7 +7,8 @@
7
7
  # interactivos— el shebang de siempre falla con un error de sintaxis que no le
8
8
  # dice nada a nadie. Así que acá se busca un Node que sirva antes de arrancar.
9
9
  #
10
- # Orden: $QM_NODE, el del PATH, y después las versiones de nvm de mayor a menor.
10
+ # Orden: $QM_NODE, el del PATH, y después lo que hayan guardado los manejadores
11
+ # de versiones —nvm, fnm y volta— de mayor a menor.
11
12
 
12
13
  set -e
13
14
 
@@ -18,26 +19,73 @@ sirve() {
18
19
  }
19
20
 
20
21
  NODO=""
22
+
23
+ # Cada manejador de versiones guarda los Node con una forma distinta:
24
+ #
25
+ # nvm $NVM_DIR/versions/node/v22.22.2/bin/node
26
+ # fnm $FNM_DIR/node-versions/v22.22.2/installation/bin/node
27
+ # volta $VOLTA_HOME/tools/image/node/22.22.2/bin/node
28
+ #
29
+ # Se recorren de mayor a menor VERSIÓN y no alfabéticamente, para que v9 no le
30
+ # gane a v22. La `v` del nombre se saca antes de ordenar porque volta no la
31
+ # pone, y después se prueban las dos formas del nombre.
32
+ #
33
+ # Acá faltaban fnm y volta, y el README decía que estaban. Se notó de la peor
34
+ # manera posible: el indicador de GNOME arranca desde el autostart, que NO tiene
35
+ # el PATH de un shell interactivo —ahí es donde fnm se carga—, así que no
36
+ # encontraba Node, se quedaba mostrando los números de la sesión anterior, y lo
37
+ # único que lo decía era un renglón en el journal.
38
+ buscar_en() {
39
+ raiz=$1
40
+ medio=$2
41
+ [ -d "$raiz" ] || return 1
42
+ for d in $(ls -1 "$raiz" 2>/dev/null | sed 's/^v//' | sort -t. -k1,1n -k2,2n -k3,3n -r); do
43
+ for nombre in "v$d" "$d"; do
44
+ if sirve "$raiz/$nombre$medio"; then
45
+ NODO="$raiz/$nombre$medio"
46
+ return 0
47
+ fi
48
+ done
49
+ done
50
+ return 1
51
+ }
52
+
21
53
  if [ -n "$QM_NODE" ] && sirve "$QM_NODE"; then
22
54
  NODO="$QM_NODE"
23
55
  elif sirve "$(command -v node 2>/dev/null)"; then
24
56
  NODO="$(command -v node)"
25
57
  else
26
- # nvm guarda cada versión en su propio directorio. Se ordena por número de
27
- # versión, no alfabéticamente, para que v9 no le gane a v22.
28
- for d in $(ls -1 "${NVM_DIR:-$HOME/.nvm}/versions/node" 2>/dev/null | sort -t. -k1.2,1n -k2,2n -k3,3n -r); do
29
- if sirve "${NVM_DIR:-$HOME/.nvm}/versions/node/$d/bin/node"; then
30
- NODO="${NVM_DIR:-$HOME/.nvm}/versions/node/$d/bin/node"
31
- break
32
- fi
33
- done
58
+ buscar_en "${NVM_DIR:-$HOME/.nvm}/versions/node" "/bin/node" \
59
+ || buscar_en "${FNM_DIR:-$HOME/.local/share/fnm}/node-versions" "/installation/bin/node" \
60
+ || buscar_en "$HOME/Library/Application Support/fnm/node-versions" "/installation/bin/node" \
61
+ || buscar_en "${VOLTA_HOME:-$HOME/.volta}/tools/image/node" "/bin/node" \
62
+ || true
34
63
  fi
35
64
 
65
+ # `src/adapters/opencode.ts` usa node:sqlite, que es experimental, así que Node
66
+ # escribe DOS renglones en stderr en cada corrida de qm:
67
+ #
68
+ # (node:56893) ExperimentalWarning: SQLite is an experimental feature…
69
+ # (Use `node --trace-warnings ...` to show where the warning was created)
70
+ #
71
+ # Eso no es un mensaje de qm y no es para quien lo corre, pero sale por el mismo
72
+ # canal por el que qm explica las cosas: desde 0.1.8 `qm --calentar` dice por ahí
73
+ # por qué una cuenta no se calentó, y la barra de macOS y el indicador de GNOME
74
+ # anotan esos renglones en el log. Medido el 2026-09-14 con Node 22 en Debian:
75
+ # el journal del indicador quedaba con dos renglones de warning por cada pid de
76
+ # node, y el motivo de verdad enterrado entre ellos. Un monitor cuyo canal de
77
+ # explicaciones viene con ruido de fábrica no se puede leer.
78
+ #
79
+ # Se apaga SÓLO esa clase de warning, no todas: una deprecación de verdad tiene
80
+ # que seguir saliendo. La bandera existe desde Node 21.3 y el piso de este repo
81
+ # es 22.6, así que siempre está.
82
+ SIN_EXPERIMENTAL="--disable-warning=ExperimentalWarning"
83
+
36
84
  if [ -z "$NODO" ]; then
37
85
  echo "qm necesita Node >= 22.6 y no encontré ninguno." >&2
38
86
  echo "Lee TypeScript sin paso de build, y eso recién existe desde 22.6." >&2
39
87
  echo "" >&2
40
- echo " nvm install 22 # o instalá Node 22 como prefieras" >&2
88
+ echo " nvm install 22 # o fnm install 22, o como prefieras" >&2
41
89
  echo " QM_NODE=/ruta/a/node qm # o decile cuál usar" >&2
42
90
  exit 1
43
91
  fi
@@ -77,7 +125,7 @@ if [ -f "$RAIZ/dist/cli/qm.js" ]; then
77
125
  echo " Tus cambios en src/ NO se están viendo. Corré \`npm run construir\`," >&2
78
126
  echo " o borrá dist/ para volver a leer el TypeScript directo." >&2
79
127
  fi
80
- exec "$NODO" "$RAIZ/dist/cli/qm.js" "$@"
128
+ exec "$NODO" $SIN_EXPERIMENTAL "$RAIZ/dist/cli/qm.js" "$@"
81
129
  fi
82
130
 
83
- exec "$NODO" "$RAIZ/src/cli/qm.ts" "$@"
131
+ exec "$NODO" $SIN_EXPERIMENTAL "$RAIZ/src/cli/qm.ts" "$@"
@@ -370,6 +370,25 @@ struct PerfilVista {
370
370
  let presupuesto: Presupuesto?
371
371
  /// Cuándo se usó por última vez, según qm. Existe también en --breve.
372
372
  let ultimoUso: Date?
373
+ /// Va al final y no encabeza. Lo decide qm; acá sólo se dibuja.
374
+ let dormida: Bool
375
+ /// Por qué, en palabras. Prosa para mostrar, no para parsear.
376
+ let porque: [String]
377
+ }
378
+
379
+ /// Quién frena primero en toda la máquina, ya resuelto por qm.
380
+ ///
381
+ /// Antes esto se decidía acá adentro, recorriendo los perfiles y quedándose con
382
+ /// el `frena` de porcentaje más alto. Era la misma elección escrita seis veces
383
+ /// —una por pantalla— y las seis coincidían sólo por casualidad: el día que el
384
+ /// criterio cambió (una cuenta dormida en 100 % ya no encabeza), cinco se
385
+ /// quedaron con el criterio viejo. CONTRIBUTING.md: una regla que un renderer
386
+ /// reimplementa es un bug del CLI.
387
+ struct Lider {
388
+ let perfil: String
389
+ let ventana: Ventana
390
+ /// true si NO quedaba ninguna despierta: el encabezado es lo único que hay.
391
+ let dormida: Bool
373
392
  }
374
393
 
375
394
  // Las reglas del núcleo no se reimplementan acá: `qm` manda `mostrar`, `frena`,
@@ -388,7 +407,7 @@ func fecha(_ s: Any?) -> Date? {
388
407
 
389
408
  // ── leer a qm ────────────────────────────────────────────────────────────
390
409
  enum Lectura {
391
- case ok([PerfilVista])
410
+ case ok([PerfilVista], Lider?)
392
411
  /// Silencio es el bug: si no hay número, hay una frase.
393
412
  case falla(String)
394
413
  }
@@ -479,9 +498,27 @@ func leer() -> Lectura {
479
498
  edadSegundos: cuota["edadSegundos"] as? Int,
480
499
  proyeccion: proy,
481
500
  presupuesto: pre,
482
- ultimoUso: fecha(p["ultimoUso"]))
501
+ ultimoUso: fecha(p["ultimoUso"]),
502
+ dormida: ((p["relevancia"] as? [String: Any])?["dormida"] as? Bool) ?? false,
503
+ porque: ((p["relevancia"] as? [String: Any])?["porque"] as? [String]) ?? [])
483
504
  }
484
- return .ok(perfiles)
505
+
506
+ var lider: Lider? = nil
507
+ if let l = raiz["frenaPrimero"] as? [String: Any],
508
+ let nombre = l["perfil"] as? String,
509
+ let v = l["ventana"] as? [String: Any] {
510
+ lider = Lider(perfil: nombre,
511
+ ventana: Ventana(clave: v["clave"] as? String ?? "?",
512
+ alcance: v["alcance"] as? String,
513
+ porcentaje: v["porcentaje"] as? Int ?? 0,
514
+ severidad: v["severidad"] as? String ?? "normal",
515
+ activa: v["activa"] as? Bool ?? false,
516
+ reinicia: fecha(v["reinicia"]),
517
+ grupo: v["grupo"] as? String,
518
+ preocupa: v["preocupa"] as? Bool ?? false),
519
+ dormida: (l["dormida"] as? Bool) ?? false)
520
+ }
521
+ return .ok(perfiles, lider)
485
522
  }
486
523
 
487
524
  // ── avisos ───────────────────────────────────────────────────────────────
@@ -521,20 +558,14 @@ final class VistaResumen: NSView {
521
558
  private let nivel: Nivel
522
559
  private let reinicia: Date?
523
560
 
524
- init?(_ perfiles: [PerfilVista]) {
525
- var mejor: (PerfilVista, Ventana, Int)? = nil
526
- var i = 0
527
- for p in perfiles where p.hayNumero {
528
- if let v = p.frena, mejor == nil || v.porcentaje > mejor!.1.porcentaje {
529
- mejor = (p, v, i)
530
- }
531
- i += 1
532
- }
533
- guard let (p, v, _) = mejor else { return nil }
534
- cuenta = corto(p.nombre)
561
+ init?(_ lider: Lider?, _ perfiles: [PerfilVista]) {
562
+ guard let l = lider else { return nil }
563
+ let p = perfiles.first(where: { $0.nombre == l.perfil })
564
+ let v = l.ventana
565
+ cuenta = corto(p?.nombre ?? l.perfil)
535
566
  barra = v.nombre
536
567
  pct = v.porcentaje
537
- nivel = nivelDe(v.porcentaje, preocupa: v.preocupa || (p.proyeccion?.chocas ?? false))
568
+ nivel = nivelDe(v.porcentaje, preocupa: v.preocupa || (p?.proyeccion?.chocas ?? false))
538
569
  reinicia = v.reinicia
539
570
  super.init(frame: NSRect(x: 0, y: 0, width: 340, height: 74))
540
571
  }
@@ -1058,7 +1089,7 @@ final class Barra: NSObject, NSApplicationDelegate {
1058
1089
  item.button?.image = icono("exclamationmark.triangle.fill")
1059
1090
  agregar(menu, porque, activo: false)
1060
1091
 
1061
- case .ok(let perfiles):
1092
+ case .ok(let perfiles, let lider):
1062
1093
  if ultimaFalla != nil { registrar("lectura de qm volvió a andar") }
1063
1094
  ultimaFalla = nil
1064
1095
  vigilar(perfiles)
@@ -1069,7 +1100,7 @@ final class Barra: NSObject, NSApplicationDelegate {
1069
1100
  var iCuenta = 0
1070
1101
  var peorPct = 0
1071
1102
 
1072
- if let resumen = VistaResumen(perfiles) {
1103
+ if let resumen = VistaResumen(lider, perfiles) {
1073
1104
  let fila = NSMenuItem()
1074
1105
  fila.view = resumen
1075
1106
  menu.addItem(fila)
@@ -1092,7 +1123,9 @@ final class Barra: NSObject, NSApplicationDelegate {
1092
1123
  // El `!` no es sólo severidad: también avisa que a este
1093
1124
  // ritmo tocás el techo ANTES del reinicio.
1094
1125
  let chocas = p.proyeccion?.chocas ?? false
1095
- let esLaProyectada = { (v: Ventana) in chocas && v.clave == cual.clave }
1126
+ // Una cuenta dormida no alarma: el «!» avisa de algo que te
1127
+ // va a frenar, y una cuenta que nadie usa no frena nada.
1128
+ let esLaProyectada = { (v: Ventana) in !p.dormida && chocas && v.clave == cual.clave }
1096
1129
 
1097
1130
  let ses = p.sesion
1098
1131
  let sem = p.semanal
@@ -1100,18 +1133,23 @@ final class Barra: NSObject, NSApplicationDelegate {
1100
1133
  piezas.append(Trozo(
1101
1134
  nombre: corto(p.nombre), producto: p.producto, indice: piezas.count,
1102
1135
  sesion: ses?.porcentaje,
1103
- sesionAlerta: ses.map { $0.preocupa || esLaProyectada($0) } ?? false,
1136
+ sesionAlerta: ses.map { !p.dormida && ($0.preocupa || esLaProyectada($0)) } ?? false,
1104
1137
  semanal: sem?.porcentaje,
1105
- semanalAlerta: sem.map { $0.preocupa || esLaProyectada($0) } ?? false,
1138
+ semanalAlerta: sem.map { !p.dormida && ($0.preocupa || esLaProyectada($0)) } ?? false,
1106
1139
  diario: p.presupuesto?.pctDiario,
1107
1140
  viejo: viejo,
1108
1141
  perfil: p.nombre,
1109
1142
  reiniciaSesion: ses?.reinicia,
1110
1143
  reiniciaSemanal: sem?.reinicia,
1111
1144
  ultimoUso: p.ultimoUso))
1112
- peorPct = max(peorPct, cual.porcentaje)
1113
- revisarAvisos(p, visibles)
1114
- revisarLiberadas(p, visibles)
1145
+ // El color del ícono sigue a lo que te frena DE VERDAD: una
1146
+ // cuenta dormida en 100 % dejaba la barra de menú en rojo
1147
+ // permanente por una cuenta que nadie usa.
1148
+ if !p.dormida { peorPct = max(peorPct, cual.porcentaje) }
1149
+ if !p.dormida {
1150
+ revisarAvisos(p, visibles)
1151
+ revisarLiberadas(p, visibles)
1152
+ }
1115
1153
  }
1116
1154
  }
1117
1155