@gengjiawen/os-init 1.23.1 → 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/CHANGELOG.md +7 -0
- package/bin/bin.js +2 -5
- package/build/all-agents.d.ts +1 -2
- package/build/all-agents.js +3 -9
- package/build/claude-code.js +2 -7
- package/build/codex.d.ts +2 -3
- package/build/codex.js +3 -36
- package/build/mihomo.js +1 -1
- package/libs/all-agents.test.ts +4 -17
- package/libs/all-agents.ts +5 -11
- package/libs/claude-code.test.ts +0 -1
- package/libs/claude-code.ts +2 -7
- package/libs/codex.test.ts +29 -108
- package/libs/codex.ts +4 -53
- package/libs/mihomo.test.ts +1 -1
- package/libs/mihomo.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
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
|
+
|
|
3
10
|
## [1.23.1](https://github.com/gengjiawen/os-init/compare/v1.23.0...v1.23.1) (2026-04-24)
|
|
4
11
|
|
|
5
12
|
|
package/bin/bin.js
CHANGED
|
@@ -63,11 +63,9 @@ program
|
|
|
63
63
|
return
|
|
64
64
|
}
|
|
65
65
|
try {
|
|
66
|
-
const { configPath, authPath
|
|
67
|
-
await writeCodexConfig(apiKey)
|
|
66
|
+
const { configPath, authPath } = writeCodexConfig(apiKey)
|
|
68
67
|
console.log(`Codex config written to: ${configPath}`)
|
|
69
68
|
console.log(`Codex auth written to: ${authPath}`)
|
|
70
|
-
console.log(`Codex model catalog written to: ${catalogPath}`)
|
|
71
69
|
await installCodexDeps()
|
|
72
70
|
} catch (err) {
|
|
73
71
|
console.error('Failed to setup Codex:', err.message)
|
|
@@ -122,7 +120,7 @@ program
|
|
|
122
120
|
: 'Setting up Claude Code + Codex...\n'
|
|
123
121
|
)
|
|
124
122
|
|
|
125
|
-
const result =
|
|
123
|
+
const result = writeAllAgentsConfig(apiKey, { full })
|
|
126
124
|
|
|
127
125
|
console.log('Claude Code:')
|
|
128
126
|
console.log(` Settings written to: ${result.claude.settingsPath}`)
|
|
@@ -133,7 +131,6 @@ program
|
|
|
133
131
|
console.log('\nCodex:')
|
|
134
132
|
console.log(` Config written to: ${result.codex.configPath}`)
|
|
135
133
|
console.log(` Auth written to: ${result.codex.authPath}`)
|
|
136
|
-
console.log(` Model catalog written to: ${result.codex.catalogPath}`)
|
|
137
134
|
|
|
138
135
|
if (result.opencode) {
|
|
139
136
|
console.log('\nOpenCode:')
|
package/build/all-agents.d.ts
CHANGED
|
@@ -9,11 +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
16
|
}
|
|
18
|
-
export declare function writeAllAgentsConfig(apiKey: string, options?: AllAgentsOptions):
|
|
17
|
+
export declare function writeAllAgentsConfig(apiKey: string, options?: AllAgentsOptions): AllAgentsResult;
|
|
19
18
|
export declare function installAllAgentsDeps(options?: AllAgentsOptions): Promise<void>;
|
package/build/all-agents.js
CHANGED
|
@@ -7,9 +7,9 @@ const codex_1 = require("./codex");
|
|
|
7
7
|
const opencode_1 = require("./opencode");
|
|
8
8
|
const execa_1 = require("execa");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
|
-
|
|
10
|
+
function writeAllAgentsConfig(apiKey, options = {}) {
|
|
11
11
|
const claudeResult = (0, claude_code_1.writeClaudeConfig)(apiKey);
|
|
12
|
-
const codexResult =
|
|
12
|
+
const codexResult = (0, codex_1.writeCodexConfig)(apiKey);
|
|
13
13
|
const result = {
|
|
14
14
|
claude: claudeResult,
|
|
15
15
|
codex: codexResult,
|
|
@@ -27,13 +27,7 @@ async function installAllAgentsDeps(options = {}) {
|
|
|
27
27
|
const usePnpm = await (0, utils_1.commandExists)('pnpm');
|
|
28
28
|
if (usePnpm) {
|
|
29
29
|
console.log('pnpm detected. Installing agent dependencies with pnpm...');
|
|
30
|
-
await (0, execa_1.execa)('pnpm', [
|
|
31
|
-
'--allow-build=@anthropic-ai/claude-code',
|
|
32
|
-
'add',
|
|
33
|
-
'-g',
|
|
34
|
-
'--force',
|
|
35
|
-
...packages,
|
|
36
|
-
], {
|
|
30
|
+
await (0, execa_1.execa)('pnpm', ['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages], {
|
|
37
31
|
stdio: 'inherit',
|
|
38
32
|
env: utils_1.PNPM_INSTALL_ENV,
|
|
39
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,13 +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', [
|
|
107
|
-
'--allow-build=@anthropic-ai/claude-code',
|
|
108
|
-
'add',
|
|
109
|
-
'-g',
|
|
110
|
-
'--force',
|
|
111
|
-
...packages,
|
|
112
|
-
], {
|
|
107
|
+
await (0, execa_1.execa)('pnpm', ['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages], {
|
|
113
108
|
stdio: 'inherit',
|
|
114
109
|
env: utils_1.PNPM_INSTALL_ENV,
|
|
115
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/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/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,26 +30,20 @@ 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
43
|
})
|
|
56
44
|
|
|
57
|
-
test('includes OpenCode config when full option is enabled',
|
|
58
|
-
const result =
|
|
45
|
+
test('includes OpenCode config when full option is enabled', () => {
|
|
46
|
+
const result = writeAllAgentsConfig('test-api-key', { full: true })
|
|
59
47
|
|
|
60
48
|
expect(result.opencode).toBeDefined()
|
|
61
49
|
expect(fs.existsSync(result.opencode!.configPath)).toBe(true)
|
|
@@ -79,7 +67,6 @@ describe('writeAllAgentsConfig', () => {
|
|
|
79
67
|
'--allow-build=@anthropic-ai/claude-code',
|
|
80
68
|
'add',
|
|
81
69
|
'-g',
|
|
82
|
-
'--force',
|
|
83
70
|
'@anthropic-ai/claude-code',
|
|
84
71
|
'@openai/codex',
|
|
85
72
|
],
|
package/libs/all-agents.ts
CHANGED
|
@@ -11,17 +11,17 @@ export interface AllAgentsOptions {
|
|
|
11
11
|
|
|
12
12
|
export interface AllAgentsResult {
|
|
13
13
|
claude: { settingsPath: string; vscodeSettingsPath: string }
|
|
14
|
-
codex: { configPath: string; authPath: string
|
|
14
|
+
codex: { configPath: string; authPath: string }
|
|
15
15
|
opencode?: { configPath: string }
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/** Write configuration for the combined setup (Claude Code + Codex; optional OpenCode with --full). */
|
|
19
|
-
export
|
|
19
|
+
export function writeAllAgentsConfig(
|
|
20
20
|
apiKey: string,
|
|
21
21
|
options: AllAgentsOptions = {}
|
|
22
|
-
):
|
|
22
|
+
): AllAgentsResult {
|
|
23
23
|
const claudeResult = writeClaudeConfig(apiKey)
|
|
24
|
-
const codexResult =
|
|
24
|
+
const codexResult = writeCodexConfig(apiKey)
|
|
25
25
|
|
|
26
26
|
const result: AllAgentsResult = {
|
|
27
27
|
claude: claudeResult,
|
|
@@ -50,13 +50,7 @@ export async function installAllAgentsDeps(
|
|
|
50
50
|
console.log('pnpm detected. Installing agent dependencies with pnpm...')
|
|
51
51
|
await execa(
|
|
52
52
|
'pnpm',
|
|
53
|
-
[
|
|
54
|
-
'--allow-build=@anthropic-ai/claude-code',
|
|
55
|
-
'add',
|
|
56
|
-
'-g',
|
|
57
|
-
'--force',
|
|
58
|
-
...packages,
|
|
59
|
-
],
|
|
53
|
+
['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages],
|
|
60
54
|
{
|
|
61
55
|
stdio: 'inherit',
|
|
62
56
|
env: PNPM_INSTALL_ENV,
|
package/libs/claude-code.test.ts
CHANGED
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}",
|
|
@@ -154,13 +155,7 @@ export async function installDeps(): Promise<void> {
|
|
|
154
155
|
console.log('pnpm detected. Installing dependencies with pnpm...')
|
|
155
156
|
await execa(
|
|
156
157
|
'pnpm',
|
|
157
|
-
[
|
|
158
|
-
'--allow-build=@anthropic-ai/claude-code',
|
|
159
|
-
'add',
|
|
160
|
-
'-g',
|
|
161
|
-
'--force',
|
|
162
|
-
...packages,
|
|
163
|
-
],
|
|
158
|
+
['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages],
|
|
164
159
|
{
|
|
165
160
|
stdio: 'inherit',
|
|
166
161
|
env: PNPM_INSTALL_ENV,
|
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/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