@gitwhy-cli/whyspec 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,210 @@
1
+ ---
2
+ name: whyspec-execute
3
+ description: Use when starting implementation, continuing work, or executing tasks from a WhySpec plan.
4
+ argument-hint: "[change-name]"
5
+ ---
6
+
7
+ Implement a change — read the plan, work through tasks, commit atomically.
8
+
9
+ When all tasks are done, run `/whyspec:capture` to save your reasoning.
10
+
11
+ ---
12
+
13
+ **Input**: Optionally specify a change name. If omitted, auto-detect or prompt for available changes.
14
+
15
+ ## Iron Law
16
+
17
+ **NEVER SKIP THE PLAN.** Read intent.md and design.md before writing a single line of code. The plan is the contract — if reality doesn't match the plan, update the plan first.
18
+
19
+ ## Red Flags — If You're Thinking This, STOP
20
+
21
+ - "The plan is clear enough, I'll just start coding" → Read intent.md. Now. It takes 15 seconds.
22
+ - "I'll batch all changes into one commit at the end" → One commit per task. That's the contract.
23
+ - "This task seems unnecessary, I'll skip it" → Ask the user to remove it. Don't silently skip.
24
+ - "The design says X but Y is clearly better" → Flag the contradiction. Don't silently override.
25
+ - "I'm done, no need to run the verify step" → Run it. Evidence beats confidence.
26
+
27
+ ## Steps
28
+
29
+ 1. **Select the change**
30
+
31
+ If ARGUMENTS provides a name, use it. Otherwise:
32
+ - Auto-select if only one active change exists
33
+ - If multiple changes exist, run `whyspec list --json` and let the user select
34
+
35
+ Announce: "Executing change: **<name>**"
36
+
37
+ 2. **Load execution context**
38
+
39
+ ```bash
40
+ whyspec execute --json "<name>"
41
+ ```
42
+
43
+ Parse the JSON response:
44
+ - `change_name`: The change being executed
45
+ - `intent`: Content of intent.md
46
+ - `design`: Content of design.md
47
+ - `tasks`: Content of tasks.md
48
+ - `progress`: `{ total, completed, remaining }`
49
+ - `pending_tasks`: Array of uncompleted tasks
50
+
51
+ 3. **Read plan files for context**
52
+
53
+ Read the full content of:
54
+ - `intent.md` — understand WHY this change exists, what constraints apply
55
+ - `design.md` — understand HOW to approach it, what decisions are pending
56
+ - `tasks.md` — understand WHAT to implement and how to verify
57
+
58
+ Keep intent and design in mind throughout implementation. When making a decision during coding, check if it's listed under "Decisions to Make" — you're resolving the Decision Bridge in real-time.
59
+
60
+ 4. **Show current progress**
61
+
62
+ ```
63
+ ## Executing: <name>
64
+
65
+ Progress: N/M tasks complete
66
+ Remaining:
67
+ - [ ] Task description 1
68
+ - [ ] Task description 2
69
+ ```
70
+
71
+ 5. **Implement tasks sequentially**
72
+
73
+ For each pending task:
74
+
75
+ a. Show: `Working on task N/M: <description>`
76
+ b. Implement the code changes
77
+ c. Mark task complete in tasks.md: `- [ ]` → `- [x]`
78
+ d. Run the task's `verify:` check if one is defined
79
+ e. Commit atomically — one commit per task or logical unit
80
+ f. Continue to next task
81
+
82
+ <examples>
83
+ <good>
84
+ Working on task 3/5: Add rate-limit middleware
85
+
86
+ Reading src/middleware/index.ts — current chain: cors → helmet → bodyParser → routes
87
+ Installing express-rate-limit@7.1.0 (compatible with Express 4.18)
88
+ Added rateLimiter middleware after helmet at src/middleware/index.ts:14
89
+ Config: 100 req/15min window, Redis store via existing src/lib/redis.ts client
90
+
91
+ verify: `npm test -- --grep "rate-limit"` → 4 tests pass
92
+ verify: `curl -I localhost:3000/api/users` → X-RateLimit-Limit: 100 header present
93
+
94
+ Committed: "feat(middleware): add rate-limit middleware with Redis backing"
95
+ Why good: References exact files/lines, shows what was done and why,
96
+ runs specific verification commands, commits atomically with clear message.
97
+ </good>
98
+
99
+ <bad>
100
+ Working on task 3/5: Add rate-limit middleware
101
+ Done! Moving to task 4.
102
+ Why bad: No detail about what was implemented. No verification.
103
+ No commit. The user can't tell if this was done correctly.
104
+ </bad>
105
+
106
+ <good>
107
+ Working on task 2/4: Refactor auth to use JWT
108
+ PAUSE — design.md says "cookie-based sessions" (design.md:12) but this task
109
+ says "JWT". This contradicts the design.
110
+ Options:
111
+ A) Update design.md to JWT and continue (Recommended — JWT aligns with the API-first intent)
112
+ B) Implement cookie-based sessions as designed
113
+ C) Discuss the trade-offs before deciding
114
+ Why good: Catches a contradiction between plan and task. Stops to resolve
115
+ with specific options instead of silently making a decision.
116
+ </good>
117
+
118
+ <bad>
119
+ Working on task 2/4: Refactor auth to use JWT
120
+ Design says cookies but I'll use JWT since the task says so.
121
+ Why bad: Silently overrides the design without flagging the contradiction.
122
+ </bad>
123
+ </examples>
124
+
125
+ 6. **On completion**
126
+
127
+ Report status using completion codes:
128
+
129
+ | Status | When | What to show |
130
+ |--------|------|-------------|
131
+ | DONE | All tasks completed and verified | Full summary + `/whyspec:capture` prompt |
132
+ | DONE_WITH_CONCERNS | Tasks done but something feels off | Summary + concerns + `/whyspec:capture` |
133
+ | BLOCKED | Cannot proceed without input | Blocker details + resume command |
134
+ | NEEDS_CONTEXT | Missing information | Specific question about what's missing |
135
+
136
+ ```
137
+ ## DONE
138
+
139
+ Change: <name>
140
+ Progress: M/M tasks complete
141
+
142
+ Completed:
143
+ - [x] Task 1: description — committed as "feat: ..."
144
+ - [x] Task 2: description — committed as "feat: ..."
145
+
146
+ Ready to capture reasoning? Run /whyspec:capture
147
+ ```
148
+
149
+ ## Tools
150
+
151
+ | Tool | When to use | When NOT to use |
152
+ |------|------------|-----------------|
153
+ | **Read** | Read plan files (intent.md, design.md, tasks.md) BEFORE coding | Don't skip reading the plan |
154
+ | **Grep** | Find affected code before editing (e.g., all usages of a function you're changing) | Don't grep after editing — grep BEFORE to understand impact |
155
+ | **Edit** | Modify existing files — prefer Edit over Write for existing code | Don't rewrite entire files when a targeted edit suffices |
156
+ | **Write** | Create new files only | Don't use Write to modify existing files |
157
+ | **Bash** | Run tests (`npm test`), verify (`curl`, build commands), commit (`git commit`) | Don't run destructive git commands without asking |
158
+ | **AskUserQuestion** | When a task is unclear, or design contradicts implementation (see format below) | Don't ask about things you can determine from the plan or code |
159
+
160
+ ### AskUserQuestion Format (use for contradictions and blockers)
161
+
162
+ 1. **Re-ground**: "Executing task N/M of **<change>** — `<task description>`"
163
+ 2. **The contradiction/blocker**: What you found vs what the plan says
164
+ 3. **Options with recommendation**: Lettered choices with your pick
165
+
166
+ <examples>
167
+ <good>
168
+ Executing task 2/4 of **add-rate-limiting** — "Configure Redis store"
169
+
170
+ design.md says use the existing ioredis client (src/lib/redis.ts:8), but that
171
+ client uses `db: 0` which is shared with session data. Rate limit keys could
172
+ collide with session keys.
173
+
174
+ A) Use db: 0 with a `ratelimit:` key prefix (simple, small collision risk)
175
+ B) Create a separate client on db: 1 (isolated, adds ~2MB memory)
176
+ C) Reuse db: 0 but with a Redis namespace library
177
+
178
+ I'd recommend B — isolation is worth 2MB.
179
+ Why good: Specific blocker with evidence from code. Options with trade-offs.
180
+ </good>
181
+ </examples>
182
+
183
+ ## Escalation Protocol
184
+
185
+ | Situation | Attempts allowed | Action |
186
+ |-----------|-----------------|--------|
187
+ | Task is unclear or ambiguous | 0 — ask immediately | Ask ONE specific clarification question |
188
+ | Implementation keeps failing | 3 attempts max | Report: what was tried, what failed, what error |
189
+ | Design contradiction found | 0 — flag immediately | Present options, let user decide |
190
+ | Unexpected dependency or constraint | 1 attempt to resolve | If can't resolve, present findings and ask |
191
+
192
+ ## Rationalization Table
193
+
194
+ | If you catch yourself thinking... | Reality |
195
+ |----------------------------------|---------|
196
+ | "I'll read the plan later, the task name is clear enough" | The plan has constraints you'll violate. Read it. 15 seconds. |
197
+ | "One big commit is fine, I'll split it later" | You won't. Atomic commits are the contract. Do it now. |
198
+ | "This test is probably passing, no need to run it" | "Probably" is not evidence. Run the test. |
199
+ | "I'll skip the verify step for this trivial task" | Trivial tasks have trivial verifications. Run them anyway. |
200
+ | "The design is slightly wrong but my way is better" | Flag it. The user made the design for a reason you might not see. |
201
+
202
+ ## Guardrails
203
+
204
+ - **Read intent.md before coding** — every implementation decision should align with the stated intent and constraints.
205
+ - **Never skip tasks** — work through all tasks in order. If a task seems unnecessary, ask the user to remove it rather than silently skipping.
206
+ - **Commit atomically** — one commit per task or logical unit. Don't batch all changes into one commit.
207
+ - **Pause on unclear tasks** — don't guess at ambiguous requirements. Ask for clarification.
208
+ - **Pause on design issues** — if reality doesn't match the plan, stop and suggest design.md updates before continuing.
209
+ - **Mark checkboxes immediately** — update tasks.md after each task completion, not at the end.
210
+ - **Always prompt capture** — end every execution session with the `/whyspec:capture` suggestion.
@@ -0,0 +1,331 @@
1
+ ---
2
+ name: whyspec-plan
3
+ description: Use when planning a code change, capturing decisions before coding, or setting up the Decision Bridge.
4
+ argument-hint: "<change-name-or-description>"
5
+ ---
6
+
7
+ Plan a change — create intent.md, design.md, and tasks.md with the Decision Bridge.
8
+
9
+ When ready to implement, run `/whyspec:execute`
10
+
11
+ ---
12
+
13
+ **Input**: A change name (kebab-case) or description of what to build via ARGUMENTS.
14
+
15
+ ## Iron Law
16
+
17
+ **ACT FIRST, ASK ONLY WHEN STUCK.** The user invoked `/whyspec:plan` with a description of what they want. Your job is to structure their intent into plan files — not to interview them.
18
+
19
+ ## Red Flags — If You're Thinking This, STOP
20
+
21
+ - "I should ask what problem this solves" → The user TOLD you. Read ARGUMENTS.
22
+ - "Let me ask about constraints first" → Explore the codebase. Find them yourself.
23
+ - "I need more context before I can plan" → You have a codebase. Read it.
24
+ - "This is too vague to plan" → Even "fix auth" is enough. Read the auth code, find the issues, plan the fix.
25
+ - "I'll create a generic template and ask the user to fill it in" → That's not planning. That's homework assignment.
26
+
27
+ ## Steps
28
+
29
+ 1. **Parse ARGUMENTS and infer intent**
30
+
31
+ Read what the user typed. Derive a kebab-case name (e.g., "add user authentication" → `add-user-auth`).
32
+
33
+ **If ARGUMENTS is empty or a single ambiguous word** (e.g., just "plan" or "help"):
34
+ Ask ONE question: "What change are you planning?" — then proceed.
35
+
36
+ **If ARGUMENTS has any meaningful description** (even brief):
37
+ Proceed immediately. Do NOT ask forcing questions. The user told you what they want.
38
+
39
+ <examples>
40
+ <good>
41
+ User: `/whyspec:plan add dark mode support`
42
+ Agent: Creates change folder, writes intent.md capturing dark mode as the goal,
43
+ design.md with CSS custom properties vs class-based approach trade-off,
44
+ tasks.md with implementation steps.
45
+ Why good: User stated what they want. Agent structured it into plan files without interrogation.
46
+ </good>
47
+
48
+ <bad>
49
+ User: `/whyspec:plan add dark mode support`
50
+ Agent: "What problem does this solve? Who feels this pain today?"
51
+ Why bad: The user literally just told you — they want dark mode. Asking "what problem does
52
+ this solve" is patronizing checklist-walking. The answer is obvious from the input.
53
+ </bad>
54
+
55
+ <good>
56
+ User: `/whyspec:plan`
57
+ Agent: "What change are you planning?"
58
+ Why good: ARGUMENTS is empty. ONE question to get started is justified.
59
+ </good>
60
+
61
+ <bad>
62
+ User: `/whyspec:plan refactor auth middleware`
63
+ Agent: "What constraints exist? What does success look like? How will you know it works?"
64
+ Why bad: Three rounds of corporate interview questions. The user wants to refactor auth
65
+ middleware — explore the codebase to understand constraints, don't ask generic questions.
66
+ </bad>
67
+ </examples>
68
+
69
+ 2. **Create the change folder**
70
+
71
+ ```bash
72
+ whyspec plan --json "<name>"
73
+ ```
74
+
75
+ Parse the JSON response:
76
+ - `path`: The change directory (e.g., `.gitwhy/changes/add-auth/`)
77
+ - `templates`: Template content for intent.md, design.md, tasks.md
78
+ - `context`: Project context from config.yaml (constraints for you — do NOT copy into files)
79
+ - `rules`: Project-specific rules (constraints for you — do NOT copy into files)
80
+
81
+ If a change with that name already exists, ask: continue the existing change, or create a new one with a different name?
82
+
83
+ 3. **Explore codebase for context** (if the change touches existing code)
84
+
85
+ Before writing plan files, read relevant code to understand:
86
+ - Current architecture in the affected area
87
+ - Existing patterns and conventions
88
+ - Dependencies and constraints
89
+
90
+ <examples>
91
+ <good>
92
+ User wants to add rate limiting.
93
+ Agent reads src/middleware/index.ts, finds Express + helmet at line 12,
94
+ sees the middleware chain: cors → helmet → bodyParser → routes.
95
+ Writes design.md: "Insert express-rate-limit after helmet in the existing
96
+ chain at src/middleware/index.ts:14. Use sliding window algorithm.
97
+ Redis backing via existing ioredis client at src/lib/redis.ts."
98
+ Why good: References exact files, line numbers, existing dependencies.
99
+ Plan is grounded in code the agent actually read.
100
+ </good>
101
+
102
+ <bad>
103
+ User wants to add rate limiting.
104
+ Agent writes design.md: "Consider using express-rate-limit or a custom
105
+ middleware solution. Evaluate Redis vs in-memory storage."
106
+ Why bad: Generic advice from training data. Ignores the actual codebase.
107
+ Could have been written without reading a single file.
108
+ </bad>
109
+ </examples>
110
+
111
+ 4. **Create intent.md**
112
+
113
+ Write to `<path>/intent.md`. Here's a concrete filled-in example:
114
+
115
+ ```markdown
116
+ ## Why This Change Exists
117
+
118
+ POST /api/users returns 500 under load because we have no rate limiting.
119
+ Production logs show 12k requests/min from a single IP during the March 28 incident.
120
+
121
+ ## What It Enables
122
+
123
+ API stability under load. Prevents abuse without blocking legitimate traffic.
124
+
125
+ ## Decisions to Make
126
+
127
+ - [ ] Rate limit storage: Redis (shared across 3 instances) vs in-memory (simpler, single-instance only)?
128
+ - [ ] Limit granularity: per-IP vs per-user-token vs both?
129
+ - [ ] Response on limit: 429 with Retry-After header vs 429 with custom error body?
130
+
131
+ These checkboxes form the "before" side of the Decision Bridge.
132
+ They will be resolved during /whyspec:capture after implementation.
133
+
134
+ ## Constraints
135
+
136
+ - Must work with existing Express middleware chain (cors → helmet → bodyParser → routes)
137
+ - Redis (ioredis) already available at src/lib/redis.ts — prefer reuse over new dependency
138
+ - P99 latency budget: <5ms per request for rate limit check
139
+
140
+ ## Success Looks Like
141
+
142
+ - `npm test` passes with rate limit integration tests
143
+ - Siege test: 1000 req/s returns 429 after threshold, Retry-After header present
144
+ - No latency regression visible in existing API benchmark
145
+
146
+ ## Assumptions
147
+
148
+ - Redis is available in all environments (need to verify staging)
149
+ - Current ioredis client supports the rate limiting pattern we choose
150
+ ```
151
+
152
+ **IMPORTANT**: The "Decisions to Make" checkboxes are the Decision Bridge. Every unsettled design choice MUST be listed here.
153
+
154
+ <examples>
155
+ <good>
156
+ ## Decisions to Make
157
+ - [ ] Rate limit storage: Redis (shared across instances) vs in-memory (simpler, single-instance only)?
158
+ - [ ] Limit granularity: per-IP vs per-user-token vs both?
159
+ - [ ] Response on limit: 429 with Retry-After header vs 429 with custom error body?
160
+ Why good: Specific, actionable decisions with concrete options derived from the codebase.
161
+ </good>
162
+
163
+ <bad>
164
+ ## Decisions to Make
165
+ - [ ] What technology to use?
166
+ - [ ] How to implement it?
167
+ - [ ] What approach is best?
168
+ Why bad: Vague decisions that could apply to literally any change. Not useful.
169
+ </bad>
170
+ </examples>
171
+
172
+ 5. **Create design.md**
173
+
174
+ Write to `<path>/design.md`. Skip the trade-off matrix for simple changes:
175
+
176
+ ```markdown
177
+ ## Approach
178
+
179
+ [Chosen technical direction — 2-3 sentences grounded in the actual codebase]
180
+
181
+ ## Trade-off Matrix
182
+
183
+ | Option | [Criterion 1] | [Criterion 2] | [Criterion 3] |
184
+ |--------|---------------|---------------|---------------|
185
+ | Option A | ... | ... | ... |
186
+ | Option B | ... | ... | ... |
187
+
188
+ ## Architecture
189
+
190
+ [ASCII diagram showing the design — components, data flow, boundaries]
191
+
192
+ ## Questions to Resolve
193
+
194
+ - [ ] [Open question needing an answer before or during coding]
195
+
196
+ ## Risks & Unknowns
197
+
198
+ - [What could go wrong]
199
+
200
+ ## Dependencies
201
+
202
+ - [External libraries, APIs, services]
203
+ ```
204
+
205
+ 6. **Create tasks.md**
206
+
207
+ Write to `<path>/tasks.md`. Define verification FIRST — goal-backward planning:
208
+
209
+ ```markdown
210
+ ## Verification
211
+
212
+ What proves this change works — defined BEFORE tasks:
213
+
214
+ - [ ] [Verification criterion 1]
215
+ - [ ] [Verification criterion 2]
216
+
217
+ ## Tasks
218
+
219
+ - [ ] Task 1: [description]
220
+ verify: [how to verify this specific task]
221
+ - [ ] Task 2: [description]
222
+ verify: [verification step]
223
+ ```
224
+
225
+ Each task should be small enough for one atomic commit.
226
+
227
+ 7. **Show summary**
228
+
229
+ ```
230
+ ## Plan Created: <name>
231
+
232
+ <path>/
233
+ intent.md — WHY: problem, constraints, success criteria
234
+ design.md — HOW: approach, trade-offs, decisions to make
235
+ tasks.md — WHAT: verification criteria + implementation checklist
236
+
237
+ Decisions to make: N pending
238
+ Tasks: N defined
239
+
240
+ Ready to implement? Run /whyspec:execute
241
+ ```
242
+
243
+ ## Tools
244
+
245
+ | Tool | When to use | When NOT to use |
246
+ |------|------------|-----------------|
247
+ | **Glob** | Find files by pattern before writing plan (e.g., `src/middleware/**/*.ts`) | Don't glob blindly — know what area you're looking for |
248
+ | **Grep** | Search for patterns in code (e.g., existing rate limit logic, auth middleware) | Don't grep the whole repo — scope to relevant dirs |
249
+ | **Read** | Read specific files to understand architecture before planning | Don't read files unrelated to the change |
250
+ | **Bash** | Run `whyspec plan --json` (CLI-as-oracle). Run `git log` to understand recent changes | Don't run destructive commands |
251
+ | **AskUserQuestion** | ONLY when ARGUMENTS is empty or genuinely ambiguous (see format below) | Don't ask questions answerable by reading code |
252
+
253
+ ### Codebase First, Web Never-First
254
+
255
+ Read the codebase BEFORE considering web search. Web search is justified ONLY when:
256
+ - The change involves a library/framework not present in the codebase
257
+ - You need version-specific migration docs
258
+ - Security advisory lookup (CVEs)
259
+
260
+ Never search the web for: architecture decisions, "best practices", or how to use a library already in the codebase.
261
+
262
+ ### AskUserQuestion Format (use sparingly)
263
+
264
+ When you MUST ask (ARGUMENTS empty, or genuinely stuck after codebase exploration):
265
+
266
+ 1. **Re-ground**: "Planning **<change>** in `<project>` on `<branch>`"
267
+ 2. **What you found**: Show what you already discovered in the codebase
268
+ 3. **One specific question**: Not a checklist. One thing you need.
269
+ 4. **Recommendation**: "I'd suggest X because Y — your call"
270
+
271
+ <examples>
272
+ <good>
273
+ Planning **add-rate-limiting** in `my-api` on `main`
274
+
275
+ I found Express 4.18 with helmet middleware at src/middleware/index.ts,
276
+ and an existing ioredis client at src/lib/redis.ts.
277
+
278
+ Should the rate limit apply globally (all routes) or only to /api/* routes?
279
+ I'd suggest /api/* only — internal health checks shouldn't be rate-limited.
280
+ Why good: Shows what was already found. Asks ONE specific question with a recommendation.
281
+ </good>
282
+
283
+ <bad>
284
+ What problem does this solve? What constraints exist? How will you know it works?
285
+ Why bad: Three generic questions. No codebase context. Classic checklist-walking.
286
+ </bad>
287
+ </examples>
288
+
289
+ ## Escalation Protocol
290
+
291
+ If you hit any of these, STOP and ask the user (max 3 attempts before escalating):
292
+
293
+ | Situation | Action |
294
+ |-----------|--------|
295
+ | ARGUMENTS is genuinely ambiguous after codebase exploration | Ask ONE specific question, not a checklist |
296
+ | Multiple valid architectures with no clear winner | Present the trade-off matrix, ask user to pick |
297
+ | Change requires access or knowledge you don't have | State what you know, what you need, and ask |
298
+ | After 3 failed attempts to infer intent | Escalate: "I need more context. Here's what I've found so far: [findings]" |
299
+
300
+ ## Guardrails
301
+
302
+ - **Don't interrogate the user** — if ARGUMENTS contains a meaningful description, proceed. Only ask when ARGUMENTS is empty or genuinely ambiguous.
303
+ - **Ground plans in the codebase** — read relevant code before writing. Plans that ignore the actual architecture are useless.
304
+ - **Don't implement code** — this skill creates plan files only. Implementation happens in `/whyspec:execute`.
305
+ - **Don't skip "Decisions to Make"** — every unsettled design choice must be a checkbox. If you can't find any decisions, you haven't thought hard enough about the change.
306
+ - **Use CLI-as-oracle** — always call `whyspec plan --json` to create the folder. Don't create paths or generate IDs manually.
307
+ - **Apply `context` and `rules` as constraints** — they guide your writing but must NOT appear in the output files.
308
+ - **Verification before tasks** — in tasks.md, define what "done" looks like before listing the work.
309
+ - **Scale to the change** — a typo fix gets a 3-line intent and 1 task. A major refactor gets the full treatment.
310
+
311
+ ## Rationalization Table
312
+
313
+ | If you catch yourself thinking... | Reality |
314
+ |----------------------------------|---------|
315
+ | "I should ask the user some clarifying questions first" | Read the codebase. Most "clarifying questions" can be answered by reading code. |
316
+ | "The user's description is too vague to plan" | Even "fix auth" is plannable — read the auth code, find the issues, plan the fix. |
317
+ | "I need to understand the full architecture before planning" | Plan the change, not the universe. Read what's relevant, skip what's not. |
318
+ | "I should create a comprehensive plan with all sections" | Scale to the change. A 1-line fix gets a 3-line plan. Don't over-engineer. |
319
+ | "Let me ask about success criteria" | Infer from the change. "Success = tests pass + the thing works." Write it yourself. |
320
+ | "I'll write generic placeholder text and the user can fill it in" | That's not planning. Populate every field with specific, codebase-grounded content. |
321
+
322
+ ## Anti-Patterns
323
+
324
+ | If you're about to... | STOP — do this instead |
325
+ |----------------------|----------------------|
326
+ | Ask "What problem does this solve?" | Read ARGUMENTS — the user just told you |
327
+ | Ask "What constraints exist?" | Explore the codebase — find the constraints yourself |
328
+ | Ask "Who is this for?" | This is a code change, not a product pitch |
329
+ | Write a generic plan without reading code | Read the affected files first |
330
+ | Create a massive plan for a small fix | Scale the plan to match the change size |
331
+ | Skip Decisions to Make because "it's obvious" | If it's obvious, write it down — it takes 10 seconds |
@@ -0,0 +1,137 @@
1
+ ---
2
+ name: whyspec-search
3
+ description: Use when looking for why something was built a certain way or finding past decisions.
4
+ argument-hint: "<query> [--domain <domain>]"
5
+ ---
6
+
7
+ Search reasoning — find past decisions, contexts, and intent across all changes.
8
+
9
+ ---
10
+
11
+ **Input**: A search query string. Optionally include `--domain <domain>` to filter by domain.
12
+
13
+ ## When to Search
14
+
15
+ Search is not just a lookup tool — it's the **team knowledge check** before new work:
16
+
17
+ - **Before planning**: "Has anyone reasoned about auth in this codebase before?"
18
+ - **During debugging**: "Have we seen this error pattern before? What was the root cause?"
19
+ - **Before refactoring**: "Why was this built this way? Was it a deliberate decision or tech debt?"
20
+ - **During code review**: "Does this approach contradict past decisions?"
21
+
22
+ ## Steps
23
+
24
+ 1. **Run the search**
25
+
26
+ ```bash
27
+ whyspec search --json "<query>"
28
+ ```
29
+
30
+ If ARGUMENTS includes `--domain`:
31
+ ```bash
32
+ whyspec search --json "<query>" --domain "<domain>"
33
+ ```
34
+
35
+ Parse the JSON response — an array of scored results, each containing:
36
+ - `id`: Context ID (e.g., `ctx_a1b2c3d4`) or file identifier
37
+ - `title`: Context or intent title
38
+ - `change_name`: Name of the change
39
+ - `domain`: Auto-detected or specified domain
40
+ - `score`: Relevance score (title=100, reasoning=30, files=20, general=10)
41
+ - `matched_sections`: Which sections matched (title, reasoning, files, etc.)
42
+ - `path`: File path for retrieval
43
+ - `snippet`: Most relevant text excerpt
44
+
45
+ 2. **Display results with scores AND reasoning snippets**
46
+
47
+ <examples>
48
+ <good>
49
+ ## Search: "authentication"
50
+
51
+ Found 3 results:
52
+
53
+ 1. [score: 130] **JWT Auth with RS256** (add-auth)
54
+ Domain: authentication | Matched: title, reasoning
55
+ > "Chose RS256 over HS256 — allows key rotation without redeploying.
56
+ > Session stored in httpOnly cookie, not localStorage (XSS protection).
57
+ > Token expiry: 15min access, 7d refresh — balances security vs UX."
58
+
59
+ This decision affects your current work if you're touching auth tokens
60
+ or session management.
61
+
62
+ 2. [score: 30] **Database Migration Plan** (migrate-db)
63
+ Domain: database | Matched: reasoning
64
+ > "Considered token storage in DB but rejected — added 3ms latency per
65
+ > request. Chose Redis for session cache instead (src/lib/redis.ts)."
66
+
67
+ 3. [score: 20] **API Rate Limiting** (add-rate-limits)
68
+ Domain: api | Matched: files
69
+ > "src/middleware/auth.ts — modified to extract JWT sub claim for
70
+ > per-user rate limiting after authentication."
71
+
72
+ View full story: `/whyspec:show add-auth`
73
+ Narrow by domain: `/whyspec:search "authentication" --domain auth`
74
+ Why good: Shows the actual reasoning from past decisions. A developer
75
+ searching for "authentication" immediately sees WHY RS256 was chosen,
76
+ WHY httpOnly cookies, and WHERE token decisions connect to rate limiting.
77
+ The annotation "This decision affects..." connects past to present.
78
+ </good>
79
+
80
+ <bad>
81
+ ## Search: "authentication"
82
+
83
+ Found 3 results:
84
+
85
+ 1. **add-auth** — JWT Authentication Setup
86
+ 2. **migrate-db** — Database Migration Plan
87
+ 3. **add-rate-limits** — API Rate Limiting
88
+
89
+ Why bad: Just titles with no reasoning snippets. The developer has to
90
+ open each one to find the relevant decision. Defeats the purpose of search.
91
+ </bad>
92
+
93
+ <good>
94
+ ## Search: "why is the session timeout 15 minutes"
95
+
96
+ No results found for "why is the session timeout 15 minutes".
97
+
98
+ Suggestions:
99
+ - Try broader terms: "session", "timeout", "token expiry"
100
+ - Search by domain: `/whyspec:search "session" --domain auth`
101
+ - Check if this decision was captured: maybe it predates WhySpec adoption
102
+ Why good: Empty results get helpful guidance, not a dead end.
103
+ </good>
104
+
105
+ <bad>
106
+ ## Search: "why is the session timeout 15 minutes"
107
+
108
+ No results found.
109
+ Why bad: Dead end. No help. User is stuck.
110
+ </bad>
111
+ </examples>
112
+
113
+ 3. **Connect results to the current context**
114
+
115
+ If the search was triggered during planning or debugging, connect the findings:
116
+ - During `/whyspec:plan`: "Past decision in add-auth chose RS256 — your new feature should be compatible with this."
117
+ - During `/whyspec:debug`: "Similar bug was investigated in debug-token-expiry — root cause was clock skew between services."
118
+ - Standalone: Offer follow-up actions: `/whyspec:show <name>` or narrower search.
119
+
120
+ ## Tools
121
+
122
+ | Tool | When to use | When NOT to use |
123
+ |------|------------|-----------------|
124
+ | **Bash** | Run `whyspec search --json "<query>"` — the primary search mechanism | Don't search manually with grep |
125
+ | **Read** | Follow up on results — read full context files when the snippet isn't enough | Don't read every result; focus on high-scoring ones |
126
+ | **Grep** | Supplement: search code for implementations referenced in search results | Don't use grep as a replacement for whyspec search |
127
+
128
+ No AskUserQuestion — this is a display-only skill. Show results and offer follow-up commands.
129
+
130
+ ## Guardrails
131
+
132
+ - **Always show scores** — include the relevance score so the user understands ranking.
133
+ - **Always show snippets** — the reasoning excerpt is more useful than titles alone. Show the most relevant decision or trade-off text.
134
+ - **Handle empty results helpfully** — suggest broader terms, different keywords, or domain filters. Never just say "No results."
135
+ - **Don't fabricate results** — only display what the CLI returns. Never synthesize or guess at matches.
136
+ - **Connect past to present** — when results are clearly relevant to ongoing work, say so explicitly.
137
+ - **Search includes plan files** — the CLI searches intent.md and design.md too, not just context files. This finds planned decisions that haven't been captured yet.