@namzu/computer-use 4.3.1 → 4.5.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 +28 -0
- package/dist/SubprocessComputerUseHost.d.ts +21 -1
- package/dist/SubprocessComputerUseHost.d.ts.map +1 -1
- package/dist/SubprocessComputerUseHost.js +67 -15
- package/dist/SubprocessComputerUseHost.js.map +1 -1
- package/dist/a11y/a11y.d.ts +16 -7
- package/dist/a11y/a11y.d.ts.map +1 -1
- package/dist/a11y/a11y.js +23 -5
- package/dist/a11y/a11y.js.map +1 -1
- package/dist/a11y/index.d.ts +7 -1
- package/dist/a11y/index.d.ts.map +1 -1
- package/dist/a11y/index.js +4 -1
- package/dist/a11y/index.js.map +1 -1
- package/dist/a11y/interface.d.ts +5 -0
- package/dist/a11y/interface.d.ts.map +1 -1
- package/dist/a11y/interface.js.map +1 -1
- package/dist/a11y/macos-helper.d.ts +80 -0
- package/dist/a11y/macos-helper.d.ts.map +1 -0
- package/dist/a11y/macos-helper.js +436 -0
- package/dist/a11y/macos-helper.js.map +1 -0
- package/dist/a11y/macos-signing.d.ts +56 -0
- package/dist/a11y/macos-signing.d.ts.map +1 -0
- package/dist/a11y/macos-signing.js +228 -0
- package/dist/a11y/macos-signing.js.map +1 -0
- package/dist/a11y/macos.d.ts +173 -0
- package/dist/a11y/macos.d.ts.map +1 -0
- package/dist/a11y/macos.js +271 -0
- package/dist/a11y/macos.js.map +1 -0
- package/dist/a11y/windows.d.ts +13 -2
- package/dist/a11y/windows.d.ts.map +1 -1
- package/dist/a11y/windows.js +29 -6
- package/dist/a11y/windows.js.map +1 -1
- package/dist/adapters/cua-driver/adapter.d.ts +26 -0
- package/dist/adapters/cua-driver/adapter.d.ts.map +1 -1
- package/dist/adapters/cua-driver/adapter.js +224 -13
- package/dist/adapters/cua-driver/adapter.js.map +1 -1
- package/dist/adapters/cua-driver/client.d.ts +5 -0
- package/dist/adapters/cua-driver/client.d.ts.map +1 -1
- package/dist/adapters/cua-driver/client.js +31 -0
- package/dist/adapters/cua-driver/client.js.map +1 -1
- package/dist/adapters/cua-driver/ui-tree.d.ts +1 -0
- package/dist/adapters/cua-driver/ui-tree.d.ts.map +1 -1
- package/dist/adapters/cua-driver/ui-tree.js +2 -0
- package/dist/adapters/cua-driver/ui-tree.js.map +1 -1
- package/dist/adapters/darwin-ax.d.ts +94 -0
- package/dist/adapters/darwin-ax.d.ts.map +1 -0
- package/dist/adapters/darwin-ax.js +754 -0
- package/dist/adapters/darwin-ax.js.map +1 -0
- package/dist/adapters/darwin.d.ts +43 -2
- package/dist/adapters/darwin.d.ts.map +1 -1
- package/dist/adapters/darwin.js +145 -7
- package/dist/adapters/darwin.js.map +1 -1
- package/dist/adapters/png.d.ts +6 -0
- package/dist/adapters/png.d.ts.map +1 -0
- package/dist/adapters/png.js +7 -0
- package/dist/adapters/png.js.map +1 -0
- package/dist/adapters/types.d.ts +5 -0
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/adapters/win32-native.d.ts +53 -0
- package/dist/adapters/win32-native.d.ts.map +1 -0
- package/dist/adapters/win32-native.js +279 -0
- package/dist/adapters/win32-native.js.map +1 -0
- package/dist/adapters/win32.d.ts +19 -1
- package/dist/adapters/win32.d.ts.map +1 -1
- package/dist/adapters/win32.js +34 -8
- package/dist/adapters/win32.js.map +1 -1
- package/dist/foreground/guard.d.ts.map +1 -1
- package/dist/foreground/guard.js +2 -0
- package/dist/foreground/guard.js.map +1 -1
- package/dist/foreground/ladder.d.ts.map +1 -1
- package/dist/foreground/ladder.js +5 -1
- package/dist/foreground/ladder.js.map +1 -1
- package/dist/foreground/types.d.ts +6 -0
- package/dist/foreground/types.d.ts.map +1 -1
- package/dist/foreground/types.js.map +1 -1
- package/dist/foreground/windows.d.ts +2 -0
- package/dist/foreground/windows.d.ts.map +1 -1
- package/dist/foreground/windows.js +23 -11
- package/dist/foreground/windows.js.map +1 -1
- package/dist/native/a11y.d.ts +61 -0
- package/dist/native/a11y.d.ts.map +1 -0
- package/dist/native/a11y.js +197 -0
- package/dist/native/a11y.js.map +1 -0
- package/dist/native/foreground-monitor.d.ts +51 -0
- package/dist/native/foreground-monitor.d.ts.map +1 -0
- package/dist/native/foreground-monitor.js +120 -0
- package/dist/native/foreground-monitor.js.map +1 -0
- package/dist/native/presence.d.ts +24 -0
- package/dist/native/presence.d.ts.map +1 -0
- package/dist/native/presence.js +47 -0
- package/dist/native/presence.js.map +1 -0
- package/dist/native/process.d.ts +73 -0
- package/dist/native/process.d.ts.map +1 -0
- package/dist/native/process.js +292 -0
- package/dist/native/process.js.map +1 -0
- package/dist/native/protocol.d.ts +408 -0
- package/dist/native/protocol.d.ts.map +1 -0
- package/dist/native/protocol.js +527 -0
- package/dist/native/protocol.js.map +1 -0
- package/dist/native/shared.d.ts +16 -0
- package/dist/native/shared.d.ts.map +1 -0
- package/dist/native/shared.js +62 -0
- package/dist/native/shared.js.map +1 -0
- package/dist/presence/presence.d.ts +11 -2
- package/dist/presence/presence.d.ts.map +1 -1
- package/dist/presence/presence.js +15 -0
- package/dist/presence/presence.js.map +1 -1
- package/dist/presence/windows.d.ts +2 -0
- package/dist/presence/windows.d.ts.map +1 -1
- package/dist/presence/windows.js +14 -0
- package/dist/presence/windows.js.map +1 -1
- package/helper-macos/main.swift +1756 -0
- package/package.json +3 -2
- package/src/SubprocessComputerUseHost.ts +80 -10
- package/src/a11y/a11y.ts +36 -11
- package/src/a11y/index.ts +28 -1
- package/src/a11y/interface.ts +5 -0
- package/src/a11y/macos-helper.ts +538 -0
- package/src/a11y/macos-signing.ts +280 -0
- package/src/a11y/macos.ts +496 -0
- package/src/a11y/windows.ts +29 -4
- package/src/adapters/cua-driver/adapter.ts +245 -17
- package/src/adapters/cua-driver/client.ts +27 -0
- package/src/adapters/cua-driver/ui-tree.ts +2 -0
- package/src/adapters/darwin-ax.ts +920 -0
- package/src/adapters/darwin.ts +184 -4
- package/src/adapters/png.ts +5 -0
- package/src/adapters/types.ts +5 -0
- package/src/adapters/win32-native.ts +328 -0
- package/src/adapters/win32.ts +52 -5
- package/src/foreground/guard.ts +1 -0
- package/src/foreground/ladder.ts +5 -1
- package/src/foreground/types.ts +6 -0
- package/src/foreground/windows.ts +24 -11
- package/src/native/a11y.ts +267 -0
- package/src/native/foreground-monitor.ts +165 -0
- package/src/native/presence.ts +58 -0
- package/src/native/process.ts +335 -0
- package/src/native/protocol.ts +963 -0
- package/src/native/shared.ts +75 -0
- package/src/presence/presence.ts +23 -2
- package/src/presence/windows.ts +14 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto'
|
|
2
|
+
import {
|
|
3
|
+
chmodSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
renameSync,
|
|
8
|
+
rmSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from 'node:fs'
|
|
11
|
+
import { join } from 'node:path'
|
|
12
|
+
import { runCommand } from '../util/spawn.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A code-signing identity that belongs to this person's Namzu home and to
|
|
16
|
+
* nothing else.
|
|
17
|
+
*
|
|
18
|
+
* Why: macOS keeps the Accessibility switch (on macOS 27 it is named "Device
|
|
19
|
+
* Control and Data Access") against the *designated requirement* of the
|
|
20
|
+
* signed app. An ad-hoc signature has none that survives a rebuild (it is the
|
|
21
|
+
* code's own hash), and macOS 27 does not trust an ad-hoc app at all, even
|
|
22
|
+
* with its switch on. A self-signed identity gives the requirement
|
|
23
|
+
* `identifier "com.namzu.helper" and certificate leaf = H"<sha1>"`, which is
|
|
24
|
+
* the same for every build signed with it, so the grant is made once and
|
|
25
|
+
* outlives rebuilds.
|
|
26
|
+
*
|
|
27
|
+
* The identity lives in a keychain of its own, never in the login keychain:
|
|
28
|
+
* `<NAMZU_HOME>/computer-use/macos/signing/namzu-signing.keychain-db`, opened
|
|
29
|
+
* with a random password kept 0600 next to it (`kc.pw`). The certificate
|
|
30
|
+
* (public) is kept as `cert.pem`; the private key is imported and the loose
|
|
31
|
+
* key files are removed. Nothing here needs sudo or touches the system trust
|
|
32
|
+
* settings.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export const SIGNING_KEYCHAIN = 'namzu-signing.keychain-db'
|
|
36
|
+
export const SIGNING_PASSWORD_FILE = 'kc.pw'
|
|
37
|
+
export const SIGNING_CERT = 'cert.pem'
|
|
38
|
+
export const SIGNING_COMMON_NAME = 'Namzu Helper Local Signing'
|
|
39
|
+
|
|
40
|
+
type Run = typeof runCommand
|
|
41
|
+
|
|
42
|
+
export interface MacSigningIdentity {
|
|
43
|
+
/** Absolute path of the dedicated keychain. */
|
|
44
|
+
readonly keychain: string
|
|
45
|
+
/** The keychain's password. */
|
|
46
|
+
readonly password: string
|
|
47
|
+
/** The certificate's SHA-1, upper-case hex: what `codesign --sign` takes. */
|
|
48
|
+
readonly identity: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function macSigningDir(root: string): string {
|
|
52
|
+
return join(root, 'signing')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const OPENSSL_CONFIG = `[req]
|
|
56
|
+
distinguished_name=dn
|
|
57
|
+
x509_extensions=ext
|
|
58
|
+
prompt=no
|
|
59
|
+
[dn]
|
|
60
|
+
CN=${SIGNING_COMMON_NAME}
|
|
61
|
+
[ext]
|
|
62
|
+
basicConstraints=critical,CA:false
|
|
63
|
+
keyUsage=critical,digitalSignature
|
|
64
|
+
extendedKeyUsage=critical,codeSigning
|
|
65
|
+
`
|
|
66
|
+
|
|
67
|
+
/** `SHA1 Fingerprint=AA:BB:…` (or `sha1 Fingerprint=`) → `AABB…`. */
|
|
68
|
+
export function parseFingerprint(output: string): string | undefined {
|
|
69
|
+
const match = /sha1 fingerprint=([0-9a-f:]+)/i.exec(output)
|
|
70
|
+
const hex = match?.[1]?.replace(/:/g, '').toUpperCase()
|
|
71
|
+
return hex && /^[0-9A-F]{40}$/.test(hex) ? hex : undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function userKeychains(output: string): string[] {
|
|
75
|
+
return [...output.matchAll(/"([^"]+)"/g)].map((m) => m[1] as string)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function identityFrom(
|
|
79
|
+
dir: string,
|
|
80
|
+
run: Run,
|
|
81
|
+
env: NodeJS.ProcessEnv,
|
|
82
|
+
): Promise<MacSigningIdentity | undefined> {
|
|
83
|
+
const keychain = join(dir, SIGNING_KEYCHAIN)
|
|
84
|
+
const cert = join(dir, SIGNING_CERT)
|
|
85
|
+
const passwordFile = join(dir, SIGNING_PASSWORD_FILE)
|
|
86
|
+
if (!existsSync(keychain) || !existsSync(cert) || !existsSync(passwordFile)) return undefined
|
|
87
|
+
const result = await run('openssl', ['x509', '-in', cert, '-noout', '-fingerprint', '-sha1'], {
|
|
88
|
+
timeoutMs: 15_000,
|
|
89
|
+
env,
|
|
90
|
+
}).catch(() => undefined)
|
|
91
|
+
const identity =
|
|
92
|
+
result && result.exitCode === 0 ? parseFingerprint(result.stdout.toString('utf8')) : undefined
|
|
93
|
+
if (!identity) return undefined
|
|
94
|
+
// The files can all be there while the keychain is gone, corrupt or holds another key.
|
|
95
|
+
const listed = await run('security', ['find-identity', '-p', 'codesigning', keychain], {
|
|
96
|
+
timeoutMs: 15_000,
|
|
97
|
+
env,
|
|
98
|
+
}).catch(() => undefined)
|
|
99
|
+
if (
|
|
100
|
+
!listed ||
|
|
101
|
+
listed.exitCode !== 0 ||
|
|
102
|
+
!listed.stdout.toString('utf8').toUpperCase().includes(identity)
|
|
103
|
+
)
|
|
104
|
+
return undefined
|
|
105
|
+
return { keychain, password: readFileSync(passwordFile, 'utf8').trim(), identity }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The system openssl on a Mac (LibreSSL, which `security import` reads); a bare name elsewhere. */
|
|
109
|
+
function opensslCommand(): string {
|
|
110
|
+
return process.platform === 'darwin' && existsSync('/usr/bin/openssl')
|
|
111
|
+
? '/usr/bin/openssl'
|
|
112
|
+
: 'openssl'
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** OpenSSL 3 writes a PKCS#12 that `security import` cannot read unless the old algorithms are asked for. */
|
|
116
|
+
async function pkcs12Compat(run: Run, env: NodeJS.ProcessEnv, openssl: string): Promise<string[]> {
|
|
117
|
+
const version = await run(openssl, ['version'], { timeoutMs: 15_000, env }).catch(() => undefined)
|
|
118
|
+
return version && /OpenSSL 3\./.test(version.stdout.toString('utf8'))
|
|
119
|
+
? ['-certpbe', 'PBE-SHA1-3DES', '-keypbe', 'PBE-SHA1-3DES', '-macalg', 'sha1']
|
|
120
|
+
: []
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function must(run: Run, env: NodeJS.ProcessEnv, command: string, args: readonly string[]) {
|
|
124
|
+
const result = await run(command, args, { timeoutMs: 60_000, env })
|
|
125
|
+
if (result.exitCode !== 0)
|
|
126
|
+
throw new Error(`${command} ${args[0] ?? ''} failed: ${result.stderr.trim().slice(0, 300)}`)
|
|
127
|
+
return result
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The identity for this Namzu home: the existing one, or a new one made once.
|
|
132
|
+
* Resolves `undefined` (with the reason in `onFailure`) when it cannot be
|
|
133
|
+
* made, so the caller can fall back to an ad-hoc signature.
|
|
134
|
+
*/
|
|
135
|
+
export async function ensureSigningIdentity(options: {
|
|
136
|
+
readonly root: string
|
|
137
|
+
readonly env: NodeJS.ProcessEnv
|
|
138
|
+
readonly run?: Run
|
|
139
|
+
readonly onFailure?: (reason: string) => void
|
|
140
|
+
/** Called when an identity that was there could not be used and was set aside; the grant must be given again. */
|
|
141
|
+
readonly onBroken?: () => void
|
|
142
|
+
}): Promise<MacSigningIdentity | undefined> {
|
|
143
|
+
const run = options.run ?? runCommand
|
|
144
|
+
const dir = macSigningDir(options.root)
|
|
145
|
+
const existing = await identityFrom(dir, run, options.env)
|
|
146
|
+
if (existing) return existing
|
|
147
|
+
if (existsSync(dir)) {
|
|
148
|
+
// Files without a working keychain: keep them for inspection and make a new identity.
|
|
149
|
+
try {
|
|
150
|
+
renameSync(dir, `${dir}.broken-${Date.now()}`)
|
|
151
|
+
options.onBroken?.()
|
|
152
|
+
} catch {
|
|
153
|
+
// Another process moved it first; what is there now is tried below.
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const stage = join(options.root, `signing-make-${process.pid}-${randomBytes(4).toString('hex')}`)
|
|
157
|
+
const openssl = opensslCommand()
|
|
158
|
+
try {
|
|
159
|
+
mkdirSync(stage, { recursive: true, mode: 0o700 })
|
|
160
|
+
const password = randomBytes(24).toString('hex')
|
|
161
|
+
const config = join(stage, 'cs.cnf')
|
|
162
|
+
const keyFile = join(stage, 'key.pem')
|
|
163
|
+
const certFile = join(stage, SIGNING_CERT)
|
|
164
|
+
const p12 = join(stage, 'id.p12')
|
|
165
|
+
const passwordFile = join(stage, SIGNING_PASSWORD_FILE)
|
|
166
|
+
const keychain = join(stage, SIGNING_KEYCHAIN)
|
|
167
|
+
writeFileSync(config, OPENSSL_CONFIG, { mode: 0o600 })
|
|
168
|
+
writeFileSync(passwordFile, `${password}\n`, { mode: 0o600 })
|
|
169
|
+
chmodSync(passwordFile, 0o600)
|
|
170
|
+
await must(run, options.env, openssl, [
|
|
171
|
+
'req',
|
|
172
|
+
'-x509',
|
|
173
|
+
'-newkey',
|
|
174
|
+
'rsa:2048',
|
|
175
|
+
'-nodes',
|
|
176
|
+
'-keyout',
|
|
177
|
+
keyFile,
|
|
178
|
+
'-out',
|
|
179
|
+
certFile,
|
|
180
|
+
'-days',
|
|
181
|
+
'3650',
|
|
182
|
+
'-config',
|
|
183
|
+
config,
|
|
184
|
+
])
|
|
185
|
+
chmodSync(keyFile, 0o600)
|
|
186
|
+
await must(run, options.env, openssl, [
|
|
187
|
+
'pkcs12',
|
|
188
|
+
'-export',
|
|
189
|
+
'-inkey',
|
|
190
|
+
keyFile,
|
|
191
|
+
'-in',
|
|
192
|
+
certFile,
|
|
193
|
+
'-out',
|
|
194
|
+
p12,
|
|
195
|
+
'-passout',
|
|
196
|
+
`file:${passwordFile}`,
|
|
197
|
+
...(await pkcs12Compat(run, options.env, openssl)),
|
|
198
|
+
])
|
|
199
|
+
const listed = await run('security', ['list-keychains', '-d', 'user'], {
|
|
200
|
+
timeoutMs: 15_000,
|
|
201
|
+
env: options.env,
|
|
202
|
+
}).catch(() => undefined)
|
|
203
|
+
const before = listed ? userKeychains(listed.stdout.toString('utf8')) : []
|
|
204
|
+
await must(run, options.env, 'security', ['create-keychain', '-p', password, keychain])
|
|
205
|
+
// create-keychain may add the new keychain to the person's search list; put the list back as it was.
|
|
206
|
+
if (before.length > 0)
|
|
207
|
+
await run('security', ['list-keychains', '-d', 'user', '-s', ...before], {
|
|
208
|
+
timeoutMs: 15_000,
|
|
209
|
+
env: options.env,
|
|
210
|
+
}).catch(() => undefined)
|
|
211
|
+
await must(run, options.env, 'security', ['set-keychain-settings', '-t', '300', '-l', keychain])
|
|
212
|
+
await must(run, options.env, 'security', ['unlock-keychain', '-p', password, keychain])
|
|
213
|
+
await must(run, options.env, 'security', [
|
|
214
|
+
'import',
|
|
215
|
+
p12,
|
|
216
|
+
'-k',
|
|
217
|
+
keychain,
|
|
218
|
+
'-P',
|
|
219
|
+
password,
|
|
220
|
+
'-T',
|
|
221
|
+
'/usr/bin/codesign',
|
|
222
|
+
])
|
|
223
|
+
await must(run, options.env, 'security', [
|
|
224
|
+
'set-key-partition-list',
|
|
225
|
+
'-S',
|
|
226
|
+
'apple-tool:,apple:',
|
|
227
|
+
'-s',
|
|
228
|
+
'-k',
|
|
229
|
+
password,
|
|
230
|
+
keychain,
|
|
231
|
+
])
|
|
232
|
+
await lockSigningKeychain(keychain, options.env, run)
|
|
233
|
+
// The private key is in the keychain now; the loose copies go.
|
|
234
|
+
rmSync(keyFile, { force: true })
|
|
235
|
+
rmSync(p12, { force: true })
|
|
236
|
+
rmSync(config, { force: true })
|
|
237
|
+
chmodSync(passwordFile, 0o600)
|
|
238
|
+
// One step: the whole folder appears at once or, when another process was first, not at all.
|
|
239
|
+
mkdirSync(options.root, { recursive: true, mode: 0o700 })
|
|
240
|
+
try {
|
|
241
|
+
renameSync(stage, dir)
|
|
242
|
+
} catch {
|
|
243
|
+
// The other process's identity is used if it works.
|
|
244
|
+
}
|
|
245
|
+
return await identityFrom(dir, run, options.env)
|
|
246
|
+
} catch (error) {
|
|
247
|
+
options.onFailure?.(error instanceof Error ? error.message : String(error))
|
|
248
|
+
return undefined
|
|
249
|
+
} finally {
|
|
250
|
+
rmSync(stage, { recursive: true, force: true })
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Opens the identity's keychain; codesign cannot ask for a password. */
|
|
255
|
+
export async function unlockSigningKeychain(
|
|
256
|
+
identity: MacSigningIdentity,
|
|
257
|
+
env: NodeJS.ProcessEnv,
|
|
258
|
+
run: Run = runCommand,
|
|
259
|
+
): Promise<boolean> {
|
|
260
|
+
const result = await run(
|
|
261
|
+
'security',
|
|
262
|
+
['unlock-keychain', '-p', identity.password, identity.keychain],
|
|
263
|
+
{
|
|
264
|
+
timeoutMs: 15_000,
|
|
265
|
+
env,
|
|
266
|
+
},
|
|
267
|
+
).catch(() => undefined)
|
|
268
|
+
return result?.exitCode === 0
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Closes the keychain again; the private key is only needed while codesign runs. */
|
|
272
|
+
export async function lockSigningKeychain(
|
|
273
|
+
keychain: string,
|
|
274
|
+
env: NodeJS.ProcessEnv,
|
|
275
|
+
run: Run = runCommand,
|
|
276
|
+
): Promise<void> {
|
|
277
|
+
await run('security', ['lock-keychain', keychain], { timeoutMs: 15_000, env }).catch(
|
|
278
|
+
() => undefined,
|
|
279
|
+
)
|
|
280
|
+
}
|