@simonyea/holysheep-cli 1.7.100 → 1.7.101

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.100",
3
+ "version": "1.7.101",
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",
@@ -35,16 +35,43 @@ const MARKER = '# >>> holysheep-cli managed >>>'
35
35
  const STATE_FILE = path.join(os.homedir(), '.holysheep', 'env-config.json')
36
36
 
37
37
  /**
38
- * Windows: 从注册表读取用户级环境变量
38
+ * Windows: 用 PowerShell 写入用户级环境变量(比 setx 更可靠)
39
39
  */
40
- function winRegQuery(key) {
40
+ function winSetEnvVar(key, value) {
41
+ try {
42
+ execSync(
43
+ `powershell.exe -NoProfile -Command "[Environment]::SetEnvironmentVariable('${key}', '${value}', 'User')"`,
44
+ { stdio: 'ignore', timeout: 10000, windowsHide: true }
45
+ )
46
+ return true
47
+ } catch {
48
+ return false
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Windows: 用 PowerShell 删除用户级环境变量
54
+ */
55
+ function winRemoveEnvVar(key) {
56
+ try {
57
+ execSync(
58
+ `powershell.exe -NoProfile -Command "[Environment]::SetEnvironmentVariable('${key}', $null, 'User')"`,
59
+ { stdio: 'ignore', timeout: 10000, windowsHide: true }
60
+ )
61
+ } catch {}
62
+ }
63
+
64
+ /**
65
+ * Windows: 用 PowerShell 读取用户级环境变量
66
+ */
67
+ function winGetEnvVar(key) {
41
68
  try {
42
69
  const out = execSync(
43
- `reg query "HKCU\\Environment" /v "${key}"`,
44
- { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000, windowsHide: true }
70
+ `powershell.exe -NoProfile -Command "[Environment]::GetEnvironmentVariable('${key}', 'User')"`,
71
+ { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 5000, windowsHide: true }
45
72
  )
46
- const match = out.match(/REG_\w+\s+(.+)/)
47
- return match ? match[1].trim() : null
73
+ const val = (out || '').trim()
74
+ return val || null
48
75
  } catch {
49
76
  return null
50
77
  }
@@ -52,8 +79,7 @@ function winRegQuery(key) {
52
79
 
53
80
  function isConfiguredInShell() {
54
81
  if (process.platform === 'win32') {
55
- // Windows: 查注册表(setx 写入后当前进程的 process.env 看不到)
56
- const val = winRegQuery('ANTHROPIC_BASE_URL')
82
+ const val = winGetEnvVar('ANTHROPIC_BASE_URL')
57
83
  return !!(val && val.includes('holysheep'))
58
84
  }
59
85
 
@@ -105,7 +131,20 @@ module.exports = {
105
131
  OPENAI_BASE_URL: baseUrlOpenAI,
106
132
  }
107
133
 
108
- const written = writeEnvToShell(envVars)
134
+ let written
135
+ if (process.platform === 'win32') {
136
+ // Windows: 用 PowerShell 直接写用户级环境变量
137
+ written = []
138
+ for (const [k, v] of Object.entries(envVars)) {
139
+ if (winSetEnvVar(k, v)) {
140
+ written.push(k)
141
+ }
142
+ }
143
+ } else {
144
+ // Mac/Linux: 写入 shell rc 文件
145
+ written = writeEnvToShell(envVars)
146
+ }
147
+
109
148
  saveState(envVars)
110
149
 
111
150
  return {
@@ -115,7 +154,11 @@ module.exports = {
115
154
  },
116
155
 
117
156
  reset() {
118
- removeEnvFromShell(MANAGED_KEYS)
157
+ if (process.platform === 'win32') {
158
+ for (const k of MANAGED_KEYS) winRemoveEnvVar(k)
159
+ } else {
160
+ removeEnvFromShell(MANAGED_KEYS)
161
+ }
119
162
  clearState()
120
163
  },
121
164
 
@@ -128,7 +171,7 @@ module.exports = {
128
171
  const result = {}
129
172
  for (const key of MANAGED_KEYS) {
130
173
  if (process.platform === 'win32') {
131
- result[key] = winRegQuery(key) || null
174
+ result[key] = winGetEnvVar(key) || null
132
175
  } else {
133
176
  result[key] = process.env[key] || null
134
177
  }