# Mac Stack Extras — going live

Builds on the [Local AI Stack on a Mac](https://krueng.ai/it/ai/ai_mac_stack.html).
Same Ollama + Hermes 3 + LlamaIndex foundation; four new abilities so the
agent can reach the world:

1. **Web search** — `duckduckgo-search`, wrapped as a Hermes tool.
2. **Image generation** — `diffusers` + Stable Diffusion XL Turbo, runs
   on Apple Silicon's MPS backend. Offline after the first download.
3. **LINE responses** — Flask webhook that ferries messages from a LINE
   Official Account through the Hermes agent and back.
4. **Cron / event-driven tasks** — `launchd` plist that runs a Python
   script on a schedule. Sample: post a daily English word at 7am.

## Files

| File | What it is |
| --- | --- |
| `requirements.txt` | Extra Python packages (search + diffusers + flask) |
| `agent_pro.py` | The original `agent.py` with three new tools wired in |
| `agent_pro_webbridge.py` | Alternative agent — web tool via Kimi WebBridge over MCP instead of `duckduckgo-search` |
| `image_gen.py` | Local SDXL Turbo wrapper — usable standalone or via the agent |
| `line_bot.py` | Flask webhook that lets a LINE user chat with the agent |
| `daily_word.py` | Sample scheduled task — agent picks a word, posts to LINE |
| `com.kruai.daily.plist` | launchd schedule file — install in ~/Library/LaunchAgents |

## Quick start

```bash
# Drop the extras alongside the Mac Stack files
cd ~/Downloads/mac_stack
source .venv/bin/activate
pip install -r /path/to/mac_stack_extras/requirements.txt
cp /path/to/mac_stack_extras/*.py .

# 1. Chat with the upgraded agent
python agent_pro.py

# 2. (Optional) Run the LINE bot
export LINE_CHANNEL_ACCESS_TOKEN="..."
export LINE_CHANNEL_SECRET="..."
python line_bot.py             # then `ngrok http 8000` in another terminal

# 3. (Optional) Schedule the daily word job
cp com.kruai.daily.plist ~/Library/LaunchAgents/   # edit paths + creds first
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.kruai.daily.plist
launchctl start com.kruai.daily                    # run once now to test
```

## Alternative: Kimi WebBridge instead of DuckDuckGo

`agent_pro.py` uses `duckduckgo-search` — a tiny pip package that scrapes
search snippets. Zero setup beyond `pip install`, but only snippets — no
logins, no clicking through, no JS-rendered pages.

`agent_pro_webbridge.py` connects the agent to **Kimi WebBridge**,
Moonshot's local browser-automation service. It drives your real
Chrome/Edge browser through Chrome DevTools Protocol, so the agent can
log in, scroll, click, fill forms. Page content never touches Moonshot's
servers.

### Install (one-time)

1. Download the **Kimi Desktop App**: <https://www.kimi.com/features/webbridge>
2. Install the **Kimi WebBridge** Chrome / Edge extension from the Chrome Web Store
   (search "Kimi WebBridge").
3. Open Kimi Desktop → Settings → WebBridge — pair the desktop app with the extension.
   Both should show as connected.
4. Copy the MCP endpoint URL the WebBridge settings show (looks like
   `http://127.0.0.1:PORT/sse`), then:

```bash
pip install llama-index-tools-mcp                        # already in requirements.txt
export WEBBRIDGE_MCP_URL="http://127.0.0.1:PORT/sse"     # use the URL from step 4
python agent_pro_webbridge.py
```

Run **both** scripts side by side to compare; pick whichever fits the task.

Full walkthroughs with diagrams: <https://krueng.ai/it/ai/ai_mac_stack_extras.html>.
