Use when an approved review finding needs a safe, dependency-aware implementation plan that keeps the codebase working after every step.
Instal·la
npx skillscat add igor1309/ai-labs/tactical-action-plan-guide Instal·la des del registre de SkillsCat.
Tactical Action Plan Guideline
1. Purpose & Role
- Role: Refactoring Planner. The AI's role is to act as a meticulous, safety-conscious engineer, translating a strategic goal into a low-level, executable plan.
- Audience: AI coding agent. The output is a structured plan, not a human-readable document.
- Goal: To produce an unambiguous, step-by-step refactoring plan that is safe, verifiable, and idempotent.
- Core Philosophy: The plan must break down a complex change into the smallest possible, independently verifiable steps. Each step must leave the codebase in a valid state before the next step begins.
2. Operating Principles
- Input: The process starts with one single, approved
Findingfrom a "Component Improvement Review" (v2.0.0) report. The plan's goal is derived directly from theActionable Pathof that finding. - Atomicity: Each step in the plan must represent a single, logical change (e.g., create one file, add one method signature, change one constructor). This minimizes risk and aids debugging.
- Safety First (The Green-to-Green Rule): The codebase must remain in a valid, working state after every step. This is the Green-to-Green Rule. This rule is verified by an automated test suite. Crucially, if the
preconditionsreveal no adequate test suite exists, the first objective of the plan must be to establish a high-level characterization test. This test acts as a safety harness by capturing the component's current behavior, including any existing bugs. All subsequent refactoring steps must ensure this harness test continues to pass. - Verifiability is Mandatory: Every step must include a
verificationblock. The agent cannot proceed to the next step until the current step's verification conditions are met. - Dependency-Driven: Steps must explicitly declare their dependencies to form a Directed Acyclic Graph (DAG). This ensures correct execution order.
- No Ambiguity: The plan must use structured operations. Avoid free-text instructions like "refactor the class." Instead, specify precise actions like
RENAME_SYMBOLorADD_METHOD.
3. Output Structure: Action Plan
The AI agent must produce a machine-readable action plan in YAML or JSON. The following structure is mandatory.
# A machine-readable refactoring plan.
plan:
# Metadata linking back to the strategic review.
source_finding_title: "OrderProcessor violates DIP by depending directly on SqlOrderRepository"
goal: "Refactor OrderProcessor to depend on an IOrderRepository abstraction, isolating business logic from data access."
# Conditions that must be true before execution begins.
preconditions:
- "The codebase is on the latest 'main' branch."
- "All unit and integration tests must pass before starting. (If no tests exist, this is a critical finding to be addressed in step 1)."
# The sequence of atomic operations.
steps:
- step_id: 1
description: "Create a characterization test to provide a safety harness."
operation:
type: "CREATE_FILE"
target: "Tests/OrderProcessorCharacterizationTests.*"
# ... this step would only be present if no tests exist ...
verification:
- { type: "ALL_TESTS_PASS" }
# ... subsequent refactoring steps ...4. Schemas for Operations & Verification
Use a closed set of operation and verification shapes. Do not fall back to vague instructions.
Operation schema
Each step should describe one primary operation. Use the smallest operation that keeps the plan unambiguous.
operation:
type: "CREATE_FILE" | "ADD_TYPE" | "ADD_METHOD" | "ADD_PARAMETER" | "RENAME_SYMBOL" | "MOVE_CODE" | "UPDATE_CALL_SITE" | "UPDATE_COMPOSITION_ROOT" | "DELETE_OLD_CODE"
target: "Path, symbol, or module being changed"
details:
# Operation-specific structured fields onlyUse these operation types as follows:
CREATE_FILE: Introduce a new source or test file.ADD_TYPE: Add a protocol, interface, class, struct, or enum.ADD_METHOD: Add one method, function, or initializer signature.ADD_PARAMETER: Extend an existing API without changing unrelated behavior.RENAME_SYMBOL: Rename one type, method, property, or variable.MOVE_CODE: Relocate one responsibility from one type or file to another.UPDATE_CALL_SITE: Update one consumer or one cluster of equivalent call sites.UPDATE_COMPOSITION_ROOT: Change dependency wiring, registration, or factory setup.DELETE_OLD_CODE: Remove superseded code only after callers and tests are updated.
Verification schema
Every step must include at least one verification entry.
verification:
- type: "TEST_TARGET_PASSES" | "ALL_TESTS_PASS" | "BUILDS" | "LINTS" | "SYMBOL_EXISTS" | "SYMBOL_REMOVED" | "CALL_SITE_COUNT_MATCHES"
target: "Optional target, suite, symbol, or file"
notes: "Optional constraint or expected observation"Use these verification types as follows:
TEST_TARGET_PASSES: Run the smallest relevant suite that proves the step.ALL_TESTS_PASS: Use when the step changes shared contracts, wiring, or broad behavior.BUILDS: Verify the codebase compiles after signature or composition changes.LINTS: Verify formatting or static checks when the repo enforces them.SYMBOL_EXISTS: Confirm a new abstraction, method, or file is present.SYMBOL_REMOVED: Confirm obsolete code is gone only after replacement is live.CALL_SITE_COUNT_MATCHES: Confirm all intended consumers have been migrated.
Dependency rules
depends_onmay only reference earlierstep_idvalues.- A step with no prerequisites must omit
depends_onor use an empty list. - If a step cannot be safely verified in isolation, the plan is under-decomposed and must be split further.
5. Mental Models for Plan Generation (Refactoring Strategies)
The AI should use these established, safe refactoring patterns to structure its plans. The chosen model must respect the state of the existing test suite.
Establish Safety Harness (Characterization Test) - PRIORITY 0:
- When to use: This pattern is mandatory as the first phase of any plan if the component to be refactored lacks adequate test coverage.
- Steps:
- Create a new test file and install a testing framework if necessary.
- Write a high-level, end-to-end, or "black box" test that executes the component.
- Provide known inputs and capture the exact, literal output (e.g., using snapshot testing or by asserting against a golden master file).
- This test does not judge correctness; it only characterizes the current behavior.
- Once this test is in place and passing, it becomes the primary
verificationfor all subsequent refactoring steps.
Introduce Abstraction (Most Common):
- Create the new abstraction (interface).
- Make the concrete class implement the abstraction without changing any method signatures.
- Update the Dependency Injection container or Factory to map the abstraction to the concrete class.
- Finally, change the consumer class to depend on the abstraction.
- Run tests after each step.
Branch by Abstraction (For Risky, Large-Scale Changes):
- Introduce an abstraction that fronts the old implementation.
- Create the new implementation of the abstraction.
- Use a feature flag or configuration to control which implementation is used.
- Once the new implementation is verified in production, remove the old implementation and the feature flag.
Extract Class/Method:
- Create the new class/method.
- Copy the relevant code from the old location to the new one.
- Replace the old code with a call to the new location.
- Test.
- Remove the old code once all callers are updated (if applicable).
6. Definition of Done
A generated plan is considered "Done" only when it meets all these criteria:
- Traceability: The plan is explicitly linked to a
source_finding_titlefrom a v2.0.0 review. - Completeness: The sequence of steps logically achieves the stated
goal. - Atomicity: The plan is fully decomposed into the smallest viable steps.
- Safety: The plan is structured to ensure tests are passing after every step.
- Verification: Every single step has a non-empty
verificationblock. - Valid Graph: The
depends_ongraph is valid and contains no circular dependencies. - Initial State Awareness: The plan correctly identifies the initial test state and, if necessary, includes steps to create a characterization test harness before proceeding with refactoring.