@gengjiawen/os-init 1.18.0 → 1.18.1
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/build/codex.js +28 -1
- package/libs/codex.test.ts +109 -0
- package/libs/codex.ts +42 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.18.1](https://github.com/gengjiawen/os-init/compare/v1.18.0...v1.18.1) (2026-03-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* set codex compact threshold to 128k ([634e5c2](https://github.com/gengjiawen/os-init/commit/634e5c2fef634aeca50f882108857be3f1298219))
|
|
9
|
+
|
|
3
10
|
## [1.18.0](https://github.com/gengjiawen/os-init/compare/v1.17.0...v1.18.0) (2026-03-13)
|
|
4
11
|
|
|
5
12
|
|
package/build/codex.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.installCodexDeps = installCodexDeps;
|
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const path = require("path");
|
|
7
7
|
const os = require("os");
|
|
8
|
+
const TOML = require("@iarna/toml");
|
|
8
9
|
const execa_1 = require("execa");
|
|
9
10
|
const utils_1 = require("./utils");
|
|
10
11
|
function getCodexConfigDir() {
|
|
@@ -14,6 +15,7 @@ const CODEX_CONFIG_TOML_TEMPLATE = `model_provider = "jw"
|
|
|
14
15
|
model = "gpt-5.4"
|
|
15
16
|
model_reasoning_effort = "high"
|
|
16
17
|
plan_mode_reasoning_effort = "xhigh"
|
|
18
|
+
model_auto_compact_token_limit = 131072
|
|
17
19
|
disable_response_storage = true
|
|
18
20
|
preferred_auth_method = "apikey"
|
|
19
21
|
service_tier = "fast"
|
|
@@ -23,11 +25,36 @@ name = "jw"
|
|
|
23
25
|
base_url = "https://ai.gengjiawen.com/api/openai"
|
|
24
26
|
wire_api = "responses"
|
|
25
27
|
`;
|
|
28
|
+
function isTomlTable(value) {
|
|
29
|
+
return (value !== undefined &&
|
|
30
|
+
typeof value === 'object' &&
|
|
31
|
+
!Array.isArray(value) &&
|
|
32
|
+
!(value instanceof Date));
|
|
33
|
+
}
|
|
34
|
+
function mergeTomlTables(existingConfig, templateConfig) {
|
|
35
|
+
const mergedConfig = { ...existingConfig };
|
|
36
|
+
for (const [key, templateValue] of Object.entries(templateConfig)) {
|
|
37
|
+
const existingValue = mergedConfig[key];
|
|
38
|
+
mergedConfig[key] =
|
|
39
|
+
isTomlTable(existingValue) && isTomlTable(templateValue)
|
|
40
|
+
? mergeTomlTables(existingValue, templateValue)
|
|
41
|
+
: templateValue;
|
|
42
|
+
}
|
|
43
|
+
return mergedConfig;
|
|
44
|
+
}
|
|
45
|
+
function getMergedCodexConfig(existingContent) {
|
|
46
|
+
const existingConfig = TOML.parse(existingContent);
|
|
47
|
+
const templateConfig = TOML.parse(CODEX_CONFIG_TOML_TEMPLATE);
|
|
48
|
+
return TOML.stringify(mergeTomlTables(existingConfig, templateConfig));
|
|
49
|
+
}
|
|
26
50
|
function writeCodexConfig(apiKey) {
|
|
27
51
|
const configDir = getCodexConfigDir();
|
|
28
52
|
(0, utils_1.ensureDir)(configDir);
|
|
29
53
|
const configPath = path.join(configDir, 'config.toml');
|
|
30
|
-
fs.
|
|
54
|
+
const configContent = fs.existsSync(configPath)
|
|
55
|
+
? getMergedCodexConfig(fs.readFileSync(configPath, 'utf8'))
|
|
56
|
+
: CODEX_CONFIG_TOML_TEMPLATE;
|
|
57
|
+
fs.writeFileSync(configPath, configContent);
|
|
31
58
|
const authPath = path.join(configDir, 'auth.json');
|
|
32
59
|
const authContent = JSON.stringify({ OPENAI_API_KEY: apiKey }, null, 2);
|
|
33
60
|
fs.writeFileSync(authPath, authContent);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as fs from 'fs'
|
|
2
|
+
import * as os from 'os'
|
|
3
|
+
import * as path from 'path'
|
|
4
|
+
import * as TOML from '@iarna/toml'
|
|
5
|
+
|
|
6
|
+
jest.mock('execa', () => ({
|
|
7
|
+
execa: jest.fn(),
|
|
8
|
+
}))
|
|
9
|
+
|
|
10
|
+
import { writeCodexConfig } from './codex'
|
|
11
|
+
|
|
12
|
+
describe('writeCodexConfig', () => {
|
|
13
|
+
let tempHome: string
|
|
14
|
+
let homedirSpy: jest.SpiedFunction<typeof os.homedir>
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-codex-'))
|
|
18
|
+
homedirSpy = jest.spyOn(os, 'homedir').mockReturnValue(tempHome)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
homedirSpy.mockRestore()
|
|
23
|
+
fs.rmSync(tempHome, { recursive: true, force: true })
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('writes config with 128k auto compact threshold', () => {
|
|
27
|
+
const result = writeCodexConfig('test-api-key')
|
|
28
|
+
const config = TOML.parse(fs.readFileSync(result.configPath, 'utf8')) as {
|
|
29
|
+
model_auto_compact_token_limit: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
expect(config.model_auto_compact_token_limit).toBe(131072)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('merges template keys and keeps custom config', () => {
|
|
36
|
+
const configDir = path.join(tempHome, '.codex')
|
|
37
|
+
fs.mkdirSync(configDir, { recursive: true })
|
|
38
|
+
const configPath = path.join(configDir, 'config.toml')
|
|
39
|
+
|
|
40
|
+
fs.writeFileSync(
|
|
41
|
+
configPath,
|
|
42
|
+
`service_tier = "slow"
|
|
43
|
+
custom_flag = true
|
|
44
|
+
|
|
45
|
+
[model_providers.jw]
|
|
46
|
+
base_url = "https://example.com" # keep comment
|
|
47
|
+
custom_model = "keep-me"
|
|
48
|
+
`
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
writeCodexConfig('test-api-key')
|
|
52
|
+
const config = TOML.parse(fs.readFileSync(configPath, 'utf8')) as {
|
|
53
|
+
service_tier: string
|
|
54
|
+
custom_flag: boolean
|
|
55
|
+
model: string
|
|
56
|
+
preferred_auth_method: string
|
|
57
|
+
model_providers: {
|
|
58
|
+
jw: {
|
|
59
|
+
base_url: string
|
|
60
|
+
custom_model: string
|
|
61
|
+
name: string
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
expect(config.service_tier).toBe('fast')
|
|
67
|
+
expect(config.custom_flag).toBe(true)
|
|
68
|
+
expect(config.model).toBe('gpt-5.4')
|
|
69
|
+
expect(config.preferred_auth_method).toBe('apikey')
|
|
70
|
+
expect(config.model_providers.jw.base_url).toBe(
|
|
71
|
+
'https://ai.gengjiawen.com/api/openai'
|
|
72
|
+
)
|
|
73
|
+
expect(config.model_providers.jw.custom_model).toBe('keep-me')
|
|
74
|
+
expect(config.model_providers.jw.name).toBe('jw')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('adds missing keys without removing custom config', () => {
|
|
78
|
+
const configDir = path.join(tempHome, '.codex')
|
|
79
|
+
fs.mkdirSync(configDir, { recursive: true })
|
|
80
|
+
const configPath = path.join(configDir, 'config.toml')
|
|
81
|
+
|
|
82
|
+
fs.writeFileSync(
|
|
83
|
+
configPath,
|
|
84
|
+
`service_tier = "slow"
|
|
85
|
+
|
|
86
|
+
[model_providers.jw]
|
|
87
|
+
base_url = "https://example.com"
|
|
88
|
+
`
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
writeCodexConfig('test-api-key')
|
|
92
|
+
const config = TOML.parse(fs.readFileSync(configPath, 'utf8')) as {
|
|
93
|
+
model: string
|
|
94
|
+
preferred_auth_method: string
|
|
95
|
+
service_tier: string
|
|
96
|
+
model_providers: {
|
|
97
|
+
jw: {
|
|
98
|
+
name: string
|
|
99
|
+
base_url: string
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
expect(config.model).toBe('gpt-5.4')
|
|
105
|
+
expect(config.preferred_auth_method).toBe('apikey')
|
|
106
|
+
expect(config.model_providers.jw.name).toBe('jw')
|
|
107
|
+
expect(config.service_tier).toBe('fast')
|
|
108
|
+
})
|
|
109
|
+
})
|
package/libs/codex.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import * as fs from 'fs'
|
|
2
2
|
import * as path from 'path'
|
|
3
3
|
import * as os from 'os'
|
|
4
|
+
import * as TOML from '@iarna/toml'
|
|
4
5
|
import { execa } from 'execa'
|
|
5
6
|
import { ensureDir, commandExists, PNPM_INSTALL_ENV } from './utils'
|
|
6
7
|
|
|
8
|
+
type TomlTable = ReturnType<typeof TOML.parse>
|
|
9
|
+
|
|
7
10
|
/** Return Codex configuration directory path */
|
|
8
11
|
function getCodexConfigDir(): string {
|
|
9
12
|
return path.join(os.homedir(), '.codex')
|
|
@@ -14,6 +17,7 @@ const CODEX_CONFIG_TOML_TEMPLATE = `model_provider = "jw"
|
|
|
14
17
|
model = "gpt-5.4"
|
|
15
18
|
model_reasoning_effort = "high"
|
|
16
19
|
plan_mode_reasoning_effort = "xhigh"
|
|
20
|
+
model_auto_compact_token_limit = 131072
|
|
17
21
|
disable_response_storage = true
|
|
18
22
|
preferred_auth_method = "apikey"
|
|
19
23
|
service_tier = "fast"
|
|
@@ -24,6 +28,40 @@ base_url = "https://ai.gengjiawen.com/api/openai"
|
|
|
24
28
|
wire_api = "responses"
|
|
25
29
|
`
|
|
26
30
|
|
|
31
|
+
function isTomlTable(value: unknown): value is TomlTable {
|
|
32
|
+
return (
|
|
33
|
+
value !== undefined &&
|
|
34
|
+
typeof value === 'object' &&
|
|
35
|
+
!Array.isArray(value) &&
|
|
36
|
+
!(value instanceof Date)
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function mergeTomlTables(
|
|
41
|
+
existingConfig: TomlTable,
|
|
42
|
+
templateConfig: TomlTable
|
|
43
|
+
): TomlTable {
|
|
44
|
+
const mergedConfig: TomlTable = { ...existingConfig }
|
|
45
|
+
|
|
46
|
+
for (const [key, templateValue] of Object.entries(templateConfig)) {
|
|
47
|
+
const existingValue = mergedConfig[key]
|
|
48
|
+
|
|
49
|
+
mergedConfig[key] =
|
|
50
|
+
isTomlTable(existingValue) && isTomlTable(templateValue)
|
|
51
|
+
? mergeTomlTables(existingValue, templateValue)
|
|
52
|
+
: templateValue
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return mergedConfig
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getMergedCodexConfig(existingContent: string): string {
|
|
59
|
+
const existingConfig = TOML.parse(existingContent) as TomlTable
|
|
60
|
+
const templateConfig = TOML.parse(CODEX_CONFIG_TOML_TEMPLATE) as TomlTable
|
|
61
|
+
|
|
62
|
+
return TOML.stringify(mergeTomlTables(existingConfig, templateConfig))
|
|
63
|
+
}
|
|
64
|
+
|
|
27
65
|
/** Write Codex config.toml and auth.json */
|
|
28
66
|
export function writeCodexConfig(apiKey: string): {
|
|
29
67
|
configPath: string
|
|
@@ -33,7 +71,10 @@ export function writeCodexConfig(apiKey: string): {
|
|
|
33
71
|
ensureDir(configDir)
|
|
34
72
|
|
|
35
73
|
const configPath = path.join(configDir, 'config.toml')
|
|
36
|
-
fs.
|
|
74
|
+
const configContent = fs.existsSync(configPath)
|
|
75
|
+
? getMergedCodexConfig(fs.readFileSync(configPath, 'utf8'))
|
|
76
|
+
: CODEX_CONFIG_TOML_TEMPLATE
|
|
77
|
+
fs.writeFileSync(configPath, configContent)
|
|
37
78
|
|
|
38
79
|
const authPath = path.join(configDir, 'auth.json')
|
|
39
80
|
const authContent = JSON.stringify({ OPENAI_API_KEY: apiKey }, null, 2)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gengjiawen/os-init",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.18.
|
|
4
|
+
"version": "1.18.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"bin": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@gengjiawen/unzip-url": "^1.1.0",
|
|
22
|
+
"@iarna/toml": "^2.2.5",
|
|
22
23
|
"commander": "^12.1.0",
|
|
23
24
|
"execa": "^8.0.1",
|
|
24
25
|
"ip": "^2.0.1",
|