|
| 1 | +--- |
| 2 | +description: Amend a completed feature specification with new edge cases, scenarios, or behavioral corrections, then cascade changes through existing tests and implementation. |
| 3 | +handoffs: |
| 4 | + - label: Analyze Consistency |
| 5 | + agent: speckit.analyze |
| 6 | + prompt: Verify the amendment is consistent across all artifacts |
| 7 | + send: true |
| 8 | +scripts: |
| 9 | + sh: scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks |
| 10 | + ps: scripts/powershell/check-prerequisites.ps1 -Json -RequireTasks -IncludeTasks |
| 11 | +--- |
| 12 | + |
| 13 | +## User Input |
| 14 | + |
| 15 | +```text |
| 16 | +$ARGUMENTS |
| 17 | +``` |
| 18 | + |
| 19 | +You **MUST** consider the user input before proceeding (if not empty). |
| 20 | + |
| 21 | +## Goal |
| 22 | + |
| 23 | +Apply a targeted amendment to a feature that has already been through the full `/speckit.specify` → `/speckit.plan` → `/speckit.tasks` → `/speckit.implement` cycle. This command handles the common case where an edge case, missing scenario, or behavioral correction is discovered **after implementation** and needs to cascade through the spec, tests, and code without re-running the full pipeline. |
| 24 | + |
| 25 | +This is a **micro-cycle**: it updates the spec as the source of truth, then cascades only the necessary changes to affected files, preserving everything that already works. |
| 26 | + |
| 27 | +## When to Use |
| 28 | + |
| 29 | +- **Post-implementation edge case**: A missing behavior discovered in production, during review, or through testing |
| 30 | +- **Behavioral correction**: An existing scenario needs modification (e.g., threshold change, new validation rule) |
| 31 | +- **New acceptance scenario**: A stakeholder or tester identifies a scenario not covered by the original spec |
| 32 | +- **Regression prevention**: Encoding a discovered bug as a scenario before fixing it |
| 33 | + |
| 34 | +## When NOT to Use |
| 35 | + |
| 36 | +- **Pre-implementation changes**: Use `/speckit.clarify` instead (spec not yet implemented) |
| 37 | +- **Large scope changes**: If the amendment affects multiple user stories or requires architectural changes, create a new feature with `/speckit.specify` |
| 38 | +- **Constitution changes**: Use `/speckit.constitution` for governance updates |
| 39 | + |
| 40 | +## Outline |
| 41 | + |
| 42 | +### Phase 1: Context Loading |
| 43 | + |
| 44 | +1. Run `{SCRIPT}` from repo root and parse JSON for FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute. For single quotes in arguments, use shell-appropriate escaping (e.g., `'I'\''m Groot'` in bash, `'I''m Groot'` in PowerShell) or use double quotes if possible (e.g., `"I'm Groot"`). |
| 45 | + |
| 46 | +2. Load and validate the implementation context: |
| 47 | + - **REQUIRED**: Read spec.md — the source of truth being amended |
| 48 | + - **REQUIRED**: Read tasks.md — for traceability of completed work |
| 49 | + - **REQUIRED**: Read plan.md — for tech stack, testing framework, and project structure |
| 50 | + - **IF EXISTS**: Read data-model.md — for entity context |
| 51 | + - **IF EXISTS**: Read contracts/ — for API specifications |
| 52 | + |
| 53 | +3. Verify implementation state: |
| 54 | + - Confirm that tasks.md has completed tasks (lines matching `- [x]` or `- [X]`) |
| 55 | + - If NO completed tasks exist, warn: "No completed tasks found. Consider using `/speckit.clarify` for pre-implementation amendments instead." Ask user to confirm before proceeding. |
| 56 | + |
| 57 | +4. Parse the amendment description from user input. Extract: |
| 58 | + - **Amendment type**: edge case | new scenario | behavioral correction | regression fix |
| 59 | + - **Affected user story**: Which user story (US1, US2, etc.) is impacted — infer from context or ask |
| 60 | + - **Behavioral statement**: The core behavior being added or changed |
| 61 | + |
| 62 | +### Phase 2: Spec Amendment (Source of Truth) |
| 63 | + |
| 64 | +1. Update spec.md with the amendment. Apply changes to **three sections**: |
| 65 | + |
| 66 | + a. **Clarifications section** — Add traceability entry: |
| 67 | + - Ensure `## Clarifications` section exists (create after overview section if missing) |
| 68 | + - Create or append to `### Amendment YYYY-MM-DD` subheading (distinct from Clarification sessions) |
| 69 | + - Add entry: `- [AMENDMENT] <amendment type>: <description> → Affected: <user story>` |
| 70 | + |
| 71 | + b. **Acceptance Scenarios** — Add the new or modified scenario: |
| 72 | + - Locate the affected user story section in "User Scenarios & Testing" |
| 73 | + - Append the new acceptance scenario using the existing format: |
| 74 | + `N. **Given** [initial state], **When** [action], **Then** [expected outcome]` |
| 75 | + - Number it sequentially after the last existing scenario for that story |
| 76 | + - If modifying an existing scenario, replace it and add a note: `(Amended YYYY-MM-DD: <reason>)` |
| 77 | + |
| 78 | + c. **Edge Cases section** — Add edge case entry if applicable: |
| 79 | + - If the amendment addresses an edge case, add it to the Edge Cases list |
| 80 | + - Format: `- <edge case description> → <handling behavior> (Added YYYY-MM-DD)` |
| 81 | + |
| 82 | + **Validation**: After writing, verify: |
| 83 | + - No duplicate scenarios exist |
| 84 | + - The new scenario does not contradict existing scenarios |
| 85 | + - Markdown structure remains valid |
| 86 | + |
| 87 | +2. Save the updated spec.md. |
| 88 | + |
| 89 | +### Phase 3: Locate Affected Implementation |
| 90 | + |
| 91 | +1. Scan the project to identify files affected by this amendment: |
| 92 | + |
| 93 | + a. **Test files** — Search for existing test files related to the affected user story: |
| 94 | + - Check test directories from plan.md project structure (e.g., `tests/`, `test/`, `spec/`, `__tests__/`) |
| 95 | + - Look for files matching the affected user story's components |
| 96 | + - Identify the testing framework from plan.md (pytest, jest, mocha, rspec, junit, etc.) |
| 97 | + |
| 98 | + b. **Implementation files** — Search for source files that implement the affected behavior: |
| 99 | + - Check source directories from plan.md project structure |
| 100 | + - Match against file paths referenced in completed tasks for the affected user story |
| 101 | + |
| 102 | + c. **Build an impact map**: |
| 103 | + |
| 104 | + ```text |
| 105 | + Amendment: <description> |
| 106 | + Affected User Story: <USN> |
| 107 | + Test files to update: [list] |
| 108 | + Implementation files to update: [list] |
| 109 | + New files needed: [list, if any] |
| 110 | + ``` |
| 111 | +
|
| 112 | + d. Present the impact map to the user and ask: "Proceed with these changes? (yes/no)" |
| 113 | + - If "no", halt and suggest adjustments |
| 114 | + - If "yes", continue to Phase 4 |
| 115 | +
|
| 116 | +### Phase 4: Test Amendment |
| 117 | +
|
| 118 | +1. Add the test for the new scenario. The approach depends on the project's testing framework (determined from plan.md): |
| 119 | +
|
| 120 | + **General pattern** (adapt to project's testing conventions): |
| 121 | + - Open the identified test file(s) for the affected user story |
| 122 | + - Add a new test case that: |
| 123 | + - Describes the scenario from the spec amendment |
| 124 | + - Follows the project's existing test naming conventions |
| 125 | + - Uses the project's existing test fixtures and helpers |
| 126 | + - Is placed logically near related existing tests |
| 127 | + - If no relevant test file exists, create one following the project's test directory structure |
| 128 | +
|
| 129 | + **Test naming**: Include a marker indicating this is a post-implementation amendment: |
| 130 | + - In the test name or description, include the amendment date or a reference to the spec scenario number |
| 131 | + - Example patterns (adapt to framework): |
| 132 | + - `test_<behavior>_amendment_YYYYMMDD` |
| 133 | + - `describe('amendment: <behavior>')` |
| 134 | + - `it('should <behavior> (amended YYYY-MM-DD)')` |
| 135 | +
|
| 136 | +2. Run the new test to confirm it **fails** (RED state): |
| 137 | + - Execute only the new test using the project's test runner |
| 138 | + - If the test **passes** (the behavior already works): Report that the amendment is already handled in code but was missing from the spec. Mark as "spec-only amendment" and skip Phase 5. |
| 139 | + - If the test **fails** (expected): Proceed to Phase 5. |
| 140 | + - If the test **errors** (setup issue): Fix the test setup, do not proceed to implementation until the test runs cleanly and fails for the right reason. |
| 141 | +
|
| 142 | +### Phase 5: Implementation Amendment |
| 143 | +
|
| 144 | +1. Make the targeted code change to satisfy the new test: |
| 145 | + - Open the identified implementation file(s) |
| 146 | + - Make the minimal change necessary to handle the new scenario |
| 147 | + - Do NOT refactor surrounding code — keep the change focused on the amendment |
| 148 | + - Follow the project's existing code style and patterns |
| 149 | +
|
| 150 | +2. Run the full test suite for the affected user story: |
| 151 | + - Execute all tests (not just the new one) for regression validation |
| 152 | + - **If all tests pass** (GREEN): Proceed to Phase 6 |
| 153 | + - **If existing tests fail** (REGRESSION): Revert the implementation change. Report the conflict and suggest the user resolve it manually or reconsider the amendment. |
| 154 | + - **If only the new test fails**: Debug and fix the implementation. Retry up to 2 times before halting and reporting the issue. |
| 155 | +
|
| 156 | +### Phase 6: Traceability Update |
| 157 | +
|
| 158 | +1. Append an amendment traceability entry to tasks.md using the existing checklist format defined by `/speckit.tasks`: |
| 159 | +
|
| 160 | + ```markdown |
| 161 | + - [x] T<next-id> [USN] Record amendment: <short description> in specs/<feature>/tasks.md |
| 162 | + - Spec: Scenario N in spec.md User Story N (Amended YYYY-MM-DD) |
| 163 | + - Test: <test file path>:<test name> |
| 164 | + - Code: <implementation file path> |
| 165 | + - Type: <edge case | new scenario | behavioral correction | regression fix> |
| 166 | + ``` |
| 167 | +
|
| 168 | + - Determine `<next-id>` by continuing from the highest existing `Txxx` task ID in the file |
| 169 | + - Place the amendment entry under the affected user story phase whenever possible |
| 170 | + - If no suitable story phase exists, append under "Final Phase: Polish & Cross-Cutting Concerns" |
| 171 | + - Do **not** introduce alternate task ID schemes (e.g., `AMEND-NNN`) unless `/speckit.tasks` is globally updated first |
| 172 | +
|
| 173 | +### Phase 7: Report |
| 174 | +
|
| 175 | +1. Output a structured completion report: |
| 176 | +
|
| 177 | + ```text |
| 178 | + ## Amendment Complete |
| 179 | +
|
| 180 | + | Aspect | Detail | |
| 181 | + |--------|--------| |
| 182 | + | Type | <amendment type> | |
| 183 | + | User Story | <affected story> | |
| 184 | + | Spec scenario | #N in User Story N | |
| 185 | + | Test | <file>:<test name> | |
| 186 | + | Implementation | <file>:<function/method> | |
| 187 | + | All tests | ✓ PASS / ✗ FAIL | |
| 188 | +
|
| 189 | + ### Files Modified |
| 190 | + - spec.md (scenario added, edge case added, clarification logged) |
| 191 | + - <test file> (new test added) |
| 192 | + - <implementation file> (targeted change) |
| 193 | + - tasks.md (amendment entry added) |
| 194 | +
|
| 195 | + ### Suggested Next Steps |
| 196 | + - Run `/speckit.analyze` to verify cross-artifact consistency |
| 197 | + - Review the amendment in a pull request before merging |
| 198 | + ``` |
| 199 | +
|
| 200 | +## Behavior Rules |
| 201 | +
|
| 202 | +- **Spec is always first**: Never modify tests or code before updating spec.md. The spec is the source of truth. |
| 203 | +- **Minimal blast radius**: Only modify files directly affected by the amendment. Do not refactor, clean up, or "improve" surrounding code. |
| 204 | +- **Fail-safe**: If any phase encounters an unrecoverable error, halt and report clearly. Do not leave artifacts in an inconsistent state. |
| 205 | +- **No spec, no change**: If spec.md is missing, instruct user to run `/speckit.specify` first. |
| 206 | +- **No tasks, no amend**: If tasks.md is missing or has no completed tasks, suggest `/speckit.clarify` instead. |
| 207 | +- **One amendment per invocation**: Handle exactly one amendment at a time. For multiple amendments, run `/speckit.amend` multiple times. |
| 208 | +- **Preserve existing work**: Never delete or modify existing acceptance scenarios unless the amendment is explicitly a correction to a specific scenario number. |
| 209 | +- **Test before implement**: Always write the failing test before making the implementation change (RED → GREEN). |
| 210 | +- **Respect user control**: Present the impact map and ask for confirmation before making changes. Halt on user's request at any point. |
| 211 | +
|
| 212 | +## Context |
| 213 | +
|
| 214 | +{ARGS} |
0 commit comments