mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-10 19:07:05 +01:00
The enforcer now imports the Steam/launcher/counted-process scan from leisure_watch.procscan (v0.1.0, shared with the leisure watcher) and drops its own copies (_playtime_procs, _counted_procs, _total_block_launchers and enforcer's two scanners). Every counted-process read passes config.CONFIG_FILE explicitly, as before. Each tick also bills a shadow leisure budget beside the enforced one, from the same incoming stamp and delta clamp, before accumulate: paused (held gatelock grab or i3lock) -> shadow_paused_seconds; else a qualifying game, a "leisure" now.json, or an untrusted/missing now.json (fail closed) bills shadow_seconds once, split over shadow_per_source. shadow_budget_seconds is earned_time.resolve(leisure=True) from the same answers, held as a same-day high-water mark. Not billed under a total block. Shadow verdict changes go to budget.jsonl as shadow_change (the live game view skips them); /api/budget and MCP get_gaming_time carry a "shadow" block. Enforced fields, cutoff, warnings and existing log records are unchanged. Also fixes two tests that assumed earned_time < 0.14 internals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dsh4Znwh2KnC7q6vbGpX1N
34 lines
1.1 KiB
Python
34 lines
1.1 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) -> dict[str, Any]:
|
|
"""Compose the shadow block from stored state.
|
|
|
|
Args:
|
|
state: Loaded accounting state.
|
|
|
|
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": state.shadow_budget_seconds,
|
|
"seconds_remaining": round(remaining, 1),
|
|
"would_block": 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()},
|
|
}
|