@gengjiawen/os-init 1.25.0 → 1.26.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.
@@ -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: 'ignore',
65
+ stdio: 'pipe',
61
66
  reject: false,
62
67
  })
68
+ expect(execaMock).toHaveBeenNthCalledWith(2, 'pnpm', ['root', '-g'])
63
69
  expect(execaMock).toHaveBeenNthCalledWith(
64
- 2,
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(2)
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: 'ignore',
100
+ stdio: 'pipe',
92
101
  reject: false,
93
102
  })
94
103
  expect(execaMock).toHaveBeenNthCalledWith(
@@ -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 { commandExists, PNPM_INSTALL_ENV } from './utils'
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 usePnpm = await commandExists('pnpm')
52
+ const pnpmVersion = await getCommandVersion('pnpm')
48
53
 
49
- if (usePnpm) {
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
- ['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages],
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,
@@ -12,9 +12,9 @@ jest.mock('@gengjiawen/unzip-url', () => ({
12
12
  }))
13
13
 
14
14
  import { unzip } from '@gengjiawen/unzip-url'
15
- import { downloadMihomoBinary, writeMihomoConfig } from './mihomo'
15
+ import { downloadClashBinary, writeClashConfig } from './clash'
16
16
 
17
- describe('writeMihomoConfig', () => {
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-mihomo-'))
44
- tempCwd = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-mihomo-cwd-'))
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,14 +78,22 @@ describe('writeMihomoConfig', () => {
78
78
  fs.rmSync(tempCwd, { recursive: true, force: true })
79
79
  })
80
80
 
81
- test('writes default mihomo config.yml to current directory', () => {
82
- const result = writeMihomoConfig()
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
 
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('- tls://dns.alidns.com:853')
91
+ expect(content).toContain('- tls://dns.google:853')
92
+ expect(content).toContain('- system://')
93
+ expect(content).toContain('sniff:')
94
+ expect(content).toContain('TLS:')
95
+ expect(content).toContain('HTTP:')
96
+ expect(content).not.toContain('sniffing:')
89
97
  expect(content).toContain('type: socks5')
90
98
  expect(content).toContain('name: socks5-proxy')
91
99
  expect(content).toContain('server: your.ip')
@@ -108,18 +116,18 @@ describe('writeMihomoConfig', () => {
108
116
  expect(content).toContain('- MATCH,PROXY')
109
117
  })
110
118
 
111
- test('writes mihomo config to custom target path', () => {
112
- const customPath = path.join(tempHome, 'custom', 'mihomo.yml')
113
- const result = writeMihomoConfig(customPath)
119
+ test('writes clash config to custom target path', () => {
120
+ const customPath = path.join(tempHome, 'custom', 'clash.yml')
121
+ const result = writeClashConfig(customPath)
114
122
 
115
123
  expect(result.configPath).toBe(customPath)
116
124
  expect(fs.existsSync(customPath)).toBe(true)
117
125
  })
118
126
 
119
- test('downloads linux mihomo binary and prefers v3 without go tag', async () => {
120
- const targetDir = path.join(tempCwd, 'mihomo-bin')
127
+ test('downloads linux clash binary and prefers v3 without go tag', async () => {
128
+ const targetDir = path.join(tempCwd, 'clash-bin')
121
129
  const fetchMock = jest.fn()
122
- const binaryContent = Buffer.from('#!/bin/sh\necho mihomo\n', 'utf8')
130
+ const binaryContent = Buffer.from('#!/bin/sh\necho clash\n', 'utf8')
123
131
 
124
132
  setProcessRuntime('linux', 'x64')
125
133
 
@@ -169,7 +177,7 @@ describe('writeMihomoConfig', () => {
169
177
 
170
178
  global.fetch = fetchMock as unknown as typeof global.fetch
171
179
 
172
- const result = await downloadMihomoBinary(targetDir)
180
+ const result = await downloadClashBinary(targetDir)
173
181
 
174
182
  expect(result.version).toBe('v1.19.13')
175
183
  expect(result.binaryPath).toBe(path.join(targetDir, 'mihomo'))
@@ -181,10 +189,10 @@ describe('writeMihomoConfig', () => {
181
189
  expect(fetchMock).toHaveBeenCalledTimes(2)
182
190
  })
183
191
 
184
- test('downloads darwin mihomo binary and selects darwin asset', async () => {
185
- const targetDir = path.join(tempCwd, 'mihomo-darwin-bin')
192
+ test('downloads darwin clash binary and selects darwin asset', async () => {
193
+ const targetDir = path.join(tempCwd, 'clash-darwin-bin')
186
194
  const fetchMock = jest.fn()
187
- const binaryContent = Buffer.from('#!/bin/sh\necho mihomo-darwin\n', 'utf8')
195
+ const binaryContent = Buffer.from('#!/bin/sh\necho clash-darwin\n', 'utf8')
188
196
 
189
197
  setProcessRuntime('darwin', 'x64')
190
198
 
@@ -224,7 +232,7 @@ describe('writeMihomoConfig', () => {
224
232
 
225
233
  global.fetch = fetchMock as unknown as typeof global.fetch
226
234
 
227
- const result = await downloadMihomoBinary(targetDir)
235
+ const result = await downloadClashBinary(targetDir)
228
236
 
229
237
  expect(result.version).toBe('v1.19.13')
230
238
  expect(result.binaryPath).toBe(path.join(targetDir, 'mihomo'))
@@ -236,10 +244,10 @@ describe('writeMihomoConfig', () => {
236
244
  expect(fetchMock).toHaveBeenCalledTimes(2)
237
245
  })
238
246
 
239
- test('downloads windows mihomo binary and extracts zip asset', async () => {
240
- const targetDir = path.join(tempCwd, 'mihomo-windows-bin')
247
+ test('downloads windows clash binary and extracts zip asset', async () => {
248
+ const targetDir = path.join(tempCwd, 'clash-windows-bin')
241
249
  const fetchMock = jest.fn()
242
- const binaryContent = Buffer.from('windows-mihomo', 'utf8')
250
+ const binaryContent = Buffer.from('windows-clash', 'utf8')
243
251
 
244
252
  setProcessRuntime('win32', 'x64')
245
253
 
@@ -275,7 +283,7 @@ describe('writeMihomoConfig', () => {
275
283
 
276
284
  global.fetch = fetchMock as unknown as typeof global.fetch
277
285
 
278
- const result = await downloadMihomoBinary(targetDir)
286
+ const result = await downloadClashBinary(targetDir)
279
287
 
280
288
  expect(result.version).toBe('v1.19.13')
281
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 MIHOMO_CONFIG_TEMPLATE = `mixed-port: 7890
8
+ const CLASH_CONFIG_TEMPLATE = `mixed-port: 7890
9
9
  mode: rule
10
10
  log-level: info
11
11
  dns:
@@ -15,11 +15,16 @@ 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 DoT upstream DNS servers plus system DNS.
19
+ nameserver:
20
+ - tls://dns.alidns.com:853
21
+ - tls://dns.google:853
22
+ - system://
18
23
  sniffer:
19
24
  enable: true
20
- sniffing:
21
- - tls
22
- - http
25
+ sniff:
26
+ TLS:
27
+ HTTP:
23
28
  tun:
24
29
  enable: true
25
30
  stack: system
@@ -51,24 +56,24 @@ rules:
51
56
  - MATCH,PROXY
52
57
  `
53
58
 
54
- const MIHOMO_LATEST_RELEASE_API_URL =
59
+ const CLASH_LATEST_RELEASE_API_URL =
55
60
  'https://api.github.com/repos/MetaCubeX/mihomo/releases/latest'
56
61
 
57
- interface MihomoReleaseAsset {
62
+ interface ClashReleaseAsset {
58
63
  name: string
59
64
  browser_download_url: string
60
65
  }
61
66
 
62
- interface MihomoRelease {
67
+ interface ClashRelease {
63
68
  tag_name: string
64
- assets: MihomoReleaseAsset[]
69
+ assets: ClashReleaseAsset[]
65
70
  }
66
71
 
67
- function getMihomoBinaryFilename(platform = process.platform): string {
72
+ function getClashBinaryFilename(platform = process.platform): string {
68
73
  return platform === 'win32' ? 'mihomo.exe' : 'mihomo'
69
74
  }
70
75
 
71
- function getMihomoPlatformToken(platform = process.platform): string {
76
+ function getClashPlatformToken(platform = process.platform): string {
72
77
  switch (platform) {
73
78
  case 'linux':
74
79
  return 'linux'
@@ -77,11 +82,11 @@ function getMihomoPlatformToken(platform = process.platform): string {
77
82
  case 'win32':
78
83
  return 'windows'
79
84
  default:
80
- throw new Error(`Unsupported platform for Mihomo download: ${platform}`)
85
+ throw new Error(`Unsupported platform for Clash download: ${platform}`)
81
86
  }
82
87
  }
83
88
 
84
- function getMihomoArchTokens(arch = process.arch): string[] {
89
+ function getClashArchTokens(arch = process.arch): string[] {
85
90
  switch (arch) {
86
91
  case 'x64':
87
92
  return ['amd64']
@@ -92,11 +97,11 @@ function getMihomoArchTokens(arch = process.arch): string[] {
92
97
  case 'ia32':
93
98
  return ['386']
94
99
  default:
95
- throw new Error(`Unsupported architecture for Mihomo download: ${arch}`)
100
+ throw new Error(`Unsupported architecture for Clash download: ${arch}`)
96
101
  }
97
102
  }
98
103
 
99
- function getMihomoCpuLevelTokens(
104
+ function getClashCpuLevelTokens(
100
105
  platform = process.platform,
101
106
  arch = process.arch
102
107
  ): string[] {
@@ -111,14 +116,14 @@ function getMihomoCpuLevelTokens(
111
116
  return ['v3', 'v2', 'v1']
112
117
  }
113
118
 
114
- function findMihomoAsset(
115
- assets: MihomoReleaseAsset[],
119
+ function findClashAsset(
120
+ assets: ClashReleaseAsset[],
116
121
  platform = process.platform,
117
122
  arch = process.arch
118
- ): MihomoReleaseAsset {
119
- const platformToken = getMihomoPlatformToken(platform)
120
- const archTokens = getMihomoArchTokens(arch)
121
- const cpuLevelTokens = getMihomoCpuLevelTokens(platform, arch)
123
+ ): ClashReleaseAsset {
124
+ const platformToken = getClashPlatformToken(platform)
125
+ const archTokens = getClashArchTokens(arch)
126
+ const cpuLevelTokens = getClashCpuLevelTokens(platform, arch)
122
127
  const extension = platform === 'win32' ? '.zip' : '.gz'
123
128
 
124
129
  const candidates = assets.filter(
@@ -128,8 +133,8 @@ function findMihomoAsset(
128
133
  )
129
134
 
130
135
  const sortCandidates = (
131
- left: MihomoReleaseAsset,
132
- right: MihomoReleaseAsset
136
+ left: ClashReleaseAsset,
137
+ right: ClashReleaseAsset
133
138
  ): number => {
134
139
  const leftHasGoTag = left.name.includes('-go')
135
140
  const rightHasGoTag = right.name.includes('-go')
@@ -175,7 +180,7 @@ function findMihomoAsset(
175
180
  }
176
181
 
177
182
  throw new Error(
178
- `No Mihomo binary found for platform ${platform} and architecture ${arch}.`
183
+ `No Clash binary found for platform ${platform} and architecture ${arch}.`
179
184
  )
180
185
  }
181
186
 
@@ -199,8 +204,8 @@ function findFileRecursively(rootDir: string, matcher: RegExp): string | null {
199
204
  return null
200
205
  }
201
206
 
202
- async function fetchMihomoLatestRelease(): Promise<MihomoRelease> {
203
- const response = await fetch(MIHOMO_LATEST_RELEASE_API_URL, {
207
+ async function fetchClashLatestRelease(): Promise<ClashRelease> {
208
+ const response = await fetch(CLASH_LATEST_RELEASE_API_URL, {
204
209
  headers: {
205
210
  Accept: 'application/vnd.github+json',
206
211
  'User-Agent': '@gengjiawen/os-init',
@@ -209,26 +214,26 @@ async function fetchMihomoLatestRelease(): Promise<MihomoRelease> {
209
214
 
210
215
  if (!response.ok) {
211
216
  throw new Error(
212
- `Failed to fetch Mihomo release metadata: ${response.status} ${response.statusText}`
217
+ `Failed to fetch Clash release metadata: ${response.status} ${response.statusText}`
213
218
  )
214
219
  }
215
220
 
216
- return (await response.json()) as MihomoRelease
221
+ return (await response.json()) as ClashRelease
217
222
  }
218
223
 
219
- export async function downloadMihomoBinary(targetDir: string): Promise<{
224
+ export async function downloadClashBinary(targetDir: string): Promise<{
220
225
  binaryPath: string
221
226
  downloadUrl: string
222
227
  version: string
223
228
  }> {
224
229
  ensureDir(targetDir)
225
230
 
226
- const release = await fetchMihomoLatestRelease()
227
- const asset = findMihomoAsset(release.assets)
228
- const binaryPath = path.join(targetDir, getMihomoBinaryFilename())
231
+ const release = await fetchClashLatestRelease()
232
+ const asset = findClashAsset(release.assets)
233
+ const binaryPath = path.join(targetDir, getClashBinaryFilename())
229
234
 
230
235
  if (process.platform === 'win32') {
231
- const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-mihomo-'))
236
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-clash-'))
232
237
 
233
238
  try {
234
239
  await unzip(asset.browser_download_url, tempDir)
@@ -236,7 +241,7 @@ export async function downloadMihomoBinary(targetDir: string): Promise<{
236
241
 
237
242
  if (!extractedBinary) {
238
243
  throw new Error(
239
- `Mihomo executable was not found in asset ${asset.name}.`
244
+ `Clash executable was not found in asset ${asset.name}.`
240
245
  )
241
246
  }
242
247
 
@@ -254,7 +259,7 @@ export async function downloadMihomoBinary(targetDir: string): Promise<{
254
259
 
255
260
  if (!response.ok) {
256
261
  throw new Error(
257
- `Failed to download Mihomo binary: ${response.status} ${response.statusText}`
262
+ `Failed to download Clash binary: ${response.status} ${response.statusText}`
258
263
  )
259
264
  }
260
265
 
@@ -270,11 +275,11 @@ export async function downloadMihomoBinary(targetDir: string): Promise<{
270
275
  }
271
276
  }
272
277
 
273
- /** Write Mihomo config.yml */
274
- export function writeMihomoConfig(targetPath?: string): { configPath: string } {
278
+ /** Write Clash config.yml */
279
+ export function writeClashConfig(targetPath?: string): { configPath: string } {
275
280
  const configPath = targetPath || path.join(process.cwd(), 'config.yml')
276
281
  ensureDir(path.dirname(configPath))
277
- fs.writeFileSync(configPath, MIHOMO_CONFIG_TEMPLATE)
282
+ fs.writeFileSync(configPath, CLASH_CONFIG_TEMPLATE)
278
283
 
279
284
  return { configPath }
280
285
  }
@@ -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: 'ignore',
132
+ stdio: 'pipe',
119
133
  reject: false,
120
134
  })
135
+ expect(execaMock).toHaveBeenNthCalledWith(2, 'pnpm', ['root', '-g'])
121
136
  expect(execaMock).toHaveBeenNthCalledWith(
122
- 2,
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
  })
@@ -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 { ensureDir, commandExists, PNPM_INSTALL_ENV } from './utils'
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 usePnpm = await commandExists('pnpm')
164
+ const pnpmVersion = await getCommandVersion('pnpm')
153
165
 
154
- if (usePnpm) {
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
- ['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages],
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/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 mihomo functionality
68
- export { writeMihomoConfig, downloadMihomoBinary } from './mihomo'
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 {