@simonyea/holysheep-cli 1.7.78 → 1.7.80

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonyea/holysheep-cli",
3
- "version": "1.7.78",
3
+ "version": "1.7.80",
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
  "keywords": [
6
6
  "openai-china",
@@ -81,8 +81,9 @@ async function runClaude(args = []) {
81
81
  ...process.env,
82
82
  ANTHROPIC_API_KEY: undefined,
83
83
  ANTHROPIC_AUTH_TOKEN: apiKey,
84
- // Force Anthropic API traffic through the local process proxy instead of
85
- // relying on the Claude binary to honor HTTP(S)_PROXY on every code path.
84
+ // Route ALL Anthropic API traffic exclusively through ANTHROPIC_BASE_URL.
85
+ // HTTP(S)_PROXY must NOT be set: it causes Claude Code to open CONNECT
86
+ // tunnels to api.anthropic.com, bypassing CRS multi-account scheduling.
86
87
  ANTHROPIC_BASE_URL: proxyUrl,
87
88
  CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
88
89
  HOLYSHEEP_CLAUDE_PROCESS_PROXY: '1',
@@ -90,10 +91,10 @@ async function runClaude(args = []) {
90
91
  HS_PROXY_URL: proxyUrl,
91
92
  HOLYSHEEP_CLAUDE_RUNTIME_KIND: runtime.kind || 'unknown',
92
93
  HOLYSHEEP_CLAUDE_LAUNCH_MODE: launchMode,
93
- HTTP_PROXY: proxyUrl,
94
- HTTPS_PROXY: proxyUrl,
95
- ALL_PROXY: proxyUrl,
96
- NO_PROXY: mergeNoProxy(process.env.NO_PROXY, ['127.0.0.1', 'localhost']),
94
+ HTTP_PROXY: undefined,
95
+ HTTPS_PROXY: undefined,
96
+ ALL_PROXY: undefined,
97
+ NO_PROXY: undefined,
97
98
  }
98
99
 
99
100
  // 不再写 settings.json — 只用 env 变量,避免 Claude Code 从两个来源
@@ -233,6 +233,10 @@ function createProcessProxyServer({ sessionId, configPath = CONFIG_PATH }) {
233
233
  }
234
234
  })
235
235
 
236
+ // Hosts that must NOT be tunneled directly — they must go through CRS via
237
+ // the HTTP path (ANTHROPIC_BASE_URL), not a CONNECT tunnel that bypasses it.
238
+ const BLOCKED_CONNECT = new Set(['api.anthropic.com'])
239
+
236
240
  server.on('connect', async (req, clientSocket, head) => {
237
241
  const target = String(req.url || '').trim()
238
242
  const [host, rawPort] = target.split(':')
@@ -242,6 +246,13 @@ function createProcessProxyServer({ sessionId, configPath = CONFIG_PATH }) {
242
246
  return clientSocket.destroy()
243
247
  }
244
248
 
249
+ if (BLOCKED_CONNECT.has(host)) {
250
+ // Block direct CONNECT tunnels to Anthropic — traffic must go through
251
+ // ANTHROPIC_BASE_URL so CRS can apply multi-account scheduling.
252
+ clientSocket.write('HTTP/1.1 403 Forbidden\r\ncontent-type: text/plain; charset=utf-8\r\n\r\nDirect tunnel to api.anthropic.com is blocked; use ANTHROPIC_BASE_URL path')
253
+ return clientSocket.destroy()
254
+ }
255
+
245
256
  const doConnect = async (lease) => {
246
257
  const upstreamSocket = await createConnectTunnel(
247
258
  deriveNodeProxyUrl(lease),
@@ -55,8 +55,12 @@ async function validateApiKey(apiKey) {
55
55
  return res.status === 200
56
56
  }
57
57
 
58
- function getVersion(tool) {
59
- if (typeof tool.getVersion === 'function') return tool.getVersion()
58
+ const { exec } = require('child_process')
59
+
60
+ function getVersionAsync(tool) {
61
+ if (typeof tool.getVersion === 'function') {
62
+ return Promise.resolve(tool.getVersion())
63
+ }
60
64
  const cmds = {
61
65
  'claude-code': 'claude --version',
62
66
  'codex': 'codex --version',
@@ -67,10 +71,13 @@ function getVersion(tool) {
67
71
  'aider': 'aider --version',
68
72
  }
69
73
  const cmd = cmds[tool.id]
70
- if (!cmd) return null
71
- try {
72
- return execSync(cmd, { stdio: 'pipe', timeout: 10000 }).toString().trim().split('\n')[0].slice(0, 30)
73
- } catch { return null }
74
+ if (!cmd) return Promise.resolve(null)
75
+ return new Promise(resolve => {
76
+ exec(cmd, { timeout: 5000 }, (err, stdout) => {
77
+ if (err) return resolve(null)
78
+ resolve(stdout.trim().split('\n')[0].slice(0, 30) || null)
79
+ })
80
+ })
74
81
  }
75
82
 
76
83
  function parseBody(req) {
@@ -141,17 +148,16 @@ let _latestVersion = null
141
148
  let _lastCheckTime = 0
142
149
  const UPDATE_CHECK_INTERVAL = 5 * 60 * 1000
143
150
 
144
- async function checkLatestVersion() {
151
+ // Returns cached value immediately; fetches in background when cache is stale.
152
+ function checkLatestVersion() {
145
153
  const now = Date.now()
146
- if (_latestVersion && now - _lastCheckTime < UPDATE_CHECK_INTERVAL) return _latestVersion
147
- try {
148
- const r = await fetchWithRetry('https://registry.npmjs.org/@simonyea/holysheep-cli/latest', {}, 2)
149
- if (r.ok) {
150
- const data = await r.json()
151
- _latestVersion = data.version || null
152
- _lastCheckTime = now
153
- }
154
- } catch {}
154
+ if (now - _lastCheckTime >= UPDATE_CHECK_INTERVAL) {
155
+ _lastCheckTime = now // prevent concurrent fetches
156
+ fetchWithRetry('https://registry.npmjs.org/@simonyea/holysheep-cli/latest', {}, 2)
157
+ .then(r => r.ok ? r.json() : null)
158
+ .then(data => { if (data?.version) _latestVersion = data.version })
159
+ .catch(() => {})
160
+ }
155
161
  return _latestVersion
156
162
  }
157
163
 
@@ -160,10 +166,10 @@ checkLatestVersion()
160
166
 
161
167
  // ── API Handlers ─────────────────────────────────────────────────────────────
162
168
 
163
- async function handleStatus(_req, res) {
169
+ function handleStatus(_req, res) {
164
170
  const apiKey = getApiKey()
165
171
  const config = loadConfig()
166
- const latest = await checkLatestVersion()
172
+ const latest = checkLatestVersion()
167
173
  json(res, {
168
174
  loggedIn: !!apiKey,
169
175
  apiKey: apiKey ? maskKey(apiKey) : null,
@@ -280,21 +286,21 @@ async function handleDoctor(_req, res) {
280
286
  }
281
287
 
282
288
  async function handleTools(_req, res) {
283
- const tools = TOOLS.map(t => {
289
+ const tools = await Promise.all(TOOLS.map(async t => {
284
290
  const installed = t.checkInstalled()
285
291
  return {
286
292
  id: t.id,
287
293
  name: t.name,
288
294
  installed,
289
295
  configured: installed ? (t.isConfigured?.() || false) : false,
290
- version: installed ? getVersion(t) : null,
296
+ version: installed ? await getVersionAsync(t) : null,
291
297
  installCmd: t.installCmd,
292
298
  hint: t.hint || null,
293
299
  launchCmd: t.launchCmd || null,
294
300
  canAutoInstall: !!AUTO_INSTALL[t.id],
295
301
  canUpgrade: !!UPGRADABLE_TOOLS.find(u => u.id === t.id),
296
302
  }
297
- })
303
+ }))
298
304
  json(res, tools)
299
305
  }
300
306