@reason-machines/cli-linux-x64 0.2.566 → 0.2.567

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 (123) hide show
  1. package/bin/reason +1 -1
  2. package/bin/vm-hands/agent-network-0sng03r6.js +2 -0
  3. package/bin/vm-hands/api-credentials-h4neeejt.js +2 -0
  4. package/bin/vm-hands/api-mr6xds10.js +2 -0
  5. package/bin/vm-hands/{ask-relay-gk4ks8mg.js → ask-relay-c0v30hh6.js} +2 -2
  6. package/bin/vm-hands/connect-cli-jc4m755k.js +2 -0
  7. package/bin/vm-hands/credentials-nfx99zxr.js +2 -0
  8. package/bin/vm-hands/custom-endpoint-device-5047vdn3.js +2 -0
  9. package/bin/vm-hands/desktop-account-d1g1m6yb.js +2 -0
  10. package/bin/vm-hands/desktop-components-7ngf8byq.js +2 -0
  11. package/bin/vm-hands/desktop-delegate-4hb0163k.js +2 -0
  12. package/bin/vm-hands/device-workspace-8941tdsy.js +2 -0
  13. package/bin/vm-hands/{fsevents-ezcg3e40.js → fsevents-e57jgcfe.js} +1 -1
  14. package/bin/vm-hands/hands-worker-source-8a4kh44t.js +2 -0
  15. package/bin/vm-hands/{index-w92ys6ra.js → index-y21r07rf.js} +8 -8
  16. package/bin/vm-hands/install-receipt-rckwjqmt.js +2 -0
  17. package/bin/vm-hands/local-automation-3mdhfw08.js +2 -0
  18. package/bin/vm-hands/local-capabilities-6e0gkrqq.js +2 -0
  19. package/bin/vm-hands/local-desktop-users-hkdfxqtj.js +2 -0
  20. package/bin/vm-hands/local-display-mac-gsh74khc.js +2 -0
  21. package/bin/vm-hands/local-display-session-r6s0wghh.js +2 -0
  22. package/bin/vm-hands/local-display-video-61peg1pj.js +2 -0
  23. package/bin/vm-hands/local-managed-process-p8xd7m5f.js +2 -0
  24. package/bin/vm-hands/local-pty-session-w0yhjdvz.js +2 -0
  25. package/bin/vm-hands/managed-runtime-4s8q8r7f.js +2 -0
  26. package/bin/vm-hands/{network-auto-update-qwds22kt.js → network-auto-update-wep7067g.js} +2 -2
  27. package/bin/vm-hands/network-contract-ht0psj5j.js +2 -0
  28. package/bin/vm-hands/{network-sign-in-kqdg70kc.js → network-sign-in-rdnerhpz.js} +2 -2
  29. package/bin/vm-hands/package-3rv6jngd.js +2 -0
  30. package/bin/vm-hands/permissions-mmg1gbdx.js +2 -0
  31. package/bin/vm-hands/reason-hands-protocol-9r62swp0.js +2 -0
  32. package/bin/vm-hands/serve-service-k3mpxpj6.js +2 -0
  33. package/bin/vm-hands/{status-q55nprve.js → status-2s3zjapg.js} +5 -5
  34. package/bin/vm-hands/version-41q9twfs.js +2 -0
  35. package/bin/vm-hands/{vm-hands-entry-lite-pg7nnyc6.js → vm-hands-entry-lite-04nx5y4f.js} +2 -2
  36. package/bin/vm-hands/{vm-hands-entry-lite-ezhfkjqr.js → vm-hands-entry-lite-07wr95rz.js} +3 -3
  37. package/bin/vm-hands/{vm-hands-entry-lite-33at6g06.js → vm-hands-entry-lite-0xfme8gg.js} +2 -2
  38. package/bin/vm-hands/{vm-hands-entry-lite-xfak34av.js → vm-hands-entry-lite-1as6h9ed.js} +4 -4
  39. package/bin/vm-hands/{vm-hands-entry-lite-gxf2r5en.js → vm-hands-entry-lite-1cdtev4n.js} +1 -1
  40. package/bin/vm-hands/{vm-hands-entry-lite-fn2805g8.js → vm-hands-entry-lite-1sy80ca9.js} +2 -2
  41. package/bin/vm-hands/{vm-hands-entry-lite-yg4dk99m.js → vm-hands-entry-lite-2927z566.js} +1 -1
  42. package/bin/vm-hands/{vm-hands-entry-lite-6adz91f3.js → vm-hands-entry-lite-298kzt93.js} +70 -70
  43. package/bin/vm-hands/{vm-hands-entry-lite-3q2ng4e9.js → vm-hands-entry-lite-3594pdj0.js} +2 -2
  44. package/bin/vm-hands/{vm-hands-entry-lite-rz1ep81m.js → vm-hands-entry-lite-3r063pb4.js} +2 -2
  45. package/bin/vm-hands/{vm-hands-entry-lite-2qfmabqn.js → vm-hands-entry-lite-4kb5rq3d.js} +3 -3
  46. package/bin/vm-hands/{vm-hands-entry-lite-5qrft0nw.js → vm-hands-entry-lite-6g9we34r.js} +3 -3
  47. package/bin/vm-hands/{vm-hands-entry-lite-s93f3pbv.js → vm-hands-entry-lite-732hnx41.js} +3 -3
  48. package/bin/vm-hands/vm-hands-entry-lite-7aeqbfc8.js +3 -0
  49. package/bin/vm-hands/{vm-hands-entry-lite-y0jtj8zz.js → vm-hands-entry-lite-8twdd0ff.js} +1 -1
  50. package/bin/vm-hands/{vm-hands-entry-lite-x6ybft9v.js → vm-hands-entry-lite-9gn7k5rp.js} +5 -5
  51. package/bin/vm-hands/{vm-hands-entry-lite-b2w5071h.js → vm-hands-entry-lite-ax2w9ywb.js} +3 -3
  52. package/bin/vm-hands/{vm-hands-entry-lite-2gxv7v1h.js → vm-hands-entry-lite-b3mfma12.js} +4 -4
  53. package/bin/vm-hands/{vm-hands-entry-lite-qjrgvdbj.js → vm-hands-entry-lite-bbjsnjct.js} +21 -21
  54. package/bin/vm-hands/{vm-hands-entry-lite-zp7chzcc.js → vm-hands-entry-lite-bc9zq8gx.js} +1 -1
  55. package/bin/vm-hands/{vm-hands-entry-lite-ngry8nkq.js → vm-hands-entry-lite-bqs4pkyb.js} +4 -4
  56. package/bin/vm-hands/{vm-hands-entry-lite-zpvr7wc6.js → vm-hands-entry-lite-bt6skt4h.js} +2 -2
  57. package/bin/vm-hands/{vm-hands-entry-lite-q62g6sx0.js → vm-hands-entry-lite-chve4vmh.js} +2 -2
  58. package/bin/vm-hands/{vm-hands-entry-lite-72h3t64b.js → vm-hands-entry-lite-crjaacc2.js} +2 -2
  59. package/bin/vm-hands/{vm-hands-entry-lite-fs6jbfp3.js → vm-hands-entry-lite-cy8yc9gb.js} +19 -19
  60. package/bin/vm-hands/{vm-hands-entry-lite-30z7wsqr.js → vm-hands-entry-lite-dfphra23.js} +3 -3
  61. package/bin/vm-hands/{vm-hands-entry-lite-a3gq377t.js → vm-hands-entry-lite-dh87ysh2.js} +2 -2
  62. package/bin/vm-hands/{vm-hands-entry-lite-994kah8n.js → vm-hands-entry-lite-dtw6cj95.js} +2 -2
  63. package/bin/vm-hands/{vm-hands-entry-lite-a8z57vry.js → vm-hands-entry-lite-dzdjwa06.js} +1 -1
  64. package/bin/vm-hands/{vm-hands-entry-lite-chq0qx9f.js → vm-hands-entry-lite-g0bpdyfz.js} +2 -2
  65. package/bin/vm-hands/{vm-hands-entry-lite-rxydyqke.js → vm-hands-entry-lite-h7f5a5mb.js} +2 -2
  66. package/bin/vm-hands/{vm-hands-entry-lite-13nx02p7.js → vm-hands-entry-lite-hh0kba1y.js} +4 -4
  67. package/bin/vm-hands/{vm-hands-entry-lite-fccn6s4j.js → vm-hands-entry-lite-hpe54h0b.js} +2 -2
  68. package/bin/vm-hands/{vm-hands-entry-lite-kbnxk71q.js → vm-hands-entry-lite-hpw27zfb.js} +2 -2
  69. package/bin/vm-hands/{vm-hands-entry-lite-284z7ct8.js → vm-hands-entry-lite-kankyeep.js} +2 -2
  70. package/bin/vm-hands/{vm-hands-entry-lite-9wp7ahwa.js → vm-hands-entry-lite-n5jyzccm.js} +4 -4
  71. package/bin/vm-hands/{vm-hands-entry-lite-88dxn9b5.js → vm-hands-entry-lite-peyr9y6z.js} +2 -2
  72. package/bin/vm-hands/{vm-hands-entry-lite-cmmb9k3g.js → vm-hands-entry-lite-r131db1f.js} +2 -2
  73. package/bin/vm-hands/{vm-hands-entry-lite-72084j3g.js → vm-hands-entry-lite-rmcdfbkk.js} +24 -24
  74. package/bin/vm-hands/{vm-hands-entry-lite-1b21avcs.js → vm-hands-entry-lite-sb1xtqxr.js} +2 -2
  75. package/bin/vm-hands/{vm-hands-entry-lite-b1vanmtv.js → vm-hands-entry-lite-sxnvhzy5.js} +4 -4
  76. package/bin/vm-hands/{vm-hands-entry-lite-cc8hwgxc.js → vm-hands-entry-lite-t2rhwchw.js} +3 -3
  77. package/bin/vm-hands/{vm-hands-entry-lite-sh4mqy93.js → vm-hands-entry-lite-t3k90kdn.js} +3 -3
  78. package/bin/vm-hands/{vm-hands-entry-lite-bkhc5mt4.js → vm-hands-entry-lite-tv5mcw97.js} +6 -6
  79. package/bin/vm-hands/{vm-hands-entry-lite-12ck5swp.js → vm-hands-entry-lite-tzv8s0e7.js} +1 -1
  80. package/bin/vm-hands/{vm-hands-entry-lite-50kqbrb7.js → vm-hands-entry-lite-vedb5r12.js} +4 -4
  81. package/bin/vm-hands/{vm-hands-entry-lite-jj7873n8.js → vm-hands-entry-lite-vha0pf8k.js} +2 -2
  82. package/bin/vm-hands/{vm-hands-entry-lite-fxptf351.js → vm-hands-entry-lite-vvhfaxpd.js} +5 -5
  83. package/bin/vm-hands/{vm-hands-entry-lite-3gc2bn5a.js → vm-hands-entry-lite-wtjqjvea.js} +2 -2
  84. package/bin/vm-hands/{vm-hands-entry-lite-p02vay5n.js → vm-hands-entry-lite-xd393rm3.js} +5 -5
  85. package/bin/vm-hands/{vm-hands-entry-lite-z65xva21.js → vm-hands-entry-lite-ys4jhf7n.js} +2 -2
  86. package/bin/vm-hands/{vm-hands-entry-lite-ttfqxjms.js → vm-hands-entry-lite-zaj1vnnd.js} +9 -9
  87. package/bin/vm-hands/vm-hands-entry-lite.js +2 -2
  88. package/bin/vm-hands/{vm-hands-executor-r6v6tzqj.js → vm-hands-executor-31ea40aw.js} +4 -4
  89. package/bin/vm-hands/{vm-hands-op-runner-wcbc42nw.js → vm-hands-op-runner-6r390v3d.js} +1 -1
  90. package/bin/vm-hands/{vm-hands-runtime-2t08ywa4.js → vm-hands-runtime-z9m50n9p.js} +3 -3
  91. package/bin/vm-hands/worker-preview-readiness-w4zy5g2p.js +2 -0
  92. package/bin/vm-hands/worker-sandbox-2trfs79b.js +2 -0
  93. package/package.json +1 -1
  94. package/bin/vm-hands/agent-network-pak3wvrv.js +0 -2
  95. package/bin/vm-hands/api-credentials-a433ykxs.js +0 -2
  96. package/bin/vm-hands/api-kex52g1d.js +0 -2
  97. package/bin/vm-hands/connect-cli-afdc1h11.js +0 -2
  98. package/bin/vm-hands/credentials-sk4sag42.js +0 -2
  99. package/bin/vm-hands/custom-endpoint-device-3jscber1.js +0 -2
  100. package/bin/vm-hands/desktop-account-xma0330a.js +0 -2
  101. package/bin/vm-hands/desktop-components-y89gpa6e.js +0 -2
  102. package/bin/vm-hands/desktop-delegate-tch2qzx0.js +0 -2
  103. package/bin/vm-hands/device-workspace-4bj43nxq.js +0 -2
  104. package/bin/vm-hands/hands-worker-source-8pe7yv0m.js +0 -2
  105. package/bin/vm-hands/install-receipt-68xxg7hn.js +0 -2
  106. package/bin/vm-hands/local-automation-1s7035zm.js +0 -2
  107. package/bin/vm-hands/local-capabilities-h1hxzrhn.js +0 -2
  108. package/bin/vm-hands/local-desktop-users-jpf0resr.js +0 -2
  109. package/bin/vm-hands/local-display-mac-h5yz0ydd.js +0 -2
  110. package/bin/vm-hands/local-display-session-0vw1x2k6.js +0 -2
  111. package/bin/vm-hands/local-display-video-k4bgptc7.js +0 -2
  112. package/bin/vm-hands/local-managed-process-b79p5wwv.js +0 -2
  113. package/bin/vm-hands/local-pty-session-tqn2xmph.js +0 -2
  114. package/bin/vm-hands/managed-runtime-9jfx2885.js +0 -2
  115. package/bin/vm-hands/network-contract-nkwcf4r9.js +0 -2
  116. package/bin/vm-hands/package-9w0mmxb5.js +0 -2
  117. package/bin/vm-hands/permissions-q9nfdxrh.js +0 -2
  118. package/bin/vm-hands/reason-hands-protocol-pck5har9.js +0 -2
  119. package/bin/vm-hands/serve-service-hcc0zvg8.js +0 -2
  120. package/bin/vm-hands/version-7q2ft41r.js +0 -2
  121. package/bin/vm-hands/vm-hands-entry-lite-997y1m1r.js +0 -3
  122. package/bin/vm-hands/worker-preview-readiness-h96yr4wf.js +0 -2
  123. package/bin/vm-hands/worker-sandbox-6kkhvryn.js +0 -2
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{mkdirSync as R,readdirSync as A,readFileSync as k,realpathSync as x}from"fs";import{userInfo as E}from"os";var zn="--vm-hands-op-runner-kind=person",qn="--vm-hands-op-runner-kind=surface",Wr="--vm-hands-surface-uid=",Vr="--vm-hands-surface-dir=",C="/sys/fs/cgroup/reason-person/desktop",Gr=new Set(["automation.call.v1","display.stream.v1","preview.serve.v1"]);function D(t){let a=new Set([t]),l=[];try{l=A("/proc")}catch{}for(let n of l){if(!/^\d+$/.test(n))continue;try{let o=k(`/proc/${n}/stat`,"utf8");if(Number(o.slice(o.lastIndexOf(")")+2).split(" ")[3])===t)a.add(Number(n))}catch{}}for(let n of a)try{process.kill(n,"SIGKILL")}catch{}}var H=(t)=>{let a=globalThis.Bun;if(!a)throw new r("pty_unavailable","Reason terminals require the Bun runtime.");let l=a.spawn({cmd:[t.shell,...t.args],cwd:t.cwd,env:{...t.environment,TERM:"xterm-256color"},terminal:{cols:t.cols,rows:t.rows,data:(c,d)=>t.onData(d)}}),n=l.terminal,o=()=>{D(l.pid);try{n?.close()}catch{}};if(!n)throw o(),new r("pty_unavailable","Reason could not allocate a pseudo-terminal.");return{write:(c)=>n.write(c),resize:(c,d)=>n.resize(c,d),kill:o,exited:l.exited.then((c)=>typeof c==="number"?c:null,()=>null)}};function O(){let t=(()=>{try{return E().username}catch{return}})();return{PATH:process.env.PATH,HOME:process.env.HOME,SHELL:process.env.SHELL,LANG:"C.UTF-8",...t?{USER:t,LOGNAME:t}:{}}}async function L(t){let[{localAutomationAvailable:a},{localDisplayReady:l},{localDisplayVideoAvailable:n},{probeWorkerPreview:o},m]=await Promise.all([import("./local-automation-1s7035zm.js"),import("./local-display-session-0vw1x2k6.js"),import("./local-display-video-k4bgptc7.js"),import("./worker-preview-readiness-h96yr4wf.js"),import("fs")]),c=AbortSignal.timeout(15000),d=null;try{m.mkdirSync(t,{recursive:!0,mode:448}),d=m.mkdtempSync(`${t}/probe-`);let[w,u,v]=await Promise.all([Promise.resolve().then(()=>a()).catch(()=>!1),l().catch(()=>!1),o(d,c).catch(()=>!1)]);return{t:"readiness",display_video:u&&await n().catch(()=>!1),lanes:{"automation.call.v1":w,"display.stream.v1":u,"preview.serve.v1":v,"tunnel.open":v,"tunnel.close":v}}}finally{if(d)m.rmSync(d,{recursive:!0,force:!0})}}function N(t){let a="";try{a=k("/proc/self/cgroup","utf8").split(`
3
- `).find((o)=>o.startsWith("0::"))?.slice(3)??""}catch{return null}if(!/^\/reason-person\/vm-hands\/[A-Za-z0-9._-]+$/.test(a))return null;if(!t)return null;let l=[t.xvnc,t.xvfb,t.openbox,t.x11vnc,t.pulseaudio,t.browser,"/usr/bin/dbus-daemon","/bin/dbus-daemon"].flatMap((o)=>{try{return o?[x(o)]:[]}catch{return[]}}),n={join:`/sys/fs/cgroup${a}/desktop`,keep:C,programs:[...new Set(l)]};for(let o of[n.join,n.keep])try{R(o,{mode:493})}catch(m){if(m.code!=="EEXIST")return null}return n}async function hl(){let[{executeLocalOperation:t,spawnCaptured:a},{runLocalPtySession:l},{configureDesktopAccount:n,desktopAccount:o},{configureWorkerSandbox:m},{configureDesktopPlacement:c},{readDesktopComponents:d}]=await Promise.all([import("./local-capabilities-h1hxzrhn.js"),import("./local-pty-session-tqn2xmph.js"),import("./desktop-account-xma0330a.js"),import("./worker-sandbox-6kkhvryn.js"),import("./desktop-delegate-tch2qzx0.js"),import("./desktop-components-y89gpa6e.js")]);m();let w=process.argv.includes(zn),u=process.argv.includes(qn),v=(i,e,p)=>a(i,e[0]==="-lic"?["-lc",...e.slice(1)]:e,p),y=(process.geteuid?.()??0)!==0;if(u){y=!1;let i=process.argv.find((e)=>e.startsWith(Wr))?.slice(Wr.length);if((process.geteuid?.()??-1)===0&&i)try{y=n({value:i})!==null&&o()!==null}catch{y=!1}}let S=new Map,_=new Map,f=(i)=>{try{process.send?.(i)}catch{}};if(u&&y){let i=o()?.home,e=i?N(d({home:i})):null;c(e&&{...e,log:(p,g)=>f({t:"log",event:p,fields:g})})}if(process.on("message",(i)=>{let e=i;if(e?.t==="cancel"){S.get(e.id)?.abort();return}if(e?.t==="control"){let s=_.get(e.id);if(u&&s&&e.control&&typeof e.control.kind==="string")import("./local-managed-process-b79p5wwv.js").then(({controlManagedDeviceProcess:h})=>h(s,{kind:e.control.kind,payload:e.control.payload??{}})).catch(()=>!1);return}if(e?.t==="retire"){if(u&&typeof e.operation_id==="string"&&typeof e.status==="string")import("./local-managed-process-b79p5wwv.js").then(({retireManagedDeviceProcess:s})=>s(e.operation_id,e.status)).catch(()=>!1);return}if(e?.t!=="op")return;if(!y){f({t:"done",id:e.id,completion:{status:"failed",error_code:"vm_hands_payload_account_unavailable"}});return}let p=e.claim.capability;if(p==="pty.start"&&!w){f({t:"done",id:e.id,completion:{status:"failed",error_code:"capability_not_granted"}});return}if(Gr.has(p)!==u){f({t:"done",id:e.id,completion:{status:"failed",error_code:"capability_not_granted"}});return}let g=new AbortController;S.set(e.id,g),_.set(e.id,e.claim);let b=p==="pty.start"?{runPtySession:(s)=>l(s,{spawnPty:H,environment:O(),loadProxy:()=>null})}:{worker:e.worker,...p==="exec.full"?{spawnFullControl:v}:{}};t(e.state,e.claim,{...b,signal:g.signal,emit:(s)=>{let{deliverySignal:h,...P}=s;f({t:"event",id:e.id,event:P})}}).then((s)=>f({t:"done",id:e.id,completion:s}),(s)=>f({t:"done",id:e.id,completion:{status:"failed",error_code:s&&typeof s==="object"&&"code"in s&&typeof s.code==="string"?s.code:"vm_hands_op_failed"}})).finally(()=>{S.delete(e.id),_.delete(e.id)})}),process.on("disconnect",()=>process.exit(0)),u){let i=process.argv.find((p)=>p.startsWith(Vr))?.slice(Vr.length),e={t:"readiness",display_video:!1,lanes:{}};f(y&&i?await L(i).catch(()=>e):e)}await new Promise(()=>{})}
4
- export{zn,qn,Wr,Vr,Gr,hl};
2
+ import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{mkdirSync as R,readdirSync as A,readFileSync as k,realpathSync as x}from"fs";import{userInfo as E}from"os";var qn="--vm-hands-op-runner-kind=person",Wn="--vm-hands-op-runner-kind=surface",Wr="--vm-hands-surface-uid=",Vr="--vm-hands-surface-dir=",C="/sys/fs/cgroup/reason-person/desktop",Gr=new Set(["automation.call.v1","display.stream.v1","preview.serve.v1"]);function D(t){let a=new Set([t]),l=[];try{l=A("/proc")}catch{}for(let n of l){if(!/^\d+$/.test(n))continue;try{let o=k(`/proc/${n}/stat`,"utf8");if(Number(o.slice(o.lastIndexOf(")")+2).split(" ")[3])===t)a.add(Number(n))}catch{}}for(let n of a)try{process.kill(n,"SIGKILL")}catch{}}var H=(t)=>{let a=globalThis.Bun;if(!a)throw new r("pty_unavailable","Reason terminals require the Bun runtime.");let l=a.spawn({cmd:[t.shell,...t.args],cwd:t.cwd,env:{...t.environment,TERM:"xterm-256color"},terminal:{cols:t.cols,rows:t.rows,data:(c,d)=>t.onData(d)}}),n=l.terminal,o=()=>{D(l.pid);try{n?.close()}catch{}};if(!n)throw o(),new r("pty_unavailable","Reason could not allocate a pseudo-terminal.");return{write:(c)=>n.write(c),resize:(c,d)=>n.resize(c,d),kill:o,exited:l.exited.then((c)=>typeof c==="number"?c:null,()=>null)}};function O(){let t=(()=>{try{return E().username}catch{return}})();return{PATH:process.env.PATH,HOME:process.env.HOME,SHELL:process.env.SHELL,LANG:"C.UTF-8",...t?{USER:t,LOGNAME:t}:{}}}async function L(t){let[{localAutomationAvailable:a},{localDisplayReady:l},{localDisplayVideoAvailable:n},{probeWorkerPreview:o},m]=await Promise.all([import("./local-automation-3mdhfw08.js"),import("./local-display-session-r6s0wghh.js"),import("./local-display-video-61peg1pj.js"),import("./worker-preview-readiness-w4zy5g2p.js"),import("fs")]),c=AbortSignal.timeout(15000),d=null;try{m.mkdirSync(t,{recursive:!0,mode:448}),d=m.mkdtempSync(`${t}/probe-`);let[w,u,v]=await Promise.all([Promise.resolve().then(()=>a()).catch(()=>!1),l().catch(()=>!1),o(d,c).catch(()=>!1)]);return{t:"readiness",display_video:u&&await n().catch(()=>!1),lanes:{"automation.call.v1":w,"display.stream.v1":u,"preview.serve.v1":v,"tunnel.open":v,"tunnel.close":v}}}finally{if(d)m.rmSync(d,{recursive:!0,force:!0})}}function N(t){let a="";try{a=k("/proc/self/cgroup","utf8").split(`
3
+ `).find((o)=>o.startsWith("0::"))?.slice(3)??""}catch{return null}if(!/^\/reason-person\/vm-hands\/[A-Za-z0-9._-]+$/.test(a))return null;if(!t)return null;let l=[t.xvnc,t.xvfb,t.openbox,t.x11vnc,t.pulseaudio,t.browser,"/usr/bin/dbus-daemon","/bin/dbus-daemon"].flatMap((o)=>{try{return o?[x(o)]:[]}catch{return[]}}),n={join:`/sys/fs/cgroup${a}/desktop`,keep:C,programs:[...new Set(l)]};for(let o of[n.join,n.keep])try{R(o,{mode:493})}catch(m){if(m.code!=="EEXIST")return null}return n}async function hl(){let[{executeLocalOperation:t,spawnCaptured:a},{runLocalPtySession:l},{configureDesktopAccount:n,desktopAccount:o},{configureWorkerSandbox:m},{configureDesktopPlacement:c},{readDesktopComponents:d}]=await Promise.all([import("./local-capabilities-6e0gkrqq.js"),import("./local-pty-session-w0yhjdvz.js"),import("./desktop-account-d1g1m6yb.js"),import("./worker-sandbox-2trfs79b.js"),import("./desktop-delegate-4hb0163k.js"),import("./desktop-components-7ngf8byq.js")]);m();let w=process.argv.includes(qn),u=process.argv.includes(Wn),v=(i,e,p)=>a(i,e[0]==="-lic"?["-lc",...e.slice(1)]:e,p),y=(process.geteuid?.()??0)!==0;if(u){y=!1;let i=process.argv.find((e)=>e.startsWith(Wr))?.slice(Wr.length);if((process.geteuid?.()??-1)===0&&i)try{y=n({value:i})!==null&&o()!==null}catch{y=!1}}let S=new Map,_=new Map,f=(i)=>{try{process.send?.(i)}catch{}};if(u&&y){let i=o()?.home,e=i?N(d({home:i})):null;c(e&&{...e,log:(p,g)=>f({t:"log",event:p,fields:g})})}if(process.on("message",(i)=>{let e=i;if(e?.t==="cancel"){S.get(e.id)?.abort();return}if(e?.t==="control"){let s=_.get(e.id);if(u&&s&&e.control&&typeof e.control.kind==="string")import("./local-managed-process-p8xd7m5f.js").then(({controlManagedDeviceProcess:h})=>h(s,{kind:e.control.kind,payload:e.control.payload??{}})).catch(()=>!1);return}if(e?.t==="retire"){if(u&&typeof e.operation_id==="string"&&typeof e.status==="string")import("./local-managed-process-p8xd7m5f.js").then(({retireManagedDeviceProcess:s})=>s(e.operation_id,e.status)).catch(()=>!1);return}if(e?.t!=="op")return;if(!y){f({t:"done",id:e.id,completion:{status:"failed",error_code:"vm_hands_payload_account_unavailable"}});return}let p=e.claim.capability;if(p==="pty.start"&&!w){f({t:"done",id:e.id,completion:{status:"failed",error_code:"capability_not_granted"}});return}if(Gr.has(p)!==u){f({t:"done",id:e.id,completion:{status:"failed",error_code:"capability_not_granted"}});return}let g=new AbortController;S.set(e.id,g),_.set(e.id,e.claim);let b=p==="pty.start"?{runPtySession:(s)=>l(s,{spawnPty:H,environment:O(),loadProxy:()=>null})}:{worker:e.worker,...p==="exec.full"?{spawnFullControl:v}:{}};t(e.state,e.claim,{...b,signal:g.signal,emit:(s)=>{let{deliverySignal:h,...P}=s;f({t:"event",id:e.id,event:P})}}).then((s)=>f({t:"done",id:e.id,completion:s}),(s)=>f({t:"done",id:e.id,completion:{status:"failed",error_code:s&&typeof s==="object"&&"code"in s&&typeof s.code==="string"?s.code:"vm_hands_op_failed"}})).finally(()=>{S.delete(e.id),_.delete(e.id)})}),process.on("disconnect",()=>process.exit(0)),u){let i=process.argv.find((p)=>p.startsWith(Vr))?.slice(Vr.length),e={t:"readiness",display_video:!1,lanes:{}};f(y&&i?await L(i).catch(()=>e):e)}await new Promise(()=>{})}
4
+ export{qn,Wn,Wr,Vr,Gr,hl};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- var gn=String.raw`(function(loadFfi, existsSync) {
2
+ var _n=String.raw`(function(loadFfi, existsSync) {
3
3
  const STARTF_USESTDHANDLES = 0x100;
4
4
  const CREATE_SUSPENDED = 0x4;
5
5
  const CREATE_UNICODE_ENVIRONMENT = 0x400;
@@ -242,4 +242,4 @@ var gn=String.raw`(function(loadFfi, existsSync) {
242
242
  }
243
243
  return { available, unavailableReason, defaultShell, shellArgs, quoteArg, environmentBlock, spawn };
244
244
  })`;
245
- export{gn};
245
+ export{_n};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- var $n={name:"github-native-engineer-device-worker-production",version:"0.2.566",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:"5.0.1",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.4",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:"^5.0.1",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
- export{$n};
2
+ var Mn={name:"github-native-engineer-device-worker-production",version:"0.2.567",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:"5.0.1",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.4",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:"^5.0.1",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
+ export{Mn};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{R}from"./vm-hands-entry-lite-z65xva21.js";import{w,Ve}from"./vm-hands-entry-lite-33at6g06.js";import{be,C}from"./vm-hands-entry-lite-rz1ep81m.js";import{q}from"./vm-hands-entry-lite-a6ss0ges.js";function ut(e,i){let t=R(e,"REASON_API_URL")?.trim();if(!t)return Ve(i);let n=new URL(t);if(n.protocol!=="https:"&&!(n.protocol==="http:"&&["127.0.0.1","localhost","::1"].includes(n.hostname)))throw Error("REASON_API_URL must use HTTPS (HTTP is allowed only for loopback development).");return n.origin}function el(e){return R(e,"REASON_API_URL")?.trim()?ut(e,"production"):void 0}function Wn(e){return R(e,"REASON_API_KEY")?.trim()||void 0}async function ir(e,i){let t=e.env??process.env,n=Wn(t);if(!n)return(e.getCredentials??be)({apiOrigin:el(t),signal:i});let a=ut(t,e.channel??w({env:t})),o=await(e.fetchImpl??fetch)(a+"/v3/self",{redirect:"error",headers:{authorization:"Bearer "+n,accept:"application/json"},signal:i}),p=await o.json().catch(()=>({})),r=q(p)?p:{};if(!o.ok){let s=typeof r.detail==="string"?r.detail:typeof r.message==="string"?r.message:"API key authentication failed ("+o.status+")";throw new C(o.status,typeof r.error==="string"?r.error:"api_key_auth_failed",s)}if(typeof r.org_id!=="string"||!r.org_id)throw Error("The API key in the environment did not resolve to a Workspace.");let l=Array.isArray(r.scopes)?r.scopes.filter((s)=>typeof s==="string"):[];return{credentialKind:"api_key",apiOrigin:a,accessToken:n,orgId:r.org_id,clientId:"api-key",refreshToken:"",expiresAt:"",scopes:l}}export{ut,el,Wn,ir};
2
+ import{R}from"./vm-hands-entry-lite-ys4jhf7n.js";import{w,Ve}from"./vm-hands-entry-lite-0xfme8gg.js";import{be,C}from"./vm-hands-entry-lite-3r063pb4.js";import{q}from"./vm-hands-entry-lite-a6ss0ges.js";function ut(e,i){let t=R(e,"REASON_API_URL")?.trim();if(!t)return Ve(i);let n=new URL(t);if(n.protocol!=="https:"&&!(n.protocol==="http:"&&["127.0.0.1","localhost","::1"].includes(n.hostname)))throw Error("REASON_API_URL must use HTTPS (HTTP is allowed only for loopback development).");return n.origin}function el(e){return R(e,"REASON_API_URL")?.trim()?ut(e,"production"):void 0}function Vn(e){return R(e,"REASON_API_KEY")?.trim()||void 0}async function ir(e,i){let t=e.env??process.env,n=Vn(t);if(!n)return(e.getCredentials??be)({apiOrigin:el(t),signal:i});let a=ut(t,e.channel??w({env:t})),o=await(e.fetchImpl??fetch)(a+"/v3/self",{redirect:"error",headers:{authorization:"Bearer "+n,accept:"application/json"},signal:i}),p=await o.json().catch(()=>({})),r=q(p)?p:{};if(!o.ok){let s=typeof r.detail==="string"?r.detail:typeof r.message==="string"?r.message:"API key authentication failed ("+o.status+")";throw new C(o.status,typeof r.error==="string"?r.error:"api_key_auth_failed",s)}if(typeof r.org_id!=="string"||!r.org_id)throw Error("The API key in the environment did not resolve to a Workspace.");let l=Array.isArray(r.scopes)?r.scopes.filter((s)=>typeof s==="string"):[];return{credentialKind:"api_key",apiOrigin:a,accessToken:n,orgId:r.org_id,clientId:"api-key",refreshToken:"",expiresAt:"",scopes:l}}export{ut,el,Vn,ir};
@@ -8,5 +8,5 @@ import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{spawn as Q}from"child_pr
8
8
  `);E=(_.pop()??"").slice(-P);for(let a of _){let d=de.exec(a),y=d?null:ue.exec(a);if(d){if(ye(s,e.uid,Number(d[1]),d[2]))L++}else if(y)A=y[1];else u=(u+a+`
9
9
  `).slice(-P)}}),p.stdin.on("error",()=>{}),p.once("error",()=>F(()=>R(S??new r("desktop_delegate_unavailable","Reason could not start its desktop as the desktop account.")))),p.once("close",(l,_)=>F(()=>{if(S)return R(S);if(E)u=(u+E).slice(-P);let a=ae(Buffer.concat(K).toString("utf8"));if(N(a)&&a.ok===!0&&N(a.result))return Z(a.result);let d=N(a)&&a.ok===!1&&typeof a.code==="string"&&typeof a.message==="string"?new r(a.code.slice(0,120),a.message.slice(0,2000)):null,y=`exited ${l??_}${d?"":" with no reply"}`,z=u.trim().split(`
10
10
  `).at(-1)?.slice(-300)??"";if(!d||d.code==="desktop_delegate_failed")process.stderr.write(`Reason worker: desktop call ${y}${u?`: ${u.trim().slice(-500)}`:""}
11
- `);if(d)return R(d);R(new r("desktop_delegate_failed",`Reason's desktop operation failed (${y}${z?`: ${z}`:""}).`))})),t.aborted)T();p.stdin.end(JSON.stringify(o))})}async function Yo(e,o,t,n={}){let i=await vr(e,{op:"automation",call:o},t,n);if(!Number.isSafeInteger(i.code)||typeof i.stdout!=="string"||typeof i.stderr!=="string")throw new r("desktop_delegate_failed","Reason's desktop reply is malformed.");return{code:i.code,stdout:Buffer.from(i.stdout,"base64"),stderr:i.stderr}}
12
- export{Al,Ue,wr,br,vr,Yo};
11
+ `);if(d)return R(d);R(new r("desktop_delegate_failed",`Reason's desktop operation failed (${y}${z?`: ${z}`:""}).`))})),t.aborted)T();p.stdin.end(JSON.stringify(o))})}async function Zo(e,o,t,n={}){let i=await vr(e,{op:"automation",call:o},t,n);if(!Number.isSafeInteger(i.code)||typeof i.stdout!=="string"||typeof i.stderr!=="string")throw new r("desktop_delegate_failed","Reason's desktop reply is malformed.");return{code:i.code,stdout:Buffer.from(i.stdout,"base64"),stderr:i.stderr}}
12
+ export{Al,Ue,wr,br,vr,Zo};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- var Un=String.raw`(function(require) {
2
+ var zn=String.raw`(function(require) {
3
3
  if (process.platform !== "win32") return null;
4
4
  let ffi, kernel32;
5
5
  try {
@@ -64,4 +64,4 @@ var Un=String.raw`(function(require) {
64
64
  },
65
65
  };
66
66
  })`;
67
- export{Un};
67
+ export{zn};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as se,spawn as E}from"child_process";var Pc="h264_ws_v1",Rc="video",Ar=["smooth","sharp","data_saver","balanced"];var Tc="video_presets";var M=8388608,D=65536,Ic="control",Dc="v1",X=200;function ls(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t,n=(i)=>typeof i==="string"&&i.length>0&&i.length<=X;if(Object.keys(e).length!==2||!n(e.user_id)||!n(e.name))return null;return{user_id:e.user_id,name:e.name}}var Oc="windows",Nc="v1",Lc="look",$c="v1",J=["reason","grok"];function us(t){return typeof t==="string"&&J.includes(t)?t:null}var _=200,Z=(t)=>typeof t==="string"&&Ar.includes(t);function Mc(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t;if(Object.keys(e).length!==2||e.format!=="h264_ws_v1"||!Z(e.preset))return null;return{format:"h264_ws_v1",preset:e.preset}}var o={hello:1,frame:2,stats:3,pong:4,serverClipboard:5,error:6,audioHello:7,audio:8,control:9,windows:10,pointer:16,key:17,config:18,ping:19,clientClipboard:20,keyframeRequest:21,ack:22,audioEnable:23,resize:24};class l extends Error{constructor(t){super(t);this.name="DisplayVideoProtocolError"}}var Q=new TextEncoder,ee=new TextDecoder("utf-8",{fatal:!0});function p(t,e){if(e.byteLength+1>M)throw new l("message_too_large");let n=new Uint8Array(5+e.byteLength),i=new DataView(n.buffer);return i.setUint32(0,e.byteLength+1),i.setUint8(4,t),n.set(e,5),n}function w(t){let e=Q.encode(t);if(e.byteLength>D)throw new l("text_too_large");return e}function m(t,e){if(!Number.isInteger(t)||t<0||t>65535)throw new l(`invalid_${e}`);return t}function te(t){if(!Number.isFinite(t))throw new l("invalid_window");return Math.max(-2147483648,Math.min(2147483647,Math.round(t)))}function Dn(t){switch(t.type){case"hello":{let e=w(t.codec),n=new Uint8Array(6+e.byteLength),i=new DataView(n.buffer);return i.setUint16(0,m(t.width,"width")),i.setUint16(2,m(t.height,"height")),i.setUint8(4,Math.max(1,Math.min(240,Math.round(t.fps)))),i.setUint8(5,Ar.indexOf(t.preset)),n.set(e,6),p(o.hello,n)}case"frame":{let e=new Uint8Array(13+t.data.byteLength),n=new DataView(e.buffer);return n.setUint8(0,t.key?1:0),n.setUint32(1,t.seq>>>0),n.setBigUint64(5,BigInt(Math.max(0,Math.floor(t.captureMicros)))),e.set(t.data,13),p(o.frame,e)}case"stats":return p(o.stats,w(JSON.stringify(t.stats)));case"pong":case"ping":{let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t.token),p(t.type==="ping"?o.ping:o.pong,e)}case"serverClipboard":return p(o.serverClipboard,w(t.text));case"clientClipboard":return p(o.clientClipboard,w(t.text));case"error":return p(o.error,w(t.code));case"pointer":{let e=new Uint8Array(5),n=new DataView(e.buffer);return n.setUint16(0,m(t.x,"x")),n.setUint16(2,m(t.y,"y")),n.setUint8(4,t.buttons&255),p(o.pointer,e)}case"key":{let e=new Uint8Array(5),n=new DataView(e.buffer);return n.setUint8(0,t.down?1:0),n.setUint32(1,t.keysym>>>0),p(o.key,e)}case"config":return p(o.config,Uint8Array.of(Ar.indexOf(t.preset)));case"keyframeRequest":return p(o.keyframeRequest,new Uint8Array(0));case"audioHello":{let e=w(t.codec),n=new Uint8Array(5+e.byteLength),i=new DataView(n.buffer);return i.setUint32(0,t.sampleRate>>>0),i.setUint8(4,t.channels&255),n.set(e,5),p(o.audioHello,n)}case"audio":{let e=new Uint8Array(8+t.data.byteLength);return new DataView(e.buffer).setBigUint64(0,BigInt(Math.max(0,Math.floor(t.captureMicros)))),e.set(t.data,8),p(o.audio,e)}case"control":return p(o.control,w(JSON.stringify(t.control)));case"windows":{let e=t.bounds.slice(0,_),n=new Uint8Array(e.length*16),i=new DataView(n.buffer);return e.forEach((s,a)=>{[s.x,s.y,s.width,s.height].forEach((c,d)=>i.setInt32(a*16+d*4,te(c)))}),p(o.windows,n)}case"audioEnable":return p(o.audioEnable,Uint8Array.of(t.on?1:0));case"resize":{let e=new Uint8Array(4),n=new DataView(e.buffer);return n.setUint16(0,m(t.width,"width")),n.setUint16(2,m(t.height,"height")),p(o.resize,e)}case"ack":{let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t.seq>>>0),p(o.ack,e)}}}function L(t){let e=Ar[t];if(!e)throw new l("invalid_preset");return e}function y(t,e){if(t.byteLength!==e)throw new l("invalid_length")}function S(t){if(t.byteLength>D)throw new l("text_too_large");try{return ee.decode(t)}catch{throw new l("invalid_text")}}function ne(t){let e;try{e=JSON.parse(S(t))}catch{throw new l("invalid_stats")}let n=e;if(!n||typeof n!=="object"||["fps","kbps","dropped","restarts","queued_bytes"].some((s)=>typeof n[s]!=="number"||!Number.isFinite(n[s])))throw new l("invalid_stats");return{fps:n.fps,kbps:n.kbps,dropped:n.dropped,restarts:n.restarts,queued_bytes:n.queued_bytes}}function re(t){let e;try{e=JSON.parse(S(t))}catch{throw new l("invalid_control")}let n=e;if(!n||typeof n!=="object"||typeof n.you!=="boolean"||typeof n.same_user!=="boolean")throw new l("invalid_control");let i=n.holder===null?null:ls(n.holder);if(i===null&&n.holder!==null)throw new l("invalid_control");return{holder:i,you:n.you,same_user:n.same_user}}function ie(t,e){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(t){case o.hello:if(e.byteLength<6)throw new l("invalid_length");return{type:"hello",width:n.getUint16(0),height:n.getUint16(2),fps:n.getUint8(4),preset:L(n.getUint8(5)),codec:S(e.subarray(6))};case o.frame:if(e.byteLength<14)throw new l("invalid_length");if(n.getUint8(0)>1)throw new l("invalid_frame_flags");return{type:"frame",key:n.getUint8(0)===1,seq:n.getUint32(1),captureMicros:Number(n.getBigUint64(5)),data:e.subarray(13)};case o.stats:return{type:"stats",stats:ne(e)};case o.ping:case o.pong:return y(e,8),{type:t===o.ping?"ping":"pong",token:n.getFloat64(0)};case o.serverClipboard:return{type:"serverClipboard",text:S(e)};case o.clientClipboard:return{type:"clientClipboard",text:S(e)};case o.error:return{type:"error",code:S(e)};case o.pointer:return y(e,5),{type:"pointer",x:n.getUint16(0),y:n.getUint16(2),buttons:n.getUint8(4)};case o.key:if(y(e,5),n.getUint8(0)>1)throw new l("invalid_key_flags");return{type:"key",down:n.getUint8(0)===1,keysym:n.getUint32(1)};case o.config:return y(e,1),{type:"config",preset:L(n.getUint8(0))};case o.keyframeRequest:return y(e,0),{type:"keyframeRequest"};case o.audioHello:if(e.byteLength<5)throw new l("invalid_length");return{type:"audioHello",sampleRate:n.getUint32(0),channels:n.getUint8(4),codec:S(e.subarray(5))};case o.audio:if(e.byteLength<9)throw new l("invalid_length");return{type:"audio",captureMicros:Number(n.getBigUint64(0)),data:e.subarray(8)};case o.audioEnable:if(y(e,1),n.getUint8(0)>1)throw new l("invalid_audio_flags");return{type:"audioEnable",on:n.getUint8(0)===1};case o.resize:return y(e,4),{type:"resize",width:n.getUint16(0),height:n.getUint16(2)};case o.control:return{type:"control",control:re(e)};case o.windows:{if(e.byteLength%16!==0||e.byteLength>_*16)throw new l("invalid_length");let i=[];for(let s=0;s<e.byteLength;s+=16)i.push({x:n.getInt32(s),y:n.getInt32(s+4),width:n.getInt32(s+8),height:n.getInt32(s+12)});return{type:"windows",bounds:i}}case o.ack:return y(e,4),{type:"ack",seq:n.getUint32(0)};default:return null}}class ds{buffer=new Uint8Array(0);push(t){let e=new Uint8Array(this.buffer.byteLength+t.byteLength);e.set(this.buffer),e.set(t,this.buffer.byteLength);let n=[],i=0;while(e.byteLength-i>=4){let s=new DataView(e.buffer,e.byteOffset+i,4).getUint32(0);if(s<1||s>M)throw new l("invalid_message_length");if(e.byteLength-i-4<s)break;let a=e[i+4],c=e.slice(i+5,i+4+s),d=ie(a,c);if(d)n.push(d);i+=4+s}return this.buffer=e.slice(i),n}}var j="/usr/bin/osascript",oe=5000,ae=1048576,ce=String.raw`
2
+ import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as se,spawn as E}from"child_process";var Pc="h264_ws_v1",Rc="video",Ar=["smooth","sharp","data_saver","balanced"];var Tc="video_presets";var M=8388608,D=65536,Ic="control",Dc="v1",X=200;function us(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t,n=(i)=>typeof i==="string"&&i.length>0&&i.length<=X;if(Object.keys(e).length!==2||!n(e.user_id)||!n(e.name))return null;return{user_id:e.user_id,name:e.name}}var Oc="windows",Nc="v1",Lc="look",$c="v1",J=["reason","grok"];function ds(t){return typeof t==="string"&&J.includes(t)?t:null}var _=200,Z=(t)=>typeof t==="string"&&Ar.includes(t);function Mc(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t;if(Object.keys(e).length!==2||e.format!=="h264_ws_v1"||!Z(e.preset))return null;return{format:"h264_ws_v1",preset:e.preset}}var o={hello:1,frame:2,stats:3,pong:4,serverClipboard:5,error:6,audioHello:7,audio:8,control:9,windows:10,pointer:16,key:17,config:18,ping:19,clientClipboard:20,keyframeRequest:21,ack:22,audioEnable:23,resize:24};class l extends Error{constructor(t){super(t);this.name="DisplayVideoProtocolError"}}var Q=new TextEncoder,ee=new TextDecoder("utf-8",{fatal:!0});function p(t,e){if(e.byteLength+1>M)throw new l("message_too_large");let n=new Uint8Array(5+e.byteLength),i=new DataView(n.buffer);return i.setUint32(0,e.byteLength+1),i.setUint8(4,t),n.set(e,5),n}function w(t){let e=Q.encode(t);if(e.byteLength>D)throw new l("text_too_large");return e}function m(t,e){if(!Number.isInteger(t)||t<0||t>65535)throw new l(`invalid_${e}`);return t}function te(t){if(!Number.isFinite(t))throw new l("invalid_window");return Math.max(-2147483648,Math.min(2147483647,Math.round(t)))}function On(t){switch(t.type){case"hello":{let e=w(t.codec),n=new Uint8Array(6+e.byteLength),i=new DataView(n.buffer);return i.setUint16(0,m(t.width,"width")),i.setUint16(2,m(t.height,"height")),i.setUint8(4,Math.max(1,Math.min(240,Math.round(t.fps)))),i.setUint8(5,Ar.indexOf(t.preset)),n.set(e,6),p(o.hello,n)}case"frame":{let e=new Uint8Array(13+t.data.byteLength),n=new DataView(e.buffer);return n.setUint8(0,t.key?1:0),n.setUint32(1,t.seq>>>0),n.setBigUint64(5,BigInt(Math.max(0,Math.floor(t.captureMicros)))),e.set(t.data,13),p(o.frame,e)}case"stats":return p(o.stats,w(JSON.stringify(t.stats)));case"pong":case"ping":{let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t.token),p(t.type==="ping"?o.ping:o.pong,e)}case"serverClipboard":return p(o.serverClipboard,w(t.text));case"clientClipboard":return p(o.clientClipboard,w(t.text));case"error":return p(o.error,w(t.code));case"pointer":{let e=new Uint8Array(5),n=new DataView(e.buffer);return n.setUint16(0,m(t.x,"x")),n.setUint16(2,m(t.y,"y")),n.setUint8(4,t.buttons&255),p(o.pointer,e)}case"key":{let e=new Uint8Array(5),n=new DataView(e.buffer);return n.setUint8(0,t.down?1:0),n.setUint32(1,t.keysym>>>0),p(o.key,e)}case"config":return p(o.config,Uint8Array.of(Ar.indexOf(t.preset)));case"keyframeRequest":return p(o.keyframeRequest,new Uint8Array(0));case"audioHello":{let e=w(t.codec),n=new Uint8Array(5+e.byteLength),i=new DataView(n.buffer);return i.setUint32(0,t.sampleRate>>>0),i.setUint8(4,t.channels&255),n.set(e,5),p(o.audioHello,n)}case"audio":{let e=new Uint8Array(8+t.data.byteLength);return new DataView(e.buffer).setBigUint64(0,BigInt(Math.max(0,Math.floor(t.captureMicros)))),e.set(t.data,8),p(o.audio,e)}case"control":return p(o.control,w(JSON.stringify(t.control)));case"windows":{let e=t.bounds.slice(0,_),n=new Uint8Array(e.length*16),i=new DataView(n.buffer);return e.forEach((s,a)=>{[s.x,s.y,s.width,s.height].forEach((c,d)=>i.setInt32(a*16+d*4,te(c)))}),p(o.windows,n)}case"audioEnable":return p(o.audioEnable,Uint8Array.of(t.on?1:0));case"resize":{let e=new Uint8Array(4),n=new DataView(e.buffer);return n.setUint16(0,m(t.width,"width")),n.setUint16(2,m(t.height,"height")),p(o.resize,e)}case"ack":{let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t.seq>>>0),p(o.ack,e)}}}function L(t){let e=Ar[t];if(!e)throw new l("invalid_preset");return e}function y(t,e){if(t.byteLength!==e)throw new l("invalid_length")}function S(t){if(t.byteLength>D)throw new l("text_too_large");try{return ee.decode(t)}catch{throw new l("invalid_text")}}function ne(t){let e;try{e=JSON.parse(S(t))}catch{throw new l("invalid_stats")}let n=e;if(!n||typeof n!=="object"||["fps","kbps","dropped","restarts","queued_bytes"].some((s)=>typeof n[s]!=="number"||!Number.isFinite(n[s])))throw new l("invalid_stats");return{fps:n.fps,kbps:n.kbps,dropped:n.dropped,restarts:n.restarts,queued_bytes:n.queued_bytes}}function re(t){let e;try{e=JSON.parse(S(t))}catch{throw new l("invalid_control")}let n=e;if(!n||typeof n!=="object"||typeof n.you!=="boolean"||typeof n.same_user!=="boolean")throw new l("invalid_control");let i=n.holder===null?null:us(n.holder);if(i===null&&n.holder!==null)throw new l("invalid_control");return{holder:i,you:n.you,same_user:n.same_user}}function ie(t,e){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(t){case o.hello:if(e.byteLength<6)throw new l("invalid_length");return{type:"hello",width:n.getUint16(0),height:n.getUint16(2),fps:n.getUint8(4),preset:L(n.getUint8(5)),codec:S(e.subarray(6))};case o.frame:if(e.byteLength<14)throw new l("invalid_length");if(n.getUint8(0)>1)throw new l("invalid_frame_flags");return{type:"frame",key:n.getUint8(0)===1,seq:n.getUint32(1),captureMicros:Number(n.getBigUint64(5)),data:e.subarray(13)};case o.stats:return{type:"stats",stats:ne(e)};case o.ping:case o.pong:return y(e,8),{type:t===o.ping?"ping":"pong",token:n.getFloat64(0)};case o.serverClipboard:return{type:"serverClipboard",text:S(e)};case o.clientClipboard:return{type:"clientClipboard",text:S(e)};case o.error:return{type:"error",code:S(e)};case o.pointer:return y(e,5),{type:"pointer",x:n.getUint16(0),y:n.getUint16(2),buttons:n.getUint8(4)};case o.key:if(y(e,5),n.getUint8(0)>1)throw new l("invalid_key_flags");return{type:"key",down:n.getUint8(0)===1,keysym:n.getUint32(1)};case o.config:return y(e,1),{type:"config",preset:L(n.getUint8(0))};case o.keyframeRequest:return y(e,0),{type:"keyframeRequest"};case o.audioHello:if(e.byteLength<5)throw new l("invalid_length");return{type:"audioHello",sampleRate:n.getUint32(0),channels:n.getUint8(4),codec:S(e.subarray(5))};case o.audio:if(e.byteLength<9)throw new l("invalid_length");return{type:"audio",captureMicros:Number(n.getBigUint64(0)),data:e.subarray(8)};case o.audioEnable:if(y(e,1),n.getUint8(0)>1)throw new l("invalid_audio_flags");return{type:"audioEnable",on:n.getUint8(0)===1};case o.resize:return y(e,4),{type:"resize",width:n.getUint16(0),height:n.getUint16(2)};case o.control:return{type:"control",control:re(e)};case o.windows:{if(e.byteLength%16!==0||e.byteLength>_*16)throw new l("invalid_length");let i=[];for(let s=0;s<e.byteLength;s+=16)i.push({x:n.getInt32(s),y:n.getInt32(s+4),width:n.getInt32(s+8),height:n.getInt32(s+12)});return{type:"windows",bounds:i}}case o.ack:return y(e,4),{type:"ack",seq:n.getUint32(0)};default:return null}}class ps{buffer=new Uint8Array(0);push(t){let e=new Uint8Array(this.buffer.byteLength+t.byteLength);e.set(this.buffer),e.set(t,this.buffer.byteLength);let n=[],i=0;while(e.byteLength-i>=4){let s=new DataView(e.buffer,e.byteOffset+i,4).getUint32(0);if(s<1||s>M)throw new l("invalid_message_length");if(e.byteLength-i-4<s)break;let a=e[i+4],c=e.slice(i+5,i+4+s),d=ie(a,c);if(d)n.push(d);i+=4+s}return this.buffer=e.slice(i),n}}var j="/usr/bin/osascript",oe=5000,ae=1048576,ce=String.raw`
3
3
  ObjC.import("CoreGraphics");
4
4
  ObjC.import("ApplicationServices");
5
5
  ObjC.import("AppKit");
@@ -101,12 +101,12 @@ function run() {
101
101
  $.NSThread.sleepForTimeInterval(wait);
102
102
  }
103
103
  }
104
- `;function de(t){let e;try{e=JSON.parse(t)}catch{return null}if(!Array.isArray(e))return null;let n=[];for(let i of e.slice(0,_)){if(!Array.isArray(i)||i.length!==4||!i.every((u)=>typeof u==="number"&&Number.isFinite(u)))return null;let[s,a,c,d]=i.map(Math.round);if(c>0&&d>0)n.push({x:s,y:a,width:c,height:d})}return n}function ps(t){let e=Date.now(),n=0,i=!1,s=(u,b={})=>{try{process.stderr.write(`${JSON.stringify({event:"display.windows_helper",state:u,...b})}
104
+ `;function de(t){let e;try{e=JSON.parse(t)}catch{return null}if(!Array.isArray(e))return null;let n=[];for(let i of e.slice(0,_)){if(!Array.isArray(i)||i.length!==4||!i.every((u)=>typeof u==="number"&&Number.isFinite(u)))return null;let[s,a,c,d]=i.map(Math.round);if(c>0&&d>0)n.push({x:s,y:a,width:c,height:d})}return n}function hs(t){let e=Date.now(),n=0,i=!1,s=(u,b={})=>{try{process.stderr.write(`${JSON.stringify({event:"display.windows_helper",state:u,...b})}
105
105
  `)}catch{}},a=(u,b={})=>{if(i)return;i=!0,s(u,{updates:n,duration_ms:Date.now()-e,...b})},c=E(j,["-l","JavaScript","-e",le],{env:{},stdio:["ignore","pipe","ignore"]});s("started");let d="";return c.stdout.on("data",(u)=>{if(i)return;d+=u.toString("utf8");for(let b=d.indexOf(`
106
106
  `);b>=0;b=d.indexOf(`
107
- `)){let x=de(d.slice(0,b));if(d=d.slice(b+1),x)n++,t(x)}if(d.length>65536)d=""}),c.once("error",(u)=>a("failed",{code:u.code??"spawn_failed"})),c.once("exit",(u,b)=>a("failed",{code:"exited",exit_code:u,signal:b})),{close(){a("stopped"),c.kill("SIGKILL")}}}var T=5,R=[{bit:1,button:0,down:1,up:2,drag:6},{bit:4,button:1,down:3,up:4,drag:7},{bit:2,button:2,down:25,up:26,drag:27}],fe=[[8,1,0],[16,-1,0],[32,0,1],[64,0,-1]],P=50,pe=500,V=4,I=131072,W=262144,O=524288,F=1048576,B=new Map([[65505,[56,I]],[65506,[60,I]],[65507,[59,W]],[65508,[62,W]],[65511,[58,O]],[65512,[61,O]],[65513,[58,O]],[65514,[61,O]],[65027,[61,O]],[65515,[55,F]],[65516,[54,F]]]),be=new Map([[65288,51],[65289,48],[65056,48],[65293,36],[65307,53],[65535,117],[65509,57],[65360,115],[65361,123],[65362,126],[65363,124],[65364,125],[65365,116],[65366,121],[65367,119],[65379,114],[65386,114],[65291,71],[65408,49],[65421,76],[65429,115],[65430,123],[65431,126],[65432,124],[65433,125],[65434,116],[65435,121],[65436,119],[65437,71],[65438,114],[65439,117],[65450,67],[65451,69],[65452,65],[65453,78],[65454,65],[65455,75],[65469,81],...[82,83,84,85,86,87,88,89,91,92].map((t,e)=>[65456+e,t]),...[122,120,99,118,96,97,98,100,101,109,103,111,105,107,113,106,64,79,80,90].map((t,e)=>[65470+e,t])]),G="asdfhgzxcv\x00bqweryt123465=97-80]ou[ip\x00lj'k;\\,/nm.\x00 `",Y='~!@#$%^&*()_+{}|:"<>?',he="`1234567890-=[]\\;',./",k=new Map;for(let t=0;t<G.length;t++){let e=G[t];if(e==="\x00")continue;if(k.set(e.charCodeAt(0),[t,!1]),e>="a"&&e<="z")k.set(e.toUpperCase().charCodeAt(0),[t,!0])}for(let t=0;t<Y.length;t++)k.set(Y.charCodeAt(t),[k.get(he.charCodeAt(t))[0],!0]);class K{now;x=-1;y=-1;mask=0;clicks=0;lastDown=null;held=new Set;constructor(t=()=>performance.now()){this.now=t}flags(){let t=0;for(let e of this.held)t|=B.get(e)[1];return t}mouse(t,e){return`m ${t} ${this.x} ${this.y} ${e} ${t===T?0:this.clicks} ${this.flags()}`}pointer(t,e,n){let i=[];if(t!==this.x||e!==this.y){this.x=t,this.y=e;let s=R.find((a)=>this.mask&a.bit);i.push(s?this.mouse(s.drag,s.button):this.mouse(T,0))}for(let s of R){let a=(this.mask&s.bit)!==0,c=(n&s.bit)!==0;if(!a&&c){let d=this.now(),u=this.lastDown;this.clicks=u&&u.button===s.button&&d-u.at<=pe&&Math.abs(t-u.x)<=V&&Math.abs(e-u.y)<=V?this.clicks+1:1,this.lastDown={button:s.button,at:d,x:t,y:e},i.push(this.mouse(s.down,s.button))}else if(a&&!c)i.push(this.mouse(s.up,s.button))}for(let[s,a,c]of fe)if(!(this.mask&s)&&n&s)i.push(`w ${a*P} ${c*P} ${this.flags()}`);return this.mask=n,i}key(t,e){let n=t?1:0,i=B.get(e);if(i){if(t)this.held.add(e);else this.held.delete(e);return[`k ${i[0]} ${n} ${this.flags()}`]}let s=be.get(e);if(s!==void 0)return[`k ${s} ${n} ${this.flags()}`];let a=e<256?e:(e&4278190080)===16777216?e&16777215:0,c=k.get(a);if(c)return[`k ${c[0]} ${n} ${this.flags()|(c[1]?I:0)}`];if(a<160||a>65535||a>=55296&&a<57344)return[];return[`u ${n} ${a} ${this.flags()}`]}}function hs(t,e=[]){let n=E(...v(e),{env:{},stdio:["pipe","pipe","ignore"]}),i=new K,s="",a=!1,c=null,d=()=>{n.kill("SIGKILL"),c?.kill("SIGKILL")},u=(f)=>{if(a)return;a=!0,d(),t.end(f)},b=(f)=>u({error:new r("display_unavailable",f)}),x=(f)=>{if(a||f.length===0)return;if(n.stdin.write(f.map((g)=>`${g}
107
+ `)){let x=de(d.slice(0,b));if(d=d.slice(b+1),x)n++,t(x)}if(d.length>65536)d=""}),c.once("error",(u)=>a("failed",{code:u.code??"spawn_failed"})),c.once("exit",(u,b)=>a("failed",{code:"exited",exit_code:u,signal:b})),{close(){a("stopped"),c.kill("SIGKILL")}}}var T=5,R=[{bit:1,button:0,down:1,up:2,drag:6},{bit:4,button:1,down:3,up:4,drag:7},{bit:2,button:2,down:25,up:26,drag:27}],fe=[[8,1,0],[16,-1,0],[32,0,1],[64,0,-1]],P=50,pe=500,V=4,I=131072,W=262144,O=524288,F=1048576,B=new Map([[65505,[56,I]],[65506,[60,I]],[65507,[59,W]],[65508,[62,W]],[65511,[58,O]],[65512,[61,O]],[65513,[58,O]],[65514,[61,O]],[65027,[61,O]],[65515,[55,F]],[65516,[54,F]]]),be=new Map([[65288,51],[65289,48],[65056,48],[65293,36],[65307,53],[65535,117],[65509,57],[65360,115],[65361,123],[65362,126],[65363,124],[65364,125],[65365,116],[65366,121],[65367,119],[65379,114],[65386,114],[65291,71],[65408,49],[65421,76],[65429,115],[65430,123],[65431,126],[65432,124],[65433,125],[65434,116],[65435,121],[65436,119],[65437,71],[65438,114],[65439,117],[65450,67],[65451,69],[65452,65],[65453,78],[65454,65],[65455,75],[65469,81],...[82,83,84,85,86,87,88,89,91,92].map((t,e)=>[65456+e,t]),...[122,120,99,118,96,97,98,100,101,109,103,111,105,107,113,106,64,79,80,90].map((t,e)=>[65470+e,t])]),G="asdfhgzxcv\x00bqweryt123465=97-80]ou[ip\x00lj'k;\\,/nm.\x00 `",Y='~!@#$%^&*()_+{}|:"<>?',he="`1234567890-=[]\\;',./",k=new Map;for(let t=0;t<G.length;t++){let e=G[t];if(e==="\x00")continue;if(k.set(e.charCodeAt(0),[t,!1]),e>="a"&&e<="z")k.set(e.toUpperCase().charCodeAt(0),[t,!0])}for(let t=0;t<Y.length;t++)k.set(Y.charCodeAt(t),[k.get(he.charCodeAt(t))[0],!0]);class K{now;x=-1;y=-1;mask=0;clicks=0;lastDown=null;held=new Set;constructor(t=()=>performance.now()){this.now=t}flags(){let t=0;for(let e of this.held)t|=B.get(e)[1];return t}mouse(t,e){return`m ${t} ${this.x} ${this.y} ${e} ${t===T?0:this.clicks} ${this.flags()}`}pointer(t,e,n){let i=[];if(t!==this.x||e!==this.y){this.x=t,this.y=e;let s=R.find((a)=>this.mask&a.bit);i.push(s?this.mouse(s.drag,s.button):this.mouse(T,0))}for(let s of R){let a=(this.mask&s.bit)!==0,c=(n&s.bit)!==0;if(!a&&c){let d=this.now(),u=this.lastDown;this.clicks=u&&u.button===s.button&&d-u.at<=pe&&Math.abs(t-u.x)<=V&&Math.abs(e-u.y)<=V?this.clicks+1:1,this.lastDown={button:s.button,at:d,x:t,y:e},i.push(this.mouse(s.down,s.button))}else if(a&&!c)i.push(this.mouse(s.up,s.button))}for(let[s,a,c]of fe)if(!(this.mask&s)&&n&s)i.push(`w ${a*P} ${c*P} ${this.flags()}`);return this.mask=n,i}key(t,e){let n=t?1:0,i=B.get(e);if(i){if(t)this.held.add(e);else this.held.delete(e);return[`k ${i[0]} ${n} ${this.flags()}`]}let s=be.get(e);if(s!==void 0)return[`k ${s} ${n} ${this.flags()}`];let a=e<256?e:(e&4278190080)===16777216?e&16777215:0,c=k.get(a);if(c)return[`k ${c[0]} ${n} ${this.flags()|(c[1]?I:0)}`];if(a<160||a>65535||a>=55296&&a<57344)return[];return[`u ${n} ${a} ${this.flags()}`]}}function fs(t,e=[]){let n=E(...v(e),{env:{},stdio:["pipe","pipe","ignore"]}),i=new K,s="",a=!1,c=null,d=()=>{n.kill("SIGKILL"),c?.kill("SIGKILL")},u=(f)=>{if(a)return;a=!0,d(),t.end(f)},b=(f)=>u({error:new r("display_unavailable",f)}),x=(f)=>{if(a||f.length===0)return;if(n.stdin.write(f.map((g)=>`${g}
108
108
  `).join("")),n.stdin.writableLength>ae)u({reason:"input_backpressure"})},z=()=>{c=E(...v(e,"clipboard"),{env:{},stdio:["ignore","pipe","ignore"]});let f="";c.stdout?.on("data",(g)=>{if(a)return;f+=g.toString("ascii");for(let h=f.indexOf(`
109
109
  `);h>=0;h=f.indexOf(`
110
110
  `)){let U=f.slice(0,h);if(f=f.slice(h+1),!U.startsWith("c "))continue;let A=U.slice(2);if(A.length>Math.ceil(D/3)*4||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(A)){u({reason:"display_protocol"});return}let C=Buffer.from(A,"base64");if(C.byteLength<=D)t.clipboard(C.toString("utf8"));if(a)return}if(f.length>Math.ceil(D/3)*4+2)u({reason:"display_protocol"})}),c.once("error",()=>b("Reason could not watch this Mac's desktop clipboard.")),c.once("exit",()=>{if(!a)b("Reason could not watch this Mac's desktop clipboard.")})};return n.stdout.on("data",(f)=>{if(a||s===null)return;s+=f.toString("utf8");let g=s.indexOf(`
111
111
  `);if(g<0){if(s.length>4096)u({reason:"display_protocol"});return}let h=q(s.slice(0,g));if(s=null,!h)u({reason:"display_protocol"});else if(!h.screen||!h.accessibility)b(e.length>0?"Reason's background worker needs Screen Recording and Accessibility on this Mac (its own Reason entry in System Settings > Privacy & Security, not the Reason app's): run `reason permissions allow` on this Mac.":"Allow Screen Recording and Accessibility for this Mac's Reason worker, then restart it.");else z(),t.ready({width:h.width,height:h.height})}),n.stdin.on("error",()=>{return}),n.once("error",()=>b("Reason could not start this Mac's desktop input.")),n.once("exit",()=>{if(s!==null)b("Reason could not start this Mac's desktop input.");else u({reason:"display_closed"})}),{pointer:(f,g,h)=>x(i.pointer(f,g,h)),key:(f,g)=>x(i.key(f,g)),clipboard:(f)=>x([`c ${Buffer.from(f,"utf8").toString("base64")}`]),close(){a=!0,d()}}}
112
- export{Pc,Rc,Ar,Tc,D,Ic,Dc,ls,Oc,Nc,Lc,$c,us,Mc,Dn,ds,Pr,Rr,ps,hs};
112
+ export{Pc,Rc,Ar,Tc,D,Ic,Dc,us,Oc,Nc,Lc,$c,ds,Mc,On,ps,Pr,Rr,hs,fs};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{resolve as s,sep as i}from"path";var vt=[[".ssh"],[".gnupg"],[".aws"],[".azure"],[".kube"],[".docker"],[".infisical"],[".password-store"],[".terraform.d"],[".config","ara"],[".config","reason"],[".config","gh"],[".config","gcloud"],[".config","infisical"],[".config","op"],[".config","1password"],[".config","pass"],[".local","share","keyrings"],["library","keychains"],["library","application support","so.ara.desktop"],["appdata","roaming","github cli"],["appdata","roaming","gcloud"],["appdata","roaming","microsoft","credentials"],["appdata","local","microsoft","credentials"],["appdata","roaming","microsoft","protect"],["appdata","roaming","1password"],["appdata","local","1password"],["appdata","roaming","microsoft","windows","start menu","programs","startup"],["documents","windowspowershell"],["documents","powershell"],["appdata","local","reason"]],Rn=[[".codex","config.toml"],[".cursor","mcp.json"],[".claude","settings.json"],[".claude","settings.local.json"],[".cargo","credentials"],[".cargo","credentials.toml"],[".gem","credentials"],[".config","git","config"],[".config","git","credentials"],[".config","pip","pip.conf"]],Tn=new Set([".bash_login",".bash_profile",".bashrc",".bunfig.toml",".claude.json",".env",".envrc",".git-credentials",".gitconfig",".mcp.json",".netrc",".npmrc",".profile",".pypirc",".terraformrc",".yarnrc",".yarnrc.yml",".zlogin",".zlogout",".zprofile",".zshenv",".zshrc","auth.json","credentials.json","credentials.tfrc.json","local-daemon.json","local-device.json","mcp.json"]),In=[".key",".p12",".pfx",".pem"];function t(n,a){if(n.length<a.length)return!1;for(let r=0;r<=n.length-a.length;r+=1)if(a.every((o,e)=>n[r+e]===o))return!0;return!1}function L(n){let a=s(n).split(i).filter(Boolean).map((o)=>o.toLowerCase());if(vt.some((o)=>t(a,o)))return!0;if(Rn.some((o)=>t(a,o)))return!0;let r=a.at(-1)??"";return Tn.has(r)||r.startsWith(".env.")||In.some((o)=>r.endsWith(o))}
3
- export{vt,Rn,Tn,In,L};
2
+ import{resolve as s,sep as i}from"path";var vt=[[".ssh"],[".gnupg"],[".aws"],[".azure"],[".kube"],[".docker"],[".infisical"],[".password-store"],[".terraform.d"],[".config","ara"],[".config","reason"],[".config","gh"],[".config","gcloud"],[".config","infisical"],[".config","op"],[".config","1password"],[".config","pass"],[".local","share","keyrings"],["library","keychains"],["library","application support","so.ara.desktop"],["appdata","roaming","github cli"],["appdata","roaming","gcloud"],["appdata","roaming","microsoft","credentials"],["appdata","local","microsoft","credentials"],["appdata","roaming","microsoft","protect"],["appdata","roaming","1password"],["appdata","local","1password"],["appdata","roaming","microsoft","windows","start menu","programs","startup"],["documents","windowspowershell"],["documents","powershell"],["appdata","local","reason"]],Tn=[[".codex","config.toml"],[".cursor","mcp.json"],[".claude","settings.json"],[".claude","settings.local.json"],[".cargo","credentials"],[".cargo","credentials.toml"],[".gem","credentials"],[".config","git","config"],[".config","git","credentials"],[".config","pip","pip.conf"]],In=new Set([".bash_login",".bash_profile",".bashrc",".bunfig.toml",".claude.json",".env",".envrc",".git-credentials",".gitconfig",".mcp.json",".netrc",".npmrc",".profile",".pypirc",".terraformrc",".yarnrc",".yarnrc.yml",".zlogin",".zlogout",".zprofile",".zshenv",".zshrc","auth.json","credentials.json","credentials.tfrc.json","local-daemon.json","local-device.json","mcp.json"]),Dn=[".key",".p12",".pfx",".pem"];function t(n,a){if(n.length<a.length)return!1;for(let r=0;r<=n.length-a.length;r+=1)if(a.every((o,e)=>n[r+e]===o))return!0;return!1}function L(n){let a=s(n).split(i).filter(Boolean).map((o)=>o.toLowerCase());if(vt.some((o)=>t(a,o)))return!0;if(Tn.some((o)=>t(a,o)))return!0;let r=a.at(-1)??"";return In.has(r)||r.startsWith(".env.")||Dn.some((o)=>r.endsWith(o))}
3
+ export{vt,Tn,In,Dn,L};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- var at=".reason/workspace",kt="workspace_base",Oe="sessions",xt="workspace_layout",Ke=".reason/workspace/sessions",Dr=/^[0-9a-f]{8}$/;function Zt(t){if(!Ne(t))return!1;let e=".reason/workspace/sessions/";if(!t.startsWith(e))return!1;let n=t.slice(e.length).split("/");return n.length===2&&Dr.test(n[0])}var i=4096,S="workspaces/pi";function Ne(t){if(typeof t!=="string"||!t||t.length>i)return!1;if(t.startsWith("/")||t.includes("\x00")||t.includes("\\"))return!1;return t.split("/").every((e)=>e!==""&&e!=="."&&e!=="..")}function X(t){if(t.kind==="root"){if(t.path===void 0)return".";if(!Ne(t.path))throw Error("invalid_device_workspace_identity");return t.path}if(!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,159}$/.test(t.workspaceId)||t.workspaceId==="."||t.workspaceId==="..")throw Error("invalid_device_workspace_identity");let e=t.layout==="sessions"?"sessions":S;return`${t.base?`${t.base}/`:""}${e}/${t.workspaceId}/repo`}function te(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t;if(e.kind==="root"&&Object.keys(e).length===1)return{kind:"root"};if(e.kind==="root"&&Object.keys(e).length===2&&Ne(e.path))return{kind:"root",path:e.path};if(e.kind!=="managed"||typeof e.workspaceId!=="string"||Object.keys(e).length!==2+(e.base===void 0?0:1)+(e.layout===void 0?0:1)||e.base!==void 0&&e.base!==".reason/workspace"||e.layout!==void 0&&e.layout!=="sessions")return null;let n={kind:"managed",workspaceId:e.workspaceId,...e.base===".reason/workspace"?{base:".reason/workspace"}:{},...e.layout==="sessions"?{layout:"sessions"}:{}};try{return X(n),n}catch{return null}}var c="/home/runner";var Ui="/run/reason/sessions",O=/^(?:\/[A-Za-z0-9._-]+)+$/,zi=/-sidechat-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,qi=/^(.+)-repository-[a-z0-9][a-z0-9._-]*-[0-9a-f]{12}$/;function a(t){return zi.exec(t)?.[1]??qi.exec(t)?.[1]??t}var Mn=/^((?:\/[A-Za-z0-9._-]+)+)\/\.reason\/workspace\/(workspaces\/pi|sessions)\/([^/]+)$/;function _(t,e=c,n="sessions"){if(!O.test(e)||e.split("/").some((s)=>s==="."||s===".."))throw Error("invalid_cloud_payload_home");let r=`${e}/${X({kind:"managed",workspaceId:t,base:".reason/workspace",...n?{layout:n}:{}})}`,o=`${Ui}/${a(t)}`;return{home:e,root:r.slice(0,-5),checkout:r,control:o,jobEnv:`${o}/job.env`,cloudAccess:`${o}/cloud-access`,logs:`${o}/logs`,pin:`${o}/ws`}}function E(t){return Mn.exec(t.replace(/\/+$/,""))?.[2]==="sessions"?"sessions":null}function Wi(t){let e=Mn.exec(t.replace(/\/+$/,""));if(!e)return null;try{let n=_(e[3],e[1],E(t));return n.root===t.replace(/\/+$/,"")?n:null}catch{return null}}
3
- export{at,kt,Oe,xt,Ke,Dr,Zt,Ne,X,te,Ui,zi,qi,Mn,Wi};
2
+ var at=".reason/workspace",kt="workspace_base",Oe="sessions",xt="workspace_layout",Ke=".reason/workspace/sessions",Dr=/^[0-9a-f]{8}$/;function Zt(t){if(!Ne(t))return!1;let e=".reason/workspace/sessions/";if(!t.startsWith(e))return!1;let n=t.slice(e.length).split("/");return n.length===2&&Dr.test(n[0])}var i=4096,S="workspaces/pi";function Ne(t){if(typeof t!=="string"||!t||t.length>i)return!1;if(t.startsWith("/")||t.includes("\x00")||t.includes("\\"))return!1;return t.split("/").every((e)=>e!==""&&e!=="."&&e!=="..")}function X(t){if(t.kind==="root"){if(t.path===void 0)return".";if(!Ne(t.path))throw Error("invalid_device_workspace_identity");return t.path}if(!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,159}$/.test(t.workspaceId)||t.workspaceId==="."||t.workspaceId==="..")throw Error("invalid_device_workspace_identity");let e=t.layout==="sessions"?"sessions":S;return`${t.base?`${t.base}/`:""}${e}/${t.workspaceId}/repo`}function te(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t;if(e.kind==="root"&&Object.keys(e).length===1)return{kind:"root"};if(e.kind==="root"&&Object.keys(e).length===2&&Ne(e.path))return{kind:"root",path:e.path};if(e.kind!=="managed"||typeof e.workspaceId!=="string"||Object.keys(e).length!==2+(e.base===void 0?0:1)+(e.layout===void 0?0:1)||e.base!==void 0&&e.base!==".reason/workspace"||e.layout!==void 0&&e.layout!=="sessions")return null;let n={kind:"managed",workspaceId:e.workspaceId,...e.base===".reason/workspace"?{base:".reason/workspace"}:{},...e.layout==="sessions"?{layout:"sessions"}:{}};try{return X(n),n}catch{return null}}var c="/home/runner";var zi="/run/reason/sessions",O=/^(?:\/[A-Za-z0-9._-]+)+$/,qi=/-sidechat-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,Wi=/^(.+)-repository-[a-z0-9][a-z0-9._-]*-[0-9a-f]{12}$/;function a(t){return qi.exec(t)?.[1]??Wi.exec(t)?.[1]??t}var Bn=/^((?:\/[A-Za-z0-9._-]+)+)\/\.reason\/workspace\/(workspaces\/pi|sessions)\/([^/]+)$/;function _(t,e=c,n="sessions"){if(!O.test(e)||e.split("/").some((s)=>s==="."||s===".."))throw Error("invalid_cloud_payload_home");let r=`${e}/${X({kind:"managed",workspaceId:t,base:".reason/workspace",...n?{layout:n}:{}})}`,o=`${zi}/${a(t)}`;return{home:e,root:r.slice(0,-5),checkout:r,control:o,jobEnv:`${o}/job.env`,cloudAccess:`${o}/cloud-access`,logs:`${o}/logs`,pin:`${o}/ws`}}function E(t){return Bn.exec(t.replace(/\/+$/,""))?.[2]==="sessions"?"sessions":null}function Vi(t){let e=Bn.exec(t.replace(/\/+$/,""));if(!e)return null;try{let n=_(e[3],e[1],E(t));return n.root===t.replace(/\/+$/,"")?n:null}catch{return null}}
3
+ export{at,kt,Oe,xt,Ke,Dr,Zt,Ne,X,te,zi,qi,Wi,Bn,Vi};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{ht,tt,ft}from"./vm-hands-entry-lite-b1vanmtv.js";import{It,Me,Dt}from"./vm-hands-entry-lite-pg7nnyc6.js";import{spawn as A}from"child_process";import{randomUUID as s}from"crypto";import{basename as C}from"path";import{fileURLToPath as E}from"url";function S(){let p=C(process.execPath).startsWith("bun");return{command:process.execPath,args:[...p?["--no-env-file",E(new URL("./worker-candidate-entry.ts",import.meta.url))]:[],"worker","__preview-probe"]}}async function to(p,a,m=S()){if(a.aborted||!["darwin","linux","win32"].includes(process.platform)||process.platform==="win32"&&!tt())return!1;let n=new AbortController,o=()=>n.abort();a.addEventListener("abort",o,{once:!0});let y=setTimeout(o,5000),t=A(m.command,m.args,{cwd:p,...Me(),stdio:["pipe","pipe","ignore"],env:It()});Dt(t);let l=!1,b=new Promise((e)=>t.once("close",()=>{l=!0,e()}));t.on("error",o);let f,w,k=new Promise((e)=>{f=e}),I=new Promise((e)=>{w=e}),v=new Promise((e)=>n.signal.addEventListener("abort",()=>e(null),{once:!0})),i="",g=0,P=!1;t.stdout.setEncoding("utf8"),t.stdout.on("data",(e)=>{if(g+=Buffer.byteLength(e),i+=e,g>512){o();return}while(i.includes(`
2
+ import{ht,tt,ft}from"./vm-hands-entry-lite-sxnvhzy5.js";import{It,Me,Dt}from"./vm-hands-entry-lite-04nx5y4f.js";import{spawn as A}from"child_process";import{randomUUID as s}from"crypto";import{basename as C}from"path";import{fileURLToPath as E}from"url";function S(){let p=C(process.execPath).startsWith("bun");return{command:process.execPath,args:[...p?["--no-env-file",E(new URL("./worker-candidate-entry.ts",import.meta.url))]:[],"worker","__preview-probe"]}}async function ro(p,a,m=S()){if(a.aborted||!["darwin","linux","win32"].includes(process.platform)||process.platform==="win32"&&!tt())return!1;let n=new AbortController,o=()=>n.abort();a.addEventListener("abort",o,{once:!0});let y=setTimeout(o,5000),t=A(m.command,m.args,{cwd:p,...Me(),stdio:["pipe","pipe","ignore"],env:It()});Dt(t);let l=!1,b=new Promise((e)=>t.once("close",()=>{l=!0,e()}));t.on("error",o);let f,w,k=new Promise((e)=>{f=e}),I=new Promise((e)=>{w=e}),v=new Promise((e)=>n.signal.addEventListener("abort",()=>e(null),{once:!0})),i="",g=0,P=!1;t.stdout.setEncoding("utf8"),t.stdout.on("data",(e)=>{if(g+=Buffer.byteLength(e),i+=e,g>512){o();return}while(i.includes(`
3
3
  `)){let c=i.indexOf(`
4
4
  `),d=i.slice(0,c);i=i.slice(c+1);try{if(!P){let r=JSON.parse(d);if(!r||Object.keys(r).length!==2||!Number.isInteger(r.port)||r.port<1024||r.port>65535||typeof r.token!=="string"||!/^[a-zA-Z0-9_-]{43}$/.test(r.token))throw Error("probe_receipt_invalid");P=!0,f({port:r.port,token:r.token})}else if(d==="ready")w(!0);else o()}catch{o()}}}),b.then(o);let h,u=!1;try{let e=await Promise.race([k,v]);if(!e||!t.pid||n.signal.aborted||a.aborted)return!1;let c=Date.now()+4500,d=s(),r={organizationId:s(),userId:s(),runId:s(),deviceId:s(),rootId:s(),attachmentRevision:0,grantRevision:1,jobId:"readiness",generation:1,fenceId:s(),port:e.port,expiresAtMs:c},L={binding:r,executorLaunchId:d,job:{jobId:r.jobId,state:"running",startedAtMs:Date.now(),finishedAtMs:null,leaseExpiresAtMs:c,exitCode:null,inputSequence:0,output:[],firstCursor:1,nextCursor:0,truncated:!1,process:{pid:t.pid,processGroupId:t.pid,executorLaunchId:d}}},x=ft({binding:r,deniedPorts:new Set,readCurrentJob:async()=>!l&&!n.signal.aborted?L:null});h=await ht({binding:r,deviceRelayUrl:`ws://127.0.0.1:${e.port}/device/readiness/${e.token}`,port:x,signal:n.signal}),u=await Promise.race([I,v])===!0&&!n.signal.aborted&&!a.aborted}catch{u=!1}finally{if(clearTimeout(y),a.removeEventListener("abort",o),h?.close(),n.abort(),t.stdin.destroy(),!l)t.kill("SIGKILL");await b}return u&&l}
5
- export{to};
5
+ export{ro};
@@ -1,11 +1,11 @@
1
1
  // @bun
2
- import{R}from"./vm-hands-entry-lite-z65xva21.js";import{Fi,ji,St,Yt,ms,gs}from"./vm-hands-entry-lite-bkhc5mt4.js";import{uc,dc}from"./vm-hands-entry-lite-q62g6sx0.js";import{Ti,Ii,bn,yr,l,mc,Di,gc,vn,Gt,Sn}from"./vm-hands-entry-lite-1b21avcs.js";import{s}from"./vm-hands-entry-lite-12ck5swp.js";import{G}from"./vm-hands-entry-lite-pg7nnyc6.js";import{randomUUID as L}from"crypto";import{chmodSync as Z,closeSync as J,constants as C,existsSync as S,fstatSync as ke,lstatSync as h,mkdirSync as q,openSync as Ie,readFileSync as K,readdirSync as re,readlinkSync as w,realpathSync as x,renameSync as k,rmSync as T,statSync as V,symlinkSync as Q,unlinkSync as p,writeFileSync as U}from"fs";import{basename as H,dirname as E,isAbsolute as je,join as m,relative as We,resolve as M,sep as me}from"path";import{spawnSync as ee}from"child_process";import{createRequire as Te}from"module";var ae=1,xe=1,Xe=128,Qe=65536,Qc="https://reasonmachines.com/api/runtime-manifest-v2",et=30000,tt=600000,Ee=1e4,nt=60000,rt=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;var Me=/^[a-z0-9_.-]{1,80}$/,it=64,at="so.ara.device-broker",Pe=[at,"com.reasonmachines.device-broker"],Ln=ji(Pe),we=["com.apple.security.cs.allow-jit","com.apple.security.cs.allow-unsigned-executable-memory"],ot=["service.install_started","service.install_completed","service.install_failed","service.launcher_adopted","service.launcher_conflict","service.started","service.reconnecting","service.reconnected","service.idle_sleep_held","service.idle_sleep_released","service.idle_sleep_failed","service.start_failed","service.stopped","service.exit_failed","service.singleton_rejected","credential.migration_started","credential.migration_completed","credential.migration_failed","credential.store_started","credential.store_completed","credential.store_failed","credential.delete_started","credential.delete_completed","credential.delete_failed","update.check_started","update.not_available","update.download_started","update.downloaded","update.verified","update.activated","update.rollback","update.failed","executor.update.check_started","executor.update.not_available","executor.update.download_started","executor.update.downloaded","executor.update.verified","executor.update.activated","executor.update.rollback","executor.update.failed","identity.refresh_completed","identity.refresh_failed","update.device_moved","update.components_installed","update.deferred","update.deferral_expired","worker.previous_exit","worker.capabilities_withheld","identity.computer_use_unavailable"];function W(e){if(e?.aborted)throw new l("update_cancelled","Managed runtime update request was cancelled.")}function fe(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function ge(e,t,n=[]){let r=new Set([...t,...n]);return t.every((i)=>(i in e))&&Object.keys(e).every((i)=>r.has(i))}function b(e){return typeof e==="string"&&rt.test(e)}function De(e){return typeof e==="string"&&!Number.isNaN(Date.parse(e))&&new Date(e).toISOString()===e}function st(e){return yr.includes(e)}function P(e){q(e,{recursive:!0,mode:448}),Z(e,448)}function Oe(e,t){P(E(e));let n=`${e}.${process.pid}.${L()}.tmp`;try{U(n,t,{mode:384,flag:"wx"}),Z(n,384),k(n,e)}finally{if(S(n))p(n)}}function Lt(e={}){if((e.platform??process.platform)!=="darwin")throw new l("unsupported_platform","The managed Reason runtime is currently available only on macOS.");let n=e.environment??process.env,r=R(n,"REASON_CLI_CHANNEL")==="staging",i=r?R(n,"REASON_MANAGED_RUNTIME_ROOT")?.trim():void 0,o=e.root!==void 0||Boolean(i&&je(i))?null:m(e.home??s(),"Library","Application Support"),c=e.root??(o?m(o,r?"Reason Staging":"Reason","CLI"):i);return{executableName:"reason",root:c,...o?{legacyRoot:m(o,"Ara",...r?["staging","runtime"]:["runtime"])}:{},versions:m(c,"versions"),current:m(c,"current"),previous:m(c,"previous"),brokerLock:m(c,"broker.lock"),transitionLock:m(c,"transition.lock"),lifecycleEvents:m(c,"lifecycle-events")}}function bl(e){let t=e.legacyRoot;if(!t)return null;return{root:t,versions:m(t,"versions"),current:m(t,"current"),previous:m(t,"previous"),brokerLock:m(t,"broker.lock"),transitionLock:m(t,"transition.lock"),lifecycleEvents:m(t,"lifecycle-events")}}function F(e,t){if(!b(t))throw new l("invalid_version","Invalid managed Reason runtime version.");let n=m(e.versions,t,"ara");if(!e.executableName)return n;let r=m(e.versions,t,e.executableName),i=(c)=>{try{return h(c),!0}catch(d){if(d.code==="ENOENT")return!1;throw d}},a=i(n),o=i(r);if(a&&o)throw new l("installed_artifact_mismatch","Ambiguous managed runtime executable layout.");return a?n:r}function oe(e,t){if(!b(t))throw new l("invalid_version","Invalid managed Reason runtime version.");return _e(F(e,t))}function _e(e){return m(E(e),H(e)==="reason"?Ii:Ti)}function Ce(e,t){if(!b(e)||!b(t))throw new l("invalid_version","Invalid managed Reason runtime version.");let[n,r]=e.split("-",2),[i,a]=t.split("-",2),o=n.split(".").map(Number),c=i.split(".").map(Number);for(let _=0;_<3;_+=1){let g=o[_]-c[_];if(g!==0)return g<0?-1:1}if(r===void 0||a===void 0){if(r===a)return 0;return r===void 0?1:-1}let d=r.split("."),u=a.split("."),f=Math.max(d.length,u.length);for(let _=0;_<f;_+=1){let g=d[_],y=u[_];if(g===void 0||y===void 0){if(g===y)return 0;return g===void 0?-1:1}if(g===y)continue;let v=/^\d+$/.test(g),A=/^\d+$/.test(y);if(v&&A)return Number(g)<Number(y)?-1:1;if(v!==A)return v?-1:1;return g<y?-1:1}return 0}function ct(e=process.arch){let t=`darwin-${e}`;if(!st(t))throw new l("unsupported_architecture","The managed Reason runtime supports only Apple Silicon and Intel Macs.");return t}function Re(e){return[...e.matchAll(/<key>\s*([^<]+?)\s*<\/key>/g)].map((t)=>t[1].trim())}function pe(e){let t=e.match(/^CodeDirectory .*$/gm)??[];return t.length>0&&t.every((n)=>(/ flags=0x[0-9a-f]+\(([^)]*)\)(?: |$)/.exec(n)?.[1]?.split(/[ ,]+/).filter(Boolean)??[]).includes("runtime"))}function lt(e){let t=`TeamIdentifier=${Fi}`,n=Pe.map((a)=>`Identifier=${a}`),r=Re(e.brokerEntitlements),i=Re(e.credentialLibraryEntitlements);if(!e.brokerDetail.split(`
2
+ import{R}from"./vm-hands-entry-lite-ys4jhf7n.js";import{ji,Hi,St,Yt,gs,_s}from"./vm-hands-entry-lite-tv5mcw97.js";import{uc,dc}from"./vm-hands-entry-lite-chve4vmh.js";import{Ii,Di,vn,yr,l,mc,Oi,gc,Sn,Gt,En}from"./vm-hands-entry-lite-sb1xtqxr.js";import{s}from"./vm-hands-entry-lite-tzv8s0e7.js";import{G}from"./vm-hands-entry-lite-04nx5y4f.js";import{randomUUID as L}from"crypto";import{chmodSync as Z,closeSync as J,constants as C,existsSync as S,fstatSync as ke,lstatSync as h,mkdirSync as q,openSync as Ie,readFileSync as K,readdirSync as re,readlinkSync as w,realpathSync as x,renameSync as k,rmSync as T,statSync as V,symlinkSync as Q,unlinkSync as p,writeFileSync as U}from"fs";import{basename as H,dirname as E,isAbsolute as je,join as m,relative as We,resolve as M,sep as me}from"path";import{spawnSync as ee}from"child_process";import{createRequire as Te}from"module";var ae=1,xe=1,Xe=128,Qe=65536,Qc="https://reasonmachines.com/api/runtime-manifest-v2",et=30000,tt=600000,Ee=1e4,nt=60000,rt=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;var Me=/^[a-z0-9_.-]{1,80}$/,it=64,at="so.ara.device-broker",Pe=[at,"com.reasonmachines.device-broker"],Ln=Hi(Pe),we=["com.apple.security.cs.allow-jit","com.apple.security.cs.allow-unsigned-executable-memory"],ot=["service.install_started","service.install_completed","service.install_failed","service.launcher_adopted","service.launcher_conflict","service.started","service.reconnecting","service.reconnected","service.idle_sleep_held","service.idle_sleep_released","service.idle_sleep_failed","service.start_failed","service.stopped","service.exit_failed","service.singleton_rejected","credential.migration_started","credential.migration_completed","credential.migration_failed","credential.store_started","credential.store_completed","credential.store_failed","credential.delete_started","credential.delete_completed","credential.delete_failed","update.check_started","update.not_available","update.download_started","update.downloaded","update.verified","update.activated","update.rollback","update.failed","executor.update.check_started","executor.update.not_available","executor.update.download_started","executor.update.downloaded","executor.update.verified","executor.update.activated","executor.update.rollback","executor.update.failed","identity.refresh_completed","identity.refresh_failed","update.device_moved","update.components_installed","update.deferred","update.deferral_expired","worker.previous_exit","worker.capabilities_withheld","identity.computer_use_unavailable"];function W(e){if(e?.aborted)throw new l("update_cancelled","Managed runtime update request was cancelled.")}function fe(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function ge(e,t,n=[]){let r=new Set([...t,...n]);return t.every((i)=>(i in e))&&Object.keys(e).every((i)=>r.has(i))}function b(e){return typeof e==="string"&&rt.test(e)}function De(e){return typeof e==="string"&&!Number.isNaN(Date.parse(e))&&new Date(e).toISOString()===e}function st(e){return yr.includes(e)}function P(e){q(e,{recursive:!0,mode:448}),Z(e,448)}function Oe(e,t){P(E(e));let n=`${e}.${process.pid}.${L()}.tmp`;try{U(n,t,{mode:384,flag:"wx"}),Z(n,384),k(n,e)}finally{if(S(n))p(n)}}function Lt(e={}){if((e.platform??process.platform)!=="darwin")throw new l("unsupported_platform","The managed Reason runtime is currently available only on macOS.");let n=e.environment??process.env,r=R(n,"REASON_CLI_CHANNEL")==="staging",i=r?R(n,"REASON_MANAGED_RUNTIME_ROOT")?.trim():void 0,o=e.root!==void 0||Boolean(i&&je(i))?null:m(e.home??s(),"Library","Application Support"),c=e.root??(o?m(o,r?"Reason Staging":"Reason","CLI"):i);return{executableName:"reason",root:c,...o?{legacyRoot:m(o,"Ara",...r?["staging","runtime"]:["runtime"])}:{},versions:m(c,"versions"),current:m(c,"current"),previous:m(c,"previous"),brokerLock:m(c,"broker.lock"),transitionLock:m(c,"transition.lock"),lifecycleEvents:m(c,"lifecycle-events")}}function bl(e){let t=e.legacyRoot;if(!t)return null;return{root:t,versions:m(t,"versions"),current:m(t,"current"),previous:m(t,"previous"),brokerLock:m(t,"broker.lock"),transitionLock:m(t,"transition.lock"),lifecycleEvents:m(t,"lifecycle-events")}}function F(e,t){if(!b(t))throw new l("invalid_version","Invalid managed Reason runtime version.");let n=m(e.versions,t,"ara");if(!e.executableName)return n;let r=m(e.versions,t,e.executableName),i=(c)=>{try{return h(c),!0}catch(d){if(d.code==="ENOENT")return!1;throw d}},a=i(n),o=i(r);if(a&&o)throw new l("installed_artifact_mismatch","Ambiguous managed runtime executable layout.");return a?n:r}function oe(e,t){if(!b(t))throw new l("invalid_version","Invalid managed Reason runtime version.");return _e(F(e,t))}function _e(e){return m(E(e),H(e)==="reason"?Di:Ii)}function Ce(e,t){if(!b(e)||!b(t))throw new l("invalid_version","Invalid managed Reason runtime version.");let[n,r]=e.split("-",2),[i,a]=t.split("-",2),o=n.split(".").map(Number),c=i.split(".").map(Number);for(let _=0;_<3;_+=1){let g=o[_]-c[_];if(g!==0)return g<0?-1:1}if(r===void 0||a===void 0){if(r===a)return 0;return r===void 0?1:-1}let d=r.split("."),u=a.split("."),f=Math.max(d.length,u.length);for(let _=0;_<f;_+=1){let g=d[_],y=u[_];if(g===void 0||y===void 0){if(g===y)return 0;return g===void 0?-1:1}if(g===y)continue;let v=/^\d+$/.test(g),A=/^\d+$/.test(y);if(v&&A)return Number(g)<Number(y)?-1:1;if(v!==A)return v?-1:1;return g<y?-1:1}return 0}function ct(e=process.arch){let t=`darwin-${e}`;if(!st(t))throw new l("unsupported_architecture","The managed Reason runtime supports only Apple Silicon and Intel Macs.");return t}function Re(e){return[...e.matchAll(/<key>\s*([^<]+?)\s*<\/key>/g)].map((t)=>t[1].trim())}function pe(e){let t=e.match(/^CodeDirectory .*$/gm)??[];return t.length>0&&t.every((n)=>(/ flags=0x[0-9a-f]+\(([^)]*)\)(?: |$)/.exec(n)?.[1]?.split(/[ ,]+/).filter(Boolean)??[]).includes("runtime"))}function lt(e){let t=`TeamIdentifier=${ji}`,n=Pe.map((a)=>`Identifier=${a}`),r=Re(e.brokerEntitlements),i=Re(e.credentialLibraryEntitlements);if(!e.brokerDetail.split(`
3
3
  `).includes(t)||!e.brokerDetail.split(`
4
4
  `).some((a)=>n.includes(a))||!pe(e.brokerDetail)||r.length!==we.length||we.some((a)=>!new RegExp(`<key>\\s*${a.replaceAll(".","\\.")}\\s*</key>\\s*<true\\s*/>`).test(e.brokerEntitlements)))throw new l("invalid_code_signature","Managed runtime broker has an invalid Reason signature, identifier, or entitlement set.");if(!e.credentialLibraryDetail.split(`
5
- `).includes(t)||!pe(e.credentialLibraryDetail)||i.length!==0)throw new l("invalid_code_signature","Managed runtime credential library has an invalid signature or entitlement.")}function D(e,t){let n=ee("/usr/bin/codesign",e,{stdio:["ignore","pipe","pipe"]});if(n.status!==0)throw new l("invalid_code_signature",t);return[new TextDecoder().decode(n.stdout??new Uint8Array),new TextDecoder().decode(n.stderr??new Uint8Array)].join("")}var ye=(e,t)=>{D(["--verify","--strict","--verbose=2",e],"Managed runtime broker code signature is invalid."),D(["--verify","--strict","--verbose=2",t],"Managed runtime credential library code signature is invalid."),lt({brokerDetail:D(["-d","--verbose=4",e],"Managed runtime broker signer could not be inspected."),brokerEntitlements:D(["-d","--entitlements",":-",e],"Managed runtime broker entitlements could not be inspected."),credentialLibraryDetail:D(["-d","--verbose=4",t],"Managed runtime credential library signer could not be inspected."),credentialLibraryEntitlements:D(["-d","--entitlements",":-",t],"Managed runtime credential library entitlements could not be inspected.")})};async function dt(e,t,n){let r=e.headers.get("content-length");if(r!==null){let f=Number(r);if(!Number.isSafeInteger(f)||f<0||f>t)throw new l("response_too_large","Managed runtime response exceeded its size limit.")}if(!e.body){let f=new Uint8Array(await e.arrayBuffer());if(f.byteLength>t)throw new l("response_too_large","Managed runtime response exceeded its size limit.");return f}let i=e.body.getReader(),a=[],o=0,c=()=>{if(!n)return i.read();return new Promise((f,_)=>{let g=()=>{n.removeEventListener("abort",g),i.cancel(n.reason).catch(()=>{}),_(n.reason??new DOMException("Aborted","AbortError"))};if(n.aborted){g();return}n.addEventListener("abort",g,{once:!0}),i.read().then((y)=>{n.removeEventListener("abort",g),f(y)},(y)=>{n.removeEventListener("abort",g),_(y)})})};try{while(!0){let f=await c();if(f.done)break;if(o+=f.value.byteLength,o>t)throw await i.cancel(),new l("response_too_large","Managed runtime response exceeded its size limit.");a.push(f.value)}}finally{try{i.releaseLock()}catch{}}let d=new Uint8Array(o),u=0;for(let f of a)d.set(f,u),u+=f.byteLength;return d}async function Yr(e){let t;try{t=new URL(e.url)}catch{throw new l("invalid_update_url","Managed runtime update URL is invalid.")}if(t.protocol!=="https:"||t.username||t.password||t.hash)throw new l("invalid_update_url","Managed runtime update URL must use HTTPS.");let n=new AbortController,r,i=()=>{r??="caller",n.abort(e.signal?.reason)};if(e.signal?.aborted)i();else e.signal?.addEventListener("abort",i,{once:!0});let a=setTimeout(()=>{r??="timeout",n.abort(Error("managed runtime fetch timed out"))},e.timeoutMs),o=(c,d)=>{if(c instanceof l)return c;if(r==="caller")return new l("update_cancelled","Managed runtime update request was cancelled.");if(r==="timeout")return new l("update_fetch_timeout","Managed runtime update request timed out.");return new l("update_fetch_failed",d)};try{let c;try{if(c=await e.fetchImpl(t,{headers:{accept:e.accept},signal:n.signal}),n.signal.aborted)throw o(n.signal.reason,"Managed runtime update request was cancelled.")}catch(d){throw o(d,"Managed runtime update request failed.")}if(!c.ok)throw new l("update_http_error","Managed runtime update request was rejected.");if(c.url&&new URL(c.url).protocol!=="https:")throw new l("insecure_redirect","Managed runtime update redirected to an insecure URL.");try{let d=await dt(c,e.maximumBytes,n.signal);if(n.signal.aborted)throw o(n.signal.reason,"Managed runtime update response was cancelled.");return d}catch(d){throw o(d,"Managed runtime update response failed.")}}finally{clearTimeout(a),e.signal?.removeEventListener("abort",i)}}async function Ve(e,t,n=Ee,r){let i=typeof n==="number"?n:Ee,a=typeof n==="number"?r:n;if(a?.aborted)return!1;let o=await uc([e,"--version"],{timeoutMs:i,...a?{signal:a}:{}});return o.exitCode===0&&o.stdout.trim().replace(/^v/,"")===t}async function ut(e){let t=!1,n=null,r=null,i=(a)=>{try{N(e.paths,a,{now:e.now})}catch{}};try{let a=e.home??s();if(!ms(e.manifest.version,a))return{status:"current"};r=Yt(a);let o=await Yr({url:new URL(mc,e.manifest.artifacts[e.target].broker.url).toString(),maximumBytes:bn,fetchImpl:async(g,y)=>{let v=await e.fetchImpl(g,y);return t=v.status===404,v},timeoutMs:e.timeoutMs,accept:"application/json",signal:e.signal}),{manifest:c}=gc(new TextDecoder().decode(o),e.trustedKeys);if(c.version!==e.manifest.version||c.published_at!==e.manifest.published_at)throw new l("identity_manifest_mismatch","Background identity manifest names another release.");let d=c.artifacts[e.target],u=await Yr({url:d.url,maximumBytes:d.size_bytes,fetchImpl:e.fetchImpl,timeoutMs:e.timeoutMs,accept:"application/octet-stream",signal:e.signal});Gt(u,d),P(e.workDirectory),n=m(e.workDirectory,`.identity-${process.pid}-${L()}`),q(n,{mode:448});let f=m(n,"identity.tgz");if(U(f,u,{mode:384,flag:"wx"}),ee("/usr/bin/tar",["-xzf",f,"-C",n],{stdio:"ignore",timeout:60000}).status!==0)throw new l("identity_extract_failed","Background identity archive could not be extracted.");return gs({sourceApp:m(n,"Reason.app"),home:a,releaseSigned:!0,...e.command?{command:e.command}:{}}),i({event:"identity.refresh_completed",runtime_version:e.manifest.version,...r?{from_version:r}:{},to_version:e.manifest.version}),{status:"installed"}}catch(a){if(t)return{status:"unpublished"};let o=a instanceof l||a instanceof St?a.code:"identity_install_failed";return process.stderr.write(`Reason background identity: identity_update_failed (${o})
6
- `),i({event:"identity.refresh_failed",runtime_version:e.manifest.version,...r?{from_version:r}:{},to_version:e.manifest.version,reason_code:o}),{status:"failed",code:o}}finally{if(n)T(n,{recursive:!0,force:!0})}}async function vl(e){if(!b(e.currentVersion))throw new l("invalid_version","Invalid current managed runtime version.");let t=e.paths??Lt(),n=e.target??ct(),r=e.fetchImpl??fetch,i=e.timeoutMs??et,a=e.timeoutMs??tt,o=e.healthCheck??((_,g,y)=>Ve(_,g,nt,y)),c=e.verifyCodeSignatures??ye,d=e.now?.()??new Date,u,f=!1;N(t,{event:"update.check_started",runtime_version:e.currentVersion,from_version:e.currentVersion},{now:()=>d});try{await Rt({paths:t,verifyCodeSignatures:c,healthCheck:o});let _=await Yr({url:e.manifestUrl??Qc,maximumBytes:bn,fetchImpl:r,timeoutMs:i,accept:"application/json",signal:e.signal}),g=Di(new TextDecoder().decode(_),e.trustedKeys);u=g.manifest.version;let y=()=>ut({paths:t,...e.now?{now:e.now}:{},manifest:g.manifest,target:n,trustedKeys:e.trustedKeys,fetchImpl:r,timeoutMs:a,workDirectory:t.versions,...e.home?{home:e.home}:{},...e.identityCommand?{command:e.identityCommand}:{},...e.signal?{signal:e.signal}:{}});if(Ce(u,e.currentVersion)<=0)return N(t,{event:"update.not_available",runtime_version:e.currentVersion,from_version:e.currentVersion,to_version:u,duration_ms:Math.max(0,(e.now?.()??new Date).getTime()-d.getTime())},{now:e.now}),Ae(t,e.home),{status:"not_available",currentVersion:e.currentVersion,offeredVersion:u,...u===e.currentVersion?{identity:await y()}:{}};let v=g.manifest.artifacts[n];N(t,{event:"update.download_started",runtime_version:e.currentVersion,from_version:e.currentVersion,to_version:u},{now:e.now});let A=await Yr({url:v.broker.url,maximumBytes:v.broker.size_bytes,fetchImpl:r,timeoutMs:a,accept:"application/octet-stream",signal:e.signal});Gt(A,v.broker),W(e.signal);let j=await Yr({url:v.credential_library.url,maximumBytes:v.credential_library.size_bytes,fetchImpl:r,timeoutMs:a,accept:"application/octet-stream",signal:e.signal});Gt(j,v.credential_library),N(t,{event:"update.downloaded",runtime_version:e.currentVersion,from_version:e.currentVersion,to_version:u},{now:e.now}),N(t,{event:"update.verified",runtime_version:e.currentVersion,from_version:e.currentVersion,to_version:u},{now:e.now}),W(e.signal);let he=mt({paths:t,version:u,artifact:v.broker,bytes:A,credentialLibraryArtifact:v.credential_library,credentialLibraryBytes:j,verifyCodeSignatures:c}),be;try{be=await o(he.executablePath,u,e.signal)}catch(B){throw W(e.signal),B}if(W(e.signal),!be)throw new l("pre_activation_health_failed","Managed runtime preflight failed.");let I=bt(t,u);if(!I.changed&&I.toVersion!==u)return N(t,{event:"update.not_available",runtime_version:I.toVersion,from_version:I.toVersion,to_version:u,duration_ms:Math.max(0,(e.now?.()??new Date).getTime()-d.getTime())},{now:e.now}),{status:"not_available",currentVersion:I.toVersion,offeredVersion:u};if(f=I.changed,!await o(t.current,u)){if(I.fromVersion){let B=Ge(t,u);N(t,{event:"update.rollback",runtime_version:B.toVersion,from_version:B.fromVersion,to_version:B.toVersion,reason_code:"post_activation_health_failed"},{now:e.now})}else ze(t,u);throw O(t),f=!1,new l("post_activation_health_failed","Managed runtime activation failed.")}return O(t),Ae(t,e.home),N(t,{event:"update.activated",runtime_version:u,from_version:e.currentVersion,to_version:u,duration_ms:Math.max(0,(e.now?.()??new Date).getTime()-d.getTime())},{now:e.now}),{status:"activated",fromVersion:e.currentVersion,toVersion:u,installed:he.installed,identity:await y()}}catch(_){throw N(t,{event:"update.failed",runtime_version:f?u??e.currentVersion:e.currentVersion,from_version:e.currentVersion,...u?{to_version:u}:{},reason_code:_ instanceof l?_.code:"update_failed",duration_ms:Math.max(0,(e.now?.()??new Date).getTime()-d.getTime())},{now:e.now}),_}}function Le(e,t,n){try{let r=h(E(e));if(!r.isDirectory()||r.isSymbolicLink())return!1;let i=h(e);if(!i.isFile()||i.isSymbolicLink()||i.size!==t.size_bytes)return!1;let a=_e(e),o=h(a);return o.isFile()&&!o.isSymbolicLink()&&o.size===n.size_bytes&&vn(K(e))===t.sha256&&vn(K(a))===n.sha256}catch{return!1}}function mt(e){let t=F(e.paths,e.version);Gt(e.bytes,e.artifact),Gt(e.credentialLibraryBytes,e.credentialLibraryArtifact);let n=e.verifyCodeSignatures??ye;if(P(e.paths.root),P(e.paths.versions),S(E(t))){if(!Le(t,e.artifact,e.credentialLibraryArtifact))throw new l("installed_artifact_mismatch","The installed runtime version does not match the verified artifact.");return n(t,oe(e.paths,e.version)),{installed:!1,executablePath:t}}let r=m(e.paths.versions,`.install-${e.version}-${process.pid}-${L()}`),i=m(r,H(t)),a=_e(i);q(r,{mode:448});try{U(i,e.bytes,{mode:448,flag:"wx"}),Z(i,448),U(a,e.credentialLibraryBytes,{mode:448,flag:"wx"}),Z(a,448),n(i,a);try{k(r,E(t))}catch(o){if(!Le(t,e.artifact,e.credentialLibraryArtifact))throw o;return{installed:!1,executablePath:t}}return{installed:!0,executablePath:t}}finally{T(r,{recursive:!0,force:!0})}}function ft(e,t){if(!b(t))throw new l("invalid_version","Invalid managed Reason runtime version.");return`versions/${t}/${H(F(e,t))}`}function te(e,t){P(E(e));let n=`${e}.${process.pid}.${L()}.tmp`;try{Q(t,n),k(n,e)}finally{if(S(n))p(n)}}var Ue=/^\.(?:ara|reason)-worker-(\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?)-(darwin-(?:arm64|x64))\.([0-9A-Za-z]{6})$/,gt=new Set(["reason","ara"]);function Fe(e,t){let n=E(e),r=M(n,t),i=E(r),a=Ue.exec(H(i));if(!gt.has(H(r))||E(i)!==n||!a||!b(a[1])||!yr.includes(a[2]))return!1;try{return h(i).isDirectory()&&E(x(i))===x(n)&&h(r).isFile()&&h(Sn(i)).isFile()}catch(o){if(o.code==="ENOENT")return!1;throw o}}function Be(e,t,n){try{if(w(e)!==t)return!1;p(e)}catch(r){if(r.code==="ENOENT")return!1;throw r}try{return Q(n,e),!0}catch(r){if(r.code==="EEXIST")return!1;try{Q(t,e)}catch(i){if(i.code!=="EEXIST")throw i}throw r}}function _t(e,t){if(!e.legacyRoot)return!1;let n;try{if(!h(t).isSymbolicLink())return!1;n=w(t)}catch(i){if(i.code==="ENOENT")return!1;throw i}if(M(E(t),n)!==m(e.legacyRoot,"current"))return!1;if(!Be(t,n,e.current))return!1;let r=Ze(e);if(r)N(e,{event:"service.launcher_adopted",runtime_version:r,to_version:r,reason_code:"legacy_runtime_root"});return!0}function yt(e,t){let n=m(e,".local","bin"),r=m(n,"ara"),i=m(n,"reason"),a=h(r,{throwIfNoEntry:!1});if(a?.isSymbolicLink()&&w(r)==="reason")return i;if(a||!h(i,{throwIfNoEntry:!1})?.isSymbolicLink())return r;let o=w(i);return o===t.current||Fe(i,o)?i:r}function Sl(e){let t=e.launcherPath??yt(e.home??s(),e.paths);try{if(h(t).isSymbolicLink()){let r=w(t);if(r===e.paths.current)return"managed";if(Fe(t,r)&&Be(t,r,e.paths.current)){let i=se(e.paths.current,e.paths.executableName)??"unknown";return N(e.paths,{event:"service.launcher_adopted",runtime_version:i,to_version:i,reason_code:"legacy_curl_entrypoint"}),"adopted"}if(_t(e.paths,t))return"adopted"}return"conflict"}catch(n){if(n.code!=="ENOENT")throw n}q(E(t),{recursive:!0,mode:448});for(let n=0;n<4;n+=1)try{return Q(e.paths.current,t),"created"}catch(r){if(r.code!=="EEXIST")throw r;try{return h(t).isSymbolicLink()&&w(t)===e.paths.current?"managed":"conflict"}catch(i){if(i.code!=="ENOENT")throw i}}return"conflict"}function se(e,t){let n;try{if(!h(e).isSymbolicLink())return null;n=w(e)}catch{return null}let r=n.match(/^versions\/(\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?)\/(ara|Reason|reason)$/);return r&&(r[2]==="ara"||r[2]===t)?r[1]:null}function Ze(e){return se(e.current,e.executableName)}function ne(e,t,n){let i=We(t,e).split(me);return i.length===2&&b(i[0])&&(i[1]==="ara"||n!==void 0&&i[1]===n)?i[0]:null}function $e(e,t){try{return h(t).isSymbolicLink()&&M(E(t),w(t))===M(e.current)}catch{return!1}}function El(e,t=process.execPath){try{return ne(x(t),x(e.versions),e.executableName)!==null}catch{let n=M(t);return n===M(e.current)||$e(e,n)||ne(n,M(e.versions),e.executableName)!==null}}function kl(e,t=process.execPath){try{return ne(x(t),x(e.versions),e.executableName)}catch{let n=M(t);if(n===M(e.current)||$e(e,n))return Ze(e);return ne(n,M(e.versions),e.executableName)}}function vt(e,t,n=!1){let r=Ze(e);if(!r)return null;if(r===t)return{changed:!1,fromVersion:r,toVersion:r};if(!n&&Ce(t,r)<=0&&!(/^\d+\.\d+\.\d+-desktop\.v1\.\d+\.\d+\.\d+$/.test(t)&&/^\d+\.\d+\.\d+-desktopdev\./.test(r)))return{changed:!1,fromVersion:r,toVersion:r};return null}function ht(e,t,n,r=!1){let i=vt(e,t,r);if(i)return i;let a=Ze(e);if(n?.(a),a)te(e.previous,w(e.current));else if(S(e.previous))p(e.previous);return te(e.current,ft(e,t)),{changed:!0,fromVersion:a,toVersion:t}}function bt(e,t){let n=F(e,t),r=oe(e,t);if(!S(n)||!V(n).isFile()||!S(r)||!V(r).isFile())throw new l("runtime_not_installed","Managed Reason runtime version is not installed.");return ce(e,t,()=>ht(e,t,(i)=>{wt(e,{schema_version:ae,from_version:i,to_version:t})}))}function Ge(e,t){return ce(e,t,()=>{if(Ze(e)!==t)throw new l("rollback_fence_failed","Managed runtime changed before rollback could be applied.");let n=se(e.previous,e.executableName);if(!n||n===t)throw new l("rollback_unavailable","No previous managed runtime is available.");let r=F(e,n),i=oe(e,n);if(!S(r)||!V(r).isFile()||!S(i)||!V(i).isFile())throw new l("rollback_unavailable","Previous managed runtime is not installed.");let a=w(e.previous),o=w(e.current);if(M(E(e.previous),a)!==M(r))throw new l("rollback_fence_failed","Previous runtime pointer does not match its installed layout.");return te(e.current,a),te(e.previous,o),{fromVersion:t,toVersion:n}})}function Ye(){let e=ee("/bin/ps",["-axww","-o","args="],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000,maxBuffer:16777216});if(e.status!==0||typeof e.stdout!=="string")return null;let t=ee("/usr/sbin/lsof",["-nP","-w","-d","txt","-Fn"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:20000,maxBuffer:67108864});if(t.error||t.status!==0&&t.status!==1||!t.stdout)return null;return`${e.stdout}
5
+ `).includes(t)||!pe(e.credentialLibraryDetail)||i.length!==0)throw new l("invalid_code_signature","Managed runtime credential library has an invalid signature or entitlement.")}function D(e,t){let n=ee("/usr/bin/codesign",e,{stdio:["ignore","pipe","pipe"]});if(n.status!==0)throw new l("invalid_code_signature",t);return[new TextDecoder().decode(n.stdout??new Uint8Array),new TextDecoder().decode(n.stderr??new Uint8Array)].join("")}var ye=(e,t)=>{D(["--verify","--strict","--verbose=2",e],"Managed runtime broker code signature is invalid."),D(["--verify","--strict","--verbose=2",t],"Managed runtime credential library code signature is invalid."),lt({brokerDetail:D(["-d","--verbose=4",e],"Managed runtime broker signer could not be inspected."),brokerEntitlements:D(["-d","--entitlements",":-",e],"Managed runtime broker entitlements could not be inspected."),credentialLibraryDetail:D(["-d","--verbose=4",t],"Managed runtime credential library signer could not be inspected."),credentialLibraryEntitlements:D(["-d","--entitlements",":-",t],"Managed runtime credential library entitlements could not be inspected.")})};async function dt(e,t,n){let r=e.headers.get("content-length");if(r!==null){let f=Number(r);if(!Number.isSafeInteger(f)||f<0||f>t)throw new l("response_too_large","Managed runtime response exceeded its size limit.")}if(!e.body){let f=new Uint8Array(await e.arrayBuffer());if(f.byteLength>t)throw new l("response_too_large","Managed runtime response exceeded its size limit.");return f}let i=e.body.getReader(),a=[],o=0,c=()=>{if(!n)return i.read();return new Promise((f,_)=>{let g=()=>{n.removeEventListener("abort",g),i.cancel(n.reason).catch(()=>{}),_(n.reason??new DOMException("Aborted","AbortError"))};if(n.aborted){g();return}n.addEventListener("abort",g,{once:!0}),i.read().then((y)=>{n.removeEventListener("abort",g),f(y)},(y)=>{n.removeEventListener("abort",g),_(y)})})};try{while(!0){let f=await c();if(f.done)break;if(o+=f.value.byteLength,o>t)throw await i.cancel(),new l("response_too_large","Managed runtime response exceeded its size limit.");a.push(f.value)}}finally{try{i.releaseLock()}catch{}}let d=new Uint8Array(o),u=0;for(let f of a)d.set(f,u),u+=f.byteLength;return d}async function Yr(e){let t;try{t=new URL(e.url)}catch{throw new l("invalid_update_url","Managed runtime update URL is invalid.")}if(t.protocol!=="https:"||t.username||t.password||t.hash)throw new l("invalid_update_url","Managed runtime update URL must use HTTPS.");let n=new AbortController,r,i=()=>{r??="caller",n.abort(e.signal?.reason)};if(e.signal?.aborted)i();else e.signal?.addEventListener("abort",i,{once:!0});let a=setTimeout(()=>{r??="timeout",n.abort(Error("managed runtime fetch timed out"))},e.timeoutMs),o=(c,d)=>{if(c instanceof l)return c;if(r==="caller")return new l("update_cancelled","Managed runtime update request was cancelled.");if(r==="timeout")return new l("update_fetch_timeout","Managed runtime update request timed out.");return new l("update_fetch_failed",d)};try{let c;try{if(c=await e.fetchImpl(t,{headers:{accept:e.accept},signal:n.signal}),n.signal.aborted)throw o(n.signal.reason,"Managed runtime update request was cancelled.")}catch(d){throw o(d,"Managed runtime update request failed.")}if(!c.ok)throw new l("update_http_error","Managed runtime update request was rejected.");if(c.url&&new URL(c.url).protocol!=="https:")throw new l("insecure_redirect","Managed runtime update redirected to an insecure URL.");try{let d=await dt(c,e.maximumBytes,n.signal);if(n.signal.aborted)throw o(n.signal.reason,"Managed runtime update response was cancelled.");return d}catch(d){throw o(d,"Managed runtime update response failed.")}}finally{clearTimeout(a),e.signal?.removeEventListener("abort",i)}}async function Ve(e,t,n=Ee,r){let i=typeof n==="number"?n:Ee,a=typeof n==="number"?r:n;if(a?.aborted)return!1;let o=await uc([e,"--version"],{timeoutMs:i,...a?{signal:a}:{}});return o.exitCode===0&&o.stdout.trim().replace(/^v/,"")===t}async function ut(e){let t=!1,n=null,r=null,i=(a)=>{try{N(e.paths,a,{now:e.now})}catch{}};try{let a=e.home??s();if(!gs(e.manifest.version,a))return{status:"current"};r=Yt(a);let o=await Yr({url:new URL(mc,e.manifest.artifacts[e.target].broker.url).toString(),maximumBytes:vn,fetchImpl:async(g,y)=>{let v=await e.fetchImpl(g,y);return t=v.status===404,v},timeoutMs:e.timeoutMs,accept:"application/json",signal:e.signal}),{manifest:c}=gc(new TextDecoder().decode(o),e.trustedKeys);if(c.version!==e.manifest.version||c.published_at!==e.manifest.published_at)throw new l("identity_manifest_mismatch","Background identity manifest names another release.");let d=c.artifacts[e.target],u=await Yr({url:d.url,maximumBytes:d.size_bytes,fetchImpl:e.fetchImpl,timeoutMs:e.timeoutMs,accept:"application/octet-stream",signal:e.signal});Gt(u,d),P(e.workDirectory),n=m(e.workDirectory,`.identity-${process.pid}-${L()}`),q(n,{mode:448});let f=m(n,"identity.tgz");if(U(f,u,{mode:384,flag:"wx"}),ee("/usr/bin/tar",["-xzf",f,"-C",n],{stdio:"ignore",timeout:60000}).status!==0)throw new l("identity_extract_failed","Background identity archive could not be extracted.");return _s({sourceApp:m(n,"Reason.app"),home:a,releaseSigned:!0,...e.command?{command:e.command}:{}}),i({event:"identity.refresh_completed",runtime_version:e.manifest.version,...r?{from_version:r}:{},to_version:e.manifest.version}),{status:"installed"}}catch(a){if(t)return{status:"unpublished"};let o=a instanceof l||a instanceof St?a.code:"identity_install_failed";return process.stderr.write(`Reason background identity: identity_update_failed (${o})
6
+ `),i({event:"identity.refresh_failed",runtime_version:e.manifest.version,...r?{from_version:r}:{},to_version:e.manifest.version,reason_code:o}),{status:"failed",code:o}}finally{if(n)T(n,{recursive:!0,force:!0})}}async function vl(e){if(!b(e.currentVersion))throw new l("invalid_version","Invalid current managed runtime version.");let t=e.paths??Lt(),n=e.target??ct(),r=e.fetchImpl??fetch,i=e.timeoutMs??et,a=e.timeoutMs??tt,o=e.healthCheck??((_,g,y)=>Ve(_,g,nt,y)),c=e.verifyCodeSignatures??ye,d=e.now?.()??new Date,u,f=!1;N(t,{event:"update.check_started",runtime_version:e.currentVersion,from_version:e.currentVersion},{now:()=>d});try{await Rt({paths:t,verifyCodeSignatures:c,healthCheck:o});let _=await Yr({url:e.manifestUrl??Qc,maximumBytes:vn,fetchImpl:r,timeoutMs:i,accept:"application/json",signal:e.signal}),g=Oi(new TextDecoder().decode(_),e.trustedKeys);u=g.manifest.version;let y=()=>ut({paths:t,...e.now?{now:e.now}:{},manifest:g.manifest,target:n,trustedKeys:e.trustedKeys,fetchImpl:r,timeoutMs:a,workDirectory:t.versions,...e.home?{home:e.home}:{},...e.identityCommand?{command:e.identityCommand}:{},...e.signal?{signal:e.signal}:{}});if(Ce(u,e.currentVersion)<=0)return N(t,{event:"update.not_available",runtime_version:e.currentVersion,from_version:e.currentVersion,to_version:u,duration_ms:Math.max(0,(e.now?.()??new Date).getTime()-d.getTime())},{now:e.now}),Ae(t,e.home),{status:"not_available",currentVersion:e.currentVersion,offeredVersion:u,...u===e.currentVersion?{identity:await y()}:{}};let v=g.manifest.artifacts[n];N(t,{event:"update.download_started",runtime_version:e.currentVersion,from_version:e.currentVersion,to_version:u},{now:e.now});let A=await Yr({url:v.broker.url,maximumBytes:v.broker.size_bytes,fetchImpl:r,timeoutMs:a,accept:"application/octet-stream",signal:e.signal});Gt(A,v.broker),W(e.signal);let j=await Yr({url:v.credential_library.url,maximumBytes:v.credential_library.size_bytes,fetchImpl:r,timeoutMs:a,accept:"application/octet-stream",signal:e.signal});Gt(j,v.credential_library),N(t,{event:"update.downloaded",runtime_version:e.currentVersion,from_version:e.currentVersion,to_version:u},{now:e.now}),N(t,{event:"update.verified",runtime_version:e.currentVersion,from_version:e.currentVersion,to_version:u},{now:e.now}),W(e.signal);let he=mt({paths:t,version:u,artifact:v.broker,bytes:A,credentialLibraryArtifact:v.credential_library,credentialLibraryBytes:j,verifyCodeSignatures:c}),be;try{be=await o(he.executablePath,u,e.signal)}catch(B){throw W(e.signal),B}if(W(e.signal),!be)throw new l("pre_activation_health_failed","Managed runtime preflight failed.");let I=bt(t,u);if(!I.changed&&I.toVersion!==u)return N(t,{event:"update.not_available",runtime_version:I.toVersion,from_version:I.toVersion,to_version:u,duration_ms:Math.max(0,(e.now?.()??new Date).getTime()-d.getTime())},{now:e.now}),{status:"not_available",currentVersion:I.toVersion,offeredVersion:u};if(f=I.changed,!await o(t.current,u)){if(I.fromVersion){let B=Ge(t,u);N(t,{event:"update.rollback",runtime_version:B.toVersion,from_version:B.fromVersion,to_version:B.toVersion,reason_code:"post_activation_health_failed"},{now:e.now})}else ze(t,u);throw O(t),f=!1,new l("post_activation_health_failed","Managed runtime activation failed.")}return O(t),Ae(t,e.home),N(t,{event:"update.activated",runtime_version:u,from_version:e.currentVersion,to_version:u,duration_ms:Math.max(0,(e.now?.()??new Date).getTime()-d.getTime())},{now:e.now}),{status:"activated",fromVersion:e.currentVersion,toVersion:u,installed:he.installed,identity:await y()}}catch(_){throw N(t,{event:"update.failed",runtime_version:f?u??e.currentVersion:e.currentVersion,from_version:e.currentVersion,...u?{to_version:u}:{},reason_code:_ instanceof l?_.code:"update_failed",duration_ms:Math.max(0,(e.now?.()??new Date).getTime()-d.getTime())},{now:e.now}),_}}function Le(e,t,n){try{let r=h(E(e));if(!r.isDirectory()||r.isSymbolicLink())return!1;let i=h(e);if(!i.isFile()||i.isSymbolicLink()||i.size!==t.size_bytes)return!1;let a=_e(e),o=h(a);return o.isFile()&&!o.isSymbolicLink()&&o.size===n.size_bytes&&Sn(K(e))===t.sha256&&Sn(K(a))===n.sha256}catch{return!1}}function mt(e){let t=F(e.paths,e.version);Gt(e.bytes,e.artifact),Gt(e.credentialLibraryBytes,e.credentialLibraryArtifact);let n=e.verifyCodeSignatures??ye;if(P(e.paths.root),P(e.paths.versions),S(E(t))){if(!Le(t,e.artifact,e.credentialLibraryArtifact))throw new l("installed_artifact_mismatch","The installed runtime version does not match the verified artifact.");return n(t,oe(e.paths,e.version)),{installed:!1,executablePath:t}}let r=m(e.paths.versions,`.install-${e.version}-${process.pid}-${L()}`),i=m(r,H(t)),a=_e(i);q(r,{mode:448});try{U(i,e.bytes,{mode:448,flag:"wx"}),Z(i,448),U(a,e.credentialLibraryBytes,{mode:448,flag:"wx"}),Z(a,448),n(i,a);try{k(r,E(t))}catch(o){if(!Le(t,e.artifact,e.credentialLibraryArtifact))throw o;return{installed:!1,executablePath:t}}return{installed:!0,executablePath:t}}finally{T(r,{recursive:!0,force:!0})}}function ft(e,t){if(!b(t))throw new l("invalid_version","Invalid managed Reason runtime version.");return`versions/${t}/${H(F(e,t))}`}function te(e,t){P(E(e));let n=`${e}.${process.pid}.${L()}.tmp`;try{Q(t,n),k(n,e)}finally{if(S(n))p(n)}}var Ue=/^\.(?:ara|reason)-worker-(\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?)-(darwin-(?:arm64|x64))\.([0-9A-Za-z]{6})$/,gt=new Set(["reason","ara"]);function Fe(e,t){let n=E(e),r=M(n,t),i=E(r),a=Ue.exec(H(i));if(!gt.has(H(r))||E(i)!==n||!a||!b(a[1])||!yr.includes(a[2]))return!1;try{return h(i).isDirectory()&&E(x(i))===x(n)&&h(r).isFile()&&h(En(i)).isFile()}catch(o){if(o.code==="ENOENT")return!1;throw o}}function Be(e,t,n){try{if(w(e)!==t)return!1;p(e)}catch(r){if(r.code==="ENOENT")return!1;throw r}try{return Q(n,e),!0}catch(r){if(r.code==="EEXIST")return!1;try{Q(t,e)}catch(i){if(i.code!=="EEXIST")throw i}throw r}}function _t(e,t){if(!e.legacyRoot)return!1;let n;try{if(!h(t).isSymbolicLink())return!1;n=w(t)}catch(i){if(i.code==="ENOENT")return!1;throw i}if(M(E(t),n)!==m(e.legacyRoot,"current"))return!1;if(!Be(t,n,e.current))return!1;let r=Ze(e);if(r)N(e,{event:"service.launcher_adopted",runtime_version:r,to_version:r,reason_code:"legacy_runtime_root"});return!0}function yt(e,t){let n=m(e,".local","bin"),r=m(n,"ara"),i=m(n,"reason"),a=h(r,{throwIfNoEntry:!1});if(a?.isSymbolicLink()&&w(r)==="reason")return i;if(a||!h(i,{throwIfNoEntry:!1})?.isSymbolicLink())return r;let o=w(i);return o===t.current||Fe(i,o)?i:r}function Sl(e){let t=e.launcherPath??yt(e.home??s(),e.paths);try{if(h(t).isSymbolicLink()){let r=w(t);if(r===e.paths.current)return"managed";if(Fe(t,r)&&Be(t,r,e.paths.current)){let i=se(e.paths.current,e.paths.executableName)??"unknown";return N(e.paths,{event:"service.launcher_adopted",runtime_version:i,to_version:i,reason_code:"legacy_curl_entrypoint"}),"adopted"}if(_t(e.paths,t))return"adopted"}return"conflict"}catch(n){if(n.code!=="ENOENT")throw n}q(E(t),{recursive:!0,mode:448});for(let n=0;n<4;n+=1)try{return Q(e.paths.current,t),"created"}catch(r){if(r.code!=="EEXIST")throw r;try{return h(t).isSymbolicLink()&&w(t)===e.paths.current?"managed":"conflict"}catch(i){if(i.code!=="ENOENT")throw i}}return"conflict"}function se(e,t){let n;try{if(!h(e).isSymbolicLink())return null;n=w(e)}catch{return null}let r=n.match(/^versions\/(\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?)\/(ara|Reason|reason)$/);return r&&(r[2]==="ara"||r[2]===t)?r[1]:null}function Ze(e){return se(e.current,e.executableName)}function ne(e,t,n){let i=We(t,e).split(me);return i.length===2&&b(i[0])&&(i[1]==="ara"||n!==void 0&&i[1]===n)?i[0]:null}function $e(e,t){try{return h(t).isSymbolicLink()&&M(E(t),w(t))===M(e.current)}catch{return!1}}function El(e,t=process.execPath){try{return ne(x(t),x(e.versions),e.executableName)!==null}catch{let n=M(t);return n===M(e.current)||$e(e,n)||ne(n,M(e.versions),e.executableName)!==null}}function kl(e,t=process.execPath){try{return ne(x(t),x(e.versions),e.executableName)}catch{let n=M(t);if(n===M(e.current)||$e(e,n))return Ze(e);return ne(n,M(e.versions),e.executableName)}}function vt(e,t,n=!1){let r=Ze(e);if(!r)return null;if(r===t)return{changed:!1,fromVersion:r,toVersion:r};if(!n&&Ce(t,r)<=0&&!(/^\d+\.\d+\.\d+-desktop\.v1\.\d+\.\d+\.\d+$/.test(t)&&/^\d+\.\d+\.\d+-desktopdev\./.test(r)))return{changed:!1,fromVersion:r,toVersion:r};return null}function ht(e,t,n,r=!1){let i=vt(e,t,r);if(i)return i;let a=Ze(e);if(n?.(a),a)te(e.previous,w(e.current));else if(S(e.previous))p(e.previous);return te(e.current,ft(e,t)),{changed:!0,fromVersion:a,toVersion:t}}function bt(e,t){let n=F(e,t),r=oe(e,t);if(!S(n)||!V(n).isFile()||!S(r)||!V(r).isFile())throw new l("runtime_not_installed","Managed Reason runtime version is not installed.");return ce(e,t,()=>ht(e,t,(i)=>{wt(e,{schema_version:ae,from_version:i,to_version:t})}))}function Ge(e,t){return ce(e,t,()=>{if(Ze(e)!==t)throw new l("rollback_fence_failed","Managed runtime changed before rollback could be applied.");let n=se(e.previous,e.executableName);if(!n||n===t)throw new l("rollback_unavailable","No previous managed runtime is available.");let r=F(e,n),i=oe(e,n);if(!S(r)||!V(r).isFile()||!S(i)||!V(i).isFile())throw new l("rollback_unavailable","Previous managed runtime is not installed.");let a=w(e.previous),o=w(e.current);if(M(E(e.previous),a)!==M(r))throw new l("rollback_fence_failed","Previous runtime pointer does not match its installed layout.");return te(e.current,a),te(e.previous,o),{fromVersion:t,toVersion:n}})}function Ye(){let e=ee("/bin/ps",["-axww","-o","args="],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000,maxBuffer:16777216});if(e.status!==0||typeof e.stdout!=="string")return null;let t=ee("/usr/sbin/lsof",["-nP","-w","-d","txt","-Fn"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:20000,maxBuffer:67108864});if(t.error||t.status!==0&&t.status!==1||!t.stdout)return null;return`${e.stdout}
7
7
  ${t.stdout}`}function Ae(e,t){let n=[];Et(e,t??s());try{let r=Ze(e);if(!r||de(e))return n;let i=re(e.versions).filter((o)=>b(o));if(i.length<=2)return n;let a=Ye();if(a===null)return n;ce(e,r,()=>{let o=new Set([Ze(e),se(e.previous,e.executableName)]);if(de(e))return;for(let c of i){if(o.has(c))continue;let d=m(e.versions,c);if(a.includes(`${d}${me}`))continue;try{T(d,{recursive:!0,force:!0}),n.push(c)}catch{}}})}catch{}return n}function Et(e,t){try{let n=le(m(t,".local","bin"));if(!n)return;let r=["reason","ara"].flatMap((c)=>{try{return[M(n,w(m(n,c)))]}catch{return[]}}),i=le(e.current);if(!i||!r.some((c)=>le(c)===i))return;let a=re(n).filter((c)=>Ue.test(c)).map((c)=>m(n,c)).filter((c)=>!r.some((d)=>E(d)===c)).filter((c)=>Date.now()-h(c).mtimeMs>3600000);if(a.length===0)return;let o=Ye();if(o===null)return;for(let c of a){if(o.includes(`${c}${me}`))continue;try{T(c,{recursive:!0,force:!0})}catch{}}}catch{}}function le(e){try{return x(e)}catch{return null}}function ze(e,t){ce(e,t,()=>{if(Ze(e)!==t)throw new l("rollback_fence_failed","Managed runtime changed before rollback could be applied.");p(e.current)})}function ve(e){return e.activationState??m(e.root,"activation.json")}function Mt(e){return fe(e)&&ge(e,["schema_version","from_version","to_version"])&&e.schema_version===ae&&(e.from_version===null||b(e.from_version))&&b(e.to_version)}function de(e){try{let t=ve(e),n=h(t);if(!n.isFile()||n.isSymbolicLink()||n.nlink!==1||(n.mode&63)!==0||n.size>4096)throw new l("invalid_activation_state","Managed runtime activation state is invalid.");let r=JSON.parse(K(t,"utf8"));if(!Mt(r))throw new l("invalid_activation_state","Managed runtime activation state is invalid.");return r}catch(t){if(t instanceof l)throw t;if(t.code==="ENOENT")return null;throw new l("invalid_activation_state","Managed runtime activation state is invalid.")}}function wt(e,t){Oe(ve(e),JSON.stringify(t)+`
8
8
  `)}function O(e){try{p(ve(e))}catch(t){if(t.code!=="ENOENT")throw t}}async function Rt(e){let t=de(e.paths);if(!t)return"none";let n=Ze(e.paths);if(n===t.from_version)return O(e.paths),"cleared";if(n!==t.to_version)throw new l("rollback_fence_failed","Managed runtime changed before activation recovery could be applied.");let r=e.verifyCodeSignatures??ye,i=e.healthCheck??Ve,a=!1;try{let o=F(e.paths,t.to_version);r(o,oe(e.paths,t.to_version)),a=await i(o,t.to_version)}catch{a=!1}if(a)return O(e.paths),N(e.paths,{event:"update.activated",runtime_version:t.to_version,...t.from_version?{from_version:t.from_version}:{},to_version:t.to_version,reason_code:"restart_recovery"}),"committed";if(t.from_version){let o=Ge(e.paths,t.to_version);return O(e.paths),N(e.paths,{event:"update.rollback",runtime_version:o.toVersion,from_version:o.fromVersion,to_version:o.toVersion,reason_code:"restart_recovery"}),"rolled_back"}return ze(e.paths,t.to_version),O(e.paths),N(e.paths,{event:"update.rollback",runtime_version:t.to_version,from_version:t.to_version,reason_code:"restart_recovery"}),"rolled_back"}function pt(e){return fe(e)&&ge(e,["schema_version","pid","nonce","started_at","runtime_version"])&&e.schema_version===ae&&typeof e.pid==="number"&&Number.isSafeInteger(e.pid)&&e.pid>0&&typeof e.nonce==="string"&&/^[0-9a-f-]{36}$/.test(e.nonce)&&De(e.started_at)&&b(e.runtime_version)}function Je(e,t){try{let n=h(e);if(!n.isDirectory()||!G(n))return null;let r=Ie(m(e,t),C.O_RDONLY|C.O_NOFOLLOW|C.O_NONBLOCK);try{let i=ke(r);if(!i.isFile()||i.nlink!==1||!G(i)||i.size>4096)return null;return K(r,"utf8")}finally{J(r)}}catch{return null}}function ue(e){try{let t=JSON.parse(Je(e,"owner.json")??"null");return pt(t)?t:null}catch{return null}}function Ke(e){try{return process.kill(e,0),!0}catch(t){return!(t instanceof Error&&("code"in t)&&t.code==="ESRCH")}}var Ne="lease",At=2,Nt=4,Y;function kt(){if(Y!==void 0)return Y;if(Y=null,process.platform!=="linux"&&process.platform!=="darwin")return null;let e;try{e=Te(import.meta.url)("bun:ffi")}catch{return null}let t=process.platform==="darwin"?"__error":"__errno_location",n=process.platform==="darwin"?["/usr/lib/libSystem.B.dylib"]:["libc.so.6",`libc.musl-${process.arch==="arm64"?"aarch64":"x86_64"}.so.1`];for(let r of n)try{let i=e.dlopen(r,{flock:{args:[e.FFIType.i32,e.FFIType.i32],returns:e.FFIType.i32},[t]:{args:[],returns:e.FFIType.ptr}}),a=i.symbols[t]();if(a===null)continue;return Y={flock:(o,c)=>i.symbols.flock(o,c),errno:()=>e.read.i32(a),wouldBlock:process.platform==="darwin"?35:11},Y}catch{}return null}var z,It=3221225472,Tt=4,xt=128,Pt=32;function Dt(e){if(z===void 0){z=null;try{let a=Te(import.meta.url)("bun:ffi"),{FFIType:o}=a;z={kernel:a.dlopen("kernel32.dll",{CreateFileW:{args:[o.ptr,o.u32,o.u32,o.ptr,o.u32,o.u32,o.ptr],returns:o.i64_fast},CloseHandle:{args:[o.i64_fast],returns:o.i32},GetLastError:{args:[],returns:o.u32}}).symbols,ptr:(d)=>a.ptr(d)}}catch{return null}}if(!z)return null;let{kernel:t,ptr:n}=z,r=Buffer.from(`${e}\x00`,"utf16le"),i=t.CreateFileW(n(r),It,0,null,Tt,xt,null);if(Number(i)===-1)return t.GetLastError()===Pt?"busy":null;return{release:()=>{t.CloseHandle(i)}}}function Ot(e){if(process.platform==="win32")return Dt(`${e}.lease`);let t=kt();if(!t)return null;let n=Ie(`${e}.lease`,C.O_RDWR|C.O_CREAT|C.O_NOFOLLOW,384);try{let r=ke(n);if(!r.isFile()||r.nlink!==1||!G(r))return J(n),"busy";if(t.flock(n,At|Nt)===0)return{release:()=>J(n)};let i=t.errno();return J(n),i===t.wouldBlock?"busy":null}catch(r){throw J(n),r}}function ie(e){P(E(e.path));let t=Ot(e.path);if(t==="busy")return{acquired:!1,owner:ue(e.path),recoveredStaleOwner:!1};let n=t!==null;try{let r=Ct(e,t);if(r.acquired)n=!1;return r}finally{if(n)t.release()}}function Ct(e,t){let n=e.alive??Ke,r=!1;for(let i=0;i<4;i+=1){let a={schema_version:ae,pid:e.pid??process.pid,nonce:e.nonce?.()??L(),started_at:(e.now?.()??new Date).toISOString(),runtime_version:e.runtimeVersion},o=`${e.path}.init-${process.pid}-${L()}`,c=!1;try{if(q(o,{mode:448}),U(m(o,"owner.json"),`${JSON.stringify(a)}
9
9
  `,{mode:384,flag:"wx"}),t!==null)U(m(o,Ne),`flock
10
10
  `,{mode:384,flag:"wx"});e.beforePublish?.();try{throw h(e.path),Object.assign(Error("Managed runtime lock exists."),{code:"EEXIST"})}catch(u){if(u.code!=="ENOENT")throw u}k(o,e.path),c=!0;let d=!1;return{acquired:!0,owner:a,recoveredStaleOwner:r,release(){if(d)return;if(d=!0,ue(e.path)?.nonce===a.nonce)T(e.path,{recursive:!0,force:!0});t?.release()}}}catch(d){let u=d.code;if(!["EEXIST","ENOTEMPTY"].includes(u??""))throw d;let f=ue(e.path),_=(e.now?.()??new Date).getTime(),g=f&&e.staleAfterMs!==void 0?_-Date.parse(f.started_at)<e.staleAfterMs:!1,y=f!==null&&!(t!==null&&Je(e.path,Ne)!==null)&&n(f.pid);if(!f||y||g)return{acquired:!1,owner:f,recoveredStaleOwner:!1};let v=`${e.path}.stale-${process.pid}-${L()}`;try{k(e.path,v),T(v,{recursive:!0,force:!0}),r=!0}catch(A){let j=A.code;if(!["ENOENT","EEXIST"].includes(j??""))throw A}}finally{if(!c)T(o,{recursive:!0,force:!0})}}throw new l("lock_unavailable","Could not acquire the managed Reason runtime lock.")}var Vt=20000;function ce(e,t,n){if(!b(t))throw new l("invalid_version","Invalid managed Reason runtime version.");let r=Date.now()+Vt,i=ie({path:e.transitionLock,runtimeVersion:t,staleAfterMs:60000});while(!i.acquired&&Date.now()<r)dc(100),i=ie({path:e.transitionLock,runtimeVersion:t,staleAfterMs:60000});if(!i.acquired)throw new l("transition_busy","Another managed Reason runtime transition is in progress.");try{return n()}finally{i.release()}}function xl(e){if(!b(e.runtimeVersion))throw new l("invalid_version","Invalid managed Reason runtime version.");let t=e.paths??Lt();return ie({path:t.brokerLock,runtimeVersion:e.runtimeVersion,...e.pid===void 0?{}:{pid:e.pid},...e.now===void 0?{}:{now:e.now},...e.nonce===void 0?{}:{nonce:e.nonce},...e.alive===void 0?{}:{alive:e.alive},...e.beforePublish===void 0?{}:{beforePublish:e.beforePublish}})}function He(e){return fe(e)&&ge(e,["schema_version","event_id","occurred_at","event","runtime_version"],["from_version","to_version","reason_code","duration_ms","attempt_count","retry_in_ms","capabilities"])&&e.schema_version===xe&&typeof e.event_id==="string"&&/^[0-9a-f-]{36}$/.test(e.event_id)&&De(e.occurred_at)&&typeof e.event==="string"&&ot.includes(e.event)&&b(e.runtime_version)&&(e.from_version===void 0||b(e.from_version))&&(e.to_version===void 0||b(e.to_version))&&(e.reason_code===void 0||typeof e.reason_code==="string"&&Me.test(e.reason_code))&&(e.duration_ms===void 0||typeof e.duration_ms==="number"&&Number.isSafeInteger(e.duration_ms)&&e.duration_ms>=0&&e.duration_ms<=86400000)&&(e.attempt_count===void 0||typeof e.attempt_count==="number"&&Number.isSafeInteger(e.attempt_count)&&e.attempt_count>=1&&e.attempt_count<=1e5)&&(e.retry_in_ms===void 0||typeof e.retry_in_ms==="number"&&Number.isSafeInteger(e.retry_in_ms)&&e.retry_in_ms>=0&&e.retry_in_ms<=30000)&&(e.capabilities===void 0||Array.isArray(e.capabilities)&&e.capabilities.length<=it&&e.capabilities.every((t)=>typeof t==="string"&&Me.test(t)))}var Ut=/^(\d{22}-[0-9a-f-]{36}\.json)$/,Ft=/^(\d{22}-[0-9a-f-]{36}\.json)\.sending-(\d+)-[0-9a-f-]{36}$/,Bt=300000,X=0n;function $t(e){let t=BigInt(new Date(e.occurred_at).getTime())*1000000n;return X=t>X?t:X+1n,`${String(X).padStart(22,"0")}-${e.event_id}.json`}function qe(e){try{return re(e.lifecycleEvents).filter((t)=>Ut.test(t)).sort()}catch{return[]}}function Se(e){try{let t=JSON.parse(K(e,"utf8"));return He(t)?t:null}catch{return null}}function zt(e,t=Ke,n=Date.now()){let r;try{r=re(e.lifecycleEvents)}catch{return}for(let i of r){let a=i.match(Ft);if(!a)continue;let o=m(e.lifecycleEvents,i),c=m(e.lifecycleEvents,a[1]),d=!t(Number(a[2]));if(!d)try{d=n-V(o).mtimeMs>=Bt}catch{continue}if(!d)continue;try{k(o,c)}catch(u){let f=u.code;if(f==="EEXIST")p(o);else if(f!=="ENOENT")throw u}}}function Jt(e){let n=qe(e).flatMap((i)=>{try{return[{name:i,size:V(m(e.lifecycleEvents,i)).size}]}catch{return[]}}),r=n.reduce((i,a)=>i+a.size,0);while(n.length>Xe||r>Qe){let i=n.shift();if(!i)break;try{p(m(e.lifecycleEvents,i.name)),r-=i.size}catch(a){if(a.code!=="ENOENT")throw a}}}function N(e,t,n={}){let r={schema_version:xe,event_id:n.eventId?.()??L(),occurred_at:(n.now?.()??new Date).toISOString(),...t};if(!He(r))throw new l("invalid_lifecycle_event","Managed runtime lifecycle event is invalid.");return P(e.lifecycleEvents),Oe(m(e.lifecycleEvents,$t(r)),`${JSON.stringify(r)}
11
- `),Jt(e),r}async function ro(e,t,n){zt(e);let r=0;for(let i of qe(e)){let a=m(e.lifecycleEvents,i);if(n){let d=Se(a);if(!d||!n(d))continue}let o=`${a}.sending-${process.pid}-${L()}`;try{k(a,o)}catch(d){if(d.code==="ENOENT")continue;throw d}let c=Se(o);if(!c){p(o);continue}try{await t(c),p(o),r+=1}catch{try{k(o,a)}catch(d){if(d.code!=="ENOENT")throw d}break}}return r}export{Qc,Lt,bl,Yr,vl,Sl,Ze,El,kl,ie,xl,N,ro};
11
+ `),Jt(e),r}async function no(e,t,n){zt(e);let r=0;for(let i of qe(e)){let a=m(e.lifecycleEvents,i);if(n){let d=Se(a);if(!d||!n(d))continue}let o=`${a}.sending-${process.pid}-${L()}`;try{k(a,o)}catch(d){if(d.code==="ENOENT")continue;throw d}let c=Se(o);if(!c){p(o);continue}try{await t(c),p(o),r+=1}catch{try{k(o,a)}catch(d){if(d.code!=="ENOENT")throw d}break}}return r}export{Qc,Lt,bl,Yr,vl,Sl,Ze,El,kl,ie,xl,N,no};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{randomBytes as z}from"crypto";import{chmodSync as H,closeSync as B,constants as yn,linkSync as Q,lstatSync as w,mkdirSync as Z,openSync as dn,readdirSync as E,readFileSync as Y,readlinkSync as v,renameSync as D,rmdirSync as x,symlinkSync as h,unlinkSync as g}from"fs";import{createRequire as gn}from"module";import{constants as pn}from"os";import{basename as O,join as s,sep as bn}from"path";import{existsSync as R,lstatSync as U,readdirSync as an,readFileSync as ln,readlinkSync as un,realpathSync as fn}from"fs";import{join as d,sep as mn}from"path";function K(n,...r){let e=d(n,"ara"),t=d(n,"reason");if(!Mi(e))return d(t,...r);if(!R(t))return d(e,...r);return R(d(e,...r))&&!R(d(t,...r))?d(e,...r):d(t,...r)}function Mi(n){try{let r=U(n);if(!r.isSymbolicLink())return r.isDirectory();return un(n)!=="reason"&&R(n)}catch{return!1}}function W(n,r=[]){if(!Mi(n))return!1;let e;try{e=[n,...an(n,{withFileTypes:!0}).filter((t)=>t.isDirectory()).map((t)=>d(n,t.name))]}catch{return!1}return e.some((t)=>["connect","connect-once"].filter((i)=>!r.includes(d(t,i))).some((i)=>{let c=d(t,i,"worker.json");try{U(c)}catch{return!1}try{let a=JSON.parse(ln(c,"utf8"))?.stateDirectory;if(typeof a!=="string")return!0;let l=(o,u)=>o===u||o.startsWith(u+mn);return l(a,n)||l(X(a),X(n))}catch{return!0}}))}function X(n){try{return fn(n)}catch{return n}}var j=new Set(["credentials.json","local-device.json","local-device.revoked.json","local-device.auth-migration.json","local-device.json.registration-pending.json","local-daemon.json","local-daemon.json.workspaces.json","local-root-fingerprint-key.json","instances","workspaces"]),F=new Set(["local-device.proxy.json"]),kn=new Set(["local-device.key","local-device.binding"]),q=new Map;function De(n,r,e){let t=s(n,"ara");if(process.platform==="win32"||/[/\\]\.reason-ssh[/\\][^/\\]+[/\\]installer-home[/\\]\.config$/.test(n))return{state:f(t)?.isDirectory()?"kept":"absent"};return rn(t,s(n,"reason"),{linkAlways:!0,kept:(i)=>W(i,e??[]),native:r===void 0?bt:()=>r},e!==void 0)}function wt(n,...r){return De(n),K(n,...r)}function cs(n,r=process.platform){if(r==="win32")return s(n,"AppData","Local","Reason","Logs");let e=s(n,"Library","Logs");if(r==="darwin")for(let t of[""," Staging"," Development"])rn(s(e,`Ara${t}`),s(e,`Reason${t}`),{linkAlways:!1,kept:()=>!1,native:bt});return s(e,"Reason")}var nn="config_rename_unavailable:busy";function rn(n,r,e,t=!1){let i=t?void 0:q.get(n);if(i)return i;let c;try{c=En(n,r,e)}catch(a){let l=`config_rename_unavailable:${k(a)??"failed"}`;try{return{state:f(n)?.isDirectory()?"kept":"absent",problem:l}}catch{return{state:"kept",problem:l}}}if(!(c.state==="absent"&&e.linkAlways)&&c.problem!==nn&&!(c.state==="kept"&&!c.problem))q.set(n,c);return c}function En(n,r,e){vn(r,e.native);let t=!1;for(let i=0;i<8;i+=1){let c=f(n);if(c?.isSymbolicLink())return v(n)===O(r)?{state:t?"renamed":"linked"}:{state:"kept"};if(!c){if(A(r))m(()=>g(r),"ENOENT");if(!(t||e.linkAlways)||!N(r))return{state:"absent"};let o=_(r,"link");h(O(r),o);try{m(()=>D(o,n),"EISDIR","ENOTEMPTY","EEXIST","ENOTDIR")}finally{m(()=>g(o),"ENOENT")}continue}if(!c.isDirectory())return{state:"absent"};if(e.kept(n))return G(r),{state:"kept"};let a=e.native();if(!a)return G(r),{state:"kept",problem:"config_rename_unavailable:no_native"};let l=Nn(a,n);if(!l)return{state:"kept",problem:nn};try{if(w(n).isSymbolicLink())continue;let o=Sn(a,n,r);if(o)return{state:"kept",problem:o};t=!0}finally{l()}}throw Object.assign(Error("legacy directory rename did not settle"),{code:"unsettled"})}function Sn(n,r,e){let t=f(e);if(!t||A(e)){if(!t)h(O(e),e);try{n.exchange(r,e)}catch(o){if(A(e))m(()=>g(e),"ENOENT");return`config_rename_unavailable:${k(o)??"exchange_failed"}`}return null}if(!t.isDirectory())return"config_rename_unavailable:ENOTDIR";if(t.dev!==w(r).dev)return"config_rename_unavailable:EXDEV";let i=[_(e,"probe"),_(e,"probe")];try{h("a",i[0]),h("b",i[1]),n.exchange(i[0],i[1])}catch(o){return`config_rename_unavailable:${k(o)??"exchange_failed"}`}finally{for(let o of i)m(()=>g(o),"ENOENT")}let c=cn(e);for(let o of kn){let u=f(s(e,o)),y=f(s(r,o));if(u&&y&&u.ino!==y.ino)Z(`${c}-replaced`,{mode:448,recursive:!0}),D(s(e,o),s(`${c}-replaced`,o))}let a={linked:new Map,unitsKept:new Set};en(r,e,"",a);let l=_(e,"rename");h(O(e),l);try{n.exchange(r,l)}catch(o){return m(()=>g(l),"ENOENT"),`config_rename_unavailable:${k(o)??"exchange_failed"}`}return tn(l,e,a,c),null}function M(n){return n===""||!n.includes(bn)}function en(n,r,e,t){let i=M(e)&&I(s(r,e),s(n,e));if(i)t.unitsKept.add(e);for(let c of E(s(n,e))){if(i&&(j.has(c)||F.has(c)))continue;let a=s(e,c),l=s(n,a),o=s(r,a),u=f(l);if(!u)continue;let y=f(o);if(u.isDirectory()){if(!y)m(()=>Z(o,{mode:u.mode&4095}),"EEXIST"),H(o,u.mode&4095);if(N(o))en(n,r,a,t)}else if(!y){if(u.isSymbolicLink())m(()=>h(v(l),o),"EEXIST");else if(m(()=>Q(l,o),"EEXIST","ENOENT"))t.linked.set(a,u.ino)}}}function vn(n,r){let e;try{if(!N(n))return;e=E(n)}catch{return}for(let t of e){let i=/^\.(rename|link|probe|claim)-(\d+)-[0-9a-f]+$/.exec(t);if(!i)continue;let c=s(n,t),a=f(c);if(!a)continue;if(!a.isDirectory()){if(!J(Number(i[2])))m(()=>g(c),"ENOENT");continue}let l=r(),o=null;if(l){try{o=l.lock(c)}catch{continue}if(!o)continue}else if(J(Number(i[2])))continue;try{let u=_(n,"claim");if(m(()=>D(c,u),"ENOENT"))tn(u,n,null,cn(n))}finally{o?.()}}}function tn(n,r,e,t){for(let[i,c]of e?.linked??[])if(!f(s(n,i))&&f(s(r,i))?.ino===c)m(()=>g(s(r,i)),"ENOENT");if(on(n,r,"",e),m(()=>x(n),"ENOTEMPTY","EEXIST"))return;D(n,t),H(t,448)}function on(n,r,e,t){let i=M(e)&&(t?t.unitsKept.has(e):I(s(r,e),s(n,e)));for(let c of E(s(n,e))){let a=s(e,c),l=s(n,a),o=s(r,a),u=w(l),y=f(o);if(y&&u.ino===y.ino&&u.dev===y.dev){g(l);continue}if(u.isFile()&&y?.isFile()&&t?.linked.get(a)===y.ino){D(l,o);continue}if(i&&(j.has(c)||F.has(c)))continue;if(!y){if(u.isFile()){if(m(()=>Q(l,o),"EEXIST"))g(l)}else m(()=>D(l,o),"EEXIST","ENOTEMPTY");continue}if(u.isDirectory()&&y.isDirectory())on(n,r,a,t),m(()=>x(l),"ENOTEMPTY","EEXIST")}}function Sc(n){let r=s(n,"ara"),e=s(n,"reason");if(!N(r)||!N(e))return null;let t=["",...E(r,{withFileTypes:!0}).filter((i)=>i.isDirectory()&&!i.name.startsWith(".")).map((i)=>i.name)];for(let i of t){let c=s(r,i),a=s(e,i);if(!I(c,a)||!I(a,c))continue;if([...j,...F].some((o)=>P(s(c,o),s(a,o))===!1))return i}return null}function Ec(n){let r=s(n,"ara"),e=s(n,"reason");if(!N(r)||!N(e))return null;let t=(i)=>{for(let c of E(s(r,i))){let a=s(i,c);if(M(i)&&(c==="connect"||c==="connect-once"))continue;let l=w(s(r,a)),o=f(s(e,a));if(!o||l.ino===o.ino&&l.dev===o.dev)continue;if(l.isDirectory()&&o.isDirectory()&&!o.isSymbolicLink()){let u=t(a);if(u!==null)return u}else if(l.isSymbolicLink()||o.isSymbolicLink()){if(!(l.isSymbolicLink()&&o.isSymbolicLink()&&v(s(r,a))===v(s(e,a))))return a}else if(P(s(r,a),s(e,a))!==!0)return a}return null};return t("")}function P(n,r){let e=f(n),t=f(r);if(!e&&!t)return null;if(!e||!t||e.isDirectory()!==t.isDirectory())return!1;if(e.ino===t.ino&&e.dev===t.dev)return!0;if(e.isDirectory())return[...new Set([...E(n),...E(r)])].every((c)=>P(s(n,c),s(r,c))===!0);try{return Y(n).equals(Y(r))}catch{return!1}}function I(n,r){for(let e of j)if(sn(s(n,e),s(r,e)))return!0;return!1}function sn(n,r){let e=f(n);if(!e)return!1;let t=f(r);if(!t)return!0;if(e.isDirectory()){if(!t.isDirectory())return!0;return E(n).some((i)=>sn(s(n,i),s(r,i)))}if(e.isSymbolicLink())return!t.isSymbolicLink()||v(n)!==v(r);return e.ino!==t.ino||e.dev!==t.dev}function G(n){if(A(n))m(()=>g(n),"ENOENT")}function cn(n){return s(n,`.pre-rename-${new Date().toISOString().replace(/[:.]/g,"-")}-${z(3).toString("hex")}`)}function A(n){try{return w(n).isSymbolicLink()&&v(n)===O(n)}catch{return!1}}function N(n){let r=f(n);return r!==null&&r.isDirectory()}function Nn(n,r){for(let e=0;e<40;e+=1){let t=n.lock(r);if(t)return t;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,50)}return null}function _(n,r){return s(n,`.${r}-${process.pid}-${z(6).toString("hex")}`)}function J(n){if(n===process.pid)return!1;try{return process.kill(n,0),!0}catch(r){return k(r)==="EPERM"}}function f(n){try{return w(n)}catch(r){if(k(r)==="ENOENT"||k(r)==="ENOTDIR")return null;throw r}}function m(n,...r){try{return n(),!0}catch(e){if(r.includes(k(e)??""))return!1;throw e}}function k(n){return n instanceof Error&&"code"in n&&typeof n.code==="string"?n.code:void 0}var T,hn=2,Dn=4,wn=2,Tn=2,V=-100;function bt(){if(T!==void 0)return T;if(T=null,process.platform!=="linux"&&process.platform!=="darwin")return null;let n;try{n=gn(import.meta.url)("bun:ffi")}catch{return null}let r=process.platform==="darwin",e=r?"__error":"__errno_location",t=r?["/usr/lib/libSystem.B.dylib"]:["libc.so.6",`libc.musl-${process.arch==="arm64"?"aarch64":"x86_64"}.so.1`],{FFIType:i}=n;for(let c of t)try{let a=r?"renamex_np":"renameat2",o=n.dlopen(c,{flock:{args:[i.i32,i.i32],returns:i.i32},[e]:{args:[],returns:i.ptr},[a]:r?{args:[i.ptr,i.ptr,i.u32],returns:i.i32}:{args:[i.i32,i.ptr,i.i32,i.ptr,i.u32],returns:i.i32}}).symbols,u=o[e]();if(u===null)continue;let y=(S)=>{let b=n.read.i32(u),p=Object.entries(pn.errno).find(([,L])=>L===b)?.[0]??`errno_${b}`;return Object.assign(Error(`${S} failed: ${p}`),{code:p})},C=(S)=>Buffer.from(`${S}\x00`,"utf8");return T={exchange(S,b){let p=C(S),L=C(b);if((r?o[a](n.ptr(p),n.ptr(L),wn):o[a](V,n.ptr(p),V,n.ptr(L),Tn))!==0)throw y("exchange")},lock(S){let b=dn(S,yn.O_RDONLY);if(o.flock(b,hn|Dn)===0)return()=>B(b);let p=y("lock");if(B(b),p.code==="EWOULDBLOCK"||p.code==="EAGAIN")return null;throw p}},T}catch{}return null}
3
- export{Mi,De,wt,cs,Sc,Ec,bt};
2
+ import{randomBytes as z}from"crypto";import{chmodSync as H,closeSync as B,constants as yn,linkSync as Q,lstatSync as w,mkdirSync as Z,openSync as dn,readdirSync as E,readFileSync as Y,readlinkSync as v,renameSync as D,rmdirSync as x,symlinkSync as h,unlinkSync as g}from"fs";import{createRequire as gn}from"module";import{constants as pn}from"os";import{basename as O,join as s,sep as bn}from"path";import{existsSync as R,lstatSync as U,readdirSync as an,readFileSync as ln,readlinkSync as un,realpathSync as fn}from"fs";import{join as d,sep as mn}from"path";function K(n,...r){let e=d(n,"ara"),t=d(n,"reason");if(!Bi(e))return d(t,...r);if(!R(t))return d(e,...r);return R(d(e,...r))&&!R(d(t,...r))?d(e,...r):d(t,...r)}function Bi(n){try{let r=U(n);if(!r.isSymbolicLink())return r.isDirectory();return un(n)!=="reason"&&R(n)}catch{return!1}}function W(n,r=[]){if(!Bi(n))return!1;let e;try{e=[n,...an(n,{withFileTypes:!0}).filter((t)=>t.isDirectory()).map((t)=>d(n,t.name))]}catch{return!1}return e.some((t)=>["connect","connect-once"].filter((i)=>!r.includes(d(t,i))).some((i)=>{let c=d(t,i,"worker.json");try{U(c)}catch{return!1}try{let a=JSON.parse(ln(c,"utf8"))?.stateDirectory;if(typeof a!=="string")return!0;let l=(o,u)=>o===u||o.startsWith(u+mn);return l(a,n)||l(X(a),X(n))}catch{return!0}}))}function X(n){try{return fn(n)}catch{return n}}var j=new Set(["credentials.json","local-device.json","local-device.revoked.json","local-device.auth-migration.json","local-device.json.registration-pending.json","local-daemon.json","local-daemon.json.workspaces.json","local-root-fingerprint-key.json","instances","workspaces"]),F=new Set(["local-device.proxy.json"]),kn=new Set(["local-device.key","local-device.binding"]),q=new Map;function De(n,r,e){let t=s(n,"ara");if(process.platform==="win32"||/[/\\]\.reason-ssh[/\\][^/\\]+[/\\]installer-home[/\\]\.config$/.test(n))return{state:f(t)?.isDirectory()?"kept":"absent"};return rn(t,s(n,"reason"),{linkAlways:!0,kept:(i)=>W(i,e??[]),native:r===void 0?bt:()=>r},e!==void 0)}function wt(n,...r){return De(n),K(n,...r)}function ls(n,r=process.platform){if(r==="win32")return s(n,"AppData","Local","Reason","Logs");let e=s(n,"Library","Logs");if(r==="darwin")for(let t of[""," Staging"," Development"])rn(s(e,`Ara${t}`),s(e,`Reason${t}`),{linkAlways:!1,kept:()=>!1,native:bt});return s(e,"Reason")}var nn="config_rename_unavailable:busy";function rn(n,r,e,t=!1){let i=t?void 0:q.get(n);if(i)return i;let c;try{c=En(n,r,e)}catch(a){let l=`config_rename_unavailable:${k(a)??"failed"}`;try{return{state:f(n)?.isDirectory()?"kept":"absent",problem:l}}catch{return{state:"kept",problem:l}}}if(!(c.state==="absent"&&e.linkAlways)&&c.problem!==nn&&!(c.state==="kept"&&!c.problem))q.set(n,c);return c}function En(n,r,e){vn(r,e.native);let t=!1;for(let i=0;i<8;i+=1){let c=f(n);if(c?.isSymbolicLink())return v(n)===O(r)?{state:t?"renamed":"linked"}:{state:"kept"};if(!c){if(A(r))m(()=>g(r),"ENOENT");if(!(t||e.linkAlways)||!N(r))return{state:"absent"};let o=_(r,"link");h(O(r),o);try{m(()=>D(o,n),"EISDIR","ENOTEMPTY","EEXIST","ENOTDIR")}finally{m(()=>g(o),"ENOENT")}continue}if(!c.isDirectory())return{state:"absent"};if(e.kept(n))return G(r),{state:"kept"};let a=e.native();if(!a)return G(r),{state:"kept",problem:"config_rename_unavailable:no_native"};let l=Nn(a,n);if(!l)return{state:"kept",problem:nn};try{if(w(n).isSymbolicLink())continue;let o=Sn(a,n,r);if(o)return{state:"kept",problem:o};t=!0}finally{l()}}throw Object.assign(Error("legacy directory rename did not settle"),{code:"unsettled"})}function Sn(n,r,e){let t=f(e);if(!t||A(e)){if(!t)h(O(e),e);try{n.exchange(r,e)}catch(o){if(A(e))m(()=>g(e),"ENOENT");return`config_rename_unavailable:${k(o)??"exchange_failed"}`}return null}if(!t.isDirectory())return"config_rename_unavailable:ENOTDIR";if(t.dev!==w(r).dev)return"config_rename_unavailable:EXDEV";let i=[_(e,"probe"),_(e,"probe")];try{h("a",i[0]),h("b",i[1]),n.exchange(i[0],i[1])}catch(o){return`config_rename_unavailable:${k(o)??"exchange_failed"}`}finally{for(let o of i)m(()=>g(o),"ENOENT")}let c=cn(e);for(let o of kn){let u=f(s(e,o)),y=f(s(r,o));if(u&&y&&u.ino!==y.ino)Z(`${c}-replaced`,{mode:448,recursive:!0}),D(s(e,o),s(`${c}-replaced`,o))}let a={linked:new Map,unitsKept:new Set};en(r,e,"",a);let l=_(e,"rename");h(O(e),l);try{n.exchange(r,l)}catch(o){return m(()=>g(l),"ENOENT"),`config_rename_unavailable:${k(o)??"exchange_failed"}`}return tn(l,e,a,c),null}function M(n){return n===""||!n.includes(bn)}function en(n,r,e,t){let i=M(e)&&I(s(r,e),s(n,e));if(i)t.unitsKept.add(e);for(let c of E(s(n,e))){if(i&&(j.has(c)||F.has(c)))continue;let a=s(e,c),l=s(n,a),o=s(r,a),u=f(l);if(!u)continue;let y=f(o);if(u.isDirectory()){if(!y)m(()=>Z(o,{mode:u.mode&4095}),"EEXIST"),H(o,u.mode&4095);if(N(o))en(n,r,a,t)}else if(!y){if(u.isSymbolicLink())m(()=>h(v(l),o),"EEXIST");else if(m(()=>Q(l,o),"EEXIST","ENOENT"))t.linked.set(a,u.ino)}}}function vn(n,r){let e;try{if(!N(n))return;e=E(n)}catch{return}for(let t of e){let i=/^\.(rename|link|probe|claim)-(\d+)-[0-9a-f]+$/.exec(t);if(!i)continue;let c=s(n,t),a=f(c);if(!a)continue;if(!a.isDirectory()){if(!J(Number(i[2])))m(()=>g(c),"ENOENT");continue}let l=r(),o=null;if(l){try{o=l.lock(c)}catch{continue}if(!o)continue}else if(J(Number(i[2])))continue;try{let u=_(n,"claim");if(m(()=>D(c,u),"ENOENT"))tn(u,n,null,cn(n))}finally{o?.()}}}function tn(n,r,e,t){for(let[i,c]of e?.linked??[])if(!f(s(n,i))&&f(s(r,i))?.ino===c)m(()=>g(s(r,i)),"ENOENT");if(on(n,r,"",e),m(()=>x(n),"ENOTEMPTY","EEXIST"))return;D(n,t),H(t,448)}function on(n,r,e,t){let i=M(e)&&(t?t.unitsKept.has(e):I(s(r,e),s(n,e)));for(let c of E(s(n,e))){let a=s(e,c),l=s(n,a),o=s(r,a),u=w(l),y=f(o);if(y&&u.ino===y.ino&&u.dev===y.dev){g(l);continue}if(u.isFile()&&y?.isFile()&&t?.linked.get(a)===y.ino){D(l,o);continue}if(i&&(j.has(c)||F.has(c)))continue;if(!y){if(u.isFile()){if(m(()=>Q(l,o),"EEXIST"))g(l)}else m(()=>D(l,o),"EEXIST","ENOTEMPTY");continue}if(u.isDirectory()&&y.isDirectory())on(n,r,a,t),m(()=>x(l),"ENOTEMPTY","EEXIST")}}function Sc(n){let r=s(n,"ara"),e=s(n,"reason");if(!N(r)||!N(e))return null;let t=["",...E(r,{withFileTypes:!0}).filter((i)=>i.isDirectory()&&!i.name.startsWith(".")).map((i)=>i.name)];for(let i of t){let c=s(r,i),a=s(e,i);if(!I(c,a)||!I(a,c))continue;if([...j,...F].some((o)=>P(s(c,o),s(a,o))===!1))return i}return null}function Ec(n){let r=s(n,"ara"),e=s(n,"reason");if(!N(r)||!N(e))return null;let t=(i)=>{for(let c of E(s(r,i))){let a=s(i,c);if(M(i)&&(c==="connect"||c==="connect-once"))continue;let l=w(s(r,a)),o=f(s(e,a));if(!o||l.ino===o.ino&&l.dev===o.dev)continue;if(l.isDirectory()&&o.isDirectory()&&!o.isSymbolicLink()){let u=t(a);if(u!==null)return u}else if(l.isSymbolicLink()||o.isSymbolicLink()){if(!(l.isSymbolicLink()&&o.isSymbolicLink()&&v(s(r,a))===v(s(e,a))))return a}else if(P(s(r,a),s(e,a))!==!0)return a}return null};return t("")}function P(n,r){let e=f(n),t=f(r);if(!e&&!t)return null;if(!e||!t||e.isDirectory()!==t.isDirectory())return!1;if(e.ino===t.ino&&e.dev===t.dev)return!0;if(e.isDirectory())return[...new Set([...E(n),...E(r)])].every((c)=>P(s(n,c),s(r,c))===!0);try{return Y(n).equals(Y(r))}catch{return!1}}function I(n,r){for(let e of j)if(sn(s(n,e),s(r,e)))return!0;return!1}function sn(n,r){let e=f(n);if(!e)return!1;let t=f(r);if(!t)return!0;if(e.isDirectory()){if(!t.isDirectory())return!0;return E(n).some((i)=>sn(s(n,i),s(r,i)))}if(e.isSymbolicLink())return!t.isSymbolicLink()||v(n)!==v(r);return e.ino!==t.ino||e.dev!==t.dev}function G(n){if(A(n))m(()=>g(n),"ENOENT")}function cn(n){return s(n,`.pre-rename-${new Date().toISOString().replace(/[:.]/g,"-")}-${z(3).toString("hex")}`)}function A(n){try{return w(n).isSymbolicLink()&&v(n)===O(n)}catch{return!1}}function N(n){let r=f(n);return r!==null&&r.isDirectory()}function Nn(n,r){for(let e=0;e<40;e+=1){let t=n.lock(r);if(t)return t;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,50)}return null}function _(n,r){return s(n,`.${r}-${process.pid}-${z(6).toString("hex")}`)}function J(n){if(n===process.pid)return!1;try{return process.kill(n,0),!0}catch(r){return k(r)==="EPERM"}}function f(n){try{return w(n)}catch(r){if(k(r)==="ENOENT"||k(r)==="ENOTDIR")return null;throw r}}function m(n,...r){try{return n(),!0}catch(e){if(r.includes(k(e)??""))return!1;throw e}}function k(n){return n instanceof Error&&"code"in n&&typeof n.code==="string"?n.code:void 0}var T,hn=2,Dn=4,wn=2,Tn=2,V=-100;function bt(){if(T!==void 0)return T;if(T=null,process.platform!=="linux"&&process.platform!=="darwin")return null;let n;try{n=gn(import.meta.url)("bun:ffi")}catch{return null}let r=process.platform==="darwin",e=r?"__error":"__errno_location",t=r?["/usr/lib/libSystem.B.dylib"]:["libc.so.6",`libc.musl-${process.arch==="arm64"?"aarch64":"x86_64"}.so.1`],{FFIType:i}=n;for(let c of t)try{let a=r?"renamex_np":"renameat2",o=n.dlopen(c,{flock:{args:[i.i32,i.i32],returns:i.i32},[e]:{args:[],returns:i.ptr},[a]:r?{args:[i.ptr,i.ptr,i.u32],returns:i.i32}:{args:[i.i32,i.ptr,i.i32,i.ptr,i.u32],returns:i.i32}}).symbols,u=o[e]();if(u===null)continue;let y=(S)=>{let b=n.read.i32(u),p=Object.entries(pn.errno).find(([,L])=>L===b)?.[0]??`errno_${b}`;return Object.assign(Error(`${S} failed: ${p}`),{code:p})},C=(S)=>Buffer.from(`${S}\x00`,"utf8");return T={exchange(S,b){let p=C(S),L=C(b);if((r?o[a](n.ptr(p),n.ptr(L),wn):o[a](V,n.ptr(p),V,n.ptr(L),Tn))!==0)throw y("exchange")},lock(S){let b=dn(S,yn.O_RDONLY);if(o.flock(b,hn|Dn)===0)return()=>B(b);let p=y("lock");if(B(b),p.code==="EWOULDBLOCK"||p.code==="EAGAIN")return null;throw p}},T}catch{}return null}
3
+ export{Bi,De,wt,ls,Sc,Ec,bt};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{t,o,_,d,n,we,P,i}from"./vm-hands-entry-lite-zpvr7wc6.js";var Vn=25,e=1e5,a=/^[0-9a-f]{64}$/,io=n({day:t().regex(/^\d{4}-\d{2}-\d{2}$/),sent:o().int().min(0).max(e),received:o().int().min(0).max(e)}),s=20,r=n({name:t().min(1).max(100),address:t().min(1).max(300).optional()}),m=n({name:t().min(1).max(100),agent:t().min(1).max(100)}),h=n({machine:t().min(1).max(200),person:t().min(1).max(200),team:t().min(1).max(200),team_id:t().min(1).max(200).optional(),workspace:_().optional(),version:t().max(64).optional(),wait_seconds:o().int().min(0).max(Vn).optional(),message_counts:d(io).max(14).optional().catch(void 0),endpoint:t().regex(a).optional().catch(void 0),hosted:d(r).max(50).optional().catch(void 0)}),l=P("kind",[n({id:t(),kind:i("who"),all:_().optional()}),n({id:t(),kind:i("send"),to:t(),body:t(),from_name:t(),from_agent:t(),wake:_(),reply_to:t().max(100).optional(),notify:_().optional()})]),Pa=n({job:l.nullable(),retry_after_seconds:o().optional(),hosted:d(m).max(s).optional().catch(void 0)}),p=n({address:t(),person:t(),machine:t(),agent:t(),repo:t().nullable(),branch:t().nullable(),status:t(),since:o().nullable(),doing:t().nullable(),worker:_(),tier:t().max(10).optional()}),c=n({person:t(),machine:t(),online:_()}),y=n({team:t().nullable(),sessions:d(p).max(2000),machines:d(c).max(500),all:_().optional()}),x=n({address:t().max(300),state:t().max(40),note:t().max(500)}),S=we([n({who:y}),n({sent:n({ids:d(t().max(100)).max(500),recipients:d(t().max(300)).max(500),from:t().max(300),deliveries:d(x).max(500).optional()})}),n({error:t().min(1).max(2000)})]),g=n({id:t().max(100),from:t().max(300),from_agent:t().max(100).nullable(),to:t().max(300),reply_to:t().max(100).nullable(),body:t().max(64000),sent_at:o()}),f=n({messages:d(g).max(100),team:t().min(1).max(200).optional(),team_id:t().min(1).max(200).optional(),workspace:_().optional(),session:t().min(1).max(100).optional().catch(void 0),machine:t().min(1).max(200).optional().catch(void 0)});
3
- export{Vn,io,Pa};
2
+ import{t,o,_,d,n,we,P,i}from"./vm-hands-entry-lite-bt6skt4h.js";var Gn=25,e=1e5,a=/^[0-9a-f]{64}$/,oo=n({day:t().regex(/^\d{4}-\d{2}-\d{2}$/),sent:o().int().min(0).max(e),received:o().int().min(0).max(e)}),s=20,r=n({name:t().min(1).max(100),address:t().min(1).max(300).optional()}),m=n({name:t().min(1).max(100),agent:t().min(1).max(100)}),h=n({machine:t().min(1).max(200),person:t().min(1).max(200),team:t().min(1).max(200),team_id:t().min(1).max(200).optional(),workspace:_().optional(),version:t().max(64).optional(),wait_seconds:o().int().min(0).max(Gn).optional(),message_counts:d(oo).max(14).optional().catch(void 0),endpoint:t().regex(a).optional().catch(void 0),hosted:d(r).max(50).optional().catch(void 0)}),l=P("kind",[n({id:t(),kind:i("who"),all:_().optional()}),n({id:t(),kind:i("send"),to:t(),body:t(),from_name:t(),from_agent:t(),wake:_(),reply_to:t().max(100).optional(),notify:_().optional()})]),Ra=n({job:l.nullable(),retry_after_seconds:o().optional(),hosted:d(m).max(s).optional().catch(void 0)}),p=n({address:t(),person:t(),machine:t(),agent:t(),repo:t().nullable(),branch:t().nullable(),status:t(),since:o().nullable(),doing:t().nullable(),worker:_(),tier:t().max(10).optional()}),c=n({person:t(),machine:t(),online:_()}),y=n({team:t().nullable(),sessions:d(p).max(2000),machines:d(c).max(500),all:_().optional()}),x=n({address:t().max(300),state:t().max(40),note:t().max(500)}),S=we([n({who:y}),n({sent:n({ids:d(t().max(100)).max(500),recipients:d(t().max(300)).max(500),from:t().max(300),deliveries:d(x).max(500).optional()})}),n({error:t().min(1).max(2000)})]),g=n({id:t().max(100),from:t().max(300),from_agent:t().max(100).nullable(),to:t().max(300),reply_to:t().max(100).nullable(),body:t().max(64000),sent_at:o()}),f=n({messages:d(g).max(100),team:t().min(1).max(200).optional(),team_id:t().min(1).max(200).optional(),workspace:_().optional(),session:t().min(1).max(100).optional().catch(void 0),machine:t().min(1).max(200).optional().catch(void 0)});
3
+ export{Gn,oo,Ra};