@simonyea/holysheep-cli 1.7.79 → 1.7.81

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.79",
3
+ "version": "1.7.81",
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",
@@ -227,6 +227,12 @@ function removeEnvFromShell(extraKeys = []) {
227
227
  'HOLYSHEEP_API_KEY',
228
228
  ...extraKeys,
229
229
  ]
230
+
231
+ // Windows:通过 PowerShell 删除用户级注册表环境变量
232
+ if (process.platform === 'win32') {
233
+ return removeWindowsUserEnvVars(HS_KEYS)
234
+ }
235
+
230
236
  const files = getShellRcFiles()
231
237
  const cleaned = []
232
238
  for (const file of files) {
@@ -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