---
name: research-and-utility-ops
description: "Data sourcing (Reddit research), network operations (public access tunnels), and utility document generation (PDFs)."
---

# Research & Utility Operations

Techniques for data retrieval, network exposure, and document production.

## Data Sourcing: Reddit Research

Reliable methods for accessing Reddit content for analysis and monitoring.

### Access Strategies
- **Method 1**: Reddit JSON API (append `.json`). Requires User-Agent.
- **Method 2**: PullPush.io Archive (Fallback). Highly reliable when Reddit blocks scrapers (403).

### Workflow
- Resolve share URLs via redirect follow to get canonical post IDs.
- Delegate deep research/summarization to subagents with `web` and `terminal`.
- Save output to `/DATA/Documents/` (markdown format).

## Network Ops: Local Server Public Access

Exposing local HTTP services (dashboards, websites) to the public internet.

### Tunnel Options
- **Cloudflare Tunnel** (Recommended): Temporary random URL via `cloudflared tunnel --url`. No account needed.
- **Ngrok**: Reliable with authtoken.
- **Tailscale Funnel**: Best if already using Tailscale.
- **Manual Port Forwarding**: Last resort (static IP required).

### ZimaOS Setup

```bash
# 1. Download cloudflared binary (no dpkg/pkg on ZimaOS)
curl -L -o /tmp/cloudflared \
  https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64
chmod +x /tmp/cloudflared

# 2. Start local HTTP server bound to 127.0.0.1 (never 0.0.0.0 for tunnels)
cd /PATH/TO/FILES && python3 -m http.server 8888 --bind 127.0.0.1 &

# 3. Start cloudflared as background process (runs indefinitely)
#    Use Hermes process tool with background=true, notify_on_complete=false
/tmp/cloudflared tunnel --url http://127.0.0.1:8888

# 4. Poll process log to extract the trycloudflare.com URL
#    Look for: "Your quick Tunnel has been created! Visit it at:"
#    URL pattern: https://<random-words>.trycloudflare.com
```

### Quick Tunnel Lifecycle

- **No uptime guarantee** — Quick Tunnels die after hours/days. When user reports "URL doesn't work anymore", don't debug — just spin up a fresh tunnel.
- **No account needed** — but for production use, create a named tunnel via Cloudflare Zero Trust.
- **One tunnel per process** — each `cloudflared tunnel --url` creates a new random subdomain.

### Re-establishing a Tunnel for an Existing Site

When a tunnel dies and the user asks to bring the site back:

1. **Check for multiple versions** — search `/DATA/` for related HTML files (e.g. `veritas*`). Projects often have multiple design variants (corporate vs. cyberpunk, different fonts/color schemes). Don't assume which file was previously served.
2. **Confirm with the user** which version they want live before starting the server. The user may say "looks bad, make it like before" — this means you served the wrong variant.
3. **Serve the right file** — `python3 -m http.server` serves the whole directory, so the URL path matters too (e.g. `/veritas-website.html` vs `/veritas-architecture.html`).

## Utility Ops: PDF Generation

Generating clean PDF documents (letters, reports) from markdown/text.

### Technical Implementation
- **Tool**: Python `fpdf2`.
- **Unicode Support**: Use **DejaVu Sans** TTF for German characters (Helvetica crashes on em-dashes).
- **Layout**: German business correspondence style (sender/recipient blocks, subject, body).

### Pitfalls
- **fpdf2 v2.5+**: `ln=True` is deprecated; use `new_x="LMARGIN", new_y="NEXT"`.
- **ZimaOS**: No pandoc/weasyprint; `fpdf2` is the only lightweight path.

## Common Pitfalls
- **Reddit**: 403 blocks are common; don't retry, use PullPush.io.
- **Tunnels**: `cloudflared` runs indefinitely; don't `wait`, check `log` for the URL.
- **PDFs**: GitHub raw URLs return HTML for font downloads; use SourceForge/GitLab binary links.
