mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-05 08:48:27 +01:00
A dispatch that runs on the box works in ~/dev/<project> — a tree no editor is
open on and the operator never looks at. The box had NO ~/CLAUDE.md, so every
cloud agent ran without the standing rules the laptop takes for granted: branch,
commit, push, open a PR. Work that was never pushed simply ceased to exist, and
nobody found out, because finding out requires looking at a filesystem nobody
looks at.
Two halves, because one of them is a prompt and prompts are soft guarantees.
1. THE CONTRACT — scripts/hetzner/box-agent-claude.md, applied into the runner
user's ~/.claude/CLAUDE.md by apply-box-agent-contract.sh, wired into
install-box-runner.sh so a fresh runner is never executing without it.
Versioned in the repo rather than scp'd from the laptop. Copying the global
file would be wrong twice: it is full of laptop-only context (zellij, the
session registry, worktree helpers) that is false on the box, and a second
copy drifts the moment either changes.
Written inside a marked block — anything outside is preserved verbatim, so a
hand-added note survives redeploys. Same merge-only contract claude-prep.ts
holds for settings.json. Verified on the live box: re-run reports
"unchanged", and an appended operator note survived a re-apply.
2. THE WATCH — agent-work-check.sh on an hourly timer, reporting via the
existing lib-alert.sh (alert_transition fires only on a state flip, so no
repeat of the 2026-08-05 alert storm).
What counts as stranded is the whole design, and the false-positive guards
are the load-bearing part:
- dirty tree (uncommitted OR untracked) → real, exists nowhere else
- a RECENT branch with NO upstream holding commits on no remote → the exact
shape of "committed but never pushed"
- NOT "ahead of upstream": ~/dev/revampit on this box reads 74 ahead / 129
behind and all 74 were squash-merged months ago. An alert that is wrong
on day one is muted by day two.
Four guards (default-branch, upstream, recency, detection) each independently
negative-tested — removing any one makes a specific case fail.
THE BUG THIS SHIPPED WITH, AND WHY THE FIX MATTERS MORE THAN THE FEATURE:
the first install reported a confident "0 repo(s) with stranded work". It runs
as root, the checkouts belong to ubuntu, git refused every one for dubious
ownership, and each was silently skipped. A monitor that cannot go red is worse
than no monitor, because it is believed. Now: git runs with safe.directory for
these read-only calls; a directory that looks like a checkout but will not open
is REPORTED, never skipped; the summary always states how many repos were
actually read (0-of-21 and 0-of-0 must not look alike); and a root that yields
zero readable repos goes red on its own. All three asserted in the test.
Live result on the box: 6 repos with stranded work, 19 scanned — five real
never-pushed feature branches nobody could see, and revampit/solon correctly
NOT flagged.
The sweep only ever reads. It must never auto-commit or auto-push: landing work
nobody reviewed is a worse outcome than work sitting still, and it would race a
live agent mid-edit.
Wired into test:ops so CI runs it.
Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>