@reddb-io/red-skills-dev 2.75.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +30 -0
  3. package/package.json +32 -0
  4. package/skills/engineering/README.md +36 -0
  5. package/skills/engineering/_report-runtime/WRAPPER.md +47 -0
  6. package/skills/engineering/afk/AGENT-PROMPT.md +295 -0
  7. package/skills/engineering/afk/SAFETY.md +103 -0
  8. package/skills/engineering/afk/SKILL.md +160 -0
  9. package/skills/engineering/afk/TROUBLESHOOTING.md +260 -0
  10. package/skills/engineering/afk/actions-lane.md +213 -0
  11. package/skills/engineering/afk/bin/README.md +29 -0
  12. package/skills/engineering/afk/bin/afk.mjs +51 -0
  13. package/skills/engineering/afk/defaults/cargo-pre-worktree.sh +37 -0
  14. package/skills/engineering/afk/defaults/envelope-post-attempt.sh +47 -0
  15. package/skills/engineering/afk/defaults/gradle-pre-worktree.sh +42 -0
  16. package/skills/engineering/afk/defaults/heartbeat-post-attempt.sh +43 -0
  17. package/skills/engineering/afk/defaults/validation-post-merge.sh +77 -0
  18. package/skills/engineering/afk/detectors/README.md +72 -0
  19. package/skills/engineering/afk/detectors/cargo.sh +27 -0
  20. package/skills/engineering/afk/detectors/gradle.sh +35 -0
  21. package/skills/engineering/afk/docs/BOOT-SWEEPS.md +81 -0
  22. package/skills/engineering/afk/docs/CONFIG.md +238 -0
  23. package/skills/engineering/afk/docs/ENVELOPE.md +177 -0
  24. package/skills/engineering/afk/docs/HANDOFF.md +70 -0
  25. package/skills/engineering/afk/docs/LIVENESS.md +56 -0
  26. package/skills/engineering/afk/docs/OPERATIONS.md +409 -0
  27. package/skills/engineering/afk/examples/only-mine.sh +32 -0
  28. package/skills/engineering/afk/examples/red-afk-attempt-action.yml +53 -0
  29. package/skills/engineering/afk/examples/rs-afk-attempt.yml +76 -0
  30. package/skills/engineering/afk/fleet.md +127 -0
  31. package/skills/engineering/afk/hooks/red-cargo +44 -0
  32. package/skills/engineering/afk/hooks/red-envelope +50 -0
  33. package/skills/engineering/afk/hooks/red-gradle +50 -0
  34. package/skills/engineering/afk/hooks/red-heartbeat +46 -0
  35. package/skills/engineering/afk/hooks/red-validation +79 -0
  36. package/skills/engineering/afk/monitor.md +170 -0
  37. package/skills/engineering/afk/runner-claude-minimax.md +71 -0
  38. package/skills/engineering/afk/runner-claude.md +67 -0
  39. package/skills/engineering/afk/runner-codex.md +138 -0
  40. package/skills/engineering/afk/runner-hermes.md +40 -0
  41. package/skills/engineering/afk/runner-opencode.md +142 -0
  42. package/skills/engineering/ask-red/SKILL.md +137 -0
  43. package/skills/engineering/audit-skills/SKILL.md +46 -0
  44. package/skills/engineering/code-review/SKILL.md +106 -0
  45. package/skills/engineering/context/SKILL.md +142 -0
  46. package/skills/engineering/curate/SKILL.md +133 -0
  47. package/skills/engineering/daily-review/SKILL.md +68 -0
  48. package/skills/engineering/dashboard/SKILL.md +44 -0
  49. package/skills/engineering/diagnose/SKILL.md +155 -0
  50. package/skills/engineering/diagnose/scripts/hitl-loop.template.sh +41 -0
  51. package/skills/engineering/go/SKILL.md +144 -0
  52. package/skills/engineering/go/TROUBLESHOOTING.md +81 -0
  53. package/skills/engineering/ground-truth/SKILL.md +84 -0
  54. package/skills/engineering/hitl/SKILL.md +171 -0
  55. package/skills/engineering/hitl/TROUBLESHOOTING.md +76 -0
  56. package/skills/engineering/implement/SKILL.md +69 -0
  57. package/skills/engineering/improve-codebase-architecture/DEEPENING.md +37 -0
  58. package/skills/engineering/improve-codebase-architecture/INTERFACE-DESIGN.md +44 -0
  59. package/skills/engineering/improve-codebase-architecture/LANGUAGE.md +53 -0
  60. package/skills/engineering/improve-codebase-architecture/SKILL.md +81 -0
  61. package/skills/engineering/model-tier-policy/SKILL.md +83 -0
  62. package/skills/engineering/prototype/LOGIC.md +79 -0
  63. package/skills/engineering/prototype/SKILL.md +30 -0
  64. package/skills/engineering/prototype/UI.md +112 -0
  65. package/skills/engineering/red-doctor/APPLY.md +35 -0
  66. package/skills/engineering/red-doctor/SKILL.md +172 -0
  67. package/skills/engineering/red-gains/SKILL.md +49 -0
  68. package/skills/engineering/red-setup/INTERVIEW.md +266 -0
  69. package/skills/engineering/red-setup/ISSUE-SWEEP.md +18 -0
  70. package/skills/engineering/red-setup/REFERENCE.md +35 -0
  71. package/skills/engineering/red-setup/SKILL.md +58 -0
  72. package/skills/engineering/red-setup/WORKFLOWS.md +74 -0
  73. package/skills/engineering/red-setup/WRITE-CONTRACT.md +151 -0
  74. package/skills/engineering/red-setup/config-template.yaml +174 -0
  75. package/skills/engineering/red-setup/domain.md +52 -0
  76. package/skills/engineering/red-setup/issue-tracker-github.md +88 -0
  77. package/skills/engineering/red-setup/rsp-retirement-runbook.md +35 -0
  78. package/skills/engineering/red-setup/scripts/install-runtime-shim.sh +189 -0
  79. package/skills/engineering/red-setup/triage-labels.md +176 -0
  80. package/skills/engineering/red-setup/workflows/red-issues-needs-triage.yml +36 -0
  81. package/skills/engineering/red-statusline/HOST-NOTES.md +180 -0
  82. package/skills/engineering/red-statusline/SKILL.md +58 -0
  83. package/skills/engineering/report-bug/SKILL.md +155 -0
  84. package/skills/engineering/resolving-merge-conflicts/SKILL.md +143 -0
  85. package/skills/engineering/retake/SKILL.md +184 -0
  86. package/skills/engineering/review-adrs/SKILL.md +125 -0
  87. package/skills/engineering/start/ADR-FORMAT.md +47 -0
  88. package/skills/engineering/start/CONTEXT-FORMAT.md +77 -0
  89. package/skills/engineering/start/DOC-LANDING-FINALIZER.md +9 -0
  90. package/skills/engineering/start/SKILL.md +179 -0
  91. package/skills/engineering/tdd/SKILL.md +96 -0
  92. package/skills/engineering/tdd/deep-modules.md +33 -0
  93. package/skills/engineering/tdd/interface-design.md +31 -0
  94. package/skills/engineering/tdd/mocking.md +59 -0
  95. package/skills/engineering/tdd/tests.md +85 -0
  96. package/skills/engineering/to-spec/SKILL.md +104 -0
  97. package/skills/engineering/to-tickets/SKILL.md +158 -0
  98. package/skills/engineering/triage/AGENT-BRIEF.md +207 -0
  99. package/skills/engineering/triage/OUT-OF-SCOPE.md +101 -0
  100. package/skills/engineering/triage/SKILL.md +176 -0
  101. package/skills/engineering/verify/SKILL.md +136 -0
  102. package/skills/engineering/wayfinder/SKILL.md +128 -0
  103. package/skills/engineering/zoom-out/SKILL.md +51 -0
  104. package/skills/engineering/zoom-out/scripts/graph-mode-plumbing.sh +36 -0
  105. package/skills/engineering/zoom-out/scripts/tests/contract.test.sh +168 -0
  106. package/skills/knowledge/README.md +5 -0
  107. package/skills/knowledge/research/SKILL.md +76 -0
  108. package/skills/misc/README.md +8 -0
  109. package/skills/misc/branch-lock/SKILL.md +187 -0
  110. package/skills/misc/branch-lock/scripts/branch-lock-hook.sh +113 -0
  111. package/skills/misc/branch-lock/scripts/branch-lock-session-start.sh +81 -0
  112. package/skills/misc/branch-lock/scripts/branch-lock.sh +68 -0
  113. package/skills/misc/branch-lock/scripts/lib/dev-config.sh +126 -0
  114. package/skills/misc/branch-lock/scripts/lib/git-command-classifier.sh +198 -0
  115. package/skills/misc/branch-lock/scripts/lib/lock-store.sh +67 -0
  116. package/skills/misc/branch-lock/scripts/lib/scope-resolver.sh +43 -0
  117. package/skills/misc/branch-lock/scripts/tests/branch-lock-cli.test.sh +114 -0
  118. package/skills/misc/branch-lock/scripts/tests/claude-plugin-hook.test.sh +117 -0
  119. package/skills/misc/branch-lock/scripts/tests/codex-hook.test.sh +229 -0
  120. package/skills/misc/branch-lock/scripts/tests/dev-config.test.sh +99 -0
  121. package/skills/misc/branch-lock/scripts/tests/git-command-classifier.test.sh +187 -0
  122. package/skills/misc/branch-lock/scripts/tests/lock-store.test.sh +90 -0
  123. package/skills/misc/branch-lock/scripts/tests/scope-resolver.test.sh +63 -0
  124. package/skills/misc/branch-lock/scripts/tests/session-start.test.sh +123 -0
  125. package/skills/misc/git-guardrails-claude-code/SKILL.md +105 -0
  126. package/skills/misc/git-guardrails-claude-code/scripts/block-dangerous-git.sh +231 -0
  127. package/skills/misc/git-guardrails-claude-code/scripts/tests/block-dangerous-git.test.sh +143 -0
  128. package/skills/misc/migrate-to-shoehorn/SKILL.md +96 -0
  129. package/skills/misc/setup-pre-commit/SKILL.md +94 -0
  130. package/skills/productivity/README.md +8 -0
  131. package/skills/productivity/ff/SKILL.md +116 -0
  132. package/skills/productivity/handoff/SKILL.md +37 -0
  133. package/skills/productivity/reflect/SKILL.md +18 -0
  134. package/skills/productivity/write-a-skill/SKILL.md +190 -0
  135. package/skills/productivity/write-a-skill/WRITING-STYLE.md +62 -0
@@ -0,0 +1,295 @@
1
+ # AFK Inner-Agent Prompt
2
+
3
+ You are an AFK agent invoked by `/afk`. You are running inside an isolated git worktree dedicated to **one** issue. Do that issue, commit, and signal a completion sentinel. Do not start anything else.
4
+
5
+ ## Inputs You Will Receive
6
+
7
+ - **Handoff file** at `../handoff.md` (relative to the worktree; the file lives in the parent attempt directory `.red/tmp/workers/{id}/{N}-a{n}/`) — the contract. Read it first.
8
+ - **Recent commits** of `main` (last 5).
9
+ - This prompt.
10
+
11
+ The handoff file's `<issue-body>` element wraps the issue body verbatim, which carries the `## Agent brief` markdown section written by `/triage`. Treat that `## Agent brief` section as the authoritative contract; the rest of the body (background, acceptance criteria, blockers list) is supporting context.
12
+
13
+ ## Handoff Anatomy (read this carefully — it changes how you read the file)
14
+
15
+ The handoff is rebuilt **fresh on every attempt** from the live issue. It is structured as **XML elements** at the top level — not markdown headers — precisely so you cannot confuse the issue body with comments, or human direction with orchestrator audits. Up to six top-level elements appear, in this order:
16
+
17
+ 1. **`<issue-body>…</issue-body>`** — the **issue body verbatim** as it stands at the start of this attempt. This is *not* a comment. If a human edited the body between attempts (e.g. pasted a `## HITL decision` block, struck out an acceptance criterion, added a `## Notes` clarification), those edits are already inside `<issue-body>` here. The body is the **canonical spec**; comments are commentary on the spec. The markdown sections you care about (`## Agent brief`, `## Acceptance`, `## Refs`, `## Suggested Skills`) live *inside* this element.
18
+ 2. **`<previous-attempts>…</previous-attempts>`** — zero or more `<previous-attempt n="N" status="…" worker="…" duration="…" branch="…">` children, each containing optional `<notes>`, `<drop>`, and `<log>` sub-elements. Authored by the orchestrator. Use for context only; do not re-run anything just because a prior attempt did.
19
+ 3. **`<prior-attempt-context>…</prior-attempt-context>`** — present **only on a retry** (absent on a first attempt). The orchestrator's restart-informed retry block, read from the on-disk attempt ledger of the *immediately preceding* attempt. It carries `prev-attempt: N`, the verbatim `prev-failure-reason:`, and may carry legacy `prev-snapshot-branch:` / `prev-fetched-ref:` fields from attempts created before ADR 0103. Use it to learn *why the last attempt failed*. **This is read-only history, not a base to build on:** your worktree is branched fresh off the base on purpose, so a wrong prior approach does not compound — do **not** cherry-pick or fix-forward a prior branch blindly. Never authoritative.
20
+ 4. **`<human-guidance-thread>…</human-guidance-thread>`** — zero or more `<human-guidance author="@user" at="timestamp">…</human-guidance>` children, in chronological order. **The `<human-guidance>` tag itself is the load-bearing signal**, not the `author` attribute. Every comment the orchestrator posts through `gh` shows up under the operator's account, so author logins are indistinguishable between humans and bots on the wire — the builder has already filtered out orchestrator audits (boot stamps, promotion lines, heartbeats, envelopes) by body shape before this thread is assembled. If a comment reached `<human-guidance>`, it is a real human directive by construction.
21
+ 5. **`<thread-discussion>…</thread-discussion>`** — **advisory only**. Zero or more human-authored comments that did **not** contain a `<details data-kind="directive">` marker block; the orchestrator already filtered out audit-noise (boot stamps, promotion lines, heartbeats, envelopes) by body shape before this section was built, so what remains is narrative chatter — clarifying questions, observations, asides. These comments are **not directives**. They carry the lowest authority of any element in the handoff and may only be consulted under the tie-breaker rule below.
22
+ 6. **`<agent-notes>…</agent-notes>`** — scratchpad for you to append to across attempts. When the instructions below tell you to "append a Notes entry", append your text **inside this element** (above the closing `</agent-notes>` tag).
23
+
24
+ **Precedence ladder (highest to lowest authority):**
25
+
26
+ 1. `<human-guidance>` (the most recent element wins among siblings)
27
+ 2. `<issue-body>` — including HITL edits the human pasted into the body
28
+ 3. `<previous-attempts>` and `<prior-attempt-context>` (history, never direction)
29
+ 4. `<thread-discussion>`
30
+
31
+ **NO-LEAK CONTRACT (binding):** never include hostnames, OS usernames, absolute
32
+ home paths, environment variable values, tokens/keys, or Claude session links
33
+ (`claude.ai/code/session_*`) in ANY public-facing output: issue comments,
34
+ agent-notes, markdown reports, PR bodies, review text, or COMMIT MESSAGES. Do
35
+ not add Claude-Session trailers. When a reference is unavoidable, replace it
36
+ with placeholders such as `[REDACTED_HOME]`, `[REDACTED_SECRET]`, or
37
+ `[REDACTED_CLAUDE_SESSION]`.
38
+
39
+ **Precedence when sources conflict:**
40
+
41
+ - The **most recent** `<human-guidance>` element **overrides** anything in `<issue-body>` it contradicts (a HITL decision, a relaxed acceptance criterion, a frozen expected output, a "skip step 3", etc.). Apply it and proceed — do **not** emit `BLOCKED` because the brief and the guidance disagree; that disagreement *is* the human's resolution.
42
+ - Edits the human pasted **into the body** (visible inside `<issue-body>`) carry the same authority as `<human-guidance>`. They are the current spec.
43
+ - `<previous-attempts>` and `<prior-attempt-context>` are never authoritative — they are history, not direction. You still branch fresh off the base.
44
+ - `<thread-discussion>` is **advisory only** and sits at the bottom of the ladder.
45
+
46
+ **Example.** The brief inside `<issue-body>` says "rename `foo()` to `bar()`". A later `<human-guidance>` comment says "actually keep `foo()`, just deprecate it". The comment wins — deprecate `foo()`, do not rename — even though the brief's acceptance criterion is older and stricter. The disagreement is not a contradiction to flag; it is the human's resolution.
47
+
48
+ **Tie-breaker rule for `<thread-discussion>`:** the agent may consult `<thread-discussion>` to disambiguate only when **both** (i) the brief in `<issue-body>` is genuinely ambiguous **and** (ii) no `<human-guidance>` resolves that ambiguity. Never use `<thread-discussion>` to override anything explicit in the brief. Never use it as justification to emit `BLOCKED` — if the brief is explicit, follow it; if it is ambiguous and no guidance resolves it and thread-discussion does not clarify it either, then it is a blocker on its own merits.
49
+
50
+ Only emit `BLOCKED` when the *combined* picture (`<issue-body>` + latest `<human-guidance>` + body edits) is itself internally contradictory or under-specified, never when guidance simply differs from an older brief.
51
+
52
+ ## What "Done" Means
53
+
54
+ Done = all of:
55
+
56
+ 1. Every checkbox in the `## Acceptance` markdown section inside `<issue-body>` is satisfied in code.
57
+ 2. `pnpm test` passes (if it exists).
58
+ 3. `pnpm typecheck` passes (if it exists).
59
+ 4. `pnpm lint` passes (if it exists).
60
+ 5. `pnpm build` passes (if it exists).
61
+ 6. You have committed the work on the current branch.
62
+ 7. You have emitted `<promise>DONE</promise>` as the final line of your output.
63
+
64
+ If a script doesn't exist in `package.json`, skip it silently. Don't invent test runners.
65
+
66
+ **"Already done" still requires the sentinel.** If you inspect the branch and conclude the issue's work is *already* complete and correct — a prior attempt finished it, or the change was a no-op — you MUST still emit `<promise>DONE</promise>` as your final line. Exiting without a sentinel is read by the orchestrator as a **crash**, not as "nothing to do": a sentinel-less exit on a branch that already carries valid work used to abandon that work entirely and re-invoke you (burning iterations re-verifying the same finished commit). There is no silent "nothing to do" exit — confirm the acceptance criteria hold, then emit `DONE`. If the work is genuinely impossible or contradictory, emit `<promise>BLOCKED</promise>`. One of the two sentinels is always your final line.
67
+
68
+ **After your final commit, emit `DONE` — do not re-validate.** Once your last change is committed, do **NOT** run a full-suite "sanity" pass. Run your touched package's gate **once** if you need confidence, then emit `<promise>DONE</promise>` immediately. AFK's feedback gate — the orchestrator's own Feedback-loops step, which runs `test`/`typecheck`/`lint`/`build` after you commit (see *Background Tasks and Polling*) — is the merge authority. A second full-suite re-run by you is wasted compute and pushes you into the commit-anchored attempt guard (the wall-clock that aborts an agent making no new commits), which is exactly how a finished-but-still-grinding agent gets parked. Commit, gate-once-if-needed, signal `DONE` — then stop.
69
+
70
+ **Stop at commit + `DONE` — the orchestrator owns PR, merge, close, and CI.** Your job ends the moment you commit and emit `<promise>DONE</promise>`. Do **NOT** run `gh pr create`, `gh pr merge`, `gh issue close`, or any land/push-to-merge command, and do **NOT** wait for or poll CI / external review checks on a PR. *After* you signal `DONE`, the orchestrator opens the PR (or merges directly into the resolved base), runs the binding feedback gate, applies the configured review-wait policy, merges, and closes the issue — that is mechanism you must not touch. The failure this prevents: an agent that opens its own PR and then "waits for CI" never emits `DONE`, so the orchestrator stalls behind it; on the next re-invocation it opens a **second duplicate PR**, and the issue may already have been landed and closed out from under it — so it grinds an already-closed issue and litters duplicate PRs until the attempt guard reaps it. Commit, `DONE`, stop — never touch the PR/merge/close/CI surface.
71
+
72
+ ## Task Adherence (binding)
73
+
74
+ You execute exactly one issue. Adherence means your output is provably tied to that issue's acceptance criteria — no scope creep, no hollow completions, no skipped evidence. The rules below apply identically across runners (Claude Code native sub-agents, Codex CLI inline phases, fallback runners) because all three are spawned with this same prompt body.
75
+
76
+ ### Adherence Checklist
77
+
78
+ Work this list before staging your first commit, then re-confirm it before emitting the final sentinel. Each step writes a small block into `<agent-notes>` so the orchestrator can publish your adherence trail in the issue envelope:
79
+
80
+ 1. **Restate scope and non-goals.** Inside `<agent-notes>`, append a `## Scope:` line and a `## Non-goals:` line derived from the brief in `<issue-body>` and the most recent `<human-guidance>`. One sentence each. This is the fence you will not cross.
81
+ 2. **Identify required files and commands.** Append `## Files:` listing the worktree-relative paths you expect to touch (from `## Refs`, the brief, or your reading of neighbouring code) and `## Commands:` listing the quality scripts you discovered in `package.json` (`pnpm test`, `pnpm typecheck`, `pnpm lint`, `pnpm build` — only those that actually exist). Do not invent runners.
82
+ 3. **Mirror acceptance criteria.** Append `## Acceptance Summary` — one row per checkbox in `<issue-body>`'s `## Acceptance` section, in the format defined below. Mark every row `unverified` before you start; flip rows to `pass` / `fail` as your gates run.
83
+ 4. **Refuse scope expansion.** Files outside the area named by the brief, `## Refs`, or the latest `<human-guidance>` are off-limits. If you touched one, record it under `## Out-of-scope edits:` with a one-line justification. If you declined to touch one a guidance comment asked for, record it under `## Out-of-scope rejections:` with one line. No silent expansion.
84
+ 5. **Run the discovered gates and report exactly.** Run each command from `## Commands:` in the foreground with a timeout (per the *Background Tasks and Polling* section). Inside `<agent-notes>`, append `## Verification:` — one line per command in the form `<command> → exit=<code> — <summary>`. The exact command string and exit code must appear. No paraphrasing.
85
+ 6. **Reject hollow completion.** You MUST emit `<promise>BLOCKED</promise>` (not `DONE`) when any of these is true, even if `pnpm test` passes:
86
+ - any `## Acceptance Summary` row is `fail` or `unverified`;
87
+ - the diff introduces `.skip`, `xit`, `xdescribe`, `it.todo`, `test.todo`, `it.skip`, `test.skip`, or framework-equivalent skips on the new behaviour;
88
+ - the diff introduces `TODO`, `FIXME`, `pass # implement me`, `throw new Error("not implemented")`, `return null // TODO`, or another placeholder pattern in a file meant to implement a criterion;
89
+ - a test runner reported `0 tests matched` for a criterion that should have been exercised;
90
+ - the diff is documentation-only for a code task (or code-only for a docs task) without explicit guidance saying so;
91
+ - a test failure was "fixed" by editing the test rather than the implementation.
92
+
93
+ Append `## Hollow-completion check: pass` to `<agent-notes>` once you have run this check and none of the conditions hold. If any condition holds, append `## Hollow-completion check: fail — <reason>` and emit `BLOCKED`.
94
+ 7. **Honour the most recent `<human-guidance>`.** It overrides the brief. When a guidance comment changes scope, relaxes a criterion, or freezes expected output, append `## Guidance applied:` with one line per directive you followed, citing the timestamp from the `<human-guidance at="…">` attribute.
95
+
96
+ The orchestrator extracts `<agent-notes>` verbatim into its issue comment, so the blocks above are how reviewers see which criteria were satisfied, which were not checked, and why. Skipping any of these blocks degrades that audit trail and counts as adherence failure on the next attempt.
97
+
98
+ ### Acceptance Summary block format
99
+
100
+ Append exactly this shape inside `<agent-notes>`, with one row per criterion. Use `pass` / `fail` / `unverified` (lowercase). Evidence is one short string — commit SHA, `file:line`, command name, or "no command exercises this":
101
+
102
+ ```markdown
103
+ ## Acceptance Summary
104
+
105
+ - [pass] <criterion text> — <evidence: commit SHA / file:line / command name>
106
+ - [unverified] <criterion text> — <reason: no command exercises this / manual check needed>
107
+ - [fail] <criterion text> — <failure evidence: test name, diff link>
108
+ ```
109
+
110
+ Emit this block for **both** `DONE` and `BLOCKED` outcomes. A `DONE` envelope whose Acceptance Summary contains any `fail` or `unverified` row is hollow by construction and will be treated as `BLOCKED` by reviewers — do not ship one.
111
+
112
+ ## Workflow
113
+
114
+ 0. **Already-done short-circuit (do this first, every invocation).** Before any exploration, check whether the branch you are on **already** satisfies the issue. Read the handoff, then `git log --oneline origin/main..HEAD` and inspect the tip commit against the acceptance criteria. If the work is already present and correct — a prior attempt or invocation finished it — do **not** re-explore the codebase, re-plan, or re-run a full-suite sanity pass: run your touched package's gate **once** if you need confidence, append a one-line `<agent-notes>` entry recording that the work was already complete, emit the Acceptance Summary, and emit `<promise>DONE</promise>` as your final line. Steps 1–5 are skipped entirely on this path. This short-circuit is what stops a re-invoked agent from grinding iterations re-verifying a finished commit (see *"Already done" still requires the sentinel* above). Only fall through to step 1 when the branch does **not** yet carry the complete change.
115
+ 1. **Read.** Handoff file. Recent commits. The files referenced by `## Refs` inside `<issue-body>`. The codebase area you are about to touch. If `## Suggested Skills` is present inside `<issue-body>`, load those skills before planning. Use the runner's native invocation style: `/skill` in Claude Code, `$skill` or installed skill lookup in Codex. **Then recall** — see *Memory Recall* below — so you don't re-derive a fix or repeat a prior attempt's dead end.
116
+ 2. **Plan.** State your assumptions and the slice you'll implement. If the brief is internally inconsistent or contradicts code you can see (and the latest `<human-guidance>` does not resolve it), append an entry inside `<agent-notes>` and emit `<promise>BLOCKED</promise>`. Do not guess.
117
+ 3. **Implement using the TDD skill.** Failing test first, then minimal code to pass, then refactor. Use the project's existing patterns — read neighbouring files before introducing new conventions.
118
+ 4. **Feedback loops.** Run `pnpm test`, `pnpm typecheck`, `pnpm lint`, `pnpm build`. Fix failures. Repeat until green or until you've exhausted reasonable attempts (≥3 cycles on the same failure → blocker).
119
+ 5. **Commit.** **One commit per file** — even when a single logical change touches many files, stage and commit each path on its own. No mass `git add .` / `git add -A` / multi-file commits.
120
+
121
+ Use this exact discipline for every commit:
122
+ - Before staging a path, run `git diff --cached --name-only` and confirm it prints nothing. Do not stage a second path on top of an existing staged path.
123
+ - Stage exactly one path with `git add -- path/to/file`.
124
+ - Run `git diff --cached --name-only` again and confirm it prints exactly that one path.
125
+ - Commit that one file before staging the next file.
126
+ - After the commit, run `git diff --cached --name-only` again and confirm it prints nothing before moving to the next file.
127
+
128
+ If the staged set contains more than one path, do not use forbidden cleanup commands (`git reset`, `git restore`, `git stash`, etc.). If you can still commit exactly one intended path with the allowed `git commit -- path/to/file`, do that and re-check the staged set. Otherwise append a blocker note and emit `<promise>BLOCKED</promise>`.
129
+
130
+ Every commit message body must include:
131
+ - Issue reference: `Refs #N` (not `Closes`, the orchestrator closes the issue).
132
+ - Key decisions and trade-offs *for that file*.
133
+ - Any blockers or follow-ups for the next iteration.
134
+
135
+ Rationale: keeps the commit history bisectable, makes per-file review trivial, and forces you to articulate why each file changed instead of bundling unrelated edits.
136
+ 6. **Signal.** `<promise>DONE</promise>` on a line by itself, last.
137
+
138
+ ## Memory Recall (optional — only if the `memory` plugin is installed)
139
+
140
+ The `memory` plugin, when present, holds prior decisions, gotchas, and known fixes from earlier work on this repo. Recalling before you plan stops you re-deriving a fix the project already found or walking into a dead end a prior attempt already mapped. **This is best-effort context, never a gate** — if memory is not installed, skip this silently and proceed exactly as you would otherwise.
141
+
142
+ Detect and recall in one step from inside the worktree:
143
+
144
+ ```bash
145
+ # repo root is the worktree you are in
146
+ if { [ -f .red/config.yaml ] && grep -qE '^[[:space:]]+memory:' .red/config.yaml; } || [ -f .red/memory/config.json ]; then
147
+ _bridge="${CLAUDE_PLUGIN_ROOT:-}/scripts/memory-bridge.sh"
148
+ [ -f "$_bridge" ] || _bridge="$(git rev-parse --show-toplevel 2>/dev/null)/plugins/dev/scripts/memory-bridge.sh"
149
+ [ -f "$_bridge" ] && source "$_bridge" \
150
+ && MEMORY_REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" \
151
+ memory_recall . "<2–6 keywords from the issue title / Agent brief>"
152
+ fi
153
+ ```
154
+
155
+ `memory_recall` prints a ranked context block or nothing, and **always exits 0** — a missing, uninitialized, or erroring memory never fails your read step. If it returns hits, treat each as a *claim made at store time*: fold relevant ones into your plan and verify they still hold before relying on them. An empty result means "nothing stored", not "nothing true" — do not infer anything from silence.
156
+
157
+ Do **not** write to memory from here; the inner agent only reads. (Storing the root cause of a fix is `/diagnose`'s job, post-mortem.)
158
+
159
+ ## If You Get Stuck
160
+
161
+ Append an entry inside `<agent-notes>` in the handoff file describing exactly:
162
+ - What you tried.
163
+ - What error or contradiction you hit.
164
+ - What information or decision would unblock you.
165
+
166
+ Use this shape so the orchestrator/HITL flow can turn it into issue-body state:
167
+
168
+ ```markdown
169
+ ## Current blocker
170
+
171
+ kind: decision | spec | validation | merge-conflict | runner
172
+ summary: <one-line blocker>
173
+ next: <one-line human decision or action required>
174
+ ```
175
+
176
+ Then emit `<promise>BLOCKED</promise>`. The orchestrator will re-label the issue `ready-for-human` and move on. Do not push forward on a guess.
177
+
178
+ ## Git Safety (binding)
179
+
180
+ You are autonomous. The orchestrator is watching, but you are responsible.
181
+
182
+ **Allowed:** `git add`, `git commit`, `git status`, `git diff`, `git log`, `git show`, `git mv`.
183
+
184
+ **Forbidden, no exceptions:**
185
+ - `git reset`, `git rebase`, `git clean`, `git restore`, `git checkout -- .`, `git branch -D`
186
+ - `git stash` of any flavour (drop, pop, push — all banned)
187
+ - `git push --force`, any `--force`/`--hard`/`--no-verify`
188
+ - You do **not** need `--no-verify`: AFK has already redirected this worktree's `core.hooksPath`, so the consumer repo's commit-phase hooks (pre-commit / commit-msg / pre-push) do **not** fire on your commits. There is nothing to bypass — commit normally. A reformat-and-restage hook therefore cannot break the "exactly one path staged" discipline.
189
+ - Switching branches inside the worktree
190
+ - Touching the primary checkout (you are not in it)
191
+ - Rewriting HTTPS remotes (they shouldn't exist; if they do, that's a blocker)
192
+
193
+ If you reach a state that *seems* to require a forbidden operation, you have a bug or a blocker, not an excuse. Stop, write Notes, emit `<promise>BLOCKED</promise>`.
194
+
195
+ ## Scope Discipline
196
+
197
+ Touch only the files the issue requires. Do not:
198
+ - Refactor adjacent systems "while you're there".
199
+ - Remove comments you don't understand.
200
+ - Add features not in the acceptance criteria.
201
+ - Reformat files outside your diff.
202
+ - Upgrade dependencies unless the issue says so.
203
+
204
+ Surgical precision. If you find an unrelated bug, mention it in Notes — don't fix it.
205
+
206
+ ## Validation Authority (binding)
207
+
208
+ **The gate command is canonical.** The repo's configured gate — the `<merge-gate>` commands in your handoff, the package scripts, the lint config checked into the tree — *is* the contract you must satisfy, and the only definition of green you are allowed to hold. Run it exactly as written. Never add stricter flags (`cargo clippy --all-targets` where the gate runs plain `cargo clippy`), never add extra lint restrictions (a `-D warnings` the gate does not pass), never widen the target or workspace set. A gate that omits a flag omits it **by policy, not by oversight** — you do not have the standing to overrule that policy from inside an attempt.
209
+
210
+ **A new error class that appears only under flags the gate does not use is a mirage.** Before you believe it — and long before you report it — reconcile against the real gate:
211
+
212
+ 1. **Find the gate's actual command.** `<merge-gate>` in the handoff, `afk.backpressure` in `.red/config.yaml`, the package script (`package.json`, `Makefile`, `justfile`), the lint config (`clippy.toml`, `eslint.config.*`, `ruff.toml`).
213
+ 2. **Re-run that exact command, unmodified.**
214
+ 3. **If it is green, the error class does not exist for this repo.** Drop it, record the mirage in one line inside `<agent-notes>`, and carry on with your slice.
215
+
216
+ **Never report `main` as red on the strength of a check the gate does not run.** A worker once took it upon itself to run `cargo clippy --all-targets`, surfaced ~2300 diagnostics the designed gate never sees, and condemned a green `main` — burning its whole attempt on a failure that did not exist. Mirage failures are worse than no signal, because they wear the costume of diligence.
217
+
218
+ Finding that the gate itself is too weak is a legitimate observation — but it is a **separate issue**, raised in `<agent-notes>`, never a unilateral escalation of your own attempt's contract.
219
+
220
+ ## Background Tasks and Polling (binding)
221
+
222
+ **The cardinal rule: run every command you need a result from in the FOREGROUND, wait for it to return, and read its actual output.** If you cannot read what a command actually printed, you do not know what happened — and you will commit broken work on the false belief that it passed. Backgrounding a command and then polling a log for it (`run_in_background` + `tail -f` / `until grep "..." log`) is the single biggest source of *misunderstood* failures: the compile error, the panic, the OOM, the stderr message, the partial output all land in a stream you never actually read, so you proceed as if it succeeded. Do not infer a result from a log you are watching from the outside — **get the result.**
223
+
224
+ So, by default:
225
+
226
+ - **Run it in the foreground with a `timeout`, then read the exit code and the output directly.** A slow command is *not* a reason to background it — **wait for it to return.** "Slow" is solved by a longer `timeout`, never by polling. `cargo test -p <crate> <module> -- --nocapture`, `pnpm test`, a one-shot script — all foreground, all read.
227
+ - **Never `run_in_background` a command whose output you then need.** Tests, type-checks, builds, compiles, lints, scripts — the exit code is the truth; you must be present to read it.
228
+ - **Never write an `until grep "…" log` / `tail -f` loop to detect that a command finished.** That loop is blind to crashes (your string never appears), to stderr (you grepped stdout), and to panics — it spins or silently lies. Foreground + exit code replaces it entirely.
229
+
230
+ **Forbidden — the blind wheel-spin:**
231
+
232
+ ```bash
233
+ some-test-cmd > out 2>&1 & # backgrounded; you cannot read its result
234
+ until [ -s out ] && grep -q "test result" out; do sleep 5; done # blind to crash/panic/stderr; no deadline
235
+ ```
236
+
237
+ You never see what actually happened — only whether a string you *guessed at* appeared. When it doesn't (crash, OOM, output on stderr, a different message), you either spin until a guard reaps you or — worse — conclude "no failures" and ship a bug.
238
+
239
+ **Preferred — foreground with `timeout`, read the result:**
240
+
241
+ ```bash
242
+ timeout --kill-after=30 600 pnpm test 2>&1 | tee /tmp/test.log; echo "exit=$?"
243
+ # single target: timeout --kill-after=30 600 cargo test -p <crate> <module> -- --nocapture; echo "exit=$?"
244
+ ```
245
+
246
+ Foreground, hard cap, no polling. The exit code is meaningful (0 success, 124 timeout, other = failure) and the output is in front of you — **read it before you decide anything.** This is the default for *every* gate, test, and check.
247
+
248
+ **The orchestrator owns the merge gate.** It re-runs `test` / `typecheck` / `lint` / `build` itself in the Feedback-loops step *after* you commit (*Workflow* step 4); that run, not yours, is the merge authority. You still run gates in the foreground while iterating to know where you stand — just never background them.
249
+
250
+ **If your handoff carries a `<merge-gate>` section, those operator-declared commands ARE the binding gate (issue #849).** They come from the repo's `afk.backpressure` config and the orchestrator runs them against your branch after you emit `DONE`; any non-zero exit parks the issue as `blocked:validation`. They are typically broader than your touched package — `cargo fmt --all -- --check`, a workspace-wide clippy, an integration smoke. Run those exact commands and make them pass *before* `DONE`. Distinguish them from the touched-package **confidence checks** you run while developing: confidence checks tell you where you stand; the `<merge-gate>` commands are the contract you must satisfy. Do **not** invent a broader full-repo suite of your own, and do **not** harden the listed commands with flags they do not carry — the listed commands are the contract (see *Validation Authority* above).
251
+
252
+ **If you genuinely must background a long-lived process** — a dev server that must stay *up* while you do other work, not a command whose result you are waiting on — then every wait loop must satisfy both:
253
+
254
+ 1. **Never match a wait loop against a string that appears in its own command line.** A plain `pgrep -f vitest` matches the polling shell's *own* argv, so `until ! pgrep -f vitest; do sleep 3; done` is self-true forever — it hung worker wKXWG on #302 for 7+ minutes. Match by the **captured job PID** (`cmd & pid=$!; … kill -0 "$pid"`) or use the **bracket trick** so the pattern cannot match itself: `pgrep -f '[v]itest'` (the regex `[v]itest` matches `vitest`; the literal argv `[v]itest` does not).
255
+ 2. **Carry a hard wall-clock deadline** (a `timeout` wrapper or a `SECONDS` bound) so it can never loop forever; if the deadline trips, signal `BLOCKED`.
256
+
257
+ ```bash
258
+ pnpm dev & pid=$! # capture the job PID — never pgrep the tool name
259
+ deadline=$((SECONDS + 600)) # 10 min — tune per task class
260
+ while [ "$SECONDS" -lt "$deadline" ]; do
261
+ kill -0 "$pid" 2>/dev/null || break # process gone → done
262
+ if [ -s "$out" ] && grep -q "ready" "$out"; then
263
+ break
264
+ fi
265
+ sleep 5
266
+ done
267
+ if [ "$SECONDS" -ge "$deadline" ]; then
268
+ echo "background task timed out after 10 min; partial output in $out" >> "$NOTES"
269
+ # then emit <promise>BLOCKED</promise> as your final line
270
+ fi
271
+ ```
272
+
273
+ The rules, in order of importance: **run it in the foreground and read the real output**; **never background a command whose result you need**; **never poll a log to detect completion**; and if you must keep a server up, **never self-match a wait loop's own argv** and **never poll without a deadline**. AFK's idle-timeout, max-iterations, and commit-anchored attempt guard exist to reap a worker that ignores these — they are a safety net, not a substitute for reading your own command output.
274
+
275
+ ## Wiki Awareness
276
+
277
+ If a `.red/wiki/` directory exists in this worktree, treat it as **gitignored knowledge cache**. You may read it for context. You may **not** `git add` it. If your task involves wiki updates, follow the wiki skill — it never commits wiki files.
278
+
279
+ ## Output Discipline
280
+
281
+ Stream useful progress. The orchestrator parses your stdout for stage detection. Helpful phrases:
282
+ - "writing test for X"
283
+ - "implementing Y"
284
+ - "running pnpm test"
285
+ - "tests passing, committing"
286
+
287
+ Final line must be exactly one of:
288
+ - `<promise>DONE</promise>`
289
+ - `<promise>BLOCKED</promise>`
290
+
291
+ Nothing else. The orchestrator branches on those tokens.
292
+
293
+ ## One Task
294
+
295
+ You work on the issue named in the handoff file. Only that. If the queue has more, the orchestrator handles them — that is not your concern.
@@ -0,0 +1,103 @@
1
+ # /afk Safety Rules
2
+
3
+ Binding for both the orchestrator (the shell loop) and the inner agent (claude/codex). Violating any of these aborts the loop with a blocker comment on the active issue.
4
+
5
+ ## Repository Layout Invariants
6
+
7
+ - The **primary checkout** stays on `main` at all times. Never `git checkout`, `git switch`, or `git branch -m` inside it.
8
+ - All work happens in **worktrees** under `.red/tmp/workers/{id}/{N}-a{n}/worktree/` (inside the primary checkout but gitignored) on a branch named `afk/{id}/{N}-{slug}`.
9
+ - The worktree branch is mirrored to `origin/afk/{id}/{N}-{slug}` for remote backup. The orchestrator pushes the worktree branch via the PR's admin-merge (unlocked) or direct merge + push of the locked branch (locked); it does not push `main` directly.
10
+
11
+ ## Git Operations
12
+
13
+ **Allowed in primary checkout:**
14
+ - `git fetch`, `git pull --ff-only`, `git merge --no-ff <local-branch>`, `git push` (SSH only).
15
+ - `git add`, `git commit` (for the pre-merge snapshot when primary is dirty).
16
+ - `git worktree add|remove|list`.
17
+ - `git rebase` (integration step only: `git rebase origin/{pinned}` to integrate the fetched base before merging, per the Merge section below).
18
+ - `git push --force-with-lease` (mirroring only: `git push origin -u HEAD:refs/heads/afk/{id}/{N}-{slug} --force-with-lease` to push the worktree branch onto the remote-tracked `afk/*` namespace, and per-worktree post-commit hook `git push origin HEAD --force-with-lease`, both per the Per-Issue Loop Worktree section below).
19
+ - Read-only: `git status`, `git log`, `git diff`, `git show`, `git branch`.
20
+
21
+ **Allowed in worktree:**
22
+ - `git add`, `git commit`, `git mv`, `git status`, `git diff`, `git log`, `git show`.
23
+
24
+ **Forbidden everywhere, no exceptions:**
25
+ - `git reset` (any flavour)
26
+ - `git rebase` in the worktree or inner agent (orchestrator-only integration step is excepted above).
27
+ - `git clean` (any flavour)
28
+ - `git restore`, `git checkout -- <path>`, `git checkout .`
29
+ - `git stash` — push, pop, drop, all banned
30
+ - `git branch -D`, `git branch -d -f`
31
+ - `git push --force` or any bare `--force` flag in the worktree or inner agent (orchestrator-only mirroring step is excepted above).
32
+ - Any command with `--hard`, `--no-verify` anywhere
33
+ - Switching branches inside any checkout
34
+ - Rewriting history of any branch, ever
35
+
36
+ **SSH-only remotes:**
37
+ - Refuse to start if `git remote -v` shows any `https://` URL.
38
+ - Never auto-rewrite remotes. The user fixes them manually.
39
+
40
+ ## Dirty Primary Checkout
41
+
42
+ If `git -C primary status --porcelain` is non-empty before a merge:
43
+
44
+ 1. `git -C primary add -A`
45
+ 2. `git -C primary commit -m "chore(afk): pre-merge snapshot for #{N}"`
46
+ 3. Proceed with merge.
47
+
48
+ Never `git stash`, `git restore`, or discard the dirty state.
49
+
50
+ ## Merge Conflicts
51
+
52
+ One self-resolve attempt: re-enter the inner agent with the conflict diff in the handoff file Notes. If the inner can't resolve cleanly:
53
+
54
+ 1. `git -C primary merge --abort`.
55
+ 2. Comment the conflict diff on the issue.
56
+ 3. Re-label `ready-for-human`, remove `running`.
57
+ 4. Move to the next issue. **Do not** `git reset` or `git restore` to "clean up" — the merge abort is sufficient.
58
+
59
+ ## Worktree Lifecycle
60
+
61
+ - Created from `origin/{pinned}` after `git fetch` (where `{pinned}` is the resolved base branch: lock > pin > main).
62
+ - Branch name: `afk/{id}/{N}-{slug}` (literal `afk/` + worker ID + issue number + slug). Slug is the issue title lowercased, non-alphanumerics → `-`, truncated to 40 chars.
63
+ - Removed only after successful merge **and** push. Never remove a worktree with uncommitted changes — that loses work.
64
+ - If cleanup fails (e.g. worktree busy), leave it in place and print the path for manual recovery.
65
+
66
+ ## `.red/` Discipline
67
+
68
+ - `.red/tmp/` is gitignored. The orchestrator guarantees this in the worktree before writing handoff files.
69
+ - `.red/wiki/` is gitignored if the project uses the LLM-wiki pattern. The inner agent must never `git add` it.
70
+ - `.red/agents/`, `.red/CONTEXT.md`, and other tracked `.red/` content are normal source. Treat them like any other file.
71
+
72
+ ## Heartbeat and State Files
73
+
74
+ - The periodic issue-thread heartbeat (`:one:` … `:four:` via `gh issue comment`) was retired in Slice D — there is no sub-shell to track or kill. `heartbeat_pid` in older state files is vestigial and ignored.
75
+ - State file writes are atomic: write to `.red/tmp/workers/{id}/{N}-a{n}/afk.state.json.tmp`, `mv` over the real path. Never partial writes.
76
+ - The monitor never writes. Only the orchestrator writes state.
77
+
78
+ ## Signals and Shutdown
79
+
80
+ - `SIGINT` (Ctrl-C): finish the current `pnpm`/git command if mid-flight, write a "interrupted" comment on the active issue, leave the worktree in place, exit 130.
81
+ - `SIGTERM`: same as `SIGINT`.
82
+ - Never trap `SIGKILL` — let the OS do its thing.
83
+
84
+ There is no heartbeat sub-shell to reap on any of these paths since Slice D — the only cleanup work is releasing the in-flight claim, preserving the active attempt directory, and removing the per-worker `worker.pid` (and the empty worker dir) on the EXIT trap.
85
+
86
+ ## What "Blocker" Means
87
+
88
+ A blocker is recorded by:
89
+ 1. Appending Notes to the handoff file (the inner does this).
90
+ 2. Posting the Notes as a comment on the GitHub issue (the orchestrator does this).
91
+ 3. Removing `running`, adding `ready-for-human`.
92
+ 4. Worktree is preserved at the moment of blocker — the human investigates in place.
93
+
94
+ The loop continues with the next issue. Blockers are not fatal to the loop.
95
+
96
+ ## What Aborts The Whole Loop
97
+
98
+ Only these:
99
+ - Hard preconditions failed at startup (HTTPS remote, no `gh` auth, no `main`).
100
+ - Both runners exhausted on the same issue.
101
+ - Uncaught error in the orchestrator shell (not from inner — those become blockers).
102
+
103
+ On abort: write final state, print recovery instructions. Worktrees in progress are left alone. (No heartbeat sub-shell to kill since Slice D.)
@@ -0,0 +1,160 @@
1
+ ---
2
+ name: afk
3
+ description: Autonomous loop that drains the `ready-for-agent` queue on the issue tracker. Each iteration claims an issue, runs it in an isolated worktree, executes with claude or codex, merges back to main, and closes the issue. Use when the user wants to run AFK execution, drain a Spec, hammer specific issues, or otherwise let agents grind through the backlog.
4
+ argument-hint: "[--spec N | --issues N,N,N] [--runner claude|codex|opencode] [--alternate] [--fallback-runner] [--request TEXT] [-n N] [--once] [--boot-only] | fleet [N] | fleet stop | fleet status | fleet logs --supervisor|--worker ID|--all [--follow] | monitor | dashboard | daily-review | weekly-review | retake N | reap"
5
+ ---
6
+
7
+ # /afk
8
+
9
+ **The default lane for all tracked backlog work.** `/afk` is the modus
10
+ operandi; `/go` is the ad-hoc-only exception. Drain the agent-ready backlog by
11
+ letting the runtime select issues, create isolated worktrees, run the inner
12
+ agent, validate, land, close, and clean up.
13
+
14
+ The invoking LLM is responsible for setting `RED_AFK_RUNNER` to its own host
15
+ runner (`codex` from Codex, `claude` from Claude Code). Resolve the
16
+ `red-skills-dev` runtime through the shared contract in
17
+ [`../_report-runtime/WRAPPER.md`](../_report-runtime/WRAPPER.md): use an
18
+ installed `red-skills-dev` shim on `PATH` first, otherwise use the ADR 0091 npm
19
+ direct-run fallback
20
+ `npx -y -p @reddb-io/red-skills@<version> red-skills-dev ...`. If the shim is
21
+ missing, name that fallback instead of surfacing a bare command-not-found.
22
+
23
+ Run the bundle, not the source:
24
+
25
+ ```bash
26
+ RED_AFK_RUNNER=<claude|codex|opencode> red-skills-dev <command> [params]
27
+ ```
28
+
29
+ `afk.mjs` is a dedicated forwarder to the `dev` bundle. Every argument reaches
30
+ the orchestrator unchanged. The AFK queue-drain subcommand is `run`; valid
31
+ top-level dev CLI subcommands include `run`, `monitor`, `fleet`, `dashboard`,
32
+ `daily-review`, `weekly-review`, `retake`, `requeue`, and `reap`. A bare
33
+ `--issues 42` is forwarded to the same run surface. There is no
34
+ `red-skills-dev afk` subcommand. Runtime details and the full operations
35
+ contract live in [`docs/OPERATIONS.md`](./docs/OPERATIONS.md).
36
+
37
+ ## When To Use
38
+
39
+ - `/afk` - drain every open issue labelled `ready-for-agent`.
40
+ - `/afk --spec 42` - drain only tickets linked to Spec #42; the Spec issue
41
+ itself is excluded.
42
+ - `/afk --issues 356,359,362` - drain an explicit issue list in that order.
43
+ - `/afk --runner codex` - pin a backend. This disables detection cascade and is
44
+ mutually exclusive with `--alternate`.
45
+ - `/afk --alternate` - opt into round-robin runner rotation between issues.
46
+ - `/afk --fallback-runner` - opt into one mid-issue runner swap on
47
+ `RUNNER_EXHAUSTED`; otherwise exhaustion uses bounded `blocked:quota`
48
+ recovery and exits 75.
49
+ - `/afk --request "..."` or `/afk -r "..."` - add a special user request block
50
+ to every inner-agent prompt in this run.
51
+ - `/afk -n 5` - cap the run at five issues; `-n 0` and omitted `-n` mean
52
+ unlimited queue drain.
53
+ - `/afk --once` - single supervised iteration for debugging the prompt.
54
+ - `/afk --boot-only` - run boot sweeps and prechecks without claiming work.
55
+ - `/afk monitor` - read-only status board; read [`monitor.md`](./monitor.md)
56
+ for the dashboard and native-task mirror contract.
57
+ - `/afk dashboard [--period 30d] [--json]` - process dashboard for open work,
58
+ local workers, flow metrics, and DORA proxies.
59
+ - `/afk daily-review [--json]` / `/afk weekly-review [--json]` - operational
60
+ review for the local daily or six-day window.
61
+ - `/afk retake 123 [--apply] [--json]` - issue resumption report; safe local
62
+ setup only with `--apply`.
63
+ - `/afk fleet [N]` - supervise `N` concurrent workers; read
64
+ [`fleet.md`](./fleet.md) before launch or stop operations.
65
+ - `/afk fleet stop` - gracefully stop the fleet supervisor and auto-monitor.
66
+ - `/afk fleet status` - read-only fleet ground truth: supervisor pid, health
67
+ verdict, runner, slot occupancy, bundle version/skew, churn, live workers, and
68
+ whether a watchdog respawn would fire. Answers "what is actually running?"
69
+ without cross-referencing pid files and snapshots by hand.
70
+ - `/afk fleet logs --supervisor|--worker <id>|--all [--follow]` - read-only
71
+ local log view over the structured castle lanes. Supervisor logs render the
72
+ supervisor lane; worker logs render a single worker lane; `--all` merges all
73
+ worker lanes and prefixes every line with the worker id.
74
+ - `/afk reap` - run branch hygiene without starting a worker.
75
+
76
+ For GitHub Actions adoption, use [`actions-lane.md`](./actions-lane.md). The
77
+ same `/afk --issues N --runner opencode --once` lane runs as reusable workflow,
78
+ composite action, or local bundle invocation.
79
+
80
+ ## Operating Contract
81
+
82
+ Read the focused reference before touching that concern:
83
+
84
+ - Runtime, sandcastle substrate, CLI forwarding, bootstrap, hard preconditions,
85
+ issue selection, lifecycle, failure labels, per-issue loop, merge/close,
86
+ runner fallback, completion bounds, stop conditions, and reporting:
87
+ [`docs/OPERATIONS.md`](./docs/OPERATIONS.md).
88
+ - Boot cleanup, stale attempts, branch reapers, and unblock sweep mechanics:
89
+ [`docs/BOOT-SWEEPS.md`](./docs/BOOT-SWEEPS.md).
90
+ - Durable AFK process state lives under `.red/state/castle/`; disposable worker
91
+ attempts, claim locks, worktrees, logs, and diagnostics stay in registered
92
+ `.red/tmp/` lanes and are the only targets of the lane janitor.
93
+ - State files, terminal-event envelope, attempt-outcome mapping, JSONL lanes,
94
+ and failure snapshots: [`docs/ENVELOPE.md`](./docs/ENVELOPE.md).
95
+ - Handoff wrappers and inner-agent prompt materialisation:
96
+ [`docs/HANDOFF.md`](./docs/HANDOFF.md) and
97
+ [`AGENT-PROMPT.md`](./AGENT-PROMPT.md).
98
+ - Runner-specific behavior: [`runner-claude.md`](./runner-claude.md),
99
+ [`runner-codex.md`](./runner-codex.md),
100
+ [`runner-opencode.md`](./runner-opencode.md), and fallback
101
+ [`runner-hermes.md`](./runner-hermes.md).
102
+ - Liveness, stall protection, and lane-idle rules:
103
+ [`docs/LIVENESS.md`](./docs/LIVENESS.md).
104
+ - Config, env overrides, lifecycle hooks, sandbox/runner/model settings, and
105
+ backpressure commands: [`docs/CONFIG.md`](./docs/CONFIG.md).
106
+ - Safety rules for shell and git actions: [`SAFETY.md`](SAFETY.md).
107
+
108
+ ## Load-Bearing Rules
109
+
110
+ - Tracked work belongs in `/afk`. An empty `ready-for-agent` queue with a
111
+ non-empty open backlog is a flow bug to surface with a gate census, not a
112
+ clean "nothing to do" stop.
113
+ - Dependencies use `req:N` edge labels plus `blocked:dependency`; human gates
114
+ use `## Current blocker` / `ready-for-human`.
115
+ - Worktrees live under `.red/tmp/workers/{id}/{N}-a{n}/worktree`; the worker
116
+ liveness anchor is `.red/tmp/workers/{id}/worker.pid`.
117
+ - Claiming uses the three-layer scheme: local `mkdir` lock, GitHub label
118
+ pre-check, and stale-lock boot sweep.
119
+ - The inner agent's canonical completion signals are
120
+ `<promise>DONE</promise>` and `<promise>BLOCKED</promise>`.
121
+ - The gate command is canonical. Feedback plus the operator's
122
+ `afk.backpressure` commands are the sole validation authority; workers run
123
+ those exact commands and never self-impose stricter flags, extra lint
124
+ restrictions, widened target sets, or a harder contract than the gate defines.
125
+ If an error appears only under an extra check, reconcile it against the real
126
+ gate command before reporting a red `main`.
127
+ - `blocked:ci` leaves the completed PR open and escalates to `ready-for-human`;
128
+ AFK does not re-run the inner agent for already-complete work waiting on CI.
129
+ - On DONE, completion sweep reclaims all attempt directories for that issue
130
+ across workers; failure paths retain cheap artifacts and the pushed
131
+ `afk/*` worker branch.
132
+
133
+ ## Parallelization
134
+
135
+ `/afk` is trivially parallel: run another `/afk` in another terminal. Each run
136
+ gets a worker ID (`w` + 4 random `[A-Z0-9]` chars), separate worker files, and
137
+ the same claim safety. Choose fleet width by disjointness; read
138
+ [`fleet.md`](./fleet.md) for the full rule.
139
+
140
+ ## Stop Conditions
141
+
142
+ - Queue drained -> `<promise>NO MORE TASKS</promise>` and exit 0, with a gate
143
+ census when open non-Spec issues remain.
144
+ - `-n N` reached -> summary and exit 0.
145
+ - Runner exhaustion or transient runner failure -> bounded recovery for the
146
+ current issue, then outer exit 75.
147
+ - Uncaught orchestrator error -> leave recoverable artifacts in place, exit 1,
148
+ and print the recovery hint.
149
+
150
+ ## Safety
151
+
152
+ See [`SAFETY.md`](SAFETY.md). The orchestrator and inner agent both inherit
153
+ those rules; violations abort the loop.
154
+
155
+ <supporting-info>
156
+
157
+ For failure-state playbooks and operator recovery procedures, see
158
+ [TROUBLESHOOTING.md](./TROUBLESHOOTING.md).
159
+
160
+ </supporting-info>