@namzu/computer-use 4.4.0 → 4.6.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.
Files changed (139) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/SubprocessComputerUseHost.d.ts +8 -1
  3. package/dist/SubprocessComputerUseHost.d.ts.map +1 -1
  4. package/dist/SubprocessComputerUseHost.js +15 -4
  5. package/dist/SubprocessComputerUseHost.js.map +1 -1
  6. package/dist/a11y/a11y.d.ts +15 -7
  7. package/dist/a11y/a11y.d.ts.map +1 -1
  8. package/dist/a11y/a11y.js +12 -5
  9. package/dist/a11y/a11y.js.map +1 -1
  10. package/dist/a11y/index.d.ts +7 -1
  11. package/dist/a11y/index.d.ts.map +1 -1
  12. package/dist/a11y/index.js +4 -1
  13. package/dist/a11y/index.js.map +1 -1
  14. package/dist/a11y/macos-helper.d.ts +80 -0
  15. package/dist/a11y/macos-helper.d.ts.map +1 -0
  16. package/dist/a11y/macos-helper.js +436 -0
  17. package/dist/a11y/macos-helper.js.map +1 -0
  18. package/dist/a11y/macos-signing.d.ts +56 -0
  19. package/dist/a11y/macos-signing.d.ts.map +1 -0
  20. package/dist/a11y/macos-signing.js +228 -0
  21. package/dist/a11y/macos-signing.js.map +1 -0
  22. package/dist/a11y/macos.d.ts +173 -0
  23. package/dist/a11y/macos.d.ts.map +1 -0
  24. package/dist/a11y/macos.js +271 -0
  25. package/dist/a11y/macos.js.map +1 -0
  26. package/dist/a11y/windows.d.ts +14 -2
  27. package/dist/a11y/windows.d.ts.map +1 -1
  28. package/dist/a11y/windows.js +31 -6
  29. package/dist/a11y/windows.js.map +1 -1
  30. package/dist/adapters/cua-driver/adapter.d.ts.map +1 -1
  31. package/dist/adapters/cua-driver/adapter.js +48 -10
  32. package/dist/adapters/cua-driver/adapter.js.map +1 -1
  33. package/dist/adapters/cua-driver/ui-tree.d.ts +1 -0
  34. package/dist/adapters/cua-driver/ui-tree.d.ts.map +1 -1
  35. package/dist/adapters/cua-driver/ui-tree.js +2 -0
  36. package/dist/adapters/cua-driver/ui-tree.js.map +1 -1
  37. package/dist/adapters/darwin-ax.d.ts +94 -0
  38. package/dist/adapters/darwin-ax.d.ts.map +1 -0
  39. package/dist/adapters/darwin-ax.js +754 -0
  40. package/dist/adapters/darwin-ax.js.map +1 -0
  41. package/dist/adapters/darwin.d.ts +43 -2
  42. package/dist/adapters/darwin.d.ts.map +1 -1
  43. package/dist/adapters/darwin.js +145 -7
  44. package/dist/adapters/darwin.js.map +1 -1
  45. package/dist/adapters/png.d.ts +6 -0
  46. package/dist/adapters/png.d.ts.map +1 -0
  47. package/dist/adapters/png.js +7 -0
  48. package/dist/adapters/png.js.map +1 -0
  49. package/dist/adapters/win32-native.d.ts +53 -0
  50. package/dist/adapters/win32-native.d.ts.map +1 -0
  51. package/dist/adapters/win32-native.js +279 -0
  52. package/dist/adapters/win32-native.js.map +1 -0
  53. package/dist/adapters/win32.d.ts +19 -1
  54. package/dist/adapters/win32.d.ts.map +1 -1
  55. package/dist/adapters/win32.js +35 -8
  56. package/dist/adapters/win32.js.map +1 -1
  57. package/dist/foreground/ladder.d.ts.map +1 -1
  58. package/dist/foreground/ladder.js +5 -1
  59. package/dist/foreground/ladder.js.map +1 -1
  60. package/dist/foreground/types.d.ts +6 -0
  61. package/dist/foreground/types.d.ts.map +1 -1
  62. package/dist/foreground/types.js.map +1 -1
  63. package/dist/foreground/windows.d.ts +2 -0
  64. package/dist/foreground/windows.d.ts.map +1 -1
  65. package/dist/foreground/windows.js +24 -11
  66. package/dist/foreground/windows.js.map +1 -1
  67. package/dist/index.d.ts +9 -0
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +7 -0
  70. package/dist/index.js.map +1 -1
  71. package/dist/native/a11y.d.ts +61 -0
  72. package/dist/native/a11y.d.ts.map +1 -0
  73. package/dist/native/a11y.js +197 -0
  74. package/dist/native/a11y.js.map +1 -0
  75. package/dist/native/env.d.ts +19 -0
  76. package/dist/native/env.d.ts.map +1 -0
  77. package/dist/native/env.js +29 -0
  78. package/dist/native/env.js.map +1 -0
  79. package/dist/native/foreground-monitor.d.ts +51 -0
  80. package/dist/native/foreground-monitor.d.ts.map +1 -0
  81. package/dist/native/foreground-monitor.js +120 -0
  82. package/dist/native/foreground-monitor.js.map +1 -0
  83. package/dist/native/presence.d.ts +24 -0
  84. package/dist/native/presence.d.ts.map +1 -0
  85. package/dist/native/presence.js +47 -0
  86. package/dist/native/presence.js.map +1 -0
  87. package/dist/native/process.d.ts +73 -0
  88. package/dist/native/process.d.ts.map +1 -0
  89. package/dist/native/process.js +302 -0
  90. package/dist/native/process.js.map +1 -0
  91. package/dist/native/protocol.d.ts +476 -0
  92. package/dist/native/protocol.d.ts.map +1 -0
  93. package/dist/native/protocol.js +601 -0
  94. package/dist/native/protocol.js.map +1 -0
  95. package/dist/native/shared.d.ts +16 -0
  96. package/dist/native/shared.d.ts.map +1 -0
  97. package/dist/native/shared.js +62 -0
  98. package/dist/native/shared.js.map +1 -0
  99. package/dist/native/watch.d.ts +35 -0
  100. package/dist/native/watch.d.ts.map +1 -0
  101. package/dist/native/watch.js +45 -0
  102. package/dist/native/watch.js.map +1 -0
  103. package/dist/presence/presence.d.ts +3 -2
  104. package/dist/presence/presence.d.ts.map +1 -1
  105. package/dist/presence/presence.js.map +1 -1
  106. package/dist/presence/windows.d.ts +2 -0
  107. package/dist/presence/windows.d.ts.map +1 -1
  108. package/dist/presence/windows.js +15 -0
  109. package/dist/presence/windows.js.map +1 -1
  110. package/helper-macos/main.swift +1756 -0
  111. package/package.json +3 -2
  112. package/src/SubprocessComputerUseHost.ts +26 -2
  113. package/src/a11y/a11y.ts +25 -11
  114. package/src/a11y/index.ts +28 -1
  115. package/src/a11y/macos-helper.ts +538 -0
  116. package/src/a11y/macos-signing.ts +280 -0
  117. package/src/a11y/macos.ts +496 -0
  118. package/src/a11y/windows.ts +31 -4
  119. package/src/adapters/cua-driver/adapter.ts +55 -15
  120. package/src/adapters/cua-driver/ui-tree.ts +2 -0
  121. package/src/adapters/darwin-ax.ts +920 -0
  122. package/src/adapters/darwin.ts +184 -4
  123. package/src/adapters/png.ts +5 -0
  124. package/src/adapters/win32-native.ts +329 -0
  125. package/src/adapters/win32.ts +53 -5
  126. package/src/foreground/ladder.ts +5 -1
  127. package/src/foreground/types.ts +6 -0
  128. package/src/foreground/windows.ts +25 -11
  129. package/src/index.ts +14 -0
  130. package/src/native/a11y.ts +267 -0
  131. package/src/native/env.ts +33 -0
  132. package/src/native/foreground-monitor.ts +165 -0
  133. package/src/native/presence.ts +58 -0
  134. package/src/native/process.ts +347 -0
  135. package/src/native/protocol.ts +1103 -0
  136. package/src/native/shared.ts +75 -0
  137. package/src/native/watch.ts +78 -0
  138. package/src/presence/presence.ts +3 -2
  139. package/src/presence/windows.ts +15 -0
@@ -0,0 +1,75 @@
1
+ import { NativeWinProcess, type NativeWinProcessOptions } from './process.js'
2
+
3
+ /**
4
+ * What the monitor and the display adapter use of a helper process. Both take
5
+ * it from {@link shareNativeProcess}, so that the lease the monitor begins and
6
+ * the input the adapter sends meet in one helper, which is the only place a
7
+ * lease can refuse an input.
8
+ */
9
+ export type NativeHelper = Pick<
10
+ NativeWinProcess,
11
+ 'isUp' | 'epoch' | 'hello' | 'warm' | 'release' | 'ready' | 'close' | 'request'
12
+ >
13
+
14
+ interface Entry {
15
+ readonly process: NativeWinProcess
16
+ holders: number
17
+ }
18
+
19
+ const entries = new Map<string, Entry>()
20
+ const spawners = new WeakMap<object, number>()
21
+ let spawnerIds = 0
22
+
23
+ function keyOf(options: NativeWinProcessOptions): string {
24
+ let spawner = 0
25
+ if (options.spawnHelper) {
26
+ const known = spawners.get(options.spawnHelper)
27
+ spawner = known ?? ++spawnerIds
28
+ if (known === undefined) spawners.set(options.spawnHelper, spawner)
29
+ }
30
+ return `${options.executable}\0${spawner}`
31
+ }
32
+
33
+ /**
34
+ * One helper process for every holder that names the same executable. The
35
+ * process ends when the last holder closes; `release` (ending an idle helper)
36
+ * only takes effect for a sole holder, since the others may hold a lease or a
37
+ * watch in it.
38
+ */
39
+ export function shareNativeProcess(options: NativeWinProcessOptions): NativeHelper {
40
+ const key = keyOf(options)
41
+ let entry = entries.get(key)
42
+ if (!entry) {
43
+ entry = { process: new NativeWinProcess(options), holders: 0 }
44
+ entries.set(key, entry)
45
+ }
46
+ const shared = entry
47
+ shared.holders++
48
+ let open = true
49
+ const inner = shared.process
50
+ return {
51
+ get isUp() {
52
+ return inner.isUp
53
+ },
54
+ get epoch() {
55
+ return inner.epoch
56
+ },
57
+ get hello() {
58
+ return inner.hello
59
+ },
60
+ warm: () => inner.warm(),
61
+ ready: () => inner.ready(),
62
+ request: (request, limitMs, signal) => inner.request(request, limitMs, signal),
63
+ release: () => {
64
+ if (shared.holders === 1) inner.release()
65
+ },
66
+ close: async () => {
67
+ if (!open) return
68
+ open = false
69
+ shared.holders--
70
+ if (shared.holders > 0) return
71
+ if (entries.get(key) === shared) entries.delete(key)
72
+ await inner.close()
73
+ },
74
+ }
75
+ }
@@ -0,0 +1,78 @@
1
+ import type { NativeWinProcessOptions } from './process.js'
2
+ import type {
3
+ NativeWatchEvent,
4
+ NativeWatchKind,
5
+ NativeWatchPollReply,
6
+ NativeWatchStartRequest,
7
+ } from './protocol.js'
8
+ import { type NativeHelper, shareNativeProcess } from './shared.js'
9
+
10
+ /**
11
+ * The controls a person uses, watched through the native helper without any
12
+ * input hook: which control was invoked, focused or selected, which menu or
13
+ * window opened or closed, what an ordinary edit field says, and which
14
+ * program came to the front.
15
+ *
16
+ * The helper reads these through read-only UI Automation subscriptions. It
17
+ * never registers for the keyboard or the mouse, so nothing here is a key or a
18
+ * button; a password field reports `secure` and never its text.
19
+ */
20
+ export type NativeWatchOptions = NativeWinProcessOptions
21
+
22
+ export type NativeWatchStart = Omit<NativeWatchStartRequest, 'op'>
23
+
24
+ export interface NativeWatching {
25
+ /** UI Automation subscriptions are in place; false: only the foreground may be watched. */
26
+ readonly controls: boolean
27
+ readonly foreground: boolean
28
+ readonly kinds: readonly NativeWatchKind[]
29
+ }
30
+
31
+ const REQUEST_MS = 5_000
32
+
33
+ export class NativeWatch {
34
+ private readonly process: NativeHelper
35
+ private started = false
36
+
37
+ constructor(options: NativeWatchOptions) {
38
+ this.process = shareNativeProcess(options)
39
+ }
40
+
41
+ get running(): boolean {
42
+ return this.started && this.process.isUp
43
+ }
44
+
45
+ /** Starts watching. A helper that has no watch (an older one) is an error that says so. */
46
+ async start(options: NativeWatchStart = {}): Promise<NativeWatching> {
47
+ if (!(await this.process.ready())) throw new Error('the native Windows helper did not start')
48
+ const caps = this.process.hello?.caps ?? []
49
+ if (!caps.includes('watch')) {
50
+ throw new Error('the native Windows helper in use cannot watch the controls a person uses')
51
+ }
52
+ const reply = await this.process.request({ op: 'watch.start', ...options }, REQUEST_MS)
53
+ this.started = true
54
+ return { controls: reply.controls, foreground: reply.foreground, kinds: reply.kinds }
55
+ }
56
+
57
+ /** What happened since the last poll, and how many events were not kept. */
58
+ async poll(): Promise<NativeWatchPollReply> {
59
+ return this.process.request({ op: 'watch.poll' }, REQUEST_MS)
60
+ }
61
+
62
+ /** Takes every subscription down. Safe to call twice. */
63
+ async stop(): Promise<void> {
64
+ if (!this.started) return
65
+ this.started = false
66
+ if (this.process.isUp) await this.process.request({ op: 'watch.stop' }, REQUEST_MS)
67
+ }
68
+
69
+ async dispose(): Promise<void> {
70
+ try {
71
+ await this.stop()
72
+ } finally {
73
+ await this.process.close()
74
+ }
75
+ }
76
+ }
77
+
78
+ export type { NativeWatchEvent }
@@ -16,8 +16,9 @@ export interface PresenceMark {
16
16
  /**
17
17
  * The visible sign that an agent is operating a window: its own cursor and a
18
18
  * border around the window. It never takes input, never changes the
19
- * foreground window and is not captured by screenshots; a failure to show it
20
- * never fails an action.
19
+ * foreground window; a failure to show it never fails an action. The
20
+ * PowerShell overlay keeps itself out of screenshots; the native helper's
21
+ * does not, so a screenshot shows where the agent pointed.
21
22
  */
22
23
  export interface Presence {
23
24
  /** Shows (or refreshes) the cursor and border for one action. Does not wait. */
@@ -5,6 +5,8 @@ import {
5
5
  wslChildEnv,
6
6
  wslPowerShellPath,
7
7
  } from '../adapters/wsl.js'
8
+ import { resolveNativeHelper } from '../native/env.js'
9
+ import { NativePresence } from '../native/presence.js'
8
10
  import { type Presence, WindowsPresence } from './presence.js'
9
11
 
10
12
  /** Variable names never handed to a helper process. */
@@ -19,6 +21,8 @@ export interface WindowsPresenceFactoryOptions {
19
21
  readonly wslProbes?: WslProbes
20
22
  /** Default true. `false` shows nothing, whatever the environment says. */
21
23
  readonly enabled?: boolean
24
+ /** The native helper (`namzu-native.exe`); default `NAMZU_NATIVE_HELPER`. Named, the overlay is drawn by the helper and no PowerShell runs. */
25
+ readonly helper?: string
22
26
  }
23
27
 
24
28
  /** Whether the environment asks for the overlay to be off. */
@@ -39,6 +43,17 @@ export function createWindowsPresence(
39
43
  const platform = options.platform ?? process.platform
40
44
  const probes = options.wslProbes ?? realWslProbes
41
45
  const wsl = isWsl(env, platform, probes)
46
+ const native = resolveNativeHelper(options.helper, env)
47
+ if (native) {
48
+ if (!wsl && platform !== 'win32') return undefined
49
+ const clean: NodeJS.ProcessEnv = {}
50
+ for (const [name, value] of Object.entries(env))
51
+ if (!SECRET_NAME.test(name)) clean[name] = value
52
+ return new NativePresence({
53
+ executable: native,
54
+ env: wsl ? wslChildEnv(clean, [], probes) : clean,
55
+ })
56
+ }
42
57
  const powershell = wsl
43
58
  ? wslPowerShellPath(probes)
44
59
  : platform === 'win32'