@reason-machines/cli-linux-arm64 0.2.406 → 0.2.408
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.
- package/THIRD_PARTY_NOTICES.txt +8 -7
- package/bin/reason +2 -2
- package/bin/runtime/srt/sandbox-runtime.mjs +52 -52
- package/bin/vm-hands/api-8d760ppa.js +2 -0
- package/bin/vm-hands/api-credentials-eea1g4aw.js +2 -0
- package/bin/vm-hands/connect-cli-m8xafyn5.js +2 -0
- package/bin/vm-hands/custom-endpoint-device-nfjhs9fv.js +2 -0
- package/bin/vm-hands/desktop-account-rx4ajy2j.js +2 -0
- package/bin/vm-hands/device-workspace-n9tn4bzw.js +2 -0
- package/bin/vm-hands/fsevents-vgg0dny6.js +2 -0
- package/bin/vm-hands/hands-worker-source-yxsap3qk.js +2 -0
- package/bin/vm-hands/index-kx10kwyx.js +12818 -0
- package/bin/vm-hands/install-receipt-rmsjtfqy.js +2 -0
- package/bin/vm-hands/local-automation-7qcnytj6.js +2 -0
- package/bin/vm-hands/local-capabilities-hchsc804.js +2 -0
- package/bin/vm-hands/local-desktop-users-c6858avg.js +2 -0
- package/bin/vm-hands/local-display-mac-zmbp9z4c.js +2 -0
- package/bin/vm-hands/local-display-session-7bgp7gvf.js +2 -0
- package/bin/vm-hands/local-pty-session-8m175hqx.js +2 -0
- package/bin/vm-hands/managed-runtime-nkmg5s5h.js +2 -0
- package/bin/vm-hands/network-contract-qt2s82ap.js +2 -0
- package/bin/vm-hands/package-11mkdcmn.js +2 -0
- package/bin/vm-hands/permissions-67xv16a5.js +2 -0
- package/bin/vm-hands/reason-hands-protocol-r356wr4t.js +2 -0
- package/bin/vm-hands/serve-service-4n7e0b08.js +2 -0
- package/bin/vm-hands/status-e7r62q4e.js +10 -0
- package/bin/vm-hands/version-vdev7tyq.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-0n2f3kx7.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-4aejamqr.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-4geps3jz.js +5 -0
- package/bin/vm-hands/{vm-hands-entry-lite-xqve205b.js → vm-hands-entry-lite-51qvfk93.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-5p5h1eng.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-6p9c8nhf.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-6whxyzz2.js +52 -0
- package/bin/vm-hands/vm-hands-entry-lite-762fbns7.js +14 -0
- package/bin/vm-hands/vm-hands-entry-lite-79s23abx.js +7 -0
- package/bin/vm-hands/vm-hands-entry-lite-8bzqc4xa.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-8evzzh7v.js +112 -0
- package/bin/vm-hands/vm-hands-entry-lite-8gtgr399.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-9ym3sx81.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-dkcm3hyn.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-dq1m5ykp.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-e5hbehqn.js +250 -0
- package/bin/vm-hands/vm-hands-entry-lite-et2bh990.js +458 -0
- package/bin/vm-hands/vm-hands-entry-lite-fyjzrvj5.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-g3ja0c3y.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-gc7c22pq.js +2 -0
- package/bin/vm-hands/{vm-hands-entry-lite-wer0qzxg.js → vm-hands-entry-lite-hcw5tk5d.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-hee1h411.js +105 -0
- package/bin/vm-hands/{vm-hands-entry-lite-dsh32j5a.js → vm-hands-entry-lite-hfmydph9.js} +5 -9
- package/bin/vm-hands/vm-hands-entry-lite-hzn1hf0p.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-mvx29q2q.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-mw0gzbds.js +6 -0
- package/bin/vm-hands/vm-hands-entry-lite-pmcz7j7t.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-pn92kh7b.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-ppytc9k7.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-qffs74x1.js +540 -0
- package/bin/vm-hands/vm-hands-entry-lite-qy9xg6em.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-rwr09j4w.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-saqdrc2w.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-snmxxhza.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-fbpxs065.js → vm-hands-entry-lite-t7an5zg2.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-v3xznxcw.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-w8kc4jtb.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-w9ckj5k4.js +5 -0
- package/bin/vm-hands/{vm-hands-entry-lite-jcd21jpm.js → vm-hands-entry-lite-wd576mgy.js} +54 -54
- package/bin/vm-hands/vm-hands-entry-lite-wf7ksh4e.js +9 -0
- package/bin/vm-hands/vm-hands-entry-lite-wyh6dp1t.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-ym1djztp.js +42 -0
- package/bin/vm-hands/vm-hands-entry-lite-zg3b0c08.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-zn0v259d.js +65 -0
- package/bin/vm-hands/vm-hands-entry-lite.js +3 -1
- package/bin/vm-hands/vm-hands-executor-79av9nam.js +11 -0
- package/bin/vm-hands/vm-hands-op-runner-kh1myd15.js +2 -0
- package/bin/vm-hands/vm-hands-runtime-yacvv937.js +4 -0
- package/bin/vm-hands/worker-sandbox-x8dsz324.js +2 -0
- package/package.json +1 -1
- package/bin/vm-hands/api-credentials-4e2gypqj.js +0 -2
- package/bin/vm-hands/api-f48wa4ym.js +0 -2
- package/bin/vm-hands/ask-relay-nydkgmvq.js +0 -8
- package/bin/vm-hands/connect-cli-10axcfnk.js +0 -2
- package/bin/vm-hands/custom-endpoint-device-8h95wy87.js +0 -2
- package/bin/vm-hands/desktop-account-2kkxwv1y.js +0 -2
- package/bin/vm-hands/device-workspace-nzz3kd5t.js +0 -2
- package/bin/vm-hands/hands-worker-source-as5wepvk.js +0 -2
- package/bin/vm-hands/index-2kk983b8.js +0 -12818
- package/bin/vm-hands/install-receipt-e6s355j1.js +0 -2
- package/bin/vm-hands/local-automation-nr2dg0t3.js +0 -2
- package/bin/vm-hands/local-capabilities-ep1d24ne.js +0 -2
- package/bin/vm-hands/local-desktop-users-sevkfkye.js +0 -2
- package/bin/vm-hands/local-display-mac-jzc0g5ge.js +0 -2
- package/bin/vm-hands/local-display-session-0vyd74rj.js +0 -2
- package/bin/vm-hands/local-pty-session-fe6jz2zy.js +0 -2
- package/bin/vm-hands/managed-runtime-5zrdx8xk.js +0 -2
- package/bin/vm-hands/network-contract-9smga6kn.js +0 -2
- package/bin/vm-hands/package-qjr5q0bp.js +0 -2
- package/bin/vm-hands/permissions-04sm9aq9.js +0 -2
- package/bin/vm-hands/reason-hands-protocol-5fhd49en.js +0 -2
- package/bin/vm-hands/serve-service-hd0k7s2x.js +0 -2
- package/bin/vm-hands/status-n3x94yjb.js +0 -96
- package/bin/vm-hands/version-aec5t9wd.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-0c4nxpza.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-159860ns.js +0 -52
- package/bin/vm-hands/vm-hands-entry-lite-1sc3wc94.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-2nec0vk1.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-40nkzw38.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-5rkakg10.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-5tgm1m3h.js +0 -458
- package/bin/vm-hands/vm-hands-entry-lite-69ray4x8.js +0 -6
- package/bin/vm-hands/vm-hands-entry-lite-6berk108.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-72nn2b4n.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-8f3px72v.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-8gjrr6hg.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-8tcnbfnm.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-9vf97byd.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-ac8sdh78.js +0 -105
- package/bin/vm-hands/vm-hands-entry-lite-bmywbwj4.js +0 -9
- package/bin/vm-hands/vm-hands-entry-lite-c60v3v0v.js +0 -540
- package/bin/vm-hands/vm-hands-entry-lite-er3nrbb9.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-g1wjmmr9.js +0 -346
- package/bin/vm-hands/vm-hands-entry-lite-g5c9ec33.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-h0y0xv5f.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-h9t84ekh.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-hd4a0a6f.js +0 -112
- package/bin/vm-hands/vm-hands-entry-lite-hepppjp0.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-hye6r7dy.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-jw5y1aa5.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-ky0w7t09.js +0 -42
- package/bin/vm-hands/vm-hands-entry-lite-mapxp682.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-np1fcr2t.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-nqvb7a2m.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-q4tcfj61.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-qpba4sxt.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-r2xmr627.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-swwb5mp2.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-vr38bh6k.js +0 -66
- package/bin/vm-hands/vm-hands-entry-lite-vwpraybq.js +0 -251
- package/bin/vm-hands/vm-hands-entry-lite-wa261sf8.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-wn4gvb8w.js +0 -11
- package/bin/vm-hands/vm-hands-entry-lite-yg5h9mhm.js +0 -7
- package/bin/vm-hands/vm-hands-entry-lite-yqrmr2c8.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-z5912r1q.js +0 -3
- package/bin/vm-hands/vm-hands-executor-m1jwswd0.js +0 -11
- package/bin/vm-hands/vm-hands-op-runner-6amaw4zn.js +0 -2
- package/bin/vm-hands/vm-hands-runtime-jt4j6362.js +0 -4
- package/bin/vm-hands/worker-sandbox-p242st5d.js +0 -2
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{mt,R}from"./vm-hands-entry-lite-w9ckj5k4.js";import{C}from"./vm-hands-entry-lite-t7an5zg2.js";import{g,Lt}from"./vm-hands-entry-lite-5p5h1eng.js";import{_e}from"./vm-hands-entry-lite-pmcz7j7t.js";function gi(e,i){let r=C(e,"REASON_API_URL")?.trim();if(!r)return Lt(i);let t=new URL(r);if(t.protocol!=="https:"&&!(t.protocol==="http:"&&["127.0.0.1","localhost","::1"].includes(t.hostname)))throw Error("REASON_API_URL must use HTTPS (HTTP is allowed only for loopback development).");return t.origin}function l(e){return C(e,"REASON_API_URL")?.trim()?gi(e,"production"):void 0}function wo(e){return C(e,"REASON_API_KEY")?.trim()||void 0}async function bo(e,i){let r=e.env??process.env,t=wo(r);if(!t)return(e.getCredentials??mt)({apiOrigin:l(r),signal:i});let a=gi(r,e.channel??g({env:r})),o=await(e.fetchImpl??fetch)(a+"/v3/self",{redirect:"error",headers:{authorization:"Bearer "+t,accept:"application/json"},signal:i}),p=await o.json().catch(()=>({})),n=_e(p)?p:{};if(!o.ok){let s=typeof n.detail==="string"?n.detail:typeof n.message==="string"?n.message:"API key authentication failed ("+o.status+")";throw new R(o.status,typeof n.error==="string"?n.error:"api_key_auth_failed",s)}if(typeof n.org_id!=="string"||!n.org_id)throw Error("The API key in the environment did not resolve to a Workspace.");let c=Array.isArray(n.scopes)?n.scopes.filter((s)=>typeof s==="string"):[];return{credentialKind:"api_key",apiOrigin:a,accessToken:t,orgId:n.org_id,clientId:"api-key",refreshToken:"",expiresAt:"",scopes:c}}async function qo(e){let i=await bo(e),r=l(e.env??process.env);if(!i)throw Error(r?`Not signed in to ${r}. Set REASON_API_KEY, or run \`reason login --api-url ${r}\`.`:"Not signed in. Run `reason login`, or set REASON_API_KEY.");return i}
|
|
3
|
+
export{gi,wo,bo,qo};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{H}from"./vm-hands-entry-lite-mvx29q2q.js";var ji=32;var Ui="__ARA_PI_TOOL_CONFINED_SCRIPT_5f0c9e2a__",Hi=262144;var k=2,Er=33554432,xr=200000,_n=4000000,et=240000;var yn=2000;var kr=16384,Fe=32768,ye=128,wn=64,je=2097152,It=1,te=16384,Ue=32768,bn=8388608,we=1000,Dt=2500,Cr=2000,Nt=Dt+Cr,R=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/,y=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,Ar={text_only:4430,invalid_json:4431,invalid_cancel_request:4432,invalid_sdk_response:4433,claim_required:4434,invalid_claim:4435,executor_mismatch:4436,stale_generation:4437,fence_conflict:4438,frame_too_large:4439,result_too_large:4440,progress_too_large:4441,terminal_cleanup_started:4442,job_journal_unavailable:4443},I=new Map(Object.entries(Ar).map(([t,n])=>[n,t]));var h=["cancelled","command_failed","duplicate_request_id","duplicate_result_evicted","invalid_repl_response","invalid_request","process_group_cleanup_unconfirmed","repl_failed","result_too_large","repl_response_too_large","repl_transport_failed","request_ledger_full","request_journal_unavailable","request_outcome_uncertain","maintenance_held","request_not_found","resume_digest_mismatch","spawn_failed","stale_generation","timeout"],E=new Set(h),vn=16384;var S=["maintenance_held","invalid_job_request","jobs_disabled","job_not_found","job_conflict","job_capacity","job_journal_unavailable","job_not_running","job_lease_expired","job_input_sequence","job_input_backpressure","stale_generation","pty_unsupported","job_mode_mismatch"];class o extends Error{code;constructor(t){super(t);this.name="HandsProtocolError",this.code=t}}function m(t){return new TextEncoder().encode(t).byteLength}function a(t){return typeof t==="object"&&t!==null&&!Array.isArray(t)}function s(t,n){let e=new Set(n);return Object.keys(t).every((i)=>e.has(i))}function ae(t){return typeof t==="string"&&R.test(t)}function U(t){return Number.isSafeInteger(t)&&Number(t)>=1}function N(t){return typeof t==="string"&&y.test(t)}function ce(t){return typeof t==="string"&&t.startsWith("pty-")&&N(t.slice(4))}function p(t){return[t.cols,t.rows].every((n)=>Number.isSafeInteger(n)&&Number(n)>=1&&Number(n)<=we)}function _(t){if(typeof t!=="string"||t.length>Math.ceil(te/3)*4||t.length%4!==0||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return-1;let n=t.endsWith("==")?2:t.endsWith("=")?1:0;if(n&&"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t[t.length-n-1])&(n===2?15:3))return-1;let i=t.length/4*3-n;return i<=te?i:-1}function l(t){if(m(t)>Er)throw new o("frame_too_large");try{return JSON.parse(t)}catch{throw new o("invalid_json")}}function Pr(t){let n=l(t);if(!a(n)||!s(n,["type","version","generation","id","jobId","action","input"])||n.type!=="job"||n.version!==k||!U(n.generation)||!ae(n.id)||!ae(n.jobId)||!a(n.input))throw new o("invalid_job_request");let e=n.input,i=Number.isSafeInteger(e.leaseExpiresAtMs)&&Number(e.leaseExpiresAtMs)>0,d=Number.isSafeInteger(e.sequence)&&Number(e.sequence)>=1;if(!(n.action==="start"?e.mode==="pty"?s(e,["mode","cols","rows","leaseExpiresAtMs"])&&ce(n.jobId)&&p(e)&&i:s(e,["script","leaseExpiresAtMs"])&&typeof e.script==="string"&&e.script.length<=xr&&i:n.action==="inspect"?s(e,["after"])&&Number.isSafeInteger(e.after)&&Number(e.after)>=0:n.action==="input"?"dataBase64"in e?s(e,["sequence","dataBase64"])&&ce(n.jobId)&&d&&_(e.dataBase64)>0:s(e,["sequence","data","eof"])&&d&&typeof e.data==="string"&&e.data.length<=kr&&typeof e.eof==="boolean":n.action==="resize"?s(e,["sequence","cols","rows"])&&ce(n.jobId)&&d&&p(e):n.action==="renew"?s(e,["leaseExpiresAtMs"])&&i:n.action==="cancel"&&s(e,[])))throw new o("invalid_job_request");return n}function Tr(t){let n=l(t);if(!a(n)||!s(n,["type","version","generation","id","ok","job","error"])||n.type!=="job_result"||n.version!==k||!U(n.generation)||!ae(n.id))throw new o("invalid_job_result");if(n.ok===!1&&n.job===void 0&&typeof n.error==="string"&&S.some((r)=>r===n.error))return n;let e=n.job;if(n.ok!==!0||n.error!==void 0||!a(e)||!s(e,["jobId","state","startedAtMs","finishedAtMs","leaseExpiresAtMs","exitCode","inputSequence","output","firstCursor","nextCursor","truncated","process","environmentRevision","environmentSnapshotId","pty"])||!ae(e.jobId)||!["starting","running","exited","cancelled","expired","uncertain"].includes(String(e.state))||!Number.isSafeInteger(e.startedAtMs)||Number(e.startedAtMs)<1||!Number.isSafeInteger(e.leaseExpiresAtMs)||Number(e.leaseExpiresAtMs)<1||e.finishedAtMs!==null&&(!Number.isSafeInteger(e.finishedAtMs)||Number(e.finishedAtMs)<Number(e.startedAtMs))||e.exitCode!==null&&(!Number.isSafeInteger(e.exitCode)||Number(e.exitCode)<0||Number(e.exitCode)>255)||!Number.isSafeInteger(e.inputSequence)||Number(e.inputSequence)<0||!Number.isSafeInteger(e.firstCursor)||Number(e.firstCursor)<1||!Number.isSafeInteger(e.nextCursor)||Number(e.nextCursor)<Number(e.firstCursor)-1||typeof e.truncated!=="boolean"||!Array.isArray(e.output)||e.output.length>ye)throw new o("invalid_job_result");if(e.environmentRevision===void 0!==(e.environmentSnapshotId===void 0)||e.environmentRevision!==void 0&&(!Number.isSafeInteger(e.environmentRevision)||Number(e.environmentRevision)<1||!N(e.environmentSnapshotId)))throw new o("invalid_job_result");let i=Number(e.firstCursor)-1,d=0;for(let r of e.output){if(!a(r)||!s(r,["cursor","stream","text"])||!Number.isSafeInteger(r.cursor)||Number(r.cursor)<=i||Number(r.cursor)>Number(e.nextCursor)||!["stdout","stderr"].includes(String(r.stream))||typeof r.text!=="string")throw new o("invalid_job_result");d+=r.text.length,i=Number(r.cursor)}if(d>Fe)throw new o("invalid_job_result");let c=e.state==="starting"||e.state==="running";if(c&&(e.finishedAtMs!==null||e.exitCode!==null)||!c&&e.finishedAtMs===null||e.state==="uncertain"&&e.exitCode!==null||e.state==="exited"&&e.exitCode===null||e.state==="cancelled"&&e.exitCode!==130||e.state==="expired"&&e.exitCode!==124)throw new o("invalid_job_result");if(e.process!==void 0){let r=e.process;if(!a(r)||!s(r,["pid","processGroupId","executorLaunchId"])||!Number.isSafeInteger(r.pid)||Number(r.pid)<1||r.processGroupId!==r.pid||!N(r.executorLaunchId)||!["starting","running"].includes(String(e.state)))throw new o("invalid_job_result")}if(e.pty!==void 0){let r=e.pty;if(!a(r)||!s(r,["version","cols","rows","output","cleanup"])||r.version!==It||!ce(e.jobId)||!p(r)||e.output.length!==0||!Array.isArray(r.output)||r.output.length>ye||(c?r.cleanup!=="pending":e.state==="uncertain"?r.cleanup!=="unconfirmed":r.cleanup!=="confirmed")||e.state==="running"&&(e.process===void 0||e.environmentRevision===void 0))throw new o("invalid_job_result");let g=Number(e.firstCursor)-1,b=0;for(let u of r.output){if(!a(u)||!s(u,["cursor","dataBase64"])||!Number.isSafeInteger(u.cursor)||Number(u.cursor)<=g||Number(u.cursor)>Number(e.nextCursor))throw new o("invalid_job_result");let f=_(u.dataBase64);if(f<=0||(b+=f)>Ue)throw new o("invalid_job_result");g=Number(u.cursor)}}return n}function Sn(t){if(m(t)>je)throw new o("frame_too_large");let n=l(t);if(!a(n)||!s(n,["version","sessionId","operationId","runId","deviceId","rootId","workspace","binding","targetRevision","rootGrantRevision","generation","fenceId","executorLaunchId","job"])||n.version!==It||![n.sessionId,n.operationId,n.runId].every(ae)||![n.deviceId,n.rootId,n.fenceId,n.executorLaunchId].every(N)||!U(n.generation)||!Number.isSafeInteger(n.rootGrantRevision)||Number(n.rootGrantRevision)<1||!["workspace_source","mcp_control"].includes(String(n.binding))||!Number.isSafeInteger(n.targetRevision)||Number(n.targetRevision)<0||n.binding==="workspace_source"&&n.targetRevision!==0||!a(n.workspace))throw new o("invalid_pty_receipt");if(!H(n.workspace))throw new o("invalid_pty_receipt");let e=Tr(JSON.stringify({type:"job_result",version:k,generation:n.generation,id:n.operationId,ok:!0,job:n.job}));if(!e.ok||!e.job.pty||e.job.pty.output.length!==0||e.job.process&&e.job.process.executorLaunchId!==n.executorLaunchId)throw new o("invalid_pty_receipt");return n}export{ji,Ui,Hi,k,Er,xr,_n,et,yn,kr,Fe,ye,wn,je,It,te,Ue,bn,we,Dt,Cr,Nt,Ar,vn,ae,U,N,ce,Pr,Tr,Sn};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{rt,g,nt}from"./vm-hands-entry-lite-5p5h1eng.js";import{chmodSync as Q,existsSync as C,mkdirSync as Z,readlinkSync as S,readFileSync as b,renameSync as nn,unlinkSync as tn,writeFileSync as en}from"fs";import{homedir as u}from"os";import{basename as _,dirname as h,isAbsolute as p,join as o,normalize as A,relative as O,resolve as N}from"path";var c=3,P=1,D=2,x=1,T=1,L="Reason may read and write files and run commands in this signed-in OS account, subject to saved restrictions and operating system permissions.",M="Reason may later execute on this computer inside a Reason sandbox, limited to folders explicitly attached by the user.",F=[M,"Ara may later execute on this computer inside an Ara sandbox, limited to folders explicitly attached by the user."];function B(n){return typeof n==="string"&&F.includes(n)}var U=["future_device","updates_only","cli_only"];function f(n){return typeof n==="string"&&U.some((t)=>t===n)}function V(n=process.env,t=u()){return n.XDG_CONFIG_HOME?.trim()||o(t,".config")}function Ir(n=process.env,t=u()){let r=g({env:n}),e=V(n,t);return o(e,nt(e).state==="kept"?"ara":"reason",...r==="staging"?["staging"]:[],"installation.json")}function a(n){return typeof n==="string"&&n.trim().length>0}var K=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function z(n){return typeof n==="string"&&K.test(n)}function l(n){return a(n)&&p(n)&&A(n)===n}function y(n){if(!n||typeof n!=="object"||Array.isArray(n))return!1;let t=n;return l(t.path)&&(t.role==="launcher"&&(t.kind==="file"||t.kind==="symlink")||t.role==="worker_root"&&t.kind==="directory"||t.role==="alias"&&t.kind==="symlink"&&l(t.target))}function m(n){return n==="staging"?["reason-staging","ara-staging"]:["reason","ara"]}function Cn(n){let t=n.owned_paths.filter((e)=>e.role==="launcher").map((e)=>e.path),[r]=m(n.channel);return t.find((e)=>_(e)===r)??t[0]??null}function I(n){let[t,r]=m(n.channel==="staging"?"staging":"production"),e=[[t,r],[r,t]];return n.owned_paths?.every((i)=>i.role!=="alias"||n.installer==="shell"&&e.some(([s,R])=>i.path===o(n.install_dir,s)&&i.target===o(n.install_dir,R))&&n.owned_paths?.some((s)=>s.role==="launcher"&&s.path===i.target))??!1}function d(n,t){try{return N(h(n),S(n))===t}catch{return!1}}function Dr(n){let t=_(n),r=t==="ara"?"reason":t==="ara-staging"?"reason-staging":null;if(!r)return n;let e=o(h(n),r);return d(e,n)||d(n,e)?e:n}function w(n,t){let r=O(n,t);return r.length>0&&!r.startsWith("..")&&!p(r)}function E(n){if(n===null)return!0;if(!n||typeof n!=="object"||Array.isArray(n))return!1;let t=n;return(t.kind==="shell_profile"||t.kind==="windows_user_path")&&a(t.location)&&a(t.value)&&(typeof t.added_by_installer==="boolean"||typeof t.added_by_ara==="boolean")&&(t.added_by_installer===void 0||typeof t.added_by_installer==="boolean")&&(t.added_by_ara===void 0||typeof t.added_by_ara==="boolean")}function k(n,t){if(t===null)return n==="cli_only";if(!t||typeof t!=="object"||Array.isArray(t))return!1;let r=t;if(r.version!==x||!a(r.recorded_at))return!1;if(n==="future_device")return r.decision==="authorized"&&B(r.scope);return r.scope===null&&r.decision===(n==="updates_only"?"ask":"disabled")}function G(n){if(!n||typeof n!=="object"||Array.isArray(n))return null;let t=n;if(t.schema_version!==P||!rt.includes(t.channel)||t.install_method!=="curl"||t.installer!=="shell"&&t.installer!=="powershell"||!a(t.installed_at)||!a(t.version)||!a(t.target)||!l(t.install_dir)||!Array.isArray(t.owned_paths)||!t.owned_paths.every(y)||!t.owned_paths.every((r)=>w(t.install_dir,r.path))||!I(t)||!E(t.path_entry))return null;return{...t,schema_version:c,installation_id:null,background_mode:"cli_only",device_consent:null}}function j(n){if(!n||typeof n!=="object"||Array.isArray(n))return null;let t=n;if(t.schema_version!==D||!v(t)||!f(t.background_mode)||!k(t.background_mode,t.device_consent))return null;return{...t,schema_version:c,installation_id:null}}function v(n){return rt.includes(n.channel)&&(n.install_method==="curl"&&(n.installer==="shell"||n.installer==="powershell")||n.install_method==="desktop"&&n.installer==="desktop"&&Array.isArray(n.owned_paths)&&n.owned_paths.length===0&&n.path_entry===null)&&a(n.installed_at)&&a(n.version)&&a(n.target)&&l(n.install_dir)&&Array.isArray(n.owned_paths)&&n.owned_paths.every(y)&&n.owned_paths.every((t)=>w(n.install_dir,t.path))&&I(n)&&E(n.path_entry)}function H(n){let t=G(n);if(t)return t;let r=j(n);if(r)return r;if(!n||typeof n!=="object"||Array.isArray(n))return null;let e=n;if(e.schema_version!==c||!z(e.installation_id)||!v(e)||!f(e.background_mode)||!k(e.background_mode,e.device_consent)||e.desktop_account_access!==void 0&&(e.desktop_account_access===null||typeof e.desktop_account_access!=="object"||Array.isArray(e.desktop_account_access)||e.desktop_account_access.version!==T||e.desktop_account_access.scope!==L||!a(e.desktop_account_access.recorded_at)||!Number.isFinite(Date.parse(e.desktop_account_access.recorded_at))))return null;return e}function An(n=Ir()){if(!C(n))return null;try{return H(JSON.parse(b(n,"utf8")))}catch{return null}}export{Ir,Cn,Dr,An};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
2
|
+
var Kt=String.raw`(function(require) {
|
|
3
3
|
if (process.platform !== "win32") return null;
|
|
4
4
|
let ffi, kernel32;
|
|
5
5
|
try {
|
|
@@ -64,4 +64,4 @@ var e=String.raw`(function(require) {
|
|
|
64
64
|
},
|
|
65
65
|
};
|
|
66
66
|
})`;
|
|
67
|
-
export{
|
|
67
|
+
export{Kt};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{C}from"./vm-hands-entry-lite-t7an5zg2.js";import{g}from"./vm-hands-entry-lite-5p5h1eng.js";import{Ir,Cn,Dr,An}from"./vm-hands-entry-lite-gc7c22pq.js";import{Dn,Ft,ao}from"./vm-hands-entry-lite-wf7ksh4e.js";import{x}from"./vm-hands-entry-lite-zg3b0c08.js";import{spawnSync as v}from"child_process";import{createHash as ke,randomUUID as Se}from"crypto";import{chmodSync as we,existsSync as P,mkdirSync as $e,readdirSync as je,readFileSync as k,renameSync as ye,rmSync as u,statSync as ve,writeFileSync as We}from"fs";import{dirname as Ae,isAbsolute as Y,join as p}from"path";import{spawnSync as de}from"child_process";import{readFileSync as me}from"fs";import{userInfo as D}from"os";import{join as fe}from"path";var ge="REASON_SCHEDULED_TASK";function H(r){return fe(r,"AppData","Local","Reason","Tasks")}function w(r){if(/[\0-\x1f\x7f"%]/.test(r))throw Error(`A background task cannot use a value with a double quote, percent sign or control character: ${r}`);return`'${r.replace(/['\u2018\u2019\u201a\u201b]/g,"$&$&")}'`}function M(r){if(!/^[A-Za-z0-9._-]+$/.test(r))throw Error(`Invalid Windows Scheduled Task name: ${r}`);return`$env:${ge}=${w(r)};`}function U(r){let e=Object.entries(r.environment).map(([t,i])=>{if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(t))throw Error(`Invalid Windows Scheduled Task environment name: ${t}`);return`$env:${t}=${w(i)};`}),n=`$global:LASTEXITCODE=1; & ${[r.program,...r.args].map(w).join(" ")} 2>&1 | ForEach-Object { Add-Content -LiteralPath ${w(r.log)} -Value $_.ToString() -Encoding UTF8 }; $c=$LASTEXITCODE;`;return[M(r.name),...e,"$ErrorActionPreference='Continue';",r.keepAlive?`do { ${n} if ($c) { Start-Sleep -Seconds 10 } } while ($c)`:`${n} exit $c`].join(" ")}function I(r){return r.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}function pe(){let r=process.env.USERDOMAIN?.trim();return r?`${r}\\${D().username}`:D().username}function B(r){let e=I(r.user??pe()),n=r.schedule==="logon",t=r.schedule==="logon"?`<LogonTrigger><Enabled>true</Enabled><UserId>${e}</UserId></LogonTrigger>`:`<TimeTrigger><Repetition><Interval>PT${r.schedule.everyMinutes}M</Interval><StopAtDurationEnd>false</StopAtDurationEnd></Repetition><StartBoundary>2026-01-01T00:00:00</StartBoundary><Enabled>true</Enabled></TimeTrigger>`,i=`-NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -Command "${r.script}"`;return`<?xml version="1.0" encoding="UTF-16"?>
|
|
3
|
+
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
4
|
+
<RegistrationInfo>
|
|
5
|
+
<Description>${I(r.description)}</Description>
|
|
6
|
+
</RegistrationInfo>
|
|
7
|
+
<Triggers>
|
|
8
|
+
${t}
|
|
9
|
+
</Triggers>
|
|
10
|
+
<Principals>
|
|
11
|
+
<Principal id="Author">
|
|
12
|
+
<UserId>${e}</UserId>
|
|
13
|
+
<LogonType>InteractiveToken</LogonType>
|
|
14
|
+
<RunLevel>LeastPrivilege</RunLevel>
|
|
15
|
+
</Principal>
|
|
16
|
+
</Principals>
|
|
17
|
+
<Settings>
|
|
18
|
+
<MultipleInstancesPolicy>${n?"StopExisting":"IgnoreNew"}</MultipleInstancesPolicy>
|
|
19
|
+
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
|
|
20
|
+
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
|
|
21
|
+
<StartWhenAvailable>true</StartWhenAvailable>
|
|
22
|
+
<IdleSettings>
|
|
23
|
+
<StopOnIdleEnd>false</StopOnIdleEnd>
|
|
24
|
+
<RestartOnIdle>false</RestartOnIdle>
|
|
25
|
+
</IdleSettings>
|
|
26
|
+
<ExecutionTimeLimit>${n?"PT0S":"PT1H"}</ExecutionTimeLimit>
|
|
27
|
+
<Priority>${n?5:7}</Priority>
|
|
28
|
+
</Settings>
|
|
29
|
+
<Actions Context="Author">
|
|
30
|
+
<Exec>
|
|
31
|
+
<Command>%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe</Command>
|
|
32
|
+
<Arguments>${I(i)}</Arguments>
|
|
33
|
+
</Exec>
|
|
34
|
+
</Actions>
|
|
35
|
+
</Task>
|
|
36
|
+
`}function V(r){return Buffer.concat([Buffer.from([255,254]),Buffer.from(r.replaceAll(`\r
|
|
37
|
+
`,`
|
|
38
|
+
`).replaceAll(`
|
|
39
|
+
`,`\r
|
|
40
|
+
`),"utf16le")])}function j(r){let e=me(r);return(e[0]===255&&e[1]===254?e.subarray(2).toString("utf16le"):e.toString("utf8")).replaceAll(`\r
|
|
41
|
+
`,`
|
|
42
|
+
`)}function F(r,e){return["/Create","/TN",r,"/XML",e,"/F"]}function E(r){return["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-EncodedCommand",Buffer.from(r,"utf16le").toString("base64")]}function _(r){return`'*${M(r).replaceAll("'","''")}*'`}function T(r,e){return E(["$all = @(Get-CimInstance Win32_Process)",`$wrappers = @($all | ? { $_.ProcessId -ne $PID -and $_.CommandLine -like ${_(r)} })`,...e.keepWrapper?[]:["foreach ($w in $wrappers) { Stop-Process -Id $w.ProcessId -Force -ErrorAction SilentlyContinue }"],`foreach ($w in $wrappers) { $all | ? { $_.ParentProcessId -eq $w.ProcessId } | % { taskkill.exe /F ${e.tree?"/T ":""}/PID $_.ProcessId | Out-Null } }`].join(`
|
|
43
|
+
`))}function X(r){return E(["$all = @(Get-CimInstance Win32_Process)",`$wrappers = @($all | ? { $_.ProcessId -ne $PID -and $_.CommandLine -like ${_(r)} })`,"foreach ($w in $wrappers) { if ($all | ? { $_.ParentProcessId -eq $w.ProcessId -and $_.Name -ne 'conhost.exe' }) { 'running'; exit 0 } }","exit 1"].join(`
|
|
44
|
+
`))}function G(r,e=process.pid){let n=de(x("powershell.exe"),E(["$all = @{}; Get-CimInstance Win32_Process | % { $all[[int]$_.ProcessId] = $_ }",`$p = $all[${Math.trunc(e)}]`,"for ($i = 0; $p -and $i -lt 64; $i++) {",` if ($p.CommandLine -like ${_(r)}) { exit 10 }`," $n = $all[[int]$p.ParentProcessId]"," if (-not $n -or $n.ProcessId -eq $p.ProcessId -or $n.CreationDate -gt $p.CreationDate) { exit 11 }"," $p = $n","}","exit 11"].join(`
|
|
45
|
+
`)),{stdio:"ignore",timeout:15000,windowsHide:!0});return n.status===10?!0:n.status===11?!1:null}var Rr="REASON_WORKER_SERVICE",Ie="worker_identity_unavailable";function be(r){return{platform:process.platform,home:r,uid:process.getuid?.(),command:(e,n)=>v(x(e),[...n],{stdio:"ignore"}).status??1,read:(e,n)=>{let t=v(x(e),[...n],{stdio:["ignore","pipe","ignore"],encoding:"utf8",timeout:1e4});return t.status===0?t.stdout:null},sleep:(e)=>Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e),workerIdentity:(e)=>ao(r,e),insideService:(e,n)=>xe(e,process.platform,process.getuid?.(),n)}}function xe(r,e,n,t=!0){if(process.env[Rr]===r||process.env.XPC_SERVICE_NAME===r)return!0;if(e==="linux")try{return k("/proc/self/cgroup","utf8").includes(`/${r}.service`)}catch{return!0}if(e==="win32")return G(r)??t;if(e!=="darwin")return!1;if(typeof n!=="number")return!0;let i=v("/bin/launchctl",["print",`gui/${n}/${r}`],{encoding:"utf8",timeout:5000});if(i.status===Ee)return!1;if(i.error||i.status!==0)return!0;let s=Number(/^\s*pid = (\d+)$/m.exec(i.stdout??"")?.[1]??0);if(!s)return!1;let a=process.pid;for(let o=0;o<64&&a>1;o+=1){if(a===s)return!0;let l=v("/bin/ps",["-o","ppid=","-p",String(a)],{encoding:"utf8",timeout:5000}),c=Number(l.stdout?.trim());if(l.error||l.status!==0||!Number.isSafeInteger(c)||c<=0)return!0;if(c===a)return!1;a=c}return a>1}var Ee=113;class K extends Error{code;constructor(r,e){super(r);this.code=e}}function xn(r,e){if(!re(r.home,r.platform))throw new K(ee);if(r.platform==="darwin")S(r);let n=An(Ir(e,r.home)),t=g({env:e})==="staging",i=t?"ara-staging":"ara",s=[n?Cn(n):null,C(e,"REASON_CLI_LAUNCHER_PATH")?.trim(),r.platform==="win32"?p(r.home,"AppData","Local","Reason",...t?["staging"]:[],"bin",t?"reason-staging.exe":"reason.exe"):p(r.home,".local","bin",i)];for(let a of s)try{if(a&&Y(a)&&ve(a).isFile())return Dr(a)}catch{}throw new K(`A background service runs the installed Reason launcher, which was not found. Install Reason with: ${r.platform==="win32"?"irm https://reasonmachines.com/install.ps1 | iex":"curl -fsSL https://reasonmachines.com/install | sh"}`,"worker_launcher_missing")}var R=/(<key>ProgramArguments<\/key>\s*<array>\n)((?:\s*<string>[^<]*<\/string>\n)*)(\s*<\/array>)/,y=new RegExp(`(\\n\\s*<key>${Ft}</key>\\s*<string>)[^<]*(</string>)`),_e=/(<key>EnvironmentVariables<\/key>\s*<dict>[\s\S]*?)(\n\s*<\/dict>)/;function Te(r){return r.replaceAll("<","<").replaceAll(">",">").replaceAll(""",'"').replaceAll("'","'").replaceAll("&","&")}function J(r){let e=[...(R.exec(r)?.[2]??"").matchAll(/<string>([^<]*)<\/string>/g)].map((t)=>Te(t[1])),n=e[1]==="--run-worker"?e.slice(2):e;return n[0]?{launcher:n[0],args:n.slice(1)}:null}function z(r,e,n){let t=n.workerIdentity?.(r)??null;return{program:t?[t.executable,"--run-worker",r,...e]:[r,...e],identity:t}}function h(r){return r.map((e)=>` <string>${d(e)}</string>`).join(`
|
|
46
|
+
`)}function Z(r,e){let n;try{n=k(r,"utf8")}catch{return null}let t=J(n);if(!t)return null;let i=Y(t.launcher)?Dr(t.launcher):t.launcher,{program:s,identity:a}=z(i,t.args,e),o=n.replace(R,(l,c,m,O)=>`${c}${h(s)}
|
|
47
|
+
${O}`);if(!a)o=o.replace(y,"");else if(y.test(o))o=o.replace(y,(l,c,m)=>`${c}${d(a.app)}${m}`);else o=o.replace(_e,(l,c,m)=>`${c}
|
|
48
|
+
<key>${Ft}</key>
|
|
49
|
+
<string>${d(a.app)}</string>${m}`);return o===n?null:o}function Pe(r,e){let n=Z(r,e);if(n!==null)A(r,n)}function cs(r,e,n){if(e.platform!=="darwin")return!1;let t=He(r,e,n);return t!==null&&Z(t.definition,e)!==null}var W="com.reasonmachines.worker.",N="so.reason.worker.",Q=[W,N];function qi(r,e=W){return`${e}connect${r==="production"?"":`.${r}`}`}function ls(r,e){return Q.some((n)=>r===qi(e,n))}function Re(r,e,n){if(e==="connect")return qi(r.channel,n);let t=ke("sha256").update(r.workspaceRoot).digest("hex").slice(0,8);return`${n}${r.name.toLowerCase()}.${t}`}var ee="A background service needs macOS (launchd), Linux (systemd --user) or Windows (Task Scheduler).";function re(r,e){if(e==="darwin")return{directory:p(r,"Library","LaunchAgents"),suffix:".plist"};if(e==="linux")return{directory:p(r,".config","systemd","user"),suffix:".service"};if(e==="win32")return{directory:H(r),suffix:".xml"};return null}function f(r,e,n,t=W){let i=Re(r,n,t),s=re(e.home,e.platform);if(!s)return null;return{label:i,definition:p(s.directory,`${i}${s.suffix}`),logs:e.platform==="linux"?`journalctl --user -u ${i}.service`:p(r.stateDirectory,"service.log")}}function He(r,e,n="serve"){return ne(r,e,n)[0]??null}function ne(r,e,n){return Q.map((t)=>f(r,e,n,t)).filter((t)=>t!==null&&P(t.definition))}function te(r,e,n){let t=f(r,e,n,N);return t&&P(t.definition)?t:null}function To(r,e,n){let t=f(r,e,n),i=te(r,e,n);if(!t||!i||!P(t.definition)||e.insideService?.(i.label))return null;if(!Ce(t,e))return"current_not_running";if(e.platform==="darwin"){if(typeof e.uid==="number"&&e.uid>0)e.command("/bin/launchctl",["bootout",`gui/${e.uid}/${i.label}`]);return u(i.definition,{force:!0}),"retired"}if(e.platform==="win32")return b(i,e,!0),"retired";return e.command("systemctl",["--user","disable","--now",`${i.label}.service`]),u(i.definition,{force:!0}),e.command("systemctl",["--user","daemon-reload"]),"retired"}function Ce(r,e){if(e.platform==="darwin")return typeof e.uid==="number"&&e.uid>0&&e.command("/bin/launchctl",["print",`gui/${e.uid}/${r.label}`])===0;if(e.platform==="win32")return e.command("schtasks",["/Query","/TN",r.label])===0;let n=`${r.label}.service`;return e.command("systemctl",["--user","is-enabled","--quiet",n])===0&&he.has(e.read("systemctl",["--user","show","--property=ActiveState","--value",n])?.trim()??"")}var he=new Set(["active","activating","reloading"]);function kn(r,e){if(e.platform==="darwin"){if(typeof e.uid!=="number"||e.uid<=0)return!1;let n=e.read("/bin/launchctl",["print",`gui/${e.uid}/${r.label}`]);return Number(/^\s*pid = (\d+)$/m.exec(n??"")?.[1]??0)>0}if(e.platform==="win32")return e.read("powershell.exe",X(r.label))?.trim()==="running";return Number(e.read("systemctl",["--user","show","--property=MainPID","--value",`${r.label}.service`])?.trim()??0)>0}function us(r){let{config:e,launcher:n,host:t,kind:i}=r,s=f(e,t,i);if(!s)return!1;let a;try{a=t.platform==="win32"?j(s.definition):k(s.definition,"utf8")}catch{return!1}if(t.platform==="win32")return a===se(e,i,s,n);if(t.platform!=="darwin")return a===oe(e,i,s,n,t.home,r.path);let o=J(a);return a.replace(y,"").replace(R,(c,m,O,ue)=>`${m}${o?`${h([o.launcher,...o.args])}
|
|
50
|
+
`:""}${ue}`)===ie(e,i,s,n,{...t,workerIdentity:()=>null},r.path).plist}function L(r,e){if(e==="connect")return{args:["connect"],environment:{REASON_CLI_CHANNEL:r.channel},description:"Reason connection of this computer"};return{args:["serve",r.name,"--dir",r.workspaceRoot,...r.executionMode==="confined"?["--sandbox"]:[]],environment:{},description:`Reason machine ${r.name} worker`}}function d(r){return r.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}function q(r,e=!1){if(/[\0-\x1f\x7f]/.test(r))throw new K("A background service cannot use a path with control characters.");let n=r.replaceAll("\\","\\\\").replaceAll('"',"\\\"").replaceAll("%","%%");return`"${e?n.replaceAll("$","$$$$"):n}"`}function ie(r,e,n,t,i,s){let a=L(r,e),o=z(t,a.args,i),l={HOME:i.home,PATH:s,[Rr]:n.label,...a.environment,...o.identity?{[Ft]:o.identity.app}:{}};return{identity:o.identity,plist:`<?xml version="1.0" encoding="UTF-8"?>
|
|
51
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
52
|
+
<plist version="1.0">
|
|
53
|
+
<dict>
|
|
54
|
+
<key>Label</key>
|
|
55
|
+
<string>${d(n.label)}</string>
|
|
56
|
+
<key>AssociatedBundleIdentifiers</key>
|
|
57
|
+
<array>
|
|
58
|
+
<string>${Dn}</string>
|
|
59
|
+
</array>
|
|
60
|
+
<key>ProgramArguments</key>
|
|
61
|
+
<array>
|
|
62
|
+
${h(o.program)}
|
|
63
|
+
</array>
|
|
64
|
+
<key>EnvironmentVariables</key>
|
|
65
|
+
<dict>
|
|
66
|
+
${Object.entries(l).map(([c,m])=>` <key>${c}</key>
|
|
67
|
+
<string>${d(m)}</string>`).join(`
|
|
68
|
+
`)}
|
|
69
|
+
</dict>
|
|
70
|
+
<key>RunAtLoad</key>
|
|
71
|
+
<true/>
|
|
72
|
+
<key>KeepAlive</key>
|
|
73
|
+
<dict>
|
|
74
|
+
<key>SuccessfulExit</key>
|
|
75
|
+
<false/>
|
|
76
|
+
</dict>
|
|
77
|
+
<key>ThrottleInterval</key>
|
|
78
|
+
<integer>10</integer>
|
|
79
|
+
<key>ExitTimeOut</key>
|
|
80
|
+
<integer>${Math.ceil(r.shutdownGraceMs/1000)+10}</integer>
|
|
81
|
+
<key>ProcessType</key>
|
|
82
|
+
<string>Standard</string>
|
|
83
|
+
<key>Umask</key>
|
|
84
|
+
<integer>63</integer>
|
|
85
|
+
<key>StandardOutPath</key>
|
|
86
|
+
<string>${d(n.logs)}</string>
|
|
87
|
+
<key>StandardErrorPath</key>
|
|
88
|
+
<string>${d(n.logs)}</string>
|
|
89
|
+
</dict>
|
|
90
|
+
</plist>
|
|
91
|
+
`}}function oe(r,e,n,t,i,s){let a=L(r,e);return`[Unit]
|
|
92
|
+
Description=${a.description}
|
|
93
|
+
|
|
94
|
+
[Service]
|
|
95
|
+
ExecStart=${[t,...a.args].map((o)=>q(o,!0)).join(" ")}
|
|
96
|
+
Environment=${[`HOME=${i}`,`PATH=${s}`,`${Rr}=${n.label}`,...Object.entries(a.environment).map(([o,l])=>`${o}=${l}`)].map((o)=>q(o)).join(" ")}
|
|
97
|
+
Restart=on-failure
|
|
98
|
+
RestartSec=10
|
|
99
|
+
TimeoutStopSec=${Math.ceil(r.shutdownGraceMs/1000)+10}
|
|
100
|
+
UMask=0077
|
|
101
|
+
|
|
102
|
+
[Install]
|
|
103
|
+
WantedBy=default.target
|
|
104
|
+
`}function se(r,e,n,t){let i=L(r,e);return B({description:i.description,schedule:"logon",script:U({name:n.label,program:t,args:i.args,environment:{[Rr]:n.label,...i.environment},log:n.logs,keepAlive:!0})})}function ae(r,e,n){e.command("powershell.exe",T(r.label,{tree:n,keepWrapper:!n}))}function b(r,e,n){e.command("schtasks",["/Delete","/F","/TN",r.label]),e.command("powershell.exe",T(r.label,{tree:n,keepWrapper:!1})),u(r.definition,{force:!0})}function A(r,e){$e(Ae(r),{recursive:!0,mode:448});let n=`${r}.${Se()}.tmp`;try{We(n,e,{mode:384,flag:"wx"}),we(n,384),ye(n,r)}finally{u(n,{force:!0})}}function S(r){if(typeof r.uid!=="number"||!Number.isSafeInteger(r.uid)||r.uid<=0)throw new K("Set up a background service as your own user, not with sudo.","worker_service_root_user");return`gui/${r.uid}`}function ds(r){let{config:e,launcher:n,host:t}=r,i=r.kind??"serve",s=te(e,t,i),a=s!==null&&t.insideService?.(s.label)===!0,o=f(e,t,i,a?N:W);if(!o)throw new K(ee);if(t.platform==="darwin")S(t);if(t.platform==="linux"&&t.command("systemctl",["--user","show-environment"])!==0)throw new K("No background service here: this computer has no systemd user session.","worker_service_manager_missing");let l=t.platform==="darwin"?ie(e,i,o,n,t,r.path):null;if(A(o.definition,l?l.plist:t.platform==="win32"?V(se(e,i,o,n)):oe(e,i,o,n,t.home,r.path)),le(e,t,o,a?null:s),l)return l.identity?o:{...o,identityProblem:Ie};if(t.platform==="win32")return o;return{...o,lingering:t.command("loginctl",["enable-linger"])===0}}function le(r,e,n,t){if(e.platform==="darwin"){let a=S(e);if(t)e.command("/bin/launchctl",["bootout",`${a}/${t.label}`]);if(ce(r,n,e)){if(t)u(t.definition,{force:!0});return}if(u(n.definition,{force:!0}),t)e.command("/bin/launchctl",["bootstrap",a,t.definition]);throw new K("Could not start the background service (launchctl bootstrap failed).","worker_service_start_failed")}if(e.platform==="win32"){if(t)b(t,e,!0);if(e.command("schtasks",F(n.label,n.definition))===0){if(ae(n,e,e.insideService?.(n.label)!==!0),e.command("schtasks",["/Run","/TN",n.label])===0)return}throw b(n,e,!0),new K("Could not start the background service (schtasks failed).")}let i=`${n.label}.service`,s=t?`${t.label}.service`:null;if(e.command("systemctl",["--user","daemon-reload"])!==0||s!==null&&e.command("systemctl",["--user","disable","--now",s])!==0||e.command("systemctl",["--user","enable",i])!==0||e.command("systemctl",["--user","restart",i])!==0){if(e.command("systemctl",["--user","disable",i]),u(n.definition,{force:!0}),e.command("systemctl",["--user","daemon-reload"]),s)e.command("systemctl",["--user","enable","--now",s]);throw new K("Could not start the background service (systemctl --user failed).","worker_service_start_failed")}if(t)u(t.definition,{force:!0}),e.command("systemctl",["--user","daemon-reload"])}function ce(r,e,n){let t=S(n);n.command("/bin/launchctl",["bootout",`${t}/${e.label}`]);let i=(Math.ceil(r.shutdownGraceMs/1000)+10)*1000;for(let s=0,a=100;;a=Math.min(a*2,2000)){if(n.command("/bin/launchctl",["bootstrap",t,e.definition])===0)return!0;if(s>=i)return!1;n.sleep(a),s+=a}}function Or(r,e,n){let t=He(r,e,n);if(!t)return null;let i=e.insideService?.(t.label)===!0;if(e.platform==="darwin"&&!i)Pe(t.definition,e);let s=f(r,e,n);if(s&&t.label!==s.label&&!i)return A(s.definition,k(t.definition,"utf8").replaceAll(t.label,s.label)),le(r,e,s,t),s;let a=e.platform==="darwin"&&i,o;if(e.platform==="win32")ae(t,e,!i),o=e.command("schtasks",["/Run","/TN",t.label])===0;else if(a)o=e.command("/bin/launchctl",["kickstart","-k",`${S(e)}/${t.label}`])===0;else if(e.platform==="darwin")o=ce(r,t,e);else e.command("systemctl",["--user","enable",`${t.label}.service`]),o=e.command("systemctl",["--user","restart",`${t.label}.service`])===0;if(!o)throw new K(`Could not restart the background service ${t.label}.`,"worker_service_restart_failed");if(s&&t.label===s.label)To(r,e,n);return t}function ps(r,e,n,t){let i=He(r,n,t),s=f(e,n,t);if(n.platform!=="darwin"||!i||!s)return;let a=`<string>${d(i.logs)}</string>`,o=k(i.definition,"utf8");if(o.includes(a))A(i.definition,o.replaceAll(a,`<string>${d(s.logs)}</string>`))}function hs(r,e,n="serve"){let t=ne(r,e,n);for(let i of t){if(e.platform==="win32"){b(i,e,e.insideService?.(i.label,!1)!==!0);continue}if(e.platform==="darwin"){if(typeof e.uid==="number"&&e.uid>0)e.command("/bin/launchctl",["bootout",`gui/${e.uid}/${i.label}`]);u(i.definition,{force:!0});continue}e.command("systemctl",["--user","disable","--now",`${i.label}.service`]),u(i.definition,{force:!0}),e.command("systemctl",["--user","daemon-reload"])}return t[0]??null}
|
|
105
|
+
export{Rr,be,K,xn,cs,qi,ls,He,To,kn,us,ds,Or,ps,hs};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Me,$i,F,Ye,xt,gr,P,V,$e}from"./vm-hands-entry-lite-e5hbehqn.js";import{G}from"./vm-hands-entry-lite-v3xznxcw.js";import{ot}from"./vm-hands-entry-lite-8evzzh7v.js";import{st}from"./vm-hands-entry-lite-wf7ksh4e.js";import{Mr}from"./vm-hands-entry-lite-762fbns7.js";import{ft,mi}from"./vm-hands-entry-lite-8gtgr399.js";import{be,xn}from"./vm-hands-entry-lite-hee1h411.js";import{dt}from"./vm-hands-entry-lite-ym1djztp.js";import{a}from"./vm-hands-entry-lite-dkcm3hyn.js";import{x}from"./vm-hands-entry-lite-zg3b0c08.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{spawn as R,spawnSync as tt}from"child_process";import{createHash as rt,randomUUID as me}from"crypto";import{closeSync as nt,copyFileSync as se,existsSync as M,fstatSync as it,mkdirSync as ie,openSync as at,readdirSync as U,readFileSync as K,readlinkSync as ct,renameSync as fe,rmSync as lt,statSync as ut,writeFileSync as pt}from"fs";import{connect as mt}from"net";import{tmpdir as L,userInfo as ge}from"os";import{basename as ae,delimiter as gt,dirname as B,join as f}from"path";var Y=`import { spawn, execFileSync } from "node:child_process";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { readFileSync, readlinkSync, lstatSync, realpathSync, statSync, mkdtempSync, mkdirSync, chmodSync, writeFileSync, readdirSync, rmSync, openSync, readSync, closeSync, renameSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
@@ -849,11 +849,7 @@ if(process.env.REASON_CLOUD_GATEWAY_EXEC === "1") {
|
|
|
849
849
|
process.stdout.write(JSON.stringify(cloudAutomationFailure(error))+"\\n");process.exitCode=1;
|
|
850
850
|
}
|
|
851
851
|
}
|
|
852
|
-
`;import{spawn as
|
|
853
|
-
`).at(-1)?.slice(-300)??"";if(!
|
|
854
|
-
`);if(R)return c(R);c(new p("desktop_delegate_failed",`Reason's desktop operation failed (${X}${V?`: ${V}`:""}).`))})),t.aborted)y();a.stdin.end(JSON.stringify(r))})}async function H(e,r,t,i={}){let o=await Ze(e,{op:"automation",call:r},t,i);if(!Number.isSafeInteger(o.code)||typeof o.stdout!=="string"||typeof o.stderr!=="string")throw new p("desktop_delegate_failed","Reason's desktop reply is malformed.");return{code:o.code,stdout:Buffer.from(o.stdout,"base64"),stderr:o.stderr}}import{execFile as He,spawn as Qe}from"child_process";import{closeSync as et,mkdirSync as tt,openSync as rt}from"fs";import{dirname as A,join as it}from"path";import{promisify as ot}from"util";var st=ot(He),Q="x-apple.systempreferences:com.apple.preference.security",at={accessibility:`${Q}?Privacy_Accessibility`,screen:`${Q}?Privacy_ScreenCapture`},nt=64,$=new Map;function k(e,r){let t=$.get(e);if(t?.has(r))return!1;if(!t){if($.size>=nt)$.delete($.keys().next().value);t=new Set,$.set(e,t)}return t.add(r),!0}function ct(){let e=x(),r=ne(ae(e),process.env),t=it(e,".local","share","reason","desktop-install.log");tt(A(t),{recursive:!0,mode:448});let i=rt(t,"a",384);try{let o=Qe(r,["desktop","install"],{detached:!0,stdio:["ignore",i,i],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});o.on("error",()=>{return}),o.unref()}finally{et(i)}}var P={open:async(e,r)=>{await st("/usr/bin/open",e,{signal:r,timeout:1e4,maxBuffer:8192})},request:(e,r)=>oe(e,r),tile:se,installDesktop:ct},ee=!1;async function te(e,r,t){try{await r.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await r.open([e],t)}}async function ce(e,r,t,i){if(await t.open([at[r]],i).catch(()=>{}),e[0]&&!i.aborted)t.tile(A(A(A(e[0]))),r)}async function lt(e,r,t,i,o){for(let s of t){if(!k(e,`grant:${s}`))continue;o.throwIfAborted(),await i.request(r,s).catch(()=>null),await ce(r,s,i,o)}}var ut={name:"open_tab",description:"Open a web page in the user's own Chrome on this Mac. Reason cannot read, screenshot or click in that tab, and no tab_id is returned: browser control needs Reason's Chrome extension. An actual browser call opens its setup page.",inputSchema:{type:"object",properties:{url:{type:"string",description:"An http or https URL."}},required:["url"],additionalProperties:!1}};function re(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function dt(e){if(typeof e!=="string")return null;try{let r=new URL(e);return r.protocol==="https:"||r.protocol==="http:"?r.href:null}catch{return null}}async function le(e,r=P){let{call:t,runId:i,signal:o}=e;if(t.kind==="browser"){if(t.operation==="discover")return re({result:{tools:[ut]}});if(t.operation!=="call")throw new p("automation_browser_setup_required","Browser control is not set up on this Mac yet. Request a browser operation or connect Chrome from Reason to set it up.")}if(e.desktopMissing&&!ee){ee=!0;try{r.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&k(i,"grant:probe")){let a=await r.request(e.identity).catch(()=>null),l=a?[...a.accessibility?[]:["accessibility"],...a.screen?[]:["screen"]]:[];for(let d of l)k(i,`grant:${d}`);for(let d of l)await ce(e.identity,d,r,o)}throw new p("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(k(i,"page:chrome-extension"))await te(ie,r,o).catch(()=>{});let s=t.arguments,c=t.operation==="call"&&t.tool==="open_tab"&&s&&typeof s==="object"&&!Array.isArray(s)?dt(s.url):null;if(!c)throw new p("automation_browser_setup_required","Browser control is not set up on this Mac yet; Reason opened its Chrome Web Store page. open_tab still opens pages.");return await te(c,r,o),re({result:{content:[{type:"text",text:JSON.stringify({opened:c,browser:"the user's Chrome",controllable:!1,note:"Opened for the user to see. Reason cannot read or act in this tab until Reason's Chrome extension is added (its Chrome Web Store page is open)."})}]}})}async function ue(e,r=P){if(e.call.kind!=="computer"||e.call.operation!=="permission_status"||e.output.code!==0||e.identity.length===0)return e.output;let t;try{t=JSON.parse(e.output.stdout.toString("utf8"))}catch{return e.output}if(!t||typeof t!=="object"||Array.isArray(t))return e.output;let i=t.permissions;if(!i||typeof i!=="object")return e.output;let o=i,s=[...o.accessibility==="missing"?["accessibility"]:[],...o.screenRecording==="missing"?["screen"]:[]];if(s.length===0)return e.output;return await lt(e.runId,e.identity,s,r,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:s}))}}var K=172032,It=18874368,Nt=8192,Ot=65536,Tt=55000,vt=60000,Rt=4,$t=40000,At=/^[0-9a-f-]{36}$/,me=Z,kt=Te();function W(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function E(){throw new p("invalid_automation_request","Reason automation request is malformed.")}function $e(e){let r=Object.keys(e).sort().join(",");if(r==="call"||r==="browser,call"){let t=e.call,i=r==="browser,call";if(!W(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||i&&(e.browser!==be||t.kind!=="browser")||JSON.stringify(t).length>Ot)E();return{call:t,userChrome:i}}if(r==="offset,output_id"){if(typeof e.output_id!=="string"||!At.test(e.output_id)||!Number.isSafeInteger(e.offset)||e.offset<0)E();return{output_id:e.output_id,offset:e.offset}}return E()}function Wr(e=process.platform,r=v){if(e==="darwin")return!0;return(e==="linux"||e==="win32")&&r()?.features.computer===!0}var Pt="__computer-use";function Ct(e){let r=(t)=>t?"granted":"missing";return`Permissions: accessibility=${r(e.accessibility)}, screenRecording=${r(e.screen)}
|
|
855
|
-
|
|
856
|
-
`),1;if(e.length===1&&e[0]==="doctor"){let a=await(r.grants??Ne)(i);if(!a)return t.write(`Reason computer use: Reason's permissions could not be read (computer_use_permission_status_unavailable)
|
|
857
|
-
`),1;return(r.stdout??process.stdout).write(Ct(a)),0}if(e.length!==1||e[0]!=="mcp")return t.write(`Usage: reason __computer-use mcp|doctor
|
|
858
|
-
`),2;let[s,...c]=i;return(r.run??Wt)(s,[...c,o.ocu,"mcp"],{...process.env,OPEN_COMPUTER_USE_DISABLE_APP_AGENT_PROXY:"1"})}function qr(e=v){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function Ae(e,r,t,i){return new Promise((o)=>{let s=S(e,r,{env:t,stdio:"ignore",windowsHide:!0}),c=setTimeout(()=>{s.kill("SIGKILL"),o(-1)},i);s.once("error",()=>{clearTimeout(c),o(-1)}),s.once("exit",(a)=>{clearTimeout(c),o(a??-1)})})}function Et(e,r,t,i){return new Promise((o)=>{let s=S(e,r,{env:t,stdio:["ignore","pipe","ignore"],windowsHide:!0}),c="";s.stdout.setEncoding("utf8").on("data",(l)=>{c+=l});let a=setTimeout(()=>{s.kill("SIGKILL"),o(null)},i);s.once("error",()=>{clearTimeout(a),o(null)}),s.once("close",(l)=>{clearTimeout(a),o(l===0?c:null)})})}function qt(e){return T(e)?f(F(),"open-browser-use"):"/tmp/open-browser-use"}function T(e){return e.platform==="win32-x64"||e.platform==="win32-arm64"}var Dt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Ft=33554432;function Bt(e,r){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let i=W(t)&&W(t.result)?t.result.metadata:null;if(!W(i)||i.extensionId!==r)return null;return typeof i.extensionInstanceId==="string"&&Dt.test(i.extensionInstanceId)?i.extensionInstanceId:null}async function ke(e,r,t){let i=t.storages.map((a)=>{try{return D(a).filter((l)=>l.endsWith(".log")||l.endsWith(".ldb")).map((l)=>f(a,l))}catch{return[]}}),o;try{o=i.some((a)=>a.length>0)?D(t.socketDir).filter((a)=>a.endsWith(".sock")):[]}catch{return[]}let s=[];for(let a of o){let l=f(t.socketDir,a),d=Bt(await Et(e,["info","--socket",l,"--timeout","2s"],r,5000),t.extensionId);if(d)s.push({instance:d,socket:l})}let c=[];for(let[a,l]of(s.length>0?i:[]).entries())for(let d of l)try{if(bt(d).size>Ft)continue;let n=j(d),u=s.find((m)=>n.includes(m.instance));if(u){c.push({storage:t.storages[a],...u});break}}catch{}return c}async function Ut(e,r,t){return(await ke(e,r,t))[0]?.instance??null}function Pe(e,r,t){return Ut(e.nativeHost,r,{socketDir:qt(e),extensionId:M,storages:[f(t,"browser-profile","Default","Local Extension Settings",M)]})}var _e=/^(Default|Profile ([0-9]+))$/;async function Lt(e,r,t=x(),i=Y){let o=f(t,"Library","Application Support","Google","Chrome"),s=[];try{s=D(o)}catch(n){if(n.code==="EPERM")throw new p("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let c=(n)=>Number(_e.exec(n)?.[2]??-1),a=s.filter((n)=>_e.test(n)&&q(f(o,n,"Extensions",C))).sort((n,u)=>c(n)-c(u)),l=(n)=>f(o,n,"Local Extension Settings",C);return(await ke(e,r,{socketDir:i,extensionId:C,storages:a.map(l)})).map(({storage:n,instance:u,socket:m})=>({profile:a.find((_)=>l(_)===n),instance:u,socket:m}))}async function Gt(e,r,t=x(),i=Y){let o=(await Lt(e,r,t,i))[0]?.instance;if(!o)throw new p("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return o}function he(e){return new Promise((r)=>{let t=St({path:e}),i=(o)=>{t.destroy(),r(o)};t.setTimeout(1000,()=>i(!1)),t.once("error",()=>i(!1)),t.once("connect",()=>i(!0))})}async function Ce(e,r){let t=Date.now()+r;while(Date.now()<t){if(await e())return!0;await new Promise((i)=>setTimeout(i,200))}return!1}var L=new Map;function G(e,r){let t=L.get(e);if(!t)t=r().finally(()=>L.delete(e)),L.set(e,t);return t}async function Mt(e,r){if(await he(e))return;if(gt(e,{force:!0}),await Ae("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],r,1e4)!==0||!await Ce(()=>he(e),5000))throw new p("automation_unavailable","Reason could not start the desktop session bus.")}async function we(e,r,t){let i=e.platform==="darwin-arm64"||T(e)?async()=>await Pe(e,r,t)!==null:async()=>await Ae(e.nativeHost,["info"],r,5000)===0;if(await i())return;let o=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],s,c=null,a=0;if(e.platform==="darwin-arm64"){let n=f(t,"browser-profile");O(n);let u=f(n,"NativeMessagingHosts");pe(u,{recursive:!0,mode:448});let m=z(e.platform).nativeHostManifests[0];de(m,f(u,fe(m)));let _=e.browser.slice(0,e.browser.indexOf(".app/")+4),g=o.filter((N)=>N!=="about:blank").concat("--no-startup-window","--use-mock-keychain");s=S("/usr/bin/open",["-g","-n","-a",_,"--args",`--user-data-dir=${n}`,...g],{env:r,stdio:"ignore"})}else if(T(e)){let n=f(t,"browser-profile");O(n),pt(xe("icacls"),[B(e.browser),"/grant","*S-1-15-2-1:(OI)(CI)(RX)","*S-1-15-2-2:(OI)(CI)(RX)"],{stdio:"ignore",windowsHide:!0,timeout:60000});let u=o.filter((m)=>m!=="about:blank").concat("--no-startup-window","--keep-alive-for-test");s=S(e.browser,[`--user-data-dir=${n}`,...u],{detached:!0,stdio:"ignore",env:r})}else{let n=f(r.HOME,".config","google-chrome"),u=f(n,"NativeMessagingHosts");pe(u,{recursive:!0,mode:448});let m=z(e.platform).nativeHostManifests[0];de(m,f(u,fe(m)));let _=process.geteuid?.()===0?["--no-sandbox"]:[];c=f(t,"browser.log");let g=ht(c,"a",384);a=_t(g).size,s=S(e.browser,[`--user-data-dir=${n}`,...o,..._,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",g,g],env:{...r,ACCESSIBILITY_ENABLED:"1"}}),mt(g)}let l=!1;s.once("error",()=>{l=!0}),s.once("exit",(n)=>{l||=n!==0}),s.unref();let d=!1;if(await Ce(async()=>l||(d=await i()),$t),!d){if(c&&j(c).subarray(a).toString("utf8").includes("No usable sandbox"))throw new p("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");throw new p("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function Dr(e){await qe(e,!0)}function Fr(e){return We(e,Ee(e))}function We(e,r){return e.platform==="darwin-arm64"||T(e)?f(r,"browser-profile"):f(r,"home",".config","google-chrome")}function Ee(e){let r=f(e.root,"automation");if(!q(r)||!Kt(e.automation))return e.automation;if(!zt(We(e,r)))try{ve(r,e.automation)}catch{}return q(r)?r:e.automation}function Kt(e){try{return D(e).length===0}catch(r){return r.code==="ENOENT"}}function zt(e){let r;try{r=wt(f(e,"SingletonLock"))}catch{return!1}let t=Number(r.slice(r.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(i){return i.code==="EPERM"}}async function qe(e,r){ye({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=Ee(e);O(t);let i=Re().username,o={USER:i,LOGNAME:i,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"||T(e)){let n=T(e)?{...o,...Jt(),HOME:x()}:{...o,HOME:x(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:Pt};if(!r)return n;await G("browser",()=>we(e,n,t));let u=await Pe(e,n,t);if(!u)throw new p("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...n,REASON_AUTOMATION_OBU_INSTANCE:u,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let s=await Be(),c=f(t,"home"),a=f(t,"runtime");O(c),O(a);let l=f(t,"bus"),d={...o,HOME:c,PATH:`${B(e.node)}:/usr/bin:/bin`,DISPLAY:s.display,XAUTHORITY:s.xauthority,XDG_RUNTIME_DIR:a,DBUS_SESSION_BUS_ADDRESS:`unix:path=${l}`,...s.sound?{PULSE_SERVER:Oe(s.sound)}:{}};if(await G("bus",()=>Mt(l,d)),r)await G("browser",()=>we(e,d,t));return d}function Jt(){let e=process.env.SystemRoot??"C:\\Windows",r=Object.fromEntries(["SystemDrive","USERPROFILE","LOCALAPPDATA","APPDATA","ProgramData","ProgramFiles","PATHEXT","ComSpec","USERNAME","USERDOMAIN","COMPUTERNAME","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","PSModuleAnalysisCachePath"].flatMap((i)=>process.env[i]?[[i,process.env[i]]]:[])),t=f(e,"System32");return{...r,SystemRoot:e,windir:e,TEMP:F(),TMP:F(),PATH:[t,f(t,"WindowsPowerShell","v1.0"),e].join(yt)}}async function jt(e,r,t){let i=Re().username,o={USER:i,LOGNAME:i,HOME:x(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:r,REASON_AUTOMATION_BACKGROUND_TABS:"1"},s=await Gt(r,o);return t.throwIfAborted(),{...o,REASON_AUTOMATION_OBU_INSTANCE:s}}function Yt(e){if(process.platform!=="win32")return["--input-type=module","--eval",e];let r=f(F(),`reason-automation-${ft("sha256").update(e).digest("hex").slice(0,16)}.mjs`);if(!q(r)||j(r,"utf8")!==e){let t=`${r}.${process.pid}.tmp`;xt(t,e,{mode:384}),ve(t,r)}return[r]}function De(e,r,t,i){if(typeof me!=="string")return Promise.reject(new p("automation_unavailable","This Reason build has no automation runtime."));let o=me;return new Promise((s,c)=>{let a=S(e,Yt(o),{env:{...r,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32",windowsHide:!0}),l=[],d=0,n="",u=null,m=!1,_=(h)=>{if(u??=h,process.platform==="win32"&&a.pid){S(f(process.env.SystemRoot??"C:\\Windows","System32","taskkill.exe"),["/pid",String(a.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0}).once("error",()=>a.kill("SIGKILL"));return}try{process.kill(-a.pid,"SIGKILL")}catch{a.kill("SIGKILL")}},g=(h)=>{if(m)return;m=!0,clearTimeout(N),i.removeEventListener("abort",y),h()},N=setTimeout(()=>_(new p("automation_timed_out","Reason automation did not finish in time.")),Tt),y=()=>_(new p("cancelled","Reason cancelled the automation call."));if(i.addEventListener("abort",y,{once:!0}),a.stdout.on("data",(h)=>{if(d+=h.byteLength,d>It)_(new p("automation_output_too_large","Reason automation output is too large."));else l.push(h)}),a.stderr.setEncoding("utf8").on("data",(h)=>{n=(n+h).slice(-Nt)}),a.stdin.on("error",()=>{}),a.once("error",()=>g(()=>c(u??new p("automation_unavailable","Reason could not start the automation runtime.")))),a.once("close",(h)=>g(()=>{if(u)c(u);else s({code:h??1,stdout:Buffer.concat(l),stderr:n})})),i.aborted)y();a.stdin.end(t)})}var I=new Map;function Xt(e,r,t){for(let[o,s]of I)if(s.expiresAt<=t)I.delete(o);while(I.size>=Rt)I.delete(I.keys().next().value);let i=Te();return I.set(i,{runId:e,bytes:r,expiresAt:t+vt}),i}async function Fe(e,r,t,i={}){let o=await(i.environment??qe)(e,r.kind==="browser");return t.throwIfAborted(),await(i.runtime??De)(e.node,o,JSON.stringify(r),t)}async function Br(e,r){let t=$e({call:e});if(!("call"in t))E();let i=v();if(!i?.features.computer||t.call.kind==="browser"&&!i.features.browser)throw new p("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await Fe(i,t.call,r)}function ge(e,r,t){let i=e.stdout.byteLength>K?Xt(r,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:kt,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,K).toString("base64"),...i?{output_id:i}:{}}}async function Ur(e,r={}){let t=$e(e.payload),i=(r.now??Date.now)();if("output_id"in t){let _=I.get(t.output_id);if(!_||_.runId!==e.runId||_.expiresAt<=i||t.offset>_.bytes.byteLength)throw new p("automation_output_unavailable","Reason automation output expired.");return{chunk:_.bytes.subarray(t.offset,t.offset+K).toString("base64")}}let o=(r.components??v)(),s=(r.platform??process.platform)==="darwin",c=s?(r.macIdentity??J)():[],a=r.macSetup??P,l=!o?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!o.features.browser;if(s&&(l||c.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return ge(await le({runId:e.runId,call:t.call,identity:c,desktopMissing:l,signal:e.signal},a),e.runId,i);if(!o?.features.computer)throw new p("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let d=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!d)throw new p("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!d&&!o.features.browser)throw new p("automation_browser_not_installed",!o.platform.startsWith("linux")?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let n=await Ie(e.runId,e.signal,r.now),u="account"in r?r.account??null:Se(),m;try{if(d){let _=await(r.userChromeEnvironment??jt)(o,d,e.signal);e.signal.throwIfAborted(),m=await(r.runtime??De)(o.node,_,JSON.stringify(t.call),e.signal)}else if(u)m=await(r.delegate??H)(u,t.call,e.signal);else m=await Fe(o,t.call,e.signal,r)}finally{n()}if(s)m=await ue({runId:e.runId,call:t.call,identity:c,output:m,signal:e.signal},a);return ge(m,e.runId,i)}
|
|
859
|
-
export{Ze as Ed,K as Fd,$e as Gd,Wr as Hd,Wt as Id,Er as Jd,qr as Kd,Lt as Ld,Gt as Md,Dr as Nd,Fr as Od,Br as Pd,Ur as Qd};
|
|
852
|
+
`;import{spawn as Ee}from"child_process";import{basename as Ce}from"path";var Te="__desktop-call",Ne="/usr/bin/setpriv",Pe=27262976,De=8192,Ue=2000;function q(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function Le(e){try{return JSON.parse(e)}catch{return null}}function Be(){return[process.execPath,...Ce(process.execPath).startsWith("bun")&&process.argv[1]?[process.argv[1]]:[],Te]}function Et(e,o,t,n={}){t.throwIfAborted();let s=n.command??Be();return new Promise((i,u)=>{let c=(n.spawnProcess??Ee)(Ne,[`--reuid=${e.uid}`,`--regid=${e.gid}`,"--clear-groups","--no-new-privs","--",...s],{cwd:e.home,detached:!0,stdio:["pipe","pipe","pipe"],env:{HOME:e.home,USER:e.username,LOGNAME:e.username,PATH:"/usr/local/bin:/usr/bin:/bin"}}),d=[],m=0,l="",p=null,g=!1,h,y=(_)=>{try{process.kill(-c.pid,_)}catch{c.kill(_)}},I=(_)=>{p??=_,y("SIGTERM"),h??=setTimeout(()=>y("SIGKILL"),Ue)},S=()=>I(new r("cancelled","Reason cancelled the desktop operation."));t.addEventListener("abort",S,{once:!0});let w=(_)=>{if(g)return;g=!0,clearTimeout(h),t.removeEventListener("abort",S),_()};if(c.stdout.on("data",(_)=>{if(m+=_.byteLength,m>Pe)I(new r("desktop_delegate_failed","Reason's desktop reply is too large."));else d.push(_)}),c.stderr.setEncoding("utf8").on("data",(_)=>{l=(l+_).slice(-De)}),c.stdin.on("error",()=>{}),c.once("error",()=>w(()=>u(p??new r("desktop_delegate_unavailable","Reason could not start its desktop as the desktop account.")))),c.once("close",(_,Oe)=>w(()=>{if(p)return u(p);let b=Le(Buffer.concat(d).toString("utf8"));if(q(b)&&b.ok===!0&&q(b.result))return i(b.result);let O=q(b)&&b.ok===!1&&typeof b.code==="string"&&typeof b.message==="string"?new r(b.code.slice(0,120),b.message.slice(0,2000)):null,X=`exited ${_??Oe}${O?"":" with no reply"}`,J=l.trim().split(`
|
|
853
|
+
`).at(-1)?.slice(-300)??"";if(!O||O.code==="desktop_delegate_failed")process.stderr.write(`Reason worker: desktop call ${X}${l?`: ${l.trim().slice(-500)}`:""}
|
|
854
|
+
`);if(O)return u(O);u(new r("desktop_delegate_failed",`Reason's desktop operation failed (${X}${J?`: ${J}`:""}).`))})),t.aborted)S();c.stdin.end(JSON.stringify(o))})}async function z(e,o,t,n={}){let s=await Et(e,{op:"automation",call:o},t,n);if(!Number.isSafeInteger(s.code)||typeof s.stdout!=="string"||typeof s.stderr!=="string")throw new r("desktop_delegate_failed","Reason's desktop reply is malformed.");return{code:s.code,stdout:Buffer.from(s.stdout,"base64"),stderr:s.stderr}}import{execFile as qe,spawn as We}from"child_process";import{closeSync as Fe,mkdirSync as Ge,openSync as He}from"fs";import{dirname as E,join as je}from"path";import{promisify as Ke}from"util";var Xe=Ke(qe),Z="x-apple.systempreferences:com.apple.preference.security",Je={accessibility:`${Z}?Privacy_Accessibility`,screen:`${Z}?Privacy_ScreenCapture`},ze=64,A=new Map;function C(e,o){let t=A.get(e);if(t?.has(o))return!1;if(!t){if(A.size>=ze)A.delete(A.keys().next().value);t=new Set,A.set(e,t)}return t.add(o),!0}function Ve(){let e=a(),o=xn(be(e),process.env),t=je(e,".local","share","reason","desktop-install.log");Ge(E(t),{recursive:!0,mode:448});let n=He(t,"a",384);try{let s=We(o,["desktop","install"],{detached:!0,stdio:["ignore",n,n],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});s.on("error",()=>{return}),s.unref()}finally{Fe(n)}}var T={open:async(e,o)=>{await Xe("/usr/bin/open",e,{signal:o,timeout:1e4,maxBuffer:8192})},request:(e,o)=>ot(e,o),tile:Mr,installDesktop:Ve},Q=!1;async function ee(e,o,t){try{await o.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await o.open([e],t)}}async function oe(e,o,t,n){if(await t.open([Je[o]],n).catch(()=>{}),e[0]&&!n.aborted)t.tile(E(E(E(e[0]))),o)}async function Ze(e,o,t,n,s){for(let i of t){if(!C(e,`grant:${i}`))continue;s.throwIfAborted(),await n.request(o,i).catch(()=>null),await oe(o,i,n,s)}}var Qe={name:"open_tab",description:"Open a web page in the user's own Chrome on this Mac. Reason cannot read, screenshot or click in that tab, and no tab_id is returned: browser control needs Reason's Chrome extension. An actual browser call opens its setup page.",inputSchema:{type:"object",properties:{url:{type:"string",description:"An http or https URL."}},required:["url"],additionalProperties:!1}};function te(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function et(e){if(typeof e!=="string")return null;try{let o=new URL(e);return o.protocol==="https:"||o.protocol==="http:"?o.href:null}catch{return null}}async function re(e,o=T){let{call:t,runId:n,signal:s}=e;if(t.kind==="browser"){if(t.operation==="discover")return te({result:{tools:[Qe]}});if(t.operation!=="call")throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet. Request a browser operation or connect Chrome from Reason to set it up.")}if(e.desktopMissing&&!Q){Q=!0;try{o.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&C(n,"grant:probe")){let c=await o.request(e.identity).catch(()=>null),d=c?[...c.accessibility?[]:["accessibility"],...c.screen?[]:["screen"]]:[];for(let m of d)C(n,`grant:${m}`);for(let m of d)await oe(e.identity,m,o,s)}throw new r("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(C(n,"page:chrome-extension"))await ee($i,o,s).catch(()=>{});let i=t.arguments,u=t.operation==="call"&&t.tool==="open_tab"&&i&&typeof i==="object"&&!Array.isArray(i)?et(i.url):null;if(!u)throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet; Reason opened its Chrome Web Store page. open_tab still opens pages.");return await ee(u,o,s),te({result:{content:[{type:"text",text:JSON.stringify({opened:u,browser:"the user's Chrome",controllable:!1,note:"Opened for the user to see. Reason cannot read or act in this tab until Reason's Chrome extension is added (its Chrome Web Store page is open)."})}]}})}async function ne(e,o=T){if(e.call.kind!=="computer"||e.call.operation!=="permission_status"||e.output.code!==0||e.identity.length===0)return e.output;let t;try{t=JSON.parse(e.output.stdout.toString("utf8"))}catch{return e.output}if(!t||typeof t!=="object"||Array.isArray(t))return e.output;let n=t.permissions;if(!n||typeof n!=="object")return e.output;let s=n,i=[...s.accessibility==="missing"?["accessibility"]:[],...s.screenRecording==="missing"?["screen"]:[]];if(i.length===0)return e.output;return await Ze(e.runId,e.identity,i,o,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:i}))}}var j=172032,ht=18874368,wt=8192,_t=65536,yt=55000,bt=60000,St=4,kt=40000,Rt=/^[0-9a-f-]{36}$/,ce=Y,It=me();function N(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function D(){throw new r("invalid_automation_request","Reason automation request is malformed.")}function he(e){let o=Object.keys(e).sort().join(",");if(o==="call"||o==="browser,call"){let t=e.call,n=o==="browser,call";if(!N(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||n&&(e.browser!==dt||t.kind!=="browser")||JSON.stringify(t).length>_t)D();return{call:t,userChrome:n}}if(o==="offset,output_id"){if(typeof e.output_id!=="string"||!Rt.test(e.output_id)||!Number.isSafeInteger(e.offset)||e.offset<0)D();return{output_id:e.output_id,offset:e.offset}}return D()}function hn(e=process.platform,o=P){if(e==="darwin")return!0;return(e==="linux"||e==="win32")&&o()?.features.computer===!0}var vt="__computer-use";function rs(e=P){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function we(e,o,t,n){return new Promise((s)=>{let i=R(e,o,{env:t,stdio:"ignore",windowsHide:!0}),u=setTimeout(()=>{i.kill("SIGKILL"),s(-1)},n);i.once("error",()=>{clearTimeout(u),s(-1)}),i.once("exit",(c)=>{clearTimeout(u),s(c??-1)})})}function Ot(e,o,t,n){return new Promise((s)=>{let i=R(e,o,{env:t,stdio:["ignore","pipe","ignore"],windowsHide:!0}),u="";i.stdout.setEncoding("utf8").on("data",(d)=>{u+=d});let c=setTimeout(()=>{i.kill("SIGKILL"),s(null)},n);i.once("error",()=>{clearTimeout(c),s(null)}),i.once("close",(d)=>{clearTimeout(c),s(d===0?u:null)})})}function At(e){return v(e)?f(L(),"open-browser-use"):"/tmp/open-browser-use"}function v(e){return e.platform==="win32-x64"||e.platform==="win32-arm64"}var Ct=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Tt=33554432;function Nt(e,o){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let n=N(t)&&N(t.result)?t.result.metadata:null;if(!N(n)||n.extensionId!==o)return null;return typeof n.extensionInstanceId==="string"&&Ct.test(n.extensionInstanceId)?n.extensionInstanceId:null}async function _e(e,o,t){let n=t.storages.map((c)=>{try{return U(c).filter((d)=>d.endsWith(".log")||d.endsWith(".ldb")).map((d)=>f(c,d))}catch{return[]}}),s;try{s=n.some((c)=>c.length>0)?U(t.socketDir).filter((c)=>c.endsWith(".sock")):[]}catch{return[]}let i=[];for(let c of s){let d=f(t.socketDir,c),m=Nt(await Ot(e,["info","--socket",d,"--timeout","2s"],o,5000),t.extensionId);if(m)i.push({instance:m,socket:d})}let u=[];for(let[c,d]of(i.length>0?n:[]).entries())for(let m of d)try{if(ut(m).size>Tt)continue;let l=K(m),p=i.find((g)=>l.includes(g.instance));if(p){u.push({storage:t.storages[c],...p});break}}catch{}return u}async function Pt(e,o,t){return(await _e(e,o,t))[0]?.instance??null}function ye(e,o,t){return Pt(e.nativeHost,o,{socketDir:At(e),extensionId:F,storages:[f(t,"browser-profile","Default","Local Extension Settings",F)]})}var le=/^(Default|Profile ([0-9]+))$/;async function Dt(e,o,t=a(),n=xt){let s=f(t,"Library","Application Support","Google","Chrome"),i=[];try{i=U(s)}catch(l){if(l.code==="EPERM")throw new r("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let u=(l)=>Number(le.exec(l)?.[2]??-1),c=i.filter((l)=>le.test(l)&&M(f(s,l,"Extensions",Me))).sort((l,p)=>u(l)-u(p)),d=(l)=>f(s,l,"Local Extension Settings",Me);return(await _e(e,o,{socketDir:n,extensionId:Me,storages:c.map(d)})).map(({storage:l,instance:p,socket:g})=>({profile:c.find((h)=>d(h)===l),instance:p,socket:g}))}async function Mt(e,o,t=a(),n=xt){let s=(await Dt(e,o,t,n))[0]?.instance;if(!s)throw new r("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return s}function ue(e){return new Promise((o)=>{let t=mt({path:e}),n=(s)=>{t.destroy(),o(s)};t.setTimeout(1000,()=>n(!1)),t.once("error",()=>n(!1)),t.once("connect",()=>n(!0))})}async function Se(e,o){let t=Date.now()+o;while(Date.now()<t){if(await e())return!0;await new Promise((n)=>setTimeout(n,200))}return!1}var W=new Map;function H(e,o){let t=W.get(e);if(!t)t=o().finally(()=>W.delete(e)),W.set(e,t);return t}async function Ut(e,o){if(await ue(e))return;if(lt(e,{force:!0}),await we("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],o,1e4)!==0||!await Se(()=>ue(e),5000))throw new r("automation_unavailable","Reason could not start the desktop session bus.")}async function de(e,o,t){let n=e.platform==="darwin-arm64"||v(e)?async()=>await ye(e,o,t)!==null:async()=>await we(e.nativeHost,["info"],o,5000)===0;if(await n())return;let s=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],i,u=null,c=0;if(e.platform==="darwin-arm64"){let l=f(t,"browser-profile");V(l);let p=f(l,"NativeMessagingHosts");ie(p,{recursive:!0,mode:448});let g=gr(e.platform).nativeHostManifests[0];se(g,f(p,ae(g)));let h=e.browser.slice(0,e.browser.indexOf(".app/")+4),y=s.filter((I)=>I!=="about:blank").concat("--no-startup-window","--use-mock-keychain");i=R("/usr/bin/open",["-g","-n","-a",h,"--args",`--user-data-dir=${l}`,...y],{env:o,stdio:"ignore"})}else if(v(e)){let l=f(t,"browser-profile");V(l),tt(x("icacls"),[B(e.browser),"/grant","*S-1-15-2-1:(OI)(CI)(RX)","*S-1-15-2-2:(OI)(CI)(RX)"],{stdio:"ignore",windowsHide:!0,timeout:60000});let p=s.filter((g)=>g!=="about:blank").concat("--no-startup-window","--keep-alive-for-test");i=R(e.browser,[`--user-data-dir=${l}`,...p],{detached:!0,stdio:"ignore",env:o})}else{let l=f(o.HOME,".config","google-chrome"),p=f(l,"NativeMessagingHosts");ie(p,{recursive:!0,mode:448});let g=gr(e.platform).nativeHostManifests[0];se(g,f(p,ae(g)));let h=process.geteuid?.()===0?["--no-sandbox"]:[];u=f(t,"browser.log");let y=at(u,"a",384);c=it(y).size,i=R(e.browser,[`--user-data-dir=${l}`,...s,...h,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",y,y],env:{...o,ACCESSIBILITY_ENABLED:"1"}}),nt(y)}let d=!1;i.once("error",()=>{d=!0}),i.once("exit",(l)=>{d||=l!==0}),i.unref();let m=!1;if(await Se(async()=>d||(m=await n()),kt),!m){if(u&&K(u).subarray(c).toString("utf8").includes("No usable sandbox"))throw new r("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function ns(e){await Re(e,!0)}function is(e){return xe(e,ke(e))}function xe(e,o){return e.platform==="darwin-arm64"||v(e)?f(o,"browser-profile"):f(o,"home",".config","google-chrome")}function ke(e){let o=f(e.root,"automation");if(!M(o)||!Lt(e.automation))return e.automation;if(!$t(xe(e,o)))try{fe(o,e.automation)}catch{}return M(o)?o:e.automation}function Lt(e){try{return U(e).length===0}catch(o){return o.code==="ENOENT"}}function $t(e){let o;try{o=ct(f(e,"SingletonLock"))}catch{return!1}let t=Number(o.slice(o.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function Re(e,o){ft({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=ke(e);V(t);let n=ge().username,s={USER:n,LOGNAME:n,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"||v(e)){let l=v(e)?{...s,...Bt(),HOME:a()}:{...s,HOME:a(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:vt};if(!o)return l;await H("browser",()=>de(e,l,t));let p=await ye(e,l,t);if(!p)throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...l,REASON_AUTOMATION_OBU_INSTANCE:p,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let i=await $e(),u=f(t,"home"),c=f(t,"runtime");V(u),V(c);let d=f(t,"bus"),m={...s,HOME:u,PATH:`${B(e.node)}:/usr/bin:/bin`,DISPLAY:i.display,XAUTHORITY:i.xauthority,XDG_RUNTIME_DIR:c,DBUS_SESSION_BUS_ADDRESS:`unix:path=${d}`,...i.sound?{PULSE_SERVER:Ye(i.sound)}:{}};if(await H("bus",()=>Ut(d,m)),o)await H("browser",()=>de(e,m,t));return m}function Bt(){let e=process.env.SystemRoot??"C:\\Windows",o=Object.fromEntries(["SystemDrive","USERPROFILE","LOCALAPPDATA","APPDATA","ProgramData","ProgramFiles","PATHEXT","ComSpec","USERNAME","USERDOMAIN","COMPUTERNAME","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","PSModuleAnalysisCachePath"].flatMap((n)=>process.env[n]?[[n,process.env[n]]]:[])),t=f(e,"System32");return{...o,SystemRoot:e,windir:e,TEMP:L(),TMP:L(),PATH:[t,f(t,"WindowsPowerShell","v1.0"),e].join(gt)}}async function qt(e,o,t){let n=ge().username,s={USER:n,LOGNAME:n,HOME:a(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:o,REASON_AUTOMATION_BACKGROUND_TABS:"1"},i=await Mt(o,s);return t.throwIfAborted(),{...s,REASON_AUTOMATION_OBU_INSTANCE:i}}function Wt(e){if(process.platform!=="win32")return["--input-type=module","--eval",e];let o=f(L(),`reason-automation-${rt("sha256").update(e).digest("hex").slice(0,16)}.mjs`);if(!M(o)||K(o,"utf8")!==e){let t=`${o}.${process.pid}.tmp`;pt(t,e,{mode:384}),fe(t,o)}return[o]}function Ie(e,o,t,n){if(typeof ce!=="string")return Promise.reject(new r("automation_unavailable","This Reason build has no automation runtime."));let s=ce;return new Promise((i,u)=>{let c=R(e,Wt(s),{env:{...o,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32",windowsHide:!0}),d=[],m=0,l="",p=null,g=!1,h=(w)=>{if(p??=w,process.platform==="win32"&&c.pid){R(f(process.env.SystemRoot??"C:\\Windows","System32","taskkill.exe"),["/pid",String(c.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0}).once("error",()=>c.kill("SIGKILL"));return}try{process.kill(-c.pid,"SIGKILL")}catch{c.kill("SIGKILL")}},y=(w)=>{if(g)return;g=!0,clearTimeout(I),n.removeEventListener("abort",S),w()},I=setTimeout(()=>h(new r("automation_timed_out","Reason automation did not finish in time.")),yt),S=()=>h(new r("cancelled","Reason cancelled the automation call."));if(n.addEventListener("abort",S,{once:!0}),c.stdout.on("data",(w)=>{if(m+=w.byteLength,m>ht)h(new r("automation_output_too_large","Reason automation output is too large."));else d.push(w)}),c.stderr.setEncoding("utf8").on("data",(w)=>{l=(l+w).slice(-wt)}),c.stdin.on("error",()=>{}),c.once("error",()=>y(()=>u(p??new r("automation_unavailable","Reason could not start the automation runtime.")))),c.once("close",(w)=>y(()=>{if(p)u(p);else i({code:w??1,stdout:Buffer.concat(d),stderr:l})})),n.aborted)S();c.stdin.end(t)})}var k=new Map;function Ft(e,o,t){for(let[s,i]of k)if(i.expiresAt<=t)k.delete(s);while(k.size>=St)k.delete(k.keys().next().value);let n=me();return k.set(n,{runId:e,bytes:o,expiresAt:t+bt}),n}async function ve(e,o,t,n={}){let s=await(n.environment??Re)(e,o.kind==="browser");return t.throwIfAborted(),await(n.runtime??Ie)(e.node,s,JSON.stringify(o),t)}async function os(e,o){let t=he({call:e});if(!("call"in t))D();let n=P();if(!n?.features.computer||t.call.kind==="browser"&&!n.features.browser)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await ve(n,t.call,o)}function pe(e,o,t){let n=e.stdout.byteLength>j?Ft(o,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:It,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,j).toString("base64"),...n?{output_id:n}:{}}}async function fn(e,o={}){let t=he(e.payload),n=(o.now??Date.now)();if("output_id"in t){let h=k.get(t.output_id);if(!h||h.runId!==e.runId||h.expiresAt<=n||t.offset>h.bytes.byteLength)throw new r("automation_output_unavailable","Reason automation output expired.");return{chunk:h.bytes.subarray(t.offset,t.offset+j).toString("base64")}}let s=(o.components??P)(),i=(o.platform??process.platform)==="darwin",u=i?(o.macIdentity??st)():[],c=o.macSetup??T,d=!s?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!s.features.browser;if(i&&(d||u.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return pe(await re({runId:e.runId,call:t.call,identity:u,desktopMissing:d,signal:e.signal},c),e.runId,n);if(!s?.features.computer)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let m=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!m)throw new r("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!m&&!s.features.browser)throw new r("automation_browser_not_installed",!s.platform.startsWith("linux")?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let l=await mi(e.runId,e.signal,o.now),p="account"in o?o.account??null:G(),g;try{if(m){let h=await(o.userChromeEnvironment??qt)(s,m,e.signal);e.signal.throwIfAborted(),g=await(o.runtime??Ie)(s.node,h,JSON.stringify(t.call),e.signal)}else if(p)g=await(o.delegate??z)(p,t.call,e.signal);else g=await ve(s,t.call,e.signal,o)}finally{l()}if(i)g=await ne({runId:e.runId,call:t.call,identity:u,output:g,signal:e.signal},c);return pe(g,e.runId,n)}
|
|
855
|
+
export{Et,hn,rs,ns,is,os,fn};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{he}from"./vm-hands-entry-lite-4aejamqr.js";var Zr=he(function(t,e){e.exports={name:"playwright-core",version:"1.60.0",description:"A high-level API to automate web browsers",repository:{type:"git",url:"git+https://github.com/microsoft/playwright.git"},homepage:"https://playwright.dev",engines:{node:">=18"},author:{name:"Microsoft Corporation"},license:"Apache-2.0",exports:{".":{types:"./index.d.ts",import:"./index.mjs",require:"./index.js",default:"./index.js"},"./package.json":"./package.json","./lib/bootstrap":"./lib/bootstrap.js","./lib/coreBundle":"./lib/coreBundle.js","./lib/utilsBundle":"./lib/utilsBundle.js","./lib/tools/cli-client/program":"./lib/tools/cli-client/program.js"},bin:{"playwright-core":"cli.js"},types:"types/types.d.ts"}});
|
|
3
|
+
export{Zr};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var ue=".reason/workspace",Ee="workspace_base",J="sessions",xe="workspace_layout",de=".reason/workspace/sessions",Ht=/^[0-9a-f]{8}$/;function ze(t){if(!Z(t))return!1;let e=".reason/workspace/sessions/";if(!t.startsWith(e))return!1;let n=t.slice(e.length).split("/");return n.length===2&&Ht.test(n[0])}var i=4096,S="workspaces/pi";function Z(t){if(typeof t!=="string"||!t||t.length>i)return!1;if(t.startsWith("/")||t.includes("\x00")||t.includes("\\"))return!1;return t.split("/").every((e)=>e!==""&&e!=="."&&e!=="..")}function T(t){if(t.kind==="root"){if(t.path===void 0)return".";if(!Z(t.path))throw Error("invalid_device_workspace_identity");return t.path}if(!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,159}$/.test(t.workspaceId)||t.workspaceId==="."||t.workspaceId==="..")throw Error("invalid_device_workspace_identity");let e=t.layout==="sessions"?"sessions":S;return`${t.base?`${t.base}/`:""}${e}/${t.workspaceId}/repo`}function H(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t;if(e.kind==="root"&&Object.keys(e).length===1)return{kind:"root"};if(e.kind==="root"&&Object.keys(e).length===2&&Z(e.path))return{kind:"root",path:e.path};if(e.kind!=="managed"||typeof e.workspaceId!=="string"||Object.keys(e).length!==2+(e.base===void 0?0:1)+(e.layout===void 0?0:1)||e.base!==void 0&&e.base!==".reason/workspace"||e.layout!==void 0&&e.layout!=="sessions")return null;let n={kind:"managed",workspaceId:e.workspaceId,...e.base===".reason/workspace"?{base:".reason/workspace"}:{},...e.layout==="sessions"?{layout:"sessions"}:{}};try{return T(n),n}catch{return null}}var c="/home/runner";var jr="/run/reason/sessions",O=/^(?:\/[A-Za-z0-9._-]+)+$/,Ur=/-sidechat-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,Hr=/^(.+)-repository-[a-z0-9][a-z0-9._-]*-[0-9a-f]{12}$/;function a(t){return Ur.exec(t)?.[1]??Hr.exec(t)?.[1]??t}var qt=/^((?:\/[A-Za-z0-9._-]+)+)\/\.reason\/workspace\/(workspaces\/pi|sessions)\/([^/]+)$/;function _(t,e=c,n="sessions"){if(!O.test(e)||e.split("/").some((s)=>s==="."||s===".."))throw Error("invalid_cloud_payload_home");let r=`${e}/${T({kind:"managed",workspaceId:t,base:".reason/workspace",...n?{layout:n}:{}})}`,o=`${jr}/${a(t)}`;return{home:e,root:r.slice(0,-5),checkout:r,control:o,jobEnv:`${o}/job.env`,cloudAccess:`${o}/cloud-access`,logs:`${o}/logs`,pin:`${o}/ws`}}function E(t){return qt.exec(t.replace(/\/+$/,""))?.[2]==="sessions"?"sessions":null}function qr(t){let e=qt.exec(t.replace(/\/+$/,""));if(!e)return null;try{let n=_(e[3],e[1],E(t));return n.root===t.replace(/\/+$/,"")?n:null}catch{return null}}
|
|
3
|
+
export{ue,Ee,J,xe,de,Ht,ze,Z,T,H,jr,Ur,Hr,qt,qr};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{E}from"./vm-hands-entry-lite-0n2f3kx7.js";import{fe,Te,Vt,Gt,Re}from"./vm-hands-entry-lite-zg3b0c08.js";import{spawn as y}from"child_process";import{existsSync as p,mkdirSync as T,readFileSync as _,writeFileSync as A}from"fs";import{homedir as m}from"os";import{basename as H,delimiter as g,join as f,win32 as u}from"path";var pr=process.platform==="win32"?Te("win32"):"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",P=pr.split(g),R=5000,S=65536,O=new Set(["zsh","bash"]),b=[[".local","bin"],[".bun","bin"],[".cargo","bin"],["go","bin"]],x=(t,e)=>new Promise((n,r)=>{let o;try{o=y(t,[...e],{...Vt(),stdio:["ignore","pipe","ignore"]}),Gt(o)}catch(c){r(c);return}let i=[],s=0,a=null,L=(c)=>{a??=Error(c);try{if(o.pid!==void 0)Re(o.pid,"SIGKILL")}catch{}},d=setTimeout(()=>L("login_shell_timeout"),R);o.stdout?.on("data",(c)=>{if(s+=c.length,s>S)L("login_shell_output_too_large");else i.push(c)}),o.once("error",(c)=>{clearTimeout(d),r(c)}),o.once("close",(c)=>{if(clearTimeout(d),a)r(a);else if(c!==0)r(Error("login_shell_exit_nonzero"));else n(Buffer.concat(i).toString("utf8"))})});function w(t){return typeof t==="string"&&t.startsWith("/")&&!t.includes("\x00")&&O.has(H(t))}function h(t){let e=new Set,n=[];for(let r of t){if(e.has(r))continue;e.add(r),n.push(r)}return n}function hr(t,e=process.platform){let n=e==="win32",r=t.split(`
|
|
3
|
+
`).at(-1)??"",o=[];for(let i of r.split(n?";":":")){let s=i.trim();if(n?!u.isAbsolute(s):!s.startsWith("/"))continue;if(s.includes("\x00"))continue;if(E(s))continue;o.push(s)}return h(o)}function an(t){let e=t?.home??m(),n=t?.directoryExists??p,r=b.map((o)=>f(e,...o)).filter((o)=>{try{return n(o)}catch{return!1}});return h([...r,...process.platform==="win32"?hr(process.env.PATH??process.env.Path??""):[],...P]).join(g)}async function C(t){let e=t?.shell??process.env.SHELL,n=()=>({path:an({home:t?.home,directoryExists:t?.directoryExists}),source:"fallback"});if(process.platform==="win32"||!w(e))return n();let r;try{r=await(t?.runLoginShell??x)(e,["-lic",'printf %s "$PATH"'])}catch{return n()}if(Buffer.byteLength(r,"utf8")>S)return n();let o=hr(r);if(o.length===0)return n();return{path:h([...o,...P]).join(":"),source:"login_shell"}}function Li(t){let e=null;return()=>(e??=C(t),e)}function l(t){if(t===void 0||t.includes("\x00")||Buffer.byteLength(t,"utf8")>32768)return;return t}function Le(t){let e=t.source??process.env,n={HOME:t.home,PATH:t.path??pr,TMPDIR:t.temporaryDirectory,SHELL:l(e.SHELL)??"/bin/zsh",LANG:l(e.LANG)??"C.UTF-8",LC_ALL:l(e.LC_ALL)??l(e.LANG)??"C.UTF-8"},r=l(e.LC_CTYPE),o=l(e.TERM),i=l(e.COLORTERM);if(r)n.LC_CTYPE=r;if(o)n.TERM=o;if(i)n.COLORTERM=i;if(process.platform==="win32"){for(let s of I){let a=l(e[s]);if(a)n[s]=a}n.TEMP=n.TMP=t.temporaryDirectory,n.SHELL=fe()??n.SHELL,n.PATH=cn(n.PATH)}return n}function cn(t,e=f(m(),".reason","python3")){let n=(i)=>t.split(u.delimiter).filter((s)=>s&&!/[\\/]WindowsApps[\\/]?$/i.test(s)).map((s)=>u.join(s,i)).find((s)=>p(s)),r=n("python.exe");if(n("python3.exe")||!r)return t;let o=`#!/bin/sh
|
|
4
|
+
exec "${r.replaceAll("\\","/")}" "$@"
|
|
5
|
+
`;try{let i=f(e,"python3");if(!p(i)||_(i,"utf8")!==o)T(e,{recursive:!0}),A(i,o)}catch{return t}return[e,t].join(u.delimiter)}var I=["SystemRoot","SystemDrive","windir","ComSpec","PATHEXT","USERPROFILE","USERNAME","USERDOMAIN","APPDATA","LOCALAPPDATA","ProgramData","ProgramFiles","ProgramFiles(x86)","ProgramW6432","CommonProgramFiles","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","OS"];
|
|
6
|
+
export{pr,hr,an,Li,Le,cn};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{H}from"./vm-hands-entry-lite-mvx29q2q.js";import{et}from"./vm-hands-entry-lite-g3ja0c3y.js";import{Ot}from"./vm-hands-entry-lite-51qvfk93.js";import{j}from"./vm-hands-entry-lite-dq1m5ykp.js";import{ne}from"./vm-hands-entry-lite-dkcm3hyn.js";import{Oe}from"./vm-hands-entry-lite-rwr09j4w.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{existsSync as D,realpathSync as q,statSync as K}from"fs";import{platform as h}from"os";import{isAbsolute as z,sep as G}from"path";import{existsSync as X}from"fs";import{createRequire as Y}from"module";var k=Oe(Ot)(()=>Y(import.meta.url)("bun:ffi"),X);function E(){return process.platform==="win32"&&typeof globalThis.Bun<"u"&&k.available()}function C(e=process.env){return k.defaultShell(e)}function M(e){return k.shellArgs(e)}function N(e){let n=k.spawn({...e,env:e.environment});return n.exited.then(()=>n.close()),{write:(o)=>n.write(o),resize:(o,t)=>n.resize(o,t),kill:()=>n.close(),exited:n.exited}}var _r=43200000,At=et,yr=4,Q=/^[A-Za-z0-9._:-]{1,160}$/,V=1000;function I(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function P(e,n){if(typeof e!=="number"||!Number.isFinite(e)||e<=0)return n;return Math.min(V,Math.max(1,Math.floor(e)))}function Z(e,n=Date.now()){let o=["relay_url","session_id","expires_at"],t=new Set([...o,"cols","rows","cwd","workspace"]);if(!I(e)||o.some((b)=>!(b in e))||Object.keys(e).some((b)=>!t.has(b)))throw new r("invalid_pty_request","Reason terminal request is malformed.");let{relay_url:c,session_id:m,expires_at:g}=e;if(typeof c!=="string")throw new r("invalid_pty_request","Reason terminal relay URL is missing.");let d;try{d=new URL(c)}catch{throw new r("invalid_pty_request","Reason terminal relay URL is invalid.")}if(d.protocol!=="wss:"&&d.protocol!=="ws:"||d.username||d.password)throw new r("invalid_pty_request","Reason terminal relay URL is invalid.");if(typeof m!=="string"||!Q.test(m))throw new r("invalid_pty_request","Reason terminal session identity is invalid.");let p=typeof g==="string"?Date.parse(g):Number.NaN;if(!Number.isFinite(p)||p<=n)throw new r("invalid_pty_request","Reason terminal session has already expired.");if(e.cwd!==void 0&&typeof e.cwd!=="string")throw new r("invalid_pty_request","Reason terminal working directory is invalid.");let a=e.workspace===void 0?void 0:H(e.workspace);if(a===null||a&&e.cwd!==void 0)throw new r("invalid_pty_request","Reason terminal workspace is invalid.");return{relay_url:c,session_id:m,expires_at:new Date(Math.min(p,n+_r)).toISOString(),cols:P(e.cols,80),rows:P(e.rows,24),...e.cwd===void 0?{}:{cwd:e.cwd},...a?{workspace:a}:{}}}function ee(e,n){if(h()==="win32")[e,n]=[e.toLowerCase(),n.toLowerCase()];return n===e||n.startsWith(e+G)}function W(e,n){if(n===void 0)return e;if(!z(n))throw new r("pty_cwd_invalid","Reason terminal working directory must be absolute.");let o;try{o=q(n)}catch{throw new r("pty_cwd_invalid","Reason terminal working directory does not exist.")}if(!ee(e,o))throw new r("pty_cwd_outside_root","Reason terminal working directory escapes the granted root.");if(!K(o).isDirectory())throw new r("pty_cwd_invalid","Reason terminal working directory is not a directory.");return o}function Po(e=process.env){if(h()==="win32")return C(e);let n=e.SHELL;if(n&&z(n)&&D(n))return n;for(let o of h()==="darwin"?["/bin/zsh","/bin/bash","/bin/sh"]:["/bin/bash","/bin/sh"])if(D(o))return o;return"/bin/sh"}function re(){let e=globalThis.Bun;if(!e)throw new r("pty_unavailable","Reason terminals require the Bun runtime.");return e.spawn}function mn(){if(h()==="win32")return E();return typeof globalThis.Bun<"u"}var te=(e)=>{if(h()==="win32")try{return N({...e,file:e.shell,args:M(e.shell),environment:{...e.environment,TERM:"xterm-256color"}})}catch{throw new r("pty_unavailable","Reason could not allocate a pseudo-terminal.")}let n=re()({cmd:[e.shell,"-i","-l"],cwd:e.cwd,env:{...e.environment,TERM:"xterm-256color"},terminal:{cols:e.cols,rows:e.rows,data:(t,c)=>{e.onData(c)}}}),o=n.terminal;if(!o){try{n.kill()}catch{}throw new r("pty_unavailable","Reason could not allocate a pseudo-terminal.")}return{write:(t)=>o.write(t),resize:(t,c)=>o.resize(t,c),kill:()=>{try{n.kill()}catch{}},exited:n.exited.then((t)=>typeof t==="number"?t:null,()=>null)}},wr=(e,n)=>n===void 0?new WebSocket(e):new WebSocket(e,{proxy:n}),v=new Set;function oe(e){if(v.size>=yr||v.has(e))return null;v.add(e);let n=!1;return()=>{if(n)return;n=!0,v.delete(e)}}async function gn(e,n={}){let o=n.now??Date.now,t=Z(e.payload,o()),c=oe(e.operationId);if(!c)throw new r("pty_slot_busy","This Reason Device already runs the maximum number of terminals.");let m=o(),g,d,p;try{let a=t.workspace?ne(e.root,t.workspace):void 0;g=a?W(D(a.boundary)?q(a.boundary):a.boundary,a.path):W(e.root,t.cwd),d=n.environment??process.env,p=n.shellPath??Po(d)}catch(a){throw c(),a}return await new Promise((a,b)=>{let w=null,i=null,S=!1,x=!1,y=!1,T=null,U=0,B=0,O=[],R=0,A=null,l=(s)=>{if(y)return;if(y=!0,A)clearTimeout(A);e.signal.removeEventListener("abort",L);try{w?.kill()}catch{}try{i?.close(1000,"pty_session_over")}catch{}if(c(),s.kind==="rejected"){b(s.error);return}let u={reason:s.reason,exit_code:T,output_bytes:U,input_bytes:B,duration_ms:Math.max(0,o()-m)};e.emitEvent("pty.stopped",{...u}).catch(()=>{return}),a({...u})},L=()=>{let s=e.signal.reason;l({kind:"rejected",error:s instanceof r?s:new r("cancelled","Reason closed the terminal session.")})};if(e.signal.aborted){L();return}e.signal.addEventListener("abort",L,{once:!0}),A=setTimeout(()=>l({kind:"resolved",reason:"session_expired"}),Math.max(1,Date.parse(t.expires_at)-o()));let F=(s)=>{if(U+=s.byteLength,!S||!i){if(O.push(s),R+=s.byteLength,R>At)l({kind:"resolved",reason:"output_backpressure"});return}try{i.send(s)}catch{l({kind:"resolved",reason:"relay_closed"});return}if(i.bufferedAmount>At)l({kind:"resolved",reason:"output_backpressure"})};try{w=(n.spawnPty??te)({shell:p,args:["-i","-l"],cwd:g,cols:t.cols,rows:t.rows,environment:d,onData:(s)=>{if(!y)F(s)}})}catch(s){l({kind:"rejected",error:s instanceof r?s:new r("pty_spawn_failed","Reason could not start the terminal shell.")});return}w.exited.then((s)=>{if(y)return;if(T=s,S&&i)try{i.send(JSON.stringify({t:"exit",code:s}))}catch{}l({kind:"resolved",reason:"shell_exited"})});let J=(n.loadProxy??j)()?.url;try{i=(n.connect??wr)(t.relay_url,J)}catch{l({kind:"rejected",error:new r("pty_relay_unavailable","Reason could not reach the terminal relay.")});return}i.binaryType="arraybuffer",i.onopen=()=>{if(y||!i)return;S=!0;try{i.send(JSON.stringify({t:"open",cols:t.cols,rows:t.rows}));for(let s of O.splice(0))i.send(s);R=0}catch{l({kind:"resolved",reason:"relay_closed"});return}x=!0,e.emitEvent("pty.ready",{session_id:t.session_id,cols:t.cols,rows:t.rows}).catch(()=>{return})},i.onmessage=(s)=>{if(y||!w)return;let u=s.data;if(typeof u==="string"){let f;try{f=JSON.parse(u)}catch{return}if(!I(f))return;if(f.t==="resize"){try{w.resize(P(f.cols,t.cols),P(f.rows,t.rows))}catch{}return}if(f.t==="close")l({kind:"resolved",reason:"client_closed"});return}let _=u instanceof ArrayBuffer?new Uint8Array(u):ArrayBuffer.isView(u)?new Uint8Array(u.buffer,u.byteOffset,u.byteLength):null;if(!_||_.byteLength===0)return;B+=_.byteLength;try{w.write(_)}catch{}},i.onclose=()=>{if(y)return;if(!x){l({kind:"rejected",error:new r("pty_relay_unavailable","Reason could not reach the terminal relay.")});return}l({kind:"resolved",reason:"relay_closed"})},i.onerror=()=>{if(y||x)return;l({kind:"rejected",error:new r("pty_relay_unavailable","Reason could not reach the terminal relay.")})}})}
|
|
3
|
+
export{_r,At,yr,Po,mn,wr,gn};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var i="libara_device_keychain.dylib",e="libreason_device_keychain.dylib";class tt extends Error{code;constructor(n,t){super(t);this.code=n;this.name="ManagedRuntimeError"}}import{existsSync as s}from"fs";import{join as a}from"path";function zi(n){let t=a(n,e);return s(t)?t:a(n,i)}
|
|
3
|
+
export{tt,zi};
|