wasintoh

šŸ‘ļø Preview Mode Skill

*Last Updated: 2024-12-03*

wasintoh 79 16 Updated 5mo ago
GitHub

Install

npx skillscat add wasintoh/toh-framework/src-skills-preview-mode

Install via the SkillsCat registry.

SKILL.md

šŸ‘ļø Preview Mode Skill

Purpose: Show users what will change before applying
Version: 1.0.0
Author: Toh Framework Team

Overview

This skill enables AI to show previews of changes before applying them, giving users confidence in what's being created.

Core Principle

AI completes work
    ↓
Show preview (description + URL if available)
    ↓
User confirms or requests changes
    ↓
Apply changes (or iterate)

SEE BEFORE COMMIT


Preview Types

Type 1: Dev Server Preview (Live)

When dev server is running:

āœ… **สร้าง Dashboard ą¹€ąøŖąø£ą¹‡ąøˆą¹ąø„ą¹‰ąø§!**

šŸ‘ļø **Preview:**
🌐 http://localhost:3000/dashboard

šŸ“ø **ąøŖąø“ą¹ˆąø‡ąø—ąøµą¹ˆąøŖąø£ą¹‰ąø²ąø‡:**
- Header ąøžąø£ą¹‰ąø­ąø” navigation
- Stats cards (4 ตัว)
- Sales chart
- Recent orders table

เปณด URL ąø”ą¹‰ąø²ąø™ąøšąø™ą¹€ąøžąø·ą¹ˆąø­ąø”ąø¹ preview ą¹„ąø”ą¹‰ą¹€ąø„ąø¢ąø„ąø£ąø±ąøš!

šŸ’” ąø•ą¹‰ąø­ąø‡ąøąø²ąø£ą¹ąøą¹‰ą¹„ąø‚ąø­ąø°ą¹„ąø£ą¹„ąø«ąø”ąø„ąø£ąø±ąøš?

Type 2: Description Preview (No Server)

When dev server isn't running:

āœ… **เตรียด Dashboard ąøžąø£ą¹‰ąø­ąø”ą¹ąø„ą¹‰ąø§!**

šŸ“‹ **Preview ąøŖąø“ą¹ˆąø‡ąø—ąøµą¹ˆąøˆąø°ąøŖąø£ą¹‰ąø²ąø‡:**

**Layout:**
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ šŸ”µ Header (Logo + Nav + Profile)   │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ šŸ“Š Stats Cards (4 columns)          │
│ ā”Œā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”            │
│ │ $ │ │ šŸ“¦ā”‚ │ šŸ‘„ā”‚ │ šŸ“ˆā”‚            │
│ ā””ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”˜            │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ šŸ“ˆ Sales Chart (Line/Bar)          │
│ [Chart area]                        │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ šŸ“‹ Recent Orders Table             │
│ ID | Customer | Amount | Status     │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

**Components:**
- StatsCard.tsx (reusable)
- SalesChart.tsx (with Recharts)
- OrdersTable.tsx (with pagination)

ąøŖąø£ą¹‰ąø²ąø‡ą¹€ąø„ąø¢ą¹„ąø«ąø”ąø„ąø£ąø±ąøš? ąø«ąø£ąø·ąø­ąø•ą¹‰ąø­ąø‡ąøąø²ąø£ąø›ąø£ąø±ąøšąø­ąø°ą¹„ąø£ąøą¹ˆąø­ąø™?

Type 3: Before/After Preview (Modifications)

When modifying existing code:

šŸ”„ **Preview ąøąø²ąø£ą¹€ąø›ąø„ąøµą¹ˆąø¢ąø™ą¹ąø›ąø„ąø‡:**

**Before:**
```tsx
<Button>Submit</Button>

After:

<Button 
  onClick={handleSubmit}
  disabled={isLoading}
>
  {isLoading ? <Spinner /> : 'Submit'}
</Button>

Changes:

  • āœ… ą¹€ąøžąø“ą¹ˆąø” onClick handler
  • āœ… ą¹€ąøžąø“ą¹ˆąø” loading state
  • āœ… ą¹€ąøžąø“ą¹ˆąø” Spinner component

Apply ąøąø²ąø£ą¹€ąø›ąø„ąøµą¹ˆąø¢ąø™ą¹ąø›ąø„ąø‡ąø™ąøµą¹‰ą¹„ąø«ąø”ąø„ąø£ąø±ąøš?


---

## Auto Dev Server Detection

AI should detect if dev server is running:

```javascript
// Check if localhost:3000 is accessible
// If yes → Provide live URL
// If no → Provide description preview

With Dev Server

šŸ‘ļø **Live Preview ąøžąø£ą¹‰ąø­ąø”ą¹ąø„ą¹‰ąø§:**
🌐 http://localhost:3000/[path]

(ą¹€ąø›ąø“ąø”ąø”ąø¹ą¹„ąø”ą¹‰ą¹€ąø„ąø¢ąø„ąø£ąø±ąøš!)

Without Dev Server

šŸ’” **เปณด preview ได้โดย:**
```bash
npm run dev

ą¹ąø„ą¹‰ąø§ą¹„ąø›ąø—ąøµą¹ˆ http://localhost:3000/[path]


---

## Preview Confirmation Flow

### Standard Flow
  1. AI creates/modifies files
  2. AI shows preview
  3. User reviews
  4. Options:
    • "OK" / "ได้เคย" → Continue
    • "แก้ไข [detail]" → AI modifies
    • "ยกเคณก" → AI reverts

### Quick Flow (For Simple Changes)
  1. AI shows preview inline
  2. Applies immediately
  3. User can undo if needed

---

## Preview Templates by Task Type

### New Page Preview

```markdown
šŸ“„ **New Page: /dashboard**

**Layout:**
[ASCII art layout]

**Features:**
- [Feature list]

**Components Used:**
- [Component list]

**Files to Create:**
- app/dashboard/page.tsx
- components/dashboard/StatsCard.tsx
- components/dashboard/SalesChart.tsx

ąøŖąø£ą¹‰ąø²ąø‡ą¹€ąø„ąø¢ą¹„ąø«ąø”ąø„ąø£ąø±ąøš?

New Component Preview

🧩 **New Component: ProductCard**

**Preview:**
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│    [Image]      │
│  Product Name   │
│     ąøæ199        │
│  [Add to Cart]  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

**Props:**
- product: Product
- onAddToCart: () => void

**Features:**
- Responsive
- Hover effect
- Loading state

ąøŖąø£ą¹‰ąø²ąø‡ą¹€ąø„ąø¢ą¹„ąø«ąø”ąø„ąø£ąø±ąøš?

Design Change Preview

✨ **Design Changes:**

**Color Palette:**
- Primary: #3B82F6 → #2563EB (darker)
- Background: #F9FAFB → #F3F4F6 (warmer)

**Typography:**
- Headings: font-semibold → font-bold
- Body: text-gray-600 → text-gray-700

**Spacing:**
- Cards: p-4 → p-6 (more breathing room)
- Sections: gap-4 → gap-6

**Before/After:**
[Side by side comparison if possible]

Apply changes ą¹„ąø«ąø”ąø„ąø£ąø±ąøš?

Logic Change Preview

āš™ļø **Logic Changes: handleSubmit**

**What changes:**
1. Add validation before submit
2. Add loading state
3. Add success/error toast
4. Clear form on success

**Flow:**

User clicks Submit
↓
Validate form (Zod)
↓
Show loading state
↓
Call API
↓
Success? → Show toast + Clear form
Error? → Show error message


Apply changes ą¹„ąø«ąø”ąø„ąø£ąø±ąøš?

Multi-File Change Preview

When changes span multiple files:

šŸ“ **Files to Change:**

**Create:**
- components/checkout/PaymentForm.tsx
- lib/stripe.ts
- app/api/checkout/route.ts

**Modify:**
- app/cart/page.tsx (add checkout button)
- types/index.ts (add PaymentIntent type)

**Total:** 3 new files, 2 modified

ดู diff ą¹ąø•ą¹ˆąø„ąø°ą¹„ąøŸąø„ą¹Œą¹„ąø«ąø”ąø„ąø£ąø±ąøš? หรือ apply เคย?

Preview for Destructive Actions

Extra confirmation for risky operations:

āš ļø **Warning: Destructive Action**

**จะคบ:**
- app/old-dashboard/ (3 files)
- components/old-chart/ (2 files)

**Total:** 5 files ąøˆąø°ąø–ąø¹ąøąø„ąøš

⚔ ąøą¹ˆąø­ąø™ąø„ąøš:
- [x] สร้าง backup checkpoint แค้ว
- [x] ą¹„ąøŸąø„ą¹Œą¹ƒąø«ąø”ą¹ˆąøžąø£ą¹‰ąø­ąø”ą¹ƒąøŠą¹‰ą¹ąø—ąø™ą¹ąø„ą¹‰ąø§

ąøžąø“ąø”ąøžą¹Œ 'confirm' ą¹€ąøžąø·ą¹ˆąø­ąø¢ąø·ąø™ąø¢ąø±ąø™ąøąø²ąø£ąø„ąøš
หรือ 'cancel' ą¹€ąøžąø·ą¹ˆąø­ąø¢ąøą¹€ąø„ąø“ąø

Preview Settings

User can configure preview behavior:

/toh-settings preview

**Preview Mode:**
- [x] Always show preview (default)
- [ ] Quick mode (apply without preview)
- [ ] Ask each time

**Preview Detail:**
- [ ] Minimal (layout only)
- [x] Normal (layout + components)
- [ ] Verbose (everything)

Integration with Other Skills

Skill Integration
Version Control Auto-checkpoint before apply
Error Handling Preview potential issues
Smart Suggestions Suggest improvements in preview
Progress Tracking Show progress after apply

Best Practices

DO:

  • āœ… Always show preview for major changes
  • āœ… Provide live URL when possible
  • āœ… Use ASCII art for layout preview
  • āœ… List all files that will change
  • āœ… Highlight breaking changes

DON'T:

  • āŒ Skip preview for destructive actions
  • āŒ Show too much technical detail
  • āŒ Assume user wants to proceed
  • āŒ Apply without any confirmation for major changes

ASCII Art Templates

Dashboard Layout

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Header                                  │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ Sidebar │ Main Content                  │
│         │                               │
│ Nav     │ Cards / Charts / Tables       │
│ Items   │                               │
│         │                               │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Card Grid

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Card  │ │ Card  │ │ Card  │
│   1   │ │   2   │ │   3   │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Form Layout

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Form Title                  │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ Label          [Input     ] │
│ Label          [Input     ] │
│ Label          [Textarea  ] │
│                [         ]  │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│         [Cancel] [Submit]   │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Table Layout

ā”Œā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ ID │ Name     │ Amount │ Status │
ā”œā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ 1  │ Item 1   │ ąøæ100   │ āœ…     │
│ 2  │ Item 2   │ ąøæ200   │ ā³     │
ā””ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Last Updated: 2024-12-03