# Plan Execute

> Autonomously executes a staged implementation plan (generated by /plan-stage) stage by stage via run_workflow, spawning a fresh implementer agent per stage foll

- Skill: `tger92/plan-execute` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx get-skill add tger92/plan-execute`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tger92/plan-execute/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: tger92 (https://skillmd.com/u/tger92)
- Updated: 2026-12-03
- Page: https://skillmd.com/skills/tger92/plan-execute

---

---
name: plan-execute
description: >-
  Autonomously executes a staged implementation plan (generated by /plan-stage)
  stage by stage via run_workflow, spawning a fresh implementer agent per stage
  followed by repeated fresh plan-audit agents until an audit pass reports zero
  remaining gaps and makes zero file modifications (default cap: 10 rounds per
  stage). Use when the user invokes /plan-execute or asks to execute and
  audit-until-clean a staged plan in docs/.
---

# Staged Plan Autonomous Executor (`/plan-execute`)

Execute a staged plan from [plan-stage](../plan-stage/SKILL.md) end to end without pausing between stages: each stage is implemented by a fresh subagent, then audited repeatedly by fresh [plan-audit](../plan-audit/SKILL.md) subagents until an audit pass makes **zero fixes** and reports **zero remaining gaps**.

> [!TIP]
> For maximum end-to-end persistence on long plans, you can invoke this skill inside `/goal` (e.g., `/goal /plan-execute docs/MY_PLAN.md`).

---

## 1. Discover, Select & Stage the Plan

Before launching `run_workflow`, resolve the target plan through this interactive discovery flow (plus extract any optional arguments from the user's request):

### 1A. Fast-Path (Explicit File Path Provided)
If the user explicitly named a plan file path (e.g., `/plan-execute docs/STAGED_PLAN_PHASE_8.md`):
- Skip Steps **1B** and **1C**.
- Inspect the file with [discover_plans.py](./scripts/discover_plans.py):
  ```bash
  python "<skill-dir>/scripts/discover_plans.py" --inspect "<path>" --cwd "<workspace>"
  ```
- If `exists == false`, tell the user the file was not found and stop. Otherwise proceed straight to **Step 1D**.

### 1B. Source Picker (`ask_question`)
When invoked **without** an explicit plan file path, ask the user where to discover plans using `ask_question`:
- **Question:** `"Where should I discover the implementation plan from?"`
- **Options:**
  1. `(Recommended) docs/ folder in current workspace (auto-falls back to Antigravity brain if no docs/ folder exists)`
  2. `Antigravity brain folder (last 3 created plans for this project)`
  3. `Custom folder path`
- If the user picks `Custom folder path` (or supplies a folder via "Other") without providing the path yet, ask them for the folder path in plain text before continuing.

### 1C. Discover Plans & Show Plan Picker (`ask_question`)
Run [discover_plans.py](./scripts/discover_plans.py) with the chosen source (resolving `<skill-dir>` to this `plan-execute` skill directory):
- `docs`:
  ```bash
  python "<skill-dir>/scripts/discover_plans.py" --source docs --cwd "<workspace>"
  ```
- `brain`:
  ```bash
  python "<skill-dir>/scripts/discover_plans.py" --source brain --cwd "<workspace>"
  ```
- `custom`:
  ```bash
  python "<skill-dir>/scripts/discover_plans.py" --source custom --folder "<folder_path>" --cwd "<workspace>"
  ```

Then inspect the returned JSON:
- If `fallback_used == "brain"`, briefly inform the user that `<workspace>/docs/` was missing or empty, so discovery automatically fell back to the Antigravity brain folder.
- If `plans` is empty (or `error` is returned), inform the user cleanly and offer to choose another source or create/stage a plan first.
- Otherwise, call `ask_question` so the user can pick the plan to execute:
  - List plans **newest-created first** (already sorted by `created_timestamp` descending), prefixing the first option with `(Recommended)`.
  - Format each option clearly with creation date and staged badge:
    `<filename> — created <created_at> [Staged]` or `<filename> — created <created_at> [Unstaged]`
    (append ` [All Projects]` when `scope_tag == "All Projects"`).

### 1D. Staged Check & Optional Auto-Staging
Inspect the chosen plan's `is_staged` flag (`true` if the file starts with `[STAGED PLAN]` on line 1 or contains `## Stage Tracker`):
- **If `is_staged == true`:** skip staging and **immediately** proceed to **Section 2** (`run_workflow`).
- **If `is_staged == false`:** call `ask_question`:
  - **Question:** `"<filename> (created <created_at>) is not staged yet. Would you like to stage it with /plan-stage before executing?"`
  - **Options:**
    1. `(Recommended) Yes — stage it with /plan-stage (saves to docs/STAGED_PLAN_<NAME>.md) and start executing immediately`
    2. `No — cancel without executing`
  - If **Yes:** read and execute [plan-stage](../plan-stage/SKILL.md) using the selected plan file as the source plan (saving `docs/STAGED_PLAN_<NAME>.md` with `[STAGED PLAN]` on line 1). Once saved, **immediately** launch **Section 2** (`run_workflow`) on that newly saved staged plan with no extra confirmation prompt.
  - If **No:** stop cleanly without executing and tell the user execution was cancelled so they can edit the plan or run `/plan-stage` manually later.

### 1E. Optional Execution Arguments
Extract any optional arguments from the user's request (keep defaults when omitted):
- `plan_path` (`string`): resolved path to the staged plan markdown file.
- `start_stage` (`int | null`, default `null`): first stage number to consider (earlier stages are skipped).
- `end_stage` (`int | null`, default `null`): last stage number to consider (later stages are skipped).
- `max_audit_rounds` (`int`, default `10`): maximum fresh `plan-audit` subagent passes per stage before halting.
- `auto_commit` (`bool`, default `false`): whether to create a local git commit (`feat(stage-<k>): <title> [verified]`) after a stage passes its clean audit.

---

## 2. Launch the Orchestrator via `run_workflow`

1. **Register the dedicated worker subagent (`define_subagent`):**
   Before calling `run_workflow`, register `plan_execute_worker` once per conversation so child workflow agents run on `model="inherit"` (your active model) without inheriting two-phase Plan/Execute (`Orchestrator`) `[plan review due]` pre-tool hooks that deadlock `type_name="self"` + `model="inherit"`:
   - `Name`: `"plan_execute_worker"`
   - `Description`: `"Autonomous stage implementer and plan-audit worker for /plan-execute workflows."`
   - `SystemPrompt`: `"You are an autonomous software engineering worker executing a single stage or plan-audit pass inside a /plan-execute workflow. Follow all scope, verification, and zero-diff rules in the prompt, and return your structured result via the finish tool."`
   - `EnableWriteTools`: `true`
   - `EnableMCPTools`: `true`
   - `EnableSubagentTools`: `false`

2. **Call `run_workflow`** with the bundled Python orchestrator script:
   - **`ScriptPath`**: `<skill-dir>/scripts/run_staged_plan.py` (resolve to the `scripts/run_staged_plan.py` file inside this installed `plan-execute` skill directory).
   - **`Description`**: `"Execute staged plan <filename> (implement + audit-until-clean per stage)"`
   - **`Args`**:
     ```json
     {
       "plan_path": "<resolved-plan-path>",
       "start_stage": null,
       "end_stage": null,
       "max_audit_rounds": 10,
       "auto_commit": false,
       "agent_type": "plan_execute_worker",
       "model": "inherit"
     }
     ```
   - Leave `WaitMsBeforeAsync` unset / `0` so the workflow runs in the background and notifies you automatically when it finishes (do **not** poll).

> [!IMPORTANT]
> **Permissions Requirement:** Child agents inside `run_workflow` cannot prompt the user interactively for terminal command approval; any command requiring approval is automatically denied. Ensure the workspace Tool Execution Policy allows the project's build, lint, type-check, and test commands to run without prompting (e.g., `always-proceed` or `proceed-in-sandbox` with required commands allowed).

---

## 3. Execution Guarantees

The workflow script [run_staged_plan.py](./scripts/run_staged_plan.py) enforces these invariants automatically:

- **Deterministic plan parsing first:** Parses standard `plan-stage` documents (`## Stage Tracker` + `## Stage ... Prompts`) directly in Python (0 LLM tokens), falling back to a parser agent only for non-standard layouts.
- **Deadlock-safe worker & model tier:** Runs implementer and auditor agents via `agent_type="plan_execute_worker"` + `model="inherit"` (your active conversation model). If invoked directly with `self+inherit` under two-phase Plan/Execute mode and hit by the finish deadlock, it automatically retries once with `model="pro"` and surfaces child `transcript.jsonl` paths on any finish failure.
- **Resumability:** Reads `## Stage Tracker` and automatically skips stages already marked `[x] Done`.
- **Exclusive Stage Tracker ownership:** Neither implementer nor auditor agents may edit `## Stage Tracker`; only the orchestrator transitions a stage from `[~] In Progress` to `[x] Done`.
- **Goal-style stage execution:** Strips the leading `/goal ` prefix from each stage's prompt and runs it with strict completion rules and cumulative `Stages 1..k` vs. future `Stages k+1..N` boundary guards.
- **Strict dual verification per audit pass:** Every audit round captures a git working-tree snapshot (status, staged/unstaged diffs, and SHA-256 content hashes of non-cache untracked files) before and after a fresh `plan-audit` agent runs. A stage advances **only** when:
  1. `passed == true`,
  2. `verification_passed == true`,
  3. `fixes_made == 0`,
  4. `remaining_gaps == []`, **and**
  5. `files_modified_during_audit == []` (falls back to checks 1–4 in non-git directories).
- **Safe failure & cap policy:** If `max_audit_rounds` (default `10`) is reached without a clean pass, or an implementer reports hard external blockers, the workflow halts immediately, leaves the stage marked `[~] In Progress` for clean resume, and outputs the remaining gaps/diffs/blockers.

---

## 4. Final Reporting

Once `run_workflow` completes:

1. Provide a clickable `file://` link to the staged plan (`docs/<PLAN>.md`).
2. Present a concise summary table with one row per stage:
   - `Stage` | `Title` | `Status` | `Audit Rounds` | `Verification Gate`
3. **If halted early:** clearly display the halted stage number, whether it stopped on an implementer blocker or hit `max_audit_rounds`, the exact remaining gaps / touched files / blockers returned by the workflow, and the exact resume instruction (fixing the blocker and re-running `/plan-execute <plan_path>`).

