@simonyea/holysheep-cli 1.7.99 → 1.7.100

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.99",
3
+ "version": "1.7.100",
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",
@@ -18,7 +18,10 @@
18
18
  'use strict'
19
19
 
20
20
  const { writeEnvToShell, removeEnvFromShell, getShellRcFiles } = require('../utils/shell')
21
+ const { execSync } = require('child_process')
21
22
  const fs = require('fs')
23
+ const path = require('path')
24
+ const os = require('os')
22
25
 
23
26
  const MANAGED_KEYS = [
24
27
  'ANTHROPIC_API_KEY',
@@ -29,14 +32,29 @@ const MANAGED_KEYS = [
29
32
  ]
30
33
 
31
34
  const MARKER = '# >>> holysheep-cli managed >>>'
35
+ const STATE_FILE = path.join(os.homedir(), '.holysheep', 'env-config.json')
36
+
37
+ /**
38
+ * Windows: 从注册表读取用户级环境变量
39
+ */
40
+ function winRegQuery(key) {
41
+ try {
42
+ const out = execSync(
43
+ `reg query "HKCU\\Environment" /v "${key}"`,
44
+ { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000, windowsHide: true }
45
+ )
46
+ const match = out.match(/REG_\w+\s+(.+)/)
47
+ return match ? match[1].trim() : null
48
+ } catch {
49
+ return null
50
+ }
51
+ }
32
52
 
33
53
  function isConfiguredInShell() {
34
54
  if (process.platform === 'win32') {
35
- // Windows: 检查环境变量是否存在且包含 holysheep
36
- return !!(
37
- process.env.ANTHROPIC_BASE_URL?.includes('holysheep') ||
38
- process.env.OPENAI_BASE_URL?.includes('holysheep')
39
- )
55
+ // Windows: 查注册表(setx 写入后当前进程的 process.env 看不到)
56
+ const val = winRegQuery('ANTHROPIC_BASE_URL')
57
+ return !!(val && val.includes('holysheep'))
40
58
  }
41
59
 
42
60
  // Mac/Linux: 检查 shell rc 文件里是否有 managed 块
@@ -54,6 +72,18 @@ function isConfiguredInShell() {
54
72
  return false
55
73
  }
56
74
 
75
+ function saveState(envVars) {
76
+ try {
77
+ const dir = path.dirname(STATE_FILE)
78
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true })
79
+ fs.writeFileSync(STATE_FILE, JSON.stringify({ configuredAt: new Date().toISOString(), keys: Object.keys(envVars) }, null, 2), 'utf8')
80
+ } catch {}
81
+ }
82
+
83
+ function clearState() {
84
+ try { fs.unlinkSync(STATE_FILE) } catch {}
85
+ }
86
+
57
87
  module.exports = {
58
88
  name: '全局环境变量',
59
89
  id: 'env-config',
@@ -76,18 +106,36 @@ module.exports = {
76
106
  }
77
107
 
78
108
  const written = writeEnvToShell(envVars)
109
+ saveState(envVars)
79
110
 
80
111
  return {
81
- file: written[0] || 'shell env',
112
+ file: written.join(', ') || 'shell env',
82
113
  hot: false,
83
114
  }
84
115
  },
85
116
 
86
117
  reset() {
87
118
  removeEnvFromShell(MANAGED_KEYS)
119
+ clearState()
88
120
  },
89
121
 
90
122
  getConfigPath() { return null },
123
+
124
+ /**
125
+ * 获取已配置的环境变量值(Windows 从注册表读,其他从 process.env 读)
126
+ */
127
+ getConfiguredValues() {
128
+ const result = {}
129
+ for (const key of MANAGED_KEYS) {
130
+ if (process.platform === 'win32') {
131
+ result[key] = winRegQuery(key) || null
132
+ } else {
133
+ result[key] = process.env[key] || null
134
+ }
135
+ }
136
+ return result
137
+ },
138
+
91
139
  hint: '配置后 VS Code Claude 扩展、Cursor、Continue、Cline、Windsurf 等工具均可直接使用',
92
140
  launchCmd: null,
93
141
  docsUrl: 'https://holysheep.ai',
@@ -702,8 +702,13 @@ const MARKER_START = '# >>> holysheep-cli managed >>>'
702
702
 
703
703
  function handleEnv(_req, res) {
704
704
  const vars = {}
705
+
706
+ // Windows: process.env 看不到 setx 写入的值,从注册表读
707
+ const envConfigTool = TOOLS.find(t => t.id === 'env-config')
708
+ const registryValues = (process.platform === 'win32' && envConfigTool?.getConfiguredValues?.()) || {}
709
+
705
710
  for (const k of HS_ENV_KEYS) {
706
- const v = process.env[k]
711
+ const v = process.env[k] || registryValues[k] || null
707
712
  vars[k] = v ? (k.includes('KEY') || k.includes('TOKEN') ? maskKey(v) : v) : null
708
713
  }
709
714