@reason-machines/cli-linux-arm64-musl 0.2.381 → 0.2.383

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 (111) hide show
  1. package/README.md +3 -1
  2. package/bin/ara +2 -2
  3. package/bin/vm-hands/api-credentials-xppmbg0m.js +2 -0
  4. package/bin/vm-hands/api-xmpbsm6b.js +2 -0
  5. package/bin/vm-hands/{ask-relay-fc0jc3t5.js → ask-relay-h8f5dmfh.js} +3 -3
  6. package/bin/vm-hands/connect-cli-qvfxpk5t.js +2 -0
  7. package/bin/vm-hands/{custom-endpoint-device-zhpake9f.js → custom-endpoint-device-bm94e9r0.js} +1 -1
  8. package/bin/vm-hands/desktop-account-3tnm4z5w.js +2 -0
  9. package/bin/vm-hands/{device-workspace-vbcry9d6.js → device-workspace-0xsj5ykf.js} +1 -1
  10. package/bin/vm-hands/hands-worker-source-azdrrhsz.js +2 -0
  11. package/bin/vm-hands/{index-bbk6a9sk.js → index-7f2kwwen.js} +1 -1
  12. package/bin/vm-hands/{install-receipt-7x81ek76.js → install-receipt-3xyx3rdd.js} +1 -1
  13. package/bin/vm-hands/local-automation-pvy9revm.js +2 -0
  14. package/bin/vm-hands/local-capabilities-zfzyknay.js +2 -0
  15. package/bin/vm-hands/local-desktop-users-ajb81vjm.js +2 -0
  16. package/bin/vm-hands/local-display-mac-9h6btvvq.js +2 -0
  17. package/bin/vm-hands/local-display-session-xqncvp30.js +2 -0
  18. package/bin/vm-hands/local-pty-session-cjas515w.js +2 -0
  19. package/bin/vm-hands/managed-runtime-s414h5nm.js +2 -0
  20. package/bin/vm-hands/{network-contract-zqvt1v0t.js → network-contract-dsw79qkc.js} +1 -1
  21. package/bin/vm-hands/package-smk3nqjs.js +2 -0
  22. package/bin/vm-hands/permissions-3mkk9mfw.js +2 -0
  23. package/bin/vm-hands/{reason-hands-protocol-8fxjynte.js → reason-hands-protocol-7d7xj1h3.js} +1 -1
  24. package/bin/vm-hands/serve-service-txzqn5kj.js +2 -0
  25. package/bin/vm-hands/status-23eqx9t3.js +96 -0
  26. package/bin/vm-hands/version-3gj9bqhc.js +2 -0
  27. package/bin/vm-hands/{vm-hands-entry-lite-7shpbsw8.js → vm-hands-entry-lite-1gxktkpe.js} +2 -2
  28. package/bin/vm-hands/vm-hands-entry-lite-2e18tm6w.js +245 -0
  29. package/bin/vm-hands/{vm-hands-entry-lite-g036gtem.js → vm-hands-entry-lite-2t0vcvd8.js} +1 -1
  30. package/bin/vm-hands/vm-hands-entry-lite-3dc4v5bd.js +11 -0
  31. package/bin/vm-hands/{vm-hands-entry-lite-hgkf1svv.js → vm-hands-entry-lite-41nygv3p.js} +2 -2
  32. package/bin/vm-hands/{vm-hands-entry-lite-j2q1k9vb.js → vm-hands-entry-lite-51hmj6am.js} +1 -1
  33. package/bin/vm-hands/{vm-hands-entry-lite-zfwg7ehq.js → vm-hands-entry-lite-5n4vsm6b.js} +2 -2
  34. package/bin/vm-hands/{vm-hands-entry-lite-k7wwza46.js → vm-hands-entry-lite-7xbgw4m0.js} +2 -2
  35. package/bin/vm-hands/vm-hands-entry-lite-8fj07njx.js +3 -0
  36. package/bin/vm-hands/{vm-hands-entry-lite-3hbe4em3.js → vm-hands-entry-lite-9cmfthkq.js} +1 -1
  37. package/bin/vm-hands/{vm-hands-entry-lite-4q8tsaqv.js → vm-hands-entry-lite-9r5tz2dx.js} +2 -2
  38. package/bin/vm-hands/{vm-hands-entry-lite-45j8qwsf.js → vm-hands-entry-lite-9w5vs9zv.js} +1 -1
  39. package/bin/vm-hands/vm-hands-entry-lite-a0yfp7s2.js +251 -0
  40. package/bin/vm-hands/{vm-hands-entry-lite-za55dtte.js → vm-hands-entry-lite-ammr3xbc.js} +2 -2
  41. package/bin/vm-hands/vm-hands-entry-lite-dh5gwmyf.js +3 -0
  42. package/bin/vm-hands/{vm-hands-entry-lite-5pm6bhb8.js → vm-hands-entry-lite-e0gdt6r5.js} +1 -1
  43. package/bin/vm-hands/{vm-hands-entry-lite-5kgvss4p.js → vm-hands-entry-lite-e2mjbqmr.js} +2 -2
  44. package/bin/vm-hands/vm-hands-entry-lite-ejm5er3h.js +7 -0
  45. package/bin/vm-hands/vm-hands-entry-lite-eqhsewc0.js +105 -0
  46. package/bin/vm-hands/{vm-hands-entry-lite-mh0xecf3.js → vm-hands-entry-lite-f02906k8.js} +4 -4
  47. package/bin/vm-hands/vm-hands-entry-lite-f5230h6t.js +67 -0
  48. package/bin/vm-hands/{vm-hands-entry-lite-zh8p7ndn.js → vm-hands-entry-lite-fb5dzy9x.js} +2 -2
  49. package/bin/vm-hands/{vm-hands-entry-lite-yjn6sk08.js → vm-hands-entry-lite-fcrqyxz0.js} +1 -1
  50. package/bin/vm-hands/vm-hands-entry-lite-fyvgav60.js +3 -0
  51. package/bin/vm-hands/vm-hands-entry-lite-g5grabna.js +540 -0
  52. package/bin/vm-hands/vm-hands-entry-lite-g7h6wjqy.js +3 -0
  53. package/bin/vm-hands/{vm-hands-entry-lite-34e71nbe.js → vm-hands-entry-lite-g8pj1jxa.js} +174 -16
  54. package/bin/vm-hands/vm-hands-entry-lite-h1rxv02g.js +458 -0
  55. package/bin/vm-hands/vm-hands-entry-lite-h8dbw0c7.js +4 -0
  56. package/bin/vm-hands/{vm-hands-entry-lite-nhtb458c.js → vm-hands-entry-lite-hnsm5t36.js} +1 -1
  57. package/bin/vm-hands/{vm-hands-entry-lite-0asdf4pm.js → vm-hands-entry-lite-jzcc9h71.js} +3 -3
  58. package/bin/vm-hands/{vm-hands-entry-lite-r6pap1kh.js → vm-hands-entry-lite-ma001vzh.js} +1 -1
  59. package/bin/vm-hands/{vm-hands-entry-lite-anmv8hp7.js → vm-hands-entry-lite-mn64e4pt.js} +286 -104
  60. package/bin/vm-hands/{vm-hands-entry-lite-9cgm6g8t.js → vm-hands-entry-lite-pk3q774c.js} +1 -1
  61. package/bin/vm-hands/vm-hands-entry-lite-qef2ndkd.js +6 -0
  62. package/bin/vm-hands/vm-hands-entry-lite-qnnfvm5r.js +5 -0
  63. package/bin/vm-hands/vm-hands-entry-lite-r8qg3wp1.js +3 -0
  64. package/bin/vm-hands/vm-hands-entry-lite-rd0ak4ye.js +4 -0
  65. package/bin/vm-hands/{vm-hands-entry-lite-00qsbphw.js → vm-hands-entry-lite-rpn0frzb.js} +2 -2
  66. package/bin/vm-hands/{vm-hands-entry-lite-g9rvf5qk.js → vm-hands-entry-lite-rtt2w6c6.js} +1 -1
  67. package/bin/vm-hands/vm-hands-entry-lite-sex82vb1.js +3 -0
  68. package/bin/vm-hands/vm-hands-entry-lite-vcwgh8tr.js +346 -0
  69. package/bin/vm-hands/{vm-hands-entry-lite-dgxxsdwb.js → vm-hands-entry-lite-xrthfx3q.js} +2 -2
  70. package/bin/vm-hands/{vm-hands-entry-lite-kxdw4myj.js → vm-hands-entry-lite-y2s2w174.js} +1 -1
  71. package/bin/vm-hands/{vm-hands-entry-lite-hc3p6r9p.js → vm-hands-entry-lite-zjfr0zh8.js} +2 -2
  72. package/bin/vm-hands/vm-hands-entry-lite.js +1 -1
  73. package/bin/vm-hands/{vm-hands-executor-qssgfea1.js → vm-hands-executor-9p92j0mv.js} +1 -1
  74. package/bin/vm-hands/vm-hands-op-runner-ers4cefp.js +2 -0
  75. package/bin/vm-hands/{vm-hands-runtime-5me6cpmn.js → vm-hands-runtime-en4gj0t0.js} +3 -3
  76. package/bin/vm-hands/worker-sandbox-tgqbmy6b.js +2 -0
  77. package/package.json +1 -1
  78. package/bin/vm-hands/api-af9g18n7.js +0 -2
  79. package/bin/vm-hands/api-credentials-65mrr3tn.js +0 -2
  80. package/bin/vm-hands/connect-cli-j478km3s.js +0 -2
  81. package/bin/vm-hands/desktop-account-5zvgspyw.js +0 -2
  82. package/bin/vm-hands/hands-worker-source-h0b1j53p.js +0 -2
  83. package/bin/vm-hands/local-automation-c86tjeft.js +0 -2
  84. package/bin/vm-hands/local-capabilities-1h99gkt6.js +0 -2
  85. package/bin/vm-hands/local-desktop-users-0hadyvx1.js +0 -2
  86. package/bin/vm-hands/local-display-mac-v1pc7177.js +0 -2
  87. package/bin/vm-hands/local-display-session-tzq0hne8.js +0 -2
  88. package/bin/vm-hands/local-pty-session-hs7rq03x.js +0 -2
  89. package/bin/vm-hands/managed-runtime-5dqaaw1x.js +0 -2
  90. package/bin/vm-hands/package-3cd7cfyv.js +0 -2
  91. package/bin/vm-hands/permissions-vbyqjbyb.js +0 -2
  92. package/bin/vm-hands/serve-service-be739c9s.js +0 -2
  93. package/bin/vm-hands/status-s8ny6men.js +0 -96
  94. package/bin/vm-hands/version-8s4syrp2.js +0 -2
  95. package/bin/vm-hands/vm-hands-entry-lite-1085xsma.js +0 -5
  96. package/bin/vm-hands/vm-hands-entry-lite-4m40gwkf.js +0 -3
  97. package/bin/vm-hands/vm-hands-entry-lite-62wmnm7g.js +0 -540
  98. package/bin/vm-hands/vm-hands-entry-lite-98076n5g.js +0 -62
  99. package/bin/vm-hands/vm-hands-entry-lite-bvbfcp1k.js +0 -4
  100. package/bin/vm-hands/vm-hands-entry-lite-c01eyep6.js +0 -3
  101. package/bin/vm-hands/vm-hands-entry-lite-dcynw6t2.js +0 -3
  102. package/bin/vm-hands/vm-hands-entry-lite-hh24bq0d.js +0 -3
  103. package/bin/vm-hands/vm-hands-entry-lite-jb2sr2r7.js +0 -3
  104. package/bin/vm-hands/vm-hands-entry-lite-kt5aj2ax.js +0 -11
  105. package/bin/vm-hands/vm-hands-entry-lite-n9nnb482.js +0 -459
  106. package/bin/vm-hands/vm-hands-entry-lite-sb9a1jcn.js +0 -4
  107. package/bin/vm-hands/vm-hands-entry-lite-xg3d0a2y.js +0 -340
  108. package/bin/vm-hands/vm-hands-entry-lite-zamt8xp7.js +0 -181
  109. package/bin/vm-hands/vm-hands-entry-lite-ze9msfq1.js +0 -3
  110. package/bin/vm-hands/vm-hands-op-runner-b76rjaps.js +0 -2
  111. package/bin/vm-hands/worker-sandbox-wpzkvwer.js +0 -2
@@ -0,0 +1,251 @@
1
+ // @bun
2
+ import{vg as k0}from"./vm-hands-entry-lite-dh5gwmyf.js";import{Mg as f0}from"./vm-hands-entry-lite-xrthfx3q.js";import{Sg as uq}from"./vm-hands-entry-lite-fb5dzy9x.js";import{ej as cq}from"./vm-hands-entry-lite-9r5tz2dx.js";import{lj as i}from"./vm-hands-entry-lite-fyvgav60.js";import{$j as G8,Uj as _,Xj as g0,_j as h0,ak as y0,ck as l8,fk as G0,hk as A0}from"./vm-hands-entry-lite-1gxktkpe.js";import{jk as H0}from"./vm-hands-entry-lite-rd0ak4ye.js";import{Ek as K}from"./vm-hands-entry-lite-51hmj6am.js";import{execFile as f1,spawn as I0}from"child_process";import{randomBytes as g1}from"crypto";import{chmodSync as h1,existsSync as p0,lstatSync as k1,mkdirSync as I1,readFileSync as p1,rmSync as v1,writeFileSync as Wq}from"fs";import{connect as u1}from"net";import{join as $}from"path";var Gq="./desktop-wallpaper-0pjhgyfk.jpg";var Aq="./dock-browser-afp005mt.png";var Sq="./dock-files-rywdm96b.png";var Vq="./dock-terminal-s41cj1jp.png";var Fq=`# Sets the X root window background and _XROOTPMAP_ID, as feh --bg-fill does.
3
+ # The native Blaxel image ships no feh, hsetroot or compositor, but it does ship
4
+ # python3-gi and libX11. tint2 reads _XROOTPMAP_ID to draw its transparent panel.
5
+ # Usage: DISPLAY=:99 python3 set-root-wallpaper.py IMAGE
6
+ import ctypes, sys
7
+ import gi
8
+ gi.require_version("GdkPixbuf", "2.0")
9
+ from gi.repository import GdkPixbuf
10
+ x = ctypes.cdll.LoadLibrary("libX11.so.6")
11
+ x.XOpenDisplay.restype = ctypes.c_void_p
12
+ x.XOpenDisplay.argtypes = [ctypes.c_char_p]
13
+ d = x.XOpenDisplay(None)
14
+ if not d: sys.exit("no display")
15
+ for name, res, args in [
16
+ ("XDefaultScreen", ctypes.c_int, [ctypes.c_void_p]),
17
+ ("XRootWindow", ctypes.c_ulong, [ctypes.c_void_p, ctypes.c_int]),
18
+ ("XDisplayWidth", ctypes.c_int, [ctypes.c_void_p, ctypes.c_int]),
19
+ ("XDisplayHeight", ctypes.c_int, [ctypes.c_void_p, ctypes.c_int]),
20
+ ("XDefaultDepth", ctypes.c_int, [ctypes.c_void_p, ctypes.c_int]),
21
+ ("XDefaultVisual", ctypes.c_void_p, [ctypes.c_void_p, ctypes.c_int]),
22
+ ("XDefaultGC", ctypes.c_void_p, [ctypes.c_void_p, ctypes.c_int]),
23
+ ("XCreatePixmap", ctypes.c_ulong, [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_uint, ctypes.c_uint, ctypes.c_uint]),
24
+ ("XCreateImage", ctypes.c_void_p, [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_uint, ctypes.c_int, ctypes.c_int, ctypes.c_char_p, ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_int]),
25
+ ("XPutImage", ctypes.c_int, [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_uint, ctypes.c_uint]),
26
+ ("XInternAtom", ctypes.c_ulong, [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]),
27
+ ("XChangeProperty", ctypes.c_int, [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int]),
28
+ ("XSetWindowBackgroundPixmap", ctypes.c_int, [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong]),
29
+ ("XClearWindow", ctypes.c_int, [ctypes.c_void_p, ctypes.c_ulong]),
30
+ ("XSetCloseDownMode", ctypes.c_int, [ctypes.c_void_p, ctypes.c_int]),
31
+ ("XCloseDisplay", ctypes.c_int, [ctypes.c_void_p]),
32
+ ]:
33
+ f = getattr(x, name); f.restype = res; f.argtypes = args
34
+ s = x.XDefaultScreen(d); root = x.XRootWindow(d, s)
35
+ w, h = x.XDisplayWidth(d, s), x.XDisplayHeight(d, s)
36
+ if x.XDefaultDepth(d, s) != 24: sys.exit("unsupported depth")
37
+ # Scale to cover the screen, then crop the centre.
38
+ src = GdkPixbuf.Pixbuf.new_from_file(sys.argv[1])
39
+ k = max(w / src.get_width(), h / src.get_height())
40
+ sw, sh = max(w, round(src.get_width() * k)), max(h, round(src.get_height() * k))
41
+ pb = src.scale_simple(sw, sh, GdkPixbuf.InterpType.BILINEAR).new_subpixbuf((sw - w) // 2, (sh - h) // 2, w, h).copy()
42
+ if pb.get_has_alpha(): pb = pb.composite_color_simple(w, h, GdkPixbuf.InterpType.NEAREST, 255, 1, 0, 0)
43
+ rgb, stride = pb.get_pixels(), pb.get_rowstride()
44
+ bgrx = bytearray(w * h * 4)
45
+ for y in range(h):
46
+ row = rgb[y * stride:y * stride + w * 3]; o = y * w * 4
47
+ bgrx[o:o + w * 4:4] = row[2::3]; bgrx[o + 1:o + w * 4:4] = row[1::3]; bgrx[o + 2:o + w * 4:4] = row[0::3]
48
+ buf = ctypes.create_string_buffer(bytes(bgrx), len(bgrx))
49
+ pix = x.XCreatePixmap(d, root, w, h, 24)
50
+ img = x.XCreateImage(d, x.XDefaultVisual(d, s), 24, 2, 0, buf, w, h, 32, 0) # ZPixmap
51
+ x.XPutImage(d, pix, x.XDefaultGC(d, s), img, 0, 0, 0, 0, w, h)
52
+ ref = ctypes.c_ulong(pix)
53
+ for atom in (b"_XROOTPMAP_ID", b"ESETROOT_PMAP_ID"):
54
+ x.XChangeProperty(d, root, x.XInternAtom(d, atom, 0), 20, 32, 0, ctypes.byref(ref), 1) # XA_PIXMAP, PropModeReplace
55
+ x.XSetWindowBackgroundPixmap(d, root, pix)
56
+ x.XClearWindow(d, root)
57
+ x.XSetCloseDownMode(d, 1) # RetainPermanent: the pixmap outlives this process
58
+ x.XCloseDisplay(d)
59
+ `;var Q8=32,Kq=76;function qx(q){return`<?xml version="1.0" encoding="UTF-8"?>
60
+ <openbox_config xmlns="http://openbox.org/3.4/rc">
61
+ <theme><keepBorder>no</keepBorder></theme>
62
+ <applications>
63
+ <!-- Debian Chromium is "Chromium"; Chrome for Testing is "Chromium-browser". -->
64
+ <application class="Chromium*">
65
+ <decor>no</decor>
66
+ <position force="yes"><x>${Q8}</x><y>${Q8}</y></position>
67
+ <size><width>${q.width-Q8*2}</width><height>${q.height-Q8-Kq}</height></size>
68
+ </application>
69
+ </applications>
70
+ </openbox_config>`}var xx=`# Remote sandbox dock \u2014 launcher icons only, centred, no panel fill
71
+ panel_items = L
72
+ panel_size = 100% 46
73
+ panel_margin = 0 10
74
+ panel_padding = 0 0 10
75
+ panel_position = bottom center horizontal
76
+ panel_shrink = 1
77
+ panel_background_id = 0
78
+ panel_layer = top
79
+ mouse_effects = 1
80
+ mouse_hover_icon_asb = 100 0 12
81
+ mouse_pressed_icon_asb = 100 0 -12
82
+
83
+ launcher_icon_size = 46
84
+ launcher_padding = 0 0 10
85
+ launcher_background_id = 0
86
+ launcher_tooltip = 1
87
+
88
+ launcher_item_app = /tmp/ara-chromium.desktop
89
+ launcher_item_app = /tmp/ara-terminal.desktop
90
+ launcher_item_app = /tmp/ara-files.desktop
91
+ `,Qx=`corner-radius = 12;
92
+ rounded-corners-exclude = [
93
+ "class_g = 'tint2'",
94
+ "window_type = 'dock'",
95
+ "window_type = 'desktop'"
96
+ ];
97
+ backend = "xrender";
98
+ shadow = false;
99
+ fading = false;
100
+ vsync = false;
101
+ inactive-opacity = 1.0;
102
+ active-opacity = 1.0;
103
+ `,Xx="/tmp/ara-dock-browser.png",Px=`[Desktop Entry]
104
+ Name=Chrome
105
+ Exec=chromium --no-sandbox %U
106
+ Icon=${Xx}
107
+ Type=Application
108
+ Categories=Network;WebBrowser;
109
+ `,bx=`[Desktop Entry]
110
+ Name=Terminal
111
+ Exec=bash -c "DISPLAY=:99 xterm -fa DejaVuSansMono -fs 11 -bg black -fg white"
112
+ Icon=/tmp/ara-dock-terminal.png
113
+ Type=Application
114
+ Categories=System;TerminalEmulator;
115
+ `,Jx=`[Desktop Entry]
116
+ Name=Files
117
+ Exec=bash -c "DISPLAY=:99 pcmanfm --no-desktop"
118
+ Icon=/tmp/ara-dock-files.png
119
+ Type=Application
120
+ Categories=System;FileManager;
121
+ `;var zq={"wallpaper.jpg":Gq,"dock-browser.png":Aq,"dock-terminal.png":Vq,"dock-files.png":Sq},Wx=Fq,Nx='set_wallpaper() { if command -v feh >/dev/null 2>&1; then feh --bg-fill "$1"; else python3 "$2" "$1"; fi; }';function Mq(q){let x=(J)=>J.replaceAll("DISPLAY=:99",`DISPLAY=${q.display}`).replaceAll("/tmp/ara-",`${q.root}/ara-`),Q=new Set(q.absent??[]),P=xx.split(`
122
+ `).filter((J)=>!(Q.has("terminal")&&J.endsWith("/ara-terminal.desktop"))&&!(Q.has("files")&&J.endsWith("/ara-files.desktop"))).join(`
123
+ `);return{files:{"openbox/rc.xml":qx(q.screen),"tint2/tint2rc":x(P),"picom/picom.conf":Qx,...Q.has("terminal")?{}:{"ara-terminal.desktop":x(bx)},...Q.has("files")?{}:{"ara-files.desktop":x(Jx)},"ara-chromium.desktop":x(Px).replace("chromium --no-sandbox %U",q.browserExec),"ara-set-root-wallpaper.py":Wx},start:['ticks() { line=$(cat "/proc/$1/stat" 2>/dev/null) || return 1; rest=${line##*) }; case $rest in Z*|X*) return 1;; esac; printf "%s" "$rest" | cut -d " " -f20; }','alive() { [ -f "$ROOT/$1.pid" ] || return 1; read -r pid start <"$ROOT/$1.pid"; current=$(ticks "$pid") || return 1; [ "$current" = "$start" ] && kill -0 "$pid" 2>/dev/null; }','launch() { name=$1; shift; "$@" 9>&- >"$ROOT/$name.log" 2>&1 & pid=$!; start=$(ticks "$pid"); printf "%s %s\\n" "$pid" "$start" >"$ROOT/$name.pid"; }',Nx,'[ ! -f "$ROOT/ara-wallpaper.jpg" ] || set_wallpaper "$ROOT/ara-wallpaper.jpg" "$ROOT/ara-set-root-wallpaper.py" || true','if ! alive tint2 && command -v tint2 >/dev/null 2>&1; then launch tint2 tint2 -c "$ROOT/tint2/tint2rc"; fi','if ! alive picom && command -v picom >/dev/null 2>&1; then launch picom picom --config "$ROOT/picom/picom.conf"; fi']}}import{createHash as lq}from"crypto";import{once as Gx}from"events";import{createWriteStream as Ax,existsSync as Sx,mkdirSync as Vx,mkdtempSync as k9,readFileSync as C8,readdirSync as I9,renameSync as Fx,realpathSync as Kx,rmSync as zx,statSync as r8,writeFileSync as Mx}from"fs";import{delimiter as v9,dirname as m8,join as Z}from"path";import{finished as Yx}from"stream/promises";var g8="omljlfpmafedpplnpkkahegadhkimdje",D9="https://chromewebstore.google.com/detail/reason/omljlfpmafedpplnpkkahegadhkimdje";function y9(q){if(!q||typeof q!=="object"||Array.isArray(q)||!("version"in q)||q.version!==1||!("status"in q))return null;if(q.status==="unavailable")return Object.keys(q).length===2?{version:1,status:"unavailable"}:null;if(q.status!=="connected"||Object.keys(q).length!==5||!("deviceId"in q)||typeof q.deviceId!=="string"||!/^[A-Za-z0-9._:-]{1,160}$/.test(q.deviceId)||!("apiOrigin"in q)||typeof q.apiOrigin!=="string"||q.apiOrigin.length>2048||!("managedRootIds"in q)||!Array.isArray(q.managedRootIds)||q.managedRootIds.length>32)return null;let x=[];for(let Q of q.managedRootIds){if(typeof Q!=="string"||!/^[A-Za-z0-9._:-]{1,160}$/.test(Q))return null;x.push(Q)}try{let Q=new URL(q.apiOrigin);if(Q.origin!==q.apiOrigin||Q.username||Q.password||!(Q.protocol==="https:"||Q.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(Q.hostname)))return null}catch{return null}return{version:1,status:"connected",deviceId:q.deviceId,apiOrigin:q.apiOrigin,managedRootIds:x}}var h={ocu:{repository:"https://github.com/iFurySt/open-codex-computer-use.git",revision:"386a260d1ab8b690adbbb27f7471595cf0c2b752",version:"0.3.5"},obu:{repository:"https://github.com/iFurySt/open-browser-use.git",revision:"ac015846df75928fbcf0f3a0f3ba3a210ce1a507",version:"0.1.42"}},v={version:"155.0.8059.84",macArm64Sha256:"13b9e98ce56f5ce18e100a009f455c9285f399e7c9dc8a76fdf2f3a9755bb5f2",linux64Sha256:"cf0f049892dea22e6a6db26d47ed0d7776b7158edcbec4634086633df8bafcbc",win64Sha256:"507f2a031441d10c62b5e3d4e863f09ac1198a571c1419976cbd8387f639afde"};var X8={ocu:{url:`https://registry.npmjs.org/open-computer-use/-/open-computer-use-${h.ocu.version}.tgz`,sha256:"7c16a87c8cd357787b02c0ebd040dd5f93880c1fb51c1901caa2e0c05d063130",size_bytes:5844280},obu:{url:`https://registry.npmjs.org/open-browser-use/-/open-browser-use-${h.obu.version}.tgz`,sha256:"9386d8ce0a147b3f55e1807b68edf736836378807541c457c9b5f6ca2cabaa4e",size_bytes:21372018},extension:{url:`https://github.com/iFurySt/open-browser-use/releases/download/v${h.obu.version}/open-browser-use-chrome-extension-${h.obu.version}.zip`,sha256:"c9c07bec1175e12ea6985b0e7784a5ef01fd03f014b958224a1e17dcd838a241",size_bytes:31070}},d="pnbmoicbkopffjjgfgfglopechaiemkp";import{spawn as k8}from"child_process";import{createRequire as Ux}from"module";import{join as Lx}from"path";var jx=30000,Bx=1048576;function I8(){return process.env.SystemRoot??"C:\\Windows"}function Cx(){return Lx(I8(),"System32","WindowsPowerShell","v1.0","powershell.exe")}var Rx=String.raw`
124
+ $ErrorActionPreference = "Stop"
125
+ Add-Type -TypeDefinition @"
126
+ using System;
127
+ using System.Runtime.InteropServices;
128
+ public static class ReasonInput {
129
+ [StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT { public int dx; public int dy; public int mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
130
+ [StructLayout(LayoutKind.Sequential)] public struct KEYBDINPUT { public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
131
+ [StructLayout(LayoutKind.Explicit)] public struct UNION { [FieldOffset(0)] public MOUSEINPUT mi; [FieldOffset(0)] public KEYBDINPUT ki; }
132
+ [StructLayout(LayoutKind.Sequential)] public struct INPUT { public uint type; public UNION u; }
133
+ [DllImport("user32.dll")] static extern uint SendInput(uint count, INPUT[] inputs, int size);
134
+ [DllImport("user32.dll")] public static extern bool SetProcessDPIAware();
135
+ [DllImport("user32.dll")] public static extern int GetSystemMetrics(int index);
136
+ [DllImport("user32.dll")] static extern uint MapVirtualKey(uint code, uint type);
137
+ [DllImport("user32.dll")] public static extern uint GetClipboardSequenceNumber();
138
+ static void Send(INPUT input) { SendInput(1, new INPUT[] { input }, Marshal.SizeOf(typeof(INPUT))); }
139
+ public static void Mouse(uint flags, int x, int y, int data) {
140
+ INPUT input = new INPUT(); input.type = 0;
141
+ input.u.mi.dx = x; input.u.mi.dy = y; input.u.mi.mouseData = data; input.u.mi.dwFlags = flags; Send(input);
142
+ }
143
+ public static void Key(ushort vk, ushort unit, uint flags) {
144
+ INPUT input = new INPUT(); input.type = 1;
145
+ input.u.ki.wVk = vk; input.u.ki.wScan = vk != 0 ? (ushort)MapVirtualKey(vk, 0) : unit; input.u.ki.dwFlags = flags; Send(input);
146
+ }
147
+ }
148
+ "@
149
+ [void][ReasonInput]::SetProcessDPIAware()
150
+ $width = [ReasonInput]::GetSystemMetrics(0)
151
+ $height = [ReasonInput]::GetSystemMetrics(1)
152
+ $session = [Diagnostics.Process]::GetCurrentProcess().SessionId
153
+ [Console]::Out.WriteLine('{"session":' + $session + ',"width":' + $width + ',"height":' + $height + '}')
154
+ [Console]::Out.Flush()
155
+ $mode = "__MODE__"
156
+ if ($mode -eq "probe") { exit 0 }
157
+ if ($mode -eq "clipboard") {
158
+ # Only changes made during this pairing: never export the initial clipboard.
159
+ $parent = Get-Process -Id __PARENT__
160
+ $last = [ReasonInput]::GetClipboardSequenceNumber()
161
+ while (-not $parent.HasExited) {
162
+ Start-Sleep -Milliseconds 100
163
+ $count = [ReasonInput]::GetClipboardSequenceNumber()
164
+ if ($count -eq $last) { continue }
165
+ $last = $count
166
+ try { $text = Get-Clipboard -Raw } catch { continue }
167
+ if (-not $text) { continue }
168
+ $bytes = [Text.Encoding]::UTF8.GetBytes($text)
169
+ if ($bytes.Length -gt __MAX_TEXT_BYTES__) { continue }
170
+ [Console]::Out.WriteLine("c " + [Convert]::ToBase64String($bytes))
171
+ [Console]::Out.Flush()
172
+ }
173
+ exit 0
174
+ }
175
+ $scaleX = 65535.0 / [Math]::Max(1, $width - 1)
176
+ $scaleY = 65535.0 / [Math]::Max(1, $height - 1)
177
+ while ($null -ne ($line = [Console]::In.ReadLine())) {
178
+ $n = $line.Split(" ")
179
+ try {
180
+ switch ($n[0]) {
181
+ "p" { [ReasonInput]::Mouse(0x8001, [int]([int]$n[1] * $scaleX), [int]([int]$n[2] * $scaleY), 0) }
182
+ "b" { [ReasonInput]::Mouse([uint32]$n[1], 0, 0, [int]$n[2]) }
183
+ "k" { [ReasonInput]::Key([uint16]$n[1], [uint16]$n[2], [uint32]$n[3]) }
184
+ "c" { Set-Clipboard -Value ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($n[1]))) }
185
+ }
186
+ } catch { [Console]::Error.WriteLine("input: $_") }
187
+ }
188
+ `;function p8(q){let x=Rx.replace("__MODE__",q).replace("__PARENT__",String(process.pid)).replace("__MAX_TEXT_BYTES__",String(_));return[Cx(),["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-EncodedCommand",Buffer.from(x,"utf16le").toString("base64")]]}var Dx=["USERPROFILE","LOCALAPPDATA","APPDATA","TEMP","TMP","PSModuleAnalysisCachePath"];function v8(){let q=Dx.flatMap((x)=>process.env[x]?[[x,process.env[x]]]:[]);return{...Object.fromEntries(q),SystemRoot:I8(),windir:I8()}}function Hq(q){let x;try{x=JSON.parse(q)}catch{return null}if(!x||typeof x!=="object")return null;let Q=x,P=(X,b)=>typeof X==="number"&&Number.isSafeInteger(X)&&X>=b;return P(Q.session,0)&&P(Q.width,1)&&P(Q.height,1)?{session:Q.session,width:Q.width,height:Q.height}:null}function fq(){return new Promise((q)=>{let x=k8(...p8("probe"),{env:v8(),stdio:["ignore","pipe","ignore"],windowsHide:!0}),Q="",P=setTimeout(()=>{x.kill("SIGKILL"),q(null)},jx);x.stdout.setEncoding("utf8").on("data",(X)=>{Q+=X}),x.once("error",()=>{clearTimeout(P),q(null)}),x.once("close",()=>{clearTimeout(P),q(Hq(Q.split(/\r?\n/)[0]??""))})})}var P8;function gq(){if(P8!==void 0)return P8;if(process.platform!=="win32")return P8=!1;try{let q=Ux(import.meta.url)("bun:ffi"),{symbols:x}=q.dlopen("kernel32.dll",{GetCurrentProcessId:{args:[],returns:q.FFIType.u32},ProcessIdToSessionId:{args:[q.FFIType.u32,q.FFIType.ptr],returns:q.FFIType.i32}}),Q=new Uint32Array(1);return P8=x.ProcessIdToSessionId(x.GetCurrentProcessId(),Q)!==0&&Q[0]>0}catch{return P8=!1}}var Yq=[{bit:1,down:2,up:4},{bit:2,down:32,up:64},{bit:4,down:8,up:16}],wq=2048,_q=4096,Tx=[[8,wq,120],[16,wq,-120],[32,_q,-120],[64,_q,120]],$q=1,h8=2,Zx=4,yx=new Set([65505,65506]),Oq=new Set([65507,65508,65511,65512,65513,65514,65027,65515,65516]),Eq=new Map([[65505,[160,!1]],[65506,[161,!1]],[65507,[162,!1]],[65508,[163,!0]],[65511,[164,!1]],[65512,[165,!0]],[65513,[164,!1]],[65514,[165,!0]],[65027,[165,!0]],[65515,[91,!0]],[65516,[92,!0]],[65288,[8,!1]],[65289,[9,!1]],[65056,[9,!1]],[65293,[13,!1]],[65307,[27,!1]],[65535,[46,!0]],[65379,[45,!0]],[65360,[36,!0]],[65367,[35,!0]],[65365,[33,!0]],[65366,[34,!0]],[65361,[37,!0]],[65362,[38,!0]],[65363,[39,!0]],[65364,[40,!0]],[65383,[93,!0]],[65509,[20,!1]],[65299,[19,!1]],[65300,[145,!1]],[65377,[44,!0]],[65407,[144,!0]],[32,[32,!1]],[65421,[13,!0]],[65408,[32,!1]],[65450,[106,!1]],[65451,[107,!1]],[65452,[108,!1]],[65453,[109,!1]],[65454,[110,!1]],[65455,[111,!0]],[65429,[36,!1]],[65430,[37,!1]],[65431,[38,!1]],[65432,[39,!1]],[65433,[40,!1]],[65434,[33,!1]],[65435,[34,!1]],[65436,[35,!1]],[65438,[45,!1]],[65439,[46,!1]],...Array.from({length:10},(q,x)=>[65456+x,[96+x,!1]]),...Array.from({length:24},(q,x)=>[65470+x,[112+x,!1]])]);class hq{x=-1;y=-1;mask=0;held=new Set;pressed=new Set;pointer(q,x,Q){let P=[];if(q!==this.x||x!==this.y)this.x=q,this.y=x,P.push(`p ${q} ${x}`);for(let X of Yq){let b=(this.mask&X.bit)!==0,J=(Q&X.bit)!==0;if(b!==J)P.push(`b ${J?X.down:X.up} 0`)}for(let[X,b,J]of Tx)if(!(this.mask&X)&&Q&X)P.push(`b ${b} ${J}`);return this.mask=Q,P}key(q,x){let Q=q?0:h8;if(yx.has(x)||Oq.has(x))if(q)this.held.add(x);else this.held.delete(x);let P=Eq.get(x);if(P)return[`k ${P[0]} 0 ${Q|(P[1]?$q:0)}`];let X=x<256?x:(x&4278190080)===16777216?x&16777215:0,b=String.fromCharCode(X),J=[...this.held].some((T)=>Oq.has(T)),N=/^[A-Za-z0-9]$/.test(b)?b.toUpperCase().charCodeAt(0):0;if(N&&(q?J:this.pressed.has(N))){if(q)this.pressed.add(N);else this.pressed.delete(N);return[`k ${N} 0 ${Q}`]}if(X<33||X>=127&&X<160||X>65535||X>=55296&&X<57344)return[];return[`k 0 ${X} ${Q|Zx}`]}release(){let q=Yq.filter((x)=>this.mask&x.bit).map((x)=>`b ${x.up} 0`);for(let x of this.pressed)q.push(`k ${x} 0 ${h8}`);for(let x of this.held){let[Q,P]=Eq.get(x);q.push(`k ${Q} 0 ${h8|(P?$q:0)}`)}return this.mask=0,this.pressed.clear(),this.held.clear(),q}}function kq(q){let x=k8(...p8("input"),{env:v8(),stdio:["pipe","pipe","ignore"],windowsHide:!0}),Q=new hq,P="",X=!1,b=null,J=()=>{if(b?.kill("SIGKILL"),x.exitCode!==null||x.signalCode!==null)return;x.stdin.end(Q.release().map((U)=>`${U}
189
+ `).join("")),setTimeout(()=>x.kill("SIGKILL"),2000).unref()},N=(U)=>{if(X)return;X=!0,J(),q.end(U)},T=(U)=>N({error:new K("display_unavailable",U)}),L=(U)=>{if(X||U.length===0)return;if(x.stdin.write(U.map((y)=>`${y}
190
+ `).join("")),x.stdin.writableLength>Bx)N({reason:"input_backpressure"})},C=()=>{b=k8(...p8("clipboard"),{env:v8(),stdio:["ignore","pipe","ignore"],windowsHide:!0});let U="";b.stdout?.on("data",(y)=>{if(X)return;U+=y.toString("ascii");for(let R=U.indexOf(`
191
+ `);R>=0;R=U.indexOf(`
192
+ `)){let Y=U.slice(0,R).replace(/\r$/,"");if(U=U.slice(R+1),!Y.startsWith("c "))continue;let S=Y.slice(2);if(S.length>Math.ceil(_/3)*4||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(S)){N({reason:"display_protocol"});return}let W=Buffer.from(S,"base64");if(W.byteLength<=_)q.clipboard(W.toString("utf8"));if(X)return}if(U.length>Math.ceil(_/3)*4+4)N({reason:"display_protocol"})}),b.once("error",()=>T("Reason could not watch this computer's desktop clipboard.")),b.once("exit",()=>{if(!X)T("Reason could not watch this computer's desktop clipboard.")})};return x.stdout.on("data",(U)=>{if(X||P===null)return;P+=U.toString("utf8");let y=P.indexOf(`
193
+ `);if(y<0){if(P.length>4096)N({reason:"display_protocol"});return}let R=Hq(P.slice(0,y).trim());if(P=null,!R)N({reason:"display_protocol"});else if(R.session===0)T("This Windows worker runs as a service, which has no desktop: run it in the signed-in desktop session.");else C(),q.ready({width:R.width,height:R.height})}),x.stdin.on("error",()=>{return}),x.once("error",()=>T("Reason could not start this computer's desktop input.")),x.once("exit",()=>{if(P!==null)T("Reason could not start this computer's desktop input.");else N({reason:"display_closed"})}),{pointer:(U,y,R)=>L(Q.pointer(U,y,R)),key:(U,y)=>L(Q.key(U,y)),clipboard:(U)=>L([`c ${Buffer.from(U,"utf8").toString("base64")}`]),close(){X=!0,J()}}}var wx=["none","standard","all"],B8="22.23.3",_x={"linux-x64":"1084aa36196bba4c3a5e69a1ee388a6e4ff729dad09445fbcd434b28fe3c24af","linux-arm64":"5ced2d48d1d7198739b7f86804de0171aefb6823b684b12341d3321afc3cb0b2","darwin-arm64":"23b25245dcfb9af7262f8ff142e9e2e0af025368117329e7a7458a51e5922f53","win32-x64":"2b0ff57b049cda1bbcea2240eec20467018713c1efe1f7360c2681859b90ed71","win32-arm64":"33dad22e4cef5ee8f9fbb1b0d037fdacd0e56d12a4580f0d63f68b894deab535"},u8={"linux-x64":{ocu:"dist/linux/amd64/open-computer-use",obu:"native/linux-amd64/open-browser-use"},"linux-arm64":{ocu:"dist/linux/arm64/open-computer-use",obu:"native/linux-arm64/open-browser-use"},"darwin-arm64":{ocu:"dist/Open Computer Use.app/Contents/MacOS/OpenComputerUse",obu:"native/darwin-arm64/open-browser-use"},"win32-x64":{ocu:"dist/windows/amd64/open-computer-use.exe",obu:"native/windows-amd64/open-browser-use.exe"},"win32-arm64":{ocu:"dist/windows/arm64/open-computer-use.exe",obu:"native/windows-arm64/open-browser-use.exe"}},rq="chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing",mq="chrome-win64/chrome.exe",a={version:"9.0.2",url:"https://ffmpeg.martin-riedl.de/download/macos/arm64/1789931890_9.0.2/ffmpeg.zip",sha256:"c8ed4c4e6978a03c485edbfe4e0a5dc2380f8a30bba5150531b31b094492d924"},$x={version:a.version,url:"https://ffmpeg.martin-riedl.de/download/macos/arm64/1789931890_9.0.2/ffprobe.zip",sha256:"fcbe839537485eaee7a7a8bc5cbc0f90d53617e80943e8a5b2e31cb851197ea6"},c8={version:a.version,url:`https://github.com/GyanD/codexffmpeg/releases/download/${a.version}/ffmpeg-${a.version}-essentials_build.zip`,sha256:"60f467265b1e312373dbcd92200c2618a74850f98d3d078e94296bb3fa2047ba"},Iq=`ffmpeg-${c8.version}-essentials_build/bin`,c="com.ifuryst.open_browser_use.extension",dq="com.reasonmachines.browser_use.extension",pq="/tmp/reason-browser-use",d8=["tint2","picom","xterm","pcmanfm"],aq=["fonts-droid-fallback"],sq=["pulseaudio"],Ox=["xvfb","openbox","x11vnc","x11-utils","x11-xserver-utils","xdotool","dbus-x11","at-spi2-core","python3","python3-gi","gir1.2-atspi-2.0","gir1.2-gtk-3.0","fonts-dejavu-core",...aq,"galculator","chromium","ffmpeg","tmux",...sq,...d8],Ex=new Set([...d8,...aq,...sq]),vq=Ox.filter((q)=>q!=="chromium"&&!Ex.has(q)),Hx=["Xvfb","openbox","x11vnc","xdotool","dbus-launch","python3","ffmpeg","tmux"],j8="/usr/bin/chromium",fx=["/usr/local/bin","/usr/bin","/bin","/opt/homebrew/bin"];function iq(q=process.platform,x=process.arch){let Q=`${q}-${x}`;return Q==="linux-x64"||Q==="linux-arm64"||Q==="darwin-arm64"||Q==="win32-x64"||Q==="win32-arm64"?Q:null}function s(q){return q==="win32-x64"||q==="win32-arm64"}function a8(q){return s(q)?`node-v${B8}-${q.replace("win32","win")}`:`node-v${B8}-${q}`}function R8(q){return{node:{version:B8,url:`https://nodejs.org/dist/v${B8}/${a8(q)}${s(q)?".zip":".tar.gz"}`,sha256:_x[q]},open_computer_use:{version:h.ocu.version,url:X8.ocu.url,sha256:X8.ocu.sha256},open_browser_use:{version:h.obu.version,url:X8.obu.url,sha256:X8.obu.sha256},...q==="darwin-arm64"?{chrome_for_testing:{version:v.version,url:`https://storage.googleapis.com/chrome-for-testing-public/${v.version}/mac-arm64/chrome-mac-arm64.zip`,sha256:v.macArm64Sha256}}:s(q)?{chrome_for_testing:{version:v.version,url:`https://storage.googleapis.com/chrome-for-testing-public/${v.version}/win64/chrome-win64.zip`,sha256:v.win64Sha256}}:{}}}function gx(q){let x={extension:d};for(let[Q,P]of Object.entries(R8(q)))x[Q]=`${P.version}@${P.sha256}`;return x}function nq(q){return Z(q,".local","share","reason","desktop")}function oq(q,x=uq()){let Q=nq(x),P=(U)=>Z(Q,U,R8(q)[U]?.version??""),X=P("open_computer_use"),b=P("open_browser_use"),J=q==="darwin-arm64",N=s(q),T=Z(x,"Library","Application Support"),L=Z(process.platform==="win32"&&process.env.LOCALAPPDATA?process.env.LOCALAPPDATA:Z(x,"AppData","Local"),"OpenBrowserUse"),C=J?Z(T,"Google","Chrome","NativeMessagingHosts",`${c}.json`):N?Z(L,"NativeMessagingHosts",`${c}.json`):Z(x,".config","google-chrome","NativeMessagingHosts",`${c}.json`);return{root:Q,automation:Z(m8(Q),"automation"),receipt:Z(Q,"receipt.json"),minimal:i8(x),node:N?Z(P("node"),a8(q),"node.exe"):Z(P("node"),"bin","node"),ocuDir:X,ocu:Z(X,u8[q].ocu),ocuApp:J?Z(X,"dist","Open Computer Use.app"):null,obuDir:b,obu:Z(b,"cli","open-browser-use.js"),nativeHost:Z(b,u8[q].obu),extensionDir:J?Z(T,"OpenBrowserUse","chrome-extension","release"):N?Z(L,"chrome-extension","release"):Z(x,".local","share","open-browser-use","chrome-extension","release"),setupNativeHostManifest:C,nativeHostManifests:J?[C,Z(T,"Google","ChromeForTesting","NativeMessagingHosts",`${c}.json`)]:N?[C]:[Z(x,".config","chromium","NativeMessagingHosts",`${c}.json`),Z(x,".config","google-chrome-for-testing","NativeMessagingHosts",`${c}.json`)],browser:J?Z(P("chrome_for_testing"),rq):N?Z(P("chrome_for_testing"),mq):j8,userChromeHost:J?Z(Q,"user-chrome","reason-browser-use"):null,userChromeRegistration:J?Z(T,"Google","Chrome","NativeMessagingHosts",`${dq}.json`):null,ffmpegDir:Z(Q,"ffmpeg"),ffmpeg:J?Z(Q,"ffmpeg",a.version,"ffmpeg"):N?Z(Q,"ffmpeg",c8.version,Iq,"ffmpeg.exe"):null,ffprobe:J?Z(Q,"ffprobe",$x.version,"ffprobe"):N?Z(Q,"ffmpeg",c8.version,Iq,"ffprobe.exe"):null}}function tq(q){try{let x=JSON.parse(C8(q,"utf8"));if(typeof x!=="object"||x===null)return null;let Q=x,P=Q.pins;if(Q.schema_version!==1||typeof Q.platform!=="string"||typeof P!=="object"||P===null||!Object.values(P).every((X)=>typeof X==="string")||!wx.includes(Q.permissions)||!Array.isArray(Q.missing_system_packages)||!Q.missing_system_packages.every((X)=>typeof X==="string")||typeof Q.updated_at!=="string")return null;return{schema_version:1,platform:Q.platform,pins:P,permissions:Q.permissions,missing_system_packages:Q.missing_system_packages,updated_at:Q.updated_at}}catch{return null}}function hx(q,x,Q=384){Vx(m8(q),{recursive:!0,mode:448});let P=`${q}.pending.${process.pid}`;Mx(P,x,{mode:Q}),Fx(P,q)}function k(q){try{return r8(q).isFile()}catch{return!1}}function eq(q){try{let x=r8(q);return x.isFile()&&(x.mode&73)!==0}catch{return!1}}function kx(q){try{return C8(q,"utf8")}catch{return null}}function u(q){for(let x of fx){let Q=Z(x,q);try{let P=r8(Q);if(P.isFile()&&(P.mode&73)!==0)return Q}catch{}}return null}function Ix(q){try{let x=JSON.parse(C8(Z(q,"package.json"),"utf8"));return typeof x==="object"&&x!==null&&typeof x.version==="string"?x.version:null}catch{return null}}function px(q,x,Q){let P=R8(Q)[q];if(!P)return!1;let X=s(Q);if(q==="node")return k(X?Z(x,a8(Q),"node.exe"):Z(x,"bin","node"));if(q==="chrome_for_testing")return k(Z(x,X?mq:rq));let b=u8[Q][q==="open_computer_use"?"ocu":"obu"];return Ix(x)===P.version&&k(Z(x,b))&&(q==="open_computer_use"||k(Z(x,"cli","open-browser-use.js")))}function vx(q){return lq("sha256").update(Buffer.from(q,"base64")).digest("hex").slice(0,32).replace(/./g,(x)=>String.fromCharCode(97+Number.parseInt(x,16)))}function s8(q){try{let x=JSON.parse(C8(q,"utf8"));return typeof x==="object"&&x!==null&&!Array.isArray(x)?x:null}catch{return null}}function ux(q){let x=s8(Z(q.extensionDir,"manifest.json"));return x!==null&&x.version===h.obu.version&&typeof x.key==="string"&&vx(x.key)===d}function cx(q,x){let Q=q?.allowed_origins;return q!==null&&q.name===c&&Array.isArray(Q)&&Q.length===1&&Q[0]===`chrome-extension://${d}/`&&(x===void 0||q.path===x)}function lx(q){return ux(q)&&k(q.nativeHost)&&q.nativeHostManifests.every((x)=>cx(s8(x),q.nativeHost))}function rx(q){return`#!/bin/sh
194
+ # Reason's Chrome extension host (reason desktop install): Open Browser Use on Reason's socket directory.
195
+ obu=${`'${q.replaceAll("'","'\\''")}'`}
196
+ case "$1" in
197
+ chrome-extension://*) exec "$obu" host --socket-dir ${pq} ;;
198
+ mcp) shift; exec "$obu" mcp --socket-dir ${pq} "$@" ;;
199
+ esac
200
+ exec "$obu" "$@"
201
+ `}function mx(q){let x=s8(q),Q=x?.allowed_origins;return x!==null&&x.name===dq&&x.type==="stdio"&&Array.isArray(Q)&&Q.includes(`chrome-extension://${g8}/`)&&typeof x.path==="string"&&eq(x.path)}function dx(q,x){if(!q.userChromeHost||!q.userChromeRegistration)return null;if(!x||kx(q.userChromeHost)!==rx(q.nativeHost)||!eq(q.userChromeHost))return{code:"user_chrome_browser_use_missing"};return mx(q.userChromeRegistration)?{host:q.userChromeHost}:{code:"user_chrome_native_host_unregistered"}}var ax={display:["display","desktop_session","desktop_video"],computer:["display","desktop_session","system_packages","node","open_computer_use"],browser:["display","desktop_session","system_packages","node","open_computer_use","open_browser_use","browser_extension","browser","chrome_for_testing"]};function I(q={}){let x=q.platform===void 0?iq():q.platform;if(!x)return null;let Q=oq(x,q.home),P=tq(Q.receipt),X=gx(x),b=P!==null&&P.platform===x&&JSON.stringify(Object.entries(P.pins).sort())===JSON.stringify(Object.entries(X).sort()),J=[],N=R8(x);for(let W of["node","open_computer_use","open_browser_use","chrome_for_testing"]){let G=N[W];if(!G)continue;let V=px(W,Z(Q.root,W,G.version),x),F=P?.pins[W],E=V&&F===X[W]?"ready":F!==void 0&&F!==X[W]?"outdated":"missing";J.push({name:W,state:E,detail:G.version})}let T=P?.pins.extension===d&&lx(Q);J.push({name:"browser_extension",state:T?"ready":"missing",detail:d});let L=u("Xvfb"),C=u("x11vnc"),U=u("openbox");if(s(x))J.push(gq()?{name:"desktop_session",state:"ready",detail:"signed-in desktop session"}:{name:"desktop_session",state:"missing",detail:"run the worker in the signed-in desktop session, not as a service"}),J.push(Q.ffmpeg&&k(Q.ffmpeg)?{name:"desktop_video",state:"ready",detail:Q.ffmpeg}:{name:"desktop_video",state:"missing",detail:"run `reason desktop install` for desktop video"});else if(x!=="darwin-arm64"){J.push(k(j8)?{name:"browser",state:"ready",detail:j8}:{name:"browser",state:"missing",detail:`non-snap Chromium at ${j8}`});let W=L!==null&&C!==null&&U!==null;J.push({name:"display",state:W?"ready":"missing",detail:"Xvfb + openbox + x11vnc"});let G=Hx.filter((w)=>u(w)===null),V=(P?.missing_system_packages??vq).filter((w)=>vq.includes(w)),F=G.length===0&&V.length===0;J.push(F?{name:"system_packages",state:"ready"}:{name:"system_packages",state:"missing",detail:[...new Set([...V,...G])].join(" ")});let E=d8.filter((w)=>u(w)===null);J.push(E.length===0?{name:"desktop_look",state:"ready"}:{name:"desktop_look",state:"missing",detail:E.join(" ")})}let y=Q.ffmpeg&&k(Q.ffmpeg)?Q.ffmpeg:u("ffmpeg"),R=!y?null:y===Q.ffmpeg?Q.ffprobe:Z(m8(Kx(y)),"ffprobe"),Y=b&&J.every((W)=>W.state==="ready"),S=(W)=>b&&J.every((G)=>!ax[W].includes(G.name)||G.state==="ready");return{platform:x,root:Q.root,automation:Q.automation,ready:Y,features:{display:S("display"),computer:S("computer"),browser:S("browser")},node:Q.node,ocu:Q.ocu,obu:Q.obu,nativeHost:Q.nativeHost,extensionDir:Q.extensionDir,browser:Q.browser,ffmpeg:y,ffprobe:R&&k(R)?R:null,userChrome:dx(Q,b&&["node","open_browser_use"].every((W)=>J.find((G)=>G.name===W)?.state==="ready")),pulseaudio:u("pulseaudio"),xvfb:L,x11vnc:C,openbox:U,components:J}}function q0(q){return sx(q)?cq():[]}function sx(q){return q?.platform==="darwin-arm64"&&q.ffmpeg===Z(q.root,"ffmpeg",a.version,"ffmpeg")}async function t9(q,x,Q,P=fetch){try{let X=await P(q,{redirect:"follow"});if(!X.ok||!X.body)throw Error(`download failed (HTTP ${X.status}): ${q}`);let b=lq("sha256"),J=Ax(Q,{mode:384});try{let T=X.body.getReader();for(let L=await T.read();!L.done;L=await T.read())if(b.update(L.value),!J.write(L.value))await Gx(J,"drain")}finally{J.end(),await Yx(J)}let N=b.digest("hex");if(N!==x)throw Error(`digest mismatch for ${q}: expected ${x}, got ${N}`)}catch(X){throw zx(Q,{force:!0}),X}}function i8(q){return Z(nq(q),"minimal.json")}function ix(q=i()){return Sx(i8(q))}function e9(q={}){hx(i8(q.home??i()),`${JSON.stringify({version:1,minimal_at:(q.now?.()??new Date).toISOString()})}
202
+ `)}function qQ(q={}){let x=q.platform===void 0?iq():q.platform;if(x===null)return null;let Q=q.home??i();if(tq(oq(x,Q).receipt)!==null)return"refresh";return ix(Q)?null:"install"}import{execFile as N1,spawn as Qq}from"child_process";import{existsSync as U1}from"fs";import{connect as L1}from"net";function nx(){let q=new Set,x=null,Q=(X)=>({holder:x?.viewer??null,you:x===X,same_user:Boolean(x?.viewer&&X.viewer&&x.viewer.user_id===X.viewer.user_id)}),P=()=>{for(let X of q)X.notify(Q(X))};return{join(X){return q.add(X),X.notify(Q(X)),()=>{if(!q.delete(X))return;if(x!==X)return;x=null,P()}},claim(X){if(x===X||!q.has(X))return;x=X,P()}}}var x0=nx();import{spawn as ox}from"child_process";import{existsSync as tx}from"fs";import{connect as ex}from"net";import{join as D8}from"path";var X0="reason_desktop",b8={sampleRate:48000,channels:2,codec:"opus"},q1=5000,x1=107,Q1=262144,t8=(q)=>D8(q,"native"),T8=(q)=>`unix:${q}`;function n8(q,x=1000){if(!tx(q))return Promise.resolve(!1);return new Promise((Q)=>{let P=ex({path:q}),X=(b)=>{P.destroy(),Q(b)};P.setTimeout(x,()=>X(!1)),P.once("error",()=>X(!1)),P.once("close",()=>X(!1)),P.once("connect",()=>X(!0))})}async function P0(q,x){if(!x)return null;let Q=t8(q);if(Buffer.byteLength(Q)>x1||/["'\\\s]/.test(Q))return null;try{if(await n8(Q))return Q;let P=ox(x,["--daemonize=no","--system=no","--use-pid-file=no","--exit-idle-time=-1","--disallow-exit=yes","--realtime=no","--high-priority=no","--disallow-module-loading=yes","--log-level=warning",`--log-target=file:${D8(q,"pulseaudio.log")}`,"-n",`--load=module-native-protocol-unix socket="${Q}" auth-anonymous=1 auth-cookie-enabled=0`,`--load=module-null-sink sink_name=${X0} rate=${b8.sampleRate} channels=${b8.channels} sink_properties=device.description=Reason_desktop`],{detached:!0,stdio:"ignore",env:{HOME:q,PATH:"/usr/bin:/bin",XDG_RUNTIME_DIR:q,PULSE_RUNTIME_PATH:D8(q,"runtime"),PULSE_STATE_PATH:D8(q,"state")}}),X=!1;P.once("error",()=>{X=!0}),P.once("exit",()=>{X=!0}),P.unref();let b=Date.now()+q1;while(Date.now()<b){if(await n8(Q))return Q;if(X)return await n8(Q)?Q:null;await new Promise((J)=>setTimeout(J,50))}if(!X)P.kill("SIGKILL");return null}catch{return null}}function b0(){let{sampleRate:q,channels:x}=b8;return["-hide_banner","-loglevel","error","-nostdin","-fflags","nobuffer","-f","pulse","-sample_rate",String(q),"-channels",String(x),"-fragment_size",String(q*x*2/50),"-i",`${X0}.monitor`,"-vn","-ac",String(x),"-ar",String(q),"-c:a","libopus","-b:a","64k","-application","lowdelay","-frame_duration","20","-flush_packets","1","-page_duration","20000","-f","ogg","pipe:1"]}var X1=[79,103,103,83],P1=Buffer.from("OpusHead"),b1=Buffer.from("OpusTags"),Q0=(q,x)=>q.byteLength>=x.byteLength&&x.every((Q,P)=>q[P]===Q);class o8 extends Error{constructor(q){super(q);this.name="OggProtocolError"}}class e8{buffer=new Uint8Array(0);partial=[];partialBytes=0;push(q){let x=new Uint8Array(this.buffer.byteLength+q.byteLength);x.set(this.buffer),x.set(q,this.buffer.byteLength);let Q=[],P=0;while(x.byteLength-P>=27){if(X1.some((y,R)=>x[P+R]!==y)||x[P+4]!==0)throw new o8("invalid_page");let X=(x[P+5]&1)!==0,b=x[P+26];if(x.byteLength-P<27+b)break;let J=x.subarray(P+27,P+27+b),N=J.reduce((y,R)=>y+R,0),T=27+b+N;if(x.byteLength-P<T)break;if(!X&&this.partialBytes>0)this.resetPartial();let L=X&&this.partialBytes===0,C=P+27+b,U=C;for(let y of J){if(C+=y,y===255)continue;if(this.appendPartial(x.subarray(U,C),L),U=C,!L){let R=this.takePartial();if(R.byteLength>0&&!Q0(R,P1)&&!Q0(R,b1))Q.push(R)}L=!1,this.resetPartial()}if(U<C)this.appendPartial(x.subarray(U,C),L);P+=T}return this.buffer=x.slice(P),Q}appendPartial(q,x){if(x||q.byteLength===0)return;if(this.partialBytes+=q.byteLength,this.partialBytes>Q1)throw new o8("packet_too_large");this.partial.push(q.slice())}takePartial(){if(this.partial.length===1)return this.partial[0];let q=new Uint8Array(this.partialBytes),x=0;for(let Q of this.partial)q.set(Q,x),x+=Q.byteLength;return q}resetPartial(){this.partial=[],this.partialBytes=0}}import{spawn as J1}from"child_process";var J0=1048576,W1=String.raw`
203
+ import gi, json, os, sys
204
+ gi.require_version("Gtk", "3.0")
205
+ from gi.repository import Gtk, Gdk, GLib
206
+ if not Gtk.init_check()[0]:
207
+ sys.exit(1)
208
+ clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
209
+ pending = b""
210
+ generation = 0
211
+ def send(value):
212
+ print(json.dumps(value, ensure_ascii=True), flush=True)
213
+ def changed(clipboard, event):
214
+ global generation
215
+ generation += 1
216
+ current = generation
217
+ def received(clipboard, text, unused):
218
+ if current == generation and text is not None and len(text.encode("utf-8")) <= ${_}:
219
+ send({"text": text})
220
+ clipboard.request_text(received, None)
221
+ # No request_text on startup: never share the pre-existing clipboard.
222
+ clipboard.connect("owner-change", changed)
223
+ def input_ready(fd, condition):
224
+ global pending
225
+ chunk = os.read(fd, 65536)
226
+ if not chunk:
227
+ Gtk.main_quit()
228
+ return False
229
+ pending += chunk
230
+ while b"\n" in pending:
231
+ line, pending = pending.split(b"\n", 1)
232
+ text = json.loads(line)
233
+ if not isinstance(text, str) or len(text.encode("utf-8")) > ${_} or "\x00" in text:
234
+ sys.exit(1)
235
+ clipboard.set_text(text, -1)
236
+ send("ack")
237
+ if len(pending) > ${_*6+2}:
238
+ sys.exit(1)
239
+ return True
240
+ GLib.io_add_watch(0, GLib.IO_IN | GLib.IO_HUP, input_ready)
241
+ send("ready")
242
+ Gtk.main()
243
+ `;function W0(q,x){let Q=J1("/usr/bin/python3",["-I","-u","-c",W1],{env:{DISPLAY:q.display,XAUTHORITY:q.xauthority},stdio:["pipe","pipe","ignore"]}),P=!1,X=!0,b="",J=0,N=[],T=setTimeout(()=>C(),5000),L=()=>{P=!0,clearTimeout(T),N.length=0,Q.kill("SIGKILL")},C=()=>{if(P)return;L(),x.end({error:new K("display_unavailable","Reason could not start this Linux desktop's UTF-8 clipboard.")})},U=(y,R=32)=>{if(P)return;if(!X){y();return}if(J+=R,J>J0)L(),x.end({reason:"input_backpressure"});else N.push({apply:y,bytes:R})};return Q.stdout.on("data",(y)=>{if(P)return;b+=y.toString("ascii");for(let R=b.indexOf(`
244
+ `);R>=0;R=b.indexOf(`
245
+ `)){let Y=b.slice(0,R);b=b.slice(R+1);let S;try{S=JSON.parse(Y)}catch{C();return}if(S==="ready"||S==="ack"){clearTimeout(T),X=!1;while(!X&&!P&&N.length){let W=N.shift();J-=W.bytes,W.apply()}}else if(S&&typeof S==="object"&&"text"in S&&typeof S.text==="string"&&Buffer.byteLength(S.text)<=_)x.clipboard(S.text);else{C();return}if(P)return}if(b.length>_*6+32)C()}),Q.stdin.on("error",C),Q.once("error",C),Q.once("exit",C),{apply:U,write(y){if(Buffer.byteLength(y)>_||y.includes("\x00")){C();return}let R=`${JSON.stringify(y)}
246
+ `;U(()=>{if(X=!0,T=setTimeout(()=>C(),5000),Q.stdin.write(R),Q.stdin.writableLength>J0)L(),x.end({reason:"input_backpressure"})},Buffer.byteLength(R))},close:L}}var n={smooth:{fps:60,crf:23,kbps:8000,x264Preset:"ultrafast",threads:2,scale:1},sharp:{fps:30,crf:19,kbps:1e4,x264Preset:"superfast",scale:1},data_saver:{fps:20,crf:28,kbps:2000,x264Preset:"ultrafast",scale:0.75},balanced:{fps:30,crf:23,kbps:4000,x264Preset:"ultrafast",threads:2,scale:1}},j1="avc1.4D002A",N0={width:1920,height:1080},B1=262144,C1=0.2,R1=250,D1=1e4,T1=1024,qq=1e4,Z1=500,y1=60,G1=1e4,A1=1000,U0=1048576,S0={kind:"mac_screen",sound:null},V0={kind:"windows_screen",sound:null},S1,L0=()=>S1??=I()?.ffmpeg??null,y8=(q,x,Q)=>Qq(q,x,{env:Q,stdio:["ignore","pipe","ignore"],windowsHide:!0}),V1,Xq=()=>V1??=q0(I()),j0=(q,x,Q)=>{let[P,...X]=[...Xq(),q];return y8(P,[...X,...x],Q)},B0=()=>_0?.videotoolbox?"h264_videotoolbox":"libx264",F1=()=>Math.round(performance.now()*1000),xq=new Set,C0=!1;function F0(q){if(xq.add(q),q.once("exit",()=>xq.delete(q)),C0)return;C0=!0,process.once("exit",()=>{for(let x of xq)try{x.kill("SIGKILL")}catch{}})}function K0(q){try{q.stdout?.destroy()}catch{}if(q.exitCode!==null||q.signalCode!==null)return;try{q.kill("SIGTERM")}catch{return}let x=setTimeout(()=>{if(q.exitCode===null&&q.signalCode===null)try{q.kill("SIGKILL")}catch{}},Z1);q.once("exit",()=>clearTimeout(x))}function K1(q,x,Q){return{args:["-f","x11grab","-draw_mouse","1","-framerate",String(q),"-video_size",`${x.width}x${x.height}`,"-i",Q],size:x}}function z1(q){return{args:["-f","avfoundation","-capture_cursor","1","-pixel_format","nv12","-framerate",String(q),"-i","Capture screen 0:none"],size:null}}function M1(q,x){return{args:["-f","gdigrab","-draw_mouse","1","-framerate",String(q),"-offset_x","0","-offset_y","0","-video_size",`${x.width}x${x.height}`,"-i","desktop"],size:x}}function Y1(q){return{args:["-probesize","32","-analyzeduration","0","-f","image2pipe","-c:v","mjpeg","-framerate",String(q),"-i","pipe:0"],size:null}}var z0=1700000;function M0(q){return Math.min(1,Math.round(Math.sqrt(z0/(q.width*q.height))*100)/100)}function w1(q,x,Q){let P=Qq(Q.axe,["stream-video","--udid",Q.udid,"--format","ffmpeg","--fps","30","--quality","85","--scale",String(Math.min(0.99,M0(Q.size)))],{stdio:["ignore","pipe","ignore"]}),X=Qq(q,x,{env:{},stdio:["pipe","pipe","ignore"]});P.stdout.pipe(X.stdin),X.stdin.on("error",()=>{});let b=()=>{if(P.exitCode===null&&P.signalCode===null)P.kill("SIGTERM")};return X.once("exit",b),X.once("error",b),P.once("exit",()=>{if(X.exitCode===null&&X.signalCode===null)X.kill("SIGTERM")}),P.once("error",()=>{if(X.exitCode===null&&X.signalCode===null)X.kill("SIGTERM")}),X}function R0(q){let x=Math.min(1,N0.width/q.width,N0.height/q.height);return{width:Math.round(q.width*x),height:Math.round(q.height*x)}}function Z8(q,x,Q,P="libx264"){let X=n[q],b=(U)=>Math.max(2,Math.floor(U/2)*2),J={width:b(Q.width*X.scale),height:b(Q.height*X.scale)},N=J.width!==x.size?.width||J.height!==x.size.height,T=Math.max(1,Math.round(X.kbps*2/X.fps)),L=["-g",String(X.fps*y1)],C=P==="h264_videotoolbox"?["-c:v","h264_videotoolbox","-realtime","1","-prio_speed","1","-allow_sw","1","-profile:v","main","-level","4.2","-bf","0","-pix_fmt","nv12",...L,"-b:v",`${X.kbps}k`,"-maxrate",`${X.kbps}k`,"-bufsize",`${T}k`,"-bsf:v","h264_metadata=aud=insert"]:["-c:v","libx264","-preset",X.x264Preset,"-tune","zerolatency","-profile:v","main","-level","4.2","-bf","0","-pix_fmt","yuv420p",...X.threads?["-threads",String(X.threads)]:[],"-x264-params","aud=1:repeat-headers=1",...L,"-crf",String(X.crf),"-maxrate",`${X.kbps}k`,"-bufsize",`${T}k`];return["-hide_banner","-loglevel","error","-nostdin","-fflags","nobuffer",...x.args,"-an",...N?["-vf",`scale=${J.width}:${J.height}:flags=fast_bilinear`]:[],...C,"-flush_packets","1","-f","h264","pipe:1"]}class Y0{buffer=new Uint8Array(0);scanned=0;key=!1;micros=0;push(q,x){if(this.buffer.byteLength===0)this.micros=x;let Q=new Uint8Array(this.buffer.byteLength+q.byteLength);Q.set(this.buffer),Q.set(q,this.buffer.byteLength),this.buffer=Q;let P=[],X=this.scanned;while(X+3<this.buffer.byteLength){if(this.buffer[X]!==0||this.buffer[X+1]!==0||this.buffer[X+2]!==1){X++;continue}let b=this.buffer[X+3]&31,J=X>0&&this.buffer[X-1]===0?X-1:X;if(b===9&&J>0)P.push({data:this.buffer.slice(0,J),key:this.key,micros:this.micros}),this.buffer=this.buffer.subarray(J),this.key=!1,this.micros=x,X-=J;if(b===5)this.key=!0;X+=3}return this.scanned=X,P}}function _1(q,x){let Q=L1({path:q}),P=Buffer.alloc(0),X="version",b=0,J=!1,N=[],T=0,L=!1,C=(W)=>{if(L)return;L=!0,Q.destroy(),x.end(W)},U=()=>C({reason:"display_protocol"}),y=(W)=>{if(L)return;if(!J){if(T+=W.byteLength,T>U0)C({reason:"input_backpressure"});else N.push(W);return}if(Q.write(W),Q.writableLength>U0)C({reason:"input_backpressure"})},R=(W)=>{P=P.subarray(W)},Y=()=>{switch(X){case"version":{if(P.byteLength<12)return!1;let W=/^RFB (\d{3})\.(\d{3})\n$/.exec(P.subarray(0,12).toString("latin1"));if(!W||Number(W[1])*1000+Number(W[2])<3007)return U(),!1;return R(12),Q.write(`RFB 003.007
247
+ `),X="security",!0}case"security":{if(P.byteLength<1)return!1;let W=P[0];if(W===0)return U(),!1;if(P.byteLength<1+W)return!1;if(!P.subarray(1,1+W).includes(1))return U(),!1;return R(1+W),Q.write(Buffer.from([1,1])),X="init",!0}case"init":{if(P.byteLength<24)return!1;let W=P.readUInt32BE(20);if(W>65536)return U(),!1;if(P.byteLength<24+W)return!1;let G={width:P.readUInt16BE(0),height:P.readUInt16BE(2)};if(R(24+W),G.width===0||G.height===0)return U(),!1;X="messages",J=!0;for(let V of N)Q.write(V);return N=[],T=0,x.ready(G),!L}case"skip":{let W=Math.min(b,P.byteLength);if(R(W),b-=W,b>0)return!1;return X="messages",!0}case"messages":{if(P.byteLength<1)return!1;switch(P[0]){case 1:{if(P.byteLength<6)return!1;let W=6+P.readUInt16BE(4)*6;if(P.byteLength<W)return!1;return R(W),!0}case 2:return R(1),!0;case 3:{if(P.byteLength<8)return!1;let W=P.readUInt32BE(4);if(W>_/2)return R(8),X="skip",b=W,!0;if(P.byteLength<8+W)return!1;let G=P.subarray(8,8+W).toString("latin1");return R(8+W),x.clipboard(G),!L}default:return U(),!1}}}},S=!1;return Q.once("connect",()=>{S=!0}),Q.on("data",(W)=>{if(L)return;P=P.byteLength?Buffer.concat([P,W]):W;while(!L&&Y());}),Q.once("error",()=>{if(!S)C({error:new K("display_unavailable","Reason could not reach this machine's desktop server.")})}),Q.once("close",()=>C({reason:"display_closed"})),{pointer(W,G,V){let F=Buffer.alloc(6);F.writeUInt8(5,0),F.writeUInt8(V&255,1),F.writeUInt16BE(W,2),F.writeUInt16BE(G,4),y(F)},key(W,G){let V=Buffer.alloc(8);V.writeUInt8(4,0),V.writeUInt8(W?1:0,1),V.writeUInt32BE(G>>>0,4),y(V)},clipboard(W){if(Array.from(W).some((F)=>F.codePointAt(0)>255)){C({reason:"clipboard_unicode_unsupported"});return}let G=Buffer.from(W,"latin1"),V=Buffer.alloc(8);V.writeUInt8(6,0),V.writeUInt32BE(G.byteLength,4),y(Buffer.concat([V,G]))},close(){L=!0,Q.destroy()}}}class Pq{run=null;viewers=new Set;get running(){return this.run!==null}start(q,x,Q,P){this.viewers.add(q),this.stop();let X;try{X=Q()}catch{this.fail();return}F0(X);let b={child:X,splitter:new Y0};this.run=b;for(let N of[...this.viewers])N.started(x);X.stdout?.on("data",(N)=>{if(this.run!==b)return;for(let T of b.splitter.push(N,P()))for(let L of[...this.viewers])L.unit(T)});let J=()=>{if(this.run!==b)return;this.run=null,this.fail()};X.once("exit",J),X.once("error",J)}leave(q){if(!this.viewers.delete(q))return;if(this.viewers.size===0)this.stop()}stop(){if(!this.run)return;K0(this.run.child),this.run=null}fail(){for(let q of[...this.viewers])q.failed()}}var D0=new WeakMap;function $1(q){let x=D0.get(q);if(!x)D0.set(q,x=new Pq);return x}function w0(q,x,Q={}){let P=Q.micros??F1,X=new y0,b=x.request.preset,J=null,N=null,T=null,L=!1,C=null,U=!1,y=!1,R=null,Y=0,S=0,W=!1,G=null,V=null,F=0,E=null,w=[],t=0,A=[],f=new Uint32Array(qq+1),p=0,F8=null,K8=0,e=0,z8=0,Lq=0,jq=0,J8=null,M8=0,l={frames:0,bytes:0,since:P()},r=[],q8=0,Y8,w8=!1,c0=P(),O={},m=()=>Math.round((P()-c0)/1000),Bq=Q.control??x0,_8=null,$8=null,H=(B)=>{let j=G8(B);return q.send(j),Lq+=j.byteLength,j.byteLength},W8=(B)=>{if(q.done)return;if(q.open)H({type:"error",code:B});q.end({reason:B})},N8=()=>Math.max(B1,n[b].kbps*1000/8*C1),U8=()=>P()/1000,l0=()=>{while(A.length>1&&A[0].atMs<U8()-D1)A.shift();return A[0]?.rttMs??null},Cq=(B)=>{let j=l0();if(j===null||w.length===0)return!1;let D=(j+R1)*B;return U8()-w[0].sentMs>D||t>D/1000*n[b].kbps*1000/8},r0=(B)=>{if(F===0)return;let j=Math.min(B,F-1);if(E!==null&&j<=E)return;E=j;let D=U8();while(w.length&&w[0].seq<=j){let z=w.shift();if(t-=z.bytes,z.seq!==j)continue;let M=Math.max(0,D-z.sentMs);while(A.length&&A.at(-1).rttMs>=M)A.pop();A.push({atMs:D,rttMs:M}),f[Math.min(qq,Math.round(M))]++,p++,F8=Math.min(F8??M,M)}},m0=()=>{let B=0;for(let j=0;j<=qq;j++)if(B+=f[j],B*2>=p)return j;return 0},d0=()=>q.bufferedAmount<=N8()/2&&!Cq(0.5),Rq=()=>{w8=!0,r=[],q8=0,C?.leave(O8),C=null},Dq=(B)=>{if(q.done)return;if(B.key)O.first_key_ms??=m();if(!L){if(!C||r.length===0&&!B.key)return;if(r.push(B),q8+=B.data.byteLength,q8>N8())Rq();return}if(W){e++;return}if(q.bufferedAmount>N8()||Cq(1)){W=!0,e++,G=setInterval(()=>{if(q.done||!d0())return;if(G)clearInterval(G);G=null,W=!1,H8()},Q.drainPollMs??25);return}if(!U){if(!B.key){e++;return}if(H({type:"hello",width:N.width,height:N.height,fps:n[b].fps,preset:b,codec:j1}),U=!0,O.first_frame_ms??=m(),!y&&J?.sound)H({type:"audioHello",...b8}),y=!0}let j=H({type:"frame",key:B.key,seq:F,captureMicros:B.micros,data:B.data});if(w.push({seq:F,sentMs:U8(),bytes:j}),t+=j,w.length>T1)t-=w.shift().bytes;F++,K8++,J8??=B.micros,M8=B.micros,l.frames++,l.bytes+=j},O8={started(B){b=B,U=!1,r=[],q8=0},unit:Dq,failed:()=>W8("encoder_failed")},E8=()=>{let B=(Q.ffmpeg??L0)();if(!J||!N){W8("encoder_failed");return}let[j,D]=[J,N],z="kind"in j&&j.kind==="simulator"?j.stream:null;if(!B&&!z){W8("encoder_failed");return}if(C??="kind"in j&&j.kind==="mac_screen"?$1(Q.spawn??j0):new Pq,O.encoder_ms===void 0)O.encoder_ms=m(),O.encoder_shared=C.running;C.start(O8,b,()=>{let M=n[b].fps;if(z)return z(M,n[b].kbps,z0);if("kind"in j&&j.kind==="simulator"){let g=Math.min(0.99,M0(j.size)),x8={width:j.size.width*g,height:j.size.height*g};return w1(B,Z8(b,Y1(Math.min(M,30)),x8,(Q.macEncoder??B0)()),j)}if("kind"in j&&j.kind==="windows_screen")return(Q.spawn??y8)(B,Z8(b,M1(M,D),R0(D)),{SystemRoot:process.env.SystemRoot??"C:\\Windows"});return"kind"in j?(Q.spawn??j0)(B,Z8(b,z1(M),R0(D),(Q.macEncoder??B0)()),{}):(Q.spawn??y8)(B,Z8(b,K1(M,D,j.display),D),{DISPLAY:j.display,XAUTHORITY:j.xauthority})},P)},L8=()=>{if(!R)return;K0(R.child),R=null},a0=()=>{let B=(Q.ffmpeg??L0)();if(R||q.done||!y||!J?.sound||!B)return;let j;try{j=(Q.spawn??y8)(B,b0(),{PULSE_SERVER:T8(J.sound)})}catch{return}F0(j);let D={child:j,reader:new e8};R=D,j.stdout?.on("data",(M)=>{if(R!==D||q.done)return;let g;try{g=D.reader.push(M)}catch{L8();return}let x8=P();for(let s0 of g){if(q.bufferedAmount>N8()){S++;continue}H({type:"audio",captureMicros:x8,data:s0}),Y++}});let z=()=>{if(R===D)L8()};j.once("exit",z),j.once("error",z)},H8=()=>{if(!C||q.done)return;z8++,E8()},Tq=()=>{if(q.done||!N)return;if(!L){if(C||w8)return;E8(),Y8=setTimeout(()=>{if(!L)Rq()},G1);return}if(clearTimeout(Y8),O.encoder_early===void 0){if(O.encoder_early=C!==null,w8)O.hold_lapsed=!0}if(!C)E8();let B=r;r=[],q8=0;for(let j of B)Dq(j);V??=setInterval(()=>{let j=P(),D=Math.max(0.001,(j-l.since)/1e6);H({type:"stats",stats:{fps:Math.round(l.frames/D*10)/10,kbps:Math.round(l.bytes*8/1000/D),dropped:e,restarts:z8,queued_bytes:q.bufferedAmount}}),l={frames:0,bytes:0,since:j}},A1)};x.desktop.then((B)=>{if(q.done)return;J=B;let j={ready(D){N=D,O.desktop_ms??=m(),Tq()},clipboard(D){if(q.open&&Buffer.byteLength(D)<=_)H({type:"serverClipboard",text:D})},end(D){if("reason"in D&&q.open)H({type:"error",code:D.reason});q.end(D)}};if("kind"in B&&B.kind==="simulator")T=B.input,j.ready(B.points);else if("kind"in B&&B.kind==="windows_screen")T=(Q.windowsInput??kq)(j);else if("kind"in B)T=(Q.macInput??((D)=>A0(D,Xq())))(j);else{let D=(Q.linuxClipboard??W0)(B,j),z=_1(B.rfbSocket,{...j,clipboard:(M)=>{if(!D)j.clipboard(M)}});T=D?{pointer:(M,g,x8)=>D.apply(()=>z.pointer(M,g,x8)),key:(M,g)=>D.apply(()=>z.key(M,g)),clipboard:(M)=>D.write(M),close(){D.close(),z.close()}}:z}Zq()},(B)=>q.end({error:B}));function Zq(){if($8||!x.viewerSameNetwork||!L||q.done||!J||!("kind"in J)||J.kind!=="mac_screen")return;$8=(Q.macWindows??G0)((B)=>{if(q.open)H({type:"windows",bounds:B})})}let yq={viewer:x.viewer??null,notify(B){if(q.open)H({type:"control",control:B})}},f8=(B)=>{if(!T)return;if(!J||!("kind"in J)||J.kind!=="simulator")Bq.claim(yq);B(T)};return{opened(){O.relay_ms??=m()},received(B){jq+=B.byteLength;let j;try{j=X.push(B)}catch{W8("viewer_protocol");return}for(let D of j){if(q.done)return;switch(D.type){case"ping":H({type:"pong",token:D.token});break;case"pointer":f8((z)=>z.pointer(D.x,D.y,D.buttons));break;case"key":f8((z)=>z.key(D.down,D.keysym));break;case"clientClipboard":f8((z)=>z.clipboard(D.text));break;case"config":if(D.preset!==b)b=D.preset,H8();break;case"keyframeRequest":if(U&&!W)H8();break;case"ack":r0(D.seq);break;case"audioEnable":if(D.on)a0();else L8();break;default:break}}if(!L&&!q.done){if(L=!0,O.viewer_ms=m(),x.viewer)_8=Bq.join(yq);Tq(),Zq()}},close(){if(_8?.(),_8=null,$8?.close(),G)clearInterval(G);if(V)clearInterval(V);clearTimeout(Y8),C?.leave(O8),L8(),T?.close()},summary:()=>({output_bytes:Lq,input_bytes:jq,video:{preset:b,frames:K8,dropped:e,restarts:z8,avg_fps:J8!==null&&M8>J8?Math.round((K8-1)/((M8-J8)/1e6)*10)/10:0,min_rtt_ms:Math.round(F8??0),p50_rtt_ms:p?m0():0,audio_packets:Y,audio_dropped:S,connect:O}})}}var T0=null,_0=null,O1=null,E1=null;function H1(){let q=I();return q?.features.display?q.ffmpeg:null}function $0(q){return T0??=new Promise((x)=>{N1(q,["-hide_banner","-encoders"],{env:{},timeout:5000,killSignal:"SIGKILL",maxBuffer:1048576,encoding:"utf8"},(Q,P)=>{let X=(b)=>!Q&&new RegExp(`^\\s*V\\S*\\s+${b}\\s`,"m").test(P);x(_0={x264:X("libx264"),videotoolbox:X("h264_videotoolbox")})})}),T0}var Z0=null;function FQ(){return Z0??=(async()=>{let q=[I()?.ffmpeg,"/opt/homebrew/bin/ffmpeg","/usr/local/bin/ffmpeg"].find((Q)=>Boolean(Q&&U1(Q)));if(!q)return null;let x=await $0(q);return x.videotoolbox||x.x264?q:null})(),Z0}function bq(q=process.platform,x={}){if(q!=="linux"&&q!=="darwin"&&q!=="win32")return Promise.resolve(!1);let Q=(x.ffmpeg??H1)();if(!Q)return Promise.resolve(!1);let P=(x.encoders??$0)(Q);if(q==="linux")return P.then((b)=>b.x264);if(q==="win32"){let b=x.windowsScreen?x.windowsScreen():E1??=fq();return Promise.all([P,b]).then(([J,N])=>J.x264&&(N?.session??0)>0)}let X=x.macScreen?x.macScreen():O1??=l8(Xq());return Promise.all([P,X]).then(([b,J])=>(b.x264||b.videotoolbox)&&J?.screen===!0&&J.accessibility)}var c1=43200000,A8=":99",l1=60000,V8=15000,Nq={width:1280,height:800},r1=/^[A-Za-z0-9._:-]{1,160}$/;function m1(q){return Boolean(q)&&typeof q==="object"&&!Array.isArray(q)}var d1=["video","viewer","viewer_same_network","viewer_network"];function a1(q,x=Date.now()){let Q=["relay_url","session_id","expires_at"];if(!m1(q)||Q.some((N)=>!(N in q))||Object.keys(q).some((N)=>!Q.includes(N)&&!d1.includes(N)))throw new K("invalid_display_request","Reason desktop request is malformed.");let P="video"in q?h0(q.video):void 0,X="viewer"in q?g0(q.viewer):null;if(P===null)throw new K("invalid_display_request","Reason desktop video request is invalid.");let b=null;try{b=typeof q.relay_url==="string"?new URL(q.relay_url):null}catch{}if(!b||b.protocol!=="wss:"&&b.protocol!=="ws:"||b.username||b.password)throw new K("invalid_display_request","Reason desktop relay URL is invalid.");if(typeof q.session_id!=="string"||!r1.test(q.session_id))throw new K("invalid_display_request","Reason desktop session identity is invalid.");let J=typeof q.expires_at==="string"?Date.parse(q.expires_at):Number.NaN;if(!Number.isFinite(J)||J<=x)throw new K("invalid_display_request","Reason desktop session has already expired.");return{relay_url:q.relay_url,session_id:q.session_id,expires_at:new Date(Math.min(J,x+c1)).toISOString(),...P?{video:P}:{},...X?{viewer:X}:{},...P&&q.viewer_same_network===!0?{viewer_same_network:!0}:{}}}function O0(q=process.platform){return(q==="linux"||q==="darwin"||q==="win32")&&I()?.features.display===!0}async function vQ(){if(process.platform==="win32")return O0()&&await bq();if(process.platform!=="darwin")return O0();return await bq()}function S8(q){I1(q,{recursive:!0,mode:448});let x=k1(q);if(!x.isDirectory()||x.isSymbolicLink()||process.getuid&&x.uid!==process.getuid())throw new K("display_unavailable","Reason desktop state directory is not private.");h1(q,448)}function s1(q,x){let Q=(X)=>{let b=Buffer.alloc(2);return b.writeUInt16BE(X.length),Buffer.concat([b,X])},P=Buffer.from([255,255]);return Buffer.concat([P,Q(Buffer.alloc(0)),Q(Buffer.from(q)),Q(Buffer.from("MIT-MAGIC-COOKIE-1")),Q(x)])}function o(q,x,Q=2000){return new Promise((P)=>{let X=u1(q),b="",J=(N)=>{X.destroy(),P(N)};X.setTimeout(Q,()=>J(!1)),X.once("error",()=>J(!1)),X.once("close",()=>J(!1)),X.once("connect",()=>{if(!x)J(!0)}),X.on("data",(N)=>{if(b+=N.toString("latin1"),b.length>=4)J(b.startsWith("RFB "))})})}async function v0(q,x){let Q=Date.now()+x;while(Date.now()<Q){if(await q())return!0;await new Promise((P)=>setTimeout(P,100))}return!1}function Uq(q,x,Q){return new Promise((P)=>{let X=I0(q,x,{detached:!0,stdio:"ignore",env:Q});X.once("error",()=>P(-1)),X.once("exit",(b)=>P(b)),X.unref(),setTimeout(()=>P(null),V8).unref()})}var Jq=null;function i1(q=i()){return Jq??=n1(q).finally(()=>{Jq=null}),Jq}async function n1(q){let x=I({home:q});if(!x?.xvfb||!x.x11vnc||!x.openbox)throw new K("display_unavailable","Run `reason desktop install` on this machine to enable its desktop.");H0({root:x.root,automation:x.automation,extensionDir:x.extensionDir});let Q=$(x.root,"display");S8(Q);let P=await t1(q,Q,x.x11vnc);if(P)return P;let X={display:A8,xauthority:$(Q,"Xauthority"),rfbSocket:$(Q,"rfb.sock")},b=$(Q,"pulse"),J=(async()=>{try{S8(b)}catch{return null}return await P0(b,x.pulseaudio)})(),N=$(Q,"home");S8(N);let T={HOME:N,PATH:"/usr/local/bin:/usr/bin:/bin",DISPLAY:X.display,XAUTHORITY:X.xauthority};if(x.pulseaudio)T.PULSE_SERVER=T8(t8(b));let L=async()=>({...X,sound:await J});if(await o({path:X.rfbSocket},!0))return await L();if(!p0(X.xauthority))Wq(X.xauthority,s1(A8.slice(1),g1(16)),{mode:384,flag:"wx"});let C=e1($(Q,"theme"),X.display),U={path:`/tmp/.X11-unix/X${A8.slice(1)}`};if(!await o(U,!1)){if(Uq(x.xvfb,[X.display,"-screen","0",`${Nq.width}x${Nq.height}x24`,"-nolisten","tcp","-auth",X.xauthority],T),!await v0(()=>o(U,!1),V8))throw new K("display_unavailable","Reason could not start the virtual display.");Uq(x.openbox,["--config-file",C.openboxConfig],T)}if(await q9(C,T),!await u0(x.x11vnc,X,Q,"x11vnc.log",T))throw new K("display_unavailable","Reason could not start the desktop server.");return await L()}async function u0(q,x,Q,P,X){if(await o({path:x.rfbSocket},!0))return!0;v1(x.rfbSocket,{force:!0});let b=await Uq(q,["-display",x.display,"-auth",x.xauthority,"-rfbport","0","-rfbportv6","-1","-unixsock",x.rfbSocket,"-nopw","-forever","-shared","-noxdamage","-sb","0","-rfbversion","3.7","-quiet","-bg","-o",$(Q,P)],X);if(b!==null&&b!==0)return!1;return await v0(()=>o({path:x.rfbSocket},!0),V8)}async function o1(){let q=["DISPLAY","XAUTHORITY","WAYLAND_DISPLAY","XDG_SESSION_TYPE"],x=(Q)=>Object.fromEntries(q.flatMap((P)=>Q[P]?[[P,Q[P]]]:[]));if(process.env.DISPLAY)return x(process.env);try{let Q=await new Promise((P,X)=>f1("systemctl",["--user","show-environment"],{encoding:"utf8",timeout:2000},(b,J)=>b?X(b):P(J)));return x(Object.fromEntries(Q.split(`
248
+ `).flatMap((P)=>{let X=P.indexOf("=");return X>0?[[P.slice(0,X),P.slice(X+1)]]:[]})))}catch{return{}}}var E0=new Set;async function t1(q,x,Q){let P=await o1(),X=/^:(\d+)(?:\.\d+)?$/.exec(P.DISPLAY??"")?.[1];if(!X||`:${X}`===A8||P.WAYLAND_DISPLAY||P.XDG_SESSION_TYPE==="wayland")return null;let b={display:`:${X}`,xauthority:P.XAUTHORITY??$(q,".Xauthority"),rfbSocket:$(x,`rfb-${X}.sock`)},J=`${b.display} ${b.xauthority}`;if(E0.has(J)||!await o({path:`/tmp/.X11-unix/X${X}`},!1))return null;let N={HOME:q,PATH:"/usr/local/bin:/usr/bin:/bin",DISPLAY:b.display,XAUTHORITY:b.xauthority};if(await u0(Q,b,x,`x11vnc-${X}.log`,N))return{...b,sound:null};return E0.add(J),process.stderr.write(`Reason worker: your screen ${b.display} could not be served; using the virtual desktop
249
+ `),null}function e1(q,x){let Q=`chromium --no-first-run --no-default-browser-check${process.geteuid?.()===0?" --no-sandbox":""} %U`,P=[["terminal","xterm"],["files","pcmanfm"]].filter(([,b])=>!p0(`/usr/bin/${b}`)).map(([b])=>b),X=Mq({root:q,display:x,screen:Nq,browserExec:Q,absent:P});for(let b of["","openbox","tint2","picom"])S8($(q,b));for(let[b,J]of Object.entries(X.files))Wq($(q,b),J,{mode:384});for(let[b,J]of Object.entries(zq))Wq($(q,`ara-${b}`),p1(J),{mode:384});return{root:q,openboxConfig:$(q,"openbox","rc.xml"),start:X.start}}async function q9(q,x){let Q=[`ROOT=${JSON.stringify(q.root)}`,...q.start,"openbox --reconfigure >/dev/null 2>&1 || true"].join(`
250
+ `);await new Promise((P)=>{let X=I0("/bin/sh",["-c",Q],{stdio:"ignore",env:{...x,PATH:"/usr/bin:/bin"}}),b=setTimeout(()=>{X.kill(),P()},V8);X.once("error",()=>{clearTimeout(b),P()}),X.once("exit",()=>{clearTimeout(b),P()})})}async function uQ(q,x={}){let Q=x.now??Date.now,P=a1(q.payload,Q());if(q.signal.throwIfAborted(),!P.video)throw new K("display_video_required","Reason desktops stream as video now; this request came without it.");let X=x.platform??process.platform;if(X!=="linux"&&X!=="darwin"&&X!=="win32")throw new K("display_video_unsupported","This machine does not serve desktop video.");let b=P.video,J=(x.video?.desktop??(X==="darwin"?async()=>S0:X==="win32"?async()=>V0:i1))();return await x9(q.signal,P,x,Q,(N)=>w0(N,{request:b,desktop:J,...P.viewer?{viewer:P.viewer}:{},viewerSameNetwork:P.viewer_same_network===!0},x.video),(N)=>G8({type:"error",code:N}))}function x9(q,x,Q,P,X,b){let J=P();return new Promise((N,T)=>{let L=null,C=!1,U=!1,y,R,Y,S=!1,W=null,G=(A)=>{if(U)return;if(W)A=W;U=!0,clearTimeout(y),clearTimeout(R),q.removeEventListener("abort",F),Y?.close();try{L?.close(1000,"display_session_over")}catch{}if("error"in A){T(A.error);return}N({reason:A.reason,...Y?.summary(),duration_ms:Math.max(0,P()-J)})},V=()=>G({error:new K("display_relay_unavailable","Reason could not reach the desktop relay.")}),F=()=>{let A=q.reason;G({error:A instanceof K?A:new K("cancelled","Reason closed the desktop session.")})},E=()=>{if(!W||!L)return;let A=W.error;try{L.send(b(A instanceof K?A.code:"display_unavailable"))}catch{}G(W)};if(Y=X({get done(){return U||W!==null},get open(){return C&&!U&&W===null},get bufferedAmount(){return L?.bufferedAmount??0},send(A){if(U||W||!C||!L)return;try{L.send(A)}catch{G({reason:"relay_closed"})}},end:(A)=>{if(U||W)return;if(!("error"in A)){G(A);return}if(W=A,S&&C)E()}}),U){Y.close();return}if(q.aborted){F();return}q.addEventListener("abort",F,{once:!0}),y=setTimeout(()=>G({reason:"session_expired"}),Math.max(1,Date.parse(x.expires_at)-P())),R=setTimeout(()=>G({reason:"viewer_absent"}),Q.viewerWaitMs??l1);try{L=(Q.connect??k0)(x.relay_url,(Q.loadProxy??f0)()?.url)}catch{V();return}L.binaryType="arraybuffer",L.onopen=()=>{if(U||!L)return;C=!0,Y?.opened()},L.onmessage=(A)=>{if(U)return;let f=A.data,p=f instanceof ArrayBuffer?new Uint8Array(f):ArrayBuffer.isView(f)?new Uint8Array(f.buffer,f.byteOffset,f.byteLength):null;if(!p||p.byteLength===0)return;if(clearTimeout(R),S=!0,W){E();return}Y?.received(p)},L.onclose=()=>{if(U)return;if(!C){V();return}G({reason:"relay_closed"})},L.onerror=()=>{if(U||C)return;V()}})}
251
+ export{g8 as Tf,D9 as Uf,y9 as Vf,d as Wf,T8 as Xf,FQ as Yf,bq as Zf,pq as _f,oq as $f,I as ag,t9 as bg,e9 as cg,qQ as dg,c1 as eg,A8 as fg,a1 as gg,O0 as hg,vQ as ig,S8 as jg,i1 as kg,uQ as lg};
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{kj as f}from"./vm-hands-entry-lite-9cgm6g8t.js";var j=["Click browser element","Double click browser element","Type text","Clear browser field","Press key","Scroll browser element into view","Drag on computer","Select browser option","Check browser control","Uncheck browser control","Hover browser element","Focus browser element","Open browser page","Reload browser page","Go back in browser","Go forward in browser","Take browser screenshot"],$A=32;function R(x){if(!Array.isArray(x)||x.length>32||!x.every((A)=>typeof A==="string"&&j.includes(A)))return;return x.slice()}var KA="__ARA_PI_TOOL_CONFINED_SCRIPT_5f0c9e2a__",QA=262144;function Y(x){if(!x||typeof x!=="object"||Array.isArray(x))return!1;let A=x,W=Object.keys(A);return W.length===2&&W.includes("template")&&W.includes("quoteDepth")&&typeof A.template==="string"&&A.template.length<=262144&&!A.template.includes("\x00")&&A.template.split("__ARA_PI_TOOL_CONFINED_SCRIPT_5f0c9e2a__").length===2&&(A.quoteDepth===1||A.quoteDepth===2||A.quoteDepth===3)}var I=2,b=33554432,K=200000,D=4000000,_=240000,YA=`
2
+ import{zj as f}from"./vm-hands-entry-lite-pk3q774c.js";var j=["Click browser element","Double click browser element","Type text","Clear browser field","Press key","Scroll browser element into view","Drag on computer","Select browser option","Check browser control","Uncheck browser control","Hover browser element","Focus browser element","Open browser page","Reload browser page","Go back in browser","Go forward in browser","Take browser screenshot"],$A=32;function R(x){if(!Array.isArray(x)||x.length>32||!x.every((A)=>typeof A==="string"&&j.includes(A)))return;return x.slice()}var KA="__ARA_PI_TOOL_CONFINED_SCRIPT_5f0c9e2a__",QA=262144;function Y(x){if(!x||typeof x!=="object"||Array.isArray(x))return!1;let A=x,W=Object.keys(A);return W.length===2&&W.includes("template")&&W.includes("quoteDepth")&&typeof A.template==="string"&&A.template.length<=262144&&!A.template.includes("\x00")&&A.template.split("__ARA_PI_TOOL_CONFINED_SCRIPT_5f0c9e2a__").length===2&&(A.quoteDepth===1||A.quoteDepth===2||A.quoteDepth===3)}var I=2,b=33554432,K=200000,D=4000000,_=240000,YA=`
3
3
  ...[executor output truncated]`,p=2000,k=1,i=16384,d=32768,y=128,LA=64,s=2097152,H=1,m=16384,c=32768,OA=8388608,n=1000,t=2500,r=2000,zA=t+r,o=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/,v=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,l={text_only:4430,invalid_json:4431,invalid_cancel_request:4432,invalid_sdk_response:4433,claim_required:4434,invalid_claim:4435,executor_mismatch:4436,stale_generation:4437,fence_conflict:4438,frame_too_large:4439,result_too_large:4440,progress_too_large:4441,terminal_cleanup_started:4442,job_journal_unavailable:4443},u=new Map(Object.entries(l).map(([x,A])=>[A,x]));function SA(x,A){return A||(u.get(x)??"")}var a=["cancelled","command_failed","duplicate_request_id","duplicate_result_evicted","invalid_repl_response","invalid_request","process_group_cleanup_unconfirmed","repl_failed","result_too_large","repl_response_too_large","repl_transport_failed","request_ledger_full","request_journal_unavailable","request_outcome_uncertain","maintenance_held","request_not_found","resume_digest_mismatch","spawn_failed","stale_generation","timeout"],e=new Set(a),w=16384,AA=200,xA=2000,WA=["maintenance_held","invalid_job_request","jobs_disabled","job_not_found","job_conflict","job_capacity","job_journal_unavailable","job_not_running","job_lease_expired","job_input_sequence","job_input_backpressure","stale_generation","pty_unsupported","job_mode_mismatch"];class G extends Error{code;constructor(x){super(x);this.name="HandsProtocolError",this.code=x}}function g(x){return new TextEncoder().encode(x).byteLength}function U(x){return typeof x==="object"&&x!==null&&!Array.isArray(x)}function B(x,A){let W=new Set(A);return Object.keys(x).every((N)=>W.has(N))}function M(x){return typeof x==="string"&&o.test(x)}function Z(x){return Number.isSafeInteger(x)&&Number(x)>=1}function J(x){return typeof x==="string"&&v.test(x)}function C(x){return typeof x==="string"&&x.startsWith("pty-")&&J(x.slice(4))}function z(x){return[x.cols,x.rows].every((A)=>Number.isSafeInteger(A)&&Number(A)>=1&&Number(A)<=n)}function E(x){if(typeof x!=="string"||x.length>Math.ceil(m/3)*4||x.length%4!==0||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(x))return-1;let A=x.endsWith("==")?2:x.endsWith("=")?1:0;if(A&&"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(x[x.length-A-1])&(A===2?15:3))return-1;let N=x.length/4*3-A;return N<=m?N:-1}function S(x){return typeof x==="string"&&/^[0-9a-f]{64}$/.test(x)}function $(x){if(g(x)>b)throw new G("frame_too_large");try{return JSON.parse(x)}catch{throw new G("invalid_json")}}function BA(x){let A=$(x);if(!U(A)||!B(A,["version","generation","id","tool","input","semanticDigest","lifecycleLeaseId","workspaceBefore"])||A.version!==I||!Z(A.generation)||!M(A.id)||!["bash","repl","resume","read","edit","write","pi_tool"].includes(String(A.tool))||!U(A.input)||A.lifecycleLeaseId!==void 0&&(A.tool!=="bash"||!J(A.lifecycleLeaseId))||A.workspaceBefore!==void 0&&(!(A.tool==="bash"||A.tool==="repl"||A.tool==="pi_tool"&&A.input.tool==="bash")||!U(A.workspaceBefore)||!B(A.workspaceBefore,["script"])||typeof A.workspaceBefore.script!=="string"||A.workspaceBefore.script.length>K))throw new G("invalid_request");let W=U(A.workspaceBefore)&&typeof A.workspaceBefore.script==="string"?{workspaceBefore:{script:A.workspaceBefore.script}}:{};if(A.tool==="bash"){if(!B(A.input,["script","retainBackground","machineSdk"])||typeof A.input.script!=="string"||A.input.script.length>K||A.input.retainBackground!==void 0&&A.input.retainBackground!==!0||A.input.machineSdk!==void 0&&A.input.machineSdk!==!0||A.semanticDigest!==void 0&&!S(A.semanticDigest))throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"bash",input:{script:A.input.script,...A.input.retainBackground===!0?{retainBackground:!0}:{},...A.input.machineSdk===!0?{machineSdk:!0}:{}},...A.semanticDigest===void 0?{}:{semanticDigest:A.semanticDigest},...A.lifecycleLeaseId===void 0?{}:{lifecycleLeaseId:A.lifecycleLeaseId},...W}}if(A.tool==="resume"){if(A.semanticDigest!==void 0||!B(A.input,["semanticDigest"])||!S(A.input.semanticDigest))throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"resume",input:{semanticDigest:A.input.semanticDigest}}}if(A.tool==="repl"){if(!B(A.input,["code"])||typeof A.input.code!=="string"||A.input.code.length>K||A.semanticDigest!==void 0)throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"repl",input:{code:A.input.code},...W}}if(A.tool==="pi_tool"){let N=A.semanticDigest===void 0?GA(A.input):null;if(!N)throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"pi_tool",input:N,...W}}if(A.tool==="read"){if(!B(A.input,["path","offset","limit"])||typeof A.input.path!=="string"||A.input.path.length<1||A.input.path.length>K||A.semanticDigest!==void 0||A.input.offset!==void 0&&(!Number.isSafeInteger(A.input.offset)||Number(A.input.offset)<1)||A.input.limit!==void 0&&(!Number.isSafeInteger(A.input.limit)||Number(A.input.limit)<1||Number(A.input.limit)>2000))throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"read",input:{path:A.input.path,...A.input.offset===void 0?{}:{offset:Number(A.input.offset)},...A.input.limit===void 0?{}:{limit:Number(A.input.limit)}}}}if(A.tool==="edit"){if(!B(A.input,["path","edits"])||typeof A.input.path!=="string"||A.input.path.length<1||!Array.isArray(A.input.edits)||A.input.edits.length<1||A.input.edits.length>128||A.semanticDigest!==void 0)throw new G("invalid_request");let N=A.input.path.length,X=[];for(let V of A.input.edits){if(!U(V)||!B(V,["oldText","newText"])||typeof V.oldText!=="string"||V.oldText.length<1||typeof V.newText!=="string")throw new G("invalid_request");if(N+=V.oldText.length+V.newText.length,N>D)throw new G("invalid_request");X.push({oldText:V.oldText,newText:V.newText})}return{version:I,generation:A.generation,id:A.id,tool:"edit",input:{path:A.input.path,edits:X}}}if(A.tool!=="write"||!B(A.input,["path","content"])||typeof A.input.path!=="string"||A.input.path.length<1||typeof A.input.content!=="string"||A.input.path.length+A.input.content.length>D||A.semanticDigest!==void 0)throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"write",input:{path:A.input.path,content:A.input.content}}}function L(x){return x===void 0||typeof x==="number"&&Number.isFinite(x)}function GA(x){let A=x.args;if(!B(x,["tool","args"])||!U(A))return null;if(x.tool==="bash")return B(A,["command","timeout"])&&typeof A.command==="string"&&A.command.length<=K&&L(A.timeout)?{tool:"bash",args:{command:A.command,...A.timeout===void 0?{}:{timeout:Number(A.timeout)}}}:null;if(typeof A.path!=="string"||A.path.length>K)return null;if(x.tool==="read")return B(A,["path","offset","limit"])&&L(A.offset)&&L(A.limit)?{tool:"read",args:{path:A.path,...A.offset===void 0?{}:{offset:Number(A.offset)},...A.limit===void 0?{}:{limit:Number(A.limit)}}}:null;if(x.tool==="write")return B(A,["path","content"])&&typeof A.content==="string"&&A.path.length+A.content.length<=D?{tool:"write",args:{path:A.path,content:A.content}}:null;if(x.tool!=="edit"||!B(A,["path","edits"])||!Array.isArray(A.edits))return null;let W=A.path.length,N=[];for(let X of A.edits){if(!U(X)||!B(X,["oldText","newText"])||typeof X.oldText!=="string"||typeof X.newText!=="string")return null;if(W+=X.oldText.length+X.newText.length,W>D)return null;N.push({oldText:X.oldText,newText:X.newText})}return{tool:"edit",args:{path:A.path,edits:N}}}function NA(x){if(!U(x))return null;if("thrown"in x)return B(x,["thrown"])&&typeof x.thrown==="string"?{thrown:x.thrown}:null;let A=x.structuredContent;if(!B(x,["content","details","structuredContent","isError"])||!Array.isArray(x.content)||x.isError!==void 0&&x.isError!==!0||A!==void 0&&(!U(A)||!B(A,["output","truncated","full_output_path","exit_code","wall_time_seconds"])||typeof A.output!=="string"||typeof A.truncated!=="boolean"||A.full_output_path!==void 0&&typeof A.full_output_path!=="string"||typeof A.exit_code!=="number"||typeof A.wall_time_seconds!=="number"))return null;let W=[];for(let N of x.content)if(U(N)&&N.type==="text"&&B(N,["type","text"])&&typeof N.text==="string")W.push({type:"text",text:N.text});else if(U(N)&&N.type==="image"&&B(N,["type","data","mimeType"])&&typeof N.data==="string"&&typeof N.mimeType==="string")W.push({type:"image",data:N.data,mimeType:N.mimeType});else return null;return{content:W,...x.details===void 0?{}:{details:x.details},...U(A)?{structuredContent:{output:String(A.output),truncated:A.truncated===!0,...typeof A.full_output_path==="string"?{full_output_path:A.full_output_path}:{},exit_code:Number(A.exit_code),wall_time_seconds:Number(A.wall_time_seconds)}}:{},...x.isError===!0?{isError:!0}:{}}}function UA(x){let A=$(x);if(!U(A)||!B(A,["version","generation","id","ok","exitCode","stdout","stderr","cwd","error","resumed","browserActions","automaticProgressImage","piToolOutcome","workerElapsedMs","environmentWaitMs","workspaceBefore"])||A.version!==I||!Z(A.generation)||!M(A.id)||typeof A.ok!=="boolean"||!Number.isSafeInteger(A.exitCode)||Number(A.exitCode)<0||Number(A.exitCode)>255||typeof A.stdout!=="string"||A.stdout.length>_||typeof A.stderr!=="string"||A.stderr.length>_||A.cwd!==void 0&&(typeof A.cwd!=="string"||A.cwd.length<1||A.cwd.length>4096||!A.cwd.startsWith("/")||A.cwd.includes("\x00"))||A.error!==void 0&&(typeof A.error!=="string"||A.error.length<1||A.error.length>p||!e.has(A.error))||A.browserActions!==void 0&&!R(A.browserActions)||A.automaticProgressImage!==void 0&&(A.automaticProgressImage!==!0||!A.ok)||A.resumed!==void 0&&A.resumed!==!0||A.workerElapsedMs!==void 0&&(!Number.isSafeInteger(A.workerElapsedMs)||Number(A.workerElapsedMs)<0)||A.environmentWaitMs!==void 0&&(!Number.isSafeInteger(A.environmentWaitMs)||Number(A.environmentWaitMs)<0)||A.workspaceBefore!==void 0&&!h(A.workspaceBefore)||A.ok&&(A.exitCode!==0||A.error!==void 0)||!A.ok&&A.exitCode===0)throw new G("invalid_result");let W=A.piToolOutcome===void 0?void 0:NA(A.piToolOutcome);if(W===null||W&&!A.ok)throw new G("invalid_result");return{version:I,generation:A.generation,id:A.id,ok:A.ok,exitCode:Number(A.exitCode),stdout:A.stdout,stderr:A.stderr,...typeof A.cwd==="string"?{cwd:A.cwd}:{},...A.browserActions!==void 0?{browserActions:R(A.browserActions)}:{},...typeof A.error==="string"?{error:A.error}:{},...A.automaticProgressImage===!0?{automaticProgressImage:!0}:{},...A.resumed===!0?{resumed:!0}:{},...W?{piToolOutcome:W}:{},...A.workerElapsedMs!==void 0?{workerElapsedMs:Number(A.workerElapsedMs)}:{},...A.environmentWaitMs!==void 0?{environmentWaitMs:Number(A.environmentWaitMs)}:{},...h(A.workspaceBefore)?{workspaceBefore:{exitCode:A.workspaceBefore.exitCode,stdout:A.workspaceBefore.stdout,stderr:A.workspaceBefore.stderr}}:{}}}function h(x){return U(x)&&B(x,["exitCode","stdout","stderr"])&&Number.isSafeInteger(x.exitCode)&&Number(x.exitCode)>=0&&Number(x.exitCode)<=255&&typeof x.stdout==="string"&&x.stdout.length<=w&&typeof x.stderr==="string"&&x.stderr.length<=w}function FA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","sequence","stdout","stderr"])||A.type!=="progress"||A.version!==I||!Z(A.generation)||!M(A.id)||!Number.isSafeInteger(A.sequence)||Number(A.sequence)<1||typeof A.stdout!=="string"||A.stdout.length>_||typeof A.stderr!=="string"||A.stderr.length>_)throw new G("invalid_progress");return{type:"progress",version:I,generation:Number(A.generation),id:A.id,sequence:Number(A.sequence),stdout:A.stdout,stderr:A.stderr}}function IA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","fenceId","executorLaunchId","requestCancelVersion","managedJobsVersion","browserRunEnvelopeVersion","terminalCleanupVersion","guestMemoryVersion","guestMemoryDiagnosticsVersion","piToolsVersion","piToolsConfinement","backgroundBashVersion","machineSdkVersion","executionTimingVersion","environmentWaitVersion","workspaceBeforeVersion"])||A.type!=="claim"||A.version!==I||!Z(A.generation)||!J(A.fenceId)||!J(A.executorLaunchId)||A.requestCancelVersion!==void 0&&A.requestCancelVersion!==1||A.managedJobsVersion!==void 0&&A.managedJobsVersion!==k||A.guestMemoryVersion!==void 0&&A.guestMemoryVersion!==1||A.guestMemoryDiagnosticsVersion!==void 0&&(A.guestMemoryDiagnosticsVersion!==1||A.guestMemoryVersion!==1)||A.terminalCleanupVersion!==void 0&&A.terminalCleanupVersion!==1||A.browserRunEnvelopeVersion!==void 0&&A.browserRunEnvelopeVersion!==1||A.piToolsVersion!==void 0&&A.piToolsVersion!==1||A.piToolsConfinement!==void 0&&(!Y(A.piToolsConfinement)||A.piToolsVersion!==1)||A.backgroundBashVersion!==void 0&&A.backgroundBashVersion!==1||A.machineSdkVersion!==void 0&&A.machineSdkVersion!==1||A.executionTimingVersion!==void 0&&A.executionTimingVersion!==1||A.environmentWaitVersion!==void 0&&(A.environmentWaitVersion!==1||A.executionTimingVersion!==1)||A.workspaceBeforeVersion!==void 0&&A.workspaceBeforeVersion!==1)throw new G("invalid_claim");return{type:"claim",version:I,generation:A.generation,fenceId:A.fenceId,executorLaunchId:A.executorLaunchId,...A.requestCancelVersion===1?{requestCancelVersion:1}:{},...A.managedJobsVersion===1?{managedJobsVersion:1}:{},...A.guestMemoryVersion===1?{guestMemoryVersion:1}:{},...A.guestMemoryDiagnosticsVersion===1?{guestMemoryDiagnosticsVersion:1}:{},...A.terminalCleanupVersion===1?{terminalCleanupVersion:1}:{},...A.browserRunEnvelopeVersion===1?{browserRunEnvelopeVersion:1}:{},...A.piToolsVersion===1?{piToolsVersion:1}:{},...Y(A.piToolsConfinement)?{piToolsConfinement:{template:A.piToolsConfinement.template,quoteDepth:A.piToolsConfinement.quoteDepth}}:{},...A.backgroundBashVersion===1?{backgroundBashVersion:1}:{},...A.machineSdkVersion===1?{machineSdkVersion:1}:{},...A.executionTimingVersion===1?{executionTimingVersion:1}:{},...A.environmentWaitVersion===1?{environmentWaitVersion:1}:{},...A.workspaceBeforeVersion===1?{workspaceBeforeVersion:1}:{}}}function XA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","fenceId","executorLaunchId","workerVersion","workerArtifactSha256","requestCancelVersion","managedJobsVersion","lifecycleVersion","browserRunEnvelopeVersion","terminalCleanupVersion","guestMemoryVersion","guestMemoryDiagnosticsVersion","piToolsVersion","piToolsConfinementVersion","backgroundBashVersion","machineSdkVersion","executionTimingVersion","environmentWaitVersion","workspaceBeforeVersion"])||A.lifecycleVersion!==void 0&&A.lifecycleVersion!==1||A.workspaceBeforeVersion!==void 0&&A.workspaceBeforeVersion!==1||A.piToolsVersion!==void 0&&A.piToolsVersion!==1||A.piToolsConfinementVersion!==void 0&&(A.piToolsConfinementVersion!==1||A.piToolsVersion!==1)||A.backgroundBashVersion!==void 0&&A.backgroundBashVersion!==1||A.machineSdkVersion!==void 0&&A.machineSdkVersion!==1||A.executionTimingVersion!==void 0&&A.executionTimingVersion!==1||A.environmentWaitVersion!==void 0&&(A.environmentWaitVersion!==1||A.executionTimingVersion!==1)||A.guestMemoryVersion!==void 0&&A.guestMemoryVersion!==1||A.guestMemoryDiagnosticsVersion!==void 0&&(A.guestMemoryDiagnosticsVersion!==1||A.guestMemoryVersion!==1)||A.terminalCleanupVersion!==void 0&&A.terminalCleanupVersion!==1||A.browserRunEnvelopeVersion!==void 0&&A.browserRunEnvelopeVersion!==1||A.type!=="claim_ack"||A.version!==I||!Z(A.generation)||!J(A.fenceId)||!J(A.executorLaunchId)||!Number.isSafeInteger(A.workerVersion)||Number(A.workerVersion)<1||!S(A.workerArtifactSha256)||A.requestCancelVersion!==void 0&&A.requestCancelVersion!==1||A.managedJobsVersion!==void 0&&A.managedJobsVersion!==k)throw new G("invalid_claim_ack");return{type:"claim_ack",...A.guestMemoryVersion===1?{guestMemoryVersion:1}:{},...A.guestMemoryDiagnosticsVersion===1?{guestMemoryDiagnosticsVersion:1}:{},...A.terminalCleanupVersion===1?{terminalCleanupVersion:1}:{},...A.browserRunEnvelopeVersion===1?{browserRunEnvelopeVersion:1}:{},...A.lifecycleVersion===1?{lifecycleVersion:1}:{},...A.piToolsVersion===1?{piToolsVersion:1}:{},...A.piToolsConfinementVersion===1?{piToolsConfinementVersion:1}:{},...A.backgroundBashVersion===1?{backgroundBashVersion:1}:{},...A.machineSdkVersion===1?{machineSdkVersion:1}:{},...A.executionTimingVersion===1?{executionTimingVersion:1}:{},...A.environmentWaitVersion===1?{environmentWaitVersion:1}:{},...A.workspaceBeforeVersion===1?{workspaceBeforeVersion:1}:{},version:I,generation:A.generation,fenceId:A.fenceId,executorLaunchId:A.executorLaunchId,workerVersion:Number(A.workerVersion),workerArtifactSha256:A.workerArtifactSha256,...A.requestCancelVersion===1?{requestCancelVersion:1}:{},...A.managedJobsVersion===1?{managedJobsVersion:1}:{}}}function TA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","jobId","action","input"])||A.type!=="job"||A.version!==I||!Z(A.generation)||!M(A.id)||!M(A.jobId)||!U(A.input))throw new G("invalid_job_request");let W=A.input,N=Number.isSafeInteger(W.leaseExpiresAtMs)&&Number(W.leaseExpiresAtMs)>0,X=Number.isSafeInteger(W.sequence)&&Number(W.sequence)>=1;if(!(A.action==="start"?W.mode==="pty"?B(W,["mode","cols","rows","leaseExpiresAtMs"])&&C(A.jobId)&&z(W)&&N:B(W,["script","leaseExpiresAtMs"])&&typeof W.script==="string"&&W.script.length<=K&&N:A.action==="inspect"?B(W,["after"])&&Number.isSafeInteger(W.after)&&Number(W.after)>=0:A.action==="input"?"dataBase64"in W?B(W,["sequence","dataBase64"])&&C(A.jobId)&&X&&E(W.dataBase64)>0:B(W,["sequence","data","eof"])&&X&&typeof W.data==="string"&&W.data.length<=i&&typeof W.eof==="boolean":A.action==="resize"?B(W,["sequence","cols","rows"])&&C(A.jobId)&&X&&z(W):A.action==="renew"?B(W,["leaseExpiresAtMs"])&&N:A.action==="cancel"&&B(W,[])))throw new G("invalid_job_request");return A}function MA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","ok","job","error"])||A.type!=="job_result"||A.version!==I||!Z(A.generation)||!M(A.id))throw new G("invalid_job_result");if(A.ok===!1&&A.job===void 0&&typeof A.error==="string"&&WA.some((F)=>F===A.error))return A;let W=A.job;if(A.ok!==!0||A.error!==void 0||!U(W)||!B(W,["jobId","state","startedAtMs","finishedAtMs","leaseExpiresAtMs","exitCode","inputSequence","output","firstCursor","nextCursor","truncated","process","environmentRevision","environmentSnapshotId","pty"])||!M(W.jobId)||!["starting","running","exited","cancelled","expired","uncertain"].includes(String(W.state))||!Number.isSafeInteger(W.startedAtMs)||Number(W.startedAtMs)<1||!Number.isSafeInteger(W.leaseExpiresAtMs)||Number(W.leaseExpiresAtMs)<1||W.finishedAtMs!==null&&(!Number.isSafeInteger(W.finishedAtMs)||Number(W.finishedAtMs)<Number(W.startedAtMs))||W.exitCode!==null&&(!Number.isSafeInteger(W.exitCode)||Number(W.exitCode)<0||Number(W.exitCode)>255)||!Number.isSafeInteger(W.inputSequence)||Number(W.inputSequence)<0||!Number.isSafeInteger(W.firstCursor)||Number(W.firstCursor)<1||!Number.isSafeInteger(W.nextCursor)||Number(W.nextCursor)<Number(W.firstCursor)-1||typeof W.truncated!=="boolean"||!Array.isArray(W.output)||W.output.length>y)throw new G("invalid_job_result");if(W.environmentRevision===void 0!==(W.environmentSnapshotId===void 0)||W.environmentRevision!==void 0&&(!Number.isSafeInteger(W.environmentRevision)||Number(W.environmentRevision)<1||!J(W.environmentSnapshotId)))throw new G("invalid_job_result");let N=Number(W.firstCursor)-1,X=0;for(let F of W.output){if(!U(F)||!B(F,["cursor","stream","text"])||!Number.isSafeInteger(F.cursor)||Number(F.cursor)<=N||Number(F.cursor)>Number(W.nextCursor)||!["stdout","stderr"].includes(String(F.stream))||typeof F.text!=="string")throw new G("invalid_job_result");X+=F.text.length,N=Number(F.cursor)}if(X>d)throw new G("invalid_job_result");let V=W.state==="starting"||W.state==="running";if(V&&(W.finishedAtMs!==null||W.exitCode!==null)||!V&&W.finishedAtMs===null||W.state==="uncertain"&&W.exitCode!==null||W.state==="exited"&&W.exitCode===null||W.state==="cancelled"&&W.exitCode!==130||W.state==="expired"&&W.exitCode!==124)throw new G("invalid_job_result");if(W.process!==void 0){let F=W.process;if(!U(F)||!B(F,["pid","processGroupId","executorLaunchId"])||!Number.isSafeInteger(F.pid)||Number(F.pid)<1||F.processGroupId!==F.pid||!J(F.executorLaunchId)||!["starting","running"].includes(String(W.state)))throw new G("invalid_job_result")}if(W.pty!==void 0){let F=W.pty;if(!U(F)||!B(F,["version","cols","rows","output","cleanup"])||F.version!==H||!C(W.jobId)||!z(F)||W.output.length!==0||!Array.isArray(F.output)||F.output.length>y||(V?F.cleanup!=="pending":W.state==="uncertain"?F.cleanup!=="unconfirmed":F.cleanup!=="confirmed")||W.state==="running"&&(W.process===void 0||W.environmentRevision===void 0))throw new G("invalid_job_result");let T=Number(W.firstCursor)-1,P=0;for(let Q of F.output){if(!U(Q)||!B(Q,["cursor","dataBase64"])||!Number.isSafeInteger(Q.cursor)||Number(Q.cursor)<=T||Number(Q.cursor)>Number(W.nextCursor))throw new G("invalid_job_result");let q=E(Q.dataBase64);if(q<=0||(P+=q)>c)throw new G("invalid_job_result");T=Number(Q.cursor)}}return A}function qA(x){if(g(x)>s)throw new G("frame_too_large");let A=$(x);if(!U(A)||!B(A,["version","sessionId","operationId","runId","deviceId","rootId","workspace","binding","targetRevision","rootGrantRevision","generation","fenceId","executorLaunchId","job"])||A.version!==H||![A.sessionId,A.operationId,A.runId].every(M)||![A.deviceId,A.rootId,A.fenceId,A.executorLaunchId].every(J)||!Z(A.generation)||!Number.isSafeInteger(A.rootGrantRevision)||Number(A.rootGrantRevision)<1||!["workspace_source","mcp_control"].includes(String(A.binding))||!Number.isSafeInteger(A.targetRevision)||Number(A.targetRevision)<0||A.binding==="workspace_source"&&A.targetRevision!==0||!U(A.workspace))throw new G("invalid_pty_receipt");if(!f(A.workspace))throw new G("invalid_pty_receipt");let W=MA(JSON.stringify({type:"job_result",version:I,generation:A.generation,id:A.operationId,ok:!0,job:A.job}));if(!W.ok||!W.job.pty||W.job.pty.output.length!==0||W.job.process&&W.job.process.executorLaunchId!==A.executorLaunchId)throw new G("invalid_pty_receipt");return A}function yA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","targetId"])||A.type!=="cancel_request"||A.version!==I||!Z(A.generation)||!M(A.id)||!M(A.targetId))throw new G("invalid_cancel_request");return A}function mA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","targetId","status"])||A.type!=="cancel_ack"||A.version!==I||!Z(A.generation)||!M(A.id)||!M(A.targetId)||!["cancelled","settled","not_found","unsupported","unconfirmed"].includes(String(A.status)))throw new G("invalid_cancel_ack");return A}function wA(x){let A=JSON.stringify(x);return BA(A),A}function hA(x){let A=JSON.stringify(x);return UA(A),A}function fA(x){let A=JSON.stringify(x);return FA(A),A}function kA(x){let A=JSON.stringify(x);return IA(A),A}function HA(x){let A=JSON.stringify(x);return XA(A),A}function O(x){return typeof x==="string"&&x.length>=1&&x.length<=AA&&!x.includes("\x00")}function VA(x){let A=["type","version","generation","id","jobRequestId","verb"];if(x.verb==="help")return B(x,A)?{verb:"help"}:null;if(x.verb==="describe"||x.verb==="namespace")return B(x,[...A,"name"])&&O(x.name)?{verb:x.verb,name:x.name}:null;if(x.verb==="search"){let W=x.args;if(!B(x,[...A,"query","args"])||typeof x.query!=="string"||x.query.trim().length<1||x.query.length>xA)return null;if(W===void 0)return{verb:"search",query:x.query};if(!U(W)||!B(W,["namespace","limit"])||W.namespace!==void 0&&!O(W.namespace)||W.limit!==void 0&&(!Number.isSafeInteger(W.limit)||Number(W.limit)<1||Number(W.limit)>50))return null;return{verb:"search",query:x.query,args:{...typeof W.namespace==="string"?{namespace:W.namespace}:{},...W.limit===void 0?{}:{limit:Number(W.limit)}}}}if(x.verb!=="call"||!B(x,[...A,"name","args"])||!O(x.name)||!U(x.args)||JSON.stringify(x.args).length>K)return null;return{verb:"call",name:x.name,args:x.args}}function gA(x){let A=$(x);if(!U(A)||A.type!=="sdk_request"||A.version!==I||!Z(A.generation)||!M(A.id)||!M(A.jobRequestId))throw new G("invalid_sdk_request");let W=VA(A);if(!W)throw new G("invalid_sdk_request");return{type:"sdk_request",version:I,generation:Number(A.generation),id:A.id,jobRequestId:A.jobRequestId,...W}}function ZA(x){let A=$(x);if(!U(A)||A.type!=="sdk_response"||A.version!==I||!Z(A.generation)||!M(A.id))throw new G("invalid_sdk_response");let W={type:"sdk_response",version:I,generation:Number(A.generation),id:A.id},N=["type","version","generation","id","ok"];if(A.ok===!0&&B(A,[...N,"result"])&&typeof A.result==="string"&&A.result.length<=_)return{...W,ok:!0,result:A.result};if(A.ok===!1&&B(A,[...N,"error"])&&typeof A.error==="string"&&A.error.length>=1&&A.error.length<=_)return{...W,ok:!1,error:A.error};throw new G("invalid_sdk_response")}function EA(x){let A=JSON.stringify(x);return ZA(A),A}
4
- export{$A as Fg,KA as Gg,QA as Hg,I as Ig,b as Jg,K as Kg,D as Lg,_ as Mg,YA as Ng,p as Og,k as Pg,i as Qg,d as Rg,y as Sg,LA as Tg,s as Ug,H as Vg,m as Wg,c as Xg,OA as Yg,n as Zg,t as _g,r as $g,zA as ah,l as bh,SA as ch,a as dh,w as eh,AA as fh,xA as gh,WA as hh,G as ih,M as jh,Z as kh,J as lh,C as mh,S as nh,BA as oh,UA as ph,FA as qh,IA as rh,XA as sh,TA as th,MA as uh,qA as vh,yA as wh,mA as xh,wA as yh,hA as zh,fA as Ah,kA as Bh,HA as Ch,gA as Dh,ZA as Eh,EA as Fh};
4
+ export{$A as Ug,KA as Vg,QA as Wg,I as Xg,b as Yg,K as Zg,D as _g,_ as $g,YA as ah,p as bh,k as ch,i as dh,d as eh,y as fh,LA as gh,s as hh,H as ih,m as jh,c as kh,OA as lh,n as mh,t as nh,r as oh,zA as ph,l as qh,SA as rh,a as sh,w as th,AA as uh,xA as vh,WA as wh,G as xh,M as yh,Z as zh,J as Ah,C as Bh,S as Ch,BA as Dh,UA as Eh,FA as Fh,IA as Gh,XA as Hh,TA as Ih,MA as Jh,qA as Kh,yA as Lh,mA as Mh,wA as Nh,hA as Oh,fA as Ph,kA as Qh,HA as Rh,gA as Sh,ZA as Th,EA as Uh};
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ import{Mg as d}from"./vm-hands-entry-lite-xrthfx3q.js";import{Tg as P}from"./vm-hands-entry-lite-2e18tm6w.js";import{$g as i}from"./vm-hands-entry-lite-ammr3xbc.js";import{mj as s}from"./vm-hands-entry-lite-fyvgav60.js";import{zj as c}from"./vm-hands-entry-lite-pk3q774c.js";import{Ek as V}from"./vm-hands-entry-lite-51hmj6am.js";import{existsSync as A,realpathSync as p,statSync as t}from"fs";import{platform as f}from"os";import{isAbsolute as l,sep as e}from"path";import{existsSync as o}from"fs";import{createRequire as n}from"module";var E=Function("return ("+P+")")()(()=>n(import.meta.url)("bun:ffi"),o);function h(){return process.platform==="win32"&&typeof globalThis.Bun<"u"&&E.available()}function m(z=process.env){return E.defaultShell(z)}function w(z){return E.shellArgs(z)}function k(z){let H=E.spawn({...z,env:z.environment});return H.exited.then(()=>H.close()),{write:(Q)=>H.write(Q),resize:(Q,J)=>H.resize(Q,J),kill:()=>H.close(),exited:H.exited}}var zz=43200000,v=i,Hz=4,Jz=/^[A-Za-z0-9._:-]{1,160}$/,Qz=1000;function r(z){return Boolean(z)&&typeof z==="object"&&!Array.isArray(z)}function g(z,H){if(typeof z!=="number"||!Number.isFinite(z)||z<=0)return H;return Math.min(Qz,Math.max(1,Math.floor(z)))}function Vz(z,H=Date.now()){let Q=["relay_url","session_id","expires_at"],J=new Set([...Q,"cols","rows","cwd","workspace"]);if(!r(z)||Q.some((C)=>!(C in z))||Object.keys(z).some((C)=>!J.has(C)))throw new V("invalid_pty_request","Reason terminal request is malformed.");let{relay_url:N,session_id:Y,expires_at:R}=z;if(typeof N!=="string")throw new V("invalid_pty_request","Reason terminal relay URL is missing.");let K;try{K=new URL(N)}catch{throw new V("invalid_pty_request","Reason terminal relay URL is invalid.")}if(K.protocol!=="wss:"&&K.protocol!=="ws:"||K.username||K.password)throw new V("invalid_pty_request","Reason terminal relay URL is invalid.");if(typeof Y!=="string"||!Jz.test(Y))throw new V("invalid_pty_request","Reason terminal session identity is invalid.");let D=typeof R==="string"?Date.parse(R):Number.NaN;if(!Number.isFinite(D)||D<=H)throw new V("invalid_pty_request","Reason terminal session has already expired.");if(z.cwd!==void 0&&typeof z.cwd!=="string")throw new V("invalid_pty_request","Reason terminal working directory is invalid.");let j=z.workspace===void 0?void 0:c(z.workspace);if(j===null||j&&z.cwd!==void 0)throw new V("invalid_pty_request","Reason terminal workspace is invalid.");return{relay_url:N,session_id:Y,expires_at:new Date(Math.min(D,H+zz)).toISOString(),cols:g(z.cols,80),rows:g(z.rows,24),...z.cwd===void 0?{}:{cwd:z.cwd},...j?{workspace:j}:{}}}function Zz(z,H){if(f()==="win32")[z,H]=[z.toLowerCase(),H.toLowerCase()];return H===z||H.startsWith(z+e)}function y(z,H){if(H===void 0)return z;if(!l(H))throw new V("pty_cwd_invalid","Reason terminal working directory must be absolute.");let Q;try{Q=p(H)}catch{throw new V("pty_cwd_invalid","Reason terminal working directory does not exist.")}if(!Zz(z,Q))throw new V("pty_cwd_outside_root","Reason terminal working directory escapes the granted root.");if(!t(Q).isDirectory())throw new V("pty_cwd_invalid","Reason terminal working directory is not a directory.");return Q}function $z(z=process.env){if(f()==="win32")return m(z);let H=z.SHELL;if(H&&l(H)&&A(H))return H;for(let Q of f()==="darwin"?["/bin/zsh","/bin/bash","/bin/sh"]:["/bin/bash","/bin/sh"])if(A(Q))return Q;return"/bin/sh"}function jz(){let z=globalThis.Bun;if(!z)throw new V("pty_unavailable","Reason terminals require the Bun runtime.");return z.spawn}function Bz(){if(f()==="win32")return h();return typeof globalThis.Bun<"u"}var Gz=(z)=>{if(f()==="win32")try{return k({...z,file:z.shell,args:w(z.shell),environment:{...z.environment,TERM:"xterm-256color"}})}catch{throw new V("pty_unavailable","Reason could not allocate a pseudo-terminal.")}let H=jz()({cmd:[z.shell,"-i","-l"],cwd:z.cwd,env:{...z.environment,TERM:"xterm-256color"},terminal:{cols:z.cols,rows:z.rows,data:(J,N)=>{z.onData(N)}}}),Q=H.terminal;if(!Q){try{H.kill()}catch{}throw new V("pty_unavailable","Reason could not allocate a pseudo-terminal.")}return{write:(J)=>Q.write(J),resize:(J,N)=>Q.resize(J,N),kill:()=>{try{H.kill()}catch{}},exited:H.exited.then((J)=>typeof J==="number"?J:null,()=>null)}},Nz=(z,H)=>{return H===void 0?new WebSocket(z):new WebSocket(z,{proxy:H})},M=new Set;function Wz(z){if(M.size>=Hz||M.has(z))return null;M.add(z);let H=!1;return()=>{if(H)return;H=!0,M.delete(z)}}async function Iz(z,H={}){let Q=H.now??Date.now,J=Vz(z.payload,Q()),N=Wz(z.operationId);if(!N)throw new V("pty_slot_busy","This Reason Device already runs the maximum number of terminals.");let Y=Q(),R,K,D;try{let j=J.workspace?s(z.root,J.workspace):void 0;R=j?y(A(j.boundary)?p(j.boundary):j.boundary,j.path):y(z.root,J.cwd),K=H.environment??process.env,D=H.shellPath??$z(K)}catch(j){throw N(),j}return await new Promise((j,C)=>{let F=null,$=null,B=!1,I=!1,X=!1,U=null,_=0,x=0,O=[],S=0,T=null,G=(Z)=>{if(X)return;if(X=!0,T)clearTimeout(T);z.signal.removeEventListener("abort",b);try{F?.kill()}catch{}try{$?.close(1000,"pty_session_over")}catch{}if(N(),Z.kind==="rejected"){C(Z.error);return}let W={reason:Z.reason,exit_code:U,output_bytes:_,input_bytes:x,duration_ms:Math.max(0,Q()-Y)};z.emitEvent("pty.stopped",{...W}).catch(()=>{return}),j({...W})},b=()=>{let Z=z.signal.reason;G({kind:"rejected",error:Z instanceof V?Z:new V("cancelled","Reason closed the terminal session.")})};if(z.signal.aborted){b();return}z.signal.addEventListener("abort",b,{once:!0}),T=setTimeout(()=>G({kind:"resolved",reason:"session_expired"}),Math.max(1,Date.parse(J.expires_at)-Q()));let u=(Z)=>{if(_+=Z.byteLength,!B||!$){if(O.push(Z),S+=Z.byteLength,S>v)G({kind:"resolved",reason:"output_backpressure"});return}try{$.send(Z)}catch{G({kind:"resolved",reason:"relay_closed"});return}if($.bufferedAmount>v)G({kind:"resolved",reason:"output_backpressure"})};try{F=(H.spawnPty??Gz)({shell:D,args:["-i","-l"],cwd:R,cols:J.cols,rows:J.rows,environment:K,onData:(Z)=>{if(!X)u(Z)}})}catch(Z){G({kind:"rejected",error:Z instanceof V?Z:new V("pty_spawn_failed","Reason could not start the terminal shell.")});return}F.exited.then((Z)=>{if(X)return;if(U=Z,B&&$)try{$.send(JSON.stringify({t:"exit",code:Z}))}catch{}G({kind:"resolved",reason:"shell_exited"})});let a=(H.loadProxy??d)()?.url;try{$=(H.connect??Nz)(J.relay_url,a)}catch{G({kind:"rejected",error:new V("pty_relay_unavailable","Reason could not reach the terminal relay.")});return}$.binaryType="arraybuffer",$.onopen=()=>{if(X||!$)return;B=!0;try{$.send(JSON.stringify({t:"open",cols:J.cols,rows:J.rows}));for(let Z of O.splice(0))$.send(Z);S=0}catch{G({kind:"resolved",reason:"relay_closed"});return}I=!0,z.emitEvent("pty.ready",{session_id:J.session_id,cols:J.cols,rows:J.rows}).catch(()=>{return})},$.onmessage=(Z)=>{if(X||!F)return;let W=Z.data;if(typeof W==="string"){let L;try{L=JSON.parse(W)}catch{return}if(!r(L))return;if(L.t==="resize"){try{F.resize(g(L.cols,J.cols),g(L.rows,J.rows))}catch{}return}if(L.t==="close")G({kind:"resolved",reason:"client_closed"});return}let q=W instanceof ArrayBuffer?new Uint8Array(W):ArrayBuffer.isView(W)?new Uint8Array(W.buffer,W.byteOffset,W.byteLength):null;if(!q||q.byteLength===0)return;x+=q.byteLength;try{F.write(q)}catch{}},$.onclose=()=>{if(X)return;if(!I){G({kind:"rejected",error:new V("pty_relay_unavailable","Reason could not reach the terminal relay.")});return}G({kind:"resolved",reason:"relay_closed"})},$.onerror=()=>{if(X||I)return;G({kind:"rejected",error:new V("pty_relay_unavailable","Reason could not reach the terminal relay.")})}})}
3
+ export{h as mg,zz as ng,v as og,Hz as pg,Vz as qg,y as rg,$z as sg,Bz as tg,Gz as ug,Nz as vg,Iz as wg};