utils/sickdays/sickdays/_constants.py
Krzysztof kuhy Rudnicki 0a51c9998d
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file length / file-length (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
sickdays pre-commit / pre-commit (push) Waiting to run
sickdays tests / test (push) Waiting to run
sickdays 0.2.0: per-locker keep set on a sick day
A sick day may keep some lockers active: a locker stands down iff the day
is sick and the locker is not in that day's keep set. New record field
`keep` = [sorted, de-duplicated locker ids, hlc].

- add/remove write state, actor and keep on one tick (keep=[] on a clear),
  so a stale keep cannot survive a clear + re-add.
- set_kept_lockers re-stamps only keep and actor; state keeps its clock, so
  a keep edit never re-asserts sick over a concurrent clear. Ticks are
  issued after every clock already on the record (clock-skew safe).
- Reading: no keep (0.1.0) or keep older than state -> keep nothing;
  malformed keep -> every locker kept (fail closed, logged); unknown ids
  ignored.
- API: stands_down, kept_lockers, set_kept_lockers, add_sick_day(keep=),
  SickDay.keep, LOCKER_* / LOCKERS. is_sick_day unchanged.
- CLI: add --keep, keep DAY [LOCKER ...], list shows keep, check --locker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PAhbNszs5JKdtnD4uBi3xp
2026-10-16 15:08:06 +02:00

78 lines
3.0 KiB
Python

# Copyright (c) 2026 Krzysztof Rudnicki
"""On-disk locations, remote paths and record field names.
Every path here is a *default*. Public functions take the corresponding
argument and only fall back to these when it is ``None``, so tests can point
the whole package at a tmp_path and a bug in this package can never write
into real user state. See ``sickdays/tests/conftest.py``, which redirects
these as a second line of defence.
Nothing here is shared with freedays. The two pools are different things
with different names, so they never share a directory, a file or a remote
node -- a sync bug in one can never touch the other.
"""
from __future__ import annotations
from pathlib import Path
from typing import Final
APP_NAME: Final = "sickdays"
STATE_DIR: Final = Path.home() / ".local" / "share" / "sickdays"
#: The CRDT log itself: ISO date -> Record(state=sick|cleared).
LOG_PATH: Final = STATE_DIR / "sick_days.json"
#: crdt-sync's per-device push/pull bookkeeping. Never merged, purely local.
SYNC_STATE_PATH: Final = STATE_DIR / "sync_state.json"
#: This install's persisted uuid. Never a fixed "pc"/"phone" constant, so two
#: machines can never collide on one device directory.
DEVICE_ID_PATH: Final = STATE_DIR / "device_id"
#: Append-only HMAC-signed record of every add/remove/import, for
#: after-the-fact review. Not consulted by any decision -- the log is the truth.
AUDIT_PATH: Final = STATE_DIR / "audit.jsonl"
#: Signing key for the audit trail, generated on first use. User-owned, as in
#: freedays: the signature answers "was this line edited after the fact" for
#: the person's own review, it does not defend a budget (there is none).
HMAC_KEY_FILE: Final = STATE_DIR / "hmac.key"
#: Remote layout, mirroring every other app: one directory per device under
#: a prefix, each device writing only its own file.
SYNC_PATH_PREFIX: Final = "sickdays-sync/devices"
SYNC_FILENAME: Final = "sick_days.json"
#: Field names inside a Record.
FIELD_STATE: Final = "state"
FIELD_ACTOR: Final = "actor"
#: The sorted, de-duplicated list of locker ids that stay active on the day
#: (0.2.0). Absent on every 0.1.0 record, which reads as "keep nothing".
FIELD_KEEP: Final = "keep"
#: Values of FIELD_STATE. Removing flips the field rather than tombstoning
#: the record: crdt-sync deletes are monotonic (OR-merged), so a tombstoned
#: date could never be marked sick again.
STATE_SICK: Final = "sick"
STATE_CLEARED: Final = "cleared"
#: Locker ids a sick day may keep active (``FIELD_KEEP``). A locker *stands
#: down* on a day iff the day is sick and the locker is not in its keep set.
#: These strings are wire format: the phone writes the same ones.
LOCKER_WORKOUT: Final = "workout"
LOCKER_LEETCODE: Final = "leetcode"
LOCKER_BOOK: Final = "book"
LOCKER_DIET: Final = "diet"
#: The phone ring, the PC fallback ring, the RTC self-wake and the
#: missed-alarm penalty -- one switch, because they are one alarm.
LOCKER_ALARM: Final = "alarm"
LOCKERS: Final = (
LOCKER_WORKOUT,
LOCKER_LEETCODE,
LOCKER_BOOK,
LOCKER_DIET,
LOCKER_ALARM,
)