@gengjiawen/os-init 1.23.1 → 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 +19 -0
- package/README.md +18 -0
- package/bin/bin.js +31 -5
- package/build/all-agents.d.ts +1 -2
- package/build/all-agents.js +3 -9
- package/build/claude-code.js +2 -7
- package/build/codex.d.ts +2 -3
- package/build/codex.js +11 -37
- 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/build/mihomo.js +1 -1
- package/libs/all-agents.test.ts +4 -17
- package/libs/all-agents.ts +5 -11
- package/libs/claude-code.test.ts +0 -1
- package/libs/claude-code.ts +2 -7
- package/libs/codex.test.ts +29 -108
- package/libs/codex.ts +14 -54
- package/libs/cursor.test.ts +204 -0
- package/libs/cursor.ts +205 -0
- package/libs/index.ts +8 -0
- package/libs/mihomo.test.ts +1 -1
- package/libs/mihomo.ts +1 -1
- package/package.json +1 -1
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'
|
package/libs/mihomo.test.ts
CHANGED
|
@@ -104,7 +104,7 @@ describe('writeMihomoConfig', () => {
|
|
|
104
104
|
expect(content).toContain('- IP-CIDR6,fe80::/10,DIRECT')
|
|
105
105
|
expect(content).toContain('- DOMAIN-SUFFIX,local,DIRECT')
|
|
106
106
|
expect(content).toContain('- DOMAIN-SUFFIX,cn,DIRECT')
|
|
107
|
-
expect(content).toContain('- GEOIP,CN,DIRECT')
|
|
107
|
+
expect(content).toContain('# - GEOIP,CN,DIRECT')
|
|
108
108
|
expect(content).toContain('- MATCH,PROXY')
|
|
109
109
|
})
|
|
110
110
|
|
package/libs/mihomo.ts
CHANGED