Sd replan loop

From developzoneio/specwright · View interactive version

Sd replan loop is an AI agent skill from the GitHub repository developzoneio/specwright. Sanctioned mid-execution re-plan protocol for specwright. Lets a workflow adapt when execution (or

How to use this skill

Skill file

sd-replan-loop

Sanctioned mid-execution re-plan protocol for specwright. Lets a workflow adapt when execution (or

the batch review) reveals that 02-tasks.md is wrong, without violating spec immutability or

skipping a gate. Referenced at runtime by /sd:feature and /sd:refactor - the only two workflows

that produce a 01-plan.md + 02-tasks.md pair to re-plan.

Not used by /sd:bug, /sd:perf, or /sd:rca: bug and rca produce no atomic task list, and perf

already carries its own adaptive loop (Phase 4 reverts a failed hypothesis and re-selects at Gate 4).


The problem this solves

The Planning pattern's strength is adaptivity - re-planning when execution surfaces new

information. specwright's immutability rule is right for audit, but it left the adaptive path

undefined: when an implementer discovers mid-Execute that a task's premise is false, or the batch

review finds the plan itself was wrong, there was no sanctioned move. The failure mode is a model

silently hack-editing 02-tasks.md (violating sequencing, leaving no trail) or stalling.

The discovery point is not only mid-task. In the one measured corpus, the single real case of a

wrong plan surfaced at batch review: an implementer found a spec decision was wrong, hand-edited

the task, corrected the spec, and left one sentence in the retro - no gate, no append-only record.

The re-plan gate must be reachable from both the Execute phase and the review phase.


What counts as a plan-invalidating discovery

A re-plan is warranted only when the plan is wrong, not when a single task needs a normal

implementation adjustment. Trigger the loop when:

from what the task assumed, a Depends on edge is backwards, or the Files list cannot carry the

change.

case: a spec/plan decision that only proves incorrect once the code is written.

Do not trigger the loop for work that stays inside one task's contract (a rename, a helper reuse,

a test tweak). That is ordinary implementation, handled by the implementer's own scope. Re-planning

is for changing the plan, not for doing the task.


Gate Re-plan (HARD)

When a plan-invalidating discovery lands, the workflow returns to this gate. It is HARD - it STOPS

and waits for explicit user approval; silence is not approval, and there is no override path.

  1. Surface the trigger. Present to the user: what was discovered, which task(s) it invalidates,

and the proposed delta. Ask:

> Re-plan <SPEC-ID>? Discovery: <trigger>. Affects <task IDs>. (approve / revise <feedback> / abort task)

  1. Append a revision entry to 01-plan.md (never rewrite prior content - see format below).

Assign the next contiguous revision number R<n>.

  1. Regenerate only the affected tasks in 02-tasks.md. Invoke sd-spec-architect with

TASK = plan, REPLAN_SCOPE = <affected task IDs>, and REVISION = R<n>. The architect

rewrites only those task blocks, marks each with Revised-by: R<n> (per sd-atomic-task-format),

and leaves every other task block byte-for-byte unchanged.

  1. Resume. Re-enter the Execute phase at the first affected (now regenerated) task. Already-passed

tasks that the revision did not touch stay checked.


The `## Revisions` log (`01-plan.md`)

Append-only. Lives at the end of 01-plan.md, below the original plan prose. The original plan

text - phased overview, sequencing rationale, risks - is never edited; a re-plan only appends

here. Create the ## Revisions header on the first revision.

## Revisions

### R1 - <UTC ISO 8601 timestamp>

- Trigger: <the discovery that invalidated the plan - one or two lines>
- Phase: <execute | review>
- Gate: re-plan
- Affected tasks: <T## list>
- Delta: <what changed in those tasks and why>
- revised-from: <one-line pointer to the original intent - what the tasks assumed before>

Rules:

never appears twice.

entry that supersedes it in prose, never a rewrite.

came through this gate, not from a hand-edit. An entry with no gate/phase line is malformed.

02-tasks.md that carries Revised-by: R<n>, and every task carrying Revised-by: R<n> must be

listed in entry R<n>. /sd:spec validate enforces this both ways (SL070-SL073).


Immutability boundary

specs are mutable by definition; this protocol never touches a done (or archived) spec.

## Revisions log and the revised-from pointer, not in stale text left behind.


What validate can and cannot see (honest scope)

/sd:spec validate is a static linter over .specs/. It has no snapshot of 02-tasks.md as it

stood at Plan phase, so it cannot detect an arbitrary silent edit by diffing. What it enforces is

the internal consistency of the revision record (SL070-SL073): a task marked Revised-by: R<n>

with no backing entry, an entry naming tasks that do not carry the marker, non-contiguous or rewritten

history, a malformed entry. A compliant re-plan always marks its work, so the linter catches a

broken record; an unmarked hack-edit stays invisible to the linter and is prevented by the gate,

not the lint. State this boundary plainly - do not imply the linter diffs the file.

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.