@simonyea/holysheep-cli 1.7.73 → 1.7.75

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.73",
3
+ "version": "1.7.75",
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",
@@ -25,13 +25,26 @@ try {
25
25
  const PROXY_HOST = parsed.hostname
26
26
  const PROXY_PORT = Number(parsed.port) || 80
27
27
  const SKIP = new Set(['127.0.0.1', '::1', 'localhost', '0.0.0.0', PROXY_HOST])
28
+ // 阻断直连 Anthropic — 强制 Claude Code 走 ANTHROPIC_BASE_URL (HTTP 路径 → proxy → CRS)
29
+ // CONNECT 隧道因 TLS SNI 不匹配无法改写目标,只能阻断
30
+ const BLOCK = new Set(['api.anthropic.com'])
28
31
 
29
32
  function shouldProxy(host, port) {
30
- return !!(port && host && !SKIP.has(host))
33
+ if (!port || !host || SKIP.has(host)) return false
34
+ if (BLOCK.has(host)) return 'block'
35
+ return true
36
+ }
37
+
38
+ // api.anthropic.com → api.holysheep.ai,让 CONNECT 隧道也走 CRS 多账号调度
39
+ // 否则 CONNECT 隧道直达 Anthropic,绕过 CRS,单 token 直连容易触发 429
40
+ function rewriteHost(host) {
41
+ if (host === 'api.anthropic.com') return 'api.holysheep.ai'
42
+ return host
31
43
  }
32
44
 
33
45
  function setupTunnel(sock, host, port, origEmit) {
34
- sock.write(`CONNECT ${host}:${port} HTTP/1.1\r\nHost: ${host}:${port}\r\n\r\n`)
46
+ const targetHost = rewriteHost(host)
47
+ sock.write(`CONNECT ${targetHost}:${port} HTTP/1.1\r\nHost: ${targetHost}:${port}\r\n\r\n`)
35
48
  let buf = Buffer.alloc(0)
36
49
  sock.on('data', function onData(chunk) {
37
50
  buf = Buffer.concat([buf, chunk])
@@ -74,7 +87,14 @@ net.Socket.prototype.connect = function(options) {
74
87
  const host = isObj ? String(options.host || options.hostname || '') : String(options || '')
75
88
  const port = isObj ? Number(options.port || 0) : Number(arguments[1] || 0)
76
89
 
77
- if (!shouldProxy(host, port)) return _origSocketConnect.apply(this, arguments)
90
+ const action = shouldProxy(host, port)
91
+ if (!action) return _origSocketConnect.apply(this, arguments)
92
+ if (action === 'block') {
93
+ // 阻断直连 Anthropic,触发连接失败,Claude Code 会回退到 ANTHROPIC_BASE_URL
94
+ const sock = this
95
+ process.nextTick(() => sock.destroy(new Error(`ECONNREFUSED: blocked direct connection to ${host}`)))
96
+ return sock
97
+ }
78
98
 
79
99
  const sock = this
80
100
  const proxyOpts = isObj
@@ -94,7 +114,13 @@ function proxied(options, cb) {
94
114
  const host = isObj ? String(options.host || options.hostname || 'localhost') : String(options || 'localhost')
95
115
  const port = isObj ? Number(options.port || 0) : Number(arguments[1] || 0)
96
116
 
97
- if (!shouldProxy(host, port)) return _origCreate.apply(this, arguments)
117
+ const action = shouldProxy(host, port)
118
+ if (!action) return _origCreate.apply(this, arguments)
119
+ if (action === 'block') {
120
+ const sock = new net.Socket()
121
+ process.nextTick(() => sock.destroy(new Error(`ECONNREFUSED: blocked direct connection to ${host}`)))
122
+ return sock
123
+ }
98
124
 
99
125
  const sock = _origCreate({ host: PROXY_HOST, port: PROXY_PORT })
100
126
  if (typeof cb === 'function') sock.once('connect', cb)