mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-21 18:12:19 +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
89 lines
3.1 KiB
TypeScript
89 lines
3.1 KiB
TypeScript
// `/api/budget` fixture: today's usage ticks up in real time so the budget
|
|
// cards visibly move while the mock runs.
|
|
|
|
import type { BudgetSnapshot } from '../src/types.ts'
|
|
import { hash } from './games.ts'
|
|
|
|
const LEGEND = [
|
|
{ key: 'app:1145360', label: 'Hades' },
|
|
{ key: 'app:367520', label: 'Hollow Knight' },
|
|
{ key: 'app:2379780', label: 'Balatro' },
|
|
{ key: 'launcher:steam', label: 'Steam (launcher)' },
|
|
{ key: 'other', label: 'Other' },
|
|
]
|
|
|
|
const started = Date.now()
|
|
let resetAt: number | null = null
|
|
|
|
export function resetToday(): void {
|
|
resetAt = Date.now()
|
|
}
|
|
|
|
export function budget(demo: boolean): BudgetSnapshot {
|
|
const budgetSeconds = demo ? 60 : 3 * 3600
|
|
const base = demo ? 20 : 2 * 3600 + 10 * 60
|
|
const since = resetAt ?? started
|
|
// From 2026-11-16 the real backend has no budget (unlimited); the demo run still does.
|
|
const unlimited = !demo
|
|
const used = Math.min(unlimited ? Infinity : budgetSeconds, (resetAt === null ? base : 0) + Math.floor((Date.now() - since) / 1000))
|
|
const remaining = unlimited ? null : budgetSeconds - used
|
|
const today = new Date()
|
|
const history = Array.from({ length: 14 }, (_, i) => {
|
|
const d = new Date(today.getTime() - (13 - i) * 86_400_000)
|
|
const h = hash(i + 7)
|
|
const segs = LEGEND.map((l, j) => ({ key: l.key, seconds: j === 0 ? 1800 + (h % 5400) : (h >>> (j * 3)) % 2400 }))
|
|
return {
|
|
day: d.toISOString().slice(0, 10),
|
|
seconds: segs.reduce((a, s) => a + s.seconds, 0),
|
|
segments: segs,
|
|
}
|
|
})
|
|
const slices = [
|
|
{ key: 'app:1145360', label: 'Hades', seconds: Math.round(used * 0.82), fraction: 0.82 },
|
|
{ key: 'launcher:steam', label: 'Steam (launcher)', seconds: Math.round(used * 0.18), fraction: 0.18 },
|
|
]
|
|
return {
|
|
ok: true,
|
|
readable: true,
|
|
state_status: 'ok',
|
|
error: null,
|
|
today: {
|
|
gaming_day: today.toISOString().slice(0, 10),
|
|
day_starts_at: '06:00 local',
|
|
seconds_used: used,
|
|
unlimited,
|
|
budget_seconds: unlimited ? null : budgetSeconds,
|
|
seconds_remaining: remaining,
|
|
fraction_used: unlimited ? null : used / budgetSeconds,
|
|
blocked: remaining !== null && remaining <= 0,
|
|
blocked_at: remaining !== null && remaining <= 0 ? Math.floor(Date.now() / 1000) : 0,
|
|
next_warning_seconds: remaining === null ? null : remaining > 1800 ? 1800 : remaining > 600 ? 600 : null,
|
|
warned_seconds: remaining !== null && remaining <= 3600 ? [3600] : [],
|
|
games: used > 0 ? slices : [],
|
|
},
|
|
session: {
|
|
available: true,
|
|
observed_at: new Date().toISOString(),
|
|
state: remaining === null || remaining > 0 ? 'engaged' : 'blocked',
|
|
game_name: 'Hades',
|
|
billing_label: 'Hades',
|
|
qualifying_count: 2,
|
|
processes: [
|
|
{ pid: 48211, name: 'Hades.exe' },
|
|
{ pid: 48190, name: 'steam' },
|
|
],
|
|
},
|
|
history,
|
|
legend: LEGEND,
|
|
rules: {
|
|
unlimited,
|
|
budget_seconds: unlimited ? null : budgetSeconds,
|
|
enforcement: true,
|
|
counts_launchers: true,
|
|
warn_at: unlimited ? [] : [3600, 1800, 600, 300],
|
|
demo,
|
|
masked_launchers: ['heroic', 'lutris'],
|
|
},
|
|
}
|
|
}
|