@simonyea/holysheep-cli 1.7.22 → 1.7.24
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 +1 -1
- package/src/commands/claude.js +58 -0
- package/src/commands/setup.js +19 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simonyea/holysheep-cli",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.24",
|
|
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",
|
package/src/commands/claude.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { spawn } = require('child_process')
|
|
4
|
+
const crypto = require('crypto')
|
|
4
5
|
const {
|
|
5
6
|
BASE_URL_ANTHROPIC,
|
|
7
|
+
BASE_URL_CLAUDE_RELAY,
|
|
6
8
|
getApiKey,
|
|
7
9
|
} = require('../utils/config')
|
|
8
10
|
const {
|
|
@@ -10,8 +12,62 @@ const {
|
|
|
10
12
|
getLocalProxyUrl,
|
|
11
13
|
startProcessProxy,
|
|
12
14
|
readConfig,
|
|
15
|
+
writeConfig,
|
|
13
16
|
} = require('../tools/claude-process-proxy')
|
|
14
17
|
|
|
18
|
+
function ensureClaudeProxyConfig(apiKey) {
|
|
19
|
+
const config = readConfig()
|
|
20
|
+
const next = { ...config }
|
|
21
|
+
let changed = false
|
|
22
|
+
|
|
23
|
+
if (!next.apiKey && apiKey) {
|
|
24
|
+
next.apiKey = apiKey
|
|
25
|
+
changed = true
|
|
26
|
+
}
|
|
27
|
+
if (!next.baseUrlAnthropic) {
|
|
28
|
+
next.baseUrlAnthropic = BASE_URL_ANTHROPIC
|
|
29
|
+
changed = true
|
|
30
|
+
}
|
|
31
|
+
if (!next.controlPlaneUrl) {
|
|
32
|
+
next.controlPlaneUrl = next.relayUrl || BASE_URL_CLAUDE_RELAY
|
|
33
|
+
changed = true
|
|
34
|
+
}
|
|
35
|
+
if (!next.relayUrl) {
|
|
36
|
+
next.relayUrl = BASE_URL_CLAUDE_RELAY
|
|
37
|
+
changed = true
|
|
38
|
+
}
|
|
39
|
+
if (!next.bridgeId) {
|
|
40
|
+
next.bridgeId = crypto.randomUUID()
|
|
41
|
+
changed = true
|
|
42
|
+
}
|
|
43
|
+
if (!next.deviceId) {
|
|
44
|
+
next.deviceId = crypto.randomUUID()
|
|
45
|
+
changed = true
|
|
46
|
+
}
|
|
47
|
+
if (!next.bridgeSecret) {
|
|
48
|
+
next.bridgeSecret = crypto.randomBytes(32).toString('hex')
|
|
49
|
+
changed = true
|
|
50
|
+
}
|
|
51
|
+
if (!next.installSource) {
|
|
52
|
+
next.installSource = 'holysheep-cli'
|
|
53
|
+
changed = true
|
|
54
|
+
}
|
|
55
|
+
if (!next.proxyMode) {
|
|
56
|
+
next.proxyMode = 'claude-process'
|
|
57
|
+
changed = true
|
|
58
|
+
}
|
|
59
|
+
if (!next.processProxyPort) {
|
|
60
|
+
next.processProxyPort = config.processProxyPort || 14556
|
|
61
|
+
changed = true
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (changed) {
|
|
65
|
+
writeConfig(next)
|
|
66
|
+
return next
|
|
67
|
+
}
|
|
68
|
+
return config
|
|
69
|
+
}
|
|
70
|
+
|
|
15
71
|
async function runClaude(args = []) {
|
|
16
72
|
const config = readConfig()
|
|
17
73
|
const apiKey = config.apiKey || getApiKey()
|
|
@@ -19,6 +75,8 @@ async function runClaude(args = []) {
|
|
|
19
75
|
throw new Error('Missing API Key. Run hs setup first.')
|
|
20
76
|
}
|
|
21
77
|
|
|
78
|
+
ensureClaudeProxyConfig(apiKey)
|
|
79
|
+
|
|
22
80
|
const { server, port, sessionId } = startProcessProxy({})
|
|
23
81
|
const proxyUrl = getLocalProxyUrl(port)
|
|
24
82
|
|
package/src/commands/setup.js
CHANGED
|
@@ -56,11 +56,22 @@ function getWindowsImmediateLaunchCmd(tool) {
|
|
|
56
56
|
return null
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
// 检测当前 shell 里的 hs 命令是否已包含 claude 子命令
|
|
60
|
+
function isHsClaudeAvailable() {
|
|
61
|
+
try {
|
|
62
|
+
const out = execSync('hs --help', {
|
|
63
|
+
encoding: 'utf8',
|
|
64
|
+
timeout: 4000,
|
|
65
|
+
shell: process.platform === 'win32',
|
|
66
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
67
|
+
})
|
|
68
|
+
return out.includes('claude')
|
|
69
|
+
} catch {
|
|
70
|
+
return false
|
|
62
71
|
}
|
|
72
|
+
}
|
|
63
73
|
|
|
74
|
+
function getPreferredCliPrefix() {
|
|
64
75
|
const mainEntry = String(require.main?.filename || '')
|
|
65
76
|
const runningFromNpxCache =
|
|
66
77
|
/[\\/]_npx[\\/]/i.test(mainEntry) ||
|
|
@@ -394,6 +405,11 @@ async function setup(options) {
|
|
|
394
405
|
const immediateCmd = getWindowsImmediateLaunchCmd({ ...r.tool, launchCmd: preferredLaunchCmd || r.tool.launchCmd })
|
|
395
406
|
console.log(` ${chalk.gray('▶ 立即启动:')} ${chalk.cyan.bold(immediateCmd || preferredLaunchCmd || r.tool.launchCmd)}`)
|
|
396
407
|
console.log(` ${chalk.gray('▶ 新开终端后:')} ${chalk.cyan.bold(preferredLaunchCmd || r.tool.launchCmd)}`)
|
|
408
|
+
} else if (r.tool.id === 'claude-code' && !isHsClaudeAvailable()) {
|
|
409
|
+
// hs claude 在当前 shell 不可用(hs 未安装或版本过旧),显示两条命令
|
|
410
|
+
const npxCmd = `npx @simonyea/holysheep-cli@${pkg.version} claude`
|
|
411
|
+
console.log(` ${chalk.gray('▶ 立即启动:')} ${chalk.cyan.bold(npxCmd)}`)
|
|
412
|
+
console.log(` ${chalk.gray('▶ 新开终端后:')} ${chalk.cyan.bold('hs claude')}`)
|
|
397
413
|
} else {
|
|
398
414
|
console.log(` ${chalk.gray('▶ 启动命令:')} ${chalk.cyan.bold(preferredLaunchCmd || r.tool.launchCmd)}`)
|
|
399
415
|
}
|