channels: wechat message scraping into context and memory (follow-up to #1991) (#1990)
Summary
- Add
wechat_scanner— a pure-CDP DOM poller for embedded WeChat Web (chat list + active conversation bubbles) with no page-world JS. - Define
webview_accounts::wechat_ingestas the shared ingest contract:webview:eventenvelopes for the respond queue plusopenhuman.memory_doc_ingestparams underwechat-web:<account_id>namespaces. - Wire the scanner into webview account open/teardown and register
wechatsession-cookie detection for onboarding heuristics. - Support opt-out via
OPENHUMAN_DISABLE_WECHAT_SCANNER=1.
Problem
WeChat Web could be embedded (#1991) but message content never reached agent context or memory.
Solution
Follow the Telegram/WhatsApp CDP scanner pattern: periodic DOM snapshot with broad heuristics, emit ingest events when the scan hash changes, and upsert memory docs via the core contract.
Submission Checklist
- [x] Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
- [x] Diff coverage ≥ 80% — enforced by CI diff-cover; full local
pnpm test:coverage/pnpm test:rustnot completed (see Validation Blocked) - [x] Coverage matrix updated — N/A: no matrix row for WeChat scraping yet
- [x] All affected feature IDs from the matrix are listed in the PR description under
## Related— N/A - [x] No new external network dependencies introduced (mock backend used per Testing Strategy)
- [x] Manual smoke checklist updated — N/A
- [x] Linked issue closed via
Closes #1990in the## Relatedsection
Impact
- Desktop CEF: WeChat webview accounts get background CDP scraping into respond queue and
wechat-web:*memory namespaces. - Users can disable scraping with
OPENHUMAN_DISABLE_WECHAT_SCANNER=1or purge via existing memory controls.
Related
- Closes #1990
- Follow-up to embedded WeChat webview support (#1991)
AI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
- Key: N/A
- URL: https://github.com/tinyhumansai/openhuman/issues/1990
Commit & Branch
- Branch:
cursor/a03-1990-wechat-message-scraping - Commit SHA:
4c995730d1ab8c0059a8f58e6ff597f32e088ad7
Validation Run
- [x]
cargo check --manifest-path app/src-tauri/Cargo.toml - [x]
cargo fmt --manifest-path Cargo.toml --all --check - [x]
cargo fmt --manifest-path app/src-tauri/Cargo.toml --all --check - [x]
cargo test --manifest-path Cargo.toml wechat_ingest - [x]
cargo test --manifest-path app/src-tauri/Cargo.toml wechat_scanner - [x]
pnpm --filter openhuman-app format:check - [x]
pnpm typecheck - [x]
pnpm lint - [x] Focused tests:
cargo test -p openhuman --lib wechat(8 passed),openhuman::webview_accounts(18 passed)
Validation Blocked
command:pnpm test:coverageandpnpm test:rusterror:Not run to completion in this sessionimpact:CI diff-cover gate must pass before merge
Behavior Changes
- Intended behavior change: WeChat Web scraping into context and memory when embedded webview is open.
- User-visible effect: WeChat chats can surface in respond queue; memory docs under
wechat-web:<account>.
Parity Contract
- Legacy behavior preserved: Zero JS injection; CDP-only like Telegram/WhatsApp scanners.
- Guard/fallback/dispatch parity checks: Ingest envelope matches existing webview ingest handler.
Duplicate / Superseded PR Handling
- Duplicate PR(s): None
- Canonical PR: This PR
- Resolution (closed/superseded/updated): N/A
Made with Cursor
Summary by CodeRabbit
-
New Features
- Support for scanning and capturing WeChat Web chat lists and message conversations.
- Automatic detection and registration of active WeChat Web logins and per-account scanner lifecycle.
- Environment toggle to disable the WeChat scanner.
-
Data & Validation
- Payload normalization, validation, and generation of list snapshots and per-chat transcripts for ingestion.
-
Tests
- Unit tests covering hashing, validation, ingest envelope shape, and scanner enable/disable behavior.
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] ▶️ Resume reviews
- [ ] 🔍 Trigger review
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 08dc9e74-04e6-41c2-ba26-dc48043acb0a
📥 Commits
Reviewing files that changed from the base of the PR and between 7f0e77c4e417bf066207bd9ae54539354349ecb3 and ba71274120c2eb830cdeffca4a2f1c4905064f8c.
📒 Files selected for processing (1)
app/src-tauri/src/wechat_scanner/mod.rs
📝 Walkthrough
Walkthrough
Adds WeChat webview support: provider detection, a CDP DOM scanner producing normalized WeChat scan payloads, per-account scanner tasks with dedupe and persistence to memory-doc RPCs, and Tauri lifecycle wiring to start/stop scanners.
Changes
WeChat Provider Scanning and Ingestion
| Layer / File(s) | Summary |
|---|---|
Ingest data model and normalization src/openhuman/webview_accounts/wechat_ingest.rs, src/openhuman/webview_accounts/wechat_ingest_test.rs, src/openhuman/webview_accounts/mod.rs |
Defines WechatScanPayload, WechatChatRow, and WechatMessageRow; adds validate_scan, builds JSON-RPC ingest envelopes and list payloads, and generates memory-doc maps for chat-list snapshots and peer transcripts with helpers and tests. |
DOM scanning and capture app/src-tauri/src/wechat_scanner/dom_snapshot.rs |
CDP DOM extraction of chat rows and message bubbles; classifies elements by tag/class heuristics, extracts unread counts and message senders, computes stable hash for deduplication, and converts DomScan to normalized WechatScanPayload. |
Scanner task lifecycle and persistence app/src-tauri/src/wechat_scanner/mod.rs |
Per-account async scanner loop with startup delay and scan interval; connects to CDP, runs DOM scrapes, deduplicates by hash, validates payloads, emits Tauri ingest events, and asynchronously persists list snapshots and per-chat transcripts. Includes ScannerRegistry and env-var disable. |
Provider detection and registration src/openhuman/webview_accounts/ops.rs |
Adds wechat provider entry with web.wechat.com host suffix and session cookie names; adds unit test detecting wxuin cookie. |
App startup and lifecycle integration app/src-tauri/src/lib.rs, app/src-tauri/src/webview_accounts/mod.rs |
Declares and registers wechat_scanner and its ScannerRegistry in Tauri managed state; wires scanner startup on account open via ensure_scanner and teardown via forget / forget_all; updates docs to include WeChat as zero-injection provider. |
Sequence Diagram(s)
sequenceDiagram
participant WebView
participant CDP
participant WechatScanner
participant MemoryDocRPC
participant TauriApp
WebView->>CDP: expose page targets / DOM
WechatScanner->>CDP: attach & capture DOM snapshot
CDP-->>WechatScanner: DOM snapshot
WechatScanner->>WechatScanner: parse DOM -> DomScan -> hash
alt new scan
WechatScanner->>TauriApp: emit "webview:event" (list ingest envelope)
WechatScanner->>MemoryDocRPC: post list snapshot & peer transcripts (JSON-RPC)
MemoryDocRPC-->>WechatScanner: RPC success/failure
end
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
- tinyhumansai/openhuman#1991: Adds WeChat provider registration and zero-injection designation in the webview-accounts plumbing, related to this PR's scanner and ingest implementation.
Suggested labels
memory
Suggested reviewers
- senamakel
Poem
🐰 I hopped through DOMs at break of day,
Found chats and hashes tucked away.
Rows and messages, neatly spun,
I bundled memories—one by one.
Hooray — the WeChat scanner's done!
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 52.63% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately describes the main change: adding WeChat message scraping into context and memory as a follow-up, which is the core purpose of this PR. |
| Linked Issues check | ✅ Passed | All acceptance criteria from #1990 are substantially met: embedded WeChat extraction via DOM scanning, context/memory ingestion with provider/account provenance, unread activity support, privacy controls via env-var gating, comprehensive tests including edge cases, and diff-coverage compliance mentioned as CI requirement. |
| Out of Scope Changes check | ✅ Passed | All file changes are directly scoped to WeChat integration: new wechat_scanner modules, webview_accounts integration, session detection, ingest contract, and tests—no unrelated modifications. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
Comment @coderabbitai help to get the list of available commands and usage tips.
@CodeGhost21 make sure this is tested locally once