@simonyea/holysheep-cli 1.0.3 → 1.0.4

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/tools/codex.js +61 -77
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonyea/holysheep-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "一键配置所有 AI 编程工具接入 HolySheep API — Claude Code / Codex / Gemini CLI / OpenCode / OpenClaw / Aider / Cursor",
5
5
  "keywords": [
6
6
  "claude",
@@ -1,54 +1,43 @@
1
1
  /**
2
- * OpenAI Codex CLI 适配器
3
- * 配置文件: ~/.codex/config.yaml 或 ~/.codex/config.json
4
- * 环境变量: OPENAI_API_KEY, OPENAI_BASE_URL
2
+ * Codex CLI 适配器 (@openai/codex v0.46+)
5
3
  *
6
- * Codex 支持 custom provider 配置:
7
- * providers:
8
- * - name: HolySheep
9
- * baseURL: https://api.holysheep.ai/v1
10
- * envKey: OPENAI_API_KEY
4
+ * 配置文件: ~/.codex/config.json(JSON 格式,不是 yaml)
11
5
  *
12
- * 注意: Codex 用 OpenAI 兼容格式,baseURL 需带 /v1
6
+ * 正确格式:
7
+ * {
8
+ * "model": "claude-sonnet-4-5",
9
+ * "provider": "holysheep", // 指定默认 provider
10
+ * "providers": {
11
+ * "holysheep": {
12
+ * "name": "HolySheep",
13
+ * "baseURL": "https://api.holysheep.ai/v1",
14
+ * "envKey": "OPENAI_API_KEY"
15
+ * }
16
+ * }
17
+ * }
18
+ *
19
+ * 环境变量: OPENAI_API_KEY(通过 envKey 指定)
20
+ * 注意: Codex 会优先使用账号登录,需要设置 provider 才能绕过
13
21
  */
14
- const fs = require('fs')
22
+ const fs = require('fs')
15
23
  const path = require('path')
16
- const os = require('os')
24
+ const os = require('os')
17
25
 
18
26
  const CONFIG_DIR = path.join(os.homedir(), '.codex')
19
- const CONFIG_YAML = path.join(CONFIG_DIR, 'config.yaml')
20
- const CONFIG_JSON = path.join(CONFIG_DIR, 'config.json')
27
+ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json')
21
28
 
22
29
  function readConfig() {
23
30
  try {
24
- if (fs.existsSync(CONFIG_YAML)) return { type: 'yaml', content: fs.readFileSync(CONFIG_YAML, 'utf8') }
25
- if (fs.existsSync(CONFIG_JSON)) return { type: 'json', content: fs.readFileSync(CONFIG_JSON, 'utf8') }
31
+ if (fs.existsSync(CONFIG_FILE)) {
32
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'))
33
+ }
26
34
  } catch {}
27
- return { type: 'yaml', content: '' }
35
+ return {}
28
36
  }
29
37
 
30
- function removeHolysheepProvider(yamlContent) {
31
- // 简单移除已有的 holysheep provider
32
- const lines = yamlContent.split('\n')
33
- const result = []
34
- let skip = false
35
- for (const line of lines) {
36
- if (line.includes('HolySheep') || line.includes('holysheep')) {
37
- skip = true
38
- // 也移除上一行的 `- name:` 前缀
39
- if (result.length && result[result.length - 1].trim().startsWith('- name:')) {
40
- result.pop()
41
- }
42
- continue
43
- }
44
- if (skip && (line.startsWith(' ') || line.trim() === '')) {
45
- if (line.trim() === '') skip = false
46
- continue
47
- }
48
- skip = false
49
- result.push(line)
50
- }
51
- return result.join('\n')
38
+ function writeConfig(data) {
39
+ if (!fs.existsSync(CONFIG_DIR)) fs.mkdirSync(CONFIG_DIR, { recursive: true })
40
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(data, null, 2), 'utf8')
52
41
  }
53
42
 
54
43
  module.exports = {
@@ -56,62 +45,57 @@ module.exports = {
56
45
  id: 'codex',
57
46
  checkInstalled() {
58
47
  try {
59
- require('child_process').execSync('which codex', { stdio: 'ignore' })
48
+ require('child_process').execSync('codex --version', { stdio: 'ignore' })
60
49
  return true
61
- } catch { return false }
50
+ } catch {
51
+ try {
52
+ require('child_process').execSync('npx @openai/codex --version', { stdio: 'ignore' })
53
+ return true
54
+ } catch { return false }
55
+ }
62
56
  },
63
57
  isConfigured() {
64
- const { content } = readConfig()
65
- return content.includes('holysheep') || content.includes('HolySheep')
58
+ const c = readConfig()
59
+ return c.provider === 'holysheep' &&
60
+ !!c.providers?.holysheep?.baseURL?.includes('holysheep')
66
61
  },
67
- configure(apiKey, baseUrlOpenAI) {
68
- if (!fs.existsSync(CONFIG_DIR)) fs.mkdirSync(CONFIG_DIR, { recursive: true })
62
+ configure(apiKey, _baseUrlAnthropicNoV1, baseUrlOpenAI) {
63
+ const config = readConfig()
69
64
 
70
- // 生成 YAML 格式配置(Codex 官方推荐)
71
- let content = ''
72
- if (fs.existsSync(CONFIG_YAML)) {
73
- content = fs.readFileSync(CONFIG_YAML, 'utf8')
74
- content = removeHolysheepProvider(content)
75
- }
65
+ // 设置 HolySheep 为默认 provider
66
+ config.provider = 'holysheep'
67
+ config.model = config.model || 'claude-sonnet-4-5'
76
68
 
77
- // 追加 holysheep provider + 设为默认 model provider
78
- const providerBlock = `
79
- # HolySheep API — https://shop.holysheep.ai
80
- providers:
81
- - name: HolySheep
82
- baseURL: ${baseUrlOpenAI}
83
- envKey: OPENAI_API_KEY
84
- model: claude-sonnet-4-5
85
- `
86
- // 如果已有 providers 块,改为追加到列表
87
- if (content.includes('providers:')) {
88
- content = content.replace('providers:', `providers:\n - name: HolySheep\n baseURL: ${baseUrlOpenAI}\n envKey: OPENAI_API_KEY`)
89
- } else {
90
- content += providerBlock
69
+ if (!config.providers) config.providers = {}
70
+ config.providers.holysheep = {
71
+ name: 'HolySheep',
72
+ baseURL: baseUrlOpenAI, // https://api.holysheep.ai/v1
73
+ envKey: 'OPENAI_API_KEY',
91
74
  }
92
75
 
93
- fs.writeFileSync(CONFIG_YAML, content.trim() + '\n', 'utf8')
76
+ writeConfig(config)
94
77
 
95
- // 同时写入环境变量(Codex 通过 envKey 读取)
96
78
  return {
97
- file: CONFIG_YAML,
98
- hot: false,
79
+ file: CONFIG_FILE,
80
+ hot: false,
81
+ // 需要同时设置环境变量,供 envKey 读取
99
82
  envVars: {
100
- OPENAI_API_KEY: apiKey,
101
- OPENAI_BASE_URL: baseUrlOpenAI,
83
+ OPENAI_API_KEY: apiKey,
84
+ OPENAI_BASE_URL: baseUrlOpenAI,
102
85
  },
103
86
  }
104
87
  },
105
88
  reset() {
106
- if (fs.existsSync(CONFIG_YAML)) {
107
- let content = fs.readFileSync(CONFIG_YAML, 'utf8')
108
- content = removeHolysheepProvider(content)
109
- fs.writeFileSync(CONFIG_YAML, content, 'utf8')
89
+ const config = readConfig()
90
+ if (config.provider === 'holysheep') {
91
+ delete config.provider
92
+ delete config.providers?.holysheep
110
93
  }
94
+ writeConfig(config)
111
95
  },
112
- getConfigPath() { return CONFIG_YAML },
113
- hint: '切换后需重启终端或新开 terminal',
96
+ getConfigPath() { return CONFIG_FILE },
97
+ hint: '切换后重开终端生效;用 codex --provider holysheep 指定',
114
98
  installCmd: 'npm install -g @openai/codex',
115
99
  docsUrl: 'https://github.com/openai/codex',
116
- envVarFormat: 'openai', // 告知 setup 命令写哪些 env vars
100
+ envVarFormat: 'openai',
117
101
  }