nitsuah/stash · agent/prompts/IMPS.md

One issue. One small PR.

An imp is a headless Claude worker, routed through 9router, that takes exactly one GitHub issue and opens one small pull request. The model never pushes and never holds a GitHub token. A deterministic gate — Docker tests, a line budget, path allow/deny lists, and a Co-Authored-By trailer — decides whether the work becomes a PR. Add machines by running setup on each, not by running two dispatchers on one.

1issue → 1 PR
1warlock per machine
15default maxLines at the gate
2fix rounds, then needs-human
0shared database, shared lock
How it works

Queue → gate → PR → review / fix

GitHub issues are the queue. Labels are the state machine. The hourly dispatcher has no model of its own: it picks work, runs the kit, and writes the ledger.

One warlock per machine, many imps per machine, many machines. The warlock is the single dispatch.mjs cycle; the imp-runner is the detached checkout it executes; imps are the workers. More throughput means more imps (--concurrency), never a second warlock — two would see the same imp:ready labels, pick the same briefs, and race on one imp-nm- volume. Machines coordinate only through labels. Contract: WARLOCK.md, checked by node /imps/warlock.mjs.

1 · Queueimp:ready + an comment with front matter (repo, issue, test, maxLines, allow).
2 · RunThrowaway worktree, clean env, tool allowlist. Commits locally as 9router imp. Push URL is no_push.
3 · GateDocker tests exit 0, diff within maxLines, paths under allow, deny list clean, every imp commit carries the trailer.
4 · PR + loopOpen a PR labelled imp, read-only review, up to two fix rounds on feedback / red CI, then imp:needs-human.
Brief human / triageNewest issue comment starting with wins. Front matter is taken verbatim. The runner substitutes {wt} and runs test: itself — the model's "tests pass" claim is never trusted.
Dispatcher 0 tokensdispatch.mjs hourly at :07 plus a 5-minute label watch: lock file, 9router MAX health probe, reclaim stranded claims, fix-sweep open imp PRs first, then pick quiet repos (prefer bot:review), respect WIP / per-repo / daily caps, pause a repo 24 h after two straight gate failures.
Worker AI · one issueimp.mjs run through 9router with PATH + router URL/key only. Tools: Read, Edit, Write, Glob, Grep, a short git allowlist, docker run. No gh, no host npm.
Gate deterministicTests and optional lint: in Docker, at least one commit, Co-Authored-By: …imp on every imp-authored commit, no leftovers, size and scope checks, hard deny of .github/, .env*, secrets/, lockfiles.
PR / review / fix AI · boundedAfter a pass, imp.mjs pr pushes and opens the PR. review.mjs posts a read-only COMMENT review (verdict recomputed from findings). fix.mjs answers threads and red CI for at most two rounds.
Labels: imp:ready → imp:working → imp:pr or imp:failed. Exhausted fix rounds or a conflict get imp:needs-human. The kit can arm squash auto-merge when the reviewer verdict is approve and every check on the head commit is green — and it re-checks before merging, because gh pr merge --auto only waits for required checks.
Many machines

The queue is the lock. Nothing else is shared.

There is no shared database, no shared volume and no leader election. Each machine has its own warlock, its own runner checkout and its own ~/.imps state, and the only thing they read and write in common is GitHub. That keeps a machine's death local — and it is also where the interesting failure modes live, so each one has a mechanism rather than a hope.

The queue is the lock label flipA warlock flips imp:ready → imp:working before spawning. Another machine sees the label and skips it. The window between reading the search result and flipping it is real and accepted: a duplicate imp produces a duplicate PR, which a human closes — not a corrupted repo.
A claim has a lease 3 hA label has no owner, so the warlock also writes a comment naming the machine and the time. The dispatcher reclaims claims older than 3 h made by another machine with no live run in this machine's ledger, comment , and put the issue back on imp:ready. A crashed machine therefore strands an issue for up to three hours, not forever.
The ledger is per-machine local~/.imps/runs.jsonl never leaves the machine. A warlock cannot fix-sweep a PR opened from another machine's ledger — it logs the PR as unknown and skips. Fix rounds happen on the machine that opened the PR, which is the machine holding its worktree and its test context.
Every run says where it came from plannedRun provenance is planned — ledger rows and dispatch events do not yet carry kitSha or machine. A future kit change will add these fields so a behaviour change after a kit fix is attributable — you can tell a bad brief from a machine that is forty commits behind instead of guessing.
The heartbeat is the one shared thing plannedHeartbeat is planned — "heartbeat": true in config.json or IMPS_HEARTBEAT=1 will update one issue, imps heartbeat: , with its kit sha, last cycle and runs today. A row that has stopped moving is a machine that is not running. It will never fail a cycle — a heartbeat that can break the loop would be worse than no heartbeat.
Do not point two machines at one IMPS_HOME. The ledger is the warlock's memory, not a cache, and two writers make every fix-sweep decision a coin flip.
Guardrails

The model is nondeterministic. The rails are not.

Everything that can be a script is a script. Caps live in code defaults (see defaults.mjs / lib.mjs), not in wishful docs, and check-defaults.mjs reads STANDARD.md and dispatch.mjs header and fails the build when they disagree with the code; it does not read pages/imps.html.

RailWhat the code does
Clean envWorker gets PATH and the 9router URL/key. No Claude session tokens, no GitHub token.
No push from the workerWorktree push URL is no_push. Only imp.mjs pr pushes, and only after the gate passes.
Diff budgetGate default maxLines is 15 (brief can raise it). Fix rounds get --slack 30 extra lines.
ScopeEvery changed path must start with a brief allow: prefix when allow is set.
Deny list.github/, .env anywhere, secrets/, package / yarn / pnpm / bun lockfiles.
TrailerEvery commit authored as the imp must match /Co-Authored-By: .*imp/i.
Throughput capsDefaults today: --max 5, --wip 8, --per-repo 4, --concurrency 4, --daily-cap 15, quiet repos only for quietHours 6.
QuotaPer-model run counter lives in ~/.imps, not the checkout, and refills on a rolling window. A counter in a directory that is reset every cycle could neither persist nor limit anything.
Cooldown24 h repo pause after two consecutive gate failures (loopBudget).
Fix budgetTwo rounds, then imp:needs-human. Conflicts escalate the same way.
Earned trustAuto-merge requires autoMergeTrust (3) previously merged imp PRs with all checks green for that repo, seeded from GitHub history. A seed query error fails closed.
Machine setup

A detached runner that keeps itself current

The kit lives in the public nitsuah/.github imps/ tree (same pattern as journeys). Each machine keeps a detached checkout outside any project tree, so the hourly wrapper can reset it to origin/main before every run and only merged kit code runs unattended.

1 · kit

setup.ps1 / setup.sh

Checks node, git, gh auth, Docker and 9router. Installs the detached runner, clones IMPS_CODE/.github for kit self-work, creates ~/.imps, and registers the schedule.

2 · schedule

hourly :07 + label watch

Windows: two Scheduled Tasks. macOS/Linux: crontab when it exists; otherwise setup prints a hint to configure your own scheduler (it does not install systemd timers automatically and does not fail).

3 · self-update

fetch + reset every cycle (exit-code checked)

The Unix wrappers (hourly.sh, label-watch.sh) abort on failed fetch or reset. The Windows wrappers (hourly.cmd, label-watch.cmd) check exit codes after git fetch and git reset — a failed fetch or reset aborts the cycle so a merged kit change always reaches the machine.

PathWhatReset by updates?
runner checkoutthe kit — code onlyyes, reset --hard origin/main every cycle
IMPS_CODE clonebase for kit self-work worktreesno — fetched only
~/.impsledger, logs, locks, config.json, quotanever — machine state
Preflight fails loudimps/preflight.mjs refuses a checkout where a required kit file is missing or any .mjs is under 200 bytes. A hand-copied stub once satisfied a "does the file exist" check and no-op'd on schedule for days while every dashboard looked healthy — an existence check is not a health check.
Drift the pull cannot fix warlock.mjswarlock.mjs checks: runner path known, runner is a real git checkout, has imps/dispatch.mjs, no tracked edits, current with origin/main, hourly.cmd (Windows) or hourly.sh (Unix) points at it and was generated from its sha, exactly one dispatch task (on Windows; Unix users must verify manually), lock not stale, ledger parseable, and one HTTP MAX probe to 9router. preflight.mjs and doctor.ps1 do not run warlock.mjs; they only verify the kit files exist and pass size checks.
Dry run IMPS_DRY_RUN=1Flows through both wrappers. A new machine can prove it sees the queue and understands the briefs before it claims a single issue.
Health, one command exit 1 on any failurewarlock.mjs checks: runner path known, runner is a real git checkout, has imps/dispatch.mjs, no tracked edits, current with origin/main, hourly.cmd (Windows) or hourly.sh (Unix) points at it and was generated from its sha, exactly one dispatch task (on Windows; Unix users must verify manually), lock not stale, ledger parseable — and one HTTP MAX probe to 9router.

Deploying a second machine is therefore: clone, run setup, done. It pulls its own updates from then on. When a machine genuinely stalls, operators must monitor stalled machines independently. The kit's RSI loop (rsi.mjs) files imp:ready issues against the kit for recurring gate failures, fix-loop needs-human spikes, and open journey issues observed during running cycles — so the fleet repairs its own tooling instead of waiting for a person to notice.

Self-improvement

Measure the runs. Teach the preamble.

Every run writes a ledger row (model served, turns, tool errors, gate reasons, tokens, kit sha). That is the training data for the next prompt change — not vibes.

Reportnode imps/imp.mjs report (and stats.mjs) surfaces recurring tool-error kinds and gate failures; dispatch.jsonl carries the same provenance for queue decisions.
One lessonEach recurring failure becomes one line under "Lessons from earlier runs" in PREAMBLE.md, or one gate rule in lib.mjs, citing the run ids. Same loop for REVIEW.md and FIX.md.
Own PRShip the lesson alone so the brief hash changes and the next batch shows whether it helped. Delete a lesson once ~10 runs pass without hitting it.
File the issuersi.mjs turns recurring gate failures, fix-loop needs-human spikes and open journey issues into capped imp:ready issues — including kit briefs against .github, so a machine that stalls leaves a written reason behind.
Cost-aware loop

Journeys find. Imps fix. Journeys verify.

Nightly journeys cost zero tokens and file bot:journey issues with screenshots and a Docker repro. Imps are for the small, already-diagnosed fixes (often bot:review first). Green nights after the merge are the verification — the bot closes the issue, not the author.