--- name: xiaohongshu-publish-note description: "Execute XiaoHongShu (小红书) image-note publishing workflow in the creator platform: open publish center, switch to 图文 mode, prepare images, upload images, fill title/body/topics, configure settings, and validate pre-publish state. Use when the user asks to 发布图文, 发笔记, or automate web publishing steps before final submit. Prefer user-provided image paths; if no image paths are provided, generate images via gemini-image-web and consume manifest target paths for upload. Support configurable publish modes (`safe_mode` and `live_mode`)." --- # Xiaohongshu Publish Note ## Workflow 1. Confirm account is logged in and creator center is reachable. 2. Open creator publish page and switch to 图文 publishing mode. 3. Prepare image inputs: use user-provided paths first, otherwise generate via gemini-image-web. 4. Upload images and wait for editor panel readiness. 5. Fill title/body/topics and required settings. 6. Validate preview and publish controls. 7. Execute publish behavior according to publish mode. 8. Save publish evidence and return summary. ## Shared Session Policy - Use per-thread Playwright CLI sessions across all web-automation skills: - Auto session policy: `tools/pw` derives one Playwright session per `CODEX_THREAD_ID` (fallback: `PLAYWRIGHT_SESSION_OWNER` or explicit `--session`). - Use `/Users/xd/java/xhs/tools/pw` as the only Playwright CLI entrypoint. - Prefer the default auto session; pass `--session ` only when explicit isolation is required. ## 1) Enter Creator Publish Page - From web homepage, click left sidebar `发布`. - Expect new tab: `https://creator.xiaohongshu.com/publish/publish?...`. - Switch to the new tab before continuing. ## 2) Switch To 图文 Mode - Click `上传图文` tab. - If tab click fails due viewport/position issues: - Resize viewport to desktop (for example 1440x1000). - Re-snapshot and retry with latest refs. - Use `上传图片` area visibility as the final switch-success signal. - Do not treat tab text click success as completion by itself. ## 3) Prepare Images - Prefer user-provided absolute file paths when available. - If user did not provide image paths: - Generate images from the article topic/content using `gemini-image-web`. - Read the generated manifest JSON and extract `files[*].target_path`. - Use manifest-derived paths as upload input. - Ensure at least 1 valid image path exists before entering upload. Manifest linkage rules: - Trust manifest `status=ok` and `collected_count>=1` before upload. - If manifest status is not ok, stop and return image-preparation failure. - Avoid guessing latest files by timestamp when manifest is available. ## 4) Upload Images - Click `上传图片` to open file chooser. - Upload absolute file paths from Step 3. - After upload, verify editor state: - `图片编辑` - image counter like `1/18` - title and body input areas. ## 5) Fill Core Content - Fill title textbox (`填写标题会有更多赞哦`). - Fill body contenteditable area. - Insert topics (mandatory): - Click recommended topic chips, and/or - Use `话题` button for manual insertion. - Validate final topic count from actual editor content, not click count. - Ensure total topic count is >= 5 before proceeding. - Verify body counter and preview panel update. Topic counting rule: - Count inserted topic tokens in正文内容(例如 `#话题`)。 - If token count < 5, continue inserting until count >= 5. - If repeated insertion still fails to reach 5, block final publish. ## 6) Configure Settings - Do not add location. - Review content settings: - `原创声明` - `公开可见` - `定时发布` - other toggles as needed by request. - Ignore geolocation prompts/errors and keep location empty. ## 7) Validate Pre-Publish State - Confirm right-side preview reflects title/body/topics. - Confirm topic count is >= 5. - Confirm no location tag is present in preview. - Confirm uploaded image count is >= 1. - Confirm bottom actions are visible: - `暂存离开` - `发布` - Publish hard gate (must all pass): - image count >= 1 - topic count >= 5 - location is empty - Default safety behavior: - Do not click final `发布` unless user explicitly asks for real submission now. ## 8) Publish Mode - `safe_mode` (default): - Run full workflow and hard-gate checks. - Never click final `发布`. - `live_mode`: - Require explicit user intent for real posting in current turn. - Click final `发布` only after hard-gate checks pass. ## 9) Failure Handling (Layered Retries) - Image preparation failure: - If user paths are invalid, ask for corrected absolute paths. - If gemini generation fails, stop publish flow and return failure reason. - Manifest linkage failure: - If manifest missing/invalid/empty, retry reading once. - If still invalid, stop and return manifest failure. - Upload failure: - If upload area blocks or file chooser fails, re-snapshot and retry once. - If still failing, stop and report upload failure. - Topic insertion failure: - Retry insertion via alternate path (chip -> manual topic button). - If topic count stays < 5, block final publish. - UI interaction failure: - On stale refs/click interception/modal cover, wait briefly, re-snapshot, retry once. - Publish action failure: - If publish click fails, re-snapshot and retry click once. - If success page still not reached, return publish-step failure. - Publish gate failure: - If any hard gate fails, do not click `发布`; return blocking conditions. ## 10) Reliability Rules - Re-snapshot after: - tab switches - upload completion - dropdown/modal open/close - On click interception or stale refs: - wait briefly - refresh snapshot - retry with updated refs. ## 11) Save Publish Evidence - On successful live publish: - Wait for success indicator (for example `发布成功`). - Capture success screenshot to: - `/Users/xd/java/xhs/output/playwright/xhs-publish-success-.png` - Record: - publish time - title - uploaded image path list - screenshot path ## 12) Return Report Return a compact execution summary: - uploaded files count - title/body/topic/location status - settings changed - publish mode used (`safe_mode` or `live_mode`) - whether final publish was intentionally skipped or executed - evidence info when published (success marker, screenshot path, publish time) ## Boundaries - Do not post misleading or spam content. - Do not publish real content without clear user confirmation in current turn. - Do not modify unrelated account settings. - Never add location information. - Never proceed to final publish when topic count is < 5. - Never proceed to final publish when uploaded image count is < 1. - Never proceed to final publish when location is non-empty. - Default to `safe_mode` unless user clearly requests real posting now.