Cfn goap plan

From masharratt/claude-flow-novice · View interactive version

Cfn goap plan is an AI agent skill from the GitHub repository masharratt/claude-flow-novice. Optional GOAP planning bookend around plan mode or cfn-megaplan. Run BEFORE plan mode to model goal state and derive an optimal action sequence. Run DURING implementation when the 3-strike rule fires to replan from current world state.

How to use this skill

Skill file

CFN GOAP Plan

Purpose: Two jobs:

  1. Pre-plan: Model goal state before entering plan mode. Forces backward reasoning from end state → actions, not forward reasoning from task description → steps.
  2. Replan: Mid-implementation recovery when assumptions fail (3-strike trigger). Re-evaluate world state, find new action sequence to goal.

CLI

echo '<json>' | node dist/src/planning/goap/cli.js

Input schema:

{
  "state": { "<key>": "<bool|number|string>" },
  "goal": { "conditions": { "<key>": "<value>" } },
  "actions": [
    {
      "name": "<string>",
      "preconditions": { "<key>": "<value>" },
      "effects": { "<key>": "<value>" },
      "cost": 1
    }
  ],
  "options": { "maxIterations": 10000, "excludedActions": [] }
}

Output: { plan: { actions, totalCost, reachable }, success, error? }


Mode 1: Pre-Plan (run before /write-plan or plan mode)

Step 0: Scope Challenge

Before modeling, verify minimum viable scope:

Step 1: Elicit Goal State

Ask: "What must be true when this is done?" — not "what steps will you take."

Extract world state keys as boolean/string/number facts. Examples:

Distinguish between:

Step 2: Model Initial State

Survey current world state. Keys that are already true belong in state, not goal.conditions.

Check:

Step 3: Define Actions

For each step needed, define:

Cost heuristics:

| Cost | Meaning |

|------|---------|

| 1 | Config change, rename, constant update |

| 2 | New function, type change, test update |

| 5 | New API endpoint, schema migration, multi-file refactor |

| 10 | Cross-project change, data migration, auth/security change |

Step 4: Run GOAP Planner

echo '{
  "state": { ... },
  "goal": { "conditions": { ... } },
  "actions": [ ... ]
}' | node dist/src/planning/goap/cli.js

If reachable: false: missing actions. Find what preconditions are unmet and add bridging actions.

If plan has redundant actions (cost higher than expected): check for circular preconditions or actions that block each other.

Step 5: Output Structured Plan

Present to user:

## GOAP Plan

### Goal State
- schema_migrated: true
- tests_passing: true
- old_code_removed: true

### Initial State
- schema_migrated: false
- tests_passing: true  (existing tests)
- old_code_removed: false

### Action Sequence (A* optimal, totalCost: N)
1. write_migration  [cost: 5]  preconditions: none  effects: schema_migrated=true
2. update_types     [cost: 2]  preconditions: schema_migrated=true  effects: types_updated=true
3. remove_old_code  [cost: 1]  preconditions: types_updated=true  effects: old_code_removed=true

### Assumptions (requires cfn-plan-review verification)
- [UNTESTED] No downstream consumers of old schema columns
- [UNTESTED] Migration is reversible (has down() function)

Then: hand off to /write-plan or plan mode with this structure as input.

Then: run cfn-plan-review on the resulting plan.


Mode 2: Replan (3-strike rule trigger)

Fire when: 3 hypotheses have failed during implementation.

Step 1: Capture Current World State

What actions from the original GOAP plan completed successfully? Update state to reflect what is now true.

What failed? Record the failed action and the actual error/blocker.

Step 2: Identify Broken Preconditions

Which precondition of the failed action turned out to be false? Example:

Step 3: Revise World State and Actions

Options:

Rerun GOAP with revised inputs.

Step 4: Escalate if Still Unreachable

If revised plan is also reachable: false, stop. Present to user:

Do not attempt a 4th hypothesis.


Integration

Optional bookend around plan mode or the cfn-megaplan pipeline. Megaplan runs /write-plan + /cfn-plan-review internally; GOAP wraps it: goal modeling before, replanning during.

| When | What |

|------|------|

| Before /cfn-megaplan (or plan mode) | Run Mode 1, output seeds the goal state for megaplan / /write-plan |

| After the plan is written | /cfn-plan-review runs (internally under megaplan, or standalone) |

| 3-strike fires | Run Mode 2, revise plan, re-enter implementation |

| Replan also fails | Escalate to user. Do not guess further |

What This Skill Does NOT Do

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.