@simonyea/holysheep-cli 2.1.38 → 2.1.41

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.
Files changed (45) hide show
  1. package/dist/configure-worker.js +4491 -0
  2. package/dist/index.js +9591 -0
  3. package/dist/process-proxy-inject.js +117 -0
  4. package/package.json +19 -6
  5. package/.gitea/workflows/sanity.yml +0 -125
  6. package/scripts/check-tarball-size.js +0 -44
  7. package/src/commands/balance.js +0 -57
  8. package/src/commands/claude-proxy.js +0 -248
  9. package/src/commands/claude.js +0 -135
  10. package/src/commands/doctor.js +0 -282
  11. package/src/commands/login.js +0 -211
  12. package/src/commands/openclaw.js +0 -258
  13. package/src/commands/reset.js +0 -53
  14. package/src/commands/setup.js +0 -493
  15. package/src/commands/upgrade.js +0 -168
  16. package/src/commands/webui.js +0 -622
  17. package/src/index.js +0 -226
  18. package/src/tools/aider.js +0 -78
  19. package/src/tools/antigravity.js +0 -42
  20. package/src/tools/claude-code.js +0 -228
  21. package/src/tools/claude-process-proxy.js +0 -1030
  22. package/src/tools/codex.js +0 -254
  23. package/src/tools/continue.js +0 -146
  24. package/src/tools/cursor.js +0 -71
  25. package/src/tools/droid.js +0 -281
  26. package/src/tools/env-config.js +0 -185
  27. package/src/tools/gemini-cli.js +0 -82
  28. package/src/tools/hermes.js +0 -354
  29. package/src/tools/index.js +0 -13
  30. package/src/tools/openclaw-bridge.js +0 -987
  31. package/src/tools/openclaw.js +0 -925
  32. package/src/tools/opencode.js +0 -227
  33. package/src/tools/process-proxy-inject.js +0 -142
  34. package/src/utils/config.js +0 -54
  35. package/src/utils/shell.js +0 -342
  36. package/src/utils/which.js +0 -63
  37. package/src/webui/aionui-runtime-fetcher.js +0 -429
  38. package/src/webui/aionui-runtime.js +0 -139
  39. package/src/webui/aionui-wrapper.js +0 -734
  40. package/src/webui/configure-worker.js +0 -67
  41. package/src/webui/server.js +0 -1566
  42. package/src/webui/workspace-runtime.js +0 -288
  43. package/src/webui/workspace-store.js +0 -325
  44. /package/{src/webui → dist}/index.html +0 -0
  45. /package/{src/tools → dist}/pty-hermes-wrapper.py +0 -0
@@ -1,342 +0,0 @@
1
- /**
2
- * Shell RC 文件管理 — 写入/清理环境变量
3
- */
4
- const fs = require('fs')
5
- const path = require('path')
6
- const os = require('os')
7
- const { execSync } = require('child_process')
8
- const pkg = require('../../package.json')
9
-
10
- const MARKER_START = '# >>> holysheep-cli managed >>>'
11
- const MARKER_END = '# <<< holysheep-cli managed <<<'
12
-
13
- function getShellRcFiles() {
14
- const home = os.homedir()
15
-
16
- // Windows:不写 shell rc,改用 setx 写系统环境变量
17
- if (process.platform === 'win32') return []
18
-
19
- const shell = process.env.SHELL || ''
20
- const candidates = []
21
-
22
- if (shell.includes('zsh')) candidates.push(path.join(home, '.zshrc'))
23
- if (shell.includes('bash')) candidates.push(path.join(home, '.bashrc'), path.join(home, '.bash_profile'))
24
- if (shell.includes('fish')) candidates.push(path.join(home, '.config', 'fish', 'config.fish'))
25
-
26
- // 默认兜底
27
- if (candidates.length === 0) {
28
- const zshrc = path.join(home, '.zshrc')
29
- const bashrc = path.join(home, '.bashrc')
30
- if (fs.existsSync(zshrc)) candidates.push(zshrc)
31
- if (fs.existsSync(bashrc)) candidates.push(bashrc)
32
- if (candidates.length === 0) candidates.push(zshrc)
33
- }
34
-
35
- return candidates
36
- }
37
-
38
- function removeHsBlock(content) {
39
- const re = new RegExp(
40
- `\\n?${escapeRegex(MARKER_START)}[\\s\\S]*?${escapeRegex(MARKER_END)}\\n?`,
41
- 'g'
42
- )
43
- return content.replace(re, '')
44
- }
45
-
46
- /**
47
- * 移除 rc 文件里用户手动写的同名 export/set -gx 行
48
- * 防止旧值在 holysheep-cli managed 块之后覆盖新值
49
- */
50
- function removeStaleExports(content, keys, isFish = false) {
51
- let result = content
52
- for (const key of keys) {
53
- if (isFish) {
54
- // fish: set -gx KEY "..." 或 set -gx KEY ...
55
- result = result.replace(new RegExp(`\\n?set\\s+-gx\\s+${escapeRegex(key)}\\s+[^\\n]*\\n?`, 'g'), '\n')
56
- } else {
57
- // bash/zsh: export KEY="..." 或 export KEY=...
58
- result = result.replace(new RegExp(`\\n?export\\s+${escapeRegex(key)}=[^\\n]*\\n?`, 'g'), '\n')
59
- }
60
- }
61
- // 清理多余空行
62
- return result.replace(/\n{3,}/g, '\n\n')
63
- }
64
-
65
- function buildEnvBlock(envVars, isFish = false) {
66
- const lines = [MARKER_START]
67
- for (const [k, v] of Object.entries(envVars)) {
68
- // fish shell 用 set -gx,其他 shell 用 export
69
- lines.push(isFish ? `set -gx ${k} "${v}"` : `export ${k}="${v}"`)
70
- }
71
- lines.push(MARKER_END)
72
- return '\n' + lines.join('\n') + '\n'
73
- }
74
-
75
- function ensureWindowsUserPathHasNpmBin() {
76
- if (process.platform !== 'win32') return []
77
-
78
- const appData = process.env.APPDATA
79
- if (!appData) return []
80
-
81
- const npmBin = path.join(appData, 'npm')
82
- let currentPath = ''
83
- try {
84
- currentPath = execSync(
85
- 'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "[Environment]::GetEnvironmentVariable(\'Path\', \'User\')"',
86
- { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
87
- ).trim()
88
- } catch {
89
- currentPath = process.env.PATH || ''
90
- }
91
-
92
- const parts = currentPath
93
- .split(';')
94
- .map((item) => item.trim())
95
- .filter(Boolean)
96
-
97
- const hasNpmBin = parts.some((item) => item.toLowerCase() === npmBin.toLowerCase())
98
- if (hasNpmBin) return []
99
-
100
- const nextPath = [...parts, npmBin].join(';')
101
- try {
102
- const escapedPath = nextPath.replace(/'/g, "''")
103
- execSync(
104
- `powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "[Environment]::SetEnvironmentVariable('Path', '${escapedPath}', 'User')"`,
105
- { stdio: 'ignore' }
106
- )
107
- return ['[用户 PATH] %APPDATA%\\npm']
108
- } catch {
109
- try {
110
- const chalk = require('chalk')
111
- console.warn(chalk.yellow(
112
- ` ⚠️ 无法自动更新 PATH,请手动将以下路径加入系统环境变量 PATH:\n ${npmBin}`
113
- ))
114
- } catch {}
115
- return []
116
- }
117
- }
118
-
119
- /**
120
- * [HolySheep fork v2.1.36 / hs25] Same mechanism as
121
- * `ensureWindowsUserPathHasNpmBin`, but targets `%USERPROFILE%\.local\bin`.
122
- *
123
- * Background: Claude Code's official Windows installer (irm
124
- * https://claude.ai/install.ps1 | iex) drops `claude.exe` under
125
- * `C:\Users\<user>\.local\bin` and prints a warning that this directory
126
- * is NOT on PATH. Our CLI Manager page then calls `commandExists('claude')`
127
- * which runs `where claude` — finds nothing — and reports 未安装, even
128
- * though the install succeeded.
129
- *
130
- * This helper:
131
- * 1. Persists `.local\bin` into the USER-level Path (so new terminals
132
- * see it too).
133
- * 2. Appends it to `process.env.PATH` of the current process, so that
134
- * the very next `commandExists('claude')` call in the same Node
135
- * instance resolves correctly — no restart required.
136
- *
137
- * Returns a list of human-readable lines describing what was touched.
138
- * No-op on non-Windows (returns []).
139
- */
140
- function ensureWindowsUserPathHasLocalBin() {
141
- if (process.platform !== 'win32') return []
142
-
143
- const userProfile = process.env.USERPROFILE || os.homedir()
144
- if (!userProfile) return []
145
-
146
- const localBin = path.join(userProfile, '.local', 'bin')
147
-
148
- let currentPath = ''
149
- try {
150
- currentPath = execSync(
151
- 'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "[Environment]::GetEnvironmentVariable(\'Path\', \'User\')"',
152
- { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
153
- ).trim()
154
- } catch {
155
- currentPath = process.env.PATH || ''
156
- }
157
-
158
- const parts = currentPath
159
- .split(';')
160
- .map((item) => item.trim())
161
- .filter(Boolean)
162
-
163
- const hasLocalBin = parts.some((item) => item.toLowerCase() === localBin.toLowerCase())
164
-
165
- // Always also hot-patch the in-process PATH so the immediate follow-up
166
- // `commandExists('claude')` check sees the new directory. This covers
167
- // the (common) case where the persisted user PATH already has it but
168
- // our own process was spawned before the PowerShell installer ran.
169
- const procParts = (process.env.PATH || '').split(';').map((p) => p.trim()).filter(Boolean)
170
- const inProcessHasIt = procParts.some((item) => item.toLowerCase() === localBin.toLowerCase())
171
- if (!inProcessHasIt) {
172
- process.env.PATH = [...procParts, localBin].join(';')
173
- }
174
-
175
- if (hasLocalBin) return inProcessHasIt ? [] : ['[当前进程 PATH] %USERPROFILE%\\.local\\bin']
176
-
177
- const nextPath = [...parts, localBin].join(';')
178
- try {
179
- const escapedPath = nextPath.replace(/'/g, "''")
180
- execSync(
181
- `powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "[Environment]::SetEnvironmentVariable('Path', '${escapedPath}', 'User')"`,
182
- { stdio: 'ignore' }
183
- )
184
- return ['[用户 PATH] %USERPROFILE%\\.local\\bin']
185
- } catch {
186
- try {
187
- const chalk = require('chalk')
188
- console.warn(chalk.yellow(
189
- ` ⚠️ 无法自动更新 PATH,请手动将以下路径加入系统环境变量 PATH:\n ${localBin}`
190
- ))
191
- } catch {}
192
- return []
193
- }
194
- }
195
-
196
- function installWindowsCliShims() {
197
- if (process.platform !== 'win32') return []
198
-
199
- const appData = process.env.APPDATA
200
- if (!appData) return []
201
-
202
- const npmBin = path.join(appData, 'npm')
203
- fs.mkdirSync(npmBin, { recursive: true })
204
-
205
- // 如果 hs.cmd 已存在(npm install -g 生成的),不覆盖
206
- if (fs.existsSync(path.join(npmBin, 'hs.cmd'))) return []
207
-
208
- const cliSpec = `@simonyea/holysheep-cli@${pkg.version}`
209
- // 用 %APPDATA% 展开路径(比 %~dp0 在 cmd.exe 里更可靠)
210
- const cmdContent = [
211
- '@echo off',
212
- 'setlocal',
213
- 'if exist "%APPDATA%\\npm\\node_modules\\@simonyea\\holysheep-cli\\bin\\hs.js" (',
214
- ' node "%APPDATA%\\npm\\node_modules\\@simonyea\\holysheep-cli\\bin\\hs.js" %*',
215
- ') else if exist "%~dp0npx.cmd" (',
216
- ` call "%~dp0npx.cmd" ${cliSpec} %*`,
217
- ') else (',
218
- ` call npx ${cliSpec} %*`,
219
- ')',
220
- ''
221
- ].join('\r\n')
222
-
223
- const ps1Content = [
224
- '$localPkg = "$env:APPDATA\\npm\\node_modules\\@simonyea\\holysheep-cli\\bin\\hs.js"',
225
- 'if (Test-Path $localPkg) {',
226
- ' & node $localPkg @args',
227
- '} elseif (Test-Path (Join-Path $PSScriptRoot "npx.cmd")) {',
228
- ` & (Join-Path $PSScriptRoot "npx.cmd") "${cliSpec}" @args`,
229
- '} else {',
230
- ` & npx "${cliSpec}" @args`,
231
- '}',
232
- ''
233
- ].join('\r\n')
234
-
235
- const written = []
236
- for (const name of ['hs', 'holysheep']) {
237
- fs.writeFileSync(path.join(npmBin, `${name}.cmd`), cmdContent, 'utf8')
238
- fs.writeFileSync(path.join(npmBin, `${name}.ps1`), ps1Content, 'utf8')
239
- written.push(`[启动器] %APPDATA%\\npm\\${name}.cmd`)
240
- }
241
-
242
- return written
243
- }
244
-
245
- function writeEnvToShell(envVars) {
246
- // Windows: 用 setx 写入用户级环境变量(需重启终端生效)
247
- if (process.platform === 'win32') {
248
- const written = []
249
- for (const [k, v] of Object.entries(envVars)) {
250
- try {
251
- execSync(`setx ${k} "${v}"`, { stdio: 'ignore' })
252
- written.push(`[系统环境变量] ${k}`)
253
- } catch {}
254
- }
255
- written.push(...installWindowsCliShims())
256
- written.push(...ensureWindowsUserPathHasNpmBin())
257
- if (written.length > 0) {
258
- const chalk = require('chalk')
259
- console.log(chalk.yellow('\n ⚠️ Windows 环境变量已写入,需要重启终端后生效'))
260
- }
261
- return written
262
- }
263
-
264
- const files = getShellRcFiles()
265
- const written = []
266
-
267
- for (const file of files) {
268
- let content = ''
269
- try { content = fs.readFileSync(file, 'utf8') } catch {}
270
- const isFish = file.endsWith('config.fish')
271
- // 1. 清理旧的 holysheep managed 块
272
- content = removeHsBlock(content)
273
- // 2. 清理用户手动写的同名 export(防止旧值覆盖新值)
274
- content = removeStaleExports(content, Object.keys(envVars), isFish)
275
- // 3. 追加新的 managed 块
276
- content += buildEnvBlock(envVars, isFish)
277
- fs.writeFileSync(file, content, 'utf8')
278
- written.push(file)
279
- }
280
- return written
281
- }
282
-
283
- function removeWindowsUserEnvVars(keys = []) {
284
- if (process.platform !== 'win32') return []
285
-
286
- const removed = []
287
- for (const key of keys) {
288
- try {
289
- execSync(
290
- `powershell.exe -NoProfile -Command "[Environment]::SetEnvironmentVariable('${key}', $null, 'User')"`,
291
- { stdio: 'ignore' }
292
- )
293
- delete process.env[key]
294
- removed.push(`[系统环境变量] ${key}`)
295
- } catch {}
296
- }
297
- return removed
298
- }
299
-
300
- function removeEnvFromShell(extraKeys = []) {
301
- // 默认清理的 key 列表(holysheep 相关的所有环境变量)
302
- const HS_KEYS = [
303
- 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_API_KEY', 'ANTHROPIC_BASE_URL',
304
- 'OPENAI_API_KEY', 'OPENAI_BASE_URL',
305
- 'HOLYSHEEP_API_KEY',
306
- ...extraKeys,
307
- ]
308
-
309
- // Windows:通过 PowerShell 删除用户级注册表环境变量
310
- if (process.platform === 'win32') {
311
- return removeWindowsUserEnvVars(HS_KEYS)
312
- }
313
-
314
- const files = getShellRcFiles()
315
- const cleaned = []
316
- for (const file of files) {
317
- if (!fs.existsSync(file)) continue
318
- const isFish = file.endsWith('config.fish')
319
- let content = fs.readFileSync(file, 'utf8')
320
- let updated = removeHsBlock(content)
321
- updated = removeStaleExports(updated, HS_KEYS, isFish)
322
- if (updated !== content) {
323
- fs.writeFileSync(file, updated, 'utf8')
324
- cleaned.push(file)
325
- }
326
- }
327
- return cleaned
328
- }
329
-
330
- function escapeRegex(s) {
331
- return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
332
- }
333
-
334
- module.exports = {
335
- getShellRcFiles,
336
- writeEnvToShell,
337
- removeEnvFromShell,
338
- ensureWindowsUserPathHasNpmBin,
339
- ensureWindowsUserPathHasLocalBin,
340
- installWindowsCliShims,
341
- removeWindowsUserEnvVars
342
- }
@@ -1,63 +0,0 @@
1
- /**
2
- * 跨平台检测命令是否存在
3
- * Windows 用 where,Unix 用 which,兜底用 --version
4
- */
5
- const { exec, execSync } = require('child_process')
6
-
7
- function canRun(command, options = {}) {
8
- try {
9
- execSync(command, { stdio: 'ignore', ...options })
10
- return true
11
- } catch {
12
- return false
13
- }
14
- }
15
-
16
- function commandExists(cmd) {
17
- if (process.platform === 'win32') {
18
- const variants = [cmd, `${cmd}.cmd`, `${cmd}.exe`, `${cmd}.bat`]
19
- for (const variant of variants) {
20
- if (canRun(`where ${variant}`)) return true
21
- }
22
-
23
- // Windows 上很多 npm 全局命令实际是 .cmd 包装器,需要交给 cmd.exe 执行。
24
- for (const variant of variants) {
25
- if (canRun(`cmd /d /s /c "${variant} --version"`, { timeout: 3000 })) return true
26
- }
27
-
28
- return false
29
- }
30
-
31
- if (canRun(`which ${cmd}`)) return true
32
-
33
- // 兜底:直接跑 --version
34
- return canRun(`${cmd} --version`, { timeout: 3000 })
35
- }
36
-
37
- function canRunAsync(command, options = {}) {
38
- return new Promise((resolve) => {
39
- exec(command, { timeout: 3000, windowsHide: true, ...options }, (error) => {
40
- resolve(!error)
41
- })
42
- })
43
- }
44
-
45
- async function commandExistsAsync(cmd) {
46
- if (process.platform === 'win32') {
47
- const variants = [cmd, `${cmd}.cmd`, `${cmd}.exe`, `${cmd}.bat`]
48
- for (const variant of variants) {
49
- if (await canRunAsync(`where ${variant}`)) return true
50
- }
51
-
52
- for (const variant of variants) {
53
- if (await canRunAsync(`cmd /d /s /c "${variant} --version"`)) return true
54
- }
55
-
56
- return false
57
- }
58
-
59
- if (await canRunAsync(`which ${cmd}`)) return true
60
- return canRunAsync(`${cmd} --version`)
61
- }
62
-
63
- module.exports = { commandExists, commandExistsAsync }