返回 Social Auto Upload
2026-03-25-xiaohongshu-shallow-alignment.md
根目录 / docs / superpowers / plans / 2026-03-25-xiaohongshu-shallow-alignment.md
1 # Xiaohongshu Shallow Alignment Implementation Plan
2
3 > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
5 **Goal:** Align the browser-based Xiaohongshu uploader with the current Douyin/Kuaishou style for login QR flow, patchright usage, and formal video/note entry points without expanding into CLI or docs work.
6
7 **Architecture:** Keep the work inside `uploader/xiaohongshu_uploader/main.py` as a shallow refactor. Introduce a thin login flow with QR extraction, cookie validation, and result payloads, then add a shared base uploader plus separate video and note browser flows that reuse common setup.
8
9 **Tech Stack:** Python, patchright, async Playwright-compatible browser automation, unittest
10
11 ---
12
13 ### Task 1: Lock expected login/setup behavior
14
15 **Files:**
16 - Create: `tests/test_xiaohongshu_uploader.py`
17 - Modify: `uploader/xiaohongshu_uploader/main.py`
18
19 - [ ] Add tests for `xiaohongshu_setup(..., return_detail=True)` invalid-cookie behavior and uploader validation behavior.
20 - [ ] Run the targeted test file and confirm it fails for the expected missing behavior.
21 - [ ] Implement the minimal production changes to satisfy those tests.
22
23 ### Task 2: Refactor Xiaohongshu uploader module
24
25 **Files:**
26 - Modify: `uploader/xiaohongshu_uploader/main.py`
27
28 - [ ] Switch the module from `playwright.async_api` to `patchright.async_api`.
29 - [ ] Replace `page.pause()` login with QR extraction, terminal printing, QR file saving, polling, and cookie persistence.
30 - [ ] Add a shared base uploader plus formal video and note entry points while keeping legacy public names callable.
31
32 ### Task 3: Refresh local debug examples
33
34 **Files:**
35 - Modify: `examples/get_xiaohongshu_cookie.py`
36 - Modify: `examples/upload_video_to_xiaohongshu.py`
37
38 - [ ] Update the login example to use the aligned setup entry.
39 - [ ] Update the upload example to expose direct video/note debug functions.
40
41 ### Task 4: Verify
42
43 **Files:**
44 - Test: `tests/test_xiaohongshu_uploader.py`
45
46 - [ ] Run the targeted unittest file.
47 - [ ] Run a quick Python syntax/import check for the modified uploader and examples.
48
48 lines MARKDOWN