@simonyea/holysheep-cli 1.7.31 → 1.7.33

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.31",
3
+ "version": "1.7.33",
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",
@@ -39,7 +39,7 @@ async function runClaude(args = []) {
39
39
 
40
40
  ensureClaudeProxyConfig(apiKey)
41
41
 
42
- const { server, port, sessionId } = startProcessProxy({})
42
+ const { server, port, sessionId } = await startProcessProxy({})
43
43
  const proxyUrl = getLocalProxyUrl(port)
44
44
 
45
45
  const env = {
@@ -218,11 +218,28 @@ function createProcessProxyServer({ sessionId, configPath = CONFIG_PATH }) {
218
218
 
219
219
  function startProcessProxy({ port = null, sessionId = null, configPath = CONFIG_PATH } = {}) {
220
220
  const config = readConfig(configPath)
221
- const listenPort = port || getProcessProxyPort(config)
221
+ const preferredPort = port || getProcessProxyPort(config)
222
222
  const effectiveSessionId = sessionId || crypto.randomUUID()
223
223
  const server = createProcessProxyServer({ sessionId: effectiveSessionId, configPath })
224
- server.listen(listenPort, '127.0.0.1')
225
- return { server, port: listenPort, sessionId: effectiveSessionId }
224
+
225
+ return new Promise((resolve, reject) => {
226
+ const tryListen = (p) => {
227
+ server.once('error', (err) => {
228
+ if (err.code === 'EADDRINUSE') {
229
+ // 端口被占用,让 OS 分配一个随机可用端口
230
+ server.once('error', reject)
231
+ server.listen(0, '127.0.0.1')
232
+ } else {
233
+ reject(err)
234
+ }
235
+ })
236
+ server.once('listening', () => {
237
+ resolve({ server, port: server.address().port, sessionId: effectiveSessionId })
238
+ })
239
+ server.listen(p, '127.0.0.1')
240
+ }
241
+ tryListen(preferredPort)
242
+ })
226
243
  }
227
244
 
228
245
  async function closeSession(configPath, sessionId) {
@@ -125,6 +125,9 @@ function installWindowsCliShims() {
125
125
  const npmBin = path.join(appData, 'npm')
126
126
  fs.mkdirSync(npmBin, { recursive: true })
127
127
 
128
+ // 如果 hs.cmd 已存在(npm install -g 生成的),不覆盖
129
+ if (fs.existsSync(path.join(npmBin, 'hs.cmd'))) return []
130
+
128
131
  const cliSpec = `@simonyea/holysheep-cli@${pkg.version}`
129
132
  // 用 %APPDATA% 展开路径(比 %~dp0 在 cmd.exe 里更可靠)
130
133
  const cmdContent = [