@simonyea/holysheep-cli 2.1.42 → 2.1.43

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.
@@ -3931,11 +3931,11 @@ var require_package = __commonJS({
3931
3931
  "package.json"(exports2, module2) {
3932
3932
  module2.exports = {
3933
3933
  name: "@simonyea/holysheep-cli",
3934
- version: "2.1.42",
3934
+ version: "2.1.43",
3935
3935
  description: "Claude Code/Cursor/Cline API relay for China \u2014 \xA51=$1, WeChat/Alipay payment, no credit card, no VPN. One command setup for all AI coding tools.",
3936
3936
  scripts: {
3937
3937
  build: "node scripts/build.mjs",
3938
- test: "node tests/droid.test.js && node tests/workspace-store.test.js && node tests/runtime-stale-upgrade.test.js && node tests/hermes.test.js && node tests/preflight.test.js && node tests/opencode-auth-purge.test.js && node tests/shell-winpath.test.js && node tests/openclaw-atomic-write.test.js && node tests/opencode-default-model.test.js && node tests/paths-bundled.test.js",
3938
+ test: "node tests/droid.test.js && node tests/workspace-store.test.js && node tests/runtime-stale-upgrade.test.js && node tests/hermes.test.js && node tests/preflight.test.js && node tests/opencode-auth-purge.test.js && node tests/shell-winpath.test.js && node tests/openclaw-atomic-write.test.js && node tests/opencode-default-model.test.js && node tests/paths-bundled.test.js && node tests/aionui-wrapper-claude-proxy.test.js",
3939
3939
  prepublishOnly: "npm run build && npm test && node scripts/check-tarball-size.js"
3940
3940
  },
3941
3941
  keywords: [
package/dist/index.js CHANGED
@@ -12,11 +12,11 @@ var require_package = __commonJS({
12
12
  "package.json"(exports2, module2) {
13
13
  module2.exports = {
14
14
  name: "@simonyea/holysheep-cli",
15
- version: "2.1.42",
15
+ version: "2.1.43",
16
16
  description: "Claude Code/Cursor/Cline API relay for China \u2014 \xA51=$1, WeChat/Alipay payment, no credit card, no VPN. One command setup for all AI coding tools.",
17
17
  scripts: {
18
18
  build: "node scripts/build.mjs",
19
- test: "node tests/droid.test.js && node tests/workspace-store.test.js && node tests/runtime-stale-upgrade.test.js && node tests/hermes.test.js && node tests/preflight.test.js && node tests/opencode-auth-purge.test.js && node tests/shell-winpath.test.js && node tests/openclaw-atomic-write.test.js && node tests/opencode-default-model.test.js && node tests/paths-bundled.test.js",
19
+ test: "node tests/droid.test.js && node tests/workspace-store.test.js && node tests/runtime-stale-upgrade.test.js && node tests/hermes.test.js && node tests/preflight.test.js && node tests/opencode-auth-purge.test.js && node tests/shell-winpath.test.js && node tests/openclaw-atomic-write.test.js && node tests/opencode-default-model.test.js && node tests/paths-bundled.test.js && node tests/aionui-wrapper-claude-proxy.test.js",
20
20
  prepublishOnly: "npm run build && npm test && node scripts/check-tarball-size.js"
21
21
  },
22
22
  keywords: [
@@ -8530,8 +8530,12 @@ var require_aionui_wrapper = __commonJS({
8530
8530
  getApiKey,
8531
8531
  loadConfig,
8532
8532
  saveConfig,
8533
- BASE_URL_OPENAI
8533
+ BASE_URL_OPENAI,
8534
+ BASE_URL_ANTHROPIC,
8535
+ BASE_URL_CLAUDE_RELAY
8534
8536
  } = require_config();
8537
+ var claudeProcessProxy = require_claude_process_proxy();
8538
+ var claudeCodeTool = require_claude_code();
8535
8539
  var BRIDGE_DIR = path.join(os.homedir(), ".holysheep");
8536
8540
  var BRIDGE_CRED_FILE = path.join(BRIDGE_DIR, "aionui-bridge.json");
8537
8541
  var TOKEN_TTL_MS = 3e4;
@@ -8984,6 +8988,76 @@ var require_aionui_wrapper = __commonJS({
8984
8988
  }, "onRequest");
8985
8989
  }
8986
8990
  __name(buildRouter, "buildRouter");
8991
+ function probeLocalPort(port, timeoutMs = 500) {
8992
+ return new Promise((resolve) => {
8993
+ const socket = net.createConnection({ host: "127.0.0.1", port });
8994
+ const timer = setTimeout(() => {
8995
+ try {
8996
+ socket.destroy();
8997
+ } catch {
8998
+ }
8999
+ resolve(false);
9000
+ }, timeoutMs);
9001
+ socket.once("connect", () => {
9002
+ clearTimeout(timer);
9003
+ try {
9004
+ socket.end();
9005
+ } catch {
9006
+ }
9007
+ resolve(true);
9008
+ });
9009
+ socket.once("error", () => {
9010
+ clearTimeout(timer);
9011
+ resolve(false);
9012
+ });
9013
+ });
9014
+ }
9015
+ __name(probeLocalPort, "probeLocalPort");
9016
+ function _ensureClaudeProxyConfig(apiKey) {
9017
+ const config = claudeProcessProxy.readConfig();
9018
+ const next = claudeCodeTool.buildBridgeConfig(apiKey, BASE_URL_ANTHROPIC, {
9019
+ ...config,
9020
+ relayUrl: config.relayUrl || BASE_URL_CLAUDE_RELAY
9021
+ });
9022
+ if (JSON.stringify(next) !== JSON.stringify(config)) {
9023
+ claudeProcessProxy.writeConfig(next);
9024
+ return next;
9025
+ }
9026
+ return config;
9027
+ }
9028
+ __name(_ensureClaudeProxyConfig, "_ensureClaudeProxyConfig");
9029
+ async function ensureClaudeProcessProxyRunning(opts = {}) {
9030
+ const proxyModule = opts.proxyModule || claudeProcessProxy;
9031
+ const probe = opts.probe || probeLocalPort;
9032
+ const apiKeyGetter = opts.apiKeyGetter || getApiKey;
9033
+ const ensureConfig = opts.ensureConfig || _ensureClaudeProxyConfig;
9034
+ const port = proxyModule.getProcessProxyPort(proxyModule.readConfig());
9035
+ const listening = await probe(port, 500);
9036
+ if (listening) {
9037
+ log(`claude process proxy already listening on 127.0.0.1:${port} (reusing; likely started by \`hs claude\` or another hs web)`);
9038
+ return { reused: true, port };
9039
+ }
9040
+ let apiKey;
9041
+ try {
9042
+ apiKey = apiKeyGetter();
9043
+ } catch {
9044
+ apiKey = null;
9045
+ }
9046
+ if (!apiKey) {
9047
+ log(`claude process proxy pre-start skipped: no HolySheep API key found (run \`hs login\` to enable Claude Code). Non-Claude backends unaffected.`);
9048
+ return { skipped: true, reason: "no-api-key", port };
9049
+ }
9050
+ try {
9051
+ ensureConfig(apiKey);
9052
+ const result = await proxyModule.startProcessProxy({});
9053
+ log(`claude process proxy listening on 127.0.0.1:${result.port} (sessionId=${String(result.sessionId).slice(0, 8)})`);
9054
+ return { reused: false, port: result.port, sessionId: result.sessionId, server: result.server };
9055
+ } catch (err) {
9056
+ log(`claude process proxy pre-start failed (continuing without it): ${err && err.message ? err.message : err}`);
9057
+ return { skipped: true, reason: "start-failed", port, error: err };
9058
+ }
9059
+ }
9060
+ __name(ensureClaudeProcessProxyRunning, "ensureClaudeProcessProxyRunning");
8987
9061
  async function startWrapper({ port, runtimeDir, runtimeVersion, runtimeSource, bunPath }) {
8988
9062
  const hsNative = detectHolySheepAionUi(runtimeDir);
8989
9063
  log(`/login mode: ${hsNative ? "holysheep-native (apiKey)" : "legacy (username/password bridge)"}`);
@@ -8992,6 +9066,7 @@ var require_aionui_wrapper = __commonJS({
8992
9066
  }
8993
9067
  const internalPort = await pickInternalPort();
8994
9068
  log(`internal runtime port: ${internalPort}`);
9069
+ const claudeProxyHandle = await ensureClaudeProcessProxyRunning();
8995
9070
  const debug = process.env.HS_WEB_DEBUG === "1";
8996
9071
  const { PACKAGE_ROOT, cliVersion, ptyHermesWrapperPath } = require_paths();
8997
9072
  const cliRoot = PACKAGE_ROOT;
@@ -9035,10 +9110,33 @@ var require_aionui_wrapper = __commonJS({
9035
9110
  }, "appendLog");
9036
9111
  aionui.stdout.on("data", (d) => appendLog("out", d));
9037
9112
  aionui.stderr.on("data", (d) => appendLog("err", d));
9113
+ let claudeProxyCleanedUp = false;
9114
+ const cleanupClaudeProxy = /* @__PURE__ */ __name(() => {
9115
+ if (claudeProxyCleanedUp) return;
9116
+ claudeProxyCleanedUp = true;
9117
+ if (!claudeProxyHandle || claudeProxyHandle.skipped || claudeProxyHandle.reused) return;
9118
+ try {
9119
+ if (claudeProxyHandle.server && typeof claudeProxyHandle.server.close === "function") {
9120
+ claudeProxyHandle.server.close();
9121
+ }
9122
+ } catch {
9123
+ }
9124
+ if (claudeProxyHandle.sessionId) {
9125
+ Promise.resolve(claudeProcessProxy.closeSession(void 0, claudeProxyHandle.sessionId)).catch(() => {
9126
+ });
9127
+ }
9128
+ }, "cleanupClaudeProxy");
9038
9129
  aionui.on("exit", (code) => {
9039
9130
  log(`runtime upstream exited (code=${code})`);
9131
+ cleanupClaudeProxy();
9040
9132
  process.exit(code || 1);
9041
9133
  });
9134
+ const _onSignal = /* @__PURE__ */ __name(() => {
9135
+ cleanupClaudeProxy();
9136
+ }, "_onSignal");
9137
+ process.once("SIGINT", _onSignal);
9138
+ process.once("SIGTERM", _onSignal);
9139
+ process.once("exit", cleanupClaudeProxy);
9042
9140
  try {
9043
9141
  await waitForUpstreamReady(internalPort);
9044
9142
  } catch (e) {
@@ -9089,7 +9187,10 @@ ${tail.split(/\r?\n/).map((ln) => ` ${ln}`).join("\n")}
9089
9187
  pruneExpiredTokens,
9090
9188
  _tokens: bootstrapTokens,
9091
9189
  TOKEN_TTL_MS,
9092
- BRIDGE_CRED_FILE
9190
+ BRIDGE_CRED_FILE,
9191
+ // [HolySheep v2.1.43] Exported for aionui-wrapper-claude-proxy.test.js
9192
+ ensureClaudeProcessProxyRunning,
9193
+ probeLocalPort
9093
9194
  };
9094
9195
  }
9095
9196
  });
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@simonyea/holysheep-cli",
3
- "version": "2.1.42",
3
+ "version": "2.1.43",
4
4
  "description": "Claude Code/Cursor/Cline API relay for China — ¥1=$1, WeChat/Alipay payment, no credit card, no VPN. One command setup for all AI coding tools.",
5
5
  "scripts": {
6
6
  "build": "node scripts/build.mjs",
7
- "test": "node tests/droid.test.js && node tests/workspace-store.test.js && node tests/runtime-stale-upgrade.test.js && node tests/hermes.test.js && node tests/preflight.test.js && node tests/opencode-auth-purge.test.js && node tests/shell-winpath.test.js && node tests/openclaw-atomic-write.test.js && node tests/opencode-default-model.test.js && node tests/paths-bundled.test.js",
7
+ "test": "node tests/droid.test.js && node tests/workspace-store.test.js && node tests/runtime-stale-upgrade.test.js && node tests/hermes.test.js && node tests/preflight.test.js && node tests/opencode-auth-purge.test.js && node tests/shell-winpath.test.js && node tests/openclaw-atomic-write.test.js && node tests/opencode-default-model.test.js && node tests/paths-bundled.test.js && node tests/aionui-wrapper-claude-proxy.test.js",
8
8
  "prepublishOnly": "npm run build && npm test && node scripts/check-tarball-size.js"
9
9
  },
10
10
  "keywords": [