AI Playbook中文

Coding agents

Dual-agent write/review loop (read-only reviewer, max 3 rounds per phase, human-approved merges)

Verification

Tested on
2026-11-23
What was tested
Scope not stated
Evidence level
Dated run records or re-runnable tests
Status
Published
Version
0.2.0
Updated
2026-11-29
Source commit
a8fb8db149
Tools
git worktree, GitHub PRs, any two different coding agents, e.g. Kimi Code, GLM Coding Plan, Qwen Code, Claude Code, Codex CLI
Models
any two different model families (example setup: Claude writes, OpenAI Codex reviews read-only)
Audience
developers
Availability in mainland China
Partly available
Alternatives for mainland China
Kimi Code + GLM Coding Plan (one writes, one reviews), a cloud model + a local reviewer model, GitHub Spec Kit for the plan phase, Claude Code subagent as reviewer

Framing: a solo developer's workflow (2026-11). Claude and Codex are one example pair; the method is vendor-neutral (Kimi, GLM, Qwen, DeepSeek, … work too). Claude: Anthropic has not supported mainland China, Hong Kong or Macau since 2026-11-12, including use while physically there (checked 2026-11-23; Supported Regions).

Situation

This is steps 4–5 of the seven-step method: "plan → review → human approval → implement → review → human merge" expressed as spec + quality gates + human gates. It is the evaluator-optimizer pattern from Anthropic's "Building effective agents" with a max-round stop condition.

Steps

  1. Isolate: one worktree and feat/<slug> branch per feature; agents never edit main.
  2. Plan: the implementer writes PLAN.md and TASKS.md, self-reviews, updates STATE.md, writes HANDOFF_REQUEST.md. Keep process files in .agents/work/<slug>/, gitignored as a whole directory. Caveat: per Codex's docs its writable sandbox treats .agents as a protected, read-only path (read 2026-11-23, not re-tested here). If Codex is the implementer, use a directory outside .agents (e.g. .work/<slug>/, also gitignored) and change the paths in AGENTS.md; other implementers are unaffected.
  3. Read-only review: run the reviewer read-only in the same worktree (Codex CLI shown; other tools have read-only/plan modes), e.g. codex exec --sandbox read-only "<review prompt>" or codex review --uncommitted. Verdict is APPROVE or CHANGES, issues tagged blocker/major/minor; only blocker/major start another round. A read-only reviewer writes no files: the writable side saves its stdout as HANDOFF_VERDICT.md.
  4. Human gate 1: after the reviewer approves the plan, you approve and write plan_approved_by: <name> in STATE.md. Humans only.
  5. Code phase: checkpoint, implement, self-review, then the implementer (or a helper) actually runs tests/build/lint and records who, full command, cwd, revision, time, exit code and log path in the handoff file. Pass = tests green + lint/build green + APPROVE.
  6. 3-round cap: still blocker/major after 3 rounds → stop, write ESCALATION.md, and notify by message; a file alone is not a notification.
  7. Human gate 2: push, merge, release, store submission happen only after you read the diff, or with your explicit authorization.

Fast path: ≤ ~20 lines with no design/API/protocol/security/dependency impact may skip plan review (mode: fast-path + reason in STATE.md); stop and switch to the full loop on any design impact.

Templates

AGENTS.md snippet, STATE.md and reviewer prompt: see the code blocks in the Chinese section (they are already in English).

Cost and time (order of magnitude, estimate, not reconciled against bills)

Failure cases and guards

From a solo developer's use and the PR #14 draft; per-item primary records are still to be added. The scaffold docs carry matching rules for "read-only sandbox can't run tests", "tee swallowing exit codes" and "process files committed"; the rest are common risks the flow already guards against, not itemized incident records.

China alternatives

Safety notes

Test notes

Verification

来源 / Sources

  • Anthropic, Building effective agents: https://www.anthropic.com/engineering/building-effective-agents
  • Codex sandbox & approvals: https://learn.chatgpt.com/docs/agent-approvals-security
  • Codex non-interactive mode: https://learn.chatgpt.com/docs/non-interactive-mode
  • Codex CLI reference: https://learn.chatgpt.com/docs/cli/reference.md
  • AGENTS.md format: https://agents.md/
  • git worktree: https://git-scm.com/docs/git-worktree
  • Anthropic Supported Regions Policy (checked 2026-11-23): https://www.anthropic.com/legal/supported-regions

Source links

Export to your agent

Path: dual-agent-write-review-loop/SKILL.md

Preview
---
name: dual-agent-write-review-loop
description: "Dual-agent write/review loop (read-only reviewer, max 3 rounds per phase, human-approved merges). Use when the user asks for help with this task."
metadata:
  version: "0.2.0"
  status: "published"
  source-commit: "5f7272be13826bec473d6f2e073c82a5a620f1d2"
---

# Dual-agent write/review loop (read-only reviewer, max 3 rounds per phase, human-approved merges)

- Version: 0.2.0
- Status: published
- Tested on: 2026-11-23
- Evidence level: field-use-logged
- Source commit: 5f7272be13826bec473d6f2e073c82a5a620f1d2

> Reference playbook: follow it only when the user asks for this task, and ask a human before running commands or irreversible actions.

## English

> **Framing: a solo developer's workflow (2026-11).** Claude and Codex are one example pair; the method is vendor-neutral (Kimi, GLM, Qwen, DeepSeek, … work too).
> Claude: Anthropic has not supported mainland China, Hong Kong or Macau since 2026-11-12, including use while physically there (checked 2026-11-23; [Supported Regions](https://www.anthropic.com/legal/supported-regions)).

### Situation
- **Audience:** solo developers and small teams who use AI to write code but won't take "done" from the same agent that wrote it, and want merge/release to stay a human decision.
- **When to use:** changes beyond a file or two, with design trade-offs, or headed for a release branch.
- **When not to use:** ~20-line changes with no design/API/protocol/security/dependency impact (use the fast path).

This is steps 4–5 of the seven-step method: "plan → review → human approval → implement → review → human merge" expressed as spec + quality gates + human gates. It is the evaluator-optimizer pattern from Anthropic's "Building effective agents" with a max-round stop condition.

### Steps
1. **Isolate:** one worktree and `feat/<slug>` branch per feature; agents never edit `main`.
2. **Plan:** the implementer writes `PLAN.md` and `TASKS.md`, self-reviews, updates `STATE.md`, writes `HANDOFF_REQUEST.md`. Keep process files in `.agents/work/<slug>/`, gitignored as a whole directory. **Caveat:** per Codex's docs its writable sandbox treats `.agents` as a protected, read-only path (read 2026-11-23, not re-tested here). If **Codex is the implementer**, use a directory outside `.agents` (e.g. `.work/<slug>/`, also gitignored) and change the paths in AGENTS.md; other implementers are unaffected.
3. **Read-only review:** run the reviewer read-only in the same worktree (Codex CLI shown; other tools have read-only/plan modes), e.g. `codex exec --sandbox read-only "<review prompt>"` or `codex review --uncommitted`. Verdict is `APPROVE` or `CHANGES`, issues tagged blocker/major/minor; **only blocker/major start another round**. A read-only reviewer **writes no files**: the writable side saves its stdout as `HANDOFF_VERDICT.md`.
4. **Human gate 1:** after the reviewer approves the plan, *you* approve and write `plan_approved_by: <name>` in `STATE.md`. Humans only.
5. **Code phase:** checkpoint, implement, self-review, then **the implementer (or a helper) actually runs tests/build/lint** and records who, full command, cwd, revision, time, exit code and log path in the handoff file. Pass = tests green + lint/build green + `APPROVE`.
6. **3-round cap:** still blocker/major after 3 rounds → stop, write `ESCALATION.md`, and **notify by message**; a file alone is not a notification.
7. **Human gate 2:** push, merge, release, store submission happen only after you read the diff, or with your explicit authorization.

**Fast path:** ≤ ~20 lines with no design/API/protocol/security/dependency impact may skip plan review (`mode: fast-path` + reason in `STATE.md`); stop and switch to the full loop on any design impact.

### Templates
- Express the loop as pipeline.yaml: `plan` (model) → `plan_review` (model, read-only) → `plan_approval` (human) → `implement` (model) → `checks` (code: tests/lint, keep exit codes) → `code_review` (model, read-only) → `merge_approval` (human). Gates: "test exit code is 0", "verdict is APPROVE", "`plan_approved_by` committed by a human"; `reliability.timeout_seconds` / `reliability.max_agent_turns` bound each stage; "max 3 review rounds per phase" is a process rule tracked as `round: n/3` in `STATE.md` and AGENTS.md — the template has no dedicated field.
- Test the reviewer prompt itself with the eval / golden-set checklist: feed 3–5 old diffs with known defects and see whether it catches them. The reviewer is a pipeline step too.
- Scaffolding for these files: see `review-kit-bootstrap`.

AGENTS.md snippet, STATE.md and reviewer prompt: see the code blocks in the Chinese section (they are already in English).

### Cost and time (order of magnitude, estimate, not reconciled against bills)
- A review call mostly reads the diff and logs, so it **usually emits an order of magnitude fewer tokens than the implementation step**, but every extra round re-reads everything. The 3-round cap is your cost ceiling.
- No dollar figures here: fill the ROI input table from your own usage logs, and count your own diff-reading time as human review cost.

### Failure cases and guards
From a solo developer's use and the PR #14 draft; per-item primary records are still to be added. The scaffold docs carry matching rules for "read-only sandbox can't run tests", "`tee` swallowing exit codes" and "process files committed"; the rest are common risks the flow already guards against, not itemized incident records.
- **Read-only sandbox can't run tests that write to disk:** the implementer runs them and attaches command + exit code + log. Only missing or suspicious evidence (stale, truncated, not matching this revision) is `BLOCKED`; an unwritable build directory alone is not.
- **`tee` swallowing the exit code:** the log says PASS but the command failed. Record exit codes, not just output.
- **Asking the read-only reviewer to write the verdict file:** it can't; the caller saves stdout.
- **An executing agent recording "approved" for the human:** forbid it in AGENTS.md; since `STATE.md` is untracked, treat the approval note in your PR comment or commit message as the record and check that it matches the `PLAN.md` hash.
- **A reviewer that "helpfully" fixes things** stops being a reviewer; enforce read-only technically.
- **Endless ping-pong** over minor issues without a round cap.
- **Same model reviewing itself** shares blind spots; change session at least, model family ideally.
- **Process files committed:** gitignore the directory; `git ls-files -- .agents/work` should be empty before merge.

### China alternatives
- `china_availability: partial`. The method only needs two *different* models: Kimi Code + GLM Coding Plan, Qwen Code + DeepSeek, or a cloud writer + a local reviewer (see `local-ai` recipes).
- Claude: see the region note above. Codex: as of 2026-11-23 mainland China is not on OpenAI's supported-countries list (carried over from the PR #14 draft; re-check before relying on it).
- Reaching a service through a proxy from an unsupported region does not make use compliant; this recipe does not teach circumvention.

### Safety notes
- Run the reviewer in a read-only sandbox with no secrets and no write-capable network.
- Executors must not push, merge or publish; never commit `.env`; scan logs for tokens before pasting them into handoff files.
- Unattended runs should use notifications (`hooks-not-polling-notifications`) plus human gates, not looser approvals.

### Test notes
- 2026-11-23: the companion scaffold `orca-kit-init` passes its 5 automated tests (Python unittest, isolated temp dirs); the loop is used day to day in a solo developer's iOS/Flutter repos, one of which has an adoption branch. **The AGENTS.md and prompt templates here are cleaned-up rewrites that were not re-run verbatim.**
- Tool versions: Codex CLI 0.171.0, Claude Code 2.1.330 (local, 2026-11-23).
- Evidence trail: FIRST_HAND_SEEDS.md.

### Verification
- Pick any merged feature: can you reconstruct who approved what and when from PLAN → VERDICT → STATE?
- Does every merge to main have a human approval record?

## 来源 / Sources

- Anthropic, Building effective agents: https://www.anthropic.com/engineering/building-effective-agents
- Codex sandbox & approvals: https://learn.chatgpt.com/docs/agent-approvals-security
- Codex non-interactive mode: https://learn.chatgpt.com/docs/non-interactive-mode
- Codex CLI reference: https://learn.chatgpt.com/docs/cli/reference.md
- AGENTS.md format: https://agents.md/
- git worktree: https://git-scm.com/docs/git-worktree
- Anthropic Supported Regions Policy (checked 2026-11-23): https://www.anthropic.com/legal/supported-regions

## Code and templates from the Chinese section (may contain Chinese comments or text)

**Block 1 — AGENTS.md**

```markdown
## Dual-agent review workflow
- Work only in a `feat/<slug>` worktree. Never commit to main/master.
- Phases: PLAN -> (review) -> human approval -> CODE -> (review) -> human merge.
- Process files live in .agents/work/<slug>/ (gitignored).
- Reviewer runs read-only and does not write files. Verdict (saved by the caller as HANDOFF_VERDICT.md) is exactly
  `APPROVE` or `CHANGES` plus issues tagged [blocker]/[major]/[minor]. Only blocker/major start a new round.
- Max 3 rounds per phase. Then stop, write ESCALATION.md and notify by message.
- The implementer (or helper) runs tests/build/lint and records: who, command, cwd, revision, time, exit code, log path.
- `plan_approved_by:` in STATE.md is written by a human only. Agents must never write or edit it.
- Never push, merge, publish, or submit to an app store without explicit human approval for that action.
- Never commit .env files or secrets.
- Fast path (<= ~20 lines, no design/API/security/dependency impact): `mode: fast-path` + reason in STATE.md.
```

**Block 2 — STATE.md**

```markdown
feature: feat/<slug>
phase: plan | code | done | escalated
round: 1/3
mode: full | fast-path (reason: ...)
plan_approved_by:            # human only
last_verdict: APPROVE | CHANGES
tests: <command> -> exit <code> (log: <path>)
next: <who does what>
```

**Block 3**

```text
You are a read-only reviewer. Do not modify files.
Read PLAN.md, TASKS.md, HANDOFF_REQUEST.md and the diff against origin/main.
Output to stdout, in this format only:
VERDICT: APPROVE | CHANGES
ISSUES:
- [blocker|major|minor] <file:line> <problem> -> <suggested fix>
TEST EVIDENCE: <do the implementer's logs show tests/build passing for THIS revision? yes/no + why>
Only blocker/major justify CHANGES. Do not raise style nits.
```