# GhostWriter

Stealth human typer for macOS. Queue up text, press a hotkey, and it types it out character-by-character wherever your cursor is — with realistic human typing behavior.

## How It Works

1. Run the daemon (`./ghostwriterd` or double-click `start.command`)
2. Open the web UI at `http://127.0.0.1:9753`
3. Write or paste text, click **Add to Queue**
4. Click where you want it typed (Google Docs, Word, any text field)
5. Press **Ctrl+Shift+G** (or **Cmd+Shift+G**) — it starts typing

If the queue is empty, it types whatever's on your clipboard.

## Hotkeys

| Shortcut | Action |
|----------|--------|
| `Ctrl+Shift+G` or `Cmd+Shift+G` | Start typing next queued item (or clipboard) |
| `Ctrl+Shift+Space` or `Cmd+Shift+Space` | Pause / Resume |
| `Ctrl+Shift+R` or `Cmd+Shift+R` | Resume from where you stopped |
| `Escape` | Emergency stop (saves position for resume) |

Hotkeys use Ctrl+Shift or Cmd+Shift (not Ctrl+Option) to avoid conflicts with Google Docs, Word, and Notion.

## Human-Like Behavior

- **Burst rhythm** — types 3-8 chars fast, then a micro-pause, like real finger movements
- **5 typo types**: adjacent key ("r" → "t"), double-tap ("helllo"), transposition ("teh"), early space ("bec ause"), missed shift ("HEllo")
- **55% of typos get fixed** (backspace + correct), **45% are left in** for you to fix later
- **Thinking pauses** — random 1-3s breaks every few sentences
- **Word difficulty** — longer words typed slower, short words faster
- **Punctuation pauses** — commas, periods, and newlines have natural delays
- **Modifier freeze** — typing instantly pauses when you press Ctrl/Cmd, so hotkeys never collide with typed characters

## Formatting (Markdown)

Write in Markdown, GhostWriter applies formatting via keyboard shortcuts:

- `**bold**` → Cmd+B toggle
- `*italic*` → Cmd+I toggle
- `# Heading 1` through `###### Heading 6` → Cmd+Option+1-6 (Google Docs compatible)

## Settings

Adjustable in the web UI:

- **Speed** — 20-200 WPM with Slow/Normal/Fast presets (default 110)
- **Typo rate** — 0-15% (default 4%)
- **Thinking pauses** — on/off

## Resume

Press Escape to stop mid-typing. Your position is saved. Press Ctrl+Shift+R to pick up exactly where you left off.

## Setup

### Requirements

- macOS 12+
- Accessibility permission for Terminal

### Grant Accessibility

System Settings → Privacy & Security → Accessibility → add **Terminal.app** → toggle ON

### Run

```bash
cd ghost-writer
./start.command
```

Or manually:

```bash
# Build (only needed once, or after editing .swift)
swiftc -O -o ghostwriterd ghostwriter.swift -framework Cocoa -framework Carbon

# Run
./ghostwriterd
```

### Files

```
ghost-writer/
├── ghostwriter.swift   # Daemon source (typing engine + HTTP server + hotkeys)
├── ghostwriter.html    # Web UI
├── ghostwriterd        # Compiled binary (arm64)
├── start.command       # Double-click launcher
└── README.md
```

Queue data is stored in `~/.ghostwriter/queue.json`.

## Architecture

- **Swift daemon** — CGEvent tap for global hotkeys, CGEvent keystroke injection for typing, raw socket HTTP server for the web UI
- **Single binary** — no dependencies, no Node, no Python
- **Web UI** — vanilla HTML/CSS/JS served by the daemon on port 9753
- **File-based queue** — JSON with atomic writes and dispatch queue locking
