Skip to main content
Guide

Phase 2 - Plan

Build a minimal wave plan with ordered waves, routing, handoffs, and risk gates.

Purpose

Create a decision-complete wave plan for MEDIUM/HIGH complexity work. TRIVIAL/LOW uses fast path or in-memory plan only.


Planning Depth by Complexity

ComplexityPlanning ApproachArtifacts
TRIVIALNone (fast path)Correlation ID only
LOWIn-memory wave planCorrelation ID only
MEDIUMgem-planner delegationPersistent plan.yaml
HIGHgem-planner delegationPersistent plan.yaml + required review
COMPLEXITY DETERMINES PLANNINGTRIVIAL/LOW = lightweight. MEDIUM/HIGH = full persistent plan with review gates.

Planner Responsibilities

The Planner (gem-planner) receives bounded planning_context and produces:

  1. Ordered waves with explicit task ownership
  2. Scoped handoffs per task (constraints, context, evidence)
  3. Risk signals per task for review routing
  4. Task coalescing where context overlaps
  5. Mechanical self-check before emitting plan

Planning Context (Bounded Input)

planning_context:
  task_clarifications:
    - "Use existing pagination helper from src/utils/pagination.ts"
    - "Follow OpenAPI conventions in api/conventions.md"
  relevant_context:
    - "user-model: file=src/models/user.ts, fields=id,name,email,createdAt"
    - "api-conventions: file=src/api/conventions.md"
  baseline: {} # For replans: immutable baseline
  current_plan: {} # For replans: exact current plan
  review_findings: [] # For replans: reviewer findings
BOUNDED CONTEXTThe Planner never gets full repo context - only objective-aligned clarifications and sufficient discovery.

Task Coalescing (Context Optimization)

Tasks that share a context base merge into one:

Merge CriteriaAll Required
Same primary agent✅
Overlapping files OR one shared research base✅
No ordering dependency✅

Result: One task carrying all acceptance criteria of merged tasks. Benefit: Saves invocation + duplicate context copy. No wall-clock cost (ownership overlap already prevented parallel execution).

Cluster shared_context: Findings consumed by ≥2 tasks inlined once per cluster, frozen for all consumers.

CLUSTER OPTIMIZATIONTasks with shared context run contiguously. The shared_context block is inlined once and frozen for all consumers.

Wave Structure

waves:
  - wave: 1
    tasks:
      - task_id: "research-api-patterns"
        agent: "gem-researcher"
        objective: "Explore API conventions and user schema"
        acceptance_criteria:
          - "Document REST patterns in src/api/"
          - "Identify pagination helper location"
        handoff:
          constraints: [...]
          relevant_context: [...]

  - wave: 2
    tasks:
      - task_id: "implement-search-endpoint"
        agent: "gem-implementer"
        objective: "Implement GET /api/users/search"
        acceptance_criteria:
          - "Filter by name/email (case-insensitive)"
          - "Pagination with page/limit"
          - "Sorting by createdAt/name/email"
          - "OpenAPI documentation"
        handoff:
          constraints: [...]
          relevant_context:
            - "research-api-patterns: patterns=REST, pagination=src/utils/pagination.ts"
          shared_context: "..." # Inlined from Wave 1 producer

Mechanical Self-Check (Before Plan Emission)

The Planner runs a mechanical self-check on every MEDIUM/HIGH plan:

CheckFailure Action
All tasks have assignable ownersFix + re-run once
Waves are positive integersFix + re-run once
Per-task acceptance criteria existFix + re-run once
Dependencies resolvable (no cycles)Fix + re-run once
Cluster consistency (shared_context valid)Fix + re-run once

Persistent failure → needs_revision returned to Orchestrator. Routine MEDIUM passes on self-check alone. HIGH / risky / explicit request / critic signals → Still routes to Reviewer.


Review Gate (Pre-Execution)

ConditionReview Required?Mode
HIGH complexityYeshigh or critic
High-risk signals (architecture, breaking_change, cross_domain_impact)Yescritic
Explicit review requestYesstandard/high
Critic signals from Phase 0Yescritic
Insufficient/contradictory evidenceYesstandard
Routine MEDIUMNo (self-check only)-

Reviewer receives dedicated handoff with target_reference, criteria, risk_ref, evidence.


Plan Persistence

For MEDIUM/HIGH, plan saved to:

docs/plan/{plan_id}/
├── plan.yaml          # Authoritative task source
├── status.yaml        # Execution state
├── wave-1/            # Task artifacts
│   ├── research-api-patterns/
│   │   ├── findings.md
│   │   └── handoff.yaml
│   └── ...
└── wave-2/
    └── ...

On resume: Loads plan.yaml verbatim - never reconstructs from conversation.


Replan Guardrails

GuardrailRule
Immutable baselineObjective + criteria never change
Max 2 replansDefault limit (configurable)
Lineage trackedrevision, replan_count in plan
Reason recordedEach replan documents why
Progress measurableMust show forward progress
Empty/repetitiveEscalates instead of looping

Replan types:

  • needs_revision → Revise plan/context (Planner or owning specialist)
  • needs_retry → Retry execution within cap (Orchestrator manages)

Concrete Planning Example: User Search API (MEDIUM)

plan_id: "20261121-user-search-api"
objective: "Add user search endpoint with filtering and pagination"
acceptance_criteria:
  - "GET /api/users/search?q=... returns filtered results"
  - "Pagination with page/limit params"
  - "Sorting by createdAt/name/email"
  - "OpenAPI documentation"
complexity: "MEDIUM"
risk_signals: ["api_change", "contract_change"]
waves:
  - wave: 1
    tasks:
      - task_id: "research-api-patterns"
        agent: "gem-researcher"
        exploration_mode: "scan"
        acceptance_criteria:
          - "Document REST patterns in src/api/"
          - "Identify pagination helper location"
        handoff:
          constraints: ["Follow existing API conventions"]
          relevant_context:
            - "user-model: file=src/models/user.ts"

  - wave: 2
    tasks:
      - task_id: "implement-search"
        agent: "gem-implementer"
        acceptance_criteria:
          - "Filter by name/email (case-insensitive)"
          - "Pagination with page/limit"
          - "Sorting by createdAt/name/email"
          - "OpenAPI documentation"
        handoff:
          constraints: ["Use Prisma", "Follow API conventions"]
          relevant_context:
            - "research-api-patterns: patterns=REST, pagination=src/utils/pagination.ts"
      - task_id: "write-search-tests"
        agent: "gem-implementer"
        # Coalesced with implement-search: same agent, overlapping files, no dependency

  - wave: 3
    tasks:
      - task_id: "integration-review"
        agent: "gem-reviewer"
        review_mode: "standard"
        review_target: "integration"
        review_scope: "changed"
review_required: true
review_mode: "standard"
review_target: "integration"
review_scope: "changed"

Plan Anatomy (Field Reference)

FieldTypeRequiredDescription
plan_idstringYesFormat: YYYYMMDD-slug, e.g. 20261121-user-search-api
objectivestringYesWhat the plan achieves
acceptance_criteriastringYesTestable criteria for completion
complexityenumYesTRIVIAL|LOW|MEDIUM|HIGH
risk_signalsstringNoSignals that trigger review
wavesobjectYesOrdered wave list with tasks
review_requiredbooleanNoWhether review gate applies
review_modeenumNostandard|high|critic
review_targetenumNoplan|task|code|decision|docs|config|integration
review_scopeenumNochanged|affected|full

Task Coalescing Example (Before/After)

Before (3 separate tasks, 3 invocations, 3 context copies):

TaskAgentFilesOverlap
implement-searchgem-implementersearch.tspagination.ts
write-search-testsgem-implementersearch.test.tspagination.ts
add-search-docsgem-documentation-writersearch.mdsearch.ts

After (coalesced where possible):

TaskAgentFilesReason
implement-search + write-search-testsgem-implementersearch.ts, search.test.tsSame agent, overlapping files, no dependency
add-search-docsgem-documentation-writersearch.mdDifferent agent, kept separate

Benefit: 2 invocations instead of 3, one context copy instead of two.


Mechanical Self-Check (Before Plan Emission)

The Planner runs a mechanical self-check on every MEDIUM/HIGH plan:

CheckFailure Action
All tasks have assignable ownersFix + re-run once
Waves are positive integersFix + re-run once
Per-task acceptance criteria existFix + re-run once
Dependencies resolvable (no cycles)Fix + re-run once
Cluster consistency (shared_context valid)Fix + re-run once

Persistent failure → needs_revision returned to Orchestrator. Routine MEDIUM passes on self-check alone. HIGH / risky / explicit request / critic signals → Still routes to Reviewer.


Replan Guardrails

GuardrailRule
Immutable baselineObjective + criteria never change
Max 2 replansDefault limit (configurable)
Lineage trackedrevision, replan_count in plan
Reason recordedEach replan documents why
Progress measurableMust show forward progress
Empty/repetitiveEscalates instead of looping

Replan types:

  • needs_revision → Revise plan/context (Planner or owning specialist)
  • needs_retry → Retry execution within cap (Orchestrator manages)

Plan Persistence

For MEDIUM/HIGH, plan saved to:

docs/plan/{plan_id}/
├── plan.yaml          # Authoritative task source
├── status.yaml        # Execution state
├── wave-1/            # Task artifacts
│   ├── research-api-patterns/
│   │   ├── findings.md
│   │   └── handoff.yaml
│   └── ...
└── wave-2/
    └── ...

On resume: Loads plan.yaml verbatim - never reconstructs from conversation.


Review Gate (Pre-Execution)

ConditionReview Required?Mode
HIGH complexityYeshigh or critic
High-risk signals (architecture, breaking_change, cross_domain_impact)Yescritic
Explicit review requestYesstandard/high
Critic signals from Phase 0Yescritic
Insufficient/contradictory evidenceYesstandard
Routine MEDIUMNo (self-check only)-

Reviewer receives dedicated handoff with target_reference, criteria, risk_ref, evidence.


Key Rules

  1. Bounded input - Planner gets only what's needed
  2. Coalesce aggressively - Merge overlapping context
  3. Self-check first - Mechanical validation before emission
  4. Review independent - Self-check ≠ Reviewer
  5. Persist for MEDIUM/HIGH - plan.yaml is authoritative
  6. Replan bounded - Max 2, immutable baseline, measurable progress

Next Phase

→ Phase 3: Execute - Wave loop, delegation, verification, persistence