@gengjiawen/os-init 1.25.0 → 1.26.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 +14 -0
- package/build/all-agents.js +14 -3
- package/build/claude-code.js +21 -4
- package/build/mihomo.js +9 -3
- package/build/utils.d.ts +3 -0
- package/build/utils.js +41 -5
- package/libs/all-agents.test.ts +14 -5
- package/libs/all-agents.ts +21 -4
- package/libs/claude-code.test.ts +47 -3
- package/libs/claude-code.ts +29 -5
- package/libs/mihomo.test.ts +6 -0
- package/libs/mihomo.ts +9 -3
- package/libs/utils.ts +51 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.26.0](https://github.com/gengjiawen/os-init/compare/v1.25.0...v1.26.0) (2026-05-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* disable claude attribution header ([143f161](https://github.com/gengjiawen/os-init/commit/143f161d71f5b1b4984f3a6513081c8b66b6aa4b))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* add system DNS to mihomo template ([37c844e](https://github.com/gengjiawen/os-init/commit/37c844e36837b191af00092c1538b10351b87a37))
|
|
14
|
+
* persist claude pnpm build approval ([dd10751](https://github.com/gengjiawen/os-init/commit/dd1075168f9e82a35b31049e2f61a64ba009812b))
|
|
15
|
+
* update mihomo sniffer config ([54df04d](https://github.com/gengjiawen/os-init/commit/54df04d48219041c0b4ab867cb80150f81639396))
|
|
16
|
+
|
|
3
17
|
## [1.25.0](https://github.com/gengjiawen/os-init/compare/v1.24.0...v1.25.0) (2026-05-19)
|
|
4
18
|
|
|
5
19
|
|
package/build/all-agents.js
CHANGED
|
@@ -24,10 +24,21 @@ async function installAllAgentsDeps(options = {}) {
|
|
|
24
24
|
if (options.full) {
|
|
25
25
|
packages.push('opencode-ai');
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
27
|
+
const pnpmVersion = await (0, utils_1.getCommandVersion)('pnpm');
|
|
28
|
+
if (pnpmVersion !== null) {
|
|
29
29
|
console.log('pnpm detected. Installing agent dependencies with pnpm...');
|
|
30
|
-
|
|
30
|
+
const supportsAllowBuild = (0, utils_1.pnpmSupportsAllowBuild)(pnpmVersion);
|
|
31
|
+
if (supportsAllowBuild) {
|
|
32
|
+
await (0, utils_1.allowPnpmGlobalBuild)('@anthropic-ai/claude-code');
|
|
33
|
+
}
|
|
34
|
+
await (0, execa_1.execa)('pnpm', [
|
|
35
|
+
...(supportsAllowBuild
|
|
36
|
+
? ['--allow-build=@anthropic-ai/claude-code']
|
|
37
|
+
: []),
|
|
38
|
+
'add',
|
|
39
|
+
'-g',
|
|
40
|
+
...packages,
|
|
41
|
+
], {
|
|
31
42
|
stdio: 'inherit',
|
|
32
43
|
env: utils_1.PNPM_INSTALL_ENV,
|
|
33
44
|
});
|
package/build/claude-code.js
CHANGED
|
@@ -11,6 +11,7 @@ const utils_1 = require("./utils");
|
|
|
11
11
|
const CLAUDE_BASE_URL = 'https://ai.gengjiawen.com/api/claude/';
|
|
12
12
|
const CLAUDE_AUTO_COMPACT_WINDOW = '128000';
|
|
13
13
|
const CLAUDE_DISABLE_1M_CONTEXT = '1';
|
|
14
|
+
const CLAUDE_ATTRIBUTION_HEADER = '0';
|
|
14
15
|
function getClaudeSettingsDir() {
|
|
15
16
|
return path.join(os.homedir(), '.claude');
|
|
16
17
|
}
|
|
@@ -34,7 +35,8 @@ const CLAUDE_SETTINGS_TEMPLATE = `{
|
|
|
34
35
|
"ANTHROPIC_BASE_URL": "${CLAUDE_BASE_URL}",
|
|
35
36
|
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
36
37
|
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "${CLAUDE_AUTO_COMPACT_WINDOW}",
|
|
37
|
-
"CLAUDE_CODE_DISABLE_1M_CONTEXT": "${CLAUDE_DISABLE_1M_CONTEXT}"
|
|
38
|
+
"CLAUDE_CODE_DISABLE_1M_CONTEXT": "${CLAUDE_DISABLE_1M_CONTEXT}",
|
|
39
|
+
"CLAUDE_CODE_ATTRIBUTION_HEADER": "${CLAUDE_ATTRIBUTION_HEADER}"
|
|
38
40
|
},
|
|
39
41
|
"includeCoAuthoredBy": false,
|
|
40
42
|
"apiKeyHelper": "echo 'API_KEY_PLACEHOLDER'",
|
|
@@ -76,6 +78,10 @@ function writeVSCodeClaudePluginConfig(apiKey) {
|
|
|
76
78
|
name: 'CLAUDE_CODE_DISABLE_1M_CONTEXT',
|
|
77
79
|
value: CLAUDE_DISABLE_1M_CONTEXT,
|
|
78
80
|
},
|
|
81
|
+
{
|
|
82
|
+
name: 'CLAUDE_CODE_ATTRIBUTION_HEADER',
|
|
83
|
+
value: CLAUDE_ATTRIBUTION_HEADER,
|
|
84
|
+
},
|
|
79
85
|
], {
|
|
80
86
|
formattingOptions: {
|
|
81
87
|
insertSpaces: true,
|
|
@@ -101,10 +107,21 @@ function writeClaudeConfig(apiKey) {
|
|
|
101
107
|
}
|
|
102
108
|
async function installDeps() {
|
|
103
109
|
const packages = ['@anthropic-ai/claude-code'];
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
110
|
+
const pnpmVersion = await (0, utils_1.getCommandVersion)('pnpm');
|
|
111
|
+
if (pnpmVersion !== null) {
|
|
106
112
|
console.log('pnpm detected. Installing dependencies with pnpm...');
|
|
107
|
-
|
|
113
|
+
const supportsAllowBuild = (0, utils_1.pnpmSupportsAllowBuild)(pnpmVersion);
|
|
114
|
+
if (supportsAllowBuild) {
|
|
115
|
+
await (0, utils_1.allowPnpmGlobalBuild)('@anthropic-ai/claude-code');
|
|
116
|
+
}
|
|
117
|
+
await (0, execa_1.execa)('pnpm', [
|
|
118
|
+
...(supportsAllowBuild
|
|
119
|
+
? ['--allow-build=@anthropic-ai/claude-code']
|
|
120
|
+
: []),
|
|
121
|
+
'add',
|
|
122
|
+
'-g',
|
|
123
|
+
...packages,
|
|
124
|
+
], {
|
|
108
125
|
stdio: 'inherit',
|
|
109
126
|
env: utils_1.PNPM_INSTALL_ENV,
|
|
110
127
|
});
|
package/build/mihomo.js
CHANGED
|
@@ -18,11 +18,17 @@ 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.
|
|
23
|
+
nameserver:
|
|
24
|
+
- 1.1.1.1
|
|
25
|
+
- 223.5.5.5
|
|
26
|
+
- system://
|
|
21
27
|
sniffer:
|
|
22
28
|
enable: true
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
sniff:
|
|
30
|
+
TLS:
|
|
31
|
+
HTTP:
|
|
26
32
|
tun:
|
|
27
33
|
enable: true
|
|
28
34
|
stack: system
|
package/build/utils.d.ts
CHANGED
|
@@ -2,4 +2,7 @@ export declare const PNPM_INSTALL_ENV: {
|
|
|
2
2
|
PNPM_CONFIG_ENABLE_PRE_POST_SCRIPTS: string;
|
|
3
3
|
};
|
|
4
4
|
export declare function ensureDir(dirPath: string): void;
|
|
5
|
+
export declare function getCommandVersion(command: string): Promise<string | null>;
|
|
6
|
+
export declare function pnpmSupportsAllowBuild(version: string): boolean;
|
|
7
|
+
export declare function allowPnpmGlobalBuild(packageName: string): Promise<void>;
|
|
5
8
|
export declare function commandExists(command: string): Promise<boolean>;
|
package/build/utils.js
CHANGED
|
@@ -2,24 +2,60 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PNPM_INSTALL_ENV = void 0;
|
|
4
4
|
exports.ensureDir = ensureDir;
|
|
5
|
+
exports.getCommandVersion = getCommandVersion;
|
|
6
|
+
exports.pnpmSupportsAllowBuild = pnpmSupportsAllowBuild;
|
|
7
|
+
exports.allowPnpmGlobalBuild = allowPnpmGlobalBuild;
|
|
5
8
|
exports.commandExists = commandExists;
|
|
6
9
|
const fs = require("fs");
|
|
10
|
+
const path = require("path");
|
|
7
11
|
const execa_1 = require("execa");
|
|
12
|
+
const yaml = require("yaml");
|
|
8
13
|
exports.PNPM_INSTALL_ENV = {
|
|
9
14
|
PNPM_CONFIG_ENABLE_PRE_POST_SCRIPTS: 'true',
|
|
10
15
|
};
|
|
11
16
|
function ensureDir(dirPath) {
|
|
12
17
|
fs.mkdirSync(dirPath, { recursive: true });
|
|
13
18
|
}
|
|
14
|
-
async function
|
|
19
|
+
async function getCommandVersion(command) {
|
|
15
20
|
try {
|
|
16
|
-
const { failed } = await (0, execa_1.execa)(command, ['--version'], {
|
|
17
|
-
stdio: '
|
|
21
|
+
const { failed, stdout } = await (0, execa_1.execa)(command, ['--version'], {
|
|
22
|
+
stdio: 'pipe',
|
|
18
23
|
reject: false,
|
|
19
24
|
});
|
|
20
|
-
return
|
|
25
|
+
return failed ? null : stdout.trim();
|
|
21
26
|
}
|
|
22
27
|
catch (error) {
|
|
23
|
-
return
|
|
28
|
+
return null;
|
|
24
29
|
}
|
|
25
30
|
}
|
|
31
|
+
function pnpmSupportsAllowBuild(version) {
|
|
32
|
+
const major = Number.parseInt(version, 10);
|
|
33
|
+
return Number.isInteger(major) && major >= 10;
|
|
34
|
+
}
|
|
35
|
+
function isRecord(value) {
|
|
36
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
37
|
+
}
|
|
38
|
+
async function allowPnpmGlobalBuild(packageName) {
|
|
39
|
+
const { stdout } = await (0, execa_1.execa)('pnpm', ['root', '-g']);
|
|
40
|
+
const globalRoot = stdout.trim();
|
|
41
|
+
if (globalRoot.length === 0) {
|
|
42
|
+
throw new Error('Unable to locate pnpm global root.');
|
|
43
|
+
}
|
|
44
|
+
ensureDir(globalRoot);
|
|
45
|
+
const workspacePath = path.join(globalRoot, 'pnpm-workspace.yaml');
|
|
46
|
+
const source = fs.existsSync(workspacePath)
|
|
47
|
+
? fs.readFileSync(workspacePath, 'utf8')
|
|
48
|
+
: '';
|
|
49
|
+
const parsed = source.trim().length > 0 ? yaml.parse(source) : {};
|
|
50
|
+
const workspace = isRecord(parsed) ? parsed : {};
|
|
51
|
+
const existingAllowBuilds = workspace.allowBuilds;
|
|
52
|
+
const allowBuilds = isRecord(existingAllowBuilds)
|
|
53
|
+
? { ...existingAllowBuilds }
|
|
54
|
+
: {};
|
|
55
|
+
allowBuilds[packageName] = true;
|
|
56
|
+
workspace.allowBuilds = allowBuilds;
|
|
57
|
+
fs.writeFileSync(workspacePath, yaml.stringify(workspace));
|
|
58
|
+
}
|
|
59
|
+
async function commandExists(command) {
|
|
60
|
+
return (await getCommandVersion(command)) !== null;
|
|
61
|
+
}
|
package/libs/all-agents.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from 'fs'
|
|
2
2
|
import * as os from 'os'
|
|
3
3
|
import * as path from 'path'
|
|
4
|
+
import * as yaml from 'yaml'
|
|
4
5
|
|
|
5
6
|
jest.mock('execa', () => ({
|
|
6
7
|
execa: jest.fn(),
|
|
@@ -50,18 +51,23 @@ describe('writeAllAgentsConfig', () => {
|
|
|
50
51
|
})
|
|
51
52
|
|
|
52
53
|
test('installs Claude and Codex in one pnpm command', async () => {
|
|
54
|
+
const pnpmGlobalRoot = path.join(tempHome, 'pnpm-global')
|
|
55
|
+
const workspacePath = path.join(pnpmGlobalRoot, 'pnpm-workspace.yaml')
|
|
56
|
+
|
|
53
57
|
execaMock
|
|
54
|
-
.mockResolvedValueOnce({ failed: false } as never)
|
|
58
|
+
.mockResolvedValueOnce({ failed: false, stdout: '10.33.2' } as never)
|
|
59
|
+
.mockResolvedValueOnce({ stdout: pnpmGlobalRoot } as never)
|
|
55
60
|
.mockResolvedValueOnce({} as never)
|
|
56
61
|
|
|
57
62
|
await installAllAgentsDeps()
|
|
58
63
|
|
|
59
64
|
expect(execaMock).toHaveBeenNthCalledWith(1, 'pnpm', ['--version'], {
|
|
60
|
-
stdio: '
|
|
65
|
+
stdio: 'pipe',
|
|
61
66
|
reject: false,
|
|
62
67
|
})
|
|
68
|
+
expect(execaMock).toHaveBeenNthCalledWith(2, 'pnpm', ['root', '-g'])
|
|
63
69
|
expect(execaMock).toHaveBeenNthCalledWith(
|
|
64
|
-
|
|
70
|
+
3,
|
|
65
71
|
'pnpm',
|
|
66
72
|
[
|
|
67
73
|
'--allow-build=@anthropic-ai/claude-code',
|
|
@@ -77,7 +83,10 @@ describe('writeAllAgentsConfig', () => {
|
|
|
77
83
|
},
|
|
78
84
|
}
|
|
79
85
|
)
|
|
80
|
-
expect(execaMock).toHaveBeenCalledTimes(
|
|
86
|
+
expect(execaMock).toHaveBeenCalledTimes(3)
|
|
87
|
+
|
|
88
|
+
const workspace = yaml.parse(fs.readFileSync(workspacePath, 'utf8'))
|
|
89
|
+
expect(workspace.allowBuilds['@anthropic-ai/claude-code']).toBe(true)
|
|
81
90
|
})
|
|
82
91
|
|
|
83
92
|
test('installs all requested agents in one npm command when pnpm is unavailable', async () => {
|
|
@@ -88,7 +97,7 @@ describe('writeAllAgentsConfig', () => {
|
|
|
88
97
|
await installAllAgentsDeps({ full: true })
|
|
89
98
|
|
|
90
99
|
expect(execaMock).toHaveBeenNthCalledWith(1, 'pnpm', ['--version'], {
|
|
91
|
-
stdio: '
|
|
100
|
+
stdio: 'pipe',
|
|
92
101
|
reject: false,
|
|
93
102
|
})
|
|
94
103
|
expect(execaMock).toHaveBeenNthCalledWith(
|
package/libs/all-agents.ts
CHANGED
|
@@ -2,7 +2,12 @@ import { writeClaudeConfig } from './claude-code'
|
|
|
2
2
|
import { writeCodexConfig } from './codex'
|
|
3
3
|
import { writeOpencodeConfig } from './opencode'
|
|
4
4
|
import { execa } from 'execa'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
allowPnpmGlobalBuild,
|
|
7
|
+
getCommandVersion,
|
|
8
|
+
pnpmSupportsAllowBuild,
|
|
9
|
+
PNPM_INSTALL_ENV,
|
|
10
|
+
} from './utils'
|
|
6
11
|
|
|
7
12
|
export interface AllAgentsOptions {
|
|
8
13
|
/** When true, also include OpenCode in the combined setup. */
|
|
@@ -44,13 +49,25 @@ export async function installAllAgentsDeps(
|
|
|
44
49
|
packages.push('opencode-ai')
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
const
|
|
52
|
+
const pnpmVersion = await getCommandVersion('pnpm')
|
|
48
53
|
|
|
49
|
-
if (
|
|
54
|
+
if (pnpmVersion !== null) {
|
|
50
55
|
console.log('pnpm detected. Installing agent dependencies with pnpm...')
|
|
56
|
+
const supportsAllowBuild = pnpmSupportsAllowBuild(pnpmVersion)
|
|
57
|
+
if (supportsAllowBuild) {
|
|
58
|
+
await allowPnpmGlobalBuild('@anthropic-ai/claude-code')
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
await execa(
|
|
52
62
|
'pnpm',
|
|
53
|
-
[
|
|
63
|
+
[
|
|
64
|
+
...(supportsAllowBuild
|
|
65
|
+
? ['--allow-build=@anthropic-ai/claude-code']
|
|
66
|
+
: []),
|
|
67
|
+
'add',
|
|
68
|
+
'-g',
|
|
69
|
+
...packages,
|
|
70
|
+
],
|
|
54
71
|
{
|
|
55
72
|
stdio: 'inherit',
|
|
56
73
|
env: PNPM_INSTALL_ENV,
|
package/libs/claude-code.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from 'fs'
|
|
2
2
|
import * as os from 'os'
|
|
3
3
|
import * as path from 'path'
|
|
4
|
+
import * as yaml from 'yaml'
|
|
4
5
|
|
|
5
6
|
jest.mock('execa', () => ({
|
|
6
7
|
execa: jest.fn(),
|
|
@@ -37,6 +38,7 @@ describe('writeClaudeConfig', () => {
|
|
|
37
38
|
let originalAppData: string | undefined
|
|
38
39
|
|
|
39
40
|
beforeEach(() => {
|
|
41
|
+
jest.clearAllMocks()
|
|
40
42
|
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-claude-'))
|
|
41
43
|
homedirSpy = jest.spyOn(os, 'homedir').mockReturnValue(tempHome)
|
|
42
44
|
originalAppData = process.env.APPDATA
|
|
@@ -80,6 +82,7 @@ describe('writeClaudeConfig', () => {
|
|
|
80
82
|
'"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "128000"'
|
|
81
83
|
)
|
|
82
84
|
expect(claudeSettings).toContain('"CLAUDE_CODE_DISABLE_1M_CONTEXT": "1"')
|
|
85
|
+
expect(claudeSettings).toContain('"CLAUDE_CODE_ATTRIBUTION_HEADER": "0"')
|
|
83
86
|
|
|
84
87
|
const vscodeSettings = fs.readFileSync(result.vscodeSettingsPath, 'utf8')
|
|
85
88
|
expect(vscodeSettings).toContain('"editor.fontSize": 14')
|
|
@@ -92,6 +95,8 @@ describe('writeClaudeConfig', () => {
|
|
|
92
95
|
expect(vscodeSettings).toContain('"CLAUDE_CODE_AUTO_COMPACT_WINDOW"')
|
|
93
96
|
expect(vscodeSettings).toContain('"128000"')
|
|
94
97
|
expect(vscodeSettings).toContain('"CLAUDE_CODE_DISABLE_1M_CONTEXT"')
|
|
98
|
+
expect(vscodeSettings).toContain('"CLAUDE_CODE_ATTRIBUTION_HEADER"')
|
|
99
|
+
expect(vscodeSettings).toContain('"0"')
|
|
95
100
|
expect(vscodeSettings).toContain('"1"')
|
|
96
101
|
expect(vscodeSettings).toContain('"test-api-key"')
|
|
97
102
|
})
|
|
@@ -108,18 +113,28 @@ describe('writeClaudeConfig', () => {
|
|
|
108
113
|
|
|
109
114
|
test('allows Claude postinstall build when installing with pnpm', async () => {
|
|
110
115
|
const execaMock = jest.mocked(execa)
|
|
116
|
+
const pnpmGlobalRoot = path.join(tempHome, 'pnpm-global')
|
|
117
|
+
const workspacePath = path.join(pnpmGlobalRoot, 'pnpm-workspace.yaml')
|
|
118
|
+
fs.mkdirSync(pnpmGlobalRoot, { recursive: true })
|
|
119
|
+
fs.writeFileSync(
|
|
120
|
+
workspacePath,
|
|
121
|
+
'allowBuilds:\n "@anthropic-ai/claude-code": false\n'
|
|
122
|
+
)
|
|
123
|
+
|
|
111
124
|
execaMock
|
|
112
|
-
.mockResolvedValueOnce({ failed: false } as never)
|
|
125
|
+
.mockResolvedValueOnce({ failed: false, stdout: '10.33.2' } as never)
|
|
126
|
+
.mockResolvedValueOnce({ stdout: pnpmGlobalRoot } as never)
|
|
113
127
|
.mockResolvedValueOnce({} as never)
|
|
114
128
|
|
|
115
129
|
await installDeps()
|
|
116
130
|
|
|
117
131
|
expect(execaMock).toHaveBeenNthCalledWith(1, 'pnpm', ['--version'], {
|
|
118
|
-
stdio: '
|
|
132
|
+
stdio: 'pipe',
|
|
119
133
|
reject: false,
|
|
120
134
|
})
|
|
135
|
+
expect(execaMock).toHaveBeenNthCalledWith(2, 'pnpm', ['root', '-g'])
|
|
121
136
|
expect(execaMock).toHaveBeenNthCalledWith(
|
|
122
|
-
|
|
137
|
+
3,
|
|
123
138
|
'pnpm',
|
|
124
139
|
[
|
|
125
140
|
'--allow-build=@anthropic-ai/claude-code',
|
|
@@ -134,6 +149,35 @@ describe('writeClaudeConfig', () => {
|
|
|
134
149
|
},
|
|
135
150
|
}
|
|
136
151
|
)
|
|
152
|
+
expect(execaMock).toHaveBeenCalledTimes(3)
|
|
153
|
+
|
|
154
|
+
const workspace = yaml.parse(fs.readFileSync(workspacePath, 'utf8'))
|
|
155
|
+
expect(workspace.allowBuilds['@anthropic-ai/claude-code']).toBe(true)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('does not pass allow-build to pnpm versions before 10', async () => {
|
|
159
|
+
const execaMock = jest.mocked(execa)
|
|
160
|
+
execaMock
|
|
161
|
+
.mockResolvedValueOnce({ failed: false, stdout: '9.15.9' } as never)
|
|
162
|
+
.mockResolvedValueOnce({} as never)
|
|
163
|
+
|
|
164
|
+
await installDeps()
|
|
165
|
+
|
|
166
|
+
expect(execaMock).toHaveBeenNthCalledWith(1, 'pnpm', ['--version'], {
|
|
167
|
+
stdio: 'pipe',
|
|
168
|
+
reject: false,
|
|
169
|
+
})
|
|
170
|
+
expect(execaMock).toHaveBeenNthCalledWith(
|
|
171
|
+
2,
|
|
172
|
+
'pnpm',
|
|
173
|
+
['add', '-g', '@anthropic-ai/claude-code'],
|
|
174
|
+
{
|
|
175
|
+
stdio: 'inherit',
|
|
176
|
+
env: {
|
|
177
|
+
PNPM_CONFIG_ENABLE_PRE_POST_SCRIPTS: 'true',
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
)
|
|
137
181
|
expect(execaMock).toHaveBeenCalledTimes(2)
|
|
138
182
|
})
|
|
139
183
|
})
|
package/libs/claude-code.ts
CHANGED
|
@@ -3,11 +3,18 @@ import * as path from 'path'
|
|
|
3
3
|
import * as os from 'os'
|
|
4
4
|
import { execa } from 'execa'
|
|
5
5
|
import { ParseError, applyEdits, modify, parse } from 'jsonc-parser'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
allowPnpmGlobalBuild,
|
|
8
|
+
ensureDir,
|
|
9
|
+
getCommandVersion,
|
|
10
|
+
pnpmSupportsAllowBuild,
|
|
11
|
+
PNPM_INSTALL_ENV,
|
|
12
|
+
} from './utils'
|
|
7
13
|
|
|
8
14
|
const CLAUDE_BASE_URL = 'https://ai.gengjiawen.com/api/claude/'
|
|
9
15
|
const CLAUDE_AUTO_COMPACT_WINDOW = '128000'
|
|
10
16
|
const CLAUDE_DISABLE_1M_CONTEXT = '1'
|
|
17
|
+
const CLAUDE_ATTRIBUTION_HEADER = '0'
|
|
11
18
|
|
|
12
19
|
/** Return Claude settings directory path */
|
|
13
20
|
function getClaudeSettingsDir(): string {
|
|
@@ -48,7 +55,8 @@ const CLAUDE_SETTINGS_TEMPLATE = `{
|
|
|
48
55
|
"ANTHROPIC_BASE_URL": "${CLAUDE_BASE_URL}",
|
|
49
56
|
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
50
57
|
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "${CLAUDE_AUTO_COMPACT_WINDOW}",
|
|
51
|
-
"CLAUDE_CODE_DISABLE_1M_CONTEXT": "${CLAUDE_DISABLE_1M_CONTEXT}"
|
|
58
|
+
"CLAUDE_CODE_DISABLE_1M_CONTEXT": "${CLAUDE_DISABLE_1M_CONTEXT}",
|
|
59
|
+
"CLAUDE_CODE_ATTRIBUTION_HEADER": "${CLAUDE_ATTRIBUTION_HEADER}"
|
|
52
60
|
},
|
|
53
61
|
"includeCoAuthoredBy": false,
|
|
54
62
|
"apiKeyHelper": "echo 'API_KEY_PLACEHOLDER'",
|
|
@@ -108,6 +116,10 @@ function writeVSCodeClaudePluginConfig(apiKey: string): {
|
|
|
108
116
|
name: 'CLAUDE_CODE_DISABLE_1M_CONTEXT',
|
|
109
117
|
value: CLAUDE_DISABLE_1M_CONTEXT,
|
|
110
118
|
},
|
|
119
|
+
{
|
|
120
|
+
name: 'CLAUDE_CODE_ATTRIBUTION_HEADER',
|
|
121
|
+
value: CLAUDE_ATTRIBUTION_HEADER,
|
|
122
|
+
},
|
|
111
123
|
],
|
|
112
124
|
{
|
|
113
125
|
formattingOptions: {
|
|
@@ -149,13 +161,25 @@ export function writeClaudeConfig(apiKey: string): {
|
|
|
149
161
|
/** Install global dependencies */
|
|
150
162
|
export async function installDeps(): Promise<void> {
|
|
151
163
|
const packages = ['@anthropic-ai/claude-code']
|
|
152
|
-
const
|
|
164
|
+
const pnpmVersion = await getCommandVersion('pnpm')
|
|
153
165
|
|
|
154
|
-
if (
|
|
166
|
+
if (pnpmVersion !== null) {
|
|
155
167
|
console.log('pnpm detected. Installing dependencies with pnpm...')
|
|
168
|
+
const supportsAllowBuild = pnpmSupportsAllowBuild(pnpmVersion)
|
|
169
|
+
if (supportsAllowBuild) {
|
|
170
|
+
await allowPnpmGlobalBuild('@anthropic-ai/claude-code')
|
|
171
|
+
}
|
|
172
|
+
|
|
156
173
|
await execa(
|
|
157
174
|
'pnpm',
|
|
158
|
-
[
|
|
175
|
+
[
|
|
176
|
+
...(supportsAllowBuild
|
|
177
|
+
? ['--allow-build=@anthropic-ai/claude-code']
|
|
178
|
+
: []),
|
|
179
|
+
'add',
|
|
180
|
+
'-g',
|
|
181
|
+
...packages,
|
|
182
|
+
],
|
|
159
183
|
{
|
|
160
184
|
stdio: 'inherit',
|
|
161
185
|
env: PNPM_INSTALL_ENV,
|
package/libs/mihomo.test.ts
CHANGED
|
@@ -86,6 +86,12 @@ describe('writeMihomoConfig', () => {
|
|
|
86
86
|
const content = fs.readFileSync(result.configPath, 'utf8')
|
|
87
87
|
expect(content).toContain('mixed-port: 7890')
|
|
88
88
|
expect(content).toContain('mode: rule')
|
|
89
|
+
expect(content).toContain('nameserver:')
|
|
90
|
+
expect(content).toContain('- system://')
|
|
91
|
+
expect(content).toContain('sniff:')
|
|
92
|
+
expect(content).toContain('TLS:')
|
|
93
|
+
expect(content).toContain('HTTP:')
|
|
94
|
+
expect(content).not.toContain('sniffing:')
|
|
89
95
|
expect(content).toContain('type: socks5')
|
|
90
96
|
expect(content).toContain('name: socks5-proxy')
|
|
91
97
|
expect(content).toContain('server: your.ip')
|
package/libs/mihomo.ts
CHANGED
|
@@ -15,11 +15,17 @@ 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.
|
|
20
|
+
nameserver:
|
|
21
|
+
- 1.1.1.1
|
|
22
|
+
- 223.5.5.5
|
|
23
|
+
- system://
|
|
18
24
|
sniffer:
|
|
19
25
|
enable: true
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
sniff:
|
|
27
|
+
TLS:
|
|
28
|
+
HTTP:
|
|
23
29
|
tun:
|
|
24
30
|
enable: true
|
|
25
31
|
stack: system
|
package/libs/utils.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as fs from 'fs'
|
|
2
|
+
import * as path from 'path'
|
|
2
3
|
import { execa } from 'execa'
|
|
4
|
+
import * as yaml from 'yaml'
|
|
3
5
|
|
|
4
6
|
export const PNPM_INSTALL_ENV = {
|
|
5
7
|
PNPM_CONFIG_ENABLE_PRE_POST_SCRIPTS: 'true',
|
|
@@ -10,17 +12,58 @@ export function ensureDir(dirPath: string): void {
|
|
|
10
12
|
fs.mkdirSync(dirPath, { recursive: true })
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
export async function getCommandVersion(
|
|
16
|
+
command: string
|
|
17
|
+
): Promise<string | null> {
|
|
15
18
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
stdio: 'ignore',
|
|
19
|
+
const { failed, stdout } = await execa(command, ['--version'], {
|
|
20
|
+
stdio: 'pipe',
|
|
19
21
|
reject: false,
|
|
20
22
|
})
|
|
21
|
-
return
|
|
23
|
+
return failed ? null : stdout.trim()
|
|
22
24
|
} catch (error) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function pnpmSupportsAllowBuild(version: string): boolean {
|
|
30
|
+
const major = Number.parseInt(version, 10)
|
|
31
|
+
return Number.isInteger(major) && major >= 10
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
35
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Persistently allow a package's pnpm install/build script in the global workspace. */
|
|
39
|
+
export async function allowPnpmGlobalBuild(packageName: string): Promise<void> {
|
|
40
|
+
const { stdout } = await execa('pnpm', ['root', '-g'])
|
|
41
|
+
const globalRoot = stdout.trim()
|
|
42
|
+
|
|
43
|
+
if (globalRoot.length === 0) {
|
|
44
|
+
throw new Error('Unable to locate pnpm global root.')
|
|
25
45
|
}
|
|
46
|
+
|
|
47
|
+
ensureDir(globalRoot)
|
|
48
|
+
|
|
49
|
+
const workspacePath = path.join(globalRoot, 'pnpm-workspace.yaml')
|
|
50
|
+
const source = fs.existsSync(workspacePath)
|
|
51
|
+
? fs.readFileSync(workspacePath, 'utf8')
|
|
52
|
+
: ''
|
|
53
|
+
const parsed = source.trim().length > 0 ? yaml.parse(source) : {}
|
|
54
|
+
const workspace = isRecord(parsed) ? parsed : {}
|
|
55
|
+
const existingAllowBuilds = workspace.allowBuilds
|
|
56
|
+
const allowBuilds = isRecord(existingAllowBuilds)
|
|
57
|
+
? { ...existingAllowBuilds }
|
|
58
|
+
: {}
|
|
59
|
+
|
|
60
|
+
allowBuilds[packageName] = true
|
|
61
|
+
workspace.allowBuilds = allowBuilds
|
|
62
|
+
|
|
63
|
+
fs.writeFileSync(workspacePath, yaml.stringify(workspace))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Check if a command exists */
|
|
67
|
+
export async function commandExists(command: string): Promise<boolean> {
|
|
68
|
+
return (await getCommandVersion(command)) !== null
|
|
26
69
|
}
|