Guest User

EARS Planning Method Skill

a guest
Feb 26th, 2026
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.29 KB | None | 0 0
  1. ---
  2. name: ears-planning-method
  3. description: >
  4. Structured planning method for code changes using EARS (Easy Approach to Requirements Syntax),
  5. RFC 2119 keywords, C4 architectural decomposition, and traceable verification. Use this skill
  6. whenever planning code changes, refactors, feature additions, bug fixes, or architectural work.
  7. Trigger on any request involving "plan", "design", "architect", "implement", "refactor",
  8. "restructure", or when the user asks for an EARS plan explicitly. Also trigger when a change
  9. touches multiple files/modules or when the user asks how something should be built. For trivial
  10. single-file fixes, produce a lightweight plan automatically — no need for the user to ask for
  11. "lightweight" explicitly. Scale up to full EARS + C4 as complexity grows.
  12. ---
  13.  
  14. # EARS Planning Method
  15.  
  16. Produce structured, traceable plans for code changes. Every plan separates **what the system must do** (requirements) from **how the agent will do it** (implementation) from **how we prove it works** (verification).
  17.  
  18. ## Complexity Tiers
  19.  
  20. Assess the change and pick the appropriate tier. Do not over-plan trivial work.
  21.  
  22. | Tier | Signal | Plan shape |
  23. |------|--------|------------|
  24. | **Light** | Single file, isolated bug fix, < ~30 LOC delta | Requirements (2-3 R#) → Steps (1-2 S#) → Verification (1 V#). No C4. |
  25. | **Standard** | Multi-file feature, moderate refactor, new component | Full EARS requirements → Implementation steps → Verification. C4 Component diagram if 2+ modules interact. |
  26. | **Heavy** | Cross-cutting concern, new subsystem, architectural migration | Full EARS + RFC 2119 precision → C4 (depth as needed) → Implementation chunked into committable units with USER checkpoints → Comprehensive verification matrix. |
  27.  
  28. When in doubt, start Standard and escalate if you discover hidden complexity while drafting.
  29.  
  30. ---
  31.  
  32. ## 1. Requirements — EARS Syntax
  33.  
  34. Write requirements about the **system/component under change**, not about the agent's to-do list. Name the system explicitly (e.g. `AuthService`, `WizardState`, `bep new`).
  35.  
  36. ### Patterns
  37.  
  38. | Pattern | Template | Use when |
  39. |---------|----------|----------|
  40. | **Ubiquitous** | `The <system> SHALL <response>.` | Invariant, always true |
  41. | **State-driven** | `While <precondition(s)>, the <system> SHALL <response>.` | Behavior depends on state |
  42. | **Event-driven** | `When <trigger>, the <system> SHALL <response>.` | Reaction to a stimulus |
  43. | **Optional/Scope** | `Where <feature/scope>, the <system> SHALL <response>.` | Conditional feature |
  44. | **Unwanted** | `If <unwanted condition>, then the <system> SHALL <mitigation>.` | Error/edge-case handling |
  45. | **Complex** | `While <precondition(s)>, when <trigger>, the <system> SHALL <response>.` | State + event combined |
  46.  
  47. ### Requirement rules
  48.  
  49. - Assign IDs: `R1`, `R2`, … — implementation and verification reference these.
  50. - Prefer **observable behavior and invariants**. Avoid file/function names unless they are part of the external contract.
  51. - One testable assertion per requirement. If a requirement contains "and" joining two distinct behaviors, split it.
  52. - Use **RFC 2119 keywords** (see §4) for precision: distinguish MUST from SHOULD from MAY.
  53.  
  54. ---
  55.  
  56. ## 2. Implementation Plan
  57.  
  58. Describe how you will satisfy the requirements as concrete agent actions, chunked into small committable units.
  59.  
  60. ### Rules
  61.  
  62. - Size steps to the change: few steps for small fixes, multiple git-committable chunks for large changes.
  63. - One concrete outcome per step: a code edit, a test addition, a verification run, or a USER checkpoint.
  64. - Prefix with `S1`, `S2`, … and annotate which requirements each step addresses (`→ R1, R3`).
  65. - Include a `USER checkpoint` step before and after risky or irreversible changes.
  66. - Steps MUST be ordered so that each chunk leaves the codebase in a valid (ideally green-tests) state.
  67.  
  68. ### Step types
  69.  
  70. | Marker | Meaning |
  71. |--------|---------|
  72. | `S#:` | Code change or file operation |
  73. | `S# [TEST]:` | Test addition or modification |
  74. | `S# [USER]:` | Checkpoint — pause for user review/commit |
  75. | `S# [VERIFY]:` | Run verification (build, lint, test suite) |
  76.  
  77. ---
  78.  
  79. ## 3. Verification
  80.  
  81. Explicit checks that map back to requirements. Every R# MUST appear in at least one V#.
  82.  
  83. ### Format
  84.  
  85. ```
  86. V<n> (R<x>, R<y>): <check command or manual validation description>
  87. ```
  88.  
  89. ### Rules
  90.  
  91. - Each V# references one or more R# IDs.
  92. - Name the check concretely: `npm test`, `cargo clippy`, `pytest tests/auth/`, or a targeted manual validation.
  93. - If a requirement is not mechanically verifiable, say so and describe the manual check.
  94. - Coverage: every R# MUST be covered. If you find an uncovered R#, add a V# or flag the gap.
  95.  
  96. ---
  97.  
  98. ## 4. RFC 2119 Keywords
  99.  
  100. Use these per [RFC 2119](https://www.rfc-editor.org/rfc/rfc2119) to convey requirement strength. Bold or uppercase when used normatively.
  101.  
  102. | Keyword | Meaning |
  103. |---------|---------|
  104. | **MUST** / **SHALL** | Absolute requirement. Violation = defect. |
  105. | **MUST NOT** / **SHALL NOT** | Absolute prohibition. |
  106. | **SHOULD** / **RECOMMENDED** | Strong default; deviation requires documented justification. |
  107. | **SHOULD NOT** / **NOT RECOMMENDED** | Strong suggestion against; deviation requires justification. |
  108. | **MAY** / **OPTIONAL** | Truly discretionary. Implementations that omit this are conformant. |
  109.  
  110. Apply within EARS requirements to distinguish hard constraints from preferences. If every requirement says SHALL, the distinction is lost — use the full range.
  111.  
  112. ---
  113.  
  114. ## 5. C4 Architectural Breakdown
  115.  
  116. Include a C4 decomposition when the change involves interactions across module boundaries. Pick the shallowest depth that makes the change legible.
  117.  
  118. Read `references/c4-guide.md` for diagramming patterns and depth selection criteria before producing C4 output.
  119.  
  120. ### Quick depth selector
  121.  
  122. | Depth | Include when |
  123. |-------|-------------|
  124. | **Context** (L1) | Change affects external system integrations or user-facing boundaries |
  125. | **Container** (L2) | Change spans services, databases, or deployment units |
  126. | **Component** (L3) | Change involves 2+ internal modules/packages within a container |
  127. | **Code** (L4) | Detailed class/function-level design needed (rare — usually pseudo is sufficient) |
  128.  
  129. Produce diagrams as Mermaid (`flowchart` or `C4Context`/`C4Container`/`C4Component` if using the C4 Mermaid extension) or as structured pseudocode tables — whichever is clearer for the change at hand.
  130.  
  131. ### Pseudo-structural breakdown (alternative to diagrams)
  132.  
  133. When a full diagram is overkill but you need to show responsibilities:
  134.  
  135. ```
  136. Component: AuthService
  137. Responsibilities: Token issuance, validation, revocation
  138. Dependencies: UserStore, TokenCache
  139. Exposes: authenticate(), refresh(), revoke()
  140.  
  141. Component: TokenCache
  142. Responsibilities: Short-lived token storage, TTL enforcement
  143. Dependencies: Redis
  144. Exposes: get(), set(), invalidate()
  145. ```
  146.  
  147. This is often more useful than a diagram for Standard-tier plans.
  148.  
  149. ---
  150.  
  151. ## 6. Compartmentalization Principles
  152.  
  153. These principles govern how you decompose work. They are not optional style preferences — they protect code quality and maintainability.
  154.  
  155. 1. **Single Responsibility per step.** Each implementation step (S#) touches one concern. If a step requires edits across unrelated modules, split it.
  156.  
  157. 2. **Interface-first.** When a change introduces or modifies a boundary between components, define the interface (types, contracts, API surface) in a dedicated step before implementing either side.
  158.  
  159. 3. **Test isolation.** Test additions (S# [TEST]) SHOULD be in separate steps from the code they validate. This ensures tests are written against the contract, not reverse-engineered from the implementation.
  160.  
  161. 4. **Blast radius awareness.** For each S#, annotate the blast radius — which other components could break. This informs checkpoint placement: if blast radius > 1 module, insert a `[USER]` checkpoint.
  162.  
  163. 5. **Dependency direction.** Note dependency flow in the plan. Changes MUST NOT introduce circular dependencies. If you detect a cycle, flag it and restructure before proceeding.
  164.  
  165. 6. **Rollback feasibility.** Each committable chunk SHOULD be independently revertable. If a step cannot be reverted without also reverting a later step, merge them or flag the coupling.
  166.  
  167. ---
  168.  
  169. ## Plan Template
  170.  
  171. Use this shape. Omit sections that don't apply at the chosen tier (e.g. Light tier omits C4 and checkpoints).
  172.  
  173. ```
  174. ## Context
  175. <1-2 sentences: what's changing and why>
  176.  
  177. ## Tier: <Light | Standard | Heavy>
  178.  
  179. ## Architecture (Standard+)
  180. <C4 diagram/pseudo-breakdown at appropriate depth>
  181.  
  182. ## Requirements
  183. R1: <EARS pattern with RFC 2119 keyword>
  184. R2: ...
  185.  
  186. ## Implementation
  187. S1: <edit description> → R1
  188. S2 [TEST]: <test addition> → R1
  189. S3 [USER]: Review/commit chunk 1
  190. S4: <edit description> → R2
  191. S5 [VERIFY]: <build/test command>
  192.  
  193. ## Verification
  194. V1 (R1): <concrete check>
  195. V2 (R2): <concrete check>
  196. V3 (R1, R2): <integration check>
  197. ```
  198.  
  199. ---
  200.  
  201. ## Examples
  202.  
  203. ### Light Tier — Bug fix
  204.  
  205. ```
  206. ## Context
  207. Off-by-one in pagination causes last item to be duplicated on page boundaries.
  208.  
  209. ## Tier: Light
  210.  
  211. ## Requirements
  212. R1: When the page boundary aligns with the last item index,
  213. the PaginationService SHALL NOT duplicate the boundary item.
  214. R2: The PaginationService SHALL return exactly `pageSize` items
  215. per page (or fewer on the final page).
  216.  
  217. ## Implementation
  218. S1: Fix boundary calculation in offset derivation → R1, R2
  219. S2 [VERIFY]: npm test -- --grep pagination
  220.  
  221. ## Verification
  222. V1 (R1, R2): npm test -- --grep pagination (existing suite covers boundary cases)
  223. ```
  224.  
  225. ### Standard Tier — New feature
  226.  
  227. ```
  228. ## Context
  229. Add rate limiting to the public API gateway.
  230.  
  231. ## Tier: Standard
  232.  
  233. ## Architecture
  234. Component: RateLimiter
  235. Responsibilities: Per-client request counting, window management, limit enforcement
  236. Dependencies: Redis (sliding window counter), APIGateway (middleware hook)
  237. Exposes: checkLimit(clientId): {allowed: bool, retryAfter?: number}
  238.  
  239. Component: APIGateway
  240. Responsibilities: Request routing, middleware pipeline
  241. Change: Insert RateLimiter middleware before auth
  242.  
  243. ## Requirements
  244. R1: When a client exceeds 100 requests per 60s window,
  245. the RateLimiter SHALL reject the request with HTTP 429
  246. and a Retry-After header.
  247. R2: The RateLimiter SHOULD use a sliding window algorithm.
  248. Fixed-window MAY be used if Redis version < 6.2.
  249. R3: If Redis is unreachable, then the RateLimiter SHALL
  250. fail open (allow the request) and emit a warning log.
  251. R4: The APIGateway SHALL invoke RateLimiter before
  252. authentication middleware.
  253.  
  254. ## Implementation
  255. S1: Define RateLimiter interface and types → R1, R2
  256. S2: Implement sliding window counter against Redis → R2
  257. S3 [TEST]: Unit tests for RateLimiter (under limit, at limit, over limit, window rollover) → R1, R2
  258. S4: Implement fail-open fallback → R3
  259. S5 [TEST]: Test Redis-unavailable path → R3
  260. S6: Wire RateLimiter into APIGateway middleware pipeline → R4
  261. S7 [USER]: Review — rate limiter is now active in the request path
  262. S8 [VERIFY]: npm test && npm run test:integration
  263.  
  264. ## Verification
  265. V1 (R1, R2): Unit tests: rate_limiter.test.ts
  266. V2 (R3): Unit test: redis_failover.test.ts
  267. V3 (R4): Integration test: middleware_order.test.ts
  268. V4 (R1): Manual: curl burst > 100 reqs, confirm 429 + Retry-After
  269. ```
Advertisement
Add Comment
Please, Sign In to add comment