specweave 1.0.78 → 1.0.79

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "specweave",
3
- "version": "1.0.78",
3
+ "version": "1.0.79",
4
4
  "description": "Spec-driven development framework for Claude Code. AI-native workflow with living documentation, intelligent agents, and multilingual support (9 languages). Enterprise-grade traceability with permanent specs and temporary increments.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -86,75 +86,20 @@ grep -ril "keyword" .specweave/docs/internal/
86
86
  <!-- /SECTION -->
87
87
 
88
88
  <!-- SECTION:lsp -->
89
- ## LSP-Enhanced Exploration (ACTIVE - Claude Code 2.0.74+)
89
+ ## LSP-Enhanced Exploration
90
90
 
91
- **LSP is POWERFUL - USE IT ACTIVELY** for semantic code understanding. 100x faster and more accurate than grep.
91
+ **USE LSP ACTIVELY** for semantic code understanding (100x faster than grep).
92
92
 
93
- **WHEN to use LSP (PROACTIVE):**
93
+ **Key operations**: `findReferences` (before refactoring) | `goToDefinition` (navigate) | `documentSymbol` (structure) | `hover` (types) | `getDiagnostics` (errors)
94
94
 
95
- | Scenario | LSP Operation | Why Use It |
96
- |----------|---------------|------------|
97
- | Before refactoring | `findReferences` | Know ALL usages before changing |
98
- | Navigate to source | `goToDefinition` | Jump directly to implementation |
99
- | Understand module | `documentSymbol` | See complete structure/hierarchy |
100
- | Check types | `hover` | Get accurate signatures, JSDoc |
101
- | Code quality | `getDiagnostics` | Errors, warnings before commit |
102
-
103
- **ACTIVE Usage Examples:**
104
- ```bash
105
- # Before renaming a function - find ALL references
106
- "Use LSP findReferences to find all usages of calculateTax"
107
-
108
- # Navigate to implementation instead of grep
109
- "Use goToDefinition to find where PaymentService is defined"
110
-
111
- # Get accurate type signature
112
- "Use hover to check the type of processOrder function"
113
-
114
- # Check for errors before suggesting changes
115
- "Use getDiagnostics on this file to check for issues"
116
-
117
- # Understand module structure
118
- "Use documentSymbol to map the API surface of auth.ts"
119
- ```
120
-
121
- **Smart Integration (ADR-0222):**
122
- - LSP is EXEMPT from "Code First, Tools Second" rule
123
- - LSP responses are small (~100-5000 bytes), no context bloat
124
- - Use LSP for precision, code execution for bulk processing
125
-
126
- **Install Language Servers** (required):
95
+ **Install**:
127
96
  ```bash
128
- # TypeScript/JavaScript
129
- npm install -g typescript-language-server typescript
130
-
131
- # Python
132
- pip install python-lsp-server
133
-
134
- # Go
135
- go install golang.org/x/tools/gopls@latest
136
-
137
- # C#
138
- brew install omnisharp # or: dotnet tool install -g omnisharp
97
+ npm install -g typescript-language-server typescript # TS/JS
98
+ pip install python-lsp-server # Python
99
+ go install golang.org/x/tools/gopls@latest # Go
139
100
  ```
140
101
 
141
- **Configuration** (optional, `.lsp.json` in project root):
142
- ```json
143
- {
144
- "vtsls": {
145
- "command": "typescript-language-server",
146
- "args": ["--stdio"],
147
- "extensionToLanguage": { ".ts": "typescript", ".tsx": "typescriptreact", ".js": "javascript" }
148
- }
149
- }
150
- ```
151
-
152
- **Best Practices**:
153
- - **ALWAYS use findReferences** before any refactoring
154
- - **ALWAYS use goToDefinition** instead of grep for navigation
155
- - **Use documentSymbol** to understand module organization
156
- - **Use hover** to verify type signatures before changes
157
- - Combine with Explore agent for comprehensive understanding
102
+ **Best Practices**: ALWAYS use `findReferences` before refactoring | Use `goToDefinition` instead of grep | Combine with Explore agent
158
103
  <!-- /SECTION -->
159
104
 
160
105
  <!-- SECTION:structure -->
@@ -163,54 +108,25 @@ brew install omnisharp # or: dotnet tool install -g omnisharp
163
108
  ```
164
109
  .specweave/
165
110
  ├── increments/####-name/ # metadata.json, spec.md, tasks.md
166
- ├── docs/internal/
167
- ├── specs/{project}/ # Living docs (check before implementing!)
168
- │ ├── architecture/adr/ # ADRs (check before design decisions!)
169
- │ └── operations/ # Runbooks
111
+ ├── docs/internal/specs/ # Living docs (check before implementing!)
112
+ └── architecture/adr/ # ADRs (check before design decisions!)
170
113
  └── config.json
171
114
  ```
172
115
 
173
- ### ⚠️ CRITICAL: Multi-Repo Project Paths (MANDATORY)
174
-
175
- **ALL multi-project repositories MUST be created in `repositories/` folder - NEVER in project root!**
116
+ **Increment folders - ONLY at root**: metadata.json, spec.md, plan.md, tasks.md
117
+ **Everything else → subfolders**: reports/ (validation, QA) | logs/{YYYY-MM-DD}/ | scripts/ | docs/domain/ | backups/
176
118
 
119
+ **Multi-repo projects**: Create in `repositories/` folder (NEVER project root!)
177
120
  ```
178
- ❌ FORBIDDEN (pollutes root):
179
121
  my-project/
180
- ├── frontend/ ← WRONG!
181
- ├── backend/ ← WRONG!
182
- ├── shared/ ← WRONG!
122
+ ├── repositories/ # All repos here: frontend/, backend/, shared/
183
123
  └── .specweave/
184
-
185
- ✅ REQUIRED (clean structure):
186
- my-project/
187
- ├── repositories/
188
- │ ├── frontend/ ← CORRECT!
189
- │ ├── backend/ ← CORRECT!
190
- │ └── shared/ ← CORRECT!
191
- └── .specweave/
192
- ```
193
-
194
- **This applies to ALL cases:**
195
- - GitHub multi-repo → `repositories/`
196
- - Azure DevOps multi-repo → `repositories/`
197
- - Bitbucket multi-repo → `repositories/`
198
- - **Local git multi-repo → `repositories/`** ← Same rule!
199
- - Monorepo with multiple packages → `repositories/` or `packages/`
200
-
201
- **When spec.md has `projects:` array:**
202
- ```yaml
203
- projects:
204
- - id: my-api
205
- scope: "Backend API"
206
124
  ```
207
- The implementation path is ALWAYS: `repositories/my-api/` (NOT `my-api/` in root!)
208
125
 
209
- **Multi-repo permissions**: In `.claude/settings.json`:
126
+ **Permissions** (`.claude/settings.json`):
210
127
  ```json
211
- {"permissions":{"allow":["Write(//**)","Edit(//**)"],"additionalDirectories":["repositories"],"defaultMode":"bypassPermissions"}}
128
+ {"permissions":{"allow":["Write(//**)","Edit(//**)"],"additionalDirectories":["repositories"]}}
212
129
  ```
213
- **Path syntax**: `//path` = absolute | `/path` = relative to settings file | `**` = recursive | `additionalDirectories` = explicit working dirs
214
130
  <!-- /SECTION -->
215
131
 
216
132
  <!-- SECTION:taskformat required -->
@@ -287,94 +203,20 @@ vi.mock('fs', () => ({ readFile: vi.fn() }));
287
203
  <!-- SECTION:api -->
288
204
  ## API Development (OpenAPI-First)
289
205
 
290
- **For API projects only.** Skip this section if your project has no REST/GraphQL endpoints.
291
-
292
- **Use OpenAPI as the source of truth for API documentation.** Postman collections and environments are derived from OpenAPI and .env.
293
-
294
- ### Configuration (`.specweave/config.json`)
206
+ **For API projects only.** OpenAPI = source of truth Postman derived from it.
295
207
 
208
+ **Config** (`.specweave/config.json`):
296
209
  ```json
297
- {
298
- "apiDocs": {
299
- "enabled": true,
300
- "openApiPath": "openapi.yaml",
301
- "generatePostman": true,
302
- "postmanPath": "postman-collection.json",
303
- "postmanEnvPath": "postman-environment.json",
304
- "generateOn": "on-increment-done",
305
- "baseUrl": "http://localhost:3000"
306
- }
307
- }
308
- ```
309
-
310
- ### Generated Artifacts
311
-
312
- | File | Purpose | Source |
313
- |------|---------|--------|
314
- | `openapi.yaml` | API specification (source of truth) | Framework decorators/annotations |
315
- | `postman-collection.json` | API requests for testing | Derived from OpenAPI |
316
- | `postman-environment.json` | Variables (baseUrl, tokens, etc.) | Derived from .env |
317
-
318
- ### OpenAPI Generation by Framework
319
-
320
- | Framework | Auto-Generation | Setup |
321
- |-----------|-----------------|-------|
322
- | **NestJS** | `@nestjs/swagger` | Decorators auto-generate OpenAPI |
323
- | **FastAPI** | Built-in | Auto-generates at `/openapi.json` |
324
- | **Express** | `swagger-jsdoc` | JSDoc comments → OpenAPI |
325
- | **Spring Boot** | `springdoc-openapi` | Annotations auto-generate |
326
- | **Go/Gin** | `swag` | Comments → OpenAPI |
327
-
328
- ### Workflow
329
-
330
- ```
331
- ┌─────────────────────────────────────────────────────────────┐
332
- │ Code (decorators/annotations) │
333
- │ ↓ (auto-generated or manual) │
334
- │ openapi.yaml (SOURCE OF TRUTH - version controlled) │
335
- │ ↓ (derived on /sw:done or /sw:api-docs) │
336
- │ ├── postman-collection.json (requests with {{baseUrl}}) │
337
- │ └── postman-environment.json (variables from .env) │
338
- └─────────────────────────────────────────────────────────────┘
210
+ {"apiDocs":{"enabled":true,"openApiPath":"openapi.yaml","generatePostman":true,"generateOn":"on-increment-done"}}
339
211
  ```
340
212
 
341
- ### Commands
213
+ **Frameworks**: NestJS (`@nestjs/swagger`) | FastAPI (built-in) | Express (`swagger-jsdoc`) | Spring Boot (`springdoc-openapi`)
342
214
 
343
- ```bash
344
- # Generate all API docs (OpenAPI + Postman collection + environment)
345
- /sw:api-docs --all
346
-
347
- # Generate only OpenAPI
348
- /sw:api-docs --openapi
349
-
350
- # Generate only Postman collection from existing OpenAPI
351
- /sw:api-docs --postman
352
-
353
- # Generate only environment file from .env
354
- /sw:api-docs --env
355
-
356
- # Validate existing OpenAPI spec
357
- /sw:api-docs --validate
358
-
359
- # Generate on increment close (automatic if enabled)
360
- /sw:done 0001 # → triggers API doc generation
361
- ```
362
-
363
- ### Postman Import
364
-
365
- After generation:
366
- 1. Postman → Import → `postman-collection.json`
367
- 2. Postman → Environments → Import → `postman-environment.json`
368
- 3. Fill in secret values (marked as secret type, values empty)
369
- 4. Select environment from dropdown
215
+ **Commands**: `/sw:api-docs --all` (OpenAPI + Postman) | `--openapi` | `--postman` | `--env` | `--validate`
370
216
 
371
- ### When Docs Update
217
+ **Flow**: Code decorators → `openapi.yaml` → `/sw:done` or `/sw:api-docs` → Postman collection + env
372
218
 
373
- | `generateOn` Setting | When API Docs Regenerate |
374
- |---------------------|--------------------------|
375
- | `on-increment-done` | When closing increment (recommended) |
376
- | `on-api-change` | When API files change (hook-based) |
377
- | `manual` | Only via `/sw:api-docs` command |
219
+ **Import**: Postman Import collection + env Fill secrets → Select env
378
220
  <!-- /SECTION -->
379
221
 
380
222
  <!-- SECTION:limits -->
@@ -421,495 +263,114 @@ Task format: `**AC**: AC-US1-01, AC-US1-02` (CRITICAL for linking)
421
263
  <!-- /SECTION -->
422
264
 
423
265
  <!-- SECTION:mcp -->
424
- ## External Service Connection (MCP + Smart Fallbacks)
266
+ ## External Service Connection
425
267
 
426
- **Core principle: Never fight connection issues. Use the path of least resistance.**
427
-
428
- ### Connection Priority (ALWAYS follow this order)
429
-
430
- ```
431
- MCP Server → REST API → SDK/Client → CLI → Direct Connection
432
- ↑ ↓
433
- BEST WORST
434
- ```
435
-
436
- ### Service Connection Matrix
437
-
438
- | Service | BEST Method | Fallback | AVOID |
439
- |---------|-------------|----------|-------|
440
- | **Supabase** | MCP Server | REST API / JS Client | Direct `psql` (IPv6 issues) |
441
- | **Cloudflare** | `wrangler` + OAuth | REST API | Manual curl |
442
- | **PostgreSQL** | MCP / Pooler (6543) | `psql` with pooler | Direct port 5432 |
443
- | **MongoDB** | Atlas Data API | MCP / Driver | Direct connection |
444
- | **Redis** | Upstash REST | MCP | `redis-cli` (TCP issues) |
445
- | **AWS** | CLI with SSO | SDK | Hardcoded keys |
446
- | **Vercel** | CLI with OAuth | REST API | Manual deploys |
447
-
448
- ### Quick Setup Commands
268
+ **Priority**: MCP Server REST API CLI Direct Connection
449
269
 
270
+ **Setup**:
450
271
  ```bash
451
- # MCP Servers (one-time, restart Claude Code after)
272
+ # MCP (restart Claude Code after)
452
273
  npx @anthropic-ai/claude-code-mcp add supabase
453
- npx @anthropic-ai/claude-code-mcp add postgres
454
-
455
- # CLI Auth (persistent OAuth sessions)
456
- wrangler login # Cloudflare
457
- vercel login # Vercel
458
- aws configure sso # AWS
459
- supabase login # Supabase CLI
460
-
461
- # Verify auth status
462
- wrangler whoami && vercel whoami && aws sts get-caller-identity
463
- ```
464
-
465
- ### Supabase (Most Common Issues)
466
-
467
- ```bash
468
- # ❌ DON'T: Direct psql or supabase db push (IPv6 fails)
469
- supabase db push # Often fails with connection errors
470
-
471
- # ✅ DO: Use REST API or MCP
472
- # REST API works everywhere - no network issues
473
- curl "${SUPABASE_URL}/rest/v1/table" \
474
- -H "apikey: ${SUPABASE_ANON_KEY}"
475
274
 
476
- # For migrations: Use Supabase Dashboard SQL Editor
477
- # OR use connection pooler (port 6543, NOT 5432)
478
- DATABASE_URL="postgresql://postgres.[ref]:[pass]@aws-0-region.pooler.supabase.com:6543/postgres"
479
- ```
480
-
481
- ### Cloudflare Workers
482
-
483
- ```bash
484
- # One-time login (saves OAuth session)
485
- wrangler login
486
-
487
- # All operations then work:
488
- wrangler deploy # Deploy worker
489
- echo "value" | wrangler secret put KEY # Set secret
490
- wrangler kv:key put --binding=KV k v # KV operations
491
- wrangler d1 execute DB --command "SQL" # D1 database
275
+ # CLI Auth
276
+ wrangler login && vercel login && supabase login
492
277
  ```
493
278
 
494
- ### Auto-Detection (Run Before External Ops)
279
+ **Supabase**: Use REST API or pooler (port 6543), AVOID direct `psql`
280
+ **Cloudflare**: `wrangler login` once, then `wrangler deploy/secret put/kv:key put`
495
281
 
282
+ **Check credentials before ops**:
496
283
  ```bash
497
- # Check configured services
498
- grep -E "SUPABASE_|DATABASE_URL|MONGODB|UPSTASH|CF_API" .env 2>/dev/null
284
+ grep -E "SUPABASE_|DATABASE_URL|CF_API" .env 2>/dev/null
499
285
  wrangler whoami 2>/dev/null
500
- aws sts get-caller-identity 2>/dev/null
501
286
  ```
502
-
503
- **Full reference**: See `/sw:service-connect` skill for complete patterns.
504
287
  <!-- /SECTION -->
505
288
 
506
289
  <!-- SECTION:autoexecute -->
507
- ## Auto-Execute Rule (CRITICAL)
508
-
509
- **NEVER output "Manual Step Required" or "Next Steps" when credentials are available.**
510
-
511
- ### The Golden Rule
512
-
513
- ```
514
- ❌ FORBIDDEN: "Manual Step Required: Open Supabase SQL Editor..."
515
- ❌ FORBIDDEN: "Next Steps: 1. Run wrangler deploy..."
516
- ❌ FORBIDDEN: "Execute this SQL in your database console..."
290
+ ## Auto-Execute Rule
517
291
 
518
- REQUIRED: Execute commands directly using available credentials
519
- ```
520
-
521
- ### Decision Tree
522
-
523
- ```
524
- Credentials in .env? ──YES──→ EXECUTE IMMEDIATELY
525
-
526
- NO
527
-
528
-
529
- ASK for credentials (don't show manual steps!)
530
-
531
-
532
- Save to .env → EXECUTE IMMEDIATELY → Continue
533
- ```
292
+ **NEVER** output "Manual Step Required" when credentials exist. **EXECUTE DIRECTLY.**
534
293
 
535
- ### Credential Lookup (MANDATORY before any external operation)
294
+ **Flow**: Check `.env` If exists, EXECUTE | If missing, ASK for credentials → Save → EXECUTE
536
295
 
296
+ **Check before ops**:
537
297
  ```bash
538
- # 1. Check .env
539
298
  grep -E "(SUPABASE_|DATABASE_URL|CF_API_|GITHUB_TOKEN)" .env 2>/dev/null
540
-
541
- # 2. Check CLI auth
542
- supabase status 2>/dev/null # Supabase
543
- wrangler whoami 2>/dev/null # Cloudflare
544
- gh auth status 2>/dev/null # GitHub
545
- aws sts get-caller-identity 2>/dev/null # AWS
546
-
547
- # 3. Use MCP server if available
548
- # MCP servers provide direct API access
549
- ```
550
-
551
- ### Auto-Execute Examples
552
-
553
- ```bash
554
- # Supabase SQL execution
555
- if [ -n "$DATABASE_URL" ]; then
556
- psql "$DATABASE_URL" -f schema.sql # ✅ Execute directly
557
- fi
558
-
559
- # Wrangler secrets
560
- if wrangler whoami 2>/dev/null; then
561
- echo "$SECRET" | wrangler secret put MY_SECRET # ✅ Execute directly
562
- wrangler deploy # ✅ Deploy directly
563
- fi
564
- ```
565
-
566
- ### If Credentials Missing → ASK, Don't Show Manual Steps
567
-
568
- ```markdown
569
- 🔐 **Credential Required**
570
-
571
- I need your DATABASE_URL to execute the migration.
572
-
573
- **Paste your connection string:**
574
- [I will save to .env and execute automatically]
299
+ wrangler whoami 2>/dev/null && gh auth status 2>/dev/null
575
300
  ```
576
301
  <!-- /SECTION -->
577
302
 
578
303
  <!-- SECTION:auto -->
579
304
  ## Auto Mode (Autonomous Execution)
580
305
 
581
- **Auto mode enables continuous autonomous execution** until all tasks are complete.
582
-
583
- ### 🚨 CRITICAL: Zero Manual Steps in Auto Mode
584
-
585
- **Auto mode MUST be fully autonomous. NEVER ask user to:**
586
- - Open a web dashboard (Supabase, AWS Console, etc.)
587
- - Copy/paste SQL into an editor
588
- - Run commands manually
589
- - Click buttons in UIs
590
-
591
- **If you need external access:**
592
- 1. Check for credentials in `.env`
593
- 2. Use CLI tools (`supabase`, `wrangler`, `gh`, `aws`)
594
- 3. Use MCP servers for direct API access
595
- 4. If credentials missing → ASK for them, save to `.env`, then EXECUTE
596
-
597
- ### 🧪 Test Execution Loop (MANDATORY)
598
-
599
- **After EVERY implementation task, run tests in a self-healing loop:**
600
-
601
- ```bash
602
- # 1. Run unit/integration tests
603
- npm test # or: npx vitest run
604
-
605
- # 2. If UI exists, run E2E tests
606
- npx playwright test
607
-
608
- # 3. If tests fail → FIX → RE-RUN (max 3 attempts)
609
- ```
610
-
611
- **Test Loop Pattern (Ralph Loop):**
612
- ```
613
- ┌─────────────────────────────────────────────────────────────┐
614
- │ IMPLEMENT → TEST → FAIL? → FIX → TEST → PASS → NEXT TASK │
615
- │ ↑________________↓ │
616
- │ (max 3 iterations) │
617
- └─────────────────────────────────────────────────────────────┘
618
- ```
619
-
620
- **E2E Test Execution (when UI exists):**
621
- ```bash
622
- # Install Playwright browsers if needed
623
- npx playwright install --with-deps chromium
624
-
625
- # Run E2E tests with proper reporting
626
- npx playwright test --reporter=list
627
-
628
- # On failure, capture screenshot/trace
629
- npx playwright test --trace on
630
- ```
631
-
632
- **Focus on MVP Critical Paths:**
633
- 1. **Authentication flows** (login, logout, register)
634
- 2. **Core business transactions** (create, update, delete)
635
- 3. **Payment/checkout flows** (if applicable)
636
- 4. **Data integrity scenarios**
637
-
638
- ### ⚠️ Pragmatic Completion (NOT 100% Blindly!)
639
-
640
- **Don't blindly follow 100% completion rules!** Reality:
641
- - Specs have bugs, ambiguities, conflicts
642
- - Requirements change mid-implementation
643
- - Some planned tasks become irrelevant
644
- - Edge cases may not be worth the effort
645
-
646
- **Smart Completion Criteria:**
647
- ```
648
- ┌─────────────────────────────────────────────────────────────┐
649
- │ MUST COMPLETE (block release): │
650
- │ • MVP critical paths (auth, core CRUD, payments) │
651
- │ • Security-sensitive flows │
652
- │ • Data integrity operations │
653
- │ • User-facing error handling │
654
- ├─────────────────────────────────────────────────────────────┤
655
- │ SHOULD COMPLETE (aim for, but pragmatic): │
656
- │ • Edge case handling │
657
- │ • Performance optimizations │
658
- │ • Nice-to-have features │
659
- ├─────────────────────────────────────────────────────────────┤
660
- │ CAN SKIP/DEFER (if blocking progress): │
661
- │ • Conflicting requirements (flag and ask user) │
662
- │ • Over-engineered edge cases │
663
- │ • Tasks made obsolete by other changes │
664
- └─────────────────────────────────────────────────────────────┘
665
- ```
666
-
667
- **When to STOP and ask user:**
668
- - Spec conflicts with another spec
669
- - Task seems unnecessary given implementation
670
- - Edge case would require major refactoring
671
- - Requirement is ambiguous
672
-
673
- ### 🧑‍🤝‍🧑 Smart Test User Strategy
674
-
675
- **Create test users strategically, not blindly:**
676
-
677
- ```typescript
678
- // Good: Create users with specific roles/states
679
- const testUsers = {
680
- admin: { email: 'admin@test.com', role: 'admin' },
681
- regularUser: { email: 'user@test.com', role: 'user' },
682
- premiumUser: { email: 'premium@test.com', plan: 'premium' },
683
- blockedUser: { email: 'blocked@test.com', status: 'blocked' },
684
- };
685
-
686
- // When to create multiple test users:
687
- // ✅ Testing role-based access control
688
- // ✅ Testing subscription tiers
689
- // ✅ Testing user states (active, blocked, pending)
690
- // ✅ Testing multi-user interactions (sharing, permissions)
691
-
692
- // When ONE test user is enough:
693
- // ✅ Basic CRUD operations
694
- // ✅ Form validation
695
- // ✅ UI component tests
696
- // ✅ API endpoint tests (mocked auth)
697
- ```
698
-
699
- **E2E Test User Setup:**
700
- ```typescript
701
- // playwright/fixtures/users.ts
702
- export const testUsers = {
703
- // Seeded in database before tests
704
- admin: { id: 'test-admin-001', email: 'admin@test.local' },
705
- user: { id: 'test-user-001', email: 'user@test.local' },
706
- };
707
-
708
- // Use fixtures, don't create users per test!
709
- test.use({ storageState: 'playwright/.auth/user.json' });
710
- ```
711
-
712
- ### 🔐 E2E Authentication (CRITICAL - Avoid Flaky Tests!)
713
-
714
- **Auth is the #1 cause of flaky E2E tests. Be ULTRASMART:**
715
-
716
- | Strategy | Speed | Reliability | Use When |
717
- |----------|-------|-------------|----------|
718
- | **storageState** | ⚡⚡⚡ | ⭐⭐⭐ | Default - login ONCE, reuse |
719
- | **API auth** | ⚡⚡ | ⭐⭐⭐ | When UI is unstable |
720
- | **UI login per test** | ⚡ | ⭐ | Only testing login flow |
721
-
722
- **Playwright Auth Setup (MANDATORY):**
723
-
724
- ```typescript
725
- // playwright/auth.setup.ts - Global setup
726
- import { test as setup } from '@playwright/test';
727
-
728
- setup('authenticate', async ({ page }) => {
729
- await page.goto('/login');
730
- await page.fill('[name="email"]', 'test@example.com');
731
- await page.fill('[name="password"]', 'testpass123');
732
- await page.click('button[type="submit"]');
733
- await page.waitForURL('/dashboard');
734
- await page.context().storageState({ path: 'playwright/.auth/user.json' });
735
- });
736
- ```
737
-
738
- ```typescript
739
- // playwright.config.ts - Reuse auth state
740
- projects: [
741
- { name: 'setup', testMatch: /.*\.setup\.ts/ },
742
- {
743
- name: 'chromium',
744
- use: { storageState: 'playwright/.auth/user.json' },
745
- dependencies: ['setup'],
746
- },
747
- ]
748
- ```
306
+ **Continuous execution until all tasks complete.**
749
307
 
750
- **Common Auth Fixes:**
308
+ ### Zero Manual Steps
751
309
 
752
- | Problem | Solution |
753
- |---------|----------|
754
- | Session expires | Increase TTL for test env |
755
- | Rate limited | Use API auth, seed users |
756
- | Captcha blocks | Disable in test env |
757
- | OAuth fails | Mock provider |
310
+ **NEVER ask user to**: Open dashboards | Copy/paste | Run commands manually
758
311
 
759
- **Auto Mode E2E Checklist:**
760
- ```
761
- ✅ Test users seeded with known passwords
762
- ✅ Auth state files generated
763
- ✅ Tests DON'T login (except login flow tests)
764
- ✅ Captcha/2FA disabled in test env
765
- ```
312
+ **Instead**: Check `.env` → Use CLI (`wrangler`, `gh`, `aws`) → Use MCP → If missing, ASK → Save → EXECUTE
766
313
 
767
- ### 🔄 Continuous Refactoring (Part of Auto Loop)
314
+ ### Test Loop (MANDATORY)
768
315
 
769
- **As tests grow, REFACTOR proactively:**
316
+ **After EVERY task**: `npm test` → If E2E exists: `npx playwright test` → Fail? FIX → Rerun (max 3x) → Pass → Next
770
317
 
771
- ```
772
- After every 3-5 tasks:
773
- 1. Review test organization → Extract shared fixtures
774
- 2. Review code duplication → Extract utilities
775
- 3. Review file sizes → Split if >300 lines
776
- 4. Review imports → Consolidate, remove unused
777
- ```
318
+ **Pattern**: IMPLEMENT → TEST → FAIL? → FIX → TEST → PASS → NEXT
778
319
 
779
- **Refactoring Triggers:**
780
- - Test file > 200 lines → Split by feature
781
- - Duplicate test setup → Extract to fixtures
782
- - Same assertion pattern 3+ times → Create helper
783
- - Source file > 300 lines → Extract module
320
+ **MVP paths**: Auth (login/logout) | Core CRUD | Payments | Data integrity
784
321
 
785
- ### 📊 Test Status Reporting (MANDATORY in Auto Mode)
322
+ ### Pragmatic Completion
786
323
 
787
- **After EVERY task, report test status to user:**
788
-
789
- ```markdown
790
- ## 🧪 Test Status Report
324
+ **Don't blindly follow 100%!** Specs have bugs, requirements change, some tasks become irrelevant.
791
325
 
792
- | Type | Status | Pass/Total | Coverage |
793
- |------|--------|------------|----------|
794
- | Unit | | 42/42 | 87% |
795
- | Integration | ✅ | 12/12 | - |
796
- | E2E | ⚠️ | 8/10 | - |
326
+ **MUST**: MVP paths | Security flows | Data integrity | User-facing errors
327
+ **SHOULD**: Edge cases | Performance | Nice-to-haves
328
+ **CAN SKIP**: Conflicts (ask user) | Over-engineered cases | Obsolete tasks
797
329
 
798
- **Failing tests:**
799
- - `auth.spec.ts:45` - Login redirect not working
800
- - `checkout.spec.ts:112` - Payment timeout
330
+ **STOP & ASK** if: Spec conflicts | Task seems unnecessary | Requirement ambiguous
801
331
 
802
- **Next:** Fixing E2E failures before continuing...
803
- ```
332
+ ### Test User Strategy
804
333
 
805
- ### 🏠 Local-First Development
334
+ **Multiple users**: RBAC | Subscription tiers | User states | Multi-user interactions
335
+ **One user**: CRUD | Form validation | Component tests | Mocked auth
806
336
 
807
- **If no deployment instructions provided, BUILD AND TEST LOCALLY FIRST:**
337
+ **E2E**: Seed DB with known users Use fixtures → `storageState` (auth once, reuse)
808
338
 
809
- ```
810
- 1. Implement feature locally
811
- 2. Run ALL tests (unit, integration, E2E)
812
- 3. Verify everything works
813
- 4. THEN ask user about deployment preferences
814
- ```
339
+ ### E2E Authentication
815
340
 
816
- **Don't assume deployment target!** Ask user:
817
- ```markdown
818
- 🚀 **Deployment Options**
341
+ **Auth = #1 flaky test cause.** Use `storageState` (login ONCE, reuse) | API auth (UI unstable) | UI login (only for login tests)
819
342
 
820
- Your scraper is ready and all tests pass locally.
343
+ **Setup**: Global auth.setup.ts Save to `playwright/.auth/user.json` Reuse in config
821
344
 
822
- **Where would you like to deploy?**
823
- - Vercel Cron (serverless, free tier available)
824
- - Railway (always-on, $5/mo)
825
- - GitHub Actions (CI-based, free)
826
- - Local cron (self-hosted)
827
- - Other?
828
- ```
345
+ **Fixes**: Session expires? Increase TTL | Rate limited? API auth | Captcha? Disable in test env
829
346
 
830
- ### 🔧 Infrastructure Decision-Making
347
+ **Checklist**: Seed users | Gen auth state | Tests DON'T login | Disable captcha/2FA
831
348
 
832
- **For scrapers, cron jobs, background tasks - ULTRATHINK on best approach:**
349
+ ### Refactoring & Reporting
833
350
 
834
- ```
835
- ┌─────────────────────────────────────────────────────────────┐
836
- │ INFRASTRUCTURE DECISION TREE │
837
- ├─────────────────────────────────────────────────────────────┤
838
- │ Scraper/Cron Job: │
839
- │ ├─ Frequency < 1/hour → Vercel Cron, GitHub Actions │
840
- │ ├─ Frequency ≥ 1/hour → Railway, Render, dedicated server │
841
- │ ├─ Heavy compute → Dedicated VM, Docker container │
842
- │ └─ Real-time → Always-on server, WebSocket │
843
- │ │
844
- │ Data Storage: │
845
- │ ├─ Simple KV → Upstash Redis, Vercel KV │
846
- │ ├─ Relational → Supabase, PlanetScale, Neon │
847
- │ ├─ Document → MongoDB Atlas, Supabase │
848
- │ └─ Time-series → TimescaleDB, InfluxDB │
849
- │ │
850
- │ File Storage: │
851
- │ ├─ Static assets → Cloudflare R2, S3 │
852
- │ └─ Large files → S3, GCS, Backblaze B2 │
853
- └─────────────────────────────────────────────────────────────┘
854
- ```
351
+ **Every 3-5 tasks**: Extract fixtures | Remove duplication | Split if >300 lines | Clean imports
855
352
 
856
- **When implementing scrapers/cron jobs:**
857
- 1. **Ultrathink** on best hosting options given requirements
858
- 2. **Research** rate limits, costs, reliability
859
- 3. **Propose** 2-3 options with trade-offs
860
- 4. **Build locally first** with tests
861
- 5. **Deploy** only after user confirms target
353
+ **Triggers**: Test >200 lines? Split | Duplicate setup? Extract | Same assertion 3x? Helper
862
354
 
863
- ### For Claude Code Users
355
+ **Report after EVERY task**: Pass/Total | Coverage | Failing tests | Next steps
864
356
 
865
- Auto mode uses Claude Code's Stop Hook to create a feedback loop:
866
- - `/sw:do` continues until all tasks complete
867
- - `/sw:auto-status` shows session progress
868
- - `/sw:cancel-auto` stops autonomous execution
357
+ ### Local-First & Infrastructure
869
358
 
870
- Session state stored in `.specweave/state/auto-session.json`.
359
+ **No deploy instructions?** Build locally → Test all → Verify → ASK user about deploy target
871
360
 
872
- ### For Non-Claude AI Systems
361
+ **Infra Decision Tree**:
362
+ - **Cron**: <1/hr → Vercel/GitHub Actions | ≥1/hr → Railway/Render
363
+ - **Storage**: KV → Upstash/Vercel KV | SQL → Supabase/Neon | Docs → MongoDB | Files → R2/S3
873
364
 
874
- If using SpecWeave with other AI systems (GPT, Gemini, etc.), implement this loop pattern:
365
+ **Process**: Ultrathink options Research costs Propose 2-3 Build local User confirms → Deploy
875
366
 
876
- ```bash
877
- # Bash loop for autonomous execution
878
- while true; do
879
- # Check if all tasks complete
880
- TOTAL=$(grep -c "^### T-" .specweave/increments/*/tasks.md 2>/dev/null || echo "0")
881
- DONE=$(grep -c '\[x\].*completed' .specweave/increments/*/tasks.md 2>/dev/null || echo "0")
882
-
883
- if [ "$TOTAL" -gt 0 ] && [ "$DONE" -ge "$TOTAL" ]; then
884
- echo "All tasks complete!"
885
- break
886
- fi
887
-
888
- # Feed prompt to your AI
889
- cat PROMPT.md | your-ai-cli
890
-
891
- # Safety: max iterations
892
- ITER=$((ITER + 1))
893
- if [ "$ITER" -ge 100 ]; then
894
- echo "Max iterations reached"
895
- break
896
- fi
897
- done
898
- ```
367
+ ### Implementation
899
368
 
900
- **Key Concepts**:
901
- - **Completion Detection**: Check tasks.md for `[x] completed` status
902
- - **Completion Tag**: Output `<auto-complete>DONE</auto-complete>` when finished
903
- - **Max Iterations**: Always set a limit (default: 100)
904
- - **Human Gates**: Pause for sensitive ops (deploy, publish, force-push)
369
+ **Claude Code**: `/sw:do` (continues till done) | `/sw:auto-status` (progress) | `/sw:cancel-auto` (stop)
905
370
 
906
- **Human-Gated Operations** (require manual approval):
907
- - `npm publish`, `git push --force`, `rm -rf /`
908
- - Any `production` deployment
909
- - API key or credential changes
910
- - Database migrations (`drop`, `delete from`, `migrate`)
371
+ **Other AI**: Loop check tasks.md `[x]` status → Max 100 iter → Human gates for: publish, force-push, prod deploy, migrations
911
372
 
912
- **Circuit Breaker Pattern**: If external API (GitHub, JIRA) fails 3+ times, queue operations and continue.
373
+ **Circuit Breaker**: External API fails 3x? Queue & continue
913
374
  <!-- /SECTION -->
914
375
 
915
376
  <!-- SECTION:docs -->