|
| 1 | +--- |
| 2 | +name: implement-story |
| 3 | +description: Implements a GitHub user story from planning through PR creation, with research, codebase analysis, and structured commits. |
| 4 | +--- |
| 5 | + |
| 6 | +# Implement User Story |
| 7 | + |
| 8 | +Takes a GitHub user story issue and produces well-organized PR(s) that reliably meet the acceptance criteria. |
| 9 | + |
| 10 | +## Arguments |
| 11 | + |
| 12 | +The user provides a GitHub issue number or URL. Example: |
| 13 | + |
| 14 | +``` |
| 15 | +/implement-story #4550 |
| 16 | +/implement-story https://github.com/stacklok/toolhive/issues/4550 |
| 17 | +``` |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Phase 1: Gather Context |
| 22 | + |
| 23 | +### 1.1 Read the Issue |
| 24 | + |
| 25 | +Fetch the issue body using GitHub tools. Extract: |
| 26 | + |
| 27 | +- **User story**: The "As a / I want / so that" statement |
| 28 | +- **Acceptance criteria**: The checkbox list — this is the contract |
| 29 | +- **Context links**: RFC links, related issues, dependencies |
| 30 | +- **Out of scope**: What NOT to do |
| 31 | + |
| 32 | +### 1.2 Fetch RFC Context |
| 33 | + |
| 34 | +If the issue links to an RFC (look for `THV-XXXX` references or links to `toolhive-rfcs`): |
| 35 | + |
| 36 | +1. Clone or locate the RFC repo locally (check `../toolhive-rfcs/` first) |
| 37 | +2. Read the full RFC document |
| 38 | +3. Extract design decisions relevant to this story — config shapes, algorithm details, error formats, key schemas, etc. |
| 39 | + |
| 40 | +If no RFC is linked, skip this step. |
| 41 | + |
| 42 | +### 1.3 Find Related Stories |
| 43 | + |
| 44 | +Search for sibling stories that share context with this one. These inform how to factor the code for extensibility: |
| 45 | + |
| 46 | +```bash |
| 47 | +# Search by keywords from the issue title |
| 48 | +gh search issues "<keywords>" --repo stacklok/toolhive --state open --limit 10 |
| 49 | + |
| 50 | +# Search for issues linking to the same RFC |
| 51 | +gh search issues "THV-XXXX" --repo stacklok/toolhive --limit 10 |
| 52 | +``` |
| 53 | + |
| 54 | +For each related story, read its acceptance criteria. Ask: |
| 55 | + |
| 56 | +- Will a future story need to extend a type, interface, or package I'm creating? |
| 57 | +- Should I define an interface now that a sibling story will implement later? |
| 58 | +- Are there naming conventions or patterns I should establish that siblings will follow? |
| 59 | + |
| 60 | +**Do not implement sibling stories.** But design the code so they can be implemented without refactoring what you build here. |
| 61 | + |
| 62 | +### 1.4 Research the Codebase |
| 63 | + |
| 64 | +Use the Explore agent or direct search to understand: |
| 65 | + |
| 66 | +1. **Where does this change fit?** Identify the packages, files, and functions that need modification. |
| 67 | +2. **What patterns exist?** Find analogous features already implemented. For example, if adding a new middleware, study how existing middleware (auth, mcp-parser, authz) is registered and wired. |
| 68 | +3. **What gets generated?** Identify files that are auto-generated (CRD manifests, mocks, docs) so you know what to regenerate. |
| 69 | +4. **What tests exist?** Find the test patterns used for similar features (table-driven tests, testcontainers, Chainsaw E2E). |
| 70 | + |
| 71 | +Document your findings before writing any code. |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## Phase 2: Plan the Work |
| 76 | + |
| 77 | +### 2.1 Map AC to Changes |
| 78 | + |
| 79 | +For each acceptance criterion, identify: |
| 80 | + |
| 81 | +- Which files need to change |
| 82 | +- Whether it's new code or a modification |
| 83 | +- What tests verify it (unit, integration, or E2E) |
| 84 | + |
| 85 | +### 2.2 Decide PR Strategy |
| 86 | + |
| 87 | +Evaluate the total scope against the project's PR guidelines: |
| 88 | + |
| 89 | +- **< 10 files changed** (excluding tests, generated code, docs) |
| 90 | +- **< 400 lines of code changed** (excluding tests, generated code, docs) |
| 91 | + |
| 92 | +If the story fits in one PR, use a single PR. If not, split into multiple PRs following these patterns: |
| 93 | + |
| 94 | +1. **Foundation first**: New types, interfaces, packages |
| 95 | +2. **Wiring second**: Integration into existing code (middleware chain, reconciler, CRD) |
| 96 | +3. **Tests alongside**: Each PR includes its own tests |
| 97 | +4. **Generated code with its trigger**: CRD type changes + `task operator-manifests operator-generate` output in the same PR |
| 98 | + |
| 99 | +### 2.3 Present the Plan |
| 100 | + |
| 101 | +Show the user a plan that covers PR boundaries AND commit boundaries within each PR: |
| 102 | + |
| 103 | +```markdown |
| 104 | +## Implementation Plan |
| 105 | + |
| 106 | +**Story**: #XXXX — [title] |
| 107 | +**PRs**: [1 or N] |
| 108 | + |
| 109 | +### PR 1: [title] |
| 110 | +**Commits**: |
| 111 | +1. [commit message] — [what changes and why] |
| 112 | +2. [commit message] — [what changes and why] |
| 113 | +3. [commit message] — [what changes and why] |
| 114 | +**Tests**: |
| 115 | +- [Unit/E2E]: [what is tested] |
| 116 | +**AC covered**: [which acceptance criteria this satisfies] |
| 117 | +**Regeneration**: [which `task` commands need to run and in which commit] |
| 118 | + |
| 119 | +### PR 2: [title] (if needed) |
| 120 | +... |
| 121 | +``` |
| 122 | + |
| 123 | +Wait for user approval before proceeding. Adjust if the user has feedback. |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## Phase 3: Implement |
| 128 | + |
| 129 | +### 3.1 Create a Branch |
| 130 | + |
| 131 | +```bash |
| 132 | +git checkout -b <user>/<short-description> main |
| 133 | +``` |
| 134 | + |
| 135 | +### 3.2 Write Code |
| 136 | + |
| 137 | +Implement the changes from the plan. Follow these principles: |
| 138 | + |
| 139 | +- **Match existing patterns**: Don't invent new conventions. Study the codebase and follow what's there. |
| 140 | +- **Design for siblings**: If related stories will extend this code, use interfaces and clear extension points. But don't build speculative abstractions — just leave the door open. |
| 141 | +- **Tests are not optional**: Every AC that says "Unit:" or "E2E:" must have a corresponding test. Write tests as you go, not at the end. |
| 142 | + |
| 143 | +### 3.3 Commit Per the Plan |
| 144 | + |
| 145 | +Follow the commit boundaries from the plan. Each commit should: |
| 146 | + |
| 147 | +- Be independently compilable (`go build ./...` passes) |
| 148 | +- Have a clear, descriptive message |
| 149 | +- Group related changes (e.g., don't mix CRD type changes with middleware logic) |
| 150 | + |
| 151 | +### 3.4 Run Regeneration Tasks |
| 152 | + |
| 153 | +After changes that affect generated artifacts, run the appropriate tasks: |
| 154 | + |
| 155 | +| Change Type | Regeneration Command | |
| 156 | +|-------------|---------------------| |
| 157 | +| CRD type definitions (`api/v1alpha1/*_types.go`) | `task operator-manifests operator-generate` | |
| 158 | +| Mock interfaces | `task gen` | |
| 159 | +| CLI commands or API endpoints | `task docs` | |
| 160 | +| Helm chart values | `task helm-docs` | |
| 161 | +| Any Go file | `task license-fix` | |
| 162 | + |
| 163 | +Run these **before committing** the related changes. Include the generated output in the same commit as the trigger. |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## Phase 4: Create PR |
| 168 | + |
| 169 | +### 4.1 Push and Create PR |
| 170 | + |
| 171 | +Follow the PR template at `.github/pull_request_template.md` and the rules in `.claude/rules/pr-creation.md`: |
| 172 | + |
| 173 | +- Title: under 70 chars, imperative mood, no conventional commit prefix |
| 174 | +- Summary: why first, then what. Reference the issue with `Closes #XXXX` |
| 175 | +- Type of change: check exactly one |
| 176 | +- Test plan: check every verification step actually run |
| 177 | + |
| 178 | +### 4.2 Verify AC Coverage |
| 179 | + |
| 180 | +Before submitting, review each acceptance criterion from the issue: |
| 181 | + |
| 182 | +- [ ] Is there code that implements it? |
| 183 | +- [ ] Is there a test that verifies it? |
| 184 | +- [ ] Has the test passed? |
| 185 | + |
| 186 | +If any AC is not covered, either implement it or flag it to the user with a reason. |
| 187 | + |
| 188 | +### 4.3 Babysit CI |
| 189 | + |
| 190 | +After pushing, monitor CI status: |
| 191 | + |
| 192 | +```bash |
| 193 | +gh pr checks <pr-number> --repo stacklok/toolhive --watch |
| 194 | +``` |
| 195 | + |
| 196 | +If CI fails: |
| 197 | +1. Read the failure logs |
| 198 | +2. Fix the issue |
| 199 | +3. Push the fix as a new commit (don't amend — keep the history clean for review) |
| 200 | +4. Re-check CI |
| 201 | + |
| 202 | +### 4.4 Multi-PR Workflow |
| 203 | + |
| 204 | +If the story spans multiple PRs: |
| 205 | + |
| 206 | +1. Create the first PR targeting `main` |
| 207 | +2. After merge, create subsequent PRs targeting `main` |
| 208 | +3. Each PR references the story issue (`Part of #XXXX`) |
| 209 | +4. The final PR uses `Closes #XXXX` |
| 210 | + |
| 211 | +--- |
| 212 | + |
| 213 | +## Edge Cases |
| 214 | + |
| 215 | +- **AC references another story**: If an acceptance criterion depends on work from another story (e.g., "STORY-001 core middleware exists"), check if that story is merged. If not, flag it to the user. |
| 216 | +- **Generated code is large**: CRD manifest regeneration can produce hundreds of lines of diff. This is expected — note it in the PR description under "Special notes for reviewers." |
| 217 | +- **Tests require infrastructure**: E2E tests may need a Kind cluster, Redis, or Keycloak. Document the setup in the test plan. Don't skip the test — write it even if the user will run it separately. |
| 218 | +- **RFC is ambiguous**: If the RFC doesn't specify a detail needed for implementation, make a pragmatic choice, document it in a code comment, and flag it in the PR description. |
0 commit comments