@simonyea/holysheep-cli 1.7.49 → 1.7.51

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
@@ -225,6 +225,7 @@ A: OpenClaw 需要 Node.js 20+,运行 `node --version` 确认版本后重试
225
225
 
226
226
  ## Changelog
227
227
 
228
+ - **v1.7.51** — 修复 `hs claude` 在 Claude Code 独立二进制版本上的整进程代理:自动识别脚本入口 / 独立二进制并切换到 `NODE_OPTIONS` 注入或 `HTTP(S)_PROXY` 模式;同时增强 `hs doctor` 的 Claude 代理诊断
228
229
  - **v1.6.14** — OpenClaw 新增 `gpt-5.3-codex-spark` 模型,通过本地 bridge 路由到 HolySheep `/v1`
229
230
  - **v1.6.13** — Codex 配置改为直接写 `api_key` 到 config.toml,不再依赖环境变量,修复 Windows 上 setup 后无需重启终端即可使用;同时精简工具列表,只保留 Claude Code / Codex / Droid / OpenClaw
230
231
  - **v1.6.12** — 修复 OpenClaw Bridge 对 GPT-5.4 的流式响应转换,避免 `holysheep/gpt-5.4` 在 OpenClaw 中报错;同时增强 Dashboard URL 解析,减少安装后浏览器打开黑屏/空白页
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonyea/holysheep-cli",
3
- "version": "1.7.49",
3
+ "version": "1.7.51",
4
4
  "description": "Claude Code/Cursor/Cline API relay for China \u2014 \u00a51=$1, WeChat/Alipay payment, no credit card, no VPN. One command setup for all AI coding tools.",
5
5
  "keywords": [
6
6
  "openai-china",
@@ -18,6 +18,24 @@ const claudeCodeTool = require('../tools/claude-code')
18
18
 
19
19
  const INJECT_PATH = path.resolve(__dirname, '../tools/process-proxy-inject.js')
20
20
 
21
+ function appendNodeRequire(existingValue, requirePath) {
22
+ const nextFlag = `--require ${requirePath}`
23
+ if (!existingValue) return nextFlag
24
+ return existingValue.includes(nextFlag) ? existingValue : `${existingValue} ${nextFlag}`.trim()
25
+ }
26
+
27
+ function mergeNoProxy(existingValue, extraHosts = []) {
28
+ const merged = new Set()
29
+ for (const chunk of String(existingValue || '').split(',')) {
30
+ const value = chunk.trim()
31
+ if (value) merged.add(value)
32
+ }
33
+ for (const host of extraHosts) {
34
+ if (host) merged.add(host)
35
+ }
36
+ return Array.from(merged).join(',')
37
+ }
38
+
21
39
  function ensureClaudeProxyConfig(apiKey) {
22
40
  const config = readConfig()
23
41
  const next = claudeCodeTool.buildBridgeConfig(apiKey, BASE_URL_ANTHROPIC, {
@@ -44,6 +62,9 @@ async function runClaude(args = []) {
44
62
 
45
63
  const { server, port, sessionId } = await startProcessProxy({})
46
64
  const proxyUrl = getLocalProxyUrl(port)
65
+ const runtime = typeof claudeCodeTool.detectClaudeRuntime === 'function'
66
+ ? claudeCodeTool.detectClaudeRuntime()
67
+ : { kind: 'unknown', launchMode: 'env-proxy' }
47
68
 
48
69
  const env = {
49
70
  ...process.env,
@@ -53,12 +74,18 @@ async function runClaude(args = []) {
53
74
  CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
54
75
  HOLYSHEEP_CLAUDE_PROCESS_PROXY: '1',
55
76
  HOLYSHEEP_CLAUDE_SESSION_ID: sessionId,
56
- NODE_OPTIONS: `--require ${INJECT_PATH}`,
57
77
  HS_PROXY_URL: proxyUrl,
58
- HTTP_PROXY: undefined,
59
- HTTPS_PROXY: undefined,
60
- ALL_PROXY: undefined,
61
- NO_PROXY: undefined,
78
+ HOLYSHEEP_CLAUDE_RUNTIME_KIND: runtime.kind || 'unknown',
79
+ HOLYSHEEP_CLAUDE_LAUNCH_MODE: runtime.launchMode || 'env-proxy',
80
+ }
81
+
82
+ if (runtime.launchMode === 'node-inject') {
83
+ env.NODE_OPTIONS = appendNodeRequire(process.env.NODE_OPTIONS, INJECT_PATH)
84
+ } else {
85
+ env.HTTP_PROXY = proxyUrl
86
+ env.HTTPS_PROXY = proxyUrl
87
+ env.ALL_PROXY = proxyUrl
88
+ env.NO_PROXY = mergeNoProxy(process.env.NO_PROXY, ['127.0.0.1', 'localhost'])
62
89
  }
63
90
 
64
91
  const child = spawn('claude', args, {
@@ -202,6 +202,9 @@ function printOpenClawDetails(tool, installState, nodeMajor) {
202
202
 
203
203
  function printClaudeProcessProxyDetails(tool) {
204
204
  const proxyConfig = typeof tool.getProcessProxyConfig === 'function' ? tool.getProcessProxyConfig() : {}
205
+ const runtime = typeof tool.detectClaudeRuntime === 'function'
206
+ ? tool.detectClaudeRuntime()
207
+ : { display: '未知', kind: 'unknown', launchMode: 'unknown', path: null }
205
208
  const relayUrl = proxyConfig.controlPlaneUrl || proxyConfig.relayUrl || BASE_URL_CLAUDE_RELAY
206
209
  const mode = proxyConfig.proxyMode || 'unknown'
207
210
  const hasBridgeSecret = Boolean(proxyConfig.bridgeSecret)
@@ -209,10 +212,19 @@ function printClaudeProcessProxyDetails(tool) {
209
212
  const hasProcessPort = Boolean(proxyConfig.processProxyPort)
210
213
  console.log(` ${chalk.gray('↳')} ${chalk.gray(`Claude 启动方式:hs claude`)}`)
211
214
  console.log(` ${chalk.gray('↳')} ${chalk.gray(`Claude 代理模式:${mode}`)}`)
215
+ console.log(` ${chalk.gray('↳')} ${chalk.gray(`Claude 可执行类型:${runtime.display}`)}`)
216
+ console.log(` ${chalk.gray('↳')} ${chalk.gray(`Claude 启动代理路径:${runtime.launchMode}`)}`)
212
217
  console.log(` ${chalk.gray('↳')} ${chalk.gray(`Claude Relay: ${relayUrl || '未配置'}`)}`)
213
218
  console.log(` ${hasBridgeSecret ? chalk.green('↳') : chalk.yellow('↳')} ${hasBridgeSecret ? chalk.green('Bridge secret 已配置') : chalk.yellow('Bridge secret 缺失')}`)
214
219
  console.log(` ${hasBridgeIds ? chalk.green('↳') : chalk.yellow('↳')} ${hasBridgeIds ? chalk.green('Bridge ID / Device ID 已配置') : chalk.yellow('Bridge ID / Device ID 缺失')}`)
215
220
  console.log(` ${hasProcessPort ? chalk.green('↳') : chalk.yellow('↳')} ${hasProcessPort ? chalk.green(`Claude process proxy 端口:${proxyConfig.processProxyPort}`) : chalk.yellow('Claude process proxy 端口缺失')}`)
221
+ if (runtime.path) {
222
+ console.log(` ${chalk.gray('↳')} ${chalk.gray(`Claude 路径:${runtime.path}`)}`)
223
+ }
224
+ const nodeMajor = parseInt(process.version.slice(1), 10)
225
+ if (nodeMajor > 22) {
226
+ console.log(` ${chalk.yellow('↳')} ${chalk.yellow(`当前 hs 运行在 ${process.version};Claude 代理更建议使用 Node 20/22 LTS`)}`)
227
+ }
216
228
  }
217
229
 
218
230
  function maskKey(key) {
@@ -12,6 +12,7 @@ const fs = require('fs')
12
12
  const path = require('path')
13
13
  const os = require('os')
14
14
  const crypto = require('crypto')
15
+ const { execSync } = require('child_process')
15
16
  const {
16
17
  BASE_URL_ANTHROPIC,
17
18
  BASE_URL_CLAUDE_RELAY,
@@ -55,6 +56,83 @@ function writeSettings(data) {
55
56
  fs.writeFileSync(SETTINGS_FILE, JSON.stringify(data, null, 2), 'utf8')
56
57
  }
57
58
 
59
+ function resolveCommandPath(cmd) {
60
+ try {
61
+ if (process.platform === 'win32') {
62
+ const out = execSync(`where ${cmd}`, { stdio: 'pipe' }).toString().trim()
63
+ const first = out.split(/\r?\n/).find(Boolean)
64
+ return first ? fs.realpathSync(first) : null
65
+ }
66
+
67
+ const out = execSync(`which ${cmd}`, { stdio: 'pipe' }).toString().trim()
68
+ const first = out.split(/\r?\n/).find(Boolean)
69
+ return first ? fs.realpathSync(first) : null
70
+ } catch {
71
+ return null
72
+ }
73
+ }
74
+
75
+ function detectBinaryFormat(buffer) {
76
+ if (!buffer || buffer.length < 4) return null
77
+ if (buffer[0] === 0x23 && buffer[1] === 0x21) return 'script'
78
+
79
+ const magic = buffer.slice(0, 4).toString('hex')
80
+ if (magic === '7f454c46') return 'elf'
81
+ if (magic === 'feedface' || magic === 'feedfacf' || magic === 'cefaedfe' || magic === 'cffaedfe') return 'mach-o'
82
+ if (buffer[0] === 0x4d && buffer[1] === 0x5a) return 'pe'
83
+
84
+ return null
85
+ }
86
+
87
+ function detectClaudeRuntime() {
88
+ const executablePath = resolveCommandPath('claude')
89
+ if (!executablePath) {
90
+ return {
91
+ available: false,
92
+ path: null,
93
+ kind: 'missing',
94
+ launchMode: 'unknown',
95
+ display: '未找到 claude',
96
+ }
97
+ }
98
+
99
+ try {
100
+ const fd = fs.openSync(executablePath, 'r')
101
+ const buffer = Buffer.alloc(16)
102
+ fs.readSync(fd, buffer, 0, buffer.length, 0)
103
+ fs.closeSync(fd)
104
+
105
+ const format = detectBinaryFormat(buffer)
106
+ if (format === 'script') {
107
+ return {
108
+ available: true,
109
+ path: executablePath,
110
+ kind: 'script',
111
+ launchMode: 'node-inject',
112
+ display: '脚本入口(使用 NODE_OPTIONS 注入)',
113
+ }
114
+ }
115
+
116
+ if (format) {
117
+ return {
118
+ available: true,
119
+ path: executablePath,
120
+ kind: 'binary',
121
+ launchMode: 'env-proxy',
122
+ display: `独立二进制(${format},使用 HTTP(S)_PROXY)`,
123
+ }
124
+ }
125
+ } catch {}
126
+
127
+ return {
128
+ available: true,
129
+ path: executablePath,
130
+ kind: 'unknown',
131
+ launchMode: 'env-proxy',
132
+ display: '未知入口类型(默认使用 HTTP(S)_PROXY)',
133
+ }
134
+ }
135
+
58
136
  module.exports = {
59
137
  name: 'Claude Code',
60
138
  id: 'claude-code',
@@ -119,4 +197,5 @@ module.exports = {
119
197
  return readConfig()
120
198
  },
121
199
  buildBridgeConfig,
200
+ detectClaudeRuntime,
122
201
  }
@@ -1,8 +1,13 @@
1
1
  'use strict'
2
2
  /**
3
3
  * 进程级代理注入 — 通过 NODE_OPTIONS=--require 加载
4
- * patch sock.emit 拦截 'connect' 事件,强制所有 TCP 连接走 CONNECT 隧道
5
- * 无论 TLSSocket 用何种方式注册监听器都无法绕过
4
+ *
5
+ * Node.js v22+ 中 tls.connect / undici 不走 net.createConnection,
6
+ * 直接调用 net.Socket.prototype.connect,因此同时 patch 两者。
7
+ *
8
+ * 原理:将所有非本地 TCP 连接重定向到本地 bridge(CONNECT 代理),
9
+ * bridge 再通过 relay-control 分配的 node 节点出口,使 CRS 看到
10
+ * 可信的节点 IP。
6
11
  */
7
12
  const net = require('net')
8
13
  const { URL } = require('url')
@@ -21,54 +26,90 @@ const PROXY_HOST = parsed.hostname
21
26
  const PROXY_PORT = Number(parsed.port) || 80
22
27
  const SKIP = new Set(['127.0.0.1', '::1', 'localhost', '0.0.0.0', PROXY_HOST])
23
28
 
24
- const _orig = net.createConnection
29
+ function shouldProxy(host, port) {
30
+ return !!(port && host && !SKIP.has(host))
31
+ }
32
+
33
+ function setupTunnel(sock, host, port, origEmit) {
34
+ sock.write(`CONNECT ${host}:${port} HTTP/1.1\r\nHost: ${host}:${port}\r\n\r\n`)
35
+ let buf = Buffer.alloc(0)
36
+ sock.on('data', function onData(chunk) {
37
+ buf = Buffer.concat([buf, chunk])
38
+ const i = buf.indexOf('\r\n\r\n')
39
+ if (i === -1) return
40
+ sock.removeListener('data', onData)
41
+ if (!buf.slice(0, i).toString().includes(' 200 ')) {
42
+ sock.emit = origEmit
43
+ sock.destroy(new Error(`CONNECT ${host}:${port} failed: ${buf.slice(0, buf.indexOf('\r\n')).toString()}`))
44
+ return
45
+ }
46
+ const rest = buf.slice(i + 4)
47
+ if (rest.length) sock.unshift(rest)
48
+ sock.emit = origEmit
49
+ origEmit('connect')
50
+ })
51
+ }
52
+
53
+ function patchEmitAndConnect(sock, host, port, connectFn) {
54
+ let tunnelReady = false
55
+ const origEmit = sock.emit.bind(sock)
56
+
57
+ sock.emit = function(type) {
58
+ if (type === 'connect' && !tunnelReady) {
59
+ tunnelReady = true
60
+ setupTunnel(sock, host, port, origEmit)
61
+ return false
62
+ }
63
+ return origEmit.apply(null, arguments)
64
+ }
65
+
66
+ return connectFn()
67
+ }
68
+
69
+ // ── patch net.Socket.prototype.connect (Node.js v22+ TLS / undici) ───────────
70
+ const _origSocketConnect = net.Socket.prototype.connect
71
+
72
+ net.Socket.prototype.connect = function(options) {
73
+ const isObj = options !== null && typeof options === 'object'
74
+ const host = isObj ? String(options.host || options.hostname || '') : String(options || '')
75
+ const port = isObj ? Number(options.port || 0) : Number(arguments[1] || 0)
76
+
77
+ if (!shouldProxy(host, port)) return _origSocketConnect.apply(this, arguments)
78
+
79
+ const sock = this
80
+ const proxyOpts = isObj
81
+ ? { ...options, host: PROXY_HOST, port: PROXY_PORT }
82
+ : { host: PROXY_HOST, port: PROXY_PORT }
83
+
84
+ return patchEmitAndConnect(sock, host, port, () =>
85
+ _origSocketConnect.call(sock, proxyOpts)
86
+ )
87
+ }
88
+
89
+ // ── patch net.createConnection (兼容直接调用的旧代码) ─────────────────────────
90
+ const _origCreate = net.createConnection
25
91
 
26
92
  function proxied(options, cb) {
27
93
  const isObj = options !== null && typeof options === 'object'
28
- const host = isObj
29
- ? String(options.host || options.hostname || 'localhost')
30
- : String(options || 'localhost')
31
- const port = isObj
32
- ? Number(options.port || 0)
33
- : Number(arguments[1] || 0)
94
+ const host = isObj ? String(options.host || options.hostname || 'localhost') : String(options || 'localhost')
95
+ const port = isObj ? Number(options.port || 0) : Number(arguments[1] || 0)
34
96
 
35
- if (!port || SKIP.has(host)) return _orig.apply(this, arguments)
97
+ if (!shouldProxy(host, port)) return _origCreate.apply(this, arguments)
98
+
99
+ const sock = _origCreate({ host: PROXY_HOST, port: PROXY_PORT })
100
+ if (typeof cb === 'function') sock.once('connect', cb)
36
101
 
37
- const sock = _orig({ host: PROXY_HOST, port: PROXY_PORT })
38
102
  let tunnelReady = false
39
103
  const origEmit = sock.emit.bind(sock)
40
-
41
- // patch emit 而不是 on/once:无论监听器怎么注册都能拦截
42
104
  sock.emit = function(type) {
43
105
  if (type === 'connect' && !tunnelReady) {
44
- // proxy TCP 已建立,发起 CONNECT 隧道
45
- sock.write(`CONNECT ${host}:${port} HTTP/1.1\r\nHost: ${host}:${port}\r\n\r\n`)
46
- let buf = Buffer.alloc(0)
47
- sock.on('data', function onData(chunk) {
48
- buf = Buffer.concat([buf, chunk])
49
- const i = buf.indexOf('\r\n\r\n')
50
- if (i === -1) return
51
- sock.removeListener('data', onData)
52
- const header = buf.slice(0, i).toString()
53
- if (!header.includes(' 200 ')) {
54
- sock.emit = origEmit
55
- sock.destroy(new Error(`CONNECT ${host}:${port} failed: ${header.split('\r\n')[0]}`))
56
- return
57
- }
58
- const rest = buf.slice(i + 4)
59
- if (rest.length) sock.unshift(rest)
60
- // 隧道就绪:恢复 emit,触发所有注册的 connect 监听器(含 TLSSocket)
61
- tunnelReady = true
62
- sock.emit = origEmit
63
- origEmit('connect')
64
- })
106
+ tunnelReady = true
107
+ setupTunnel(sock, host, port, origEmit)
65
108
  return false
66
109
  }
67
- // eslint-disable-next-line prefer-rest-params
68
110
  return origEmit.apply(null, arguments)
69
111
  }
70
112
 
71
- if (typeof cb === 'function') sock.once('connect', cb)
72
113
  return sock
73
114
  }
74
115