@reason-machines/cli-linux-x64 0.2.527 → 0.2.529

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 (86) hide show
  1. package/bin/reason +1 -1
  2. package/bin/vm-hands/api-5ewaw0vr.js +2 -0
  3. package/bin/vm-hands/api-credentials-cdz9mw03.js +2 -0
  4. package/bin/vm-hands/connect-cli-ekfj4bg7.js +2 -0
  5. package/bin/vm-hands/credentials-ts56n6gk.js +2 -0
  6. package/bin/vm-hands/{custom-endpoint-device-6d759gkr.js → custom-endpoint-device-7tgcmhbz.js} +1 -1
  7. package/bin/vm-hands/desktop-account-jdqya1ff.js +2 -0
  8. package/bin/vm-hands/{hands-worker-source-hytk3v4n.js → hands-worker-source-hkjndq4w.js} +1 -1
  9. package/bin/vm-hands/{install-receipt-g15a9v84.js → install-receipt-8tpfepde.js} +1 -1
  10. package/bin/vm-hands/local-automation-zzbppk8c.js +2 -0
  11. package/bin/vm-hands/local-capabilities-mzt7ndkf.js +2 -0
  12. package/bin/vm-hands/{local-desktop-users-wkvb4dpg.js → local-desktop-users-tjcpyakd.js} +1 -1
  13. package/bin/vm-hands/{local-display-mac-d1t1qve5.js → local-display-mac-gtp439kc.js} +1 -1
  14. package/bin/vm-hands/local-display-session-hgh7wgdm.js +2 -0
  15. package/bin/vm-hands/local-display-video-xmwveqz7.js +2 -0
  16. package/bin/vm-hands/local-managed-process-wjan7e28.js +2 -0
  17. package/bin/vm-hands/local-pty-session-tnz6jwtt.js +2 -0
  18. package/bin/vm-hands/{managed-runtime-533929j6.js → managed-runtime-4vb4ve3j.js} +1 -1
  19. package/bin/vm-hands/{network-contract-84vs9gfz.js → network-contract-e98v6mwd.js} +1 -1
  20. package/bin/vm-hands/permissions-k58an38w.js +2 -0
  21. package/bin/vm-hands/{reason-hands-protocol-t51p2jgn.js → reason-hands-protocol-39wqa1xa.js} +1 -1
  22. package/bin/vm-hands/{serve-service-mjnye8vs.js → serve-service-9h4h44zs.js} +1 -1
  23. package/bin/vm-hands/{status-m8cfgr58.js → status-m04nbybr.js} +1 -1
  24. package/bin/vm-hands/version-feand7cf.js +2 -0
  25. package/bin/vm-hands/{vm-hands-entry-lite-jzmrhjkz.js → vm-hands-entry-lite-04x5xjt6.js} +1 -1
  26. package/bin/vm-hands/{vm-hands-entry-lite-yfc1w62e.js → vm-hands-entry-lite-13s0mfpr.js} +1 -1
  27. package/bin/vm-hands/{vm-hands-entry-lite-yj9hbtm1.js → vm-hands-entry-lite-2hfrcr50.js} +3 -3
  28. package/bin/vm-hands/{vm-hands-entry-lite-x342zztg.js → vm-hands-entry-lite-37b5045h.js} +1 -1
  29. package/bin/vm-hands/{vm-hands-entry-lite-mc5y3xr9.js → vm-hands-entry-lite-4anjdcth.js} +2 -2
  30. package/bin/vm-hands/{vm-hands-entry-lite-c6m5n5gh.js → vm-hands-entry-lite-4dqpcyk4.js} +4 -4
  31. package/bin/vm-hands/{vm-hands-entry-lite-06e9xm3v.js → vm-hands-entry-lite-4r1yn35v.js} +3 -3
  32. package/bin/vm-hands/{vm-hands-entry-lite-c5pyaaax.js → vm-hands-entry-lite-5tnma5qb.js} +3 -3
  33. package/bin/vm-hands/{vm-hands-entry-lite-tns12zqc.js → vm-hands-entry-lite-73f4cgkf.js} +2 -2
  34. package/bin/vm-hands/{vm-hands-entry-lite-ep1bq0xq.js → vm-hands-entry-lite-7tc69m74.js} +2 -2
  35. package/bin/vm-hands/{vm-hands-entry-lite-7mntg1rq.js → vm-hands-entry-lite-8dgbw34a.js} +2 -2
  36. package/bin/vm-hands/{vm-hands-entry-lite-msb3z9nq.js → vm-hands-entry-lite-9azmqs47.js} +3 -3
  37. package/bin/vm-hands/{vm-hands-entry-lite-8n2hetqw.js → vm-hands-entry-lite-anc8wmfd.js} +1 -1
  38. package/bin/vm-hands/{vm-hands-entry-lite-q13ekwev.js → vm-hands-entry-lite-b6gsggvp.js} +2 -2
  39. package/bin/vm-hands/{vm-hands-entry-lite-zwnevt4c.js → vm-hands-entry-lite-cgddp0y3.js} +1 -1
  40. package/bin/vm-hands/{vm-hands-entry-lite-yfvz7s4m.js → vm-hands-entry-lite-ct4mtq1m.js} +1 -1
  41. package/bin/vm-hands/{vm-hands-entry-lite-zea60aw2.js → vm-hands-entry-lite-d5m4pfrm.js} +2 -2
  42. package/bin/vm-hands/{vm-hands-entry-lite-r2100wsz.js → vm-hands-entry-lite-gqw0sj34.js} +3 -3
  43. package/bin/vm-hands/{vm-hands-entry-lite-k2kx2ex0.js → vm-hands-entry-lite-hfx1q0b0.js} +2 -2
  44. package/bin/vm-hands/{vm-hands-entry-lite-mhw459y7.js → vm-hands-entry-lite-hr8wmzyh.js} +3 -3
  45. package/bin/vm-hands/{vm-hands-entry-lite-mpy0j95a.js → vm-hands-entry-lite-hv3dxd5k.js} +1 -1
  46. package/bin/vm-hands/{vm-hands-entry-lite-4pm82ns4.js → vm-hands-entry-lite-j5t2pj4v.js} +1 -1
  47. package/bin/vm-hands/{vm-hands-entry-lite-8b6qfv1c.js → vm-hands-entry-lite-jhbeh0qy.js} +3 -3
  48. package/bin/vm-hands/{vm-hands-entry-lite-2egd9wr5.js → vm-hands-entry-lite-jhq35va0.js} +1 -1
  49. package/bin/vm-hands/{vm-hands-entry-lite-gmxfz6k2.js → vm-hands-entry-lite-jvszqt0z.js} +2 -2
  50. package/bin/vm-hands/{vm-hands-entry-lite-5nhmye0y.js → vm-hands-entry-lite-k9vk84wa.js} +2 -2
  51. package/bin/vm-hands/{vm-hands-entry-lite-q9spnspj.js → vm-hands-entry-lite-mnwfn7zv.js} +17 -17
  52. package/bin/vm-hands/{vm-hands-entry-lite-ygymhgk8.js → vm-hands-entry-lite-p83pttx8.js} +4 -4
  53. package/bin/vm-hands/{vm-hands-entry-lite-rxfxd2hs.js → vm-hands-entry-lite-q8rj7vmp.js} +1 -1
  54. package/bin/vm-hands/{vm-hands-entry-lite-5n4ay2gs.js → vm-hands-entry-lite-qc6gxqgs.js} +2 -2
  55. package/bin/vm-hands/{vm-hands-entry-lite-kpahnwm7.js → vm-hands-entry-lite-r2msq3z0.js} +21 -21
  56. package/bin/vm-hands/{vm-hands-entry-lite-dxaa88rs.js → vm-hands-entry-lite-vj7xzb3y.js} +1 -1
  57. package/bin/vm-hands/vm-hands-entry-lite-wgsdpq31.js +2 -0
  58. package/bin/vm-hands/{vm-hands-entry-lite-jvvk1gjx.js → vm-hands-entry-lite-x2bv0n2g.js} +1 -1
  59. package/bin/vm-hands/{vm-hands-entry-lite-3thdz953.js → vm-hands-entry-lite-xe0benev.js} +1 -1
  60. package/bin/vm-hands/vm-hands-entry-lite-y5hv1gjv.js +3 -0
  61. package/bin/vm-hands/{vm-hands-entry-lite-pd34mbnm.js → vm-hands-entry-lite-yxp1k8qm.js} +1 -1
  62. package/bin/vm-hands/{vm-hands-entry-lite-bjtcy8n6.js → vm-hands-entry-lite-ztsp4gs8.js} +3 -3
  63. package/bin/vm-hands/vm-hands-entry-lite.js +2 -2
  64. package/bin/vm-hands/{vm-hands-executor-mx3j751y.js → vm-hands-executor-6jaxxp69.js} +2 -2
  65. package/bin/vm-hands/{vm-hands-op-runner-bpv5sz6e.js → vm-hands-op-runner-jjd51571.js} +1 -1
  66. package/bin/vm-hands/{vm-hands-runtime-z81qbpbr.js → vm-hands-runtime-h58h37am.js} +3 -3
  67. package/bin/vm-hands/worker-preview-readiness-84stxabw.js +2 -0
  68. package/bin/vm-hands/worker-sandbox-563c5g2f.js +2 -0
  69. package/package.json +1 -1
  70. package/bin/vm-hands/api-credentials-rwy5ys03.js +0 -2
  71. package/bin/vm-hands/api-rjgpedvk.js +0 -2
  72. package/bin/vm-hands/connect-cli-p72wek72.js +0 -2
  73. package/bin/vm-hands/credentials-6mbx2mke.js +0 -2
  74. package/bin/vm-hands/desktop-account-fpf13hm4.js +0 -2
  75. package/bin/vm-hands/local-automation-pdhkw5de.js +0 -2
  76. package/bin/vm-hands/local-capabilities-pmks6jpv.js +0 -2
  77. package/bin/vm-hands/local-display-session-m8469h63.js +0 -2
  78. package/bin/vm-hands/local-display-video-6xq6fjtm.js +0 -2
  79. package/bin/vm-hands/local-managed-process-2tx1h7cb.js +0 -2
  80. package/bin/vm-hands/local-pty-session-p60ha91y.js +0 -2
  81. package/bin/vm-hands/permissions-4myxznfs.js +0 -2
  82. package/bin/vm-hands/version-gszhe6py.js +0 -2
  83. package/bin/vm-hands/vm-hands-entry-lite-b48eyd09.js +0 -3
  84. package/bin/vm-hands/vm-hands-entry-lite-j1hddtjs.js +0 -2
  85. package/bin/vm-hands/worker-preview-readiness-afw3ezwg.js +0 -2
  86. package/bin/vm-hands/worker-sandbox-egdjwgcp.js +0 -2
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import{E}from"./vm-hands-entry-lite-72nj66ab.js";import{fe,De,Ne,Le,$e}from"./vm-hands-entry-lite-q13ekwev.js";import{spawn as y}from"child_process";import{existsSync as p,mkdirSync as T,readFileSync as _,writeFileSync as A}from"fs";import{homedir as m}from"os";import{basename as H,delimiter as g,join as f,win32 as u}from"path";var Cr=process.platform==="win32"?De("win32"):"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",P=Cr.split(g),R=5000,S=65536,O=new Set(["zsh","bash"]),b=[[".local","bin"],[".bun","bin"],[".cargo","bin"],["go","bin"]],x=(t,e)=>new Promise((n,r)=>{let o;try{o=y(t,[...e],{...Ne(),stdio:["ignore","pipe","ignore"]}),Le(o)}catch(c){r(c);return}let i=[],s=0,a=null,L=(c)=>{a??=Error(c);try{if(o.pid!==void 0)$e(o.pid,"SIGKILL")}catch{}},d=setTimeout(()=>L("login_shell_timeout"),R);o.stdout?.on("data",(c)=>{if(s+=c.length,s>S)L("login_shell_output_too_large");else i.push(c)}),o.once("error",(c)=>{clearTimeout(d),r(c)}),o.once("close",(c)=>{if(clearTimeout(d),a)r(a);else if(c!==0)r(Error("login_shell_exit_nonzero"));else n(Buffer.concat(i).toString("utf8"))})});function w(t){return typeof t==="string"&&t.startsWith("/")&&!t.includes("\x00")&&O.has(H(t))}function h(t){let e=new Set,n=[];for(let r of t){if(e.has(r))continue;e.add(r),n.push(r)}return n}function Ar(t,e=process.platform){let n=e==="win32",r=t.split(`
3
- `).at(-1)??"",o=[];for(let i of r.split(n?";":":")){let s=i.trim();if(n?!u.isAbsolute(s):!s.startsWith("/"))continue;if(s.includes("\x00"))continue;if(E(s))continue;o.push(s)}return h(o)}function xn(t){let e=t?.home??m(),n=t?.directoryExists??p,r=b.map((o)=>f(e,...o)).filter((o)=>{try{return n(o)}catch{return!1}});return h([...r,...process.platform==="win32"?Ar(process.env.PATH??process.env.Path??""):[],...P]).join(g)}async function C(t){let e=t?.shell??process.env.SHELL,n=()=>({path:xn({home:t?.home,directoryExists:t?.directoryExists}),source:"fallback"});if(process.platform==="win32"||!w(e))return n();let r;try{r=await(t?.runLoginShell??x)(e,["-lic",'printf %s "$PATH"'])}catch{return n()}if(Buffer.byteLength(r,"utf8")>S)return n();let o=Ar(r);if(o.length===0)return n();return{path:h([...o,...P]).join(":"),source:"login_shell"}}function lo(t){let e=null;return()=>(e??=C(t),e)}function l(t){if(t===void 0||t.includes("\x00")||Buffer.byteLength(t,"utf8")>32768)return;return t}function Ue(t){let e=t.source??process.env,n={HOME:t.home,PATH:t.path??Cr,TMPDIR:t.temporaryDirectory,SHELL:l(e.SHELL)??"/bin/zsh",LANG:l(e.LANG)??"C.UTF-8",LC_ALL:l(e.LC_ALL)??l(e.LANG)??"C.UTF-8"},r=l(e.LC_CTYPE),o=l(e.TERM),i=l(e.COLORTERM);if(r)n.LC_CTYPE=r;if(o)n.TERM=o;if(i)n.COLORTERM=i;if(process.platform==="win32"){for(let s of I){let a=l(e[s]);if(a)n[s]=a}n.TEMP=n.TMP=t.temporaryDirectory,n.SHELL=fe()??n.SHELL,n.PATH=kn(n.PATH)}return n}function kn(t,e=f(m(),".reason","python3")){let n=(i)=>t.split(u.delimiter).filter((s)=>s&&!/[\\/]WindowsApps[\\/]?$/i.test(s)).map((s)=>u.join(s,i)).find((s)=>p(s)),r=n("python.exe");if(n("python3.exe")||!r)return t;let o=`#!/bin/sh
2
+ import{E}from"./vm-hands-entry-lite-72nj66ab.js";import{fe,De,Ne,Le,$e}from"./vm-hands-entry-lite-b6gsggvp.js";import{spawn as y}from"child_process";import{existsSync as p,mkdirSync as T,readFileSync as _,writeFileSync as A}from"fs";import{homedir as m}from"os";import{basename as H,delimiter as g,join as f,win32 as u}from"path";var Cr=process.platform==="win32"?De("win32"):"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",P=Cr.split(g),R=5000,S=65536,O=new Set(["zsh","bash"]),b=[[".local","bin"],[".bun","bin"],[".cargo","bin"],["go","bin"]],x=(t,e)=>new Promise((n,r)=>{let o;try{o=y(t,[...e],{...Ne(),stdio:["ignore","pipe","ignore"]}),Le(o)}catch(c){r(c);return}let i=[],s=0,a=null,L=(c)=>{a??=Error(c);try{if(o.pid!==void 0)$e(o.pid,"SIGKILL")}catch{}},d=setTimeout(()=>L("login_shell_timeout"),R);o.stdout?.on("data",(c)=>{if(s+=c.length,s>S)L("login_shell_output_too_large");else i.push(c)}),o.once("error",(c)=>{clearTimeout(d),r(c)}),o.once("close",(c)=>{if(clearTimeout(d),a)r(a);else if(c!==0)r(Error("login_shell_exit_nonzero"));else n(Buffer.concat(i).toString("utf8"))})});function w(t){return typeof t==="string"&&t.startsWith("/")&&!t.includes("\x00")&&O.has(H(t))}function h(t){let e=new Set,n=[];for(let r of t){if(e.has(r))continue;e.add(r),n.push(r)}return n}function Ar(t,e=process.platform){let n=e==="win32",r=t.split(`
3
+ `).at(-1)??"",o=[];for(let i of r.split(n?";":":")){let s=i.trim();if(n?!u.isAbsolute(s):!s.startsWith("/"))continue;if(s.includes("\x00"))continue;if(E(s))continue;o.push(s)}return h(o)}function xn(t){let e=t?.home??m(),n=t?.directoryExists??p,r=b.map((o)=>f(e,...o)).filter((o)=>{try{return n(o)}catch{return!1}});return h([...r,...process.platform==="win32"?Ar(process.env.PATH??process.env.Path??""):[],...P]).join(g)}async function C(t){let e=t?.shell??process.env.SHELL,n=()=>({path:xn({home:t?.home,directoryExists:t?.directoryExists}),source:"fallback"});if(process.platform==="win32"||!w(e))return n();let r;try{r=await(t?.runLoginShell??x)(e,["-lic",'printf %s "$PATH"'])}catch{return n()}if(Buffer.byteLength(r,"utf8")>S)return n();let o=Ar(r);if(o.length===0)return n();return{path:h([...o,...P]).join(":"),source:"login_shell"}}function uo(t){let e=null;return()=>(e??=C(t),e)}function l(t){if(t===void 0||t.includes("\x00")||Buffer.byteLength(t,"utf8")>32768)return;return t}function Ue(t){let e=t.source??process.env,n={HOME:t.home,PATH:t.path??Cr,TMPDIR:t.temporaryDirectory,SHELL:l(e.SHELL)??"/bin/zsh",LANG:l(e.LANG)??"C.UTF-8",LC_ALL:l(e.LC_ALL)??l(e.LANG)??"C.UTF-8"},r=l(e.LC_CTYPE),o=l(e.TERM),i=l(e.COLORTERM);if(r)n.LC_CTYPE=r;if(o)n.TERM=o;if(i)n.COLORTERM=i;if(process.platform==="win32"){for(let s of I){let a=l(e[s]);if(a)n[s]=a}n.TEMP=n.TMP=t.temporaryDirectory,n.SHELL=fe()??n.SHELL,n.PATH=kn(n.PATH)}return n}function kn(t,e=f(m(),".reason","python3")){let n=(i)=>t.split(u.delimiter).filter((s)=>s&&!/[\\/]WindowsApps[\\/]?$/i.test(s)).map((s)=>u.join(s,i)).find((s)=>p(s)),r=n("python.exe");if(n("python3.exe")||!r)return t;let o=`#!/bin/sh
4
4
  exec "${r.replaceAll("\\","/")}" "$@"
5
5
  `;try{let i=f(e,"python3");if(!p(i)||_(i,"utf8")!==o)T(e,{recursive:!0}),A(i,o)}catch{return t}return[e,t].join(u.delimiter)}var I=["SystemRoot","SystemDrive","windir","ComSpec","PATHEXT","USERPROFILE","USERNAME","USERDOMAIN","APPDATA","LOCALAPPDATA","ProgramData","ProgramFiles","ProgramFiles(x86)","ProgramW6432","CommonProgramFiles","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","OS"];
6
- export{Cr,Ar,xn,lo,Ue,kn};
6
+ export{Cr,Ar,xn,uo,Ue,kn};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- var i="libara_device_keychain.dylib",e="libreason_device_keychain.dylib";class mt extends Error{code;constructor(n,t){super(t);this.code=n;this.name="ManagedRuntimeError"}}import{existsSync as s}from"fs";import{join as a}from"path";function No(n){let t=a(n,e);return s(t)?t:a(n,i)}
3
- export{mt,No};
2
+ var i="libara_device_keychain.dylib",e="libreason_device_keychain.dylib";class mt extends Error{code;constructor(n,t){super(t);this.code=n;this.name="ManagedRuntimeError"}}import{existsSync as s}from"fs";import{join as a}from"path";function Lo(n){let t=a(n,e);return s(t)?t:a(n,i)}
3
+ export{mt,Lo};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Ge,pt}from"./vm-hands-entry-lite-5nhmye0y.js";import{Qe}from"./vm-hands-entry-lite-j1hddtjs.js";import{Lo,le,Kr,gt,$o}from"./vm-hands-entry-lite-mhw459y7.js";import{E}from"./vm-hands-entry-lite-72nj66ab.js";import{a,nr}from"./vm-hands-entry-lite-gmxfz6k2.js";import{spawnSync as H}from"child_process";import{dirname as w}from"path";import{spawn as A}from"child_process";import{accessSync as _,constants as v}from"fs";import{basename as C,join as O}from"path";var l=null;function S(e){if(l===e)l=null;if(e.exitCode===null&&e.signalCode===null)e.kill("SIGTERM")}var Ir=(e,t)=>{if(l)S(l);let s=O(e,Lo);try{_(s,v.X_OK)}catch{return()=>{}}let n;try{n=A(s,["--app",e,"--name",C(e,".app"),"--permission",t==="screen"?"screen_recording":"accessibility"],{detached:!0,stdio:"ignore"})}catch{return()=>{}}return n.on("error",()=>{if(l===n)l=null}),n.once("exit",()=>{if(l===n)l=null}),n.unref(),l=n,()=>S(n)};import{chmodSync as ne,existsSync as se,mkdirSync as re,readFileSync as D,realpathSync as ie,renameSync as oe,statSync as j,writeFileSync as ae}from"fs";import{dirname as de,isAbsolute as G,join as N,resolve as T,sep as b}from"path";function F(e=a()){return N(nr(e),"reason","protected-path-grants.json")}var f=null;function L(e){let t=JSON.parse(e);if(!Array.isArray(t?.grants))return[];return t.grants.flatMap((s)=>{let n=s;return n&&typeof n.path==="string"&&G(n.path)&&(n.kind==="file"||n.kind==="folder")&&typeof n.grantedAt==="number"?[{path:n.path,kind:n.kind,grantedAt:n.grantedAt}]:[]})}function y(e=F()){try{let{mtimeMs:t}=j(e);if(f&&f.file===e&&f.mtimeMs===t)return f.grants;let s=L(D(e,"utf8"));return f={file:e,mtimeMs:t,grants:s},s}catch{return[]}}function W(e,t){return e.kind==="file"?t===e.path:t===e.path||t.startsWith(`${e.path}${b}`)}function U(e,t){let s=T(e);return y(t).some((n)=>W(n,s))}function yo(e,t){return E(e)&&!U(e,t)}function wo(e,t,s){let n=t?"file-read* file-write*":"file-read*";return y(s).filter((r)=>r.path===e||r.path.startsWith(`${e}${b}`)).map((r)=>`(allow ${n} (${r.kind==="file"?"literal":"subpath"} ${JSON.stringify(r.path)}))`)}var P="x-apple.systempreferences:com.apple.preference.security",J="curl -fsSL https://reasonmachines.com/install.sh | bash",q=180000,B=2000;var k={screen:{label:"Screen & System Audio Recording",purpose:"desktop video, computer-use screenshots",level:"required",pane:`${P}?Privacy_ScreenCapture`},accessibility:{label:"Accessibility",purpose:"computer-use clicks and typing, desktop input",level:"required",pane:`${P}?Privacy_Accessibility`},disk:{label:"Full Disk Access",purpose:"Sessions in Desktop, Documents, Downloads, iCloud Drive and Mail",level:"recommended",pane:`${P}?Privacy_AllFiles`}};function R(e){return e.executable}function K(e,t){if(e==="computer_use_identity_missing")return`Reason's background identity is not installed (${e}); reinstall Reason: ${J}`;if(e==="computer_use_identity_outdated")return`Reason's background identity is outdated (${Kr(t)??"unknown"}; this CLI is ${Qe}) (${e}); \`reason update\` installs this release's`;return`Reason's background identity cannot run computer use for this CLI (${e}); run the installed \`reason\``}function ls(e=a()){let t=gt(e);if(t.length>0)return{state:"ready",path:w(w(w(t[0]))),prefix:t};let s=$o(t,e)??"computer_use_identity_unavailable";return{state:s,path:le(e),detail:K(s,e)}}function V(){return{identity:()=>ls(),grants:(e)=>Ge(e),request:(e,t)=>pt(e,t),worker:async()=>(await import("./status-m8cfgr58.js")).connectionMacState(),open:(e)=>{H("/usr/bin/open",e,{stdio:"ignore",timeout:1e4})},tile:Ir,restartConnection:async()=>(await import("./connect-cli-p72wek72.js")).restartConnection(),sleep:(e)=>new Promise((t)=>setTimeout(t,e)),now:()=>Date.now()}}function M(e,t,s){if(e.state!=="ready"||!t)return"unknown";return t[s]?"granted":"missing"}async function us(e){let t=e.identity(),s=t.state==="ready"?await e.grants(t.prefix):null,n=await e.worker(),r=n?R(n):null,i=!r||n?.full_disk_access==="unknown"?"unknown":n?.full_disk_access==="granted"?"granted":"missing",c=(u,d,o)=>{let{label:p,purpose:h,level:m}=k[u];return{id:u,label:p,purpose:h,level:m,state:d,holder:o}};return{identity:{state:t.state,path:t.path,detail:t.state==="ready"?null:t.detail},worker_detail:r?null:"Full Disk Access is read from this computer's running worker; `reason connect` starts it.",permissions:[c("screen",M(t,s,"screen"),t.path),c("accessibility",M(t,s,"accessibility"),t.path),c("disk",i,r)]}}function Ks(e){let t=e.identity.state==="ready"?null:e.identity.state,s=e.permissions.filter((i)=>i.state==="granted").length,n=[...t?[t]:[],...e.permissions.filter((i)=>i.state!=="granted"&&!(t&&i.id!=="disk")).map((i)=>`${i.label} ${i.state}`)],r=!t&&e.permissions.some((i)=>i.state==="missing");return`Permissions: ${s} of ${e.permissions.length}${n.length>0?` (${n.join(", ")})`:""}`+(r?" \u2014 reason permissions allow":n.length>0?" \u2014 reason permissions":"")}async function x(e,t){let s=t.now()+q;for(;;){if(await e())return!0;if(t.now()>=s)return!1;await t.sleep(B)}}async function Js(e,t){let s=t.host??V(),{io:n}=t,r=await us(s),i=r.permissions.filter((o)=>e.includes(o.id)&&o.state!=="granted");if(i.length===0)return n.stdout.write(`Reason permissions: ${e.map((o)=>k[o].label).join(", ")} already allowed.
2
+ import{Ge,pt}from"./vm-hands-entry-lite-k9vk84wa.js";import{Qe}from"./vm-hands-entry-lite-wgsdpq31.js";import{$o,le,Kr,gt,Mo}from"./vm-hands-entry-lite-hr8wmzyh.js";import{E}from"./vm-hands-entry-lite-72nj66ab.js";import{a,nr}from"./vm-hands-entry-lite-jvszqt0z.js";import{spawnSync as H}from"child_process";import{dirname as w}from"path";import{spawn as A}from"child_process";import{accessSync as _,constants as v}from"fs";import{basename as C,join as O}from"path";var l=null;function S(e){if(l===e)l=null;if(e.exitCode===null&&e.signalCode===null)e.kill("SIGTERM")}var Ir=(e,t)=>{if(l)S(l);let s=O(e,$o);try{_(s,v.X_OK)}catch{return()=>{}}let n;try{n=A(s,["--app",e,"--name",C(e,".app"),"--permission",t==="screen"?"screen_recording":"accessibility"],{detached:!0,stdio:"ignore"})}catch{return()=>{}}return n.on("error",()=>{if(l===n)l=null}),n.once("exit",()=>{if(l===n)l=null}),n.unref(),l=n,()=>S(n)};import{chmodSync as ne,existsSync as se,mkdirSync as re,readFileSync as D,realpathSync as ie,renameSync as oe,statSync as j,writeFileSync as ae}from"fs";import{dirname as de,isAbsolute as G,join as N,resolve as T,sep as b}from"path";function F(e=a()){return N(nr(e),"reason","protected-path-grants.json")}var f=null;function L(e){let t=JSON.parse(e);if(!Array.isArray(t?.grants))return[];return t.grants.flatMap((s)=>{let n=s;return n&&typeof n.path==="string"&&G(n.path)&&(n.kind==="file"||n.kind==="folder")&&typeof n.grantedAt==="number"?[{path:n.path,kind:n.kind,grantedAt:n.grantedAt}]:[]})}function y(e=F()){try{let{mtimeMs:t}=j(e);if(f&&f.file===e&&f.mtimeMs===t)return f.grants;let s=L(D(e,"utf8"));return f={file:e,mtimeMs:t,grants:s},s}catch{return[]}}function W(e,t){return e.kind==="file"?t===e.path:t===e.path||t.startsWith(`${e.path}${b}`)}function U(e,t){let s=T(e);return y(t).some((n)=>W(n,s))}function wo(e,t){return E(e)&&!U(e,t)}function bo(e,t,s){let n=t?"file-read* file-write*":"file-read*";return y(s).filter((r)=>r.path===e||r.path.startsWith(`${e}${b}`)).map((r)=>`(allow ${n} (${r.kind==="file"?"literal":"subpath"} ${JSON.stringify(r.path)}))`)}var P="x-apple.systempreferences:com.apple.preference.security",J="curl -fsSL https://reasonmachines.com/install.sh | bash",q=180000,B=2000;var k={screen:{label:"Screen & System Audio Recording",purpose:"desktop video, computer-use screenshots",level:"required",pane:`${P}?Privacy_ScreenCapture`},accessibility:{label:"Accessibility",purpose:"computer-use clicks and typing, desktop input",level:"required",pane:`${P}?Privacy_Accessibility`},disk:{label:"Full Disk Access",purpose:"Sessions in Desktop, Documents, Downloads, iCloud Drive and Mail",level:"recommended",pane:`${P}?Privacy_AllFiles`}};function R(e){return e.executable}function K(e,t){if(e==="computer_use_identity_missing")return`Reason's background identity is not installed (${e}); reinstall Reason: ${J}`;if(e==="computer_use_identity_outdated")return`Reason's background identity is outdated (${Kr(t)??"unknown"}; this CLI is ${Qe}) (${e}); \`reason update\` installs this release's`;return`Reason's background identity cannot run computer use for this CLI (${e}); run the installed \`reason\``}function ls(e=a()){let t=gt(e);if(t.length>0)return{state:"ready",path:w(w(w(t[0]))),prefix:t};let s=Mo(t,e)??"computer_use_identity_unavailable";return{state:s,path:le(e),detail:K(s,e)}}function V(){return{identity:()=>ls(),grants:(e)=>Ge(e),request:(e,t)=>pt(e,t),worker:async()=>(await import("./status-m04nbybr.js")).connectionMacState(),open:(e)=>{H("/usr/bin/open",e,{stdio:"ignore",timeout:1e4})},tile:Ir,restartConnection:async()=>(await import("./connect-cli-ekfj4bg7.js")).restartConnection(),sleep:(e)=>new Promise((t)=>setTimeout(t,e)),now:()=>Date.now()}}function M(e,t,s){if(e.state!=="ready"||!t)return"unknown";return t[s]?"granted":"missing"}async function us(e){let t=e.identity(),s=t.state==="ready"?await e.grants(t.prefix):null,n=await e.worker(),r=n?R(n):null,i=!r||n?.full_disk_access==="unknown"?"unknown":n?.full_disk_access==="granted"?"granted":"missing",c=(u,d,o)=>{let{label:p,purpose:h,level:m}=k[u];return{id:u,label:p,purpose:h,level:m,state:d,holder:o}};return{identity:{state:t.state,path:t.path,detail:t.state==="ready"?null:t.detail},worker_detail:r?null:"Full Disk Access is read from this computer's running worker; `reason connect` starts it.",permissions:[c("screen",M(t,s,"screen"),t.path),c("accessibility",M(t,s,"accessibility"),t.path),c("disk",i,r)]}}function Ks(e){let t=e.identity.state==="ready"?null:e.identity.state,s=e.permissions.filter((i)=>i.state==="granted").length,n=[...t?[t]:[],...e.permissions.filter((i)=>i.state!=="granted"&&!(t&&i.id!=="disk")).map((i)=>`${i.label} ${i.state}`)],r=!t&&e.permissions.some((i)=>i.state==="missing");return`Permissions: ${s} of ${e.permissions.length}${n.length>0?` (${n.join(", ")})`:""}`+(r?" \u2014 reason permissions allow":n.length>0?" \u2014 reason permissions":"")}async function x(e,t){let s=t.now()+q;for(;;){if(await e())return!0;if(t.now()>=s)return!1;await t.sleep(B)}}async function Js(e,t){let s=t.host??V(),{io:n}=t,r=await us(s),i=r.permissions.filter((o)=>e.includes(o.id)&&o.state!=="granted");if(i.length===0)return n.stdout.write(`Reason permissions: ${e.map((o)=>k[o].label).join(", ")} already allowed.
3
3
  `),0;let c=!1,u=!1,d=s.identity();for(let o of i){let{label:p,pane:h}=k[o.id];if(o.id!=="disk"){if(d.state!=="ready"){if(!c)n.stderr.write(`Reason permissions: ${d.detail}
4
4
  `);c=!0;continue}let g=o.id;await s.request(d.prefix,g),s.open([h]);let I=s.tile(d.path,g);if(n.stdout.write(`Allow Reason in System Settings > Privacy & Security > ${p}.
5
5
  `),!t.wait)continue;if(n.stdout.write(`Waiting for it (Ctrl-C to stop)\u2026
@@ -11,4 +11,4 @@ import{Ge,pt}from"./vm-hands-entry-lite-5nhmye0y.js";import{Qe}from"./vm-hands-e
11
11
  `),await x(async()=>(await s.worker())?.full_disk_access==="granted",s))n.stdout.write(`Full Disk Access: granted.
12
12
  `);else n.stderr.write("Full Disk Access is not reported yet. If you allowed it, `reason connect` restarts the worker with it.\n"),c=!0}if(u)try{if(await s.restartConnection())n.stdout.write(`This computer's Reason connection restarted to use them.
13
13
  `)}catch(o){n.stderr.write(`This computer's Reason connection uses them after it restarts (\`reason connect\`): ${o instanceof Error?o.message:String(o)}
14
- `)}return c?1:0}export{Ir,yo,wo,ls,us,Ks,Js};
14
+ `)}return c?1:0}export{Ir,wo,bo,ls,us,Ks,Js};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{We,mo,F,Ve,Ht,Tr,x}from"./vm-hands-entry-lite-8b6qfv1c.js";import{K}from"./vm-hands-entry-lite-yfvz7s4m.js";import{pt}from"./vm-hands-entry-lite-5nhmye0y.js";import{gt}from"./vm-hands-entry-lite-mhw459y7.js";import{Ir}from"./vm-hands-entry-lite-ep1bq0xq.js";import{Pt,Hi}from"./vm-hands-entry-lite-3thdz953.js";import{G,qe}from"./vm-hands-entry-lite-zea60aw2.js";import{xe,Jn}from"./vm-hands-entry-lite-ygymhgk8.js";import{St}from"./vm-hands-entry-lite-5n4ay2gs.js";import{a}from"./vm-hands-entry-lite-gmxfz6k2.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{C}from"./vm-hands-entry-lite-q13ekwev.js";import{spawn as R,spawnSync as st}from"child_process";import{createHash as it,randomUUID as ge}from"crypto";import{closeSync as at,copyFileSync as ae,existsSync as M,fstatSync as ct,mkdirSync as ce,openSync as lt,readdirSync as U,readFileSync as X,readlinkSync as ut,renameSync as he,rmSync as dt,statSync as mt,writeFileSync as ft}from"fs";import{connect as ht}from"net";import{tmpdir as L,userInfo as we}from"os";import{basename as le,delimiter as wt,dirname as B,join as f}from"path";var z=`import { spawn, execFileSync } from "node:child_process";
2
+ import{We,go,F,Ve,Ht,Tr,x}from"./vm-hands-entry-lite-jhbeh0qy.js";import{K}from"./vm-hands-entry-lite-ct4mtq1m.js";import{pt}from"./vm-hands-entry-lite-k9vk84wa.js";import{gt}from"./vm-hands-entry-lite-hr8wmzyh.js";import{Ir}from"./vm-hands-entry-lite-7tc69m74.js";import{Pt,Hi}from"./vm-hands-entry-lite-xe0benev.js";import{G,qe}from"./vm-hands-entry-lite-d5m4pfrm.js";import{xe,Jn}from"./vm-hands-entry-lite-p83pttx8.js";import{St}from"./vm-hands-entry-lite-qc6gxqgs.js";import{a}from"./vm-hands-entry-lite-jvszqt0z.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{C}from"./vm-hands-entry-lite-b6gsggvp.js";import{spawn as R,spawnSync as st}from"child_process";import{createHash as it,randomUUID as ge}from"crypto";import{closeSync as at,copyFileSync as ae,existsSync as M,fstatSync as ct,mkdirSync as ce,openSync as lt,readdirSync as U,readFileSync as X,readlinkSync as ut,renameSync as he,rmSync as dt,statSync as mt,writeFileSync as ft}from"fs";import{connect as ht}from"net";import{tmpdir as L,userInfo as we}from"os";import{basename as le,delimiter as wt,dirname as B,join as f}from"path";var z=`import { spawn, execFileSync } from "node:child_process";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { readFileSync, readlinkSync, lstatSync, realpathSync, statSync, mkdtempSync, mkdirSync, chmodSync, writeFileSync, readdirSync, rmSync, openSync, readSync, closeSync, renameSync } from "node:fs";
5
5
  import { tmpdir } from "node:os";
@@ -856,5 +856,5 @@ if(process.env.REASON_CLOUD_GATEWAY_EXEC === "1") {
856
856
  }
857
857
  `;import{spawn as Te}from"child_process";import{lstatSync as V,readFileSync as Z,rmSync as Ne}from"fs";import{basename as Pe}from"path";var De="__desktop-call",Me="/usr/bin/setpriv",Ue=27262976,Le=8192,$e=2000;function W(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function Be(e){try{return JSON.parse(e)}catch{return null}}function Fe(){return[process.execPath,...Pe(process.execPath).startsWith("bun")&&process.argv[1]?[process.argv[1]]:[],De]}function Ge(e){let o=(i)=>{try{return V(i).uid}catch{return null}},t=V("/tmp/.X11-unix",{throwIfNoEntry:!1});if(!t?.isDirectory()||t.uid!==0)return;let n=["/tmp/.X99-lock","/tmp/.X11-unix/X99"].filter((i)=>{let u=o(i);return u!==null&&u!==e.uid});if(!n.length)return;let s="";try{let i=Z("/tmp/.X99-lock","utf8").trim();if(/^\d+$/.test(i))s=Z(`/proc/${i}/comm`,"utf8").trim()}catch{}if(/^X/.test(s))return;for(let i of n)Ne(i,{force:!0})}function Bt(e,o,t,n={}){if(t.throwIfAborted(),(o.op==="display"||o.op==="automation")&&process.platform==="linux"&&process.getuid?.()===0)try{Ge(e)}catch{}let s=n.command??Fe();return new Promise((i,u)=>{let c=(n.spawnProcess??Te)(Me,[`--reuid=${e.uid}`,`--regid=${e.gid}`,"--clear-groups","--no-new-privs","--",...s],{cwd:e.home,detached:!0,stdio:["pipe","pipe","pipe"],env:{HOME:e.home,USER:e.username,LOGNAME:e.username,PATH:"/usr/local/bin:/usr/bin:/bin"}}),d=[],m=0,l="",p=null,g=!1,w,h=(y)=>{try{process.kill(-c.pid,y)}catch{c.kill(y)}},I=(y)=>{p??=y,h("SIGTERM"),w??=setTimeout(()=>h("SIGKILL"),$e)},S=()=>I(new r("cancelled","Reason cancelled the desktop operation."));t.addEventListener("abort",S,{once:!0});let _=(y)=>{if(g)return;g=!0,clearTimeout(w),t.removeEventListener("abort",S),y()};if(c.stdout.on("data",(y)=>{if(m+=y.byteLength,m>Ue)I(new r("desktop_delegate_failed","Reason's desktop reply is too large."));else d.push(y)}),c.stderr.setEncoding("utf8").on("data",(y)=>{l=(l+y).slice(-Le)}),c.stdin.on("error",()=>{}),c.once("error",()=>_(()=>u(p??new r("desktop_delegate_unavailable","Reason could not start its desktop as the desktop account.")))),c.once("close",(y,Ee)=>_(()=>{if(p)return u(p);let b=Be(Buffer.concat(d).toString("utf8"));if(W(b)&&b.ok===!0&&W(b.result))return i(b.result);let O=W(b)&&b.ok===!1&&typeof b.code==="string"&&typeof b.message==="string"?new r(b.code.slice(0,120),b.message.slice(0,2000)):null,J=`exited ${y??Ee}${O?"":" with no reply"}`,Y=l.trim().split(`
858
858
  `).at(-1)?.slice(-300)??"";if(!O||O.code==="desktop_delegate_failed")process.stderr.write(`Reason worker: desktop call ${J}${l?`: ${l.trim().slice(-500)}`:""}
859
- `);if(O)return u(O);u(new r("desktop_delegate_failed",`Reason's desktop operation failed (${J}${Y?`: ${Y}`:""}).`))})),t.aborted)S();c.stdin.end(JSON.stringify(o))})}async function Q(e,o,t,n={}){let s=await Bt(e,{op:"automation",call:o},t,n);if(!Number.isSafeInteger(s.code)||typeof s.stdout!=="string"||typeof s.stderr!=="string")throw new r("desktop_delegate_failed","Reason's desktop reply is malformed.");return{code:s.code,stdout:Buffer.from(s.stdout,"base64"),stderr:s.stderr}}import{execFile as He,spawn as je}from"child_process";import{closeSync as Xe,mkdirSync as Ke,openSync as Je}from"fs";import{dirname as E,join as Ye}from"path";import{promisify as ze}from"util";var Ze=ze(He),ee="x-apple.systempreferences:com.apple.preference.security",Qe={accessibility:`${ee}?Privacy_Accessibility`,screen:`${ee}?Privacy_ScreenCapture`},et=64,A=new Map;function T(e,o){let t=A.get(e);if(t?.has(o))return!1;if(!t){if(A.size>=et)A.delete(A.keys().next().value);t=new Set,A.set(e,t)}return t.add(o),!0}function tt(){let e=a(),o=Jn(xe(e),process.env),t=Ye(e,".local","share","reason","desktop-install.log");Ke(E(t),{recursive:!0,mode:448});let n=Je(t,"a",384);try{let s=je(o,["desktop","install"],{detached:!0,stdio:["ignore",n,n],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});s.on("error",()=>{return}),s.unref()}finally{Xe(n)}}var N={open:async(e,o)=>{await Ze("/usr/bin/open",e,{signal:o,timeout:1e4,maxBuffer:8192})},request:(e,o)=>pt(e,o),tile:Ir,installDesktop:tt},te=!1;async function oe(e,o,t){try{await o.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await o.open([e],t)}}async function ne(e,o,t,n){if(await t.open([Qe[o]],n).catch(()=>{}),e[0]&&!n.aborted)t.tile(E(E(E(e[0]))),o)}async function ot(e,o,t,n,s){for(let i of t){if(!T(e,`grant:${i}`))continue;s.throwIfAborted(),await n.request(o,i).catch(()=>null),await ne(o,i,n,s)}}var rt={name:"open_tab",description:"Open a web page in the user's own Chrome on this Mac. Reason cannot read, screenshot or click in that tab, and no tab_id is returned: browser control needs Reason's Chrome extension. An actual browser call opens its setup page.",inputSchema:{type:"object",properties:{url:{type:"string",description:"An http or https URL."}},required:["url"],additionalProperties:!1}};function re(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function nt(e){if(typeof e!=="string")return null;try{let o=new URL(e);return o.protocol==="https:"||o.protocol==="http:"?o.href:null}catch{return null}}async function se(e,o=N){let{call:t,runId:n,signal:s}=e;if(t.kind==="browser"){if(t.operation==="discover")return re({result:{tools:[rt]}});if(t.operation!=="call")throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet. Request a browser operation or connect Chrome from Reason to set it up.")}if(e.desktopMissing&&!te){te=!0;try{o.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&T(n,"grant:probe")){let c=await o.request(e.identity).catch(()=>null),d=c?[...c.accessibility?[]:["accessibility"],...c.screen?[]:["screen"]]:[];for(let m of d)T(n,`grant:${m}`);for(let m of d)await ne(e.identity,m,o,s)}throw new r("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(T(n,"page:chrome-extension"))await oe(mo,o,s).catch(()=>{});let i=t.arguments,u=t.operation==="call"&&t.tool==="open_tab"&&i&&typeof i==="object"&&!Array.isArray(i)?nt(i.url):null;if(!u)throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet; Reason opened its Chrome Web Store page. open_tab still opens pages.");return await oe(u,o,s),re({result:{content:[{type:"text",text:JSON.stringify({opened:u,browser:"the user's Chrome",controllable:!1,note:"Opened for the user to see. Reason cannot read or act in this tab until Reason's Chrome extension is added (its Chrome Web Store page is open)."})}]}})}async function ie(e,o=N){if(e.call.kind!=="computer"||e.call.operation!=="permission_status"||e.output.code!==0||e.identity.length===0)return e.output;let t;try{t=JSON.parse(e.output.stdout.toString("utf8"))}catch{return e.output}if(!t||typeof t!=="object"||Array.isArray(t))return e.output;let n=t.permissions;if(!n||typeof n!=="object")return e.output;let s=n,i=[...s.accessibility==="missing"?["accessibility"]:[],...s.screenRecording==="missing"?["screen"]:[]];if(i.length===0)return e.output;return await ot(e.runId,e.identity,i,o,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:i}))}}var j=172032,_t=18874368,yt=8192,bt=65536,xt=55000,kt=60000,Rt=4,It=40000,vt=/^[0-9a-f-]{36}$/,ue=z,Ot=ge();function P(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function D(){throw new r("invalid_automation_request","Reason automation request is malformed.")}function _e(e){let o=Object.keys(e).sort().join(",");if(o==="call"||o==="browser,call"){let t=e.call,n=o==="browser,call";if(!P(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||n&&(e.browser!==St||t.kind!=="browser")||JSON.stringify(t).length>bt)D();return{call:t,userChrome:n}}if(o==="offset,output_id"){if(typeof e.output_id!=="string"||!vt.test(e.output_id)||!Number.isSafeInteger(e.offset)||e.offset<0)D();return{output_id:e.output_id,offset:e.offset}}return D()}function Pn(e=process.platform,o=x){if(e==="darwin")return!0;return(e==="linux"||e==="win32")&&o()?.features.computer===!0}var At="__computer-use";function Us(e=x){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function ye(e,o,t,n){return new Promise((s)=>{let i=R(e,o,{env:t,stdio:"ignore",windowsHide:!0}),u=setTimeout(()=>{i.kill("SIGKILL"),s(-1)},n);i.once("error",()=>{clearTimeout(u),s(-1)}),i.once("exit",(c)=>{clearTimeout(u),s(c??-1)})})}function Et(e,o,t,n){return new Promise((s)=>{let i=R(e,o,{env:t,stdio:["ignore","pipe","ignore"],windowsHide:!0}),u="";i.stdout.setEncoding("utf8").on("data",(d)=>{u+=d});let c=setTimeout(()=>{i.kill("SIGKILL"),s(null)},n);i.once("error",()=>{clearTimeout(c),s(null)}),i.once("close",(d)=>{clearTimeout(c),s(d===0?u:null)})})}function Ct(e){return v(e)?f(L(),"open-browser-use"):"/tmp/open-browser-use"}function v(e){return e.platform==="win32-x64"||e.platform==="win32-arm64"}var Tt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Nt=33554432;function Dt(e,o){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let n=P(t)&&P(t.result)?t.result.metadata:null;if(!P(n)||n.extensionId!==o)return null;return typeof n.extensionInstanceId==="string"&&Tt.test(n.extensionInstanceId)?n.extensionInstanceId:null}async function be(e,o,t){let n=t.storages.map((c)=>{try{return U(c).filter((d)=>d.endsWith(".log")||d.endsWith(".ldb")).map((d)=>f(c,d))}catch{return[]}}),s;try{s=n.some((c)=>c.length>0)?U(t.socketDir).filter((c)=>c.endsWith(".sock")):[]}catch{return[]}let i=[];for(let c of s){let d=f(t.socketDir,c),m=Dt(await Et(e,["info","--socket",d,"--timeout","2s"],o,5000),t.extensionId);if(m)i.push({instance:m,socket:d})}let u=[];for(let[c,d]of(i.length>0?n:[]).entries())for(let m of d)try{if(mt(m).size>Nt)continue;let l=X(m),p=i.find((g)=>l.includes(g.instance));if(p){u.push({storage:t.storages[c],...p});break}}catch{}return u}async function Mt(e,o,t){return(await be(e,o,t))[0]?.instance??null}function Se(e,o,t){return Mt(e.nativeHost,o,{socketDir:Ct(e),extensionId:F,storages:[f(t,"browser-profile","Default","Local Extension Settings",F)]})}var de=/^(Default|Profile ([0-9]+))$/;async function Ut(e,o,t=a(),n=Ht){let s=f(t,"Library","Application Support","Google","Chrome"),i=[];try{i=U(s)}catch(l){if(l.code==="EPERM")throw new r("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let u=(l)=>Number(de.exec(l)?.[2]??-1),c=i.filter((l)=>de.test(l)&&M(f(s,l,"Extensions",We))).sort((l,p)=>u(l)-u(p)),d=(l)=>f(s,l,"Local Extension Settings",We);return(await be(e,o,{socketDir:n,extensionId:We,storages:c.map(d)})).map(({storage:l,instance:p,socket:g})=>({profile:c.find((w)=>d(w)===l),instance:p,socket:g}))}async function Lt(e,o,t=a(),n=Ht){let s=(await Ut(e,o,t,n))[0]?.instance;if(!s)throw new r("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return s}function pe(e){return new Promise((o)=>{let t=ht({path:e}),n=(s)=>{t.destroy(),o(s)};t.setTimeout(1000,()=>n(!1)),t.once("error",()=>n(!1)),t.once("connect",()=>n(!0))})}async function ke(e,o){let t=Date.now()+o;while(Date.now()<t){if(await e())return!0;await new Promise((n)=>setTimeout(n,200))}return!1}var q=new Map;function H(e,o){let t=q.get(e);if(!t)t=o().finally(()=>q.delete(e)),q.set(e,t);return t}async function $t(e,o){if(await pe(e))return;if(dt(e,{force:!0}),await ye("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],o,1e4)!==0||!await ke(()=>pe(e),5000))throw new r("automation_unavailable","Reason could not start the desktop session bus.")}async function me(e,o,t){let n=e.platform==="darwin-arm64"||v(e)?async()=>await Se(e,o,t)!==null:async()=>await ye(e.nativeHost,["info"],o,5000)===0;if(await n())return;let s=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],i,u=null,c=0;if(e.platform==="darwin-arm64"){let l=f(t,"browser-profile");G(l);let p=f(l,"NativeMessagingHosts");ce(p,{recursive:!0,mode:448});let g=Tr(e.platform).nativeHostManifests[0];ae(g,f(p,le(g)));let w=e.browser.slice(0,e.browser.indexOf(".app/")+4),h=s.filter((I)=>I!=="about:blank").concat("--no-startup-window","--use-mock-keychain");i=R("/usr/bin/open",["-g","-n","-a",w,"--args",`--user-data-dir=${l}`,...h],{env:o,stdio:"ignore"})}else if(v(e)){let l=f(t,"browser-profile");G(l),st(C("icacls"),[B(e.browser),"/grant","*S-1-15-2-1:(OI)(CI)(RX)","*S-1-15-2-2:(OI)(CI)(RX)"],{stdio:"ignore",windowsHide:!0,timeout:60000});let p=s.filter((g)=>g!=="about:blank").concat("--no-startup-window","--keep-alive-for-test");i=R(e.browser,[`--user-data-dir=${l}`,...p],{detached:!0,stdio:"ignore",env:o})}else{let l=f(o.HOME,".config","google-chrome"),p=f(l,"NativeMessagingHosts");ce(p,{recursive:!0,mode:448});let g=Tr(e.platform).nativeHostManifests[0];ae(g,f(p,le(g)));let w=process.geteuid?.()===0?["--no-sandbox"]:[];u=f(t,"browser.log");let h=lt(u,"a",384);c=ct(h).size,i=R(e.browser,[`--user-data-dir=${l}`,...s,...w,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",h,h],env:{...o,ACCESSIBILITY_ENABLED:"1"}}),at(h)}let d=!1;i.once("error",()=>{d=!0}),i.once("exit",(l)=>{d||=l!==0}),i.unref();let m=!1;if(await ke(async()=>d||(m=await n()),It),!m){if(u&&X(u).subarray(c).toString("utf8").includes("No usable sandbox"))throw new r("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function zs(e){await ve(e,!0)}function qs(e){return Re(e,Ie(e))}function Re(e,o){return e.platform==="darwin-arm64"||v(e)?f(o,"browser-profile"):f(o,"home",".config","google-chrome")}function Ie(e){let o=f(e.root,"automation");if(!M(o)||!Wt(e.automation))return e.automation;if(!qt(Re(e,o)))try{he(o,e.automation)}catch{}return M(o)?o:e.automation}function Wt(e){try{return U(e).length===0}catch(o){return o.code==="ENOENT"}}function qt(e){let o;try{o=ut(f(e,"SingletonLock"))}catch{return!1}let t=Number(o.slice(o.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function ve(e,o){Pt({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=Ie(e);G(t);let n=we().username,s={USER:n,LOGNAME:n,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"||v(e)){let l=v(e)?{...s,...Ft(),HOME:a()}:{...s,HOME:a(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:At};if(!o)return l;await H("browser",()=>me(e,l,t));let p=await Se(e,l,t);if(!p)throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...l,REASON_AUTOMATION_OBU_INSTANCE:p,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let i=await qe(),u=f(t,"home"),c=f(t,"runtime");G(u),G(c);let d=f(t,"bus"),m={...s,HOME:u,PATH:`${B(e.node)}:/usr/bin:/bin`,DISPLAY:i.display,XAUTHORITY:i.xauthority,XDG_RUNTIME_DIR:c,DBUS_SESSION_BUS_ADDRESS:`unix:path=${d}`,...i.sound?{PULSE_SERVER:Ve(i.sound)}:{}};if(await H("bus",()=>$t(d,m)),o)await H("browser",()=>me(e,m,t));return m}function Ft(){let e=process.env.SystemRoot??"C:\\Windows",o=Object.fromEntries(["SystemDrive","USERPROFILE","LOCALAPPDATA","APPDATA","ProgramData","ProgramFiles","PATHEXT","ComSpec","USERNAME","USERDOMAIN","COMPUTERNAME","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","PSModuleAnalysisCachePath"].flatMap((n)=>process.env[n]?[[n,process.env[n]]]:[])),t=f(e,"System32");return{...o,SystemRoot:e,windir:e,TEMP:L(),TMP:L(),PATH:[t,f(t,"WindowsPowerShell","v1.0"),e].join(wt)}}async function Gt(e,o,t){let n=we().username,s={USER:n,LOGNAME:n,HOME:a(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:o,REASON_AUTOMATION_BACKGROUND_TABS:"1"},i=await Lt(o,s);return t.throwIfAborted(),{...s,REASON_AUTOMATION_OBU_INSTANCE:i}}function jt(e){if(process.platform!=="win32")return["--input-type=module","--eval",e];let o=f(L(),`reason-automation-${it("sha256").update(e).digest("hex").slice(0,16)}.mjs`);if(!M(o)||X(o,"utf8")!==e){let t=`${o}.${process.pid}.tmp`;ft(t,e,{mode:384}),he(t,o)}return[o]}function Oe(e,o,t,n){if(typeof ue!=="string")return Promise.reject(new r("automation_unavailable","This Reason build has no automation runtime."));let s=ue;return new Promise((i,u)=>{let c=R(e,jt(s),{env:{...o,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32",windowsHide:!0}),d=[],m=0,l="",p=null,g=!1,w=(_)=>{if(p??=_,process.platform==="win32"&&c.pid){R(f(process.env.SystemRoot??"C:\\Windows","System32","taskkill.exe"),["/pid",String(c.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0}).once("error",()=>c.kill("SIGKILL"));return}try{process.kill(-c.pid,"SIGKILL")}catch{c.kill("SIGKILL")}},h=(_)=>{if(g)return;g=!0,clearTimeout(I),n.removeEventListener("abort",S),_()},I=setTimeout(()=>w(new r("automation_timed_out","Reason automation did not finish in time.")),xt),S=()=>w(new r("cancelled","Reason cancelled the automation call."));if(n.addEventListener("abort",S,{once:!0}),c.stdout.on("data",(_)=>{if(m+=_.byteLength,m>_t)w(new r("automation_output_too_large","Reason automation output is too large."));else d.push(_)}),c.stderr.setEncoding("utf8").on("data",(_)=>{l=(l+_).slice(-yt)}),c.stdin.on("error",()=>{}),c.once("error",()=>h(()=>u(p??new r("automation_unavailable","Reason could not start the automation runtime.")))),c.once("close",(_)=>h(()=>{if(p)u(p);else i({code:_??1,stdout:Buffer.concat(d),stderr:l})})),n.aborted)S();c.stdin.end(t)})}var k=new Map;function Xt(e,o,t){for(let[s,i]of k)if(i.expiresAt<=t)k.delete(s);while(k.size>=Rt)k.delete(k.keys().next().value);let n=ge();return k.set(n,{runId:e,bytes:o,expiresAt:t+kt}),n}async function Ae(e,o,t,n={}){let s=await(n.environment??ve)(e,o.kind==="browser");return t.throwIfAborted(),await(n.runtime??Oe)(e.node,s,JSON.stringify(o),t)}async function Ws(e,o){let t=_e({call:e});if(!("call"in t))D();let n=x();if(!n?.features.computer||t.call.kind==="browser"&&!n.features.browser)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await Ae(n,t.call,o)}function fe(e,o,t){let n=e.stdout.byteLength>j?Xt(o,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:Ot,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,j).toString("base64"),...n?{output_id:n}:{}}}async function Rn(e,o={}){let t=_e(e.payload),n=(o.now??Date.now)();if("output_id"in t){let h=k.get(t.output_id);if(!h||h.runId!==e.runId||h.expiresAt<=n||t.offset>h.bytes.byteLength)throw new r("automation_output_unavailable","Reason automation output expired.");return{chunk:h.bytes.subarray(t.offset,t.offset+j).toString("base64")}}let s=(o.components??x)(),i=(o.platform??process.platform)==="darwin",u=i?(o.macIdentity??gt)():[],c=o.macSetup??N,d=!s?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!s.features.browser;if(i&&(d||u.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return fe(await se({runId:e.runId,call:t.call,identity:u,desktopMissing:d,signal:e.signal},c),e.runId,n);if(!s?.features.computer)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let m=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!m)throw new r("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!m&&!s.features.browser)throw new r("automation_browser_not_installed",!s.platform.startsWith("linux")?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let l=t.call.kind==="browser"&&t.call.operation!=="record_start"&&t.call.operation!=="record_stop",p=await Hi(e.runId,e.signal,o.now,l?"call":"run"),g="account"in o?o.account??null:K(),w;try{if(m){let h=await(o.userChromeEnvironment??Gt)(s,m,e.signal);e.signal.throwIfAborted(),w=await(o.runtime??Oe)(s.node,h,JSON.stringify(t.call),e.signal)}else if(g)w=await(o.delegate??Q)(g,t.call,e.signal);else w=await Ae(s,t.call,e.signal,o)}finally{p()}if(i)w=await ie({runId:e.runId,call:t.call,identity:u,output:w,signal:e.signal},c);return fe(w,e.runId,n)}
859
+ `);if(O)return u(O);u(new r("desktop_delegate_failed",`Reason's desktop operation failed (${J}${Y?`: ${Y}`:""}).`))})),t.aborted)S();c.stdin.end(JSON.stringify(o))})}async function Q(e,o,t,n={}){let s=await Bt(e,{op:"automation",call:o},t,n);if(!Number.isSafeInteger(s.code)||typeof s.stdout!=="string"||typeof s.stderr!=="string")throw new r("desktop_delegate_failed","Reason's desktop reply is malformed.");return{code:s.code,stdout:Buffer.from(s.stdout,"base64"),stderr:s.stderr}}import{execFile as He,spawn as je}from"child_process";import{closeSync as Xe,mkdirSync as Ke,openSync as Je}from"fs";import{dirname as E,join as Ye}from"path";import{promisify as ze}from"util";var Ze=ze(He),ee="x-apple.systempreferences:com.apple.preference.security",Qe={accessibility:`${ee}?Privacy_Accessibility`,screen:`${ee}?Privacy_ScreenCapture`},et=64,A=new Map;function T(e,o){let t=A.get(e);if(t?.has(o))return!1;if(!t){if(A.size>=et)A.delete(A.keys().next().value);t=new Set,A.set(e,t)}return t.add(o),!0}function tt(){let e=a(),o=Jn(xe(e),process.env),t=Ye(e,".local","share","reason","desktop-install.log");Ke(E(t),{recursive:!0,mode:448});let n=Je(t,"a",384);try{let s=je(o,["desktop","install"],{detached:!0,stdio:["ignore",n,n],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});s.on("error",()=>{return}),s.unref()}finally{Xe(n)}}var N={open:async(e,o)=>{await Ze("/usr/bin/open",e,{signal:o,timeout:1e4,maxBuffer:8192})},request:(e,o)=>pt(e,o),tile:Ir,installDesktop:tt},te=!1;async function oe(e,o,t){try{await o.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await o.open([e],t)}}async function ne(e,o,t,n){if(await t.open([Qe[o]],n).catch(()=>{}),e[0]&&!n.aborted)t.tile(E(E(E(e[0]))),o)}async function ot(e,o,t,n,s){for(let i of t){if(!T(e,`grant:${i}`))continue;s.throwIfAborted(),await n.request(o,i).catch(()=>null),await ne(o,i,n,s)}}var rt={name:"open_tab",description:"Open a web page in the user's own Chrome on this Mac. Reason cannot read, screenshot or click in that tab, and no tab_id is returned: browser control needs Reason's Chrome extension. An actual browser call opens its setup page.",inputSchema:{type:"object",properties:{url:{type:"string",description:"An http or https URL."}},required:["url"],additionalProperties:!1}};function re(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function nt(e){if(typeof e!=="string")return null;try{let o=new URL(e);return o.protocol==="https:"||o.protocol==="http:"?o.href:null}catch{return null}}async function se(e,o=N){let{call:t,runId:n,signal:s}=e;if(t.kind==="browser"){if(t.operation==="discover")return re({result:{tools:[rt]}});if(t.operation!=="call")throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet. Request a browser operation or connect Chrome from Reason to set it up.")}if(e.desktopMissing&&!te){te=!0;try{o.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&T(n,"grant:probe")){let c=await o.request(e.identity).catch(()=>null),d=c?[...c.accessibility?[]:["accessibility"],...c.screen?[]:["screen"]]:[];for(let m of d)T(n,`grant:${m}`);for(let m of d)await ne(e.identity,m,o,s)}throw new r("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(T(n,"page:chrome-extension"))await oe(go,o,s).catch(()=>{});let i=t.arguments,u=t.operation==="call"&&t.tool==="open_tab"&&i&&typeof i==="object"&&!Array.isArray(i)?nt(i.url):null;if(!u)throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet; Reason opened its Chrome Web Store page. open_tab still opens pages.");return await oe(u,o,s),re({result:{content:[{type:"text",text:JSON.stringify({opened:u,browser:"the user's Chrome",controllable:!1,note:"Opened for the user to see. Reason cannot read or act in this tab until Reason's Chrome extension is added (its Chrome Web Store page is open)."})}]}})}async function ie(e,o=N){if(e.call.kind!=="computer"||e.call.operation!=="permission_status"||e.output.code!==0||e.identity.length===0)return e.output;let t;try{t=JSON.parse(e.output.stdout.toString("utf8"))}catch{return e.output}if(!t||typeof t!=="object"||Array.isArray(t))return e.output;let n=t.permissions;if(!n||typeof n!=="object")return e.output;let s=n,i=[...s.accessibility==="missing"?["accessibility"]:[],...s.screenRecording==="missing"?["screen"]:[]];if(i.length===0)return e.output;return await ot(e.runId,e.identity,i,o,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:i}))}}var j=172032,_t=18874368,yt=8192,bt=65536,xt=55000,kt=60000,Rt=4,It=40000,vt=/^[0-9a-f-]{36}$/,ue=z,Ot=ge();function P(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function D(){throw new r("invalid_automation_request","Reason automation request is malformed.")}function _e(e){let o=Object.keys(e).sort().join(",");if(o==="call"||o==="browser,call"){let t=e.call,n=o==="browser,call";if(!P(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||n&&(e.browser!==St||t.kind!=="browser")||JSON.stringify(t).length>bt)D();return{call:t,userChrome:n}}if(o==="offset,output_id"){if(typeof e.output_id!=="string"||!vt.test(e.output_id)||!Number.isSafeInteger(e.offset)||e.offset<0)D();return{output_id:e.output_id,offset:e.offset}}return D()}function Pn(e=process.platform,o=x){if(e==="darwin")return!0;return(e==="linux"||e==="win32")&&o()?.features.computer===!0}var At="__computer-use";function Us(e=x){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function ye(e,o,t,n){return new Promise((s)=>{let i=R(e,o,{env:t,stdio:"ignore",windowsHide:!0}),u=setTimeout(()=>{i.kill("SIGKILL"),s(-1)},n);i.once("error",()=>{clearTimeout(u),s(-1)}),i.once("exit",(c)=>{clearTimeout(u),s(c??-1)})})}function Et(e,o,t,n){return new Promise((s)=>{let i=R(e,o,{env:t,stdio:["ignore","pipe","ignore"],windowsHide:!0}),u="";i.stdout.setEncoding("utf8").on("data",(d)=>{u+=d});let c=setTimeout(()=>{i.kill("SIGKILL"),s(null)},n);i.once("error",()=>{clearTimeout(c),s(null)}),i.once("close",(d)=>{clearTimeout(c),s(d===0?u:null)})})}function Ct(e){return v(e)?f(L(),"open-browser-use"):"/tmp/open-browser-use"}function v(e){return e.platform==="win32-x64"||e.platform==="win32-arm64"}var Tt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Nt=33554432;function Dt(e,o){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let n=P(t)&&P(t.result)?t.result.metadata:null;if(!P(n)||n.extensionId!==o)return null;return typeof n.extensionInstanceId==="string"&&Tt.test(n.extensionInstanceId)?n.extensionInstanceId:null}async function be(e,o,t){let n=t.storages.map((c)=>{try{return U(c).filter((d)=>d.endsWith(".log")||d.endsWith(".ldb")).map((d)=>f(c,d))}catch{return[]}}),s;try{s=n.some((c)=>c.length>0)?U(t.socketDir).filter((c)=>c.endsWith(".sock")):[]}catch{return[]}let i=[];for(let c of s){let d=f(t.socketDir,c),m=Dt(await Et(e,["info","--socket",d,"--timeout","2s"],o,5000),t.extensionId);if(m)i.push({instance:m,socket:d})}let u=[];for(let[c,d]of(i.length>0?n:[]).entries())for(let m of d)try{if(mt(m).size>Nt)continue;let l=X(m),p=i.find((g)=>l.includes(g.instance));if(p){u.push({storage:t.storages[c],...p});break}}catch{}return u}async function Mt(e,o,t){return(await be(e,o,t))[0]?.instance??null}function Se(e,o,t){return Mt(e.nativeHost,o,{socketDir:Ct(e),extensionId:F,storages:[f(t,"browser-profile","Default","Local Extension Settings",F)]})}var de=/^(Default|Profile ([0-9]+))$/;async function Ut(e,o,t=a(),n=Ht){let s=f(t,"Library","Application Support","Google","Chrome"),i=[];try{i=U(s)}catch(l){if(l.code==="EPERM")throw new r("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let u=(l)=>Number(de.exec(l)?.[2]??-1),c=i.filter((l)=>de.test(l)&&M(f(s,l,"Extensions",We))).sort((l,p)=>u(l)-u(p)),d=(l)=>f(s,l,"Local Extension Settings",We);return(await be(e,o,{socketDir:n,extensionId:We,storages:c.map(d)})).map(({storage:l,instance:p,socket:g})=>({profile:c.find((w)=>d(w)===l),instance:p,socket:g}))}async function Lt(e,o,t=a(),n=Ht){let s=(await Ut(e,o,t,n))[0]?.instance;if(!s)throw new r("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return s}function pe(e){return new Promise((o)=>{let t=ht({path:e}),n=(s)=>{t.destroy(),o(s)};t.setTimeout(1000,()=>n(!1)),t.once("error",()=>n(!1)),t.once("connect",()=>n(!0))})}async function ke(e,o){let t=Date.now()+o;while(Date.now()<t){if(await e())return!0;await new Promise((n)=>setTimeout(n,200))}return!1}var q=new Map;function H(e,o){let t=q.get(e);if(!t)t=o().finally(()=>q.delete(e)),q.set(e,t);return t}async function $t(e,o){if(await pe(e))return;if(dt(e,{force:!0}),await ye("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],o,1e4)!==0||!await ke(()=>pe(e),5000))throw new r("automation_unavailable","Reason could not start the desktop session bus.")}async function me(e,o,t){let n=e.platform==="darwin-arm64"||v(e)?async()=>await Se(e,o,t)!==null:async()=>await ye(e.nativeHost,["info"],o,5000)===0;if(await n())return;let s=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],i,u=null,c=0;if(e.platform==="darwin-arm64"){let l=f(t,"browser-profile");G(l);let p=f(l,"NativeMessagingHosts");ce(p,{recursive:!0,mode:448});let g=Tr(e.platform).nativeHostManifests[0];ae(g,f(p,le(g)));let w=e.browser.slice(0,e.browser.indexOf(".app/")+4),h=s.filter((I)=>I!=="about:blank").concat("--no-startup-window","--use-mock-keychain");i=R("/usr/bin/open",["-g","-n","-a",w,"--args",`--user-data-dir=${l}`,...h],{env:o,stdio:"ignore"})}else if(v(e)){let l=f(t,"browser-profile");G(l),st(C("icacls"),[B(e.browser),"/grant","*S-1-15-2-1:(OI)(CI)(RX)","*S-1-15-2-2:(OI)(CI)(RX)"],{stdio:"ignore",windowsHide:!0,timeout:60000});let p=s.filter((g)=>g!=="about:blank").concat("--no-startup-window","--keep-alive-for-test");i=R(e.browser,[`--user-data-dir=${l}`,...p],{detached:!0,stdio:"ignore",env:o})}else{let l=f(o.HOME,".config","google-chrome"),p=f(l,"NativeMessagingHosts");ce(p,{recursive:!0,mode:448});let g=Tr(e.platform).nativeHostManifests[0];ae(g,f(p,le(g)));let w=process.geteuid?.()===0?["--no-sandbox"]:[];u=f(t,"browser.log");let h=lt(u,"a",384);c=ct(h).size,i=R(e.browser,[`--user-data-dir=${l}`,...s,...w,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",h,h],env:{...o,ACCESSIBILITY_ENABLED:"1"}}),at(h)}let d=!1;i.once("error",()=>{d=!0}),i.once("exit",(l)=>{d||=l!==0}),i.unref();let m=!1;if(await ke(async()=>d||(m=await n()),It),!m){if(u&&X(u).subarray(c).toString("utf8").includes("No usable sandbox"))throw new r("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function zs(e){await ve(e,!0)}function qs(e){return Re(e,Ie(e))}function Re(e,o){return e.platform==="darwin-arm64"||v(e)?f(o,"browser-profile"):f(o,"home",".config","google-chrome")}function Ie(e){let o=f(e.root,"automation");if(!M(o)||!Wt(e.automation))return e.automation;if(!qt(Re(e,o)))try{he(o,e.automation)}catch{}return M(o)?o:e.automation}function Wt(e){try{return U(e).length===0}catch(o){return o.code==="ENOENT"}}function qt(e){let o;try{o=ut(f(e,"SingletonLock"))}catch{return!1}let t=Number(o.slice(o.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function ve(e,o){Pt({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=Ie(e);G(t);let n=we().username,s={USER:n,LOGNAME:n,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"||v(e)){let l=v(e)?{...s,...Ft(),HOME:a()}:{...s,HOME:a(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:At};if(!o)return l;await H("browser",()=>me(e,l,t));let p=await Se(e,l,t);if(!p)throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...l,REASON_AUTOMATION_OBU_INSTANCE:p,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let i=await qe(),u=f(t,"home"),c=f(t,"runtime");G(u),G(c);let d=f(t,"bus"),m={...s,HOME:u,PATH:`${B(e.node)}:/usr/bin:/bin`,DISPLAY:i.display,XAUTHORITY:i.xauthority,XDG_RUNTIME_DIR:c,DBUS_SESSION_BUS_ADDRESS:`unix:path=${d}`,...i.sound?{PULSE_SERVER:Ve(i.sound)}:{}};if(await H("bus",()=>$t(d,m)),o)await H("browser",()=>me(e,m,t));return m}function Ft(){let e=process.env.SystemRoot??"C:\\Windows",o=Object.fromEntries(["SystemDrive","USERPROFILE","LOCALAPPDATA","APPDATA","ProgramData","ProgramFiles","PATHEXT","ComSpec","USERNAME","USERDOMAIN","COMPUTERNAME","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","PSModuleAnalysisCachePath"].flatMap((n)=>process.env[n]?[[n,process.env[n]]]:[])),t=f(e,"System32");return{...o,SystemRoot:e,windir:e,TEMP:L(),TMP:L(),PATH:[t,f(t,"WindowsPowerShell","v1.0"),e].join(wt)}}async function Gt(e,o,t){let n=we().username,s={USER:n,LOGNAME:n,HOME:a(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:o,REASON_AUTOMATION_BACKGROUND_TABS:"1"},i=await Lt(o,s);return t.throwIfAborted(),{...s,REASON_AUTOMATION_OBU_INSTANCE:i}}function jt(e){if(process.platform!=="win32")return["--input-type=module","--eval",e];let o=f(L(),`reason-automation-${it("sha256").update(e).digest("hex").slice(0,16)}.mjs`);if(!M(o)||X(o,"utf8")!==e){let t=`${o}.${process.pid}.tmp`;ft(t,e,{mode:384}),he(t,o)}return[o]}function Oe(e,o,t,n){if(typeof ue!=="string")return Promise.reject(new r("automation_unavailable","This Reason build has no automation runtime."));let s=ue;return new Promise((i,u)=>{let c=R(e,jt(s),{env:{...o,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32",windowsHide:!0}),d=[],m=0,l="",p=null,g=!1,w=(_)=>{if(p??=_,process.platform==="win32"&&c.pid){R(f(process.env.SystemRoot??"C:\\Windows","System32","taskkill.exe"),["/pid",String(c.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0}).once("error",()=>c.kill("SIGKILL"));return}try{process.kill(-c.pid,"SIGKILL")}catch{c.kill("SIGKILL")}},h=(_)=>{if(g)return;g=!0,clearTimeout(I),n.removeEventListener("abort",S),_()},I=setTimeout(()=>w(new r("automation_timed_out","Reason automation did not finish in time.")),xt),S=()=>w(new r("cancelled","Reason cancelled the automation call."));if(n.addEventListener("abort",S,{once:!0}),c.stdout.on("data",(_)=>{if(m+=_.byteLength,m>_t)w(new r("automation_output_too_large","Reason automation output is too large."));else d.push(_)}),c.stderr.setEncoding("utf8").on("data",(_)=>{l=(l+_).slice(-yt)}),c.stdin.on("error",()=>{}),c.once("error",()=>h(()=>u(p??new r("automation_unavailable","Reason could not start the automation runtime.")))),c.once("close",(_)=>h(()=>{if(p)u(p);else i({code:_??1,stdout:Buffer.concat(d),stderr:l})})),n.aborted)S();c.stdin.end(t)})}var k=new Map;function Xt(e,o,t){for(let[s,i]of k)if(i.expiresAt<=t)k.delete(s);while(k.size>=Rt)k.delete(k.keys().next().value);let n=ge();return k.set(n,{runId:e,bytes:o,expiresAt:t+kt}),n}async function Ae(e,o,t,n={}){let s=await(n.environment??ve)(e,o.kind==="browser");return t.throwIfAborted(),await(n.runtime??Oe)(e.node,s,JSON.stringify(o),t)}async function Ws(e,o){let t=_e({call:e});if(!("call"in t))D();let n=x();if(!n?.features.computer||t.call.kind==="browser"&&!n.features.browser)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await Ae(n,t.call,o)}function fe(e,o,t){let n=e.stdout.byteLength>j?Xt(o,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:Ot,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,j).toString("base64"),...n?{output_id:n}:{}}}async function Rn(e,o={}){let t=_e(e.payload),n=(o.now??Date.now)();if("output_id"in t){let h=k.get(t.output_id);if(!h||h.runId!==e.runId||h.expiresAt<=n||t.offset>h.bytes.byteLength)throw new r("automation_output_unavailable","Reason automation output expired.");return{chunk:h.bytes.subarray(t.offset,t.offset+j).toString("base64")}}let s=(o.components??x)(),i=(o.platform??process.platform)==="darwin",u=i?(o.macIdentity??gt)():[],c=o.macSetup??N,d=!s?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!s.features.browser;if(i&&(d||u.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return fe(await se({runId:e.runId,call:t.call,identity:u,desktopMissing:d,signal:e.signal},c),e.runId,n);if(!s?.features.computer)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let m=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!m)throw new r("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!m&&!s.features.browser)throw new r("automation_browser_not_installed",!s.platform.startsWith("linux")?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let l=t.call.kind==="browser"&&t.call.operation!=="record_start"&&t.call.operation!=="record_stop",p=await Hi(e.runId,e.signal,o.now,l?"call":"run"),g="account"in o?o.account??null:K(),w;try{if(m){let h=await(o.userChromeEnvironment??Gt)(s,m,e.signal);e.signal.throwIfAborted(),w=await(o.runtime??Oe)(s.node,h,JSON.stringify(t.call),e.signal)}else if(g)w=await(o.delegate??Q)(g,t.call,e.signal);else w=await Ae(s,t.call,e.signal,o)}finally{p()}if(i)w=await ie({runId:e.runId,call:t.call,identity:u,output:w,signal:e.signal},c);return fe(w,e.runId,n)}
860
860
  export{Bt,Pn,Us,zs,qs,Ws,Rn};
@@ -1,7 +1,7 @@
1
1
  // @bun
2
- import{Mt}from"./vm-hands-entry-lite-yptpy066.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{fe,se,C}from"./vm-hands-entry-lite-q13ekwev.js";import{spawn as J,spawnSync as ee}from"child_process";import{existsSync as h,mkdtempSync as ne,readFileSync as K,readdirSync as te,realpathSync as re,rmSync as oe,statSync as G}from"fs";import{platform as T,tmpdir as ie}from"os";import{dirname as A,join as c,win32 as w}from"path";import{fileURLToPath as ae,pathToFileURL as W}from"url";var le=["bwrap","socat","rg"],de=2000;var ce=3,L=4000,ue=new Set([".git",".hg",".svn","node_modules"]),me=["runAsHostUid","sysrq-trigger"],X=c(A(A(ae(import.meta.url))),"packages","sandbox-runtime"),pe=c(X,"src","index.ts"),z=!1;function Vi(){z=!0}function j(){return z?c(A(re(process.execPath)),"runtime","srt"):void 0}function y(){let e=c(j()??X,"vendor","srt-win");return c(e,process.arch,"srt-win.exe")}async function Y(){let e=j();if(e&&process.platform==="linux"&&!h(c(e,"vendor","seccomp",process.arch,"apply-seccomp")))throw Error("packaged_sandbox_runtime_vendor_missing");if(e&&process.platform==="win32"&&!h(y()))throw Error("packaged_sandbox_runtime_vendor_missing");if(e){let i=K(c(e,"sandbox-runtime.mjs"),"utf8");for(let s of me)if(!i.includes(s))throw Error(`packaged_sandbox_runtime_fork_missing:${s}`)}let n=(await import(e?W(c(e,"sandbox-runtime.mjs")).href:W(pe).href)).SandboxManager;if(!n||typeof n.initialize!=="function"||typeof n.wrapWithSandboxArgv!=="function")throw Error("sandbox-runtime does not expose the expected SandboxManager API.");return{SandboxManager:n}}function ge(e={}){if((e.platformName??T())!=="linux")return!1;let o=e.fileExists??h,n=e.readFile??((i)=>K(i,"utf8"));for(let i of["/.dockerenv","/run/.containerenv"])try{if(o(i))return!0}catch{}try{return/docker|containerd|kubepods|lxc|libpod/.test(n("/proc/1/cgroup"))}catch{return!1}}function we(e){return["/bin/true","/usr/bin/true"].find((t)=>e(t))??null}function Se(e,t){return e==="strict"?["--ro-bind","/","/","--unshare-pid","--unshare-user","--cap-drop","ALL","--proc","/proc","--",t]:["--ro-bind","/","/","--unshare-pid","--unshare-user","--bind","/proc","/proc","--",t]}function be(e,t){try{let o=ee("bwrap",Se(e,t),{stdio:"ignore",timeout:de});return!o.error&&o.status===0}catch{return!1}}function xe(e){let t=e.platformName??T(),o=e.fileExists??h;if(t==="win32")return(e.bash??fe)()&&o(y())?m??"strict":null;if(t!=="linux")return null;let n=e.hasExecutable??Mt;if(!le.every((l)=>n(l)))return null;let i=we(o);if(!i)return null;let s=m??(e.containerized??ge({platformName:t})?"weak":"strict");return(e.probeNamespaces??((l)=>be(l,i)))(s)?s:null}var S=null,M=!1,p=null,F=null;var m=null,P=null,_=null,E=null,v=[],g=new Map;function D(){throw b("sandbox_mode_conflict"),new r("sandbox_unavailable","Sandbox process policy conflicts with an existing probe or session. Restart the worker.")}function Gi(e){if(m!==null&&m!==e||M&&S!==null&&S!==e||P!==null&&P!==e)D();m=e}function b(e){if(!p)process.stderr.write(`Reason worker: confined commands are off (${e})
2
+ import{Mt}from"./vm-hands-entry-lite-yptpy066.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{fe,se,C}from"./vm-hands-entry-lite-b6gsggvp.js";import{spawn as J,spawnSync as ee}from"child_process";import{existsSync as h,mkdtempSync as ne,readFileSync as K,readdirSync as te,realpathSync as re,rmSync as oe,statSync as G}from"fs";import{platform as T,tmpdir as ie}from"os";import{dirname as A,join as c,win32 as w}from"path";import{fileURLToPath as ae,pathToFileURL as W}from"url";var le=["bwrap","socat","rg"],de=2000;var ce=3,L=4000,ue=new Set([".git",".hg",".svn","node_modules"]),me=["runAsHostUid","sysrq-trigger"],X=c(A(A(ae(import.meta.url))),"packages","sandbox-runtime"),pe=c(X,"src","index.ts"),z=!1;function Gi(){z=!0}function j(){return z?c(A(re(process.execPath)),"runtime","srt"):void 0}function y(){let e=c(j()??X,"vendor","srt-win");return c(e,process.arch,"srt-win.exe")}async function Y(){let e=j();if(e&&process.platform==="linux"&&!h(c(e,"vendor","seccomp",process.arch,"apply-seccomp")))throw Error("packaged_sandbox_runtime_vendor_missing");if(e&&process.platform==="win32"&&!h(y()))throw Error("packaged_sandbox_runtime_vendor_missing");if(e){let i=K(c(e,"sandbox-runtime.mjs"),"utf8");for(let s of me)if(!i.includes(s))throw Error(`packaged_sandbox_runtime_fork_missing:${s}`)}let n=(await import(e?W(c(e,"sandbox-runtime.mjs")).href:W(pe).href)).SandboxManager;if(!n||typeof n.initialize!=="function"||typeof n.wrapWithSandboxArgv!=="function")throw Error("sandbox-runtime does not expose the expected SandboxManager API.");return{SandboxManager:n}}function ge(e={}){if((e.platformName??T())!=="linux")return!1;let o=e.fileExists??h,n=e.readFile??((i)=>K(i,"utf8"));for(let i of["/.dockerenv","/run/.containerenv"])try{if(o(i))return!0}catch{}try{return/docker|containerd|kubepods|lxc|libpod/.test(n("/proc/1/cgroup"))}catch{return!1}}function we(e){return["/bin/true","/usr/bin/true"].find((t)=>e(t))??null}function Se(e,t){return e==="strict"?["--ro-bind","/","/","--unshare-pid","--unshare-user","--cap-drop","ALL","--proc","/proc","--",t]:["--ro-bind","/","/","--unshare-pid","--unshare-user","--bind","/proc","/proc","--",t]}function be(e,t){try{let o=ee("bwrap",Se(e,t),{stdio:"ignore",timeout:de});return!o.error&&o.status===0}catch{return!1}}function xe(e){let t=e.platformName??T(),o=e.fileExists??h;if(t==="win32")return(e.bash??fe)()&&o(y())?m??"strict":null;if(t!=="linux")return null;let n=e.hasExecutable??Mt;if(!le.every((l)=>n(l)))return null;let i=we(o);if(!i)return null;let s=m??(e.containerized??ge({platformName:t})?"weak":"strict");return(e.probeNamespaces??((l)=>be(l,i)))(s)?s:null}var S=null,M=!1,p=null,F=null;var m=null,P=null,_=null,E=null,v=[],g=new Map;function D(){throw b("sandbox_mode_conflict"),new r("sandbox_unavailable","Sandbox process policy conflicts with an existing probe or session. Restart the worker.")}function Ki(e){if(m!==null&&m!==e||M&&S!==null&&S!==e||P!==null&&P!==e)D();m=e}function b(e){if(!p)process.stderr.write(`Reason worker: confined commands are off (${e})
3
3
  `);p=e}function hr(e){if(p)return!1;if(!M){if(S=xe(e??{}),M=!0,S&&!e)Ce()}return S!==null}function he(){return hr()?S:null}var R=null,x=0;function I(e,t){if(p)throw new r("sandbox_unavailable","Confined execution is unavailable in this worker process.");if(m&&e.sandboxMode&&m!==e.sandboxMode)D();let o=m??e.sandboxMode??he();if(!o)throw new r("sandbox_unavailable","Confined command execution is unavailable on this operating system.");if(P&&P!==o)D();return P=o,R??=(async()=>{let{SandboxManager:n}=await(e.loadSandboxRuntime??Y)();return await n.initialize(Ne(o,t)),n})().catch((n)=>{if(R=null,t)_=null,process.stderr.write(`Reason worker: the Windows sandbox did not start for this folder (${String(n).slice(0,500)})
4
4
  `);else b(`initialize_failed: ${String(n)}`);throw n instanceof r?n:new r("sandbox_unavailable","The confined execution sandbox failed to start.")}),R.then((n)=>{if(p)throw new r("sandbox_unavailable","Confined execution became unavailable during sandbox initialization.");return n})}function O(){if(x-=1,x===0)for(let e of v.splice(0))e()}async function ye(e,t=!0,o,n){let i=n===void 0?1/0:Date.now()+n;await Q();let s=_e();if(t)await s;let a=JSON.stringify(e),l=!1,u=()=>{if(!l)return;l=!1;let d=(g.get(a)??1)-1;if(d>0)g.set(a,d);else g.delete(a)};try{for(;;){if(o?.aborted)throw new r("cancelled","Operation was cancelled.");if(Date.now()>=i)return!1;if(E){await E;continue}let d=g.keys().next().value;if(_??=d??a,_===a&&(d===void 0||d===a))break;if(!l){l=!0,g.set(a,(g.get(a)??0)+1);continue}if(x===0&&d===a){Pe();continue}await new Promise((f)=>{if(v.push(f),o?.addEventListener("abort",()=>f(),{once:!0}),i!==1/0)setTimeout(f,Math.max(0,i-Date.now())).unref?.()})}return x+=1,!0}finally{if(l&&x===0)for(let d of v.splice(0))d();u()}}function Pe(){return E??=Me().finally(()=>{E=null}),E}function Ee(e,t,o=process.env){let n=o.USERPROFILE?w.resolve(o.USERPROFILE).toLowerCase():null,i=w.resolve(e).toLowerCase(),s=n!==null&&i.startsWith(`${n}\\`),a=t?q(o).filter((l)=>l.toLowerCase()===i||l.toLowerCase().startsWith(`${i}\\`)):[];return{denyRead:[],allowRead:[e],allowWrite:t?[e]:[],denyWrite:t?a:s?[]:[e]}}function q(e,t=process.execPath){let o=new Map;for(let n of[...(e.PATH??e.Path??"").split(";"),w.dirname(t)]){if(!n||!w.isAbsolute(n))continue;let i=w.resolve(n);if(!o.has(i.toLowerCase()))o.set(i.toLowerCase(),i)}return[...o.values()]}function Re(e=process.env,t=process.execPath){let o=[e.SystemRoot,e.ProgramFiles,e["ProgramFiles(x86)"],e.ProgramW6432,e.ProgramData,e.USERPROFILE].filter((n)=>!!n).map((n)=>w.resolve(n).toLowerCase());return q(e,t).filter((n)=>{let i=n.toLowerCase();return!o.some((s)=>i===s||i.startsWith(`${s}\\`))})}var U=null,H=null;function Q(e=y()){return H??=(async()=>{let t;try{t=JSON.parse((await V(e,["status"])).stdout).user?.user?.sid}catch{return null}if(typeof t!=="string"||!/^S-1-[0-9-]+$/.test(t))return null;if(!await new Promise((n)=>{let i=J(C("icacls"),[e,"/grant",`*${t}:(RX)`],{stdio:"ignore",windowsHide:!0,timeout:30000});i.on("error",()=>n(!1)),i.on("close",(s)=>n(s===0))}))process.stderr.write(`Reason worker: could not let the Windows sandbox user run srt-win.exe
5
5
  `);return t})(),H}function V(e,t,o){return new Promise((n)=>{let i=J(e,t,{stdio:["pipe","pipe","ignore"],windowsHide:!0,timeout:120000}),s="";i.stdout?.setEncoding("utf8").on("data",(a)=>{s+=a}),i.on("error",()=>n({status:null,stdout:s})),i.on("close",(a)=>n({status:a,stdout:s})),i.stdin?.end(o??"")})}function _e(e=y()){return U??=(async()=>{let t=Re();if(t.length===0)return;let o=await Q(e),n=o?await V(e,["acl","stamp","--holder-pid",String(process.ppid),"--sandbox-user-sid",o],JSON.stringify({denyRead:[],denyWrite:t})):null;if(!n||n.status!==0&&n.status!==2)b(`program_folder_deny_failed: ${n?`exit ${n.status}`:"no sandbox user"}`),process.stderr.write(`Reason worker: could not deny the Windows sandbox writes to PATH folders (${n?`exit ${n.status}`:"no sandbox user"}); confined commands are off
6
- `)})(),U}var Ae=`h=$(mktemp -d) || exit 125; trap 'rm -rf "$h"' EXIT; mkdir -p "$h/AppData/Roaming" "$h/AppData/Local"; w=$(cygpath -w "$h"); export HOME="$h" USERPROFILE="$w" APPDATA="$w\\AppData\\Roaming" LOCALAPPDATA="$w\\AppData\\Local" TEMP="$w" TMP="$w"; `;async function Me(){let e=R;if(R=null,_=null,!e)return;try{await(await e).reset()}catch{}}async function Ce(e={}){if(p)return!1;if(e.loadSandboxRuntime)return B(e.loadSandboxRuntime);if(!hr())return!1;return F??=B(Y),F}async function B(e){try{let{SandboxManager:t}=await e();if(process.platform==="win32"){if(!h(y()))b("dependencies_missing: srt-win.exe");return!p}let o=t.checkDependencies().errors;if(o.length>0)return b(`dependencies_missing: ${o.join(", ")}`),!1;return!p}catch(t){return b(`load_failed: ${String(t)}`),!1}}function gn(e=h,t=T()){if(t==="win32")return se("win32");return["/bin/bash","/bin/sh"].find((o)=>e(o))??"/bin/sh"}function ve(e){return e.map((t)=>`'${t.replaceAll("'","'\\''")}'`).join(" ")}function De(e,t,o=(n)=>te(n,{withFileTypes:!0}).filter((i)=>i.isDirectory()||i.isFile()).map((i)=>i.name)){let n=[],i=[{path:e,depth:0}],s=0;while(i.length>0&&s<L){let a=i.pop(),l;try{l=o(a.path)}catch{continue}for(let u of l){if(s+=1,s>L)break;let d=c(a.path,u);if(t(d)){n.push(d);continue}if(a.depth+1<ce&&!ue.has(u))i.push({path:d,depth:a.depth+1})}}return n}function Te(e){let t=c(e.root,".git"),o=[];try{if(G(t).isDirectory())o=[c(t,"config"),c(t,"hooks")]}catch{}return{denyRead:["/home","/root","/tmp","/tmp/.X11-unix",...e.protectedPaths],allowRead:[e.root,e.temporaryDirectory],allowWrite:[...e.allowWrite?[e.root]:[],e.temporaryDirectory],denyWrite:[...e.protectedPaths,...o]}}function ke(e,t){let o=c(t,".git"),n=[];try{if(G(o).isDirectory())n=[c(o,"config"),c(o,"hooks")]}catch{}return{denyRead:[...e],allowRead:[],allowWrite:[],denyWrite:[...e,...n]}}function Ne(e,t){if(t)return{network:{allowedDomains:[],deniedDomains:[]},filesystem:t,windows:{srtWin:{path:y()}}};return{network:{allowedDomains:[],deniedDomains:[]},filesystem:{denyRead:[],allowRead:[],allowWrite:[],denyWrite:[]},...e==="weak"?{enableWeakerNestedSandbox:!0}:{}}}function Ki(e){let t=e.createTemporaryDirectory??(()=>ne(c(ie(),"reason-device-"))),o=e.removeTemporaryDirectory??((n)=>oe(n,{recursive:!0,force:!0}));return async(n,i,s)=>{let a=process.platform==="win32",l;if(a){let d=Ee(s.root,s.allowWrite);if(!await ye(d,!s.workerProbe,s.signal,s.timeoutMs))return{exitCode:null,signal:null,stdout:"",stderr:"",timedOut:!0,truncated:!1};try{l=await I(e,d)}catch(f){throw O(),f}}else l=await I(e),x+=1;let u;try{u=t();let d=De(s.root,e.isProtectedPath),f;try{f=await l.wrapWithSandboxArgv((a?Ae:"")+ve([n,...i]),e.shell??gn(),{filesystem:a?ke(d,s.root):Te({root:s.root,allowWrite:s.allowWrite,temporaryDirectory:u,protectedPaths:d})},s.signal,s.cwd)}catch(N){throw N instanceof r?N:new r("sandbox_unavailable","The confined execution sandbox could not wrap the command.")}let[k,...Z]=f.argv;if(!k)throw new r("sandbox_unavailable","The confined execution sandbox produced no command.");return await e.spawnCaptured(k,Z,{cwd:s.cwd,timeoutMs:s.timeoutMs,signal:s.signal,env:a?f.env:e.scrubEnvironment(s.root,u)})}finally{O();try{l.cleanupAfterCommand()}catch{}if(u!==void 0)o(u)}}}
7
- export{Vi,Gi,hr,gn,Ki};
6
+ `)})(),U}var Ae=`h=$(mktemp -d) || exit 125; trap 'rm -rf "$h"' EXIT; mkdir -p "$h/AppData/Roaming" "$h/AppData/Local"; w=$(cygpath -w "$h"); export HOME="$h" USERPROFILE="$w" APPDATA="$w\\AppData\\Roaming" LOCALAPPDATA="$w\\AppData\\Local" TEMP="$w" TMP="$w"; `;async function Me(){let e=R;if(R=null,_=null,!e)return;try{await(await e).reset()}catch{}}async function Ce(e={}){if(p)return!1;if(e.loadSandboxRuntime)return B(e.loadSandboxRuntime);if(!hr())return!1;return F??=B(Y),F}async function B(e){try{let{SandboxManager:t}=await e();if(process.platform==="win32"){if(!h(y()))b("dependencies_missing: srt-win.exe");return!p}let o=t.checkDependencies().errors;if(o.length>0)return b(`dependencies_missing: ${o.join(", ")}`),!1;return!p}catch(t){return b(`load_failed: ${String(t)}`),!1}}function gn(e=h,t=T()){if(t==="win32")return se("win32");return["/bin/bash","/bin/sh"].find((o)=>e(o))??"/bin/sh"}function ve(e){return e.map((t)=>`'${t.replaceAll("'","'\\''")}'`).join(" ")}function De(e,t,o=(n)=>te(n,{withFileTypes:!0}).filter((i)=>i.isDirectory()||i.isFile()).map((i)=>i.name)){let n=[],i=[{path:e,depth:0}],s=0;while(i.length>0&&s<L){let a=i.pop(),l;try{l=o(a.path)}catch{continue}for(let u of l){if(s+=1,s>L)break;let d=c(a.path,u);if(t(d)){n.push(d);continue}if(a.depth+1<ce&&!ue.has(u))i.push({path:d,depth:a.depth+1})}}return n}function Te(e){let t=c(e.root,".git"),o=[];try{if(G(t).isDirectory())o=[c(t,"config"),c(t,"hooks")]}catch{}return{denyRead:["/home","/root","/tmp","/tmp/.X11-unix",...e.protectedPaths],allowRead:[e.root,e.temporaryDirectory],allowWrite:[...e.allowWrite?[e.root]:[],e.temporaryDirectory],denyWrite:[...e.protectedPaths,...o]}}function ke(e,t){let o=c(t,".git"),n=[];try{if(G(o).isDirectory())n=[c(o,"config"),c(o,"hooks")]}catch{}return{denyRead:[...e],allowRead:[],allowWrite:[],denyWrite:[...e,...n]}}function Ne(e,t){if(t)return{network:{allowedDomains:[],deniedDomains:[]},filesystem:t,windows:{srtWin:{path:y()}}};return{network:{allowedDomains:[],deniedDomains:[]},filesystem:{denyRead:[],allowRead:[],allowWrite:[],denyWrite:[]},...e==="weak"?{enableWeakerNestedSandbox:!0}:{}}}function Ji(e){let t=e.createTemporaryDirectory??(()=>ne(c(ie(),"reason-device-"))),o=e.removeTemporaryDirectory??((n)=>oe(n,{recursive:!0,force:!0}));return async(n,i,s)=>{let a=process.platform==="win32",l;if(a){let d=Ee(s.root,s.allowWrite);if(!await ye(d,!s.workerProbe,s.signal,s.timeoutMs))return{exitCode:null,signal:null,stdout:"",stderr:"",timedOut:!0,truncated:!1};try{l=await I(e,d)}catch(f){throw O(),f}}else l=await I(e),x+=1;let u;try{u=t();let d=De(s.root,e.isProtectedPath),f;try{f=await l.wrapWithSandboxArgv((a?Ae:"")+ve([n,...i]),e.shell??gn(),{filesystem:a?ke(d,s.root):Te({root:s.root,allowWrite:s.allowWrite,temporaryDirectory:u,protectedPaths:d})},s.signal,s.cwd)}catch(N){throw N instanceof r?N:new r("sandbox_unavailable","The confined execution sandbox could not wrap the command.")}let[k,...Z]=f.argv;if(!k)throw new r("sandbox_unavailable","The confined execution sandbox produced no command.");return await e.spawnCaptured(k,Z,{cwd:s.cwd,timeoutMs:s.timeoutMs,signal:s.signal,env:a?f.env:e.scrubEnvironment(s.root,u)})}finally{O();try{l.cleanupAfterCommand()}catch{}if(u!==void 0)o(u)}}}
7
+ export{Gi,Ki,hr,gn,Ji};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- var tr={name:"github-native-engineer-device-worker-production",version:"0.2.527",private:!0,type:"module",engines:{node:">=22",bun:">=1.3.0"},workspaces:["../../packages/runtime-distribution"],dependencies:{"@agentclientprotocol/sdk":"1.9.0","@anthropic-ai/sandbox-runtime":"^0.0.80","@earendil-works/pi-tui":"1.0.0","@reason/runtime-distribution":"workspace:*",diff:"8.0.4","open-browser-use-sdk":"0.1.42","playwright-core":"1.60.0",toml:"4.2.0",zod:"^4.4.3"},overrides:{"@hono/node-server":"^1.19.15","@earendil-works/pi-agent-core":"1.0.0","@earendil-works/pi-ai":"1.0.0","@earendil-works/pi-coding-agent":"1.0.0","@earendil-works/chord":"1.0.0","@earendil-works/pi-codemode":"1.0.0","@earendil-works/pi-mcp":"1.0.0","@earendil-works/pi-telemetry":"1.0.0","@earendil-works/pi-tui":"1.0.0","brace-expansion":"2.1.7",axios:"^1.20.0","basic-ftp":"^6.2.1","@grpc/grpc-js":"^1.14.5",browserslist:"^4.28.8","engine.io":"^6.6.7","fast-uri":"^3.1.8",hono:"^4.13.7","ip-address":"^10.7.1",nanoid:"^3.3.18",dompurify:"^3.4.17",postcss:"^8.5.23",qs:"^6.16.0","shell-quote":"^1.11.0","socket.io-parser":"^4.2.7",tmp:"^0.2.7",toml:"^4.2.0",undici:"^8.10.2",ws:"^8.21.0","js-yaml":"^4.3.2","@modelcontextprotocol/sdk":"^1.31.0","proxy-addr":"^2.0.8","source-map-js":"^1.2.2"}};
2
+ var tr={name:"github-native-engineer-device-worker-production",version:"0.2.529",private:!0,type:"module",engines:{node:">=22",bun:">=1.3.0"},workspaces:["../../packages/runtime-distribution"],dependencies:{"@agentclientprotocol/sdk":"1.9.0","@anthropic-ai/sandbox-runtime":"^0.0.80","@earendil-works/pi-tui":"1.0.0","@reason/runtime-distribution":"workspace:*",diff:"8.0.4","open-browser-use-sdk":"0.1.42","playwright-core":"1.60.0",toml:"4.2.0",zod:"^4.4.3"},overrides:{"@hono/node-server":"^1.19.15","@earendil-works/pi-agent-core":"1.0.0","@earendil-works/pi-ai":"1.0.0","@earendil-works/pi-coding-agent":"1.0.0","@earendil-works/chord":"1.0.0","@earendil-works/pi-codemode":"1.0.0","@earendil-works/pi-mcp":"1.0.0","@earendil-works/pi-telemetry":"1.0.0","@earendil-works/pi-tui":"1.0.0","brace-expansion":"2.1.7",axios:"^1.20.0","basic-ftp":"^6.2.1","@grpc/grpc-js":"^1.14.5",browserslist:"^4.28.8","engine.io":"^6.6.7","fast-uri":"^3.1.8",hono:"^4.13.7","ip-address":"^10.7.1",nanoid:"^3.3.18",dompurify:"^3.4.17",postcss:"^8.5.23",qs:"^6.16.0","shell-quote":"^1.11.0","socket.io-parser":"^4.2.7",tmp:"^0.2.7",toml:"^4.2.0",undici:"^8.10.2",ws:"^8.21.0","js-yaml":"^4.3.2","@modelcontextprotocol/sdk":"^1.31.0","proxy-addr":"^2.0.8","source-map-js":"^1.2.2"}};
3
3
  export{tr};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{lr}from"./vm-hands-entry-lite-s85p7tqp.js";import{Me}from"./vm-hands-entry-lite-3gbf905c.js";import{execFileSync as p}from"child_process";import{realpathSync as S,statSync as w}from"fs";import{tmpdir as P}from"os";import{createRequire as b}from"module";import{win32 as r}from"path";var h=["/bin/bash","/usr/bin/bash"],g="Git Bash was not found. Install Git for Windows (https://git-scm.com/download/win), then run `reason connect`.";function c(o){try{return w(o).isFile()}catch{return!1}}var i=(o)=>[r.join(o,"bin","bash.exe"),r.join(o,"usr","bin","bash.exe")];function x(o,e){let t=r.normalize(o).toLowerCase(),s=(e.SystemRoot??e.SYSTEMROOT??"C:\\Windows").toLowerCase();return t.startsWith(r.join(s,"system32").toLowerCase()+"\\")||t.startsWith(r.join(s,"sysnative").toLowerCase()+"\\")||t.includes("\\windowsapps\\")}function f(o=process.env,e=c){let t=[];for(let s of(o.PATH??o.Path??"").split(";"))if(s&&r.isAbsolute(s))t.push(r.join(s,"git.exe"));for(let s of[o.ProgramW6432,o.ProgramFiles,o["ProgramFiles(x86)"]])if(s)t.push(r.join(s,"Git","cmd","git.exe"));if(o.LOCALAPPDATA)t.push(r.join(o.LOCALAPPDATA,"Programs","Git","cmd","git.exe"));return t.find(e)??null}var a;function Zo(o=process.platform){if(o!=="win32")return"git";return a??=f(),a}function J(o){let e=process.platform==="win32"?f(o):"git";if(!e)return null;try{return p(e,["--exec-path"],{encoding:"utf8",timeout:5000,windowsHide:!0,stdio:["ignore","pipe","ignore"],env:o}).trim()||null}catch{return null}}function y(o=process.env,e=J,t=c){let s=[],l=e(o);if(l)s.push(...i(r.resolve(l,"..","..","..")));for(let n of[o.ProgramW6432,o.ProgramFiles,o["ProgramFiles(x86)"]])if(n)s.push(...i(r.join(n,"Git")));if(o.LOCALAPPDATA)s.push(...i(r.join(o.LOCALAPPDATA,"Programs","Git")));for(let n of(o.PATH??o.Path??"").split(";"))if(n&&r.isAbsolute(n))s.push(r.join(n,"bash.exe"));return s.find((n)=>!x(n,o)&&t(n))??null}var d;function fe(o=process.platform){if(o!=="win32")return h.find(c)??null;return d??=y(),d}function se(o=process.platform){let e=fe(o);if(!e)throw Error(o==="win32"?g:"bash_unavailable");return e}function Qo(o=process.platform){return S(o==="win32"?P():"/tmp")}function De(o=process.platform,e=process.env){if(o!=="win32")return"/usr/bin:/bin";let t=e.SystemRoot??e.SYSTEMROOT??"C:\\Windows";return[r.join(t,"System32"),t,r.join(t,"System32","Wbem"),r.join(t,"System32","WindowsPowerShell","v1.0")].join(";")}function C(o,e=process.platform){if(e!=="win32"||/[\\/]/.test(o))return o;let t=/\.exe$/i.test(o)?o:`${o}.exe`,s=De(e).split(";");return r.join(t.toLowerCase()==="powershell.exe"?s[3]:s[0],t)}function Oe(o=process.platform,e=process.env){if(o!=="win32")return{PATH:De(o)};let t=e.SystemRoot??e.SYSTEMROOT??"C:\\Windows";return{PATH:De(o,e),SystemRoot:t,WINDIR:t}}function Ne(o=process.platform){return o==="win32"?{windowsHide:!0}:{detached:!0}}var u;function m(){if(u===void 0)u=Me(lr)(b(import.meta.url));return u}function Le(o,e=process.platform){let t=o.pid;if(e!=="win32"||t===void 0)return;let s=m();if(s?.track(t))o.once("close",()=>s.release(t))}function $e(o,e="SIGTERM",t=process.platform){if(t!=="win32"){process.kill(-o,e);return}if(e===0){process.kill(o,0);return}if(m()?.terminate(o))return;p(C("taskkill",t),["/PID",String(o),"/T","/F"],{stdio:"ignore",timeout:1e4,windowsHide:!0})}function A(o,e=63,t=process.platform){return t==="win32"||o.uid===process.getuid?.()&&(o.mode&e)===0}var N=/^(?:con|prn|aux|nul|com[0-9\u00b9\u00b2\u00b3]|lpt[0-9\u00b9\u00b2\u00b3]|conin\$|conout\$)(?:\..*)?$|:|[. ]$/i;function ln(o){return o!=="."&&o!==".."&&N.test(o)}
3
- export{Zo,fe,se,Qo,De,C,Oe,Ne,Le,$e,A,ln};
2
+ import{lr}from"./vm-hands-entry-lite-s85p7tqp.js";import{Me}from"./vm-hands-entry-lite-3gbf905c.js";import{execFileSync as p}from"child_process";import{realpathSync as S,statSync as w}from"fs";import{tmpdir as P}from"os";import{createRequire as b}from"module";import{win32 as r}from"path";var h=["/bin/bash","/usr/bin/bash"],g="Git Bash was not found. Install Git for Windows (https://git-scm.com/download/win), then run `reason connect`.";function c(o){try{return w(o).isFile()}catch{return!1}}var i=(o)=>[r.join(o,"bin","bash.exe"),r.join(o,"usr","bin","bash.exe")];function x(o,e){let t=r.normalize(o).toLowerCase(),s=(e.SystemRoot??e.SYSTEMROOT??"C:\\Windows").toLowerCase();return t.startsWith(r.join(s,"system32").toLowerCase()+"\\")||t.startsWith(r.join(s,"sysnative").toLowerCase()+"\\")||t.includes("\\windowsapps\\")}function f(o=process.env,e=c){let t=[];for(let s of(o.PATH??o.Path??"").split(";"))if(s&&r.isAbsolute(s))t.push(r.join(s,"git.exe"));for(let s of[o.ProgramW6432,o.ProgramFiles,o["ProgramFiles(x86)"]])if(s)t.push(r.join(s,"Git","cmd","git.exe"));if(o.LOCALAPPDATA)t.push(r.join(o.LOCALAPPDATA,"Programs","Git","cmd","git.exe"));return t.find(e)??null}var a;function Qo(o=process.platform){if(o!=="win32")return"git";return a??=f(),a}function J(o){let e=process.platform==="win32"?f(o):"git";if(!e)return null;try{return p(e,["--exec-path"],{encoding:"utf8",timeout:5000,windowsHide:!0,stdio:["ignore","pipe","ignore"],env:o}).trim()||null}catch{return null}}function y(o=process.env,e=J,t=c){let s=[],l=e(o);if(l)s.push(...i(r.resolve(l,"..","..","..")));for(let n of[o.ProgramW6432,o.ProgramFiles,o["ProgramFiles(x86)"]])if(n)s.push(...i(r.join(n,"Git")));if(o.LOCALAPPDATA)s.push(...i(r.join(o.LOCALAPPDATA,"Programs","Git")));for(let n of(o.PATH??o.Path??"").split(";"))if(n&&r.isAbsolute(n))s.push(r.join(n,"bash.exe"));return s.find((n)=>!x(n,o)&&t(n))??null}var d;function fe(o=process.platform){if(o!=="win32")return h.find(c)??null;return d??=y(),d}function se(o=process.platform){let e=fe(o);if(!e)throw Error(o==="win32"?g:"bash_unavailable");return e}function Ui(o=process.platform){return S(o==="win32"?P():"/tmp")}function De(o=process.platform,e=process.env){if(o!=="win32")return"/usr/bin:/bin";let t=e.SystemRoot??e.SYSTEMROOT??"C:\\Windows";return[r.join(t,"System32"),t,r.join(t,"System32","Wbem"),r.join(t,"System32","WindowsPowerShell","v1.0")].join(";")}function C(o,e=process.platform){if(e!=="win32"||/[\\/]/.test(o))return o;let t=/\.exe$/i.test(o)?o:`${o}.exe`,s=De(e).split(";");return r.join(t.toLowerCase()==="powershell.exe"?s[3]:s[0],t)}function Oe(o=process.platform,e=process.env){if(o!=="win32")return{PATH:De(o)};let t=e.SystemRoot??e.SYSTEMROOT??"C:\\Windows";return{PATH:De(o,e),SystemRoot:t,WINDIR:t}}function Ne(o=process.platform){return o==="win32"?{windowsHide:!0}:{detached:!0}}var u;function m(){if(u===void 0)u=Me(lr)(b(import.meta.url));return u}function Le(o,e=process.platform){let t=o.pid;if(e!=="win32"||t===void 0)return;let s=m();if(s?.track(t))o.once("close",()=>s.release(t))}function $e(o,e="SIGTERM",t=process.platform){if(t!=="win32"){process.kill(-o,e);return}if(e===0){process.kill(o,0);return}if(m()?.terminate(o))return;p(C("taskkill",t),["/PID",String(o),"/T","/F"],{stdio:"ignore",timeout:1e4,windowsHide:!0})}function A(o,e=63,t=process.platform){return t==="win32"||o.uid===process.getuid?.()&&(o.mode&e)===0}var N=/^(?:con|prn|aux|nul|com[0-9\u00b9\u00b2\u00b3]|lpt[0-9\u00b9\u00b2\u00b3]|conin\$|conout\$)(?:\..*)?$|:|[. ]$/i;function ln(o){return o!=="."&&o!==".."&&N.test(o)}
3
+ export{Qo,fe,se,Ui,De,C,Oe,Ne,Le,$e,A,ln};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{_,Zr,yt,ke}from"./vm-hands-entry-lite-mc5y3xr9.js";import{No}from"./vm-hands-entry-lite-tns12zqc.js";import{a}from"./vm-hands-entry-lite-gmxfz6k2.js";import{t,i,s,n}from"./vm-hands-entry-lite-bjtcy8n6.js";import{createHmac as _t,createPublicKey as be,randomBytes as bt,randomUUID as me,verify as he}from"crypto";import{chmodSync as L,existsSync as z,mkdirSync as Se,readFileSync as Ie,realpathSync as St,renameSync as De,statSync as It,unlinkSync as Le,writeFileSync as we}from"fs";import{basename as Dt,dirname as w,isAbsolute as Ae,join as m,resolve as Lt}from"path";var $e=[Object.freeze({family:"ara",channel:"stable",applicationId:"so.ara.desktop"}),Object.freeze({family:"ara",channel:"staging",applicationId:"so.ara.desktop.staging"}),Object.freeze({family:"reason",channel:"stable",applicationId:"com.reasonmachines.desktop"}),Object.freeze({family:"reason",channel:"staging",applicationId:"com.reasonmachines.desktop.staging"})];var Z="REASON_DESKTOP_RUNTIME",q="REASON_DESKTOP_RUNTIME_CHANNEL",Q="REASON_DESKTOP_RUNTIME_INSTANCE_ID",ee="REASON_DESKTOP_RUNTIME_WORKSPACE_SCOPE",We={[Z]:"ARA_DESKTOP_RUNTIME",[q]:"ARA_DESKTOP_RUNTIME_CHANNEL",[Q]:"ARA_DESKTOP_RUNTIME_INSTANCE_ID",[ee]:"ARA_DESKTOP_RUNTIME_WORKSPACE_SCOPE"};function x(r){if(r===void 0)return;if(!/^[a-f0-9]{64}$/.test(r))throw Error("Invalid desktop workspace scope.");return r}import{chmodSync as h,existsSync as g,mkdirSync as S,readFileSync as N,realpathSync as te,renameSync as ne,unlinkSync as I,writeFileSync as k}from"fs";import{createPrivateKey as ie,createPublicKey as re,generateKeyPairSync as oe,randomUUID as ae,sign as se}from"crypto";import{createRequire as ce}from"module";import{homedir as le,platform as T}from"os";import{dirname as de,join as f}from"path";var O=1,ue=16384,y=65536,pe=128,ge=128,U=65536;class l extends Error{code;nativeStatus;constructor(r,e){super(`Reason Device proof boundary failed (${r}).${e===void 0?"":` Native status: ${e}.`}`);this.code=r;this.nativeStatus=e;this.name="LocalCredentialBoundaryError"}}var D=null;function F(){if(!D)try{D=ce(import.meta.url)("bun:ffi")}catch{throw new l("native_boundary_unavailable")}return D}function fe(r){if(typeof r!=="string")return null;try{let e=new URL(r);if(e.protocol!=="https:"&&e.hostname!=="127.0.0.1"&&e.hostname!=="localhost"&&e.hostname!=="[::1]"&&e.hostname!=="::1")return null;return e.origin}catch{return null}}function ye(r){if(!r||typeof r!=="object"||Array.isArray(r))throw new l("invalid_credential_record");let e=r,o=fe(e.apiOrigin);if(e.version!==O||!o||typeof e.orgId!=="string"||e.orgId.length<1||e.orgId.length>160||typeof e.deviceId!=="string"||e.deviceId.length<1||e.deviceId.length>160||typeof e.credential!=="string"||!/^(?:reason|ara)_dev_/.test(e.credential)||e.credential.length>4096)throw new l("invalid_credential_record");return{version:O,apiOrigin:o,orgId:e.orgId,deviceId:e.deviceId,credential:e.credential}}function Gt(r=process.execPath){let e=r;try{e=te(r)}catch{}return No(de(e))}function u(r){return F().ptr(r)}function ve(r){if(!g(r))throw new l("native_boundary_unavailable");let{dlopen:e,FFIType:o}=F();try{return e(r,{ara_device_configure_scope:{args:[o.ptr,o.u64],returns:o.i32},ara_device_key_load_public:{args:[o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_key_create_fresh_public:{args:[o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_key_sign:{args:[o.ptr,o.u64,o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_key_is_non_extractable:{args:[o.ptr],returns:o.i32},ara_device_key_delete:{args:[o.ptr],returns:o.i32},ara_device_binding_read:{args:[o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_binding_create:{args:[o.ptr,o.u64],returns:o.i32},ara_device_binding_update:{args:[o.ptr,o.u64],returns:o.i32},ara_device_binding_delete:{args:[o.ptr],returns:o.i32},ara_device_keychain_read:{args:[o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_keychain_delete:{args:[o.ptr],returns:o.i32}})}catch(c){if(c instanceof l)throw c;throw new l("native_boundary_unavailable")}}function K(r){return Buffer.from(r).toString("base64url")}function v(r){if(typeof r!=="string"||!/^[A-Za-z0-9_-]{87}$/.test(r))return!1;try{let e=Buffer.from(r,"base64url");return e.byteLength===65&&e[0]===4}catch{return!1}}function M(r){if(r.byteLength<8||r.byteLength>72||r[0]!==48)return!1;let e=r[1];return e!==void 0&&e<128&&e+2===r.byteLength}class Ke{libraryPath;runtimePlatform;workspaceScope;library=null;constructor(r=Gt(),e=T(),o){this.libraryPath=r;this.runtimePlatform=e;this.workspaceScope=o;x(o)}symbols(){if(this.runtimePlatform!=="darwin")throw new l("unsupported_platform");this.library??=ve(this.libraryPath);let r=new TextEncoder().encode(this.workspaceScope??""),e=this.library.symbols.ara_device_configure_scope(u(r.length?r:new Uint8Array(1)),BigInt(r.length));if(e!==0)throw new l("native_boundary_unavailable",e);return this.library.symbols}publicKey(r){let e=new Uint8Array(pe),o=new BigUint64Array(1),c=r==="load"?this.symbols().ara_device_key_load_public(u(e),BigInt(e.byteLength),u(o)):this.symbols().ara_device_key_create_fresh_public(u(e),BigInt(e.byteLength),u(o));if(c!==0)throw new l(r==="load"?"proof_key_read_failed":"proof_key_generation_failed",c);let d=Number(o[0]);if(!Number.isSafeInteger(d)||d!==65)throw new l("invalid_public_key");let p=K(e.subarray(0,d));if(!v(p))throw new l("invalid_public_key");return p}loadPublicKey(){return this.publicKey("load")}createFreshPublicKey(){return this.publicKey("create_fresh")}sign(r){if(r.byteLength<1||r.byteLength>U)throw new l("proof_sign_failed");let e=new Uint8Array(ge),o=new BigUint64Array(1),c=this.symbols().ara_device_key_sign(u(r),BigInt(r.byteLength),u(e),BigInt(e.byteLength),u(o));if(c!==0)throw new l("proof_sign_failed",c);let d=Number(o[0]);if(!Number.isSafeInteger(d)||d<1||d>e.byteLength)throw new l("invalid_signature");let p=e.subarray(0,d);if(!M(p))throw new l("invalid_signature");return K(p)}privateKeyIsNonExtractable(){let r=new Uint8Array(1),e=this.symbols().ara_device_key_is_non_extractable(u(r));if(e!==0||r[0]!==1)throw new l("proof_key_read_failed",e);return!0}deleteKey(){let r=new Uint8Array(1),e=this.symbols().ara_device_key_delete(u(r));if(e!==0)throw new l("proof_key_delete_failed",e);return r[0]===1}loadBinding(){let r=new Uint8Array(y),e=new BigUint64Array(1),o=this.symbols().ara_device_binding_read(u(r),BigInt(r.byteLength),u(e));if(o===1)return null;if(o!==0)throw new l("binding_read_failed",o);let c=Number(e[0]);if(!Number.isSafeInteger(c)||c<1||c>r.byteLength)throw new l("invalid_binding");return r.slice(0,c)}createBinding(r){if(r.byteLength<1||r.byteLength>y)throw new l("invalid_binding");let e=this.symbols().ara_device_binding_create(u(r),BigInt(r.byteLength));if(e!==0)throw new l("binding_create_failed",e)}updateBinding(r){if(r.byteLength<1||r.byteLength>y)throw new l("invalid_binding");let e=this.symbols().ara_device_binding_update(u(r),BigInt(r.byteLength));if(e!==0)throw new l("binding_update_failed",e)}deleteBinding(){let r=new Uint8Array(1),e=this.symbols().ara_device_binding_delete(u(r));if(e!==0)throw new l("binding_delete_failed",e);return r[0]===1}loadLegacyCredential(){let r=new Uint8Array(ue),e=new BigUint64Array(1),o=this.symbols().ara_device_keychain_read(u(r),BigInt(r.byteLength),u(e));if(o===1)return null;if(o!==0)throw new l("legacy_credential_read_failed",o);let c=Number(e[0]);if(!Number.isSafeInteger(c)||c<1||c>r.byteLength)throw new l("invalid_credential_record");try{let d=new TextDecoder("utf-8",{fatal:!0}).decode(r.subarray(0,c));return ye(JSON.parse(d))}catch(d){if(d instanceof l)throw d;throw new l("invalid_credential_record")}}deleteLegacyCredential(){let r=new Uint8Array(1),e=this.symbols().ara_device_keychain_delete(u(r));if(e!==0)throw new l("legacy_credential_delete_failed",e);return r[0]===1}}function C(r){let e=r.export({format:"jwk"});if(e.crv!=="P-256"||typeof e.x!=="string"||typeof e.y!=="string")throw new l("invalid_public_key");let o=Buffer.from(e.x,"base64url"),c=Buffer.from(e.y,"base64url");if(o.byteLength!==32||c.byteLength!==32)throw new l("invalid_public_key");let d=Buffer.concat([Buffer.of(4),o,c]).toString("base64url");if(!v(d))throw new l("invalid_public_key");return d}function _e(){let r=process.env.XDG_CONFIG_HOME?.trim()||f(le(),".config");yt(r);let e=f(r,"ara");return Zr(e)?e:f(r,"reason")}class Lr{directory;constructor(r=_e()){this.directory=r}keyPath(){return f(this.directory,"local-device.key")}bindingPath(){return f(this.directory,"local-device.binding")}loadPrivateKeyObject(){let r=this.keyPath();if(!g(r))throw new l("proof_key_read_failed");try{let e=N(r,"utf8");return ie({key:e,format:"pem"})}catch{throw new l("proof_key_read_failed")}}loadPublicKey(){let r=this.loadPrivateKeyObject(),e=re(r);return C(e)}createFreshPublicKey(){S(this.directory,{recursive:!0,mode:448});let{privateKey:r,publicKey:e}=oe("ec",{namedCurve:"P-256"}),o=r.export({type:"pkcs8",format:"pem"}),c=this.keyPath();return k(c,o,{mode:384}),h(c,384),C(e)}sign(r){if(r.byteLength<1||r.byteLength>U)throw new l("proof_sign_failed");let e=this.loadPrivateKeyObject(),o;try{o=se("sha256",r,e)}catch{throw new l("proof_sign_failed")}if(!M(o))throw new l("invalid_signature");return o.toString("base64url")}privateKeyIsNonExtractable(){return!1}deleteKey(){let r=this.keyPath();if(!g(r))return!1;return I(r),!0}loadBinding(){let r=this.bindingPath();if(!g(r))return null;try{return new Uint8Array(N(r))}catch{return null}}createBinding(r){if(r.byteLength<1||r.byteLength>y)throw new l("invalid_binding");S(this.directory,{recursive:!0,mode:448});let e=this.bindingPath();if(g(e))throw new l("binding_create_failed");k(e,r,{mode:384}),h(e,384)}updateBinding(r){if(r.byteLength<1||r.byteLength>y)throw new l("invalid_binding");S(this.directory,{recursive:!0,mode:448});let e=this.bindingPath();if(!g(e))throw new l("binding_update_failed");let o=`${e}.${ae()}`;try{k(o,r,{mode:384,flag:"wx"}),h(o,384),ne(o,e)}finally{if(g(o))I(o)}}deleteBinding(){let r=this.bindingPath();if(!g(r))return!1;return I(r),!0}loadLegacyCredential(){return null}deleteLegacyCredential(){return!1}}function V(){return T()==="darwin"?new Ke:new Lr}var b=t().min(1).max(160).regex(/^[A-Za-z0-9._:-]+$/),B=i({id:b,kind:n("permission_denied"),operation:s(["bash","read","write","edit"]),provenance:s(["sandbox_policy","os_permission_unknown"]),occurredAt:t().datetime(),expiresAt:t().datetime(),sessionId:b,deviceId:b,organizationId:b}).strict();var A=4;var P="macos-keychain-p256-v1",Pe=1,Ee=`ARA-DEVICE-BINDING-V1
2
+ import{_,Zr,yt,ke}from"./vm-hands-entry-lite-4anjdcth.js";import{Lo}from"./vm-hands-entry-lite-73f4cgkf.js";import{a}from"./vm-hands-entry-lite-jvszqt0z.js";import{t,i,s,n}from"./vm-hands-entry-lite-ztsp4gs8.js";import{createHmac as _t,createPublicKey as be,randomBytes as bt,randomUUID as me,verify as he}from"crypto";import{chmodSync as L,existsSync as z,mkdirSync as Se,readFileSync as Ie,realpathSync as St,renameSync as De,statSync as It,unlinkSync as Le,writeFileSync as we}from"fs";import{basename as Dt,dirname as w,isAbsolute as Ae,join as m,resolve as Lt}from"path";var $e=[Object.freeze({family:"ara",channel:"stable",applicationId:"so.ara.desktop"}),Object.freeze({family:"ara",channel:"staging",applicationId:"so.ara.desktop.staging"}),Object.freeze({family:"reason",channel:"stable",applicationId:"com.reasonmachines.desktop"}),Object.freeze({family:"reason",channel:"staging",applicationId:"com.reasonmachines.desktop.staging"})];var Z="REASON_DESKTOP_RUNTIME",q="REASON_DESKTOP_RUNTIME_CHANNEL",Q="REASON_DESKTOP_RUNTIME_INSTANCE_ID",ee="REASON_DESKTOP_RUNTIME_WORKSPACE_SCOPE",We={[Z]:"ARA_DESKTOP_RUNTIME",[q]:"ARA_DESKTOP_RUNTIME_CHANNEL",[Q]:"ARA_DESKTOP_RUNTIME_INSTANCE_ID",[ee]:"ARA_DESKTOP_RUNTIME_WORKSPACE_SCOPE"};function x(r){if(r===void 0)return;if(!/^[a-f0-9]{64}$/.test(r))throw Error("Invalid desktop workspace scope.");return r}import{chmodSync as h,existsSync as g,mkdirSync as S,readFileSync as N,realpathSync as te,renameSync as ne,unlinkSync as I,writeFileSync as k}from"fs";import{createPrivateKey as ie,createPublicKey as re,generateKeyPairSync as oe,randomUUID as ae,sign as se}from"crypto";import{createRequire as ce}from"module";import{homedir as le,platform as T}from"os";import{dirname as de,join as f}from"path";var O=1,ue=16384,y=65536,pe=128,ge=128,U=65536;class l extends Error{code;nativeStatus;constructor(r,e){super(`Reason Device proof boundary failed (${r}).${e===void 0?"":` Native status: ${e}.`}`);this.code=r;this.nativeStatus=e;this.name="LocalCredentialBoundaryError"}}var D=null;function F(){if(!D)try{D=ce(import.meta.url)("bun:ffi")}catch{throw new l("native_boundary_unavailable")}return D}function fe(r){if(typeof r!=="string")return null;try{let e=new URL(r);if(e.protocol!=="https:"&&e.hostname!=="127.0.0.1"&&e.hostname!=="localhost"&&e.hostname!=="[::1]"&&e.hostname!=="::1")return null;return e.origin}catch{return null}}function ye(r){if(!r||typeof r!=="object"||Array.isArray(r))throw new l("invalid_credential_record");let e=r,o=fe(e.apiOrigin);if(e.version!==O||!o||typeof e.orgId!=="string"||e.orgId.length<1||e.orgId.length>160||typeof e.deviceId!=="string"||e.deviceId.length<1||e.deviceId.length>160||typeof e.credential!=="string"||!/^(?:reason|ara)_dev_/.test(e.credential)||e.credential.length>4096)throw new l("invalid_credential_record");return{version:O,apiOrigin:o,orgId:e.orgId,deviceId:e.deviceId,credential:e.credential}}function Gt(r=process.execPath){let e=r;try{e=te(r)}catch{}return Lo(de(e))}function u(r){return F().ptr(r)}function ve(r){if(!g(r))throw new l("native_boundary_unavailable");let{dlopen:e,FFIType:o}=F();try{return e(r,{ara_device_configure_scope:{args:[o.ptr,o.u64],returns:o.i32},ara_device_key_load_public:{args:[o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_key_create_fresh_public:{args:[o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_key_sign:{args:[o.ptr,o.u64,o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_key_is_non_extractable:{args:[o.ptr],returns:o.i32},ara_device_key_delete:{args:[o.ptr],returns:o.i32},ara_device_binding_read:{args:[o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_binding_create:{args:[o.ptr,o.u64],returns:o.i32},ara_device_binding_update:{args:[o.ptr,o.u64],returns:o.i32},ara_device_binding_delete:{args:[o.ptr],returns:o.i32},ara_device_keychain_read:{args:[o.ptr,o.u64,o.ptr],returns:o.i32},ara_device_keychain_delete:{args:[o.ptr],returns:o.i32}})}catch(c){if(c instanceof l)throw c;throw new l("native_boundary_unavailable")}}function K(r){return Buffer.from(r).toString("base64url")}function v(r){if(typeof r!=="string"||!/^[A-Za-z0-9_-]{87}$/.test(r))return!1;try{let e=Buffer.from(r,"base64url");return e.byteLength===65&&e[0]===4}catch{return!1}}function M(r){if(r.byteLength<8||r.byteLength>72||r[0]!==48)return!1;let e=r[1];return e!==void 0&&e<128&&e+2===r.byteLength}class Ke{libraryPath;runtimePlatform;workspaceScope;library=null;constructor(r=Gt(),e=T(),o){this.libraryPath=r;this.runtimePlatform=e;this.workspaceScope=o;x(o)}symbols(){if(this.runtimePlatform!=="darwin")throw new l("unsupported_platform");this.library??=ve(this.libraryPath);let r=new TextEncoder().encode(this.workspaceScope??""),e=this.library.symbols.ara_device_configure_scope(u(r.length?r:new Uint8Array(1)),BigInt(r.length));if(e!==0)throw new l("native_boundary_unavailable",e);return this.library.symbols}publicKey(r){let e=new Uint8Array(pe),o=new BigUint64Array(1),c=r==="load"?this.symbols().ara_device_key_load_public(u(e),BigInt(e.byteLength),u(o)):this.symbols().ara_device_key_create_fresh_public(u(e),BigInt(e.byteLength),u(o));if(c!==0)throw new l(r==="load"?"proof_key_read_failed":"proof_key_generation_failed",c);let d=Number(o[0]);if(!Number.isSafeInteger(d)||d!==65)throw new l("invalid_public_key");let p=K(e.subarray(0,d));if(!v(p))throw new l("invalid_public_key");return p}loadPublicKey(){return this.publicKey("load")}createFreshPublicKey(){return this.publicKey("create_fresh")}sign(r){if(r.byteLength<1||r.byteLength>U)throw new l("proof_sign_failed");let e=new Uint8Array(ge),o=new BigUint64Array(1),c=this.symbols().ara_device_key_sign(u(r),BigInt(r.byteLength),u(e),BigInt(e.byteLength),u(o));if(c!==0)throw new l("proof_sign_failed",c);let d=Number(o[0]);if(!Number.isSafeInteger(d)||d<1||d>e.byteLength)throw new l("invalid_signature");let p=e.subarray(0,d);if(!M(p))throw new l("invalid_signature");return K(p)}privateKeyIsNonExtractable(){let r=new Uint8Array(1),e=this.symbols().ara_device_key_is_non_extractable(u(r));if(e!==0||r[0]!==1)throw new l("proof_key_read_failed",e);return!0}deleteKey(){let r=new Uint8Array(1),e=this.symbols().ara_device_key_delete(u(r));if(e!==0)throw new l("proof_key_delete_failed",e);return r[0]===1}loadBinding(){let r=new Uint8Array(y),e=new BigUint64Array(1),o=this.symbols().ara_device_binding_read(u(r),BigInt(r.byteLength),u(e));if(o===1)return null;if(o!==0)throw new l("binding_read_failed",o);let c=Number(e[0]);if(!Number.isSafeInteger(c)||c<1||c>r.byteLength)throw new l("invalid_binding");return r.slice(0,c)}createBinding(r){if(r.byteLength<1||r.byteLength>y)throw new l("invalid_binding");let e=this.symbols().ara_device_binding_create(u(r),BigInt(r.byteLength));if(e!==0)throw new l("binding_create_failed",e)}updateBinding(r){if(r.byteLength<1||r.byteLength>y)throw new l("invalid_binding");let e=this.symbols().ara_device_binding_update(u(r),BigInt(r.byteLength));if(e!==0)throw new l("binding_update_failed",e)}deleteBinding(){let r=new Uint8Array(1),e=this.symbols().ara_device_binding_delete(u(r));if(e!==0)throw new l("binding_delete_failed",e);return r[0]===1}loadLegacyCredential(){let r=new Uint8Array(ue),e=new BigUint64Array(1),o=this.symbols().ara_device_keychain_read(u(r),BigInt(r.byteLength),u(e));if(o===1)return null;if(o!==0)throw new l("legacy_credential_read_failed",o);let c=Number(e[0]);if(!Number.isSafeInteger(c)||c<1||c>r.byteLength)throw new l("invalid_credential_record");try{let d=new TextDecoder("utf-8",{fatal:!0}).decode(r.subarray(0,c));return ye(JSON.parse(d))}catch(d){if(d instanceof l)throw d;throw new l("invalid_credential_record")}}deleteLegacyCredential(){let r=new Uint8Array(1),e=this.symbols().ara_device_keychain_delete(u(r));if(e!==0)throw new l("legacy_credential_delete_failed",e);return r[0]===1}}function C(r){let e=r.export({format:"jwk"});if(e.crv!=="P-256"||typeof e.x!=="string"||typeof e.y!=="string")throw new l("invalid_public_key");let o=Buffer.from(e.x,"base64url"),c=Buffer.from(e.y,"base64url");if(o.byteLength!==32||c.byteLength!==32)throw new l("invalid_public_key");let d=Buffer.concat([Buffer.of(4),o,c]).toString("base64url");if(!v(d))throw new l("invalid_public_key");return d}function _e(){let r=process.env.XDG_CONFIG_HOME?.trim()||f(le(),".config");yt(r);let e=f(r,"ara");return Zr(e)?e:f(r,"reason")}class Lr{directory;constructor(r=_e()){this.directory=r}keyPath(){return f(this.directory,"local-device.key")}bindingPath(){return f(this.directory,"local-device.binding")}loadPrivateKeyObject(){let r=this.keyPath();if(!g(r))throw new l("proof_key_read_failed");try{let e=N(r,"utf8");return ie({key:e,format:"pem"})}catch{throw new l("proof_key_read_failed")}}loadPublicKey(){let r=this.loadPrivateKeyObject(),e=re(r);return C(e)}createFreshPublicKey(){S(this.directory,{recursive:!0,mode:448});let{privateKey:r,publicKey:e}=oe("ec",{namedCurve:"P-256"}),o=r.export({type:"pkcs8",format:"pem"}),c=this.keyPath();return k(c,o,{mode:384}),h(c,384),C(e)}sign(r){if(r.byteLength<1||r.byteLength>U)throw new l("proof_sign_failed");let e=this.loadPrivateKeyObject(),o;try{o=se("sha256",r,e)}catch{throw new l("proof_sign_failed")}if(!M(o))throw new l("invalid_signature");return o.toString("base64url")}privateKeyIsNonExtractable(){return!1}deleteKey(){let r=this.keyPath();if(!g(r))return!1;return I(r),!0}loadBinding(){let r=this.bindingPath();if(!g(r))return null;try{return new Uint8Array(N(r))}catch{return null}}createBinding(r){if(r.byteLength<1||r.byteLength>y)throw new l("invalid_binding");S(this.directory,{recursive:!0,mode:448});let e=this.bindingPath();if(g(e))throw new l("binding_create_failed");k(e,r,{mode:384}),h(e,384)}updateBinding(r){if(r.byteLength<1||r.byteLength>y)throw new l("invalid_binding");S(this.directory,{recursive:!0,mode:448});let e=this.bindingPath();if(!g(e))throw new l("binding_update_failed");let o=`${e}.${ae()}`;try{k(o,r,{mode:384,flag:"wx"}),h(o,384),ne(o,e)}finally{if(g(o))I(o)}}deleteBinding(){let r=this.bindingPath();if(!g(r))return!1;return I(r),!0}loadLegacyCredential(){return null}deleteLegacyCredential(){return!1}}function V(){return T()==="darwin"?new Ke:new Lr}var b=t().min(1).max(160).regex(/^[A-Za-z0-9._:-]+$/),B=i({id:b,kind:n("permission_denied"),operation:s(["bash","read","write","edit"]),provenance:s(["sandbox_policy","os_permission_unknown"]),occurredAt:t().datetime(),expiresAt:t().datetime(),sessionId:b,deviceId:b,organizationId:b}).strict();var A=4;var P="macos-keychain-p256-v1",Pe=1,Ee=`ARA-DEVICE-BINDING-V1
3
3
  `;function Re(r){return r===void 0||typeof r==="number"&&Number.isInteger(r)&&r>=1&&r<=4}function G(r,e=Date.now()){let o=B.safeParse(r);if(!o.success)return!1;let c=o.data,d=typeof c.occurredAt==="string"?Date.parse(c.occurredAt):NaN,p=typeof c.expiresAt==="string"?Date.parse(c.expiresAt):NaN;return c.kind==="permission_denied"&&["bash","read","write","edit"].includes(c.operation)&&["sandbox_policy","os_permission_unknown"].includes(c.provenance)&&Number.isFinite(d)&&d<=e&&p>e&&p>d&&p-d<=600000}function Kt(r,e,o=Date.now()){if(!r||!e||r.state!=="connected"||r.deviceId!==e.deviceId)return null;let c=Date.parse(r.lastHeartbeatAt??""),d=r.permissionRecovery;if(!(o-c>=0&&o-c<30000)||!G(d,o)||d.deviceId!==e.deviceId||d.organizationId!==e.orgId)return null;try{process.kill(r.pid,0)}catch{return null}return d}function H(r={},e=a()){let o=_({env:{...process.env,...r}}),c=r.XDG_CONFIG_HOME?.trim()||m(e,".config");return ke(c,...o==="staging"?["staging"]:[])}function $r(r={},e=a()){return m(H(r,e),"local-device.json")}function xe(r={},e=a()){return m(H(r,e),"local-daemon.json")}function Ne(r,e){Se(w(r),{recursive:!0,mode:448}),L(w(r),448);let o=`${r}.${process.pid}.${me()}.tmp`;try{we(o,`${JSON.stringify(e,null,2)}
4
4
  `,{mode:384,flag:"wx"}),L(o,384),De(o,r),L(r,384)}finally{if(z(o))Le(o)}return r}function E(r){if(!z(r))return null;try{return JSON.parse(Ie(r,"utf8"))}catch{return null}}function Oe(r){if(!Array.isArray(r))return null;let e=[];for(let o of r){if(!o||typeof o!=="object")return null;let c=o;if(typeof c.id!=="string"||typeof c.label!=="string"||typeof c.path!=="string"||typeof c.pathFingerprint!=="string"||!c.permissions||typeof c.permissions.read!=="boolean"||typeof c.permissions.write!=="boolean"||typeof c.permissions.execute!=="boolean"||typeof c.permissions.discover_environment!=="boolean"||typeof c.permissions.expose_mcp!=="boolean")return null;e.push({id:c.id,label:c.label,path:c.path,pathFingerprint:c.pathFingerprint,permissions:c.permissions})}return e}function J(r,e,o=[]){let c=Object.keys(r);return e.every((d)=>Object.hasOwn(r,d))&&c.every((d)=>e.includes(d)||o.includes(d))}function Ce(r){if(typeof r!=="string")return null;try{let e=new URL(r);if(e.protocol!=="https:"&&e.hostname!=="127.0.0.1"&&e.hostname!=="localhost")return null;return e.origin}catch{return null}}function Y(r){if(!r||typeof r!=="object"||Array.isArray(r))return null;let e=r,o=Oe(e.roots),c=Ce(e.apiOrigin);if(!c||typeof e.orgId!=="string"||typeof e.deviceId!=="string"||typeof e.displayName!=="string"||typeof e.registeredAt!=="string"||!Re(e.handsSlots)||e.worker!==void 0&&(!e.worker||!/^[a-f0-9]{64}$/.test(e.worker.configDigest)||!["persistent","ephemeral"].includes(e.worker.lifetime)||!Number.isFinite(Date.parse(e.worker.expiresAt)))||!o)return null;return{apiOrigin:c,orgId:e.orgId,deviceId:e.deviceId,displayName:e.displayName,registeredAt:e.registeredAt,...e.handsSlots!==void 0?{handsSlots:e.handsSlots}:{},...e.worker!==void 0?{worker:e.worker}:{},roots:o}}function Te(r){return{version:A,apiOrigin:r.apiOrigin,orgId:r.orgId,deviceId:r.deviceId,devicePublicKey:r.devicePublicKey,displayName:r.displayName,registeredAt:r.registeredAt,...r.handsSlots!==void 0?{handsSlots:r.handsSlots}:{},...r.worker!==void 0?{worker:r.worker}:{},roots:r.roots.map((e)=>({id:e.id,label:e.label,path:e.path,pathFingerprint:e.pathFingerprint,permissions:{read:e.permissions.read,write:e.permissions.write,execute:e.permissions.execute,discover_environment:e.permissions.discover_environment,expose_mcp:e.permissions.expose_mcp}})),credentialStorage:P}}function X(r){if(!r||typeof r!=="object"||Array.isArray(r))return null;let e=r;if(!J(e,["version","apiOrigin","orgId","deviceId","devicePublicKey","displayName","registeredAt","roots","credentialStorage"],["handsSlots","worker"]))return null;let o=Y(e);if(!o||e.version!==A||e.credentialStorage!==P||!v(e.devicePublicKey))return null;return{version:A,...o,devicePublicKey:e.devicePublicKey,credentialStorage:P}}function Ue(r){return new TextEncoder().encode(`${Ee}${JSON.stringify(Te(r))}`)}function Fe(r){let e=Buffer.from(r,"base64url");return be({format:"jwk",key:{kty:"EC",crv:"P-256",x:e.subarray(1,33).toString("base64url"),y:e.subarray(33,65).toString("base64url")}})}function Me(r){let e;try{e=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(r))}catch{throw new l("invalid_binding")}if(!e||typeof e!=="object"||Array.isArray(e))throw new l("invalid_binding");let o=e;if(!J(o,["version","state","signature"])||o.version!==Pe||typeof o.signature!=="string"||!/^[A-Za-z0-9_-]{10,128}$/.test(o.signature))throw new l("invalid_binding");let c=X(o.state);if(!c)throw new l("invalid_binding");let d=!1;try{d=he("sha256",Ue(c),Fe(c.devicePublicKey),Buffer.from(o.signature,"base64url"))}catch{d=!1}if(!d)throw new l("invalid_binding");return c}function je(r){let{credentialStorage:e,...o}=r;return o}function Mr(r=$r(),e={}){let o=E(r),c=e.proofStore??e.credentialStore??V(),d=c.loadBinding();if(!d){if(o&&typeof o==="object"&&!Array.isArray(o)&&Ve(o))return null;if(o!==null)throw new l("invalid_binding");return null}let p=Me(d),W=c.loadPublicKey();if(c.privateKeyIsNonExtractable(),W!==p.devicePublicKey)throw new l("invalid_public_key");let R=X(o);if(e.repair!==!1&&(!R||JSON.stringify(R)!==JSON.stringify(p)))Ne(r,p);return je(p)}function Ve(r){let e=r,o=Y(r);if(!o)return null;if(e.version===2){if(typeof e.deviceCredential!=="string"||!/^(?:reason|ara)_dev_/.test(e.deviceCredential)||e.deviceCredential.length>4096)return null;return{state:o,credentialSource:"plaintext-v2"}}if(e.version!==3||e.credentialStorage!=="macos-keychain-v1"||"deviceCredential"in e)return null;return{state:o,credentialSource:"keychain-v3"}}function ht(r=xe()){let e=E(r);if(!e||typeof e!=="object")return null;let o=e;if(o.version!==1||typeof o.pid!=="number"||!Number.isInteger(o.pid)||!["starting","connected","stopped","error"].includes(o.state??"")||typeof o.startedAt!=="string"||o.lastHeartbeatAt!==void 0&&typeof o.lastHeartbeatAt!=="string"||o.lastUsedAt!==void 0&&typeof o.lastUsedAt!=="string"||o.organizationId!==void 0&&typeof o.organizationId!=="string"||o.organizationName!==void 0&&typeof o.organizationName!=="string"||o.organizationSlug!==void 0&&typeof o.organizationSlug!=="string"||o.error!==void 0&&typeof o.error!=="string"||o.reconnectingSince!==void 0&&typeof o.reconnectingSince!=="string"||o.workspace!==void 0&&typeof o.workspace!=="string")return null;if(o.permissionRecovery!==void 0&&!G(o.permissionRecovery))delete o.permissionRecovery;return o}var Jt=1;function Be(r=$r()){return m(w(r),"local-device.proxy.json")}function j(r=Be()){let e=E(r);if(!e||typeof e!=="object"||Array.isArray(e))return null;let o=e;if(o.version!==Jt||typeof o.url!=="string"||o.url.length===0||o.caFile!==void 0&&(typeof o.caFile!=="string"||!Ae(o.caFile)))return null;return{version:Jt,url:o.url,...o.caFile?{caFile:o.caFile}:{}}}
5
5
  export{l,Gt,Ke,Lr,Kt,$r,Mr,ht,Jt,j};
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{a}from"./vm-hands-entry-lite-gmxfz6k2.js";import{readFileSync as c}from"fs";import{isAbsolute as l,normalize as i}from"path";var m="REASON_WORKER_DESKTOP_USER",u=null;function p(t,o){for(let s of o.split(`
2
+ import{a}from"./vm-hands-entry-lite-jvszqt0z.js";import{readFileSync as c}from"fs";import{isAbsolute as l,normalize as i}from"path";var m="REASON_WORKER_DESKTOP_USER",u=null;function p(t,o){for(let s of o.split(`
3
3
  `)){let e=s.split(":");if(e.length<7||Number(e[2])!==t||!/^\d+$/.test(e[2])||!/^\d+$/.test(e[3]))continue;let n=e[5];if(!/^[a-z_][a-z0-9_-]*$/i.test(e[0])||!l(n)||i(n)!==n||n==="/")return null;return{username:e[0],uid:t,gid:Number(e[3]),home:n}}return null}function Gs(t={}){let o="value"in t?t.value:process.env[m];if(u=null,o===void 0||o==="")return null;let s=t.platform??process.platform,e="euid"in t?t.euid:process.geteuid?.(),n=/^[1-9]\d{0,9}$/.test(o)?Number(o):NaN,r=s==="linux"&&e===0&&Number.isSafeInteger(n)?p(n,(t.passwd??(()=>c("/etc/passwd","utf8")))()):null;if(!r||r.gid===0)throw Error("worker_desktop_user_invalid");return u=r,r}function K(){return u}function Ln(){return u?.home??a()}
4
4
  export{Gs,K,Ln};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{$n,Mn,Ro,Wt}from"./vm-hands-entry-lite-5nhmye0y.js";import{Tn,Ve,go,In,Dn,On,Rr,x}from"./vm-hands-entry-lite-8b6qfv1c.js";import{Pt}from"./vm-hands-entry-lite-3thdz953.js";import{Nr}from"./vm-hands-entry-lite-4pm82ns4.js";import{j}from"./vm-hands-entry-lite-zwnevt4c.js";import{a}from"./vm-hands-entry-lite-gmxfz6k2.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as ce,spawn as ne}from"child_process";import{randomBytes as Oe}from"crypto";import{chmodSync as he,existsSync as ae,lstatSync as Je,mkdirSync as Qe,readFileSync as oe,rmSync as ie,writeFileSync as u}from"fs";import{connect as Se}from"net";import{join as I}from"path";var B=32,Y=76;var m="./desktop-wallpaper-fd8f2wb2.jpg";var v="./dock-browser-y53t41cx.png";var Z="./dock-files-cp52htdw.png";var V="./dock-terminal-1es514yq.png";var z="./grok-wallpaper-71zwn2pj.jpg";var W="./grok-dock-browser-pzw59wnd.png";var U="./grok-dock-files-eckq444x.png";var ee="./grok-dock-terminal-hcpz3e43.png";var re=`# Sets the X root window background and _XROOTPMAP_ID, as feh --bg-fill does.
2
+ import{$n,Mn,To,Wt}from"./vm-hands-entry-lite-k9vk84wa.js";import{Tn,Ve,_o,In,Dn,On,Rr,x}from"./vm-hands-entry-lite-jhbeh0qy.js";import{Pt}from"./vm-hands-entry-lite-xe0benev.js";import{Nr}from"./vm-hands-entry-lite-j5t2pj4v.js";import{j}from"./vm-hands-entry-lite-cgddp0y3.js";import{a}from"./vm-hands-entry-lite-jvszqt0z.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as ce,spawn as ne}from"child_process";import{randomBytes as Oe}from"crypto";import{chmodSync as he,existsSync as ae,lstatSync as Je,mkdirSync as Qe,readFileSync as oe,rmSync as ie,writeFileSync as u}from"fs";import{connect as Se}from"net";import{join as I}from"path";var B=32,Y=76;var m="./desktop-wallpaper-fd8f2wb2.jpg";var v="./dock-browser-y53t41cx.png";var Z="./dock-files-cp52htdw.png";var V="./dock-terminal-1es514yq.png";var z="./grok-wallpaper-71zwn2pj.jpg";var W="./grok-dock-browser-pzw59wnd.png";var U="./grok-dock-files-eckq444x.png";var ee="./grok-dock-terminal-hcpz3e43.png";var re=`# Sets the X root window background and _XROOTPMAP_ID, as feh --bg-fill does.
3
3
  # The native Blaxel image ships no feh, hsetroot or compositor, but it does ship
4
4
  # python3-gi and libX11. tint2 reads _XROOTPMAP_ID to draw its transparent panel.
5
5
  # Usage: DISPLAY=:99 python3 set-root-wallpaper.py IMAGE
@@ -141,7 +141,7 @@ Type=Application
141
141
  Categories=System;FileManager;
142
142
  `;var te={"wallpaper.jpg":m,"dock-browser.png":v,"dock-terminal.png":V,"dock-files.png":Z,"grok-wallpaper.jpg":z,"grok-dock-browser.png":W,"grok-dock-terminal.png":ee,"grok-dock-files.png":U},Ce=re,Ge='set_wallpaper() { if command -v feh >/dev/null 2>&1; then feh --bg-fill "$1"; else python3 "$2" "$1"; fi; }';function de(e){let D=(p)=>p.replaceAll("DISPLAY=:99",`DISPLAY=${e.display}`).replaceAll("/tmp/ara-",`${e.root}/ara-`),s=e.look==="grok",d=new Set(e.absent??[]),t=d.has("files")&&e.filesViewerExec?e.filesViewerExec:null;if(t)d.delete("files");let c=(s?ue:Ne).split(`
143
143
  `).filter((p)=>!(d.has("terminal")&&p.endsWith("/ara-terminal.desktop"))&&!(d.has("files")&&p.endsWith("/ara-files.desktop"))).join(`
144
- `),n=(p)=>s?p.replace("/tmp/ara-dock-","/tmp/ara-grok-dock-"):p,o=t?$e.replace(/^Exec=.*$/m,`Exec=${t}`).replace("Categories=System;FileManager;","Categories=Utility;Viewer;"):$e,f=s?"ara-grok-wallpaper.jpg":"ara-wallpaper.jpg",i={"openbox/rc.xml":Ye(e.screen),"tint2/tint2rc":D(c),"picom/picom.conf":Re,...d.has("terminal")?{}:{"ara-terminal.desktop":D(n(Fe))},...d.has("files")?{}:{"ara-files.desktop":D(n(o))},"ara-chromium.desktop":D(n(Ke)).replace("chromium --no-sandbox %U",e.browserExec),"ara-set-root-wallpaper.py":Ce},X=[...N.slice(0,3),Ge,`[ ! -f "$ROOT/${f}" ] || set_wallpaper "$ROOT/${f}" "$ROOT/ara-set-root-wallpaper.py" || true`,'if alive tint2 && ! cmp -s "$ROOT/tint2/tint2rc" "$ROOT/tint2/applied"; then read -r pid _ <"$ROOT/tint2.pid"; kill -USR1 "$pid" 2>/dev/null || true; fi','cp "$ROOT/tint2/tint2rc" "$ROOT/tint2/applied" 2>/dev/null || true',...N.slice(3)];return{files:i,start:X}}var N=['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"; }','if [ -f "$ROOT/tint2/tint2rc" ] && ! alive tint2 && command -v tint2 >/dev/null 2>&1; then launch tint2 tint2 -c "$ROOT/tint2/tint2rc"; fi','if [ -f "$ROOT/picom/picom.conf" ] && ! alive picom && command -v picom >/dev/null 2>&1; then launch picom picom --config "$ROOT/picom/picom.conf"; fi'];var Te=43200000,A=":99",ke=60000,P=15000,R={width:1280,height:800},_e=/^[A-Za-z0-9._:-]{1,160}$/;function we(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}var Me=["video","viewer","viewer_same_network","viewer_network","look"];function me(e,D=Date.now()){let s=["relay_url","session_id","expires_at"];if(!we(e)||s.some((f)=>!(f in e))||Object.keys(e).some((f)=>!s.includes(f)&&!Me.includes(f)))throw new r("invalid_display_request","Reason desktop request is malformed.");let d="video"in e?Ro(e.video):void 0,t="viewer"in e?$n(e.viewer):null,c="look"in e?Mn(e.look):null;if(d===null)throw new r("invalid_display_request","Reason desktop video request is invalid.");let n=null;try{n=typeof e.relay_url==="string"?new URL(e.relay_url):null}catch{}if(!n||n.protocol!=="wss:"&&n.protocol!=="ws:"||n.username||n.password)throw new r("invalid_display_request","Reason desktop relay URL is invalid.");if(typeof e.session_id!=="string"||!_e.test(e.session_id))throw new r("invalid_display_request","Reason desktop session identity is invalid.");let o=typeof e.expires_at==="string"?Date.parse(e.expires_at):Number.NaN;if(!Number.isFinite(o)||o<=D)throw new r("invalid_display_request","Reason desktop session has already expired.");return{relay_url:e.relay_url,session_id:e.session_id,expires_at:new Date(Math.min(o,D+Te)).toISOString(),...d?{video:d}:{},...t?{viewer:t}:{},...d&&e.viewer_same_network===!0?{viewer_same_network:!0}:{},...c?{look:c}:{}}}function Ft(e=process.platform){return(e==="linux"||e==="darwin"||e==="win32")&&x()?.features.display===!0}async function Vs(){if(process.platform==="win32")return Ft()&&await Rr();if(process.platform!=="darwin")return Ft();return await Rr()}function G(e){Qe(e,{recursive:!0,mode:448});let D=Je(e);if(!D.isDirectory()||D.isSymbolicLink()||process.getuid&&D.uid!==process.getuid())throw new r("display_unavailable","Reason desktop state directory is not private.");he(e,448)}function ve(e,D){let s=(t)=>{let c=Buffer.alloc(2);return c.writeUInt16BE(t.length),Buffer.concat([c,t])},d=Buffer.from([255,255]);return Buffer.concat([d,s(Buffer.alloc(0)),s(Buffer.from(e)),s(Buffer.from("MIT-MAGIC-COOKIE-1")),s(D)])}function y(e,D,s=2000){return new Promise((d)=>{let t=Se(e),c="",n=(o)=>{t.destroy(),d(o)};t.setTimeout(s,()=>n(!1)),t.once("error",()=>n(!1)),t.once("close",()=>n(!1)),t.once("connect",()=>{if(!D)n(!0)}),t.on("data",(o)=>{if(c+=o.toString("latin1"),c.length>=4)n(c.startsWith("RFB "))})})}async function Q(e,D){let s=Date.now()+D;while(Date.now()<s){if(await e())return!0;await new Promise((d)=>setTimeout(d,100))}return!1}function g(e,D,s){return new Promise((d)=>{let t=ne(e,D,{detached:!0,stdio:"ignore",env:s});t.once("error",()=>d(-1)),t.once("exit",(c)=>d(c)),t.unref(),setTimeout(()=>d(null),P).unref()})}var J=null;function qe(e=a()){return J??=Ze(e).finally(()=>{J=null}),J}async function Ze(e){let D=x({home:e});if(!D?.xvfb||!D.x11vnc||!D.openbox)throw new r("display_unavailable","Run `reason desktop install` on this machine to enable its desktop.");Pt({root:D.root,automation:D.automation,extensionDir:D.extensionDir});let s=I(D.root,"display");G(s);let d=await We(e,s,D.x11vnc);if(d)return d;let t={display:A,xauthority:I(s,"Xauthority"),rfbSocket:I(s,"rfb.sock")},c=I(s,"pulse"),n=(async()=>{try{G(c)}catch{return null}return await go(c,D.pulseaudio)})();G(I(s,"home"));let o=S(s,t,D.pulseaudio),f=async()=>({...t,sound:await n});if(await y({path:t.rfbSocket},!0))return be(I(s,"theme"),N,o),await f();if(!ae(t.xauthority))u(t.xauthority,ve(A.slice(1),Oe(16)),{mode:384,flag:"wx"});let i=T(I(s,"theme"),t.display,R,e),X={path:`/tmp/.X11-unix/X${A.slice(1)}`};if(!await y(X,!1)){let p=`${R.width}x${R.height}`;if(D.xvnc)ie(t.rfbSocket,{force:!0}),g(D.xvnc,[t.display,"-geometry",p,"-depth","24","-nolisten","tcp","-auth",t.xauthority,"-rfbport","-1","-rfbunixpath",t.rfbSocket,"-SecurityTypes","None","-UseBlacklist=0","-AlwaysShared","-desktop","Reason"],o);else g(D.xvfb,[t.display,"-screen","0",`${p}x24`,"-nolisten","tcp","-auth",t.xauthority],o);if(!await Q(()=>y(X,!1),P)||D.xvnc&&!await Q(()=>y({path:t.rfbSocket},!0),P))throw new r("display_unavailable","Reason could not start the virtual display.");g(D.openbox,["--config-file",i.openboxConfig],o)}if(await k(i,o),!await fe(D.x11vnc,t,s,"x11vnc.log",o))throw new r("display_unavailable","Reason could not start the desktop server.");return await f()}function S(e,D,s){let d={HOME:I(e,"home"),PATH:"/usr/local/bin:/usr/bin:/bin",DISPLAY:D.display,XAUTHORITY:D.xauthority};if(s)d.PULSE_SERVER=Ve(Tn(I(e,"pulse")));return d}async function fe(e,D,s,d,t){if(await y({path:D.rfbSocket},!0))return!0;ie(D.rfbSocket,{force:!0});let c=await g(e,["-display",D.display,"-auth",D.xauthority,"-rfbport","0","-rfbportv6","-1","-unixsock",D.rfbSocket,"-nopw","-forever","-shared","-noxdamage","-sb","0","-rfbversion","3.7","-quiet","-bg","-o",I(s,d)],t);if(c!==null&&c!==0)return!1;return await Q(()=>y({path:D.rfbSocket},!0),P)}async function ze(){let e=["DISPLAY","XAUTHORITY","WAYLAND_DISPLAY","XDG_SESSION_TYPE"],D=(s)=>Object.fromEntries(e.flatMap((d)=>s[d]?[[d,s[d]]]:[]));if(process.env.DISPLAY)return D(process.env);try{let s=await new Promise((d,t)=>ce("systemctl",["--user","show-environment"],{encoding:"utf8",timeout:2000},(c,n)=>c?t(c):d(n)));return D(Object.fromEntries(s.split(`
144
+ `),n=(p)=>s?p.replace("/tmp/ara-dock-","/tmp/ara-grok-dock-"):p,o=t?$e.replace(/^Exec=.*$/m,`Exec=${t}`).replace("Categories=System;FileManager;","Categories=Utility;Viewer;"):$e,f=s?"ara-grok-wallpaper.jpg":"ara-wallpaper.jpg",i={"openbox/rc.xml":Ye(e.screen),"tint2/tint2rc":D(c),"picom/picom.conf":Re,...d.has("terminal")?{}:{"ara-terminal.desktop":D(n(Fe))},...d.has("files")?{}:{"ara-files.desktop":D(n(o))},"ara-chromium.desktop":D(n(Ke)).replace("chromium --no-sandbox %U",e.browserExec),"ara-set-root-wallpaper.py":Ce},X=[...N.slice(0,3),Ge,`[ ! -f "$ROOT/${f}" ] || set_wallpaper "$ROOT/${f}" "$ROOT/ara-set-root-wallpaper.py" || true`,'if alive tint2 && ! cmp -s "$ROOT/tint2/tint2rc" "$ROOT/tint2/applied"; then read -r pid _ <"$ROOT/tint2.pid"; kill -USR1 "$pid" 2>/dev/null || true; fi','cp "$ROOT/tint2/tint2rc" "$ROOT/tint2/applied" 2>/dev/null || true',...N.slice(3)];return{files:i,start:X}}var N=['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"; }','if [ -f "$ROOT/tint2/tint2rc" ] && ! alive tint2 && command -v tint2 >/dev/null 2>&1; then launch tint2 tint2 -c "$ROOT/tint2/tint2rc"; fi','if [ -f "$ROOT/picom/picom.conf" ] && ! alive picom && command -v picom >/dev/null 2>&1; then launch picom picom --config "$ROOT/picom/picom.conf"; fi'];var Te=43200000,A=":99",ke=60000,P=15000,R={width:1280,height:800},_e=/^[A-Za-z0-9._:-]{1,160}$/;function we(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}var Me=["video","viewer","viewer_same_network","viewer_network","look"];function me(e,D=Date.now()){let s=["relay_url","session_id","expires_at"];if(!we(e)||s.some((f)=>!(f in e))||Object.keys(e).some((f)=>!s.includes(f)&&!Me.includes(f)))throw new r("invalid_display_request","Reason desktop request is malformed.");let d="video"in e?To(e.video):void 0,t="viewer"in e?$n(e.viewer):null,c="look"in e?Mn(e.look):null;if(d===null)throw new r("invalid_display_request","Reason desktop video request is invalid.");let n=null;try{n=typeof e.relay_url==="string"?new URL(e.relay_url):null}catch{}if(!n||n.protocol!=="wss:"&&n.protocol!=="ws:"||n.username||n.password)throw new r("invalid_display_request","Reason desktop relay URL is invalid.");if(typeof e.session_id!=="string"||!_e.test(e.session_id))throw new r("invalid_display_request","Reason desktop session identity is invalid.");let o=typeof e.expires_at==="string"?Date.parse(e.expires_at):Number.NaN;if(!Number.isFinite(o)||o<=D)throw new r("invalid_display_request","Reason desktop session has already expired.");return{relay_url:e.relay_url,session_id:e.session_id,expires_at:new Date(Math.min(o,D+Te)).toISOString(),...d?{video:d}:{},...t?{viewer:t}:{},...d&&e.viewer_same_network===!0?{viewer_same_network:!0}:{},...c?{look:c}:{}}}function Ft(e=process.platform){return(e==="linux"||e==="darwin"||e==="win32")&&x()?.features.display===!0}async function Vs(){if(process.platform==="win32")return Ft()&&await Rr();if(process.platform!=="darwin")return Ft();return await Rr()}function G(e){Qe(e,{recursive:!0,mode:448});let D=Je(e);if(!D.isDirectory()||D.isSymbolicLink()||process.getuid&&D.uid!==process.getuid())throw new r("display_unavailable","Reason desktop state directory is not private.");he(e,448)}function ve(e,D){let s=(t)=>{let c=Buffer.alloc(2);return c.writeUInt16BE(t.length),Buffer.concat([c,t])},d=Buffer.from([255,255]);return Buffer.concat([d,s(Buffer.alloc(0)),s(Buffer.from(e)),s(Buffer.from("MIT-MAGIC-COOKIE-1")),s(D)])}function y(e,D,s=2000){return new Promise((d)=>{let t=Se(e),c="",n=(o)=>{t.destroy(),d(o)};t.setTimeout(s,()=>n(!1)),t.once("error",()=>n(!1)),t.once("close",()=>n(!1)),t.once("connect",()=>{if(!D)n(!0)}),t.on("data",(o)=>{if(c+=o.toString("latin1"),c.length>=4)n(c.startsWith("RFB "))})})}async function Q(e,D){let s=Date.now()+D;while(Date.now()<s){if(await e())return!0;await new Promise((d)=>setTimeout(d,100))}return!1}function g(e,D,s){return new Promise((d)=>{let t=ne(e,D,{detached:!0,stdio:"ignore",env:s});t.once("error",()=>d(-1)),t.once("exit",(c)=>d(c)),t.unref(),setTimeout(()=>d(null),P).unref()})}var J=null;function qe(e=a()){return J??=Ze(e).finally(()=>{J=null}),J}async function Ze(e){let D=x({home:e});if(!D?.xvfb||!D.x11vnc||!D.openbox)throw new r("display_unavailable","Run `reason desktop install` on this machine to enable its desktop.");Pt({root:D.root,automation:D.automation,extensionDir:D.extensionDir});let s=I(D.root,"display");G(s);let d=await We(e,s,D.x11vnc);if(d)return d;let t={display:A,xauthority:I(s,"Xauthority"),rfbSocket:I(s,"rfb.sock")},c=I(s,"pulse"),n=(async()=>{try{G(c)}catch{return null}return await _o(c,D.pulseaudio)})();G(I(s,"home"));let o=S(s,t,D.pulseaudio),f=async()=>({...t,sound:await n});if(await y({path:t.rfbSocket},!0))return be(I(s,"theme"),N,o),await f();if(!ae(t.xauthority))u(t.xauthority,ve(A.slice(1),Oe(16)),{mode:384,flag:"wx"});let i=T(I(s,"theme"),t.display,R,e),X={path:`/tmp/.X11-unix/X${A.slice(1)}`};if(!await y(X,!1)){let p=`${R.width}x${R.height}`;if(D.xvnc)ie(t.rfbSocket,{force:!0}),g(D.xvnc,[t.display,"-geometry",p,"-depth","24","-nolisten","tcp","-auth",t.xauthority,"-rfbport","-1","-rfbunixpath",t.rfbSocket,"-SecurityTypes","None","-UseBlacklist=0","-AlwaysShared","-desktop","Reason"],o);else g(D.xvfb,[t.display,"-screen","0",`${p}x24`,"-nolisten","tcp","-auth",t.xauthority],o);if(!await Q(()=>y(X,!1),P)||D.xvnc&&!await Q(()=>y({path:t.rfbSocket},!0),P))throw new r("display_unavailable","Reason could not start the virtual display.");g(D.openbox,["--config-file",i.openboxConfig],o)}if(await k(i,o),!await fe(D.x11vnc,t,s,"x11vnc.log",o))throw new r("display_unavailable","Reason could not start the desktop server.");return await f()}function S(e,D,s){let d={HOME:I(e,"home"),PATH:"/usr/local/bin:/usr/bin:/bin",DISPLAY:D.display,XAUTHORITY:D.xauthority};if(s)d.PULSE_SERVER=Ve(Tn(I(e,"pulse")));return d}async function fe(e,D,s,d,t){if(await y({path:D.rfbSocket},!0))return!0;ie(D.rfbSocket,{force:!0});let c=await g(e,["-display",D.display,"-auth",D.xauthority,"-rfbport","0","-rfbportv6","-1","-unixsock",D.rfbSocket,"-nopw","-forever","-shared","-noxdamage","-sb","0","-rfbversion","3.7","-quiet","-bg","-o",I(s,d)],t);if(c!==null&&c!==0)return!1;return await Q(()=>y({path:D.rfbSocket},!0),P)}async function ze(){let e=["DISPLAY","XAUTHORITY","WAYLAND_DISPLAY","XDG_SESSION_TYPE"],D=(s)=>Object.fromEntries(e.flatMap((d)=>s[d]?[[d,s[d]]]:[]));if(process.env.DISPLAY)return D(process.env);try{let s=await new Promise((d,t)=>ce("systemctl",["--user","show-environment"],{encoding:"utf8",timeout:2000},(c,n)=>c?t(c):d(n)));return D(Object.fromEntries(s.split(`
145
145
  `).flatMap((d)=>{let t=d.indexOf("=");return t>0?[[d.slice(0,t),d.slice(t+1)]]:[]})))}catch{return{}}}var se=new Set;async function We(e,D,s){let d=await ze(),t=/^:(\d+)(?:\.\d+)?$/.exec(d.DISPLAY??"")?.[1];if(!t||`:${t}`===A||d.WAYLAND_DISPLAY||d.XDG_SESSION_TYPE==="wayland")return null;let c={display:`:${t}`,xauthority:d.XAUTHORITY??I(e,".Xauthority"),rfbSocket:I(D,`rfb-${t}.sock`)},n=`${c.display} ${c.xauthority}`;if(se.has(n)||!await y({path:`/tmp/.X11-unix/X${t}`},!1))return null;let o={HOME:e,PATH:"/usr/local/bin:/usr/bin:/bin",DISPLAY:c.display,XAUTHORITY:c.xauthority};if(await fe(s,c,D,`x11vnc-${t}.log`,o))return{...c,sound:null};return se.add(n),process.stderr.write(`Reason worker: your screen ${c.display} could not be served; using the virtual desktop
146
146
  `),null}var Ie="look";function pe(e){try{return Mn(oe(I(e,Ie),"utf8").trim())??"reason"}catch{return"reason"}}function T(e,D,s,d,t=pe(e)){let c=`chromium --no-first-run --no-default-browser-check${process.geteuid?.()===0?" --no-sandbox":""} %U`,n=[["terminal","xterm"],["files","pcmanfm"]].filter(([,i])=>!ae(`/usr/bin/${i}`)).map(([i])=>i),o=`${c.replace(/ %U$/,"")} --app=file://${I(d,".reason","workspace")}/`,f=de({root:e,display:D,screen:s,browserExec:c,absent:n,look:t,filesViewerExec:o});for(let i of["","openbox","tint2","picom"])G(I(e,i));u(I(e,Ie),`${t}
147
147
  `,{mode:384});for(let[i,X]of Object.entries(f.files))u(I(e,i),X,{mode:384});for(let[i,X]of Object.entries(te))u(I(e,`ara-${i}`),oe(X),{mode:384});return{root:e,openboxConfig:I(e,"openbox","rc.xml"),start:f.start}}function k(e,D){return be(e.root,[...e.start,"openbox --reconfigure >/dev/null 2>&1 || true"],D)}function be(e,D,s){let d=[`ROOT=${JSON.stringify(e)}`,...D].join(`
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{U}from"./vm-hands-entry-lite-a0g6c3wr.js";import{O,T,b}from"./vm-hands-entry-lite-06e9xm3v.js";import{je,gr,_r,Sn,En,ct}from"./vm-hands-entry-lite-kpahnwm7.js";import{$r}from"./vm-hands-entry-lite-zwnevt4c.js";import{p,ut,An,_e,we}from"./vm-hands-entry-lite-yj9hbtm1.js";import{v,h}from"./vm-hands-entry-lite-k2kx2ex0.js";import{a,nr,qo}from"./vm-hands-entry-lite-gmxfz6k2.js";import{an,y,t,k,o,d,ms,Ie,Bi,u,i,W,g,ee,s,n,cn}from"./vm-hands-entry-lite-bjtcy8n6.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{se,A}from"./vm-hands-entry-lite-q13ekwev.js";import{randomUUID as Q}from"crypto";import{spawn as Le}from"child_process";import{existsSync as Z,lstatSync as me,mkdirSync as We,readFileSync as Ne,realpathSync as G,rmSync as Ve,writeFileSync as He}from"fs";import{dirname as Ue,join as j,relative as qe,sep as Je}from"path";var Se=["process.run.v1","process.full.v1"],xe=600000,Pe=1800000,Ee=20000,ne="process.cancel.v1",ie=i({action:n("start"),request_id:t().uuid(),command:t().min(1).max(16000).refine((e)=>!e.includes("\x00")),cwd:t().min(1).max(4096).refine((e)=>!e.includes("\x00")&&!e.startsWith("/")&&!e.split(/[\\/]/).includes("..")).describe("Path relative to the granted device root; omit to use that root. Must not start with /, contain a .. path segment, or contain a NUL character.").optional(),mode:s(["host","confined"]).default("host"),timeout_ms:o().int().min(1000).max(Pe).default(xe).describe("Absolute process budget including queue and startup time. Defaults to ten minutes; longer explicit requests require the selected root's advertised max_timeout_ms. Retrying never renews the deadline.")}).strict(),K={device_id:t().uuid(),root_id:t().uuid()},Re=g("action",[ie.extend(K),i({...K,action:n("inspect"),process_id:t().uuid(),after:o().int().min(0).default(0),wait_ms:o().int().min(0).max(Ee).default(0).describe("Wait for new output or a state change, bounded by this call's wait budget. Expiring this wait does not cancel the process or extend its deadline.")}).strict(),i({...K,action:n("cancel"),process_id:t().uuid()}).strict()]),Fe=an(Re,{io:"input"}),Ke=ie.extend({process_brain_fence:t().uuid(),process_expires_at:y.datetime()}).strict(),J=i({version:n(1),process_id:t().uuid(),state:s(["starting","running","exited","cancelled","expired","uncertain"]),exit_code:o().int().nullable(),first_cursor:o().int().min(0),next_cursor:o().int().min(0),truncated:d(),observed_at:y.datetime(),output:u(i({cursor:o().int().min(1),stream:s(["stdout","stderr"]),text:t().max(32768)}).strict()).max(128)}).strict().refine((e)=>{if(Buffer.byteLength(JSON.stringify(e))>1e5||e.next_cursor<e.first_cursor-1)return!1;if((e.state==="starting"||e.state==="running"||e.state==="uncertain")&&e.exit_code!==null)return!1;if(e.state==="exited"&&(e.exit_code===null||e.exit_code<0||e.exit_code>255))return!1;if(e.state==="cancelled"&&e.exit_code!==130||e.state==="expired"&&e.exit_code!==124)return!1;let _=e.first_cursor-1;for(let l of e.output){if(l.cursor<=_||l.cursor>e.next_cursor)return!1;_=l.cursor}return!0});function ae(e){return Se.includes(e)}var Xe=i({operation_constraints:ee(t(),Ie())}),Ye=i({ready:n(!0),version:n(1),execution_mode:s(["host","confined"]),max_timeout_ms:o().int().min(1000).optional()});var De=i({version:n(1),process_id:t().uuid(),state:s(["queued","cancelled_before_start","not_started"]),exit_code:ms(),output:u(Bi()).length(0),first_cursor:n(0),next_cursor:n(0),truncated:n(!1),cancellation_requested:n(!1),reason_code:s(["cancelled_before_start","process_journal_capacity","path_not_found","process_timeout_unsupported"]).optional(),expires_at:y.datetime().optional().describe("Accepted absolute process deadline. Reading, waiting and retrying do not extend it.")}).strict(),Ce=i({...J.shape,state:s(["queued","starting","running","exited","cancelled","expired","uncertain","cancelled_before_start","not_started"]),observed_at:y.datetime().optional(),expires_at:y.datetime().optional().describe("Accepted absolute process deadline. Reading, waiting and retrying do not extend it."),cancellation_requested:d(),reason_code:t().nullable().optional(),execution_authority:n("lost").optional().describe("Historical receipt only; the current Brain cannot control this older-generation process."),recovery:i({cause:n("brain_generation_changed"),terminal_confirmed:d(),next_step:s(["inspect_until_terminal","reconcile_effects_before_new_intent"])}).strict().optional().describe("Historical process recovery only. An unconfirmed outcome forbids replay. A confirmed terminal observation proves the old process stopped, not that its command had no effects. Reconcile the result; only restart still-needed, safely repeatable work with a new request_id and current authority. Respect user cancellation."),last_observed_state:J.shape.state.or(n("cancelled_before_start")).nullable().optional().describe("Last saved observation before authority was lost; a running observation does not establish current child liveness.")}).strict(),$e=an(Ce),Qe=W([J,De.refine((e)=>e.state==="cancelled_before_start")]),X=i({version:n(1),process_id:t().uuid(),state:s(["exited","cancelled","expired"]),exit_code:o().int().min(0).max(255),observed_at:y.datetime()}).strict().refine((e)=>(e.state!=="cancelled"||e.exit_code===130)&&(e.state!=="expired"||e.exit_code===124)),Ze=i({process_terminal_observation:X}).strict();var Ji="preview.serve.v1",Xi=43200000;var ce="preview.open.v1",de=1,_n="gid_proxy_v1",Yi="egress",yn=/^(?:\*\.)?[a-z0-9](?:[a-z0-9.-]{0,251}[a-z0-9])?(?::[1-9][0-9]{0,4})?$/,Ae=i({version:n(_n),allowed_domains:u(t().max(260).regex(yn)).max(1024)}).strict(),ke=cn((e)=>U(e)!==null,"invalid workspace"),Oe=i({version:n(1),request_id:k(),session_id:k(),command:t().min(1).max(16000).refine((e)=>!e.includes("\x00")),port:o().int().min(1024).max(65535),workspace:ke,egress:Ae.optional()}).strict(),Zi=Oe.extend({expires_at:y.datetime()}).strict();var Me=4,Te=5000;function Y(e,c,_){let l=null;try{l=ut(e)}catch{}An({deviceRelayUrl:l?.deviceRelayUrl??"",binding:l?.binding??null,jobId:c,port:l?.binding.port??0,reason:l?_:"binding_invalid"})}function le(e){let c=new Map;return{open(_){let l=(x)=>Y(_,e.claim.operation_id,x),I;try{I=ut(_)}catch{return l("binding_invalid")}let{binding:w,deviceRelayUrl:z}=I,E=e.claim.owner;if(!E||w.organizationId!==E.organization_id||w.userId!==E.user_id||w.deviceId!==E.device_id||w.rootId!==e.claim.root_id||w.jobId!==e.claim.operation_id||w.fenceId!==e.claim.operation_id||w.generation!==de||w.expiresAtMs>Math.min(Date.now()+p.lifetimeMs+Te,e.expiresAtMs))return l("binding_mismatch");if(w.expiresAtMs<=Date.now())return l("binding_expired");if(c.get(w.port)?.abort(),c.delete(w.port),c.size>=Me)return l("preview_capacity");let L=new AbortController;c.set(w.port,L);let P=we({binding:w,deniedPorts:e.deniedPorts,readCurrentJob:async()=>{if(L.signal.aborted)return null;let x=await e.inspect();return x?{binding:w,executorLaunchId:e.executorLaunchId,job:x}:null}});_e({binding:w,deviceRelayUrl:z,port:P,signal:L.signal}).then((x)=>x.closed,(x)=>{let R=x instanceof Error?x.message:"preview_failed";if(R!=="preview_not_authorized")process.stderr.write(`${JSON.stringify({event:"worker_preview.open_failed",job_id:w.jobId,port:w.port,reason_code:R})}
3
- `)}).finally(()=>{if(c.get(w.port)===L)c.delete(w.port)})},dispose(){for(let _ of c.values())_.abort();c.clear()}}}class st extends r{observation;constructor(e){super("process_authority_lost","Process authority was lost; the owned process group has stopped.");this.observation=e}}var fe=256,B=new Map,he="preview.serve.v1",V=new Map;function be(e){let c=V.get(e.operation_id);if(c){if(c.claim!==e)throw C("process_authority_lost");return c}if(V.size>=fe)throw C("process_journal_capacity");let _={claim:e,executing:!1,cancelRequested:!1,phase:"pending"};return V.set(e.operation_id,_),_}function pe(e){return{version:1,process_id:e,state:"cancelled_before_start",exit_code:null,output:[],first_cursor:0,next_cursor:0,truncated:!1,cancellation_requested:!1,reason_code:"cancelled_before_start"}}var ue=(e)=>new Promise((c)=>setTimeout(c,e)),C=(e="process_outcome_uncertain")=>new r(e,"The managed process outcome could not be confirmed; inspect its saved receipt before starting another intent.");function ze(e=a(),c=Ge()){let _=Ue($r({},e)),l=qe(nr(e),_),[I,...w]=l.split(Je);return{directory:j(c,l,"processes"),previous:[j(_,"processes"),...I==="reason"?[j(c,"ara",...w,"processes")]:[]]}}function Ge(){if(process.platform!=="darwin")throw new r("process_unavailable","Managed Mac process execution is unavailable.");let e=qo();if(!e)throw new r("process_unavailable","The private per-user process directory is unavailable.");return e}async function fr(e){if(!e.claim.owner||e.signal.aborted||e.expiresAtMs<=Date.now())throw C("process_authority_lost");let c=be(e.claim);if(c.executing)throw C("process_busy");if(c.executing=!0,c.cancelRequested)return c.phase="settling",pe(e.claim.operation_id);c.phase="starting";let _=e.journals??ze();We(_.directory,{recursive:!0,mode:448});let l=gr({runtimeDirectory:G(_.directory),previousRuntimeDirectories:(_.previous??[]).filter((m)=>Z(m)).map((m)=>G(m)),root:e.root,runId:JSON.stringify([e.claim.owner,e.claim.run_id,e.claim.root_id,e.claim.operation_id]),maxScopes:fe});try{for(let m of[e.root,e.cwd])if(!je(G(m),l.journalDirectory))throw new r("process_journal_inside_workspace","The selected root contains the private process journal. Select an existing narrower granted workspace root outside the journal; no command was dispatched.")}catch(m){throw l.disposeSocket(),m}let I=me(l.journalDirectory),w=e.claim.capability===he,z=()=>B.set(e.claim.operation_id,{path:l.journalDirectory,ino:I.ino,dev:I.dev,anyCompletion:w}),E=l.launchDirectory,L=j(E,"config.json"),P={url:"",transport:"local_job_ipc",directShell:{mode:e.mode,executable:e.shell,jobId:e.claim.operation_id},workerVersion:O,protocolVersion:2,workerArtifactSha256:b,workerEntrypoint:T,targetGeneration:1,fenceId:Q(),...process.platform==="win32"?{bashExecutable:se()}:{},workRoot:e.root,workspaceAliasPath:e.root,repoPath:e.cwd,jobEnvPath:j(E,"unused.env"),replSocketPath:j(E,"unused.sock"),readyPath:j(E,"ready.json"),directTerminalReceiptPath:j(E,"terminal.json"),launchId:Q(),expiresAtMs:e.expiresAtMs+5000,bashTimeoutMs:60000,replTimeoutMs:1000,allowedTools:["bash"],managedJobs:{journalDirectory:l.journalDirectory,scopeId:l.scopeId},jobControlSocketPath:l.socketPath,...e.prefix?{bashCommandPrefix:e.prefix}:{},...e.jobsUser?{jobsUser:e.jobsUser}:{}},x;try{He(L,JSON.stringify(P),{mode:384});let m=Sn({configPath:L,root:e.cwd,grantedRoot:e.root,workRoot:e.root,temporaryDirectory:E});x=e.spawnWorker?.(L,P)??Le(m.command,m.args,{...m.options,env:e.environment,stdio:[En,"ignore","ignore"]})}catch(m){throw l.disposeSocket(),m}let R=!1,F=new Promise((m,S)=>{x.once("exit",(f)=>{R=!0,m(f)}),x.once("error",(f)=>{R=!0,S(f)})});F.catch(()=>{});let ge={root:e.root,runId:e.claim.run_id,scopeId:l.scopeId,socketPath:l.socketPath,generation:1,fenceId:P.fenceId,executorLaunchId:P.launchId,expiresAtMs:P.expiresAtMs},N=async(m)=>{let S=await _r(ge,{type:"job",version:2,generation:1,id:Q(),jobId:e.claim.operation_id,...m==="start"?{action:m,input:{script:e.command,leaseExpiresAtMs:e.expiresAtMs}}:m==="inspect"?{action:m,input:{after:0}}:m==="probe"?{action:"inspect",input:{after:Number.MAX_SAFE_INTEGER}}:{action:m,input:{}}},new AbortController().signal);if(!S.ok)throw C(S.error);return S.job},H=!1,q=!1,te,re=()=>{H=!0,ct(x,"SIGTERM")};e.signal.addEventListener("abort",re,{once:!0});let M,oe=0,ve=async(m)=>{let S=[...m.output],f={version:1,process_id:e.claim.operation_id,state:m.state,exit_code:m.exitCode,first_cursor:m.firstCursor,next_cursor:m.nextCursor,truncated:m.truncated,output:S,observed_at:new Date().toISOString()};while(Buffer.byteLength(JSON.stringify(f))>90000&&S.length)S.shift(),f.truncated=!0,f.first_cursor=S[0]?.cursor??f.next_cursor+1;M=J.parse(f),await e.emit(M),oe=Date.now()};try{let m=Math.min(Date.now()+1e4,e.expiresAtMs);while(!Z(P.readyPath)){if(R)throw new r("process_start_failed","The managed process supervisor exited before accepting a command; no command was dispatched.");if(e.signal.aborted||Date.now()>=m)throw C("process_start_unconfirmed");await ue(25)}let S=JSON.parse(Ne(P.readyPath,"utf8"));if(S.launchId!==P.launchId||S.fenceId!==P.fenceId||S.workerArtifactSha256!==b)throw C();if(e.signal.throwIfAborted(),c.cancelRequested)return pe(e.claim.operation_id);let f;try{q=!0,f=await N("start")}catch(D){if(!(D instanceof r)||D.code!=="hands_job_result_unknown")throw D;f=await N("inspect")}if(c.phase="running",c.cancel=async()=>{await N("cancel")},w&&e.preview)c.tunnels=le({claim:e.claim,executorLaunchId:P.launchId,expiresAtMs:e.expiresAtMs,deniedPorts:e.preview.deniedPorts,inspect:async()=>c.phase==="running"&&!R?await N("probe"):null});if(c.cancelRequested)await c.cancel(),f=await N("inspect");for(;;){if(!["starting","running"].includes(f.state))c.phase="settling",c.cancel=void 0;if(!M||M.state!==f.state||M.next_cursor!==f.nextCursor&&Date.now()-oe>=5000)await ve(f);if(!["starting","running"].includes(f.state))break;if(e.signal.aborted||R)throw C();await ue(1000);try{f=await N("inspect"),te=void 0}catch(D){if(!(D instanceof r)||D.code!=="hands_job_result_unknown"||e.signal.aborted||R||Date.now()-(te??=Date.now())>120000)throw D}}if(!M||M.state==="uncertain")throw C();return M}finally{if(c.phase="settling",c.cancel=void 0,c.tunnels?.dispose(),c.tunnels=void 0,await c.cancelInFlight?.catch(()=>{}),e.signal.removeEventListener("abort",re),!R&&!H)ct(x,"SIGTERM");let m,S=await Promise.race([F.then((f)=>({code:f})),new Promise((f)=>{m=setTimeout(()=>f(null),6000)})]).finally(()=>{clearTimeout(m)});if(!S){try{ct(x,"SIGKILL")}catch{}try{await F}finally{if(R)l.disposeSocket()}throw C("process_cleanup_unconfirmed")}try{if((H||e.signal.aborted)&&S.code===0&&q){v(E);let f=JSON.parse(h(P.directTerminalReceiptPath)),D=X.safeParse(f.observation);if(Object.keys(f).length===4&&f.launch_id===P.launchId&&f.fence_id===P.fenceId&&f.scope_id===l.scopeId&&D.success&&D.data.process_id===e.claim.operation_id){if(w)z();throw new st(D.data)}}}catch(f){if(f instanceof st)throw f}finally{if(R)l.disposeSocket()}if(S.code!==0&&!H&&q)throw C("process_cleanup_unconfirmed");if(!H&&S.code===0&&(M&&["exited","cancelled","expired"].includes(M.state)||!q&&c.cancelRequested)||w&&S.code===0&&!q)z()}}async function js(e,c){if(c.kind===ce&&e.capability===he){let I=V.get(e.operation_id);if(I?.claim===e&&I.tunnels)I.tunnels.open(c.payload);else Y(c.payload,e.operation_id,"server_not_running");return!0}if(c.kind!==ne||!ae(e.capability)||!e.owner||c.payload.process_id!==e.operation_id)return!1;let _=V.get(e.operation_id);if(_&&_.claim!==e)return!1;let l=be(e);if(l.cancelRequested=!0,l.phase==="running"&&l.cancel)l.cancelInFlight??=l.cancel(),await l.cancelInFlight;return!0}function Hs(e,c){V.delete(e);let _=B.get(e);if(!_||c!=="succeeded"&&!_.anyCompletion)return B.delete(e),!1;try{let l=me(_.path);if(!l.isDirectory()||l.isSymbolicLink()||l.ino!==_.ino||l.dev!==_.dev||!A(l)||G(_.path)!==_.path||Z(j(_.path,"owner.lock")))return!1;return Ve(_.path,{recursive:!0}),B.delete(e),!0}catch{return!1}}
4
- export{Ji,Xi,_n,Yi,yn,Zi,st,fr,js,Hs};
2
+ import{U}from"./vm-hands-entry-lite-a0g6c3wr.js";import{O,T,b}from"./vm-hands-entry-lite-4r1yn35v.js";import{je,gr,_r,Sn,En,ct}from"./vm-hands-entry-lite-r2msq3z0.js";import{$r}from"./vm-hands-entry-lite-cgddp0y3.js";import{p,ut,An,_e,we}from"./vm-hands-entry-lite-2hfrcr50.js";import{v,h}from"./vm-hands-entry-lite-hfx1q0b0.js";import{a,nr,Wo}from"./vm-hands-entry-lite-jvszqt0z.js";import{an,y,t,k,o,d,ms,Ie,Bi,u,i,W,g,ee,s,n,cn}from"./vm-hands-entry-lite-ztsp4gs8.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{se,A}from"./vm-hands-entry-lite-b6gsggvp.js";import{randomUUID as Q}from"crypto";import{spawn as Le}from"child_process";import{existsSync as Z,lstatSync as me,mkdirSync as We,readFileSync as Ne,realpathSync as G,rmSync as Ve,writeFileSync as He}from"fs";import{dirname as Ue,join as j,relative as qe,sep as Je}from"path";var Se=["process.run.v1","process.full.v1"],xe=600000,Pe=1800000,Ee=20000,ne="process.cancel.v1",ie=i({action:n("start"),request_id:t().uuid(),command:t().min(1).max(16000).refine((e)=>!e.includes("\x00")),cwd:t().min(1).max(4096).refine((e)=>!e.includes("\x00")&&!e.startsWith("/")&&!e.split(/[\\/]/).includes("..")).describe("Path relative to the granted device root; omit to use that root. Must not start with /, contain a .. path segment, or contain a NUL character.").optional(),mode:s(["host","confined"]).default("host"),timeout_ms:o().int().min(1000).max(Pe).default(xe).describe("Absolute process budget including queue and startup time. Defaults to ten minutes; longer explicit requests require the selected root's advertised max_timeout_ms. Retrying never renews the deadline.")}).strict(),K={device_id:t().uuid(),root_id:t().uuid()},Re=g("action",[ie.extend(K),i({...K,action:n("inspect"),process_id:t().uuid(),after:o().int().min(0).default(0),wait_ms:o().int().min(0).max(Ee).default(0).describe("Wait for new output or a state change, bounded by this call's wait budget. Expiring this wait does not cancel the process or extend its deadline.")}).strict(),i({...K,action:n("cancel"),process_id:t().uuid()}).strict()]),Fe=an(Re,{io:"input"}),Ke=ie.extend({process_brain_fence:t().uuid(),process_expires_at:y.datetime()}).strict(),J=i({version:n(1),process_id:t().uuid(),state:s(["starting","running","exited","cancelled","expired","uncertain"]),exit_code:o().int().nullable(),first_cursor:o().int().min(0),next_cursor:o().int().min(0),truncated:d(),observed_at:y.datetime(),output:u(i({cursor:o().int().min(1),stream:s(["stdout","stderr"]),text:t().max(32768)}).strict()).max(128)}).strict().refine((e)=>{if(Buffer.byteLength(JSON.stringify(e))>1e5||e.next_cursor<e.first_cursor-1)return!1;if((e.state==="starting"||e.state==="running"||e.state==="uncertain")&&e.exit_code!==null)return!1;if(e.state==="exited"&&(e.exit_code===null||e.exit_code<0||e.exit_code>255))return!1;if(e.state==="cancelled"&&e.exit_code!==130||e.state==="expired"&&e.exit_code!==124)return!1;let _=e.first_cursor-1;for(let l of e.output){if(l.cursor<=_||l.cursor>e.next_cursor)return!1;_=l.cursor}return!0});function ae(e){return Se.includes(e)}var Xe=i({operation_constraints:ee(t(),Ie())}),Ye=i({ready:n(!0),version:n(1),execution_mode:s(["host","confined"]),max_timeout_ms:o().int().min(1000).optional()});var De=i({version:n(1),process_id:t().uuid(),state:s(["queued","cancelled_before_start","not_started"]),exit_code:ms(),output:u(Bi()).length(0),first_cursor:n(0),next_cursor:n(0),truncated:n(!1),cancellation_requested:n(!1),reason_code:s(["cancelled_before_start","process_journal_capacity","path_not_found","process_timeout_unsupported"]).optional(),expires_at:y.datetime().optional().describe("Accepted absolute process deadline. Reading, waiting and retrying do not extend it.")}).strict(),Ce=i({...J.shape,state:s(["queued","starting","running","exited","cancelled","expired","uncertain","cancelled_before_start","not_started"]),observed_at:y.datetime().optional(),expires_at:y.datetime().optional().describe("Accepted absolute process deadline. Reading, waiting and retrying do not extend it."),cancellation_requested:d(),reason_code:t().nullable().optional(),execution_authority:n("lost").optional().describe("Historical receipt only; the current Brain cannot control this older-generation process."),recovery:i({cause:n("brain_generation_changed"),terminal_confirmed:d(),next_step:s(["inspect_until_terminal","reconcile_effects_before_new_intent"])}).strict().optional().describe("Historical process recovery only. An unconfirmed outcome forbids replay. A confirmed terminal observation proves the old process stopped, not that its command had no effects. Reconcile the result; only restart still-needed, safely repeatable work with a new request_id and current authority. Respect user cancellation."),last_observed_state:J.shape.state.or(n("cancelled_before_start")).nullable().optional().describe("Last saved observation before authority was lost; a running observation does not establish current child liveness.")}).strict(),$e=an(Ce),Qe=W([J,De.refine((e)=>e.state==="cancelled_before_start")]),X=i({version:n(1),process_id:t().uuid(),state:s(["exited","cancelled","expired"]),exit_code:o().int().min(0).max(255),observed_at:y.datetime()}).strict().refine((e)=>(e.state!=="cancelled"||e.exit_code===130)&&(e.state!=="expired"||e.exit_code===124)),Ze=i({process_terminal_observation:X}).strict();var Xi="preview.serve.v1",Yi=43200000;var ce="preview.open.v1",de=1,_n="gid_proxy_v1",Zi="egress",yn=/^(?:\*\.)?[a-z0-9](?:[a-z0-9.-]{0,251}[a-z0-9])?(?::[1-9][0-9]{0,4})?$/,Ae=i({version:n(_n),allowed_domains:u(t().max(260).regex(yn)).max(1024)}).strict(),ke=cn((e)=>U(e)!==null,"invalid workspace"),Oe=i({version:n(1),request_id:k(),session_id:k(),command:t().min(1).max(16000).refine((e)=>!e.includes("\x00")),port:o().int().min(1024).max(65535),workspace:ke,egress:Ae.optional()}).strict(),Qi=Oe.extend({expires_at:y.datetime()}).strict();var Me=4,Te=5000;function Y(e,c,_){let l=null;try{l=ut(e)}catch{}An({deviceRelayUrl:l?.deviceRelayUrl??"",binding:l?.binding??null,jobId:c,port:l?.binding.port??0,reason:l?_:"binding_invalid"})}function le(e){let c=new Map;return{open(_){let l=(x)=>Y(_,e.claim.operation_id,x),I;try{I=ut(_)}catch{return l("binding_invalid")}let{binding:w,deviceRelayUrl:z}=I,E=e.claim.owner;if(!E||w.organizationId!==E.organization_id||w.userId!==E.user_id||w.deviceId!==E.device_id||w.rootId!==e.claim.root_id||w.jobId!==e.claim.operation_id||w.fenceId!==e.claim.operation_id||w.generation!==de||w.expiresAtMs>Math.min(Date.now()+p.lifetimeMs+Te,e.expiresAtMs))return l("binding_mismatch");if(w.expiresAtMs<=Date.now())return l("binding_expired");if(c.get(w.port)?.abort(),c.delete(w.port),c.size>=Me)return l("preview_capacity");let L=new AbortController;c.set(w.port,L);let P=we({binding:w,deniedPorts:e.deniedPorts,readCurrentJob:async()=>{if(L.signal.aborted)return null;let x=await e.inspect();return x?{binding:w,executorLaunchId:e.executorLaunchId,job:x}:null}});_e({binding:w,deviceRelayUrl:z,port:P,signal:L.signal}).then((x)=>x.closed,(x)=>{let R=x instanceof Error?x.message:"preview_failed";if(R!=="preview_not_authorized")process.stderr.write(`${JSON.stringify({event:"worker_preview.open_failed",job_id:w.jobId,port:w.port,reason_code:R})}
3
+ `)}).finally(()=>{if(c.get(w.port)===L)c.delete(w.port)})},dispose(){for(let _ of c.values())_.abort();c.clear()}}}class st extends r{observation;constructor(e){super("process_authority_lost","Process authority was lost; the owned process group has stopped.");this.observation=e}}var fe=256,B=new Map,he="preview.serve.v1",V=new Map;function be(e){let c=V.get(e.operation_id);if(c){if(c.claim!==e)throw C("process_authority_lost");return c}if(V.size>=fe)throw C("process_journal_capacity");let _={claim:e,executing:!1,cancelRequested:!1,phase:"pending"};return V.set(e.operation_id,_),_}function pe(e){return{version:1,process_id:e,state:"cancelled_before_start",exit_code:null,output:[],first_cursor:0,next_cursor:0,truncated:!1,cancellation_requested:!1,reason_code:"cancelled_before_start"}}var ue=(e)=>new Promise((c)=>setTimeout(c,e)),C=(e="process_outcome_uncertain")=>new r(e,"The managed process outcome could not be confirmed; inspect its saved receipt before starting another intent.");function ze(e=a(),c=Ge()){let _=Ue($r({},e)),l=qe(nr(e),_),[I,...w]=l.split(Je);return{directory:j(c,l,"processes"),previous:[j(_,"processes"),...I==="reason"?[j(c,"ara",...w,"processes")]:[]]}}function Ge(){if(process.platform!=="darwin")throw new r("process_unavailable","Managed Mac process execution is unavailable.");let e=Wo();if(!e)throw new r("process_unavailable","The private per-user process directory is unavailable.");return e}async function fr(e){if(!e.claim.owner||e.signal.aborted||e.expiresAtMs<=Date.now())throw C("process_authority_lost");let c=be(e.claim);if(c.executing)throw C("process_busy");if(c.executing=!0,c.cancelRequested)return c.phase="settling",pe(e.claim.operation_id);c.phase="starting";let _=e.journals??ze();We(_.directory,{recursive:!0,mode:448});let l=gr({runtimeDirectory:G(_.directory),previousRuntimeDirectories:(_.previous??[]).filter((m)=>Z(m)).map((m)=>G(m)),root:e.root,runId:JSON.stringify([e.claim.owner,e.claim.run_id,e.claim.root_id,e.claim.operation_id]),maxScopes:fe,folders:[e.root,e.cwd]});try{for(let m of[e.root,e.cwd])if(!je(G(m),l.journalDirectory))throw new r("process_journal_inside_workspace","The selected root contains the private process journal. Select an existing narrower granted workspace root outside the journal; no command was dispatched.")}catch(m){throw l.disposeSocket(),m}let I=me(l.journalDirectory),w=e.claim.capability===he,z=()=>B.set(e.claim.operation_id,{path:l.journalDirectory,ino:I.ino,dev:I.dev,anyCompletion:w}),E=l.launchDirectory,L=j(E,"config.json"),P={url:"",transport:"local_job_ipc",directShell:{mode:e.mode,executable:e.shell,jobId:e.claim.operation_id},workerVersion:O,protocolVersion:2,workerArtifactSha256:b,workerEntrypoint:T,targetGeneration:1,fenceId:Q(),...process.platform==="win32"?{bashExecutable:se()}:{},workRoot:e.root,workspaceAliasPath:e.root,repoPath:e.cwd,jobEnvPath:j(E,"unused.env"),replSocketPath:j(E,"unused.sock"),readyPath:j(E,"ready.json"),directTerminalReceiptPath:j(E,"terminal.json"),launchId:Q(),expiresAtMs:e.expiresAtMs+5000,bashTimeoutMs:60000,replTimeoutMs:1000,allowedTools:["bash"],managedJobs:{journalDirectory:l.journalDirectory,scopeId:l.scopeId},jobControlSocketPath:l.socketPath,...e.prefix?{bashCommandPrefix:e.prefix}:{},...e.jobsUser?{jobsUser:e.jobsUser}:{}},x;try{He(L,JSON.stringify(P),{mode:384});let m=Sn({configPath:L,root:e.cwd,grantedRoot:e.root,workRoot:e.root,temporaryDirectory:E});x=e.spawnWorker?.(L,P)??Le(m.command,m.args,{...m.options,env:e.environment,stdio:[En,"ignore","ignore"]})}catch(m){throw l.disposeSocket(),m}let R=!1,F=new Promise((m,S)=>{x.once("exit",(f)=>{R=!0,m(f)}),x.once("error",(f)=>{R=!0,S(f)})});F.catch(()=>{});let ge={root:e.root,runId:e.claim.run_id,scopeId:l.scopeId,socketPath:l.socketPath,generation:1,fenceId:P.fenceId,executorLaunchId:P.launchId,expiresAtMs:P.expiresAtMs},N=async(m)=>{let S=await _r(ge,{type:"job",version:2,generation:1,id:Q(),jobId:e.claim.operation_id,...m==="start"?{action:m,input:{script:e.command,leaseExpiresAtMs:e.expiresAtMs}}:m==="inspect"?{action:m,input:{after:0}}:m==="probe"?{action:"inspect",input:{after:Number.MAX_SAFE_INTEGER}}:{action:m,input:{}}},new AbortController().signal);if(!S.ok)throw C(S.error);return S.job},H=!1,q=!1,te,re=()=>{H=!0,ct(x,"SIGTERM")};e.signal.addEventListener("abort",re,{once:!0});let M,oe=0,ve=async(m)=>{let S=[...m.output],f={version:1,process_id:e.claim.operation_id,state:m.state,exit_code:m.exitCode,first_cursor:m.firstCursor,next_cursor:m.nextCursor,truncated:m.truncated,output:S,observed_at:new Date().toISOString()};while(Buffer.byteLength(JSON.stringify(f))>90000&&S.length)S.shift(),f.truncated=!0,f.first_cursor=S[0]?.cursor??f.next_cursor+1;M=J.parse(f),await e.emit(M),oe=Date.now()};try{let m=Math.min(Date.now()+1e4,e.expiresAtMs);while(!Z(P.readyPath)){if(R)throw new r("process_start_failed","The managed process supervisor exited before accepting a command; no command was dispatched.");if(e.signal.aborted||Date.now()>=m)throw C("process_start_unconfirmed");await ue(25)}let S=JSON.parse(Ne(P.readyPath,"utf8"));if(S.launchId!==P.launchId||S.fenceId!==P.fenceId||S.workerArtifactSha256!==b)throw C();if(e.signal.throwIfAborted(),c.cancelRequested)return pe(e.claim.operation_id);let f;try{q=!0,f=await N("start")}catch(D){if(!(D instanceof r)||D.code!=="hands_job_result_unknown")throw D;f=await N("inspect")}if(c.phase="running",c.cancel=async()=>{await N("cancel")},w&&e.preview)c.tunnels=le({claim:e.claim,executorLaunchId:P.launchId,expiresAtMs:e.expiresAtMs,deniedPorts:e.preview.deniedPorts,inspect:async()=>c.phase==="running"&&!R?await N("probe"):null});if(c.cancelRequested)await c.cancel(),f=await N("inspect");for(;;){if(!["starting","running"].includes(f.state))c.phase="settling",c.cancel=void 0;if(!M||M.state!==f.state||M.next_cursor!==f.nextCursor&&Date.now()-oe>=5000)await ve(f);if(!["starting","running"].includes(f.state))break;if(e.signal.aborted||R)throw C();await ue(1000);try{f=await N("inspect"),te=void 0}catch(D){if(!(D instanceof r)||D.code!=="hands_job_result_unknown"||e.signal.aborted||R||Date.now()-(te??=Date.now())>120000)throw D}}if(!M||M.state==="uncertain")throw C();return M}finally{if(c.phase="settling",c.cancel=void 0,c.tunnels?.dispose(),c.tunnels=void 0,await c.cancelInFlight?.catch(()=>{}),e.signal.removeEventListener("abort",re),!R&&!H)ct(x,"SIGTERM");let m,S=await Promise.race([F.then((f)=>({code:f})),new Promise((f)=>{m=setTimeout(()=>f(null),6000)})]).finally(()=>{clearTimeout(m)});if(!S){try{ct(x,"SIGKILL")}catch{}try{await F}finally{if(R)l.disposeSocket()}throw C("process_cleanup_unconfirmed")}try{if((H||e.signal.aborted)&&S.code===0&&q){v(E);let f=JSON.parse(h(P.directTerminalReceiptPath)),D=X.safeParse(f.observation);if(Object.keys(f).length===4&&f.launch_id===P.launchId&&f.fence_id===P.fenceId&&f.scope_id===l.scopeId&&D.success&&D.data.process_id===e.claim.operation_id){if(w)z();throw new st(D.data)}}}catch(f){if(f instanceof st)throw f}finally{if(R)l.disposeSocket()}if(S.code!==0&&!H&&q)throw C("process_cleanup_unconfirmed");if(!H&&S.code===0&&(M&&["exited","cancelled","expired"].includes(M.state)||!q&&c.cancelRequested)||w&&S.code===0&&!q)z()}}async function js(e,c){if(c.kind===ce&&e.capability===he){let I=V.get(e.operation_id);if(I?.claim===e&&I.tunnels)I.tunnels.open(c.payload);else Y(c.payload,e.operation_id,"server_not_running");return!0}if(c.kind!==ne||!ae(e.capability)||!e.owner||c.payload.process_id!==e.operation_id)return!1;let _=V.get(e.operation_id);if(_&&_.claim!==e)return!1;let l=be(e);if(l.cancelRequested=!0,l.phase==="running"&&l.cancel)l.cancelInFlight??=l.cancel(),await l.cancelInFlight;return!0}function Hs(e,c){V.delete(e);let _=B.get(e);if(!_||c!=="succeeded"&&!_.anyCompletion)return B.delete(e),!1;try{let l=me(_.path);if(!l.isDirectory()||l.isSymbolicLink()||l.ino!==_.ino||l.dev!==_.dev||!A(l)||G(_.path)!==_.path||Z(j(_.path,"owner.lock")))return!1;return Ve(_.path,{recursive:!0}),B.delete(e),!0}catch{return!1}}
4
+ export{Xi,Yi,_n,Zi,yn,Qi,st,fr,js,Hs};
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{A}from"./vm-hands-entry-lite-q13ekwev.js";import{randomUUID as m}from"crypto";import{closeSync as k,constants as c,fstatSync as u,lstatSync as s,mkdirSync as l,openSync as E,readFileSync as S,realpathSync as a,renameSync as g,unlinkSync as p,writeFileSync as O}from"fs";import{dirname as w,resolve as _}from"path";var d=65536;function f(r){try{return s(r),!0}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")return!1;throw o}}function v(r,o=!1){if(!f(r)){if(!o)throw Error("worker_state_missing");y(r),l(r,{mode:448})}let e=s(r);if(!e.isDirectory()||e.isSymbolicLink()||!A(e)||a(r)!==_(r))throw Error("worker_state_directory_not_private_or_canonical")}function y(r){let o=w(r);if(!f(o))y(o),l(o,{mode:448});if(a(o)!==_(o))throw Error("worker_parent_not_canonical")}function h(r,o=d){let e=E(r,c.O_RDONLY|c.O_NOFOLLOW);try{let n=u(e);if(!n.isFile()||n.nlink!==1||!A(n)||n.size>o)throw Error("worker_file_not_private");return S(e,"utf8")}finally{k(e)}}function fo(r,o,e=d){let n=JSON.stringify(o);if(n===void 0)throw Error("worker_file_invalid");let t=n+`
2
+ import{A}from"./vm-hands-entry-lite-b6gsggvp.js";import{randomUUID as m}from"crypto";import{closeSync as k,constants as c,fstatSync as u,lstatSync as s,mkdirSync as l,openSync as E,readFileSync as S,realpathSync as a,renameSync as g,unlinkSync as p,writeFileSync as O}from"fs";import{dirname as w,resolve as _}from"path";var d=65536;function f(r){try{return s(r),!0}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")return!1;throw o}}function v(r,o=!1){if(!f(r)){if(!o)throw Error("worker_state_missing");y(r),l(r,{mode:448})}let e=s(r);if(!e.isDirectory()||e.isSymbolicLink()||!A(e)||a(r)!==_(r))throw Error("worker_state_directory_not_private_or_canonical")}function y(r){let o=w(r);if(!f(o))y(o),l(o,{mode:448});if(a(o)!==_(o))throw Error("worker_parent_not_canonical")}function h(r,o=d){let e=E(r,c.O_RDONLY|c.O_NOFOLLOW);try{let n=u(e);if(!n.isFile()||n.nlink!==1||!A(n)||n.size>o)throw Error("worker_file_not_private");return S(e,"utf8")}finally{k(e)}}function mo(r,o,e=d){let n=JSON.stringify(o);if(n===void 0)throw Error("worker_file_invalid");let t=n+`
3
3
  `;if(Buffer.byteLength(t,"utf8")>e)throw Error("worker_file_too_large");if(v(w(r)),f(r))h(r,e);let i=`${r}.${m()}`;try{O(i,t,{mode:384,flag:"wx"}),g(i,r)}finally{if(f(i))p(i)}}
4
- export{f,v,h,fo};
4
+ export{f,v,h,mo};