Skip to content

Latest commit

 

History

History
1132 lines (835 loc) · 23.9 KB

File metadata and controls

1132 lines (835 loc) · 23.9 KB

Vibecoding OS - Appendices

Extended examples, detailed case studies, and deep dives


Appendix A: SEAL Learning Evolution Examples

These show how patterns develop over time across real tasks.

A.1: Triage Pattern Evolution

Task 1: "Change button color to blue"

AI Behavior:

Phase 0: TRIAGE
Classification: COMPLEX (default behavior, no patterns yet)
Reason: Not sure if this needs planning

Proceeding to Phase 1: Planning...

User feedback: Rating 3/5

"This was way too much. It's just a color change. Didn't need all that planning."

SEAL records:

Pattern: Triage
- Request: "change button color"
- Classification: COMPLEX (wrong)
- Should have been: TRIVIAL
- Confidence: 0.10 (very uncertain)

Task 2: "Update header text to say 'Welcome'"

AI Behavior:

Phase 0: TRIAGE
Classification: COMPLEX (still following default)

User feedback: Rating 3/5

"Again, this is trivial. Just a text change."

SEAL records:

Pattern: Triage - Updated
- Added: "change color" → TRIVIAL
- Added: "update text" → TRIVIAL
- Confidence: 0.25 (starting to form)

Task 3: "Add a contact form with name, email, message fields"

AI Behavior:

Phase 0: TRIAGE
Checking patterns... no match for "add form"
Classification: COMPLEX (correct default)

User feedback: Rating 5/5

"Perfect. This needed planning and you did it right."

SEAL records:

Pattern: Triage - Updated
Trivial indicators:
- "change color" → confidence +0.2 = 0.45
- "update text" → confidence +0.2 = 0.45
- "fix typo" → added = 0.33

Complex indicators:
- "add form" → confirmed = 0.60
- "new feature" → confirmed = 0.60

Task 5: "Change the submit button color to green"

AI Behavior:

Phase 0: TRIAGE
Checking patterns...
Match found: "change ... color"
Pattern confidence: 0.45 (emerging)

Classification: TRIVIAL (learned!)
Skipping to Phase 2: Coding

User feedback: Rating 5/5

"Perfect! Fast and exactly what I needed."

SEAL records:

Pattern: Triage - Confidence Increase
Trivial indicators:
- "change color" → confidence +0.2 = 0.65
- "update text" → 0.65
- "fix typo" → 0.53

Pattern now RELIABLE (confidence ≥ 0.65)

Task 10: "Make the logo bigger"

AI Behavior:

Phase 0: TRIAGE
Checking patterns...
Match found: visual change pattern
Related to "change color", "update styling"

Classification: TRIVIAL (learned!)

User feedback: Rating 5/5

SEAL records:

Pattern: Triage - Strong Pattern Formed
Trivial indicators (confidence ≥ 0.80):
- Visual changes: color, size, spacing
- Text updates: content, labels, headings
- Simple styling: CSS-only changes

Complex indicators (confidence ≥ 0.85):
- "add", "create", "new" + feature/component
- "fix" + functional issue
- Database, API, auth keywords

Pattern now BEST PRACTICE

A.2: Discovery Pattern Evolution

Task 2: Planning a login form

AI asks:

Phase 1.1: DISCOVERY

Questions:
1. What state management library should we use?
2. Do you prefer Redux or Context API?
3. Should we use FormIk or React Hook Form?

User response:

"I don't know what any of that means. I just want a login form."

Rating: 3/5 - "Questions were confusing"

SEAL records:

Discovery Pattern
Ineffective Questions:
- "state management library" → user confused
- Technical library comparisons → user confused
- Jargon without context → user confused

Confidence: 0.15 (avoid these)

Task 3: Planning a dashboard

AI asks (revised approach):

Phase 1.1: DISCOVERY

Questions:
1. What information should appear on the dashboard?
2. Should users be able to customize what they see?
3. Does it need to work on mobile phones?

User response:

"Show user stats, recent activity, and notifications. No customization needed for now. Yes, mobile is important."

Rating: 5/5 - "Clear questions, useful answers"

SEAL records:

Discovery Pattern - Updated
Effective Questions:
- "What should appear..." → outcome-focused
- "Should users be able to..." → clear yes/no
- "Does it need to work on..." → practical constraint

Confidence: 0.60 (emerging pattern)

Task 7: Planning a search feature

AI asks:

Phase 1.1: DISCOVERY

Questions:
1. What should users be able to search for?
2. Should search work while offline?
3. How fast does search need to be (instant or can take a second)?

User response:

"Search products by name or category. No offline needed. Can take a second, that's fine."

Rating: 5/5 - "Exactly the right questions"

SEAL records:

Discovery Pattern - Best Practice Formed
Effective Questions (confidence ≥ 0.85):
- "What should [action]..." → outcome-focused
- "Should this work [constraint]..." → practical
- "How [quality attribute]..." → measurable

Avoid (confidence 0.90 to AVOID):
- Technical jargon
- Implementation details
- Library/framework names
- Architectural patterns

Pattern: ASK OUTCOMES, NOT IMPLEMENTATIONS

A.3: Coding Style Pattern Evolution

Task 3: Create Button component

AI creates:

// components/Button.tsx
import React from 'react';

class Button extends React.Component {
  render() {
    return (
      <button style={{...this.props.style}}>
        {this.props.children}
      </button>
    );
  }
}

export default Button;

User feedback: Rating 3/5

"Use functional components, not classes. And use CSS modules, not inline styles."

SEAL records:

Coding Style Pattern
- Class components → user doesn't want (0.10 - avoid)
- Functional components → user prefers (0.60 - emerging)
- Inline styles → user doesn't want (0.10 - avoid)
- CSS Modules → user prefers (0.60 - emerging)

Task 6: Create Card component

AI creates (applying learned pattern):

// components/Card/index.tsx
import React from 'react';
import styles from './styles.module.css';

interface CardProps {
  title: string;
  children: React.ReactNode;
}

export function Card({ title, children }: CardProps) {
  return (
    <div className={styles.card}>
      <h2 className={styles.title}>{title}</h2>
      <div className={styles.content}>
        {children}
      </div>
    </div>
  );
}

User feedback: Rating 5/5

"Perfect! This is exactly the style I want."

SEAL records:

Coding Style Pattern - Confidence Increased
Component Structure:
- Functional components with hooks → 0.80 (reliable)
- Directory: ComponentName/index.tsx → 0.80
- Separate styles file → 0.80
- CSS Modules → 0.80
- TypeScript interfaces → 0.75

Naming:
- PascalCase for components → 0.85
- camelCase for functions → 0.85
- Props destructured in parameters → 0.80

Task 12: Create Modal component

AI creates (automatic application):

// components/Modal/index.tsx
import React, { useState } from 'react';
import styles from './styles.module.css';

interface ModalProps {
  isOpen: boolean;
  onClose: () => void;
  title: string;
  children: React.ReactNode;
}

export function Modal({ isOpen, onClose, title, children }: ModalProps) {
  if (!isOpen) return null;

  return (
    <div className={styles.overlay} onClick={onClose}>
      <div className={styles.modal} onClick={(e) => e.stopPropagation()}>
        <div className={styles.header}>
          <h2>{title}</h2>
          <button onClick={onClose} className={styles.closeButton}>
            ×
          </button>
        </div>
        <div className={styles.content}>
          {children}
        </div>
      </div>
    </div>
  );
}
/* components/Modal/styles.module.css */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: white;
  border-radius: 8px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

/* etc... */

User feedback: Rating 5/5

"No iteration needed. You nailed it first try."

SEAL records:

Coding Style Pattern - PROJECT STANDARD
Confidence: 0.95

This is now the automatic style for all components.
Zero iteration needed. Pattern is project identity.

Component Structure (AUTO-APPLY):
✓ Functional with hooks
✓ Directory: ComponentName/
✓ Files: index.tsx, styles.module.css, (types.ts if complex)
✓ Props interface with descriptive names
✓ Destructured props
✓ CSS Modules with BEM-like naming
✓ TypeScript strict mode
✓ Loading states for async
✓ Error boundaries where appropriate

Appendix B: Complete Task Walkthroughs

B.1: Login Form (Full Complex Task)

User Request: "I need a login form where users can enter email and password, then log in."


Phase 0: TRIAGE

Phase 0: TRIAGE

Analysis:
- Keywords: "login", "form", "authentication"
- Matches complex indicators (confidence: 0.92)
- Requires: API integration, validation, state management, error handling

Classification: COMPLEX
Proceeding to Phase 1: Planning

Phase 1.1: DISCOVERY

Phase 1.1: DISCOVERY

Discovery Questions:

1. Where should login credentials be verified?
   (Backend API, Firebase, Auth0, etc.)

2. What should happen after successful login?
   (Redirect to dashboard? Store user data? Session token?)

3. What should happen if login fails?
   (Show error message? Allow retry? Forgot password link?)

4. Should this work on mobile devices?

⏸️ Waiting for your confirmation to proceed.

User responds:

  1. Backend API at /api/login
  2. Redirect to /dashboard and store token
  3. Show error "Invalid email or password"
  4. Yes, mobile important

Phase 1.2: RESEARCH

Phase 1.2: RESEARCH

Checking PROJECT-STATE.md Section 5.B...
Checking existing codebase...

Relevant Findings:

**Existing Patterns** (Section 5.B.5):
- Component structure: Functional + CSS Modules (confidence: 0.95)
- Form handling: useState + try/catch (confidence: 0.88)
- API calls: fetch with error handling (confidence: 0.92)

**Existing Code**:
- src/lib/api.ts: API client with auth helpers
- src/components/Input/: Reusable input component (use this)
- src/styles/form.module.css: Form styling conventions

**Tech Stack**:
- Next.js 14
- TypeScript
- CSS Modules
- No form library (using vanilla React)

⏸️ Waiting for your confirmation to proceed.

Phase 1.3: BRAINSTORM

Phase 1.3: BRAINSTORM

Checking Architecture Preferences (Section 5.B.4)...
User preference: Simple/Monolith (confidence: 0.93)

Proposed Approaches:

### Approach 1: Simple/Monolith ⭐ (My Recommendation)
**Overview**: Login form component with direct API call

**Implementation**:
- Create LoginForm component in src/components/
- Use existing Input component
- Direct fetch call to /api/login
- Store token in localStorage
- Redirect with Next.js router

**Pros**:
- Fast to implement (1 file)
- Easy to understand
- Matches existing patterns
- No new dependencies

**Cons**:
- Token in localStorage (not most secure, but simple)

**Complexity**: Low

---

### Approach 2: Moderate
**Overview**: Login form + custom auth hook

**Implementation**:
- Create useAuth hook for auth logic
- LoginForm component uses hook
- Centralized auth state

**Pros**:
- Reusable auth logic
- Better separation of concerns

**Cons**:
- More files to create
- More complex for simple use case

**Complexity**: Medium

---

### Approach 3: Complex
**Overview**: Full auth context + protected routes

**Implementation**:
- AuthContext provider
- useAuth hook
- Higher-order component for protection
- Auth middleware

**Pros**:
- Professional architecture
- Scalable

**Cons**:
- Way more complex than needed right now
- Can add later if needed

**Complexity**: High

---

**My Recommendation**: Approach 1 (Simple/Monolith)

Reasoning: Based on your "Keep It Boring" preference and existing patterns,
the simple approach will work perfectly. We can always refactor to Approach 2/3
later if you add more auth features.

⏸️ Which approach would you like to use?

User: "Approach 1 sounds perfect"


Phase 1.4: EVALUATION

Phase 1.4: EVALUATION

Scoring Approach 1 against Vibecoding principles:

| Criteria       | Score | Reasoning                           |
|----------------|-------|-------------------------------------|
| Simplicity     | 5/5   | One component, straightforward      |
| Reliability    | 4/5   | Proven pattern, error handling      |
| Vibecodability | 5/5   | Easy to modify, no complex state    |
|                       |                                     |
| **Total**      | 14/15 | Excellent fit for your project      |

⏸️ Proceeding to Premortem.

Phase 1.5: PREMORTEM

Phase 1.5: PREMORTEM

Checking PROJECT-STATE.md Section 6 (Actual Risks Encountered)...

Assumption: The login implementation FAILED. Here's why:

### Risk 1: Network Offline
- **Likelihood**: High (happens regularly in your project)
- **Impact**: Form submits, hangs, never shows error
- **Mitigation**:
  - Add timeout to fetch (10 seconds)
  - Show "No internet" error
  - Test with DevTools offline mode

### Risk 2: Invalid Email Format
- **Likelihood**: High (users make typos)
- **Impact**: API rejects it, generic error shows
- **Mitigation**:
  - Client-side email validation
  - Show "Please enter a valid email" before submitting

### Risk 3: Rapid Re-submission
- **Likelihood**: Medium (impatient users)
- **Impact**: Multiple API calls, potential account lockout
- **Mitigation**:
  - Disable button while loading
  - Add "Logging in..." text

### Risk 4: Password Visibility
- **Likelihood**: Low but requested before
- **Impact**: User can't see what they typed
- **Mitigation**:
  - Add eye icon to toggle visibility
  - Common UX pattern

### Risks from Section 6 that apply:
- Network offline (occurred in Tasks #5, #8, #12)
- Mobile keyboard covering button (occurred in Task #9)

⏸️ Risks identified. Proceeding to Specification.

Phase 1.6: SPECIFICATION

Phase 1.6: SPECIFICATION

Checking PROJECT-STATE.md Sections 5.B, 5.C...

Implementation Specification:

### File Tree

src/ components/ LoginForm/ index.tsx [CREATE] styles.module.css [CREATE] app/ login/ page.tsx [MODIFY - add form] lib/ api.ts [MODIFY - add loginUser function]


### Data Flow
  1. User enters email + password
  2. Client validates email format
  3. On submit:
    • Disable button, show "Logging in..."
    • Call /api/login
    • If success: Store token, redirect to /dashboard
    • If error: Show message, re-enable button
  4. Handle offline: Show "No internet" error

### Function Signatures

```typescript
// components/LoginForm/index.tsx
interface LoginFormProps {
  onSuccess?: () => void;
}

function validateEmail(email: string): boolean

async function handleSubmit(e: FormEvent): Promise<void>

// lib/api.ts
interface LoginResponse {
  token: string;
  user: { id: string; email: string; name: string };
}

async function loginUser(email: string, password: string): Promise<LoginResponse>

Implementation Steps (Phase 2)

  1. Scaffolding: Create file structure, install no new deps
  2. Connectivity: Hardcode test credentials, verify flow works
  3. Core Logic: Add validation, real API call, token storage
  4. UI Binding: Loading states, error messages, styling

Mitigations from Premortem

✓ Network timeout: 10 second fetch timeout ✓ Email validation: Regex check before submit ✓ Button disable: isLoading state ✓ Password visibility: eye icon toggle ✓ Mobile keyboard: CSS padding-bottom

⏸️ Ready to code. Waiting for approval.


---

**Phase 1.7: APPROVAL**

Phase 1.7: APPROVAL

Ready to Code?

I've planned:

  • LoginForm component with email/password inputs
  • API integration with /api/login
  • Error handling for offline, invalid input, failed login
  • Loading states and clear error messages
  • Mobile-friendly with keyboard handling
  • 2 files to create, 1 to modify

Estimated time: 15-20 minutes Complexity: Low (matches existing patterns)

Are you confident this plan solves the problem with minimal future headaches?

Type 'GO' to start Phase 2 (Coding).


User: "GO"

---

**Phase 2: CODING** (Abbreviated - see actual files for full code)

Phase 2.1: SCAFFOLDING [Creates files, shows placeholder code]

Scaffolding Check: ✓ Directories created ✓ No new dependencies needed ✓ Placeholder files compile


Phase 2.2: CONNECTIVITY [Adds hardcoded test data, verifies flow]

Connectivity Check: ✓ Console log appears on submit ✓ Data flows through system ✓ No errors in console


Phase 2.3: CORE LOGIC [Implements validation, API call, error handling]

Core Logic Check: ✓ Email validation works ✓ API call succeeds with test credentials ✓ Token stored in localStorage ✓ Errors logged correctly


Phase 2.4: UI BINDING [Adds real form, styling, loading states]

UI Binding Check: ✓ Form looks correct ✓ Loading state shows ✓ Error messages display ✓ Mobile responsive


---

**Phase 3: TESTING**

Phase 3.1: MANUAL WALKTHROUGH

Test Steps:

  1. Navigate to /login

    • Expected: Login form appears with email/password fields
  2. Try submitting empty form

    • Expected: "Email and password are required"
  3. Try submitting invalid email "notanemail"

    • Expected: "Please enter a valid email address"
  4. Submit valid credentials (test@example.com / password123)

    • Expected: Button shows "Logging in..."
    • Expected: Button disabled
    • Expected: Redirect to /dashboard after 1-2 seconds
  5. Try submitting wrong password

    • Expected: "Invalid email or password"
    • Expected: Form still editable
  6. Test on mobile (DevTools)

    • Expected: Keyboard doesn't cover button
    • Expected: Form looks good

Please test and report results.


User tests, reports: "All passed except #3 - shows generic error instead of email format error"

Phase 3.3: FIX & REPEAT

In file: src/components/LoginForm/index.tsx

Change line 23 from: if (!email || !password) { setError('Email and password are required'); return; }

To: if (!email || !password) { setError('Email and password are required'); return; }

if (!validateEmail(email)) { setError('Please enter a valid email address'); return; }

Reason: Email validation was present but not checked before submit

Please test again.


User: "All tests pass now!"

---

**Phase 4: REVIEW**

Phase 4.1: CODE AUDIT - Complete ✓

Quality Checks: ✓ Readable by junior developer ✓ All user actions have error handling ✓ Loading states present ✓ Error messages in plain English ✓ No console.log in production ✓ Follows established patterns ✓ No unused code


Phase 4.2: DOCUMENTATION - Complete ✓

Updated README.md:

  • Added "Login" to feature list
  • Noted token storage approach (localStorage)

Phase 4.3: SEAL LEARNING

Quick feedback to improve future tasks:

Rating (1-5): ___

What worked well:

What could be better:

Should this become a pattern?:


User responds:
> Rating: 5/5
>
> What worked well:
> - Planning caught the offline issue before coding
> - You applied existing patterns automatically
> - Loading states and error messages were exactly right
>
> What could be better:
> - Could have caught the email validation ordering issue in planning
>
> Should this become a pattern:
> - Yes, this is exactly how I want forms handled

SEAL updates:
```markdown
### Task #7: Login Form
- **Date**: 2025-01-27
- **Type**: Feature
- **Status**: Completed ✅
- **Rating**: 5/5
- **Files Modified**:
  - components/LoginForm/index.tsx (created)
  - components/LoginForm/styles.module.css (created)
  - lib/api.ts (modified - added loginUser)
- **Notes**: Perfect execution. Pattern should be template for future forms.

---

**Pattern Created**: Form Handling (Confidence: 0.88 → 0.94)
- Email validation BEFORE submit check
- Loading button states (disable + text change)
- Plain English error messages
- 10s timeout for network calls
- Token storage: localStorage
- Redirect: Next.js router
- Mobile: padding-bottom for keyboard

**Success Factors**:
- Premortem caught offline risk
- Existing patterns applied automatically
- One minor fix needed (validation ordering)

**Next Form Task**: Will apply this pattern automatically

Appendix C: Pattern Confidence Scoring Guide

How Confidence is Calculated

Initial Pattern Creation (Task 1):
confidence = 0.33 (based on 1 success)

Second Success (Task 2):
confidence = (0.33 + 0.33) / 2 = 0.33
confidence += 0.27 (success bonus)
= 0.60 (emerging)

Third Success (Task 3):
confidence = (0.60 + success_score) / 2
success_score = 0.40 (weighted by consistency)
= 0.50 + 0.28 (bonus)
= 0.78 (reliable)

Fourth Success (Task 4):
= 0.88 (best practice)

Fifth Success (Task 5):
= 0.94 (project standard)

Confidence Decay

If a pattern fails:

Pattern confidence: 0.88
Task applies pattern → Rating 2/5

Decay calculation:
failure_penalty = (5 - rating) * 0.05 = 0.15
confidence = 0.88 - 0.15 = 0.73

Pattern demoted from "Best Practice" to "Reliable"
Note added: "Check for [specific failure condition]"

Confidence Rebuilding

After demotion, successful applications rebuild:

Task 1 after demotion: Rating 5/5
confidence = 0.73 + 0.08 = 0.81

Task 2 after demotion: Rating 5/5
confidence = 0.81 + 0.06 = 0.87 (back to Best Practice)

Appendix D: Emergency Scenarios

D.1: Code Breaks in Production

Scenario: User reports "login form is broken"

AI Response:

Phase 0: TRIAGE
Classification: BUG FIX (urgent)

Loading PROJECT-STATE.md Section 6 (Known Issues)...
Checking recent changes...

**Issue**: Login form broken
**Last Modified**: Task #7 (yesterday)
**Recent Changes**: Added email validation

**Hypothesis**: Validation logic may have bug

Proceeding to investigation...

Emergency fix protocol (from 03-constraints-quality.md Section 14):

1. Don't rewrite entire file
2. Identify specific issue
3. Provide surgical fix
4. Test fix
5. If fails, rollback and simplify

D.2: Pattern Applied Incorrectly

Scenario: AI applies form pattern to a button component

User: "Why does this button have form validation? It's just a button."

AI Response:

Phase 2.3: CORE LOGIC

Checking applied patterns...

Found: Applied "Form Handling" pattern (confidence: 0.94)
Reason: Keyword match on "button" + "submit"

**This was incorrect application.**

Reverting to simple button component per 03-constraints-quality.md Section 15:
"If a fix fails twice, rollback and try simpler approach"

Creating simple button without form logic...

SEAL updates:

Pattern: Form Handling
Note added: "Only apply to actual forms (form tag present)"
Confidence: 0.94 → 0.90 (minor adjustment)
Added exclusion rule: Standalone buttons

Appendix E: Multi-Task Project Flow

Shows how SEAL improves across a series of related tasks.

Project: E-commerce Site

Task 1: Product listing page

  • No patterns yet
  • Took 45 minutes
  • 3 iterations
  • Rating: 4/5

Task 5: Product detail page

  • Applying emerging patterns (confidence: 0.60)
  • Took 35 minutes
  • 2 iterations
  • Rating: 5/5

Task 10: Shopping cart

  • Strong patterns (confidence: 0.85)
  • Took 20 minutes
  • 1 iteration
  • Rating: 5/5

Task 15: Checkout flow

  • Auto-applying patterns
  • Took 15 minutes
  • 0 iterations (first try success!)
  • Rating: 5/5

Task 20: Admin dashboard

  • All patterns project standard
  • Took 12 minutes
  • 0 iterations
  • Rating: 5/5

Metrics Over Time

Success Rate:          Avg Time Per Task:
Task 1-5:   70%        Task 1-5:   40 min
Task 6-10:  85%        Task 6-10:  25 min
Task 11-15: 92%        Task 11-15: 18 min
Task 16-20: 95%        Task 16-20: 14 min

Pattern Coverage:      Iterations Per Task:
Task 5:  40%           Task 1-5:   2.5
Task 10: 65%           Task 6-10:  1.8
Task 15: 82%           Task 11-15: 1.2
Task 20: 91%           Task 16-20: 0.6

Total Time Saved: By Task 20, AI is 3x faster than Task 1, with 5x better first-try success rate.


End of Appendices

Return to README.md | QUICK-START.md | SYSTEM-FLOWCHART.md