@reason-machines/cli-linux-arm64-musl 0.2.282 → 0.2.284

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 (61) hide show
  1. package/bin/ara +1 -1
  2. package/bin/vm-hands/connect-cli-qgb0c8w3.js +2 -0
  3. package/bin/vm-hands/{custom-endpoint-device-92914wyp.js → custom-endpoint-device-7kd3qh6r.js} +1 -1
  4. package/bin/vm-hands/desktop-account-5kmddfvt.js +2 -0
  5. package/bin/vm-hands/{device-workspace-zk5xwd10.js → device-workspace-te28d7t5.js} +1 -1
  6. package/bin/vm-hands/{hands-worker-source-da93x0qx.js → hands-worker-source-6ts5hhas.js} +1 -1
  7. package/bin/vm-hands/{index-w9nq2f0p.js → index-9aw1gjs5.js} +1 -1
  8. package/bin/vm-hands/local-automation-hke70vcy.js +2 -0
  9. package/bin/vm-hands/local-capabilities-kx04m22x.js +2 -0
  10. package/bin/vm-hands/local-desktop-users-nxyv3mk1.js +2 -0
  11. package/bin/vm-hands/local-display-mac-rp51a8w7.js +2 -0
  12. package/bin/vm-hands/local-display-session-3ax4x1jh.js +2 -0
  13. package/bin/vm-hands/{network-contract-41qanjhp.js → network-contract-wkc0ycet.js} +1 -1
  14. package/bin/vm-hands/package-56yg8k4a.js +2 -0
  15. package/bin/vm-hands/permissions-dtrq2yvs.js +2 -0
  16. package/bin/vm-hands/{reason-hands-protocol-51gs8j7v.js → reason-hands-protocol-2gkb9qeb.js} +1 -1
  17. package/bin/vm-hands/{status-sj500a30.js → status-1gp3c1j6.js} +2 -2
  18. package/bin/vm-hands/version-h4be3gh5.js +2 -0
  19. package/bin/vm-hands/{vm-hands-entry-lite-fraghb8k.js → vm-hands-entry-lite-4fnbmmp6.js} +1 -1
  20. package/bin/vm-hands/{vm-hands-entry-lite-ptmqg51y.js → vm-hands-entry-lite-53jm8bj7.js} +2 -2
  21. package/bin/vm-hands/vm-hands-entry-lite-5pb2jqh3.js +343 -0
  22. package/bin/vm-hands/{vm-hands-entry-lite-s2xydt0n.js → vm-hands-entry-lite-5vrdj7jm.js} +2 -2
  23. package/bin/vm-hands/{vm-hands-entry-lite-am0fatcw.js → vm-hands-entry-lite-7e0r93qr.js} +2 -2
  24. package/bin/vm-hands/{vm-hands-entry-lite-54n8tmj1.js → vm-hands-entry-lite-7neqq6s2.js} +24 -23
  25. package/bin/vm-hands/{vm-hands-entry-lite-c2nrar90.js → vm-hands-entry-lite-8kqg77ym.js} +1 -1
  26. package/bin/vm-hands/{vm-hands-entry-lite-z2np2gzv.js → vm-hands-entry-lite-9dr4z8fr.js} +2 -2
  27. package/bin/vm-hands/{vm-hands-entry-lite-bw9verbt.js → vm-hands-entry-lite-avqrqtfe.js} +2 -2
  28. package/bin/vm-hands/{vm-hands-entry-lite-1nnj48qj.js → vm-hands-entry-lite-csnwmngz.js} +2 -2
  29. package/bin/vm-hands/{vm-hands-entry-lite-65pbrs1x.js → vm-hands-entry-lite-h2xpqaxn.js} +1 -1
  30. package/bin/vm-hands/{vm-hands-entry-lite-bfwf82rw.js → vm-hands-entry-lite-k1wbh9dq.js} +2 -2
  31. package/bin/vm-hands/{vm-hands-entry-lite-84aq8d12.js → vm-hands-entry-lite-kxbpf40y.js} +1 -1
  32. package/bin/vm-hands/{vm-hands-entry-lite-sv6xwe0h.js → vm-hands-entry-lite-m5pmd2cz.js} +2 -2
  33. package/bin/vm-hands/{vm-hands-entry-lite-25t4e0vk.js → vm-hands-entry-lite-pfsce35z.js} +3 -3
  34. package/bin/vm-hands/{vm-hands-entry-lite-s5qn1k80.js → vm-hands-entry-lite-qbk0wxrz.js} +2 -2
  35. package/bin/vm-hands/{vm-hands-entry-lite-7gh1rbn7.js → vm-hands-entry-lite-ss2w3h3d.js} +1 -1
  36. package/bin/vm-hands/{vm-hands-entry-lite-1fznjm91.js → vm-hands-entry-lite-vqcatbcw.js} +2 -2
  37. package/bin/vm-hands/{vm-hands-entry-lite-9pmag2qk.js → vm-hands-entry-lite-vvmq0mtv.js} +2 -2
  38. package/bin/vm-hands/{vm-hands-entry-lite-ffg7rf02.js → vm-hands-entry-lite-wffqkcjq.js} +1 -1
  39. package/bin/vm-hands/{vm-hands-entry-lite-1hwdab4e.js → vm-hands-entry-lite-whcnpjdx.js} +1 -1
  40. package/bin/vm-hands/{vm-hands-entry-lite-anaydk9m.js → vm-hands-entry-lite-y9k070mt.js} +2 -2
  41. package/bin/vm-hands/{vm-hands-entry-lite-bwt3y6wz.js → vm-hands-entry-lite-yf8h8gmh.js} +1 -1
  42. package/bin/vm-hands/{vm-hands-entry-lite-gqncr2j0.js → vm-hands-entry-lite-yh7n4svm.js} +2 -2
  43. package/bin/vm-hands/{vm-hands-entry-lite-k4c504n7.js → vm-hands-entry-lite-yvmzze06.js} +1 -1
  44. package/bin/vm-hands/vm-hands-entry-lite.js +1 -1
  45. package/bin/vm-hands/{vm-hands-executor-p7kq9n00.js → vm-hands-executor-jqm7qrjs.js} +1 -1
  46. package/bin/vm-hands/{vm-hands-op-runner-350k7hem.js → vm-hands-op-runner-t3w7aasf.js} +1 -1
  47. package/bin/vm-hands/{vm-hands-runtime-st3eagc2.js → vm-hands-runtime-4fsnx2aq.js} +3 -3
  48. package/bin/vm-hands/worker-sandbox-4c9302zr.js +2 -0
  49. package/package.json +1 -1
  50. package/bin/vm-hands/connect-cli-26easn4y.js +0 -2
  51. package/bin/vm-hands/desktop-account-vsrtgkk9.js +0 -2
  52. package/bin/vm-hands/local-automation-hk8bgn7w.js +0 -2
  53. package/bin/vm-hands/local-capabilities-j6cmcwdc.js +0 -2
  54. package/bin/vm-hands/local-desktop-users-3j79jbyp.js +0 -2
  55. package/bin/vm-hands/local-display-mac-j1v3mcgx.js +0 -2
  56. package/bin/vm-hands/local-display-session-4402sa84.js +0 -2
  57. package/bin/vm-hands/package-rx9y4bwe.js +0 -2
  58. package/bin/vm-hands/permissions-avhf90my.js +0 -2
  59. package/bin/vm-hands/version-zanrbm0q.js +0 -2
  60. package/bin/vm-hands/vm-hands-entry-lite-21zpypby.js +0 -343
  61. package/bin/vm-hands/worker-sandbox-nnce49w0.js +0 -2
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Ab as W9,Bb as u0,Ib as z0,wb as WQ,xb as Z8,yb as u9,zb as q0}from"./vm-hands-entry-lite-c2nrar90.js";import{Qb as PQ,Rb as IQ,Sb as rZ,Tb as tZ,Ub as G8}from"./vm-hands-entry-lite-qvrnx0vk.js";import{Zb as R0}from"./vm-hands-entry-lite-n07kxrd1.js";import{Mc as a$,Pc as o$,sd as R9,td as n0,ud as H8,vd as w0,zd as N0}from"./vm-hands-entry-lite-gqncr2j0.js";import{_d as I}from"./vm-hands-entry-lite-sv6xwe0h.js";import{Ie as kQ,Je as f8,Xe as wQ,bf as s9,cf as w8}from"./vm-hands-entry-lite-bfwf82rw.js";import{Bf as c9,Jf as A8,Kf as P0,Lf as j0,Mf as d9,Tf as R8,Uf as $Q,Vf as l$,ef as WZ,hf as F9,qf as r$,rf as t$,tf as e$,vf as v9,wf as p$,xf as u$,yf as x8}from"./vm-hands-entry-lite-ptmqg51y.js";import{Vg as aZ}from"./vm-hands-entry-lite-s5qn1k80.js";import{$g as iZ,Xg as U8,Yg as p9}from"./vm-hands-entry-lite-9pmag2qk.js";import{ah as F8,bh as l0,ch as W8,dh as s0,eh as K9,fh as Q8,gh as r8,hh as p0,ih as v0,jh as d$,th as F$}from"./vm-hands-entry-lite-84aq8d12.js";import{yh as JZ}from"./vm-hands-entry-lite-1fznjm91.js";import{Eh as oZ}from"./vm-hands-entry-lite-anaydk9m.js";import{Gh as C}from"./vm-hands-entry-lite-ffg7rf02.js";import{Hh as L1,Kh as ZZ}from"./vm-hands-entry-lite-7gh1rbn7.js";var v={chunk:32768,upload:1048576,total:536870912,streams:16,queued:512,buffered:262144,relayBuffered:8388608,requestMs:30000,lifetimeMs:600000,authorizationMs:2000};function g9($){return $!==null&&typeof $==="object"&&!Array.isArray($)}function g0($,Q,Z=Number.MAX_SAFE_INTEGER){return typeof $==="number"&&Number.isSafeInteger($)&&$>=Q&&$<=Z}function I$($){return typeof $==="string"&&/^[a-zA-Z0-9_-]{1,160}$/.test($)}function _0($){if(!g9($)||Object.keys($).length!==12||![$.organizationId,$.userId,$.runId,$.deviceId,$.rootId,$.jobId,$.fenceId].every(I$)||!g0($.attachmentRevision,0)||!g0($.grantRevision,1)||!g0($.generation,1)||!g0($.port,1024,65535)||!g0($.expiresAtMs,1))throw Error("preview_binding_invalid");return Object.freeze({...$})}function y0($,Q){return Object.keys($).every((Z)=>$[Z]===Q[Z])}function M9($){if($.length>4096||!$.startsWith("/")||$.startsWith("//")||/[\\\x00-\x20\x7f#]/.test($))throw Error("preview_path_invalid");let Q=decodeURIComponent($);if(Q.startsWith("//")||/[\\\x00-\x1f\x7f]/.test(Q))throw Error("preview_path_invalid");return $}function P$($){return Array.isArray($)&&$.length<=64&&$.every((Q)=>Array.isArray(Q)&&Q.length===2&&typeof Q[0]==="string"&&/^[a-zA-Z0-9-]{1,80}$/.test(Q[0])&&typeof Q[1]==="string"&&Q[1].length<=4096&&!/[\x00-\x1f\x7f]/.test(Q[1]))}function N9($,Q=v.chunk){if($.length>Math.ceil(Q/3)*4||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test($))throw Error("preview_data_invalid");let Z=Buffer.from($,"base64");if(Z.length>Q)throw Error("preview_data_too_large");return Z}function R$($){if(Array.isArray($))return Buffer.concat($);if(typeof $==="string")return Buffer.from($,"utf8");if($ instanceof ArrayBuffer)return Buffer.from($);return $}function E$($){if(Buffer.byteLength($)>v.upload*1.4+300000)throw Error("preview_frame_too_large");let Q=JSON.parse($);if(!g9(Q))throw Error("preview_frame_invalid");if(Q.type==="hello"){let Z=_0(Q.binding);return g0(Q.messages,v.chunk,v.upload)?{type:"hello",binding:Z,messages:Q.messages}:{type:"hello",binding:Z}}if(Q.type==="refused"&&typeof Q.reason==="string"&&/^[a-z_]{1,32}$/.test(Q.reason))return{type:"refused",binding:_0(Q.binding),reason:Q.reason};if(!I$(Q.id))throw Error("preview_frame_invalid");if(Q.type==="end"||Q.type==="cancel"||Q.type==="credit")return{type:Q.type,id:Q.id};if(Q.type==="ws"&&typeof Q.protocol==="string"&&/^[a-zA-Z0-9._-]{0,100}$/.test(Q.protocol))return{type:"ws",id:Q.id,protocol:Q.protocol};if(Q.type==="data"&&typeof Q.data==="string"&&typeof Q.binary==="boolean")return N9(Q.data,v.upload),{type:"data",id:Q.id,data:Q.data,binary:Q.binary};if(Q.type==="head"&&g0(Q.status,200,599)&&P$(Q.headers))return{type:"head",id:Q.id,status:Q.status,headers:Q.headers};if(Q.type==="request"&&typeof Q.method==="string"&&/^(GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS)$/.test(Q.method)&&typeof Q.path==="string"&&P$(Q.headers)&&typeof Q.body==="string"&&typeof Q.upgrade==="boolean")return N9(Q.body,v.upload),{type:"request",id:Q.id,method:Q.method,path:M9(Q.path),headers:Q.headers,body:Q.body,upgrade:Q.upgrade};throw Error("preview_frame_invalid")}function T8($){let Q=[...$],Z=new Set(Q.filter(([J])=>J.toLowerCase()==="connection").flatMap(([,J])=>J.toLowerCase().split(",").map((G)=>G.trim()))),X=new Set(["authorization","proxy-authorization","cookie","set-cookie","host","origin","referer","connection","upgrade","keep-alive","transfer-encoding","te","trailer","content-length","forwarded","alt-svc","service-worker-allowed","clear-site-data","refresh"]);return Q.filter(([J])=>!X.has(J.toLowerCase())&&!Z.has(J.toLowerCase())&&!/^(x-forwarded-|x-ara-|sec-websocket-|access-control-)/i.test(J))}async function O8($){let Q;try{return await Promise.race([Promise.resolve().then($).then((Z)=>Z===!0||(Z===!1?!1:void 0),()=>{return}),new Promise((Z)=>{Q=setTimeout(()=>Z(void 0),v.authorizationMs)})])}finally{clearTimeout(Q)}}async function j9($){return await O8($)===!0}function y9($,Q){let Z=new URL($);if(Z.username||Z.password||Z.search||Z.hash||!(Z.protocol==="wss:"||Z.protocol==="ws:"&&["127.0.0.1","[::1]"].includes(Z.hostname))||!new RegExp(`^/${Q}/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]{32,}$`).test(Z.pathname))throw Error("preview_relay_invalid");return Z.href}function S$($){if(!g9($)||Object.keys($).length!==2||typeof $.deviceRelayUrl!=="string")throw Error("preview_open_invalid");return{binding:_0($.binding),deviceRelayUrl:y9($.deviceRelayUrl,"device")}}function w$($){if(!g9($)||Object.keys($).length!==1||!("binding"in $))throw Error("preview_close_invalid");return{binding:_0($.binding)}}import{request as B4}from"http";import{WebSocket as C9}from"ws";import{randomBytes as F4,timingSafeEqual as W4}from"crypto";import{createServer as U4}from"net";var b$="x-preview-connection";async function k$($,Q){if(Q.aborted)throw Error("preview_closed");let Z=F4(32).toString("base64url"),X=new Set,J=!1,G=U4((Y)=>{if(J||Q.aborted||X.size>=v.streams*2)return Y.destroy();X.add(Y);let H=new AbortController;Y.once("close",()=>{X.delete(Y),H.abort()}),Y.on("error",()=>Y.destroy()),Y.setTimeout(2000,()=>Y.destroy());let W=Buffer.alloc(0),F=(L)=>{W=Buffer.concat([W,L]);let B=W.indexOf(`\r
2
+ import{Ab as W9,Bb as u0,Ib as z0,wb as WQ,xb as Z8,yb as u9,zb as q0}from"./vm-hands-entry-lite-8kqg77ym.js";import{Qb as PQ,Rb as IQ,Sb as rZ,Tb as tZ,Ub as G8}from"./vm-hands-entry-lite-qvrnx0vk.js";import{Zb as R0}from"./vm-hands-entry-lite-n07kxrd1.js";import{Bd as N0,Oc as a$,Rc as o$,ud as R9,vd as n0,wd as H8,xd as w0}from"./vm-hands-entry-lite-yh7n4svm.js";import{ae as I}from"./vm-hands-entry-lite-m5pmd2cz.js";import{Ke as kQ,Le as f8,Ze as wQ,df as s9,ef as w8}from"./vm-hands-entry-lite-k1wbh9dq.js";import{Af as x8,Df as c9,Lf as A8,Mf as P0,Nf as j0,Of as d9,Vf as R8,Wf as $Q,Xf as l$,gf as WZ,jf as F9,sf as r$,tf as t$,vf as e$,xf as v9,yf as p$,zf as u$}from"./vm-hands-entry-lite-53jm8bj7.js";import{Xg as aZ}from"./vm-hands-entry-lite-qbk0wxrz.js";import{Zg as U8,_g as p9,bh as iZ}from"./vm-hands-entry-lite-vvmq0mtv.js";import{ch as F8,dh as l0,eh as W8,fh as s0,gh as K9,hh as Q8,ih as r8,jh as p0,kh as v0,lh as d$,vh as F$}from"./vm-hands-entry-lite-kxbpf40y.js";import{Ah as JZ}from"./vm-hands-entry-lite-vqcatbcw.js";import{Gh as oZ}from"./vm-hands-entry-lite-y9k070mt.js";import{Ih as C}from"./vm-hands-entry-lite-wffqkcjq.js";import{Jh as L1,Mh as ZZ}from"./vm-hands-entry-lite-ss2w3h3d.js";var v={chunk:32768,upload:1048576,total:536870912,streams:16,queued:512,buffered:262144,relayBuffered:8388608,requestMs:30000,lifetimeMs:600000,authorizationMs:2000};function g9($){return $!==null&&typeof $==="object"&&!Array.isArray($)}function g0($,Q,Z=Number.MAX_SAFE_INTEGER){return typeof $==="number"&&Number.isSafeInteger($)&&$>=Q&&$<=Z}function I$($){return typeof $==="string"&&/^[a-zA-Z0-9_-]{1,160}$/.test($)}function _0($){if(!g9($)||Object.keys($).length!==12||![$.organizationId,$.userId,$.runId,$.deviceId,$.rootId,$.jobId,$.fenceId].every(I$)||!g0($.attachmentRevision,0)||!g0($.grantRevision,1)||!g0($.generation,1)||!g0($.port,1024,65535)||!g0($.expiresAtMs,1))throw Error("preview_binding_invalid");return Object.freeze({...$})}function y0($,Q){return Object.keys($).every((Z)=>$[Z]===Q[Z])}function M9($){if($.length>4096||!$.startsWith("/")||$.startsWith("//")||/[\\\x00-\x20\x7f#]/.test($))throw Error("preview_path_invalid");let Q=decodeURIComponent($);if(Q.startsWith("//")||/[\\\x00-\x1f\x7f]/.test(Q))throw Error("preview_path_invalid");return $}function P$($){return Array.isArray($)&&$.length<=64&&$.every((Q)=>Array.isArray(Q)&&Q.length===2&&typeof Q[0]==="string"&&/^[a-zA-Z0-9-]{1,80}$/.test(Q[0])&&typeof Q[1]==="string"&&Q[1].length<=4096&&!/[\x00-\x1f\x7f]/.test(Q[1]))}function N9($,Q=v.chunk){if($.length>Math.ceil(Q/3)*4||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test($))throw Error("preview_data_invalid");let Z=Buffer.from($,"base64");if(Z.length>Q)throw Error("preview_data_too_large");return Z}function R$($){if(Array.isArray($))return Buffer.concat($);if(typeof $==="string")return Buffer.from($,"utf8");if($ instanceof ArrayBuffer)return Buffer.from($);return $}function E$($){if(Buffer.byteLength($)>v.upload*1.4+300000)throw Error("preview_frame_too_large");let Q=JSON.parse($);if(!g9(Q))throw Error("preview_frame_invalid");if(Q.type==="hello"){let Z=_0(Q.binding);return g0(Q.messages,v.chunk,v.upload)?{type:"hello",binding:Z,messages:Q.messages}:{type:"hello",binding:Z}}if(Q.type==="refused"&&typeof Q.reason==="string"&&/^[a-z_]{1,32}$/.test(Q.reason))return{type:"refused",binding:_0(Q.binding),reason:Q.reason};if(!I$(Q.id))throw Error("preview_frame_invalid");if(Q.type==="end"||Q.type==="cancel"||Q.type==="credit")return{type:Q.type,id:Q.id};if(Q.type==="ws"&&typeof Q.protocol==="string"&&/^[a-zA-Z0-9._-]{0,100}$/.test(Q.protocol))return{type:"ws",id:Q.id,protocol:Q.protocol};if(Q.type==="data"&&typeof Q.data==="string"&&typeof Q.binary==="boolean")return N9(Q.data,v.upload),{type:"data",id:Q.id,data:Q.data,binary:Q.binary};if(Q.type==="head"&&g0(Q.status,200,599)&&P$(Q.headers))return{type:"head",id:Q.id,status:Q.status,headers:Q.headers};if(Q.type==="request"&&typeof Q.method==="string"&&/^(GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS)$/.test(Q.method)&&typeof Q.path==="string"&&P$(Q.headers)&&typeof Q.body==="string"&&typeof Q.upgrade==="boolean")return N9(Q.body,v.upload),{type:"request",id:Q.id,method:Q.method,path:M9(Q.path),headers:Q.headers,body:Q.body,upgrade:Q.upgrade};throw Error("preview_frame_invalid")}function T8($){let Q=[...$],Z=new Set(Q.filter(([J])=>J.toLowerCase()==="connection").flatMap(([,J])=>J.toLowerCase().split(",").map((G)=>G.trim()))),X=new Set(["authorization","proxy-authorization","cookie","set-cookie","host","origin","referer","connection","upgrade","keep-alive","transfer-encoding","te","trailer","content-length","forwarded","alt-svc","service-worker-allowed","clear-site-data","refresh"]);return Q.filter(([J])=>!X.has(J.toLowerCase())&&!Z.has(J.toLowerCase())&&!/^(x-forwarded-|x-ara-|sec-websocket-|access-control-)/i.test(J))}async function O8($){let Q;try{return await Promise.race([Promise.resolve().then($).then((Z)=>Z===!0||(Z===!1?!1:void 0),()=>{return}),new Promise((Z)=>{Q=setTimeout(()=>Z(void 0),v.authorizationMs)})])}finally{clearTimeout(Q)}}async function j9($){return await O8($)===!0}function y9($,Q){let Z=new URL($);if(Z.username||Z.password||Z.search||Z.hash||!(Z.protocol==="wss:"||Z.protocol==="ws:"&&["127.0.0.1","[::1]"].includes(Z.hostname))||!new RegExp(`^/${Q}/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]{32,}$`).test(Z.pathname))throw Error("preview_relay_invalid");return Z.href}function S$($){if(!g9($)||Object.keys($).length!==2||typeof $.deviceRelayUrl!=="string")throw Error("preview_open_invalid");return{binding:_0($.binding),deviceRelayUrl:y9($.deviceRelayUrl,"device")}}function w$($){if(!g9($)||Object.keys($).length!==1||!("binding"in $))throw Error("preview_close_invalid");return{binding:_0($.binding)}}import{request as B4}from"http";import{WebSocket as C9}from"ws";import{randomBytes as F4,timingSafeEqual as W4}from"crypto";import{createServer as U4}from"net";var b$="x-preview-connection";async function k$($,Q){if(Q.aborted)throw Error("preview_closed");let Z=F4(32).toString("base64url"),X=new Set,J=!1,G=U4((Y)=>{if(J||Q.aborted||X.size>=v.streams*2)return Y.destroy();X.add(Y);let H=new AbortController;Y.once("close",()=>{X.delete(Y),H.abort()}),Y.on("error",()=>Y.destroy()),Y.setTimeout(2000,()=>Y.destroy());let W=Buffer.alloc(0),F=(L)=>{W=Buffer.concat([W,L]);let B=W.indexOf(`\r
3
3
  \r
4
4
  `);if(B<0){if(W.length>16384)Y.destroy();return}if(Y.pause(),Y.off("data",F),B>16384||W.length>v.upload+16384)return Y.destroy();K(W,B).catch(()=>Y.destroy())};Y.on("data",F);async function K(L,B){let U=L.subarray(0,B).toString("latin1").split(`\r
5
5
  `),M=/^(GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS) (\S+) HTTP\/1\.1$/.exec(U.shift()??"");if(!M)throw Error("preview_request_invalid");M9(M[2]);let _=!1,q=0,D=[];for(let T of U){let k=/^([a-zA-Z0-9-]+):[ \t]*([^\x00-\x08\x0a-\x1f\x7f]*)$/.exec(T);if(!k)throw Error("preview_header_invalid");if(k[1].toLowerCase()===b$){q++;let g=Buffer.from(k[2].trim());_=g.length===Z.length&&W4(g,Buffer.from(Z))}else if(k[1].toLowerCase()!=="host")D.push(T)}if(!_||q!==1||J||H.signal.aborted)throw Error("preview_connection_denied");let x=await $.connect(H.signal);if(J||H.signal.aborted)throw x.destroy(),Error("preview_closed");X.add(x),x.on("error",()=>Y.destroy()),x.once("close",()=>{X.delete(x),Y.destroy()}),Y.once("close",()=>x.destroy()),Y.setTimeout(0);let b=[`${M[1]} ${M[2]} HTTP/1.1`,`Host: 127.0.0.1:${x.remotePort}`,...D,"",""].join(`\r
@@ -303,7 +303,7 @@ async (input) => {
303
303
  if (!bridge || typeof bridge.evaluate !== "function") throw new Error("Reason Hands browser bridge is not installed");
304
304
  return await bridge.evaluate(typeof input === "string" ? input : input && input.code);
305
305
  }
306
- `.trim();import{Buffer as Q9}from"buffer";import{randomUUID as a3}from"crypto";class lQ extends Error{code;constructor($){super($==="hands_repl_private_profile_attribute_denied"?"Private browser attribute read denied.":$);this.code=$;this.name="HandsReplBrowserDispatcherError"}}var sQ=new Set(["__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","__proto__","constructor","prototype"]),dQ=/^hands_[A-Za-z0-9_-]{8,128}$/,o3=2048,nQ=32,iQ=1e4,r3=new Set(["href","src","alt","title","role","aria-label","aria-expanded","aria-checked","aria-selected","aria-disabled","placeholder","type","name","data-testid"]);function t3($){let Q=$.split("+"),Z=(Q.pop()??"").replace(/^Key/,"").toLowerCase();if(Z==="f12")return!0;if(Q.some((X)=>["Control","ControlOrMeta","Meta"].includes(X))&&["l","n","t","j","i","p","s","w","u","o","r","tab","pageup","pagedown"].includes(Z))return!0;if(Q.some((X)=>["Control","ControlOrMeta","Meta"].includes(X))&&Q.includes("Shift")&&Z==="c")return!0;return Q.includes("Alt")&&["d","arrowleft","arrowright","home"].includes(Z)}var e3=($)=>{let Q=$.closest("a[href],area[href]");return{password:$.tagName==="INPUT"&&$.type==="password",executableLink:Boolean(Q&&!/^(https?:|about:blank)/i.test(Q.href))}},aQ={browser:{close:{returns:"void"},contexts:{returns:"context[]"},isConnected:{returns:"json"},version:{returns:"json"}},context:{addCookies:{returns:"void"},addInitScript:{returns:"void"},browser:{returns:"browser"},clearCookies:{returns:"void"},clearPermissions:{returns:"void"},close:{returns:"void"},cookies:{returns:"json"},grantPermissions:{returns:"void"},newPage:{returns:"page"},pages:{returns:"page[]"},setDefaultNavigationTimeout:{returns:"void"},setDefaultTimeout:{returns:"void"},setExtraHTTPHeaders:{returns:"void"},setGeolocation:{returns:"void"},setHTTPCredentials:{returns:"void"},setOffline:{returns:"void"},setViewportSize:{returns:"void"},storageState:{returns:"json"},viewportSize:{returns:"json",special:"contextViewportSize"}},page:{addInitScript:{returns:"void"},addScriptTag:{returns:"void"},addStyleTag:{returns:"void"},bringToFront:{returns:"void"},close:{returns:"void"},content:{returns:"json"},context:{returns:"context"},emulateMedia:{returns:"void"},evaluate:{returns:"json",requiresStringSource:!0},frame:{returns:"frame"},frameLocator:{returns:"frameLocator"},frames:{returns:"frame[]"},getByAltText:{returns:"locator"},getByLabel:{returns:"locator"},getByPlaceholder:{returns:"locator"},getByRole:{returns:"locator"},getByTestId:{returns:"locator"},getByText:{returns:"locator"},getByTitle:{returns:"locator"},goBack:{returns:"void"},goForward:{returns:"void"},goto:{returns:"void"},isClosed:{returns:"json"},locator:{returns:"locator"},mainFrame:{returns:"frame"},opener:{returns:"page"},pdf:{returns:"bytes"},reload:{returns:"void"},screenshot:{returns:"bytes"},selectOption:{returns:"json"},setContent:{returns:"void"},setDefaultNavigationTimeout:{returns:"void"},setDefaultTimeout:{returns:"void"},setExtraHTTPHeaders:{returns:"void"},setInputFiles:{returns:"void"},setViewportSize:{returns:"void"},title:{returns:"json"},url:{returns:"json"},viewportSize:{returns:"json"},waitForFunction:{returns:"void",requiresStringSource:!0},waitForLoadState:{returns:"void"},waitForNavigation:{returns:"void"},waitForTimeout:{returns:"void"},waitForURL:{returns:"void"}},locator:{all:{returns:"locator[]"},allInnerTexts:{returns:"json"},allTextContents:{returns:"json"},and:{returns:"locator"},ariaSnapshot:{returns:"json"},blur:{returns:"void"},boundingBox:{returns:"json"},check:{returns:"void"},clear:{returns:"void"},click:{returns:"void"},contentFrame:{returns:"frameLocator"},count:{returns:"json"},dblclick:{returns:"void"},dragTo:{returns:"void"},evaluate:{returns:"json",requiresStringSource:!0},evaluateAll:{returns:"json",requiresStringSource:!0},fill:{returns:"void"},filter:{returns:"locator"},first:{returns:"locator",special:"property"},focus:{returns:"void"},getAttribute:{returns:"json"},getByAltText:{returns:"locator"},getByLabel:{returns:"locator"},getByPlaceholder:{returns:"locator"},getByRole:{returns:"locator"},getByTestId:{returns:"locator"},getByText:{returns:"locator"},getByTitle:{returns:"locator"},hover:{returns:"void"},innerHTML:{returns:"json"},innerText:{returns:"json"},inputValue:{returns:"json"},isChecked:{returns:"json"},isEditable:{returns:"json"},isEnabled:{returns:"json"},isHidden:{returns:"json"},isVisible:{returns:"json"},last:{returns:"locator",special:"property"},locator:{returns:"locator"},nth:{returns:"locator"},or:{returns:"locator"},page:{returns:"page"},press:{returns:"void"},pressSequentially:{returns:"void"},scrollIntoViewIfNeeded:{returns:"void"},screenshot:{returns:"bytes"},selectOption:{returns:"json"},setInputFiles:{returns:"void"},tap:{returns:"void"},textContent:{returns:"json"},type:{returns:"void"},uncheck:{returns:"void"},waitFor:{returns:"void"}},frame:{addScriptTag:{returns:"void"},addStyleTag:{returns:"void"},childFrames:{returns:"frame[]"},content:{returns:"json"},evaluate:{returns:"json",requiresStringSource:!0},frameLocator:{returns:"frameLocator"},getByAltText:{returns:"locator"},getByLabel:{returns:"locator"},getByPlaceholder:{returns:"locator"},getByRole:{returns:"locator"},getByTestId:{returns:"locator"},getByText:{returns:"locator"},getByTitle:{returns:"locator"},goto:{returns:"void"},isDetached:{returns:"json"},locator:{returns:"locator"},name:{returns:"json"},page:{returns:"page"},parentFrame:{returns:"frame"},setContent:{returns:"void"},title:{returns:"json"},url:{returns:"json"},waitForFunction:{returns:"void",requiresStringSource:!0},waitForLoadState:{returns:"void"},waitForNavigation:{returns:"void"},waitForTimeout:{returns:"void"},waitForURL:{returns:"void"}},frameLocator:{getByAltText:{returns:"locator"},getByLabel:{returns:"locator"},getByPlaceholder:{returns:"locator"},getByRole:{returns:"locator"},getByTestId:{returns:"locator"},getByText:{returns:"locator"},getByTitle:{returns:"locator"},locator:{returns:"locator"},owner:{returns:"locator"}}};function R($){throw new lQ($)}function G0($){if(!$||typeof $!=="object"||Array.isArray($))return!1;let Q=Object.getPrototypeOf($);return Q===Object.prototype||Q===null}function Z9($,Q=0,Z={nodes:0}){if(Q>nQ||++Z.nodes>iQ)R("hands_repl_json_too_complex");if($===null||typeof $==="boolean"||typeof $==="string")return;if(typeof $==="number"){if(!Number.isFinite($))R("hands_repl_invalid_json");return}if(Array.isArray($)){for(let X of $)Z9(X,Q+1,Z);return}if(!G0($))R("hands_repl_invalid_json");for(let[X,J]of Object.entries($)){if(sQ.has(X))R("hands_repl_invalid_json");Z9(J,Q+1,Z)}}function m8($){return typeof $==="string"&&Object.hasOwn(aQ,$)}function $1($){if(!$.endsWith("[]"))return null;let Q=$.slice(0,-2);return m8(Q)?Q:null}function pQ($){return G0($)&&Object.keys($).length===2&&$.$handsRepl==="bytes"&&typeof $.base64==="string"}function Q1($){return G0($)&&Object.keys($).length===1&&$.$handsRepl==="undefined"}function uQ($){return G0($)&&Object.keys($).length===2&&$.$handsRepl==="routeFulfill"&&"options"in $}function E0($){return!!$&&typeof $==="object"}function a9(){return Object.freeze({$handsRepl:"undefined"})}function Z1($){if(!Q9.isBuffer($)&&!($ instanceof Uint8Array))R("hands_repl_expected_bytes");return Object.freeze({$handsRepl:"bytes",base64:Q9.from($).toString("base64")})}function oQ($){if(!E0($.browser)||!E0($.context)||!E0($.page))R("hands_repl_invalid_roots");if(typeof $.a11y!=="function"||typeof $.view!=="function")R("hands_repl_invalid_callbacks");let Q=$.maxHandles??o3;if(!Number.isInteger(Q)||Q<3||Q>1e5)R("hands_repl_invalid_handle_limit");let Z=new Map,X=new WeakMap,J=$.createOpaqueId??a3,G=(K,L)=>{if(!E0(L))R("hands_repl_expected_target");let B=X.get(L)?.get(K);if(B)return B;if(Z.size>=Q)R("hands_repl_handle_limit");let U="";for(let q=0;q<16;q+=1){let D=`hands_${J()}`;if(dQ.test(D)&&!Z.has(D)){U=D;break}}if(!U)R("hands_repl_invalid_opaque_id");let M=Object.freeze({$handsRepl:"handle",id:U,kind:K});Z.set(U,{kind:K,target:L});let _=X.get(L);if(!_)_=new Map,X.set(L,_);return _.set(K,M),M},z=Object.freeze({browser:G("browser",$.browser),context:G("context",$.context),page:G("page",$.page)}),V=(K)=>{if(!G0(K)||Object.keys(K).length!==3||K.$handsRepl!=="handle"||typeof K.id!=="string"||!dQ.test(K.id)||!m8(K.kind))R("hands_repl_invalid_handle");let L=Z.get(K.id);if(!L||L.kind!==K.kind)R("hands_repl_unknown_handle");return L},Y=(K,L=0,B=new Set)=>{if(L>nQ)R("hands_repl_json_too_complex");if(K===void 0)return a9();if(K===null||typeof K==="boolean"||typeof K==="string")return K;if(typeof K==="number"){if(!Number.isFinite(K))R("hands_repl_non_json_result");return K}if(Array.isArray(K)){if(B.has(K))R("hands_repl_cyclic_result");B.add(K);try{return K.map((U)=>Y(U,L+1,B))}finally{B.delete(K)}}if(!G0(K))R("hands_repl_non_json_result");if(B.has(K))R("hands_repl_cyclic_result");B.add(K);try{let U=Object.create(null);for(let M of Object.keys(K)){let _=Object.getOwnPropertyDescriptor(K,M);if(!_||!("value"in _))continue;U[M]=Y(_.value,L+1,B)}return U}finally{B.delete(K)}},H=(K,L)=>{if(L==="void")return a9();if(L==="json")return Y(K);if(L==="bytes")return Z1(K);let B=$1(L);if(B){if(!Array.isArray(K))R("hands_repl_expected_target_list");if(B==="context"&&K.some((U)=>U!==$.context))R("hands_repl_foreign_context");return K.map((U)=>G(B,U))}if(K===null||K===void 0)return a9();if(!m8(L))R("hands_repl_invalid_return_kind");if(L==="context"&&K!==$.context)R("hands_repl_foreign_context");return G(L,K)},W=(K)=>{if(G0(K)&&K.$handsRepl==="handle")return V(K).target;if(pQ(K))return Q9.from(K.base64,"base64");if(Q1(K))return;if(uQ(K))R("hands_repl_route_fulfill_only");if(Array.isArray(K))return K.map(W);if(!G0(K))return K;let L=Object.create(null);for(let[B,U]of Object.entries(K))L[B]=W(U);return L};return Object.freeze({roots:z,dispatch:async(K)=>{if(!G0(K)||typeof K.type!=="string")R("hands_repl_invalid_request");if(K.type==="a11y"){let T=K.target===void 0?Z.get(z.page.id):V(K.target);if(!T||T.kind!=="page"&&T.kind!=="locator")R("hands_repl_invalid_a11y_target");return Y(await $.a11y(T.target))}if(K.type==="view"){if(Z9(K.source),K.options!==void 0)Z9(K.options);let T=pQ(K.source)?Q9.from(K.source.base64,"base64"):K.source;if($.privateProfile&&!Q9.isBuffer(T))R("hands_repl_profile_requires_image_bytes");return Y(await $.view(T,K.options))}if(K.type!=="call")R("hands_repl_invalid_request");if(typeof K.method!=="string"||K.method.length===0||K.method.length>128)R("hands_repl_invalid_method");if(sQ.has(K.method))R("hands_repl_forbidden_method");let L=V(K.target),B=K.args??[];if(!Array.isArray(B))R("hands_repl_invalid_arguments");if(Z9(B),L.kind==="page"&&K.method==="captureScreenshot"){if(B.length!==0)R("hands_repl_invalid_arguments");if(!$.screenshotExport)R("hands_repl_screenshot_export_unavailable");return Y(await $.screenshotExport(L.target))}if(L.kind==="context"&&["startRecording","stopRecording"].includes(K.method)){if(!$.recording||L.target!==$.context)R("hands_repl_recording_unavailable");if(B.length>(K.method==="startRecording"?1:0))R("hands_repl_invalid_arguments");return Y(K.method==="startRecording"?await $.recording.start(B[0]):await $.recording.stop())}if($.privateProfile){let T=K.method;if(["evaluate","evaluateAll","waitForFunction","addInitScript","addScriptTag","addStyleTag","setContent","setInputFiles","route","content","cookies","storageState","addCookies","clearCookies","setExtraHTTPHeaders","setHTTPCredentials","grantPermissions","clearPermissions","innerHTML","textContent","allTextContents"].includes(T)||L.kind==="browser"&&T==="close"||L.kind==="context"&&T==="close")R("hands_repl_private_profile_method_denied");if(L.kind==="browser"&&T==="contexts")return H([$.context],"context[]");if((T==="screenshot"||T==="pdf")&&G0(B[0])&&(("path"in B[0])||("style"in B[0])))R("hands_repl_private_profile_path_denied");if(T==="goto"){if(typeof B[0]!=="string")R("hands_repl_private_profile_url_denied");try{let k=new URL(B[0]);if(!["http:","https:"].includes(k.protocol)&&B[0]!=="about:blank")R("hands_repl_private_profile_url_denied")}catch{R("hands_repl_private_profile_url_denied")}}if(T==="getAttribute"&&(typeof B[0]!=="string"||!r3.has(B[0].toLowerCase())))R("hands_repl_private_profile_attribute_denied");if(L.kind==="locator"&&["innerText","allInnerTexts","getAttribute"].includes(T)){let k=[L.target];if(T==="allInnerTexts"){let g=Reflect.get(L.target,"all");if(typeof g!=="function")R("hands_repl_private_profile_probe_unavailable");let O=await Reflect.apply(g,L.target,[]);if(!Array.isArray(O)||O.length>iQ||!O.every(E0))R("hands_repl_private_profile_probe_unavailable");k=O}for(let g of k){let O=Reflect.get(g,"isVisible");if(typeof O!=="function"||!await Reflect.apply(O,g,[]))R("hands_repl_private_profile_hidden_value_denied")}}if(T==="press"&&typeof B[0]==="string"&&t3(B[0]))R("hands_repl_private_profile_browser_shortcut_denied");if(L.kind==="locator"&&["inputValue","click","dblclick","tap","press"].includes(T)){let k=Reflect.get(L.target,"evaluate");if(typeof k!=="function")R("hands_repl_private_profile_probe_unavailable");let g=await Reflect.apply(k,L.target,[e3]);if(!G0(g)||typeof g.password!=="boolean"||typeof g.executableLink!=="boolean")R("hands_repl_private_profile_probe_unavailable");if(T==="inputValue"&&g.password)R("hands_repl_private_profile_password_denied");if(T!=="inputValue"&&g.executableLink)R("hands_repl_private_profile_url_denied");if(T==="inputValue"){let O=Reflect.get(L.target,"isVisible");if(typeof O!=="function"||!await Reflect.apply(O,L.target,[]))R("hands_repl_private_profile_hidden_value_denied")}}}let U=aQ[L.kind][K.method];if(!U)R("hands_repl_method_not_allowed");if(U.requiresStringSource&&typeof B[0]!=="string")R("hands_repl_string_source_required");if(L.kind==="browser"&&K.method==="contexts")return[z.context];if(["addInitScript","addScriptTag","addStyleTag","screenshot","pdf","storageState"].includes(K.method)&&B.some((T)=>G0(T)&&("path"in T)))R("hands_repl_file_path_not_allowed");if(K.method==="goto"&&typeof B[0]==="string"){let T;try{T=new URL(B[0]).protocol}catch{R("hands_repl_invalid_url")}if(!["http:","https:","data:","about:","blob:"].includes(T))R("hands_repl_file_path_not_allowed")}if(U.special==="contextViewportSize"){let T=Reflect.get(L.target,"pages");if(typeof T!=="function")R("hands_repl_method_unavailable");let k=await Reflect.apply(T,L.target,[]),g=Array.isArray(k)?k[0]:void 0,O=E0(g)?Reflect.get(g,"viewportSize"):void 0;if(typeof O!=="function")return a9();return H(await Reflect.apply(O,g,[]),U.returns)}if(U.special==="property"){let T=Reflect.get(L.target,K.method);return H(typeof T==="function"?Reflect.apply(T,L.target,[]):T,U.returns)}let M=Reflect.get(L.target,K.method);if(typeof M!=="function")R("hands_repl_method_unavailable");if(U.special==="route"){let T=B[1];if(!uQ(T))R("hands_repl_invalid_route_handler");Z9(T.options);let k=W(T.options),g=async(j)=>{if(!E0(j))R("hands_repl_invalid_route");let A=Reflect.get(j,"fulfill");if(typeof A!=="function")R("hands_repl_invalid_route");await Reflect.apply(A,j,[k])},O=[W(B[0]??null),g],N=await Reflect.apply(M,L.target,O);return H(N,U.returns)}let _=B.map(W);if(K.method==="setInputFiles"){let T=L.kind==="locator"?0:1,k=async(O)=>{if(typeof O!=="string"){if(!G0(O)||typeof O.name!=="string"||typeof O.mimeType!=="string"||!Q9.isBuffer(O.buffer))R("hands_repl_invalid_file_input");return O}if(!$.readWorkspaceFile)R("hands_repl_workspace_required");return $.readWorkspaceFile(O)},g=_[T];_[T]=Array.isArray(g)?await Promise.all(g.map(k)):await k(g)}if(K.method==="goto")await $.beforeNavigation?.();let q=$.actionRecorder?.(),D=await Reflect.apply(M,L.target,_),b={click:"Click browser element",tap:"Click browser element",dblclick:"Double click browser element",fill:"Type text",type:"Type text",pressSequentially:"Type text",clear:"Clear browser field",press:"Press key",scrollIntoViewIfNeeded:"Scroll browser element into view",dragTo:"Drag on computer",selectOption:"Select browser option",check:"Check browser control",uncheck:"Uncheck browser control",hover:"Hover browser element",focus:"Focus browser element",goto:"Open browser page",reload:"Reload browser page",goBack:"Go back in browser",goForward:"Go forward in browser",screenshot:"Take browser screenshot"}[K.method];if(b){let T=Reflect.get(L.target,"page"),k=L.kind==="page"?L.target:typeof T==="function"?Reflect.apply(T,L.target,[]):void 0;q?.(b,E0(k)?k:void 0)}return H(D,U.returns)}})}import{isIP as QZ}from"net";import{Resolver as X1}from"dns/promises";import{isIP as r9}from"net";var J1=[["0.0.0.0",8],["10.0.0.0",8],["100.64.0.0",10],["127.0.0.0",8],["169.254.0.0",16],["172.16.0.0",12],["192.0.0.0",24],["192.0.2.0",24],["192.168.0.0",16],["198.18.0.0",15],["198.51.100.0",24],["203.0.113.0",24],["224.0.0.0",4],["240.0.0.0",4]];function g8($){if(r9($)!==4)return null;let Q=$.split(".");if(Q.length!==4)return null;let Z=0;for(let X of Q){let J=Number(X);if(!Number.isInteger(J)||J<0||J>255)return null;Z=Z*256+J}return Z>>>0}function Y1($,Q,Z){let X=g8(Q);if(X===null)return!1;let J=Z===0?0:4294967295<<32-Z>>>0;return($&J)>>>0===(X&J)>>>0}function rQ($){let Q=g8($);if(Q===null)return!0;return J1.some(([Z,X])=>Y1(Q,Z,X))}function G1($){if(r9($)!==6)return null;let Q=$.toLowerCase(),Z=Q.indexOf("%");if(Z>=0)Q=Q.slice(0,Z);let X=[],J=Q.lastIndexOf(":"),G=J>=0?Q.slice(J+1):"";if(G.includes(".")){let K=g8(G);if(K===null)return null;X=[K>>>16&65535,K&65535],Q=Q.slice(0,J+1)+"0:0"}let z=Q.split("::");if(z.length>2)return null;let V=(K)=>{if(K==="")return[];let L=[];for(let B of K.split(":")){if(B===""||B.length>4||!/^[0-9a-f]+$/.test(B))return null;L.push(Number.parseInt(B,16))}return L},Y=V(z[0]??"");if(Y===null)return null;if(z.length===1){let K=Y;if(K.length!==8)return null;return X.length>0?K.slice(0,6).concat(X):K}let H=V(z[1]??"");if(H===null)return null;let W=8-Y.length-H.length;if(W<0)return null;let F=Y.concat(Array(W).fill(0),H);if(F.length!==8)return null;return X.length>0?F.slice(0,6).concat(X):F}function z1($,Q){return`${$>>8&255}.${$&255}.${Q>>8&255}.${Q&255}`}function K1($){let Q=G1($);if(Q===null)return!0;let[Z,X,J]=Q;if((Z&57344)!==8192)return!0;if(Z===8193&&(X&65024)===0)return!0;if(Z===8193&&X===3512)return!0;if(Z===16383&&(X&61440)===0)return!0;if(Z===8194)return rQ(z1(X,J));return!1}function tQ($){return $.replace(/^\[|\]$/g,"")}function o9($){let Q=tQ($.trim()),Z=r9(Q);if(Z===4)return rQ(Q);if(Z===6)return K1(Q);return!0}function eQ($){if($ instanceof Error&&$.name==="TimeoutError")return"dns_timeout";switch(typeof $==="object"&&$!==null&&"code"in $?$.code:void 0){case"ENOTFOUND":return"dns_not_found";case"ENODATA":return"dns_empty";case"EAI_AGAIN":case"ESERVFAIL":case"ECONNREFUSED":return"dns_temporary";case"ETIMEOUT":case"ETIMEDOUT":return"dns_timeout";default:return"dns_failed"}}var $Z=5000;function V1($){return async(Q,Z)=>{if(Z?.aborted)throw Error("aborted");let X=new X1({timeout:$Z,tries:1});if($)X.setServers($);let J=()=>X.cancel();Z?.addEventListener("abort",J,{once:!0});try{let[G,z]=await Promise.allSettled([X.resolve4(Q),X.resolve6(Q)]),V=[...G.status==="fulfilled"?G.value:[],...z.status==="fulfilled"?z.value:[]];if(V.length>0)return V;let Y=[G,z].flatMap((W)=>W.status==="rejected"?[W.reason]:[]);throw Y.find((W)=>["dns_temporary","dns_timeout"].includes(eQ(W)))??Y[0]??Object.assign(Error("DNS returned no addresses"),{code:"ENODATA"})}finally{Z?.removeEventListener("abort",J)}}}var H1=V1();async function F1($,Q,Z,X){if(X?.aborted)throw Error("aborted");let J=new AbortController,G,z,V=Q($,J.signal);V.catch(()=>{});try{return await Promise.race([V,new Promise((Y,H)=>{if(G=setTimeout(()=>H(new DOMException("DNS lookup timed out","TimeoutError")),Z),X)z=()=>H(Error("aborted")),X.addEventListener("abort",z,{once:!0})})])}finally{if(G!==void 0)clearTimeout(G);if(X&&z)X.removeEventListener("abort",z);J.abort()}}async function p5($,Q=H1,Z){let X=tQ($);if(r9(X))return o9(X)?{ok:!1,reason:"non_public_ip"}:{ok:!0,addresses:[X]};let J;try{J=await F1(X,Q,$Z,Z)}catch(G){return{ok:!1,reason:Z?.aborted?Z.reason instanceof Error&&Z.reason.name==="TimeoutError"?"dns_timeout":"aborted":eQ(G)}}if(J.length===0)return{ok:!1,reason:"dns_empty"};if(J.some(o9))return{ok:!1,reason:"non_public_ip"};return{ok:!0,addresses:J}}var W1=/^(?:\*\.)?[a-z0-9](?:[a-z0-9.-]{0,251}[a-z0-9])?$/;function y8($){return $.length<=253&&W1.test($.toLowerCase())}function U1($,Q){let Z=$.trim().toLowerCase();if(!y8(Z))return!1;if(Z.startsWith("*.")){let X=Z.slice(2);return Q===X||Q.endsWith(`.${X}`)}return Z===Q}function B1($){let Q=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec($);if(!Q)return null;let Z=Q.slice(1).map(Number);return Z.some((X)=>X>255)?null:Z}function h8($,Q=[]){let Z=(X)=>{if(X=X.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.$/,""),!X.includes(":"))return X;try{X=new URL(`http://[${X}]/`).hostname.slice(1,-1)}catch{return X}let J=/^::ffff:([\da-f]+):([\da-f]+)$/.exec(X);if(!J)return X;let G=parseInt(J[1],16),z=parseInt(J[2],16);return`${G>>8}.${G&255}.${z>>8}.${z&255}`};return Q.some((X)=>Z(X)===Z($))}function c0($){$=$.toLowerCase().replace(/^\[|\]$/g,"");let Q=B1($);if(Q){let[G,z,V]=Q;if(G===127)return"loopback";return G===0||G===10||G>=224||G===100&&z>=64&&z<=127||G===169&&z===254||G===172&&z>=16&&z<=31||G===192&&(z===168||z===0&&(V===0||V===2)||z===88&&V===99)||G===198&&(z===18||z===19||z===51&&V===100)||G===203&&z===0&&V===113?"private":"public"}if(!$.includes(":"))return"hostname";try{$=new URL(`http://[${$}]/`).hostname.slice(1,-1)}catch{return"private"}if($==="::1")return"loopback";let Z=/^::ffff:([\da-f]+):([\da-f]+)$/.exec($);if(Z){let G=parseInt(Z[1],16),z=parseInt(Z[2],16);return c0(`${G>>8}.${G&255}.${z>>8}.${z&255}`)==="public"?"public":"private"}let[X,J=0]=$.split(":").map((G)=>parseInt(G||"0",16));return X<8192||X>16383||X===8194||X===8193&&(J<512||J===3512)||X===16383&&J<4096?"private":"public"}function A9($,Q){let Z;try{Z=new URL($)}catch{return{allowed:!1,url:$,host:null,reason:"invalid_url"}}if(["about:","data:","blob:"].includes(Z.protocol))return{allowed:!0,url:$,host:null,reason:"local_document"};if(!["http:","https:","ws:","wss:"].includes(Z.protocol))return{allowed:!1,url:$,host:Z.hostname||null,reason:"unsupported_protocol"};let X=Z.hostname.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.$/,"");if(Q.mode==="off")return{allowed:!0,url:$,host:X,reason:"policy_off"};let J=(V)=>({allowed:!1,url:$,host:X,reason:V});if(Z.username||Z.password)return J("invalid_url");if(Q.mode==="public_web"){let V=c0(X)!=="public"&&c0(X)!=="hostname"||X==="localhost"||/\.(?:localhost|local|internal|arpa)$/.test(X)||!X.includes(".")&&!QZ(X)||Boolean(QZ(X)&&o9(X));return{allowed:!V,url:$,host:X,reason:V?"private_network":"public_web"}}let G=Number(Z.port||(["https:","wss:"].includes(Z.protocol)?443:80));if(Q.deniedPorts?.includes(G)||h8(X,Q.deniedHosts))return J("destination_not_allowed");let z=c0(X);if(z==="private"||["local","internal","arpa"].some((V)=>X===V||X.endsWith(`.${V}`)))return J("private_network");if(z==="loopback"||X==="localhost"||X.endsWith(".localhost"))return Q.allowedLoopbackPorts?.includes(G)?{allowed:!0,url:$,host:X,reason:"loopback"}:J("destination_not_allowed");if(Q.allowedDomains.some((V)=>U1(V,X)))return{allowed:!0,url:$,host:X,reason:"allowed_domain"};return{allowed:!1,url:$,host:X,reason:"destination_not_allowed"}}import XZ from"child_process";import{accessSync as N1,constants as M1,readFileSync as j1,statSync as C1}from"fs";import{createRequire as q1}from"module";import{isAbsolute as v8,join as T1}from"path";var c8=Object.freeze({schemaVersion:1,driver:"playwright-core",driverVersion:JZ.dependencies["playwright-core"],browser:"chromium"}),YZ=["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge","/Applications/Brave Browser.app/Contents/MacOS/Brave Browser","/Applications/Chromium.app/Contents/MacOS/Chromium"],d8=["/usr/bin/chromium","/usr/bin/chromium-browser","/usr/bin/google-chrome","/usr/bin/google-chrome-stable"];function x9($){try{return N1($,M1.X_OK),v8($)&&C1($).isFile()}catch{return!1}}function p8($,Q=process.platform){let Z=Q==="darwin"?YZ:Q==="linux"?d8:null;return Z?($??Z).find(x9)??null:null}function O1(){if(!process.versions.bun)return;let $=Symbol.for("ara.headless-browser.bun-pipe-owners");if(Object.hasOwn(globalThis,$))return;let Q=[];XZ.spawn=new Proxy(XZ.spawn,{apply(Z,X,J){let G=Reflect.apply(Z,X,J),z=J[1],V=J[2]?.stdio;if(Array.isArray(z)&&z.includes("--remote-debugging-pipe")&&Array.isArray(V)&&V[3]==="pipe"&&V[4]==="pipe")Q.push(G);return G}}),Object.defineProperty(globalThis,$,{value:Q})}async function t9($){if(O1(),$!==void 0){if(!v8($))throw Error("hands_browser_driver_path_must_be_absolute");let X=T1($,"package.json"),J=JSON.parse(j1(X,"utf8"));if(J.name!==c8.driver)throw Error("hands_browser_wrong_driver");let G=q1(X)($),z=G.default?.chromium??G.chromium;if(!z)throw Error("hands_browser_missing_chromium");return{version:J.version,chromium:z}}let[Q,Z]=await Promise.all([import("./index-w9nq2f0p.js"),import("./package-rx9y4bwe.js").then((m)=>L1(m.default,1))]);return{version:Z.default.version,chromium:Q.chromium}}var D1=($,Q=c8.driverVersion)=>({status:"unavailable",reason:$,expectedDriverVersion:Q}),_1=($)=>$.loadDriver?.()??t9($.driverModuleDirectory);async function X9($={}){return GZ($,c8.driverVersion)}async function u8($,Q={}){if($.driverVersion!=="1.61.1"||!v8($.driverModuleDirectory))throw Error("hands_browser_invalid_managed_compatibility");return GZ({...Q,driverModuleDirectory:$.driverModuleDirectory,allowSystemBrowser:!0},$.driverVersion)}async function GZ($,Q){let Z=(Y)=>D1(Y,Q),X=$.platform??process.platform;if(X!=="linux"&&X!=="darwin")return Z("unsupported_platform");let J;try{J=await _1($)}catch{return Z("driver_missing")}if(J.version!==Q)return Z("driver_version_mismatch");let G=(Y,H)=>({status:"resolved",executablePath:Y,source:H,driverVersion:J.version});if($.executablePath!==void 0)return x9($.executablePath)?G($.executablePath,"configured"):Z("executable_missing");let z=J.chromium.executablePath();if(x9(z))return G(z,"managed");let V=$.allowSystemBrowser===!0?p8($.systemCandidates,X):null;return V?G(V,"system"):Z("executable_missing")}var g1=["/usr/local/bin/chromium",...d8];function y1($,Q=UZ()){return p8($??(Q==="linux"?g1:void 0),Q)}async function h1(){try{return(await t9()).chromium}catch{return w1(import.meta.url)("playwright-core").chromium}}var v1=1048576,c1=105000,d1=20000,VZ=5000,p1=2000,u1=1000,l1=30000,HZ=81920,s1={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp",".gif":"image/gif"};async function n1($,Q){let Z=new URL($.url()),X={...await $.allHeaders(),host:Z.host};for(let J of Object.keys(X))if(/^(?:proxy-|connection$|upgrade$|transfer-encoding$|content-length$)/i.test(J))delete X[J];return new Promise((J,G)=>{let V=(Z.protocol==="https:"?k1:b1)(Z,{method:$.method(),headers:X,agent:!1,lookup:(H,W,F)=>{let K=d0.isIP(Q);if(W.all)F(null,[{address:Q,family:K}]);else F(null,Q,K)}},(H)=>{let W=[],F=0;H.on("data",(K)=>{if(F+=K.length,F>33554432)V.destroy(Error("hands_browser_response_too_large"));else W.push(K)}),H.on("error",G),H.on("end",()=>{let K={};for(let[L,B]of Object.entries(H.headers))if(B!==void 0&&!["transfer-encoding","connection","content-length"].includes(L))K[L]=Array.isArray(B)?B.join(`
306
+ `.trim();import{Buffer as Q9}from"buffer";import{randomUUID as a3}from"crypto";class lQ extends Error{code;constructor($){super($==="hands_repl_private_profile_attribute_denied"?"Private browser attribute read denied.":$);this.code=$;this.name="HandsReplBrowserDispatcherError"}}var sQ=new Set(["__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","__proto__","constructor","prototype"]),dQ=/^hands_[A-Za-z0-9_-]{8,128}$/,o3=2048,nQ=32,iQ=1e4,r3=new Set(["href","src","alt","title","role","aria-label","aria-expanded","aria-checked","aria-selected","aria-disabled","placeholder","type","name","data-testid"]);function t3($){let Q=$.split("+"),Z=(Q.pop()??"").replace(/^Key/,"").toLowerCase();if(Z==="f12")return!0;if(Q.some((X)=>["Control","ControlOrMeta","Meta"].includes(X))&&["l","n","t","j","i","p","s","w","u","o","r","tab","pageup","pagedown"].includes(Z))return!0;if(Q.some((X)=>["Control","ControlOrMeta","Meta"].includes(X))&&Q.includes("Shift")&&Z==="c")return!0;return Q.includes("Alt")&&["d","arrowleft","arrowright","home"].includes(Z)}var e3=($)=>{let Q=$.closest("a[href],area[href]");return{password:$.tagName==="INPUT"&&$.type==="password",executableLink:Boolean(Q&&!/^(https?:|about:blank)/i.test(Q.href))}},aQ={browser:{close:{returns:"void"},contexts:{returns:"context[]"},isConnected:{returns:"json"},version:{returns:"json"}},context:{addCookies:{returns:"void"},addInitScript:{returns:"void"},browser:{returns:"browser"},clearCookies:{returns:"void"},clearPermissions:{returns:"void"},close:{returns:"void"},cookies:{returns:"json"},grantPermissions:{returns:"void"},newPage:{returns:"page"},pages:{returns:"page[]"},setDefaultNavigationTimeout:{returns:"void"},setDefaultTimeout:{returns:"void"},setExtraHTTPHeaders:{returns:"void"},setGeolocation:{returns:"void"},setHTTPCredentials:{returns:"void"},setOffline:{returns:"void"},setViewportSize:{returns:"void"},storageState:{returns:"json"},viewportSize:{returns:"json",special:"contextViewportSize"}},page:{addInitScript:{returns:"void"},addScriptTag:{returns:"void"},addStyleTag:{returns:"void"},bringToFront:{returns:"void"},close:{returns:"void"},content:{returns:"json"},context:{returns:"context"},emulateMedia:{returns:"void"},evaluate:{returns:"json",requiresStringSource:!0},frame:{returns:"frame"},frameLocator:{returns:"frameLocator"},frames:{returns:"frame[]"},getByAltText:{returns:"locator"},getByLabel:{returns:"locator"},getByPlaceholder:{returns:"locator"},getByRole:{returns:"locator"},getByTestId:{returns:"locator"},getByText:{returns:"locator"},getByTitle:{returns:"locator"},goBack:{returns:"void"},goForward:{returns:"void"},goto:{returns:"void"},isClosed:{returns:"json"},locator:{returns:"locator"},mainFrame:{returns:"frame"},opener:{returns:"page"},pdf:{returns:"bytes"},reload:{returns:"void"},screenshot:{returns:"bytes"},selectOption:{returns:"json"},setContent:{returns:"void"},setDefaultNavigationTimeout:{returns:"void"},setDefaultTimeout:{returns:"void"},setExtraHTTPHeaders:{returns:"void"},setInputFiles:{returns:"void"},setViewportSize:{returns:"void"},title:{returns:"json"},url:{returns:"json"},viewportSize:{returns:"json"},waitForFunction:{returns:"void",requiresStringSource:!0},waitForLoadState:{returns:"void"},waitForNavigation:{returns:"void"},waitForTimeout:{returns:"void"},waitForURL:{returns:"void"}},locator:{all:{returns:"locator[]"},allInnerTexts:{returns:"json"},allTextContents:{returns:"json"},and:{returns:"locator"},ariaSnapshot:{returns:"json"},blur:{returns:"void"},boundingBox:{returns:"json"},check:{returns:"void"},clear:{returns:"void"},click:{returns:"void"},contentFrame:{returns:"frameLocator"},count:{returns:"json"},dblclick:{returns:"void"},dragTo:{returns:"void"},evaluate:{returns:"json",requiresStringSource:!0},evaluateAll:{returns:"json",requiresStringSource:!0},fill:{returns:"void"},filter:{returns:"locator"},first:{returns:"locator",special:"property"},focus:{returns:"void"},getAttribute:{returns:"json"},getByAltText:{returns:"locator"},getByLabel:{returns:"locator"},getByPlaceholder:{returns:"locator"},getByRole:{returns:"locator"},getByTestId:{returns:"locator"},getByText:{returns:"locator"},getByTitle:{returns:"locator"},hover:{returns:"void"},innerHTML:{returns:"json"},innerText:{returns:"json"},inputValue:{returns:"json"},isChecked:{returns:"json"},isEditable:{returns:"json"},isEnabled:{returns:"json"},isHidden:{returns:"json"},isVisible:{returns:"json"},last:{returns:"locator",special:"property"},locator:{returns:"locator"},nth:{returns:"locator"},or:{returns:"locator"},page:{returns:"page"},press:{returns:"void"},pressSequentially:{returns:"void"},scrollIntoViewIfNeeded:{returns:"void"},screenshot:{returns:"bytes"},selectOption:{returns:"json"},setInputFiles:{returns:"void"},tap:{returns:"void"},textContent:{returns:"json"},type:{returns:"void"},uncheck:{returns:"void"},waitFor:{returns:"void"}},frame:{addScriptTag:{returns:"void"},addStyleTag:{returns:"void"},childFrames:{returns:"frame[]"},content:{returns:"json"},evaluate:{returns:"json",requiresStringSource:!0},frameLocator:{returns:"frameLocator"},getByAltText:{returns:"locator"},getByLabel:{returns:"locator"},getByPlaceholder:{returns:"locator"},getByRole:{returns:"locator"},getByTestId:{returns:"locator"},getByText:{returns:"locator"},getByTitle:{returns:"locator"},goto:{returns:"void"},isDetached:{returns:"json"},locator:{returns:"locator"},name:{returns:"json"},page:{returns:"page"},parentFrame:{returns:"frame"},setContent:{returns:"void"},title:{returns:"json"},url:{returns:"json"},waitForFunction:{returns:"void",requiresStringSource:!0},waitForLoadState:{returns:"void"},waitForNavigation:{returns:"void"},waitForTimeout:{returns:"void"},waitForURL:{returns:"void"}},frameLocator:{getByAltText:{returns:"locator"},getByLabel:{returns:"locator"},getByPlaceholder:{returns:"locator"},getByRole:{returns:"locator"},getByTestId:{returns:"locator"},getByText:{returns:"locator"},getByTitle:{returns:"locator"},locator:{returns:"locator"},owner:{returns:"locator"}}};function R($){throw new lQ($)}function G0($){if(!$||typeof $!=="object"||Array.isArray($))return!1;let Q=Object.getPrototypeOf($);return Q===Object.prototype||Q===null}function Z9($,Q=0,Z={nodes:0}){if(Q>nQ||++Z.nodes>iQ)R("hands_repl_json_too_complex");if($===null||typeof $==="boolean"||typeof $==="string")return;if(typeof $==="number"){if(!Number.isFinite($))R("hands_repl_invalid_json");return}if(Array.isArray($)){for(let X of $)Z9(X,Q+1,Z);return}if(!G0($))R("hands_repl_invalid_json");for(let[X,J]of Object.entries($)){if(sQ.has(X))R("hands_repl_invalid_json");Z9(J,Q+1,Z)}}function m8($){return typeof $==="string"&&Object.hasOwn(aQ,$)}function $1($){if(!$.endsWith("[]"))return null;let Q=$.slice(0,-2);return m8(Q)?Q:null}function pQ($){return G0($)&&Object.keys($).length===2&&$.$handsRepl==="bytes"&&typeof $.base64==="string"}function Q1($){return G0($)&&Object.keys($).length===1&&$.$handsRepl==="undefined"}function uQ($){return G0($)&&Object.keys($).length===2&&$.$handsRepl==="routeFulfill"&&"options"in $}function E0($){return!!$&&typeof $==="object"}function a9(){return Object.freeze({$handsRepl:"undefined"})}function Z1($){if(!Q9.isBuffer($)&&!($ instanceof Uint8Array))R("hands_repl_expected_bytes");return Object.freeze({$handsRepl:"bytes",base64:Q9.from($).toString("base64")})}function oQ($){if(!E0($.browser)||!E0($.context)||!E0($.page))R("hands_repl_invalid_roots");if(typeof $.a11y!=="function"||typeof $.view!=="function")R("hands_repl_invalid_callbacks");let Q=$.maxHandles??o3;if(!Number.isInteger(Q)||Q<3||Q>1e5)R("hands_repl_invalid_handle_limit");let Z=new Map,X=new WeakMap,J=$.createOpaqueId??a3,G=(K,L)=>{if(!E0(L))R("hands_repl_expected_target");let B=X.get(L)?.get(K);if(B)return B;if(Z.size>=Q)R("hands_repl_handle_limit");let U="";for(let q=0;q<16;q+=1){let D=`hands_${J()}`;if(dQ.test(D)&&!Z.has(D)){U=D;break}}if(!U)R("hands_repl_invalid_opaque_id");let M=Object.freeze({$handsRepl:"handle",id:U,kind:K});Z.set(U,{kind:K,target:L});let _=X.get(L);if(!_)_=new Map,X.set(L,_);return _.set(K,M),M},z=Object.freeze({browser:G("browser",$.browser),context:G("context",$.context),page:G("page",$.page)}),V=(K)=>{if(!G0(K)||Object.keys(K).length!==3||K.$handsRepl!=="handle"||typeof K.id!=="string"||!dQ.test(K.id)||!m8(K.kind))R("hands_repl_invalid_handle");let L=Z.get(K.id);if(!L||L.kind!==K.kind)R("hands_repl_unknown_handle");return L},Y=(K,L=0,B=new Set)=>{if(L>nQ)R("hands_repl_json_too_complex");if(K===void 0)return a9();if(K===null||typeof K==="boolean"||typeof K==="string")return K;if(typeof K==="number"){if(!Number.isFinite(K))R("hands_repl_non_json_result");return K}if(Array.isArray(K)){if(B.has(K))R("hands_repl_cyclic_result");B.add(K);try{return K.map((U)=>Y(U,L+1,B))}finally{B.delete(K)}}if(!G0(K))R("hands_repl_non_json_result");if(B.has(K))R("hands_repl_cyclic_result");B.add(K);try{let U=Object.create(null);for(let M of Object.keys(K)){let _=Object.getOwnPropertyDescriptor(K,M);if(!_||!("value"in _))continue;U[M]=Y(_.value,L+1,B)}return U}finally{B.delete(K)}},H=(K,L)=>{if(L==="void")return a9();if(L==="json")return Y(K);if(L==="bytes")return Z1(K);let B=$1(L);if(B){if(!Array.isArray(K))R("hands_repl_expected_target_list");if(B==="context"&&K.some((U)=>U!==$.context))R("hands_repl_foreign_context");return K.map((U)=>G(B,U))}if(K===null||K===void 0)return a9();if(!m8(L))R("hands_repl_invalid_return_kind");if(L==="context"&&K!==$.context)R("hands_repl_foreign_context");return G(L,K)},W=(K)=>{if(G0(K)&&K.$handsRepl==="handle")return V(K).target;if(pQ(K))return Q9.from(K.base64,"base64");if(Q1(K))return;if(uQ(K))R("hands_repl_route_fulfill_only");if(Array.isArray(K))return K.map(W);if(!G0(K))return K;let L=Object.create(null);for(let[B,U]of Object.entries(K))L[B]=W(U);return L};return Object.freeze({roots:z,dispatch:async(K)=>{if(!G0(K)||typeof K.type!=="string")R("hands_repl_invalid_request");if(K.type==="a11y"){let T=K.target===void 0?Z.get(z.page.id):V(K.target);if(!T||T.kind!=="page"&&T.kind!=="locator")R("hands_repl_invalid_a11y_target");return Y(await $.a11y(T.target))}if(K.type==="view"){if(Z9(K.source),K.options!==void 0)Z9(K.options);let T=pQ(K.source)?Q9.from(K.source.base64,"base64"):K.source;if($.privateProfile&&!Q9.isBuffer(T))R("hands_repl_profile_requires_image_bytes");return Y(await $.view(T,K.options))}if(K.type!=="call")R("hands_repl_invalid_request");if(typeof K.method!=="string"||K.method.length===0||K.method.length>128)R("hands_repl_invalid_method");if(sQ.has(K.method))R("hands_repl_forbidden_method");let L=V(K.target),B=K.args??[];if(!Array.isArray(B))R("hands_repl_invalid_arguments");if(Z9(B),L.kind==="page"&&K.method==="captureScreenshot"){if(B.length!==0)R("hands_repl_invalid_arguments");if(!$.screenshotExport)R("hands_repl_screenshot_export_unavailable");return Y(await $.screenshotExport(L.target))}if(L.kind==="context"&&["startRecording","stopRecording"].includes(K.method)){if(!$.recording||L.target!==$.context)R("hands_repl_recording_unavailable");if(B.length>(K.method==="startRecording"?1:0))R("hands_repl_invalid_arguments");return Y(K.method==="startRecording"?await $.recording.start(B[0]):await $.recording.stop())}if($.privateProfile){let T=K.method;if(["evaluate","evaluateAll","waitForFunction","addInitScript","addScriptTag","addStyleTag","setContent","setInputFiles","route","content","cookies","storageState","addCookies","clearCookies","setExtraHTTPHeaders","setHTTPCredentials","grantPermissions","clearPermissions","innerHTML","textContent","allTextContents"].includes(T)||L.kind==="browser"&&T==="close"||L.kind==="context"&&T==="close")R("hands_repl_private_profile_method_denied");if(L.kind==="browser"&&T==="contexts")return H([$.context],"context[]");if((T==="screenshot"||T==="pdf")&&G0(B[0])&&(("path"in B[0])||("style"in B[0])))R("hands_repl_private_profile_path_denied");if(T==="goto"){if(typeof B[0]!=="string")R("hands_repl_private_profile_url_denied");try{let k=new URL(B[0]);if(!["http:","https:"].includes(k.protocol)&&B[0]!=="about:blank")R("hands_repl_private_profile_url_denied")}catch{R("hands_repl_private_profile_url_denied")}}if(T==="getAttribute"&&(typeof B[0]!=="string"||!r3.has(B[0].toLowerCase())))R("hands_repl_private_profile_attribute_denied");if(L.kind==="locator"&&["innerText","allInnerTexts","getAttribute"].includes(T)){let k=[L.target];if(T==="allInnerTexts"){let g=Reflect.get(L.target,"all");if(typeof g!=="function")R("hands_repl_private_profile_probe_unavailable");let O=await Reflect.apply(g,L.target,[]);if(!Array.isArray(O)||O.length>iQ||!O.every(E0))R("hands_repl_private_profile_probe_unavailable");k=O}for(let g of k){let O=Reflect.get(g,"isVisible");if(typeof O!=="function"||!await Reflect.apply(O,g,[]))R("hands_repl_private_profile_hidden_value_denied")}}if(T==="press"&&typeof B[0]==="string"&&t3(B[0]))R("hands_repl_private_profile_browser_shortcut_denied");if(L.kind==="locator"&&["inputValue","click","dblclick","tap","press"].includes(T)){let k=Reflect.get(L.target,"evaluate");if(typeof k!=="function")R("hands_repl_private_profile_probe_unavailable");let g=await Reflect.apply(k,L.target,[e3]);if(!G0(g)||typeof g.password!=="boolean"||typeof g.executableLink!=="boolean")R("hands_repl_private_profile_probe_unavailable");if(T==="inputValue"&&g.password)R("hands_repl_private_profile_password_denied");if(T!=="inputValue"&&g.executableLink)R("hands_repl_private_profile_url_denied");if(T==="inputValue"){let O=Reflect.get(L.target,"isVisible");if(typeof O!=="function"||!await Reflect.apply(O,L.target,[]))R("hands_repl_private_profile_hidden_value_denied")}}}let U=aQ[L.kind][K.method];if(!U)R("hands_repl_method_not_allowed");if(U.requiresStringSource&&typeof B[0]!=="string")R("hands_repl_string_source_required");if(L.kind==="browser"&&K.method==="contexts")return[z.context];if(["addInitScript","addScriptTag","addStyleTag","screenshot","pdf","storageState"].includes(K.method)&&B.some((T)=>G0(T)&&("path"in T)))R("hands_repl_file_path_not_allowed");if(K.method==="goto"&&typeof B[0]==="string"){let T;try{T=new URL(B[0]).protocol}catch{R("hands_repl_invalid_url")}if(!["http:","https:","data:","about:","blob:"].includes(T))R("hands_repl_file_path_not_allowed")}if(U.special==="contextViewportSize"){let T=Reflect.get(L.target,"pages");if(typeof T!=="function")R("hands_repl_method_unavailable");let k=await Reflect.apply(T,L.target,[]),g=Array.isArray(k)?k[0]:void 0,O=E0(g)?Reflect.get(g,"viewportSize"):void 0;if(typeof O!=="function")return a9();return H(await Reflect.apply(O,g,[]),U.returns)}if(U.special==="property"){let T=Reflect.get(L.target,K.method);return H(typeof T==="function"?Reflect.apply(T,L.target,[]):T,U.returns)}let M=Reflect.get(L.target,K.method);if(typeof M!=="function")R("hands_repl_method_unavailable");if(U.special==="route"){let T=B[1];if(!uQ(T))R("hands_repl_invalid_route_handler");Z9(T.options);let k=W(T.options),g=async(j)=>{if(!E0(j))R("hands_repl_invalid_route");let A=Reflect.get(j,"fulfill");if(typeof A!=="function")R("hands_repl_invalid_route");await Reflect.apply(A,j,[k])},O=[W(B[0]??null),g],N=await Reflect.apply(M,L.target,O);return H(N,U.returns)}let _=B.map(W);if(K.method==="setInputFiles"){let T=L.kind==="locator"?0:1,k=async(O)=>{if(typeof O!=="string"){if(!G0(O)||typeof O.name!=="string"||typeof O.mimeType!=="string"||!Q9.isBuffer(O.buffer))R("hands_repl_invalid_file_input");return O}if(!$.readWorkspaceFile)R("hands_repl_workspace_required");return $.readWorkspaceFile(O)},g=_[T];_[T]=Array.isArray(g)?await Promise.all(g.map(k)):await k(g)}if(K.method==="goto")await $.beforeNavigation?.();let q=$.actionRecorder?.(),D=await Reflect.apply(M,L.target,_),b={click:"Click browser element",tap:"Click browser element",dblclick:"Double click browser element",fill:"Type text",type:"Type text",pressSequentially:"Type text",clear:"Clear browser field",press:"Press key",scrollIntoViewIfNeeded:"Scroll browser element into view",dragTo:"Drag on computer",selectOption:"Select browser option",check:"Check browser control",uncheck:"Uncheck browser control",hover:"Hover browser element",focus:"Focus browser element",goto:"Open browser page",reload:"Reload browser page",goBack:"Go back in browser",goForward:"Go forward in browser",screenshot:"Take browser screenshot"}[K.method];if(b){let T=Reflect.get(L.target,"page"),k=L.kind==="page"?L.target:typeof T==="function"?Reflect.apply(T,L.target,[]):void 0;q?.(b,E0(k)?k:void 0)}return H(D,U.returns)}})}import{isIP as QZ}from"net";import{Resolver as X1}from"dns/promises";import{isIP as r9}from"net";var J1=[["0.0.0.0",8],["10.0.0.0",8],["100.64.0.0",10],["127.0.0.0",8],["169.254.0.0",16],["172.16.0.0",12],["192.0.0.0",24],["192.0.2.0",24],["192.168.0.0",16],["198.18.0.0",15],["198.51.100.0",24],["203.0.113.0",24],["224.0.0.0",4],["240.0.0.0",4]];function g8($){if(r9($)!==4)return null;let Q=$.split(".");if(Q.length!==4)return null;let Z=0;for(let X of Q){let J=Number(X);if(!Number.isInteger(J)||J<0||J>255)return null;Z=Z*256+J}return Z>>>0}function Y1($,Q,Z){let X=g8(Q);if(X===null)return!1;let J=Z===0?0:4294967295<<32-Z>>>0;return($&J)>>>0===(X&J)>>>0}function rQ($){let Q=g8($);if(Q===null)return!0;return J1.some(([Z,X])=>Y1(Q,Z,X))}function G1($){if(r9($)!==6)return null;let Q=$.toLowerCase(),Z=Q.indexOf("%");if(Z>=0)Q=Q.slice(0,Z);let X=[],J=Q.lastIndexOf(":"),G=J>=0?Q.slice(J+1):"";if(G.includes(".")){let K=g8(G);if(K===null)return null;X=[K>>>16&65535,K&65535],Q=Q.slice(0,J+1)+"0:0"}let z=Q.split("::");if(z.length>2)return null;let V=(K)=>{if(K==="")return[];let L=[];for(let B of K.split(":")){if(B===""||B.length>4||!/^[0-9a-f]+$/.test(B))return null;L.push(Number.parseInt(B,16))}return L},Y=V(z[0]??"");if(Y===null)return null;if(z.length===1){let K=Y;if(K.length!==8)return null;return X.length>0?K.slice(0,6).concat(X):K}let H=V(z[1]??"");if(H===null)return null;let W=8-Y.length-H.length;if(W<0)return null;let F=Y.concat(Array(W).fill(0),H);if(F.length!==8)return null;return X.length>0?F.slice(0,6).concat(X):F}function z1($,Q){return`${$>>8&255}.${$&255}.${Q>>8&255}.${Q&255}`}function K1($){let Q=G1($);if(Q===null)return!0;let[Z,X,J]=Q;if((Z&57344)!==8192)return!0;if(Z===8193&&(X&65024)===0)return!0;if(Z===8193&&X===3512)return!0;if(Z===16383&&(X&61440)===0)return!0;if(Z===8194)return rQ(z1(X,J));return!1}function tQ($){return $.replace(/^\[|\]$/g,"")}function o9($){let Q=tQ($.trim()),Z=r9(Q);if(Z===4)return rQ(Q);if(Z===6)return K1(Q);return!0}function eQ($){if($ instanceof Error&&$.name==="TimeoutError")return"dns_timeout";switch(typeof $==="object"&&$!==null&&"code"in $?$.code:void 0){case"ENOTFOUND":return"dns_not_found";case"ENODATA":return"dns_empty";case"EAI_AGAIN":case"ESERVFAIL":case"ECONNREFUSED":return"dns_temporary";case"ETIMEOUT":case"ETIMEDOUT":return"dns_timeout";default:return"dns_failed"}}var $Z=5000;function V1($){return async(Q,Z)=>{if(Z?.aborted)throw Error("aborted");let X=new X1({timeout:$Z,tries:1});if($)X.setServers($);let J=()=>X.cancel();Z?.addEventListener("abort",J,{once:!0});try{let[G,z]=await Promise.allSettled([X.resolve4(Q),X.resolve6(Q)]),V=[...G.status==="fulfilled"?G.value:[],...z.status==="fulfilled"?z.value:[]];if(V.length>0)return V;let Y=[G,z].flatMap((W)=>W.status==="rejected"?[W.reason]:[]);throw Y.find((W)=>["dns_temporary","dns_timeout"].includes(eQ(W)))??Y[0]??Object.assign(Error("DNS returned no addresses"),{code:"ENODATA"})}finally{Z?.removeEventListener("abort",J)}}}var H1=V1();async function F1($,Q,Z,X){if(X?.aborted)throw Error("aborted");let J=new AbortController,G,z,V=Q($,J.signal);V.catch(()=>{});try{return await Promise.race([V,new Promise((Y,H)=>{if(G=setTimeout(()=>H(new DOMException("DNS lookup timed out","TimeoutError")),Z),X)z=()=>H(Error("aborted")),X.addEventListener("abort",z,{once:!0})})])}finally{if(G!==void 0)clearTimeout(G);if(X&&z)X.removeEventListener("abort",z);J.abort()}}async function p5($,Q=H1,Z){let X=tQ($);if(r9(X))return o9(X)?{ok:!1,reason:"non_public_ip"}:{ok:!0,addresses:[X]};let J;try{J=await F1(X,Q,$Z,Z)}catch(G){return{ok:!1,reason:Z?.aborted?Z.reason instanceof Error&&Z.reason.name==="TimeoutError"?"dns_timeout":"aborted":eQ(G)}}if(J.length===0)return{ok:!1,reason:"dns_empty"};if(J.some(o9))return{ok:!1,reason:"non_public_ip"};return{ok:!0,addresses:J}}var W1=/^(?:\*\.)?[a-z0-9](?:[a-z0-9.-]{0,251}[a-z0-9])?$/;function y8($){return $.length<=253&&W1.test($.toLowerCase())}function U1($,Q){let Z=$.trim().toLowerCase();if(!y8(Z))return!1;if(Z.startsWith("*.")){let X=Z.slice(2);return Q===X||Q.endsWith(`.${X}`)}return Z===Q}function B1($){let Q=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec($);if(!Q)return null;let Z=Q.slice(1).map(Number);return Z.some((X)=>X>255)?null:Z}function h8($,Q=[]){let Z=(X)=>{if(X=X.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.$/,""),!X.includes(":"))return X;try{X=new URL(`http://[${X}]/`).hostname.slice(1,-1)}catch{return X}let J=/^::ffff:([\da-f]+):([\da-f]+)$/.exec(X);if(!J)return X;let G=parseInt(J[1],16),z=parseInt(J[2],16);return`${G>>8}.${G&255}.${z>>8}.${z&255}`};return Q.some((X)=>Z(X)===Z($))}function c0($){$=$.toLowerCase().replace(/^\[|\]$/g,"");let Q=B1($);if(Q){let[G,z,V]=Q;if(G===127)return"loopback";return G===0||G===10||G>=224||G===100&&z>=64&&z<=127||G===169&&z===254||G===172&&z>=16&&z<=31||G===192&&(z===168||z===0&&(V===0||V===2)||z===88&&V===99)||G===198&&(z===18||z===19||z===51&&V===100)||G===203&&z===0&&V===113?"private":"public"}if(!$.includes(":"))return"hostname";try{$=new URL(`http://[${$}]/`).hostname.slice(1,-1)}catch{return"private"}if($==="::1")return"loopback";let Z=/^::ffff:([\da-f]+):([\da-f]+)$/.exec($);if(Z){let G=parseInt(Z[1],16),z=parseInt(Z[2],16);return c0(`${G>>8}.${G&255}.${z>>8}.${z&255}`)==="public"?"public":"private"}let[X,J=0]=$.split(":").map((G)=>parseInt(G||"0",16));return X<8192||X>16383||X===8194||X===8193&&(J<512||J===3512)||X===16383&&J<4096?"private":"public"}function A9($,Q){let Z;try{Z=new URL($)}catch{return{allowed:!1,url:$,host:null,reason:"invalid_url"}}if(["about:","data:","blob:"].includes(Z.protocol))return{allowed:!0,url:$,host:null,reason:"local_document"};if(!["http:","https:","ws:","wss:"].includes(Z.protocol))return{allowed:!1,url:$,host:Z.hostname||null,reason:"unsupported_protocol"};let X=Z.hostname.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.$/,"");if(Q.mode==="off")return{allowed:!0,url:$,host:X,reason:"policy_off"};let J=(V)=>({allowed:!1,url:$,host:X,reason:V});if(Z.username||Z.password)return J("invalid_url");if(Q.mode==="public_web"){let V=c0(X)!=="public"&&c0(X)!=="hostname"||X==="localhost"||/\.(?:localhost|local|internal|arpa)$/.test(X)||!X.includes(".")&&!QZ(X)||Boolean(QZ(X)&&o9(X));return{allowed:!V,url:$,host:X,reason:V?"private_network":"public_web"}}let G=Number(Z.port||(["https:","wss:"].includes(Z.protocol)?443:80));if(Q.deniedPorts?.includes(G)||h8(X,Q.deniedHosts))return J("destination_not_allowed");let z=c0(X);if(z==="private"||["local","internal","arpa"].some((V)=>X===V||X.endsWith(`.${V}`)))return J("private_network");if(z==="loopback"||X==="localhost"||X.endsWith(".localhost"))return Q.allowedLoopbackPorts?.includes(G)?{allowed:!0,url:$,host:X,reason:"loopback"}:J("destination_not_allowed");if(Q.allowedDomains.some((V)=>U1(V,X)))return{allowed:!0,url:$,host:X,reason:"allowed_domain"};return{allowed:!1,url:$,host:X,reason:"destination_not_allowed"}}import XZ from"child_process";import{accessSync as N1,constants as M1,readFileSync as j1,statSync as C1}from"fs";import{createRequire as q1}from"module";import{isAbsolute as v8,join as T1}from"path";var c8=Object.freeze({schemaVersion:1,driver:"playwright-core",driverVersion:JZ.dependencies["playwright-core"],browser:"chromium"}),YZ=["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge","/Applications/Brave Browser.app/Contents/MacOS/Brave Browser","/Applications/Chromium.app/Contents/MacOS/Chromium"],d8=["/usr/bin/chromium","/usr/bin/chromium-browser","/usr/bin/google-chrome","/usr/bin/google-chrome-stable"];function x9($){try{return N1($,M1.X_OK),v8($)&&C1($).isFile()}catch{return!1}}function p8($,Q=process.platform){let Z=Q==="darwin"?YZ:Q==="linux"?d8:null;return Z?($??Z).find(x9)??null:null}function O1(){if(!process.versions.bun)return;let $=Symbol.for("ara.headless-browser.bun-pipe-owners");if(Object.hasOwn(globalThis,$))return;let Q=[];XZ.spawn=new Proxy(XZ.spawn,{apply(Z,X,J){let G=Reflect.apply(Z,X,J),z=J[1],V=J[2]?.stdio;if(Array.isArray(z)&&z.includes("--remote-debugging-pipe")&&Array.isArray(V)&&V[3]==="pipe"&&V[4]==="pipe")Q.push(G);return G}}),Object.defineProperty(globalThis,$,{value:Q})}async function t9($){if(O1(),$!==void 0){if(!v8($))throw Error("hands_browser_driver_path_must_be_absolute");let X=T1($,"package.json"),J=JSON.parse(j1(X,"utf8"));if(J.name!==c8.driver)throw Error("hands_browser_wrong_driver");let G=q1(X)($),z=G.default?.chromium??G.chromium;if(!z)throw Error("hands_browser_missing_chromium");return{version:J.version,chromium:z}}let[Q,Z]=await Promise.all([import("./index-9aw1gjs5.js"),import("./package-56yg8k4a.js").then((m)=>L1(m.default,1))]);return{version:Z.default.version,chromium:Q.chromium}}var D1=($,Q=c8.driverVersion)=>({status:"unavailable",reason:$,expectedDriverVersion:Q}),_1=($)=>$.loadDriver?.()??t9($.driverModuleDirectory);async function X9($={}){return GZ($,c8.driverVersion)}async function u8($,Q={}){if($.driverVersion!=="1.61.1"||!v8($.driverModuleDirectory))throw Error("hands_browser_invalid_managed_compatibility");return GZ({...Q,driverModuleDirectory:$.driverModuleDirectory,allowSystemBrowser:!0},$.driverVersion)}async function GZ($,Q){let Z=(Y)=>D1(Y,Q),X=$.platform??process.platform;if(X!=="linux"&&X!=="darwin")return Z("unsupported_platform");let J;try{J=await _1($)}catch{return Z("driver_missing")}if(J.version!==Q)return Z("driver_version_mismatch");let G=(Y,H)=>({status:"resolved",executablePath:Y,source:H,driverVersion:J.version});if($.executablePath!==void 0)return x9($.executablePath)?G($.executablePath,"configured"):Z("executable_missing");let z=J.chromium.executablePath();if(x9(z))return G(z,"managed");let V=$.allowSystemBrowser===!0?p8($.systemCandidates,X):null;return V?G(V,"system"):Z("executable_missing")}var g1=["/usr/local/bin/chromium",...d8];function y1($,Q=UZ()){return p8($??(Q==="linux"?g1:void 0),Q)}async function h1(){try{return(await t9()).chromium}catch{return w1(import.meta.url)("playwright-core").chromium}}var v1=1048576,c1=105000,d1=20000,VZ=5000,p1=2000,u1=1000,l1=30000,HZ=81920,s1={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp",".gif":"image/gif"};async function n1($,Q){let Z=new URL($.url()),X={...await $.allHeaders(),host:Z.host};for(let J of Object.keys(X))if(/^(?:proxy-|connection$|upgrade$|transfer-encoding$|content-length$)/i.test(J))delete X[J];return new Promise((J,G)=>{let V=(Z.protocol==="https:"?k1:b1)(Z,{method:$.method(),headers:X,agent:!1,lookup:(H,W,F)=>{let K=d0.isIP(Q);if(W.all)F(null,[{address:Q,family:K}]);else F(null,Q,K)}},(H)=>{let W=[],F=0;H.on("data",(K)=>{if(F+=K.length,F>33554432)V.destroy(Error("hands_browser_response_too_large"));else W.push(K)}),H.on("error",G),H.on("end",()=>{let K={};for(let[L,B]of Object.entries(H.headers))if(B!==void 0&&!["transfer-encoding","connection","content-length"].includes(L))K[L]=Array.isArray(B)?B.join(`
307
307
  `):B;J({status:H.statusCode??502,headers:K,body:Buffer.concat(W)})})}),Y=setTimeout(()=>V.destroy(Error("hands_browser_fetch_timeout")),l1);V.once("close",()=>clearTimeout(Y)),V.on("error",G),V.end($.postDataBuffer()??void 0)})}async function i1($,Q,Z=()=>{},X={lookup:(J)=>S1(J,{all:!0}),fetch:n1}){let J=new WeakSet,G=new WeakMap,z=(V)=>{let Y=G.get(V);if(Y)return Y;let H=(async()=>{if(!$.newCDPSession)return;let W=await $.newCDPSession(V),F=new Map;W.on("Network.loadingFinished",({requestId:K})=>F.delete(K)),W.on("Network.loadingFailed",({requestId:K})=>F.delete(K)),W.on("Fetch.requestPaused",async(K)=>{let L=K.networkId??K.requestId,B=K.redirectedRequestId?(F.get(L)??0)+1:0;F.set(L,B);let U=A9(K.request.url,Q),M=Q.mode==="enforce"&&Boolean(K.redirectedRequestId)&&U.host!==null&&!d0.isIP(U.host),_=!U.allowed?U:M?{...U,allowed:!1,reason:"destination_not_allowed"}:B>20?{...U,allowed:!1,reason:"redirect_not_supported"}:null;try{if(_)Z(_),await W.send("Fetch.failRequest",{requestId:K.requestId,errorReason:"BlockedByClient"});else await W.send("Fetch.continueRequest",{requestId:K.requestId})}catch{await W.send("Fetch.failRequest",{requestId:K.requestId,errorReason:"Failed"}).catch(()=>{})}}),await W.send("Network.enable"),await W.send("Fetch.enable",{patterns:[{urlPattern:"*",requestStage:"Request"}]}),J.add(V)})();return G.set(V,H),H};return await $.route("**/*",async(V)=>{let Y=V.request().url(),H=A9(Y,Q);if(H.allowed&&Q.mode==="public_web"){await V.continue();return}let W=V.request();if(H.allowed&&H.host&&d0.isIP(H.host)&&W.isNavigationRequest?.()){let F=W.frame();if(J.has(F.page())&&F===F.page().mainFrame()){await V.continue();return}}if(H.allowed&&(Q.mode==="off"||H.reason==="local_document")){await V.continue();return}if(H.allowed&&H.host)try{let F=H.host,K=c0(F),L,B=await(async()=>{if(K!=="hostname")return[{address:F,family:d0.isIP(F)}];if(H.reason==="loopback")return[{address:"127.0.0.1",family:4}];try{return await Promise.race([X.lookup(F),new Promise((U,M)=>{L=setTimeout(()=>M(Error("hands_browser_dns_timeout")),5000)})])}finally{if(L)clearTimeout(L)}})();if(!B.length||B.some(({address:U})=>{let M=c0(U);return!d0.isIP(U)||Q.mode==="enforce"&&h8(U,Q.deniedHosts)||(H.reason==="loopback"?M!=="loopback":M!=="public")}))H={...H,allowed:!1,reason:"private_network"};else{let U=await X.fetch(V.request(),B[0].address);if(U.status>=300&&U.status<400){let M=U.headers.location??Y;try{M=new URL(M,Y).href}catch{}let _=A9(M,Q);H=_.allowed?{..._,allowed:!1,reason:"redirect_not_supported"}:_}else{await V.fulfill(U);return}}}catch{await V.abort("failed");return}Z(H),await V.abort("blockedbyclient")}),await $.routeWebSocket("**/*",async(V)=>{let Y=A9(V.url(),Q);if(Q.mode==="enforce"&&Y.allowed&&(!Y.host||!d0.isIP(Y.host)))Y={...Y,allowed:!1,reason:"destination_not_allowed"};if(Y.allowed){V.connectToServer();return}Z(Y),await V.close({code:1008,reason:"Reason egress policy denied"})}),Q.mode==="off"?void 0:{preparePage:z}}async function BZ($,Q=UZ(),Z){if(Z){let J=await u8(Z,{platform:Q,systemCandidates:$});return J.status==="resolved"?J.executablePath:null}if($!==void 0){let J=y1($,Q);if(J)return J}let X=await X9({platform:Q,systemCandidates:$,allowSystemBrowser:!0});return X.status==="resolved"?X.executablePath:null}function FZ($,Q){if(!$)throw Error("hands_repl_workspace_required");let Z=s8($),X=J9($),J=n8(X,J9(X,Q)),z=J!==".."&&!J.startsWith(`..${i8}`)&&!KZ(J)?J9(Z,J):J9(Z,Q);if(R0(J9(X,Q))||R0(z))throw Error("hands_repl_protected_path");let V=(B)=>{let U=n8(Z,B);return U!==""&&U!==".."&&!U.startsWith(`..${i8}`)&&!KZ(U)},Y=s8(z);if(R0(Y))throw Error("hands_repl_protected_path");if(!V(z)||!V(Y))throw Error("hands_repl_file_outside_workspace");let H=n8(Z,z).split(i8),W=[Z,...H.map((B,U)=>J9(Z,...H.slice(0,U+1)))],F=W.map((B)=>zZ(B));if(F.some((B)=>B.isSymbolicLink()))throw Error("hands_repl_file_symlink");let K=F[F.length-1];if(!K.isFile()||K.nlink!==1||K.size>16777216)throw Error("hands_repl_file_not_regular_or_too_large");let L=I1(z,l8.O_RDONLY|l8.O_NOFOLLOW|l8.O_NONBLOCK);try{let B=P1(L);if(B.dev!==K.dev||B.ino!==K.ino||!B.isFile())throw Error("hands_repl_file_changed");for(let q=0;q<W.length;q++){let D=zZ(W[q]);if(D.dev!==F[q].dev||D.ino!==F[q].ino||D.isSymbolicLink())throw Error("hands_repl_file_changed")}if(!V(s8(z)))throw Error("hands_repl_file_outside_workspace");let U=Buffer.alloc(16777217),M=0;while(M<U.length){let q=R1(L,U,M,U.length-M,null);if(!q)break;M+=q}if(M===U.length)throw Error("hands_repl_file_too_large");let _=U.subarray(0,M);return{name:f1(z),mimeType:s1[m1(z).toLowerCase()]??"application/octet-stream",buffer:_}}finally{x1(L)}}function Y9($,Q){$.end(`${JSON.stringify(Q)}
308
308
  `)}function e9($){try{E1($)}catch{}}async function LZ($){if($.managedBrowser&&$.driverModuleDirectory!==void 0)throw Error("hands_browser_ambiguous_driver_configuration");let Q=$.launch||$.targetContext?null:$.managedBrowser?await u8($.managedBrowser,{executablePath:$.browserExecutablePath}):await X9({executablePath:$.browserExecutablePath,driverModuleDirectory:$.driverModuleDirectory});if(Q?.status==="unavailable")throw Error(`hands_browser_${Q.reason}`);let Z=Q?.status==="resolved"?Q.executablePath:$.browserExecutablePath;if(!Z||!x9(Z))throw Error("hands_browser_unavailable");let X=$.launch??(async(N)=>($.targetContext?await h1():(await t9($.managedBrowser?.driverModuleDirectory??$.driverModuleDirectory)).chromium).launch(N)),J=[],G={},z=null,V=null,Y=null,H=null,W=!1,F=null,K=new Map,L=new WeakMap,B=null,U=()=>{if(W)throw Error("hands_repl_stopped");if(H)throw H},M=(N)=>{let j=L.get(N);if(j)return j;let A=Promise.resolve().then(()=>N.close()).then(()=>{K.delete(N)});return L.set(N,A),A},_=async()=>{let N=[...K.entries()].reverse(),j=B??=performance.now()+u1,A=Promise.allSettled(N.filter(([,P])=>P==="context").map(([P])=>M(P))),m;try{await Promise.race([A,new Promise((P)=>{m=setTimeout(P,Math.max(0,j-performance.now()))})])}finally{if(m)clearTimeout(m)}let w=await Promise.allSettled(N.map(([P])=>M(P))),E=[];for(let[P,f]of w.entries()){if(f.status!=="rejected")continue;let d=f.reason instanceof Error&&["Error","TimeoutError","ProtocolError"].includes(f.reason.name)?f.reason.name:"unknown";E.push(Error(`hands_repl_close_failed: ${N[P][1]}: ${d}`))}if(E.length)throw AggregateError(E,"hands_repl_stop_unconfirmed")},q=(N,j)=>{if(K.set(N,j),W||H)M(N).catch(()=>{return}),U();return N},D=async()=>{let N=await X({executablePath:Z,headless:!0,chromiumSandbox:$.managedBrowser===void 0,args:["--disable-background-networking","--disable-quic","--disable-dev-shm-usage","--disable-gpu","--disable-software-rasterizer","--dns-prefetch-disable","--force-webrtc-ip-handling-policy=disable_non_proxied_udp","--no-pings"]}),j=null;try{q(N,"browser"),j=$.targetContext??q(await N.newContext({viewport:{width:1440,height:900},screen:{width:1440,height:900},serviceWorkers:"block",acceptDownloads:!1}),"context");let A=await i1(j,$.networkPolicy??{mode:"off"},$.onEgressDenied);if(U(),A){let S=j.newPage.bind(j);j.newPage=async()=>{let h=await S();return await A.preparePage(h),h}}let w=j.pages()[0]??await j.newPage();await A?.preparePage(w),U();let E=async(S=w)=>{let h=S;if(typeof h.ariaSnapshot==="function")return h.ariaSnapshot({timeout:1e4});return w.locator("body").innerText({timeout:1e4})},P=async(S,h={})=>{let c=h&&typeof h==="object"&&!Array.isArray(h)?h:{},a,H0="image/png";if(Buffer.isBuffer(S)||S instanceof Uint8Array)a=Buffer.from(S);else if(typeof S==="string"&&(S.startsWith("data:")||/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(S)))a=Buffer.from(S.replace(/^data:[^,]*,/,""),"base64");else if(typeof S==="string"){let k0=FZ($.workspaceRoot,S);a=k0.buffer,H0=k0.mimeType}else throw Error("view() needs a Buffer, a base64 string, or a path to an image file");if(a.length===0)throw Error("view(): the image is empty");let B8=String(c.label??"").replace(/[\r\n>]+/g," ").trim().slice(0,120),D0=Number(c.maxWidth)||1024,i0=Number(c.quality)||72,w9=$.targetContext?await N.newPage():await j.newPage();try{let k0=`data:${H0};base64,${a.toString("base64")}`;for(let r=0;r<5;r+=1){let B0=await w9.evaluate(async(F0)=>{let L0=new Image;L0.src=F0.url,await L0.decode();let f0=Math.min(1,F0.maxWidth/L0.naturalWidth),Y0=document.createElement("canvas");Y0.width=Math.max(1,Math.round(L0.naturalWidth*f0)),Y0.height=Math.max(1,Math.round(L0.naturalHeight*f0));let X0=Y0.getContext("2d");if(!X0)throw Error("view(): canvas unavailable");return X0.fillStyle="#ffffff",X0.fillRect(0,0,Y0.width,Y0.height),X0.drawImage(L0,0,0,Y0.width,Y0.height),{data:Y0.toDataURL("image/jpeg",F0.q/100).split(",")[1]??"",width:Y0.width,height:Y0.height,sourceWidth:L0.naturalWidth,sourceHeight:L0.naturalHeight}},{url:k0,maxWidth:D0,q:i0}),a0=Buffer.from(B0.data,"base64");if(a0.length<=HZ){let F0=B8||"image";return`<<<ARA_VIEW_IMAGE ${B0.data} image/jpeg ${F0}>>>
309
309
  Viewing ${F0} (${B0.sourceWidth}x${B0.sourceHeight} source, sent at ${B0.width}x${B0.height}, ${Math.round(a0.length/1024)}KB).`}if(D0>640)D0=Math.round(D0*0.75);else i0=Math.max(30,i0-15)}throw Error(`view(): could not reduce the image under ${Math.round(HZ/1024)}KB`)}finally{await w9.close().catch(()=>{return})}},f=oQ({browser:$.targetContext?.browser()??N,context:j,page:w,a11y:E,view:P,readWorkspaceFile:(S)=>FZ($.workspaceRoot,S),privateProfile:$.privateProfile,beforeNavigation:$.beforeNavigation,recording:$.recording,screenshotExport:$.screenshotExport,actionRecorder:()=>{let S=J,h=G;return(c,a)=>{if(S.length<WZ)S.push(c);if(a)h.page=a}}}),d=async(S)=>{U();let h=q(await N.newContext({serviceWorkers:"block",acceptDownloads:!1}),"context");try{await h.route("**/*",(a)=>a.abort()),U(),await h.routeWebSocket("**/*",(a)=>a.close({code:1008,reason:"Reason evaluator network denied"})),U(),await h.exposeBinding("__araHandsRpc",async(a,H0)=>$.onBrowserOperation?$.onBrowserOperation(S,()=>f.dispatch(H0)):f.dispatch(H0)),U();let c=await h.newPage();return U(),await c.goto("data:text/html,<title>Reason Hands evaluator</title>"),U(),await c.evaluate(`(${vQ})(${JSON.stringify(f.roots)})`),{context:h,page:c,runId:S}}catch(c){throw await M(h).catch(()=>{return}),c}},u=await d(),l={browser:N,context:j,page:w,evaluator:u,async captureProgressFrame(S){return P(await S.screenshot({type:"jpeg",quality:65,timeout:2000}),{label:"Screen after browser action"})},async resetEvaluator(S){await M(l.evaluator.context),l.evaluator=await d(S)}};return U(),l}catch(A){throw await _().catch(()=>{return}),A}},x=async()=>{if(U(),z)return z;if(!Y){V=D();let N;Y=Promise.race([V,new Promise((j,A)=>{N=setTimeout(()=>A(Error("hands_browser_unavailable: startup timed out")),d1)})]).then((j)=>{return U(),z=j,j}).catch(async()=>{H=Error("hands_browser_unavailable: startup failed or timed out");let j;try{await Promise.race([_(),new Promise((A,m)=>{j=setTimeout(()=>m(Error("hands_repl_stop_timeout")),VZ)})])}catch{H=Error("hands_browser_unavailable: startup cleanup unconfirmed")}finally{if(j)clearTimeout(j)}throw H}).finally(()=>{if(N)clearTimeout(N)})}return Y},b=async(N,j,A=!1)=>{let m=await x(),w=G;if($.onBrowserOperation&&m.evaluator.runId!==j)await m.resetEvaluator(j);let P=(async()=>{let u=await m.evaluator.page.evaluate(`(${cQ})(${JSON.stringify({code:N})})`);if(typeof u!=="string")throw Error("hands_repl_invalid_evaluator_output");let l=w.page;if(A&&l&&!u.includes("<<<ARA_VIEW_IMAGE")){let S=()=>m.captureProgressFrame(l);try{let h=await($.onBrowserOperation?$.onBrowserOperation(j,S):S());return w.automaticProgressImage=!0,`${u}
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{Qb as D}from"./vm-hands-entry-lite-qvrnx0vk.js";import{Gh as j}from"./vm-hands-entry-lite-ffg7rf02.js";import{statSync as i}from"fs";import{delimiter as n,join as t}from"path";function _(q,z=process.env.PATH??""){if(!q||q.includes("/")||q.includes("\x00"))return!1;return z.split(n).some((G)=>{if(!G)return!1;try{let Q=i(t(G,q));return Q.isFile()&&(Q.mode&73)!==0}catch{return!1}})}import{spawn as r,spawnSync as e}from"child_process";import{existsSync as k,mkdtempSync as E,readFileSync as O,readdirSync as o,realpathSync as qq,rmSync as b,statSync as zq}from"fs";import{platform as y,tmpdir as g}from"os";import{dirname as A,join as Z}from"path";import{fileURLToPath as Gq,pathToFileURL as T}from"url";var Hq=["bwrap","socat","rg"],Jq=2000,v=20000,Qq=3,P=4000,Vq=new Set([".git",".hg",".svn","node_modules"]),Wq=["runAsHostUid","sysrq-trigger"],Yq=Z(A(A(Gq(import.meta.url))),"packages/sandbox-runtime/src/index.ts"),h=!1;function fq(){h=!0}async function u(){let z=h?Z(A(qq(process.execPath)),"runtime","srt"):void 0;if(z&&process.platform==="linux"&&!k(Z(z,"vendor","seccomp",process.arch,"apply-seccomp")))throw Error("packaged_sandbox_runtime_vendor_missing");if(z){let J=O(Z(z,"sandbox-runtime.mjs"),"utf8");for(let Y of Wq)if(!J.includes(Y))throw Error(`packaged_sandbox_runtime_fork_missing:${Y}`)}let H=(await import(z?T(Z(z,"sandbox-runtime.mjs")).href:T(Yq).href)).SandboxManager;if(!H||typeof H.initialize!=="function"||typeof H.wrapWithSandboxArgv!=="function")throw Error("sandbox-runtime does not expose the expected SandboxManager API.");return{SandboxManager:H}}function Zq(q={}){if((q.platformName??y())!=="linux")return!1;let G=q.fileExists??k,Q=q.readFile??((H)=>O(H,"utf8"));for(let H of["/.dockerenv","/run/.containerenv"])try{if(G(H))return!0}catch{}try{return/docker|containerd|kubepods|lxc|libpod/.test(Q("/proc/1/cgroup"))}catch{return!1}}function l(q){return["/bin/true","/usr/bin/true"].find((z)=>q(z))??null}function $q(q,z){return q==="strict"?["--ro-bind","/","/","--unshare-pid","--unshare-user","--cap-drop","ALL","--proc","/proc","--",z]:["--ro-bind","/","/","--unshare-pid","--unshare-user","--bind","/proc","/proc","--",z]}function jq(q,z){try{let G=e("bwrap",$q(q,z),{stdio:"ignore",timeout:Jq});return!G.error&&G.status===0}catch{return!1}}function Bq(q){let z=q.platformName??y();if(z!=="linux")return null;let G=q.hasExecutable??_;if(!Hq.every((V)=>G(V)))return null;let Q=q.fileExists??k,H=l(Q);if(!H)return null;let J=B??(q.containerized??Zq({platformName:z})?"weak":"strict");return(q.probeNamespaces??((V)=>jq(V,H)))(J)?J:null}var L=null,C=!1,K=null,S=null,f=null,B=null,F=null;function M(){throw I("sandbox_mode_conflict"),new j("sandbox_unavailable","Sandbox process policy conflicts with an existing probe or session. Restart the worker.")}function xq(q){if(B!==null&&B!==q||C&&L!==null&&L!==q||F!==null&&F!==q)M();B=q}function I(q){K=q}function c(q){if(K)return!1;if(!C){if(L=Bq(q??{}),C=!0,L&&!q)d()}return L!==null}function Lq(){return c()?L:null}var U=null,w=0;function m(q){if(K)throw new j("sandbox_unavailable","Confined execution is unavailable in this worker process.");if(B&&q.sandboxMode&&B!==q.sandboxMode)M();let z=B??q.sandboxMode??Lq();if(!z)throw new j("sandbox_unavailable","Confined command execution is unavailable on this operating system.");if(F&&F!==z)M();return F=z,U??=(async()=>{let{SandboxManager:G}=await(q.loadSandboxRuntime??u)();return await G.initialize(Iq(z)),G})().catch((G)=>{throw U=null,I(`initialize_failed: ${String(G)}`),G instanceof j?G:new j("sandbox_unavailable","The confined execution sandbox failed to start.")}),U.then((G)=>{if(K)throw new j("sandbox_unavailable","Confined execution became unavailable during sandbox initialization.");return G})}async function Kq(){let q=U;if(U=null,!q)return;try{await(await q).reset()}catch{}}async function d(q={}){if(K)return!1;if(q.loadSandboxRuntime)return x(q.loadSandboxRuntime);if(!c())return!1;return S??=x(u),S}async function x(q){try{let{SandboxManager:z}=await q(),G=z.checkDependencies().errors;if(G.length>0)return I(`dependencies_missing: ${G.join(", ")}`),!1;return!K}catch(z){return I(`load_failed: ${String(z)}`),!1}}async function Rq(q={}){if(!q.loadSandboxRuntime&&!q.sandboxMode){if(!await d())return!1;return f??=R({}),f}return R(q)}async function R(q){let z;try{z=await m(q)}catch{return!1}let G=await Xq(z);if(!G)I("confined_command_failed");if(w===0)await Kq();return G}async function Xq(q){let z=l(k);if(!z)return!1;let G=E(Z(g(),"reason-device-probe-"));try{let{argv:Q}=await q.wrapWithSandboxArgv(a([z]),p(),{filesystem:s({root:G,allowWrite:!1,temporaryDirectory:G,protectedPaths:[]})},void 0,G),[H,...J]=Q;if(!H)return!1;return await Fq(H,J,G)}catch{return!1}finally{try{q.cleanupAfterCommand()}catch{}b(G,{recursive:!0,force:!0})}}function Fq(q,z,G,Q={}){return new Promise((H)=>{let J=!1,Y,V=(X)=>{if(J)return;J=!0,clearTimeout(Y),H(X)},W;try{W=(Q.spawnChild??r)(q,z,{cwd:G,env:{PATH:D,HOME:G,TMPDIR:G},stdio:"ignore"})}catch{V(!1);return}W.once("error",()=>V(!1));let $=(X,N)=>V(X===0&&N===null);if(W.once("exit",$),W.once("close",$),W.exitCode!==null||W.signalCode!==null)$(W.exitCode,W.signalCode);if(J)return;Y=setTimeout(()=>{V(!1);try{W.kill("SIGKILL")}catch{}},Math.min(Q.timeoutMs??v,v))})}function p(q=k){return["/bin/bash","/bin/sh"].find((z)=>q(z))??"/bin/sh"}function a(q){return q.map((z)=>`'${z.replaceAll("'","'\\''")}'`).join(" ")}function Uq(q,z,G=(Q)=>o(Q,{withFileTypes:!0}).filter((H)=>H.isDirectory()||H.isFile()).map((H)=>H.name)){let Q=[],H=[{path:q,depth:0}],J=0;while(H.length>0&&J<P){let Y=H.pop(),V;try{V=G(Y.path)}catch{continue}for(let W of V){if(J+=1,J>P)break;let $=Z(Y.path,W);if(z($)){Q.push($);continue}if(Y.depth+1<Qq&&!Vq.has(W))H.push({path:$,depth:Y.depth+1})}}return Q}function s(q){let z=Z(q.root,".git"),G=[];try{if(zq(z).isDirectory())G=[Z(z,"config"),Z(z,"hooks")]}catch{}return{denyRead:["/home","/root","/tmp","/tmp/.X11-unix",...q.protectedPaths],allowRead:[q.root,q.temporaryDirectory],allowWrite:[...q.allowWrite?[q.root]:[],q.temporaryDirectory],denyWrite:[...q.protectedPaths,...G]}}function Iq(q){return{network:{allowedDomains:[],deniedDomains:[]},filesystem:{denyRead:[],allowRead:[],allowWrite:[],denyWrite:[]},...q==="weak"?{enableWeakerNestedSandbox:!0}:{}}}function Dq(q){let z=q.createTemporaryDirectory??(()=>E(Z(g(),"reason-device-"))),G=q.removeTemporaryDirectory??((Q)=>b(Q,{recursive:!0,force:!0}));return async(Q,H,J)=>{let Y=await m(q),V=z();w+=1;try{let W;try{W=await Y.wrapWithSandboxArgv(a([Q,...H]),q.shell??p(),{filesystem:s({root:J.root,allowWrite:J.allowWrite,temporaryDirectory:V,protectedPaths:Uq(J.root,q.isProtectedPath)})},J.signal,J.cwd)}catch(N){throw N instanceof j?N:new j("sandbox_unavailable","The confined execution sandbox could not wrap the command.")}let[$,...X]=W.argv;if(!$)throw new j("sandbox_unavailable","The confined execution sandbox produced no command.");return await q.spawnCaptured($,X,{cwd:J.cwd,timeoutMs:J.timeoutMs,signal:J.signal,env:q.scrubEnvironment(J.root,V)})}finally{w-=1;try{Y.cleanupAfterCommand()}catch{}G(V)}}}
2
+ import{Qb as D}from"./vm-hands-entry-lite-qvrnx0vk.js";import{Ih as j}from"./vm-hands-entry-lite-wffqkcjq.js";import{statSync as i}from"fs";import{delimiter as n,join as t}from"path";function _(q,z=process.env.PATH??""){if(!q||q.includes("/")||q.includes("\x00"))return!1;return z.split(n).some((G)=>{if(!G)return!1;try{let Q=i(t(G,q));return Q.isFile()&&(Q.mode&73)!==0}catch{return!1}})}import{spawn as r,spawnSync as e}from"child_process";import{existsSync as k,mkdtempSync as E,readFileSync as O,readdirSync as o,realpathSync as qq,rmSync as b,statSync as zq}from"fs";import{platform as y,tmpdir as g}from"os";import{dirname as A,join as Z}from"path";import{fileURLToPath as Gq,pathToFileURL as T}from"url";var Hq=["bwrap","socat","rg"],Jq=2000,v=20000,Qq=3,P=4000,Vq=new Set([".git",".hg",".svn","node_modules"]),Wq=["runAsHostUid","sysrq-trigger"],Yq=Z(A(A(Gq(import.meta.url))),"packages/sandbox-runtime/src/index.ts"),h=!1;function fq(){h=!0}async function u(){let z=h?Z(A(qq(process.execPath)),"runtime","srt"):void 0;if(z&&process.platform==="linux"&&!k(Z(z,"vendor","seccomp",process.arch,"apply-seccomp")))throw Error("packaged_sandbox_runtime_vendor_missing");if(z){let J=O(Z(z,"sandbox-runtime.mjs"),"utf8");for(let Y of Wq)if(!J.includes(Y))throw Error(`packaged_sandbox_runtime_fork_missing:${Y}`)}let H=(await import(z?T(Z(z,"sandbox-runtime.mjs")).href:T(Yq).href)).SandboxManager;if(!H||typeof H.initialize!=="function"||typeof H.wrapWithSandboxArgv!=="function")throw Error("sandbox-runtime does not expose the expected SandboxManager API.");return{SandboxManager:H}}function Zq(q={}){if((q.platformName??y())!=="linux")return!1;let G=q.fileExists??k,Q=q.readFile??((H)=>O(H,"utf8"));for(let H of["/.dockerenv","/run/.containerenv"])try{if(G(H))return!0}catch{}try{return/docker|containerd|kubepods|lxc|libpod/.test(Q("/proc/1/cgroup"))}catch{return!1}}function l(q){return["/bin/true","/usr/bin/true"].find((z)=>q(z))??null}function $q(q,z){return q==="strict"?["--ro-bind","/","/","--unshare-pid","--unshare-user","--cap-drop","ALL","--proc","/proc","--",z]:["--ro-bind","/","/","--unshare-pid","--unshare-user","--bind","/proc","/proc","--",z]}function jq(q,z){try{let G=e("bwrap",$q(q,z),{stdio:"ignore",timeout:Jq});return!G.error&&G.status===0}catch{return!1}}function Bq(q){let z=q.platformName??y();if(z!=="linux")return null;let G=q.hasExecutable??_;if(!Hq.every((V)=>G(V)))return null;let Q=q.fileExists??k,H=l(Q);if(!H)return null;let J=B??(q.containerized??Zq({platformName:z})?"weak":"strict");return(q.probeNamespaces??((V)=>jq(V,H)))(J)?J:null}var L=null,C=!1,K=null,S=null,f=null,B=null,F=null;function M(){throw I("sandbox_mode_conflict"),new j("sandbox_unavailable","Sandbox process policy conflicts with an existing probe or session. Restart the worker.")}function xq(q){if(B!==null&&B!==q||C&&L!==null&&L!==q||F!==null&&F!==q)M();B=q}function I(q){K=q}function c(q){if(K)return!1;if(!C){if(L=Bq(q??{}),C=!0,L&&!q)d()}return L!==null}function Lq(){return c()?L:null}var U=null,w=0;function m(q){if(K)throw new j("sandbox_unavailable","Confined execution is unavailable in this worker process.");if(B&&q.sandboxMode&&B!==q.sandboxMode)M();let z=B??q.sandboxMode??Lq();if(!z)throw new j("sandbox_unavailable","Confined command execution is unavailable on this operating system.");if(F&&F!==z)M();return F=z,U??=(async()=>{let{SandboxManager:G}=await(q.loadSandboxRuntime??u)();return await G.initialize(Iq(z)),G})().catch((G)=>{throw U=null,I(`initialize_failed: ${String(G)}`),G instanceof j?G:new j("sandbox_unavailable","The confined execution sandbox failed to start.")}),U.then((G)=>{if(K)throw new j("sandbox_unavailable","Confined execution became unavailable during sandbox initialization.");return G})}async function Kq(){let q=U;if(U=null,!q)return;try{await(await q).reset()}catch{}}async function d(q={}){if(K)return!1;if(q.loadSandboxRuntime)return x(q.loadSandboxRuntime);if(!c())return!1;return S??=x(u),S}async function x(q){try{let{SandboxManager:z}=await q(),G=z.checkDependencies().errors;if(G.length>0)return I(`dependencies_missing: ${G.join(", ")}`),!1;return!K}catch(z){return I(`load_failed: ${String(z)}`),!1}}async function Rq(q={}){if(!q.loadSandboxRuntime&&!q.sandboxMode){if(!await d())return!1;return f??=R({}),f}return R(q)}async function R(q){let z;try{z=await m(q)}catch{return!1}let G=await Xq(z);if(!G)I("confined_command_failed");if(w===0)await Kq();return G}async function Xq(q){let z=l(k);if(!z)return!1;let G=E(Z(g(),"reason-device-probe-"));try{let{argv:Q}=await q.wrapWithSandboxArgv(a([z]),p(),{filesystem:s({root:G,allowWrite:!1,temporaryDirectory:G,protectedPaths:[]})},void 0,G),[H,...J]=Q;if(!H)return!1;return await Fq(H,J,G)}catch{return!1}finally{try{q.cleanupAfterCommand()}catch{}b(G,{recursive:!0,force:!0})}}function Fq(q,z,G,Q={}){return new Promise((H)=>{let J=!1,Y,V=(X)=>{if(J)return;J=!0,clearTimeout(Y),H(X)},W;try{W=(Q.spawnChild??r)(q,z,{cwd:G,env:{PATH:D,HOME:G,TMPDIR:G},stdio:"ignore"})}catch{V(!1);return}W.once("error",()=>V(!1));let $=(X,N)=>V(X===0&&N===null);if(W.once("exit",$),W.once("close",$),W.exitCode!==null||W.signalCode!==null)$(W.exitCode,W.signalCode);if(J)return;Y=setTimeout(()=>{V(!1);try{W.kill("SIGKILL")}catch{}},Math.min(Q.timeoutMs??v,v))})}function p(q=k){return["/bin/bash","/bin/sh"].find((z)=>q(z))??"/bin/sh"}function a(q){return q.map((z)=>`'${z.replaceAll("'","'\\''")}'`).join(" ")}function Uq(q,z,G=(Q)=>o(Q,{withFileTypes:!0}).filter((H)=>H.isDirectory()||H.isFile()).map((H)=>H.name)){let Q=[],H=[{path:q,depth:0}],J=0;while(H.length>0&&J<P){let Y=H.pop(),V;try{V=G(Y.path)}catch{continue}for(let W of V){if(J+=1,J>P)break;let $=Z(Y.path,W);if(z($)){Q.push($);continue}if(Y.depth+1<Qq&&!Vq.has(W))H.push({path:$,depth:Y.depth+1})}}return Q}function s(q){let z=Z(q.root,".git"),G=[];try{if(zq(z).isDirectory())G=[Z(z,"config"),Z(z,"hooks")]}catch{}return{denyRead:["/home","/root","/tmp","/tmp/.X11-unix",...q.protectedPaths],allowRead:[q.root,q.temporaryDirectory],allowWrite:[...q.allowWrite?[q.root]:[],q.temporaryDirectory],denyWrite:[...q.protectedPaths,...G]}}function Iq(q){return{network:{allowedDomains:[],deniedDomains:[]},filesystem:{denyRead:[],allowRead:[],allowWrite:[],denyWrite:[]},...q==="weak"?{enableWeakerNestedSandbox:!0}:{}}}function Dq(q){let z=q.createTemporaryDirectory??(()=>E(Z(g(),"reason-device-"))),G=q.removeTemporaryDirectory??((Q)=>b(Q,{recursive:!0,force:!0}));return async(Q,H,J)=>{let Y=await m(q),V=z();w+=1;try{let W;try{W=await Y.wrapWithSandboxArgv(a([Q,...H]),q.shell??p(),{filesystem:s({root:J.root,allowWrite:J.allowWrite,temporaryDirectory:V,protectedPaths:Uq(J.root,q.isProtectedPath)})},J.signal,J.cwd)}catch(N){throw N instanceof j?N:new j("sandbox_unavailable","The confined execution sandbox could not wrap the command.")}let[$,...X]=W.argv;if(!$)throw new j("sandbox_unavailable","The confined execution sandbox produced no command.");return await q.spawnCaptured($,X,{cwd:J.cwd,timeoutMs:J.timeoutMs,signal:J.signal,env:q.scrubEnvironment(J.root,V)})}finally{w-=1;try{Y.cleanupAfterCommand()}catch{}G(V)}}}
3
3
  export{_ as Jb,fq as Kb,xq as Lb,c as Mb,Rq as Nb,p as Ob,Dq as Pb};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Xg as c}from"./vm-hands-entry-lite-9pmag2qk.js";var g={REASON_API_KEY:"ARA_API_KEY",REASON_API_URL:"ARA_API_URL",REASON_CLI_CHANNEL:"ARA_CLI_CHANNEL",REASON_CLI_LAUNCHER_PATH:"ARA_CLI_LAUNCHER_PATH",REASON_MANAGED_RUNTIME_ROOT:"ARA_MANAGED_RUNTIME_ROOT",REASON_INSTALL_ALIAS_PATH:"ARA_INSTALL_ALIAS_PATH",REASON_INSTALL_DIR:"ARA_INSTALL_DIR",REASON_INSTALL_METHOD:"ARA_INSTALL_METHOD",REASON_INSTALL_PINNED_VERSION:"ARA_INSTALL_PINNED_VERSION",REASON_INSTALL_UPGRADE:"ARA_INSTALL_UPGRADE"},g0=Object.values(g),jZ=new Set;function MQ(Q,Z){let $=Q[Z];if($?.trim())return $;let X=Q[g[Z]];if(X?.trim())jZ.add(g[Z]);return X}function KZ(Q,Z){return{[Q]:Z,[g[Q]]:Z}}import{basename as BZ}from"path";var i=["production","staging"],OZ="https://api.reasonmachines.com",kZ="https://staging-api.reasonmachines.com";var l={production:{api:"https://api.reasonmachines.ai",app:"https://reasonmachines.ai"},staging:{api:"https://staging-api.reasonmachines.ai",app:"https://staging.reasonmachines.ai"}},AZ=new Set(["ara-staging","reason-staging"]);function KQ(Q={}){let Z=MQ(Q.env??process.env,"REASON_CLI_CHANNEL")?.trim().toLowerCase();if(Z){if(i.includes(Z))return Z;throw Error(`Unknown Reason CLI channel: ${Z}`)}let $=BZ(Q.executablePath??process.execPath).toLowerCase();return AZ.has($)?"staging":"production"}function h(Q){return Q==="staging"?kZ:OZ}function y0(Q){return`${h(Q)}/mcp/ara`}var BQ={production:["https://api.ara.so",l.production.api],staging:["https://api-staging.ara.so",l.staging.api]};function jQ(Q){let Z;try{Z=new URL(Q).origin}catch{return Q}let $=i.find((X)=>BQ[X].includes(Z));return $?h($):Z}function p0(Q,Z){return Q===Z||jQ(Q)===jQ(Z)}function OQ(Q,Z){return i.some(($)=>BQ[$].includes(Q)&&Z===h($))}function u0(Q,Z){try{let $=new URL(Z);return!$.username&&!$.password&&($.origin===h(Q)||$.origin===l[Q].api)}catch{return!1}}function d0(Q){try{let Z=new URL(Q).hostname.replace(/^\[|\]$/g,"").toLowerCase();return Z==="localhost"||Z==="127.0.0.1"||Z==="::1"}catch{return!1}}import{randomBytes as xQ}from"crypto";import{chmodSync as LQ,closeSync as FQ,constants as _Z,linkSync as bQ,lstatSync as x,mkdirSync as fQ,openSync as NZ,readdirSync as P,readFileSync as TQ,readlinkSync as D,renameSync as N,rmdirSync as CQ,symlinkSync as _,unlinkSync as B}from"fs";import{createRequire as xZ}from"module";import{constants as LZ}from"os";import{basename as f,join as U,sep as bZ}from"path";import{existsSync as m,lstatSync as AQ,readdirSync as PZ,readFileSync as FZ,readlinkSync as TZ,realpathSync as DZ}from"fs";import{join as K,sep as RZ}from"path";function o(Q,...Z){let $=K(Q,"ara"),X=K(Q,"reason");if(!v($))return K(X,...Z);if(!m(X))return K($,...Z);return m(K($,...Z))&&!m(K(X,...Z))?K($,...Z):K(X,...Z)}function v(Q){try{let Z=AQ(Q);if(!Z.isSymbolicLink())return Z.isDirectory();return TZ(Q)!=="reason"&&m(Q)}catch{return!1}}function PQ(Q,Z=[]){if(!v(Q))return!1;let $;try{$=[Q,...PZ(Q,{withFileTypes:!0}).filter((X)=>X.isDirectory()).map((X)=>K(Q,X.name))]}catch{return!1}return $.some((X)=>["connect","connect-once"].filter((z)=>!Z.includes(K(X,z))).some((z)=>{let W=K(X,z,"worker.json");try{AQ(W)}catch{return!1}try{let q=JSON.parse(FZ(W,"utf8"))?.stateDirectory;if(typeof q!=="string")return!0;let V=(J,w)=>J===w||J.startsWith(w+RZ);return V(q,Q)||V(kQ(q),kQ(Q))}catch{return!0}}))}function kQ(Q){try{return DZ(Q)}catch{return Q}}var u=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"]),n=new Set(["local-device.proxy.json"]),fZ=new Set(["local-device.key","local-device.binding"]),DQ=new Map;function r(Q,Z,$){let X=U(Q,"ara");if(/[/\\]\.reason-ssh[/\\][^/\\]+[/\\]installer-home[/\\]\.config$/.test(Q))return{state:G(X)?.isDirectory()?"kept":"absent"};return EQ(X,U(Q,"reason"),{linkAlways:!0,kept:(z)=>PQ(z,$??[]),native:Z===void 0?pQ:()=>Z},$!==void 0)}function SQ(Q,...Z){return r(Q),o(Q,...Z)}function z1(Q,Z=process.platform){let $=U(Q,"Library","Logs");if(Z==="darwin")for(let X of[""," Staging"," Development"])EQ(U($,`Ara${X}`),U($,`Reason${X}`),{linkAlways:!1,kept:()=>!1,native:pQ});return U($,"Reason")}var IQ="config_rename_unavailable:busy";function EQ(Q,Z,$,X=!1){let z=X?void 0:DQ.get(Q);if(z)return z;let W;try{W=CZ(Q,Z,$)}catch(q){let V=`config_rename_unavailable:${A(q)??"failed"}`;try{return{state:G(Q)?.isDirectory()?"kept":"absent",problem:V}}catch{return{state:"kept",problem:V}}}if(!(W.state==="absent"&&$.linkAlways)&&W.problem!==IQ&&!(W.state==="kept"&&!W.problem))DQ.set(Q,W);return W}function CZ(Q,Z,$){IZ(Z,$.native);let X=!1;for(let z=0;z<8;z+=1){let W=G(Q);if(W?.isSymbolicLink())return D(Q)===f(Z)?{state:X?"renamed":"linked"}:{state:"kept"};if(!W){if(p(Z))M(()=>B(Z),"ENOENT");if(!(X||$.linkAlways)||!R(Z))return{state:"absent"};let J=b(Z,"link");_(f(Z),J);try{M(()=>N(J,Q),"EISDIR","ENOTEMPTY","EEXIST","ENOTDIR")}finally{M(()=>B(J),"ENOENT")}continue}if(!W.isDirectory())return{state:"absent"};if($.kept(Q))return RQ(Z),{state:"kept"};let q=$.native();if(!q)return RQ(Z),{state:"kept",problem:"config_rename_unavailable:no_native"};let V=EZ(q,Q);if(!V)return{state:"kept",problem:IQ};try{if(x(Q).isSymbolicLink())continue;let J=SZ(q,Q,Z);if(J)return{state:"kept",problem:J};X=!0}finally{V()}}throw Object.assign(Error("legacy directory rename did not settle"),{code:"unsettled"})}function SZ(Q,Z,$){let X=G($);if(!X||p($)){if(!X)_(f($),$);try{Q.exchange(Z,$)}catch(J){if(p($))M(()=>B($),"ENOENT");return`config_rename_unavailable:${A(J)??"exchange_failed"}`}return null}if(!X.isDirectory())return"config_rename_unavailable:ENOTDIR";if(X.dev!==x(Z).dev)return"config_rename_unavailable:EXDEV";let z=[b($,"probe"),b($,"probe")];try{_("a",z[0]),_("b",z[1]),Q.exchange(z[0],z[1])}catch(J){return`config_rename_unavailable:${A(J)??"exchange_failed"}`}finally{for(let J of z)M(()=>B(J),"ENOENT")}let W=yQ($);for(let J of fZ){let w=G(U($,J)),j=G(U(Z,J));if(w&&j&&w.ino!==j.ino)fQ(`${W}-replaced`,{mode:448,recursive:!0}),N(U($,J),U(`${W}-replaced`,J))}let q={linked:new Map,unitsKept:new Set};gQ(Z,$,"",q);let V=b($,"rename");_(f($),V);try{Q.exchange(Z,V)}catch(J){return M(()=>B(V),"ENOENT"),`config_rename_unavailable:${A(J)??"exchange_failed"}`}return hQ(V,$,q,W),null}function t(Q){return Q===""||!Q.includes(bZ)}function gQ(Q,Z,$,X){let z=t($)&&y(U(Z,$),U(Q,$));if(z)X.unitsKept.add($);for(let W of P(U(Q,$))){if(z&&(u.has(W)||n.has(W)))continue;let q=U($,W),V=U(Q,q),J=U(Z,q),w=G(V);if(!w)continue;let j=G(J);if(w.isDirectory()){if(!j)M(()=>fQ(J,{mode:w.mode&4095}),"EEXIST"),LQ(J,w.mode&4095);if(R(J))gQ(Q,Z,q,X)}else if(!j){if(w.isSymbolicLink())M(()=>_(D(V),J),"EEXIST");else if(M(()=>bQ(V,J),"EEXIST","ENOENT"))X.linked.set(q,w.ino)}}}function IZ(Q,Z){let $;try{if(!R(Q))return;$=P(Q)}catch{return}for(let X of $){let z=/^\.(rename|link|probe|claim)-(\d+)-[0-9a-f]+$/.exec(X);if(!z)continue;let W=U(Q,X),q=G(W);if(!q)continue;if(!q.isDirectory()){if(!_Q(Number(z[2])))M(()=>B(W),"ENOENT");continue}let V=Z(),J=null;if(V){try{J=V.lock(W)}catch{continue}if(!J)continue}else if(_Q(Number(z[2])))continue;try{let w=b(Q,"claim");if(M(()=>N(W,w),"ENOENT"))hQ(w,Q,null,yQ(Q))}finally{J?.()}}}function hQ(Q,Z,$,X){for(let[z,W]of $?.linked??[])if(!G(U(Q,z))&&G(U(Z,z))?.ino===W)M(()=>B(U(Z,z)),"ENOENT");if(mQ(Q,Z,"",$),M(()=>CQ(Q),"ENOTEMPTY","EEXIST"))return;N(Q,X),LQ(X,448)}function mQ(Q,Z,$,X){let z=t($)&&(X?X.unitsKept.has($):y(U(Z,$),U(Q,$)));for(let W of P(U(Q,$))){let q=U($,W),V=U(Q,q),J=U(Z,q),w=x(V),j=G(J);if(j&&w.ino===j.ino&&w.dev===j.dev){B(V);continue}if(w.isFile()&&j?.isFile()&&X?.linked.get(q)===j.ino){N(V,J);continue}if(z&&(u.has(W)||n.has(W)))continue;if(!j){if(w.isFile()){if(M(()=>bQ(V,J),"EEXIST"))B(V)}else M(()=>N(V,J),"EEXIST","ENOTEMPTY");continue}if(w.isDirectory()&&j.isDirectory())mQ(Q,Z,q,X),M(()=>CQ(V),"ENOTEMPTY","EEXIST")}}function W1(Q){let Z=U(Q,"ara"),$=U(Q,"reason");if(!R(Z)||!R($))return null;let X=["",...P(Z,{withFileTypes:!0}).filter((z)=>z.isDirectory()&&!z.name.startsWith(".")).map((z)=>z.name)];for(let z of X){let W=U(Z,z),q=U($,z);if(!y(W,q)||!y(q,W))continue;if([...u,...n].some((J)=>a(U(W,J),U(q,J))===!1))return z}return null}function q1(Q){let Z=U(Q,"ara"),$=U(Q,"reason");if(!R(Z)||!R($))return null;let X=(z)=>{for(let W of P(U(Z,z))){let q=U(z,W);if(t(z)&&(W==="connect"||W==="connect-once"))continue;let V=x(U(Z,q)),J=G(U($,q));if(!J||V.ino===J.ino&&V.dev===J.dev)continue;if(V.isDirectory()&&J.isDirectory()&&!J.isSymbolicLink()){let w=X(q);if(w!==null)return w}else if(V.isSymbolicLink()||J.isSymbolicLink()){if(!(V.isSymbolicLink()&&J.isSymbolicLink()&&D(U(Z,q))===D(U($,q))))return q}else if(a(U(Z,q),U($,q))!==!0)return q}return null};return X("")}function a(Q,Z){let $=G(Q),X=G(Z);if(!$&&!X)return null;if(!$||!X||$.isDirectory()!==X.isDirectory())return!1;if($.ino===X.ino&&$.dev===X.dev)return!0;if($.isDirectory())return[...new Set([...P(Q),...P(Z)])].every((W)=>a(U(Q,W),U(Z,W))===!0);try{return TQ(Q).equals(TQ(Z))}catch{return!1}}function y(Q,Z){for(let $ of u)if(vQ(U(Q,$),U(Z,$)))return!0;return!1}function vQ(Q,Z){let $=G(Q);if(!$)return!1;let X=G(Z);if(!X)return!0;if($.isDirectory()){if(!X.isDirectory())return!0;return P(Q).some((z)=>vQ(U(Q,z),U(Z,z)))}if($.isSymbolicLink())return!X.isSymbolicLink()||D(Q)!==D(Z);return $.ino!==X.ino||$.dev!==X.dev}function RQ(Q){if(p(Q))M(()=>B(Q),"ENOENT")}function yQ(Q){return U(Q,`.pre-rename-${new Date().toISOString().replace(/[:.]/g,"-")}-${xQ(3).toString("hex")}`)}function p(Q){try{return x(Q).isSymbolicLink()&&D(Q)===f(Q)}catch{return!1}}function R(Q){let Z=G(Q);return Z!==null&&Z.isDirectory()}function EZ(Q,Z){for(let $=0;$<40;$+=1){let X=Q.lock(Z);if(X)return X;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,50)}return null}function b(Q,Z){return U(Q,`.${Z}-${process.pid}-${xQ(6).toString("hex")}`)}function _Q(Q){if(Q===process.pid)return!1;try{return process.kill(Q,0),!0}catch(Z){return A(Z)==="EPERM"}}function G(Q){try{return x(Q)}catch(Z){if(A(Z)==="ENOENT"||A(Z)==="ENOTDIR")return null;throw Z}}function M(Q,...Z){try{return Q(),!0}catch($){if(Z.includes(A($)??""))return!1;throw $}}function A(Q){return Q instanceof Error&&"code"in Q&&typeof Q.code==="string"?Q.code:void 0}var L,gZ=2,hZ=4,mZ=2,vZ=2,NQ=-100;function pQ(){if(L!==void 0)return L;if(L=null,process.platform!=="linux"&&process.platform!=="darwin")return null;let Q;try{Q=xZ(import.meta.url)("bun:ffi")}catch{return null}let Z=process.platform==="darwin",$=Z?"__error":"__errno_location",X=Z?["/usr/lib/libSystem.B.dylib"]:["libc.so.6",`libc.musl-${process.arch==="arm64"?"aarch64":"x86_64"}.so.1`],{FFIType:z}=Q;for(let W of X)try{let q=Z?"renamex_np":"renameat2",J=Q.dlopen(W,{flock:{args:[z.i32,z.i32],returns:z.i32},[$]:{args:[],returns:z.ptr},[q]:Z?{args:[z.ptr,z.ptr,z.u32],returns:z.i32}:{args:[z.i32,z.ptr,z.i32,z.ptr,z.u32],returns:z.i32}}).symbols,w=J[$]();if(w===null)continue;let j=(T)=>{let k=Q.read.i32(w),O=Object.entries(LZ.errno).find(([,E])=>E===k)?.[0]??`errno_${k}`;return Object.assign(Error(`${T} failed: ${O}`),{code:O})},HQ=(T)=>Buffer.from(`${T}\x00`,"utf8");return L={exchange(T,k){let O=HQ(T),E=HQ(k);if((Z?J[q](Q.ptr(O),Q.ptr(E),mZ):J[q](NQ,Q.ptr(O),NQ,Q.ptr(E),vZ))!==0)throw j("exchange")},lock(T){let k=NZ(T,_Z.O_RDONLY);if(J.flock(k,gZ|hZ)===0)return()=>FQ(k);let O=j("lock");if(FQ(k),O.code==="EWOULDBLOCK"||O.code==="EAGAIN")return null;throw O}},L}catch{}return null}import{createHmac as V0,createPublicKey as w0,randomBytes as G0,randomUUID as zZ,verify as H0}from"crypto";import{chmodSync as qQ,existsSync as WZ,mkdirSync as M0,readFileSync as j0,realpathSync as K0,renameSync as B0,statSync as O0,unlinkSync as k0,writeFileSync as A0}from"fs";import{basename as P0,dirname as YQ,isAbsolute as qZ,join as s,resolve as F0}from"path";var Y1=[Object.freeze({family:"ara",channel:"stable",applicationId:"so.ara.desktop"}),Object.freeze({family:"ara",channel:"staging",applicationId:"so.ara.desktop.staging"}),Object.freeze({family:"reason",channel:"stable",applicationId:"com.reasonmachines.desktop"}),Object.freeze({family:"reason",channel:"staging",applicationId:"com.reasonmachines.desktop.staging"})];var yZ="REASON_DESKTOP_RUNTIME",pZ="REASON_DESKTOP_RUNTIME_CHANNEL",uZ="REASON_DESKTOP_RUNTIME_INSTANCE_ID",dZ="REASON_DESKTOP_RUNTIME_WORKSPACE_SCOPE",M1={[yZ]:"ARA_DESKTOP_RUNTIME",[pZ]:"ARA_DESKTOP_RUNTIME_CHANNEL",[uZ]:"ARA_DESKTOP_RUNTIME_INSTANCE_ID",[dZ]:"ARA_DESKTOP_RUNTIME_WORKSPACE_SCOPE"};function uQ(Q){if(Q===void 0)return;if(!/^[a-f0-9]{64}$/.test(Q))throw Error("Invalid desktop workspace scope.");return Q}import{chmodSync as QQ,existsSync as F,mkdirSync as ZQ,readFileSync as lQ,realpathSync as lZ,renameSync as iZ,unlinkSync as $Q,writeFileSync as XQ}from"fs";import{createPrivateKey as oZ,createPublicKey as nZ,generateKeyPairSync as rZ,randomUUID as tZ,sign as aZ}from"crypto";import{createRequire as eZ}from"module";import{homedir as Q0,platform as rQ}from"os";import{dirname as Z0,join as C}from"path";import{existsSync as sZ}from"fs";import{join as cQ}from"path";var e="libara_device_keychain.dylib",dQ="libreason_device_keychain.dylib";class cZ extends Error{code;constructor(Q,Z){super(Z);this.code=Q;this.name="ManagedRuntimeError"}}function sQ(Q){let Z=cQ(Q,dQ);return sZ(Z)?Z:cQ(Q,e)}var iQ=1,$0=16384,S=65536,X0=128,z0=128,tQ=65536;class Y extends Error{code;nativeStatus;constructor(Q,Z){super(`Reason Device proof boundary failed (${Q}).${Z===void 0?"":` Native status: ${Z}.`}`);this.code=Q;this.nativeStatus=Z;this.name="LocalCredentialBoundaryError"}}function aQ(Q){if(Q.code==="proof_key_read_failed"&&Q.nativeStatus===-25300)return"proof_key_missing";switch(Q.nativeStatus){case-25308:return"keychain_interaction_required";case-25293:return"keychain_access_denied";case-25291:return"keychain_unavailable";default:return Q.code}}var zQ=null;function eQ(){if(!zQ)try{zQ=eZ(import.meta.url)("bun:ffi")}catch{throw new Y("native_boundary_unavailable")}return zQ}function W0(Q){if(typeof Q!=="string")return null;try{let Z=new URL(Q);if(Z.protocol!=="https:"&&Z.hostname!=="127.0.0.1"&&Z.hostname!=="localhost"&&Z.hostname!=="[::1]"&&Z.hostname!=="::1")return null;return Z.origin}catch{return null}}function q0(Q){if(!Q||typeof Q!=="object"||Array.isArray(Q))throw new Y("invalid_credential_record");let Z=Q,$=W0(Z.apiOrigin);if(Z.version!==iQ||!$||typeof Z.orgId!=="string"||Z.orgId.length<1||Z.orgId.length>160||typeof Z.deviceId!=="string"||Z.deviceId.length<1||Z.deviceId.length>160||typeof Z.credential!=="string"||!/^(?:reason|ara)_dev_/.test(Z.credential)||Z.credential.length>4096)throw new Y("invalid_credential_record");return{version:iQ,apiOrigin:$,orgId:Z.orgId,deviceId:Z.deviceId,credential:Z.credential}}function J0(Q=process.execPath){let Z=Q;try{Z=lZ(Q)}catch{}return sQ(Z0(Z))}function H(Q){return eQ().ptr(Q)}function Y0(Q){if(!F(Q))throw new Y("native_boundary_unavailable");let{dlopen:Z,FFIType:$}=eQ();try{return Z(Q,{ara_device_configure_scope:{args:[$.ptr,$.u64],returns:$.i32},ara_device_key_load_public:{args:[$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_key_create_fresh_public:{args:[$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_key_sign:{args:[$.ptr,$.u64,$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_key_is_non_extractable:{args:[$.ptr],returns:$.i32},ara_device_key_delete:{args:[$.ptr],returns:$.i32},ara_device_binding_read:{args:[$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_binding_create:{args:[$.ptr,$.u64],returns:$.i32},ara_device_binding_update:{args:[$.ptr,$.u64],returns:$.i32},ara_device_binding_delete:{args:[$.ptr],returns:$.i32},ara_device_keychain_read:{args:[$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_keychain_delete:{args:[$.ptr],returns:$.i32}})}catch(X){if(X instanceof Y)throw X;throw new Y("native_boundary_unavailable")}}function oQ(Q){return Buffer.from(Q).toString("base64url")}function I(Q){if(typeof Q!=="string"||!/^[A-Za-z0-9_-]{87}$/.test(Q))return!1;try{let Z=Buffer.from(Q,"base64url");return Z.byteLength===65&&Z[0]===4}catch{return!1}}function QZ(Q){if(Q.byteLength<8||Q.byteLength>72||Q[0]!==48)return!1;let Z=Q[1];return Z!==void 0&&Z<128&&Z+2===Q.byteLength}class ZZ{libraryPath;runtimePlatform;workspaceScope;library=null;constructor(Q=J0(),Z=rQ(),$){this.libraryPath=Q;this.runtimePlatform=Z;this.workspaceScope=$;uQ($)}symbols(){if(this.runtimePlatform!=="darwin")throw new Y("unsupported_platform");this.library??=Y0(this.libraryPath);let Q=new TextEncoder().encode(this.workspaceScope??""),Z=this.library.symbols.ara_device_configure_scope(H(Q.length?Q:new Uint8Array(1)),BigInt(Q.length));if(Z!==0)throw new Y("native_boundary_unavailable",Z);return this.library.symbols}publicKey(Q){let Z=new Uint8Array(X0),$=new BigUint64Array(1),X=Q==="load"?this.symbols().ara_device_key_load_public(H(Z),BigInt(Z.byteLength),H($)):this.symbols().ara_device_key_create_fresh_public(H(Z),BigInt(Z.byteLength),H($));if(X!==0)throw new Y(Q==="load"?"proof_key_read_failed":"proof_key_generation_failed",X);let z=Number($[0]);if(!Number.isSafeInteger(z)||z!==65)throw new Y("invalid_public_key");let W=oQ(Z.subarray(0,z));if(!I(W))throw new Y("invalid_public_key");return W}loadPublicKey(){return this.publicKey("load")}createFreshPublicKey(){return this.publicKey("create_fresh")}sign(Q){if(Q.byteLength<1||Q.byteLength>tQ)throw new Y("proof_sign_failed");let Z=new Uint8Array(z0),$=new BigUint64Array(1),X=this.symbols().ara_device_key_sign(H(Q),BigInt(Q.byteLength),H(Z),BigInt(Z.byteLength),H($));if(X!==0)throw new Y("proof_sign_failed",X);let z=Number($[0]);if(!Number.isSafeInteger(z)||z<1||z>Z.byteLength)throw new Y("invalid_signature");let W=Z.subarray(0,z);if(!QZ(W))throw new Y("invalid_signature");return oQ(W)}privateKeyIsNonExtractable(){let Q=new Uint8Array(1),Z=this.symbols().ara_device_key_is_non_extractable(H(Q));if(Z!==0||Q[0]!==1)throw new Y("proof_key_read_failed",Z);return!0}deleteKey(){let Q=new Uint8Array(1),Z=this.symbols().ara_device_key_delete(H(Q));if(Z!==0)throw new Y("proof_key_delete_failed",Z);return Q[0]===1}loadBinding(){let Q=new Uint8Array(S),Z=new BigUint64Array(1),$=this.symbols().ara_device_binding_read(H(Q),BigInt(Q.byteLength),H(Z));if($===1)return null;if($!==0)throw new Y("binding_read_failed",$);let X=Number(Z[0]);if(!Number.isSafeInteger(X)||X<1||X>Q.byteLength)throw new Y("invalid_binding");return Q.slice(0,X)}createBinding(Q){if(Q.byteLength<1||Q.byteLength>S)throw new Y("invalid_binding");let Z=this.symbols().ara_device_binding_create(H(Q),BigInt(Q.byteLength));if(Z!==0)throw new Y("binding_create_failed",Z)}updateBinding(Q){if(Q.byteLength<1||Q.byteLength>S)throw new Y("invalid_binding");let Z=this.symbols().ara_device_binding_update(H(Q),BigInt(Q.byteLength));if(Z!==0)throw new Y("binding_update_failed",Z)}deleteBinding(){let Q=new Uint8Array(1),Z=this.symbols().ara_device_binding_delete(H(Q));if(Z!==0)throw new Y("binding_delete_failed",Z);return Q[0]===1}loadLegacyCredential(){let Q=new Uint8Array($0),Z=new BigUint64Array(1),$=this.symbols().ara_device_keychain_read(H(Q),BigInt(Q.byteLength),H(Z));if($===1)return null;if($!==0)throw new Y("legacy_credential_read_failed",$);let X=Number(Z[0]);if(!Number.isSafeInteger(X)||X<1||X>Q.byteLength)throw new Y("invalid_credential_record");try{let z=new TextDecoder("utf-8",{fatal:!0}).decode(Q.subarray(0,X));return q0(JSON.parse(z))}catch(z){if(z instanceof Y)throw z;throw new Y("invalid_credential_record")}}deleteLegacyCredential(){let Q=new Uint8Array(1),Z=this.symbols().ara_device_keychain_delete(H(Q));if(Z!==0)throw new Y("legacy_credential_delete_failed",Z);return Q[0]===1}}function nQ(Q){let Z=Q.export({format:"jwk"});if(Z.crv!=="P-256"||typeof Z.x!=="string"||typeof Z.y!=="string")throw new Y("invalid_public_key");let $=Buffer.from(Z.x,"base64url"),X=Buffer.from(Z.y,"base64url");if($.byteLength!==32||X.byteLength!==32)throw new Y("invalid_public_key");let z=Buffer.concat([Buffer.of(4),$,X]).toString("base64url");if(!I(z))throw new Y("invalid_public_key");return z}function U0(){let Q=process.env.XDG_CONFIG_HOME?.trim()||C(Q0(),".config");r(Q);let Z=C(Q,"ara");return v(Z)?Z:C(Q,"reason")}class $Z{directory;constructor(Q=U0()){this.directory=Q}keyPath(){return C(this.directory,"local-device.key")}bindingPath(){return C(this.directory,"local-device.binding")}loadPrivateKeyObject(){let Q=this.keyPath();if(!F(Q))throw new Y("proof_key_read_failed");try{let Z=lQ(Q,"utf8");return oZ({key:Z,format:"pem"})}catch{throw new Y("proof_key_read_failed")}}loadPublicKey(){let Q=this.loadPrivateKeyObject(),Z=nZ(Q);return nQ(Z)}createFreshPublicKey(){ZQ(this.directory,{recursive:!0,mode:448});let{privateKey:Q,publicKey:Z}=rZ("ec",{namedCurve:"P-256"}),$=Q.export({type:"pkcs8",format:"pem"}),X=this.keyPath();return XQ(X,$,{mode:384}),QQ(X,384),nQ(Z)}sign(Q){if(Q.byteLength<1||Q.byteLength>tQ)throw new Y("proof_sign_failed");let Z=this.loadPrivateKeyObject(),$;try{$=aZ("sha256",Q,Z)}catch{throw new Y("proof_sign_failed")}if(!QZ($))throw new Y("invalid_signature");return $.toString("base64url")}privateKeyIsNonExtractable(){return!1}deleteKey(){let Q=this.keyPath();if(!F(Q))return!1;return $Q(Q),!0}loadBinding(){let Q=this.bindingPath();if(!F(Q))return null;try{return new Uint8Array(lQ(Q))}catch{return null}}createBinding(Q){if(Q.byteLength<1||Q.byteLength>S)throw new Y("invalid_binding");ZQ(this.directory,{recursive:!0,mode:448});let Z=this.bindingPath();if(F(Z))throw new Y("binding_create_failed");XQ(Z,Q,{mode:384}),QQ(Z,384)}updateBinding(Q){if(Q.byteLength<1||Q.byteLength>S)throw new Y("invalid_binding");ZQ(this.directory,{recursive:!0,mode:448});let Z=this.bindingPath();if(!F(Z))throw new Y("binding_update_failed");let $=`${Z}.${tZ()}`;try{XQ($,Q,{mode:384,flag:"wx"}),QQ($,384),iZ($,Z)}finally{if(F($))$Q($)}}deleteBinding(){let Q=this.bindingPath();if(!F(Q))return!1;return $Q(Q),!0}loadLegacyCredential(){return null}deleteLegacyCredential(){return!1}}function WQ(){return rQ()==="darwin"?new ZZ:new $Z}var UQ=4;var d="macos-keychain-p256-v1",JZ=1,T0=`ARA-DEVICE-BINDING-V1
2
+ import{Zg as c}from"./vm-hands-entry-lite-vvmq0mtv.js";var g={REASON_API_KEY:"ARA_API_KEY",REASON_API_URL:"ARA_API_URL",REASON_CLI_CHANNEL:"ARA_CLI_CHANNEL",REASON_CLI_LAUNCHER_PATH:"ARA_CLI_LAUNCHER_PATH",REASON_MANAGED_RUNTIME_ROOT:"ARA_MANAGED_RUNTIME_ROOT",REASON_INSTALL_ALIAS_PATH:"ARA_INSTALL_ALIAS_PATH",REASON_INSTALL_DIR:"ARA_INSTALL_DIR",REASON_INSTALL_METHOD:"ARA_INSTALL_METHOD",REASON_INSTALL_PINNED_VERSION:"ARA_INSTALL_PINNED_VERSION",REASON_INSTALL_UPGRADE:"ARA_INSTALL_UPGRADE"},g0=Object.values(g),jZ=new Set;function MQ(Q,Z){let $=Q[Z];if($?.trim())return $;let X=Q[g[Z]];if(X?.trim())jZ.add(g[Z]);return X}function KZ(Q,Z){return{[Q]:Z,[g[Q]]:Z}}import{basename as BZ}from"path";var i=["production","staging"],OZ="https://api.reasonmachines.com",kZ="https://staging-api.reasonmachines.com";var l={production:{api:"https://api.reasonmachines.ai",app:"https://reasonmachines.ai"},staging:{api:"https://staging-api.reasonmachines.ai",app:"https://staging.reasonmachines.ai"}},AZ=new Set(["ara-staging","reason-staging"]);function KQ(Q={}){let Z=MQ(Q.env??process.env,"REASON_CLI_CHANNEL")?.trim().toLowerCase();if(Z){if(i.includes(Z))return Z;throw Error(`Unknown Reason CLI channel: ${Z}`)}let $=BZ(Q.executablePath??process.execPath).toLowerCase();return AZ.has($)?"staging":"production"}function h(Q){return Q==="staging"?kZ:OZ}function y0(Q){return`${h(Q)}/mcp/ara`}var BQ={production:["https://api.ara.so",l.production.api],staging:["https://api-staging.ara.so",l.staging.api]};function jQ(Q){let Z;try{Z=new URL(Q).origin}catch{return Q}let $=i.find((X)=>BQ[X].includes(Z));return $?h($):Z}function p0(Q,Z){return Q===Z||jQ(Q)===jQ(Z)}function OQ(Q,Z){return i.some(($)=>BQ[$].includes(Q)&&Z===h($))}function u0(Q,Z){try{let $=new URL(Z);return!$.username&&!$.password&&($.origin===h(Q)||$.origin===l[Q].api)}catch{return!1}}function d0(Q){try{let Z=new URL(Q).hostname.replace(/^\[|\]$/g,"").toLowerCase();return Z==="localhost"||Z==="127.0.0.1"||Z==="::1"}catch{return!1}}import{randomBytes as xQ}from"crypto";import{chmodSync as LQ,closeSync as FQ,constants as _Z,linkSync as bQ,lstatSync as x,mkdirSync as fQ,openSync as NZ,readdirSync as P,readFileSync as TQ,readlinkSync as D,renameSync as N,rmdirSync as CQ,symlinkSync as _,unlinkSync as B}from"fs";import{createRequire as xZ}from"module";import{constants as LZ}from"os";import{basename as f,join as U,sep as bZ}from"path";import{existsSync as m,lstatSync as AQ,readdirSync as PZ,readFileSync as FZ,readlinkSync as TZ,realpathSync as DZ}from"fs";import{join as K,sep as RZ}from"path";function o(Q,...Z){let $=K(Q,"ara"),X=K(Q,"reason");if(!v($))return K(X,...Z);if(!m(X))return K($,...Z);return m(K($,...Z))&&!m(K(X,...Z))?K($,...Z):K(X,...Z)}function v(Q){try{let Z=AQ(Q);if(!Z.isSymbolicLink())return Z.isDirectory();return TZ(Q)!=="reason"&&m(Q)}catch{return!1}}function PQ(Q,Z=[]){if(!v(Q))return!1;let $;try{$=[Q,...PZ(Q,{withFileTypes:!0}).filter((X)=>X.isDirectory()).map((X)=>K(Q,X.name))]}catch{return!1}return $.some((X)=>["connect","connect-once"].filter((z)=>!Z.includes(K(X,z))).some((z)=>{let W=K(X,z,"worker.json");try{AQ(W)}catch{return!1}try{let q=JSON.parse(FZ(W,"utf8"))?.stateDirectory;if(typeof q!=="string")return!0;let V=(J,w)=>J===w||J.startsWith(w+RZ);return V(q,Q)||V(kQ(q),kQ(Q))}catch{return!0}}))}function kQ(Q){try{return DZ(Q)}catch{return Q}}var u=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"]),n=new Set(["local-device.proxy.json"]),fZ=new Set(["local-device.key","local-device.binding"]),DQ=new Map;function r(Q,Z,$){let X=U(Q,"ara");if(/[/\\]\.reason-ssh[/\\][^/\\]+[/\\]installer-home[/\\]\.config$/.test(Q))return{state:G(X)?.isDirectory()?"kept":"absent"};return EQ(X,U(Q,"reason"),{linkAlways:!0,kept:(z)=>PQ(z,$??[]),native:Z===void 0?pQ:()=>Z},$!==void 0)}function SQ(Q,...Z){return r(Q),o(Q,...Z)}function z1(Q,Z=process.platform){let $=U(Q,"Library","Logs");if(Z==="darwin")for(let X of[""," Staging"," Development"])EQ(U($,`Ara${X}`),U($,`Reason${X}`),{linkAlways:!1,kept:()=>!1,native:pQ});return U($,"Reason")}var IQ="config_rename_unavailable:busy";function EQ(Q,Z,$,X=!1){let z=X?void 0:DQ.get(Q);if(z)return z;let W;try{W=CZ(Q,Z,$)}catch(q){let V=`config_rename_unavailable:${A(q)??"failed"}`;try{return{state:G(Q)?.isDirectory()?"kept":"absent",problem:V}}catch{return{state:"kept",problem:V}}}if(!(W.state==="absent"&&$.linkAlways)&&W.problem!==IQ&&!(W.state==="kept"&&!W.problem))DQ.set(Q,W);return W}function CZ(Q,Z,$){IZ(Z,$.native);let X=!1;for(let z=0;z<8;z+=1){let W=G(Q);if(W?.isSymbolicLink())return D(Q)===f(Z)?{state:X?"renamed":"linked"}:{state:"kept"};if(!W){if(p(Z))M(()=>B(Z),"ENOENT");if(!(X||$.linkAlways)||!R(Z))return{state:"absent"};let J=b(Z,"link");_(f(Z),J);try{M(()=>N(J,Q),"EISDIR","ENOTEMPTY","EEXIST","ENOTDIR")}finally{M(()=>B(J),"ENOENT")}continue}if(!W.isDirectory())return{state:"absent"};if($.kept(Q))return RQ(Z),{state:"kept"};let q=$.native();if(!q)return RQ(Z),{state:"kept",problem:"config_rename_unavailable:no_native"};let V=EZ(q,Q);if(!V)return{state:"kept",problem:IQ};try{if(x(Q).isSymbolicLink())continue;let J=SZ(q,Q,Z);if(J)return{state:"kept",problem:J};X=!0}finally{V()}}throw Object.assign(Error("legacy directory rename did not settle"),{code:"unsettled"})}function SZ(Q,Z,$){let X=G($);if(!X||p($)){if(!X)_(f($),$);try{Q.exchange(Z,$)}catch(J){if(p($))M(()=>B($),"ENOENT");return`config_rename_unavailable:${A(J)??"exchange_failed"}`}return null}if(!X.isDirectory())return"config_rename_unavailable:ENOTDIR";if(X.dev!==x(Z).dev)return"config_rename_unavailable:EXDEV";let z=[b($,"probe"),b($,"probe")];try{_("a",z[0]),_("b",z[1]),Q.exchange(z[0],z[1])}catch(J){return`config_rename_unavailable:${A(J)??"exchange_failed"}`}finally{for(let J of z)M(()=>B(J),"ENOENT")}let W=yQ($);for(let J of fZ){let w=G(U($,J)),j=G(U(Z,J));if(w&&j&&w.ino!==j.ino)fQ(`${W}-replaced`,{mode:448,recursive:!0}),N(U($,J),U(`${W}-replaced`,J))}let q={linked:new Map,unitsKept:new Set};gQ(Z,$,"",q);let V=b($,"rename");_(f($),V);try{Q.exchange(Z,V)}catch(J){return M(()=>B(V),"ENOENT"),`config_rename_unavailable:${A(J)??"exchange_failed"}`}return hQ(V,$,q,W),null}function t(Q){return Q===""||!Q.includes(bZ)}function gQ(Q,Z,$,X){let z=t($)&&y(U(Z,$),U(Q,$));if(z)X.unitsKept.add($);for(let W of P(U(Q,$))){if(z&&(u.has(W)||n.has(W)))continue;let q=U($,W),V=U(Q,q),J=U(Z,q),w=G(V);if(!w)continue;let j=G(J);if(w.isDirectory()){if(!j)M(()=>fQ(J,{mode:w.mode&4095}),"EEXIST"),LQ(J,w.mode&4095);if(R(J))gQ(Q,Z,q,X)}else if(!j){if(w.isSymbolicLink())M(()=>_(D(V),J),"EEXIST");else if(M(()=>bQ(V,J),"EEXIST","ENOENT"))X.linked.set(q,w.ino)}}}function IZ(Q,Z){let $;try{if(!R(Q))return;$=P(Q)}catch{return}for(let X of $){let z=/^\.(rename|link|probe|claim)-(\d+)-[0-9a-f]+$/.exec(X);if(!z)continue;let W=U(Q,X),q=G(W);if(!q)continue;if(!q.isDirectory()){if(!_Q(Number(z[2])))M(()=>B(W),"ENOENT");continue}let V=Z(),J=null;if(V){try{J=V.lock(W)}catch{continue}if(!J)continue}else if(_Q(Number(z[2])))continue;try{let w=b(Q,"claim");if(M(()=>N(W,w),"ENOENT"))hQ(w,Q,null,yQ(Q))}finally{J?.()}}}function hQ(Q,Z,$,X){for(let[z,W]of $?.linked??[])if(!G(U(Q,z))&&G(U(Z,z))?.ino===W)M(()=>B(U(Z,z)),"ENOENT");if(mQ(Q,Z,"",$),M(()=>CQ(Q),"ENOTEMPTY","EEXIST"))return;N(Q,X),LQ(X,448)}function mQ(Q,Z,$,X){let z=t($)&&(X?X.unitsKept.has($):y(U(Z,$),U(Q,$)));for(let W of P(U(Q,$))){let q=U($,W),V=U(Q,q),J=U(Z,q),w=x(V),j=G(J);if(j&&w.ino===j.ino&&w.dev===j.dev){B(V);continue}if(w.isFile()&&j?.isFile()&&X?.linked.get(q)===j.ino){N(V,J);continue}if(z&&(u.has(W)||n.has(W)))continue;if(!j){if(w.isFile()){if(M(()=>bQ(V,J),"EEXIST"))B(V)}else M(()=>N(V,J),"EEXIST","ENOTEMPTY");continue}if(w.isDirectory()&&j.isDirectory())mQ(Q,Z,q,X),M(()=>CQ(V),"ENOTEMPTY","EEXIST")}}function W1(Q){let Z=U(Q,"ara"),$=U(Q,"reason");if(!R(Z)||!R($))return null;let X=["",...P(Z,{withFileTypes:!0}).filter((z)=>z.isDirectory()&&!z.name.startsWith(".")).map((z)=>z.name)];for(let z of X){let W=U(Z,z),q=U($,z);if(!y(W,q)||!y(q,W))continue;if([...u,...n].some((J)=>a(U(W,J),U(q,J))===!1))return z}return null}function q1(Q){let Z=U(Q,"ara"),$=U(Q,"reason");if(!R(Z)||!R($))return null;let X=(z)=>{for(let W of P(U(Z,z))){let q=U(z,W);if(t(z)&&(W==="connect"||W==="connect-once"))continue;let V=x(U(Z,q)),J=G(U($,q));if(!J||V.ino===J.ino&&V.dev===J.dev)continue;if(V.isDirectory()&&J.isDirectory()&&!J.isSymbolicLink()){let w=X(q);if(w!==null)return w}else if(V.isSymbolicLink()||J.isSymbolicLink()){if(!(V.isSymbolicLink()&&J.isSymbolicLink()&&D(U(Z,q))===D(U($,q))))return q}else if(a(U(Z,q),U($,q))!==!0)return q}return null};return X("")}function a(Q,Z){let $=G(Q),X=G(Z);if(!$&&!X)return null;if(!$||!X||$.isDirectory()!==X.isDirectory())return!1;if($.ino===X.ino&&$.dev===X.dev)return!0;if($.isDirectory())return[...new Set([...P(Q),...P(Z)])].every((W)=>a(U(Q,W),U(Z,W))===!0);try{return TQ(Q).equals(TQ(Z))}catch{return!1}}function y(Q,Z){for(let $ of u)if(vQ(U(Q,$),U(Z,$)))return!0;return!1}function vQ(Q,Z){let $=G(Q);if(!$)return!1;let X=G(Z);if(!X)return!0;if($.isDirectory()){if(!X.isDirectory())return!0;return P(Q).some((z)=>vQ(U(Q,z),U(Z,z)))}if($.isSymbolicLink())return!X.isSymbolicLink()||D(Q)!==D(Z);return $.ino!==X.ino||$.dev!==X.dev}function RQ(Q){if(p(Q))M(()=>B(Q),"ENOENT")}function yQ(Q){return U(Q,`.pre-rename-${new Date().toISOString().replace(/[:.]/g,"-")}-${xQ(3).toString("hex")}`)}function p(Q){try{return x(Q).isSymbolicLink()&&D(Q)===f(Q)}catch{return!1}}function R(Q){let Z=G(Q);return Z!==null&&Z.isDirectory()}function EZ(Q,Z){for(let $=0;$<40;$+=1){let X=Q.lock(Z);if(X)return X;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,50)}return null}function b(Q,Z){return U(Q,`.${Z}-${process.pid}-${xQ(6).toString("hex")}`)}function _Q(Q){if(Q===process.pid)return!1;try{return process.kill(Q,0),!0}catch(Z){return A(Z)==="EPERM"}}function G(Q){try{return x(Q)}catch(Z){if(A(Z)==="ENOENT"||A(Z)==="ENOTDIR")return null;throw Z}}function M(Q,...Z){try{return Q(),!0}catch($){if(Z.includes(A($)??""))return!1;throw $}}function A(Q){return Q instanceof Error&&"code"in Q&&typeof Q.code==="string"?Q.code:void 0}var L,gZ=2,hZ=4,mZ=2,vZ=2,NQ=-100;function pQ(){if(L!==void 0)return L;if(L=null,process.platform!=="linux"&&process.platform!=="darwin")return null;let Q;try{Q=xZ(import.meta.url)("bun:ffi")}catch{return null}let Z=process.platform==="darwin",$=Z?"__error":"__errno_location",X=Z?["/usr/lib/libSystem.B.dylib"]:["libc.so.6",`libc.musl-${process.arch==="arm64"?"aarch64":"x86_64"}.so.1`],{FFIType:z}=Q;for(let W of X)try{let q=Z?"renamex_np":"renameat2",J=Q.dlopen(W,{flock:{args:[z.i32,z.i32],returns:z.i32},[$]:{args:[],returns:z.ptr},[q]:Z?{args:[z.ptr,z.ptr,z.u32],returns:z.i32}:{args:[z.i32,z.ptr,z.i32,z.ptr,z.u32],returns:z.i32}}).symbols,w=J[$]();if(w===null)continue;let j=(T)=>{let k=Q.read.i32(w),O=Object.entries(LZ.errno).find(([,E])=>E===k)?.[0]??`errno_${k}`;return Object.assign(Error(`${T} failed: ${O}`),{code:O})},HQ=(T)=>Buffer.from(`${T}\x00`,"utf8");return L={exchange(T,k){let O=HQ(T),E=HQ(k);if((Z?J[q](Q.ptr(O),Q.ptr(E),mZ):J[q](NQ,Q.ptr(O),NQ,Q.ptr(E),vZ))!==0)throw j("exchange")},lock(T){let k=NZ(T,_Z.O_RDONLY);if(J.flock(k,gZ|hZ)===0)return()=>FQ(k);let O=j("lock");if(FQ(k),O.code==="EWOULDBLOCK"||O.code==="EAGAIN")return null;throw O}},L}catch{}return null}import{createHmac as V0,createPublicKey as w0,randomBytes as G0,randomUUID as zZ,verify as H0}from"crypto";import{chmodSync as qQ,existsSync as WZ,mkdirSync as M0,readFileSync as j0,realpathSync as K0,renameSync as B0,statSync as O0,unlinkSync as k0,writeFileSync as A0}from"fs";import{basename as P0,dirname as YQ,isAbsolute as qZ,join as s,resolve as F0}from"path";var Y1=[Object.freeze({family:"ara",channel:"stable",applicationId:"so.ara.desktop"}),Object.freeze({family:"ara",channel:"staging",applicationId:"so.ara.desktop.staging"}),Object.freeze({family:"reason",channel:"stable",applicationId:"com.reasonmachines.desktop"}),Object.freeze({family:"reason",channel:"staging",applicationId:"com.reasonmachines.desktop.staging"})];var yZ="REASON_DESKTOP_RUNTIME",pZ="REASON_DESKTOP_RUNTIME_CHANNEL",uZ="REASON_DESKTOP_RUNTIME_INSTANCE_ID",dZ="REASON_DESKTOP_RUNTIME_WORKSPACE_SCOPE",M1={[yZ]:"ARA_DESKTOP_RUNTIME",[pZ]:"ARA_DESKTOP_RUNTIME_CHANNEL",[uZ]:"ARA_DESKTOP_RUNTIME_INSTANCE_ID",[dZ]:"ARA_DESKTOP_RUNTIME_WORKSPACE_SCOPE"};function uQ(Q){if(Q===void 0)return;if(!/^[a-f0-9]{64}$/.test(Q))throw Error("Invalid desktop workspace scope.");return Q}import{chmodSync as QQ,existsSync as F,mkdirSync as ZQ,readFileSync as lQ,realpathSync as lZ,renameSync as iZ,unlinkSync as $Q,writeFileSync as XQ}from"fs";import{createPrivateKey as oZ,createPublicKey as nZ,generateKeyPairSync as rZ,randomUUID as tZ,sign as aZ}from"crypto";import{createRequire as eZ}from"module";import{homedir as Q0,platform as rQ}from"os";import{dirname as Z0,join as C}from"path";import{existsSync as sZ}from"fs";import{join as cQ}from"path";var e="libara_device_keychain.dylib",dQ="libreason_device_keychain.dylib";class cZ extends Error{code;constructor(Q,Z){super(Z);this.code=Q;this.name="ManagedRuntimeError"}}function sQ(Q){let Z=cQ(Q,dQ);return sZ(Z)?Z:cQ(Q,e)}var iQ=1,$0=16384,S=65536,X0=128,z0=128,tQ=65536;class Y extends Error{code;nativeStatus;constructor(Q,Z){super(`Reason Device proof boundary failed (${Q}).${Z===void 0?"":` Native status: ${Z}.`}`);this.code=Q;this.nativeStatus=Z;this.name="LocalCredentialBoundaryError"}}function aQ(Q){if(Q.code==="proof_key_read_failed"&&Q.nativeStatus===-25300)return"proof_key_missing";switch(Q.nativeStatus){case-25308:return"keychain_interaction_required";case-25293:return"keychain_access_denied";case-25291:return"keychain_unavailable";default:return Q.code}}var zQ=null;function eQ(){if(!zQ)try{zQ=eZ(import.meta.url)("bun:ffi")}catch{throw new Y("native_boundary_unavailable")}return zQ}function W0(Q){if(typeof Q!=="string")return null;try{let Z=new URL(Q);if(Z.protocol!=="https:"&&Z.hostname!=="127.0.0.1"&&Z.hostname!=="localhost"&&Z.hostname!=="[::1]"&&Z.hostname!=="::1")return null;return Z.origin}catch{return null}}function q0(Q){if(!Q||typeof Q!=="object"||Array.isArray(Q))throw new Y("invalid_credential_record");let Z=Q,$=W0(Z.apiOrigin);if(Z.version!==iQ||!$||typeof Z.orgId!=="string"||Z.orgId.length<1||Z.orgId.length>160||typeof Z.deviceId!=="string"||Z.deviceId.length<1||Z.deviceId.length>160||typeof Z.credential!=="string"||!/^(?:reason|ara)_dev_/.test(Z.credential)||Z.credential.length>4096)throw new Y("invalid_credential_record");return{version:iQ,apiOrigin:$,orgId:Z.orgId,deviceId:Z.deviceId,credential:Z.credential}}function J0(Q=process.execPath){let Z=Q;try{Z=lZ(Q)}catch{}return sQ(Z0(Z))}function H(Q){return eQ().ptr(Q)}function Y0(Q){if(!F(Q))throw new Y("native_boundary_unavailable");let{dlopen:Z,FFIType:$}=eQ();try{return Z(Q,{ara_device_configure_scope:{args:[$.ptr,$.u64],returns:$.i32},ara_device_key_load_public:{args:[$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_key_create_fresh_public:{args:[$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_key_sign:{args:[$.ptr,$.u64,$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_key_is_non_extractable:{args:[$.ptr],returns:$.i32},ara_device_key_delete:{args:[$.ptr],returns:$.i32},ara_device_binding_read:{args:[$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_binding_create:{args:[$.ptr,$.u64],returns:$.i32},ara_device_binding_update:{args:[$.ptr,$.u64],returns:$.i32},ara_device_binding_delete:{args:[$.ptr],returns:$.i32},ara_device_keychain_read:{args:[$.ptr,$.u64,$.ptr],returns:$.i32},ara_device_keychain_delete:{args:[$.ptr],returns:$.i32}})}catch(X){if(X instanceof Y)throw X;throw new Y("native_boundary_unavailable")}}function oQ(Q){return Buffer.from(Q).toString("base64url")}function I(Q){if(typeof Q!=="string"||!/^[A-Za-z0-9_-]{87}$/.test(Q))return!1;try{let Z=Buffer.from(Q,"base64url");return Z.byteLength===65&&Z[0]===4}catch{return!1}}function QZ(Q){if(Q.byteLength<8||Q.byteLength>72||Q[0]!==48)return!1;let Z=Q[1];return Z!==void 0&&Z<128&&Z+2===Q.byteLength}class ZZ{libraryPath;runtimePlatform;workspaceScope;library=null;constructor(Q=J0(),Z=rQ(),$){this.libraryPath=Q;this.runtimePlatform=Z;this.workspaceScope=$;uQ($)}symbols(){if(this.runtimePlatform!=="darwin")throw new Y("unsupported_platform");this.library??=Y0(this.libraryPath);let Q=new TextEncoder().encode(this.workspaceScope??""),Z=this.library.symbols.ara_device_configure_scope(H(Q.length?Q:new Uint8Array(1)),BigInt(Q.length));if(Z!==0)throw new Y("native_boundary_unavailable",Z);return this.library.symbols}publicKey(Q){let Z=new Uint8Array(X0),$=new BigUint64Array(1),X=Q==="load"?this.symbols().ara_device_key_load_public(H(Z),BigInt(Z.byteLength),H($)):this.symbols().ara_device_key_create_fresh_public(H(Z),BigInt(Z.byteLength),H($));if(X!==0)throw new Y(Q==="load"?"proof_key_read_failed":"proof_key_generation_failed",X);let z=Number($[0]);if(!Number.isSafeInteger(z)||z!==65)throw new Y("invalid_public_key");let W=oQ(Z.subarray(0,z));if(!I(W))throw new Y("invalid_public_key");return W}loadPublicKey(){return this.publicKey("load")}createFreshPublicKey(){return this.publicKey("create_fresh")}sign(Q){if(Q.byteLength<1||Q.byteLength>tQ)throw new Y("proof_sign_failed");let Z=new Uint8Array(z0),$=new BigUint64Array(1),X=this.symbols().ara_device_key_sign(H(Q),BigInt(Q.byteLength),H(Z),BigInt(Z.byteLength),H($));if(X!==0)throw new Y("proof_sign_failed",X);let z=Number($[0]);if(!Number.isSafeInteger(z)||z<1||z>Z.byteLength)throw new Y("invalid_signature");let W=Z.subarray(0,z);if(!QZ(W))throw new Y("invalid_signature");return oQ(W)}privateKeyIsNonExtractable(){let Q=new Uint8Array(1),Z=this.symbols().ara_device_key_is_non_extractable(H(Q));if(Z!==0||Q[0]!==1)throw new Y("proof_key_read_failed",Z);return!0}deleteKey(){let Q=new Uint8Array(1),Z=this.symbols().ara_device_key_delete(H(Q));if(Z!==0)throw new Y("proof_key_delete_failed",Z);return Q[0]===1}loadBinding(){let Q=new Uint8Array(S),Z=new BigUint64Array(1),$=this.symbols().ara_device_binding_read(H(Q),BigInt(Q.byteLength),H(Z));if($===1)return null;if($!==0)throw new Y("binding_read_failed",$);let X=Number(Z[0]);if(!Number.isSafeInteger(X)||X<1||X>Q.byteLength)throw new Y("invalid_binding");return Q.slice(0,X)}createBinding(Q){if(Q.byteLength<1||Q.byteLength>S)throw new Y("invalid_binding");let Z=this.symbols().ara_device_binding_create(H(Q),BigInt(Q.byteLength));if(Z!==0)throw new Y("binding_create_failed",Z)}updateBinding(Q){if(Q.byteLength<1||Q.byteLength>S)throw new Y("invalid_binding");let Z=this.symbols().ara_device_binding_update(H(Q),BigInt(Q.byteLength));if(Z!==0)throw new Y("binding_update_failed",Z)}deleteBinding(){let Q=new Uint8Array(1),Z=this.symbols().ara_device_binding_delete(H(Q));if(Z!==0)throw new Y("binding_delete_failed",Z);return Q[0]===1}loadLegacyCredential(){let Q=new Uint8Array($0),Z=new BigUint64Array(1),$=this.symbols().ara_device_keychain_read(H(Q),BigInt(Q.byteLength),H(Z));if($===1)return null;if($!==0)throw new Y("legacy_credential_read_failed",$);let X=Number(Z[0]);if(!Number.isSafeInteger(X)||X<1||X>Q.byteLength)throw new Y("invalid_credential_record");try{let z=new TextDecoder("utf-8",{fatal:!0}).decode(Q.subarray(0,X));return q0(JSON.parse(z))}catch(z){if(z instanceof Y)throw z;throw new Y("invalid_credential_record")}}deleteLegacyCredential(){let Q=new Uint8Array(1),Z=this.symbols().ara_device_keychain_delete(H(Q));if(Z!==0)throw new Y("legacy_credential_delete_failed",Z);return Q[0]===1}}function nQ(Q){let Z=Q.export({format:"jwk"});if(Z.crv!=="P-256"||typeof Z.x!=="string"||typeof Z.y!=="string")throw new Y("invalid_public_key");let $=Buffer.from(Z.x,"base64url"),X=Buffer.from(Z.y,"base64url");if($.byteLength!==32||X.byteLength!==32)throw new Y("invalid_public_key");let z=Buffer.concat([Buffer.of(4),$,X]).toString("base64url");if(!I(z))throw new Y("invalid_public_key");return z}function U0(){let Q=process.env.XDG_CONFIG_HOME?.trim()||C(Q0(),".config");r(Q);let Z=C(Q,"ara");return v(Z)?Z:C(Q,"reason")}class $Z{directory;constructor(Q=U0()){this.directory=Q}keyPath(){return C(this.directory,"local-device.key")}bindingPath(){return C(this.directory,"local-device.binding")}loadPrivateKeyObject(){let Q=this.keyPath();if(!F(Q))throw new Y("proof_key_read_failed");try{let Z=lQ(Q,"utf8");return oZ({key:Z,format:"pem"})}catch{throw new Y("proof_key_read_failed")}}loadPublicKey(){let Q=this.loadPrivateKeyObject(),Z=nZ(Q);return nQ(Z)}createFreshPublicKey(){ZQ(this.directory,{recursive:!0,mode:448});let{privateKey:Q,publicKey:Z}=rZ("ec",{namedCurve:"P-256"}),$=Q.export({type:"pkcs8",format:"pem"}),X=this.keyPath();return XQ(X,$,{mode:384}),QQ(X,384),nQ(Z)}sign(Q){if(Q.byteLength<1||Q.byteLength>tQ)throw new Y("proof_sign_failed");let Z=this.loadPrivateKeyObject(),$;try{$=aZ("sha256",Q,Z)}catch{throw new Y("proof_sign_failed")}if(!QZ($))throw new Y("invalid_signature");return $.toString("base64url")}privateKeyIsNonExtractable(){return!1}deleteKey(){let Q=this.keyPath();if(!F(Q))return!1;return $Q(Q),!0}loadBinding(){let Q=this.bindingPath();if(!F(Q))return null;try{return new Uint8Array(lQ(Q))}catch{return null}}createBinding(Q){if(Q.byteLength<1||Q.byteLength>S)throw new Y("invalid_binding");ZQ(this.directory,{recursive:!0,mode:448});let Z=this.bindingPath();if(F(Z))throw new Y("binding_create_failed");XQ(Z,Q,{mode:384}),QQ(Z,384)}updateBinding(Q){if(Q.byteLength<1||Q.byteLength>S)throw new Y("invalid_binding");ZQ(this.directory,{recursive:!0,mode:448});let Z=this.bindingPath();if(!F(Z))throw new Y("binding_update_failed");let $=`${Z}.${tZ()}`;try{XQ($,Q,{mode:384,flag:"wx"}),QQ($,384),iZ($,Z)}finally{if(F($))$Q($)}}deleteBinding(){let Q=this.bindingPath();if(!F(Q))return!1;return $Q(Q),!0}loadLegacyCredential(){return null}deleteLegacyCredential(){return!1}}function WQ(){return rQ()==="darwin"?new ZZ:new $Z}var UQ=4;var d="macos-keychain-p256-v1",JZ=1,T0=`ARA-DEVICE-BINDING-V1
3
3
  `;function D0(Q){return Q===void 0||typeof Q==="number"&&Number.isInteger(Q)&&Q>=1&&Q<=4}function YZ(Q={},Z=c()){let $=KQ({env:{...process.env,...Q}}),X=Q.XDG_CONFIG_HOME?.trim()||s(Z,".config");return SQ(X,...$==="staging"?["staging"]:[])}function VQ(Q={},Z=c()){return s(YZ(Q,Z),"local-device.json")}function UZ(Q={},Z=c()){return s(YZ(Q,Z),"local-daemon.json")}function wQ(Q,Z){M0(YQ(Q),{recursive:!0,mode:448}),qQ(YQ(Q),448);let $=`${Q}.${process.pid}.${zZ()}.tmp`;try{A0($,`${JSON.stringify(Z,null,2)}
4
4
  `,{mode:384,flag:"wx"}),qQ($,384),B0($,Q),qQ(Q,384)}finally{if(WZ($))k0($)}return Q}function GQ(Q){if(!WZ(Q))return null;try{return JSON.parse(j0(Q,"utf8"))}catch{return null}}function JQ(Q,Z,$){try{Q.onCredentialLifecycle?.({event:Z,...$?{reasonCode:$}:{}})}catch{}}function R0(Q){if(!Array.isArray(Q))return null;let Z=[];for(let $ of Q){if(!$||typeof $!=="object")return null;let X=$;if(typeof X.id!=="string"||typeof X.label!=="string"||typeof X.path!=="string"||typeof X.pathFingerprint!=="string"||!X.permissions||typeof X.permissions.read!=="boolean"||typeof X.permissions.write!=="boolean"||typeof X.permissions.execute!=="boolean"||typeof X.permissions.discover_environment!=="boolean"||typeof X.permissions.expose_mcp!=="boolean")return null;Z.push({id:X.id,label:X.label,path:X.path,pathFingerprint:X.pathFingerprint,permissions:X.permissions})}return Z}function VZ(Q,Z,$=[]){let X=Object.keys(Q);return Z.every((z)=>Object.hasOwn(Q,z))&&X.every((z)=>Z.includes(z)||$.includes(z))}function _0(Q){if(typeof Q!=="string")return null;try{let Z=new URL(Q);if(Z.protocol!=="https:"&&Z.hostname!=="127.0.0.1"&&Z.hostname!=="localhost")return null;return Z.origin}catch{return null}}function wZ(Q){if(!Q||typeof Q!=="object"||Array.isArray(Q))return null;let Z=Q,$=R0(Z.roots),X=_0(Z.apiOrigin);if(!X||typeof Z.orgId!=="string"||typeof Z.deviceId!=="string"||typeof Z.displayName!=="string"||typeof Z.registeredAt!=="string"||!D0(Z.handsSlots)||Z.worker!==void 0&&(!Z.worker||!/^[a-f0-9]{64}$/.test(Z.worker.configDigest)||!["persistent","ephemeral"].includes(Z.worker.lifetime)||!Number.isFinite(Date.parse(Z.worker.expiresAt)))||!$)return null;return{apiOrigin:X,orgId:Z.orgId,deviceId:Z.deviceId,displayName:Z.displayName,registeredAt:Z.registeredAt,...Z.handsSlots!==void 0?{handsSlots:Z.handsSlots}:{},...Z.worker!==void 0?{worker:Z.worker}:{},roots:$}}function N0(Q){return{...Q,credentialStorage:d}}function x0(Q){return{version:UQ,apiOrigin:Q.apiOrigin,orgId:Q.orgId,deviceId:Q.deviceId,devicePublicKey:Q.devicePublicKey,displayName:Q.displayName,registeredAt:Q.registeredAt,...Q.handsSlots!==void 0?{handsSlots:Q.handsSlots}:{},...Q.worker!==void 0?{worker:Q.worker}:{},roots:Q.roots.map((Z)=>({id:Z.id,label:Z.label,path:Z.path,pathFingerprint:Z.pathFingerprint,permissions:{read:Z.permissions.read,write:Z.permissions.write,execute:Z.permissions.execute,discover_environment:Z.permissions.discover_environment,expose_mcp:Z.permissions.expose_mcp}})),credentialStorage:d}}function GZ(Q){if(!Q||typeof Q!=="object"||Array.isArray(Q))return null;let Z=Q;if(!VZ(Z,["version","apiOrigin","orgId","deviceId","devicePublicKey","displayName","registeredAt","roots","credentialStorage"],["handsSlots","worker"]))return null;let $=wZ(Z);if(!$||Z.version!==UQ||Z.credentialStorage!==d||!I(Z.devicePublicKey))return null;return{version:UQ,...$,devicePublicKey:Z.devicePublicKey,credentialStorage:d}}function HZ(Q){return new TextEncoder().encode(`${T0}${JSON.stringify(x0(Q))}`)}function L0(Q){let Z=Buffer.from(Q,"base64url");return w0({format:"jwk",key:{kty:"EC",crv:"P-256",x:Z.subarray(1,33).toString("base64url"),y:Z.subarray(33,65).toString("base64url")}})}function b0(Q,Z){let $={version:JZ,state:Q,signature:Z.sign(HZ(Q))};return new TextEncoder().encode(JSON.stringify($))}function MZ(Q){let Z;try{Z=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(Q))}catch{throw new Y("invalid_binding")}if(!Z||typeof Z!=="object"||Array.isArray(Z))throw new Y("invalid_binding");let $=Z;if(!VZ($,["version","state","signature"])||$.version!==JZ||typeof $.signature!=="string"||!/^[A-Za-z0-9_-]{10,128}$/.test($.signature))throw new Y("invalid_binding");let X=GZ($.state);if(!X)throw new Y("invalid_binding");let z=!1;try{z=H0("sha256",HZ(X),L0(X.devicePublicKey),Buffer.from($.signature,"base64url"))}catch{z=!1}if(!z)throw new Y("invalid_binding");return X}function f0(Q){let{credentialStorage:Z,...$}=Q;return $}function C0(Q){return Q instanceof Y?aQ(Q):"credential_boundary_failed"}function v1(Q=VQ(),Z={}){let $=GQ(Q),X=Z.proofStore??Z.credentialStore??WQ(),z=X.loadBinding();if(!z){if($&&typeof $==="object"&&!Array.isArray($)&&S0($))return null;if($!==null)throw new Y("invalid_binding");return null}let W=MZ(z),q=X.loadPublicKey();if(X.privateKeyIsNonExtractable(),q!==W.devicePublicKey)throw new Y("invalid_public_key");let V=GZ($);if(Z.repair!==!1&&(!V||JSON.stringify(V)!==JSON.stringify(W)))wQ(Q,W);return f0(W)}function S0(Q){let Z=Q,$=wZ(Q);if(!$)return null;if(Z.version===2){if(typeof Z.deviceCredential!=="string"||!/^(?:reason|ara)_dev_/.test(Z.deviceCredential)||Z.deviceCredential.length>4096)return null;return{state:$,credentialSource:"plaintext-v2"}}if(Z.version!==3||Z.credentialStorage!=="macos-keychain-v1"||"deviceCredential"in Z)return null;return{state:$,credentialSource:"keychain-v3"}}function y1(Q,Z=VQ(),$={}){let X=$.proofStore??$.credentialStore??WQ();JQ($,"credential.store_started");try{if(!I(Q.devicePublicKey)||X.loadPublicKey()!==Q.devicePublicKey)throw new Y("invalid_public_key");X.privateKeyIsNonExtractable();let z=N0(Q),W=X.loadBinding();if(W){let V=MZ(W);if(V.devicePublicKey!==Q.devicePublicKey||V.orgId!==Q.orgId||V.deviceId!==Q.deviceId||V.apiOrigin!==Q.apiOrigin&&!OQ(V.apiOrigin,Q.apiOrigin))throw new Y("invalid_binding")}let q=b0(z,X);if(W)X.updateBinding(q);else X.createBinding(q);return wQ(Z,z),JQ($,"credential.store_completed"),Z}catch(z){throw JQ($,"credential.store_failed",C0(z)),z}}function p1(Q=UZ()){let Z=GQ(Q);if(!Z||typeof Z!=="object")return null;let $=Z;if($.version!==1||typeof $.pid!=="number"||!Number.isInteger($.pid)||!["starting","connected","stopped","error"].includes($.state??"")||typeof $.startedAt!=="string"||$.lastHeartbeatAt!==void 0&&typeof $.lastHeartbeatAt!=="string"||$.lastUsedAt!==void 0&&typeof $.lastUsedAt!=="string"||$.organizationId!==void 0&&typeof $.organizationId!=="string"||$.organizationName!==void 0&&typeof $.organizationName!=="string"||$.organizationSlug!==void 0&&typeof $.organizationSlug!=="string"||$.error!==void 0&&typeof $.error!=="string"||$.reconnectingSince!==void 0&&typeof $.reconnectingSince!=="string"||$.workspace!==void 0&&typeof $.workspace!=="string")return null;return $}function u1(Q,Z=UZ()){return wQ(Z,Q)}var XZ=1;function I0(Q=VQ()){return s(YQ(Q),"local-device.proxy.json")}function d1(Q=I0()){let Z=GQ(Q);if(!Z||typeof Z!=="object"||Array.isArray(Z))return null;let $=Z;if($.version!==XZ||typeof $.url!=="string"||$.url.length===0||$.caFile!==void 0&&(typeof $.caFile!=="string"||!qZ($.caFile)))return null;return{version:XZ,url:$.url,...$.caFile?{caFile:$.caFile}:{}}}function c1(Q,Z={read:!0,write:!1,execute:!1,discover_environment:!1,expose_mcp:!1},$=G0(32)){let X=new Set,z=[];for(let W of Q){let q=K0(qZ(W)?W:F0(W));if(!O0(q).isDirectory())throw Error(`Local execution root is not a directory: ${W}`);if(X.has(q))continue;X.add(q),z.push({id:zZ(),label:P0(q)||q,path:q,pathFingerprint:V0("sha256",$).update(q).digest("hex"),permissions:{...Z}})}if(z.length===0)throw Error("At least one explicit local execution root is required.");return z}
5
- export{MQ as ze,KZ as Ae,i as Be,KQ as Ce,h as De,y0 as Ee,jQ as Fe,p0 as Ge,OQ as He,u0 as Ie,d0 as Je,r as Ke,SQ as Le,z1 as Me,W1 as Ne,q1 as Oe,pQ as Pe,cZ as Qe,Y as Re,J0 as Se,I as Te,QZ as Ue,ZZ as Ve,$Z as We,VQ as Xe,UZ as Ye,v1 as Ze,y1 as _e,p1 as $e,u1 as af,XZ as bf,d1 as cf,c1 as df};
5
+ export{MQ as Be,KZ as Ce,i as De,KQ as Ee,h as Fe,y0 as Ge,jQ as He,p0 as Ie,OQ as Je,u0 as Ke,d0 as Le,r as Me,SQ as Ne,z1 as Oe,W1 as Pe,q1 as Qe,pQ as Re,cZ as Se,Y as Te,J0 as Ue,I as Ve,QZ as We,ZZ as Xe,$Z as Ye,VQ as Ze,UZ as _e,v1 as $e,y1 as af,p1 as bf,u1 as cf,XZ as df,d1 as ef,c1 as ff};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
2
  var U=".reason/workspace",T="workspace_base",W="sessions",y="workspace_layout",g=".reason/workspace/sessions",$=/^[0-9a-f]{8}$/;function C(b){if(!F(b))return!1;let j=".reason/workspace/sessions/";if(!b.startsWith(j))return!1;let q=b.slice(j.length).split("/");return q.length===2&&$.test(q[0])}var B=4096,G="workspaces/pi";function F(b){if(typeof b!=="string"||!b||b.length>B)return!1;if(b.startsWith("/")||b.includes("\x00")||b.includes("\\"))return!1;return b.split("/").every((j)=>j!==""&&j!=="."&&j!=="..")}function V(b){if(b.kind==="root"){if(b.path===void 0)return".";if(!F(b.path))throw Error("invalid_device_workspace_identity");return b.path}if(!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,159}$/.test(b.workspaceId)||b.workspaceId==="."||b.workspaceId==="..")throw Error("invalid_device_workspace_identity");let j=b.layout==="sessions"?"sessions":G;return`${b.base?`${b.base}/`:""}${j}/${b.workspaceId}/repo`}function P(b){if(!b||typeof b!=="object"||Array.isArray(b))return null;let j=b;if(j.kind==="root"&&Object.keys(j).length===1)return{kind:"root"};if(j.kind==="root"&&Object.keys(j).length===2&&F(j.path))return{kind:"root",path:j.path};if(j.kind!=="managed"||typeof j.workspaceId!=="string"||Object.keys(j).length!==2+(j.base===void 0?0:1)+(j.layout===void 0?0:1)||j.base!==void 0&&j.base!==".reason/workspace"||j.layout!==void 0&&j.layout!=="sessions")return null;let q={kind:"managed",workspaceId:j.workspaceId,...j.base===".reason/workspace"?{base:".reason/workspace"}:{},...j.layout==="sessions"?{layout:"sessions"}:{}};try{return V(q),q}catch{return null}}var X="/home/runner",x="/run/reason/sessions",f=/^(?:\/[A-Za-z0-9._-]+)+$/,M=/-sidechat-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,K=/^(.+)-repository-[a-z0-9][a-z0-9._-]*-[0-9a-f]{12}$/;function Y(b){return M.exec(b)?.[1]??K.exec(b)?.[1]??b}var Z=/^((?:\/[A-Za-z0-9._-]+)+)\/\.reason\/workspace\/(workspaces\/pi|sessions)\/([^/]+)$/,A="*/.reason/workspace/workspaces/pi/*|*/.reason/workspace/sessions/*";function H(b,j=X,q="sessions"){if(!f.test(j)||j.split("/").some((Q)=>Q==="."||Q===".."))throw Error("invalid_cloud_payload_home");let J=`${j}/${V({kind:"managed",workspaceId:b,base:".reason/workspace",...q?{layout:q}:{}})}`,z=`${x}/${Y(b)}`;return{home:j,root:J.slice(0,-5),checkout:J,control:z,jobEnv:`${z}/job.env`,cloudAccess:`${z}/cloud-access`,logs:`${z}/logs`,pin:`${z}/ws`}}function N(b){return Z.exec(b.replace(/\/+$/,""))?.[2]==="sessions"?"sessions":null}function L(b){return{kind:"managed",workspaceId:b,layout:"sessions"}}function D(b){let j=Z.exec(b.replace(/\/+$/,""));if(!j)return null;try{let q=H(j[3],j[1],N(b));return q.root===b.replace(/\/+$/,"")?q:null}catch{return null}}
3
- export{U as ah,T as bh,W as ch,y as dh,g as eh,$ as fh,C as gh,F as hh,V as ih,P as jh,X as kh,x as lh,M as mh,K as nh,Z as oh,A as ph,H as qh,N as rh,L as sh,D as th};
3
+ export{U as ch,T as dh,W as eh,y as fh,g as gh,$ as hh,C as ih,F as jh,V as kh,P as lh,X as mh,x as nh,M as oh,K as ph,Z as qh,A as rh,H as sh,N as th,L as uh,D as vh};