Working on the live stack meant fighting the daemon: it triaged alerts a deploy caused, and its own commits landed mid-session. Stopping the service is the only lever today, and it is easy to leave stopped. `hold 45m <why>` in Matrix, or `maintainer.py --hold 45m --reason …` from a shell, pauses everything the daemon starts by itself — health cycles, alert triage, weekly upgrades — for a bounded time. Operator messages still run, and alerts still batch, so one triage run covers the whole hold. It says in the room when the hold starts and when it runs out, `status` shows it, and `resume` ends it early. The hold lives in hold.json beside the state file: `--hold` from a shell has to reach a daemon that rewrites its own state whenever it likes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
6.0 KiB
semprini-maintainer — Claude Instructions
What this is
A standalone, always-on autonomous maintenance agent for the semprini.me container
stack. It runs on the stack host itself (AWS Lightsail Semprini-Core,
ubuntu@3.107.254.151) as the systemd service semprini-maintainer. It keeps the stack
healthy and current and talks to the operator over Matrix (chat.semprini.me).
It is the unattended driver for the canonical stack-support agent, which lives in the separate semprini-core repo. This project does not reimplement that logic: it notices events, invokes the stack-support agent headless via Claude Code, and relays the agent's JSON result.
Relationship to other projects
-
semprini-core (
~/semprini-coreon the host, a git checkout ofmain) — the stack this agent maintains. At runtime the agent reads, fromrepo_dir:agents/stack-support.agent.md(injected as system prompt)docs/stack-support-runbook.mdandCLAUDE.mdcore_stack/compose*.yml
Keep the stack-support agent definition canonical in semprini-core — do not fork a copy here.
-
semprini-blog (GitHub) and conk run on the same host and are exposed to the agent via
extra_dirs. It can operate their containers but cannot push their repos, so it proposes file changes instead.
How it works (one screen)
- Operator messages (Stack Maintenance room): read by a long-poll
/sync, so they arrive within about a second. A follow-up withinconversation_ttl_secondsresumes the same Claude session (--resume), so it behaves like a chat.status,cancel,new,upgrade,hold,resumeandhelpare answered by the listener without the agent, even mid-run. - Hold (
hold 45m <why>in Matrix,maintainer.py --hold 45m --reason …from a shell): a time-boxed pause on everything the daemon starts by itself — health cycles, alert triage and upgrades — while operator messages still run and alerts still batch, so one triage run covers the whole hold. It lives inhold.jsonnext to the state file because a shell has to reach a daemon that owns its own state file, and it expires by itself so nothing stays paused by accident. semprini-core'ssync-to-host.shsets 15 minutes on each deploy. - Alerts (
#stack-alerts, written by@alertsvia Loki → Alertmanager → matrix-alerts): FIRING messages are batched foralerts.batch_secondsand triaged in one run, answered in a thread under the alert. Non-okresults are mirrored to Stack Maintenance. A fingerprint is re-investigated at most everyalerts.cooldown_seconds.PipelineTestis acknowledged, never investigated. - Health timer (5 min): Kuma monitors confirmed DOWN over
down_confirmationscycles, DOWN→UP blips (Kumaimportant=1heartbeats since a watermark), host checks (disk, memory, kernel OOM kills, container restart loops, a stale Kuma) and host reboots. All findings from one cycle become one health task. Kuma'skuma.dbis read via a throwawaykeinos/sqlite3container. Scope = Kuma's active monitors, re-read every cycle. - Daily report at
digest_hour_utc; weekly upgrade atupgrade_weekday/upgrade_hour_utc(all images on the host, not only Kuma-tracked ones; a pending reboot is escalated for approval). - One agent run at a time. The queue is persisted in the state file with priority operator > alerts > health > upgrade, so nothing is lost across restarts.
- Git: before a run the daemon fast-forwards clean checkouts in
git.repos; after it, it pushes unpushed commits and reports new commits or a dirty tree. The agent commits every change it applies tomainand pushes it (GIT_POLICYinmaintainer.py; semprini-coreCLAUDE.md→ Deploying changes). It pushes asclaude-codewith a token fromregister-gitea-bot.sh. - Claude credential:
claude_oauth_tokenfromclaude setup-token, saved bymaintainer.py --set-claude-tokenand re-read before every run. If the agent cannot run (AgentUnavailable), the task stays queued, the operator is told once, and retries back off from 60s to 15 min. - Self-update: hourly
git fetchof this checkout; a newermainis fast-forwarded, checked with--check, and re-exec'd, or rolled back if the check fails. - Autonomy (
config.json→autonomy):full(default) |fix-only|notify.
Conventions / guardrails
- Runs as host user
ubuntu(groupsdocker,adm), not root. Claude Code refuses--permission-mode bypassPermissionsunder root. maintainer.pyis stdlib-only — keep it dependency-free so it deploys without a venv.- Secrets live in
config.jsonand.bot-secrets— never commit (gitignored). - Deploying a change here: push to
mainon git.semprini.me. The running daemon picks it up withinself_update_interval_seconds. Keep--checkmeaningful — it is the gate a self-update must pass. - Prefer editing existing files over adding new ones.
- Log lines, alert text and web content reach the agent's context and are attacker- influenced. The system prompt says so; keep that line when editing prompts.
Files
| File | Purpose |
|---|---|
maintainer.py |
The daemon (stdlib only). |
config.example.json |
Template — copy to config.json. |
register-matrix-bot.sh |
Creates @maintainer-bot + the Stack Maintenance room; writes token to config. |
register-gitea-bot.sh |
Mints the claude-code Gitea token (push + PRs); writes it to config. |
install.sh |
Checks, git credential helper, renders + enables the unit. |
semprini-maintainer.service |
systemd unit template (@USER@, @HOME@, @DIR@). |
docs/architecture.md |
Architecture decision record. |
Test without the service
python3 maintainer.py --check # parsers, schedule, config, paths
python3 maintainer.py --once health # one health cycle + any agent work it queues
python3 maintainer.py --once digest # post the daily report now
python3 maintainer.py --once upgrade # run the upgrade now