@gengjiawen/os-init 1.26.0 → 1.26.2
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 +16 -0
- package/README.md +13 -5
- package/bin/bin.js +34 -11
- package/build/clash.d.ts +8 -0
- package/build/{mihomo.js → clash.js} +30 -31
- package/build/codex.js +2 -2
- package/build/index.d.ts +2 -1
- package/build/index.js +6 -4
- package/build/setup-env.d.ts +5 -0
- package/build/setup-env.js +132 -0
- package/libs/{mihomo.test.ts → clash.test.ts} +23 -21
- package/libs/{mihomo.ts → clash.ts} +37 -38
- package/libs/codex.test.ts +11 -0
- package/libs/codex.ts +2 -2
- package/libs/index.ts +5 -2
- package/libs/setup-env.test.ts +85 -0
- package/libs/setup-env.ts +172 -0
- package/macOS-init.md +10 -31
- package/package.json +4 -10
- package/build/mihomo.d.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.26.2](https://github.com/gengjiawen/os-init/compare/v1.26.1...v1.26.2) (2026-06-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* set codex reasoning effort to high ([0211fab](https://github.com/gengjiawen/os-init/commit/0211fab79a984ba7b12ead089ce80aa3cf1116d8))
|
|
9
|
+
|
|
10
|
+
## [1.26.1](https://github.com/gengjiawen/os-init/compare/v1.26.0...v1.26.1) (2026-06-05)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* source bashrc from bash_profile on macOS ([8f5c9ae](https://github.com/gengjiawen/os-init/commit/8f5c9ae43e122766399d7a8584b91afabf5b9b7b))
|
|
16
|
+
* update vulnerable dependencies ([88eb62b](https://github.com/gengjiawen/os-init/commit/88eb62b2ce5706823c87f1dd1d827b10461a42c1))
|
|
17
|
+
* use dot nameservers for clash ([1b72d01](https://github.com/gengjiawen/os-init/commit/1b72d0138487173252d2b7ec295727317b4a8d34))
|
|
18
|
+
|
|
3
19
|
## [1.26.0](https://github.com/gengjiawen/os-init/compare/v1.25.0...v1.26.0) (2026-05-25)
|
|
4
20
|
|
|
5
21
|
|
package/README.md
CHANGED
|
@@ -90,21 +90,29 @@ Use a custom Cursor state database path when needed:
|
|
|
90
90
|
pnpx @gengjiawen/os-init disable-ts-extension --db "$HOME/Library/Application Support/Cursor/User/globalStorage/state.vscdb"
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
###
|
|
93
|
+
### Setup Environment Variables
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pnpx @gengjiawen/os-init setup-env
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Writes PNPM_HOME, RUSTUP_HOME, CARGO_HOME, and PATH entries (brew, cargo, pnpm, jsvu, yarn) to `~/.bashrc`. Automatically detects brew prefix per platform and only adds the rustup stable toolchain bin on macOS. On macOS, it also creates or updates `~/.bash_profile` so Bash login shells load `~/.bashrc`. Idempotent — safe to run multiple times.
|
|
100
|
+
|
|
101
|
+
### Generate Clash Config
|
|
94
102
|
|
|
95
103
|
```bash
|
|
96
104
|
pnpx @gengjiawen/os-init set-clash
|
|
97
105
|
pnpx @gengjiawen/os-init set-clash --download
|
|
98
|
-
pnpx @gengjiawen/os-init set-clash --target ~/
|
|
106
|
+
pnpx @gengjiawen/os-init set-clash --target ~/clash/config.yml
|
|
99
107
|
```
|
|
100
108
|
|
|
101
|
-
Generates a
|
|
109
|
+
Generates a Clash `config.yml` from the built-in template. This command will:
|
|
102
110
|
|
|
103
111
|
- Write `./config.yml` in the current directory by default
|
|
104
|
-
- Download the
|
|
112
|
+
- Download the Clash binary to the config directory when `--download` is set
|
|
105
113
|
- Support a custom output path with `-t, --target <path>`
|
|
106
114
|
|
|
107
|
-
After generating the config, you can keep
|
|
115
|
+
After generating the config, you can keep Clash running with pm2:
|
|
108
116
|
|
|
109
117
|
```bash
|
|
110
118
|
pm2 start mihomo --name mihomo -- -f /absolute/path/to/config.yml && pm2 save
|
package/bin/bin.js
CHANGED
|
@@ -14,9 +14,10 @@ const {
|
|
|
14
14
|
writeRaycastConfig,
|
|
15
15
|
setupDevEnvironment,
|
|
16
16
|
setupAndroidEnvironment,
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
writeClashConfig,
|
|
18
|
+
downloadClashBinary,
|
|
19
19
|
disableCursorTypescriptExtension,
|
|
20
|
+
setupEnv,
|
|
20
21
|
} = require('../build')
|
|
21
22
|
const { appendFishImportScript } = require('../build/fish-shell-utils')
|
|
22
23
|
|
|
@@ -262,30 +263,52 @@ program
|
|
|
262
263
|
}
|
|
263
264
|
})
|
|
264
265
|
|
|
266
|
+
program
|
|
267
|
+
.command('setup-env')
|
|
268
|
+
.description(
|
|
269
|
+
'setup environment variables in .bashrc (PATH, PNPM_HOME, CARGO_HOME, RUSTUP_HOME); on macOS ensure .bash_profile sources it'
|
|
270
|
+
)
|
|
271
|
+
.action(async () => {
|
|
272
|
+
try {
|
|
273
|
+
const { bashrcPath, bashProfilePath, changed } = setupEnv()
|
|
274
|
+
console.log(
|
|
275
|
+
changed
|
|
276
|
+
? `Environment variables written to: ${bashrcPath}`
|
|
277
|
+
: `Environment variables already configured in: ${bashrcPath}`
|
|
278
|
+
)
|
|
279
|
+
if (bashProfilePath) {
|
|
280
|
+
console.log(`Bash profile configured at: ${bashProfilePath}`)
|
|
281
|
+
}
|
|
282
|
+
} catch (err) {
|
|
283
|
+
console.error('Failed to setup environment:', err.message)
|
|
284
|
+
process.exit(1)
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
|
|
265
288
|
program
|
|
266
289
|
.command('set-clash')
|
|
267
|
-
.description('generate clash
|
|
268
|
-
.option('-t, --target <path>', 'Target path for
|
|
269
|
-
.option('--download', 'Download
|
|
290
|
+
.description('generate clash config.yml in current directory')
|
|
291
|
+
.option('-t, --target <path>', 'Target path for clash config.yml')
|
|
292
|
+
.option('--download', 'Download Clash binary to the config directory')
|
|
270
293
|
.action(async (options) => {
|
|
271
294
|
try {
|
|
272
|
-
const { configPath } =
|
|
295
|
+
const { configPath } = writeClashConfig(options.target)
|
|
273
296
|
const resolvedConfigPath = path.resolve(configPath)
|
|
274
297
|
let mihomoCommand = 'mihomo'
|
|
275
298
|
|
|
276
299
|
if (options.download) {
|
|
277
|
-
const { binaryPath, downloadUrl, version } = await
|
|
300
|
+
const { binaryPath, downloadUrl, version } = await downloadClashBinary(
|
|
278
301
|
path.dirname(resolvedConfigPath)
|
|
279
302
|
)
|
|
280
303
|
mihomoCommand = path.resolve(binaryPath)
|
|
281
|
-
console.log(`
|
|
282
|
-
console.log(`
|
|
283
|
-
console.log(`
|
|
304
|
+
console.log(`Clash download URL: ${downloadUrl}`)
|
|
305
|
+
console.log(`Clash version: ${version}`)
|
|
306
|
+
console.log(`Clash binary downloaded to: ${binaryPath}`)
|
|
284
307
|
}
|
|
285
308
|
|
|
286
309
|
const pm2Command = `pm2 start ${shellEscape(mihomoCommand)} --name mihomo -- -f ${shellEscape(resolvedConfigPath)} && pm2 save`
|
|
287
310
|
console.log(`Clash config written to: ${configPath}`)
|
|
288
|
-
console.log('Run
|
|
311
|
+
console.log('Run Clash with pm2:')
|
|
289
312
|
console.log(` ${pm2Command}`)
|
|
290
313
|
} catch (err) {
|
|
291
314
|
console.error('Failed to generate Clash config:', err.message)
|
package/build/clash.d.ts
ADDED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.downloadClashBinary = downloadClashBinary;
|
|
4
|
+
exports.writeClashConfig = writeClashConfig;
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const os = require("os");
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const zlib_1 = require("zlib");
|
|
9
9
|
const unzip_url_1 = require("@gengjiawen/unzip-url");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
|
-
const
|
|
11
|
+
const CLASH_CONFIG_TEMPLATE = `mixed-port: 7890
|
|
12
12
|
mode: rule
|
|
13
13
|
log-level: info
|
|
14
14
|
dns:
|
|
@@ -18,11 +18,10 @@ dns:
|
|
|
18
18
|
- 1.1.1.1
|
|
19
19
|
- 223.5.5.5
|
|
20
20
|
- 119.29.29.29
|
|
21
|
-
# Regular domain queries use these upstream DNS servers.
|
|
22
|
-
# system:// reads DNS servers from the operating system.
|
|
21
|
+
# Regular domain queries use these DoT upstream DNS servers plus system DNS.
|
|
23
22
|
nameserver:
|
|
24
|
-
-
|
|
25
|
-
-
|
|
23
|
+
- tls://dns.alidns.com:853
|
|
24
|
+
- tls://dns.google:853
|
|
26
25
|
- system://
|
|
27
26
|
sniffer:
|
|
28
27
|
enable: true
|
|
@@ -59,11 +58,11 @@ rules:
|
|
|
59
58
|
# - GEOIP,CN,DIRECT
|
|
60
59
|
- MATCH,PROXY
|
|
61
60
|
`;
|
|
62
|
-
const
|
|
63
|
-
function
|
|
61
|
+
const CLASH_LATEST_RELEASE_API_URL = 'https://api.github.com/repos/MetaCubeX/mihomo/releases/latest';
|
|
62
|
+
function getClashBinaryFilename(platform = process.platform) {
|
|
64
63
|
return platform === 'win32' ? 'mihomo.exe' : 'mihomo';
|
|
65
64
|
}
|
|
66
|
-
function
|
|
65
|
+
function getClashPlatformToken(platform = process.platform) {
|
|
67
66
|
switch (platform) {
|
|
68
67
|
case 'linux':
|
|
69
68
|
return 'linux';
|
|
@@ -72,10 +71,10 @@ function getMihomoPlatformToken(platform = process.platform) {
|
|
|
72
71
|
case 'win32':
|
|
73
72
|
return 'windows';
|
|
74
73
|
default:
|
|
75
|
-
throw new Error(`Unsupported platform for
|
|
74
|
+
throw new Error(`Unsupported platform for Clash download: ${platform}`);
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
function
|
|
77
|
+
function getClashArchTokens(arch = process.arch) {
|
|
79
78
|
switch (arch) {
|
|
80
79
|
case 'x64':
|
|
81
80
|
return ['amd64'];
|
|
@@ -86,10 +85,10 @@ function getMihomoArchTokens(arch = process.arch) {
|
|
|
86
85
|
case 'ia32':
|
|
87
86
|
return ['386'];
|
|
88
87
|
default:
|
|
89
|
-
throw new Error(`Unsupported architecture for
|
|
88
|
+
throw new Error(`Unsupported architecture for Clash download: ${arch}`);
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
|
-
function
|
|
91
|
+
function getClashCpuLevelTokens(platform = process.platform, arch = process.arch) {
|
|
93
92
|
if (platform !== 'linux' && platform !== 'darwin') {
|
|
94
93
|
return [];
|
|
95
94
|
}
|
|
@@ -98,10 +97,10 @@ function getMihomoCpuLevelTokens(platform = process.platform, arch = process.arc
|
|
|
98
97
|
}
|
|
99
98
|
return ['v3', 'v2', 'v1'];
|
|
100
99
|
}
|
|
101
|
-
function
|
|
102
|
-
const platformToken =
|
|
103
|
-
const archTokens =
|
|
104
|
-
const cpuLevelTokens =
|
|
100
|
+
function findClashAsset(assets, platform = process.platform, arch = process.arch) {
|
|
101
|
+
const platformToken = getClashPlatformToken(platform);
|
|
102
|
+
const archTokens = getClashArchTokens(arch);
|
|
103
|
+
const cpuLevelTokens = getClashCpuLevelTokens(platform, arch);
|
|
105
104
|
const extension = platform === 'win32' ? '.zip' : '.gz';
|
|
106
105
|
const candidates = assets.filter((asset) => asset.name.startsWith(`mihomo-${platformToken}-`) &&
|
|
107
106
|
asset.name.endsWith(extension));
|
|
@@ -136,7 +135,7 @@ function findMihomoAsset(assets, platform = process.platform, arch = process.arc
|
|
|
136
135
|
return fallbackMatches[0];
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
|
-
throw new Error(`No
|
|
138
|
+
throw new Error(`No Clash binary found for platform ${platform} and architecture ${arch}.`);
|
|
140
139
|
}
|
|
141
140
|
function findFileRecursively(rootDir, matcher) {
|
|
142
141
|
const entries = fs.readdirSync(rootDir, { withFileTypes: true });
|
|
@@ -154,30 +153,30 @@ function findFileRecursively(rootDir, matcher) {
|
|
|
154
153
|
}
|
|
155
154
|
return null;
|
|
156
155
|
}
|
|
157
|
-
async function
|
|
158
|
-
const response = await fetch(
|
|
156
|
+
async function fetchClashLatestRelease() {
|
|
157
|
+
const response = await fetch(CLASH_LATEST_RELEASE_API_URL, {
|
|
159
158
|
headers: {
|
|
160
159
|
Accept: 'application/vnd.github+json',
|
|
161
160
|
'User-Agent': '@gengjiawen/os-init',
|
|
162
161
|
},
|
|
163
162
|
});
|
|
164
163
|
if (!response.ok) {
|
|
165
|
-
throw new Error(`Failed to fetch
|
|
164
|
+
throw new Error(`Failed to fetch Clash release metadata: ${response.status} ${response.statusText}`);
|
|
166
165
|
}
|
|
167
166
|
return (await response.json());
|
|
168
167
|
}
|
|
169
|
-
async function
|
|
168
|
+
async function downloadClashBinary(targetDir) {
|
|
170
169
|
(0, utils_1.ensureDir)(targetDir);
|
|
171
|
-
const release = await
|
|
172
|
-
const asset =
|
|
173
|
-
const binaryPath = path.join(targetDir,
|
|
170
|
+
const release = await fetchClashLatestRelease();
|
|
171
|
+
const asset = findClashAsset(release.assets);
|
|
172
|
+
const binaryPath = path.join(targetDir, getClashBinaryFilename());
|
|
174
173
|
if (process.platform === 'win32') {
|
|
175
|
-
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-
|
|
174
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-clash-'));
|
|
176
175
|
try {
|
|
177
176
|
await (0, unzip_url_1.unzip)(asset.browser_download_url, tempDir);
|
|
178
177
|
const extractedBinary = findFileRecursively(tempDir, /^mihomo.*\.exe$/i);
|
|
179
178
|
if (!extractedBinary) {
|
|
180
|
-
throw new Error(`
|
|
179
|
+
throw new Error(`Clash executable was not found in asset ${asset.name}.`);
|
|
181
180
|
}
|
|
182
181
|
fs.copyFileSync(extractedBinary, binaryPath);
|
|
183
182
|
}
|
|
@@ -193,7 +192,7 @@ async function downloadMihomoBinary(targetDir) {
|
|
|
193
192
|
},
|
|
194
193
|
});
|
|
195
194
|
if (!response.ok) {
|
|
196
|
-
throw new Error(`Failed to download
|
|
195
|
+
throw new Error(`Failed to download Clash binary: ${response.status} ${response.statusText}`);
|
|
197
196
|
}
|
|
198
197
|
const compressedBinary = Buffer.from(await response.arrayBuffer());
|
|
199
198
|
fs.writeFileSync(binaryPath, (0, zlib_1.gunzipSync)(compressedBinary));
|
|
@@ -205,9 +204,9 @@ async function downloadMihomoBinary(targetDir) {
|
|
|
205
204
|
version: release.tag_name,
|
|
206
205
|
};
|
|
207
206
|
}
|
|
208
|
-
function
|
|
207
|
+
function writeClashConfig(targetPath) {
|
|
209
208
|
const configPath = targetPath || path.join(process.cwd(), 'config.yml');
|
|
210
209
|
(0, utils_1.ensureDir)(path.dirname(configPath));
|
|
211
|
-
fs.writeFileSync(configPath,
|
|
210
|
+
fs.writeFileSync(configPath, CLASH_CONFIG_TEMPLATE);
|
|
212
211
|
return { configPath };
|
|
213
212
|
}
|
package/build/codex.js
CHANGED
|
@@ -15,8 +15,8 @@ function getCodexConfigDir() {
|
|
|
15
15
|
function getCodexConfigTomlTemplate() {
|
|
16
16
|
return `model_provider = "jw"
|
|
17
17
|
model = "gpt-5.5"
|
|
18
|
-
model_reasoning_effort = "
|
|
19
|
-
plan_mode_reasoning_effort = "
|
|
18
|
+
model_reasoning_effort = "high"
|
|
19
|
+
plan_mode_reasoning_effort = "high"
|
|
20
20
|
model_auto_compact_token_limit = 131072
|
|
21
21
|
disable_response_storage = true
|
|
22
22
|
preferred_auth_method = "apikey"
|
package/build/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ export { writeOpencodeConfig, installOpencodeDeps } from './opencode';
|
|
|
7
7
|
export { writeAllAgentsConfig, installAllAgentsDeps } from './all-agents';
|
|
8
8
|
export { setupDevEnvironment } from './dev-setup';
|
|
9
9
|
export { setupAndroidEnvironment } from './android-setup';
|
|
10
|
-
export {
|
|
10
|
+
export { writeClashConfig, downloadClashBinary } from './clash';
|
|
11
|
+
export { setupEnv } from './setup-env';
|
|
11
12
|
export { CURSOR_TYPESCRIPT_EXTENSION_ID, disableCursorTypescriptExtension, getCursorStateDbPath, mergeDisabledExtension, } from './cursor';
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeDisabledExtension = exports.getCursorStateDbPath = exports.disableCursorTypescriptExtension = exports.CURSOR_TYPESCRIPT_EXTENSION_ID = exports.
|
|
3
|
+
exports.mergeDisabledExtension = exports.getCursorStateDbPath = exports.disableCursorTypescriptExtension = exports.CURSOR_TYPESCRIPT_EXTENSION_ID = exports.setupEnv = exports.downloadClashBinary = exports.writeClashConfig = 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");
|
|
@@ -54,9 +54,11 @@ var dev_setup_1 = require("./dev-setup");
|
|
|
54
54
|
Object.defineProperty(exports, "setupDevEnvironment", { enumerable: true, get: function () { return dev_setup_1.setupDevEnvironment; } });
|
|
55
55
|
var android_setup_1 = require("./android-setup");
|
|
56
56
|
Object.defineProperty(exports, "setupAndroidEnvironment", { enumerable: true, get: function () { return android_setup_1.setupAndroidEnvironment; } });
|
|
57
|
-
var
|
|
58
|
-
Object.defineProperty(exports, "
|
|
59
|
-
Object.defineProperty(exports, "
|
|
57
|
+
var clash_1 = require("./clash");
|
|
58
|
+
Object.defineProperty(exports, "writeClashConfig", { enumerable: true, get: function () { return clash_1.writeClashConfig; } });
|
|
59
|
+
Object.defineProperty(exports, "downloadClashBinary", { enumerable: true, get: function () { return clash_1.downloadClashBinary; } });
|
|
60
|
+
var setup_env_1 = require("./setup-env");
|
|
61
|
+
Object.defineProperty(exports, "setupEnv", { enumerable: true, get: function () { return setup_env_1.setupEnv; } });
|
|
60
62
|
var cursor_1 = require("./cursor");
|
|
61
63
|
Object.defineProperty(exports, "CURSOR_TYPESCRIPT_EXTENSION_ID", { enumerable: true, get: function () { return cursor_1.CURSOR_TYPESCRIPT_EXTENSION_ID; } });
|
|
62
64
|
Object.defineProperty(exports, "disableCursorTypescriptExtension", { enumerable: true, get: function () { return cursor_1.disableCursorTypescriptExtension; } });
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupEnv = setupEnv;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
const MARKER_START = '# ===== os-init setup-env - START =====';
|
|
8
|
+
const MARKER_END = '# ===== os-init setup-env - END =====';
|
|
9
|
+
const BASH_PROFILE_MARKER_START = '# ===== os-init setup-env bash_profile - START =====';
|
|
10
|
+
const BASH_PROFILE_MARKER_END = '# ===== os-init setup-env bash_profile - END =====';
|
|
11
|
+
function getBrewPrefix() {
|
|
12
|
+
if (process.platform === 'darwin') {
|
|
13
|
+
if (fs.existsSync('/opt/homebrew/bin/brew')) {
|
|
14
|
+
return '/opt/homebrew';
|
|
15
|
+
}
|
|
16
|
+
return '/usr/local';
|
|
17
|
+
}
|
|
18
|
+
return '/home/linuxbrew/.linuxbrew';
|
|
19
|
+
}
|
|
20
|
+
function getPnpmHome() {
|
|
21
|
+
const home = os.homedir();
|
|
22
|
+
if (process.platform === 'darwin') {
|
|
23
|
+
return path.join(home, 'Library', 'pnpm');
|
|
24
|
+
}
|
|
25
|
+
return path.join(home, '.pnpm');
|
|
26
|
+
}
|
|
27
|
+
function generateBashrcContent() {
|
|
28
|
+
const brewPrefix = getBrewPrefix();
|
|
29
|
+
const home = os.homedir();
|
|
30
|
+
const pnpmHome = getPnpmHome();
|
|
31
|
+
const cargoHome = path.join(home, '.cargo');
|
|
32
|
+
const rustupHome = path.join(home, '.rustup');
|
|
33
|
+
const pathEntries = [
|
|
34
|
+
`${brewPrefix}/bin`,
|
|
35
|
+
`${brewPrefix}/sbin`,
|
|
36
|
+
pnpmHome,
|
|
37
|
+
`${cargoHome}/bin`,
|
|
38
|
+
`${home}/.jsvu/bin`,
|
|
39
|
+
`${home}/.local/bin`,
|
|
40
|
+
`${home}/.yarn/bin`,
|
|
41
|
+
];
|
|
42
|
+
if (process.platform === 'darwin') {
|
|
43
|
+
pathEntries.push(`${rustupHome}/toolchains/stable-aarch64-apple-darwin/bin`);
|
|
44
|
+
}
|
|
45
|
+
return `${MARKER_START}
|
|
46
|
+
export PNPM_HOME="${pnpmHome}"
|
|
47
|
+
export RUSTUP_HOME="${rustupHome}"
|
|
48
|
+
export CARGO_HOME="${cargoHome}"
|
|
49
|
+
export PATH="${pathEntries.join(':')}:$PATH"
|
|
50
|
+
${MARKER_END}
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
function generateBashProfileContent() {
|
|
54
|
+
return `${BASH_PROFILE_MARKER_START}
|
|
55
|
+
if [ -f "$HOME/.bashrc" ]; then
|
|
56
|
+
. "$HOME/.bashrc"
|
|
57
|
+
fi
|
|
58
|
+
${BASH_PROFILE_MARKER_END}
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
function stripLeadingNewline(content) {
|
|
62
|
+
if (content.startsWith('\r\n')) {
|
|
63
|
+
return content.slice(2);
|
|
64
|
+
}
|
|
65
|
+
if (content.startsWith('\n')) {
|
|
66
|
+
return content.slice(1);
|
|
67
|
+
}
|
|
68
|
+
return content;
|
|
69
|
+
}
|
|
70
|
+
function bashProfileSourcesBashrc(content) {
|
|
71
|
+
return content
|
|
72
|
+
.split(/\r?\n/)
|
|
73
|
+
.some((line) => /^\s*(?:source|\.)\s+(?:"\$HOME\/\.bashrc"|'\$HOME\/\.bashrc'|\$HOME\/\.bashrc|~\/\.bashrc)(?:\s|$)/.test(line));
|
|
74
|
+
}
|
|
75
|
+
function ensureMacBashProfileSourcesBashrc(home) {
|
|
76
|
+
const bashProfilePath = path.join(home, '.bash_profile');
|
|
77
|
+
let currentContent = '';
|
|
78
|
+
if (fs.existsSync(bashProfilePath)) {
|
|
79
|
+
currentContent = fs.readFileSync(bashProfilePath, 'utf-8');
|
|
80
|
+
}
|
|
81
|
+
if (currentContent.includes(BASH_PROFILE_MARKER_START) ||
|
|
82
|
+
bashProfileSourcesBashrc(currentContent)) {
|
|
83
|
+
return { bashProfilePath, changed: false };
|
|
84
|
+
}
|
|
85
|
+
const newBlock = (currentContent && !currentContent.endsWith('\n') ? '\n' : '') +
|
|
86
|
+
generateBashProfileContent();
|
|
87
|
+
fs.appendFileSync(bashProfilePath, newBlock);
|
|
88
|
+
return { bashProfilePath, changed: true };
|
|
89
|
+
}
|
|
90
|
+
function setupEnv() {
|
|
91
|
+
const home = os.homedir();
|
|
92
|
+
const bashrcPath = path.join(home, '.bashrc');
|
|
93
|
+
let currentContent = '';
|
|
94
|
+
if (fs.existsSync(bashrcPath)) {
|
|
95
|
+
currentContent = fs.readFileSync(bashrcPath, 'utf-8');
|
|
96
|
+
}
|
|
97
|
+
if (currentContent.includes(MARKER_START)) {
|
|
98
|
+
const startIdx = currentContent.indexOf(MARKER_START);
|
|
99
|
+
const endIdx = currentContent.indexOf(MARKER_END, startIdx);
|
|
100
|
+
if (endIdx !== -1) {
|
|
101
|
+
const before = currentContent.slice(0, startIdx);
|
|
102
|
+
const after = stripLeadingNewline(currentContent.slice(endIdx + MARKER_END.length));
|
|
103
|
+
const newBlock = generateBashrcContent();
|
|
104
|
+
const nextContent = before + newBlock + after;
|
|
105
|
+
const bashrcChanged = nextContent !== currentContent;
|
|
106
|
+
if (bashrcChanged) {
|
|
107
|
+
fs.writeFileSync(bashrcPath, nextContent);
|
|
108
|
+
}
|
|
109
|
+
if (process.platform === 'darwin') {
|
|
110
|
+
const profileResult = ensureMacBashProfileSourcesBashrc(home);
|
|
111
|
+
return {
|
|
112
|
+
bashrcPath,
|
|
113
|
+
bashProfilePath: profileResult.bashProfilePath,
|
|
114
|
+
changed: bashrcChanged || profileResult.changed,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return { bashrcPath, changed: bashrcChanged };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const newBlock = (currentContent && !currentContent.endsWith('\n') ? '\n' : '') +
|
|
121
|
+
generateBashrcContent();
|
|
122
|
+
fs.appendFileSync(bashrcPath, newBlock);
|
|
123
|
+
if (process.platform === 'darwin') {
|
|
124
|
+
const profileResult = ensureMacBashProfileSourcesBashrc(home);
|
|
125
|
+
return {
|
|
126
|
+
bashrcPath,
|
|
127
|
+
bashProfilePath: profileResult.bashProfilePath,
|
|
128
|
+
changed: true,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return { bashrcPath, changed: true };
|
|
132
|
+
}
|
|
@@ -12,9 +12,9 @@ jest.mock('@gengjiawen/unzip-url', () => ({
|
|
|
12
12
|
}))
|
|
13
13
|
|
|
14
14
|
import { unzip } from '@gengjiawen/unzip-url'
|
|
15
|
-
import {
|
|
15
|
+
import { downloadClashBinary, writeClashConfig } from './clash'
|
|
16
16
|
|
|
17
|
-
describe('
|
|
17
|
+
describe('writeClashConfig', () => {
|
|
18
18
|
let tempHome: string
|
|
19
19
|
let tempCwd: string
|
|
20
20
|
let homedirSpy: jest.SpiedFunction<typeof os.homedir>
|
|
@@ -40,8 +40,8 @@ describe('writeMihomoConfig', () => {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
beforeEach(() => {
|
|
43
|
-
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-
|
|
44
|
-
tempCwd = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-
|
|
43
|
+
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-clash-'))
|
|
44
|
+
tempCwd = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-clash-cwd-'))
|
|
45
45
|
homedirSpy = jest.spyOn(os, 'homedir').mockReturnValue(tempHome)
|
|
46
46
|
cwdSpy = jest.spyOn(process, 'cwd').mockReturnValue(tempCwd)
|
|
47
47
|
originalPlatformDescriptor = Object.getOwnPropertyDescriptor(
|
|
@@ -78,8 +78,8 @@ describe('writeMihomoConfig', () => {
|
|
|
78
78
|
fs.rmSync(tempCwd, { recursive: true, force: true })
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
-
test('writes default
|
|
82
|
-
const result =
|
|
81
|
+
test('writes default clash config.yml to current directory', () => {
|
|
82
|
+
const result = writeClashConfig()
|
|
83
83
|
|
|
84
84
|
expect(result.configPath).toBe(path.join(tempCwd, 'config.yml'))
|
|
85
85
|
|
|
@@ -87,6 +87,8 @@ describe('writeMihomoConfig', () => {
|
|
|
87
87
|
expect(content).toContain('mixed-port: 7890')
|
|
88
88
|
expect(content).toContain('mode: rule')
|
|
89
89
|
expect(content).toContain('nameserver:')
|
|
90
|
+
expect(content).toContain('- tls://dns.alidns.com:853')
|
|
91
|
+
expect(content).toContain('- tls://dns.google:853')
|
|
90
92
|
expect(content).toContain('- system://')
|
|
91
93
|
expect(content).toContain('sniff:')
|
|
92
94
|
expect(content).toContain('TLS:')
|
|
@@ -114,18 +116,18 @@ describe('writeMihomoConfig', () => {
|
|
|
114
116
|
expect(content).toContain('- MATCH,PROXY')
|
|
115
117
|
})
|
|
116
118
|
|
|
117
|
-
test('writes
|
|
118
|
-
const customPath = path.join(tempHome, 'custom', '
|
|
119
|
-
const result =
|
|
119
|
+
test('writes clash config to custom target path', () => {
|
|
120
|
+
const customPath = path.join(tempHome, 'custom', 'clash.yml')
|
|
121
|
+
const result = writeClashConfig(customPath)
|
|
120
122
|
|
|
121
123
|
expect(result.configPath).toBe(customPath)
|
|
122
124
|
expect(fs.existsSync(customPath)).toBe(true)
|
|
123
125
|
})
|
|
124
126
|
|
|
125
|
-
test('downloads linux
|
|
126
|
-
const targetDir = path.join(tempCwd, '
|
|
127
|
+
test('downloads linux clash binary and prefers v3 without go tag', async () => {
|
|
128
|
+
const targetDir = path.join(tempCwd, 'clash-bin')
|
|
127
129
|
const fetchMock = jest.fn()
|
|
128
|
-
const binaryContent = Buffer.from('#!/bin/sh\necho
|
|
130
|
+
const binaryContent = Buffer.from('#!/bin/sh\necho clash\n', 'utf8')
|
|
129
131
|
|
|
130
132
|
setProcessRuntime('linux', 'x64')
|
|
131
133
|
|
|
@@ -175,7 +177,7 @@ describe('writeMihomoConfig', () => {
|
|
|
175
177
|
|
|
176
178
|
global.fetch = fetchMock as unknown as typeof global.fetch
|
|
177
179
|
|
|
178
|
-
const result = await
|
|
180
|
+
const result = await downloadClashBinary(targetDir)
|
|
179
181
|
|
|
180
182
|
expect(result.version).toBe('v1.19.13')
|
|
181
183
|
expect(result.binaryPath).toBe(path.join(targetDir, 'mihomo'))
|
|
@@ -187,10 +189,10 @@ describe('writeMihomoConfig', () => {
|
|
|
187
189
|
expect(fetchMock).toHaveBeenCalledTimes(2)
|
|
188
190
|
})
|
|
189
191
|
|
|
190
|
-
test('downloads darwin
|
|
191
|
-
const targetDir = path.join(tempCwd, '
|
|
192
|
+
test('downloads darwin clash binary and selects darwin asset', async () => {
|
|
193
|
+
const targetDir = path.join(tempCwd, 'clash-darwin-bin')
|
|
192
194
|
const fetchMock = jest.fn()
|
|
193
|
-
const binaryContent = Buffer.from('#!/bin/sh\necho
|
|
195
|
+
const binaryContent = Buffer.from('#!/bin/sh\necho clash-darwin\n', 'utf8')
|
|
194
196
|
|
|
195
197
|
setProcessRuntime('darwin', 'x64')
|
|
196
198
|
|
|
@@ -230,7 +232,7 @@ describe('writeMihomoConfig', () => {
|
|
|
230
232
|
|
|
231
233
|
global.fetch = fetchMock as unknown as typeof global.fetch
|
|
232
234
|
|
|
233
|
-
const result = await
|
|
235
|
+
const result = await downloadClashBinary(targetDir)
|
|
234
236
|
|
|
235
237
|
expect(result.version).toBe('v1.19.13')
|
|
236
238
|
expect(result.binaryPath).toBe(path.join(targetDir, 'mihomo'))
|
|
@@ -242,10 +244,10 @@ describe('writeMihomoConfig', () => {
|
|
|
242
244
|
expect(fetchMock).toHaveBeenCalledTimes(2)
|
|
243
245
|
})
|
|
244
246
|
|
|
245
|
-
test('downloads windows
|
|
246
|
-
const targetDir = path.join(tempCwd, '
|
|
247
|
+
test('downloads windows clash binary and extracts zip asset', async () => {
|
|
248
|
+
const targetDir = path.join(tempCwd, 'clash-windows-bin')
|
|
247
249
|
const fetchMock = jest.fn()
|
|
248
|
-
const binaryContent = Buffer.from('windows-
|
|
250
|
+
const binaryContent = Buffer.from('windows-clash', 'utf8')
|
|
249
251
|
|
|
250
252
|
setProcessRuntime('win32', 'x64')
|
|
251
253
|
|
|
@@ -281,7 +283,7 @@ describe('writeMihomoConfig', () => {
|
|
|
281
283
|
|
|
282
284
|
global.fetch = fetchMock as unknown as typeof global.fetch
|
|
283
285
|
|
|
284
|
-
const result = await
|
|
286
|
+
const result = await downloadClashBinary(targetDir)
|
|
285
287
|
|
|
286
288
|
expect(result.version).toBe('v1.19.13')
|
|
287
289
|
expect(result.binaryPath).toBe(path.join(targetDir, 'mihomo.exe'))
|
|
@@ -5,7 +5,7 @@ import { gunzipSync } from 'zlib'
|
|
|
5
5
|
import { unzip } from '@gengjiawen/unzip-url'
|
|
6
6
|
import { ensureDir } from './utils'
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const CLASH_CONFIG_TEMPLATE = `mixed-port: 7890
|
|
9
9
|
mode: rule
|
|
10
10
|
log-level: info
|
|
11
11
|
dns:
|
|
@@ -15,11 +15,10 @@ dns:
|
|
|
15
15
|
- 1.1.1.1
|
|
16
16
|
- 223.5.5.5
|
|
17
17
|
- 119.29.29.29
|
|
18
|
-
# Regular domain queries use these upstream DNS servers.
|
|
19
|
-
# system:// reads DNS servers from the operating system.
|
|
18
|
+
# Regular domain queries use these DoT upstream DNS servers plus system DNS.
|
|
20
19
|
nameserver:
|
|
21
|
-
-
|
|
22
|
-
-
|
|
20
|
+
- tls://dns.alidns.com:853
|
|
21
|
+
- tls://dns.google:853
|
|
23
22
|
- system://
|
|
24
23
|
sniffer:
|
|
25
24
|
enable: true
|
|
@@ -57,24 +56,24 @@ rules:
|
|
|
57
56
|
- MATCH,PROXY
|
|
58
57
|
`
|
|
59
58
|
|
|
60
|
-
const
|
|
59
|
+
const CLASH_LATEST_RELEASE_API_URL =
|
|
61
60
|
'https://api.github.com/repos/MetaCubeX/mihomo/releases/latest'
|
|
62
61
|
|
|
63
|
-
interface
|
|
62
|
+
interface ClashReleaseAsset {
|
|
64
63
|
name: string
|
|
65
64
|
browser_download_url: string
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
interface
|
|
67
|
+
interface ClashRelease {
|
|
69
68
|
tag_name: string
|
|
70
|
-
assets:
|
|
69
|
+
assets: ClashReleaseAsset[]
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
function
|
|
72
|
+
function getClashBinaryFilename(platform = process.platform): string {
|
|
74
73
|
return platform === 'win32' ? 'mihomo.exe' : 'mihomo'
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
function
|
|
76
|
+
function getClashPlatformToken(platform = process.platform): string {
|
|
78
77
|
switch (platform) {
|
|
79
78
|
case 'linux':
|
|
80
79
|
return 'linux'
|
|
@@ -83,11 +82,11 @@ function getMihomoPlatformToken(platform = process.platform): string {
|
|
|
83
82
|
case 'win32':
|
|
84
83
|
return 'windows'
|
|
85
84
|
default:
|
|
86
|
-
throw new Error(`Unsupported platform for
|
|
85
|
+
throw new Error(`Unsupported platform for Clash download: ${platform}`)
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
function
|
|
89
|
+
function getClashArchTokens(arch = process.arch): string[] {
|
|
91
90
|
switch (arch) {
|
|
92
91
|
case 'x64':
|
|
93
92
|
return ['amd64']
|
|
@@ -98,11 +97,11 @@ function getMihomoArchTokens(arch = process.arch): string[] {
|
|
|
98
97
|
case 'ia32':
|
|
99
98
|
return ['386']
|
|
100
99
|
default:
|
|
101
|
-
throw new Error(`Unsupported architecture for
|
|
100
|
+
throw new Error(`Unsupported architecture for Clash download: ${arch}`)
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
function
|
|
104
|
+
function getClashCpuLevelTokens(
|
|
106
105
|
platform = process.platform,
|
|
107
106
|
arch = process.arch
|
|
108
107
|
): string[] {
|
|
@@ -117,14 +116,14 @@ function getMihomoCpuLevelTokens(
|
|
|
117
116
|
return ['v3', 'v2', 'v1']
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
function
|
|
121
|
-
assets:
|
|
119
|
+
function findClashAsset(
|
|
120
|
+
assets: ClashReleaseAsset[],
|
|
122
121
|
platform = process.platform,
|
|
123
122
|
arch = process.arch
|
|
124
|
-
):
|
|
125
|
-
const platformToken =
|
|
126
|
-
const archTokens =
|
|
127
|
-
const cpuLevelTokens =
|
|
123
|
+
): ClashReleaseAsset {
|
|
124
|
+
const platformToken = getClashPlatformToken(platform)
|
|
125
|
+
const archTokens = getClashArchTokens(arch)
|
|
126
|
+
const cpuLevelTokens = getClashCpuLevelTokens(platform, arch)
|
|
128
127
|
const extension = platform === 'win32' ? '.zip' : '.gz'
|
|
129
128
|
|
|
130
129
|
const candidates = assets.filter(
|
|
@@ -134,8 +133,8 @@ function findMihomoAsset(
|
|
|
134
133
|
)
|
|
135
134
|
|
|
136
135
|
const sortCandidates = (
|
|
137
|
-
left:
|
|
138
|
-
right:
|
|
136
|
+
left: ClashReleaseAsset,
|
|
137
|
+
right: ClashReleaseAsset
|
|
139
138
|
): number => {
|
|
140
139
|
const leftHasGoTag = left.name.includes('-go')
|
|
141
140
|
const rightHasGoTag = right.name.includes('-go')
|
|
@@ -181,7 +180,7 @@ function findMihomoAsset(
|
|
|
181
180
|
}
|
|
182
181
|
|
|
183
182
|
throw new Error(
|
|
184
|
-
`No
|
|
183
|
+
`No Clash binary found for platform ${platform} and architecture ${arch}.`
|
|
185
184
|
)
|
|
186
185
|
}
|
|
187
186
|
|
|
@@ -205,8 +204,8 @@ function findFileRecursively(rootDir: string, matcher: RegExp): string | null {
|
|
|
205
204
|
return null
|
|
206
205
|
}
|
|
207
206
|
|
|
208
|
-
async function
|
|
209
|
-
const response = await fetch(
|
|
207
|
+
async function fetchClashLatestRelease(): Promise<ClashRelease> {
|
|
208
|
+
const response = await fetch(CLASH_LATEST_RELEASE_API_URL, {
|
|
210
209
|
headers: {
|
|
211
210
|
Accept: 'application/vnd.github+json',
|
|
212
211
|
'User-Agent': '@gengjiawen/os-init',
|
|
@@ -215,26 +214,26 @@ async function fetchMihomoLatestRelease(): Promise<MihomoRelease> {
|
|
|
215
214
|
|
|
216
215
|
if (!response.ok) {
|
|
217
216
|
throw new Error(
|
|
218
|
-
`Failed to fetch
|
|
217
|
+
`Failed to fetch Clash release metadata: ${response.status} ${response.statusText}`
|
|
219
218
|
)
|
|
220
219
|
}
|
|
221
220
|
|
|
222
|
-
return (await response.json()) as
|
|
221
|
+
return (await response.json()) as ClashRelease
|
|
223
222
|
}
|
|
224
223
|
|
|
225
|
-
export async function
|
|
224
|
+
export async function downloadClashBinary(targetDir: string): Promise<{
|
|
226
225
|
binaryPath: string
|
|
227
226
|
downloadUrl: string
|
|
228
227
|
version: string
|
|
229
228
|
}> {
|
|
230
229
|
ensureDir(targetDir)
|
|
231
230
|
|
|
232
|
-
const release = await
|
|
233
|
-
const asset =
|
|
234
|
-
const binaryPath = path.join(targetDir,
|
|
231
|
+
const release = await fetchClashLatestRelease()
|
|
232
|
+
const asset = findClashAsset(release.assets)
|
|
233
|
+
const binaryPath = path.join(targetDir, getClashBinaryFilename())
|
|
235
234
|
|
|
236
235
|
if (process.platform === 'win32') {
|
|
237
|
-
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-
|
|
236
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-clash-'))
|
|
238
237
|
|
|
239
238
|
try {
|
|
240
239
|
await unzip(asset.browser_download_url, tempDir)
|
|
@@ -242,7 +241,7 @@ export async function downloadMihomoBinary(targetDir: string): Promise<{
|
|
|
242
241
|
|
|
243
242
|
if (!extractedBinary) {
|
|
244
243
|
throw new Error(
|
|
245
|
-
`
|
|
244
|
+
`Clash executable was not found in asset ${asset.name}.`
|
|
246
245
|
)
|
|
247
246
|
}
|
|
248
247
|
|
|
@@ -260,7 +259,7 @@ export async function downloadMihomoBinary(targetDir: string): Promise<{
|
|
|
260
259
|
|
|
261
260
|
if (!response.ok) {
|
|
262
261
|
throw new Error(
|
|
263
|
-
`Failed to download
|
|
262
|
+
`Failed to download Clash binary: ${response.status} ${response.statusText}`
|
|
264
263
|
)
|
|
265
264
|
}
|
|
266
265
|
|
|
@@ -276,11 +275,11 @@ export async function downloadMihomoBinary(targetDir: string): Promise<{
|
|
|
276
275
|
}
|
|
277
276
|
}
|
|
278
277
|
|
|
279
|
-
/** Write
|
|
280
|
-
export function
|
|
278
|
+
/** Write Clash config.yml */
|
|
279
|
+
export function writeClashConfig(targetPath?: string): { configPath: string } {
|
|
281
280
|
const configPath = targetPath || path.join(process.cwd(), 'config.yml')
|
|
282
281
|
ensureDir(path.dirname(configPath))
|
|
283
|
-
fs.writeFileSync(configPath,
|
|
282
|
+
fs.writeFileSync(configPath, CLASH_CONFIG_TEMPLATE)
|
|
284
283
|
|
|
285
284
|
return { configPath }
|
|
286
285
|
}
|
package/libs/codex.test.ts
CHANGED
|
@@ -34,6 +34,17 @@ describe('writeCodexConfig', () => {
|
|
|
34
34
|
expect(fs.existsSync(result.authPath)).toBe(true)
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
+
test('writes codex reasoning efforts as high', () => {
|
|
38
|
+
const result = writeCodexConfig('test-api-key')
|
|
39
|
+
const config = TOML.parse(fs.readFileSync(result.configPath, 'utf8')) as {
|
|
40
|
+
model_reasoning_effort: string
|
|
41
|
+
plan_mode_reasoning_effort: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
expect(config.model_reasoning_effort).toBe('high')
|
|
45
|
+
expect(config.plan_mode_reasoning_effort).toBe('high')
|
|
46
|
+
})
|
|
47
|
+
|
|
37
48
|
test('merges template keys and keeps custom config', () => {
|
|
38
49
|
const configDir = path.join(tempHome, '.codex')
|
|
39
50
|
fs.mkdirSync(configDir, { recursive: true })
|
package/libs/codex.ts
CHANGED
|
@@ -17,8 +17,8 @@ function getCodexConfigDir(): string {
|
|
|
17
17
|
function getCodexConfigTomlTemplate(): string {
|
|
18
18
|
return `model_provider = "jw"
|
|
19
19
|
model = "gpt-5.5"
|
|
20
|
-
model_reasoning_effort = "
|
|
21
|
-
plan_mode_reasoning_effort = "
|
|
20
|
+
model_reasoning_effort = "high"
|
|
21
|
+
plan_mode_reasoning_effort = "high"
|
|
22
22
|
model_auto_compact_token_limit = 131072
|
|
23
23
|
disable_response_storage = true
|
|
24
24
|
preferred_auth_method = "apikey"
|
package/libs/index.ts
CHANGED
|
@@ -64,8 +64,11 @@ export { setupDevEnvironment } from './dev-setup'
|
|
|
64
64
|
// Re-export android-setup functionality
|
|
65
65
|
export { setupAndroidEnvironment } from './android-setup'
|
|
66
66
|
|
|
67
|
-
// Re-export
|
|
68
|
-
export {
|
|
67
|
+
// Re-export clash functionality
|
|
68
|
+
export { writeClashConfig, downloadClashBinary } from './clash'
|
|
69
|
+
|
|
70
|
+
// Re-export setup-env functionality
|
|
71
|
+
export { setupEnv } from './setup-env'
|
|
69
72
|
|
|
70
73
|
// Re-export Cursor functionality
|
|
71
74
|
export {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as fs from 'fs'
|
|
2
|
+
import * as os from 'os'
|
|
3
|
+
import * as path from 'path'
|
|
4
|
+
import { setupEnv } from './setup-env'
|
|
5
|
+
|
|
6
|
+
describe('setupEnv', () => {
|
|
7
|
+
let tempHome: string
|
|
8
|
+
let homedirSpy: jest.SpiedFunction<typeof os.homedir>
|
|
9
|
+
let platformDescriptor: PropertyDescriptor | undefined
|
|
10
|
+
|
|
11
|
+
function mockPlatform(platform: NodeJS.Platform): void {
|
|
12
|
+
Object.defineProperty(process, 'platform', {
|
|
13
|
+
value: platform,
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-env-'))
|
|
19
|
+
homedirSpy = jest.spyOn(os, 'homedir').mockReturnValue(tempHome)
|
|
20
|
+
platformDescriptor = Object.getOwnPropertyDescriptor(process, 'platform')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
homedirSpy.mockRestore()
|
|
25
|
+
if (platformDescriptor) {
|
|
26
|
+
Object.defineProperty(process, 'platform', platformDescriptor)
|
|
27
|
+
}
|
|
28
|
+
fs.rmSync(tempHome, { recursive: true, force: true })
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('writes environment block to bashrc on Linux', () => {
|
|
32
|
+
mockPlatform('linux')
|
|
33
|
+
|
|
34
|
+
const result = setupEnv()
|
|
35
|
+
const bashrcPath = path.join(tempHome, '.bashrc')
|
|
36
|
+
|
|
37
|
+
expect(result).toEqual({
|
|
38
|
+
bashrcPath,
|
|
39
|
+
changed: true,
|
|
40
|
+
})
|
|
41
|
+
expect(fs.readFileSync(bashrcPath, 'utf-8')).toContain('export PNPM_HOME=')
|
|
42
|
+
expect(fs.existsSync(path.join(tempHome, '.bash_profile'))).toBe(false)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('creates macOS bash profile that sources bashrc', () => {
|
|
46
|
+
mockPlatform('darwin')
|
|
47
|
+
|
|
48
|
+
const result = setupEnv()
|
|
49
|
+
const bashProfilePath = path.join(tempHome, '.bash_profile')
|
|
50
|
+
|
|
51
|
+
expect(result).toEqual({
|
|
52
|
+
bashrcPath: path.join(tempHome, '.bashrc'),
|
|
53
|
+
bashProfilePath,
|
|
54
|
+
changed: true,
|
|
55
|
+
})
|
|
56
|
+
expect(fs.readFileSync(bashProfilePath, 'utf-8')).toContain(
|
|
57
|
+
'. "$HOME/.bashrc"'
|
|
58
|
+
)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('does not duplicate an existing macOS bashrc source line', () => {
|
|
62
|
+
mockPlatform('darwin')
|
|
63
|
+
const bashProfilePath = path.join(tempHome, '.bash_profile')
|
|
64
|
+
const bashProfileContent = 'source ~/.bashrc\n'
|
|
65
|
+
fs.writeFileSync(bashProfilePath, bashProfileContent)
|
|
66
|
+
|
|
67
|
+
const result = setupEnv()
|
|
68
|
+
|
|
69
|
+
expect(result.bashProfilePath).toBe(bashProfilePath)
|
|
70
|
+
expect(fs.readFileSync(bashProfilePath, 'utf-8')).toBe(bashProfileContent)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('second macOS run reports unchanged files', () => {
|
|
74
|
+
mockPlatform('darwin')
|
|
75
|
+
|
|
76
|
+
setupEnv()
|
|
77
|
+
const result = setupEnv()
|
|
78
|
+
|
|
79
|
+
expect(result).toEqual({
|
|
80
|
+
bashrcPath: path.join(tempHome, '.bashrc'),
|
|
81
|
+
bashProfilePath: path.join(tempHome, '.bash_profile'),
|
|
82
|
+
changed: false,
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
})
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as fs from 'fs'
|
|
2
|
+
import * as path from 'path'
|
|
3
|
+
import * as os from 'os'
|
|
4
|
+
|
|
5
|
+
const MARKER_START = '# ===== os-init setup-env - START ====='
|
|
6
|
+
const MARKER_END = '# ===== os-init setup-env - END ====='
|
|
7
|
+
const BASH_PROFILE_MARKER_START =
|
|
8
|
+
'# ===== os-init setup-env bash_profile - START ====='
|
|
9
|
+
const BASH_PROFILE_MARKER_END =
|
|
10
|
+
'# ===== os-init setup-env bash_profile - END ====='
|
|
11
|
+
|
|
12
|
+
function getBrewPrefix(): string {
|
|
13
|
+
if (process.platform === 'darwin') {
|
|
14
|
+
if (fs.existsSync('/opt/homebrew/bin/brew')) {
|
|
15
|
+
return '/opt/homebrew'
|
|
16
|
+
}
|
|
17
|
+
return '/usr/local'
|
|
18
|
+
}
|
|
19
|
+
return '/home/linuxbrew/.linuxbrew'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getPnpmHome(): string {
|
|
23
|
+
const home = os.homedir()
|
|
24
|
+
if (process.platform === 'darwin') {
|
|
25
|
+
return path.join(home, 'Library', 'pnpm')
|
|
26
|
+
}
|
|
27
|
+
return path.join(home, '.pnpm')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function generateBashrcContent(): string {
|
|
31
|
+
const brewPrefix = getBrewPrefix()
|
|
32
|
+
const home = os.homedir()
|
|
33
|
+
const pnpmHome = getPnpmHome()
|
|
34
|
+
const cargoHome = path.join(home, '.cargo')
|
|
35
|
+
const rustupHome = path.join(home, '.rustup')
|
|
36
|
+
|
|
37
|
+
const pathEntries = [
|
|
38
|
+
`${brewPrefix}/bin`,
|
|
39
|
+
`${brewPrefix}/sbin`,
|
|
40
|
+
pnpmHome,
|
|
41
|
+
`${cargoHome}/bin`,
|
|
42
|
+
`${home}/.jsvu/bin`,
|
|
43
|
+
`${home}/.local/bin`,
|
|
44
|
+
`${home}/.yarn/bin`,
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
if (process.platform === 'darwin') {
|
|
48
|
+
pathEntries.push(`${rustupHome}/toolchains/stable-aarch64-apple-darwin/bin`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return `${MARKER_START}
|
|
52
|
+
export PNPM_HOME="${pnpmHome}"
|
|
53
|
+
export RUSTUP_HOME="${rustupHome}"
|
|
54
|
+
export CARGO_HOME="${cargoHome}"
|
|
55
|
+
export PATH="${pathEntries.join(':')}:$PATH"
|
|
56
|
+
${MARKER_END}
|
|
57
|
+
`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function generateBashProfileContent(): string {
|
|
61
|
+
return `${BASH_PROFILE_MARKER_START}
|
|
62
|
+
if [ -f "$HOME/.bashrc" ]; then
|
|
63
|
+
. "$HOME/.bashrc"
|
|
64
|
+
fi
|
|
65
|
+
${BASH_PROFILE_MARKER_END}
|
|
66
|
+
`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function stripLeadingNewline(content: string): string {
|
|
70
|
+
if (content.startsWith('\r\n')) {
|
|
71
|
+
return content.slice(2)
|
|
72
|
+
}
|
|
73
|
+
if (content.startsWith('\n')) {
|
|
74
|
+
return content.slice(1)
|
|
75
|
+
}
|
|
76
|
+
return content
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function bashProfileSourcesBashrc(content: string): boolean {
|
|
80
|
+
return content
|
|
81
|
+
.split(/\r?\n/)
|
|
82
|
+
.some((line) =>
|
|
83
|
+
/^\s*(?:source|\.)\s+(?:"\$HOME\/\.bashrc"|'\$HOME\/\.bashrc'|\$HOME\/\.bashrc|~\/\.bashrc)(?:\s|$)/.test(
|
|
84
|
+
line
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function ensureMacBashProfileSourcesBashrc(home: string): {
|
|
90
|
+
bashProfilePath: string
|
|
91
|
+
changed: boolean
|
|
92
|
+
} {
|
|
93
|
+
const bashProfilePath = path.join(home, '.bash_profile')
|
|
94
|
+
let currentContent = ''
|
|
95
|
+
|
|
96
|
+
if (fs.existsSync(bashProfilePath)) {
|
|
97
|
+
currentContent = fs.readFileSync(bashProfilePath, 'utf-8')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
currentContent.includes(BASH_PROFILE_MARKER_START) ||
|
|
102
|
+
bashProfileSourcesBashrc(currentContent)
|
|
103
|
+
) {
|
|
104
|
+
return { bashProfilePath, changed: false }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const newBlock =
|
|
108
|
+
(currentContent && !currentContent.endsWith('\n') ? '\n' : '') +
|
|
109
|
+
generateBashProfileContent()
|
|
110
|
+
fs.appendFileSync(bashProfilePath, newBlock)
|
|
111
|
+
|
|
112
|
+
return { bashProfilePath, changed: true }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function setupEnv(): {
|
|
116
|
+
bashrcPath: string
|
|
117
|
+
bashProfilePath?: string
|
|
118
|
+
changed: boolean
|
|
119
|
+
} {
|
|
120
|
+
const home = os.homedir()
|
|
121
|
+
const bashrcPath = path.join(home, '.bashrc')
|
|
122
|
+
|
|
123
|
+
let currentContent = ''
|
|
124
|
+
if (fs.existsSync(bashrcPath)) {
|
|
125
|
+
currentContent = fs.readFileSync(bashrcPath, 'utf-8')
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (currentContent.includes(MARKER_START)) {
|
|
129
|
+
// Replace existing block
|
|
130
|
+
const startIdx = currentContent.indexOf(MARKER_START)
|
|
131
|
+
const endIdx = currentContent.indexOf(MARKER_END, startIdx)
|
|
132
|
+
if (endIdx !== -1) {
|
|
133
|
+
const before = currentContent.slice(0, startIdx)
|
|
134
|
+
const after = stripLeadingNewline(
|
|
135
|
+
currentContent.slice(endIdx + MARKER_END.length)
|
|
136
|
+
)
|
|
137
|
+
const newBlock = generateBashrcContent()
|
|
138
|
+
const nextContent = before + newBlock + after
|
|
139
|
+
const bashrcChanged = nextContent !== currentContent
|
|
140
|
+
if (bashrcChanged) {
|
|
141
|
+
fs.writeFileSync(bashrcPath, nextContent)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (process.platform === 'darwin') {
|
|
145
|
+
const profileResult = ensureMacBashProfileSourcesBashrc(home)
|
|
146
|
+
return {
|
|
147
|
+
bashrcPath,
|
|
148
|
+
bashProfilePath: profileResult.bashProfilePath,
|
|
149
|
+
changed: bashrcChanged || profileResult.changed,
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return { bashrcPath, changed: bashrcChanged }
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Append new block
|
|
157
|
+
const newBlock =
|
|
158
|
+
(currentContent && !currentContent.endsWith('\n') ? '\n' : '') +
|
|
159
|
+
generateBashrcContent()
|
|
160
|
+
fs.appendFileSync(bashrcPath, newBlock)
|
|
161
|
+
|
|
162
|
+
if (process.platform === 'darwin') {
|
|
163
|
+
const profileResult = ensureMacBashProfileSourcesBashrc(home)
|
|
164
|
+
return {
|
|
165
|
+
bashrcPath,
|
|
166
|
+
bashProfilePath: profileResult.bashProfilePath,
|
|
167
|
+
changed: true,
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return { bashrcPath, changed: true }
|
|
172
|
+
}
|
package/macOS-init.md
CHANGED
|
@@ -12,51 +12,30 @@ sudo /usr/sbin/DevToolsSecurity -enable
|
|
|
12
12
|
```bash
|
|
13
13
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
|
|
14
14
|
brew install git
|
|
15
|
-
brew install node
|
|
16
15
|
brew install fish
|
|
17
16
|
brew install go
|
|
17
|
+
brew install n
|
|
18
18
|
brew install rustup-init
|
|
19
|
-
brew install
|
|
19
|
+
brew install cursor
|
|
20
20
|
brew install google-chrome
|
|
21
21
|
brew install jetbrains-toolbox
|
|
22
22
|
brew install omnidisksweeper
|
|
23
23
|
brew install git-lfs
|
|
24
24
|
brew install jordanbaird-ice
|
|
25
|
+
brew install raycast
|
|
26
|
+
sudo n lts
|
|
27
|
+
rustup-init -y
|
|
25
28
|
sudo git lfs install --system
|
|
26
|
-
npm i -g pnpm yarn && pnpm setup
|
|
29
|
+
npm i -g pnpm yarn && pnpm setup && SHELL=fish pnpm setup && source ~/.bashrc
|
|
30
|
+
pnpx @gengjiawen/os-init set-fish
|
|
31
|
+
pnpx @gengjiawen/os-init disable-ts-extension
|
|
32
|
+
pnpx @gengjiawen/os-init setup-env
|
|
27
33
|
pnpm i -g vite 7zip-bin-full
|
|
28
34
|
sudo ln -s "$(NODE_PATH="$(pnpm root -g)" node -p "require('7zip-bin-full').path7z")" /usr/local/bin/7z
|
|
29
35
|
```
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
Fish config
|
|
33
|
-
```
|
|
34
|
-
egrep "^export " ~/.bashrc | while read e
|
|
35
|
-
set var (echo $e | sed -E "s/^export ([A-Za-z_0-9]+)=(.*)\$/\1/")
|
|
36
|
-
set value (echo $e | sed -E "s/^export ([A-Za-z_0-9]+)=(.*)\$/\2/")
|
|
37
|
-
|
|
38
|
-
# remove surrounding quotes if existing
|
|
39
|
-
set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/")
|
|
40
|
-
|
|
41
|
-
if test $var = "PATH"
|
|
42
|
-
# replace ":" by spaces. this is how PATH looks for Fish
|
|
43
|
-
set value (echo $value | sed -E "s/:/ /g")
|
|
44
|
-
|
|
45
|
-
# use eval because we need to expand the value
|
|
46
|
-
eval set -xg $var $value
|
|
47
|
-
|
|
48
|
-
continue
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# evaluate variables. we can use eval because we most likely just used "$var"
|
|
52
|
-
set value (eval echo $value)
|
|
53
|
-
|
|
54
|
-
#echo "set -xg '$var' '$value' (via '$e')"
|
|
55
|
-
set -xg $var $value
|
|
56
|
-
end
|
|
57
|
-
```
|
|
58
|
-
|
|
59
37
|
make homebrew path first
|
|
38
|
+
|
|
60
39
|
```bash
|
|
61
40
|
fish_add_path /opt/homebrew/opt
|
|
62
41
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gengjiawen/os-init",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.26.
|
|
4
|
+
"version": "1.26.2",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"bin": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"execa": "^8.0.1",
|
|
25
25
|
"ip": "^2.0.1",
|
|
26
26
|
"jsonc-parser": "^3.3.1",
|
|
27
|
-
"yaml": "^2.
|
|
27
|
+
"yaml": "^2.9.0"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
@@ -43,20 +43,14 @@
|
|
|
43
43
|
"cpy-cli": "^6.0.0",
|
|
44
44
|
"husky": "9.1.6",
|
|
45
45
|
"jest": "30.3.0",
|
|
46
|
-
"lint-staged": "^15.
|
|
46
|
+
"lint-staged": "^15.5.2",
|
|
47
47
|
"nodemon": "3.1.4",
|
|
48
48
|
"prettier": "3.5.3",
|
|
49
49
|
"rimraf": "6.1.3",
|
|
50
50
|
"ts-jest": "29.4.9",
|
|
51
|
-
"ts-node": "^10.9.
|
|
51
|
+
"ts-node": "^10.9.2",
|
|
52
52
|
"typescript": "5.6.3"
|
|
53
53
|
},
|
|
54
|
-
"pnpm": {
|
|
55
|
-
"overrides": {
|
|
56
|
-
"minimatch@3.1.2": "3.1.3",
|
|
57
|
-
"minimatch@9.0.5": "9.0.9"
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
54
|
"husky": {
|
|
61
55
|
"hooks": {
|
|
62
56
|
"pre-commit": "lint-staged"
|
package/build/mihomo.d.ts
DELETED