Skip to content

[Bug] wx init fails to auto-detect xwechat data directory (v0.3.0) #74

@digibeing1001

Description

@digibeing1001

Environment

  • OS: Windows 11 + WSL2 (Ubuntu)
  • WeChat Version: xwechat (new WeChat desktop, not legacy WeChat)
  • wx-cli Version: 0.3.0
  • Install Method: npm install -g @jackwener/wx-cli

Data Directory Structure

The new xwechat stores data at:

C:\Users\zexin\Documents\xwechat_files\
├── Backup/
├── WMPF/
├── all_users/
├── kenny_blog_ba4b/
├── wxid_3vmmyby98la022_906b/
│   ├── db_storage/
│   │   ├── message/
│   │   │   ├── biz_message_0.db
│   │   │   ├── media_0.db
│   │   │   ├── message_0.db
│   │   │   ├── message_1.db
│   │   │   └── ...
│   │   ├── contact/
│   │   ├── favorite/
│   │   └── ...
│   ├── msg/
│   └── resource/
└── wxid_lcdlrizly9bj02_7c92/
    └── ...

Problem

1. wx init fails with auto-detection error

$ wx init
检测微信数据目录...
错误: 未能自动检测到微信数据目录
请手动编辑 config.json 中的 db_dir 字段

Even after manually creating config.json with the correct db_dir:

{"db_dir":"C:\\Users\\zexin\\Documents\\xwechat_files\\wxid_3vmmyby98la022_906b"}

wx init still fails with the same auto-detection error. It seems wx init ignores the db_dir config and always tries auto-detection first.

2. Other commands fail due to missing all_keys.json

$ wx sessions
启动 wx-daemon...
错误: wx-daemon 启动超时(>15s)

Daemon log shows:

[daemon] DB_DIR: C:\Users\zexin\Documents\xwechat_files\wxid_3vmmyby98la022_906b
[daemon] 启动失败: 读取密钥文件 "C:\\Users\\zexin\\.wx-cli\\all_keys.json" 失败: 系统找不到指定的文件。 (os error 2)

Expected Behavior

  1. wx init should recognize xwechat data directory structure (xwechat_files/wxid_*_*/db_storage)
  2. OR wx init should use db_dir from config.json when auto-detection fails
  3. OR provide a --db-dir CLI flag to manually specify the data directory

Workarounds Tried

  1. ✅ Created config.json with correct db_dir — ignored by wx init
  2. ❌ Tried WX_CLI_DB_DIR environment variable — not supported
  3. ❌ Tried wx init --force — same auto-detection error

Suggested Fix

Option A: Add xwechat path patterns to auto-detection:

  • %USERPROFILE%\Documents\xwechat_files\wxid_*
  • %USERPROFILE%\Documents\xwechat_files\*\db_storage

Option B: Make wx init fall back to db_dir from config.json when auto-detection fails

Option C: Add --db-dir CLI argument to wx init

Additional Context

The legacy WeChat path (WeChat Files/wxid_*/Msg) works fine, but the new xwechat uses a completely different structure:

  • Root: xwechat_files instead of WeChat Files
  • Account dirs: wxid_*_xxxx (with suffix) instead of wxid_*
  • Database location: db_storage/message/ instead of Msg/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions