claude_desktop: fix gains report headroom gating + data_location

- Gate the headroom section on install_headroom (bashio::config.true), same
  as svc-headroom, instead of only checking whether the binary is on PATH
  (it's pip-installed unconditionally at build time, so it's always
  present). have_headroom is now just a secondary availability guard.
  Fixes noisy/stale headroom output when the option is disabled.
- Switch the shebang to with-contenv bashio so HOME comes from the s6
  envdir instead of a hardcoded /data/data. 20-folders.sh only rewrites
  /data/data references under /defaults, /etc/cont-init.d,
  /etc/services.d and /etc/s6-overlay/s6-rc.d — not /usr/local/bin — so
  a custom data_location previously left this script reading/writing the
  wrong home directory.

Verified live: real cron firing confirms with-contenv correctly resolves
HOME and bashio::config from the s6 envdir when invoked by cron; isolated
gating-logic test covers all four enabled/binary-present combinations.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
alexbelgium
2026-07-07 22:09:11 +02:00
parent 66b91278b9
commit e1a0f01fb9

View File

@@ -1,24 +1,34 @@
#!/usr/bin/env bash
#!/usr/bin/with-contenv bashio
# Hourly rtk + headroom token-savings snapshot for the add-on log.
# Invoked by cron (see /defaults/crontabs/root); its stdout is redirected to /proc/1/fd/1,
# so the report appears in the add-on log. Doubles as a heartbeat: if the numbers stop
# growing, the corresponding tool has stopped working.
export HOME=/data/data
# with-contenv supplies HOME from the s6 envdir, so this honors a custom `data_location`
# (see 20-folders.sh) instead of hardcoding /data/data; it also makes bashio::config
# available for the install_headroom gate below.
export NO_COLOR=1 # keep the add-on log free of ANSI color codes
export PATH="/lsiopy/bin:/usr/local/bin:/usr/bin:/bin:${PATH}"
have_rtk=false; command -v rtk >/dev/null 2>&1 && have_rtk=true
have_headroom=false; command -v headroom >/dev/null 2>&1 && have_headroom=true
# Nothing to report if neither tool is installed — stay quiet.
if ! $have_rtk && ! $have_headroom; then exit 0; fi
# headroom is pip-installed unconditionally at build time, so its binary is on PATH even
# when install_headroom is off — gate on the same config svc-headroom checks, and only
# fall back to have_headroom as a secondary availability guard.
headroom_enabled=false
if bashio::config.true 'install_headroom' && $have_headroom; then
headroom_enabled=true
fi
# Nothing to report if neither tool is active — stay quiet.
if ! $have_rtk && ! $headroom_enabled; then exit 0; fi
echo "===== claude gains report $(date '+%Y-%m-%d %H:%M:%S') ====="
if $have_rtk; then
echo "--- rtk gain ---"
rtk gain 2>&1 || echo "[warn] rtk gain failed"
fi
if $have_headroom; then
if $headroom_enabled; then
echo "--- headroom savings ---"
headroom savings 2>&1 || echo "[warn] headroom savings failed"
fi