Files
reliquary/plugins/spire/skills/gremlins/SKILL.md
T
2026-11-01 17:40:01 +01:00

57 lines
4.6 KiB
Markdown

---
name: gremlins
description: Trains one headless implementer (the base) per build with `claude -p` and forks a gremlin from it per block, so each gremlin starts from the base's reading at prompt-cache prices.
allowed-tools: Bash(uv:*)
---
# Gremlins
- **Base**: headless `claude -p` session; reads the code a build touches, writes the trunk notes, changes nothing.
- **Gremlin**: fork of the base's session (`--resume <base> --fork-session`) working one block from a brief.
- Spawn completions return to the caller (the session that ran the Bash call); Call sequence step 3.
## Commands
`G` = `uv run --script "${CLAUDE_SKILL_DIR}/gremlins.py"`. Each command prints one JSON object on stdout. Exit: 0 ok; 1 call ended `error` or `stopped`; 2 refused or usage error.
| Command | Does | Boxes |
|---|---|---|
| `G init --run R --model M [--effort E] [--cwd D] [--agent A] [--binary P]` | Writes `run.json`: launch fingerprint (binary, full model id, flags, cwd, appended prompt) and the argv, stored once. Refuses to overwrite an existing run. | B1 |
| `G train --run R --base B --brief F` | One blocking call with `--session-id`; on `ok` writes `bases/B.json`. Prints `{status, session_id, cost, …}`. | B1 |
| `G spawn --run R --base B --job J --brief F` | One blocking fork of B, stored argv reused verbatim. Prompt = spawn template + delta header (git changes since the base's commit) + brief. Prints `{status, cache, note, cost, …}`. | B2, B3, B5 |
| `G rebase --run R --base B --brief F` | Resumes B without a fork, with delta header and brief; updates `bases/B.json` (session id from the result). Warns when jobs of B are still `running`. | B7 |
| `G status --run R [--job J]` | Bases with warmth (`warm`/`expiring`/`cold`, `warm_until`, `ttl_left_s`), and job records. | B6, B3 |
`R` = the run log `.md` (`run.md` or `<name>.md`). `M` = full model id (e.g. `claude-opus-5-5[1m]`); aliases refused. Any command: `[--scratch D]` (State dir), on every call or none. No `kill`, `wait`, `ping` or `continue` command exists.
## Call sequence
1. `G init …` (foreground).
2. `G train …`: blocking Bash call, `timeout: 600000`. Past the timeout the harness backgrounds it; the completion notice carries the result.
3. Each `G spawn …`: its own Bash call, `run_in_background: true`; parallel spawns = parallel background calls. Read the result JSON from each completion notice; never poll.
4. `G status …`: check warmth before spawning again, or re-read a job record. At phase close, copy its cost totals into the run log.
`ledger.jsonl` records every call: real model (from `modelUsage`), four token columns, cost delta against the base (B5). Warmth is reported only; nothing keeps a base warm (B6).
## Stopping a gremlin
`TaskStop` the backgrounded Bash call (B4); kills `claude` and its bash wrappers. Known leftover (spec §7): a command the gremlin had in flight (e.g. a long test run through its Bash) can survive as an orphan and run to its end. After a hard stop the job file may stay `running` with no ledger line; `status` shows that record as written, and you know which calls you stopped.
## Briefs carry the rules
The spawn template sets no commit rule. Each brief states: whether that gremlin commits, which paths it may touch, its gate. Parallel gremlins: "do not commit" plus the path list.
## State dir
`<toplevel>/.spire/scratch/<run-slug>/gremlins`; `<toplevel>` = the run log's checkout; run log in another repo or none: the cwd's. Slug = the run log's parent dir name when the file is `run.md`, else its stem. Scratch per `workpad` Tiers (git-ignored; explicit paths). `SPIRE_SCRATCH` overrides the scratch root (absolute path to a dedicated directory; the helper writes a `*` `.gitignore` at its root). `--scratch <dir>` sets it (an env prefix does not match `Bash(uv:*)`, probe 2026-10-23).
- `run.json` (written once by `init`), `mcp-empty.json`, `preamble.md` (frozen copy: stable system prompt, stable cache)
- `bases/<B>.json` (only `train` and `rebase` write it); `jobs/<J>.json` (each by its own command)
- `ledger.jsonl` (one appended line per finished or stopped call)
- `raw/<J>.jsonl` (stream), `raw/<J>.err`; `briefs/<J>.md` (full prompt sent)
- `notes/<J>.md` (gremlin handoff notes); `out/` (their gate and test output)
## Cache hits
A fork hits the base's cache only with the same argv, pinned env, cwd and an unchanged system prompt. `spawn` reports `cache: hit|partial|miss`; a miss is reported, not an error. Env scrub (deny-list) removes Desktop, SDK, Remote Control and uv variables from every launch; unknown host variables pass. No platform-specific process code; runs on Windows Git Bash, WSL, Linux, macOS (B8).