cli-wechat-bridge 1.1.5 → 1.1.7
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.
- package/README.md +212 -232
- package/bin/_run-entry.mjs +20 -5
- package/bin/wecom-check-update.mjs +5 -0
- package/bin/wecom-claude.mjs +5 -0
- package/bin/wecom-codex.mjs +5 -0
- package/bin/wecom-daemon.mjs +5 -0
- package/bin/wecom-opencode.mjs +5 -0
- package/bin/wecom-pi.mjs +5 -0
- package/bin/wecom-setup.mjs +5 -0
- package/dist/bridge/bridge-adapters.claude.js +128 -4
- package/dist/bridge/bridge-adapters.codex.js +214 -23
- package/dist/bridge/bridge-adapters.core.js +2 -1
- package/dist/bridge/bridge-adapters.pi.js +1 -1
- package/dist/bridge/bridge-adapters.shared.js +2 -1
- package/dist/bridge/bridge-final-reply.js +2 -65
- package/dist/bridge/bridge-process-reaper.js +35 -2
- package/dist/bridge/bridge-state.js +11 -4
- package/dist/bridge/bridge-utils.js +4 -96
- package/dist/bridge/wechat-bridge.js +476 -206
- package/dist/bridge/wechat-forwarding.js +2 -58
- package/dist/bridge/wechat-outbound-queue.js +2 -0
- package/dist/channels/wechat/bridge-final-reply.js +65 -0
- package/dist/channels/wechat/channel-message.js +24 -0
- package/dist/channels/wechat/index.js +5 -0
- package/dist/channels/wechat/wechat-channel-port.js +67 -0
- package/dist/channels/wechat/wechat-forwarding.js +79 -0
- package/dist/channels/wechat/wechat-outbound-queue.js +79 -0
- package/dist/channels/wecom/bridge-final-reply.js +26 -0
- package/dist/channels/wecom/setup-cli.js +6 -0
- package/dist/channels/wecom/setup.js +176 -0
- package/dist/channels/wecom/wecom-channel-port.js +45 -0
- package/dist/channels/wecom/wecom-config.js +66 -0
- package/dist/channels/wecom/wecom-media.js +141 -0
- package/dist/channels/wecom/wecom-message.js +149 -0
- package/dist/channels/wecom/wecom-transport.js +308 -0
- package/dist/companion/codex-remote-client.js +2 -1
- package/dist/companion/local-companion-start.js +49 -9
- package/dist/companion/local-companion.js +2 -1
- package/dist/core/bridge-control.js +32 -0
- package/dist/core/bridge-event-forwarder.js +50 -0
- package/dist/core/bridge-message-router.js +32 -0
- package/dist/core/channel-types.js +3 -0
- package/dist/core/direct-run.js +17 -0
- package/dist/core/inbound-message-claims.js +61 -0
- package/dist/core/text-utils.js +63 -0
- package/dist/daemon/daemon-link.js +3 -0
- package/dist/daemon/wechat-daemon.js +466 -172
- package/dist/i18n/messages-en.js +4 -2
- package/dist/i18n/messages-zh.js +4 -2
- package/dist/utils/doctor.js +30 -10
- package/dist/wechat/setup.js +113 -13
- package/package.json +117 -107
package/dist/i18n/messages-en.js
CHANGED
|
@@ -25,7 +25,7 @@ export const messages = {
|
|
|
25
25
|
// === Hook health check ===
|
|
26
26
|
"hook.healthCheck.warning": "[Warning] No hook events received from Claude after 15s.\nThe hook system may not be working — Claude output will not reach WeChat.",
|
|
27
27
|
"hook.healthCheck.logHint": "\nCheck: {logPath}",
|
|
28
|
-
"hook.healthCheck.fixes": "\nCommon fixes:\n- Ensure Node.js >= 22.
|
|
28
|
+
"hook.healthCheck.fixes": "\nCommon fixes:\n- Ensure Node.js >= 22.13.0: node --version\n- Reinstall: npm install -g cli-wechat-bridge@latest\n- Check firewall: allow localhost TCP connections",
|
|
29
29
|
// === PTY fallback ===
|
|
30
30
|
"pty.fallback.warning": "[Warning] PTY unavailable — using fallback mode (TERM=dumb).\nCore features (messaging, approvals, session management) work normally; terminal rendering (colors, progress bars) may be degraded.\nFix: Linux install build-essential python3 | Windows run npm rebuild node-pty | macOS run xcode-select --install\nRun --doctor for detailed environment info.\n",
|
|
31
31
|
// === Spawn diagnostic ===
|
|
@@ -36,7 +36,7 @@ export const messages = {
|
|
|
36
36
|
"spawn.diagnostic.linuxBuildTools": "- Linux requires build tools for node-pty: sudo apt install build-essential python3\n- Then reinstall: npm install -g cli-wechat-bridge@latest",
|
|
37
37
|
"spawn.diagnostic.notFound": "- The command \"{target}\" was not found on PATH.\n- Verify it is installed and accessible from your terminal.",
|
|
38
38
|
"spawn.diagnostic.generic": "- Reinstall: npm install -g cli-wechat-bridge@latest",
|
|
39
|
-
"spawn.diagnostic.nodeVersion": "- Ensure Node.js >= 22.
|
|
39
|
+
"spawn.diagnostic.nodeVersion": "- Ensure Node.js >= 22.13.0: node --version",
|
|
40
40
|
"spawn.diagnostic.winFull": "- Ensure Windows 10 build 18309+ (run 'winver' to check)\n- Install Visual C++ Redistributable: https://aka.ms/vs/17/release/vc_redist.x64.exe\n- Run: npm rebuild node-pty\n- Try running as Administrator",
|
|
41
41
|
// === Emoji bindings ===
|
|
42
42
|
"binding.usage": "Invalid format.\nUsage: /bind [emoji] command\nExample: /bind 🚀 deploy --prod",
|
|
@@ -59,6 +59,7 @@ export const messages = {
|
|
|
59
59
|
"doctor.label.codePage": "Console code page",
|
|
60
60
|
"doctor.codePage.nonAsciiWarning": "{codePage} (not UTF-8 and the data directory path contains non-ASCII characters; hook scripts from older versions break in this environment — upgrade to the latest release)",
|
|
61
61
|
"doctor.label.connectivity": "WeChat connectivity",
|
|
62
|
+
"doctor.label.wecomConnectivity": "WeCom connectivity",
|
|
62
63
|
"doctor.connectivity.ok": "reachable ({baseUrl})",
|
|
63
64
|
"doctor.connectivity.unreachable": "cannot reach {baseUrl} (check network and firewall)",
|
|
64
65
|
"doctor.connectivity.proxyHint": "cannot reach {baseUrl}. Proxy {proxy} detected, but Node fetch ignores proxy environment variables by default; if your network requires the proxy, set NODE_USE_ENV_PROXY=1 and retry.",
|
|
@@ -82,6 +83,7 @@ export const messages = {
|
|
|
82
83
|
"doctor.dataDirMissing": "(will be created on first run)",
|
|
83
84
|
"doctor.credentialsFound": "found",
|
|
84
85
|
"doctor.credentialsMissing": "not found (run wechat-setup first)",
|
|
86
|
+
"doctor.credentialsMissingWecom": "not found (run wecom-setup first)",
|
|
85
87
|
"doctor.mode.bridge": "standalone bridge",
|
|
86
88
|
"doctor.mode.generic": "generic",
|
|
87
89
|
"doctor.notSpecified": "(not specified)",
|
package/dist/i18n/messages-zh.js
CHANGED
|
@@ -25,7 +25,7 @@ export const messages = {
|
|
|
25
25
|
// === Hook 健康检查 ===
|
|
26
26
|
"hook.healthCheck.warning": "[警告] 15 秒内未收到 Claude hook 事件。\nhook 系统可能未正常工作 — Claude 的输出将无法到达微信。",
|
|
27
27
|
"hook.healthCheck.logHint": "\n查看日志: {logPath}",
|
|
28
|
-
"hook.healthCheck.fixes": "\n常见修复方法:\n- 确保 Node.js >= 22.
|
|
28
|
+
"hook.healthCheck.fixes": "\n常见修复方法:\n- 确保 Node.js >= 22.13.0: node --version\n- 重新安装: npm install -g cli-wechat-bridge@latest\n- 检查防火墙: 允许 localhost TCP 连接",
|
|
29
29
|
// === PTY 回退 ===
|
|
30
30
|
"pty.fallback.warning": "[警告] PTY 不可用 — 已切换到回退模式(TERM=dumb)。\n核心功能(消息收发、审批、会话管理)正常工作;终端渲染(颜色、进度条)可能受限。\n修复方法: Linux 安装 build-essential python3 | Windows 运行 npm rebuild node-pty | macOS 运行 xcode-select --install\n运行 --doctor 查看详细环境信息。\n",
|
|
31
31
|
// === 启动诊断 ===
|
|
@@ -36,7 +36,7 @@ export const messages = {
|
|
|
36
36
|
"spawn.diagnostic.linuxBuildTools": "- Linux 需要编译工具来构建 node-pty: sudo apt install build-essential python3\n- 然后重新安装: npm install -g cli-wechat-bridge@latest",
|
|
37
37
|
"spawn.diagnostic.notFound": "- 命令 \"{target}\" 未在 PATH 中找到。\n- 请确认已安装并可从终端访问。",
|
|
38
38
|
"spawn.diagnostic.generic": "- 重新安装: npm install -g cli-wechat-bridge@latest",
|
|
39
|
-
"spawn.diagnostic.nodeVersion": "- 确保 Node.js >= 22.
|
|
39
|
+
"spawn.diagnostic.nodeVersion": "- 确保 Node.js >= 22.13.0: node --version",
|
|
40
40
|
"spawn.diagnostic.winFull": "- 确保 Windows 10 build 18309+(运行 winver 查看)\n- 安装 Visual C++ Redistributable: https://aka.ms/vs/17/release/vc_redist.x64.exe\n- 运行: npm rebuild node-pty\n- 尝试以管理员身份运行",
|
|
41
41
|
// === Emoji 绑定 ===
|
|
42
42
|
"binding.usage": "格式错误。\n用法: /bind [表情] 命令\n示例: /bind 🚀 deploy --prod",
|
|
@@ -59,6 +59,7 @@ export const messages = {
|
|
|
59
59
|
"doctor.label.codePage": "控制台代码页",
|
|
60
60
|
"doctor.codePage.nonAsciiWarning": "{codePage}(非 UTF-8,且数据目录路径含非 ASCII 字符;旧版本的 hook 脚本在此环境下会乱码失效,请升级到最新版本)",
|
|
61
61
|
"doctor.label.connectivity": "微信服务可达性",
|
|
62
|
+
"doctor.label.wecomConnectivity": "企业微信服务可达性",
|
|
62
63
|
"doctor.connectivity.ok": "可达 ({baseUrl})",
|
|
63
64
|
"doctor.connectivity.unreachable": "无法访问 {baseUrl}(检查网络与防火墙)",
|
|
64
65
|
"doctor.connectivity.proxyHint": "无法访问 {baseUrl}。检测到代理 {proxy},但 Node fetch 默认不使用代理环境变量;若必须经代理出网,请设置 NODE_USE_ENV_PROXY=1 后重试。",
|
|
@@ -82,6 +83,7 @@ export const messages = {
|
|
|
82
83
|
"doctor.dataDirMissing": "(首次运行会创建)",
|
|
83
84
|
"doctor.credentialsFound": "已找到",
|
|
84
85
|
"doctor.credentialsMissing": "未找到 (先运行 wechat-setup)",
|
|
86
|
+
"doctor.credentialsMissingWecom": "未找到 (先运行 wecom-setup)",
|
|
85
87
|
"doctor.mode.bridge": "独立桥接",
|
|
86
88
|
"doctor.mode.generic": "通用",
|
|
87
89
|
"doctor.notSpecified": "(未指定)",
|
package/dist/utils/doctor.js
CHANGED
|
@@ -74,11 +74,11 @@ function defaultGetWindowsCodePage() {
|
|
|
74
74
|
return null;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
async function defaultFetchServerDate() {
|
|
77
|
+
async function defaultFetchServerDate(baseUrl = DEFAULT_BASE_URL) {
|
|
78
78
|
const controller = new AbortController();
|
|
79
79
|
const timer = setTimeout(() => controller.abort(), SERVER_DATE_TIMEOUT_MS);
|
|
80
80
|
try {
|
|
81
|
-
const res = await fetch(
|
|
81
|
+
const res = await fetch(baseUrl, {
|
|
82
82
|
method: "GET",
|
|
83
83
|
signal: controller.signal,
|
|
84
84
|
});
|
|
@@ -179,6 +179,7 @@ function isBridgeAdapterKind(value) {
|
|
|
179
179
|
export function parseDoctorCliArgs(argv, mode = "generic", fallbackCwd = process.cwd()) {
|
|
180
180
|
let cwd = fallbackCwd;
|
|
181
181
|
let adapter;
|
|
182
|
+
let channelId = "wechat";
|
|
182
183
|
for (let i = 0; i < argv.length; i += 1) {
|
|
183
184
|
const arg = argv[i];
|
|
184
185
|
const next = argv[i + 1];
|
|
@@ -195,11 +196,17 @@ export function parseDoctorCliArgs(argv, mode = "generic", fallbackCwd = process
|
|
|
195
196
|
i += 1;
|
|
196
197
|
continue;
|
|
197
198
|
}
|
|
199
|
+
if (arg === "--channel" && (next === "wechat" || next === "wecom")) {
|
|
200
|
+
channelId = next;
|
|
201
|
+
i += 1;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
198
204
|
}
|
|
199
205
|
return {
|
|
200
206
|
mode,
|
|
201
207
|
cwd: path.resolve(cwd),
|
|
202
208
|
adapter,
|
|
209
|
+
...(channelId === "wecom" ? { channelId } : {}),
|
|
203
210
|
};
|
|
204
211
|
}
|
|
205
212
|
function statusTag(status) {
|
|
@@ -582,10 +589,15 @@ export async function buildDoctorReport(options = {}, rawDeps = {}) {
|
|
|
582
589
|
}
|
|
583
590
|
}
|
|
584
591
|
const proxyUrl = pickProxyEnvValue(deps.env);
|
|
585
|
-
const
|
|
592
|
+
const connectivityUrl = doctorOptions.channelId === "wecom"
|
|
593
|
+
? "https://open.work.weixin.qq.com"
|
|
594
|
+
: DEFAULT_BASE_URL;
|
|
595
|
+
const serverDate = await deps.fetchServerDate(connectivityUrl);
|
|
586
596
|
if (serverDate) {
|
|
587
|
-
lines.push(row(STATE_OK, msg(
|
|
588
|
-
|
|
597
|
+
lines.push(row(STATE_OK, msg(doctorOptions.channelId === "wecom"
|
|
598
|
+
? "label.wecomConnectivity"
|
|
599
|
+
: "label.connectivity"), msg("connectivity.ok", {
|
|
600
|
+
baseUrl: connectivityUrl,
|
|
589
601
|
})));
|
|
590
602
|
const skewMs = deps.now() - serverDate.getTime();
|
|
591
603
|
const skewSeconds = Math.round(Math.abs(skewMs) / 1000);
|
|
@@ -595,9 +607,11 @@ export async function buildDoctorReport(options = {}, rawDeps = {}) {
|
|
|
595
607
|
: msg("clock.skewWarning", { skewSeconds })));
|
|
596
608
|
}
|
|
597
609
|
else {
|
|
598
|
-
lines.push(row(STATE_WARN, msg(
|
|
599
|
-
?
|
|
600
|
-
:
|
|
610
|
+
lines.push(row(STATE_WARN, msg(doctorOptions.channelId === "wecom"
|
|
611
|
+
? "label.wecomConnectivity"
|
|
612
|
+
: "label.connectivity"), proxyUrl && deps.env.NODE_USE_ENV_PROXY !== "1"
|
|
613
|
+
? msg("connectivity.proxyHint", { baseUrl: connectivityUrl, proxy: proxyUrl })
|
|
614
|
+
: msg("connectivity.unreachable", { baseUrl: connectivityUrl })));
|
|
601
615
|
}
|
|
602
616
|
try {
|
|
603
617
|
await deps.loadNodePty();
|
|
@@ -612,9 +626,15 @@ export async function buildDoctorReport(options = {}, rawDeps = {}) {
|
|
|
612
626
|
const dataDir = deps.resolveDataDir();
|
|
613
627
|
const dataDirExists = deps.exists(dataDir);
|
|
614
628
|
lines.push(row(dataDirExists ? STATE_OK : STATE_FAIL, msg("label.dataDir"), dataDirExists ? dataDir : `${dataDir} ${msg("dataDirMissing")}`));
|
|
615
|
-
const credFile =
|
|
629
|
+
const credFile = doctorOptions.channelId === "wecom"
|
|
630
|
+
? path.join(dataDir, "wecom", "account.json")
|
|
631
|
+
: path.join(dataDir, "account.json");
|
|
616
632
|
const credExists = deps.exists(credFile);
|
|
617
|
-
lines.push(row(credExists ? STATE_OK : STATE_FAIL, msg("label.credentials"), credExists
|
|
633
|
+
lines.push(row(credExists ? STATE_OK : STATE_FAIL, msg("label.credentials"), credExists
|
|
634
|
+
? msg("credentialsFound")
|
|
635
|
+
: msg(doctorOptions.channelId === "wecom"
|
|
636
|
+
? "credentialsMissingWecom"
|
|
637
|
+
: "credentialsMissing")));
|
|
618
638
|
section(lines, msg("section.runtime"));
|
|
619
639
|
lines.push(fieldRow(msg("label.mode"), formatMode(doctorOptions.mode)));
|
|
620
640
|
lines.push(fieldRow(msg("label.cwd"), doctorOptions.cwd));
|
package/dist/wechat/setup.js
CHANGED
|
@@ -11,6 +11,7 @@ import fs from "node:fs";
|
|
|
11
11
|
import readline from "node:readline";
|
|
12
12
|
import { BOT_TYPE, CONTEXT_CACHE_FILE, CREDENTIALS_FILE, DEFAULT_BASE_URL, ensureChannelDataDir, migrateLegacyChannelFiles, SYNC_BUF_FILE, } from "./channel-config.js";
|
|
13
13
|
import { isWechatSyncSessionTimeout } from "./wechat-transport.js";
|
|
14
|
+
import { isDirectModuleRun } from "../core/direct-run.js";
|
|
14
15
|
const CHANNEL_VERSION = "0.3.0";
|
|
15
16
|
export function loadExistingCredentials() {
|
|
16
17
|
try {
|
|
@@ -130,18 +131,74 @@ async function askYesNo(prompt) {
|
|
|
130
131
|
rl.close();
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
+
// eslint-disable-next-line no-control-regex
|
|
135
|
+
const ANSI_SGR_RE = /\u001b\[[0-9;]*m/g;
|
|
136
|
+
function resolveLoginTerminal() {
|
|
137
|
+
const columns = process.stdout.columns;
|
|
138
|
+
return {
|
|
139
|
+
platform: process.platform,
|
|
140
|
+
isTTY: process.stdout.isTTY === true,
|
|
141
|
+
columns: typeof columns === "number" && Number.isFinite(columns) && columns > 0
|
|
142
|
+
? columns
|
|
143
|
+
: undefined,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export function getQRCodeVisibleWidth(qr) {
|
|
147
|
+
return Math.max(0, ...qr
|
|
148
|
+
.replace(/\r/g, "")
|
|
149
|
+
.split("\n")
|
|
150
|
+
.map((line) => Array.from(line.replace(ANSI_SGR_RE, "")).length));
|
|
151
|
+
}
|
|
152
|
+
export function selectQRCodePresentation(params) {
|
|
153
|
+
if (!params.isTTY ||
|
|
154
|
+
typeof params.columns !== "number" ||
|
|
155
|
+
!Number.isFinite(params.columns) ||
|
|
156
|
+
params.columns <= 0 ||
|
|
157
|
+
params.renderedWidth + 1 > params.columns) {
|
|
158
|
+
return "url_only";
|
|
159
|
+
}
|
|
160
|
+
return "qr_with_url";
|
|
161
|
+
}
|
|
162
|
+
export function formatQRCodeLoginInstruction(presentation) {
|
|
163
|
+
return presentation === "qr_with_url"
|
|
164
|
+
? "Scan the QR code above with WeChat, then confirm the login on your phone. If scanning fails, open the browser URL above.\n"
|
|
165
|
+
: "The QR code was not rendered in this terminal. Open the browser URL above, then confirm the login in WeChat.\n";
|
|
166
|
+
}
|
|
167
|
+
async function generateQRCode(qrContent, options) {
|
|
168
|
+
const qrterm = await import("qrcode-terminal");
|
|
169
|
+
return await new Promise((resolve, reject) => {
|
|
170
|
+
try {
|
|
171
|
+
qrterm.default.generate(qrContent, options, resolve);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
reject(error);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
export async function printQRCode(qrContent, write, terminal = resolveLoginTerminal(), qrMode = "small", qrGenerator = generateQRCode) {
|
|
179
|
+
if (!terminal.isTTY) {
|
|
180
|
+
return "url_only";
|
|
181
|
+
}
|
|
134
182
|
try {
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
qrterm.default.generate(qrContent, { small: true }, (qr) => {
|
|
138
|
-
write(`${qr}\n`);
|
|
139
|
-
resolve();
|
|
140
|
-
});
|
|
183
|
+
const qr = await qrGenerator(qrContent, {
|
|
184
|
+
small: qrMode === "small",
|
|
141
185
|
});
|
|
186
|
+
const presentation = selectQRCodePresentation({
|
|
187
|
+
isTTY: terminal.isTTY,
|
|
188
|
+
columns: terminal.columns,
|
|
189
|
+
renderedWidth: getQRCodeVisibleWidth(qr),
|
|
190
|
+
});
|
|
191
|
+
if (presentation === "qr_with_url") {
|
|
192
|
+
write(`${qr}\n`);
|
|
193
|
+
}
|
|
194
|
+
write(presentation === "qr_with_url"
|
|
195
|
+
? `If scanning fails, open this short-lived WeChat login URL in a browser. Do not share it:\n${qrContent}\n\n`
|
|
196
|
+
: `Open this short-lived WeChat login URL in a browser. Do not share it:\n${qrContent}\n\n`);
|
|
197
|
+
return presentation;
|
|
142
198
|
}
|
|
143
199
|
catch {
|
|
144
|
-
write(`Open this
|
|
200
|
+
write(`The QR code could not be rendered. Open this short-lived WeChat login URL in a browser. Do not share it:\n${qrContent}\n\n`);
|
|
201
|
+
return "url_only";
|
|
145
202
|
}
|
|
146
203
|
}
|
|
147
204
|
function saveCredentials(account) {
|
|
@@ -174,16 +231,54 @@ function printPostLoginHelp(log) {
|
|
|
174
231
|
log("");
|
|
175
232
|
log("Run wechat-setup again any time you need to refresh the login.");
|
|
176
233
|
}
|
|
234
|
+
export function parseWechatSetupCliArgs(argv) {
|
|
235
|
+
let qrMode = "small";
|
|
236
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
237
|
+
const arg = argv[index];
|
|
238
|
+
if (arg === "--help" || arg === "-h") {
|
|
239
|
+
return { help: true, qrMode };
|
|
240
|
+
}
|
|
241
|
+
if (arg === "--qr-mode") {
|
|
242
|
+
const value = argv[index + 1];
|
|
243
|
+
if (value !== "small" && value !== "normal") {
|
|
244
|
+
throw new Error("--qr-mode requires small or normal.");
|
|
245
|
+
}
|
|
246
|
+
qrMode = value;
|
|
247
|
+
index += 1;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (arg === "--qr-mode=small" || arg === "--qr-mode=normal") {
|
|
251
|
+
qrMode = arg.endsWith("=small") ? "small" : "normal";
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
throw new Error(`Unknown wechat-setup option: ${arg}`);
|
|
255
|
+
}
|
|
256
|
+
return { help: false, qrMode };
|
|
257
|
+
}
|
|
258
|
+
export function formatWechatSetupUsage() {
|
|
259
|
+
return [
|
|
260
|
+
"Usage: wechat-setup [--qr-mode <small|normal>]",
|
|
261
|
+
"",
|
|
262
|
+
"Log in to WeChat and save bridge credentials.",
|
|
263
|
+
"QR mode defaults to small; use --qr-mode normal when the terminal renders small QR blocks incorrectly.",
|
|
264
|
+
"",
|
|
265
|
+
].join("\n");
|
|
266
|
+
}
|
|
177
267
|
export async function runWechatLogin(options = {}) {
|
|
178
268
|
const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
179
269
|
const log = options.log ?? ((message) => console.log(message));
|
|
180
270
|
const write = options.write ?? ((message) => process.stdout.write(message));
|
|
181
271
|
const timeoutMs = options.timeoutMs ?? 480_000;
|
|
182
272
|
const pollIntervalMs = options.pollIntervalMs ?? 1_000;
|
|
273
|
+
const terminal = options.terminal ?? resolveLoginTerminal();
|
|
274
|
+
const qrMode = options.qrMode ?? "small";
|
|
275
|
+
if (!terminal.isTTY) {
|
|
276
|
+
throw new Error("WeChat login requires an interactive terminal. Run wechat-setup directly in PowerShell, Command Prompt, or a terminal window.");
|
|
277
|
+
}
|
|
183
278
|
log("Fetching WeChat login QR code...\n");
|
|
184
279
|
const qrResp = await fetchQRCode(baseUrl);
|
|
185
|
-
await printQRCode(qrResp.qrcode_img_content, write);
|
|
186
|
-
log(
|
|
280
|
+
const presentation = await printQRCode(qrResp.qrcode_img_content, write, terminal, qrMode);
|
|
281
|
+
log(formatQRCodeLoginInstruction(presentation));
|
|
187
282
|
const deadline = Date.now() + timeoutMs;
|
|
188
283
|
let scannedPrinted = false;
|
|
189
284
|
while (Date.now() < deadline) {
|
|
@@ -252,7 +347,12 @@ export async function ensureWechatCredentials(options = {}) {
|
|
|
252
347
|
const login = options.login ?? (() => runWechatLogin(options));
|
|
253
348
|
return login();
|
|
254
349
|
}
|
|
255
|
-
async function main() {
|
|
350
|
+
async function main(argv = process.argv.slice(2)) {
|
|
351
|
+
const cliOptions = parseWechatSetupCliArgs(argv);
|
|
352
|
+
if (cliOptions.help) {
|
|
353
|
+
console.log(formatWechatSetupUsage());
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
256
356
|
migrateLegacyChannelFiles((message) => console.log(message));
|
|
257
357
|
const existing = loadExistingCredentials();
|
|
258
358
|
if (existing) {
|
|
@@ -266,10 +366,10 @@ async function main() {
|
|
|
266
366
|
return;
|
|
267
367
|
}
|
|
268
368
|
}
|
|
269
|
-
await runWechatLogin({ requireUserId: true });
|
|
369
|
+
await runWechatLogin({ requireUserId: true, qrMode: cliOptions.qrMode });
|
|
270
370
|
printPostLoginHelp((message) => console.log(message));
|
|
271
371
|
}
|
|
272
|
-
const isDirectRun =
|
|
372
|
+
const isDirectRun = isDirectModuleRun(import.meta.url, process.argv, import.meta.main);
|
|
273
373
|
if (isDirectRun) {
|
|
274
374
|
main().catch((err) => {
|
|
275
375
|
const message = err instanceof Error ? err.message : String(err);
|
package/package.json
CHANGED
|
@@ -1,109 +1,119 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cli-wechat-bridge",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "CLI
|
|
5
|
-
"type": "module",
|
|
6
|
-
"files": [
|
|
7
|
-
"bin/",
|
|
8
|
-
"dist/",
|
|
9
|
-
"scripts/ensure-node-pty-permissions.mjs",
|
|
10
|
-
"README.md",
|
|
11
|
-
"LICENSE.txt"
|
|
12
|
-
],
|
|
13
|
-
"keywords": [
|
|
1
|
+
{
|
|
2
|
+
"name": "cli-wechat-bridge",
|
|
3
|
+
"version": "1.1.7",
|
|
4
|
+
"description": "CLI bridge for Codex, Claude Code, OpenCode, and Pi over WeChat and WeCom",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"bin/",
|
|
8
|
+
"dist/",
|
|
9
|
+
"scripts/ensure-node-pty-permissions.mjs",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE.txt"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
14
|
"wechat",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"wechat-
|
|
39
|
-
"wechat-
|
|
40
|
-
"wechat-
|
|
41
|
-
"wechat-
|
|
42
|
-
"wechat-
|
|
43
|
-
"wechat-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"bridge
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
15
|
+
"wecom",
|
|
16
|
+
"cli",
|
|
17
|
+
"bridge",
|
|
18
|
+
"codex",
|
|
19
|
+
"claude",
|
|
20
|
+
"opencode",
|
|
21
|
+
"pi",
|
|
22
|
+
"terminal"
|
|
23
|
+
],
|
|
24
|
+
"author": "UNLINEARITY",
|
|
25
|
+
"license": "AGPL-3.0-or-later",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/UNLINEARITY/CLI-WeChat-Bridge.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/UNLINEARITY/CLI-WeChat-Bridge/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/UNLINEARITY/CLI-WeChat-Bridge#readme",
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"bin": {
|
|
38
|
+
"wechat-codex": "bin/wechat-codex.mjs",
|
|
39
|
+
"wechat-claude": "bin/wechat-claude.mjs",
|
|
40
|
+
"wechat-opencode": "bin/wechat-opencode.mjs",
|
|
41
|
+
"wechat-pi": "bin/wechat-pi.mjs",
|
|
42
|
+
"wechat-daemon": "bin/wechat-daemon.mjs",
|
|
43
|
+
"wechat-setup": "bin/wechat-setup.mjs",
|
|
44
|
+
"wechat-check-update": "bin/wechat-check-update.mjs",
|
|
45
|
+
"wecom-codex": "bin/wecom-codex.mjs",
|
|
46
|
+
"wecom-claude": "bin/wecom-claude.mjs",
|
|
47
|
+
"wecom-opencode": "bin/wecom-opencode.mjs",
|
|
48
|
+
"wecom-pi": "bin/wecom-pi.mjs",
|
|
49
|
+
"wecom-daemon": "bin/wecom-daemon.mjs",
|
|
50
|
+
"wecom-setup": "bin/wecom-setup.mjs",
|
|
51
|
+
"wecom-check-update": "bin/wecom-check-update.mjs"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"postinstall": "node scripts/ensure-node-pty-permissions.mjs",
|
|
55
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
56
|
+
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
57
|
+
"prepack": "npm run build",
|
|
58
|
+
"lint": "eslint bin src test",
|
|
59
|
+
"lint:fix": "eslint bin src test --fix",
|
|
60
|
+
"typecheck:src": "tsc -p tsconfig.typecheck.src.json --noEmit --pretty false",
|
|
61
|
+
"quality": "npm run lint && npm run typecheck:src && bun test test && npm run build",
|
|
62
|
+
"smoke:global": "node scripts/smoke-global-install.mjs",
|
|
63
|
+
"publish:dual": "node scripts/publish-dual.mjs",
|
|
64
|
+
"setup": "node --no-warnings --experimental-strip-types src/wechat/setup.ts",
|
|
65
|
+
"start": "node --no-warnings --experimental-strip-types src/wechat/wechat-channel.ts",
|
|
66
|
+
"check": "node --no-warnings --experimental-strip-types src/wechat/wechat-channel.ts --check",
|
|
67
|
+
"bridge": "node --no-warnings --experimental-strip-types src/bridge/wechat-bridge.ts",
|
|
68
|
+
"daemon": "node --no-warnings --experimental-strip-types src/daemon/wechat-daemon.ts",
|
|
69
|
+
"bridge:codex": "node --no-warnings --experimental-strip-types src/bridge/wechat-bridge.ts --adapter codex",
|
|
70
|
+
"codex:panel": "node --no-warnings --experimental-strip-types src/companion/codex-remote-client.ts",
|
|
71
|
+
"codex:start": "node --no-warnings --experimental-strip-types src/companion/local-companion-start.ts",
|
|
72
|
+
"claude:start": "node --no-warnings --experimental-strip-types src/companion/local-companion-start.ts --adapter claude",
|
|
73
|
+
"claude:companion": "node --no-warnings --experimental-strip-types src/companion/local-companion.ts --adapter claude",
|
|
74
|
+
"bridge:claude": "node --no-warnings --experimental-strip-types src/bridge/wechat-bridge.ts --adapter claude",
|
|
75
|
+
"bridge:opencode": "node --no-warnings --experimental-strip-types src/bridge/wechat-bridge.ts --adapter opencode",
|
|
76
|
+
"opencode:panel": "node --no-warnings --experimental-strip-types src/companion/local-companion.ts --adapter opencode",
|
|
77
|
+
"opencode:start": "node --no-warnings --experimental-strip-types src/companion/local-companion-start.ts --adapter opencode",
|
|
78
|
+
"bridge:pi": "node --no-warnings --experimental-strip-types src/bridge/wechat-bridge.ts --adapter pi",
|
|
79
|
+
"pi:companion": "node --no-warnings --experimental-strip-types src/companion/local-companion.ts --adapter pi",
|
|
80
|
+
"pi:start": "node --no-warnings --experimental-strip-types src/companion/local-companion-start.ts --adapter pi",
|
|
81
|
+
"bridge:bun": "bun src/bridge/wechat-bridge.ts",
|
|
82
|
+
"test": "bun test test",
|
|
83
|
+
"test:bridge": "bun test test/bridge",
|
|
84
|
+
"test:companion": "bun test test/companion",
|
|
77
85
|
"test:wechat": "bun test test/wechat",
|
|
78
|
-
"test:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"@
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"@
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
86
|
+
"test:wecom": "bun test test/wecom",
|
|
87
|
+
"test:watch": "bun test --watch test"
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
91
|
+
"@opencode-ai/sdk": "^1.18.0",
|
|
92
|
+
"@wecom/aibot-node-sdk": "1.0.7",
|
|
93
|
+
"node-pty": "^1.1.0",
|
|
94
|
+
"qrcode-terminal": "^0.12.0"
|
|
95
|
+
},
|
|
96
|
+
"overrides": {
|
|
97
|
+
"@hono/node-server": "2.1.1",
|
|
98
|
+
"body-parser": "2.3.0",
|
|
99
|
+
"brace-expansion": "5.0.9",
|
|
100
|
+
"express-rate-limit": "8.6.2",
|
|
101
|
+
"fast-uri": "3.1.5",
|
|
102
|
+
"hono": "4.13.3",
|
|
103
|
+
"ip-address": "10.5.0",
|
|
104
|
+
"path-to-regexp": "8.4.2",
|
|
105
|
+
"qs": "6.15.3"
|
|
106
|
+
},
|
|
107
|
+
"devDependencies": {
|
|
108
|
+
"@eslint/js": "^10.0.1",
|
|
109
|
+
"@types/bun": "latest",
|
|
110
|
+
"@types/node": "^24.12.4",
|
|
111
|
+
"eslint": "^10.3.0",
|
|
112
|
+
"typescript": "^6.0.2",
|
|
113
|
+
"typescript-eslint": "^8.59.3"
|
|
114
|
+
},
|
|
115
|
+
"engines": {
|
|
116
|
+
"bun": ">=1.0.0",
|
|
117
|
+
"node": ">=22.13.0"
|
|
118
|
+
}
|
|
119
|
+
}
|