@gengjiawen/os-init 1.24.0 → 1.25.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 +12 -0
- package/README.md +18 -0
- package/bin/bin.js +29 -0
- package/build/codex.js +8 -1
- package/build/cursor.d.ts +24 -0
- package/build/cursor.js +110 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +6 -1
- package/libs/codex.ts +10 -1
- package/libs/cursor.test.ts +204 -0
- package/libs/cursor.ts +205 -0
- package/libs/index.ts +8 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.25.0](https://github.com/gengjiawen/os-init/compare/v1.24.0...v1.25.0) (2026-05-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add disable-ts-extension command ([26c8d38](https://github.com/gengjiawen/os-init/commit/26c8d389f5524eebf27fb0e16f92f1a800d53b73))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **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))
|
|
14
|
+
|
|
3
15
|
## [1.24.0](https://github.com/gengjiawen/os-init/compare/v1.23.1...v1.24.0) (2026-04-29)
|
|
4
16
|
|
|
5
17
|
|
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')
|
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
|
|
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 {};
|
package/build/cursor.js
ADDED
|
@@ -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/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
|
|
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'
|