mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-21 12:32:24 +01:00
Kuhy removed the daily gaming/leisure budget; only shutdown time (screen-locker) stays. One gate, _gaming_gate.gaming_enforced_on(day), wraps earned_time 0.22.0 gaming_enforced; resolve_budget carries it as BudgetResolution.enforced and rules_for as PlaytimeRules.gaming_enforced. Unlimited day: no warning, no cutoff, no kill, no leisure billing or leisure kill; a block left from an earlier day is lifted. Time is still billed for history. Backlog game choice and launch scope are untouched. MCP, CLI and /api/budget report unlimited with null numbers; the web UI paints the no-cap icon, no meter. Past-day history keeps working. Failure modes: switch unreadable or day key not a date -> fail OPEN (unlimited), logged ERROR once per cause, never raises, so the 5 h fallback is never enforced and the daemon never crashes. Demo runs stay enforced. The playtime_state.json schema is unchanged. Pins earned-time-v0.22.0 and leisure-watch-v0.2.8 (freshness gate; only golive.py changed, procscan untouched). DOCS-web-control-api notes null fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWViGJJaqBKGr1Hbppr
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
"""The shadow leisure block (contract C4) for ``/api/budget`` and MCP.
|
|
|
|
Read-only and display-only: what the leisure budget *would* say, beside the
|
|
enforced gaming numbers it never changes.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
from steam_backlog_enforcer._playtime_state import PlaytimeState
|
|
|
|
|
|
def shadow_view(state: PlaytimeState, *, unlimited: bool = False) -> dict[str, Any]:
|
|
"""Compose the shadow block from stored state.
|
|
|
|
Args:
|
|
state: Loaded accounting state.
|
|
unlimited: No budget applies (2026-11-16): report no budget number.
|
|
|
|
Returns:
|
|
Used/budget/remaining seconds, whether the leisure budget would block
|
|
now, paused seconds, and the per-source split.
|
|
"""
|
|
remaining = max(0.0, state.shadow.budget_seconds - state.shadow.seconds)
|
|
return {
|
|
"seconds_used": round(state.shadow.seconds, 1),
|
|
"budget_seconds": None if unlimited else state.shadow.budget_seconds,
|
|
"seconds_remaining": None if unlimited else round(remaining, 1),
|
|
"would_block": False if unlimited else remaining <= 0.0,
|
|
"paused_seconds": round(state.shadow.paused_seconds, 1),
|
|
"per_source": {k: round(v, 1) for k, v in state.shadow.per_source.items()},
|
|
}
|