claude-codex-wechat 0.1.51 → 0.1.53

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 CHANGED
@@ -24,6 +24,19 @@ pnpm add -g claude-codex-wechat
24
24
 
25
25
  > 该包依赖 `better-sqlite3`。大多数电脑会直接下载预编译好的二进制;极少数环境可能需要本地编译工具链。
26
26
 
27
+ ## 更新
28
+
29
+ ```bash
30
+ claude-codex-wechat upgrade
31
+ ```
32
+
33
+ 会自动拉取最新版并重启服务(重启期间微信桥接会短暂中断)。若提示未知命令,说明当前版本还没有该命令,改用:
34
+
35
+ ```bash
36
+ npm install -g claude-codex-wechat@latest --registry=https://registry.npmmirror.com/
37
+ claude-codex-wechat restart
38
+ ```
39
+
27
40
  ## 开始使用
28
41
 
29
42
  安装完,三步就能跑通:
@@ -57,6 +70,7 @@ claude-codex-wechat doctor
57
70
  | `claude-codex-wechat restart` | 重启 |
58
71
  | `claude-codex-wechat stop` | 停止 |
59
72
  | `claude-codex-wechat doctor` | 体检:检查配置、前端产物、`claude`/`codex` 是否就绪 |
73
+ | `claude-codex-wechat upgrade` | 更新到最新版并自动重启(`--force` 强制重装) |
60
74
  | `claude-codex-wechat print-config` | 打印当前配置 |
61
75
  | `claude-codex-wechat uninstall` | 卸载后台服务 |
62
76
  | `claude-codex-wechat help` | 显示帮助 |
@@ -2,7 +2,9 @@
2
2
  import { createRequire as __cjsCreateRequire } from 'node:module'; const require = __cjsCreateRequire(import.meta.url);
3
3
 
4
4
  // src/cli.ts
5
+ import { execFile as execFile2 } from "node:child_process";
5
6
  import { existsSync as existsSync11, readFileSync as readFileSync10 } from "node:fs";
7
+ import { promisify as promisify2 } from "node:util";
6
8
  import { dirname as dirname9, join as join14 } from "node:path";
7
9
  import { fileURLToPath as fileURLToPath3 } from "node:url";
8
10
 
@@ -6248,7 +6250,50 @@ function fileSizeHint(path) {
6248
6250
  }
6249
6251
  }
6250
6252
 
6253
+ // src/daemon/upgrade.ts
6254
+ var UPGRADE_REGISTRY_URL = "https://registry.npmmirror.com/";
6255
+ var LATEST_MANIFEST_PATH = "claude-codex-wechat/latest";
6256
+ var FETCH_TIMEOUT_MS2 = 5e3;
6257
+ async function resolveLatestVersion(input) {
6258
+ const url = new URL(LATEST_MANIFEST_PATH, input.registryUrl).toString();
6259
+ const response = await input.fetchImpl(url, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS2) });
6260
+ if (!response.ok) throw new Error(`registry_responded_${response.status}`);
6261
+ const data = await response.json();
6262
+ const version = typeof data?.version === "string" ? data.version.trim() : "";
6263
+ if (!version) throw new Error("registry_missing_version");
6264
+ return version;
6265
+ }
6266
+ async function performUpgrade(deps) {
6267
+ const { currentVersion, force = false } = deps;
6268
+ const registryUrl = deps.registryUrl ?? UPGRADE_REGISTRY_URL;
6269
+ const fetchImpl = deps.fetchImpl ?? fetch;
6270
+ deps.log(`\xB7 \u5F53\u524D\u7248\u672C ${currentVersion}`);
6271
+ let latest;
6272
+ try {
6273
+ latest = await resolveLatestVersion({ fetchImpl, registryUrl });
6274
+ } catch (err) {
6275
+ return {
6276
+ outcome: "check-failed",
6277
+ from: currentVersion,
6278
+ message: err instanceof Error ? err.message : String(err)
6279
+ };
6280
+ }
6281
+ deps.log(`\xB7 \u6700\u65B0\u7248\u672C ${latest}`);
6282
+ if (!force && !isNewerVersion(latest, currentVersion)) {
6283
+ return { outcome: "already-latest", from: currentVersion, to: latest };
6284
+ }
6285
+ deps.log("\xB7 \u6B63\u5728\u66F4\u65B0 \u2026");
6286
+ const installed = await deps.install();
6287
+ if (!installed.ok) {
6288
+ return { outcome: "install-failed", from: currentVersion, to: latest, message: installed.message };
6289
+ }
6290
+ deps.log("\xB7 \u91CD\u542F\u670D\u52A1 \u2026\uFF08\u5FAE\u4FE1\u6865\u63A5\u4F1A\u77ED\u6682\u4E2D\u65AD\uFF09");
6291
+ await deps.restart();
6292
+ return { outcome: "upgraded", from: currentVersion, to: latest };
6293
+ }
6294
+
6251
6295
  // src/cli.ts
6296
+ var execFileAsync2 = promisify2(execFile2);
6252
6297
  var here = dirname9(fileURLToPath3(import.meta.url));
6253
6298
  var webRoot = join14(here, "..", "web");
6254
6299
  async function main() {
@@ -6276,6 +6321,9 @@ async function main() {
6276
6321
  case "doctor":
6277
6322
  await cmdDoctor();
6278
6323
  return;
6324
+ case "upgrade":
6325
+ await cmdUpgrade();
6326
+ return;
6279
6327
  case "uninstall":
6280
6328
  await cmdUninstall();
6281
6329
  return;
@@ -6318,6 +6366,60 @@ async function cmdRestart() {
6318
6366
  const status = await restartService(createServiceContext());
6319
6367
  printServiceStatus("service restarted", status);
6320
6368
  }
6369
+ async function cmdUpgrade() {
6370
+ const args = process.argv.slice(3);
6371
+ const force = args.includes("--force");
6372
+ const registryArg = args.find((arg) => arg.startsWith("--registry="));
6373
+ const registryUrl = registryArg ? registryArg.slice("--registry=".length) : void 0;
6374
+ const currentVersion = readClientVersion();
6375
+ const result = await performUpgrade({
6376
+ currentVersion,
6377
+ force,
6378
+ registryUrl,
6379
+ log: (message) => console.log(message),
6380
+ install: () => runGlobalInstall(registryUrl ?? UPGRADE_REGISTRY_URL),
6381
+ restart: async () => {
6382
+ await restartService(createServiceContext());
6383
+ }
6384
+ });
6385
+ switch (result.outcome) {
6386
+ case "upgraded":
6387
+ console.log(`\u2713 \u5DF2\u5347\u7EA7\u5230 ${result.to}`);
6388
+ return;
6389
+ case "already-latest":
6390
+ console.log(`\u2713 \u5DF2\u662F\u6700\u65B0\u7248 ${result.to}\uFF08\u91CD\u88C5\u8BF7\u52A0 --force\uFF09`);
6391
+ return;
6392
+ case "check-failed":
6393
+ console.error(`\u67E5\u8BE2\u6700\u65B0\u7248\u672C\u5931\u8D25\uFF1A${result.message}`);
6394
+ console.error("\u670D\u52A1\u672A\u6539\u52A8\u3002\u53EF\u7A0D\u540E\u91CD\u8BD5\uFF0C\u6216\u624B\u52A8\u6267\u884C\uFF1A");
6395
+ printManualUpgradeCommands();
6396
+ process.exitCode = 1;
6397
+ return;
6398
+ case "install-failed":
6399
+ console.error(`\u66F4\u65B0\u5931\u8D25\uFF1A${result.message}`);
6400
+ console.error("\u670D\u52A1\u672A\u91CD\u542F\uFF0C\u4ECD\u5728\u8FD0\u884C\u65E7\u7248\u672C\u3002\u53EF\u624B\u52A8\u6267\u884C\uFF1A");
6401
+ printManualUpgradeCommands();
6402
+ process.exitCode = 1;
6403
+ }
6404
+ }
6405
+ async function runGlobalInstall(registryUrl) {
6406
+ try {
6407
+ const { stderr } = await execFileAsync2(
6408
+ "npm",
6409
+ ["install", "-g", "claude-codex-wechat@latest", `--registry=${registryUrl}`],
6410
+ { shell: useShellForCli() }
6411
+ );
6412
+ if (stderr.trim()) console.log(stderr.trim());
6413
+ return { ok: true };
6414
+ } catch (err) {
6415
+ const detail = err instanceof Error && "stderr" in err && typeof err.stderr === "string" && err.stderr.trim() ? err.stderr.trim() : err instanceof Error ? err.message : String(err);
6416
+ return { ok: false, message: detail };
6417
+ }
6418
+ }
6419
+ function printManualUpgradeCommands() {
6420
+ console.error(` npm install -g claude-codex-wechat@latest --registry=${UPGRADE_REGISTRY_URL}`);
6421
+ console.error(" claude-codex-wechat restart");
6422
+ }
6321
6423
  async function cmdStatus() {
6322
6424
  const status = await readServiceStatus(createServiceContext());
6323
6425
  printServiceStatus("service status", status);
@@ -6372,7 +6474,9 @@ function printUpdateHint() {
6372
6474
  const current = update.currentVersion ?? readClientVersion();
6373
6475
  console.log(`
6374
6476
  \u53D1\u73B0\u65B0\u7248 v${update.latestVersion}\uFF08\u5F53\u524D v${current}\uFF09\u3002\u66F4\u65B0\uFF1A`);
6375
- console.log(" npm install -g claude-codex-wechat@latest --registry=https://registry.npmmirror.com/");
6477
+ console.log(" claude-codex-wechat upgrade");
6478
+ console.log("\n\u82E5\u63D0\u793A\u672A\u77E5\u547D\u4EE4\uFF0C\u6539\u7528\uFF1A");
6479
+ console.log(` npm install -g claude-codex-wechat@latest --registry=${UPGRADE_REGISTRY_URL}`);
6376
6480
  console.log(" claude-codex-wechat restart");
6377
6481
  }
6378
6482
  function cmdPrintConfig() {
@@ -6424,6 +6528,7 @@ function printUsage() {
6424
6528
  logs \u6253\u5370\u6700\u8FD1\u65E5\u5FD7
6425
6529
  tail \u5B9E\u65F6\u8DDF\u968F\u65E5\u5FD7
6426
6530
  doctor \u68C0\u67E5\u914D\u7F6E\u3001\u524D\u7AEF\u4EA7\u7269\u4E0E claude/codex \u53EF\u6267\u884C\u6587\u4EF6
6531
+ upgrade \u66F4\u65B0\u5230\u6700\u65B0\u7248\u5E76\u91CD\u542F\uFF08--force \u5F3A\u5236\u91CD\u88C5\uFF0C--registry= \u6307\u5B9A\u6E90\uFF09
6427
6532
  uninstall \u5378\u8F7D\u540E\u53F0\u670D\u52A1
6428
6533
  print-config \u6253\u5370\u5F53\u524D\u914D\u7F6E\u6587\u4EF6\u5185\u5BB9
6429
6534
  help \u663E\u793A\u672C\u5E2E\u52A9