Run on the stack host, react to Matrix events, keep the repo current

The stack moved to AWS Lightsail, so the maintainer now runs on that host
as ubuntu and is triggered by events rather than polling:

- A long-poll /sync delivers operator messages and #stack-alerts within
  about a second. Follow-ups resume the Claude session, so the Stack
  Maintenance room works like a chat. status, cancel, new, upgrade and
  help are answered even while a run is in progress.
- FIRING alerts from the Alertmanager bridge are batched and triaged in a
  thread, with a per-fingerprint cooldown.
- Agent runs go one at a time from a persisted priority queue, so an
  unusable agent defers work instead of losing it.
- Health checks add host resources (disk, memory, OOM kills, restart
  loops, stale Kuma) and reboot detection; one cycle's findings share a run.
- The daily report and the weekly upgrade run at fixed UTC times; the
  upgrade covers every image on the host.
- Applied changes are committed to semprini-core main and pushed. The
  daemon fast-forwards before a run and pushes leftovers after it.
- The Claude credential comes from `claude setup-token` via
  --set-claude-token. Self-update runs hourly, gated by --check.
- install.sh renders the unit for the current user and configures the git
  credential helper.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
paulandClaude Opus 5 committed 2026-09-15 23:22:34 +12:00
1 parent 46a1ec1e01
commit 556ffb6561
7 files changed
+2132 -863

No files matched your search

+13 -15
View File
@@ -1,28 +1,26 @@
[Unit]
Description=semprini-core autonomous stack maintenance agent
Documentation=file:///home/paul/Dev/semprini-maintainer/README.md
Documentation=https://git.semprini.me/paul/semprini-maintainer
After=docker.service network-online.target
Wants=network-online.target
Requires=docker.service
[Service]
Type=simple
# Runs as the host user (must be in the 'docker' group). NOT root: Claude Code
# refuses --permission-mode bypassPermissions when running as root.
User=paul
Group=paul
SupplementaryGroups=docker
WorkingDirectory=/home/paul/Dev/semprini-maintainer
Environment=HOME=/home/paul
Environment=PATH=/home/paul/.local/bin:/usr/local/bin:/usr/bin:/bin
ExecStart=/usr/bin/python3 /home/paul/Dev/semprini-maintainer/maintainer.py --config /home/paul/Dev/semprini-maintainer/config.json
# A template: install.sh fills in @USER@, @HOME@ and @DIR@.
# NOT root: Claude Code refuses --permission-mode bypassPermissions as root.
User=@USER@
Group=@USER@
# docker: drive the stack. adm: read the kernel log for OOM kills.
SupplementaryGroups=docker adm
WorkingDirectory=@DIR@
Environment=HOME=@HOME@
Environment=PATH=@HOME@/.local/bin:/usr/local/bin:/usr/bin:/bin
ExecStart=/usr/bin/python3 @DIR@/maintainer.py --config @DIR@/config.json
Restart=always
RestartSec=30
# Give a long-running upgrade plenty of time before any stop is considered hung.
TimeoutStopSec=120
# Light hardening (kept permissive — the agent legitimately drives Docker).
NoNewPrivileges=false
# Stopping kills the whole cgroup, an agent run in progress included.
TimeoutStopSec=30
StandardOutput=journal
StandardError=journal
SyslogIdentifier=semprini-maintainer