@vortex-os/computer-use 0.1.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.
@@ -0,0 +1,84 @@
1
+ # computer-use — resident worker (throwaway PoC). JSON-lines adapter over the shared logic in lib.ps1 (MCP only).
2
+ # Contract: one request line on stdin (JSON {id,op,args}) -> process -> one response line on stdout (JSON -Compress). Logs go to stderr.
3
+ # Heavy setup (.NET, Add-Type, DPI) runs once at startup. Later calls pay no setup cost = faster than per-call spawn.
4
+ # op: probe | read_ui | capture. (watch is sent by Node over the per-call path — avoids tying up the single worker, codex #1)
5
+ $ErrorActionPreference = 'Stop'
6
+ . (Join-Path $PSScriptRoot 'lib.ps1')
7
+ Initialize-AxEnv
8
+ [Console]::Error.WriteLine("[ax-worker] ready pid=$PID")
9
+
10
+ function Write-AxResponse($obj) {
11
+ # Exactly one line (-Compress required). Depth 20 covers the read_ui tree + the {id,ok,result} wrapper (prevents tree truncation).
12
+ [Console]::Out.WriteLine(($obj | ConvertTo-Json -Compress -Depth 20))
13
+ [Console]::Out.Flush()
14
+ }
15
+
16
+ while ($null -ne ($line = [Console]::In.ReadLine())) {
17
+ $line = $line.Trim()
18
+ if ($line -eq '') { continue }
19
+ $id = $null
20
+ try {
21
+ $req = $line | ConvertFrom-Json
22
+ $id = $req.id
23
+ switch ($req.op) {
24
+ 'probe' { $res = Get-AxProbe }
25
+ 'read_ui' {
26
+ $a = $req.args; $p = @{}
27
+ if ($null -ne $a.maxDepth) { $p.MaxDepth = [int]$a.maxDepth }
28
+ if ($null -ne $a.maxElements) { $p.MaxElements = [int]$a.maxElements }
29
+ if ($null -ne $a.textCap) { $p.TextCap = [int]$a.textCap }
30
+ if ($a.target) { $p.Target = [string]$a.target }
31
+ if ($a.windowMatch) { $p.WindowMatch = [string]$a.windowMatch }
32
+ $res = Get-AxReadUi @p
33
+ }
34
+ 'capture' {
35
+ $a = $req.args; $p = @{}
36
+ if ($null -ne $a.boxW) { $p.BoxW = [int]$a.boxW }
37
+ if ($null -ne $a.boxH) { $p.BoxH = [int]$a.boxH }
38
+ if ($null -ne $a.scale) { $p.Scale = [double]$a.scale }
39
+ if ($null -ne $a.maxSide) { $p.MaxSide = [int]$a.maxSide }
40
+ if ($null -ne $a.maxPixels) { $p.MaxPixels = [long]$a.maxPixels }
41
+ if ($a.detail) { $p.Detail = [string]$a.detail }
42
+ if ($a.region) { $p.Region = [string]$a.region }
43
+ if ($a.windowMatch) { $p.WindowMatch = [string]$a.windowMatch }
44
+ if ($a.monitor) { $p.Monitor = [string]$a.monitor }
45
+ if ($null -ne $a.watchFrames) { $p.WatchFrames = [int]$a.watchFrames }
46
+ if ($null -ne $a.intervalMs) { $p.IntervalMs = [int]$a.intervalMs }
47
+ if ($a.changeOnly) { $p.ChangeOnly = $true }
48
+ if ($null -ne $a.changeThreshold) { $p.ChangeThreshold = [double]$a.changeThreshold }
49
+ if ($a.outDir) { $p.OutDir = [string]$a.outDir }
50
+ $res = Invoke-AxCapture @p
51
+ }
52
+ 'poll_change' {
53
+ $a = $req.args; $p = @{}
54
+ if ($null -ne $a.boxW) { $p.BoxW = [int]$a.boxW }
55
+ if ($null -ne $a.boxH) { $p.BoxH = [int]$a.boxH }
56
+ if ($null -ne $a.scale) { $p.Scale = [double]$a.scale }
57
+ if ($null -ne $a.maxSide) { $p.MaxSide = [int]$a.maxSide }
58
+ if ($null -ne $a.maxPixels) { $p.MaxPixels = [long]$a.maxPixels }
59
+ if ($a.detail) { $p.Detail = [string]$a.detail }
60
+ if ($a.includeImage) { $p.IncludeImage = $true }
61
+ if ($a.region) { $p.Region = [string]$a.region }
62
+ if ($a.windowMatch) { $p.WindowMatch = [string]$a.windowMatch }
63
+ if ($a.monitor) { $p.Monitor = [string]$a.monitor }
64
+ if ($null -ne $a.changeThreshold) { $p.ChangeThreshold = [double]$a.changeThreshold }
65
+ if ($a.watchId) { $p.WatchId = [string]$a.watchId }
66
+ if ($a.reset) { $p.Reset = $true }
67
+ if ($a.outDir) { $p.OutDir = [string]$a.outDir }
68
+ $res = Invoke-AxPollChange @p
69
+ }
70
+ 'beep' {
71
+ $a = $req.args; $p = @{}
72
+ if ($a.pattern) { $p.Pattern = [string]$a.pattern }
73
+ if ($a.PSObject.Properties['count']) { $p.Count = [int]$a.count } # when unset, $a.count auto-returns .Count(=1) -> must check the property exists
74
+ if ($null -ne $a.frequency) { $p.Frequency = [int]$a.frequency }
75
+ if ($null -ne $a.durationMs) { $p.DurationMs = [int]$a.durationMs }
76
+ $res = Invoke-AxBeep @p
77
+ }
78
+ default { throw "unknown op: $($req.op)" }
79
+ }
80
+ Write-AxResponse ([ordered]@{ id = $id; ok = $true; result = $res })
81
+ } catch {
82
+ Write-AxResponse ([ordered]@{ id = $id; ok = $false; error = "$($_.Exception.Message)" })
83
+ }
84
+ }