@gengjiawen/os-init 1.24.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 CHANGED
@@ -1,5 +1,31 @@
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
+
17
+ ## [1.25.0](https://github.com/gengjiawen/os-init/compare/v1.24.0...v1.25.0) (2026-05-19)
18
+
19
+
20
+ ### Features
21
+
22
+ * add disable-ts-extension command ([26c8d38](https://github.com/gengjiawen/os-init/commit/26c8d389f5524eebf27fb0e16f92f1a800d53b73))
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **codex:** Windows TOML parse failure in model_catalog_json merge ([#38](https://github.com/gengjiawen/os-init/issues/38)) ([86375a8](https://github.com/gengjiawen/os-init/commit/86375a89aff460d3b367a4f2af9a5205abc0570e))
28
+
3
29
  ## [1.24.0](https://github.com/gengjiawen/os-init/compare/v1.23.1...v1.24.0) (2026-04-29)
4
30
 
5
31
 
package/README.md CHANGED
@@ -72,6 +72,24 @@ Example:
72
72
  pnpx @gengjiawen/os-init set-fish
73
73
  ```
74
74
 
75
+ ### Disable VS Code TypeScript Extension in Cursor
76
+
77
+ ```bash
78
+ pnpx @gengjiawen/os-init disable-ts-extension
79
+ ```
80
+
81
+ Disables `vscode.typescript-language-features`, the VS Code TypeScript language
82
+ features extension bundled with Cursor, because it can consume too much memory.
83
+ The command writes Cursor's UI disabled-extension state so it stays disabled
84
+ across restarts, updates Cursor's `state.vscdb` with Node's built-in
85
+ `node:sqlite` module, and preserves any other disabled extensions.
86
+
87
+ Use a custom Cursor state database path when needed:
88
+
89
+ ```bash
90
+ pnpx @gengjiawen/os-init disable-ts-extension --db "$HOME/Library/Application Support/Cursor/User/globalStorage/state.vscdb"
91
+ ```
92
+
75
93
  ### Generate Mihomo Config
76
94
 
77
95
  ```bash
package/bin/bin.js CHANGED
@@ -16,6 +16,7 @@ const {
16
16
  setupAndroidEnvironment,
17
17
  writeMihomoConfig,
18
18
  downloadMihomoBinary,
19
+ disableCursorTypescriptExtension,
19
20
  } = require('../build')
20
21
  const { appendFishImportScript } = require('../build/fish-shell-utils')
21
22
 
@@ -233,6 +234,34 @@ program
233
234
  }
234
235
  })
235
236
 
237
+ program
238
+ .command('disable-ts-extension')
239
+ .description(
240
+ 'disable VS Code TypeScript extension in Cursor to avoid excessive memory use'
241
+ )
242
+ .option('--db <path>', 'Cursor state.vscdb path')
243
+ .action(async (options) => {
244
+ try {
245
+ const result = await disableCursorTypescriptExtension({
246
+ dbPath: options.db,
247
+ })
248
+
249
+ console.log(
250
+ result.changed
251
+ ? `Cursor extension disabled: ${result.extensionId}`
252
+ : `Cursor extension already disabled: ${result.extensionId}`
253
+ )
254
+ console.log(`Cursor state DB: ${result.dbPath}`)
255
+ console.log(`Cursor storage key: ${result.key}`)
256
+ } catch (err) {
257
+ console.error(
258
+ 'Failed to disable VS Code TypeScript extension in Cursor:',
259
+ err.message
260
+ )
261
+ process.exit(1)
262
+ }
263
+ })
264
+
236
265
  program
237
266
  .command('set-clash')
238
267
  .description('generate clash/mihomo config.yml in current directory')
@@ -24,10 +24,21 @@ async function installAllAgentsDeps(options = {}) {
24
24
  if (options.full) {
25
25
  packages.push('opencode-ai');
26
26
  }
27
- const usePnpm = await (0, utils_1.commandExists)('pnpm');
28
- if (usePnpm) {
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
- await (0, execa_1.execa)('pnpm', ['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages], {
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
  });
@@ -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 usePnpm = await (0, utils_1.commandExists)('pnpm');
105
- if (usePnpm) {
110
+ const pnpmVersion = await (0, utils_1.getCommandVersion)('pnpm');
111
+ if (pnpmVersion !== null) {
106
112
  console.log('pnpm detected. Installing dependencies with pnpm...');
107
- await (0, execa_1.execa)('pnpm', ['--allow-build=@anthropic-ai/claude-code', 'add', '-g', ...packages], {
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/codex.js CHANGED
@@ -44,8 +44,15 @@ function mergeTomlTables(existingConfig, templateConfig) {
44
44
  }
45
45
  return mergedConfig;
46
46
  }
47
+ function stripModelCatalogJsonFromToml(content) {
48
+ return content
49
+ .split('\n')
50
+ .filter((line) => !/^\s*model_catalog_json\s*=/.test(line))
51
+ .join('\n');
52
+ }
47
53
  function getMergedCodexConfig(existingContent) {
48
- const existingConfig = TOML.parse(existingContent);
54
+ const sanitizedContent = stripModelCatalogJsonFromToml(existingContent);
55
+ const existingConfig = TOML.parse(sanitizedContent);
49
56
  const templateConfig = TOML.parse(getCodexConfigTomlTemplate());
50
57
  delete existingConfig.service_tier;
51
58
  delete existingConfig.model_catalog_json;
@@ -0,0 +1,24 @@
1
+ export declare const CURSOR_TYPESCRIPT_EXTENSION_ID = "vscode.typescript-language-features";
2
+ interface DisabledExtensionIdentifier {
3
+ id: string;
4
+ uuid?: string;
5
+ }
6
+ export interface DisableCursorExtensionOptions {
7
+ dbPath?: string;
8
+ extensionId?: string;
9
+ }
10
+ export interface DisableCursorExtensionResult {
11
+ dbPath: string;
12
+ key: string;
13
+ extensionId: string;
14
+ changed: boolean;
15
+ disabledExtensions: DisabledExtensionIdentifier[];
16
+ }
17
+ export declare function getCursorStateDbPath(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv, homeDir?: string): string;
18
+ export declare function mergeDisabledExtension(rawValue: string | null | undefined, extensionId?: string): {
19
+ changed: boolean;
20
+ value: string;
21
+ disabledExtensions: DisabledExtensionIdentifier[];
22
+ };
23
+ export declare function disableCursorTypescriptExtension(options?: DisableCursorExtensionOptions): Promise<DisableCursorExtensionResult>;
24
+ export {};
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CURSOR_TYPESCRIPT_EXTENSION_ID = void 0;
4
+ exports.getCursorStateDbPath = getCursorStateDbPath;
5
+ exports.mergeDisabledExtension = mergeDisabledExtension;
6
+ exports.disableCursorTypescriptExtension = disableCursorTypescriptExtension;
7
+ const fs = require("fs");
8
+ const os = require("os");
9
+ const path = require("path");
10
+ const node_buffer_1 = require("node:buffer");
11
+ const node_sqlite_1 = require("node:sqlite");
12
+ exports.CURSOR_TYPESCRIPT_EXTENSION_ID = 'vscode.typescript-language-features';
13
+ const DISABLED_EXTENSIONS_STORAGE_KEY = 'extensionsIdentifiers/disabled';
14
+ function getCursorStateDbPath(platform = process.platform, env = process.env, homeDir = os.homedir()) {
15
+ switch (platform) {
16
+ case 'darwin':
17
+ return path.join(homeDir, 'Library', 'Application Support', 'Cursor', 'User', 'globalStorage', 'state.vscdb');
18
+ case 'linux':
19
+ return path.join(homeDir, '.config', 'Cursor', 'User', 'globalStorage', 'state.vscdb');
20
+ case 'win32':
21
+ return path.join(env.APPDATA || path.join(homeDir, 'AppData', 'Roaming'), 'Cursor', 'User', 'globalStorage', 'state.vscdb');
22
+ default:
23
+ return path.join(homeDir, '.config', 'Cursor', 'User', 'globalStorage', 'state.vscdb');
24
+ }
25
+ }
26
+ function isDisabledExtensionIdentifier(value) {
27
+ return (typeof value === 'object' &&
28
+ value !== null &&
29
+ 'id' in value &&
30
+ typeof value.id === 'string');
31
+ }
32
+ function mergeDisabledExtension(rawValue, extensionId = exports.CURSOR_TYPESCRIPT_EXTENSION_ID) {
33
+ const trimmedValue = rawValue?.trim();
34
+ const parsedValue = trimmedValue ? JSON.parse(trimmedValue) : [];
35
+ if (!Array.isArray(parsedValue)) {
36
+ throw new Error(`${DISABLED_EXTENSIONS_STORAGE_KEY} must contain a JSON array`);
37
+ }
38
+ const disabledExtensions = parsedValue.map((item) => {
39
+ if (!isDisabledExtensionIdentifier(item)) {
40
+ throw new Error(`${DISABLED_EXTENSIONS_STORAGE_KEY} contains an invalid extension identifier`);
41
+ }
42
+ return item;
43
+ });
44
+ const hasExtension = disabledExtensions.some((item) => item.id.toLowerCase() === extensionId.toLowerCase());
45
+ if (hasExtension) {
46
+ return {
47
+ changed: false,
48
+ value: JSON.stringify(disabledExtensions),
49
+ disabledExtensions,
50
+ };
51
+ }
52
+ const nextDisabledExtensions = [
53
+ ...disabledExtensions,
54
+ {
55
+ id: extensionId,
56
+ },
57
+ ];
58
+ return {
59
+ changed: true,
60
+ value: JSON.stringify(nextDisabledExtensions),
61
+ disabledExtensions: nextDisabledExtensions,
62
+ };
63
+ }
64
+ function storageValueToString(value) {
65
+ if (value === null || value === undefined) {
66
+ return undefined;
67
+ }
68
+ if (typeof value === 'string') {
69
+ return value;
70
+ }
71
+ if (node_buffer_1.Buffer.isBuffer(value)) {
72
+ return value.toString('utf8');
73
+ }
74
+ if (value instanceof Uint8Array) {
75
+ return node_buffer_1.Buffer.from(value).toString('utf8');
76
+ }
77
+ throw new Error(`${DISABLED_EXTENSIONS_STORAGE_KEY} must be stored as text`);
78
+ }
79
+ async function disableCursorTypescriptExtension(options = {}) {
80
+ const dbPath = options.dbPath || getCursorStateDbPath();
81
+ const extensionId = options.extensionId || exports.CURSOR_TYPESCRIPT_EXTENSION_ID;
82
+ fs.mkdirSync(path.dirname(dbPath), { recursive: true });
83
+ if (fs.existsSync(dbPath)) {
84
+ const stat = fs.statSync(dbPath);
85
+ if (!stat.isFile()) {
86
+ throw new Error(`Cursor state DB path is not a file: ${dbPath}`);
87
+ }
88
+ }
89
+ const db = new node_sqlite_1.DatabaseSync(dbPath);
90
+ try {
91
+ db.exec('create table if not exists ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value BLOB)');
92
+ const row = db
93
+ .prepare('select value from ItemTable where key = ?')
94
+ .get(DISABLED_EXTENSIONS_STORAGE_KEY);
95
+ const merged = mergeDisabledExtension(storageValueToString(row?.value), extensionId);
96
+ if (merged.changed) {
97
+ db.prepare('insert or replace into ItemTable(key,value) values (?, ?)').run(DISABLED_EXTENSIONS_STORAGE_KEY, merged.value);
98
+ }
99
+ return {
100
+ dbPath,
101
+ key: DISABLED_EXTENSIONS_STORAGE_KEY,
102
+ extensionId,
103
+ changed: merged.changed,
104
+ disabledExtensions: merged.disabledExtensions,
105
+ };
106
+ }
107
+ finally {
108
+ db.close();
109
+ }
110
+ }
package/build/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export { writeAllAgentsConfig, installAllAgentsDeps } from './all-agents';
8
8
  export { setupDevEnvironment } from './dev-setup';
9
9
  export { setupAndroidEnvironment } from './android-setup';
10
10
  export { writeMihomoConfig, downloadMihomoBinary } from './mihomo';
11
+ 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.downloadMihomoBinary = exports.writeMihomoConfig = exports.setupAndroidEnvironment = exports.setupDevEnvironment = exports.installAllAgentsDeps = exports.writeAllAgentsConfig = exports.installOpencodeDeps = exports.writeOpencodeConfig = exports.installCodexDeps = exports.writeCodexConfig = exports.installDeps = exports.writeClaudeConfig = void 0;
3
+ exports.mergeDisabledExtension = exports.getCursorStateDbPath = exports.disableCursorTypescriptExtension = exports.CURSOR_TYPESCRIPT_EXTENSION_ID = exports.downloadMihomoBinary = exports.writeMihomoConfig = 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");
@@ -57,3 +57,8 @@ Object.defineProperty(exports, "setupAndroidEnvironment", { enumerable: true, ge
57
57
  var mihomo_1 = require("./mihomo");
58
58
  Object.defineProperty(exports, "writeMihomoConfig", { enumerable: true, get: function () { return mihomo_1.writeMihomoConfig; } });
59
59
  Object.defineProperty(exports, "downloadMihomoBinary", { enumerable: true, get: function () { return mihomo_1.downloadMihomoBinary; } });
60
+ var cursor_1 = require("./cursor");
61
+ Object.defineProperty(exports, "CURSOR_TYPESCRIPT_EXTENSION_ID", { enumerable: true, get: function () { return cursor_1.CURSOR_TYPESCRIPT_EXTENSION_ID; } });
62
+ Object.defineProperty(exports, "disableCursorTypescriptExtension", { enumerable: true, get: function () { return cursor_1.disableCursorTypescriptExtension; } });
63
+ Object.defineProperty(exports, "getCursorStateDbPath", { enumerable: true, get: function () { return cursor_1.getCursorStateDbPath; } });
64
+ Object.defineProperty(exports, "mergeDisabledExtension", { enumerable: true, get: function () { return cursor_1.mergeDisabledExtension; } });
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
- sniffing:
24
- - tls
25
- - http
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 commandExists(command) {
19
+ async function getCommandVersion(command) {
15
20
  try {
16
- const { failed } = await (0, execa_1.execa)(command, ['--version'], {
17
- stdio: 'ignore',
21
+ const { failed, stdout } = await (0, execa_1.execa)(command, ['--version'], {
22
+ stdio: 'pipe',
18
23
  reject: false,
19
24
  });
20
- return !failed;
25
+ return failed ? null : stdout.trim();
21
26
  }
22
27
  catch (error) {
23
- return false;
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
+ }
@@ -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,
@@ -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/codex.ts CHANGED
@@ -57,8 +57,17 @@ function mergeTomlTables(
57
57
  return mergedConfig
58
58
  }
59
59
 
60
+ /** Strip model_catalog_json before parse; Windows paths break TOML string escapes. */
61
+ function stripModelCatalogJsonFromToml(content: string): string {
62
+ return content
63
+ .split('\n')
64
+ .filter((line) => !/^\s*model_catalog_json\s*=/.test(line))
65
+ .join('\n')
66
+ }
67
+
60
68
  function getMergedCodexConfig(existingContent: string): string {
61
- const existingConfig = TOML.parse(existingContent) as TomlTable
69
+ const sanitizedContent = stripModelCatalogJsonFromToml(existingContent)
70
+ const existingConfig = TOML.parse(sanitizedContent) as TomlTable
62
71
  const templateConfig = TOML.parse(getCodexConfigTomlTemplate()) as TomlTable
63
72
  delete existingConfig.service_tier
64
73
  delete existingConfig.model_catalog_json
@@ -0,0 +1,204 @@
1
+ import * as fs from 'fs'
2
+ import * as os from 'os'
3
+ import * as path from 'path'
4
+ import { Buffer } from 'node:buffer'
5
+ import { DatabaseSync } from 'node:sqlite'
6
+ import {
7
+ CURSOR_TYPESCRIPT_EXTENSION_ID,
8
+ disableCursorTypescriptExtension,
9
+ getCursorStateDbPath,
10
+ mergeDisabledExtension,
11
+ } from './cursor'
12
+
13
+ const DISABLED_EXTENSIONS_STORAGE_KEY = 'extensionsIdentifiers/disabled'
14
+
15
+ interface DisabledExtensionIdentifier {
16
+ id: string
17
+ uuid?: string
18
+ }
19
+
20
+ function readDisabledExtensions(dbPath: string): DisabledExtensionIdentifier[] {
21
+ const db = new DatabaseSync(dbPath)
22
+
23
+ try {
24
+ const row = db
25
+ .prepare('select value from ItemTable where key = ?')
26
+ .get(DISABLED_EXTENSIONS_STORAGE_KEY) as
27
+ | { value: string | Buffer }
28
+ | undefined
29
+
30
+ if (!row) {
31
+ throw new Error('disabled extensions row was not written')
32
+ }
33
+
34
+ const value =
35
+ typeof row.value === 'string'
36
+ ? row.value
37
+ : Buffer.from(row.value).toString('utf8')
38
+
39
+ return JSON.parse(value) as DisabledExtensionIdentifier[]
40
+ } finally {
41
+ db.close()
42
+ }
43
+ }
44
+
45
+ function writeDisabledExtensions(
46
+ dbPath: string,
47
+ disabledExtensions: DisabledExtensionIdentifier[]
48
+ ): void {
49
+ fs.mkdirSync(path.dirname(dbPath), { recursive: true })
50
+
51
+ const db = new DatabaseSync(dbPath)
52
+
53
+ try {
54
+ db.exec(
55
+ 'create table if not exists ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value BLOB)'
56
+ )
57
+ db.prepare('insert or replace into ItemTable(key,value) values (?, ?)').run(
58
+ DISABLED_EXTENSIONS_STORAGE_KEY,
59
+ JSON.stringify(disabledExtensions)
60
+ )
61
+ } finally {
62
+ db.close()
63
+ }
64
+ }
65
+
66
+ describe('getCursorStateDbPath', () => {
67
+ test('returns macOS Cursor state DB path', () => {
68
+ expect(getCursorStateDbPath('darwin', {}, '/Users/dev')).toBe(
69
+ path.join(
70
+ '/Users/dev',
71
+ 'Library',
72
+ 'Application Support',
73
+ 'Cursor',
74
+ 'User',
75
+ 'globalStorage',
76
+ 'state.vscdb'
77
+ )
78
+ )
79
+ })
80
+
81
+ test('returns Linux Cursor state DB path', () => {
82
+ expect(getCursorStateDbPath('linux', {}, '/home/dev')).toBe(
83
+ path.join(
84
+ '/home/dev',
85
+ '.config',
86
+ 'Cursor',
87
+ 'User',
88
+ 'globalStorage',
89
+ 'state.vscdb'
90
+ )
91
+ )
92
+ })
93
+
94
+ test('returns Windows Cursor state DB path', () => {
95
+ expect(
96
+ getCursorStateDbPath(
97
+ 'win32',
98
+ { APPDATA: 'C:\\Users\\dev\\AppData\\Roaming' },
99
+ 'C:\\Users\\dev'
100
+ )
101
+ ).toBe(
102
+ path.join(
103
+ 'C:\\Users\\dev\\AppData\\Roaming',
104
+ 'Cursor',
105
+ 'User',
106
+ 'globalStorage',
107
+ 'state.vscdb'
108
+ )
109
+ )
110
+ })
111
+ })
112
+
113
+ describe('mergeDisabledExtension', () => {
114
+ test('adds VS Code TypeScript extension to empty storage value', () => {
115
+ const result = mergeDisabledExtension(undefined)
116
+
117
+ expect(result.changed).toBe(true)
118
+ expect(result.disabledExtensions).toEqual([
119
+ { id: CURSOR_TYPESCRIPT_EXTENSION_ID },
120
+ ])
121
+ expect(JSON.parse(result.value)).toEqual([
122
+ { id: CURSOR_TYPESCRIPT_EXTENSION_ID },
123
+ ])
124
+ })
125
+
126
+ test('preserves existing disabled extensions', () => {
127
+ const result = mergeDisabledExtension(
128
+ JSON.stringify([{ id: 'publisher.extension', uuid: 'test-uuid' }])
129
+ )
130
+
131
+ expect(result.changed).toBe(true)
132
+ expect(result.disabledExtensions).toEqual([
133
+ { id: 'publisher.extension', uuid: 'test-uuid' },
134
+ { id: CURSOR_TYPESCRIPT_EXTENSION_ID },
135
+ ])
136
+ })
137
+
138
+ test('is idempotent and matches extension id case-insensitively', () => {
139
+ const result = mergeDisabledExtension(
140
+ JSON.stringify([{ id: CURSOR_TYPESCRIPT_EXTENSION_ID.toUpperCase() }])
141
+ )
142
+
143
+ expect(result.changed).toBe(false)
144
+ expect(result.disabledExtensions).toEqual([
145
+ { id: CURSOR_TYPESCRIPT_EXTENSION_ID.toUpperCase() },
146
+ ])
147
+ })
148
+
149
+ test('rejects non-array storage value', () => {
150
+ expect(() => mergeDisabledExtension(JSON.stringify({ id: 'bad' }))).toThrow(
151
+ `${DISABLED_EXTENSIONS_STORAGE_KEY} must contain a JSON array`
152
+ )
153
+ })
154
+ })
155
+
156
+ describe('disableCursorTypescriptExtension', () => {
157
+ let tempDir: string
158
+
159
+ beforeEach(() => {
160
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-init-cursor-'))
161
+ })
162
+
163
+ afterEach(() => {
164
+ fs.rmSync(tempDir, { recursive: true, force: true })
165
+ })
166
+
167
+ test('creates Cursor state DB and disables VS Code TypeScript extension', async () => {
168
+ const dbPath = path.join(
169
+ tempDir,
170
+ 'Cursor',
171
+ 'User',
172
+ 'globalStorage',
173
+ 'state.vscdb'
174
+ )
175
+
176
+ const result = await disableCursorTypescriptExtension({ dbPath })
177
+
178
+ expect(result).toMatchObject({
179
+ dbPath,
180
+ key: DISABLED_EXTENSIONS_STORAGE_KEY,
181
+ extensionId: CURSOR_TYPESCRIPT_EXTENSION_ID,
182
+ changed: true,
183
+ })
184
+ expect(readDisabledExtensions(dbPath)).toEqual([
185
+ { id: CURSOR_TYPESCRIPT_EXTENSION_ID },
186
+ ])
187
+ })
188
+
189
+ test('preserves existing disabled extensions and is idempotent', async () => {
190
+ const dbPath = path.join(tempDir, 'state.vscdb')
191
+
192
+ writeDisabledExtensions(dbPath, [{ id: 'publisher.extension' }])
193
+
194
+ const firstResult = await disableCursorTypescriptExtension({ dbPath })
195
+ const secondResult = await disableCursorTypescriptExtension({ dbPath })
196
+
197
+ expect(firstResult.changed).toBe(true)
198
+ expect(secondResult.changed).toBe(false)
199
+ expect(readDisabledExtensions(dbPath)).toEqual([
200
+ { id: 'publisher.extension' },
201
+ { id: CURSOR_TYPESCRIPT_EXTENSION_ID },
202
+ ])
203
+ })
204
+ })
package/libs/cursor.ts ADDED
@@ -0,0 +1,205 @@
1
+ import * as fs from 'fs'
2
+ import * as os from 'os'
3
+ import * as path from 'path'
4
+ import { Buffer } from 'node:buffer'
5
+ import { DatabaseSync } from 'node:sqlite'
6
+
7
+ export const CURSOR_TYPESCRIPT_EXTENSION_ID =
8
+ 'vscode.typescript-language-features'
9
+
10
+ const DISABLED_EXTENSIONS_STORAGE_KEY = 'extensionsIdentifiers/disabled'
11
+
12
+ interface DisabledExtensionIdentifier {
13
+ id: string
14
+ uuid?: string
15
+ }
16
+
17
+ export interface DisableCursorExtensionOptions {
18
+ dbPath?: string
19
+ extensionId?: string
20
+ }
21
+
22
+ export interface DisableCursorExtensionResult {
23
+ dbPath: string
24
+ key: string
25
+ extensionId: string
26
+ changed: boolean
27
+ disabledExtensions: DisabledExtensionIdentifier[]
28
+ }
29
+
30
+ export function getCursorStateDbPath(
31
+ platform = process.platform,
32
+ env: NodeJS.ProcessEnv = process.env,
33
+ homeDir = os.homedir()
34
+ ): string {
35
+ switch (platform) {
36
+ case 'darwin':
37
+ return path.join(
38
+ homeDir,
39
+ 'Library',
40
+ 'Application Support',
41
+ 'Cursor',
42
+ 'User',
43
+ 'globalStorage',
44
+ 'state.vscdb'
45
+ )
46
+ case 'linux':
47
+ return path.join(
48
+ homeDir,
49
+ '.config',
50
+ 'Cursor',
51
+ 'User',
52
+ 'globalStorage',
53
+ 'state.vscdb'
54
+ )
55
+ case 'win32':
56
+ return path.join(
57
+ env.APPDATA || path.join(homeDir, 'AppData', 'Roaming'),
58
+ 'Cursor',
59
+ 'User',
60
+ 'globalStorage',
61
+ 'state.vscdb'
62
+ )
63
+ default:
64
+ return path.join(
65
+ homeDir,
66
+ '.config',
67
+ 'Cursor',
68
+ 'User',
69
+ 'globalStorage',
70
+ 'state.vscdb'
71
+ )
72
+ }
73
+ }
74
+
75
+ function isDisabledExtensionIdentifier(
76
+ value: unknown
77
+ ): value is DisabledExtensionIdentifier {
78
+ return (
79
+ typeof value === 'object' &&
80
+ value !== null &&
81
+ 'id' in value &&
82
+ typeof value.id === 'string'
83
+ )
84
+ }
85
+
86
+ export function mergeDisabledExtension(
87
+ rawValue: string | null | undefined,
88
+ extensionId = CURSOR_TYPESCRIPT_EXTENSION_ID
89
+ ): {
90
+ changed: boolean
91
+ value: string
92
+ disabledExtensions: DisabledExtensionIdentifier[]
93
+ } {
94
+ const trimmedValue = rawValue?.trim()
95
+ const parsedValue = trimmedValue ? JSON.parse(trimmedValue) : []
96
+
97
+ if (!Array.isArray(parsedValue)) {
98
+ throw new Error(
99
+ `${DISABLED_EXTENSIONS_STORAGE_KEY} must contain a JSON array`
100
+ )
101
+ }
102
+
103
+ const disabledExtensions = parsedValue.map((item) => {
104
+ if (!isDisabledExtensionIdentifier(item)) {
105
+ throw new Error(
106
+ `${DISABLED_EXTENSIONS_STORAGE_KEY} contains an invalid extension identifier`
107
+ )
108
+ }
109
+ return item
110
+ })
111
+
112
+ const hasExtension = disabledExtensions.some(
113
+ (item) => item.id.toLowerCase() === extensionId.toLowerCase()
114
+ )
115
+
116
+ if (hasExtension) {
117
+ return {
118
+ changed: false,
119
+ value: JSON.stringify(disabledExtensions),
120
+ disabledExtensions,
121
+ }
122
+ }
123
+
124
+ const nextDisabledExtensions = [
125
+ ...disabledExtensions,
126
+ {
127
+ id: extensionId,
128
+ },
129
+ ]
130
+
131
+ return {
132
+ changed: true,
133
+ value: JSON.stringify(nextDisabledExtensions),
134
+ disabledExtensions: nextDisabledExtensions,
135
+ }
136
+ }
137
+
138
+ function storageValueToString(value: unknown): string | undefined {
139
+ if (value === null || value === undefined) {
140
+ return undefined
141
+ }
142
+
143
+ if (typeof value === 'string') {
144
+ return value
145
+ }
146
+
147
+ if (Buffer.isBuffer(value)) {
148
+ return value.toString('utf8')
149
+ }
150
+
151
+ if (value instanceof Uint8Array) {
152
+ return Buffer.from(value).toString('utf8')
153
+ }
154
+
155
+ throw new Error(`${DISABLED_EXTENSIONS_STORAGE_KEY} must be stored as text`)
156
+ }
157
+
158
+ export async function disableCursorTypescriptExtension(
159
+ options: DisableCursorExtensionOptions = {}
160
+ ): Promise<DisableCursorExtensionResult> {
161
+ const dbPath = options.dbPath || getCursorStateDbPath()
162
+ const extensionId = options.extensionId || CURSOR_TYPESCRIPT_EXTENSION_ID
163
+
164
+ fs.mkdirSync(path.dirname(dbPath), { recursive: true })
165
+
166
+ if (fs.existsSync(dbPath)) {
167
+ const stat = fs.statSync(dbPath)
168
+ if (!stat.isFile()) {
169
+ throw new Error(`Cursor state DB path is not a file: ${dbPath}`)
170
+ }
171
+ }
172
+
173
+ const db = new DatabaseSync(dbPath)
174
+
175
+ try {
176
+ db.exec(
177
+ 'create table if not exists ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value BLOB)'
178
+ )
179
+
180
+ const row = db
181
+ .prepare('select value from ItemTable where key = ?')
182
+ .get(DISABLED_EXTENSIONS_STORAGE_KEY) as { value: unknown } | undefined
183
+
184
+ const merged = mergeDisabledExtension(
185
+ storageValueToString(row?.value),
186
+ extensionId
187
+ )
188
+
189
+ if (merged.changed) {
190
+ db.prepare(
191
+ 'insert or replace into ItemTable(key,value) values (?, ?)'
192
+ ).run(DISABLED_EXTENSIONS_STORAGE_KEY, merged.value)
193
+ }
194
+
195
+ return {
196
+ dbPath,
197
+ key: DISABLED_EXTENSIONS_STORAGE_KEY,
198
+ extensionId,
199
+ changed: merged.changed,
200
+ disabledExtensions: merged.disabledExtensions,
201
+ }
202
+ } finally {
203
+ db.close()
204
+ }
205
+ }
package/libs/index.ts CHANGED
@@ -66,3 +66,11 @@ export { setupAndroidEnvironment } from './android-setup'
66
66
 
67
67
  // Re-export mihomo functionality
68
68
  export { writeMihomoConfig, downloadMihomoBinary } from './mihomo'
69
+
70
+ // Re-export Cursor functionality
71
+ export {
72
+ CURSOR_TYPESCRIPT_EXTENSION_ID,
73
+ disableCursorTypescriptExtension,
74
+ getCursorStateDbPath,
75
+ mergeDisabledExtension,
76
+ } from './cursor'
@@ -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
- sniffing:
21
- - tls
22
- - http
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
- /** Check if a command exists */
14
- export async function commandExists(command: string): Promise<boolean> {
15
+ export async function getCommandVersion(
16
+ command: string
17
+ ): Promise<string | null> {
15
18
  try {
16
- // execa with reject: false will not throw on non-zero exit codes.
17
- const { failed } = await execa(command, ['--version'], {
18
- stdio: 'ignore',
19
+ const { failed, stdout } = await execa(command, ['--version'], {
20
+ stdio: 'pipe',
19
21
  reject: false,
20
22
  })
21
- return !failed
23
+ return failed ? null : stdout.trim()
22
24
  } catch (error) {
23
- // Catch errors for commands that don't support --version or other issues
24
- return false
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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gengjiawen/os-init",
3
3
  "private": false,
4
- "version": "1.24.0",
4
+ "version": "1.26.0",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "bin": {