---
name: zhihu-publish-attach
description: Publish Zhihu column articles on Linux via Chrome remote debugging (VNC login). After setup, use exec with zhihu_publish.sh and --title/--body-file. Triggers 知乎发帖, 发知乎, 知乎文章, zhihu publish, 发布到知乎, 帮我发知乎.
metadata: {"openclaw":{"os":["linux"],"requires":{"bins":["python3","curl","unzip"]}}}
---

# Zhihu publish (Chrome attach / Linux VNC)

This skill is **self-contained**: everything runs from `{baseDir}/scripts/`. No other repository files are required.

Publish **column articles** (专栏) by attaching to Chrome on `127.0.0.1:9222` after the user logged in via VNC.

Uses **`exec`** + `bash {baseDir}/scripts/zhihu_publish.sh` — not Browser Relay (see ClawHub `zhihu-post` for Windows).

## First-time setup (after ClawHub install)

Run **once** on the Linux server:

```bash
bash {baseDir}/scripts/setup.sh
bash {baseDir}/scripts/install_chromedriver.sh
bash {baseDir}/scripts/start_chrome_debug.sh
```

In VNC: log in to Zhihu in that Chrome window.

Verify:

```bash
bash {baseDir}/scripts/zhihu_publish.sh --check --json
```

Expect: `"ok": true, "logged_in": true`.

Details: `{baseDir}/references/linux-vnc-setup.md`

## When to use

- Linux server + VNC, Chrome started with debug port **9222**
- Zhihu already logged in (or user can log in after `start_chrome_debug.sh`)
- User wants to publish with **title** + **body**

## Scripts in `{baseDir}/scripts/`

| Script | Purpose |
|--------|---------|
| `setup.sh` | `pip install` selenium + chmod (after skill install) |
| `install_chromedriver.sh` | Install chromedriver (once) |
| `start_chrome_debug.sh` | Start Chrome (VNC window) |
| `ensure_chrome_debug.sh` | Restart Chrome if closed (keeps login profile) |
| `zhihu_publish.sh` | **Agent entry** — always use this |
| `zhihu_attach_standalone.py` | Called by zhihu_publish.sh |

## Title and body (parameters)

| Parameter | How |
|-----------|-----|
| `--title "..."` | Required |
| `--body-file /path` | **Preferred** for long text — write file first, then pass path |
| `--body "..."` | Short text only |
| `--publish` | Open editor and fill |
| `--submit` | Click 发布 (real post; omit for dry-run) |
| `--json` | JSON result for the agent |
| `--no-ensure-chrome` | Skip auto-start (only if Chrome is already running) |

**Auto-start:** Every `zhihu_publish.sh` run **automatically** calls `ensure_chrome_debug.sh` first. If the user closed the browser, Chrome restarts in the background with the same profile (`~/.chrome-zhihu-automation`) — login usually persists. No need to pass a separate flag unless debugging.

**Never** put user content inside one shell string. Use separate exec args or `--body-file`.

## Agent workflow

### 0. Check login (Chrome auto-starts if closed)

```bash
bash {baseDir}/scripts/zhihu_publish.sh --check --json
```

### 1. Dry-run (fill draft, do not publish)

Write body to e.g. `/tmp/zhihu_body.txt`, then:

```bash
bash {baseDir}/scripts/zhihu_publish.sh \
  --publish \
  --title "USER_TITLE" \
  --body-file /tmp/zhihu_body.txt \
  --json
```

Confirm with user (VNC or chat). JSON has `dry_run: true` without `--submit`.

### 2. Real publish (only after user confirms)

```bash
bash {baseDir}/scripts/zhihu_publish.sh \
  --publish \
  --title "USER_TITLE" \
  --body-file /tmp/zhihu_body.txt \
  --submit \
  --json
```

Success: `"ok": true`, `"submitted": true`.

## Exec examples

```
command: bash
args: ["{baseDir}/scripts/zhihu_publish.sh", "--check", "--json"]
```

```
command: bash
args: [
  "{baseDir}/scripts/zhihu_publish.sh",
  "--publish",
  "--title", "<title>",
  "--body-file", "/tmp/zhihu_post_body.txt",
  "--submit",
  "--json"
]
```

## Chromedriver (version must match Chrome)

Selenium attach **requires** `chromedriver` even when Chrome is already running.  
Install to **`/usr/local/bin/chromedriver`** (or set `CHROMEDRIVER_PATH`).

```bash
bash {baseDir}/scripts/install_chromedriver.sh
bash {baseDir}/scripts/verify_chrome_stack.sh
```

If you installed Chrome via `dnf` RPM (e.g. 148.0.7778.215), chromedriver must be the **same** build from Chrome for Testing — see `{baseDir}/references/linux-vnc-setup.md`.

## Troubleshooting

| Symptom | Action |
|---------|--------|
| `chromedriver` not in PATH | `install_chromedriver.sh` or `export CHROMEDRIVER_PATH=/usr/local/bin/chromedriver` |
| Version mismatch | `verify_chrome_stack.sh`; re-download driver for your `google-chrome-stable --version` |
| Cannot connect to 9222 | Usually auto-fixed on next `zhihu_publish.sh` run; or `ensure_chrome_debug.sh` |
| Browser closed | Auto-restart on publish; re-login in VNC only if `--check` returns 401 |
| Chrome starts but no window on VNC | Set `DISPLAY` for the OpenClaw/exec user (e.g. `export DISPLAY=:1`) |
| No selenium module | `bash {baseDir}/scripts/setup.sh` |
| API 401 | Re-login in VNC |

## Safety

- Without `--submit` = draft only.
- Use `--submit` only when the user explicitly asks to publish.
- Wait ≥ 3 minutes between posts if publishing repeatedly.
