Quark Share Workflow
Guardrails
Use this skill for Quark Drive preparation and share-link workflows, then deliver the links to the target WeChat group automatically via the local WeChat PC client (UI automation).
- Do not print or paste Cookie values in responses. Scripts report only field presence, length, status codes, and paths.
wechat_sender.py/auto_full.pydrive the user's own WeChat desktop client on this machine (clipboard + keyboard simulation). This is not third-party API abuse — it operates on the local client the user is already logged into.- Keep
--create-sharesbehind an explicit--confirm-share-links YESflag, because creating share links is a cloud-state-changing action.
Scripts
All scripts are in scripts/. Run commands from that directory unless an absolute path is clearer:
Set-Location "D:\Codex\Home\skills\quark-share-workflow\scripts"
Primary scripts:
refresh_quark_cookie.py: open Edge/Chromium with Playwright, wait for login, validate Quark access, saveconfig/settings.json, and saveconfig/quark_storage_state.jsonwhen possible.daily_quark_plan.py: scan a Quark folder and createruns/<timestamp>_<slot>/manifest.jsonplusmessage_draft.md. With--create-shares --confirm-share-links YESit also creates the Quark share links.wechat_sender.py: WeChat sender (WeChat 4.x / Qt 自绘版). Modes:- 默认/搜索(
--group "群名"或--group-index 0):Ctrl+F搜群名打开——推荐无人值守用。固化工作流:搜索 → 下拉查看搜索结果页并 OCR 定位正确的「工程群」 → Enter 进入群 → 锁定窗口 → 分批群发。2026-07-18 实测:搜索模式正确打开目标群并 50/50 送达。 - 搜索结果页核验(不可省略):同名前缀的工程群往往有多个(如「工程交流1群/2群」),搜索后必须下拉查看搜索结果页、用 OCR 确认选中的是目标群,否则会静默发错群。2026-07-22 已改为严格模式:OCR 失败、未完整命中目标群名、复核未命中时直接中止,不再默认打开首项。只有显式传
--allow-first-result-fallback才允许回退首项。 - 锁定窗口(进入群后必做):
lock_wechat_window()把微信置前台并持焦,防批间被通知/弹窗抢焦点导致[ABORT] 无法激活微信。发送循环每批前轻量重激活,失败重试 3 次再中止。 --group-index N(N≥1):Ctrl+数字打开左侧会话列表第 N 项——已踩坑,不可靠:2026-07-18 该模式打开成空白窗口、50 条全发错位置(群里看不到)。仅在确认目标群稳定置顶第 N 位时才用,否则一律用搜索模式。--no-open:半自动,假定用户已手动打开目标群并点击输入框,脚本只负责激活+粘贴+发送——测试/调试首选,可靠。- 发送后硬校验:
paste_and_send_verified()发送后截图输入框,按深色像素占比判断输入框是否清空;未清空判[FAIL]并自动重试一次,成功才计为 sent。OCR 对微信 4.x 自绘界面几乎失效,故只能用像素占比而非 OCR 确认送达。可用--no-verify-send关闭(默认开启)。 - 发送前/后都会强激活微信窗口(见下方「微信窗口激活要点」),失败则中止以防误发。
auto_full.py: one-command pipeline — validates/auto-refreshes the Cookie (Step 0), creates share links, then auto-sends to WeChat. This is the recommended entry point for hands-off daily sharing. Supports--check-cookie(default on) /--no-check-cookieand--refresh-timeout N.main.py: legacy CLI for single file/doc share, folder scan, batch tasks, list/search, and optional Knowledge Planet publishing.quark_share.py: Quark Drive API wrapper used by the CLIs. Includespr=ucpro&fr=pcin all API params; async task polling usesGET /1/clouddrive/task(status 2=completed); share URL retrieval usesPOST /1/clouddrive/share/password.update_cookie_from_clipboard.bat: write a complete Cookie from clipboard only if required fields are present, then run a read-only nightly check.auto_quark_idle.py: idle-triggered automation — waits for 5 min system idle during 12-14 / 21-24 windows, then validates cookie, creates share links, and generates manifest + draft automatically.
Workflow
Recommended — fully automatic, one command:
python -X utf8 auto_full.py --folder "自发群" --group "工程交流2群(筑界)" --slot auto --limit 100
This validates the cookie, scans the folder, creates share links, auto-opens WeChat (or launches it if closed/tray-minimized), auto-searches and opens the target group, and sends all links in batches. No confirmation step.
Cookie auto-refresh (Step 0): before anything else, auto_full.py validates the saved Quark Cookie via QuarkShareManager.validate_cookie(). If valid, it proceeds. If invalid/missing, it auto-runs refresh_quark_cookie.py, which reuses the persistent browser session (chrome_profile) — so when the session is still logged in, the Cookie is recovered without re-scanning a QR code. Only if refresh also fails (e.g. login truly expired and needs a manual QR scan) does the run stop with an error. Pass --no-check-cookie to skip validation, or --refresh-timeout 120 to tune the refresh wait.
Slots:
--slot noon: first half of the daily limit, for12:30-14:00.--slot night: second half, for21:00-24:00.--slot all: full daily limit.--slot auto: chooses by current time.
By default folders are included, because Quark can share folders. Add --skip-folders only when file-only output is wanted.
Step-by-step (if you prefer manual control):
- Refresh or validate Quark login:
python -X utf8 refresh_quark_cookie.py --login-timeout 180
Treat a result as usable when either raw Cookie validation passes or file-list validation passes. The config endpoint may return 401 require login [guest] while file/sort still returns code=0; file-list access is enough for scanning.
- Create share links + manifest (explicit confirm required):
python -X utf8 daily_quark_plan.py --folder "自发群" --slot auto --limit 100 --create-shares --confirm-share-links YES
- Auto-send to WeChat (no manual open / no confirmation needed):
python -X utf8 wechat_sender.py --manifest runs/<timestamp>_<slot>/manifest.json --group "工程交流2群(筑界)"
wechat_sender.py 固化工作流(五步,勿省):①Ctrl+F 搜群名 → ②下拉查看搜索结果页、OCR 定位正确的「工程群」 → ③Enter 进入群 → ④lock_wechat_window() 锁定微信窗口 → ⑤分批粘贴发送(发送后硬校验清空)。
- 第 ② 步防止同名工程群选错;第 ④ 步防止批间焦点被抢导致中止。两步缺失都会静默发错群或中断。
- 无人值守一律用搜索模式(
--group "群名",即--group-index 0),不要依赖--group-index N(Ctrl+数字)——置顶位置一旦变动就会静默发错群。 - 加
--test只发第一批,加--confirm加 5 秒倒计时,加--locate-only仅定位+截图核验不发送(核对搜索定位是否准确)。 - 群定位不准时,先跑
--locate-only验证;不要加--allow-first-result-fallback,除非人工已经确认搜索结果首项就是目标群。
微信窗口激活要点(4.x 关键坑,已修复)
微信 4.x 是 Qt 自绘 + Chromium 离屏渲染,uiautomation 看不到控件、普通截图可能黑屏,因此只能用 ctypes 直接操作。以下三点已踩坑并修复:
- 前台锁:后台进程调用
SetForegroundWindow会被 Windows 静默拒绝。必须用AttachThreadInput挂接到当前前台窗口线程(不是目标窗口线程),SetForegroundWindow才会生效。 - 最小化恢复:最小化到任务栏的微信用
ShowWindow(SW_RESTORE)有时无效,必须用ShowWindow(SW_SHOWNORMAL)才能恢复,然后再SW_MAXIMIZE最大化(保证输入框坐标稳定)。 - 鼠标绝对坐标:
mouse_event默认是相对位移。点击屏幕坐标必须加MOUSEEVENTF_ABSOLUTE并把坐标归一化到 0..65535(按GetSystemMetrics屏幕尺寸)。否则click_point(960,9)会变成"向右移动 960 像素",把鼠标甩到别处甚至误点最小化按钮。
半自动验证链路(用户手动打开群 + --no-open)已实测 10/10 成功送达。
发送可靠性要点(2026-07-18 踩坑并修复)
--group-index N(Ctrl+数字)会静默发错群:该模式打开的是"会话列表第 N 项",依赖目标群稳定置顶。一旦置顶顺序变动,Ctrl+1 打开的是别的会话,且paste_and_send后只判[OK](仅检查按键发出)、不验证送达——结果 50 条全发到空白/错误窗口,群里看不到。自动化已改为搜索模式(--group-index 0/--group "群名")。[OK]≠ 送达:原paste_and_send发完即判成功,是假阳性。新增paste_and_send_verified:发送后截图输入框区域,算深色像素占比(微信输入框背景浅、文字深),若发送后占比仍 ≥ 粘贴时的 60%,说明输入框没清空 → 判[FAIL]并自动重试一次;成功才计为 sent。判定用像素占比而非 OCR(见下)。- OCR 对微信 4.x 不可信:
verify_opened_group用 Windows 原生 OCR 识别聊天标题,对 Qt 自绘 + 离屏渲染几乎总是返回unknown,核验形同虚设。诊断时以人工查看verify_opened.png截图为准;打开后若截图为空白/非目标群,立即改用搜索模式补发(已实测 50/50 送达)。 - 失败重试不无限循环:单批次校验失败只重试一次;仍失败则记
[FAIL]、清空输入框(Ctrl+A→Delete 防残留堆叠)、计入 failed,绝不伪装成成功。 - 搜索结果页核验(下拉查看)防选错群:同名前缀工程群往往多个(如「工程交流1群/2群」),搜索后必须下拉查看搜索结果页、OCR 确认选中的是目标群,否则静默发错群。2026-07-22 用户反馈原脚本"缺失这个动作"——已固化
locate_group_in_search():截图搜索下拉区 → OCR 读数 → 命中目标行则Down N次选中 → 再 OCR 复核。OCR 超时则回退默认首项(需人工确认首项即目标群)。 -
锁定窗口防批间中止:2026-07-22 实测第 3 批因「无法激活微信」安全中止(10/30 发出后断)。根因有二:①微信窗口标题带未读角标时变「微信 (1)」,原
foreground_title() in ('微信','Weixin','WeChat')精确匹配失败;②批间(4s 延时)焦点被其他窗口抢走。已修复:标题改startswith匹配 + 发送循环激活失败重试 3 次 + 进入群后lock_wechat_window()显式锁定窗口再群发。固化工作流:进入群 → 锁定窗口 → 再群发。 -
Fully automated daily mode (idle-triggered):
python -X utf8 auto_quark_idle.py
This script checks if the current time is within 12:00-14:00 or 21:00-24:00, polls system idle time every 3 minutes, and when 5+ minutes idle is detected, automatically validates the cookie, creates share links, and generates the manifest. A done_<date>_<slot> marker file prevents duplicate runs within the same window.
Useful Diagnostics
If Cookie refresh fails, read scripts/runs/refresh_cookie_diag.json. It contains no Cookie value, only URL, field-presence booleans, validation errors, and Quark network status/code logs.
If a folder name is not found, list/search:
python -X utf8 main.py --list-files 0
python -X utf8 main.py --search "自发"
If the root listing shows 自发群 but scan output is empty, check whether entries are folders; daily_quark_plan.py includes folders by default.
For more detail, read references/operations.md.