@agent-wechat/cli 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +197 -0
  2. package/dist/cli.js +10 -7
  3. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,197 @@
1
+ # @agent-wechat/cli
2
+
3
+ Command-line tool for managing agent-wechat containers and interacting with WeChat.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @agent-wechat/cli
9
+ ```
10
+
11
+ This installs the `wx` command globally.
12
+
13
+ ## Prerequisites
14
+
15
+ - [Docker](https://docs.docker.com/get-docker/) installed and running
16
+
17
+ `wx up` automatically pulls the Docker image from ghcr.io if it isn't found locally.
18
+
19
+ > **Note:** agent-wechat requires `SYS_PTRACE` and `seccomp=unconfined` to interact with the WeChat desktop process. It cannot run in serverless or restricted container environments (AWS Fargate, Cloud Run, etc.). Use a VM or bare-metal Docker host.
20
+
21
+ ## Quick Start
22
+
23
+ ```bash
24
+ # Start the container
25
+ wx up
26
+
27
+ # Check status
28
+ wx status
29
+
30
+ # Log in (displays QR code in terminal)
31
+ wx auth login
32
+
33
+ # List chats
34
+ wx chats list
35
+
36
+ # Send a message
37
+ wx messages send <chatId> --text "Hello"
38
+ ```
39
+
40
+ ## Commands
41
+
42
+ ### Container
43
+
44
+ | Command | Description |
45
+ |---------|-------------|
46
+ | `wx up` | Start the agent-wechat container |
47
+ | `wx down` | Stop and remove the container |
48
+ | `wx logs` | Tail container logs |
49
+ | `wx status` | Show container and login status |
50
+
51
+ ### Auth
52
+
53
+ | Command | Description |
54
+ |---------|-------------|
55
+ | `wx auth login` | Log in to WeChat (shows QR code) |
56
+ | `wx auth logout` | Log out of WeChat |
57
+ | `wx auth status` | Check login status |
58
+ | `wx auth token` | Show current auth token |
59
+ | `wx auth token --regenerate` | Generate a new auth token |
60
+
61
+ Login options:
62
+ - `--timeout <seconds>` — login timeout (default: 300)
63
+ - `--new` — switch to a new account instead of existing
64
+
65
+ ### Chats
66
+
67
+ | Command | Description |
68
+ |---------|-------------|
69
+ | `wx chats list` | List chats from WeChat |
70
+ | `wx chats get <chatId>` | Get details for a specific chat |
71
+ | `wx chats find <name>` | Search chats by display name |
72
+ | `wx chats open <chatId>` | Open a chat in the WeChat UI |
73
+
74
+ Options: `--limit <n>`, `--offset <n>`, `--json`
75
+
76
+ ### Messages
77
+
78
+ | Command | Description |
79
+ |---------|-------------|
80
+ | `wx messages list <chatId>` | List messages in a chat |
81
+ | `wx messages send <chatId>` | Send a message |
82
+ | `wx messages media <chatId> <localId>` | Download a media attachment |
83
+
84
+ Send options:
85
+ - `--text "message"` — send text
86
+ - `--image photo.jpg` — send an image
87
+ - `--file document.pdf` — send a file
88
+
89
+ Media options:
90
+ - `--output <path>` — save to a specific file path
91
+
92
+ ### Sessions
93
+
94
+ | Command | Description |
95
+ |---------|-------------|
96
+ | `wx session list` | List all sessions |
97
+ | `wx session create <name>` | Create a new session |
98
+ | `wx session start <id>` | Start a session |
99
+ | `wx session stop <id>` | Stop a session |
100
+ | `wx session delete <id>` | Delete a session |
101
+
102
+ ### Debug
103
+
104
+ | Command | Description |
105
+ |---------|-------------|
106
+ | `wx screenshot [file]` | Save a screenshot (default: screenshot.png) |
107
+ | `wx a11y` | Dump the accessibility tree (`--format json|aria`) |
108
+
109
+ ## Global Options
110
+
111
+ | Option | Description |
112
+ |--------|-------------|
113
+ | `-s, --session <name>` | Use a specific session (default: "default") |
114
+ | `-V, --version` | Show version |
115
+ | `-h, --help` | Show help |
116
+
117
+ ## Configuration
118
+
119
+ The CLI reads configuration from environment variables and a local token file:
120
+
121
+ | Source | Description |
122
+ |--------|-------------|
123
+ | `AGENT_WECHAT_URL` | Server URL (default: `http://localhost:6174`) |
124
+ | `AGENT_WECHAT_TOKEN` | Auth token (overrides token file) |
125
+ | `~/.config/agent-wechat/token` | Auto-generated auth token |
126
+
127
+ The auth token is generated automatically on first run and shared with the container via a read-only volume mount.
128
+
129
+ ## Running the Container
130
+
131
+ There are two ways to run the agent-wechat container.
132
+
133
+ > **Note:** agent-wechat requires `SYS_PTRACE` and `seccomp=unconfined` because it uses ptrace to interact with the WeChat desktop process. It cannot run in serverless or restricted container environments (AWS Fargate, Cloud Run, Azure Container Instances, etc.). Use a VM or bare-metal Docker host.
134
+
135
+ ### Option 1: `wx up` (local development)
136
+
137
+ The simplest way. `wx up` pulls/starts the container with the right flags, volume mounts, and auth token:
138
+
139
+ ```bash
140
+ wx up
141
+ ```
142
+
143
+ This starts a container named `agent-wechat` with:
144
+ - **Port 6174** — REST API (exposed to all interfaces)
145
+ - **Port 5900** — VNC (localhost only — use SSH tunnel for remote access)
146
+ - Persistent volumes for data and WeChat home directory
147
+ - Auth token from `~/.config/agent-wechat/token` (auto-generated on first run)
148
+
149
+ ### Option 2: Docker Compose (production / networked)
150
+
151
+ For production or when running alongside other services (e.g., OpenClaw), use the `docker-compose.yml` in the repo root as a reference:
152
+
153
+ ```yaml
154
+ services:
155
+ agent-wechat:
156
+ image: ghcr.io/thisnick/agent-wechat:latest
157
+ container_name: agent-wechat
158
+ security_opt:
159
+ - seccomp=unconfined
160
+ cap_add:
161
+ - SYS_PTRACE
162
+ ports:
163
+ - "6174:6174"
164
+ - "127.0.0.1:5900:5900"
165
+ volumes:
166
+ - agent-wechat-data:/data
167
+ - agent-wechat-home:/home/wechat
168
+ - ~/.config/agent-wechat/token:/data/auth-token:ro
169
+ restart: unless-stopped
170
+
171
+ volumes:
172
+ agent-wechat-data:
173
+ agent-wechat-home:
174
+ ```
175
+
176
+ Generate a token before starting:
177
+
178
+ ```bash
179
+ mkdir -p ~/.config/agent-wechat
180
+ openssl rand -hex 32 > ~/.config/agent-wechat/token
181
+ chmod 600 ~/.config/agent-wechat/token
182
+ ```
183
+
184
+ If running alongside OpenClaw on the same Docker network, set `serverUrl` to `http://agent-wechat:6174` in your OpenClaw config.
185
+
186
+ ### Building locally
187
+
188
+ To build the Docker image from source instead of pulling from ghcr.io:
189
+
190
+ ```bash
191
+ # From the repo root — auto-detects host architecture
192
+ pnpm build:image
193
+
194
+ # Or specify architecture
195
+ pnpm build:image:arm64
196
+ pnpm build:image:amd64
197
+ ```
package/dist/cli.js CHANGED
@@ -7906,6 +7906,7 @@ import path from "path";
7906
7906
  import { fileURLToPath } from "url";
7907
7907
  var VERSION = "0.1.0";
7908
7908
  var CONTAINER_NAME = "agent-wechat";
7909
+ var GHCR_IMAGE = "ghcr.io/thisnick/agent-wechat";
7909
7910
  var DEFAULT_PORT = 6174;
7910
7911
  var VNC_PORT = 5900;
7911
7912
  var __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -7939,9 +7940,7 @@ function getConfig() {
7939
7940
  };
7940
7941
  }
7941
7942
  function getImageTag() {
7942
- const arch = os.arch();
7943
- if (arch === "arm64") return "agent-wechat:arm64";
7944
- return "agent-wechat:amd64";
7943
+ return `${GHCR_IMAGE}:latest`;
7945
7944
  }
7946
7945
  var program2 = new Command();
7947
7946
  program2.name("wx").description("WeChat automation CLI").version(VERSION).option("-s, --session <name>", "Use specified session", "default");
@@ -8438,9 +8437,13 @@ async function cmdUp() {
8438
8437
  try {
8439
8438
  execSync(`docker image inspect ${image}`, { stdio: "ignore" });
8440
8439
  } catch {
8441
- console.error(`Image ${image} not found.`);
8442
- console.error(`Run 'pnpm build:image' first to build the image.`);
8443
- process.exit(1);
8440
+ console.log(`Image ${image} not found locally. Pulling...`);
8441
+ try {
8442
+ execSync(`docker pull ${image}`, { stdio: "inherit" });
8443
+ } catch {
8444
+ console.error(`Failed to pull ${image}. Check your internet connection and Docker setup.`);
8445
+ process.exit(1);
8446
+ }
8444
8447
  }
8445
8448
  const token = ensureToken();
8446
8449
  console.log(`Starting container ${CONTAINER_NAME} from ${image}...`);
@@ -8484,7 +8487,7 @@ Waiting for server to be ready...`);
8484
8487
  await new Promise((r) => setTimeout(r, 1e3));
8485
8488
  process.stdout.write(".");
8486
8489
  }
8487
- console.log("\nServer did not become ready in time. Check logs with: pnpm cli logs");
8490
+ console.log("\nServer did not become ready in time. Check logs with: wx logs");
8488
8491
  } catch (error) {
8489
8492
  console.error("Failed to start container:", error);
8490
8493
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-wechat/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "wx": "./dist/cli.js"