@gengjiawen/os-init 1.23.0 → 1.24.0
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/AGENTS.md +2 -2
- package/CHANGELOG.md +14 -0
- package/bin/bin.js +5 -41
- package/build/all-agents.d.ts +1 -6
- package/build/all-agents.js +4 -6
- package/build/claude-code.js +2 -1
- package/build/codex.d.ts +2 -3
- package/build/codex.js +3 -36
- package/build/index.d.ts +0 -1
- package/build/index.js +1 -4
- package/build/mihomo.js +1 -1
- package/build/opencode.js +0 -1
- package/libs/all-agents.test.ts +11 -22
- package/libs/all-agents.ts +16 -15
- package/libs/claude-code.test.ts +33 -0
- package/libs/claude-code.ts +9 -4
- package/libs/codex.test.ts +29 -108
- package/libs/codex.ts +4 -53
- package/libs/index.ts +0 -3
- package/libs/mihomo.test.ts +1 -1
- package/libs/mihomo.ts +1 -1
- package/libs/opencode.test.ts +0 -3
- package/libs/opencode.ts +0 -1
- package/package.json +1 -1
- package/build/gemini-cli.d.ts +0 -5
- package/build/gemini-cli.js +0 -52
- package/libs/gemini-cli.ts +0 -69
package/AGENTS.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Project Structure
|
|
4
4
|
|
|
5
|
-
- `bin/`: Node CLI entrypoint (`bin/bin.js`) and command definitions (e.g., `set-codex`, `set-
|
|
5
|
+
- `bin/`: Node CLI entrypoint (`bin/bin.js`) and command definitions (e.g., `set-codex`, `set-opencode`).
|
|
6
6
|
- `libs/`: TypeScript source for config writers/installers and setup utilities (main exports in `libs/index.ts`).
|
|
7
7
|
- `build/`: Compiled JS + `.d.ts` output from `tsc` (`outDir`), consumed by the CLI and published to npm.
|
|
8
8
|
- `dev-setup/`: Optional Docker-based dev environment (sshd + compose) for remote/portable workflows.
|
|
@@ -22,7 +22,7 @@ Use `pnpm` (CI uses it).
|
|
|
22
22
|
|
|
23
23
|
- Formatting: Prettier (no semicolons, single quotes). Run `pnpm format` before pushing.
|
|
24
24
|
- TypeScript: strict options are enabled; prefer explicit, typed helpers over `any`.
|
|
25
|
-
- Naming: files are kebab-case in `libs/` (e.g., `
|
|
25
|
+
- Naming: files are kebab-case in `libs/` (e.g., `opencode.ts`); exported functions are `camelCase`.
|
|
26
26
|
|
|
27
27
|
## Testing Guidelines
|
|
28
28
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.24.0](https://github.com/gengjiawen/os-init/compare/v1.23.1...v1.24.0) (2026-04-29)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add CLAUDE_CODE_EFFORT_LEVEL setting to user settings template ([a32c352](https://github.com/gengjiawen/os-init/commit/a32c3520236bb5511a33ddc586107861ea6dfabb))
|
|
9
|
+
|
|
10
|
+
## [1.23.1](https://github.com/gengjiawen/os-init/compare/v1.23.0...v1.23.1) (2026-04-24)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* allow claude postinstall with pnpm ([f494b78](https://github.com/gengjiawen/os-init/commit/f494b78134025992863a2272432d64348fd4532e))
|
|
16
|
+
|
|
3
17
|
## [1.23.0](https://github.com/gengjiawen/os-init/compare/v1.22.0...v1.23.0) (2026-04-24)
|
|
4
18
|
|
|
5
19
|
|
package/bin/bin.js
CHANGED
|
@@ -7,8 +7,6 @@ const {
|
|
|
7
7
|
installDeps,
|
|
8
8
|
writeCodexConfig,
|
|
9
9
|
installCodexDeps,
|
|
10
|
-
writeGeminiConfig,
|
|
11
|
-
installGeminiDeps,
|
|
12
10
|
writeOpencodeConfig,
|
|
13
11
|
installOpencodeDeps,
|
|
14
12
|
writeAllAgentsConfig,
|
|
@@ -65,11 +63,9 @@ program
|
|
|
65
63
|
return
|
|
66
64
|
}
|
|
67
65
|
try {
|
|
68
|
-
const { configPath, authPath
|
|
69
|
-
await writeCodexConfig(apiKey)
|
|
66
|
+
const { configPath, authPath } = writeCodexConfig(apiKey)
|
|
70
67
|
console.log(`Codex config written to: ${configPath}`)
|
|
71
68
|
console.log(`Codex auth written to: ${authPath}`)
|
|
72
|
-
console.log(`Codex model catalog written to: ${catalogPath}`)
|
|
73
69
|
await installCodexDeps()
|
|
74
70
|
} catch (err) {
|
|
75
71
|
console.error('Failed to setup Codex:', err.message)
|
|
@@ -78,30 +74,6 @@ program
|
|
|
78
74
|
console.log('Codex is ready. use `codex` in terminal to start building')
|
|
79
75
|
})
|
|
80
76
|
|
|
81
|
-
program
|
|
82
|
-
.command('set-gemini')
|
|
83
|
-
.description('setup Gemini CLI config and auth')
|
|
84
|
-
.argument('<apiKey>', 'API key to set for Gemini CLI')
|
|
85
|
-
.action(async (apiKey) => {
|
|
86
|
-
if (!apiKey || String(apiKey).trim().length === 0) {
|
|
87
|
-
console.error('Missing required argument: <apiKey>')
|
|
88
|
-
program.help({ error: true })
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
const { envPath, settingsPath } = writeGeminiConfig(apiKey)
|
|
93
|
-
console.log(`Gemini CLI env written to: ${envPath}`)
|
|
94
|
-
console.log(`Gemini CLI settings written to: ${settingsPath}`)
|
|
95
|
-
await installGeminiDeps()
|
|
96
|
-
} catch (err) {
|
|
97
|
-
console.error('Failed to setup Gemini CLI:', err.message)
|
|
98
|
-
process.exit(1)
|
|
99
|
-
}
|
|
100
|
-
console.log(
|
|
101
|
-
'Gemini CLI is ready. use `gemini` in terminal to start building'
|
|
102
|
-
)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
77
|
program
|
|
106
78
|
.command('set-opencode')
|
|
107
79
|
.description('setup OpenCode CLI config and auth')
|
|
@@ -128,10 +100,10 @@ program
|
|
|
128
100
|
program
|
|
129
101
|
.command('set-agents')
|
|
130
102
|
.description(
|
|
131
|
-
'setup Claude Code and Codex at once (use --full to include OpenCode
|
|
103
|
+
'setup Claude Code and Codex at once (use --full to include OpenCode)'
|
|
132
104
|
)
|
|
133
105
|
.argument('<apiKey>', 'API key to set for agents')
|
|
134
|
-
.option('--full', 'Also setup OpenCode
|
|
106
|
+
.option('--full', 'Also setup OpenCode')
|
|
135
107
|
.action(async (apiKey, options) => {
|
|
136
108
|
if (!apiKey || String(apiKey).trim().length === 0) {
|
|
137
109
|
console.error('Missing required argument: <apiKey>')
|
|
@@ -144,11 +116,11 @@ program
|
|
|
144
116
|
try {
|
|
145
117
|
console.log(
|
|
146
118
|
full
|
|
147
|
-
? 'Setting up Claude Code + Codex + OpenCode
|
|
119
|
+
? 'Setting up Claude Code + Codex + OpenCode...\n'
|
|
148
120
|
: 'Setting up Claude Code + Codex...\n'
|
|
149
121
|
)
|
|
150
122
|
|
|
151
|
-
const result =
|
|
123
|
+
const result = writeAllAgentsConfig(apiKey, { full })
|
|
152
124
|
|
|
153
125
|
console.log('Claude Code:')
|
|
154
126
|
console.log(` Settings written to: ${result.claude.settingsPath}`)
|
|
@@ -159,19 +131,12 @@ program
|
|
|
159
131
|
console.log('\nCodex:')
|
|
160
132
|
console.log(` Config written to: ${result.codex.configPath}`)
|
|
161
133
|
console.log(` Auth written to: ${result.codex.authPath}`)
|
|
162
|
-
console.log(` Model catalog written to: ${result.codex.catalogPath}`)
|
|
163
134
|
|
|
164
135
|
if (result.opencode) {
|
|
165
136
|
console.log('\nOpenCode:')
|
|
166
137
|
console.log(` Config written to: ${result.opencode.configPath}`)
|
|
167
138
|
}
|
|
168
139
|
|
|
169
|
-
if (result.gemini) {
|
|
170
|
-
console.log('\nGemini CLI:')
|
|
171
|
-
console.log(` Env written to: ${result.gemini.envPath}`)
|
|
172
|
-
console.log(` Settings written to: ${result.gemini.settingsPath}`)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
140
|
console.log('\nInstalling dependencies...')
|
|
176
141
|
await installAllAgentsDeps({ full })
|
|
177
142
|
} catch (err) {
|
|
@@ -184,7 +149,6 @@ program
|
|
|
184
149
|
console.log(' - Use `codex` for Codex')
|
|
185
150
|
if (full) {
|
|
186
151
|
console.log(' - Use `opencode` for OpenCode')
|
|
187
|
-
console.log(' - Use `gemini` for Gemini CLI')
|
|
188
152
|
}
|
|
189
153
|
})
|
|
190
154
|
|
package/build/all-agents.d.ts
CHANGED
|
@@ -9,15 +9,10 @@ export interface AllAgentsResult {
|
|
|
9
9
|
codex: {
|
|
10
10
|
configPath: string;
|
|
11
11
|
authPath: string;
|
|
12
|
-
catalogPath: string;
|
|
13
12
|
};
|
|
14
13
|
opencode?: {
|
|
15
14
|
configPath: string;
|
|
16
15
|
};
|
|
17
|
-
gemini?: {
|
|
18
|
-
envPath: string;
|
|
19
|
-
settingsPath: string;
|
|
20
|
-
};
|
|
21
16
|
}
|
|
22
|
-
export declare function writeAllAgentsConfig(apiKey: string, options?: AllAgentsOptions):
|
|
17
|
+
export declare function writeAllAgentsConfig(apiKey: string, options?: AllAgentsOptions): AllAgentsResult;
|
|
23
18
|
export declare function installAllAgentsDeps(options?: AllAgentsOptions): Promise<void>;
|
package/build/all-agents.js
CHANGED
|
@@ -4,32 +4,30 @@ exports.writeAllAgentsConfig = writeAllAgentsConfig;
|
|
|
4
4
|
exports.installAllAgentsDeps = installAllAgentsDeps;
|
|
5
5
|
const claude_code_1 = require("./claude-code");
|
|
6
6
|
const codex_1 = require("./codex");
|
|
7
|
-
const gemini_cli_1 = require("./gemini-cli");
|
|
8
7
|
const opencode_1 = require("./opencode");
|
|
9
8
|
const execa_1 = require("execa");
|
|
10
9
|
const utils_1 = require("./utils");
|
|
11
|
-
|
|
10
|
+
function writeAllAgentsConfig(apiKey, options = {}) {
|
|
12
11
|
const claudeResult = (0, claude_code_1.writeClaudeConfig)(apiKey);
|
|
13
|
-
const codexResult =
|
|
12
|
+
const codexResult = (0, codex_1.writeCodexConfig)(apiKey);
|
|
14
13
|
const result = {
|
|
15
14
|
claude: claudeResult,
|
|
16
15
|
codex: codexResult,
|
|
17
16
|
};
|
|
18
17
|
if (options.full) {
|
|
19
18
|
result.opencode = (0, opencode_1.writeOpencodeConfig)(apiKey);
|
|
20
|
-
result.gemini = (0, gemini_cli_1.writeGeminiConfig)(apiKey);
|
|
21
19
|
}
|
|
22
20
|
return result;
|
|
23
21
|
}
|
|
24
22
|
async function installAllAgentsDeps(options = {}) {
|
|
25
23
|
const packages = ['@anthropic-ai/claude-code', '@openai/codex'];
|
|
26
24
|
if (options.full) {
|
|
27
|
-
packages.push('opencode-ai'
|
|
25
|
+
packages.push('opencode-ai');
|
|
28
26
|
}
|
|
29
27
|
const usePnpm = await (0, utils_1.commandExists)('pnpm');
|
|
30
28
|
if (usePnpm) {
|
|
31
29
|
console.log('pnpm detected. Installing agent dependencies with pnpm...');
|
|
32
|
-
await (0, execa_1.execa)('pnpm', ['add', '-g', ...packages], {
|
|
30
|
+
await (0, execa_1.execa)('pnpm', ['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages], {
|
|
33
31
|
stdio: 'inherit',
|
|
34
32
|
env: utils_1.PNPM_INSTALL_ENV,
|
|
35
33
|
});
|
package/build/claude-code.js
CHANGED
|
@@ -28,6 +28,7 @@ function getVSCodeUserSettingsPath() {
|
|
|
28
28
|
const CLAUDE_SETTINGS_TEMPLATE = `{
|
|
29
29
|
"env": {
|
|
30
30
|
"DISABLE_TELEMETRY": "1",
|
|
31
|
+
"CLAUDE_CODE_EFFORT_LEVEL": "max",
|
|
31
32
|
"OTEL_METRICS_EXPORTER": "otlp",
|
|
32
33
|
"ANTHROPIC_API_KEY": "API_KEY_PLACEHOLDER",
|
|
33
34
|
"ANTHROPIC_BASE_URL": "${CLAUDE_BASE_URL}",
|
|
@@ -103,7 +104,7 @@ async function installDeps() {
|
|
|
103
104
|
const usePnpm = await (0, utils_1.commandExists)('pnpm');
|
|
104
105
|
if (usePnpm) {
|
|
105
106
|
console.log('pnpm detected. Installing dependencies with pnpm...');
|
|
106
|
-
await (0, execa_1.execa)('pnpm', ['add', '-g', ...packages], {
|
|
107
|
+
await (0, execa_1.execa)('pnpm', ['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages], {
|
|
107
108
|
stdio: 'inherit',
|
|
108
109
|
env: utils_1.PNPM_INSTALL_ENV,
|
|
109
110
|
});
|
package/build/codex.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export declare function writeCodexConfig(apiKey: string):
|
|
1
|
+
export declare function writeCodexConfig(apiKey: string): {
|
|
2
2
|
configPath: string;
|
|
3
3
|
authPath: string;
|
|
4
|
-
|
|
5
|
-
}>;
|
|
4
|
+
};
|
|
6
5
|
export declare function installCodexDeps(): Promise<void>;
|
package/build/codex.js
CHANGED
|
@@ -9,19 +9,9 @@ const TOML = require("@iarna/toml");
|
|
|
9
9
|
const execa_1 = require("execa");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
const CODEX_BASE_URL = 'https://ai.gengjiawen.com/api/openai';
|
|
12
|
-
const CODEX_MODEL_CATALOG_CONFIG_PATH = '~/.codex/remote-model-catalog.json';
|
|
13
|
-
const CODEX_MODEL_CATALOG_FILENAME = 'remote-model-catalog.json';
|
|
14
12
|
function getCodexConfigDir() {
|
|
15
13
|
return path.join(os.homedir(), '.codex');
|
|
16
14
|
}
|
|
17
|
-
function getCodexModelCatalogPath() {
|
|
18
|
-
return path.join(getCodexConfigDir(), CODEX_MODEL_CATALOG_FILENAME);
|
|
19
|
-
}
|
|
20
|
-
function getCodexModelCatalogConfigPath() {
|
|
21
|
-
return os.platform() === 'win32'
|
|
22
|
-
? getCodexModelCatalogPath()
|
|
23
|
-
: CODEX_MODEL_CATALOG_CONFIG_PATH;
|
|
24
|
-
}
|
|
25
15
|
function getCodexConfigTomlTemplate() {
|
|
26
16
|
return `model_provider = "jw"
|
|
27
17
|
model = "gpt-5.5"
|
|
@@ -30,7 +20,6 @@ plan_mode_reasoning_effort = "xhigh"
|
|
|
30
20
|
model_auto_compact_token_limit = 131072
|
|
31
21
|
disable_response_storage = true
|
|
32
22
|
preferred_auth_method = "apikey"
|
|
33
|
-
model_catalog_json = ${JSON.stringify(getCodexModelCatalogConfigPath())}
|
|
34
23
|
|
|
35
24
|
[model_providers.jw]
|
|
36
25
|
name = "jw"
|
|
@@ -59,34 +48,12 @@ function getMergedCodexConfig(existingContent) {
|
|
|
59
48
|
const existingConfig = TOML.parse(existingContent);
|
|
60
49
|
const templateConfig = TOML.parse(getCodexConfigTomlTemplate());
|
|
61
50
|
delete existingConfig.service_tier;
|
|
51
|
+
delete existingConfig.model_catalog_json;
|
|
62
52
|
return TOML.stringify(mergeTomlTables(existingConfig, templateConfig));
|
|
63
53
|
}
|
|
64
|
-
|
|
65
|
-
if (typeof fetch !== 'function') {
|
|
66
|
-
throw new Error('Global fetch API is unavailable in this Node.js runtime.');
|
|
67
|
-
}
|
|
68
|
-
const response = await fetch(`${CODEX_BASE_URL}/models`, {
|
|
69
|
-
headers: {
|
|
70
|
-
Accept: 'application/json',
|
|
71
|
-
Authorization: `Bearer ${apiKey}`,
|
|
72
|
-
'User-Agent': '@gengjiawen/os-init',
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
if (!response.ok) {
|
|
76
|
-
throw new Error(`Failed to refresh Codex model catalog: ${response.status} ${response.statusText}`);
|
|
77
|
-
}
|
|
78
|
-
const catalog = (await response.json());
|
|
79
|
-
if (!Array.isArray(catalog?.models) || catalog.models.length === 0) {
|
|
80
|
-
throw new Error('Failed to refresh Codex model catalog: response does not contain any models.');
|
|
81
|
-
}
|
|
82
|
-
const catalogPath = getCodexModelCatalogPath();
|
|
83
|
-
fs.writeFileSync(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`);
|
|
84
|
-
return catalogPath;
|
|
85
|
-
}
|
|
86
|
-
async function writeCodexConfig(apiKey) {
|
|
54
|
+
function writeCodexConfig(apiKey) {
|
|
87
55
|
const configDir = getCodexConfigDir();
|
|
88
56
|
(0, utils_1.ensureDir)(configDir);
|
|
89
|
-
const catalogPath = await refreshCodexModelCatalog(apiKey);
|
|
90
57
|
const configPath = path.join(configDir, 'config.toml');
|
|
91
58
|
const configContent = fs.existsSync(configPath)
|
|
92
59
|
? getMergedCodexConfig(fs.readFileSync(configPath, 'utf8'))
|
|
@@ -95,7 +62,7 @@ async function writeCodexConfig(apiKey) {
|
|
|
95
62
|
const authPath = path.join(configDir, 'auth.json');
|
|
96
63
|
const authContent = JSON.stringify({ OPENAI_API_KEY: apiKey }, null, 2);
|
|
97
64
|
fs.writeFileSync(authPath, authContent);
|
|
98
|
-
return { configPath, authPath
|
|
65
|
+
return { configPath, authPath };
|
|
99
66
|
}
|
|
100
67
|
async function installCodexDeps() {
|
|
101
68
|
const packages = ['@openai/codex'];
|
package/build/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export declare function writeRaycastConfig(apiKey: string): {
|
|
|
3
3
|
};
|
|
4
4
|
export { writeClaudeConfig, installDeps } from './claude-code';
|
|
5
5
|
export { writeCodexConfig, installCodexDeps } from './codex';
|
|
6
|
-
export { writeGeminiConfig, installGeminiDeps } from './gemini-cli';
|
|
7
6
|
export { writeOpencodeConfig, installOpencodeDeps } from './opencode';
|
|
8
7
|
export { writeAllAgentsConfig, installAllAgentsDeps } from './all-agents';
|
|
9
8
|
export { setupDevEnvironment } from './dev-setup';
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.downloadMihomoBinary = exports.writeMihomoConfig = exports.setupAndroidEnvironment = exports.setupDevEnvironment = exports.installAllAgentsDeps = exports.writeAllAgentsConfig = exports.installOpencodeDeps = exports.writeOpencodeConfig = exports.
|
|
3
|
+
exports.downloadMihomoBinary = exports.writeMihomoConfig = exports.setupAndroidEnvironment = exports.setupDevEnvironment = exports.installAllAgentsDeps = exports.writeAllAgentsConfig = exports.installOpencodeDeps = exports.writeOpencodeConfig = exports.installCodexDeps = exports.writeCodexConfig = exports.installDeps = exports.writeClaudeConfig = void 0;
|
|
4
4
|
exports.writeRaycastConfig = writeRaycastConfig;
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const path = require("path");
|
|
@@ -44,9 +44,6 @@ Object.defineProperty(exports, "installDeps", { enumerable: true, get: function
|
|
|
44
44
|
var codex_1 = require("./codex");
|
|
45
45
|
Object.defineProperty(exports, "writeCodexConfig", { enumerable: true, get: function () { return codex_1.writeCodexConfig; } });
|
|
46
46
|
Object.defineProperty(exports, "installCodexDeps", { enumerable: true, get: function () { return codex_1.installCodexDeps; } });
|
|
47
|
-
var gemini_cli_1 = require("./gemini-cli");
|
|
48
|
-
Object.defineProperty(exports, "writeGeminiConfig", { enumerable: true, get: function () { return gemini_cli_1.writeGeminiConfig; } });
|
|
49
|
-
Object.defineProperty(exports, "installGeminiDeps", { enumerable: true, get: function () { return gemini_cli_1.installGeminiDeps; } });
|
|
50
47
|
var opencode_1 = require("./opencode");
|
|
51
48
|
Object.defineProperty(exports, "writeOpencodeConfig", { enumerable: true, get: function () { return opencode_1.writeOpencodeConfig; } });
|
|
52
49
|
Object.defineProperty(exports, "installOpencodeDeps", { enumerable: true, get: function () { return opencode_1.installOpencodeDeps; } });
|
package/build/mihomo.js
CHANGED
|
@@ -50,7 +50,7 @@ rules:
|
|
|
50
50
|
- IP-CIDR6,fe80::/10,DIRECT
|
|
51
51
|
- DOMAIN-SUFFIX,local,DIRECT
|
|
52
52
|
- DOMAIN-SUFFIX,cn,DIRECT
|
|
53
|
-
- GEOIP,CN,DIRECT
|
|
53
|
+
# - GEOIP,CN,DIRECT
|
|
54
54
|
- MATCH,PROXY
|
|
55
55
|
`;
|
|
56
56
|
const MIHOMO_LATEST_RELEASE_API_URL = 'https://api.github.com/repos/MetaCubeX/mihomo/releases/latest';
|
package/build/opencode.js
CHANGED
package/libs/all-agents.test.ts
CHANGED
|
@@ -13,7 +13,6 @@ describe('writeAllAgentsConfig', () => {
|
|
|
13
13
|
let tempHome: string
|
|
14
14
|
let homedirSpy: jest.SpiedFunction<typeof os.homedir>
|
|
15
15
|
let originalAppData: string | undefined
|
|
16
|
-
let originalFetch: typeof global.fetch | undefined
|
|
17
16
|
const execaMock = jest.mocked(execa)
|
|
18
17
|
|
|
19
18
|
beforeEach(() => {
|
|
@@ -21,12 +20,7 @@ describe('writeAllAgentsConfig', () => {
|
|
|
21
20
|
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-all-agents-'))
|
|
22
21
|
homedirSpy = jest.spyOn(os, 'homedir').mockReturnValue(tempHome)
|
|
23
22
|
originalAppData = process.env.APPDATA
|
|
24
|
-
originalFetch = global.fetch
|
|
25
23
|
process.env.APPDATA = path.join(tempHome, 'AppData', 'Roaming')
|
|
26
|
-
global.fetch = jest.fn().mockResolvedValue({
|
|
27
|
-
ok: true,
|
|
28
|
-
json: async () => ({ models: [{ id: 'gpt-5.5' }] }),
|
|
29
|
-
}) as unknown as typeof global.fetch
|
|
30
24
|
})
|
|
31
25
|
|
|
32
26
|
afterEach(() => {
|
|
@@ -36,33 +30,23 @@ describe('writeAllAgentsConfig', () => {
|
|
|
36
30
|
} else {
|
|
37
31
|
process.env.APPDATA = originalAppData
|
|
38
32
|
}
|
|
39
|
-
if (originalFetch === undefined) {
|
|
40
|
-
global.fetch = undefined as unknown as typeof global.fetch
|
|
41
|
-
} else {
|
|
42
|
-
global.fetch = originalFetch
|
|
43
|
-
}
|
|
44
33
|
fs.rmSync(tempHome, { recursive: true, force: true })
|
|
45
34
|
})
|
|
46
35
|
|
|
47
|
-
test('writes Claude and Codex config by default',
|
|
48
|
-
const result =
|
|
36
|
+
test('writes Claude and Codex config by default', () => {
|
|
37
|
+
const result = writeAllAgentsConfig('test-api-key')
|
|
49
38
|
|
|
50
39
|
expect(fs.existsSync(result.claude.settingsPath)).toBe(true)
|
|
51
40
|
expect(fs.existsSync(result.codex.configPath)).toBe(true)
|
|
52
41
|
expect(fs.existsSync(result.codex.authPath)).toBe(true)
|
|
53
|
-
expect(fs.existsSync(result.codex.catalogPath)).toBe(true)
|
|
54
42
|
expect(result.opencode).toBeUndefined()
|
|
55
|
-
expect(result.gemini).toBeUndefined()
|
|
56
43
|
})
|
|
57
44
|
|
|
58
|
-
test('includes OpenCode
|
|
59
|
-
const result =
|
|
45
|
+
test('includes OpenCode config when full option is enabled', () => {
|
|
46
|
+
const result = writeAllAgentsConfig('test-api-key', { full: true })
|
|
60
47
|
|
|
61
48
|
expect(result.opencode).toBeDefined()
|
|
62
49
|
expect(fs.existsSync(result.opencode!.configPath)).toBe(true)
|
|
63
|
-
expect(result.gemini).toBeDefined()
|
|
64
|
-
expect(fs.existsSync(result.gemini!.envPath)).toBe(true)
|
|
65
|
-
expect(fs.existsSync(result.gemini!.settingsPath)).toBe(true)
|
|
66
50
|
})
|
|
67
51
|
|
|
68
52
|
test('installs Claude and Codex in one pnpm command', async () => {
|
|
@@ -79,7 +63,13 @@ describe('writeAllAgentsConfig', () => {
|
|
|
79
63
|
expect(execaMock).toHaveBeenNthCalledWith(
|
|
80
64
|
2,
|
|
81
65
|
'pnpm',
|
|
82
|
-
[
|
|
66
|
+
[
|
|
67
|
+
'--allow-build=@anthropic-ai/claude-code',
|
|
68
|
+
'add',
|
|
69
|
+
'-g',
|
|
70
|
+
'@anthropic-ai/claude-code',
|
|
71
|
+
'@openai/codex',
|
|
72
|
+
],
|
|
83
73
|
{
|
|
84
74
|
stdio: 'inherit',
|
|
85
75
|
env: {
|
|
@@ -110,7 +100,6 @@ describe('writeAllAgentsConfig', () => {
|
|
|
110
100
|
'@anthropic-ai/claude-code',
|
|
111
101
|
'@openai/codex',
|
|
112
102
|
'opencode-ai',
|
|
113
|
-
'@google/gemini-cli',
|
|
114
103
|
],
|
|
115
104
|
{ stdio: 'inherit' }
|
|
116
105
|
)
|
package/libs/all-agents.ts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { writeClaudeConfig } from './claude-code'
|
|
2
2
|
import { writeCodexConfig } from './codex'
|
|
3
|
-
import { writeGeminiConfig } from './gemini-cli'
|
|
4
3
|
import { writeOpencodeConfig } from './opencode'
|
|
5
4
|
import { execa } from 'execa'
|
|
6
5
|
import { commandExists, PNPM_INSTALL_ENV } from './utils'
|
|
7
6
|
|
|
8
7
|
export interface AllAgentsOptions {
|
|
9
|
-
/** When true, also include OpenCode
|
|
8
|
+
/** When true, also include OpenCode in the combined setup. */
|
|
10
9
|
full?: boolean
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export interface AllAgentsResult {
|
|
14
13
|
claude: { settingsPath: string; vscodeSettingsPath: string }
|
|
15
|
-
codex: { configPath: string; authPath: string
|
|
14
|
+
codex: { configPath: string; authPath: string }
|
|
16
15
|
opencode?: { configPath: string }
|
|
17
|
-
gemini?: { envPath: string; settingsPath: string }
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
/** Write configuration for the combined setup (Claude Code + Codex; optional OpenCode
|
|
21
|
-
export
|
|
18
|
+
/** Write configuration for the combined setup (Claude Code + Codex; optional OpenCode with --full). */
|
|
19
|
+
export function writeAllAgentsConfig(
|
|
22
20
|
apiKey: string,
|
|
23
21
|
options: AllAgentsOptions = {}
|
|
24
|
-
):
|
|
22
|
+
): AllAgentsResult {
|
|
25
23
|
const claudeResult = writeClaudeConfig(apiKey)
|
|
26
|
-
const codexResult =
|
|
24
|
+
const codexResult = writeCodexConfig(apiKey)
|
|
27
25
|
|
|
28
26
|
const result: AllAgentsResult = {
|
|
29
27
|
claude: claudeResult,
|
|
@@ -32,29 +30,32 @@ export async function writeAllAgentsConfig(
|
|
|
32
30
|
|
|
33
31
|
if (options.full) {
|
|
34
32
|
result.opencode = writeOpencodeConfig(apiKey)
|
|
35
|
-
result.gemini = writeGeminiConfig(apiKey)
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
return result
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
/** Install dependencies for the combined setup (Claude Code + Codex; optional OpenCode
|
|
38
|
+
/** Install dependencies for the combined setup (Claude Code + Codex; optional OpenCode with --full). */
|
|
42
39
|
export async function installAllAgentsDeps(
|
|
43
40
|
options: AllAgentsOptions = {}
|
|
44
41
|
): Promise<void> {
|
|
45
42
|
const packages = ['@anthropic-ai/claude-code', '@openai/codex']
|
|
46
43
|
if (options.full) {
|
|
47
|
-
packages.push('opencode-ai'
|
|
44
|
+
packages.push('opencode-ai')
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
const usePnpm = await commandExists('pnpm')
|
|
51
48
|
|
|
52
49
|
if (usePnpm) {
|
|
53
50
|
console.log('pnpm detected. Installing agent dependencies with pnpm...')
|
|
54
|
-
await execa(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
await execa(
|
|
52
|
+
'pnpm',
|
|
53
|
+
['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages],
|
|
54
|
+
{
|
|
55
|
+
stdio: 'inherit',
|
|
56
|
+
env: PNPM_INSTALL_ENV,
|
|
57
|
+
}
|
|
58
|
+
)
|
|
58
59
|
} else {
|
|
59
60
|
console.log('pnpm not found. Falling back to npm...')
|
|
60
61
|
await execa('npm', ['install', '-g', ...packages], { stdio: 'inherit' })
|
package/libs/claude-code.test.ts
CHANGED
|
@@ -7,6 +7,8 @@ jest.mock('execa', () => ({
|
|
|
7
7
|
}))
|
|
8
8
|
|
|
9
9
|
import { writeClaudeConfig } from './claude-code'
|
|
10
|
+
import { installDeps } from './claude-code'
|
|
11
|
+
import { execa } from 'execa'
|
|
10
12
|
|
|
11
13
|
function getVSCodeUserSettingsPath(homeDir: string): string {
|
|
12
14
|
if (process.platform === 'darwin') {
|
|
@@ -103,4 +105,35 @@ describe('writeClaudeConfig', () => {
|
|
|
103
105
|
`VSCode settings is not valid JSONC: ${vscodeSettingsPath}. Please fix it and retry.`
|
|
104
106
|
)
|
|
105
107
|
})
|
|
108
|
+
|
|
109
|
+
test('allows Claude postinstall build when installing with pnpm', async () => {
|
|
110
|
+
const execaMock = jest.mocked(execa)
|
|
111
|
+
execaMock
|
|
112
|
+
.mockResolvedValueOnce({ failed: false } as never)
|
|
113
|
+
.mockResolvedValueOnce({} as never)
|
|
114
|
+
|
|
115
|
+
await installDeps()
|
|
116
|
+
|
|
117
|
+
expect(execaMock).toHaveBeenNthCalledWith(1, 'pnpm', ['--version'], {
|
|
118
|
+
stdio: 'ignore',
|
|
119
|
+
reject: false,
|
|
120
|
+
})
|
|
121
|
+
expect(execaMock).toHaveBeenNthCalledWith(
|
|
122
|
+
2,
|
|
123
|
+
'pnpm',
|
|
124
|
+
[
|
|
125
|
+
'--allow-build=@anthropic-ai/claude-code',
|
|
126
|
+
'add',
|
|
127
|
+
'-g',
|
|
128
|
+
'@anthropic-ai/claude-code',
|
|
129
|
+
],
|
|
130
|
+
{
|
|
131
|
+
stdio: 'inherit',
|
|
132
|
+
env: {
|
|
133
|
+
PNPM_CONFIG_ENABLE_PRE_POST_SCRIPTS: 'true',
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
expect(execaMock).toHaveBeenCalledTimes(2)
|
|
138
|
+
})
|
|
106
139
|
})
|
package/libs/claude-code.ts
CHANGED
|
@@ -42,6 +42,7 @@ function getVSCodeUserSettingsPath(): string {
|
|
|
42
42
|
const CLAUDE_SETTINGS_TEMPLATE = `{
|
|
43
43
|
"env": {
|
|
44
44
|
"DISABLE_TELEMETRY": "1",
|
|
45
|
+
"CLAUDE_CODE_EFFORT_LEVEL": "max",
|
|
45
46
|
"OTEL_METRICS_EXPORTER": "otlp",
|
|
46
47
|
"ANTHROPIC_API_KEY": "API_KEY_PLACEHOLDER",
|
|
47
48
|
"ANTHROPIC_BASE_URL": "${CLAUDE_BASE_URL}",
|
|
@@ -152,10 +153,14 @@ export async function installDeps(): Promise<void> {
|
|
|
152
153
|
|
|
153
154
|
if (usePnpm) {
|
|
154
155
|
console.log('pnpm detected. Installing dependencies with pnpm...')
|
|
155
|
-
await execa(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
await execa(
|
|
157
|
+
'pnpm',
|
|
158
|
+
['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages],
|
|
159
|
+
{
|
|
160
|
+
stdio: 'inherit',
|
|
161
|
+
env: PNPM_INSTALL_ENV,
|
|
162
|
+
}
|
|
163
|
+
)
|
|
159
164
|
} else {
|
|
160
165
|
console.log('pnpm not found. Falling back to npm...')
|
|
161
166
|
await execa('npm', ['install', '-g', ...packages], { stdio: 'inherit' })
|
package/libs/codex.test.ts
CHANGED
|
@@ -12,57 +12,29 @@ import { writeCodexConfig } from './codex'
|
|
|
12
12
|
describe('writeCodexConfig', () => {
|
|
13
13
|
let tempHome: string
|
|
14
14
|
let homedirSpy: jest.SpiedFunction<typeof os.homedir>
|
|
15
|
-
let originalFetch: typeof global.fetch | undefined
|
|
16
|
-
|
|
17
|
-
function getExpectedModelCatalogConfigPath(): string {
|
|
18
|
-
return os.platform() === 'win32'
|
|
19
|
-
? path.join(tempHome, '.codex', 'remote-model-catalog.json')
|
|
20
|
-
: '~/.codex/remote-model-catalog.json'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function mockCatalogFetch(
|
|
24
|
-
catalog: { models: Array<Record<string, unknown>> } = {
|
|
25
|
-
models: [{ id: 'gpt-5.5' }],
|
|
26
|
-
}
|
|
27
|
-
): jest.Mock {
|
|
28
|
-
const fetchMock = jest.fn().mockResolvedValue({
|
|
29
|
-
ok: true,
|
|
30
|
-
json: async () => catalog,
|
|
31
|
-
})
|
|
32
|
-
global.fetch = fetchMock as unknown as typeof global.fetch
|
|
33
|
-
return fetchMock
|
|
34
|
-
}
|
|
35
15
|
|
|
36
16
|
beforeEach(() => {
|
|
37
17
|
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-codex-'))
|
|
38
18
|
homedirSpy = jest.spyOn(os, 'homedir').mockReturnValue(tempHome)
|
|
39
|
-
originalFetch = global.fetch
|
|
40
|
-
mockCatalogFetch()
|
|
41
19
|
})
|
|
42
20
|
|
|
43
21
|
afterEach(() => {
|
|
44
22
|
homedirSpy.mockRestore()
|
|
45
|
-
if (originalFetch === undefined) {
|
|
46
|
-
global.fetch = undefined as unknown as typeof global.fetch
|
|
47
|
-
} else {
|
|
48
|
-
global.fetch = originalFetch
|
|
49
|
-
}
|
|
50
23
|
fs.rmSync(tempHome, { recursive: true, force: true })
|
|
51
24
|
})
|
|
52
25
|
|
|
53
|
-
test('writes config with 128k auto compact threshold',
|
|
54
|
-
const result =
|
|
26
|
+
test('writes config with 128k auto compact threshold', () => {
|
|
27
|
+
const result = writeCodexConfig('test-api-key')
|
|
55
28
|
const config = TOML.parse(fs.readFileSync(result.configPath, 'utf8')) as {
|
|
56
29
|
model_auto_compact_token_limit: number
|
|
57
|
-
model_catalog_json: string
|
|
58
30
|
}
|
|
59
31
|
|
|
60
32
|
expect(config.model_auto_compact_token_limit).toBe(131072)
|
|
61
|
-
expect(config
|
|
62
|
-
expect(fs.existsSync(result.
|
|
33
|
+
expect(config).not.toHaveProperty('model_catalog_json')
|
|
34
|
+
expect(fs.existsSync(result.authPath)).toBe(true)
|
|
63
35
|
})
|
|
64
36
|
|
|
65
|
-
test('merges template keys and keeps custom config',
|
|
37
|
+
test('merges template keys and keeps custom config', () => {
|
|
66
38
|
const configDir = path.join(tempHome, '.codex')
|
|
67
39
|
fs.mkdirSync(configDir, { recursive: true })
|
|
68
40
|
const configPath = path.join(configDir, 'config.toml')
|
|
@@ -78,11 +50,10 @@ custom_model = "keep-me"
|
|
|
78
50
|
`
|
|
79
51
|
)
|
|
80
52
|
|
|
81
|
-
|
|
53
|
+
writeCodexConfig('test-api-key')
|
|
82
54
|
const config = TOML.parse(fs.readFileSync(configPath, 'utf8')) as {
|
|
83
55
|
custom_flag: boolean
|
|
84
56
|
model: string
|
|
85
|
-
model_catalog_json: string
|
|
86
57
|
preferred_auth_method: string
|
|
87
58
|
model_providers: {
|
|
88
59
|
jw: {
|
|
@@ -94,9 +65,9 @@ custom_model = "keep-me"
|
|
|
94
65
|
}
|
|
95
66
|
|
|
96
67
|
expect(config).not.toHaveProperty('service_tier')
|
|
68
|
+
expect(config).not.toHaveProperty('model_catalog_json')
|
|
97
69
|
expect(config.custom_flag).toBe(true)
|
|
98
70
|
expect(config.model).toBe('gpt-5.5')
|
|
99
|
-
expect(config.model_catalog_json).toBe(getExpectedModelCatalogConfigPath())
|
|
100
71
|
expect(config.preferred_auth_method).toBe('apikey')
|
|
101
72
|
expect(config.model_providers.jw.base_url).toBe(
|
|
102
73
|
'https://ai.gengjiawen.com/api/openai'
|
|
@@ -105,7 +76,7 @@ custom_model = "keep-me"
|
|
|
105
76
|
expect(config.model_providers.jw.name).toBe('jw')
|
|
106
77
|
})
|
|
107
78
|
|
|
108
|
-
test('adds missing keys without removing custom config',
|
|
79
|
+
test('adds missing keys without removing custom config', () => {
|
|
109
80
|
const configDir = path.join(tempHome, '.codex')
|
|
110
81
|
fs.mkdirSync(configDir, { recursive: true })
|
|
111
82
|
const configPath = path.join(configDir, 'config.toml')
|
|
@@ -119,10 +90,9 @@ base_url = "https://example.com"
|
|
|
119
90
|
`
|
|
120
91
|
)
|
|
121
92
|
|
|
122
|
-
|
|
93
|
+
writeCodexConfig('test-api-key')
|
|
123
94
|
const config = TOML.parse(fs.readFileSync(configPath, 'utf8')) as {
|
|
124
95
|
model: string
|
|
125
|
-
model_catalog_json: string
|
|
126
96
|
preferred_auth_method: string
|
|
127
97
|
model_providers: {
|
|
128
98
|
jw: {
|
|
@@ -133,83 +103,34 @@ base_url = "https://example.com"
|
|
|
133
103
|
}
|
|
134
104
|
|
|
135
105
|
expect(config.model).toBe('gpt-5.5')
|
|
136
|
-
expect(config
|
|
106
|
+
expect(config).not.toHaveProperty('model_catalog_json')
|
|
137
107
|
expect(config.preferred_auth_method).toBe('apikey')
|
|
138
108
|
expect(config.model_providers.jw.name).toBe('jw')
|
|
139
109
|
expect(config).not.toHaveProperty('service_tier')
|
|
140
110
|
})
|
|
141
111
|
|
|
142
|
-
test('
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
{ id: 'gpt-5.5-mini' },
|
|
147
|
-
{ id: 'gpt-5.3-codex' },
|
|
148
|
-
],
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
const result = await writeCodexConfig('test-api-key')
|
|
152
|
-
|
|
153
|
-
expect(fetchMock).toHaveBeenCalledWith(
|
|
154
|
-
'https://ai.gengjiawen.com/api/openai/models',
|
|
155
|
-
{
|
|
156
|
-
headers: {
|
|
157
|
-
Accept: 'application/json',
|
|
158
|
-
Authorization: 'Bearer test-api-key',
|
|
159
|
-
'User-Agent': '@gengjiawen/os-init',
|
|
160
|
-
},
|
|
161
|
-
}
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
const catalog = JSON.parse(fs.readFileSync(result.catalogPath, 'utf8')) as {
|
|
165
|
-
models: Array<{ id: string }>
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
expect(catalog).toEqual({
|
|
169
|
-
models: [
|
|
170
|
-
{ id: 'gpt-5.5' },
|
|
171
|
-
{ id: 'gpt-5.5-mini' },
|
|
172
|
-
{ id: 'gpt-5.3-codex' },
|
|
173
|
-
],
|
|
174
|
-
})
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
test('writes an absolute model catalog path on Windows', async () => {
|
|
178
|
-
const platformSpy = jest.spyOn(os, 'platform').mockReturnValue('win32')
|
|
179
|
-
|
|
180
|
-
try {
|
|
181
|
-
const result = await writeCodexConfig('test-api-key')
|
|
182
|
-
const config = TOML.parse(fs.readFileSync(result.configPath, 'utf8')) as {
|
|
183
|
-
model_catalog_json: string
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
expect(config.model_catalog_json).toBe(
|
|
187
|
-
path.join(tempHome, '.codex', 'remote-model-catalog.json')
|
|
188
|
-
)
|
|
189
|
-
} finally {
|
|
190
|
-
platformSpy.mockRestore()
|
|
191
|
-
}
|
|
192
|
-
})
|
|
112
|
+
test('drops model_catalog_json when merging existing codex config', () => {
|
|
113
|
+
const configDir = path.join(tempHome, '.codex')
|
|
114
|
+
fs.mkdirSync(configDir, { recursive: true })
|
|
115
|
+
const configPath = path.join(configDir, 'config.toml')
|
|
193
116
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
statusText: 'Service Unavailable',
|
|
199
|
-
}) as unknown as typeof global.fetch
|
|
117
|
+
fs.writeFileSync(
|
|
118
|
+
configPath,
|
|
119
|
+
`model_catalog_json = "${path.join(tempHome, '.codex', 'remote-model-catalog.json')}"
|
|
120
|
+
model = "gpt-custom"
|
|
200
121
|
|
|
201
|
-
|
|
202
|
-
|
|
122
|
+
[model_providers.jw]
|
|
123
|
+
base_url = "https://example.com"
|
|
124
|
+
`
|
|
203
125
|
)
|
|
204
126
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
expect(
|
|
212
|
-
|
|
213
|
-
).toBe(false)
|
|
127
|
+
writeCodexConfig('test-api-key')
|
|
128
|
+
const config = TOML.parse(fs.readFileSync(configPath, 'utf8')) as Record<
|
|
129
|
+
string,
|
|
130
|
+
unknown
|
|
131
|
+
>
|
|
132
|
+
|
|
133
|
+
expect(config).not.toHaveProperty('model_catalog_json')
|
|
134
|
+
expect(config.model).toBe('gpt-5.5')
|
|
214
135
|
})
|
|
215
136
|
})
|
package/libs/codex.ts
CHANGED
|
@@ -6,27 +6,14 @@ import { execa } from 'execa'
|
|
|
6
6
|
import { ensureDir, commandExists, PNPM_INSTALL_ENV } from './utils'
|
|
7
7
|
|
|
8
8
|
type TomlTable = ReturnType<typeof TOML.parse>
|
|
9
|
-
type CodexModelCatalog = { models: unknown[] }
|
|
10
9
|
|
|
11
10
|
const CODEX_BASE_URL = 'https://ai.gengjiawen.com/api/openai'
|
|
12
|
-
const CODEX_MODEL_CATALOG_CONFIG_PATH = '~/.codex/remote-model-catalog.json'
|
|
13
|
-
const CODEX_MODEL_CATALOG_FILENAME = 'remote-model-catalog.json'
|
|
14
11
|
|
|
15
12
|
/** Return Codex configuration directory path */
|
|
16
13
|
function getCodexConfigDir(): string {
|
|
17
14
|
return path.join(os.homedir(), '.codex')
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
function getCodexModelCatalogPath(): string {
|
|
21
|
-
return path.join(getCodexConfigDir(), CODEX_MODEL_CATALOG_FILENAME)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getCodexModelCatalogConfigPath(): string {
|
|
25
|
-
return os.platform() === 'win32'
|
|
26
|
-
? getCodexModelCatalogPath()
|
|
27
|
-
: CODEX_MODEL_CATALOG_CONFIG_PATH
|
|
28
|
-
}
|
|
29
|
-
|
|
30
17
|
function getCodexConfigTomlTemplate(): string {
|
|
31
18
|
return `model_provider = "jw"
|
|
32
19
|
model = "gpt-5.5"
|
|
@@ -35,7 +22,6 @@ plan_mode_reasoning_effort = "xhigh"
|
|
|
35
22
|
model_auto_compact_token_limit = 131072
|
|
36
23
|
disable_response_storage = true
|
|
37
24
|
preferred_auth_method = "apikey"
|
|
38
|
-
model_catalog_json = ${JSON.stringify(getCodexModelCatalogConfigPath())}
|
|
39
25
|
|
|
40
26
|
[model_providers.jw]
|
|
41
27
|
name = "jw"
|
|
@@ -75,54 +61,19 @@ function getMergedCodexConfig(existingContent: string): string {
|
|
|
75
61
|
const existingConfig = TOML.parse(existingContent) as TomlTable
|
|
76
62
|
const templateConfig = TOML.parse(getCodexConfigTomlTemplate()) as TomlTable
|
|
77
63
|
delete existingConfig.service_tier
|
|
64
|
+
delete existingConfig.model_catalog_json
|
|
78
65
|
|
|
79
66
|
return TOML.stringify(mergeTomlTables(existingConfig, templateConfig))
|
|
80
67
|
}
|
|
81
68
|
|
|
82
|
-
async function refreshCodexModelCatalog(apiKey: string): Promise<string> {
|
|
83
|
-
if (typeof fetch !== 'function') {
|
|
84
|
-
throw new Error('Global fetch API is unavailable in this Node.js runtime.')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const response = await fetch(`${CODEX_BASE_URL}/models`, {
|
|
88
|
-
headers: {
|
|
89
|
-
Accept: 'application/json',
|
|
90
|
-
Authorization: `Bearer ${apiKey}`,
|
|
91
|
-
'User-Agent': '@gengjiawen/os-init',
|
|
92
|
-
},
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
if (!response.ok) {
|
|
96
|
-
throw new Error(
|
|
97
|
-
`Failed to refresh Codex model catalog: ${response.status} ${response.statusText}`
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const catalog = (await response.json()) as CodexModelCatalog
|
|
102
|
-
|
|
103
|
-
if (!Array.isArray(catalog?.models) || catalog.models.length === 0) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
'Failed to refresh Codex model catalog: response does not contain any models.'
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const catalogPath = getCodexModelCatalogPath()
|
|
110
|
-
fs.writeFileSync(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`)
|
|
111
|
-
|
|
112
|
-
return catalogPath
|
|
113
|
-
}
|
|
114
|
-
|
|
115
69
|
/** Write Codex config.toml and auth.json */
|
|
116
|
-
export
|
|
70
|
+
export function writeCodexConfig(apiKey: string): {
|
|
117
71
|
configPath: string
|
|
118
72
|
authPath: string
|
|
119
|
-
|
|
120
|
-
}> {
|
|
73
|
+
} {
|
|
121
74
|
const configDir = getCodexConfigDir()
|
|
122
75
|
ensureDir(configDir)
|
|
123
76
|
|
|
124
|
-
const catalogPath = await refreshCodexModelCatalog(apiKey)
|
|
125
|
-
|
|
126
77
|
const configPath = path.join(configDir, 'config.toml')
|
|
127
78
|
const configContent = fs.existsSync(configPath)
|
|
128
79
|
? getMergedCodexConfig(fs.readFileSync(configPath, 'utf8'))
|
|
@@ -133,7 +84,7 @@ export async function writeCodexConfig(apiKey: string): Promise<{
|
|
|
133
84
|
const authContent = JSON.stringify({ OPENAI_API_KEY: apiKey }, null, 2)
|
|
134
85
|
fs.writeFileSync(authPath, authContent)
|
|
135
86
|
|
|
136
|
-
return { configPath, authPath
|
|
87
|
+
return { configPath, authPath }
|
|
137
88
|
}
|
|
138
89
|
|
|
139
90
|
/** Install Codex dependency */
|
package/libs/index.ts
CHANGED
|
@@ -52,9 +52,6 @@ export { writeClaudeConfig, installDeps } from './claude-code'
|
|
|
52
52
|
// Re-export codex functionality
|
|
53
53
|
export { writeCodexConfig, installCodexDeps } from './codex'
|
|
54
54
|
|
|
55
|
-
// Re-export gemini-cli functionality
|
|
56
|
-
export { writeGeminiConfig, installGeminiDeps } from './gemini-cli'
|
|
57
|
-
|
|
58
55
|
// Re-export opencode functionality
|
|
59
56
|
export { writeOpencodeConfig, installOpencodeDeps } from './opencode'
|
|
60
57
|
|
package/libs/mihomo.test.ts
CHANGED
|
@@ -104,7 +104,7 @@ describe('writeMihomoConfig', () => {
|
|
|
104
104
|
expect(content).toContain('- IP-CIDR6,fe80::/10,DIRECT')
|
|
105
105
|
expect(content).toContain('- DOMAIN-SUFFIX,local,DIRECT')
|
|
106
106
|
expect(content).toContain('- DOMAIN-SUFFIX,cn,DIRECT')
|
|
107
|
-
expect(content).toContain('- GEOIP,CN,DIRECT')
|
|
107
|
+
expect(content).toContain('# - GEOIP,CN,DIRECT')
|
|
108
108
|
expect(content).toContain('- MATCH,PROXY')
|
|
109
109
|
})
|
|
110
110
|
|
package/libs/mihomo.ts
CHANGED
package/libs/opencode.test.ts
CHANGED
|
@@ -64,9 +64,6 @@ describe('writeOpencodeConfig', () => {
|
|
|
64
64
|
expect(config.provider.MyCustomProvider.models.deepseek).toEqual(
|
|
65
65
|
expectedModelConfig('deepseek')
|
|
66
66
|
)
|
|
67
|
-
expect(config.provider.MyCustomProvider.models['gemini-flash']).toEqual(
|
|
68
|
-
expectedModelConfig('gemini-flash')
|
|
69
|
-
)
|
|
70
67
|
expect(config.model).toBe('MyCustomProvider/code')
|
|
71
68
|
expect(config.small_model).toBe('MyCustomProvider/code')
|
|
72
69
|
})
|
package/libs/opencode.ts
CHANGED
package/package.json
CHANGED
package/build/gemini-cli.d.ts
DELETED
package/build/gemini-cli.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeGeminiConfig = writeGeminiConfig;
|
|
4
|
-
exports.installGeminiDeps = installGeminiDeps;
|
|
5
|
-
const fs = require("fs");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const os = require("os");
|
|
8
|
-
const execa_1 = require("execa");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
function getGeminiConfigDir() {
|
|
11
|
-
return path.join(os.homedir(), '.gemini');
|
|
12
|
-
}
|
|
13
|
-
const GEMINI_ENV_TEMPLATE = `GOOGLE_GEMINI_BASE_URL=https://ai.gengjiawen.com/api/gemini
|
|
14
|
-
GEMINI_API_KEY=API_KEY_PLACEHOLDER
|
|
15
|
-
GEMINI_MODEL=gemini-3-pro-preview
|
|
16
|
-
`;
|
|
17
|
-
const GEMINI_SETTINGS_TEMPLATE = {
|
|
18
|
-
ide: {
|
|
19
|
-
enabled: true,
|
|
20
|
-
},
|
|
21
|
-
security: {
|
|
22
|
-
auth: {
|
|
23
|
-
selectedType: 'gemini-api-key',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
function writeGeminiConfig(apiKey) {
|
|
28
|
-
const configDir = getGeminiConfigDir();
|
|
29
|
-
(0, utils_1.ensureDir)(configDir);
|
|
30
|
-
const envPath = path.join(configDir, '.env');
|
|
31
|
-
const envContent = GEMINI_ENV_TEMPLATE.replace('API_KEY_PLACEHOLDER', apiKey);
|
|
32
|
-
fs.writeFileSync(envPath, envContent);
|
|
33
|
-
const settingsPath = path.join(configDir, 'settings.json');
|
|
34
|
-
fs.writeFileSync(settingsPath, JSON.stringify(GEMINI_SETTINGS_TEMPLATE, null, 2));
|
|
35
|
-
return { envPath, settingsPath };
|
|
36
|
-
}
|
|
37
|
-
async function installGeminiDeps() {
|
|
38
|
-
const usePnpm = await (0, utils_1.commandExists)('pnpm');
|
|
39
|
-
const geminiPackage = '@google/gemini-cli';
|
|
40
|
-
if (usePnpm) {
|
|
41
|
-
console.log('pnpm detected. Installing Gemini CLI with pnpm...');
|
|
42
|
-
await (0, execa_1.execa)('pnpm', ['add', '-g', geminiPackage], {
|
|
43
|
-
stdio: 'inherit',
|
|
44
|
-
env: utils_1.PNPM_INSTALL_ENV,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
console.log('pnpm not found. Falling back to npm...');
|
|
49
|
-
await (0, execa_1.execa)('npm', ['install', '-g', geminiPackage], { stdio: 'inherit' });
|
|
50
|
-
}
|
|
51
|
-
console.log('Gemini CLI installed successfully.');
|
|
52
|
-
}
|
package/libs/gemini-cli.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs'
|
|
2
|
-
import * as path from 'path'
|
|
3
|
-
import * as os from 'os'
|
|
4
|
-
import { execa } from 'execa'
|
|
5
|
-
import { ensureDir, commandExists, PNPM_INSTALL_ENV } from './utils'
|
|
6
|
-
|
|
7
|
-
/** Return Gemini CLI configuration directory path */
|
|
8
|
-
function getGeminiConfigDir(): string {
|
|
9
|
-
return path.join(os.homedir(), '.gemini')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Template for Gemini CLI .env file */
|
|
13
|
-
const GEMINI_ENV_TEMPLATE = `GOOGLE_GEMINI_BASE_URL=https://ai.gengjiawen.com/api/gemini
|
|
14
|
-
GEMINI_API_KEY=API_KEY_PLACEHOLDER
|
|
15
|
-
GEMINI_MODEL=gemini-3-pro-preview
|
|
16
|
-
`
|
|
17
|
-
|
|
18
|
-
/** Template for Gemini CLI settings.json */
|
|
19
|
-
const GEMINI_SETTINGS_TEMPLATE = {
|
|
20
|
-
ide: {
|
|
21
|
-
enabled: true,
|
|
22
|
-
},
|
|
23
|
-
security: {
|
|
24
|
-
auth: {
|
|
25
|
-
selectedType: 'gemini-api-key',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Write Gemini CLI config files (.env and settings.json) */
|
|
31
|
-
export function writeGeminiConfig(apiKey: string): {
|
|
32
|
-
envPath: string
|
|
33
|
-
settingsPath: string
|
|
34
|
-
} {
|
|
35
|
-
const configDir = getGeminiConfigDir()
|
|
36
|
-
ensureDir(configDir)
|
|
37
|
-
|
|
38
|
-
// Write .env file
|
|
39
|
-
const envPath = path.join(configDir, '.env')
|
|
40
|
-
const envContent = GEMINI_ENV_TEMPLATE.replace('API_KEY_PLACEHOLDER', apiKey)
|
|
41
|
-
fs.writeFileSync(envPath, envContent)
|
|
42
|
-
|
|
43
|
-
// Write settings.json file
|
|
44
|
-
const settingsPath = path.join(configDir, 'settings.json')
|
|
45
|
-
fs.writeFileSync(
|
|
46
|
-
settingsPath,
|
|
47
|
-
JSON.stringify(GEMINI_SETTINGS_TEMPLATE, null, 2)
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
return { envPath, settingsPath }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Install Gemini CLI dependency */
|
|
54
|
-
export async function installGeminiDeps(): Promise<void> {
|
|
55
|
-
const usePnpm = await commandExists('pnpm')
|
|
56
|
-
const geminiPackage = '@google/gemini-cli'
|
|
57
|
-
|
|
58
|
-
if (usePnpm) {
|
|
59
|
-
console.log('pnpm detected. Installing Gemini CLI with pnpm...')
|
|
60
|
-
await execa('pnpm', ['add', '-g', geminiPackage], {
|
|
61
|
-
stdio: 'inherit',
|
|
62
|
-
env: PNPM_INSTALL_ENV,
|
|
63
|
-
})
|
|
64
|
-
} else {
|
|
65
|
-
console.log('pnpm not found. Falling back to npm...')
|
|
66
|
-
await execa('npm', ['install', '-g', geminiPackage], { stdio: 'inherit' })
|
|
67
|
-
}
|
|
68
|
-
console.log('Gemini CLI installed successfully.')
|
|
69
|
-
}
|