@legios/quartermaster 0.1.11 → 0.1.12
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 +24 -5
- package/bin/qm +21 -2
- package/bin/qm-indicator +235 -8
- package/bin/qm-tray.ps1 +6 -1
- package/dist/adapters/barra.js +142 -31
- package/dist/adapters/barra.js.map +1 -1
- package/extension/quartermaster@legios/extension.js +257 -0
- package/extension/quartermaster@legios/metadata.json +8 -0
- package/extension/quartermaster@legios/stylesheet.css +10 -0
- package/package.json +2 -1
- package/scripts/gate-presupuesto.py +433 -0
- package/scripts/mandar-pr-winget.mjs +106 -21
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
|
|
53
|
-
asks once whether to put it in the
|
|
54
|
-
install itself can't: brew can't start anything from a formula,
|
|
55
|
-
reads OAuth tokens shouldn't register login
|
|
56
|
-
question: `brew services start
|
|
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
|
package/bin/qm
CHANGED
|
@@ -33,6 +33,25 @@ else
|
|
|
33
33
|
done
|
|
34
34
|
fi
|
|
35
35
|
|
|
36
|
+
# `src/adapters/opencode.ts` usa node:sqlite, que es experimental, así que Node
|
|
37
|
+
# escribe DOS renglones en stderr en cada corrida de qm:
|
|
38
|
+
#
|
|
39
|
+
# (node:56893) ExperimentalWarning: SQLite is an experimental feature…
|
|
40
|
+
# (Use `node --trace-warnings ...` to show where the warning was created)
|
|
41
|
+
#
|
|
42
|
+
# Eso no es un mensaje de qm y no es para quien lo corre, pero sale por el mismo
|
|
43
|
+
# canal por el que qm explica las cosas: desde 0.1.8 `qm --calentar` dice por ahí
|
|
44
|
+
# por qué una cuenta no se calentó, y la barra de macOS y el indicador de GNOME
|
|
45
|
+
# anotan esos renglones en el log. Medido el 2026-09-14 con Node 22 en Debian:
|
|
46
|
+
# el journal del indicador quedaba con dos renglones de warning por cada pid de
|
|
47
|
+
# node, y el motivo de verdad enterrado entre ellos. Un monitor cuyo canal de
|
|
48
|
+
# explicaciones viene con ruido de fábrica no se puede leer.
|
|
49
|
+
#
|
|
50
|
+
# Se apaga SÓLO esa clase de warning, no todas: una deprecación de verdad tiene
|
|
51
|
+
# que seguir saliendo. La bandera existe desde Node 21.3 y el piso de este repo
|
|
52
|
+
# es 22.6, así que siempre está.
|
|
53
|
+
SIN_EXPERIMENTAL="--disable-warning=ExperimentalWarning"
|
|
54
|
+
|
|
36
55
|
if [ -z "$NODO" ]; then
|
|
37
56
|
echo "qm necesita Node >= 22.6 y no encontré ninguno." >&2
|
|
38
57
|
echo "Lee TypeScript sin paso de build, y eso recién existe desde 22.6." >&2
|
|
@@ -77,7 +96,7 @@ if [ -f "$RAIZ/dist/cli/qm.js" ]; then
|
|
|
77
96
|
echo " Tus cambios en src/ NO se están viendo. Corré \`npm run construir\`," >&2
|
|
78
97
|
echo " o borrá dist/ para volver a leer el TypeScript directo." >&2
|
|
79
98
|
fi
|
|
80
|
-
exec "$NODO" "$RAIZ/dist/cli/qm.js" "$@"
|
|
99
|
+
exec "$NODO" $SIN_EXPERIMENTAL "$RAIZ/dist/cli/qm.js" "$@"
|
|
81
100
|
fi
|
|
82
101
|
|
|
83
|
-
exec "$NODO" "$RAIZ/src/cli/qm.ts" "$@"
|
|
102
|
+
exec "$NODO" $SIN_EXPERIMENTAL "$RAIZ/src/cli/qm.ts" "$@"
|
package/bin/qm-indicator
CHANGED
|
@@ -1678,6 +1678,19 @@ class Indicador:
|
|
|
1678
1678
|
# Desde cuándo. Sin esto, una bandera que se queda pegada no se puede
|
|
1679
1679
|
# distinguir de un calentado que recién arrancó.
|
|
1680
1680
|
self.calentando_desde: int | None = None
|
|
1681
|
+
# Lo último que falló de cada cosa, para anotar CAMBIOS y no repetir, y
|
|
1682
|
+
# para poder decir cuándo volvió a andar. Un log que repite la misma
|
|
1683
|
+
# falla cada dos minutos no se lee, y uno que nunca dice «volvió» deja
|
|
1684
|
+
# cada falla abierta para siempre: leyéndolo mañana no hay forma de
|
|
1685
|
+
# saber si el problema duró un minuto o duró toda la noche.
|
|
1686
|
+
self._fallo_calentado: str | None = None
|
|
1687
|
+
self._fallo_lectura: str | None = None
|
|
1688
|
+
self._fallo_lectura_desde: float | None = None
|
|
1689
|
+
# Los motivos por cuenta que qm ya explicó en esta corrida. Van una vez
|
|
1690
|
+
# y no tienen «volvió»: los calentados alternan entre todas las cuentas
|
|
1691
|
+
# y sólo las que se mueven, así que que un motivo no aparezca NO dice
|
|
1692
|
+
# que se arregló.
|
|
1693
|
+
self._motivos_calentado: set[str] = set()
|
|
1681
1694
|
self.reloj: int | None = None
|
|
1682
1695
|
self.proxima_lectura: int | None = None
|
|
1683
1696
|
self.turno = 0
|
|
@@ -2071,27 +2084,67 @@ class Indicador:
|
|
|
2071
2084
|
args.append("--cuentas=" + ",".join(mueven))
|
|
2072
2085
|
registrar("calentar", cuentas=",".join(mueven) if mueven else "todas")
|
|
2073
2086
|
try:
|
|
2087
|
+
# El stderr se PIDE, no se tira. Desde 0.1.8 `qm --calentar` explica
|
|
2088
|
+
# ahí por qué una cuenta no se calentó —sin credencial, token
|
|
2089
|
+
# vencido—, y con STDERR_SILENCE esa explicación se iba a /dev/null:
|
|
2090
|
+
# la barra de macOS la anota desde esa misma versión y acá se
|
|
2091
|
+
# perdía.
|
|
2074
2092
|
proc = Gio.Subprocess.new(
|
|
2075
|
-
args, Gio.SubprocessFlags.STDOUT_SILENCE | Gio.SubprocessFlags.
|
|
2093
|
+
args, Gio.SubprocessFlags.STDOUT_SILENCE | Gio.SubprocessFlags.STDERR_PIPE
|
|
2076
2094
|
)
|
|
2077
|
-
except GLib.Error:
|
|
2095
|
+
except GLib.Error as e:
|
|
2096
|
+
self._anotar_calentado(f"no pude correr qm: {str(e).replace(chr(10), ' ')[:110]}")
|
|
2078
2097
|
self.programar_calentado()
|
|
2079
2098
|
return False
|
|
2080
2099
|
self.calentando = True
|
|
2081
2100
|
self.calentando_desde = GLib.get_monotonic_time()
|
|
2082
|
-
proc.
|
|
2101
|
+
proc.communicate_utf8_async(None, None, self._fin_calentado)
|
|
2083
2102
|
return False
|
|
2084
2103
|
|
|
2104
|
+
def _anotar_calentado(self, fallo: str | None) -> None:
|
|
2105
|
+
"""La falla del calentado, anotada cuando CAMBIA y con su vuelta."""
|
|
2106
|
+
if fallo == self._fallo_calentado:
|
|
2107
|
+
return
|
|
2108
|
+
if fallo is not None:
|
|
2109
|
+
registrar("calentar.fallo", motivo=fallo)
|
|
2110
|
+
else:
|
|
2111
|
+
registrar("calentar.volvio")
|
|
2112
|
+
self._fallo_calentado = fallo
|
|
2113
|
+
|
|
2085
2114
|
def _fin_calentado(self, proc, resultado) -> None:
|
|
2086
2115
|
self.calentando = False
|
|
2087
2116
|
self.calentando_desde = None
|
|
2117
|
+
fallo, dicho = None, ""
|
|
2088
2118
|
try:
|
|
2089
|
-
proc.
|
|
2119
|
+
_, _, dicho = proc.communicate_utf8_finish(resultado)
|
|
2090
2120
|
except GLib.Error as e:
|
|
2091
2121
|
# Se sigue mostrando lo viejo, con su edad a la vista — pero ahora
|
|
2092
2122
|
# queda anotado POR QUÉ quedó viejo. Este `except` se tragaba la
|
|
2093
2123
|
# única pista de que el refresco no estaba pasando.
|
|
2094
|
-
|
|
2124
|
+
fallo = str(e).replace("\n", " ")[:120]
|
|
2125
|
+
else:
|
|
2126
|
+
# Y acá estaba el agujero: NADA de esto tira. `wait_finish` y
|
|
2127
|
+
# `communicate_utf8_finish` devuelven bien con el hijo saliendo 1
|
|
2128
|
+
# —medido: exit=1, sin excepción—, así que el código de salida hay
|
|
2129
|
+
# que mirarlo a mano. Un `qm --calentar` que salía 1 no dejaba una
|
|
2130
|
+
# sola línea. Es justo lo que pasó en 0.1.9, cuando la barra mandaba
|
|
2131
|
+
# `--cuentas=personal` y el CLI comparaba `.claude-personal`: en
|
|
2132
|
+
# macOS se vio en el log y acá no había log que ver.
|
|
2133
|
+
if not proc.get_if_exited():
|
|
2134
|
+
fallo = f"lo mató la señal {proc.get_term_sig()}"
|
|
2135
|
+
elif proc.get_exit_status() != 0:
|
|
2136
|
+
primera = [l.strip() for l in (dicho or "").splitlines() if l.strip()]
|
|
2137
|
+
fallo = f"salió {proc.get_exit_status()}"
|
|
2138
|
+
if primera:
|
|
2139
|
+
fallo += f": {primera[0][:110]}"
|
|
2140
|
+
self._anotar_calentado(fallo)
|
|
2141
|
+
# Los motivos por cuenta van aunque el calentado haya salido 0: que una
|
|
2142
|
+
# cuenta no se pueda calentar no hace fallar a las otras, y sin esto la
|
|
2143
|
+
# única pista de que esa cuenta quedó afuera es un número viejo.
|
|
2144
|
+
for m in [l.strip() for l in (dicho or "").splitlines() if l.strip()]:
|
|
2145
|
+
if m not in self._motivos_calentado:
|
|
2146
|
+
self._motivos_calentado.add(m)
|
|
2147
|
+
registrar("calentar.cuenta", motivo=m[:110])
|
|
2095
2148
|
self.refrescar()
|
|
2096
2149
|
|
|
2097
2150
|
def disparar(self) -> bool:
|
|
@@ -2109,9 +2162,22 @@ class Indicador:
|
|
|
2109
2162
|
# `leer_qm` devuelve una FRASE cuando no pudo: se muestra en el menú y
|
|
2110
2163
|
# hasta acá no quedaba escrita en ningún lado. Si qm falla a las tres de
|
|
2111
2164
|
# la mañana, mañana no hay forma de saber por qué.
|
|
2112
|
-
if isinstance(datos, str)
|
|
2113
|
-
|
|
2114
|
-
|
|
2165
|
+
if isinstance(datos, str):
|
|
2166
|
+
if datos != self._fallo_lectura:
|
|
2167
|
+
registrar("qm.sin-datos", motivo=datos[:110])
|
|
2168
|
+
if self._fallo_lectura_desde is None:
|
|
2169
|
+
self._fallo_lectura_desde = time.time()
|
|
2170
|
+
self._fallo_lectura = datos
|
|
2171
|
+
else:
|
|
2172
|
+
# La caída ya se anotaba; la VUELTA no, y sin ella toda falla queda
|
|
2173
|
+
# abierta para siempre. Leyendo el journal al otro día no había
|
|
2174
|
+
# forma de saber si qm estuvo caído un minuto o toda la noche, que
|
|
2175
|
+
# es justo lo que se va a buscar. Con el rato que duró, que es el
|
|
2176
|
+
# número que contesta esa pregunta.
|
|
2177
|
+
if self._fallo_lectura is not None:
|
|
2178
|
+
registrar("qm.volvio", tras=duracion(int(time.time() - (self._fallo_lectura_desde or time.time()))))
|
|
2179
|
+
self._fallo_lectura = None
|
|
2180
|
+
self._fallo_lectura_desde = None
|
|
2115
2181
|
self.datos = datos
|
|
2116
2182
|
for hijo in self.menu.get_children():
|
|
2117
2183
|
self.menu.remove(hijo)
|
|
@@ -2359,7 +2425,163 @@ def leer_desde(ruta: str) -> dict:
|
|
|
2359
2425
|
return json.loads(pathlib.Path(ruta).read_text())
|
|
2360
2426
|
|
|
2361
2427
|
|
|
2428
|
+
ARRANQUE = Path(os.environ.get("XDG_CONFIG_HOME", str(Path.home() / ".config"))) \
|
|
2429
|
+
/ "autostart" / "quartermaster.desktop"
|
|
2430
|
+
|
|
2431
|
+
|
|
2432
|
+
def instalar_arranque() -> int:
|
|
2433
|
+
"""Que el item arranque solo al iniciar sesión.
|
|
2434
|
+
|
|
2435
|
+
Vive acá y no sólo en el Makefile porque quien instaló por apt o por npm no
|
|
2436
|
+
tiene un Makefile: el .deb deja bin/qm-indicator en /usr/lib/quartermaster y
|
|
2437
|
+
nada más, así que el item quedaba a un comando que hay que saber. Es el
|
|
2438
|
+
mismo agujero que en macOS tapó `qm-barra --instalar-arranque`, y `qm` lo
|
|
2439
|
+
ofrece en la primera corrida por el mismo camino.
|
|
2440
|
+
|
|
2441
|
+
El Exec apunta a ESTE archivo resuelto, no a `qm-indicator` a secas: el
|
|
2442
|
+
arranque de la sesión no pasa por el .zshrc del usuario, así que ~/.local/bin
|
|
2443
|
+
puede no estar en su PATH.
|
|
2444
|
+
"""
|
|
2445
|
+
try:
|
|
2446
|
+
ARRANQUE.parent.mkdir(parents=True, exist_ok=True)
|
|
2447
|
+
ARRANQUE.write_text(
|
|
2448
|
+
"[Desktop Entry]\n"
|
|
2449
|
+
"Type=Application\n"
|
|
2450
|
+
"Name=quartermaster\n"
|
|
2451
|
+
"Comment=Cuota de Claude Code en la barra de arriba\n"
|
|
2452
|
+
f"Exec={YO}\n"
|
|
2453
|
+
"Icon=utilities-system-monitor-symbolic\n"
|
|
2454
|
+
"Terminal=false\n"
|
|
2455
|
+
"X-GNOME-Autostart-enabled=true\n",
|
|
2456
|
+
encoding="utf-8")
|
|
2457
|
+
except OSError as e:
|
|
2458
|
+
print(f"no pude escribir {ARRANQUE}: {e}", file=sys.stderr)
|
|
2459
|
+
return 1
|
|
2460
|
+
print(f"{ARRANQUE} escrito")
|
|
2461
|
+
return 0
|
|
2462
|
+
|
|
2463
|
+
|
|
2464
|
+
def quitar_arranque() -> int:
|
|
2465
|
+
"""Lo contrario, porque instalar sin poder desinstalar no es una opción."""
|
|
2466
|
+
try:
|
|
2467
|
+
ARRANQUE.unlink()
|
|
2468
|
+
except FileNotFoundError:
|
|
2469
|
+
print(f"{ARRANQUE} no estaba")
|
|
2470
|
+
return 0
|
|
2471
|
+
except OSError as e:
|
|
2472
|
+
print(f"no pude borrar {ARRANQUE}: {e}", file=sys.stderr)
|
|
2473
|
+
return 1
|
|
2474
|
+
print(f"{ARRANQUE} borrado")
|
|
2475
|
+
return 0
|
|
2476
|
+
|
|
2477
|
+
|
|
2478
|
+
EXTENSION_UUID = "quartermaster@legios"
|
|
2479
|
+
EXTENSIONES = Path(os.environ.get("XDG_DATA_HOME", str(Path.home() / ".local/share"))) \
|
|
2480
|
+
/ "gnome-shell" / "extensions"
|
|
2481
|
+
#: De dónde sale la extensión: al lado del paquete, sea un clone, el .deb o npm.
|
|
2482
|
+
EXTENSION_FUENTE = YO.parent.parent / "extension" / EXTENSION_UUID
|
|
2483
|
+
|
|
2484
|
+
|
|
2485
|
+
def _habilitadas() -> list[str] | None:
|
|
2486
|
+
"""La lista de `enabled-extensions`, o None si no hay gsettings."""
|
|
2487
|
+
try:
|
|
2488
|
+
dicho = subprocess.run(
|
|
2489
|
+
["gsettings", "get", "org.gnome.shell", "enabled-extensions"],
|
|
2490
|
+
capture_output=True, text=True, timeout=5, check=True).stdout.strip()
|
|
2491
|
+
except (OSError, subprocess.SubprocessError):
|
|
2492
|
+
return None
|
|
2493
|
+
# `@as []` para la lista vacía, `['a', 'b']` para el resto.
|
|
2494
|
+
if dicho.startswith("@as"):
|
|
2495
|
+
dicho = dicho[3:].strip()
|
|
2496
|
+
return [x.strip().strip("'\"") for x in dicho.strip("[]").split(",") if x.strip()]
|
|
2497
|
+
|
|
2498
|
+
|
|
2499
|
+
def instalar_extension() -> int:
|
|
2500
|
+
"""El item propio en la barra: un click abre el panel.
|
|
2501
|
+
|
|
2502
|
+
Sin ella el item lo hospeda AppIndicator y el click izquierdo cae al menú de
|
|
2503
|
+
GTK, que no sostiene el agarre y se cierra apenas lo tocás — el síntoma que
|
|
2504
|
+
la extensión existe para evitar, escrito en su propio extension.js.
|
|
2505
|
+
|
|
2506
|
+
Vive acá y no sólo en el Makefile por lo mismo que `--instalar-arranque`:
|
|
2507
|
+
quien instaló por npm o por apt no tiene un Makefile.
|
|
2508
|
+
|
|
2509
|
+
Salidas: 0 habilitada y andando ya, 2 instalada pero GNOME la carga recién
|
|
2510
|
+
en la próxima sesión, 1 no se pudo. El 2 no es un error y no se puede
|
|
2511
|
+
esconder: decir «listo» de algo que no se ve hasta cerrar sesión es
|
|
2512
|
+
exactamente la mentira que este programa no comete.
|
|
2513
|
+
"""
|
|
2514
|
+
if not EXTENSION_FUENTE.is_dir():
|
|
2515
|
+
print(f"no encuentro la extensión en {EXTENSION_FUENTE}", file=sys.stderr)
|
|
2516
|
+
return 1
|
|
2517
|
+
destino = EXTENSIONES / EXTENSION_UUID
|
|
2518
|
+
try:
|
|
2519
|
+
EXTENSIONES.mkdir(parents=True, exist_ok=True)
|
|
2520
|
+
if destino.exists():
|
|
2521
|
+
shutil.rmtree(destino)
|
|
2522
|
+
shutil.copytree(EXTENSION_FUENTE, destino)
|
|
2523
|
+
except OSError as e:
|
|
2524
|
+
print(f"no pude copiarla a {destino}: {e}", file=sys.stderr)
|
|
2525
|
+
return 1
|
|
2526
|
+
|
|
2527
|
+
# Anotarla en la lista de habilitadas ANTES de pedir el enable: en Wayland
|
|
2528
|
+
# GNOME no carga una extensión recién copiada, así que `gnome-extensions
|
|
2529
|
+
# enable` falla con «doesn't exist» y sin esta anotación no quedaría puesta
|
|
2530
|
+
# tampoco para la próxima sesión.
|
|
2531
|
+
lista = _habilitadas()
|
|
2532
|
+
if lista is not None and EXTENSION_UUID not in lista:
|
|
2533
|
+
nueva = "[" + ", ".join(f"'{x}'" for x in [*lista, EXTENSION_UUID]) + "]"
|
|
2534
|
+
try:
|
|
2535
|
+
subprocess.run(["gsettings", "set", "org.gnome.shell", "enabled-extensions", nueva],
|
|
2536
|
+
capture_output=True, timeout=5, check=True)
|
|
2537
|
+
except (OSError, subprocess.SubprocessError) as e:
|
|
2538
|
+
print(f"no pude anotarla en enabled-extensions: {e}", file=sys.stderr)
|
|
2539
|
+
return 1
|
|
2540
|
+
|
|
2541
|
+
try:
|
|
2542
|
+
ok = subprocess.run(["gnome-extensions", "enable", EXTENSION_UUID],
|
|
2543
|
+
capture_output=True, timeout=5).returncode == 0
|
|
2544
|
+
except OSError:
|
|
2545
|
+
ok = False
|
|
2546
|
+
if ok:
|
|
2547
|
+
print(f"{EXTENSION_UUID} habilitada")
|
|
2548
|
+
return 0
|
|
2549
|
+
print(f"{EXTENSION_UUID} instalada y anotada. GNOME no carga extensiones "
|
|
2550
|
+
"nuevas en Wayland: cerrá sesión y volvé a entrar una vez.")
|
|
2551
|
+
return 2
|
|
2552
|
+
|
|
2553
|
+
|
|
2554
|
+
def quitar_extension() -> int:
|
|
2555
|
+
"""Saca el item propio y devuelve el de AppIndicator."""
|
|
2556
|
+
try:
|
|
2557
|
+
subprocess.run(["gnome-extensions", "disable", EXTENSION_UUID],
|
|
2558
|
+
capture_output=True, timeout=5)
|
|
2559
|
+
except OSError:
|
|
2560
|
+
pass
|
|
2561
|
+
destino = EXTENSIONES / EXTENSION_UUID
|
|
2562
|
+
try:
|
|
2563
|
+
if destino.exists():
|
|
2564
|
+
shutil.rmtree(destino)
|
|
2565
|
+
(CACHE / "extension-viva").unlink(missing_ok=True)
|
|
2566
|
+
except OSError as e:
|
|
2567
|
+
print(f"no pude borrarla: {e}", file=sys.stderr)
|
|
2568
|
+
return 1
|
|
2569
|
+
print(f"{EXTENSION_UUID} quitada")
|
|
2570
|
+
return 0
|
|
2571
|
+
|
|
2572
|
+
|
|
2362
2573
|
def main() -> int:
|
|
2574
|
+
# Antes que nada: ninguna de las dos necesita sesión gráfica ni un qm en el
|
|
2575
|
+
# PATH, y `qm` llama a la primera desde una terminal.
|
|
2576
|
+
if "--instalar-arranque" in sys.argv:
|
|
2577
|
+
return instalar_arranque()
|
|
2578
|
+
if "--quitar-arranque" in sys.argv:
|
|
2579
|
+
return quitar_arranque()
|
|
2580
|
+
if "--instalar-extension" in sys.argv:
|
|
2581
|
+
return instalar_extension()
|
|
2582
|
+
if "--quitar-extension" in sys.argv:
|
|
2583
|
+
return quitar_extension()
|
|
2584
|
+
|
|
2363
2585
|
fijo = None
|
|
2364
2586
|
if "--desde" in sys.argv:
|
|
2365
2587
|
i = sys.argv.index("--desde")
|
|
@@ -2410,6 +2632,11 @@ def main() -> int:
|
|
|
2410
2632
|
print("ya hay un quartermaster corriendo en esta sesión.", file=sys.stderr)
|
|
2411
2633
|
return 0
|
|
2412
2634
|
|
|
2635
|
+
# La primera línea del journal la pone systemd y dice el scope, no dice
|
|
2636
|
+
# QUÉ arrancó: ni qué qm encontró —puede haber uno en ~/.local/bin y otro
|
|
2637
|
+
# del paquete—, ni con qué tema, ni con qué pid. Leyendo el log de ayer eso
|
|
2638
|
+
# es lo primero que hace falta. La barra de macOS lo anota desde 0.1.8.
|
|
2639
|
+
registrar("arranca", qm=qm, pid=os.getpid(), tema="oscuro" if TEMA.oscuro else "claro")
|
|
2413
2640
|
Indicador(qm)
|
|
2414
2641
|
Gtk.main()
|
|
2415
2642
|
return 0
|
package/bin/qm-tray.ps1
CHANGED
|
@@ -509,7 +509,12 @@ function RenglonesPresupuesto($pre) {
|
|
|
509
509
|
if ($pre.PSObject.Properties['gastadoMedido'] -and $null -ne $pre.gastadoMedido -and
|
|
510
510
|
$pre.PSObject.Properties['medidoDesde'] -and $null -ne $pre.medidoDesde) {
|
|
511
511
|
$desde = ([datetime]$pre.medidoDesde).ToLocalTime().ToString('HH:mm', [cultureinfo]::InvariantCulture)
|
|
512
|
-
|
|
512
|
+
# `0.0` y no `0`: con un entero de primer argumento PowerShell elige la
|
|
513
|
+
# sobrecarga [math]::Max(int, int) y le redondea el saldo al entero de
|
|
514
|
+
# abajo. Medido en el CI el 2026-09-14 con el JSON de un qm anterior:
|
|
515
|
+
# 14.3 - 14.0 daba «te queda 0.0 %» donde las otras cuatro pantallas
|
|
516
|
+
# decían 0.3. Se corta un presupuesto entero de menos de 1 %.
|
|
517
|
+
$queda = if ($pre.PSObject.Properties['restanteMedido'] -and $null -ne $pre.restanteMedido) { [double]$pre.restanteMedido } else { [math]::Max(0.0, $porDiaHoy - [double]$pre.gastadoMedido) }
|
|
513
518
|
return @($dia, "gastaste $(& $un $pre.gastadoMedido) % desde las $desde · te queda $(& $un $queda) %")
|
|
514
519
|
}
|
|
515
520
|
$hoy = ([double]$pre.quedaHoy).ToString('0.0', [cultureinfo]::InvariantCulture)
|
package/dist/adapters/barra.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// La pregunta de la barra
|
|
1
|
+
// La pregunta de la barra, en la primera corrida de `qm` en una terminal.
|
|
2
2
|
//
|
|
3
3
|
// POR QUÉ EXISTE. La barra es el punto entero del programa y ninguna vía de
|
|
4
4
|
// instalación la puede mostrar sola: `brew install` corre en un sandbox que no
|
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
// paquete que lee tokens OAuth no registra agentes que nadie pidió). Así que
|
|
8
8
|
// quedaba a un comando que había que leer en un caveat — y nadie lo lee.
|
|
9
9
|
//
|
|
10
|
+
// En Linux el agujero era el mismo y más grande: el item de la barra de arriba
|
|
11
|
+
// sólo se prendía con `make indicador` y `make autostart`, y quien instaló por
|
|
12
|
+
// apt o por npm no tiene un Makefile. El .deb deja bin/qm-indicator en
|
|
13
|
+
// /usr/lib/quartermaster y nada más. Por eso la misma pregunta va en las dos
|
|
14
|
+
// plataformas, con el mismo consentimiento explícito y la misma anotación de
|
|
15
|
+
// que ya se preguntó.
|
|
16
|
+
//
|
|
10
17
|
// La salida es preguntar. Una vez, en una terminal, después de mostrar los
|
|
11
18
|
// números: quien acaba de instalar ve la pregunta en el primer `qm`, y el
|
|
12
19
|
// consentimiento es explícito, que es lo que el postinstall no tenía.
|
|
@@ -14,22 +21,26 @@
|
|
|
14
21
|
// Nunca pregunta donde una pregunta rompe algo: --json, --breve, --watch y
|
|
15
22
|
// --umbral los leen scripts y statuslines, y sin terminal el proceso quedaría
|
|
16
23
|
// colgado esperando una respuesta que no va a llegar.
|
|
17
|
-
import { execFileSync } from 'node:child_process';
|
|
24
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
18
25
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
19
26
|
import { homedir } from 'node:os';
|
|
20
27
|
import { dirname, join } from 'node:path';
|
|
21
28
|
import { createInterface } from 'node:readline/promises';
|
|
22
29
|
import { RUTA_CONFIG } from "../core/config.js";
|
|
23
30
|
export function debeOfrecer(s) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// Lo que vale en las dos plataformas, primero: hay alguien para contestar,
|
|
32
|
+
// no se preguntó antes, y no está puesto ya.
|
|
33
|
+
if (!s.terminal || s.ci || !s.modoNormal || s.yaPreguntado)
|
|
34
|
+
return false;
|
|
35
|
+
if (!s.hayBarra || s.arranqueInstalado || s.corriendo)
|
|
36
|
+
return false;
|
|
37
|
+
// Y después, lo que cada una necesita para que lo ofrecido llegue a verse.
|
|
38
|
+
if (s.plataforma === 'darwin')
|
|
39
|
+
return s.compilador;
|
|
40
|
+
if (s.plataforma === 'linux') {
|
|
41
|
+
return s.sesionGrafica && s.interprete && (s.hostDelItem || s.puedeHospedar);
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
33
44
|
}
|
|
34
45
|
/**
|
|
35
46
|
* Por dónde se arranca, según dónde vive el paquete.
|
|
@@ -41,7 +52,10 @@ export function debeOfrecer(s) {
|
|
|
41
52
|
* usa la ruta `opt/` estable. El lanzador por `opt/` queda de repuesto para una
|
|
42
53
|
* fórmula instalada antes de que tuviera el bloque `service`.
|
|
43
54
|
*/
|
|
44
|
-
export function comoArrancar(raiz) {
|
|
55
|
+
export function comoArrancar(raiz, plataforma = process.platform) {
|
|
56
|
+
if (plataforma === 'linux') {
|
|
57
|
+
return { via: 'indicador', lanzador: join(raiz, 'bin', 'qm-indicator') };
|
|
58
|
+
}
|
|
45
59
|
const cellar = /^(.*)\/Cellar\/quartermaster\/[^/]+\/libexec\/?$/.exec(raiz);
|
|
46
60
|
if (cellar !== null) {
|
|
47
61
|
const prefijo = cellar[1];
|
|
@@ -62,28 +76,75 @@ const AGENTES = [
|
|
|
62
76
|
'homebrew.mxcl.quartermaster.plist',
|
|
63
77
|
].map((f) => join(homedir(), 'Library', 'LaunchAgents', f));
|
|
64
78
|
function sale0(cmd, args) {
|
|
79
|
+
return salida(cmd, args) === 0;
|
|
80
|
+
}
|
|
81
|
+
/** El código de salida, o -1 si no se pudo correr. Hay una bandera que usa el 2. */
|
|
82
|
+
function salida(cmd, args, ms = 4000) {
|
|
65
83
|
try {
|
|
66
|
-
execFileSync(cmd, args, { stdio: 'ignore', timeout:
|
|
67
|
-
return
|
|
84
|
+
execFileSync(cmd, args, { stdio: 'ignore', timeout: ms });
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
const n = e.status;
|
|
89
|
+
return typeof n === 'number' ? n : -1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** El proceso del item, por su ruta: el binario se llama distinto en cada plataforma. */
|
|
93
|
+
function corriendo(plataforma) {
|
|
94
|
+
const patron = plataforma === 'linux' ? 'quartermaster/bin/qm-indicator' : 'quartermaster/qm-barra';
|
|
95
|
+
return sale0('pgrep', ['-f', patron]);
|
|
96
|
+
}
|
|
97
|
+
/** El .desktop del arranque de sesión, donde XDG diga. */
|
|
98
|
+
const ARRANQUE_LINUX = join(process.env['XDG_CONFIG_HOME'] || join(homedir(), '.config'), 'autostart', 'quartermaster.desktop');
|
|
99
|
+
/**
|
|
100
|
+
* Ya hay una extensión del shell que muestre el item: la propia, o una de
|
|
101
|
+
* AppIndicator —la de rgcjonas o la de Ubuntu—. `gnome-extensions` lista las
|
|
102
|
+
* habilitadas; si no está el comando, no hay GNOME Shell.
|
|
103
|
+
*/
|
|
104
|
+
function hayHost() {
|
|
105
|
+
try {
|
|
106
|
+
const dichas = execFileSync('gnome-extensions', ['list', '--enabled'], { encoding: 'utf8', timeout: 4000, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
107
|
+
return dichas.split('\n').some((e) => e === EXTENSION || e.includes('appindicator'));
|
|
68
108
|
}
|
|
69
109
|
catch {
|
|
70
110
|
return false;
|
|
71
111
|
}
|
|
72
112
|
}
|
|
73
|
-
const
|
|
113
|
+
const EXTENSION = 'quartermaster@legios';
|
|
114
|
+
/** El paquete trae la extensión propia y hay un GNOME Shell donde ponerla. */
|
|
115
|
+
const puedeHospedar = (raiz) => existsSync(join(raiz, 'extension', EXTENSION)) && sale0('gnome-extensions', ['version']);
|
|
116
|
+
/** python3 con gi y el AppIndicator que el item importa al arrancar. */
|
|
117
|
+
const hayInterprete = () => sale0('python3', [
|
|
118
|
+
'-c',
|
|
119
|
+
"import gi;gi.require_version('AyatanaAppIndicator3','0.1');"
|
|
120
|
+
+ 'from gi.repository import AyatanaAppIndicator3,Gtk;import cairo',
|
|
121
|
+
]);
|
|
74
122
|
export function situacionActual(raiz, modoNormal) {
|
|
75
123
|
const darwin = process.platform === 'darwin';
|
|
76
|
-
|
|
124
|
+
const linux = process.platform === 'linux';
|
|
125
|
+
// Las preguntas baratas primero, y las que cuestan un proceso sólo si la
|
|
126
|
+
// plataforma es la suya y todavía puede haber algo que ofrecer: en un `qm`
|
|
127
|
+
// que ya preguntó, acá no corre nada.
|
|
128
|
+
const comun = {
|
|
77
129
|
plataforma: process.platform,
|
|
78
130
|
terminal: process.stdin.isTTY === true && process.stdout.isTTY === true,
|
|
79
131
|
ci: Boolean(process.env['CI']),
|
|
80
132
|
modoNormal,
|
|
81
133
|
yaPreguntado: existsSync(RUTA_RESPUESTA),
|
|
82
|
-
hayBarra: existsSync(join(raiz, 'bin', 'qm-barra')),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
134
|
+
hayBarra: existsSync(join(raiz, 'bin', darwin ? 'qm-barra' : 'qm-indicator')),
|
|
135
|
+
};
|
|
136
|
+
const vale = comun.terminal && !comun.ci && comun.modoNormal && !comun.yaPreguntado && comun.hayBarra;
|
|
137
|
+
return {
|
|
138
|
+
...comun,
|
|
139
|
+
compilador: vale && darwin && sale0('xcode-select', ['-p']),
|
|
140
|
+
sesionGrafica: linux && Boolean(process.env['DISPLAY'] || process.env['WAYLAND_DISPLAY']),
|
|
141
|
+
interprete: vale && linux && hayInterprete(),
|
|
142
|
+
hostDelItem: vale && linux && hayHost(),
|
|
143
|
+
puedeHospedar: vale && linux && puedeHospedar(raiz),
|
|
144
|
+
arranqueInstalado: darwin
|
|
145
|
+
? AGENTES.some((a) => existsSync(a))
|
|
146
|
+
: linux && existsSync(ARRANQUE_LINUX),
|
|
147
|
+
corriendo: vale && (darwin || linux) && corriendo(process.platform),
|
|
87
148
|
};
|
|
88
149
|
}
|
|
89
150
|
function anotar(respuesta) {
|
|
@@ -96,8 +157,42 @@ function anotar(respuesta) {
|
|
|
96
157
|
// deja a nadie sin números.
|
|
97
158
|
}
|
|
98
159
|
}
|
|
99
|
-
/** Arranca la barra y que arranque sola al iniciar sesión.
|
|
100
|
-
function arrancar(a) {
|
|
160
|
+
/** Arranca la barra y que arranque sola al iniciar sesión. */
|
|
161
|
+
function arrancar(a, s) {
|
|
162
|
+
if (a.via === 'indicador') {
|
|
163
|
+
// La extensión propia primero: es la que hace que un click abra el panel.
|
|
164
|
+
// Sin ella el item cae al menú de GTK, que no sostiene el agarre y se cierra
|
|
165
|
+
// apenas lo tocás. `--instalar-extension` sale 2 cuando quedó instalada y
|
|
166
|
+
// GNOME la carga recién al volver a entrar; eso no es un fallo, es lo que
|
|
167
|
+
// hay que decir.
|
|
168
|
+
let pideVolverAEntrar = false;
|
|
169
|
+
if (s.puedeHospedar) {
|
|
170
|
+
const n = salida(a.lanzador, ['--instalar-extension'], 15000);
|
|
171
|
+
if (n === 2)
|
|
172
|
+
pideVolverAEntrar = true;
|
|
173
|
+
else if (n !== 0 && !s.hostDelItem)
|
|
174
|
+
return { pudo: false, pideVolverAEntrar: false };
|
|
175
|
+
}
|
|
176
|
+
// Dos pasos y no uno: el .desktop es para la PRÓXIMA sesión, y quien acaba
|
|
177
|
+
// de contestar que sí quiere verlo ahora. `launchd` y `brew services`
|
|
178
|
+
// arrancan al instalar; un .desktop de autostart no arranca nada.
|
|
179
|
+
if (!existsSync(a.lanzador) || !sale0(a.lanzador, ['--instalar-arranque'])) {
|
|
180
|
+
return { pudo: false, pideVolverAEntrar };
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
// Desprendido y sin heredar la terminal: si no, queda colgado del shell
|
|
184
|
+
// y se muere al cerrarlo. La salida va a /dev/null acá y al journal en
|
|
185
|
+
// los arranques de sesión, que es donde se la va a buscar.
|
|
186
|
+
spawn(a.lanzador, [], { detached: true, stdio: 'ignore' }).unref();
|
|
187
|
+
return { pudo: true, pideVolverAEntrar };
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return { pudo: false, pideVolverAEntrar };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return { pudo: arrancarMac(a), pideVolverAEntrar: false };
|
|
194
|
+
}
|
|
195
|
+
function arrancarMac(a) {
|
|
101
196
|
if (a.via === 'brew' && sale0(a.brew, ['services', 'start', 'quartermaster']))
|
|
102
197
|
return true;
|
|
103
198
|
// `brew services` falla si la fórmula instalada es anterior al bloque
|
|
@@ -109,12 +204,14 @@ function arrancar(a) {
|
|
|
109
204
|
* `qm`: es un ofrecimiento, no parte de la respuesta.
|
|
110
205
|
*/
|
|
111
206
|
export async function ofrecerBarra(raiz, modoNormal) {
|
|
112
|
-
|
|
207
|
+
const s = situacionActual(raiz, modoNormal);
|
|
208
|
+
if (!debeOfrecer(s))
|
|
113
209
|
return;
|
|
210
|
+
const donde = process.platform === 'linux' ? 'la barra de arriba' : 'la barra de menú';
|
|
114
211
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
115
212
|
let texto;
|
|
116
213
|
try {
|
|
117
|
-
texto = await rl.question(
|
|
214
|
+
texto = await rl.question(`¿Mostrar esto en ${donde}, y que arranque solo al iniciar sesión? [S/n] `);
|
|
118
215
|
}
|
|
119
216
|
catch {
|
|
120
217
|
// Ctrl-D o ctrl-c: la pregunta se aborta y readline tira ABORT_ERR. Eso no
|
|
@@ -129,22 +226,36 @@ export async function ofrecerBarra(raiz, modoNormal) {
|
|
|
129
226
|
}
|
|
130
227
|
const a = comoArrancar(raiz);
|
|
131
228
|
const comando = a.via === 'brew' ? 'brew services start quartermaster' : `${a.lanzador} --instalar-arranque`;
|
|
229
|
+
const listo = process.platform === 'linux' ? ' listo: arriba, en la barra.' : ' listo: arriba a la derecha.';
|
|
132
230
|
if (/^\s*n/i.test(texto)) {
|
|
133
231
|
anotar('no');
|
|
134
232
|
console.log(`Listo, no se vuelve a preguntar. Si cambiás de idea: ${comando}`);
|
|
135
233
|
return;
|
|
136
234
|
}
|
|
137
235
|
anotar('si');
|
|
138
|
-
|
|
236
|
+
const hecho = arrancar(a, s);
|
|
237
|
+
if (!hecho.pudo) {
|
|
139
238
|
console.log(`No pude arrancarla. A mano: ${comando}`);
|
|
140
239
|
return;
|
|
141
240
|
}
|
|
142
|
-
//
|
|
143
|
-
// espera a
|
|
144
|
-
|
|
241
|
+
// En macOS la primera vez compila bin/qm-barra.swift, que tarda unos
|
|
242
|
+
// segundos. Se espera a verlo corriendo para no decir «listo» de algo que no
|
|
243
|
+
// apareció — que es el bug que este programa existe para no cometer.
|
|
244
|
+
// Y lo que se dice al final tiene que ser lo que se va a ver. GNOME no carga
|
|
245
|
+
// una extensión recién instalada en Wayland: si ésta es la que va a mostrar
|
|
246
|
+
// el item, hasta la próxima sesión no aparece nada, y decir «listo: arriba,
|
|
247
|
+
// en la barra» ahí sería mentir sobre la única cosa que se vino a hacer.
|
|
248
|
+
const vuelta = hecho.pideVolverAEntrar
|
|
249
|
+
? (s.hostDelItem
|
|
250
|
+
? ' listo: arriba, en la barra. El panel completo aparece cuando vuelvas a'
|
|
251
|
+
+ ' entrar: GNOME no carga extensiones nuevas en Wayland.'
|
|
252
|
+
: ' listo, pero el item aparece cuando vuelvas a entrar: GNOME no carga'
|
|
253
|
+
+ ' extensiones nuevas en Wayland.')
|
|
254
|
+
: listo;
|
|
255
|
+
process.stdout.write(`arrancando ${donde}…`);
|
|
145
256
|
for (let i = 0; i < 60; i += 1) {
|
|
146
|
-
if (corriendo()) {
|
|
147
|
-
console.log(
|
|
257
|
+
if (corriendo(process.platform)) {
|
|
258
|
+
console.log(vuelta);
|
|
148
259
|
return;
|
|
149
260
|
}
|
|
150
261
|
await new Promise((r) => setTimeout(r, 1000));
|