AI Playbook中文

Coding agents

An approval gate for background agent tasks: A plans, B critiques, a human approves before anything is built

Verification

Tested on
2026-11-12
What was tested
Scope not stated
Evidence level
Dated run records or re-runnable tests
Status
Published
Version
0.1.0
Updated
2026-12-05
Source commit
e16314b8c3
Tools
a small local task runner (any script/CLI that stores per-task state files), two coding agents, e.g. Codex CLI + Grok CLI, or Kimi Code + GLM Coding Plan, git worktree, a completion webhook / notification
Models
Not filled in
Audience
developers
Availability in mainland China
Partly available
Alternatives for mainland China
a manual version of the same files in the repo, Claude Code plan mode + a second reviewer, GitHub Spec Kit (specify -> plan -> tasks)

Framing: a solo developer's workflow (2026-11). The task runner is a solo developer's personal local tool; this recipe covers the general pattern and does not require the same tool. Codex / Grok are examples; check each provider's terms for your region (this recipe doesn't judge that). If you use Claude: not supported in mainland China, Hong Kong or Macau since 2026-11-12 (checked 2026-11-23).

Situation

Steps

  1. One directory per task, state as files: task description, plan A, plan B (critique of A), agreed_plan, approval flag, implementation notes, review, stage logs, state JSON. The directory is the handoff record.
  2. Two models in the plan phase: A drafts, B critiques read-only, the two are merged into agreed_plan.
  3. Stop at awaiting_approval by default. No auto-approve unless the owner explicitly allows it for that class of task. Approval is a flag file created by a human, never by an agent; it records the task ID and the hash of agreed_plan.md and is verified before implementation — any plan edit invalidates it.
  4. Implement only after approval, in an isolated worktree/task branch; independent review; mark completed — no merge, no push.
  5. Notify on done/failed with a local webhook instead of polling (hooks-not-polling-notifications); the message holds only task ID, status and a one-line summary.
  6. Collab mode (A plans + B critiques + human approves) for complex tasks, single-model mode for mechanical ones; neither bypasses "no merge".

Templates

State machine and task-directory layout: see the Chinese section (code block is English). Map stages to pipeline.yaml: gates "approval flag created by a human and its hash matches the current agreed plan"; reliability.timeout_seconds/max_agent_turns per stage and "review verdict APPROVE"; budget per stage. Calibrate the reviewer with the eval / golden-set checklist.

Cost (order of magnitude, estimate)

Failure cases and guards

China alternatives

Safety notes

Test notes

Verification

来源 / Sources

  • Anthropic, Building effective agents: https://www.anthropic.com/engineering/building-effective-agents
  • LangGraph interrupts (human approval as a hard stop): https://docs.langchain.com/oss/python/langgraph/interrupts
  • 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: agent-task-approval-gate/SKILL.md

Preview
---
name: agent-task-approval-gate
description: "An approval gate for background agent tasks: A plans, B critiques, a human approves before anything is built. Use when the user asks for help with this task."
metadata:
  version: "0.1.0"
  status: "published"
  source-commit: "5f7272be13826bec473d6f2e073c82a5a620f1d2"
---

# An approval gate for background agent tasks: A plans, B critiques, a human approves before anything is built

- Version: 0.1.0
- Status: published
- Tested on: 2026-11-12
- 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).** The task runner is a solo developer's personal local tool; this recipe covers the general pattern and does not require the same tool. Codex / Grok are examples; check each provider's terms for your region (this recipe doesn't judge that). If you use Claude: not supported in mainland China, Hong Kong or Macau since 2026-11-12 (checked 2026-11-23).

### Situation
- **Audience:** you want to hand tasks to background agents without watching, but want them to stop for your approval of the plan **before any code is written**.
- **Difference from `dual-agent-write-review-loop`:** that loop runs in front of you in one worktree; this is a **background, unattended-capable** task: state on disk, default stop at "awaiting approval", completion by notification.
- **When not to use:** few-line changes, or exploratory work needing conversation.

### Steps
1. **One directory per task**, state as files: task description, plan A, plan B (critique of A), `agreed_plan`, approval flag, implementation notes, review, stage logs, state JSON. The directory is the handoff record.
2. **Two models in the plan phase:** A drafts, B critiques read-only, the two are merged into `agreed_plan`.
3. **Stop at `awaiting_approval` by default.** No auto-approve unless the owner explicitly allows it for that class of task. Approval is a flag file created by a human, never by an agent; **it records the task ID and the hash of `agreed_plan.md` and is verified before implementation — any plan edit invalidates it.**
4. **Implement only after approval,** in an isolated worktree/task branch; independent review; mark completed — **no merge, no push**.
5. **Notify on done/failed** with a local webhook instead of polling (`hooks-not-polling-notifications`); the message holds only task ID, status and a one-line summary.
6. **Collab mode (A plans + B critiques + human approves) for complex tasks, single-model mode for mechanical ones;** neither bypasses "no merge".

### Templates
State machine and task-directory layout: see the Chinese section (code block is English). Map stages to pipeline.yaml: gates "approval flag created by a human and its hash matches the current agreed plan"; `reliability.timeout_seconds`/`max_agent_turns` per stage and "review verdict APPROVE"; budget per stage. Calibrate the reviewer with the eval / golden-set checklist.

### Cost (order of magnitude, estimate)
- Collab turns one task into "two plan calls + implementation + one review", about 2–3 more calls than a single model; it buys you a chance to stop wrong directions before code exists. Use it where rework is expensive. Estimate per stage in the ROI input table.

### Failure cases and guards
- **Auto-approve by default (guard):** it empties the gate; the flag must be human-made.
- **Approval flag not bound to a plan version (guard):** an edited plan would inherit the old approval; hence the hash check.
- **No notification, so you babysit (guard).**
- **Serious findings in review (occurred, recorded):** on a camera-app task, the independent review returned a graded (blocker/major/minor) list of concurrency and lifecycle issues, with major items needing another pass — the point of separating writer and reviewer (the review record stays in the task directory and is not published here).
- **Background task quietly pushing/merging (guard):** the task spec forbids it and the state machine has no such step.
- **Secrets leaking into logs or notifications (guard):** notifications carry ID and summary only; check logs before pasting.

### China alternatives
- `china_availability: partial`. The method is generic: A and B can be Kimi Code / GLM Coding Plan / Qwen Code / DeepSeek; notify via Feishu/DingTalk/WeCom bots.
- Check regional availability of Codex, Grok and Claude yourself; no circumvention advice.

### Safety notes
- Only a human can create the approval flag; the agents' environment should lack permission to do so.
- Never give sudo passwords or tokens to background agents; keep webhook addresses and tokens in config, not in task dirs, logs or repos.
- Background tasks run in an isolated worktree and never touch main.

### Test notes
- 2026-11-02 to 2026-11-12: the tool ran 9 collab tasks, all completed; directories retain plans A/B, `agreed_plan`, approval flag, implementation notes, review and logs. The earliest (2026-11-02) has a graded review.
- **The layout above is a summary of the task directories, not re-run verbatim.** The personal tool has no version number; Codex CLI on the same machine was 0.171.0 (2026-11-23).

### Verification
- Submit a task: it must stop at `awaiting_approval`; without the flag, nothing is implemented.
- After creating the flag, implementation starts, a notification arrives at the end, and the main branch is untouched.

## 来源 / Sources

- Anthropic, Building effective agents: https://www.anthropic.com/engineering/building-effective-agents
- LangGraph interrupts (human approval as a hard stop): https://docs.langchain.com/oss/python/langgraph/interrupts
- 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**

```text
tasks/<id>/
  task.md            # 任务描述、范围、禁止事项、验收
  plan_a.md          # 模型 A 的方案
  plan_b.md          # 模型 B 对方案的评审
  agreed_plan.md     # 合并后的计划(等批准)
  approval.flag      # 由人创建,内容: <task id> <sha256 of agreed_plan.md>;Agent 不得创建;方案变更即作废
  implementation.md  # 实现说明与测试证据
  review.md          # 独立评审:BLOCKER / MAJOR / MINOR
  state.json         # mode, status, created_at, updated_at
```