steam-backlog-enforcer/steam_backlog_enforcer
Krzysztof kuhy Rudnicki 0c05d71008 Add a daily gaming-time budget with a binary-level cutoff
Accumulates time spent in Steam games and other launchers, and once the
daily budget (default 8h) is spent, shuts Steam down, kills the games, and
makes them unlaunchable until the next 06:00.

The gaming day starts at 06:00 local rather than midnight so a late session
counts against the day it began in; rollover is checked lazily against a
stored day key, so it survives suspend, reboot and daemon restarts with no
timer of its own. Elapsed time comes from wall-clock deltas clamped to two
tick intervals, which keeps suspends, missed ticks and NTP steps honest.

The block is a read-only bind mount of a refusal stub over all four launcher
entry points -- /usr/bin/steam is only a two-line exec wrapper, so masking it
alone leaves bin_steam.sh, Steam's own steam.sh and lutris live. A bind mount
mutates no bytes, umount restores exactly, and a reboot clears it
unconditionally; chmod/rename would leave Steam broken if the daemon died
mid-block. /proc/self/mountinfo is the authority on what is masked, never the
saved state, which is what makes a stale block release even if the state file
was deleted. The mount is deferred one tick past the cutoff so
`steam -shutdown` still works and games close cleanly.

Launchers are matched by cmdline, not comm: /usr/bin/lutris is a python3
script, so the kernel records its comm as "python3" and the existing scan
never sees it. The kill set is wider than the budget predicate, walking down
from each launcher, because a Lutris-launched Wine game carries no SteamAppId.

State is chattr +i'd -- ~/.config is user-writable, so root ownership alone
would not stop `rm` from resetting the counter -- and a missing state file
while mounts are live fails closed rather than lifting the block.

Also fixes a pre-existing bug: do_enforce returned when no game was assigned,
exiting the process. Since the budget is accounted for from inside that loop,
it silently stopped enforcing whenever a game was finished but not rescanned.

Verified on the desktop with a real game: AoE2 counted 18 processes, tripped
at the 60s demo budget, all processes killed, all four paths masked and
refusing, then gaming-unblock restored them byte-identical with
`pacman -Qkk steam lutris` reporting 0 altered files.

1322 tests pass at 100.00% branch coverage; pacman validated the ALPM hook.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QbEaXapjMSkxyzgvbdkUFb
2026-08-04 20:00:08 +02:00
..
docs feat(enforcer): raise manual pick cap from 2 to 3 concurrent games 2026-07-23 18:05:29 +02:00
tests Add a daily gaming-time budget with a binary-level cutoff 2026-08-04 20:00:08 +02:00
__init__.py feat: steam 100 percent extension 2026-03-02 20:29:32 +01:00
_actions.py fix(game_install): refuse to delete folders matching an allowed game's name 2026-07-25 15:50:29 +02:00
_allowed_games.py fix(game_install): refuse to delete folders matching an allowed game's name 2026-07-25 15:50:29 +02:00
_cmd_done.py feat(enforcer): allow two concurrent manual picks 2026-07-19 17:28:23 +02:00
_cmd_playtime.py Add a daily gaming-time budget with a binary-level cutoff 2026-08-04 20:00:08 +02:00
_desktop_env.py Pass XDG_RUNTIME_DIR when launching Steam as the desktop user 2026-07-26 14:39:38 +02:00
_enforce_loop.py Add a daily gaming-time budget with a binary-level cutoff 2026-08-04 20:00:08 +02:00
_hltb_detail.py fix: HLTB count_comp=0 bug, false matches, and ProtonDB log noise 2026-05-28 20:40:51 +02:00
_hltb_search.py fix: HLTB count_comp=0 bug, false matches, and ProtonDB log noise 2026-05-28 20:40:51 +02:00
_hltb_types.py chore: set up as standalone repo 2026-05-28 07:21:29 +02:00
_mcp.py Add a daily gaming-time budget with a binary-level cutoff 2026-08-04 20:00:08 +02:00
_playtime_block.py Add a daily gaming-time budget with a binary-level cutoff 2026-08-04 20:00:08 +02:00
_playtime.py Add a daily gaming-time budget with a binary-level cutoff 2026-08-04 20:00:08 +02:00
_scanning_confidence.py fix: HLTB count_comp=0 bug, false matches, and ProtonDB log noise 2026-05-28 20:40:51 +02:00
_stats.py Fix pre-existing CI failures from the MCP-server commit 2026-07-10 23:04:07 +02:00
_steam_state.py fix(enforcer): defer Steam restart while a game update is in progress 2026-07-18 15:59:47 +02:00
_total_block.py feat: block-gaming purges Steam/Proton filesystem remnants + helper packages 2026-07-04 17:25:08 +02:00
_web_dataset.py feat(enforcer): allow two concurrent manual picks 2026-07-19 17:28:23 +02:00
_web_server.py feat: add interactive web UI for backlog completion planning 2026-05-29 18:35:45 +02:00
_whitelist.py perf(whitelist): only shell out to chattr when the immutable flag differs 2026-07-25 20:15:12 +02:00
config.py Add a daily gaming-time budget with a binary-level cutoff 2026-08-04 20:00:08 +02:00
enforcer.py feat(enforcer): allow two concurrent manual picks 2026-07-19 17:28:23 +02:00
game_install.py Pass XDG_RUNTIME_DIR when launching Steam as the desktop user 2026-07-26 14:39:38 +02:00
hltb.py feat: add pick-manual command with 2-week enforcement lock 2026-05-30 17:15:37 +02:00
library_hider.py Pass XDG_RUNTIME_DIR when launching Steam as the desktop user 2026-07-26 14:39:38 +02:00
main.py Add a daily gaming-time budget with a binary-level cutoff 2026-08-04 20:00:08 +02:00
protondb.py fix: HLTB count_comp=0 bug, false matches, and ProtonDB log noise 2026-05-28 20:40:51 +02:00
scanning.py chore: set up as standalone repo 2026-05-28 07:21:29 +02:00
steam_api.py feat(steam_backlog_enforcer): harden whitelist against circumvention 2026-05-17 20:44:05 +02:00
store_blocker.py feat: add block-gaming command (Stage 4) + guard-lib migration cleanup 2026-07-04 11:45:54 +02:00