@codename_inc/spectre 3.7.0

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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +411 -0
  3. package/bin/spectre.js +8 -0
  4. package/package.json +23 -0
  5. package/plugins/spectre/.claude-plugin/plugin.json +5 -0
  6. package/plugins/spectre/agents/analyst.md +122 -0
  7. package/plugins/spectre/agents/dev.md +70 -0
  8. package/plugins/spectre/agents/finder.md +105 -0
  9. package/plugins/spectre/agents/patterns.md +207 -0
  10. package/plugins/spectre/agents/reviewer.md +128 -0
  11. package/plugins/spectre/agents/sync.md +151 -0
  12. package/plugins/spectre/agents/tester.md +209 -0
  13. package/plugins/spectre/agents/web-research.md +109 -0
  14. package/plugins/spectre/commands/architecture_review.md +120 -0
  15. package/plugins/spectre/commands/clean.md +313 -0
  16. package/plugins/spectre/commands/code_review.md +408 -0
  17. package/plugins/spectre/commands/create_plan.md +117 -0
  18. package/plugins/spectre/commands/create_tasks.md +374 -0
  19. package/plugins/spectre/commands/create_test_guide.md +120 -0
  20. package/plugins/spectre/commands/evaluate.md +50 -0
  21. package/plugins/spectre/commands/execute.md +87 -0
  22. package/plugins/spectre/commands/fix.md +61 -0
  23. package/plugins/spectre/commands/forget.md +58 -0
  24. package/plugins/spectre/commands/handoff.md +161 -0
  25. package/plugins/spectre/commands/kickoff.md +115 -0
  26. package/plugins/spectre/commands/learn.md +15 -0
  27. package/plugins/spectre/commands/plan.md +170 -0
  28. package/plugins/spectre/commands/plan_review.md +33 -0
  29. package/plugins/spectre/commands/quick_dev.md +101 -0
  30. package/plugins/spectre/commands/rebase.md +73 -0
  31. package/plugins/spectre/commands/recall.md +5 -0
  32. package/plugins/spectre/commands/research.md +159 -0
  33. package/plugins/spectre/commands/scope.md +119 -0
  34. package/plugins/spectre/commands/ship.md +172 -0
  35. package/plugins/spectre/commands/sweep.md +82 -0
  36. package/plugins/spectre/commands/test.md +380 -0
  37. package/plugins/spectre/commands/ux_spec.md +91 -0
  38. package/plugins/spectre/commands/validate.md +343 -0
  39. package/plugins/spectre/hooks/hooks.json +34 -0
  40. package/plugins/spectre/hooks/scripts/bootstrap.cjs +99 -0
  41. package/plugins/spectre/hooks/scripts/handoff-resume.cjs +410 -0
  42. package/plugins/spectre/hooks/scripts/lib.cjs +83 -0
  43. package/plugins/spectre/hooks/scripts/load-knowledge.cjs +120 -0
  44. package/plugins/spectre/hooks/scripts/precompact-warning.cjs +19 -0
  45. package/plugins/spectre/hooks/scripts/register_learning.cjs +144 -0
  46. package/plugins/spectre/hooks/scripts/test_bootstrap.cjs +84 -0
  47. package/plugins/spectre/hooks/scripts/test_handoff-resume.cjs +858 -0
  48. package/plugins/spectre/hooks/scripts/test_load-knowledge.cjs +285 -0
  49. package/plugins/spectre/hooks/scripts/test_register-learning.cjs +146 -0
  50. package/plugins/spectre/skills/spectre-apply/SKILL.md +189 -0
  51. package/plugins/spectre/skills/spectre-guide/SKILL.md +358 -0
  52. package/plugins/spectre/skills/spectre-learn/SKILL.md +635 -0
  53. package/plugins/spectre/skills/spectre-learn/references/recall-template.md +31 -0
  54. package/plugins/spectre/skills/spectre-tdd/SKILL.md +111 -0
  55. package/src/config.test.js +134 -0
  56. package/src/install.test.js +273 -0
  57. package/src/lib/config.js +516 -0
  58. package/src/lib/constants.js +60 -0
  59. package/src/lib/doctor.js +168 -0
  60. package/src/lib/install.js +482 -0
  61. package/src/lib/knowledge.js +217 -0
  62. package/src/lib/paths.js +98 -0
  63. package/src/lib/project.js +473 -0
  64. package/src/main.js +150 -0
@@ -0,0 +1,82 @@
1
+ ---
2
+ description: 👻 | Light pass cleanup - clean, lint, test, commit
3
+ ---
4
+
5
+ ## Pre-Commit Sweep
6
+
7
+ You are preparing uncommitted or recently committed changes for check-in. Perform a systematic cleanup, then commit with descriptive conventional commits.
8
+
9
+ **Execution Style**: Fast, formulaic checklist. No subagents, no user approval gates. Execute each step and move on.
10
+
11
+ ### 1. Diff Sanity Check
12
+
13
+ - Review full diff for unintentional changes (whitespace-only edits, merge artifacts)
14
+ - Verify no accidentally staged files outside the intended scope
15
+ - Confirm no secrets, API keys, credentials, or sensitive data in diff
16
+
17
+ ### 2. Logging Audit
18
+
19
+ - Remove temporary/debug logging (console.log, print, debug flags, etc.)
20
+ - Preserve intentional logs: errors, critical warnings, key state transitions
21
+ - Verify log levels are appropriate for production context
22
+
23
+ ### 3. Code Hygiene
24
+
25
+ - Remove commented-out code (it's in git history if needed)
26
+ - Resolve or document any TODO/FIXME/HACK introduced in this session
27
+ - Remove hardcoded test values that should be config/env
28
+
29
+ ### 4. Opportunistic Dead Code Cleanup
30
+
31
+ Quick scan of changed files only — remove anything obviously dead, no deep investigation:
32
+
33
+ - Orphaned imports with no usage in the file
34
+ - Unused variables or functions declared but never referenced
35
+ - Commented-out code blocks
36
+ - Debug artifacts (debugger statements, leftover TODO/FIXME from this work)
37
+
38
+ Do not hunt for dead code beyond the changed files. This is opportunistic, not forensic.
39
+
40
+ ### 5. Lint (Strict)
41
+
42
+ - Run the project linter and **fix all violations** — no skipping, no eslint-disable
43
+ - Address structural lint issues (file size, complexity thresholds) by refactoring, not suppressing
44
+ - Verify .gitignore coverage (no temp files, build artifacts, IDE configs)
45
+
46
+ ### 6. Test
47
+
48
+ - Identify test files related to the changed files (co-located tests, imports, shared modules)
49
+ - Run those tests and the broader test suite
50
+ - Fix any failures caused by the changes
51
+ - Do NOT write new tests in this step — this is a sweep, not a test authoring pass
52
+
53
+ ### 7. Commit
54
+
55
+ Group changes into logical conventional commits. Commits are project history and critical context for LLMs and future developers — invest in making them descriptive.
56
+
57
+ **Format**: `type(scope): description`
58
+
59
+ **Types**: feat, fix, refactor, test, chore, docs, style, perf
60
+
61
+ **Grouping** — separate commits by concern:
62
+ - Feature/behavior additions → `feat`
63
+ - Refactors/cleanup with no behavior change → `refactor`
64
+ - Bug fixes → `fix`
65
+ - Test additions/updates → `test`
66
+ - Config/dependency changes → `chore`
67
+ - Documentation → `docs`
68
+
69
+ **Commit message quality**:
70
+ - Subject line answers: what changed and why (not "fix stuff" or "update files")
71
+ - Include scope to locate the change: `feat(auth): add token refresh on 401 response`
72
+ - If the commit touches multiple concerns, it's too big — split it
73
+ - Body (optional) adds context: motivation, trade-offs, what was considered and rejected
74
+
75
+ **Anti-patterns**:
76
+ - `fix: updates` — says nothing
77
+ - `refactor: clean up` — clean up what? why?
78
+ - One giant commit for unrelated changes
79
+
80
+ ### 8. Render Footer
81
+
82
+ Use `@skill-spectre:spectre-guide` skill for Next Steps footer.
@@ -0,0 +1,380 @@
1
+ ---
2
+ description: 👻 | Risk-aware test coverage & commit - primary agent
3
+ ---
4
+ # test: test coverage with risk-aware focus
5
+
6
+ ## Description
7
+
8
+ - **What** — Triage changes into risk tiers, dispatch @spectre:tester subagents to fix lint and write **risk-appropriate tests** (not brute-force 100% line coverage), and commit after each passing batch.
9
+ - **Outcome** — All lint issues fixed, surgical test coverage that maximizes confidence while minimizing token cost, incremental commits per batch, artifacts recorded in OUT_DIR.
10
+ - **Philosophy** — Test behaviors at boundaries, not implementation details. Prioritize code that can hurt users when it breaks. Skip tests that only measure "was this line executed?" without verifying correctness.
11
+
12
+ ## ARGUMENTS Input
13
+
14
+ Optional scope hint or specific files to focus on.
15
+
16
+ <ARGUMENTS> $ARGUMENTS </ARGUMENTS>
17
+
18
+ ## Instructions
19
+
20
+ - Primary agent plans and verifies; @tester subagents write test code
21
+ - Maximize parallelism: dispatch multiple @tester agents simultaneously, not sequentially
22
+ - Primary agent coordinates; subagents execute test writing in parallel batches
23
+ - No OUT_DIR artifacts — this is a lightweight flow
24
+ - Risk assessment is inline reasoning, not a classification phase
25
+ - Test behaviors at boundaries, not implementation details
26
+ - Skip tests for P3 files (types, configs, simple wrappers)
27
+ - when committing, —no-verify and eslint-disable, or committing code with eslint-disable, is expressly forbidden without the user’s explicit permission.
28
+
29
+ ### Why Risk-Weighted > 100% Line Coverage
30
+
31
+ **100% line coverage is a vanity metric that:**
32
+
33
+ - Treats all code equally (a payment handler vs a string formatter)
34
+ - Tests implementation details (brittle, breaks on refactor)
35
+ - Creates maintenance burden (tests that slow you down)
36
+ - Gives false confidence (100% coverage ≠ 100% correctness)
37
+ - Burns tokens on code that can't break in production
38
+
39
+ **Risk-weighted coverage instead:**
40
+
41
+ - Focuses testing effort where bugs cause user pain
42
+ - Tests behaviors and contracts, not internal wiring
43
+ - Creates tests that survive refactoring
44
+ - Catches actual bugs via mutation-resistant assertions
45
+ - Dramatically reduces token cost while increasing safety
46
+
47
+ ### Risk Tier Definitions
48
+
49
+ #### P0 — Critical (Must Test Thoroughly)
50
+
51
+ **Identification patterns:**
52
+
53
+ - Path contains: `auth`, `payment`, `security`, `crypto`, `session`, `token`
54
+ - File has `@critical` JSDoc/comment annotation
55
+ - Handles: user data mutations, financial transactions, PII, permissions
56
+ - API handlers for external consumers
57
+ - Database migration files
58
+
59
+ **Coverage requirements:**
60
+
61
+ - 100% **behavioral** coverage (every user-facing outcome has a test)
62
+ - All error paths tested with specific error assertions
63
+ - Edge cases for security-sensitive inputs (null, empty, malformed, overflow)
64
+ - Contract tests for all public APIs (schema validation)
65
+ - Mutation-resistant assertions (would a bug actually fail this test?)
66
+
67
+ **Test quality bar:**
68
+
69
+ ```typescript
70
+ // ✅ GOOD P0 test - tests behavior and catches real bugs
71
+ it('rejects payment when card is expired', async () => {
72
+ const result = await processPayment({ card: expiredCard, amount: 100 });
73
+ expect(result.status).toBe('DECLINED');
74
+ expect(result.reason).toBe('CARD_EXPIRED');
75
+ expect(chargeService.charge).not.toHaveBeenCalled(); // Side effect prevented
76
+ });
77
+
78
+ // ❌ BAD test - tests implementation, not behavior
79
+ it('calls validateCard', async () => {
80
+ await processPayment({ card, amount: 100 });
81
+ expect(validateCard).toHaveBeenCalledWith(card);
82
+ });
83
+ ```
84
+
85
+ #### P1 — Core (Test Key Behaviors)
86
+
87
+ **Identification patterns:**
88
+
89
+ - Main feature components (not utility wrappers)
90
+ - API route handlers (internal)
91
+ - State management (stores, reducers, contexts)
92
+ - Core business logic
93
+ - Data fetching/caching layers
94
+
95
+ **Coverage requirements:**
96
+
97
+ - Happy path coverage for all public functions
98
+ - Critical error paths (ones users would see)
99
+ - Contract tests at team boundaries (exported APIs other modules consume)
100
+ - No need to test internal helper functions
101
+ - No need to test every code branch, just primary behaviors
102
+
103
+ **Test quality bar:**
104
+
105
+ ```typescript
106
+ // ✅ GOOD P1 test - covers the behavior users care about
107
+ it('fetches and caches user profile', async () => {
108
+ const profile = await getUserProfile(userId);
109
+ expect(profile.name).toBe('Joe');
110
+
111
+ // Second call uses cache
112
+ await getUserProfile(userId);
113
+ expect(api.get).toHaveBeenCalledTimes(1);
114
+ });
115
+
116
+ // ❌ SKIP - internal implementation detail
117
+ it('calls normalizeUserData internally', () => { ... });
118
+ ```
119
+
120
+ #### P2 — Supporting (Test Public Surface Only)
121
+
122
+ **Identification patterns:**
123
+
124
+ - Utility functions and helpers
125
+ - Internal services not exposed to other teams
126
+ - Formatters, validators, transformers
127
+ - Hooks that compose other hooks
128
+ - Adapters and wrappers
129
+
130
+ **Coverage requirements:**
131
+
132
+ - Public exported functions: happy path only
133
+ - Skip internal/private functions entirely
134
+ - Skip trivial functions (single-line returns, simple compositions)
135
+ - Only test if the function has logic worth verifying
136
+
137
+ **Test quality bar:**
138
+
139
+ ```typescript
140
+ // ✅ GOOD P2 test - public util with actual logic
141
+ it('formats currency correctly', () => {
142
+ expect(formatCurrency(1234.5, 'USD')).toBe('$1,234.50');
143
+ expect(formatCurrency(1234.5, 'EUR')).toBe('€1,234.50');
144
+ });
145
+
146
+ // ❌ SKIP - trivial wrapper with no logic
147
+ // export const getFullName = (u) => `${u.first} ${u.last}`;
148
+ ```
149
+
150
+ #### P3 — Low Risk (Skip Testing)
151
+
152
+ **Identification patterns:**
153
+
154
+ - TypeScript type definitions (`.d.ts`)
155
+ - JSON/YAML configuration files
156
+ - CSS/SCSS/Tailwind styles
157
+ - Markdown documentation
158
+ - Constants and enums (no logic)
159
+ - Re-export barrels (`index.ts` that just re-exports)
160
+ - Simple component wrappers (just pass props through)
161
+ - Build scripts and tooling config
162
+
163
+ **Coverage requirements:**
164
+
165
+ - **NO TESTS REQUIRED** — Types are the test
166
+ - Type checking + linting is sufficient
167
+ - These files cannot break at runtime in ways tests would catch
168
+
169
+ ### Test Quality Requirements (All Tiers)
170
+
171
+ #### Each test MUST:
172
+
173
+ - **Test ONE behavior** — Single assertion focus, clear failure message
174
+ - **Use descriptive names** — `when_[condition]_then_[outcome]` or `[action]_should_[result]`
175
+ - **Assert outcomes, not calls** — Verify what happened, not what was invoked
176
+ - **Be refactor-resilient** — Test should pass if behavior unchanged, even if internals change
177
+ - **Catch real bugs** — Ask: "If I introduced a bug, would this test fail?"
178
+
179
+ #### Each test MUST NOT:
180
+
181
+ - **Mock implementation details** — Don't mock internal functions
182
+ - **Assert on call counts** — Unless testing side-effect prevention
183
+ - **Duplicate type coverage** — Don't test that TS types are correct
184
+ - **Test framework behavior** — Don't test that React renders or Express routes
185
+
186
+ #### Mutation Testing Mindset
187
+
188
+ For every test, ask: "If I changed the implementation to return a wrong value, would this test catch it?"
189
+
190
+ ```typescript
191
+ // ✅ Mutation-resistant — changing the discount calculation would fail this
192
+ it('applies 20% discount for premium users', () => {
193
+ expect(calculateTotal({ items: [100], userTier: 'premium' })).toBe(80);
194
+ });
195
+
196
+ // ❌ NOT mutation-resistant — always passes regardless of implementation
197
+ it('calls calculateDiscount', () => {
198
+ calculateTotal({ items: [100], userTier: 'premium' });
199
+ expect(calculateDiscount).toHaveBeenCalled();
200
+ });
201
+ ```
202
+
203
+ ### Contract Tests at Team Boundaries
204
+
205
+ When your code is consumed by other teams/modules, add contract tests:
206
+
207
+ ```typescript
208
+ // API Contract Test
209
+ describe('UserAPI contract', () => {
210
+ it('GET /users/:id returns UserResponse schema', async () => {
211
+ const response = await request(app).get('/users/123');
212
+ expect(response.body).toMatchSchema(UserResponseSchema);
213
+ });
214
+
215
+ it('returns standard APIError shape on 404', async () => {
216
+ const response = await request(app).get('/users/nonexistent');
217
+ expect(response.status).toBe(404);
218
+ expect(response.body).toMatchSchema(APIErrorSchema);
219
+ });
220
+ });
221
+
222
+ // Event Contract Test
223
+ describe('UserCreated event contract', () => {
224
+ it('emits event matching UserCreatedEvent schema', async () => {
225
+ await createUser({ name: 'Test' });
226
+ expect(eventBus.lastEvent).toMatchSchema(UserCreatedEventSchema);
227
+ });
228
+ });
229
+ ```
230
+
231
+ ## Steps
232
+
233
+ ### Step 1/4 — Discover Full Working Set and Plan
234
+
235
+ - **Action** — DiscoverFullWorkingSet:
236
+ - Validate commit_id if provided
237
+ - Gather: committed changes + staged + unstaged + untracked
238
+ - **Full Working Set** = UNION of all sources
239
+ - **Action** — RecordWorkingSet: Write `OUT_DIR/working_set.json`
240
+ - **Action** — BaselineLintFull: Run lint on ALL files in Full Working Set
241
+ - **Action** — MapDependencies: Build import/dep snapshot
242
+
243
+ ### Step (2/4) - Risk Assessment & Test Plan
244
+
245
+ - **Action** — InlineRiskCheck: Quick mental triage of changed files
246
+
247
+ **P0 Critical** (thorough coverage required):
248
+
249
+ - Paths containing: `auth`, `payment`, `security`, `crypto`, `session`, `token`
250
+ - Handles: user data mutations, financial transactions, PII, permissions
251
+ - Has `@critical` annotation
252
+
253
+ **P1 Core** (key behaviors):
254
+
255
+ - API handlers, feature components, state management, services
256
+
257
+ **P2 Supporting** (public surface only):
258
+
259
+ - Utils, helpers, hooks, formatters
260
+
261
+ **P3 Skip** (no tests):
262
+
263
+ - Type definitions (`.d.ts`), configs, styles, index barrels, simple wrappers
264
+
265
+ - **Action** — CreateTestPlan: Write 3-7 bullet test plan
266
+
267
+ - Format: `- [P{tier}] {file}: {behavior to test}`
268
+ - P0 files get multiple bullets (all behaviors + error paths)
269
+ - P1 files get 1-2 bullets (happy path + critical errors)
270
+ - P2 files get 1 bullet (public function smoke test)
271
+ - P3 files listed as "SKIP — {reason}"
272
+
273
+ - **Action** - Update`OUT_DIR/working_set.json` with risk tier categorization.
274
+
275
+ ### Step (3/4) - Write Tests & Verify
276
+
277
+ - **Action** — DispatchTestWriter: Spawn MULTIPLE @spectre:tester subagents IN PARALLEL
278
+
279
+ - **Parallelization Strategy**:
280
+ - Partition test plan items into independent batches (by file or logical grouping)
281
+ - Dispatch one @spectre:tester per batch — aim for 3-5 parallel agents for medium scope, up to 8 for large scope
282
+ - Each agent receives: its batch of test plan items, file paths, risk tier context
283
+ - **Critical**: Use a single message with multiple Task tool calls to launch all agents simultaneously
284
+ - **Batching Heuristics**:
285
+ - P0 files: 1 agent per file (thorough coverage requires focus)
286
+ - P1 files: Group 2-3 related files per agent
287
+ - P2 files: Group 3-5 files per agent (lighter coverage)
288
+ - Instruct each: "Write behavioral tests, assert outcomes not calls, mutation-resistant"
289
+ - Wait for all agents to complete before proceeding to lint/test verification
290
+
291
+ - **Action** — RunLint: Execute linter; fix violations
292
+
293
+ - **If** lint fails → autofix first, then manual fix
294
+ - **Else** → continue
295
+
296
+ - **Action** — RunTests: Execute full test suite
297
+
298
+ - **If** tests fail → analyze failure, fix via @spectre:tester or direct edit
299
+ - **Else** → continue
300
+
301
+ - **Action** — VerifyQuality: Spot-check 1-2 tests
302
+
303
+ - Confirm: tests assert behaviors, would catch real bugs, survive refactoring
304
+ - **If** test quality poor → rework via @@spectre:tester
305
+ - **Else** → continue
306
+
307
+ ### Step (4/4) - Commit
308
+
309
+ - **Action** — CommitPlanningArtifacts: Gather and commit planning/working docs FIRST
310
+ - Check for uncommitted files in `OUT_DIR/`:
311
+ - `working_set.json` (scope and risk tier categorization)
312
+ - Any other `.md` or `.json` artifacts created during this flow
313
+ - Check for uncommitted docs in `docs/tasks/{branch_name}/` or related planning directories
314
+ - **If** uncommitted planning artifacts exist:
315
+ - Stage all: `git add docs/tasks/{branch_name}/ OUT_DIR/`
316
+ - Commit: `docs(test): add test planning artifacts for {branch_name}`
317
+
318
+ - **Action** — GroupChanges: Organize code changes into logical commits
319
+
320
+ - Group by: feat/fix/refactor/test/chore
321
+ - Tests can be bundled with their feature or separate (your judgment)
322
+
323
+ - **Action** — CommitAll: Create conventional commits for code changes
324
+
325
+ - Format: `type(scope): description`
326
+ - Each commit answers: What changed and why?
327
+
328
+ - **Action** — RenderFooter: Render Next Steps footer using `@skill-spectre:spectre-guide` skill (contains format template and spectre command options)
329
+
330
+ ## Next Steps
331
+
332
+ See `@skill-spectre:spectre-guide` skill for footer format and command options.
333
+
334
+ ## Success Criteria
335
+
336
+ **Step 1 - Analyze Diff**:
337
+
338
+ - [ ] Scope identified (files changed) and documented
339
+
340
+ - [ ] Behaviors changed listed (not just file names)
341
+
342
+ **Step 2 - Risk Assessment & Test Plan**:
343
+
344
+ - [ ] Each changed file assigned P0-P3 tier
345
+
346
+ - [ ] Test plan created with 3-7 bullets
347
+
348
+ - [ ] P3 files explicitly marked SKIP
349
+
350
+ **Step 3 - Write Tests & Verify**:
351
+
352
+ - [ ] Multiple @spectre:tester agents dispatched in parallel (not sequential)
353
+
354
+ - [ ] Test plan partitioned into independent batches
355
+
356
+ - [ ] All agents launched in single message (parallel tool calls)
357
+
358
+ - [ ] P0 files have thorough behavioral coverage
359
+
360
+ - [ ] P1 files have key path coverage
361
+
362
+ - [ ] P2 files have public surface coverage
363
+
364
+ - [ ] P3 files have NO tests (confirmed skipped)
365
+
366
+ - [ ] Lint passes
367
+
368
+ - [ ] All tests pass
369
+
370
+ - [ ] Test quality spot-checked
371
+
372
+ **Step 4 - Commit**:
373
+
374
+ - [ ] Changes grouped logically
375
+
376
+ - [ ] Conventional commit format used
377
+
378
+ - [ ] Single Next Steps footer rendered
379
+
380
+ - [ ] Next steps guide read and options sourced
@@ -0,0 +1,91 @@
1
+ ---
2
+ description: Define the User Flows and generate a UX Spec - primary agent
3
+ ---
4
+ # ux_spec: Define Exactly How the Feature Works
5
+
6
+ Transform product requirements into a definitive behavioral specification. Two stages: align on user flows, then generate detailed spec. Output: `ux.md` ready for implementation.
7
+
8
+ <ARGUMENTS> $ARGUMENTS </ARGUMENTS>
9
+
10
+ ---
11
+
12
+ # STAGE 1: Flow Discovery & Alignment
13
+
14
+ **Goal**: Align on HOW the feature works before specifying details.
15
+
16
+ ## Step 1 — Understand the Feature
17
+
18
+ 1. **Read requirements**: `docs/tasks/{branch}/task_summary.md` and `docs/tasks/{branch}/specs/prd.md`
19
+ 2. **Research patterns**: Find existing screens/components similar to what we're building, note conventions
20
+ 3. **Identify journeys**: List user goals, entry points, and completion states
21
+
22
+ ## Step 2 — Present User Flows
23
+
24
+ Write each flow as a narrative walkthrough:
25
+
26
+ **Per flow include**: Goal, Entry point, Journey steps (User sees → User does → System responds), Decision points with branches, Success state, Questions where ambiguity exists
27
+
28
+ After writing all flows, prompt:
29
+
30
+ > **User Flows for Review**
31
+ >
32
+ > I've mapped {N} flows: {list with one-line summaries}
33
+ >
34
+ > Please review: Are these the right flows? Any missing? Do journeys feel right? Answer flagged questions.
35
+ >
36
+ > Reply with feedback, or **"Flows approved"** to proceed.
37
+
38
+ **Wait for approval. If feedback → revise and re-present. If approved → Stage 2.**
39
+
40
+ ---
41
+
42
+ # STAGE 2: Detailed Specification
43
+
44
+ **Gate**: Only proceed after explicit flow approval.
45
+
46
+ ## Step 3 — Clarify Remaining Details
47
+
48
+ Review approved flows for gaps: component behaviors, edge cases, state definitions.
49
+
50
+ If significant gaps, ask 3-5 targeted questions (empty states, error handling, loading, limits). Save to `clarifications/ux_clarifications_{timestamp}.md`, prompt user to read, incorporate answers.
51
+
52
+ ## Step 4 — Write the Specification
53
+
54
+ Generate complete spec with these sections:
55
+
56
+ ### Required Sections
57
+
58
+ 1. **Overview** — What this feature is, problem it solves, primary user goal (1 paragraph)
59
+ 2. **Screens** — Every screen: name, purpose (1 line), navigation relationships
60
+ 3. **Flows** — Formalized from Stage 1 with alternate paths (validation fail, cancel, network error)
61
+ 4. **Layouts** — Per screen: header/main/footer structure + responsive behavior (desktop >1024, tablet 768-1024, mobile <768)
62
+ 5. **Components** — Each interactive element: purpose, location, states (default, hover, active, disabled, loading, error)
63
+ 6. **Interactions** — Table format: Element | Action | Result (exhaustive)
64
+ 7. **States** — Table format: State | Trigger | Appearance | Available Actions (empty, loading, loaded, error)
65
+ 8. **Content** — Exact copy: page titles, buttons, empty states, error messages, confirmation dialogs
66
+ 9. **Edge Cases** — Limits/boundaries, null/long data handling, permissions, offline/network failures
67
+ 10. **Accessibility** — Tab order, keyboard actions (Enter/Space/Escape), screen reader announcements, focus management
68
+
69
+ Save to `docs/tasks/{branch}/ux.md`
70
+
71
+ Prompt:
72
+
73
+ > **UX Specification Complete**
74
+ >
75
+ > Written to `{path}`. Please review: Any behaviors wrong or missing? Edge cases not covered?
76
+ >
77
+ > Reply with feedback, or **"Approved"** to finalize.
78
+
79
+ **Wait for approval.**
80
+
81
+ ## Step 5 — Handoff
82
+
83
+ Confirm completion with summary: screens specified, flows documented, components with states, edge cases and accessibility covered.
84
+
85
+ Read `.spectre/next_steps_guide.md` and render Next Steps footer:
86
+
87
+ ```
88
+ Next Steps | Phase: Scope | Status: UX Complete
89
+ Recommendation: {contextual next action}
90
+ Options: /create_plan, /create_tasks, /tdd
91
+ ```