diet-guard/diet-guard-gate.service
Krzysztof kuhy Rudnicki c310861855 slots: minute-of-day consumers (phase 2 of 3: Python side)
Every Python consumer now speaks slot minutes:

- satisfaction is nearest-slot snapping (_slot_wire.satisfied_by_entries)
  at every "is this slot logged?" site: gate, CLI status, MCP, catering
  occupancy and dedup. Nothing on disk is rewritten; 07:00/10:00 entries
  keep covering 07:15/10:15 after a schedule move.
- log_meal writes slot_fields(minute) before signing (slot + slot_min).
- schedule store and sync encode via schedule_to_wire/from_wire; a
  whole-hour schedule stays byte-identical (f/l/n only).
- CLI ate --hour takes HH or HH:MM; MCP log_meal takes "HH:MM" or a
  legacy int hour, validated against today's slots; get_slots returns
  {minute, label}.
- gate History tab: first/last are HH:MM ttk.Comboboxes (quarter-hour
  list, typed times, Up/Down step without posting the popdown), locked
  as disabled; validation mirrors normalized().
- gate timer fires every 15 min; docs rewritten for minutes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015npsYVB2PdtWkG7MPAi4tn
2026-10-10 19:53:39 +02:00

26 lines
1.3 KiB
Desktop File

[Unit]
Description=Diet Guard log-to-unlock gate (periodic check)
After=graphical-session.target
[Service]
Type=oneshot
# DISPLAY mirrors wake-alarm.service: the gate opens a Tk window when a lock
# is due, so without DISPLAY it would crash with "no display name and no
# $DISPLAY" before it could even check. The command self-checks gate_is_due()
# and exits 0 when no lock is needed, so running it every ~15 min is cheap.
# No PYTHONPATH needed: diet_guard is pip-installed (see install.sh / README),
# so /usr/bin/python finds it via user site-packages.
#
# XAUTHORITY pins the X auth cookie path explicitly. It is belt-and-suspenders,
# not the fix: when this unit fires at SESSION START (Persistent=true catch-up),
# it can beat the display manager writing ~/.Xauthority, so the cookie is simply
# absent yet -- pointing at it does not help. That race is handled in Python by
# wait_for_display(), which polls the display until it is connectable before
# opening the window (previously a session-start launch died on a "couldn't
# connect to display" TclError and never showed). The sleep gives the session a
# brief head start; the Python wait is what makes it reliable.
Environment=DISPLAY=:0
Environment=XAUTHORITY=%h/.Xauthority
ExecStartPre=/bin/sleep 1
ExecStart=/usr/bin/python -m diet_guard gate