@kyan-du/agent-wechat-cli 0.12.0 → 0.13.0

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/dist/cli.js CHANGED
@@ -3480,7 +3480,7 @@ var {
3480
3480
  } = import_index.default;
3481
3481
 
3482
3482
  // src/cli.ts
3483
- import { execFileSync as execFileSync2, spawn } from "node:child_process";
3483
+ import { execFileSync as execFileSync3, spawn } from "node:child_process";
3484
3484
  import { createHash, randomBytes as randomBytes2 } from "node:crypto";
3485
3485
  import fs4 from "node:fs";
3486
3486
  import os2 from "node:os";
@@ -8684,8 +8684,84 @@ async function replaceImage(options) {
8684
8684
  }
8685
8685
  }
8686
8686
 
8687
+ // src/cli-upgrade.ts
8688
+ import { execFileSync as execFileSync2 } from "node:child_process";
8689
+ var CliUpgradeError = class extends Error {
8690
+ code;
8691
+ constructor(code, message) {
8692
+ super(message);
8693
+ this.code = code;
8694
+ }
8695
+ };
8696
+ var CLI_PACKAGE = "@kyan-du/agent-wechat-cli";
8697
+ var SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
8698
+ function parseVersion(value, source) {
8699
+ const match = SEMVER.exec(value);
8700
+ if (!match) throw new CliUpgradeError("CLI_UPGRADE_INVALID_VERSION", `${source} returned an invalid semantic version`);
8701
+ const prerelease = match[4]?.split(".") ?? [];
8702
+ if (prerelease.some((part) => /^\d+$/.test(part) && (part.length > 1 && part.startsWith("0")))) {
8703
+ throw new CliUpgradeError("CLI_UPGRADE_INVALID_VERSION", `${source} returned an invalid semantic version`);
8704
+ }
8705
+ return { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), prerelease };
8706
+ }
8707
+ function compareIdentifiers(left, right) {
8708
+ const leftNumeric = /^\d+$/.test(left);
8709
+ const rightNumeric = /^\d+$/.test(right);
8710
+ if (leftNumeric && rightNumeric) return Number(left) - Number(right);
8711
+ if (leftNumeric !== rightNumeric) return leftNumeric ? -1 : 1;
8712
+ return left.localeCompare(right);
8713
+ }
8714
+ function compareVersions(leftValue, rightValue) {
8715
+ const left = parseVersion(leftValue, "installed CLI version");
8716
+ const right = parseVersion(rightValue, "npm latest");
8717
+ for (const key of ["major", "minor", "patch"]) {
8718
+ if (left[key] !== right[key]) return left[key] - right[key];
8719
+ }
8720
+ if (left.prerelease.length === 0 || right.prerelease.length === 0) {
8721
+ return left.prerelease.length === right.prerelease.length ? 0 : left.prerelease.length === 0 ? 1 : -1;
8722
+ }
8723
+ for (let index = 0; index < Math.max(left.prerelease.length, right.prerelease.length); index += 1) {
8724
+ if (left.prerelease[index] === void 0) return -1;
8725
+ if (right.prerelease[index] === void 0) return 1;
8726
+ const compared = compareIdentifiers(left.prerelease[index], right.prerelease[index]);
8727
+ if (compared !== 0) return compared;
8728
+ }
8729
+ return 0;
8730
+ }
8731
+ function checkCliUpgrade(currentVersion, readLatest = () => execFileSync2("npm", ["view", CLI_PACKAGE, "dist-tags.latest", "--json"], {
8732
+ encoding: "utf8",
8733
+ stdio: ["ignore", "pipe", "pipe"],
8734
+ timeout: 15e3
8735
+ })) {
8736
+ parseVersion(currentVersion, "installed CLI version");
8737
+ let rawLatest;
8738
+ try {
8739
+ rawLatest = readLatest();
8740
+ } catch {
8741
+ throw new CliUpgradeError("CLI_UPGRADE_REGISTRY_ERROR", "could not read npm latest for the CLI package");
8742
+ }
8743
+ let latest;
8744
+ try {
8745
+ latest = JSON.parse(rawLatest);
8746
+ } catch {
8747
+ throw new CliUpgradeError("CLI_UPGRADE_INVALID_VERSION", "npm latest returned an invalid semantic version");
8748
+ }
8749
+ if (typeof latest !== "string") throw new CliUpgradeError("CLI_UPGRADE_INVALID_VERSION", "npm latest returned an invalid semantic version");
8750
+ const parsedLatest = parseVersion(latest, "npm latest");
8751
+ if (parsedLatest.prerelease.length > 0) {
8752
+ throw new CliUpgradeError("CLI_UPGRADE_PRERELEASE_REJECTED", "npm latest unexpectedly points to a prerelease");
8753
+ }
8754
+ const comparison = compareVersions(currentVersion, latest);
8755
+ return {
8756
+ currentVersion,
8757
+ latestVersion: latest,
8758
+ updateAvailable: comparison < 0,
8759
+ ...comparison < 0 ? { command: `npm install --global ${CLI_PACKAGE}@${latest}` } : {}
8760
+ };
8761
+ }
8762
+
8687
8763
  // src/cli.ts
8688
- var VERSION = false ? "0.0.0-test" : "0.12.0";
8764
+ var VERSION = false ? "0.0.0-test" : "0.13.0";
8689
8765
  var MAX_UPLOAD_BYTES = 50 * 1024 * 1024;
8690
8766
  function readToken() {
8691
8767
  try {
@@ -8868,12 +8944,12 @@ async function syncServer(binary, sha256) {
8868
8944
  const inventory = loadInventory();
8869
8945
  if (!info || !inventory || info.Id !== inventory.containerId) throw new CliError("INSTANCE_NOT_RUNNING", "trusted instance is not running", EXIT.SERVICE);
8870
8946
  const remote = `/tmp/agent-server-${process.pid}`;
8871
- execFileSync2("docker", ["cp", binary, `${info.Id}:${remote}`], { stdio: "inherit" });
8947
+ execFileSync3("docker", ["cp", binary, `${info.Id}:${remote}`], { stdio: "inherit" });
8872
8948
  try {
8873
- execFileSync2("docker", ["exec", info.Id, "sh", "-c", `cp /opt/agent-server/agent-server /tmp/agent-server.rollback && chmod 755 ${remote} && mv ${remote} /opt/agent-server/agent-server && pkill -f '^/opt/agent-server/agent-server$'`], { stdio: "inherit" });
8949
+ execFileSync3("docker", ["exec", info.Id, "sh", "-c", `cp /opt/agent-server/agent-server /tmp/agent-server.rollback && chmod 755 ${remote} && mv ${remote} /opt/agent-server/agent-server && pkill -f '^/opt/agent-server/agent-server$'`], { stdio: "inherit" });
8874
8950
  await waitHealthy();
8875
8951
  } catch {
8876
- execFileSync2("docker", ["exec", info.Id, "sh", "-c", "test -f /tmp/agent-server.rollback && mv /tmp/agent-server.rollback /opt/agent-server/agent-server && pkill -f '^/opt/agent-server/agent-server$' || true"], { stdio: "ignore" });
8952
+ execFileSync3("docker", ["exec", info.Id, "sh", "-c", "test -f /tmp/agent-server.rollback && mv /tmp/agent-server.rollback /opt/agent-server/agent-server && pkill -f '^/opt/agent-server/agent-server$' || true"], { stdio: "ignore" });
8877
8953
  throw new CliError("DEV_SYNC_ROLLBACK", "developer server sync failed and original binary was restored", EXIT.ROLLBACK);
8878
8954
  }
8879
8955
  output({ synced: true, sha256 }, () => console.log("Developer server synchronized"));
@@ -9025,7 +9101,21 @@ program2.command("send <chat-id>").description("Send exactly one payload to a st
9025
9101
  program2.command("upgrade").description("Check CLI/image upgrades without claiming atomic self-upgrade").addOption(new Option("--check", "read-only upgrade check")).addOption(new Option("--cli", "print an exact npm CLI upgrade command")).addOption(new Option("--image <reference>", "transactionally rebuild with an exact compatible image")).action((options) => action(async () => {
9026
9102
  const selected = [options.check === true, options.cli === true, typeof options.image === "string"].filter(Boolean).length;
9027
9103
  if (selected > 1) throw new CliError("ARGUMENT_CONFLICT", "--check, --cli, and --image are mutually exclusive", EXIT.ARGUMENT);
9028
- if (options.cli) throw new CliError("CLI_UPGRADE_UNAVAILABLE", "P1-B npm publication has not been independently verified; use the repository-only pnpm cli workflow", EXIT.ENVIRONMENT);
9104
+ if (options.cli) {
9105
+ let result2;
9106
+ try {
9107
+ result2 = checkCliUpgrade(VERSION);
9108
+ } catch (error) {
9109
+ if (error instanceof CliUpgradeError) {
9110
+ throw new CliError(error.code, error.message, error.code === "CLI_UPGRADE_REGISTRY_ERROR" ? EXIT.SERVICE : EXIT.ENVIRONMENT);
9111
+ }
9112
+ throw error;
9113
+ }
9114
+ return output(result2, () => {
9115
+ if (result2.command) console.log(result2.command);
9116
+ else console.log(`CLI is already up to date (${result2.currentVersion})`);
9117
+ });
9118
+ }
9029
9119
  if (options.image) {
9030
9120
  const result2 = await replaceImage({ image: options.image, identity: ensureDeviceIdentity(CONFIG_DIR), token: ensureToken() });
9031
9121
  return output({ upgraded: true, imageDigest: result2.imageDigest }, () => console.log(`Image upgraded to ${result2.imageDigest}`));
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "cliVersion": "0.12.0",
3
+ "cliVersion": "0.13.0",
4
4
  "repository": "ghcr.io/kyan-du/agent-wechat",
5
5
  "apiVersion": 1,
6
6
  "allowedReferences": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kyan-du/agent-wechat-cli",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "wx": "./dist/cli.js"