# DeepSeek Browser Smoke Implementation Plan

> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

**Goal:** Add a repo-local verification path that exercises the browser-delivered `sgclaw` binary through the ZeroClaw/DeepSeek compat runtime without requiring a real DeepSeek account.

**Architecture:** Keep the existing SuperRPA browser smoke script unchanged. Add a small sgClaw-owned helper module that behaves like a fake OpenAI-compatible DeepSeek server and a runner script that starts that server, injects `DEEPSEEK_*` into the browser process environment, and delegates the actual browser/UI verification to the existing `sgclaw_chat_smoke.mjs`.

**Tech Stack:** Node.js ESM, Node built-in `node:test`, local HTTP server, Chromium `build_sgclaw.py`, existing SuperRPA `sgclaw_chat_smoke.mjs`.

### Task 1: Add Fake DeepSeek Response Planner

**Files:**
- Create: `/home/zyl/projects/sgClaw/claw/.worktrees/zeroclaw-core-refactor/tools/browser_smoke/fake_deepseek_server.mjs`
- Test: `/home/zyl/projects/sgClaw/claw/.worktrees/zeroclaw-core-refactor/tools/browser_smoke/fake_deepseek_server.test.mjs`

**Step 1: Write the failing test**

Add `node:test` coverage that proves the fake server planner:
- returns Baidu tool calls for `打开百度搜索天气`
- returns Zhihu navigate tool calls for `打开知乎搜索天气`
- returns final summaries matching the existing smoke script expectations
- rejects unsupported instructions clearly

**Step 2: Run test to verify it fails**

Run:
```bash
node --test tools/browser_smoke/fake_deepseek_server.test.mjs
```

Expected: FAIL because the helper module does not exist yet.

**Step 3: Implement the minimal helper**

The helper should:
- inspect the latest user message / tool-result phase
- emit OpenAI-compatible `choices[0].message.tool_calls` for the first round
- emit `choices[0].message.content` for the second round
- keep summaries identical to the current smoke assertions

**Step 4: Run test to verify it passes**

Run:
```bash
node --test tools/browser_smoke/fake_deepseek_server.test.mjs
```

Expected: PASS

### Task 2: Add DeepSeek Smoke Wrapper Script

**Files:**
- Create: `/home/zyl/projects/sgClaw/claw/.worktrees/zeroclaw-core-refactor/tools/browser_smoke/run_deepseek_browser_smoke.mjs`
- Modify: `/home/zyl/projects/sgClaw/claw/.worktrees/zeroclaw-core-refactor/README.md`

**Step 1: Write the failing wrapper expectation**

Add a small test or dry-run seam in the helper test that proves the wrapper environment includes:
- `DEEPSEEK_API_KEY`
- `DEEPSEEK_BASE_URL`
- `DEEPSEEK_MODEL`

and points at the fake local server.

**Step 2: Run the targeted test to verify it fails**

Run:
```bash
node --test tools/browser_smoke/fake_deepseek_server.test.mjs
```

Expected: FAIL because no wrapper/env builder exists yet.

**Step 3: Implement the wrapper**

The wrapper should:
- start the fake DeepSeek server
- invoke:
```bash
node /home/zyl/projects/superRpa/src/chrome/browser/superrpa/sgclaw/sgclaw_chat_smoke.mjs
```
- inject `DEEPSEEK_*` into the child environment
- print the child stdout/stderr through
- stop the fake server on exit

**Step 4: Run the targeted test to verify it passes**

Run:
```bash
node --test tools/browser_smoke/fake_deepseek_server.test.mjs
```

Expected: PASS

### Task 3: Verify the Browser-Delivered DeepSeek Path

**Files:**
- Verify: `/home/zyl/projects/sgClaw/claw/.worktrees/zeroclaw-core-refactor/tools/browser_smoke/*`
- Verify: `/home/zyl/projects/superRpa/src/chrome/browser/superrpa/sgclaw/build_sgclaw.py`

**Step 1: Build the browser-delivered binary from the worktree**

Run:
```bash
python3 /home/zyl/projects/superRpa/src/chrome/browser/superrpa/sgclaw/build_sgclaw.py \
  --manifest-path /home/zyl/projects/sgClaw/claw/.worktrees/zeroclaw-core-refactor/Cargo.toml \
  --out /home/zyl/projects/superRpa/src/out/KylinRelease/sgclaw
```

Expected: PASS

**Step 2: Run the DeepSeek smoke wrapper**

Run:
```bash
node tools/browser_smoke/run_deepseek_browser_smoke.mjs
```

Expected:
- existing browser smoke passes
- `sgclaw` is forced down the compat runtime path through `DEEPSEEK_*`
- Baidu and Zhihu tasks still complete

**Step 3: Re-run full Rust tests to guard against regressions**

Run:
```bash
python3 /home/zyl/projects/superRpa/src/tools/crates/run_cargo.py test \
  --manifest-path /home/zyl/projects/sgClaw/claw/.worktrees/zeroclaw-core-refactor/Cargo.toml \
  --tests
```

Expected: PASS
