First of six phase 1 PRs from the plan on #1. No checks yet: this is the frame every check runs in. Already running on CT 173 (bootstrapped from this branch), with all four sources answering.
What's here
Settings (thor/config.py): non-secret /etc/thor/thor.json plus secrets in /etc/thor/*.env (root:thor 0640, never in git). Every check defaults to shadow.
Source clients (thor/clients/), all read-only. A source that can't answer raises SourceError, which means "unknown", never "nothing found".
Prometheus: instant and range queries.
Loki: lifted from Gandalf's reboots.py (gandalf@1c250d6), now keeping stream labels and refusing windows over 30 days.
Proxmox: token thor@pve!monitor (PVEAuditor). Tries the nodes in turn and remembers the one that answered. A refused token fails at once instead of trying every node. ceph_flags() includes pause.
Gandalf: machine key from gandalf#68, suppressions with include_ended.
Tinker: adapted from Gandalf's TicketClient; every create sends dedup_key (tinker_tickets#123). Nothing calls it yet.
Database (thor/db.py): schema thor on CT 149, versioned migrations, UTC times. Every failure is a DatabaseError the caller survives.
Monitor loop (thor/monitor.py), 120 s, following the Area 1 rules:
Each cycle reviews the window since the last good one; after downtime it catches up for at most 24 h.
A source that can't answer opens a blind period; it doesn't fail the cycle.
Writes are buffered in memory while CT 149 is away (bounded), and the loop keeps running.
A failing check leaves its window to be reviewed again next cycle; other checks still run.
Web (thor/web/): /health checks the DB, monitor freshness and the deployed commit, and returns 503 when stale or when the DB is away. /metrics exposes thor_last_good_cycle_timestamp_seconds, thor_source_up, thor_cycle_duration_seconds and thor_build_info.
CI (.gitea/workflows/ci.yml), modelled on Pulse's:
flake8 and the em/en dash check
pytest with a 90% coverage floor
MariaDB integration tests
bandit, pip-audit
gitleaks, actionlint, shellcheck, zizmor, semgrep
Pinned actions and a pinned image digest (node:22-trixie, so Python 3.13 like prod).
main deploys through a signed webhook, then waits for /health to report the commit.
Deploy (deploy/):
thor_deploy.sh, Pulse's pattern: exact sha, timestamp and replay checks, installs units and the nginx site only when changed, rolls back unless /health reports the sha with a working DB. Sandbox-tested.
bootstrap.sh: idempotent first install.
Hardened systemd units.
The webhook runs as its own user, with a sudoers entry for the deploy script only.
Verification
51 unit tests pass, plus 4 DB tests against a real MariaDB. Coverage is 95% without the DB.
flake8, bandit, shellcheck, actionlint, zizmor and semgrep (238 rules) are clean locally. No em or en dashes.
On CT 173: migration 1 applied; /health returns {"db":true,"monitor":"ok","sha":"b0e240a...","status":"ok"}; first cycle took 0.2 s with no blind sources.
Not in this PR
The engine, the memory check and the T1 replay (PR 2), reboots and known conditions with the T2 to T4 replays (PR 3), /covering and the UI (PR 4, comes with screenshots), MCP (PR 5), and Kuma/Prometheus/Grafana watching Thor (PR 6).
First of six phase 1 PRs from the plan on #1. No checks yet: this is the frame every check runs in. Already running on CT 173 (bootstrapped from this branch), with all four sources answering.
## What's here
- **Settings** (`thor/config.py`): non-secret `/etc/thor/thor.json` plus secrets in `/etc/thor/*.env` (root:thor 0640, never in git). Every check defaults to `shadow`.
- **Source clients** (`thor/clients/`), all read-only. A source that can't answer raises `SourceError`, which means "unknown", never "nothing found".
- Prometheus: instant and range queries.
- Loki: lifted from Gandalf's `reboots.py` (gandalf@1c250d6), now keeping stream labels and refusing windows over 30 days.
- Proxmox: token `thor@pve!monitor` (PVEAuditor). Tries the nodes in turn and remembers the one that answered. A refused token fails at once instead of trying every node. `ceph_flags()` includes `pause`.
- Gandalf: machine key from gandalf#68, suppressions with `include_ended`.
- Tinker: adapted from Gandalf's `TicketClient`; every create sends `dedup_key` (tinker_tickets#123). Nothing calls it yet.
- **Database** (`thor/db.py`): schema `thor` on CT 149, versioned migrations, UTC times. Every failure is a `DatabaseError` the caller survives.
- **Monitor loop** (`thor/monitor.py`), 120 s, following the Area 1 rules:
- Each cycle reviews the window since the last good one; after downtime it catches up for at most 24 h.
- A source that can't answer opens a blind period; it doesn't fail the cycle.
- Writes are buffered in memory while CT 149 is away (bounded), and the loop keeps running.
- A failing check leaves its window to be reviewed again next cycle; other checks still run.
- **Web** (`thor/web/`): `/health` checks the DB, monitor freshness and the deployed commit, and returns 503 when stale or when the DB is away. `/metrics` exposes `thor_last_good_cycle_timestamp_seconds`, `thor_source_up`, `thor_cycle_duration_seconds` and `thor_build_info`.
- **CI** (`.gitea/workflows/ci.yml`), modelled on Pulse's:
- flake8 and the em/en dash check
- pytest with a 90% coverage floor
- MariaDB integration tests
- bandit, pip-audit
- gitleaks, actionlint, shellcheck, zizmor, semgrep
- Pinned actions and a pinned image digest (`node:22-trixie`, so Python 3.13 like prod).
- `main` deploys through a signed webhook, then waits for `/health` to report the commit.
- **Deploy** (`deploy/`):
- `thor_deploy.sh`, Pulse's pattern: exact sha, timestamp and replay checks, installs units and the nginx site only when changed, rolls back unless `/health` reports the sha with a working DB. Sandbox-tested.
- `bootstrap.sh`: idempotent first install.
- Hardened systemd units.
- The webhook runs as its own user, with a sudoers entry for the deploy script only.
## Verification
- 51 unit tests pass, plus 4 DB tests against a real MariaDB. Coverage is 95% without the DB.
- flake8, bandit, shellcheck, actionlint, zizmor and semgrep (238 rules) are clean locally. No em or en dashes.
- **On CT 173:** migration 1 applied; `/health` returns `{"db":true,"monitor":"ok","sha":"b0e240a...","status":"ok"}`; first cycle took 0.2 s with no blind sources.
## Not in this PR
The engine, the memory check and the T1 replay (PR 2), reboots and known conditions with the T2 to T4 replays (PR 3), `/covering` and the UI (PR 4, comes with screenshots), MCP (PR 5), and Kuma/Prometheus/Grafana watching Thor (PR 6).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Work in progress for thor#1 phase 1 (PR 1 of 6). Not yet pushed: CI workflow and deploy files still to add.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- .gitea/workflows/ci.yml: flake8 + dash check, pytest (90% coverage floor), MariaDB
integration tests, bandit, pip-audit, gitleaks, actionlint, shellcheck, zizmor, semgrep;
main deploys through a signed webhook and waits for /health to report the commit.
- deploy/thor_deploy.sh: deploys an exact sha, installs units and nginx site when changed,
rolls back unless /health reports the sha with a working database. Sandbox-tested.
- deploy/bootstrap.sh: idempotent first install on CT 173.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
/var/log/thor-deploy.log: deploying e676a8e... (previous b0e240a...), then deployed e676a8e...: healthy, 3 s later.
No tracebacks in journalctl -u thor -u thor-monitor.
Also set up for this deploy: repo secret WEBHOOK_SECRET (copied from the CT without printing it); thor.lotusguild.org in NPM (proxy host 60, cloned from Gandalf's host 50, wildcard cert) behind the Authelia rule two_factor, group admin.
Merged and deployed through CI (run 4019: lint, test, integration, security, scan, deploy all green).
**Deploy verified on CT 173:**
- Prod HEAD: `e676a8e6587de77d8e22a503fd9ad529aacd15c6` (the merge commit); `/opt/thor/revision.env` matches.
- `thor`, `thor-monitor` and `webhook` are active.
- `/health`: `{"db":true,"monitor":"ok","sha":"e676a8e...","status":"ok"}`, HTTP 200.
- `/var/log/thor-deploy.log`: `deploying e676a8e... (previous b0e240a...)`, then `deployed e676a8e...: healthy`, 3 s later.
- No tracebacks in `journalctl -u thor -u thor-monitor`.
Also set up for this deploy: repo secret `WEBHOOK_SECRET` (copied from the CT without printing it); `thor.lotusguild.org` in NPM (proxy host 60, cloned from Gandalf's host 50, wildcard cert) behind the Authelia rule `two_factor`, group admin.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
First of six phase 1 PRs from the plan on #1. No checks yet: this is the frame every check runs in. Already running on CT 173 (bootstrapped from this branch), with all four sources answering.
What's here
thor/config.py): non-secret/etc/thor/thor.jsonplus secrets in/etc/thor/*.env(root:thor 0640, never in git). Every check defaults toshadow.thor/clients/), all read-only. A source that can't answer raisesSourceError, which means "unknown", never "nothing found".reboots.py(gandalf@1c250d6), now keeping stream labels and refusing windows over 30 days.thor@pve!monitor(PVEAuditor). Tries the nodes in turn and remembers the one that answered. A refused token fails at once instead of trying every node.ceph_flags()includespause.include_ended.TicketClient; every create sendsdedup_key(tinker_tickets#123). Nothing calls it yet.thor/db.py): schemathoron CT 149, versioned migrations, UTC times. Every failure is aDatabaseErrorthe caller survives.thor/monitor.py), 120 s, following the Area 1 rules:thor/web/):/healthchecks the DB, monitor freshness and the deployed commit, and returns 503 when stale or when the DB is away./metricsexposesthor_last_good_cycle_timestamp_seconds,thor_source_up,thor_cycle_duration_secondsandthor_build_info..gitea/workflows/ci.yml), modelled on Pulse's:node:22-trixie, so Python 3.13 like prod).maindeploys through a signed webhook, then waits for/healthto report the commit.deploy/):thor_deploy.sh, Pulse's pattern: exact sha, timestamp and replay checks, installs units and the nginx site only when changed, rolls back unless/healthreports the sha with a working DB. Sandbox-tested.bootstrap.sh: idempotent first install.Verification
/healthreturns{"db":true,"monitor":"ok","sha":"b0e240a...","status":"ok"}; first cycle took 0.2 s with no blind sources.Not in this PR
The engine, the memory check and the T1 replay (PR 2), reboots and known conditions with the T2 to T4 replays (PR 3),
/coveringand the UI (PR 4, comes with screenshots), MCP (PR 5), and Kuma/Prometheus/Grafana watching Thor (PR 6).🤖 Generated with Claude Code
Merged and deployed through CI (run 4019: lint, test, integration, security, scan, deploy all green).
Deploy verified on CT 173:
e676a8e6587de77d8e22a503fd9ad529aacd15c6(the merge commit);/opt/thor/revision.envmatches.thor,thor-monitorandwebhookare active./health:{"db":true,"monitor":"ok","sha":"e676a8e...","status":"ok"}, HTTP 200./var/log/thor-deploy.log:deploying e676a8e... (previous b0e240a...), thendeployed e676a8e...: healthy, 3 s later.journalctl -u thor -u thor-monitor.Also set up for this deploy: repo secret
WEBHOOK_SECRET(copied from the CT without printing it);thor.lotusguild.orgin NPM (proxy host 60, cloned from Gandalf's host 50, wildcard cert) behind the Authelia ruletwo_factor, group admin.