Files
reliquary/plugins/spire/skills/gremlins/SKILL.md
T
g4borg 53fe662735 🩹 export: 4 files (small fixes)
M plugins/spire/CHANGELOG.md
M plugins/spire/skills/gremlins/SKILL.md
M plugins/spire/skills/implementation/SKILL.md
M plugins/spire/skills/implementation/references/known-failures.md
2026-11-25 02:18:54 +01:00

7.9 KiB

name, description, allowed-tools
name description allowed-tools
gremlins Trains one headless implementer (the base) per build with the caller's own CLI (`claude -p` or `codex exec`) and forks a gremlin from it per block, so each gremlin starts from the base's reading at prompt-cache prices. Bash(uv:*)

Gremlins

  • Base: headless session of the harness; reads the code a build touches, writes trunk notes when its brief names a path, changes nothing else.
  • Gremlin: fork of the base's session (on Claude --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. If ${CLAUDE_SKILL_DIR} appears literally, it is this SKILL.md's own folder; resolve it there and do not search elsewhere.

Command Does Boxes
G init --run R --model M [--effort E] [--cwd D] [--agent A] [--binary P] [--harness claude|codex] [--pass-env NAME]… [--network] Writes run.json: launch fingerprint (binary, full model id, flags, cwd, appended prompt) and the argv, stored once. Prints env_dropped (names the scrub would drop). Refuses to overwrite an existing run. B1
G train --run R --base B --brief F One blocking call (on Claude with --session-id; on Codex the id comes from the stream's thread.started); on ok writes bases/B.json. Prints {status, session_id, cost, warnings, …}. 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; on Codex, a model slug from models_cache.json. Any command: [--scratch D] (State dir), on every call or none. No kill, wait, ping or continue command exists.

On Codex

  • G = python3 "<dir of this SKILL.md>/gremlins.py" (no uv; Python >= 3.10). Commands, output and exit codes as above.
  • Escalation (d, default, assumed): run each G call escalated, with the justification "starts headless codex gremlins; needs to write ~/.codex and use the network". Fallback (a), for headless callers: start the caller with --add-dir ~/.codex -c sandbox_workspace_write.network_access=true. Exposure: the caller's model can write all of CODEX_HOME (auth.json, config.toml) for the whole session. init preflights CODEX_HOME and refuses codex_home_not_writable otherwise.
  • Long calls: one long-running exec session per call, waited on; parallel spawns are parallel sessions; interrupt a session to stop it.
  • Forks never commit: .git is read-only under workspace-write. The spawn prompt tells the fork to list its changed paths; the caller commits. Boundary: a repo under /tmp or $TMPDIR is writable there, so keep Codex runs' repos outside both.
  • Cache verdict is a turn-delta estimate: a fork that does a lot of its own work reads partial, and a true miss also reads partial (the generic prefix is always cached); miss is practically unreachable. No cost column (cost is null).
  • --network: off by default; init --network opts in (recorded in the fingerprint). A --pass-env token is useless without it.
  • P4 (user runs it; not yet run): from an interactive Codex TUI in a trusted repo, run G init --model <slug> --effort low, G train ..., G spawn ..., each escalated. Check that an approval prompt appears, the call succeeds, CODEX_THREAD_ID is present (names only), and a long call can be waited on. If it fails, lead with (a).

Call sequence

  1. G init … (foreground).
  2. G train …: blocking Bash call with the Bash tool's timeout: 600000. This is the harness wait, not a cap on the run: past it the harness backgrounds the call and never kills 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

The preamble already tells every session what a base and a fork are, to use no agents, to run in the foreground, to commit only when the task says so (explicit paths, no push), the handoff-note format, and to trust the delta header. The templates name the note path and the out dir. Do not repeat any of it in a brief.

  • Train brief: what to read (plan, design, code areas), the trunk-notes path if wanted, and the build's standing rules, once: host rules, wrappers, gate commands. They bind every fork.
  • Spawn brief: the task only: scope, the paths it may touch, commit yes or no (with the message; on Codex always no), its gate, block-specific traps, anything to add to the end message.
  • Parallel forks: "do not commit" plus the path list.
  • Results: the handoff note is the spawn result's note (notes/<J>.md); gate output is in out/.

The helper sets no commit default: the preamble says a fork commits only when its brief says so. Each spawn brief says yes or no.

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 quire 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. Secret-shaped names (TOKEN, SECRET, PASSWORD, API_KEY, a trailing _KEY, …) are dropped too; --pass-env NAME at init lets one through (decide at init from env_dropped; a missing name means a new run). Limit: only inherited env is scrubbed; secrets your shell startup files export reach the gremlin's shell again. No platform-specific process code; runs on Windows Git Bash, WSL, Linux, macOS (B8).