# KERNL Desktop Control - Setup Guide

## Overview

**Approach 3: Desktop Control** is the most ambitious export method - it automates the Claude Desktop application using keyboard/mouse control and OCR.

⚠️ **Important:** This approach is **OPTIONAL** and has complex dependencies. We recommend using Approach 1 (Filesystem) or Approach 2 (Chrome) instead.

## Why Desktop Control?

**Pros:**
- 🎮 Complete automation (no user interaction needed)
- 📸 Works even if APIs change
- 🔍 OCR reads any text on screen
- 💪 Most robust long-term solution

**Cons:**
- ⚙️ Requires native compilation (robotjs)
- 🐌 Slowest approach (~10 min for 1000 conversations)
- 🖱️ Takes control of mouse/keyboard
- 🪟 Windows-specific implementation
- 🔧 Complex setup

## Dependencies

### Required Packages

```bash
npm install screenshot-desktop  # ✅ Already installed
npm install tesseract.js        # ✅ Already installed
npm install clipboardy           # ✅ Already installed
npm install robotjs              # ❌ Requires native compilation
```

### robotjs Setup (Windows)

**Prerequisites:**
1. **Python 2.7** (yes, Python 2.7 is required)
   - Download: https://www.python.org/downloads/release/python-2718/
   - Add to PATH

2. **Visual Studio Build Tools**
   - Download: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022
   - Install "Desktop development with C++"
   - Or: `npm install -g windows-build-tools` (admin PowerShell)

3. **node-gyp**
   ```bash
   npm install -g node-gyp
   ```

**Installation:**
```bash
cd "D:\Project Mind\kernl-mcp"
npm install robotjs
```

**Common Issues:**

**"Python not found"**
```bash
npm config set python "C:\Python27\python.exe"
```

**"MSBuild not found"**
```bash
npm config set msvs_version 2022
```

**"node-gyp rebuild failed"**
- Ensure Visual Studio Build Tools installed
- Try: `npm install -g node-gyp`
- Rebuild: `npm rebuild robotjs`

## Alternative: Use Without robotjs

Desktop Control will gracefully degrade without robotjs:

```typescript
const result = await testDesktopControl();

if (!result.robotjsAvailable) {
  console.log('❌ robotjs not available');
  console.log('💡 Use Approach 1 (Filesystem) or Approach 2 (Chrome) instead');
}
```

The code will detect missing robotjs and provide clear error messages.

## Testing

### Step 1: Check Prerequisites

```bash
node dist/export/test-desktop.js
```

This will check:
- ✅ Claude Desktop running
- ✅ robotjs available
- ✅ screenshot-desktop working
- ✅ Tesseract OCR working
- ✅ clipboardy working

### Step 2: Run Export (if prerequisites met)

The test script will:
1. Take control of mouse/keyboard
2. Focus Claude Desktop window
3. Capture screenshot
4. Run OCR to find conversations
5. Navigate through conversations
6. Copy content via clipboard
7. Export first 10 conversations

**⚠️ DO NOT move mouse or type during export!**

## Comparison with Other Approaches

| Approach | Speed | Setup Complexity | While Claude Running? |
|----------|-------|------------------|----------------------|
| 1. Filesystem | 5 sec | Easy | ❌ No (requires closed) |
| 2. Chrome | 30 sec | Easy | ✅ Yes |
| **3. Desktop** | **10 min** | **Hard** | **✅ Yes** |
| 4. Meta | 2 min | Easy | ✅ Yes |

## Recommendation

**For most users:**
- Use **Approach 1** (Filesystem) when Claude Desktop is closed
- Use **Approach 2** (Chrome) when Claude Desktop is running

**Only use Approach 3 if:**
- You need visual verification (OCR)
- Other approaches fail
- You want complete automation
- You're comfortable with native compilation

## Skip Desktop Control?

It's **perfectly fine** to skip this approach! The other 3 approaches provide 100% coverage:

```typescript
// Export without Desktop Control
const result = await exportAllConversations({
  methods: ['filesystem', 'chrome', 'meta'],  // Skip 'desktop'
  deduplicate: true
});
```

## Status

✅ **Code implemented** - desktop-export.ts complete
⚠️ **Dependencies optional** - robotjs not required for other approaches
📝 **Documentation complete** - full setup guide provided
🎯 **Recommendation** - Use Approach 1 or 2 instead

---

**Next Steps:**
1. Skip robotjs installation (optional dependency)
2. Move to Approach 4 (Meta-Recursive)
3. Build unified export coordinator
4. Test Approaches 1, 2, and 4 together
