[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M76RV7QEPRXT7V5ED2TY2PN4":3,"skill-same:01M76RV7QEPRXT7V5ED2TY2PN4":44},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M76RV7QEPRXT7V5ED2TY2PN4","loop",null,"Full execution protocol for MODE: LOOP — the compound-engineering loop: brainstorm → plan → build → review → improve, iterating under defense-in-depth stop conditions with generator\u002Fcritic separation, durable resumable state, and mandatory compounding learning capture. Loaded on demand by the architect when the loop command emits a [MODE: LOOP ...] signal.","AlexanderNarbaev\u002Fagi","AlexanderNarbaev","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F33544956?v=4","01M755ZKB1JJ26ZBNZSDJ4C0TV","01M755ZKBX072HZMHVQBWK7MK7",1,"AGPL-3.0","https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev\u002Fagi\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Floop\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: loop\ndescription: >\n  Full execution protocol for MODE: LOOP — the compound-engineering loop:\n  brainstorm → plan → build → review → improve, iterating under\n  defense-in-depth stop conditions with generator\u002Fcritic separation,\n  durable resumable state, and mandatory compounding learning capture.\n  Loaded on demand by the architect when the loop command emits a\n  [MODE: LOOP ...] signal.\n---\n\n# Compound-Engineering Loop Protocol\n\nMODE: LOOP runs an objective end to end as a series of gated phases, then\nloops to compound improvements until the objective is met or a stop condition\nfires. Each cycle reuses the existing mode skills (`brainstorm`, `plan`,\n`critic-gate`, `execute`, `phase-wrap`) and ends with a learning-capture step\nso the next cycle is cheaper — that is what makes the loop *compounding* rather\nthan merely repeating.\n\nThis is a real implementation workflow: it delegates to the coder, declares\nscope, and mutates source code through the normal EXECUTE path. It is distinct\nfrom full-auto (autonomous cross-phase oversight via the `critic_oversight`\nagent) and turbo (parallel lanes within a single phase). LOOP is a\nuser-initiated, gated, sequential, compounding workflow.\n\nThe two design rules that everything below serves:\n\n1. **Separate the generator from the verifier.** The context that writes a\n   change must never be the only context that approves it. Implementation,\n   independent review, and critic challenge live in separate delegated\n   contexts. Review is report-only; a distinct fix step applies changes.\n2. **Stop on positive evidence or a budget — never on vibes.** Every phase has\n   an entry gate and an exit gate backed by concrete evidence, and the loop has\n   layered stop conditions so it can never run away.\n\n---\n\n## Step 0 — Parse Header\n\nParse the `[MODE: LOOP ...]` header to extract:\n\n- `objective`: the goal text after the header (the WHAT to achieve). Empty only\n  when `resume=true`.\n- `max_cycles`: integer 1..5 (default 3) — hard cap on outer improvement cycles.\n- `autonomy`: `checkpoint` (default) or `auto`.\n  - `checkpoint`: pause at each phase gate and wait for explicit user approval\n    before continuing.\n  - `auto`: proceed across gates without prompting, but still enforce every\n    hard stop condition and the mandatory review\u002Fcritic gates.\n- `depth`: `standard` (default) or `exhaustive` (wider exploration in\n  BRAINSTORM and PLAN: more candidate approaches, deeper localization).\n- `resume`: `true` | `false`. When true, resume the existing run from durable\n  state instead of starting a new objective.\n\nIf the header is malformed or required fields are missing, report the error and\nstop.\n\n---\n\n## Step 1 — Preconditions & Durable State\n\n1. **Working tree.** Check `git status`. If the tree is dirty, surface the\n   uncommitted changes and ask whether to proceed (checkpoint) or proceed only\n   if the changes are clearly part of this objective (auto). Do not silently\n   build on an unknown working state.\n2. **Run state directory.** Loop state lives under `.swarm\u002Floop\u002F\u003Crun-id>\u002F`\n   (containment invariant — never write loop state outside `.swarm\u002F`).\n   - New run (`resume=false`): allocate a `run-id` (short slug + timestamp),\n     create `.swarm\u002Floop\u002F\u003Crun-id>\u002Fstate.json`, and record the baseline:\n     objective, parsed parameters, start HEAD commit, `cycle: 0`,\n     `phase: brainstorm`, empty `improvements` and `learnings` lists.\n   - Resume (`resume=true`): locate the most recent `.swarm\u002Floop\u002F\u003Crun-id>\u002F`\n     with an unfinished state, read it, **validate required fields** (`run_id`,\n     `cycle`, `phase`, `done` must all be present and have the correct types;\n     if any are missing or malformed, report the corruption clearly and stop\n     rather than continuing with undefined values), print a short progress\n     summary (cycle N of max_cycles, current phase, last gate result), and\n     continue from the recorded phase. If no resumable run exists, say so and\n     stop.\n   - **Retention:** On both new-run and resume entry, prune completed runs\n     (`.done === true`) that exceed 10 in count — keep the 10 most recent by\n     timestamp, remove the rest. This prevents unbounded state accumulation\n     under `.swarm\u002Floop\u002F`.\n3. **State is derived, not authoritative for code.** The durable state file\n   tracks *loop control* (cycle counter, phase, gate outcomes, captured\n   learnings, stop reason). Actual implementation progress is derived from git\n   and the plan ledger (`.swarm\u002Fplan-ledger.jsonl`), never from conversation\n   memory — so a killed\u002Fresumed session never loses or re-does work.\n\nWrite the state file after every gate transition. The on-disk state is the\nsingle source of truth for resumability.\n\n---\n\n## Step 2 — The Cycle\n\nOne cycle is five phases run in order: **BRAINSTORM → PLAN → BUILD → REVIEW →\nIMPROVE**. Do not skip or collapse phases. Each phase has an entry gate\n(precondition) and an exit gate (positive evidence required before the next\nphase begins). In `checkpoint` autonomy, pause at each gate for user approval.\n\nOn cycle 2+, BRAINSTORM is replaced by a lightweight **refinement** step: feed\nthe prior cycle's captured improvements and residual findings into PLAN\ndirectly (skip full discovery dialogue) — the objective is already framed.\n\n### Phase 1 — BRAINSTORM (cycle 1 only)\n\n- **Entry gate:** objective is non-empty; no approved plan already covers it.\n- **Action:** Load `file:.opencode\u002Fskills\u002Fbrainstorm\u002FSKILL.md` and run it to\n  produce `.swarm\u002Fspec.md` and a QA gate profile. With `depth=exhaustive`,\n  require at least one non-obvious candidate approach.\n- **Exit gate:** `spec.md` exists with explicit, testable success criteria and\n  scope boundaries. Record the success criteria into loop state — they are the\n  objective-met test used by the stop conditions. Checkpoint: confirm the spec\n  with the user.\n\n### Phase 2 — PLAN\n\n- **Entry gate:** a spec (or, on cycle 2+, the improvement directives) exists.\n- **Action:**\n  1. Load `file:.opencode\u002Fskills\u002Fpre-phase-briefing\u002FSKILL.md` (required before\n     planning, especially on cycle 2+: it reads the prior retrospective and\n     verifies codebase reality so the new plan reflects what actually changed).\n  2. Load `file:.opencode\u002Fskills\u002Fplan\u002FSKILL.md` to decompose the work into\n     tasks and call `save_plan`. With `depth=exhaustive`, prefer finer task\n     granularity and deeper localization.\n  3. Load `file:.opencode\u002Fskills\u002Fcritic-gate\u002FSKILL.md` to put the plan through\n     an independent critic.\n- **Exit gate:** critic verdict is APPROVED (NEEDS_REVISION → revise and\n  re-submit, max 2 cycles per the critic-gate skill; REJECTED → stop and report\n  to the user). Record the verdict in loop state.\n\n### Phase 3 — BUILD\n\n- **Entry gate:** a critic-approved plan exists.\n- **Action:** Load `file:.opencode\u002Fskills\u002Fexecute\u002FSKILL.md` and run the plan\n  phase by phase. The coder implements each task; per-task QA gates (tests,\n  lint, security, etc.) run as defined by the selected QA profile. The coder\n  context is the **generator** — it does not get to declare its own work\n  correct.\n- **Exit gate:** all planned tasks for the cycle are implemented and their\n  per-task QA gates pass with recorded evidence. NEVER weaken, mock, skip, or\n  delete a failing test\u002Fassertion to make a gate pass — fix the root cause or\n  stop and report.\n\n### Phase 4 — REVIEW (report-only) + FIX\n\nThis phase is the heart of the generator\u002Fverifier separation. It runs on the\n**actual current diff**, in contexts independent of the coder.\n\n- **Entry gate:** BUILD exit gate passed; capture the current diff\n  (`git diff` against the cycle's start commit).\n- **Action:**\n  1. **Independent reviewer.** Delegate the real diff and the QA evidence to a\n     fresh reviewer context. It defaults to disbelief, looks for correctness\n     bugs, regressions, security issues, missing edge cases, and\n     claimed-vs-actual mismatches, and classifies each finding. The reviewer\n     does not edit code — it reports.\n  2. **Critic challenge.** Delegate the reviewer-approved diff and any\n     HIGH\u002FCRITICAL findings to a separate critic context that challenges weak\n     evidence, overclaimed severity, and missing sibling-file checks. The\n     critic may overturn the reviewer.\n  3. **Fix step.** For every `NEEDS_REVISION` \u002F `REJECTED` \u002F `BLOCKED` item,\n     return to the coder (generator) to fix it with code, tests, or evidence,\n     then re-run the affected reviewer\u002Fcritic gate. Any edit after approval\n     invalidates that approval — re-review.\n- **Exit gate:** reviewer approval AND critic approval on the latest diff, with\n  the latest edit older than both approvals. Record the reviewer\u002Fcritic verdicts\n  durably alongside the phase evidence (the phase-wrap evidence manager writes\n  retrospective and gate artifacts under `.swarm\u002Fevidence\u002F` — keep the\n  review\u002Fcritic outcomes with that phase's evidence so `phase_complete` and any\n  later audit can read them). This satisfies the mandatory implementation\n  closeout gate.\n\n### Phase 5 — IMPROVE (phase-wrap + compounding capture)\n\nThis is what makes the loop compound. Do not declare completion without it.\n\n- **Entry gate:** REVIEW exit gate passed.\n- **Action:**\n  1. Load `file:.opencode\u002Fskills\u002Fphase-wrap\u002FSKILL.md` and write the mandatory\n     retrospective (the `phase_complete` gate blocks without a valid `retro-N`\n     bundle). Rescan the codebase and update documentation exactly as the\n     phase-wrap skill directs — that is, scoped to its authorized set\n     (README.md \u002F CONTRIBUTING.md \u002F docs\u002F via the `docs` agent). Do NOT edit the\n     governance contract files (AGENTS.md \u002F CLAUDE.md); they constrain the loop\n     and are out of scope for autonomous edits.\n  2. **Capture learnings durably.** Distill what this cycle taught — recurring\n     bug classes, surprising couplings, tooling gotchas, convention decisions —\n     into the knowledge base (the `knowledge_add` tool \u002F the memory tools when\n     enabled) and\u002For a categorized note under `.swarm\u002Floop\u002F\u003Crun-id>\u002Flearnings\u002F`.\n  3. **Make learnings discoverable.** Ensure the next loop will actually read\n     them: persist via `knowledge_add` (which `knowledge_recall` surfaces in\n     later phases) rather than a write-only note nobody reads — capturing\n     learnings nothing retrieves does not compound.\n  4. **Feed findings forward.** Record any review\u002Fcritic finding that recurred\n     so it becomes an explicit check in the next cycle's reviewer prompt.\n- **Exit gate:** retrospective written and accepted by `phase_complete`;\n  learnings persisted; the cycle's improvements and residual findings recorded\n  in loop state.\n\n---\n\n## Step 3 — Loop Decision (Stop Conditions)\n\nAfter IMPROVE, evaluate the stop conditions **in order**. Use defense in depth:\nseveral overlapping conditions, not one. Record the chosen `stop_reason` in\nloop state.\n\n1. **Objective met (primary).** The success criteria captured in Phase 1 are\n   all satisfied AND the full validation suite \u002F required QA gates are green.\n   → STOP (success).\n2. **Cycle budget exhausted.** `cycle >= max_cycles`. → STOP. Never exceed\n   `max_cycles`.\n3. **No-progress \u002F plateau.** The just-finished cycle produced no qualifying\n   improvement toward the objective (no new passing criteria, no accepted\n   review fix that advanced the goal). → STOP and report the plateau; looping\n   again would burn budget without progress.\n4. **Oscillation.** The cycle reintroduced or reverted a change made in a prior\n   cycle (the diff fingerprint repeats). → STOP and report; the loop is\n   thrashing.\n5. **Unrecoverable error.** A gate cannot pass for a reason outside this\n   objective's scope (e.g., REJECTED plan, environment failure, a required\n   external dependency is unavailable). → STOP and report.\n6. **Explicit user stop.** The user asked to stop. → STOP immediately.\n\nIf none fire and budget remains: increment `cycle`, set the next cycle's input\nto the recorded improvement directives + residual findings, and return to\n**Phase 2 (PLAN)** (cycle 2+ skips full BRAINSTORM). In `checkpoint` autonomy,\nconfirm \"continue for another cycle?\" with the user before looping.\n\n---\n\n## Step 4 — Completion\n\nWhen a stop condition fires:\n\n1. Mark loop state `done` with the `stop_reason` and final HEAD commit.\n2. Present a human-readable summary:\n   - Objective and whether it was met.\n   - Baseline → final state (what changed, key files\u002Ftasks).\n   - Cycles run (and why it stopped).\n   - Tasks completed vs deferred; residual review findings and where they are\n     recorded.\n   - Learnings captured this run and where they live.\n   - Suggested next steps (e.g., open a PR via `\u002Fswarm pr-review` or the\n     commit-pr flow — do NOT open a PR unless the user asks).\n3. Emit a machine-detectable completion marker on its own line so callers \u002F\n   automation can detect terminal state:\n\n   `\u003Cloop-complete reason=\"objective-met|budget-exhausted|plateau|oscillation|unrecoverable-error|user-stop\" cycles=\"N\"\u002F>`\n\n---\n\n## Durable State Schema (`.swarm\u002Floop\u002F\u003Crun-id>\u002Fstate.json`)\n\nA minimal, append-friendly shape — extend as needed but keep these fields:\n\n```json\n{\n  \"run_id\": \"rate-limit-20260618T0712Z\",\n  \"objective\": \"add rate limiting to the public API\",\n  \"params\": { \"max_cycles\": 3, \"autonomy\": \"checkpoint\", \"depth\": \"standard\" },\n  \"start_commit\": \"\u003Csha>\",\n  \"cycle\": 1,\n  \"phase\": \"review\",\n  \"success_criteria\": [\"...\", \"...\"],\n  \"gates\": [\n    { \"cycle\": 1, \"phase\": \"plan\", \"result\": \"approved\", \"at\": \"\u003Ciso>\" }\n  ],\n  \"improvements\": [],\n  \"learnings\": [],\n  \"done\": false,\n  \"stop_reason\": null,\n  \"final_commit\": null\n}\n```\n\n---\n\n## Autonomy Quick Reference\n\n| Behavior | `checkpoint` (default) | `auto` |\n| --- | --- | --- |\n| Pause at phase gates | Yes — wait for user approval | No |\n| Confirm before next cycle | Yes | No |\n| Mandatory review + critic gates | Enforced | Enforced |\n| Hard stop conditions (budget, plateau, oscillation, errors) | Enforced | Enforced |\n| Weaken\u002Fmock\u002Fskip a failing test | Never | Never |\n\n`auto` reduces prompts; it never reduces verification.\n\n---\n\n## Anti-Patterns (do not do these)\n\n- Letting the coder context approve its own diff. Review and critic must be\n  independent contexts.\n- Treating passing tests, explorer output, or self-review as the implementation\n  closeout gate. They are not.\n- Editing code after reviewer\u002Fcritic approval and then declaring done without\n  re-review. Any post-approval edit invalidates the approval.\n- Looping \"one more time\" past `max_cycles` or after a plateau because it feels\n  close. Stop and report.\n- Skipping the IMPROVE\u002Fcompound capture step to finish faster. The compounding\n  step is the point of the loop.\n- Storing loop progress only in conversation context. Persist to\n  `.swarm\u002Floop\u002F\u003Crun-id>\u002F` so the loop survives interruption.\n- Weakening, mocking, skipping, or deleting a failing assertion to turn a gate\n  green. Fix the root cause or stop.\n","# Compound-Engineering Loop Protocol\n\nMODE: LOOP runs an objective end to end as a series of gated phases, then\nloops to compound improvements until the objective is met or a stop condition\nfires. Each cycle reuses the existing mode skills (`brainstorm`, `plan`,\n`critic-gate`, `execute`, `phase-wrap`) and ends with a learning-capture step\nso the next cycle is cheaper — that is what makes the loop *compounding* rather\nthan merely repeating.\n\nThis is a real implementation workflow: it delegates to the coder, declares\nscope, and mutates source code through the normal EXECUTE path. It is distinct\nfrom full-auto (autonomous cross-phase oversight via the `critic_oversight`\nagent) and turbo (parallel lanes within a single phase). LOOP is a\nuser-initiated, gated, sequential, compounding workflow.\n\nThe two design rules that everything below serves:\n\n1. **Separate the generator from the verifier.** The context that writes a\n   change must never be the only context that approves it. Implementation,\n   independent review, and critic challenge live in separate delegated\n   contexts. Review is report-only; a distinct fix step applies changes.\n2. **Stop on positive evidence or a budget — never on vibes.** Every phase has\n   an entry gate and an exit gate backed by concrete evidence, and the loop has\n   layered stop conditions so it can never run away.\n\n---\n\n## Step 0 — Parse Header\n\nParse the `[MODE: LOOP ...]` header to extract:\n\n- `objective`: the goal text after the header (the WHAT to achieve). Empty only\n  when `resume=true`.\n- `max_cycles`: integer 1..5 (default 3) — hard cap on outer improvement cycles.\n- `autonomy`: `checkpoint` (default) or `auto`.\n  - `checkpoint`: pause at each phase gate and wait for explicit user approval\n    before continuing.\n  - `auto`: proceed across gates without prompting, but still enforce every\n    hard stop condition and the mandatory review\u002Fcritic gates.\n- `depth`: `standard` (default) or `exhaustive` (wider exploration in\n  BRAINSTORM and PLAN: more candidate approaches, deeper localization).\n- `resume`: `true` | `false`. When true, resume the existing run from durable\n  state instead of starting a new objective.\n\nIf the header is malformed or required fields are missing, report the error and\nstop.\n\n---\n\n## Step 1 — Preconditions & Durable State\n\n1. **Working tree.** Check `git status`. If the tree is dirty, surface the\n   uncommitted changes and ask whether to proceed (checkpoint) or proceed only\n   if the changes are clearly part of this objective (auto). Do not silently\n   build on an unknown working state.\n2. **Run state directory.** Loop state lives under `.swarm\u002Floop\u002F\u003Crun-id>\u002F`\n   (containment invariant — never write loop state outside `.swarm\u002F`).\n   - New run (`resume=false`): allocate a `run-id` (short slug + timestamp),\n     create `.swarm\u002Floop\u002F\u003Crun-id>\u002Fstate.json`, and record the baseline:\n     objective, parsed parameters, start HEAD commit, `cycle: 0`,\n     `phase: brainstorm`, empty `improvements` and `learnings` lists.\n   - Resume (`resume=true`): locate the most recent `.swarm\u002Floop\u002F\u003Crun-id>\u002F`\n     with an unfinished state, read it, **validate required fields** (`run_id`,\n     `cycle`, `phase`, `done` must all be present and have the correct types;\n     if any are missing or malformed, report the corruption clearly and stop\n     rather than continuing with undefined values), print a short progress\n     summary (cycle N of max_cycles, current phase, last gate result), and\n     continue from the recorded phase. If no resumable run exists, say so and\n     stop.\n   - **Retention:** On both new-run and resume entry, prune completed runs\n     (`.done === true`) that exceed 10 in count — keep the 10 most recent by\n     timestamp, remove the rest. This prevents unbounded state accumulation\n     under `.swarm\u002Floop\u002F`.\n3. **State is derived, not authoritative for code.** The durable state file\n   tracks *loop control* (cycle counter, phase, gate outcomes, captured\n   learnings, stop reason). Actual implementation progress is derived from git\n   and the plan ledger (`.swarm\u002Fplan-ledger.jsonl`), never from conversation\n   memory — so a killed\u002Fresumed session never loses or re-does work.\n\nWrite the state file after every gate transition. The on-disk state is the\nsingle source of truth for resumability.\n\n---\n\n## Step 2 — The Cycle\n\nOne cycle is five phases run in order: **BRAINSTORM → PLAN → BUILD → REVIEW →\nIMPROVE**. Do not skip or collapse phases. Each phase has an entry gate\n(precondition) and an exit gate (positive evidence required before the next\nphase begins). In `checkpoint` autonomy, pause at each gate for user approval.\n\nOn cycle 2+, BRAINSTORM is replaced by a lightweight **refinement** step: feed\nthe prior cycle's captured improvements and residual findings into PLAN\ndirectly (skip full discovery dialogue) — the objective is already framed.\n\n### Phase 1 — BRAINSTORM (cycle 1 only)\n\n- **Entry gate:** objective is non-empty; no approved plan already covers it.\n- **Action:** Load `file:.opencode\u002Fskills\u002Fbrainstorm\u002FSKILL.md` and run it to\n  produce `.swarm\u002Fspec.md` and a QA gate profile. With `depth=exhaustive`,\n  require at least one non-obvious candidate approach.\n- **Exit gate:** `spec.md` exists with explicit, testable success criteria and\n  scope boundaries. Record the success criteria into loop state — they are the\n  objective-met test used by the stop conditions. Checkpoint: confirm the spec\n  with the user.\n\n### Phase 2 — PLAN\n\n- **Entry gate:** a spec (or, on cycle 2+, the improvement directives) exists.\n- **Action:**\n  1. Load `file:.opencode\u002Fskills\u002Fpre-phase-briefing\u002FSKILL.md` (required before\n     planning, especially on cycle 2+: it reads the prior retrospective and\n     verifies codebase reality so the new plan reflects what actually changed).\n  2. Load `file:.opencode\u002Fskills\u002Fplan\u002FSKILL.md` to decompose the work into\n     tasks and call `save_plan`. With `depth=exhaustive`, prefer finer task\n     granularity and deeper localization.\n  3. Load `file:.opencode\u002Fskills\u002Fcritic-gate\u002FSKILL.md` to put the plan through\n     an independent critic.\n- **Exit gate:** critic verdict is APPROVED (NEEDS_REVISION → revise and\n  re-submit, max 2 cycles per the critic-gate skill; REJECTED → stop and report\n  to the user). Record the verdict in loop state.\n\n### Phase 3 — BUILD\n\n- **Entry gate:** a critic-approved plan exists.\n- **Action:** Load `file:.opencode\u002Fskills\u002Fexecute\u002FSKILL.md` and run the plan\n  phase by phase. The coder implements each task; per-task QA gates (tests,\n  lint, security, etc.) run as defined by the selected QA profile. The coder\n  context is the **generator** — it does not get to declare its own work\n  correct.\n- **Exit gate:** all planned tasks for the cycle are implemented and their\n  per-task QA gates pass with recorded evidence. NEVER weaken, mock, skip, or\n  delete a failing test\u002Fassertion to make a gate pass — fix the root cause or\n  stop and report.\n\n### Phase 4 — REVIEW (report-only) + FIX\n\nThis phase is the heart of the generator\u002Fverifier separation. It runs on the\n**actual current diff**, in contexts independent of the coder.\n\n- **Entry gate:** BUILD exit gate passed; capture the current diff\n  (`git diff` against the cycle's start commit).\n- **Action:**\n  1. **Independent reviewer.** Delegate the real diff and the QA evidence to a\n     fresh reviewer context. It defaults to disbelief, looks for correctness\n     bugs, regressions, security issues, missing edge cases, and\n     claimed-vs-actual mismatches, and classifies each finding. The reviewer\n     does not edit code — it reports.\n  2. **Critic challenge.** Delegate the reviewer-approved diff and any\n     HIGH\u002FCRITICAL findings to a separate critic context that challenges weak\n     evidence, overclaimed severity, and missing sibling-file checks. The\n     critic may overturn the reviewer.\n  3. **Fix step.** For every `NEEDS_REVISION` \u002F `REJECTED` \u002F `BLOCKED` item,\n     return to the coder (generator) to fix it with code, tests, or evidence,\n     then re-run the affected reviewer\u002Fcritic gate. Any edit after approval\n     invalidates that approval — re-review.\n- **Exit gate:** reviewer approval AND critic approval on the latest diff, with\n  the latest edit older than both approvals. Record the reviewer\u002Fcritic verdicts\n  durably alongside the phase evidence (the phase-wrap evidence manager writes\n  retrospective and gate artifacts under `.swarm\u002Fevidence\u002F` — keep the\n  review\u002Fcritic outcomes with that phase's evidence so `phase_complete` and any\n  later audit can read them). This satisfies the mandatory implementation\n  closeout gate.\n\n### Phase 5 — IMPROVE (phase-wrap + compounding capture)\n\nThis is what makes the loop compound. Do not declare completion without it.\n\n- **Entry gate:** REVIEW exit gate passed.\n- **Action:**\n  1. Load `file:.opencode\u002Fskills\u002Fphase-wrap\u002FSKILL.md` and write the mandatory\n     retrospective (the `phase_complete` gate blocks without a valid `retro-N`\n     bundle). Rescan the codebase and update documentation exactly as the\n     phase-wrap skill directs — that is, scoped to its authorized set\n     (README.md \u002F CONTRIBUTING.md \u002F docs\u002F via the `docs` agent). Do NOT edit the\n     governance contract files (AGENTS.md \u002F CLAUDE.md); they constrain the loop\n     and are out of scope for autonomous edits.\n  2. **Capture learnings durably.** Distill what this cycle taught — recurring\n     bug classes, surprising couplings, tooling gotchas, convention decisions —\n     into the knowledge base (the `knowledge_add` tool \u002F the memory tools when\n     enabled) and\u002For a categorized note under `.swarm\u002Floop\u002F\u003Crun-id>\u002Flearnings\u002F`.\n  3. **Make learnings discoverable.** Ensure the next loop will actually read\n     them: persist via `knowledge_add` (which `knowledge_recall` surfaces in\n     later phases) rather than a write-only note nobody reads — capturing\n     learnings nothing retrieves does not compound.\n  4. **Feed findings forward.** Record any review\u002Fcritic finding that recurred\n     so it becomes an explicit check in the next cycle's reviewer prompt.\n- **Exit gate:** retrospective written and accepted by `phase_complete`;\n  learnings persisted; the cycle's improvements and residual findings recorded\n  in loop state.\n\n---\n\n## Step 3 — Loop Decision (Stop Conditions)\n\nAfter IMPROVE, evaluate the stop conditions **in order**. Use defense in depth:\nseveral overlapping conditions, not one. Record the chosen `stop_reason` in\nloop state.\n\n1. **Objective met (primary).** The success criteria captured in Phase 1 are\n   all satisfied AND the full validation suite \u002F required QA gates are green.\n   → STOP (success).\n2. **Cycle budget exhausted.** `cycle >= max_cycles`. → STOP. Never exceed\n   `max_cycles`.\n3. **No-progress \u002F plateau.** The just-finished cycle produced no qualifying\n   improvement toward the objective (no new passing criteria, no accepted\n   review fix that advanced the goal). → STOP and report the plateau; looping\n   again would burn budget without progress.\n4. **Oscillation.** The cycle reintroduced or reverted a change made in a prior\n   cycle (the diff fingerprint repeats). → STOP and report; the loop is\n   thrashing.\n5. **Unrecoverable error.** A gate cannot pass for a reason outside this\n   objective's scope (e.g., REJECTED plan, environment failure, a required\n   external dependency is unavailable). → STOP and report.\n6. **Explicit user stop.** The user asked to stop. → STOP immediately.\n\nIf none fire and budget remains: increment `cycle`, set the next cycle's input\nto the recorded improvement directives + residual findings, and return to\n**Phase 2 (PLAN)** (cycle 2+ skips full BRAINSTORM). In `checkpoint` autonomy,\nconfirm \"continue for another cycle?\" with the user before looping.\n\n---\n\n## Step 4 — Completion\n\nWhen a stop condition fires:\n\n1. Mark loop state `done` with the `stop_reason` and final HEAD commit.\n2. Present a human-readable summary:\n   - Objective and whether it was met.\n   - Baseline → final state (what changed, key files\u002Ftasks).\n   - Cycles run (and why it stopped).\n   - Tasks completed vs deferred; residual review findings and where they are\n     recorded.\n   - Learnings captured this run and where they live.\n   - Suggested next steps (e.g., open a PR via `\u002Fswarm pr-review` or the\n     commit-pr flow — do NOT open a PR unless the user asks).\n3. Emit a machine-detectable completion marker on its own line so callers \u002F\n   automation can detect terminal state:\n\n   `\u003Cloop-complete reason=\"objective-met|budget-exhausted|plateau|oscillation|unrecoverable-error|user-stop\" cycles=\"N\"\u002F>`\n\n---\n\n## Durable State Schema (`.swarm\u002Floop\u002F\u003Crun-id>\u002Fstate.json`)\n\nA minimal, append-friendly shape — extend as needed but keep these fields:\n\n```json\n{\n  \"run_id\": \"rate-limit-20260618T0712Z\",\n  \"objective\": \"add rate limiting to the public API\",\n  \"params\": { \"max_cycles\": 3, \"autonomy\": \"checkpoint\", \"depth\": \"standard\" },\n  \"start_commit\": \"\u003Csha>\",\n  \"cycle\": 1,\n  \"phase\": \"review\",\n  \"success_criteria\": [\"...\", \"...\"],\n  \"gates\": [\n    { \"cycle\": 1, \"phase\": \"plan\", \"result\": \"approved\", \"at\": \"\u003Ciso>\" }\n  ],\n  \"improvements\": [],\n  \"learnings\": [],\n  \"done\": false,\n  \"stop_reason\": null,\n  \"final_commit\": null\n}\n```\n\n---\n\n## Autonomy Quick Reference\n\n| Behavior | `checkpoint` (default) | `auto` |\n| --- | --- | --- |\n| Pause at phase gates | Yes — wait for user approval | No |\n| Confirm before next cycle | Yes | No |\n| Mandatory review + critic gates | Enforced | Enforced |\n| Hard stop conditions (budget, plateau, oscillation, errors) | Enforced | Enforced |\n| Weaken\u002Fmock\u002Fskip a failing test | Never | Never |\n\n`auto` reduces prompts; it never reduces verification.\n\n---\n\n## Anti-Patterns (do not do these)\n\n- Letting the coder context approve its own diff. Review and critic must be\n  independent contexts.\n- Treating passing tests, explorer output, or self-review as the implementation\n  closeout gate. They are not.\n- Editing code after reviewer\u002Fcritic approval and then declaring done without\n  re-review. Any post-approval edit invalidates the approval.\n- Looping \"one more time\" past `max_cycles` or after a plateau because it feels\n  close. Stop and report.\n- Skipping the IMPROVE\u002Fcompound capture step to finish faster. The compounding\n  step is the point of the loop.\n- Storing loop progress only in conversation context. Persist to\n  `.swarm\u002Floop\u002F\u003Crun-id>\u002F` so the loop survives interruption.\n- Weakening, mocking, skipping, or deleting a failing assertion to turn a gate\n  green. Fix the root cause or stop.\n",{"name":5,"description":7},"main","7709dc9e5ebd3bd641124ad2a3f6bb053ac2dab6",".opencode\u002Fskills\u002Floop",0,"https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev\u002Fagi","https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev","2026-11-15 04:35:36",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add AlexanderNarbaev\u002Fagi --skill loop",{"tool":36,"command":37},"bunx","bunx skills add AlexanderNarbaev\u002Fagi --skill loop",{"tool":39,"command":40},"pnpm","pnpm dlx skills add AlexanderNarbaev\u002Fagi --skill loop","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev\u002Fagi\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Floop\u002FSKILL.md",true,[],[45,52,59,66,73,80],{"skillNo":46,"name":47,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":18},"01M76RZHYHMGE1WP9JBCMNA801","springboot-patterns","Spring Boot architecture patterns, REST API design, layered services, data access, caching, async processing, and logging. Use for Java Spring Boot backend work.","https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev\u002Fagi\u002Fblob\u002Fmain\u002F.veai\u002Fskills\u002Fspringboot-patterns\u002FSKILL.md",[],[],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":18},"01M76RZE6JNZH5HV7Q8JM7R0PN","search-first","Research-before-coding workflow. Search for existing tools, libraries, and patterns before writing custom code. Invokes the researcher agent.","https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev\u002Fagi\u002Fblob\u002Fmain\u002F.veai\u002Fskills\u002Fsearch-first\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":18},"01M76RZBV42EMQV77H7GMFY4AJ","scholar-evaluation","Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.","https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev\u002Fagi\u002Fblob\u002Fmain\u002F.veai\u002Fskills\u002Fscholar-evaluation\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":18},"01M76RZ97GC3XAY48H126C30PM","redis-patterns","Redis data structure patterns, caching strategies, distributed locks, rate limiting, pub\u002Fsub, and connection management for production applications.","https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev\u002Fagi\u002Fblob\u002Fmain\u002F.veai\u002Fskills\u002Fredis-patterns\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M76RZ528FANTKX7Q9XR0CXM7","react-patterns","React 18\u002F19 patterns including hooks discipline, server\u002Fclient component boundaries, Suspense + error boundaries, form actions, data fetching, state management decision trees, and accessibility-first composition. Use when writing or reviewing React components.","https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev\u002Fagi\u002Fblob\u002Fmain\u002F.veai\u002Fskills\u002Freact-patterns\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":18},"01M76RZ1244PZQRQV5HBQ4PVYQ","query-patterns","SQL patterns, relational database design, query optimization, transactions, analytics, and dialect-aware best practices.","https:\u002F\u002Fgithub.com\u002FAlexanderNarbaev\u002Fagi\u002Fblob\u002Fmain\u002F.veai\u002Fskills\u002Fquery-patterns\u002FSKILL.md",[],[]]