posthumous 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- posthumous-0.7.0/.claude/settings.local.json +11 -0
- posthumous-0.7.0/.gitignore +14 -0
- posthumous-0.7.0/CLAUDE.md +87 -0
- posthumous-0.7.0/LICENSE +21 -0
- posthumous-0.7.0/PKG-INFO +696 -0
- posthumous-0.7.0/README.md +656 -0
- posthumous-0.7.0/blog/01-checkin-armed.png +0 -0
- posthumous-0.7.0/blog/02-dashboard-fresh.png +0 -0
- posthumous-0.7.0/blog/03-checkin-after.png +0 -0
- posthumous-0.7.0/blog/04-dashboard-armed.png +0 -0
- posthumous-0.7.0/blog/05-dashboard-triggered.png +0 -0
- posthumous-0.7.0/blog/06-checkin-triggered.png +0 -0
- posthumous-0.7.0/blog/index.md +295 -0
- posthumous-0.7.0/docs/superpowers/plans/2026-03-16-resilient-federation.md +1256 -0
- posthumous-0.7.0/docs/superpowers/plans/2026-04-12-quorum-federation.md +1914 -0
- posthumous-0.7.0/docs/superpowers/specs/2026-03-16-resilient-federation-design.md +195 -0
- posthumous-0.7.0/docs/superpowers/specs/2026-04-12-quorum-federation-design.md +234 -0
- posthumous-0.7.0/pyproject.toml +77 -0
- posthumous-0.7.0/src/posthumous/__init__.py +3 -0
- posthumous-0.7.0/src/posthumous/__main__.py +6 -0
- posthumous-0.7.0/src/posthumous/auth.py +239 -0
- posthumous-0.7.0/src/posthumous/cli.py +739 -0
- posthumous-0.7.0/src/posthumous/config.py +500 -0
- posthumous-0.7.0/src/posthumous/crypto.py +229 -0
- posthumous-0.7.0/src/posthumous/dsl.py +421 -0
- posthumous-0.7.0/src/posthumous/notifications.py +300 -0
- posthumous-0.7.0/src/posthumous/peers.py +497 -0
- posthumous-0.7.0/src/posthumous/quorum.py +182 -0
- posthumous-0.7.0/src/posthumous/runner.py +350 -0
- posthumous-0.7.0/src/posthumous/scheduler.py +308 -0
- posthumous-0.7.0/src/posthumous/scripts.py +340 -0
- posthumous-0.7.0/src/posthumous/server.py +822 -0
- posthumous-0.7.0/src/posthumous/state.py +399 -0
- posthumous-0.7.0/src/posthumous/systemd.py +104 -0
- posthumous-0.7.0/src/posthumous/watchdog.py +327 -0
- posthumous-0.7.0/tests/__init__.py +1 -0
- posthumous-0.7.0/tests/conftest.py +42 -0
- posthumous-0.7.0/tests/test_auth.py +252 -0
- posthumous-0.7.0/tests/test_cli.py +1527 -0
- posthumous-0.7.0/tests/test_cli_config.py +271 -0
- posthumous-0.7.0/tests/test_cli_run.py +584 -0
- posthumous-0.7.0/tests/test_config.py +862 -0
- posthumous-0.7.0/tests/test_crypto.py +431 -0
- posthumous-0.7.0/tests/test_dsl.py +809 -0
- posthumous-0.7.0/tests/test_notifications.py +425 -0
- posthumous-0.7.0/tests/test_peers.py +1528 -0
- posthumous-0.7.0/tests/test_quorum.py +210 -0
- posthumous-0.7.0/tests/test_runner.py +613 -0
- posthumous-0.7.0/tests/test_scheduler.py +661 -0
- posthumous-0.7.0/tests/test_scripts.py +526 -0
- posthumous-0.7.0/tests/test_server.py +1385 -0
- posthumous-0.7.0/tests/test_state.py +612 -0
- posthumous-0.7.0/tests/test_systemd.py +215 -0
- posthumous-0.7.0/tests/test_watchdog.py +850 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Build & Test Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install with dev dependencies
|
|
9
|
+
pip install -e ".[dev]"
|
|
10
|
+
|
|
11
|
+
# Run all tests (coverage is auto-enabled via pyproject.toml)
|
|
12
|
+
pytest
|
|
13
|
+
|
|
14
|
+
# Run a single test file / class / test
|
|
15
|
+
pytest tests/test_watchdog.py
|
|
16
|
+
pytest tests/test_auth.py::TestTOTP
|
|
17
|
+
pytest tests/test_state.py::TestState::test_transition_armed_to_warning
|
|
18
|
+
|
|
19
|
+
# Run tests matching a pattern
|
|
20
|
+
pytest -k "lockout"
|
|
21
|
+
|
|
22
|
+
# CLI entry points (both are equivalent)
|
|
23
|
+
posthumous --help
|
|
24
|
+
phm --help
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
No linter is configured. Build system is Hatchling (`pyproject.toml`). Python 3.10+.
|
|
28
|
+
|
|
29
|
+
## Architecture
|
|
30
|
+
|
|
31
|
+
Posthumous is a federated deadman switch. Users check in periodically via TOTP; if they stop, the system progresses through ARMED → WARNING → GRACE → TRIGGERED, sending notifications and running scripts at each stage. After trigger, a scheduler runs recurring post-trigger actions forever.
|
|
32
|
+
|
|
33
|
+
### Source Layout
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
src/posthumous/ # Package source (hatch wheel target)
|
|
37
|
+
tests/ # One test module per source module
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Runtime files live in `~/.posthumous/`: `config.yaml`, `state.yaml`, `scripts/`, `logs/`.
|
|
41
|
+
|
|
42
|
+
### Module Layers
|
|
43
|
+
|
|
44
|
+
**Foundation** (no internal imports):
|
|
45
|
+
- `config.py` — YAML config loading, duration parsing ("7 days", "12 hours"), validation. `Config` dataclass with `from_yaml()`, `to_dict()`, `validate()`.
|
|
46
|
+
- `state.py` — Atomic YAML persistence (temp file + `os.replace`), `Status` enum, `StateManager` with lazy loading. `State` dataclass tracks check-ins, failures, peer states, schedule dedup.
|
|
47
|
+
- `dsl.py` — When-expression parser for scheduling. `ScheduleType` enum covers trigger-relative, recurring, anniversary, absolute-once, absolute-recurring. Key functions: `parse_when_expression()`, `get_next_occurrence()`, `should_execute()`, `get_period_key()`.
|
|
48
|
+
- `notifications.py` — Apprise wrapper with retry logic (3x, 5s between). Template formatting with `{days_left}`, `{hours_left}`, `{node_name}`, etc. Runs Apprise via `run_in_executor` (sync library).
|
|
49
|
+
- `scripts.py` — Async subprocess execution. `ScriptContext` exports `POSTHUMOUS_*` env vars and creates a temp JSON context file (auto-cleaned). 300s default timeout.
|
|
50
|
+
- `auth.py` — TOTP via pyotp, API token verification, HMAC-SHA256 message signing for peer auth, brute-force lockout tracking. `Authenticator` class, `LockedOutError`/`AuthError` exceptions.
|
|
51
|
+
|
|
52
|
+
**Integration** (compose foundation modules):
|
|
53
|
+
- `watchdog.py` — Async timer loop (60s check interval). `_transition_through(*statuses)` fires callbacks in sequence when catching up after downtime.
|
|
54
|
+
- `scheduler.py` — Post-trigger action engine. Parses when-expressions via `dsl.py`, tracks execution with period-based dedup keys (e.g., "2026", "2026-W05"). Only runs when TRIGGERED.
|
|
55
|
+
- `peers.py` — HMAC-signed broadcasts to federated peers via `_broadcast_to_all()` (concurrent). Handles check-in sync, trigger propagation, scheduled item completion. Background health check loop.
|
|
56
|
+
- `server.py` — aiohttp server: dark-themed web check-in form, JSON API, peer sync endpoints (`/sync/checkin`, `/sync/trigger`, `/sync/scheduled`, `/sync/state`).
|
|
57
|
+
|
|
58
|
+
**CLI** (`cli.py`):
|
|
59
|
+
- Wires all components together in the `run` command. Uses shared `execute_actions()` for warning/grace/trigger callbacks. Click-based with subcommands: `init`, `config`, `run`, `checkin`, `status`, `peers`, `test-notify`, `test-trigger`, `export`, `import`.
|
|
60
|
+
|
|
61
|
+
### State Machine
|
|
62
|
+
|
|
63
|
+
Check-ins reset to ARMED from any pre-trigger state. TRIGGERED is terminal — no check-in can undo it.
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
ARMED ──timeout──► WARNING ──timeout──► GRACE ──timeout──► TRIGGERED
|
|
67
|
+
▲ │ │ │
|
|
68
|
+
└───── check-in ────┴───── check-in ────┘ ▼
|
|
69
|
+
(scheduler runs forever)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Key Design Decisions
|
|
73
|
+
|
|
74
|
+
- **Atomic writes**: State uses `tempfile.mkstemp()` + `os.replace()` in the same directory for crash-safe persistence.
|
|
75
|
+
- **Catch-up transitions**: If a node was offline and missed WARNING, the watchdog fires all intermediate callbacks in order before reaching the current state.
|
|
76
|
+
- **Federation bias**: Failure mode is duplicates (annoying) not silence (catastrophic). Multiple nodes may fire the same action; dedup keys prevent repeats on the same node.
|
|
77
|
+
- **Async throughout**: Watchdog, scheduler, peer health, and script execution all use asyncio. Apprise (synchronous) runs via `run_in_executor`.
|
|
78
|
+
- **UTC everywhere**: All timestamps use `datetime.now(timezone.utc)`. Time arithmetic uses `timedelta` and `dateutil.relativedelta` for month/year offsets in the DSL.
|
|
79
|
+
|
|
80
|
+
### Test Conventions
|
|
81
|
+
|
|
82
|
+
- Async tests use `@pytest.mark.asyncio` with `asyncio_mode = "auto"` (auto-detect, no explicit marker needed)
|
|
83
|
+
- Watchdog/scheduler callbacks are tested with `AsyncMock`
|
|
84
|
+
- Peer tests mock `aiohttp.ClientSession` (must use `AsyncMock` for `.close()`)
|
|
85
|
+
- Time-dependent tests use `freezegun` to mock `datetime.now`
|
|
86
|
+
- `aioresponses` mocks HTTP calls in peer/server tests
|
|
87
|
+
- Shared fixtures in `tests/conftest.py`: `tmp_config_dir` (creates `~/.posthumous/` structure in `tmp_path`), `sample_config_yaml` (writes a valid config file)
|
posthumous-0.7.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alex Towell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|